diff --git a/build b/build index 86ee83a..f70d7bb 100644 --- a/build +++ b/build @@ -1 +1 @@ -40 \ No newline at end of file +42 \ No newline at end of file diff --git a/src/MicroService.h b/src/MicroService.h index 835f446..5fed2d1 100644 --- a/src/MicroService.h +++ b/src/MicroService.h @@ -131,6 +131,7 @@ namespace OpenWifi { [[nodiscard]] std::string PrivateEndPoint() const { return MyPrivateEndPoint_; }; [[nodiscard]] std::string PublicEndPoint() const { return MyPublicEndPoint_; }; [[nodiscard]] std::string MakeSystemEventMessage( const std::string & Type ) const ; + [[nodiscard]] const Types::SubSystemVec & GetFullSubSystems() { return SubSystems_; } inline uint64_t DaemonBusTimer() const { return DAEMON_BUS_TIMER; }; void BusMessageReceived( const std::string & Key, const std::string & Message); diff --git a/src/RESTAPI_handler.cpp b/src/RESTAPI_handler.cpp index 20fa463..9119b61 100644 --- a/src/RESTAPI_handler.cpp +++ b/src/RESTAPI_handler.cpp @@ -235,13 +235,23 @@ namespace OpenWifi { void RESTAPIHandler::BadRequest(const std::string & Reason) { PrepareResponse(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST); Poco::JSON::Object ErrorObject; - ErrorObject.set("ErrorCode",500); + ErrorObject.set("ErrorCode",400); ErrorObject.set("ErrorDetails",Request->getMethod()); ErrorObject.set("ErrorDescription",Reason.empty() ? "Command is missing parameters or wrong values." : Reason) ; std::ostream &Answer = Response->send(); Poco::JSON::Stringifier::stringify(ErrorObject, Answer); } + void RESTAPIHandler::InternalError(const std::string & Reason) { + PrepareResponse(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); + Poco::JSON::Object ErrorObject; + ErrorObject.set("ErrorCode",500); + ErrorObject.set("ErrorDetails",Request->getMethod()); + ErrorObject.set("ErrorDescription",Reason.empty() ? "Please try later or review the data submitted." : Reason) ; + std::ostream &Answer = Response->send(); + Poco::JSON::Stringifier::stringify(ErrorObject, Answer); + } + void RESTAPIHandler::UnAuthorized(const std::string & Reason) { PrepareResponse(Poco::Net::HTTPResponse::HTTP_FORBIDDEN); Poco::JSON::Object ErrorObject; diff --git a/src/RESTAPI_handler.h b/src/RESTAPI_handler.h index ed27282..0ae4235 100644 --- a/src/RESTAPI_handler.h +++ b/src/RESTAPI_handler.h @@ -114,6 +114,7 @@ namespace OpenWifi { bool GetBoolParameter(const std::string &Name, bool Default); void BadRequest(const std::string &Reason ); + void InternalError(const std::string &Reason = ""); void UnAuthorized(const std::string &Reason = ""); void ReturnObject(Poco::JSON::Object &Object); void NotFound(); diff --git a/src/RESTAPI_system_command.cpp b/src/RESTAPI_system_command.cpp index afcc268..8155dd4 100644 --- a/src/RESTAPI_system_command.cpp +++ b/src/RESTAPI_system_command.cpp @@ -9,6 +9,8 @@ #include "Poco/Exception.h" #include "Poco/JSON/Parser.h" +#include "Poco/DateTime.h" +#include "Poco/DateTimeFormat.h" #include "Daemon.h" #include "RESTAPI_protocol.h" @@ -113,6 +115,26 @@ namespace OpenWifi { Answer.set(RESTAPI::Protocol::OS, Poco::Environment::osName()); Answer.set(RESTAPI::Protocol::PROCESSORS, Poco::Environment::processorCount()); Answer.set(RESTAPI::Protocol::HOSTNAME, Poco::Environment::nodeName()); + + Poco::JSON::Array Certificates; + auto SubSystems = Daemon()->GetFullSubSystems(); + std::set CertNames; + for(const auto &i:SubSystems) { + auto Hosts=i->HostSize(); + for(uint64_t j=0;jHost(j).CertFile(); + auto InsertResult = CertNames.insert(CertFileName); + if( InsertResult.second ) { + Poco::JSON::Object Inner; + Inner.set("filename", CertFileName); + Poco::Crypto::X509Certificate C(CertFileName); + auto ExpiresOn = C.expiresOn(); + Inner.set("expiresOn",ExpiresOn.timestamp().epochTime()); + Certificates.add(Inner); + } + } + } + Answer.set("certificates", Certificates); ReturnObject(Answer); return; } diff --git a/src/SubSystemServer.h b/src/SubSystemServer.h index 3a2c374..ff5e045 100644 --- a/src/SubSystemServer.h +++ b/src/SubSystemServer.h @@ -76,7 +76,8 @@ class SubSystemServer : public Poco::Util::Application::Subsystem { inline const std::string & Name() const { return Name_; }; const char * name() const override { return Name_.c_str(); } - const PropertiesFileServerEntry &Host(int index) { return ConfigServersList_[index]; }; + const PropertiesFileServerEntry & Host(uint64_t index) { return ConfigServersList_[index]; }; + uint64_t HostSize() const { return ConfigServersList_.size(); } Poco::Logger &Logger() { return Logger_; }; void SetLoggingLevel(Poco::Message::Priority NewPriority) { Logger_.setLevel(NewPriority); } int GetLoggingLevel() { return Logger_.getLevel(); }