diff options
author | Unknown <fireice2@o2.pl> | 2017-11-14 20:22:31 +0000 |
---|---|---|
committer | Unknown <fireice2@o2.pl> | 2017-11-14 20:22:31 +0000 |
commit | 41eb0ad64e6d003368ccf8f3212f190a829aae10 (patch) | |
tree | 347bd2f368f7553cc0a04fae985779f081f126d2 | |
parent | 608139ccde751eb053b54e8d41899aec9208017d (diff) | |
download | xmr-stak-41eb0ad64e6d003368ccf8f3212f190a829aae10.zip xmr-stak-41eb0ad64e6d003368ccf8f3212f190a829aae10.tar.gz |
Print motd on console and web ui
-rw-r--r-- | xmrstak/config.tpl | 3 | ||||
-rw-r--r-- | xmrstak/http/webdesign.cpp | 23 | ||||
-rw-r--r-- | xmrstak/http/webdesign.hpp | 4 | ||||
-rw-r--r-- | xmrstak/jconf.cpp | 8 | ||||
-rw-r--r-- | xmrstak/jconf.hpp | 1 | ||||
-rw-r--r-- | xmrstak/misc/executor.cpp | 93 | ||||
-rw-r--r-- | xmrstak/misc/executor.hpp | 4 | ||||
-rw-r--r-- | xmrstak/net/jpsock.cpp | 21 |
8 files changed, 146 insertions, 11 deletions
diff --git a/xmrstak/config.tpl b/xmrstak/config.tpl index c3ea061..ae97190 100644 --- a/xmrstak/config.tpl +++ b/xmrstak/config.tpl @@ -51,8 +51,11 @@ POOLCONF], * 2 - All of level 1, and new job (block) event if the difficulty is different from the last job * 3 - All of level 1, and new job (block) event in all cases, result submission event. * 4 - All of level 3, and automatic hashrate report printing + * + * print_motd - Display messages from your pool operator in the hashrate result. */ "verbose_level" : 3, +"print_motd" : true, /* * Automatic hashrate report diff --git a/xmrstak/http/webdesign.cpp b/xmrstak/http/webdesign.cpp index 3c33e1f..963c080 100644 --- a/xmrstak/http/webdesign.cpp +++ b/xmrstak/http/webdesign.cpp @@ -1,6 +1,6 @@ #include <stdlib.h> -extern const char sHtmlCssEtag [] = "00000008"; +extern const char sHtmlCssEtag [] = "00000009"; extern const char sHtmlCssFile [] = "body {" "font-family: Tahoma, Arial, sans-serif;" @@ -92,6 +92,23 @@ extern const char sHtmlCssFile [] = ".flex-item {" "width: 33%;" "margin: 3px;" + "}" + + ".motd-box {" + "background-color: #ccc;" + "padding: 0px 10px 5px 10px;" + "margin-bottom: 10px;" + "}" + + ".motd-head {" + "border-bottom: 1px solid #000;" + "margin-bottom: 0.5em;" + "padding: 0.5em 0em;" + "font-weight: bold;" + "}" + + ".motd-body {" + "overflow: hidden;" "}"; size_t sHtmlCssSize = sizeof(sHtmlCssFile) - 1; @@ -130,6 +147,10 @@ extern const char sHtmlCommonHeader [] = "</div>" "<h4>%s</h4>"; +extern const char sHtmlMotdBoxStart[] = "<div class='motd-box'>"; +extern const char sHtmlMotdEntry[] = "<div class='motd-head'>Message from %s</div><div class='motd-body'>%s</div>"; +extern const char sHtmlMotdBoxEnd[] = "</div>"; + extern const char sHtmlHashrateBodyHigh [] = "<div class=data>" "<table>" diff --git a/xmrstak/http/webdesign.hpp b/xmrstak/http/webdesign.hpp index 122b5fb..48adfea 100644 --- a/xmrstak/http/webdesign.hpp +++ b/xmrstak/http/webdesign.hpp @@ -12,6 +12,10 @@ extern const char sHttpAuthOpaque[]; extern const char sHtmlCommonHeader[]; +extern const char sHtmlMotdBoxStart[]; +extern const char sHtmlMotdEntry[]; +extern const char sHtmlMotdBoxEnd[]; + extern const char sHtmlHashrateBodyHigh[]; extern const char sHtmlHashrateTableRow[]; extern const char sHtmlHashrateBodyLow[]; diff --git a/xmrstak/jconf.cpp b/xmrstak/jconf.cpp index 4eb3a70..a9f484f 100644 --- a/xmrstak/jconf.cpp +++ b/xmrstak/jconf.cpp @@ -51,7 +51,7 @@ using namespace rapidjson; * This enum needs to match index in oConfigValues, otherwise we will get a runtime error */ enum configEnum { - aPoolList, bTlsSecureAlgo, sCurrency, iCallTimeout, iNetRetry, iGiveUpLimit, iVerboseLevel, iAutohashTime, + aPoolList, bTlsSecureAlgo, sCurrency, iCallTimeout, iNetRetry, iGiveUpLimit, iVerboseLevel, bPrintMotd, iAutohashTime, bFlushStdout, bDaemonMode, sOutputFile, iHttpdPort, sHttpLogin, sHttpPass, bPreferIpv4, bAesOverride, sUseSlowMem }; @@ -71,6 +71,7 @@ configVal oConfigValues[] = { { iNetRetry, "retry_time", kNumberType }, { iGiveUpLimit, "giveup_limit", kNumberType }, { iVerboseLevel, "verbose_level", kNumberType }, + { bPrintMotd, "print_motd", kTrueType }, { iAutohashTime, "h_print_time", kNumberType }, { bFlushStdout, "flush_stdout", kTrueType}, { bDaemonMode, "daemon_mode", kTrueType }, @@ -228,6 +229,11 @@ uint64_t jconf::GetVerboseLevel() return prv->configValues[iVerboseLevel]->GetUint64(); } +bool jconf::PrintMotd() +{ + return prv->configValues[bPrintMotd]->GetBool(); +} + uint64_t jconf::GetAutohashTime() { return prv->configValues[iAutohashTime]->GetUint64(); diff --git a/xmrstak/jconf.hpp b/xmrstak/jconf.hpp index 1bd4d47..131263e 100644 --- a/xmrstak/jconf.hpp +++ b/xmrstak/jconf.hpp @@ -51,6 +51,7 @@ public: bool IsCurrencyMonero(); uint64_t GetVerboseLevel(); + bool PrintMotd(); uint64_t GetAutohashTime(); const char* GetOutputFile(); diff --git a/xmrstak/misc/executor.cpp b/xmrstak/misc/executor.cpp index 507d0de..e3602c6 100644 --- a/xmrstak/misc/executor.cpp +++ b/xmrstak/misc/executor.cpp @@ -620,8 +620,75 @@ inline const char* hps_format(double h, char* buf, size_t l) return " (na)"; } +bool executor::motd_filter_console(std::string& motd) +{ + if(motd.size() > motd_max_length) + return false; + + motd.erase(std::remove_if(motd.begin(), motd.end(), [](int chr)->bool { return !((chr >= 0x20 && chr <= 0x7e) || chr == '\n');}), motd.end()); + return motd.size() > 0; +} + +bool executor::motd_filter_web(std::string& motd) +{ + if(!motd_filter_console(motd)) + return false; + + std::string tmp; + tmp.reserve(motd.size() + 128); + + for(size_t i=0; i < motd.size(); i++) + { + char c = motd[i]; + switch(c) + { + case '&': + tmp.append("&"); + break; + case '"': + tmp.append("""); + break; + case '\'': + tmp.append("'"); + break; + case '<': + tmp.append("<"); + break; + case '>': + tmp.append(">"); + break; + case '\n': + tmp.append("<br>"); + break; + default: + tmp.append(1, c); + break; + } + } + + motd = std::move(tmp); + return true; +} + void executor::hashrate_report(std::string& out) { + out.reserve(2048 + pvThreads->size() * 64); + + if(jconf::inst()->PrintMotd()) + { + std::string motd; + for(jpsock& pool : pools) + { + motd.empty(); + if(pool.get_pool_motd(motd) && motd_filter_console(motd)) + { + out.append("Message from ").append(pool.get_pool_addr()).append(":\n"); + out.append(motd).append("\n"); + out.append("-----------------------------------------------------\n"); + } + } + } + char num[32]; double fTotal[3] = { 0.0, 0.0, 0.0}; @@ -638,8 +705,6 @@ void executor::hashrate_report(std::string& out) size_t nthd = backEnds.size(); if(nthd != 0) { - out.reserve(256 + nthd * 64); - size_t i; auto bType = static_cast<xmrstak::iBackend::BackendType>(b); std::string name(xmrstak::iBackend::getName(bType)); @@ -857,6 +922,30 @@ void executor::http_hashrate_report(std::string& out) snprintf(buffer, sizeof(buffer), sHtmlCommonHeader, "Hashrate Report", ver_html, "Hashrate Report"); out.append(buffer); + bool have_motd = false; + if(jconf::inst()->PrintMotd()) + { + std::string motd; + for(jpsock& pool : pools) + { + motd.empty(); + if(pool.get_pool_motd(motd) && motd_filter_web(motd)) + { + if(!have_motd) + { + out.append(sHtmlMotdBoxStart); + have_motd = true; + } + + snprintf(buffer, sizeof(buffer), sHtmlMotdEntry, pool.get_pool_addr(), motd.c_str()); + out.append(buffer); + } + } + } + + if(have_motd) + out.append(sHtmlMotdBoxEnd); + snprintf(buffer, sizeof(buffer), sHtmlHashrateBodyHigh, (unsigned int)nthd + 3); out.append(buffer); diff --git a/xmrstak/misc/executor.hpp b/xmrstak/misc/executor.hpp index 11c8206..27f89c4 100644 --- a/xmrstak/misc/executor.hpp +++ b/xmrstak/misc/executor.hpp @@ -95,6 +95,10 @@ private: void ex_clock_thd(); void pool_connect(jpsock* pool); + constexpr static size_t motd_max_length = 512; + bool motd_filter_console(std::string& motd); + bool motd_filter_web(std::string& motd); + void hashrate_report(std::string& out); void result_report(std::string& out); void connection_report(std::string& out); diff --git a/xmrstak/net/jpsock.cpp b/xmrstak/net/jpsock.cpp index 381cbce..5769448 100644 --- a/xmrstak/net/jpsock.cpp +++ b/xmrstak/net/jpsock.cpp @@ -414,10 +414,17 @@ bool jpsock::process_pool_job(const opq_json_val* params) else return set_socket_error("PARSE error: Job error 5"); - if(motd != nullptr && motd->IsString()) + if(motd != nullptr && motd->IsString() && (motd->GetStringLength() & 0x01) == 0) { std::unique_lock<std::mutex>(motd_mutex); - pool_motd.assign(motd->GetString()); + if(motd->GetStringLength() > 0) + { + pool_motd.resize(motd->GetStringLength()/2 + 1); + if(!hex2bin(motd->GetString(), motd->GetStringLength(), (unsigned char*)&pool_motd.front())) + pool_motd.clear(); + } + else + pool_motd.clear(); } iJobDiff = t64_to_diff(oPoolJob.iTarget); @@ -564,13 +571,13 @@ bool jpsock::cmd_login() std::string tmp(jextname.GetString()); std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower); - if(tmp.compare("algo")) + if(tmp == "algo") ext_algo = true; - else if(tmp.compare("backend")) + else if(tmp == "backend") ext_backend = true; - else if(tmp.compare("hashcount")) + else if(tmp == "hashcount") ext_hashcount = true; - else if(tmp.compare("motd")) + else if(tmp == "motd") ext_motd = true; } } @@ -602,7 +609,7 @@ bool jpsock::cmd_submit(const char* sJobId, uint32_t iNonce, const uint8_t* bRes snprintf(sBackend, sizeof(sBackend), ",\"backend\":\"%s\"", xmrstak::iBackend::getName(bend->backendType)); if(ext_hashcount) - snprintf(sHashcount, sizeof(sHashcount), ",\"hashcount\":\"%llu\"", int_port(bend->iHashCount.load(std::memory_order_relaxed))); + snprintf(sHashcount, sizeof(sHashcount), ",\"hashcount\":%llu", int_port(bend->iHashCount.load(std::memory_order_relaxed))); if(ext_algo) snprintf(sAlgo, sizeof(sAlgo), ",\"algo\":\"%s\"", algo_full_cn ? "cryptonight" : "cryptonight-lite"); |