|
49 | 49 | #include <openssl/err.h>
|
50 | 50 | #endif
|
51 | 51 |
|
52 |
| - |
53 | 52 | #ifdef _WIN32
|
54 | 53 | # define strcasecmp _stricmp
|
55 | 54 | #endif // _WIN32
|
@@ -90,6 +89,170 @@ void help()
|
90 | 89 | cout<<"Brought to by fireice_uk and psychocrypt under GPLv3."<<endl;
|
91 | 90 | }
|
92 | 91 |
|
| 92 | +bool read_yes_no(const char* str) |
| 93 | +{ |
| 94 | + std::string tmp; |
| 95 | + do |
| 96 | + { |
| 97 | + std::cout << str << std::endl; |
| 98 | + std::cin >> tmp; |
| 99 | + std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower); |
| 100 | + } |
| 101 | + while(tmp != "y" && tmp != "n" && tmp != "yes" && tmp != "no"); |
| 102 | + |
| 103 | + return tmp == "y" || tmp == "yes"; |
| 104 | +} |
| 105 | + |
| 106 | +inline const char* bool_to_str(bool v) |
| 107 | +{ |
| 108 | + return v ? "true" : "false"; |
| 109 | +} |
| 110 | + |
| 111 | +std::string get_multipool_entry(bool& final) |
| 112 | +{ |
| 113 | + std::cout<<std::endl<<"- Next Pool:"<<std::endl<<std::endl; |
| 114 | + |
| 115 | + std::string pool; |
| 116 | + if(xmrstak::params::inst().currency == "monero") |
| 117 | + std::cout<<"- Pool address: e.g. pool.usxmrpool.com:3333"<<std::endl; |
| 118 | + else |
| 119 | + std::cout<<"- Pool address: e.g. mine.aeon-pool.com:5555"<<std::endl; |
| 120 | + std::cin >> pool; |
| 121 | + |
| 122 | + std::string userName; |
| 123 | + std::cout<<"- Username (wallet address or pool login):"<<std::endl; |
| 124 | + std::cin >> userName; |
| 125 | + |
| 126 | + std::string passwd; |
| 127 | + std::cin.clear(); std::cin.ignore(INT_MAX,'\n'); |
| 128 | + std::cout<<"- Password (mostly empty or x):"<<std::endl; |
| 129 | + getline(std::cin, passwd); |
| 130 | + |
| 131 | + bool tls = read_yes_no("- Does this pool port support TLS/SSL? Use no if unknown. (y/N)"); |
| 132 | + bool nicehash = read_yes_no("- Do you want to use nicehash on this pool? (y/n)"); |
| 133 | + |
| 134 | + int64_t pool_weight; |
| 135 | + std::cout << "- Please enter a weight for this pool: "<<std::endl; |
| 136 | + while(!(std::cin >> pool_weight) || pool_weight <= 0) |
| 137 | + { |
| 138 | + std::cin.clear(); |
| 139 | + std::cin.ignore(INT_MAX, '\n'); |
| 140 | + std::cout << "Invalid weight. Try 1, 10, 100, etc:" << std::endl; |
| 141 | + } |
| 142 | + |
| 143 | + final = !read_yes_no("- Do you want to add another pool? (y/n)"); |
| 144 | + |
| 145 | + return "\t{\"pool_address\" : \"" + pool +"\", \"wallet_address\" : \"" + userName + "\", \"pool_password\" : \"" + |
| 146 | + passwd + "\", \"use_nicehash\" : " + bool_to_str(nicehash) + ", \"use_tls\" : " + bool_to_str(tls) + |
| 147 | + ", \"tls_fingerprint\" : \"\", \"pool_weight\" : " + std::to_string(pool_weight) + " },\n"; |
| 148 | +} |
| 149 | + |
| 150 | +void do_guided_config(bool userSetPasswd) |
| 151 | +{ |
| 152 | + using namespace xmrstak; |
| 153 | + |
| 154 | + // load the template of the backend config into a char variable |
| 155 | + const char *tpl = |
| 156 | + #include "../config.tpl" |
| 157 | + ; |
| 158 | + |
| 159 | + configEditor configTpl{}; |
| 160 | + configTpl.set(std::string(tpl)); |
| 161 | + std::cout<<"Please enter:"<<std::endl; |
| 162 | + auto& currency = params::inst().currency; |
| 163 | + if(currency.empty()) |
| 164 | + { |
| 165 | + std::string tmp; |
| 166 | +#if defined(CONF_NO_AEON) |
| 167 | + tmp = "monero"; |
| 168 | +#elif defined(CONF_NO_MONERO) |
| 169 | + tmp = "aeon"; |
| 170 | +#endif |
| 171 | + while(tmp != "monero" && tmp != "aeon") |
| 172 | + { |
| 173 | + std::cout<<"- Currency: 'monero' or 'aeon'"<<std::endl; |
| 174 | + std::cin >> tmp; |
| 175 | + std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower); |
| 176 | + } |
| 177 | + currency = tmp; |
| 178 | + } |
| 179 | + |
| 180 | + auto& pool = params::inst().poolURL; |
| 181 | + bool userSetPool = true; |
| 182 | + if(pool.empty()) |
| 183 | + { |
| 184 | + userSetPool = false; |
| 185 | + if(currency == "monero") |
| 186 | + std::cout<<"- Pool address: e.g. pool.usxmrpool.com:3333"<<std::endl; |
| 187 | + else |
| 188 | + std::cout<<"- Pool address: e.g. mine.aeon-pool.com:5555"<<std::endl; |
| 189 | + std::cin >> pool; |
| 190 | + } |
| 191 | + |
| 192 | + auto& userName = params::inst().poolUsername; |
| 193 | + if(userName.empty()) |
| 194 | + { |
| 195 | + std::cout<<"- Username (wallet address or pool login):"<<std::endl; |
| 196 | + std::cin >> userName; |
| 197 | + } |
| 198 | + |
| 199 | + auto& passwd = params::inst().poolPasswd; |
| 200 | + if(passwd.empty() && (!userSetPasswd)) |
| 201 | + { |
| 202 | + // clear everything from stdin to allow an empty password |
| 203 | + std::cin.clear(); std::cin.ignore(INT_MAX,'\n'); |
| 204 | + std::cout<<"- Password (mostly empty or x):"<<std::endl; |
| 205 | + getline(std::cin, passwd); |
| 206 | + } |
| 207 | + |
| 208 | + bool tls = read_yes_no("- Does this pool port support TLS/SSL? Use no if unknown. (y/N)"); |
| 209 | + bool nicehash = read_yes_no("- Do you want to use nicehash on this pool? (y/n)"); |
| 210 | + |
| 211 | + bool multipool; |
| 212 | + if(!userSetPool) |
| 213 | + multipool = read_yes_no("- Do you want to use multiple pools? (y/n)"); |
| 214 | + else |
| 215 | + multipool = false; |
| 216 | + |
| 217 | + int64_t pool_weight; |
| 218 | + if(multipool) |
| 219 | + { |
| 220 | + std::cout << "Pool weight is a number telling the miner how important the pool is." << std::endl; |
| 221 | + std::cout << "Miner will mine mostly at the pool with the highest weight, unless the pool fails." << std::endl; |
| 222 | + std::cout << "Weight must be an integer larger than 0." << std::endl; |
| 223 | + std::cout << "- Please enter a weight for this pool: "<<std::endl; |
| 224 | + |
| 225 | + while(!(std::cin >> pool_weight) || pool_weight <= 0) |
| 226 | + { |
| 227 | + std::cin.clear(); |
| 228 | + std::cin.ignore(INT_MAX, '\n'); |
| 229 | + std::cout << "Invalid weight. Try 1, 10, 100, etc:" << std::endl; |
| 230 | + } |
| 231 | + } |
| 232 | + else |
| 233 | + pool_weight = 1; |
| 234 | + |
| 235 | + std::string pool_table; |
| 236 | + pool_table += "\t{\"pool_address\" : \"" + pool +"\", \"wallet_address\" : \"" + userName + "\", \"pool_password\" : \"" + |
| 237 | + passwd + "\", \"use_nicehash\" : " + bool_to_str(nicehash) + ", \"use_tls\" : " + bool_to_str(tls) + |
| 238 | + ", \"tls_fingerprint\" : \"\", \"pool_weight\" : " + std::to_string(pool_weight) + " },\n"; |
| 239 | + |
| 240 | + if(multipool) |
| 241 | + { |
| 242 | + bool final; |
| 243 | + do |
| 244 | + { |
| 245 | + pool_table += get_multipool_entry(final); |
| 246 | + } |
| 247 | + while(!final); |
| 248 | + } |
| 249 | + |
| 250 | + configTpl.replace("POOLCONF", pool_table); |
| 251 | + configTpl.replace("CURRENCY", currency); |
| 252 | + configTpl.write(params::inst().configFile); |
| 253 | + std::cout<<"Configuration stored in file '"<<params::inst().configFile<<"'"<<std::endl; |
| 254 | +} |
| 255 | + |
93 | 256 | int main(int argc, char *argv[])
|
94 | 257 | {
|
95 | 258 | #ifndef CONF_NO_TLS
|
@@ -244,60 +407,7 @@ int main(int argc, char *argv[])
|
244 | 407 |
|
245 | 408 | // check if we need a guided start
|
246 | 409 | if(!configEditor::file_exist(params::inst().configFile))
|
247 |
| - { |
248 |
| - // load the template of the backend config into a char variable |
249 |
| - const char *tpl = |
250 |
| - #include "../config.tpl" |
251 |
| - ; |
252 |
| - configEditor configTpl{}; |
253 |
| - configTpl.set(std::string(tpl)); |
254 |
| - std::cout<<"Please enter:"<<std::endl; |
255 |
| - auto& currency = params::inst().currency; |
256 |
| - if(currency.empty()) |
257 |
| - { |
258 |
| - std::string tmp; |
259 |
| -#if defined(CONF_NO_AEON) |
260 |
| - tmp = "monero"; |
261 |
| -#elif defined(CONF_NO_MONERO) |
262 |
| - tmp = "aeon"; |
263 |
| -#endif |
264 |
| - while(!xmrstak::strcmp_i(tmp, "monero") && !xmrstak::strcmp_i(tmp, "aeon")) |
265 |
| - { |
266 |
| - std::cout<<"- currency: 'monero' or 'aeon'"<<std::endl; |
267 |
| - std::cin >> tmp; |
268 |
| - } |
269 |
| - currency = tmp; |
270 |
| - } |
271 |
| - auto& pool = params::inst().poolURL; |
272 |
| - if(pool.empty()) |
273 |
| - { |
274 |
| - if(xmrstak::strcmp_i(currency, "monero")) |
275 |
| - std::cout<<"- pool address: e.g. pool.usxmrpool.com:3333"<<std::endl; |
276 |
| - else |
277 |
| - std::cout<<"- pool address: e.g. mine.aeon-pool.com:5555"<<std::endl; |
278 |
| - std::cin >> pool; |
279 |
| - } |
280 |
| - auto& userName = params::inst().poolUsername; |
281 |
| - if(userName.empty()) |
282 |
| - { |
283 |
| - std::cout<<"- user name (wallet address or pool login):"<<std::endl; |
284 |
| - std::cin >> userName; |
285 |
| - } |
286 |
| - auto& passwd = params::inst().poolPasswd; |
287 |
| - if(passwd.empty() && (!userSetPasswd)) |
288 |
| - { |
289 |
| - // clear everything from stdin to allow an empty password |
290 |
| - std::cin.clear(); std::cin.ignore(INT_MAX,'\n'); |
291 |
| - std::cout<<"- password (mostly empty or x):"<<std::endl; |
292 |
| - getline(std::cin, passwd); |
293 |
| - } |
294 |
| - configTpl.replace("POOLURL", pool); |
295 |
| - configTpl.replace("POOLUSER", userName); |
296 |
| - configTpl.replace("POOLPASSWD", passwd); |
297 |
| - configTpl.replace("CURRENCY", currency); |
298 |
| - configTpl.write(params::inst().configFile); |
299 |
| - std::cout<<"Configuration stored in file '"<<params::inst().configFile<<"'"<<std::endl; |
300 |
| - } |
| 410 | + do_guided_config(userSetPasswd); |
301 | 411 |
|
302 | 412 | if(!jconf::inst()->parse_config(params::inst().configFile.c_str()))
|
303 | 413 | {
|
|
0 commit comments