diff --git a/src/MicroService.cpp b/src/MicroService.cpp index be06fac..949780a 100644 --- a/src/MicroService.cpp +++ b/src/MicroService.cpp @@ -154,6 +154,37 @@ namespace OpenWifi { return Res; } + void MicroService::LoadConfigurationFile() { + std::string Location = Poco::Environment::get(DAEMON_CONFIG_ENV_VAR,"."); + Poco::Path ConfigFile; + + ConfigFile = ConfigFileName_.empty() ? Location + "/" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_; + + if(!ConfigFile.isFile()) + { + std::cerr << DAEMON_APP_NAME << ": Configuration " + << ConfigFile.toString() << " does not seem to exist. Please set " + DAEMON_CONFIG_ENV_VAR + + " env variable the path of the " + DAEMON_PROPERTIES_FILENAME + " file." << std::endl; + std::exit(Poco::Util::Application::EXIT_CONFIG); + } + + loadConfiguration(ConfigFile.toString()); + } + + void MicroService::Reload() { + std::string KeyFile = ConfigPath("openwifi.service.key"); + std::string KeyFilePassword = ConfigPath("openwifi.service.key.password" , "" ); + AppKey_ = Poco::SharedPtr(new Poco::Crypto::RSAKey("", KeyFile, KeyFilePassword)); + Cipher_ = CipherFactory_.createCipher(*AppKey_); + ID_ = Utils::GetSystemId(); + if(!DebugMode_) + DebugMode_ = ConfigGetBool("openwifi.system.debug",false); + MyPrivateEndPoint_ = ConfigGetString("openwifi.system.uri.private"); + MyPublicEndPoint_ = ConfigGetString("openwifi.system.uri.public"); + UIURI_ = ConfigGetString("openwifi.system.uri.ui"); + MyHash_ = CreateHash(MyPublicEndPoint_); + } + void MicroService::initialize(Poco::Util::Application &self) { // add the default services SubSystems_.push_back(KafkaManager()); @@ -164,11 +195,12 @@ namespace OpenWifi { Poco::Net::HTTPSStreamFactory::registerFactory(); Poco::Net::FTPStreamFactory::registerFactory(); Poco::Net::FTPSStreamFactory::registerFactory(); - std::string Location = Poco::Environment::get(DAEMON_CONFIG_ENV_VAR,"."); + + LoadConfigurationFile(); + +/* std::string Location = Poco::Environment::get(DAEMON_CONFIG_ENV_VAR,"."); Poco::Path ConfigFile; - ConfigFile = ConfigFileName_.empty() ? Location + "/" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_; - if(!ConfigFile.isFile()) { std::cerr << DAEMON_APP_NAME << ": Configuration " @@ -176,10 +208,10 @@ namespace OpenWifi { + " env variable the path of the " + DAEMON_PROPERTIES_FILENAME + " file." << std::endl; std::exit(Poco::Util::Application::EXIT_CONFIG); } - - static const char * LogFilePathKey = "logging.channels.c2.path"; - loadConfiguration(ConfigFile.toString()); +*/ + + static const char * LogFilePathKey = "logging.channels.c2.path"; if(LogDir_.empty()) { std::string OriginalLogFileValue = ConfigPath(LogFilePathKey); @@ -187,6 +219,7 @@ namespace OpenWifi { } else { config().setString(LogFilePathKey, LogDir_); } + Poco::File DataDir(ConfigPath("openwifi.system.data")); DataDir_ = DataDir.path(); if(!DataDir.exists()) { @@ -196,17 +229,9 @@ namespace OpenWifi { logger().log(E); } } - std::string KeyFile = ConfigPath("openwifi.service.key"); - std::string KeyFilePassword = ConfigPath("openwifi.service.key.password" , "" ); - AppKey_ = Poco::SharedPtr(new Poco::Crypto::RSAKey("", KeyFile, KeyFilePassword)); - Cipher_ = CipherFactory_.createCipher(*AppKey_); - ID_ = Utils::GetSystemId(); - if(!DebugMode_) - DebugMode_ = ConfigGetBool("openwifi.system.debug",false); - MyPrivateEndPoint_ = ConfigGetString("openwifi.system.uri.private"); - MyPublicEndPoint_ = ConfigGetString("openwifi.system.uri.public"); - UIURI_ = ConfigGetString("openwifi.system.uri.ui"); - MyHash_ = CreateHash(MyPublicEndPoint_); + + Reload(); + InitializeSubSystemServers(); ServerApplication::initialize(self); diff --git a/src/MicroService.h b/src/MicroService.h index 07e8460..db4cb3e 100644 --- a/src/MicroService.h +++ b/src/MicroService.h @@ -142,7 +142,11 @@ namespace OpenWifi { static inline uint64_t GetPID() { return Poco::Process::id(); }; [[nodiscard]] inline const std::string GetPublicAPIEndPoint() { return MyPublicEndPoint_ + "/api/v1"; }; [[nodiscard]] inline const std::string & GetUIURI() const { return UIURI_;}; - void Reload(const std::string &Name); + + void Reload(const std::string &Name); // reload a subsystem + void Reload(); // reload the daemon itself + + void LoadConfigurationFile(); private: bool HelpRequested_ = false; diff --git a/src/RESTAPI_server.cpp b/src/RESTAPI_server.cpp index 6dc3a9d..b02b7fa 100644 --- a/src/RESTAPI_server.cpp +++ b/src/RESTAPI_server.cpp @@ -99,6 +99,7 @@ namespace OpenWifi { } void RESTAPI_server::reinitialize(Poco::Util::Application &self) { + Daemon()->LoadConfigurationFile(); std::cout << "TESTER: " << Daemon()->ConfigGetString("tester") << std::endl; Logger_.information("Reinitializing."); Stop(); diff --git a/test_scripts/curl/cli b/test_scripts/curl/cli index 6720869..6a28462 100755 --- a/test_scripts/curl/cli +++ b/test_scripts/curl/cli @@ -429,7 +429,7 @@ systeminfo() { } reloadsubsystem() { - payload="{ \"command\" : \"reload\", \"subsystems\" : [ \"OUIServer\" , \"CommandManager\" ] }" + payload="{ \"command\" : \"reload\", \"subsystems\" : [ \"$1\" ] }" curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/system" \ -H "accept: application/json" \ -H "Authorization: Bearer ${token}" \ @@ -474,7 +474,7 @@ case "$1" in "getloglevels") login; getloglevels; logout ;; "getloglevelnames") login; getloglevelnames; logout ;; "getsubsystemnames") login; getsubsystemnames; logout ;; - "reloadsubsystem") login; reloadsubsystem; logout ;; + "reloadsubsystem") login; reloadsubsystem "$2"; logout ;; "systeminfo") login; systeminfo ; logout;; *) help ;; esac