diff --git a/build b/build index da2d398..3f10ffe 100644 --- a/build +++ b/build @@ -1 +1 @@ -14 \ No newline at end of file +15 \ No newline at end of file diff --git a/openpapi/owsec.yaml b/openpapi/owsec.yaml index aaf31c2..958de20 100644 --- a/openpapi/owsec.yaml +++ b/openpapi/owsec.yaml @@ -493,6 +493,16 @@ components: sms: type: string + ExtraSystemConfiguration: + type: array + items: + type: object + properties: + parameterName: + type: string + parameterValue: + type: string + ######################################################################################### ## ## These are endpoints that all services in the uCentral stack must provide @@ -2057,6 +2067,69 @@ paths: 404: $ref: '#/components/responses/NotFound' + /systemConfiguration: + get: + tags: + - SystemConfiguration + summary: Retrieve system configuration items + operationId: getSystemConfiguration + parameters: + - in: query + description: Which parameters you want to retrieve + name: entries + schema: + type: string + example: + - element1 + - element1,element2,element3 + required: false + responses: + 200: + description: List of configuration elements + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/ExtraSystemConfiguration' + 403: + $ref: '#/components/responses/Unauthorized' + 404: + $ref: '#/components/responses/NotFound' + + put: + tags: + - SystemConfiguration + summary: Set some or all system configuration + operationId: setSystemConfiguration + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ExtraSystemConfiguration' + + responses: + 200: + $ref: '#/components/schemas/ExtraSystemConfiguration' + 403: + $ref: '#/components/responses/Unauthorized' + 404: + $ref: '#/components/responses/NotFound' + + delete: + tags: + - SystemConfiguration + summary: Delete all additional system configuration + operationId: deleteSystemConfiguration + + responses: + 200: + $ref: '#/components/responses/Success' + 403: + $ref: '#/components/responses/Unauthorized' + 404: + $ref: '#/components/responses/NotFound' + ######################################################################################### ## ## These are endpoints that all services in the uCentral stack must provide diff --git a/src/RESTObjects/RESTAPI_SecurityObjects.cpp b/src/RESTObjects/RESTAPI_SecurityObjects.cpp index 583de45..8c1c50b 100644 --- a/src/RESTObjects/RESTAPI_SecurityObjects.cpp +++ b/src/RESTObjects/RESTAPI_SecurityObjects.cpp @@ -721,4 +721,20 @@ namespace OpenWifi::SecurityObjects { return false; } + void ExtraSystemConfiguration::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "parameterName", parameterName); + field_to_json(Obj, "parameterValue", parameterValue); + } + + bool ExtraSystemConfiguration::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "parameterName", parameterName); + field_from_json(Obj, "parameterValue", parameterValue); + return true; + } catch (...) { + std::cout << "Cannot parse: Token" << std::endl; + } + return false; + } + } // namespace OpenWifi::SecurityObjects diff --git a/src/RESTObjects/RESTAPI_SecurityObjects.h b/src/RESTObjects/RESTAPI_SecurityObjects.h index 649fb49..88253ec 100644 --- a/src/RESTObjects/RESTAPI_SecurityObjects.h +++ b/src/RESTObjects/RESTAPI_SecurityObjects.h @@ -367,5 +367,13 @@ namespace OpenWifi { bool from_json(const Poco::JSON::Object::Ptr &Obj); }; - } // namespace SecurityObjects + struct ExtraSystemConfiguration { + std::string parameterName; + std::string parameterValue; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + +} // namespace SecurityObjects } // namespace OpenWifi diff --git a/src/framework/RESTAPI_SystemConfiguration.h b/src/framework/RESTAPI_SystemConfiguration.h index d148784..1ab3b40 100644 --- a/src/framework/RESTAPI_SystemConfiguration.h +++ b/src/framework/RESTAPI_SystemConfiguration.h @@ -4,8 +4,8 @@ #pragma once -#include "framework/MicroServiceFuncs.h" #include "framework/RESTAPI_Handler.h" +#include "framework/MicroServiceFuncs.h" using namespace std::chrono_literals; @@ -14,8 +14,8 @@ namespace OpenWifi { class RESTAPI_system_configuration : public RESTAPIHandler { public: RESTAPI_system_configuration(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, - RESTAPI_GenericServerAccounting &Server, - uint64_t TransactionId, bool Internal) + RESTAPI_GenericServerAccounting &Server, uint64_t TransactionId, + bool Internal) : RESTAPIHandler(bindings, L, std::vector{Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_GET, @@ -27,23 +27,42 @@ namespace OpenWifi { inline void DoPost() final {} - inline void DoGet() final { return OK(); } + inline void DoGet() final { + auto entries = GetParameter("entries",""); + if(entries.empty()) { + return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); + } - inline void DoPut() final { - if (UserInfo_.userinfo.userRole != SecurityObjects::ROOT) { + auto entriesArray = Poco::StringTokenizer(entries,",",Poco::StringTokenizer::TOK_TRIM); + Poco::JSON::Array Array; + for(const auto &entry:entriesArray) { + SecurityObjects::ExtraSystemConfiguration X; + X.parameterName = entry; + X.parameterValue = MicroServiceConfigGetString(entry,""); + Poco::JSON::Object E; + X.to_json(E); + Array.add(E); + } + + std::ostringstream os; + Array.stringify(os); + return ReturnRawJSON(os.str()); + } + + inline void DoPut() final{ + if(UserInfo_.userinfo.userRole!=SecurityObjects::ROOT) { return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED); } - return OK(); + return BadRequest(RESTAPI::Errors::NotImplemented); }; - inline void DoDelete() final { - if (UserInfo_.userinfo.userRole != SecurityObjects::ROOT) { + inline void DoDelete() final{ + if(UserInfo_.userinfo.userRole!=SecurityObjects::ROOT) { return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED); } - MicroServiceDeleteOverrideConfiguration(); - return OK(); + return BadRequest(RESTAPI::Errors::NotImplemented); }; }; -} // namespace OpenWifi +}