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 /xmrstak/misc | |
parent | 608139ccde751eb053b54e8d41899aec9208017d (diff) | |
download | xmr-stak-41eb0ad64e6d003368ccf8f3212f190a829aae10.zip xmr-stak-41eb0ad64e6d003368ccf8f3212f190a829aae10.tar.gz |
Print motd on console and web ui
Diffstat (limited to 'xmrstak/misc')
-rw-r--r-- | xmrstak/misc/executor.cpp | 93 | ||||
-rw-r--r-- | xmrstak/misc/executor.hpp | 4 |
2 files changed, 95 insertions, 2 deletions
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); |