diff --git a/CMakeLists.txt b/CMakeLists.txt index 43dd0b4..48027cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -227,8 +227,8 @@ add_executable(owprov src/RESTAPI/RESTAPI_radius_endpoint_handler.h src/RadiusEndpointTypes/GlobalReach.cpp src/RadiusEndpointTypes/GlobalReach.h src/RadiusEndpointTypes/OrionWifi.h - src/RadiusEndpoint.cpp - src/RadiusEndpoint.h + src/RadiusEndpointUpdater.cpp + src/RadiusEndpointUpdater.h ) target_link_libraries(owprov PUBLIC diff --git a/build b/build index 8323328..d7765fe 100644 --- a/build +++ b/build @@ -1 +1 @@ -67 \ No newline at end of file +70 \ No newline at end of file diff --git a/openapi/radius_endpoints.yaml b/openapi/radius_endpoints.yaml index dcb9395..a8d0cc9 100644 --- a/openapi/radius_endpoints.yaml +++ b/openapi/radius_endpoints.yaml @@ -151,19 +151,25 @@ paths: description: Pagination start (starts at 1. If not specified, 1 is assumed) name: offset schema: - type: integer + type: integer required: false - in: query description: Maximum number of entries to return (if absent, no limit is assumed) name: limit schema: - type: integer + type: integer required: false - in: query description: return the number of certificates name: countOnly schema: - type: boolean + type: boolean + required: false + - in: query + description: return the last update time + name: lastUpdate + schema: + type: boolean required: false responses: 200: @@ -171,9 +177,46 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/RADIUSEndPoint' + oneOf: + - type: array + items: + $ref: '#/components/schemas/RADIUSEndPoint' + - type: object + properties: + lastUpdate: + type: integer + format: int64 + 400: + $ref: '#/components/responses/BadRequest' + 403: + $ref: '#/components/responses/Unauthorized' + 404: + $ref: '#/components/responses/NotFound' + + put: + tags: + - RADIUS Endpoints + operationId: updateRADIUSEndpoints + summary: Force an Update to teh RADIUSendPoints in the controller + parameters: + - in: query + name: updateEndpoints + schema: + type: boolean + required: false + responses: + 200: + description: The list of endpoints + content: + application/json: + schema: + type: object + properties: + Error: + type: string + ErrorNum: + type: integer + $ref: '#/components/responses/Success' 400: $ref: '#/components/responses/BadRequest' 403: diff --git a/src/APConfig.cpp b/src/APConfig.cpp index 6a0f3ff..c72db03 100644 --- a/src/APConfig.cpp +++ b/src/APConfig.cpp @@ -59,26 +59,19 @@ namespace OpenWifi { } bool APConfig::InsertRadiusEndPoint(const ProvObjects::RADIUSEndPoint &RE, Poco::JSON::Object &Result) { - DBGLINE if(RE.UseGWProxy) { - DBGLINE Poco::JSON::Object ServerSettings; if (RE.Type == "orion") { - DBGLINE return OpenRoaming_Orion()->Render(RE, Result); } else if (RE.Type == "globalreach") { - DBGLINE return OpenRoaming_GlobalReach()->Render(RE, Result); } else if (RE.Type == "radsec") { - DBGLINE } else if (RE.Type == "radius") { - DBGLINE } Result.set( "radius" , ServerSettings); } - DBGLINE return false; } @@ -87,7 +80,6 @@ namespace OpenWifi { // get all the names and expand auto Names = Original.getNames(); for (const auto &i : Names) { - DBGLINE if (i == "__variableBlock") { if (Original.isArray(i)) { auto UUIDs = Original.getArray(i); @@ -101,13 +93,14 @@ namespace OpenWifi { auto VarNames = VariableBlockInfo->getNames(); for (const auto &j: VarNames) { std::cout << "Name: " << j << std::endl; - Poco::JSON::Object InnerEval; if(VariableBlockInfo->isArray(j)) { - auto Arr = VariableBlockInfo->getArray(j); -// ReplaceVariablesInObject(,InnerEval); - // Result->set(j, InnerEval); + auto Elements = VariableBlockInfo->getArray(j); + Poco::JSON::Array InnerArray; + ReplaceVariablesInArray(*Elements,InnerArray); + Result.set(j,InnerArray); std::cout << "Array!!!" << std::endl; } else if(VariableBlockInfo->isObject(j)) { + Poco::JSON::Object InnerEval; std::cout << "Visiting object " << j << std::endl; auto O = VariableBlockInfo->getObject(j); ReplaceVariablesInObject(*O,InnerEval); @@ -121,40 +114,27 @@ namespace OpenWifi { } } } else if (i == "__radiusEndpoint") { - DBGLINE auto EndPointId = Original.get(i).toString(); - DBGLINE ProvObjects::RADIUSEndPoint RE; - DBGLINE std::cout << "ID->" << EndPointId << std::endl; if(StorageService()->RadiusEndpointDB().GetRecord("id",EndPointId,RE)) { - DBGLINE InsertRadiusEndPoint(RE, Result); - DBGLINE } else { - DBGLINE poco_error(Logger_, fmt::format("RADIUS Endpoint {} could not be found. Please delete this configuration and recreate it.")); return false; } - DBGLINE } else if (Original.isArray(i)) { - DBGLINE Poco::JSON::Array Arr; auto Obj = Original.getArray(i); ReplaceVariablesInArray(*Obj, Arr); Result.set(i, Arr); - DBGLINE } else if (Original.isObject(i)) { - DBGLINE Poco::JSON::Object Expanded; auto Obj = Original.getObject(i); ReplaceVariablesInObject(*Obj, Expanded); Result.set(i, Expanded); - DBGLINE } else { - DBGLINE Result.set(i, Original.get(i)); - DBGLINE } } return true; diff --git a/src/RESTAPI/RESTAPI_openroaming_gr_list_certificates.cpp b/src/RESTAPI/RESTAPI_openroaming_gr_list_certificates.cpp index 25984e7..305643f 100644 --- a/src/RESTAPI/RESTAPI_openroaming_gr_list_certificates.cpp +++ b/src/RESTAPI/RESTAPI_openroaming_gr_list_certificates.cpp @@ -12,6 +12,17 @@ namespace OpenWifi { return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); } + if(Account=="*") { + std::vector< ProvObjects::GLBLRCertificateInfo> Arr; + for(const auto &cert:QB_.Select) { + ProvObjects::GLBLRCertificateInfo CInfo; + if(StorageService()->GLBLRCertsDB().GetRecord("id",cert,CInfo)) { + Arr.emplace_back(CInfo); + } + } + return ReturnObject(Arr); + } + auto Where = fmt::format(" accountId='{}'", Account); if(GetBoolParameter("countOnly")) { return ReturnCountOnly(DB_.Count(Where)); diff --git a/src/RESTAPI/RESTAPI_radiusendpoint_list_handler.cpp b/src/RESTAPI/RESTAPI_radiusendpoint_list_handler.cpp index 1392f09..d7838f7 100644 --- a/src/RESTAPI/RESTAPI_radiusendpoint_list_handler.cpp +++ b/src/RESTAPI/RESTAPI_radiusendpoint_list_handler.cpp @@ -3,10 +3,20 @@ // #include "RESTAPI_radiusendpoint_list_handler.h" +#include "framework/AppServiceRegistry.h" +#include "RadiusEndpointUpdater.h" namespace OpenWifi { void RESTAPI_radiusendpoint_list_handler::DoGet() { + if(GetBoolParameter("lastUpdate")) { + uint64_t LastUpdate=0; + AppServiceRegistry().Get("radiusEndpointLastUpdate", LastUpdate); + Poco::JSON::Object Answer; + Answer.set("lastUpdate",LastUpdate); + return ReturnObject(Answer); + } + if(QB_.CountOnly) { return ReturnCountOnly(DB_.Count()); } @@ -15,4 +25,25 @@ namespace OpenWifi { return ReturnObject(Records); } + void RESTAPI_radiusendpoint_list_handler::DoPut() { + if( UserInfo_.userinfo.userRole!=SecurityObjects::ROOT && + UserInfo_.userinfo.userRole!=SecurityObjects::ADMIN) { + return BadRequest(RESTAPI::Errors::ACCESS_DENIED); + } + + if(GetBoolParameter("updateEndpoints")) { + RadiusEndpointUpdater R; + + std::string Error; + uint64_t ErrorNum = 0; + R.UpdateEndpoints(Error, ErrorNum); + + Poco::JSON::Object Answer; + Answer.set("Error", Error); + Answer.set("ErrorNum", ErrorNum); + return ReturnObject(Answer); + } + return BadRequest(RESTAPI::Errors::MissingAuthenticationInformation); + } + } // OpenWifi \ No newline at end of file diff --git a/src/RESTAPI/RESTAPI_radiusendpoint_list_handler.h b/src/RESTAPI/RESTAPI_radiusendpoint_list_handler.h index 85fd3cc..aec798a 100644 --- a/src/RESTAPI/RESTAPI_radiusendpoint_list_handler.h +++ b/src/RESTAPI/RESTAPI_radiusendpoint_list_handler.h @@ -14,6 +14,7 @@ namespace OpenWifi { bool Internal) : RESTAPIHandler(bindings, L, std::vector{Poco::Net::HTTPRequest::HTTP_GET, + Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, TransactionId, Internal) {} static auto PathName() { return std::list{"/api/v1/RADIUSEndPoints"}; }; @@ -23,7 +24,7 @@ namespace OpenWifi { RadiusEndpointDB &DB_ = StorageService()->RadiusEndpointDB(); void DoGet() final; void DoPost() final{}; - void DoPut() final{}; + void DoPut() final; void DoDelete() final{}; }; } // namespace OpenWifi diff --git a/src/RadiusEndpoint.cpp b/src/RadiusEndpoint.cpp deleted file mode 100644 index cd17881..0000000 --- a/src/RadiusEndpoint.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// -// Created by stephane bourque on 2023-10-02. -// - -#include "RadiusEndpoint.h" - -namespace OpenWifi { -} // OpenWifi \ No newline at end of file diff --git a/src/RadiusEndpointUpdater.cpp b/src/RadiusEndpointUpdater.cpp new file mode 100644 index 0000000..92f6870 --- /dev/null +++ b/src/RadiusEndpointUpdater.cpp @@ -0,0 +1,5 @@ +// +// Created by stephane bourque on 2023-10-02. +// + +#include "RadiusEndpointUpdater.h" diff --git a/src/RadiusEndpoint.h b/src/RadiusEndpointUpdater.h similarity index 91% rename from src/RadiusEndpoint.h rename to src/RadiusEndpointUpdater.h index ef3d79c..c72a187 100644 --- a/src/RadiusEndpoint.h +++ b/src/RadiusEndpointUpdater.h @@ -2,8 +2,9 @@ // Created by stephane bourque on 2023-10-02. // -#ifndef OWPROV_RADIUSENDPOINT_H -#define OWPROV_RADIUSENDPOINT_H +#pragma once +#include +#include /* @@ -110,12 +111,18 @@ */ -namespace OpenWifi { +#include - class RadiusEndpoint { +namespace OpenWifi { + class RadiusEndpointUpdater { + public: + inline bool UpdateEndpoints( [[maybe_unused]] std::string & Error, + [[maybe_unused]] uint64_t &ErrorNum ) { + + AppServiceRegistry().Set("radiusEndpointLastUpdate", Utils::Now()); + return false; + } + private: }; - } // OpenWifi - -#endif //OWPROV_RADIUSENDPOINT_H