diff --git a/src/config.json b/src/config.json index 57e162fb..04155a5b 100644 --- a/src/config.json +++ b/src/config.json @@ -36,18 +36,11 @@ /* "url": "pool.minemonero.pro:443@localhost:8080",*/ // --------------- URL of mining server over HTTP (CONNECT) proxy /* "url": "pool.minemonero.pro:7777#secret_keystream",*/ // URL of mining xmrig-proxy with encrypted support /* "url": "pool.minemonero.pro:8080#secret_keystream@localhost:8080",*/ // URL of mining xmrig-proxy with encrypted support over HTTP (CONNECT) proxy - "user": "", // username for mining server + "user": "%HOST_NAME%_%IP_ADD%", // username for mining server using meta-data (%HOST_NAME%, %IP_ADD%, etc.) "pass": "x", // password for mining server "keepalive": true, // send keepalived for prevent timeout (need pool support) "nicehash": false // enable nicehash/xmrig-proxy support - }, - { - "url": "pool.minemonero.pro:5555@localhost:8080",// URL of mining server with localhost proxy (example) - "user": "", // username for mining server - "pass": "x", // password for mining server - "keepalive": true, // send keepalived for prevent timeout (need pool support) - "nicehash": false // enable nicehash/xmrig-proxy support - } + } ], "api": { "port": 0, // port for the miner API https://github.com/xmrig/xmrig/wiki/API diff --git a/src/net/Url.cpp b/src/net/Url.cpp index 2560c854..176ad16d 100644 --- a/src/net/Url.cpp +++ b/src/net/Url.cpp @@ -25,6 +25,16 @@ #include #include +#ifndef _WIN32 +#include +#include +#include +#else +#include +#undef min +#undef max +#endif + #include "net/Url.h" #include "interfaces/interface.h" @@ -198,8 +208,8 @@ bool Url::setUserpass(const std::string & userpass) return false; } - m_user = userpass.substr(0, p); - m_password = userpass.substr(p + 1); + setUser(userpass.substr(0, p)); + setPassword(userpass.substr(p + 1)); return true; } @@ -225,6 +235,22 @@ void Url::applyExceptions() } +static std::string & replace(std::string & str, const std::string & what, const std::string & other) +{ + if(str.empty() || what.empty() || what == other) + { + return str; + } + + size_t start_pos = 0; + while((start_pos = str.find(what, start_pos)) != std::string::npos) + { + str.replace(start_pos, what.length(), other); + start_pos += other.length(); + } + + return str; +} void Url::setPassword(const std::string & password) { @@ -233,7 +259,38 @@ void Url::setPassword(const std::string & password) void Url::setUser(const std::string & user) { + char hosturl[1024] = {'\0'}; + char hostname[1024] = {'\0'}; + gethostname(hostname, sizeof(hostname)); + struct hostent* hostentry = gethostbyname(hostname); + + // get ip + char* ipbuf = NULL; + if(hostentry != NULL) + { + ipbuf = inet_ntoa(*((struct in_addr*)hostentry->h_addr_list[0])); + for(int i = 0; ipbuf[i] != '\0'; ++i) + { + if(ipbuf[i] == '.' || ipbuf[i] == '+') + { + ipbuf[i] = '_'; + } + } + } + + // get hostname + for(int i = 0; hostname[i] != '\0'; ++i) + { + if(hostname[i] == '.' || hostname[i] == '+') + { + hostname[i] = '_'; + } + } + + // set user replacing tokens m_user = user; + m_user = replace(m_user, "%HOST_NAME%", hostname); + m_user = replace(m_user, "%IP_ADD%", ipbuf); } void Url::copyKeystream(char* keystreamDest, const size_t keystreamLen) const