Added API endpoint "GET /1/config".

This commit is contained in:
XMRig 2018-03-31 19:00:31 +07:00
parent 341557c34e
commit 8d4d1a3285
3 changed files with 74 additions and 49 deletions

View file

@ -89,6 +89,17 @@ void ApiRouter::ApiRouter::get(const xmrig::HttpRequest &req, xmrig::HttpReply &
rapidjson::Document doc;
doc.SetObject();
if (req.match("/1/config")) {
if (req.isRestricted()) {
reply.status = 403;
return;
}
m_controller->config()->getJSON(doc);
return finalize(reply, doc);
}
getIdentify(doc);
getMiner(doc);
getHashrate(doc);

View file

@ -23,18 +23,23 @@
#include <string.h>
#include <uv.h>
#include <inttypes.h>
#include "core/Config.h"
#include "core/ConfigCreator.h"
#include "core/ConfigLoader.h"
#include "Cpu.h"
#include "net/Url.h"
#include "rapidjson/document.h"
#include "rapidjson/filewritestream.h"
#include "rapidjson/prettywriter.h"
#include "xmrig.h"
static char affinity_tmp[20] = { 0 };
xmrig::Config::Config() : xmrig::CommonConfig(),
m_doubleHash(false),
m_dryRun(false),
@ -66,69 +71,78 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
{
doc.SetObject();
// auto &allocator = doc.GetAllocator();
auto &allocator = doc.GetAllocator();
// doc.AddMember("access-log-file", accessLog() ? rapidjson::Value(rapidjson::StringRef(accessLog())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
// doc.AddMember("algo", rapidjson::StringRef(algoName()), allocator);
doc.AddMember("algo", rapidjson::StringRef(algoName()), allocator);
// rapidjson::Value api(rapidjson::kObjectType);
// api.AddMember("port", apiPort(), allocator);
// api.AddMember("access-token", apiToken() ? rapidjson::Value(rapidjson::StringRef(apiToken())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
// api.AddMember("worker-id", apiWorkerId() ? rapidjson::Value(rapidjson::StringRef(apiWorkerId())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
// api.AddMember("ipv6", isApiIPv6(), allocator);
// api.AddMember("restricted", isApiRestricted(), allocator);
// doc.AddMember("api", api, allocator);
rapidjson::Value api(rapidjson::kObjectType);
api.AddMember("port", apiPort(), allocator);
api.AddMember("access-token", apiToken() ? rapidjson::Value(rapidjson::StringRef(apiToken())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
api.AddMember("worker-id", apiWorkerId() ? rapidjson::Value(rapidjson::StringRef(apiWorkerId())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
api.AddMember("ipv6", isApiIPv6(), allocator);
api.AddMember("restricted", isApiRestricted(), allocator);
doc.AddMember("api", api, allocator);
// doc.AddMember("background", isBackground(), allocator);
doc.AddMember("av", algoVariant(), allocator);
doc.AddMember("background", isBackground(), allocator);
// rapidjson::Value bind(rapidjson::kArrayType);
// for (const Addr *addr : m_addrs) {
// bind.PushBack(rapidjson::StringRef(addr->addr()), allocator);
// }
doc.AddMember("colors", isColors(), allocator);
// doc.AddMember("bind", bind, allocator);
// doc.AddMember("colors", isColors(), allocator);
// doc.AddMember("custom-diff", diff(), allocator);
// doc.AddMember("donate-level", donateLevel(), allocator);
// doc.AddMember("log-file", logFile() ? rapidjson::Value(rapidjson::StringRef(logFile())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
// doc.AddMember("mode", rapidjson::StringRef(modeName()), allocator);
if (affinity() != -1L) {
snprintf(affinity_tmp, sizeof(affinity_tmp) - 1, "0x%" PRIX64, affinity());
doc.AddMember("cpu-affinity", rapidjson::StringRef(affinity_tmp), allocator);
}
else {
doc.AddMember("cpu-affinity", rapidjson::kNullType, allocator);
}
// rapidjson::Value pools(rapidjson::kArrayType);
if (priority() != -1) {
doc.AddMember("cpu-priority", priority(), allocator);
}
else {
doc.AddMember("cpu-priority", rapidjson::kNullType, allocator);
}
// for (const Url *url : m_pools) {
// rapidjson::Value obj(rapidjson::kObjectType);
doc.AddMember("donate-level", donateLevel(), allocator);
doc.AddMember("huge-pages", isHugePages(), allocator);
doc.AddMember("log-file", logFile() ? rapidjson::Value(rapidjson::StringRef(logFile())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
doc.AddMember("max-cpu-usage", m_maxCpuUsage, allocator);
// obj.AddMember("url", rapidjson::StringRef(url->url()), allocator);
// obj.AddMember("user", rapidjson::StringRef(url->user()), allocator);
// obj.AddMember("pass", rapidjson::StringRef(url->password()), allocator);
// obj.AddMember("coin", rapidjson::StringRef(url->coin()), allocator);
rapidjson::Value pools(rapidjson::kArrayType);
// if (url->keepAlive() == 0 || url->keepAlive() == Url::kKeepAliveTimeout) {
// obj.AddMember("keepalive", url->keepAlive() > 0, allocator);
// }
// else {
// obj.AddMember("keepalive", url->keepAlive(), allocator);
// }
for (const Url *url : m_pools) {
rapidjson::Value obj(rapidjson::kObjectType);
// obj.AddMember("variant", url->variant(), allocator);
obj.AddMember("url", rapidjson::StringRef(url->url()), allocator);
obj.AddMember("user", rapidjson::StringRef(url->user()), allocator);
obj.AddMember("pass", rapidjson::StringRef(url->password()), allocator);
// pools.PushBack(obj, allocator);
// }
if (url->keepAlive() == 0 || url->keepAlive() == Url::kKeepAliveTimeout) {
obj.AddMember("keepalive", url->keepAlive() > 0, allocator);
}
else {
obj.AddMember("keepalive", url->keepAlive(), allocator);
}
// doc.AddMember("pools", pools, allocator);
obj.AddMember("nicehash", url->isNicehash(), allocator);
obj.AddMember("variant", url->variant(), allocator);
// doc.AddMember("retries", retries(), allocator);
// doc.AddMember("retry-pause", retryPause(), allocator);
// doc.AddMember("reuse-timeout", reuseTimeout(), allocator);
// doc.AddMember("user-agent", userAgent() ? rapidjson::Value(rapidjson::StringRef(userAgent())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
pools.PushBack(obj, allocator);
}
//# ifdef HAVE_SYSLOG_H
// doc.AddMember("syslog", syslog(), allocator);
//# endif
doc.AddMember("pools", pools, allocator);
doc.AddMember("print-time", printTime(), allocator);
doc.AddMember("retries", retries(), allocator);
doc.AddMember("retry-pause", retryPause(), allocator);
doc.AddMember("safe", m_safe, allocator);
doc.AddMember("threads", threads(), allocator);
doc.AddMember("user-agent", userAgent() ? rapidjson::Value(rapidjson::StringRef(userAgent())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
// doc.AddMember("verbose", isVerbose(), allocator);
// doc.AddMember("watch", m_watch, allocator);
// doc.AddMember("workers", isWorkers(), allocator);
# ifdef HAVE_SYSLOG_H
doc.AddMember("syslog", syslog(), allocator);
# endif
doc.AddMember("watch", m_watch, allocator);
}

View file

@ -138,7 +138,7 @@ static struct option const config_options[] = {
{ "retry-pause", 1, nullptr, xmrig::IConfig::RetryPauseKey },
{ "safe", 0, nullptr, xmrig::IConfig::SafeKey },
{ "syslog", 0, nullptr, xmrig::IConfig::SyslogKey },
{ "threads", 1, nullptr, xmrig::IConfig::SafeKey },
{ "threads", 1, nullptr, xmrig::IConfig::ThreadsKey },
{ "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey },
{ 0, 0, 0, 0 }
};