diff --git a/openapi/openroaming_globalreach.yaml b/openapi/openroaming_globalreach.yaml index f778168..f85c85b 100644 --- a/openapi/openroaming_globalreach.yaml +++ b/openapi/openroaming_globalreach.yaml @@ -370,3 +370,38 @@ paths: 404: $ref: '#/components/responses/NotFound' + put: + tags: + - RadiusEndpointTypes-Global Reach Certificate + operationId: updateOpenRoamingGlobalReachCertificate + summary: Update certificate information. + parameters: + - in: path + description: The account name - this is the provisioning ID for the account. Not the GlobalReach ID. + name: account + schema: + type: string + required: true + - in: path + description: the UUID of the certificate + name: id + schema: + type: string + required: true + - in: query + description: Must be set to "1" + name: updateCertificate + schema: + type: boolean + default: false + required: false + responses: + 200: + $ref: '#/components/schemas/GLBLRCertificateInfo' + 400: + $ref: '#/components/responses/BadRequest' + 403: + $ref: '#/components/responses/Unauthorized' + 404: + $ref: '#/components/responses/NotFound' + diff --git a/openapi/radius_endpoints.yaml b/openapi/radius_endpoints.yaml index a0ab85f..dd54005 100644 --- a/openapi/radius_endpoints.yaml +++ b/openapi/radius_endpoints.yaml @@ -146,6 +146,18 @@ components: type: integer format: int64 + RADIUSEndpointUpdateStatus: + type: object + properties: + lastUpdate: + type: integer + format: int64 + lastConfigurationChange: + type: integer + format: int64 + + + paths: /RADIUSEndPoints: get: @@ -174,7 +186,7 @@ paths: required: false - in: query description: return the last update time - name: lastUpdate + name: currentStatus schema: type: boolean required: false @@ -188,11 +200,8 @@ paths: - type: array items: $ref: '#/components/schemas/RADIUSEndPoint' - - type: object - properties: - lastUpdate: - type: integer - format: int64 + - type: + $ref: '#/components/schemas/RADIUSEndpointUpdateStatus' 400: $ref: '#/components/responses/BadRequest' 403: diff --git a/src/RESTAPI/RESTAPI_openroaming_gr_cert_handler.cpp b/src/RESTAPI/RESTAPI_openroaming_gr_cert_handler.cpp index 5f8b351..5616e23 100644 --- a/src/RESTAPI/RESTAPI_openroaming_gr_cert_handler.cpp +++ b/src/RESTAPI/RESTAPI_openroaming_gr_cert_handler.cpp @@ -79,4 +79,35 @@ namespace OpenWifi { return BadRequest(RESTAPI::Errors::RecordNotCreated); } + void RESTAPI_openroaming_gr_cert_handler::DoPut() { + auto Account = GetBinding("account",""); + auto Id = GetBinding("id",""); + auto UpdateCertificate = GetBoolParameter("updateCertificate",false); + + if(Account.empty() || Id.empty() || !UpdateCertificate){ + return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); + } + + ProvObjects::GLBLRAccountInfo AccountInfo; + if(!StorageService()->GLBLRAccountInfoDB().GetRecord("id",Account, AccountInfo)) { + return BadRequest(RESTAPI::Errors::InvalidGlobalReachAccount); + } + + ProvObjects::GLBLRCertificateInfo Existing; + if(!DB_.GetRecord("id",Id,Existing)) { + return NotFound(); + } + + if(OpenRoaming_GlobalReach()->CreateRADSECCertificate(AccountInfo.GlobalReachAcctId,Existing.name,AccountInfo.CSR, Existing)) { + Existing.created = Utils::Now(); + DB_.UpdateRecord("id",Existing.id,Existing); + RecordType CreatedObject; + DB_.GetRecord("id",Existing.id,CreatedObject); + ProvObjects::RADIUSEndpointUpdateStatus Status; + Status.ChangeConfiguration(); + return ReturnObject(CreatedObject); + } + return BadRequest(RESTAPI::Errors::RecordNotUpdated); + } + } // OpenWifi \ No newline at end of file diff --git a/src/RESTAPI/RESTAPI_openroaming_gr_cert_handler.h b/src/RESTAPI/RESTAPI_openroaming_gr_cert_handler.h index e8d7aca..7d319e3 100644 --- a/src/RESTAPI/RESTAPI_openroaming_gr_cert_handler.h +++ b/src/RESTAPI/RESTAPI_openroaming_gr_cert_handler.h @@ -16,6 +16,7 @@ namespace OpenWifi { std::vector{Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_POST, + Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, TransactionId, Internal) {} static auto PathName() { return std::list{"/api/v1/openroaming/globalreach/certificate/{account}/{id}"}; }; @@ -25,7 +26,7 @@ namespace OpenWifi { GLBLRCertsDB &DB_ = StorageService()->GLBLRCertsDB(); void DoGet() final; void DoPost() final; - void DoPut() final {}; + void DoPut() final ; void DoDelete() final; }; } // namespace OpenWifi diff --git a/src/RESTAPI/RESTAPI_radius_endpoint_handler.cpp b/src/RESTAPI/RESTAPI_radius_endpoint_handler.cpp index ac15651..6088f85 100644 --- a/src/RESTAPI/RESTAPI_radius_endpoint_handler.cpp +++ b/src/RESTAPI/RESTAPI_radius_endpoint_handler.cpp @@ -30,6 +30,8 @@ namespace OpenWifi { RecordType Record; if(DB_.GetRecord("id",id,Record)) { DB_.DeleteRecord("id",id); + ProvObjects::RADIUSEndpointUpdateStatus Status; + Status.ChangeConfiguration(); return OK(); } return NotFound(); @@ -158,6 +160,8 @@ namespace OpenWifi { if(DB_.CreateRecord(NewRecord)) { RecordType AddedRecord; DB_.GetRecord("id", NewRecord.info.id, AddedRecord); + ProvObjects::RADIUSEndpointUpdateStatus Status; + Status.ChangeConfiguration(); return ReturnObject(AddedRecord); } return BadRequest(RESTAPI::Errors::RecordNotCreated); @@ -187,6 +191,8 @@ namespace OpenWifi { if(DB_.UpdateRecord("id", Existing.info.id, Existing)) { RecordType AddedRecord; DB_.GetRecord("id", Existing.info.id, AddedRecord); + ProvObjects::RADIUSEndpointUpdateStatus Status; + Status.ChangeConfiguration(); return ReturnObject(AddedRecord); } diff --git a/src/RESTAPI/RESTAPI_radiusendpoint_list_handler.cpp b/src/RESTAPI/RESTAPI_radiusendpoint_list_handler.cpp index 647be71..a80027e 100644 --- a/src/RESTAPI/RESTAPI_radiusendpoint_list_handler.cpp +++ b/src/RESTAPI/RESTAPI_radiusendpoint_list_handler.cpp @@ -17,6 +17,12 @@ namespace OpenWifi { return ReturnObject(Answer); } + if(GetBoolParameter("currentStatus")) { + ProvObjects::RADIUSEndpointUpdateStatus Status; + Status.Read(); + return ReturnObject(Status); + } + if(QB_.CountOnly) { return ReturnCountOnly(DB_.Count()); } diff --git a/src/RESTObjects/RESTAPI_ProvObjects.cpp b/src/RESTObjects/RESTAPI_ProvObjects.cpp index fac94af..2a139f5 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.cpp +++ b/src/RESTObjects/RESTAPI_ProvObjects.cpp @@ -1384,4 +1384,53 @@ namespace OpenWifi::ProvObjects { return false; } + void RADIUSEndpointUpdateStatus::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "lastUpdate", lastUpdate); + field_to_json(Obj, "lastConfigurationChange", lastConfigurationChange); + } + + bool RADIUSEndpointUpdateStatus::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "lastUpdate", lastUpdate); + field_from_json(Obj, "lastConfigurationChange", lastConfigurationChange); + return true; + } catch (const Poco::Exception &E) { + + } + return false; + } + + bool RADIUSEndpointUpdateStatus::Read() { + Poco::File F(OpenWifi::MicroServiceDataDirectory()+"/RADIUSEndpointUpdateStatus.json"); + try { + if (F.exists()) { + Poco::JSON::Parser P; + std::ifstream ifs(F.path(), std::ios_base::in | std::ios_base::binary); + auto Obj = P.parse(ifs); + return from_json(Obj.extract()); + } + } catch (...) { + } + return false; + } + + bool RADIUSEndpointUpdateStatus::Save() { + Poco::File F(OpenWifi::MicroServiceDataDirectory()+"/RADIUSEndpointUpdateStatus.json"); + try { + Poco::JSON::Object Obj; + to_json(Obj); + std::ofstream O(F.path(), std::ios_base::out | std::ios_base::trunc | std::ios_base::binary); + Poco::JSON::Stringifier::stringify(Obj, O); + return true; + } catch (...) { + } + return false; + } + + bool RADIUSEndpointUpdateStatus::ChangeConfiguration() { + Read(); + lastConfigurationChange = Utils::Now(); + return Save(); + } + } // namespace OpenWifi::ProvObjects diff --git a/src/RESTObjects/RESTAPI_ProvObjects.h b/src/RESTObjects/RESTAPI_ProvObjects.h index 6cd9725..6014d61 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.h +++ b/src/RESTObjects/RESTAPI_ProvObjects.h @@ -901,4 +901,17 @@ namespace OpenWifi::ProvObjects { void to_json(Poco::JSON::Object &Obj) const; bool from_json(const Poco::JSON::Object::Ptr &Obj); }; + + struct RADIUSEndpointUpdateStatus { + std::uint64_t lastUpdate=0; + std::uint64_t lastConfigurationChange=0; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + bool Read(); + bool Save(); + bool ChangeConfiguration(); + }; + + }; // namespace OpenWifi::ProvObjects diff --git a/src/RadiusEndpointTypes/GlobalReach.cpp b/src/RadiusEndpointTypes/GlobalReach.cpp index 2618057..68960cb 100644 --- a/src/RadiusEndpointTypes/GlobalReach.cpp +++ b/src/RadiusEndpointTypes/GlobalReach.cpp @@ -76,7 +76,6 @@ namespace OpenWifi { ProvObjects::GLBLRCertificateInfo &NewCertificate) { try { - std::cout << __LINE__ << ":" << GlobalReachAccountId << std::endl; auto BearerToken = MakeToken(GlobalReachAccountId); Poco::URI URI{"https://config.openro.am/v1/radsec/issue"}; std::string Path(URI.getPathAndQuery()); diff --git a/src/RadiusEndpointUpdater.h b/src/RadiusEndpointUpdater.h index 5162093..5478323 100644 --- a/src/RadiusEndpointUpdater.h +++ b/src/RadiusEndpointUpdater.h @@ -194,8 +194,10 @@ namespace OpenWifi { GWObjects::RadiusProxyPoolList NewPools; Poco::JSON::Object ErrorObj; if(SDK::GW::RADIUS::SetConfiguration(Client, Pools, NewPools, ErrorObj)) { - AppServiceRegistry().Set("radiusEndpointLastUpdate", Utils::Now()); - return true; + ProvObjects::RADIUSEndpointUpdateStatus Status; + Status.Read(); + Status.lastConfigurationChange = Status.lastUpdate = Utils::Now(); + return Status.Save(); } /* ErrorCode: