mirror of
https://github.com/PurpleI2P/i2pd-tools
synced 2025-01-15 17:20:08 +00:00
[AutoConf] Fix multiply input, regex pre-init
This commit is contained in:
parent
73c3b9ef8c
commit
7e4d2c73cd
85
autoconf.cpp
85
autoconf.cpp
@ -6,9 +6,18 @@
|
|||||||
#include<string>
|
#include<string>
|
||||||
#include<fstream>
|
#include<fstream>
|
||||||
#include<limits>
|
#include<limits>
|
||||||
|
#include<regex>
|
||||||
|
|
||||||
#define CIN_CLEAR std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
#define CIN_CLEAR std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||||
|
|
||||||
namespace AutoConf {
|
namespace AutoConf {
|
||||||
|
namespace Regexps {
|
||||||
|
//const std::regex port("\\d{1,5}");
|
||||||
|
std::regex path(R"([a-zA-Z0-9_\.\/\\]+)"); // (\w|\.|\\|\/)+
|
||||||
|
std::regex proxy("\\w+:\\/\\/(\\w|\\d|\\.|\\-)+\\:\\d+");
|
||||||
|
std::regex any(".*");
|
||||||
|
|
||||||
|
}
|
||||||
namespace PreInitConfigs {
|
namespace PreInitConfigs {
|
||||||
constexpr const char * yggOnlyConf = "ipv4=false\r\n"
|
constexpr const char * yggOnlyConf = "ipv4=false\r\n"
|
||||||
"ipv6=false\r\n"
|
"ipv6=false\r\n"
|
||||||
@ -41,22 +50,22 @@ const std::map<std::string, AsksT> Texts = // maybe vector better
|
|||||||
{"loglevel","Введите уровень лога(warn,info,none,critical,error,debug)"},
|
{"loglevel","Введите уровень лога(warn,info,none,critical,error,debug)"},
|
||||||
{"logCFLYN", "Использовать полный CFL-форму даты в логах? ПО умолчанию только время"},
|
{"logCFLYN", "Использовать полный CFL-форму даты в логах? ПО умолчанию только время"},
|
||||||
{"daemonYN", "Использовать режим демона?"},
|
{"daemonYN", "Использовать режим демона?"},
|
||||||
{"FamilyUsing", "Введите название фамилии или enter просто"},
|
{"FamilyUsing", "Введите название фамилии или -"},
|
||||||
//TODO: an another
|
//TODO: an another
|
||||||
{"UseIPv6", "Использовать ipv6?"},
|
{"UseIPv6", "Использовать ipv6?"},
|
||||||
{"UseIPv4", "Использовать ipv4?"},
|
{"UseIPv4", "Использовать ipv4?"},
|
||||||
{"BeFloodfillYN", "Быть флудфиллом?"},
|
{"BeFloodfillYN", "Быть флудфиллом?"},
|
||||||
{"NoTransitYN", "Отключить транзит? (это уменьшит анонимность)"},
|
{"NoTransitYN", "Отключить транзит? (это уменьшит анонимность)"},
|
||||||
{"Bandwidth", "Напиши пропускную способность (Enter для по умолчанию) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"},
|
{"Bandwidth", "Напиши пропускную способность (- для по умолчанию) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"},
|
||||||
{"Share", "Процент шары (Enter для по умолчанию) [0-100]"},
|
{"Share", "Процент шары (- для по умолчанию) [0-100]"},
|
||||||
//
|
//
|
||||||
{"NTCPEnabledYN", "Использовать NTCP?"},
|
{"NTCPEnabledYN", "Использовать NTCP?"},
|
||||||
{"NTCPPublishedYN", "Опубликовать IP В NTCP?"},
|
{"NTCPPublishedYN", "Опубликовать IP В NTCP?"},
|
||||||
{"NTCPPPort", "NTCP Порт. Либо энтер для пропуска"},
|
{"NTCPPPort", "NTCP Порт. Либо - для пропуска"},
|
||||||
{"NTCPPProxy", "NTCP Proxy, пример (socks://localhost:4545) или энтер для поумолчанию (неиспользуется)"},
|
{"NTCPPProxy", "NTCP Proxy, пример (socks://localhost:4545) или - для по умолчанию (неиспользуется)"},
|
||||||
{"SSUEnabledYN", "Использовать SSU?"},
|
{"SSUEnabledYN", "Использовать SSU?"},
|
||||||
{"SSUPPort", "SSU Порт. Либо энтер для пропуска"},
|
{"SSUPPort", "SSU Порт. Либо - для пропуска"},
|
||||||
{"SSUProxy", "SSU Proxy, пример (socks://localhost:4545) или энтер для поумолчанию (неиспользуется)"}
|
{"SSUProxy", "SSU Proxy, пример (socks://localhost:4545) или - для по умолчанию (неиспользуется)"}
|
||||||
|
|
||||||
}},
|
}},
|
||||||
{"en", {
|
{"en", {
|
||||||
@ -77,22 +86,22 @@ const std::map<std::string, AsksT> Texts = // maybe vector better
|
|||||||
{"loglevel", "Enter log level (warn, info, none, critical, error, debug)"},
|
{"loglevel", "Enter log level (warn, info, none, critical, error, debug)"},
|
||||||
{"logCFLYN", "Use full CFL format for date in logs? Default is only time."},
|
{"logCFLYN", "Use full CFL format for date in logs? Default is only time."},
|
||||||
{"daemonYN", "Use daemon mode?"},
|
{"daemonYN", "Use daemon mode?"},
|
||||||
{"FamilyUsing", "Enter your netfamily or just hit enter."},
|
{"FamilyUsing", "Enter your netfamily or just hit -."},
|
||||||
//TODO: an another
|
//TODO: an another
|
||||||
{"UseIPv6", "Use ipv6?"},
|
{"UseIPv6", "Use ipv6?"},
|
||||||
{"UseIPv4", "Use ipv4?"},
|
{"UseIPv4", "Use ipv4?"},
|
||||||
{"BeFloodfillYN", "Be a floodfill?"},
|
{"BeFloodfillYN", "Be a floodfill?"},
|
||||||
{"NoTransitYN", "Disable transit? (this will reduce anonymity)"},
|
{"NoTransitYN", "Disable transit? (this will reduce anonymity)"},
|
||||||
{"Bandwidth", "Write bandwidth (enter for default) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"},
|
{"Bandwidth", "Write bandwidth (- for default) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"},
|
||||||
{"Share", "Share percents (enter for default) [0-100]"},
|
{"Share", "Share percents (- for default) [0-100]"},
|
||||||
//
|
//
|
||||||
{"NTCPEnabledYN", "Use NTCP?"},
|
{"NTCPEnabledYN", "Use NTCP?"},
|
||||||
{"NTCPPublishedYN", "Publish IP in NTCP?"},
|
{"NTCPPublishedYN", "Publish IP in NTCP?"},
|
||||||
{"NTCPPPort", "NTCP Port or enter for auto port (random)"},
|
{"NTCPPPort", "NTCP Port or - for auto port (random)"},
|
||||||
{"NTCPPProxy", "NTCP Proxy, example (socks://localhost:4545) or enter for default"},
|
{"NTCPPProxy", "NTCP Proxy, example (socks://localhost:4545) or - for default"},
|
||||||
{"SSUEnabledYN", "Use SSU?"},
|
{"SSUEnabledYN", "Use SSU?"},
|
||||||
{"SSUPPort", "SSU Port or enter for auto port (random)"},
|
{"SSUPPort", "SSU Port or - for auto port (random)"},
|
||||||
{"SSUProxy", "SSU Proxy, example (socks://localhost:4545) or enter for default"}
|
{"SSUProxy", "SSU Proxy, example (socks://localhost:4545) or - for default"}
|
||||||
|
|
||||||
}}
|
}}
|
||||||
};
|
};
|
||||||
@ -101,8 +110,9 @@ const std::map<std::string, AsksT> Texts = // maybe vector better
|
|||||||
bool AskYN(void) noexcept {
|
bool AskYN(void) noexcept {
|
||||||
char answ;
|
char answ;
|
||||||
std::cout << " ? (y/n) ";
|
std::cout << " ? (y/n) ";
|
||||||
CIN_CLEAR;
|
|
||||||
std::cin >> answ;
|
std::cin >> answ;
|
||||||
|
CIN_CLEAR;
|
||||||
|
std::cout <<"answ: " << answ<<std::endl;;
|
||||||
switch(answ) {
|
switch(answ) {
|
||||||
case 'y':
|
case 'y':
|
||||||
case 'Y':
|
case 'Y':
|
||||||
@ -118,6 +128,7 @@ std::string GetLanguage(void) noexcept {
|
|||||||
std::string lang;
|
std::string lang;
|
||||||
std::cout << "Language/Язык:\r\nru - русский\r\nen - английский\r\n";
|
std::cout << "Language/Язык:\r\nru - русский\r\nen - английский\r\n";
|
||||||
std::cin >> lang;
|
std::cin >> lang;
|
||||||
|
CIN_CLEAR;
|
||||||
if (Texts.find(lang) != Texts.end()) {
|
if (Texts.find(lang) != Texts.end()) {
|
||||||
return lang;
|
return lang;
|
||||||
} else {
|
} else {
|
||||||
@ -130,6 +141,7 @@ bool IsOnlyYggdrasil(const std::string & lang) noexcept {
|
|||||||
unsigned short answ;
|
unsigned short answ;
|
||||||
std::cout << AutoConf::Texts.at(lang).at("WelcomeText") << std::endl;
|
std::cout << AutoConf::Texts.at(lang).at("WelcomeText") << std::endl;
|
||||||
std::cin >> answ;
|
std::cin >> answ;
|
||||||
|
CIN_CLEAR;
|
||||||
switch(answ) {
|
switch(answ) {
|
||||||
case 1:
|
case 1:
|
||||||
return false;
|
return false;
|
||||||
@ -144,6 +156,7 @@ bool IsOnlyYggdrasil(const std::string & lang) noexcept {
|
|||||||
|
|
||||||
int
|
int
|
||||||
main(void) {
|
main(void) {
|
||||||
|
std::cout << "RUn Program" << std::endl;
|
||||||
std::cout << "https://i2pd.readthedocs.io/en/latest/user-guide/configuration/\r\nhttps://github.com/PurpleI2P/i2pd/blob/openssl/contrib/i2pd.conf\r\n";
|
std::cout << "https://i2pd.readthedocs.io/en/latest/user-guide/configuration/\r\nhttps://github.com/PurpleI2P/i2pd/blob/openssl/contrib/i2pd.conf\r\n";
|
||||||
std::ostringstream conf;
|
std::ostringstream conf;
|
||||||
auto lang = AutoConf::GetLanguage();
|
auto lang = AutoConf::GetLanguage();
|
||||||
@ -157,28 +170,32 @@ main(void) {
|
|||||||
// Asks
|
// Asks
|
||||||
using namespace AutoConf;
|
using namespace AutoConf;
|
||||||
[](std::ostringstream &conf, const std::string &lang) {
|
[](std::ostringstream &conf, const std::string &lang) {
|
||||||
#define ASKYN_MACRO(A,B,C) { \
|
#define ASKYN_MACRO(A,B,C, REGEX) { \
|
||||||
std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \
|
std::cout << "Cycle" << std::endl;\
|
||||||
|
std::cout << AutoConf::Texts.at(lang).at(A); \
|
||||||
if(AskYN()) { \
|
if(AskYN()) { \
|
||||||
|
while(1) {\
|
||||||
|
std::cout << "Cycle1" << std::endl;\
|
||||||
std::cout << AutoConf::Texts.at(lang).at(B) << "\r\n"; \
|
std::cout << AutoConf::Texts.at(lang).at(B) << "\r\n"; \
|
||||||
std::string inp; \
|
std::string inp; \
|
||||||
|
std::cin >> inp;\
|
||||||
CIN_CLEAR; \
|
CIN_CLEAR; \
|
||||||
std::getline(std::cin, inp); \
|
std::smatch bmatch;\
|
||||||
conf << C "=" << inp << "\r\n"; \
|
std::regex_match(inp, bmatch, REGEX);\
|
||||||
} \
|
if (bmatch.length() > 0) {\
|
||||||
|
conf << C "=" << inp << "\r\n"; \
|
||||||
|
break;\
|
||||||
|
}else {std::cerr<<"No correct input"<<std::endl;}\
|
||||||
|
} \
|
||||||
|
}\
|
||||||
};
|
};
|
||||||
ASKYN_MACRO("TunConfYN","TunConf","tunconf");
|
std::cout << "ASKYN" << std::endl;
|
||||||
ASKYN_MACRO("TunnelsDirYN","TunnelsDir","tunnelsdir");
|
ASKYN_MACRO("TunConfYN","TunConf","tunconf", AutoConf::Regexps::path);
|
||||||
// TODO:
|
ASKYN_MACRO("TunnelsDirYN","TunnelsDir","tunnelsdir",AutoConf::Regexps::path);
|
||||||
/*
|
ASKYN_MACRO("certsdirYN","certsdir","certsdir",AutoConf::Regexps::path);
|
||||||
{"daemonYN", "Use daemon mode?"},
|
ASKYN_MACRO("pidfileYN","pidfile","pidfile",AutoConf::Regexps::path);
|
||||||
{"FamilyUsing", "Enter your last name or just hit enter."},
|
ASKYN_MACRO("logYN","log","log",AutoConf::Regexps::any);
|
||||||
|
ASKYN_MACRO("loglevelYN","loglevel","loglevel",AutoConf::Regexps::any); // TODO: word type
|
||||||
*/
|
|
||||||
ASKYN_MACRO("certsdirYN","certsdir","certsdir");
|
|
||||||
ASKYN_MACRO("pidfileYN","pidfile","pidfile");
|
|
||||||
ASKYN_MACRO("logYN","log","log");
|
|
||||||
ASKYN_MACRO("loglevelYN","loglevel","loglevel");
|
|
||||||
#define ASK_BOOL(A,B) { \
|
#define ASK_BOOL(A,B) { \
|
||||||
std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \
|
std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \
|
||||||
bool v = AskYN();\
|
bool v = AskYN();\
|
||||||
@ -188,9 +205,10 @@ main(void) {
|
|||||||
ASK_BOOL("UseIPv4", "ipv4");
|
ASK_BOOL("UseIPv4", "ipv4");
|
||||||
ASK_BOOL("logCFLYN", "logclftime");
|
ASK_BOOL("logCFLYN", "logclftime");
|
||||||
ASK_BOOL("daemonYN", "daemon");
|
ASK_BOOL("daemonYN", "daemon");
|
||||||
|
// TODO: - to constexpr or just const and use this const in text formating
|
||||||
#define ASK_TEXT(A, B) {\
|
#define ASK_TEXT(A, B) {\
|
||||||
std::cout << AutoConf::Texts.at(lang).at(A) << std::endl;\
|
std::cout << AutoConf::Texts.at(lang).at(A) << std::endl;\
|
||||||
std::string inp; CIN_CLEAR; std::getline(std::cin, inp); if (inp.length() > 0) {\
|
std::string inp; std::cin >> inp;CIN_CLEAR; if (inp != "-") {\
|
||||||
conf << B "=" << inp << "\r\n";\
|
conf << B "=" << inp << "\r\n";\
|
||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
@ -209,7 +227,6 @@ main(void) {
|
|||||||
ASK_BOOL("SSUEnabledYN", "enabled");
|
ASK_BOOL("SSUEnabledYN", "enabled");
|
||||||
ASK_TEXT("SSUPPort", "port");
|
ASK_TEXT("SSUPPort", "port");
|
||||||
ASK_TEXT("SSUProxy", "proxy");
|
ASK_TEXT("SSUProxy", "proxy");
|
||||||
|
|
||||||
#undef ASK_TEXT
|
#undef ASK_TEXT
|
||||||
#undef ASK_BOOL
|
#undef ASK_BOOL
|
||||||
#undef ASKYN_MACRO
|
#undef ASKYN_MACRO
|
||||||
|
Loading…
x
Reference in New Issue
Block a user