From 35a2e59dc7f3c6a79700d2a881009b4ee33a39d6 Mon Sep 17 00:00:00 2001 From: WipedLifePotato Date: Thu, 19 Sep 2024 16:21:36 +0700 Subject: [PATCH 1/6] AutoConf program pre-init --- Makefile | 8 ++- autoconf.cpp | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 autoconf.cpp diff --git a/Makefile b/Makefile index 818ea36..6af1fe0 100755 --- a/Makefile +++ b/Makefile @@ -45,9 +45,13 @@ else endif -all: $(I2PD_LIB) vain keygen keyinfo famtool routerinfo regaddr regaddr_3ld i2pbase64 offlinekeys b33address regaddralias x25519 verifyhost +all: $(I2PD_LIB) vain keygen keyinfo famtool routerinfo regaddr regaddr_3ld i2pbase64 offlinekeys b33address regaddralias x25519 verifyhost autoconf vain: vain.o $(I2PD_LIB) $(CXX) -o vain $(LDFLAGS) vain.o $(LDLIBS) + +autoconf: autoconf.o $(I2PD_LIB) + $(CXX) -o autoconf $(DEFINES) $(LDFLAGS) autoconf.o $(LDLIBS) + routerinfo: routerinfo.o $(I2PD_LIB) $(CXX) -o routerinfo $(LDFLAGS) routerinfo.o $(LDLIBS) -latomic @@ -103,7 +107,7 @@ clean-obj: rm -f $(wildcard *.o) clean-bin: - rm -f b33address famtool i2pbase64 keygen keyinfo offlinekeys regaddr regaddr_3ld regaddralias routerinfo x25519 verifyhost vain + rm -f b33address famtool i2pbase64 keygen keyinfo offlinekeys regaddr regaddr_3ld regaddralias routerinfo x25519 verifyhost vain autoconf clean: clean-i2pd clean-obj clean-bin diff --git a/autoconf.cpp b/autoconf.cpp new file mode 100644 index 0000000..d435b3f --- /dev/null +++ b/autoconf.cpp @@ -0,0 +1,171 @@ +#ifndef AUTOCONFC +#define AUTOCONFC +#include +#include +#include +#include +#include +namespace AutoConf { +namespace PreInitConfigs { + constexpr const char * yggOnlyConf = "ipv4=false\r\n" + "ipv6=false\r\n" + "ssu=false\r\n" + "ntcp2.enabled=false\r\n" + "ssu2.enabled=false\r\n" + "meshnets.yggdrasil=true\r\n"; +} +// Texts +using AsksT = std::map; +const std::map Texts = // maybe vector better + { + {"ru", { + {"WelcomeText","Привет. Выбери тип конфига\r\n1 - клирнет\r\n2 - только yggdrasil"}, + // Without section + {"TunConfYN", "Использовать другой путь для туннелей?"}, + {"TunConf", "Введите путь для туннелей"}, + {"TunnelsDirYN", "Использовать другой путь для папки туннелей?"}, + {"TunnelsDir","Введите путь для папки с туннелями"}, + {"certsdirYN", "Использовать другой путь для папки с сертификатами?"}, + {"certsdir", "Введите путь для папки с сертификатами"}, + {"pidfileYN","использовать другой путь для PID файла?"}, + {"pidfile", "Введите путь для pidfile"}, + {"logYN","Нужно ли изменить путь лога?"}, + {"log", "Введите тип лога(file,stdout,syslog)"}, + {"logfileYN","Нужно ли изменить путь logfile?"}, + {"logfile", "Введите путь logfile"}, + {"loglevelYN","Нужно ли изменить стандартный уровень логирования?"}, + {"loglevel","Введите уровень лога(warn,info,none,critical,error,debug)"}, + {"logCFLYN", "Использовать полный CFL-форму даты в логах? ПО умолчанию только время"}, + {"daemonYN", "Использовать режим демона?"}, + {"FamilyUsing", "Введите название фамилии или enter просто"}, + //TODO: an another + {"UseIPv6", "Использовать ipv6?"}, + {"UseIPv4", "Использовать ipv4?"}, + {"BeFloodfill", "Быть флудфиллом?"}, + {"NoTransit", "Отключить транзит? (это уменьшит анонимность)"} + }}, + {"en", { + {"WelcomeText","Hello. Select type of config\r\n1 - clearnet\r\n2 - only yggdrasil"}, + {"TunConfYN", "Use a different path for tunnels?"}, + {"TunConf", "Enter path for tunnels"}, + {"TunnelsDirYN", "Use a different path for the tunnels folder?"}, + {"TunnelsDir", "Enter path for the tunnels folder"}, + {"certsdirYN", "Use a different path for the certificates folder?"}, + {"certsdir", "Enter path for the certificates folder"}, + {"pidfileYN", "Use a different path for the PID file?"}, + {"pidfile", "Enter path for pidfile"}, + {"logYN", "Do you need to change the log path?"}, + {"log", "Enter log type (file, stdout, syslog)"}, + {"logfileYN", "Do you need to change the logfile path?"}, + {"logfile", "Enter path for logfile"}, + {"loglevelYN", "Do you need to change the default log level?"}, + {"loglevel", "Enter log level (warn, info, none, critical, error, debug)"}, + {"logCFLYN", "Use full CFL format for date in logs? Default is only time."}, + {"daemonYN", "Use daemon mode?"}, + {"FamilyUsing", "Enter your last name or just hit enter."}, + //TODO: an another + {"UseIPv6", "Use ipv6?"}, + {"UseIPv4", "Use ipv4?"}, + {"BeFloodfill", "Be a floodfill?"}, + {"NoTransit", "Disable transit? (this will reduce anonymity)"} + }} + }; + +// Functions +bool AskYN(void) noexcept { + char answ; + std::cout << " ? (y/n) "; + std::cin >> answ; + switch(answ) { + case 'y': + case 'Y': + return true; + case 'n': + case 'N': + return false; + default: + return AskYN(); // stack overflow, would use while(true) + } +} +std::string GetLanguage(void) noexcept { + std::string lang; + std::cout << "Language/Язык:\r\nru - русский\r\nen - английский\r\n"; + std::cin >> lang; + if (Texts.find(lang) != Texts.end()) { + return lang; + } else { + std::cerr << "Not correct language, try again" << std::endl; + return GetLanguage(); // stack overflow + } +} + +bool IsOnlyYggdrasil(const std::string & lang) noexcept { + unsigned short answ; + std::cout << AutoConf::Texts.at(lang).at("WelcomeText") << std::endl; + std::cin >> answ; + switch(answ) { + case 1: + return false; + case 2: + return true; + default: + return IsOnlyYggdrasil(lang); + } +} + +} + +int +main(void) { + 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; + auto lang = AutoConf::GetLanguage(); + auto isOnlyYgg = AutoConf::IsOnlyYggdrasil(lang); + if (isOnlyYgg) { + #ifndef _WIN32 + conf << "daemon=true\r\n"; + #endif + conf << AutoConf::PreInitConfigs::yggOnlyConf; + } else { + // Asks + using namespace AutoConf; + [](std::ostringstream &conf, const std::string &lang) { + std::cout << AutoConf::Texts.at(lang).at("TunConfYN") << std::endl; + if (AskYN()) { + std::cout << AutoConf::Texts.at(lang).at("TunConf") << "\r\n"; + std::string tunConf; + std::cin.ignore(); + std::getline(std::cin, tunConf); + conf << "tunnels.path=" << tunConf << "\r\n"; + } + + std::cout << AutoConf::Texts.at(lang).at("TunnelsDirYN") << std::endl; + if (AskYN()) { + std::cout << AutoConf::Texts.at(lang).at("TunnelsDir") << "\r\n"; + std::string tunnelsDir; + std::cin.ignore(); + std::getline(std::cin, tunnelsDir); + conf << "tunnels.dir=" << tunnelsDir << "\r\n"; + } + + // TODO: + { + std::cout << AutoConf::Texts.at(lang).at("UseIPv6") << "\r\n"; + bool useIPv6 = AskYN(); + conf << "ipv6=" << (useIPv6 ? "true" : "false") << "\r\n"; + } + + { + std::cout << AutoConf::Texts.at(lang).at("UseIPv4") << "\r\n"; + bool useIPv4 = AskYN(); + conf << "ipv4=" << (useIPv4 ? "true" : "false") << "\r\n"; + } + }(conf, lang); + } + std::cout << "Config: " << std::endl; + std::cout << conf.str() << std::endl; + std::ofstream confFile("i2pd_.conf"); + confFile << conf.str(); + confFile.close(); +} +#endif From 205f7c61ae37cb31008303983a5fd05b3973964b Mon Sep 17 00:00:00 2001 From: WipedLifePotato Date: Thu, 19 Sep 2024 21:11:33 +0700 Subject: [PATCH 2/6] [AutoConf] FirstSection --- autoconf.cpp | 77 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 29 deletions(-) diff --git a/autoconf.cpp b/autoconf.cpp index d435b3f..4d06205 100644 --- a/autoconf.cpp +++ b/autoconf.cpp @@ -41,7 +41,7 @@ const std::map Texts = // maybe vector better //TODO: an another {"UseIPv6", "Использовать ipv6?"}, {"UseIPv4", "Использовать ipv4?"}, - {"BeFloodfill", "Быть флудфиллом?"}, + {"BeFloodfillYN", "Быть флудфиллом?"}, {"NoTransit", "Отключить транзит? (это уменьшит анонимность)"} }}, {"en", { @@ -66,7 +66,7 @@ const std::map Texts = // maybe vector better //TODO: an another {"UseIPv6", "Use ipv6?"}, {"UseIPv4", "Use ipv4?"}, - {"BeFloodfill", "Be a floodfill?"}, + {"BeFloodfillYN", "Be a floodfill?"}, {"NoTransit", "Disable transit? (this will reduce anonymity)"} }} }; @@ -130,41 +130,60 @@ main(void) { // Asks using namespace AutoConf; [](std::ostringstream &conf, const std::string &lang) { - std::cout << AutoConf::Texts.at(lang).at("TunConfYN") << std::endl; - if (AskYN()) { - std::cout << AutoConf::Texts.at(lang).at("TunConf") << "\r\n"; - std::string tunConf; - std::cin.ignore(); - std::getline(std::cin, tunConf); - conf << "tunnels.path=" << tunConf << "\r\n"; - } - - std::cout << AutoConf::Texts.at(lang).at("TunnelsDirYN") << std::endl; - if (AskYN()) { - std::cout << AutoConf::Texts.at(lang).at("TunnelsDir") << "\r\n"; - std::string tunnelsDir; - std::cin.ignore(); - std::getline(std::cin, tunnelsDir); - conf << "tunnels.dir=" << tunnelsDir << "\r\n"; - } + #define ASKYN_MACRO(A,B,C) { \ + std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \ + if(AskYN()) { \ + std::cout << AutoConf::Texts.at(lang).at(B) << "\r\n"; \ + std::string inp; \ + std::cin.ignore(); \ + std::getline(std::cin, inp); \ + conf << C "=" << inp << "\r\n"; \ + } \ + }; + ASKYN_MACRO("TunConfYN","TunConf","tunconf"); + ASKYN_MACRO("TunnelsDirYN","TunnelsDir","tunnelsdir"); // TODO: - { - std::cout << AutoConf::Texts.at(lang).at("UseIPv6") << "\r\n"; - bool useIPv6 = AskYN(); - conf << "ipv6=" << (useIPv6 ? "true" : "false") << "\r\n"; - } + /* + {"daemonYN", "Use daemon mode?"}, + {"FamilyUsing", "Enter your last name or just hit enter."}, - { - std::cout << AutoConf::Texts.at(lang).at("UseIPv4") << "\r\n"; - bool useIPv4 = AskYN(); - conf << "ipv4=" << (useIPv4 ? "true" : "false") << "\r\n"; + */ + 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) { \ + std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \ + bool v = AskYN();\ + conf << B "=" << (v ? "true":"false") << "\r\n";\ } + ASK_BOOL("UseIPv6", "ipv6"); + ASK_BOOL("UseIPv4", "ipv4"); + ASK_BOOL("logCFLYN", "logclftime"); + ASK_BOOL("daemonYN", "daemon"); + #define ASK_TEXT(A, B) {\ + std::cout << AutoConf::Texts.at(lang).at(A) << std::endl;\ + std::string inp; std::cin.ignore(); std::getline(std::cin, inp);; if (inp.length() != 0) {\ + conf << B "=" << inp << "\r\n";\ + }\ + } + ASK_TEXT("FamilyUsing","family"); + ASK_BOOL("BeFloodfillYN", "floodflill"); + + ///// }(conf, lang); } std::cout << "Config: " << std::endl; std::cout << conf.str() << std::endl; - std::ofstream confFile("i2pd_.conf"); + //TODO: To Constexpr + std::cout << "Save File: (\"i2pd_.conf\"):"; + std::string outFileName; + std::cin.ignore(); //maybe not need write everywhere cin.ignore() one time maybe will be enough + std::getline(std::cin, outFileName); + //TODO: to constxpr + if (outFileName.length() == 0) outFileName = "i2pd_.conf"; + std::ofstream confFile(outFileName); confFile << conf.str(); confFile.close(); } From 73c3b9ef8ce9b5da102083643fa42c60f9d6d137 Mon Sep 17 00:00:00 2001 From: WipedLifePotato Date: Thu, 19 Sep 2024 21:38:16 +0700 Subject: [PATCH 3/6] [AutoConf] SSU2, NTCP2 --- autoconf.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/autoconf.cpp b/autoconf.cpp index 4d06205..45c8d47 100644 --- a/autoconf.cpp +++ b/autoconf.cpp @@ -5,6 +5,9 @@ #include #include #include +#include +#define CIN_CLEAR std::cin.clear(); std::cin.ignore(std::numeric_limits::max(), '\n'); + namespace AutoConf { namespace PreInitConfigs { constexpr const char * yggOnlyConf = "ipv4=false\r\n" @@ -14,6 +17,7 @@ namespace PreInitConfigs { "ssu2.enabled=false\r\n" "meshnets.yggdrasil=true\r\n"; } + // Texts using AsksT = std::map; const std::map Texts = // maybe vector better @@ -42,7 +46,18 @@ const std::map Texts = // maybe vector better {"UseIPv6", "Использовать ipv6?"}, {"UseIPv4", "Использовать ipv4?"}, {"BeFloodfillYN", "Быть флудфиллом?"}, - {"NoTransit", "Отключить транзит? (это уменьшит анонимность)"} + {"NoTransitYN", "Отключить транзит? (это уменьшит анонимность)"}, + {"Bandwidth", "Напиши пропускную способность (Enter для по умолчанию) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, + {"Share", "Процент шары (Enter для по умолчанию) [0-100]"}, + // + {"NTCPEnabledYN", "Использовать NTCP?"}, + {"NTCPPublishedYN", "Опубликовать IP В NTCP?"}, + {"NTCPPPort", "NTCP Порт. Либо энтер для пропуска"}, + {"NTCPPProxy", "NTCP Proxy, пример (socks://localhost:4545) или энтер для поумолчанию (неиспользуется)"}, + {"SSUEnabledYN", "Использовать SSU?"}, + {"SSUPPort", "SSU Порт. Либо энтер для пропуска"}, + {"SSUProxy", "SSU Proxy, пример (socks://localhost:4545) или энтер для поумолчанию (неиспользуется)"} + }}, {"en", { {"WelcomeText","Hello. Select type of config\r\n1 - clearnet\r\n2 - only yggdrasil"}, @@ -62,12 +77,23 @@ const std::map Texts = // maybe vector better {"loglevel", "Enter log level (warn, info, none, critical, error, debug)"}, {"logCFLYN", "Use full CFL format for date in logs? Default is only time."}, {"daemonYN", "Use daemon mode?"}, - {"FamilyUsing", "Enter your last name or just hit enter."}, + {"FamilyUsing", "Enter your netfamily or just hit enter."}, //TODO: an another {"UseIPv6", "Use ipv6?"}, {"UseIPv4", "Use ipv4?"}, {"BeFloodfillYN", "Be a floodfill?"}, - {"NoTransit", "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]"}, + {"Share", "Share percents (enter for default) [0-100]"}, + // + {"NTCPEnabledYN", "Use NTCP?"}, + {"NTCPPublishedYN", "Publish IP in NTCP?"}, + {"NTCPPPort", "NTCP Port or enter for auto port (random)"}, + {"NTCPPProxy", "NTCP Proxy, example (socks://localhost:4545) or enter for default"}, + {"SSUEnabledYN", "Use SSU?"}, + {"SSUPPort", "SSU Port or enter for auto port (random)"}, + {"SSUProxy", "SSU Proxy, example (socks://localhost:4545) or enter for default"} + }} }; @@ -75,6 +101,7 @@ const std::map Texts = // maybe vector better bool AskYN(void) noexcept { char answ; std::cout << " ? (y/n) "; + CIN_CLEAR; std::cin >> answ; switch(answ) { case 'y': @@ -130,13 +157,12 @@ main(void) { // Asks using namespace AutoConf; [](std::ostringstream &conf, const std::string &lang) { - #define ASKYN_MACRO(A,B,C) { \ std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \ if(AskYN()) { \ std::cout << AutoConf::Texts.at(lang).at(B) << "\r\n"; \ std::string inp; \ - std::cin.ignore(); \ + CIN_CLEAR; \ std::getline(std::cin, inp); \ conf << C "=" << inp << "\r\n"; \ } \ @@ -164,14 +190,30 @@ main(void) { ASK_BOOL("daemonYN", "daemon"); #define ASK_TEXT(A, B) {\ std::cout << AutoConf::Texts.at(lang).at(A) << std::endl;\ - std::string inp; std::cin.ignore(); std::getline(std::cin, inp);; if (inp.length() != 0) {\ + std::string inp; CIN_CLEAR; std::getline(std::cin, inp); if (inp.length() > 0) {\ conf << B "=" << inp << "\r\n";\ }\ } ASK_TEXT("FamilyUsing","family"); ASK_BOOL("BeFloodfillYN", "floodflill"); + ASK_BOOL("NoTransitYN", "transit"); + ASK_TEXT("Bandwidth","bandwidth"); + ASK_TEXT("Share","share"); + ///// With sections + conf << "[ntcp2]\r\n"; + ASK_BOOL("NTCPEnabledYN", "enabled"); + ASK_BOOL("NTCPPublishedYN", "publish"); + ASK_TEXT("NTCPPPort", "port"); + ASK_TEXT("NTCPPProxy", "proxy"); + conf << "[ssu2]\r\n"; + ASK_BOOL("SSUEnabledYN", "enabled"); + ASK_TEXT("SSUPPort", "port"); + ASK_TEXT("SSUProxy", "proxy"); + + #undef ASK_TEXT + #undef ASK_BOOL + #undef ASKYN_MACRO - ///// }(conf, lang); } std::cout << "Config: " << std::endl; @@ -179,7 +221,7 @@ main(void) { //TODO: To Constexpr std::cout << "Save File: (\"i2pd_.conf\"):"; std::string outFileName; - std::cin.ignore(); //maybe not need write everywhere cin.ignore() one time maybe will be enough + std::cin.clear(); std::getline(std::cin, outFileName); //TODO: to constxpr if (outFileName.length() == 0) outFileName = "i2pd_.conf"; From 7e4d2c73cd1edf884620541e9b7543ace9589208 Mon Sep 17 00:00:00 2001 From: WipedLifePotato Date: Fri, 20 Sep 2024 12:49:25 +0700 Subject: [PATCH 4/6] [AutoConf] Fix multiply input, regex pre-init --- autoconf.cpp | 85 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/autoconf.cpp b/autoconf.cpp index 45c8d47..1ed6596 100644 --- a/autoconf.cpp +++ b/autoconf.cpp @@ -6,9 +6,18 @@ #include #include #include +#include + #define CIN_CLEAR std::cin.clear(); std::cin.ignore(std::numeric_limits::max(), '\n'); 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 { constexpr const char * yggOnlyConf = "ipv4=false\r\n" "ipv6=false\r\n" @@ -41,22 +50,22 @@ const std::map Texts = // maybe vector better {"loglevel","Введите уровень лога(warn,info,none,critical,error,debug)"}, {"logCFLYN", "Использовать полный CFL-форму даты в логах? ПО умолчанию только время"}, {"daemonYN", "Использовать режим демона?"}, - {"FamilyUsing", "Введите название фамилии или enter просто"}, + {"FamilyUsing", "Введите название фамилии или -"}, //TODO: an another {"UseIPv6", "Использовать ipv6?"}, {"UseIPv4", "Использовать ipv4?"}, {"BeFloodfillYN", "Быть флудфиллом?"}, {"NoTransitYN", "Отключить транзит? (это уменьшит анонимность)"}, - {"Bandwidth", "Напиши пропускную способность (Enter для по умолчанию) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, - {"Share", "Процент шары (Enter для по умолчанию) [0-100]"}, + {"Bandwidth", "Напиши пропускную способность (- для по умолчанию) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, + {"Share", "Процент шары (- для по умолчанию) [0-100]"}, // {"NTCPEnabledYN", "Использовать NTCP?"}, {"NTCPPublishedYN", "Опубликовать IP В NTCP?"}, - {"NTCPPPort", "NTCP Порт. Либо энтер для пропуска"}, - {"NTCPPProxy", "NTCP Proxy, пример (socks://localhost:4545) или энтер для поумолчанию (неиспользуется)"}, + {"NTCPPPort", "NTCP Порт. Либо - для пропуска"}, + {"NTCPPProxy", "NTCP Proxy, пример (socks://localhost:4545) или - для по умолчанию (неиспользуется)"}, {"SSUEnabledYN", "Использовать SSU?"}, - {"SSUPPort", "SSU Порт. Либо энтер для пропуска"}, - {"SSUProxy", "SSU Proxy, пример (socks://localhost:4545) или энтер для поумолчанию (неиспользуется)"} + {"SSUPPort", "SSU Порт. Либо - для пропуска"}, + {"SSUProxy", "SSU Proxy, пример (socks://localhost:4545) или - для по умолчанию (неиспользуется)"} }}, {"en", { @@ -77,22 +86,22 @@ const std::map Texts = // maybe vector better {"loglevel", "Enter log level (warn, info, none, critical, error, debug)"}, {"logCFLYN", "Use full CFL format for date in logs? Default is only time."}, {"daemonYN", "Use daemon mode?"}, - {"FamilyUsing", "Enter your netfamily or just hit enter."}, + {"FamilyUsing", "Enter your netfamily or just hit -."}, //TODO: an another {"UseIPv6", "Use ipv6?"}, {"UseIPv4", "Use ipv4?"}, {"BeFloodfillYN", "Be a floodfill?"}, {"NoTransitYN", "Disable transit? (this will reduce anonymity)"}, - {"Bandwidth", "Write bandwidth (enter for default) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, - {"Share", "Share percents (enter for default) [0-100]"}, + {"Bandwidth", "Write bandwidth (- for default) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, + {"Share", "Share percents (- for default) [0-100]"}, // {"NTCPEnabledYN", "Use NTCP?"}, {"NTCPPublishedYN", "Publish IP in NTCP?"}, - {"NTCPPPort", "NTCP Port or enter for auto port (random)"}, - {"NTCPPProxy", "NTCP Proxy, example (socks://localhost:4545) or enter for default"}, + {"NTCPPPort", "NTCP Port or - for auto port (random)"}, + {"NTCPPProxy", "NTCP Proxy, example (socks://localhost:4545) or - for default"}, {"SSUEnabledYN", "Use SSU?"}, - {"SSUPPort", "SSU Port or enter for auto port (random)"}, - {"SSUProxy", "SSU Proxy, example (socks://localhost:4545) or enter for default"} + {"SSUPPort", "SSU Port or - for auto port (random)"}, + {"SSUProxy", "SSU Proxy, example (socks://localhost:4545) or - for default"} }} }; @@ -101,8 +110,9 @@ const std::map Texts = // maybe vector better bool AskYN(void) noexcept { char answ; std::cout << " ? (y/n) "; - CIN_CLEAR; std::cin >> answ; + CIN_CLEAR; + std::cout <<"answ: " << answ<> lang; + CIN_CLEAR; if (Texts.find(lang) != Texts.end()) { return lang; } else { @@ -130,6 +141,7 @@ bool IsOnlyYggdrasil(const std::string & lang) noexcept { unsigned short answ; std::cout << AutoConf::Texts.at(lang).at("WelcomeText") << std::endl; std::cin >> answ; + CIN_CLEAR; switch(answ) { case 1: return false; @@ -144,6 +156,7 @@ bool IsOnlyYggdrasil(const std::string & lang) noexcept { int 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::ostringstream conf; auto lang = AutoConf::GetLanguage(); @@ -157,28 +170,32 @@ main(void) { // Asks using namespace AutoConf; [](std::ostringstream &conf, const std::string &lang) { - #define ASKYN_MACRO(A,B,C) { \ - std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \ + #define ASKYN_MACRO(A,B,C, REGEX) { \ + std::cout << "Cycle" << std::endl;\ + std::cout << AutoConf::Texts.at(lang).at(A); \ if(AskYN()) { \ + while(1) {\ + std::cout << "Cycle1" << std::endl;\ std::cout << AutoConf::Texts.at(lang).at(B) << "\r\n"; \ std::string inp; \ + std::cin >> inp;\ CIN_CLEAR; \ - std::getline(std::cin, inp); \ - conf << C "=" << inp << "\r\n"; \ - } \ + std::smatch bmatch;\ + std::regex_match(inp, bmatch, REGEX);\ + if (bmatch.length() > 0) {\ + conf << C "=" << inp << "\r\n"; \ + break;\ + }else {std::cerr<<"No correct input"< 0) {\ + std::string inp; std::cin >> inp;CIN_CLEAR; if (inp != "-") {\ conf << B "=" << inp << "\r\n";\ }\ } @@ -209,7 +227,6 @@ main(void) { ASK_BOOL("SSUEnabledYN", "enabled"); ASK_TEXT("SSUPPort", "port"); ASK_TEXT("SSUProxy", "proxy"); - #undef ASK_TEXT #undef ASK_BOOL #undef ASKYN_MACRO From 90905e35159e2624d21191d5c3b5dee315642a8e Mon Sep 17 00:00:00 2001 From: WipedLifePotato Date: Fri, 20 Sep 2024 13:15:45 +0700 Subject: [PATCH 5/6] [AutoConf] Fix options name --- autoconf.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/autoconf.cpp b/autoconf.cpp index 1ed6596..c687ab5 100644 --- a/autoconf.cpp +++ b/autoconf.cpp @@ -9,12 +9,13 @@ #include #define CIN_CLEAR std::cin.clear(); std::cin.ignore(std::numeric_limits::max(), '\n'); - +#define HTTP_SUPPORTS_LANGUAGE "german, italian, polish, portuguese, russian, spanish, turkish, turkmen, ukrainian, uzbek" 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 proxy("\\w+:\\/\\/(\\w|\\d|\\.|\\-)+\\:\\d+"); std::regex any(".*"); } @@ -65,8 +66,8 @@ const std::map Texts = // maybe vector better {"NTCPPProxy", "NTCP Proxy, пример (socks://localhost:4545) или - для по умолчанию (неиспользуется)"}, {"SSUEnabledYN", "Использовать SSU?"}, {"SSUPPort", "SSU Порт. Либо - для пропуска"}, - {"SSUProxy", "SSU Proxy, пример (socks://localhost:4545) или - для по умолчанию (неиспользуется)"} - + {"SSUProxy", "SSU Proxy, пример (socks://localhost:4545) или - для по умолчанию (неиспользуется)"}, + {"HTTPLang", "Выбрите язык веб-интерфейса, либо - для опции по умолчанию (" HTTP_SUPPORTS_LANGUAGE ")" } }}, {"en", { {"WelcomeText","Hello. Select type of config\r\n1 - clearnet\r\n2 - only yggdrasil"}, @@ -94,6 +95,7 @@ const std::map Texts = // maybe vector better {"NoTransitYN", "Disable transit? (this will reduce anonymity)"}, {"Bandwidth", "Write bandwidth (- for default) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, {"Share", "Share percents (- for default) [0-100]"}, + {"HTTPLang", "Select Web-interface language or - for default (" HTTP_SUPPORTS_LANGUAGE ")" }, // {"NTCPEnabledYN", "Use NTCP?"}, {"NTCPPublishedYN", "Publish IP in NTCP?"}, @@ -112,7 +114,6 @@ bool AskYN(void) noexcept { std::cout << " ? (y/n) "; std::cin >> answ; CIN_CLEAR; - std::cout <<"answ: " << answ<> inp;\ @@ -189,12 +187,11 @@ main(void) { } \ }\ }; - std::cout << "ASKYN" << std::endl; ASKYN_MACRO("TunConfYN","TunConf","tunconf", AutoConf::Regexps::path); ASKYN_MACRO("TunnelsDirYN","TunnelsDir","tunnelsdir",AutoConf::Regexps::path); ASKYN_MACRO("certsdirYN","certsdir","certsdir",AutoConf::Regexps::path); ASKYN_MACRO("pidfileYN","pidfile","pidfile",AutoConf::Regexps::path); - ASKYN_MACRO("logYN","log","log",AutoConf::Regexps::any); + //ASKYN_MACRO("logYN","log","log",AutoConf::Regexps::any); ASKYN_MACRO("loglevelYN","loglevel","loglevel",AutoConf::Regexps::any); // TODO: word type #define ASK_BOOL(A,B) { \ std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \ @@ -213,20 +210,22 @@ main(void) { }\ } ASK_TEXT("FamilyUsing","family"); - ASK_BOOL("BeFloodfillYN", "floodflill"); - ASK_BOOL("NoTransitYN", "transit"); + ASK_BOOL("BeFloodfillYN", "floodfill"); + ASK_BOOL("NoTransitYN", "notransit"); ASK_TEXT("Bandwidth","bandwidth"); ASK_TEXT("Share","share"); ///// With sections conf << "[ntcp2]\r\n"; ASK_BOOL("NTCPEnabledYN", "enabled"); - ASK_BOOL("NTCPPublishedYN", "publish"); + ASK_BOOL("NTCPPublishedYN", "published"); ASK_TEXT("NTCPPPort", "port"); ASK_TEXT("NTCPPProxy", "proxy"); conf << "[ssu2]\r\n"; ASK_BOOL("SSUEnabledYN", "enabled"); ASK_TEXT("SSUPPort", "port"); ASK_TEXT("SSUProxy", "proxy"); + conf << "[http]\r\n"; + ASK_TEXT("HTTPLang", "lang"); #undef ASK_TEXT #undef ASK_BOOL #undef ASKYN_MACRO From ea98854c7e30ecf692914d6b14c39f377e86d059 Mon Sep 17 00:00:00 2001 From: wipedlifepotato <60944239+wipedlifepotato@users.noreply.github.com> Date: Fri, 20 Sep 2024 13:42:54 +0700 Subject: [PATCH 6/6] [AutoConf] Add information to README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index f9e2172..e5921ee 100755 --- a/README.md +++ b/README.md @@ -188,3 +188,9 @@ verify signed router.info xLSOIwih0Jx3JObPRCBJexYOpPYJsEwQ1A== -----END EC PRIVATE KEY----- +#### AutoConf +A program for help create the config file for i2pd + +For a now a better way to manual write the config file + +For usage just run ./AutoConf or AutoConf.exe