This commit is contained in:
BenDr0id 2018-07-23 17:36:23 +02:00
parent 49680c282e
commit 527b557f9e
7 changed files with 58 additions and 42 deletions

View file

@ -40,6 +40,8 @@
uv_mutex_t Service::m_mutex;
std::map<std::string, ControlCommand> Service::m_clientCommand;
std::map<std::string, ClientStatus> Service::m_clientStatus;
std::map<std::string, std::list<std::string>> Service::m_remoteLog;
int Service::m_currentServerTime = 0;
bool Service::start()
@ -55,6 +57,7 @@ void Service::release()
m_clientCommand.clear();
m_clientStatus.clear();
m_remoteLog.clear();
uv_mutex_unlock(&m_mutex);
}
@ -77,6 +80,8 @@ unsigned Service::handleGET(const Options* options, const std::string& url, cons
resultCode = getClientConfig(options, clientId, resp);
} else if (url.rfind("/admin/getClientCommand", 0) == 0) {
resultCode = getClientCommand(clientId, resp);
} else if (url.rfind("/admin/getClientLog", 0) == 0) {
//resultCode = getClientCommand(clientId, resp);
}
}
else {
@ -228,10 +233,6 @@ unsigned Service::setClientStatus(const std::string& clientIp, const std::string
clientStatus.parseFromJson(document);
clientStatus.setExternalIp(clientIp);
if (m_clientStatus.find(clientId) == m_clientStatus.end()) {
m_clientCommand[clientId] = ControlCommand(ControlCommand::RESTART);
}
m_clientStatus[clientId] = clientStatus;
resultCode = getClientCommand(clientId, resp);
@ -293,6 +294,29 @@ unsigned Service::resetClientStatusList(const std::string& data, std::string& re
return MHD_HTTP_OK;
}
unsigned Service::getClientLog(const std::string& clientId, std::string& resp)
{
if (m_remoteLog.find(clientId) != m_remoteLog.end()) {
rapidjson::Document respDocument;
respDocument.SetObject();
auto& allocator = respDocument.GetAllocator();
rapidjson::Value controlCommand = m_clientCommand[clientId].toJson(allocator);
respDocument.AddMember("client_log", controlCommand, allocator);
rapidjson::StringBuffer buffer(0, 4096);
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.SetMaxDecimalPlaces(10);
respDocument.Accept(writer);
resp = buffer.GetString();
}
return MHD_HTTP_OK;
}
unsigned Service::getAdminPage(const Options* options, std::string& resp)
{
std::stringstream data;

View file

@ -48,6 +48,7 @@ public:
private:
static unsigned getClientConfig(const Options* options, const std::string& clientId, std::string& resp);
static unsigned getClientCommand(const std::string& clientId, std::string& resp);
static unsigned getClientLog(const std::string& clientId, std::string& resp);
static unsigned getClientStatusList(std::string& resp);
static unsigned getAdminPage(const Options* options, std::string& resp);
@ -63,6 +64,7 @@ private:
static std::map<std::string, ClientStatus> m_clientStatus;
static std::map<std::string, ControlCommand> m_clientCommand;
static std::map<std::string, std::list<std::string>> m_remoteLog;
static uv_mutex_t m_mutex;