Adding RESTAPI_handler fix.

This commit is contained in:
stephb9959
2021-09-21 08:11:54 -07:00
parent acf2b71fec
commit dcc09f3d4e
4 changed files with 50 additions and 20 deletions

View File

@@ -154,6 +154,37 @@ namespace OpenWifi {
return Res; 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<Poco::Crypto::RSAKey>(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) { void MicroService::initialize(Poco::Util::Application &self) {
// add the default services // add the default services
SubSystems_.push_back(KafkaManager()); SubSystems_.push_back(KafkaManager());
@@ -164,11 +195,12 @@ namespace OpenWifi {
Poco::Net::HTTPSStreamFactory::registerFactory(); Poco::Net::HTTPSStreamFactory::registerFactory();
Poco::Net::FTPStreamFactory::registerFactory(); Poco::Net::FTPStreamFactory::registerFactory();
Poco::Net::FTPSStreamFactory::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; Poco::Path ConfigFile;
ConfigFile = ConfigFileName_.empty() ? Location + "/" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_; ConfigFile = ConfigFileName_.empty() ? Location + "/" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_;
if(!ConfigFile.isFile()) if(!ConfigFile.isFile())
{ {
std::cerr << DAEMON_APP_NAME << ": Configuration " std::cerr << DAEMON_APP_NAME << ": Configuration "
@@ -176,10 +208,10 @@ namespace OpenWifi {
+ " env variable the path of the " + DAEMON_PROPERTIES_FILENAME + " file." << std::endl; + " env variable the path of the " + DAEMON_PROPERTIES_FILENAME + " file." << std::endl;
std::exit(Poco::Util::Application::EXIT_CONFIG); std::exit(Poco::Util::Application::EXIT_CONFIG);
} }
static const char * LogFilePathKey = "logging.channels.c2.path";
loadConfiguration(ConfigFile.toString()); loadConfiguration(ConfigFile.toString());
*/
static const char * LogFilePathKey = "logging.channels.c2.path";
if(LogDir_.empty()) { if(LogDir_.empty()) {
std::string OriginalLogFileValue = ConfigPath(LogFilePathKey); std::string OriginalLogFileValue = ConfigPath(LogFilePathKey);
@@ -187,6 +219,7 @@ namespace OpenWifi {
} else { } else {
config().setString(LogFilePathKey, LogDir_); config().setString(LogFilePathKey, LogDir_);
} }
Poco::File DataDir(ConfigPath("openwifi.system.data")); Poco::File DataDir(ConfigPath("openwifi.system.data"));
DataDir_ = DataDir.path(); DataDir_ = DataDir.path();
if(!DataDir.exists()) { if(!DataDir.exists()) {
@@ -196,17 +229,9 @@ namespace OpenWifi {
logger().log(E); logger().log(E);
} }
} }
std::string KeyFile = ConfigPath("openwifi.service.key");
std::string KeyFilePassword = ConfigPath("openwifi.service.key.password" , "" ); Reload();
AppKey_ = Poco::SharedPtr<Poco::Crypto::RSAKey>(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_);
InitializeSubSystemServers(); InitializeSubSystemServers();
ServerApplication::initialize(self); ServerApplication::initialize(self);

View File

@@ -142,7 +142,11 @@ namespace OpenWifi {
static inline uint64_t GetPID() { return Poco::Process::id(); }; static inline uint64_t GetPID() { return Poco::Process::id(); };
[[nodiscard]] inline const std::string GetPublicAPIEndPoint() { return MyPublicEndPoint_ + "/api/v1"; }; [[nodiscard]] inline const std::string GetPublicAPIEndPoint() { return MyPublicEndPoint_ + "/api/v1"; };
[[nodiscard]] inline const std::string & GetUIURI() const { return UIURI_;}; [[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: private:
bool HelpRequested_ = false; bool HelpRequested_ = false;

View File

@@ -99,6 +99,7 @@ namespace OpenWifi {
} }
void RESTAPI_server::reinitialize(Poco::Util::Application &self) { void RESTAPI_server::reinitialize(Poco::Util::Application &self) {
Daemon()->LoadConfigurationFile();
std::cout << "TESTER: " << Daemon()->ConfigGetString("tester") << std::endl; std::cout << "TESTER: " << Daemon()->ConfigGetString("tester") << std::endl;
Logger_.information("Reinitializing."); Logger_.information("Reinitializing.");
Stop(); Stop();

View File

@@ -429,7 +429,7 @@ systeminfo() {
} }
reloadsubsystem() { reloadsubsystem() {
payload="{ \"command\" : \"reload\", \"subsystems\" : [ \"OUIServer\" , \"CommandManager\" ] }" payload="{ \"command\" : \"reload\", \"subsystems\" : [ \"$1\" ] }"
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/system" \ curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/system" \
-H "accept: application/json" \ -H "accept: application/json" \
-H "Authorization: Bearer ${token}" \ -H "Authorization: Bearer ${token}" \
@@ -474,7 +474,7 @@ case "$1" in
"getloglevels") login; getloglevels; logout ;; "getloglevels") login; getloglevels; logout ;;
"getloglevelnames") login; getloglevelnames; logout ;; "getloglevelnames") login; getloglevelnames; logout ;;
"getsubsystemnames") login; getsubsystemnames; logout ;; "getsubsystemnames") login; getsubsystemnames; logout ;;
"reloadsubsystem") login; reloadsubsystem; logout ;; "reloadsubsystem") login; reloadsubsystem "$2"; logout ;;
"systeminfo") login; systeminfo ; logout;; "systeminfo") login; systeminfo ; logout;;
*) help ;; *) help ;;
esac esac