From 9a5c090f2327219d00a9a0af7887d1dd2f8b6d15 Mon Sep 17 00:00:00 2001 From: Dario Date: Mon, 11 May 2020 15:01:29 +0200 Subject: [PATCH] adding replace for 0.0.0.0 ip --- CMakeLists.txt | 5 +---- src/cpp/ServerConfig.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fcceba09e..a5e9a3f40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,15 +120,12 @@ include_directories( endif(WIN32) - - - target_link_libraries(Gradido_LoginServer ${CONAN_LIBS} ${IROHA_ED25519}) if(WIN32) TARGET_LINK_LIBRARIES(Gradido_LoginServer optimized ${MYSQL_LIBRARIES} Shlwapi) TARGET_LINK_LIBRARIES(Gradido_LoginServer debug ${COMPILED_MARIADB_CLIENT_DEBUG} Shlwapi) else(WIN32) -target_link_libraries(Gradido_LoginServer mariadb/libmariadb PocoNet PocoUtil PocoJSON PocoFoundation PocoData PocoNetSSL protoc protobuf -pthread) +target_link_libraries(Gradido_LoginServer libmariadb PocoNet PocoUtil PocoJSON PocoFoundation PocoData PocoNetSSL protoc protobuf -pthread) endif(WIN32) # install diff --git a/src/cpp/ServerConfig.cpp b/src/cpp/ServerConfig.cpp index eed5ef06a..e5089306f 100644 --- a/src/cpp/ServerConfig.cpp +++ b/src/cpp/ServerConfig.cpp @@ -8,6 +8,7 @@ #include "Poco/Net/SSLManager.h" #include "Poco/Net/KeyConsoleHandler.h" #include "Poco/Net/RejectCertificateHandler.h" +#include "Poco/Net/DNS.h" #include "Poco/SharedPtr.h" #include "Poco/Mutex.h" @@ -17,6 +18,7 @@ #include "Poco/DateTimeFormat.h" #include "Poco/DateTimeFormatter.h" + using Poco::Net::SSLManager; using Poco::Net::Context; using Poco::Net::KeyConsoleHandler; @@ -47,6 +49,36 @@ namespace ServerConfig { std::string g_versionString = ""; bool g_disableEmail = false; + bool replaceZeroIPWithLocalhostIP(std::string& url) + { + auto pos = url.find("0.0.0.0", 0); + if (pos != std::string::npos) { + std::string ipAddressString = ""; + auto host = Poco::Net::DNS::thisHost(); + for (auto it = host.addresses().begin(); it != host.addresses().end(); it++) { + auto ipAddress = *it; + if (!ipAddress.isIPv4Compatible() && !ipAddress.isIPv4Mapped()) { + continue; + } + if (ipAddress.isLoopback()) { + continue; + } + ipAddressString = ipAddress.toString(); + //isIPv4Compatible + //!isLoopback + //printf("ipaddress: %s\n", ipAddressString.data()); + break; + //break; + } + url.replace(pos, 7, ipAddressString); + } + + //printf("ipaddress: %s\n", ipAddress.data()); + + return true; + } + + bool loadMnemonicWordLists() { for (int i = 0; i < MNEMONIC_MAX; i++) { @@ -104,8 +136,15 @@ namespace ServerConfig { g_SessionTimeout = cfg.getInt("session.timeout", SESSION_TIMEOUT_DEFAULT); g_serverPath = cfg.getString("loginServer.path", ""); g_default_locale = LanguageManager::languageFromString(cfg.getString("loginServer.default_locale")); + // replace 0.0.0.0 with actual server ip + g_php_serverPath = cfg.getString("phpServer.url", ""); + replaceZeroIPWithLocalhostIP(g_php_serverPath); g_php_serverHost = cfg.getString("phpServer.host", ""); + replaceZeroIPWithLocalhostIP(g_php_serverHost); + /*std::string testIp = "http://0.0.0.0/account"; + replaceZeroIPWithLocalhostIP(testIp); + printf("testIp: %s\n", testIp.data());*/ //g_FakeLoginSleepTime = cfg.getInt("crypto.fake_login_sleep_time", g_FakeLoginSleepTime); return true; }