User with meta-data

The user can define with meta-data tokens.
This commit is contained in:
enWILLYado 2018-02-26 22:37:12 +01:00
parent 27700182ff
commit cd77d02a81
2 changed files with 61 additions and 11 deletions

View file

@ -36,14 +36,7 @@
/* "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
"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
"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

View file

@ -25,6 +25,16 @@
#include <stdlib.h>
#include <algorithm>
#ifndef _WIN32
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#else
#include <winsock2.h>
#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