Config templates (#222)
* Implemented template editor and template assignment
This commit is contained in:
parent
2140e56e3a
commit
80bc45f322
6 changed files with 1487 additions and 45 deletions
|
@ -180,6 +180,7 @@ static struct option const options[] = {
|
|||
{ "api-port", 1, nullptr, 4000 },
|
||||
{ "api-access-token", 1, nullptr, 4001 },
|
||||
{ "api-worker-id", 1, nullptr, 4002 },
|
||||
{ "reboot-cmd", 1, nullptr, 4021 },
|
||||
{ "cc-url", 1, nullptr, 4003 },
|
||||
{ "cc-access-token", 1, nullptr, 4004 },
|
||||
{ "cc-worker-id", 1, nullptr, 4005 },
|
||||
|
@ -236,6 +237,7 @@ static struct option const config_options[] = {
|
|||
{ "doublehash-thread-mask", 1, nullptr, 4013 },
|
||||
{ "multihash-thread-mask", 1, nullptr, 4013 },
|
||||
{ "asm-optimization", 1, nullptr, 4020 },
|
||||
{ "reboot-cmd", 1, nullptr, 4021 },
|
||||
{ nullptr, 0, nullptr, 0 }
|
||||
};
|
||||
|
||||
|
@ -641,7 +643,7 @@ bool Options::parseArg(int key, const char *arg)
|
|||
case 4020: /* --asm-optimization */
|
||||
return parseAsmOptimization(arg);
|
||||
|
||||
case 4021: /* --cc-reboot-cmd */
|
||||
case 4021: /* --cc-reboot-cmd || --reboot-cmd */
|
||||
free(m_ccRebootCmd);
|
||||
m_ccRebootCmd = strdup(arg);
|
||||
break;
|
||||
|
|
|
@ -28,6 +28,11 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include "win_dirent.h"
|
||||
#endif
|
||||
|
||||
#include "log/Log.h"
|
||||
#include <3rdparty/cpp-httplib/httplib.h>
|
||||
#include <3rdparty/rapidjson/document.h>
|
||||
|
@ -102,6 +107,8 @@ unsigned Service::handleGET(const Options* options, const std::string& url, cons
|
|||
resultCode = getAdminPage(options, resp);
|
||||
} else if (url.rfind("/admin/getClientStatusList", 0) == 0) {
|
||||
resultCode = getClientStatusList(resp);
|
||||
} else if (url.rfind("/admin/getClientConfigTemplates", 0) == 0) {
|
||||
resultCode = getClientConfigTemplates(options, resp);
|
||||
} else {
|
||||
if (!clientId.empty()) {
|
||||
if (url.rfind("/client/getConfig", 0) == 0 || url.rfind("/admin/getClientConfig", 0) == 0) {
|
||||
|
@ -269,7 +276,7 @@ unsigned Service::getClientStatusList(std::string& resp)
|
|||
|
||||
unsigned Service::setClientStatus(const Options* options, const std::string& clientIp, const std::string& clientId, const std::string& data, std::string& resp)
|
||||
{
|
||||
int resultCode = MHD_HTTP_BAD_REQUEST;
|
||||
unsigned resultCode = MHD_HTTP_BAD_REQUEST;
|
||||
|
||||
rapidjson::Document document;
|
||||
if (!document.Parse(data.c_str()).HasParseError()) {
|
||||
|
@ -347,6 +354,65 @@ unsigned Service::getClientLog(const std::string& clientId, std::string& resp)
|
|||
return MHD_HTTP_OK;
|
||||
}
|
||||
|
||||
unsigned Service::getClientConfigTemplates(const Options* options, std::string& resp)
|
||||
{
|
||||
std::string configFolder(".");
|
||||
|
||||
if (options->ccClientConfigFolder() != nullptr) {
|
||||
configFolder = options->ccClientConfigFolder();
|
||||
# ifdef WIN32
|
||||
configFolder += '\\';
|
||||
# else
|
||||
configFolder += '/';
|
||||
# endif
|
||||
}
|
||||
|
||||
std::vector<std::string> templateFiles;
|
||||
|
||||
DIR* dirp = opendir(configFolder.c_str());
|
||||
if (dirp) {
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dirp)) != NULL) {
|
||||
if (entry->d_type == DT_REG) {
|
||||
std::string filename = entry->d_name;
|
||||
std::string starting = "template_";
|
||||
std::string ending = "_config.json";
|
||||
|
||||
if (filename.rfind(starting, 0) == 0 && filename.find(ending, (filename.length() - ending.length())) != std::string::npos) {
|
||||
filename.erase(0, starting.length());
|
||||
filename.erase(filename.length()-ending.length());
|
||||
|
||||
templateFiles.push_back(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
}
|
||||
|
||||
rapidjson::Document respDocument;
|
||||
respDocument.SetObject();
|
||||
|
||||
auto& allocator = respDocument.GetAllocator();
|
||||
|
||||
rapidjson::Value templateList(rapidjson::kArrayType);
|
||||
for (auto& templateFile : templateFiles) {
|
||||
rapidjson::Value templateEntry(templateFile.c_str(), allocator);
|
||||
templateList.PushBack(templateEntry, allocator);
|
||||
}
|
||||
|
||||
respDocument.AddMember("templates", templateList, 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;
|
||||
|
|
|
@ -54,6 +54,7 @@ private:
|
|||
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 getClientConfigTemplates(const Options* options, std::string& resp);
|
||||
static unsigned getAdminPage(const Options* options, std::string& resp);
|
||||
|
||||
static unsigned setClientStatus(const Options* options, const std::string& clientIp, const std::string& clientId, const std::string& data, std::string& resp);
|
||||
|
|
|
@ -36,14 +36,14 @@
|
|||
#define APP_DESC "XMRigCC CPU miner"
|
||||
#define APP_COPYRIGHT "Copyright (C) 2017- BenDr0id"
|
||||
#endif
|
||||
#define APP_VERSION "1.8.6 (based on XMRig)"
|
||||
#define APP_VERSION "1.8.7 (based on XMRig)"
|
||||
#define APP_DOMAIN ""
|
||||
#define APP_SITE "https://github.com/Bendr0id/xmrigCC"
|
||||
#define APP_KIND "cpu"
|
||||
|
||||
#define APP_VER_MAJOR 1
|
||||
#define APP_VER_MINOR 8
|
||||
#define APP_VER_BUILD 6
|
||||
#define APP_VER_BUILD 7
|
||||
#define APP_VER_REV 0
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
|
1224
src/win_dirent.h
Normal file
1224
src/win_dirent.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue