Updated the logging system

This commit is contained in:
WolverinDEV
2019-11-23 21:16:55 +01:00
parent b7d60361c0
commit fb5dc72970
28 changed files with 135 additions and 104 deletions
@@ -1,5 +1,7 @@
#include <memory>
#include <spdlog/sinks/rotating_file_sink.h>
#include <iostream>
#include <bitset>
#include <algorithm>
@@ -475,7 +477,8 @@ CommandResult ConnectedClient::handleCommandServerEdit(Command &cmd) {
serverInstance->getWebList()->enable_report(target_server);
else
serverInstance->getWebList()->disable_report(target_server);
debugMessage(string() + "Changed weblist state to -> " + (cmd["virtualserver_weblist_enabled"].as<bool>() ? "activated" : "disabled"));
debugMessage(target_server->getServerId(), "Changed weblist state to -> {}",
cmd["virtualserver_weblist_enabled"].as<bool>() ? "activated" : "disabled");
}
} SERVEREDIT_CHK_PROP_CACHED("virtualserver_needed_identity_security_level", permission::b_virtualserver_modify_needed_identity_security_level, int) }
@@ -3812,7 +3815,7 @@ CommandResult ConnectedClient::handleCommandFTDeleteFile(Command &cmd) {
for (const auto &file : files) {
if (!file) continue;
if (!serverInstance->getFileServer()->deleteFile(file)) {
logCritical(this->getServerId(), lstream << "Cound not delete file " << file->path << "/" << file->name);
logCritical(this->getServerId(), "Could not delete file {}/{}", file->path, file->name);
}
}
@@ -7370,8 +7373,12 @@ CommandResult ConnectedClient::handleCommandLogView(ts::Command& cmd) {
PERM_CHECKR(permission::b_virtualserver_log_view, 1, true);
for(const auto& sink : logger::logger(target_server)->sinks()) {
if(dynamic_pointer_cast<logger::ColoredFileSink>(sink)) {
log_path = dynamic_pointer_cast<logger::ColoredFileSink>(sink)->_file_helper.filename();
if(dynamic_pointer_cast<spdlog::sinks::rotating_file_sink_mt>(sink)) {
log_path = dynamic_pointer_cast<spdlog::sinks::rotating_file_sink_mt>(sink)->filename();
break;
} else if(dynamic_pointer_cast<spdlog::sinks::rotating_file_sink_st>(sink)) {
log_path = dynamic_pointer_cast<spdlog::sinks::rotating_file_sink_st>(sink)->filename();
break;
}
}
if(log_path.empty())
+12 -4
View File
@@ -220,8 +220,12 @@ bool DataClient::permissionGranted(PermissionTestType test, permission::Permissi
auto client = dynamic_cast<ConnectedClient*>(this);
if(client)
serverId = client->getServerId();
debugMessage(serverId, lstream << "[Permission] Value test result for test type " << test << ".");
debugMessage(serverId, lstream << "[Permission] Permission: " << permission::resolvePermissionData(type)->name << " Required value: " << required << " Gained value: " << value << " Force required: " << force_granted << " Channel: " << (target ? target->name() : "none") << " Result: " << result);
debugMessage(serverId, "[Permission] Value test result for test type {}.", test);
debugMessage(serverId,
"[Permission] Permission: {} Required value: {} Gained value: {} Force required: {} Channel: {} Result: {}",
permission::resolvePermissionData(type)->name,
required, value, force_granted, (target ? target->name() : "none"), result
);
};
#endif
return result;
@@ -237,8 +241,12 @@ bool DataClient::permissionGrantGranted(PermissionTestType test, permission::Per
auto client = dynamic_cast<ConnectedClient*>(this);
if(client)
serverId = client->getServerId();
debugMessage(serverId, lstream << "[Permission] Grant test result for test type " << test << ".");
debugMessage(serverId, lstream << "[Permission] Permission: " << permission::resolvePermissionData(type)->name << " Required value: " << required << " Gained value: " << value << " Force required: " << force_granted << " Channel: " << (target ? target->name() : "none") << " Result: " << result);
debugMessage(serverId, "[Permission] Grant test result for test type {}.", test);
debugMessage(serverId,
"[Permission] Permission: {} Required value: {} Gained value: {} Force required: {} Channel: {} Result: {}",
permission::resolvePermissionData(type)->name,
required, value, force_granted, (target ? target->name() : "none"), result
);
};
#endif
return result;
+1 -1
View File
@@ -27,7 +27,7 @@ void InternalClient::sendCommand(const ts::Command &command, bool low) {
}
bool InternalClient::closeConnection(const std::chrono::system_clock::time_point& timeout) {
logError("Internal manager is force to disconnect?");
logError(this->getServerId(), "Internal client is force to disconnect?");
if(this->server)
this->server->unregisterInternalClient(static_pointer_cast<InternalClient>(_this.lock()));
+29 -17
View File
@@ -57,39 +57,51 @@ CommandResult SpeakingClient::handleCommandHandshakeBegin(Command& cmd) { //If !
try {
this->handshake.identityData = make_shared<Json::Value>();
this->handshake.proof_message = cmd["data"].string();
Json::Reader reader;
std::istringstream stream(this->handshake.proof_message);
reader.parse(stream, *this->handshake.identityData);
if(!stream) return {findError("web_handshake_invalid"), "invalid json!"};
if((*this->handshake.identityData)["user_id"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"};
if((*this->handshake.identityData)["user_name"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"};
if((*this->handshake.identityData)["user_group"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"};
if((*this->handshake.identityData)["user_groups"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"};
if((*this->handshake.identityData)["data_age"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"};
std::string error{};
Json::CharReaderBuilder rbuilder{};
const std::unique_ptr<Json::CharReader> reader(rbuilder.newCharReader());
auto& json_str = this->handshake.proof_message;
if(!reader->parse(json_str.data(), json_str.data() + json_str.size(), &*this->handshake.identityData, &error)) {
debugMessage(this->getServerId(), "[{}] Failed to parse forum account data: {}", error);
return {findError("web_handshake_invalid"), "invalid json!"};
}
auto& json_data = *this->handshake.identityData;
if(json_data["user_id"].isNull())
return {findError("web_handshake_invalid"), "Missing json data (user_id)!"};
if(json_data["user_name"].isNull())
return {findError("web_handshake_invalid"), "Missing json data (user_name)!"};
if(json_data["user_group"].isNull())
return {findError("web_handshake_invalid"), "Missing json data (user_group)!"};
if(json_data["user_groups"].isNull())
return {findError("web_handshake_invalid"), "Missing json data (user_groups)!"};
if(json_data["data_age"].isNull())
return {findError("web_handshake_invalid"), "Missing json data (data_age)!"};
//Type test
(*this->handshake.identityData)["user_id"].asInt64();
json_data["user_id"].asInt64();
if((*this->handshake.identityData)["data_age"].asUInt64() < duration_cast<milliseconds>((system_clock::now() - hours(72)).time_since_epoch()).count())
if(json_data["data_age"].asUInt64() < duration_cast<milliseconds>((system_clock::now() - hours(72)).time_since_epoch()).count())
return {findError("web_handshake_invalid"), "Provided data is too old!"};
this->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = base64::encode(digest::sha1("TeaSpeak-Forum#" + (*this->handshake.identityData)["user_id"].asString()));
this->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = base64::encode(digest::sha1("TeaSpeak-Forum#" + json_data["user_id"].asString()));
this->properties()[property::CLIENT_TEAFORO_ID] = (*this->handshake.identityData)["user_id"].asInt64();
this->properties()[property::CLIENT_TEAFORO_NAME] = (*this->handshake.identityData)["user_name"].asString();
this->properties()[property::CLIENT_TEAFORO_ID] = json_data["user_id"].asInt64();
this->properties()[property::CLIENT_TEAFORO_NAME] = json_data["user_name"].asString();
{
///* 0x01 := Banned | 0x02 := Stuff | 0x04 := Premium */
uint64_t flags = 0;
if((*this->handshake.identityData)["is_banned"].isBool() && (*this->handshake.identityData)["is_banned"].asBool())
if(json_data["is_banned"].isBool() && json_data["is_banned"].asBool())
flags |= 0x01U;
if((*this->handshake.identityData)["is_staff"].isBool() && (*this->handshake.identityData)["is_staff"].asBool())
if(json_data["is_staff"].isBool() && json_data["is_staff"].asBool())
flags |= 0x02U;
if((*this->handshake.identityData)["is_premium"].isBool() && (*this->handshake.identityData)["is_premium"].asBool())
if(json_data["is_premium"].isBool() && json_data["is_premium"].asBool())
flags |= 0x04U;
this->properties()[property::CLIENT_TEAFORO_FLAGS] = flags;
+1 -1
View File
@@ -96,7 +96,7 @@ MusicClient::~MusicClient() {
void MusicClient::sendCommand(const ts::Command &command, bool low) { }
bool MusicClient::closeConnection(const std::chrono::system_clock::time_point&) {
logError("Music manager is forced to disconnect!");
logError(this->getServerId(), "Music manager is forced to disconnect!");
/*
if(this->server)
+1 -1
View File
@@ -124,7 +124,7 @@ void QueryClient::writeMessage(const std::string& message) {
if(this->connectionType == ConnectionType::PLAIN) this->writeRawMessage(message);
else if(this->connectionType == ConnectionType::SSL_ENCRIPTED) this->ssl_handler.send(pipes::buffer_view{(void*) message.data(), message.length()});
else logCritical("Invalid query connection type!");
else logCritical(LOG_GENERAL, "Invalid query connection type to write to!");
}
@@ -135,7 +135,7 @@ CommandResult QueryClient::handleCommandLogin(Command& cmd) {
username = cmd[0][0].key();
password = cmd[0][1].key();
}
debugMessage("Attempted query login with " + username + " - " + password);
debugMessage(LOG_QUERY, "Having query login attempt for username {}", username);
auto _account = serverInstance->getQueryServer()->find_query_account_by_name(username);
auto account = _account ? serverInstance->getQueryServer()->load_password(_account) : nullptr;
@@ -374,7 +374,6 @@ CommandResult QueryClient::handleCommandJoin(Command &) {
if(this->currentChannel)
return {findError("server_already_joined"), "already joined!"};
debugMessage("Uid -> " + this->properties()[property::CLIENT_UNIQUE_IDENTIFIER].as<string>());
this->server->assignDefaultChannel(this->ref(), true);
return CommandResult::Success;
}
@@ -811,7 +810,7 @@ CommandResult QueryClient::handleCommandServerSnapshotDeploy(Command& cmd) {
auto hash = cmd["hash"].string();
if(hash.empty()) return {findError("parameter_invalid"), "Invalid hash (not present)"};
debugMessage("Hash: '" + hash + "'");
debugMessage(this->getServerId(), "Serversnapshot calculated hash: {}", hash);
bool mapping = cmd.hasParm("mapping");
cmd.disableParm("mapping");
@@ -834,7 +833,7 @@ CommandResult QueryClient::handleCommandServerSnapshotDeploy(Command& cmd) {
Command res("");
if(!result){
logError("Could not apply server snapshot: " + error);
logError(this->getServerId(), "Could not apply server snapshot: {}", error);
res["success"] = false;
res["sid"] = 0;
res["message"] = error;
@@ -929,7 +928,7 @@ CommandResult QueryClient::handleCommandServerNotifyRegister(Command &cmd) {
CMD_REQ_PARM("event");
CMD_RESET_IDLE;
if(!cmd[0].has("specifier") && cmd["event"].as<string>() != "all") { //Lagacy support
logMessage("[Query] Client " + this->getLoggingPeerIp() + ":" + to_string(this->getPeerPort()) + " uses the lagacy notify system, which is deprecated!");
logMessage(this->getServerId(), "{} Client {}:{} uses the lagacy notify system, which is deprecated!", CLIENT_STR_LOG_PREFIX, this->getLoggingPeerIp(), this->getPeerPort());
string event = cmd["event"];
std::transform(event.begin(), event.end(), event.begin(), ::tolower);
#include "XMacroEventTypes.h"
@@ -985,7 +984,7 @@ CommandResult QueryClient::handleCommandServerNotifyUnregister(Command &cmd) {
CMD_REQ_PARM("event");
CMD_RESET_IDLE;
if(!cmd[0].has("specifier")){
logMessage("[Query] Client " + this->getLoggingPeerIp() + ":" + to_string(this->getPeerPort()) + " uses the lagacy notify system, which is deprecated!");
logMessage(this->getServerId(), "{} Client {}:{} uses the lagacy notify system, which is deprecated!", CLIENT_STR_LOG_PREFIX, this->getLoggingPeerIp(), this->getPeerPort());
string event = cmd["event"];
std::transform(event.begin(), event.end(), event.begin(), ::tolower);
#include "XMacroEventTypes.h"
+2 -2
View File
@@ -42,7 +42,7 @@ VoiceClient::~VoiceClient() {
this->connection = nullptr;
if(this->flushing_thread)
logCritical(0, "Deleting a VoiceClient which should still be hold within the flush thread!");
logCritical(this->getServerId(), "Deleting a VoiceClient which should still be hold within the flush thread!");
memtrack::freed<VoiceClient>(this);
}
@@ -50,7 +50,7 @@ VoiceClient::~VoiceClient() {
void VoiceClient::sendCommand0(const ts::Command &command, bool low, bool direct, std::unique_ptr<threads::Future<bool>> listener) {
auto cmd = command.build();
if(cmd.empty()) {
logCritical("Attempted to send an empty command!");
logCritical(this->getServerId(), "{} Attempted to send an empty command!", CLIENT_STR_LOG_PREFIX);
return;
}
@@ -29,13 +29,11 @@ CommandResult VoiceClient::handleCommand(ts::Command &command) {
return SpeakingClient::handleCommand(command);
}
inline int getSecurityLevel(ecc_key* pubKey, size_t offset) {
inline bool calculate_security_level(int& result, ecc_key* pubKey, size_t offset) {
size_t pubLength = 256;
char pubBuffer[256];
if(ecc_export(reinterpret_cast<unsigned char *>(pubBuffer), &pubLength, PK_PUBLIC, pubKey) != CRYPT_OK){
logError(lstream << "failed to export pub key" << endl);
return -1;
}
if((result = ecc_export(reinterpret_cast<unsigned char *>(pubBuffer), &pubLength, PK_PUBLIC, pubKey)) != CRYPT_OK)
return false;
std::string hashStr = base64_encode(pubBuffer, pubLength) + to_string(offset);
char shaBuffer[SHA_DIGEST_LENGTH];
@@ -53,7 +51,8 @@ inline int getSecurityLevel(ecc_key* pubKey, size_t offset) {
else break;
}
}
return zeroBits;
result = zeroBits;
return true;
}
CommandResult VoiceClient::handleCommandClientInit(Command &cmd) {
@@ -61,7 +60,11 @@ CommandResult VoiceClient::handleCommandClientInit(Command &cmd) {
this->connection->acknowledge_handler.reset();
if(this->getType() == ClientType::CLIENT_TEAMSPEAK) {
auto securityLevel = getSecurityLevel(this->crypto.remote_key.get(), cmd["client_key_offset"]);
int securityLevel;
if(!calculate_security_level(securityLevel, this->crypto.remote_key.get(), cmd["client_key_offset"])) {
logError(this->getServerId(), "[{}] Failed to calculate security level. Error code: {}", CLIENT_STR_LOG_PREFIX, securityLevel);
return {ErrorType::VSError};
}
if(securityLevel < 8)
return {findError("channel_invalid_security_hash"), "cant calculate security level"};