From 87c4b714b1b89465619af489f0ff436cfe5a2d90 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Mon, 2 Oct 2023 22:28:47 -0700 Subject: [PATCH] https://telecominfraproject.atlassian.net/browse/WIFI-7831 Signed-off-by: stephb9959 --- CMakeLists.txt | 4 +- build | 2 +- openapi/openroaming_globalreach.yaml | 20 ++--- openapi/openroaming_orion.yaml | 12 +-- ...ius_tunnels.yaml => radius_endpoints.yaml} | 5 ++ src/APConfig.cpp | 10 +-- src/Daemon.cpp | 6 +- src/OpenRoaming/OrionWifi.h | 25 ------ .../RESTAPI_openroaming_gr_acct_handler.cpp | 2 +- .../RESTAPI_openroaming_gr_cert_handler.cpp | 2 +- src/RESTObjects/RESTAPI_ProvObjects.cpp | 4 + src/RESTObjects/RESTAPI_ProvObjects.h | 2 + .../GlobalReach.cpp | 35 +++++++- .../GlobalReach.h | 2 + src/RadiusEndpointTypes/OrionWifi.h | 79 +++++++++++++++++++ src/storage/storage_radius_endpoints.cpp | 13 ++- src/storage/storage_radius_endpoints.h | 4 +- 17 files changed, 166 insertions(+), 61 deletions(-) rename openapi/{radius_tunnels.yaml => radius_endpoints.yaml} (98%) delete mode 100644 src/OpenRoaming/OrionWifi.h rename src/{OpenRoaming => RadiusEndpointTypes}/GlobalReach.cpp (88%) rename src/{OpenRoaming => RadiusEndpointTypes}/GlobalReach.h (94%) create mode 100644 src/RadiusEndpointTypes/OrionWifi.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 54e77be..43dd0b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -225,8 +225,8 @@ add_executable(owprov src/RESTAPI/RESTAPI_radiusendpoint_list_handler.h src/RESTAPI/RESTAPI_radius_endpoint_handler.cpp src/RESTAPI/RESTAPI_radius_endpoint_handler.h - src/OpenRoaming/GlobalReach.cpp src/OpenRoaming/GlobalReach.h - src/OpenRoaming/OrionWifi.h + src/RadiusEndpointTypes/GlobalReach.cpp src/RadiusEndpointTypes/GlobalReach.h + src/RadiusEndpointTypes/OrionWifi.h src/RadiusEndpoint.cpp src/RadiusEndpoint.h ) diff --git a/build b/build index b2412e3..8323328 100644 --- a/build +++ b/build @@ -1 +1 @@ -62 \ No newline at end of file +67 \ No newline at end of file diff --git a/openapi/openroaming_globalreach.yaml b/openapi/openroaming_globalreach.yaml index 2a91951..f778168 100644 --- a/openapi/openroaming_globalreach.yaml +++ b/openapi/openroaming_globalreach.yaml @@ -1,6 +1,6 @@ openapi: 3.0.1 info: - title: OpenWiFi OpenRoaming Provisioning Model for Global Reach + title: OpenWiFi RadiusEndpointTypes Provisioning Model for Global Reach description: Definitions and APIs to Open Roaming WiFi. version: 2.5.0 license: @@ -92,7 +92,7 @@ paths: /openroaming/globalreach/accounts: get: tags: - - OpenRoaming-Global Reach + - RadiusEndpointTypes-Global Reach operationId: getOpenRoamingGlobalReachAccountList summary: Retrieve account list. parameters: @@ -135,7 +135,7 @@ paths: /openroaming/globalreach/account/{name}: get: tags: - - OpenRoaming-Global Reach + - RadiusEndpointTypes-Global Reach operationId: getOpenRoamingGlobalReachAccount summary: Retrieve account information. parameters: @@ -157,7 +157,7 @@ paths: delete: tags: - - OpenRoaming-Global Reach + - RadiusEndpointTypes-Global Reach operationId: deleteOpenRoamingGlobalReachAccount summary: Delete account information. parameters: @@ -179,7 +179,7 @@ paths: post: tags: - - OpenRoaming-Global Reach + - RadiusEndpointTypes-Global Reach operationId: createOpenRoamingGlobalReachAccount summary: Create account information. parameters: @@ -206,7 +206,7 @@ paths: put: tags: - - OpenRoaming-Global Reach + - RadiusEndpointTypes-Global Reach operationId: modifyOpenRoamingGlobalReachAccount summary: Modify account information. parameters: @@ -234,7 +234,7 @@ paths: /openroaming/globalreach/certificates/{account}: get: tags: - - OpenRoaming-Global Reach Certificate + - RadiusEndpointTypes-Global Reach Certificate operationId: getOpenRoamingGlobalReachCertificateList summary: Retrieve certificate list. parameters: @@ -283,7 +283,7 @@ paths: /openroaming/globalreach/certificate/{account}/{id}: get: tags: - - OpenRoaming-Global Reach Certificate + - RadiusEndpointTypes-Global Reach Certificate operationId: getOpenRoamingGlobalReachCertificate summary: Retrieve certificate information. parameters: @@ -311,7 +311,7 @@ paths: delete: tags: - - OpenRoaming-Global Reach Certificate + - RadiusEndpointTypes-Global Reach Certificate operationId: deleteOpenRoamingGlobalReachCertificate summary: Delete certificate information. parameters: @@ -339,7 +339,7 @@ paths: post: tags: - - OpenRoaming-Global Reach Certificate + - RadiusEndpointTypes-Global Reach Certificate operationId: createOpenRoamingGlobalReachCertificate summary: Create certificate information. parameters: diff --git a/openapi/openroaming_orion.yaml b/openapi/openroaming_orion.yaml index 0dd0e66..07617cd 100644 --- a/openapi/openroaming_orion.yaml +++ b/openapi/openroaming_orion.yaml @@ -1,6 +1,6 @@ openapi: 3.0.1 info: - title: OpenWiFi OpenRoaming Provisioning Model for Google Orion + title: OpenWiFi RadiusEndpointTypes Provisioning Model for Google Orion description: Definitions and APIs to Open Roaming WiFi. version: 2.5.0 license: @@ -54,7 +54,7 @@ paths: /openroaming/orion/accounts: get: tags: - - OpenRoaming-Google Orion + - RadiusEndpointTypes-Google Orion operationId: getOpenRoamingGlobalReachAccountList summary: Retrieve account list. parameters: @@ -97,7 +97,7 @@ paths: /openroaming/orion/account/{id}: get: tags: - - OpenRoaming-Google Orion + - RadiusEndpointTypes-Google Orion operationId: getOpenRoamingGlobalReachAccount summary: Retrieve account information. parameters: @@ -119,7 +119,7 @@ paths: delete: tags: - - OpenRoaming-Google Orion + - RadiusEndpointTypes-Google Orion operationId: deleteOpenRoamingGlobalReachAccount summary: Delete account information. parameters: @@ -141,7 +141,7 @@ paths: post: tags: - - OpenRoaming-Google Orion + - RadiusEndpointTypes-Google Orion operationId: createOpenRoamingGlobalReachAccount summary: Create account information. parameters: @@ -168,7 +168,7 @@ paths: put: tags: - - OpenRoaming-Google Orion + - RadiusEndpointTypes-Google Orion operationId: modifyOpenRoamingGlobalReachAccount summary: Modify account information. parameters: diff --git a/openapi/radius_tunnels.yaml b/openapi/radius_endpoints.yaml similarity index 98% rename from openapi/radius_tunnels.yaml rename to openapi/radius_endpoints.yaml index eac4bcb..dcb9395 100644 --- a/openapi/radius_tunnels.yaml +++ b/openapi/radius_endpoints.yaml @@ -133,6 +133,11 @@ components: items: type: string format: uuid + NasIdentifier: + type: string + AccountingInterval: + type: integer + format: int64 paths: /RADIUSEndPoints: diff --git a/src/APConfig.cpp b/src/APConfig.cpp index 74fa538..3e6ab18 100644 --- a/src/APConfig.cpp +++ b/src/APConfig.cpp @@ -9,8 +9,8 @@ #include "Poco/StringTokenizer.h" #include "fmt/format.h" -#include -#include +#include +#include namespace OpenWifi { @@ -62,11 +62,9 @@ namespace OpenWifi { if(RE.UseGWProxy) { Poco::JSON::Object ServerSettings; if (RE.Type == "orion") { - auto OrionServers = Orion::GetServers(); - + OpenRoaming_Orion()->Render(RE, Result); } else if (RE.Type == "globalreach") { - auto GRServers = GlobalReach::GetServers(); - + OpenRoaming_GlobalReach()->Render(RE, Result); } else if (RE.Type == "radsec") { } else if (RE.Type == "radius") { diff --git a/src/Daemon.cpp b/src/Daemon.cpp index 17391fe..8b84600 100644 --- a/src/Daemon.cpp +++ b/src/Daemon.cpp @@ -23,7 +23,8 @@ #include "UI_Prov_WebSocketNotifications.h" #include "framework/ConfigurationValidator.h" #include "framework/UI_WebSocketClientServer.h" -#include +#include +#include namespace OpenWifi { class Daemon *Daemon::instance_ = nullptr; @@ -37,7 +38,8 @@ namespace OpenWifi { AutoDiscovery(), JobController(), UI_WebSocketClientServer(), FindCountryFromIP(), Signup(), FileDownloader(), - OpenRoaming_GlobalReach() + OpenRoaming_GlobalReach(), + OpenRoaming_Orion() }); } return instance_; diff --git a/src/OpenRoaming/OrionWifi.h b/src/OpenRoaming/OrionWifi.h deleted file mode 100644 index 2993899..0000000 --- a/src/OpenRoaming/OrionWifi.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// Created by stephane bourque on 2023-09-28. -// - -#pragma once - -#include -#include -#include - -namespace OpenWifi { - - namespace Orion { - static inline const std::vector OrionWifiServerAddresses = { - { "216.239.32.91", 2083 }, - { "216.239.34.91", 2083 } - }; - - inline std::vector GetServers() { - return OrionWifiServerAddresses; - } - - } - -} \ No newline at end of file diff --git a/src/RESTAPI/RESTAPI_openroaming_gr_acct_handler.cpp b/src/RESTAPI/RESTAPI_openroaming_gr_acct_handler.cpp index f0c5b3e..f79e731 100644 --- a/src/RESTAPI/RESTAPI_openroaming_gr_acct_handler.cpp +++ b/src/RESTAPI/RESTAPI_openroaming_gr_acct_handler.cpp @@ -3,7 +3,7 @@ // #include "RESTAPI_openroaming_gr_acct_handler.h" -#include +#include namespace OpenWifi { diff --git a/src/RESTAPI/RESTAPI_openroaming_gr_cert_handler.cpp b/src/RESTAPI/RESTAPI_openroaming_gr_cert_handler.cpp index bbcccb0..5f8b351 100644 --- a/src/RESTAPI/RESTAPI_openroaming_gr_cert_handler.cpp +++ b/src/RESTAPI/RESTAPI_openroaming_gr_cert_handler.cpp @@ -3,7 +3,7 @@ // #include "RESTAPI_openroaming_gr_cert_handler.h" -#include +#include namespace OpenWifi { diff --git a/src/RESTObjects/RESTAPI_ProvObjects.cpp b/src/RESTObjects/RESTAPI_ProvObjects.cpp index 85129c4..7e21685 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.cpp +++ b/src/RESTObjects/RESTAPI_ProvObjects.cpp @@ -1361,6 +1361,8 @@ namespace OpenWifi::ProvObjects { field_to_json(Obj, "Index", Index); field_to_json(Obj, "UsedBy", UsedBy); field_to_json(Obj, "UseGWProxy", UseGWProxy); + field_to_json(Obj, "NasIdentifier", NasIdentifier); + field_to_json(Obj, "AccountingInterval", AccountingInterval); } bool RADIUSEndPoint::from_json(const Poco::JSON::Object::Ptr &Obj) { @@ -1373,6 +1375,8 @@ namespace OpenWifi::ProvObjects { field_from_json(Obj, "Index", Index); field_from_json(Obj, "UsedBy", UsedBy); field_from_json(Obj, "UseGWProxy", UseGWProxy); + field_from_json(Obj, "NasIdentifier", NasIdentifier); + field_from_json(Obj, "AccountingInterval", AccountingInterval); return true; } catch (const Poco::Exception &E) { diff --git a/src/RESTObjects/RESTAPI_ProvObjects.h b/src/RESTObjects/RESTAPI_ProvObjects.h index 7914f86..2c78d16 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.h +++ b/src/RESTObjects/RESTAPI_ProvObjects.h @@ -895,6 +895,8 @@ namespace OpenWifi::ProvObjects { std::vector UsedBy; std::vector RadiusServers; std::vector RadsecServers; + std::string NasIdentifier{"{{$serialNumber}}"}; + std::uint64_t AccountingInterval=600; void to_json(Poco::JSON::Object &Obj) const; bool from_json(const Poco::JSON::Object::Ptr &Obj); diff --git a/src/OpenRoaming/GlobalReach.cpp b/src/RadiusEndpointTypes/GlobalReach.cpp similarity index 88% rename from src/OpenRoaming/GlobalReach.cpp rename to src/RadiusEndpointTypes/GlobalReach.cpp index 7fec166..bbbaceb 100644 --- a/src/OpenRoaming/GlobalReach.cpp +++ b/src/RadiusEndpointTypes/GlobalReach.cpp @@ -41,11 +41,38 @@ namespace OpenWifi { StorageService()->GLBLRAccountInfoDB().Iterate(F); } + bool OpenRoaming::Render(const OpenWifi::ProvObjects::RADIUSEndPoint &RE, Poco::JSON::Object::Ptr &Result) { + if(RE.UseGWProxy) { + Poco::JSON::Object Auth, Acct, CoA; + + Auth.set("host", RE.Index); + Auth.set("port", 1812 ); + Auth.set("secret", RE.RadsecServers[0].Secret); + + Acct.set("host", RE.Index); + Acct.set("port", 1813); + Acct.set("secret", RE.RadsecServers[0].Secret); + Acct.set("interval", RE.AccountingInterval); + + CoA.set("host", RE.Index); + CoA.set("port", 3799); + CoA.set("secret", RE.RadsecServers[0].Secret); + + Result->set("nas-identifier", RE.NasIdentifier); + Result->set("authentication", Auth); + Result->set("accounting", Acct); + Result->set("dynamic-authorization", CoA); + } else { + + } + return false; + } + bool OpenRoaming::CreateRADSECCertificate( - const std::string &GlobalReachAccountId, - const std::string &Name, - const std::string &CSR, - ProvObjects::GLBLRCertificateInfo &NewCertificate) { + const std::string &GlobalReachAccountId, + const std::string &Name, + const std::string &CSR, + ProvObjects::GLBLRCertificateInfo &NewCertificate) { try { std::cout << __LINE__ << ":" << GlobalReachAccountId << std::endl; diff --git a/src/OpenRoaming/GlobalReach.h b/src/RadiusEndpointTypes/GlobalReach.h similarity index 94% rename from src/OpenRoaming/GlobalReach.h rename to src/RadiusEndpointTypes/GlobalReach.h index 6e73014..abfe33d 100644 --- a/src/OpenRoaming/GlobalReach.h +++ b/src/RadiusEndpointTypes/GlobalReach.h @@ -36,6 +36,8 @@ namespace OpenWifi { void InitCache(); + bool Render(const OpenWifi::ProvObjects::RADIUSEndPoint &RE, Poco::JSON::Object::Ptr &Result); + private: std::string MakeToken(const std::string &GlobalReachAccountId, const std::string &PrivateKey = ""); diff --git a/src/RadiusEndpointTypes/OrionWifi.h b/src/RadiusEndpointTypes/OrionWifi.h new file mode 100644 index 0000000..c95d50a --- /dev/null +++ b/src/RadiusEndpointTypes/OrionWifi.h @@ -0,0 +1,79 @@ +// +// Created by stephane bourque on 2023-09-28. +// + +#pragma once + +#include +#include +#include +#include + +namespace OpenWifi { + + namespace Orion { + + class OpenRoaming : public SubSystemServer { + public: + static auto instance() { + static auto instance_ = new OpenRoaming; + return instance_; + } + + inline int Start() override { + + return 0; + } + + inline void Stop() override { + + } + + static inline const std::vector OrionWifiServerAddresses = { + {"216.239.32.91", 2083}, + {"216.239.34.91", 2083} + }; + + inline std::vector GetServers() { + return OrionWifiServerAddresses; + } + + inline bool Render(const OpenWifi::ProvObjects::RADIUSEndPoint &RE, Poco::JSON::Object::Ptr &Result) { + if(RE.UseGWProxy) { + Poco::JSON::Object Auth, Acct, CoA; + + Auth.set("host", RE.Index); + Auth.set("port", 1812 ); + Auth.set("secret", RE.RadsecServers[0].Secret); + + Acct.set("host", RE.Index); + Acct.set("port", 1813); + Acct.set("secret", RE.RadsecServers[0].Secret); + Acct.set("interval", RE.AccountingInterval); + + CoA.set("host", RE.Index); + CoA.set("port", 3799); + CoA.set("secret", RE.RadsecServers[0].Secret); + + Result->set("nas-identifier", RE.NasIdentifier); + Result->set("authentication", Auth); + Result->set("accounting", Acct); + Result->set("dynamic-authorization", CoA); + + } else { + + } + return false; + } + + private: + OpenRoaming() noexcept + : SubSystemServer("OpenRoaming_Orion", "ORION", "orion") { + } + }; + + } + + inline auto OpenRoaming_Orion() { return Orion::OpenRoaming::instance(); } + +} \ No newline at end of file diff --git a/src/storage/storage_radius_endpoints.cpp b/src/storage/storage_radius_endpoints.cpp index a63e1cb..ee83cde 100644 --- a/src/storage/storage_radius_endpoints.cpp +++ b/src/storage/storage_radius_endpoints.cpp @@ -19,7 +19,9 @@ namespace OpenWifi { ORM::Field{"PoolStrategy", ORM::FieldType::FT_TEXT}, ORM::Field{"Index", ORM::FieldType::FT_TEXT}, ORM::Field{"UsedBy", ORM::FieldType::FT_TEXT}, - ORM::Field{"UseGWProxy", ORM::FieldType::FT_BOOLEAN} + ORM::Field{"UseGWProxy", ORM::FieldType::FT_BOOLEAN}, + ORM::Field{"NasIdentifier", ORM::FieldType::FT_TEXT}, + ORM::Field{"AccountingInterval", ORM::FieldType::FT_BIGINT} }; static ORM::IndexVec RadiusEndpointDB_Indexes{ @@ -31,7 +33,10 @@ namespace OpenWifi { bool RadiusEndpointDB::Upgrade([[maybe_unused]] uint32_t from, uint32_t &to) { to = Version(); - std::vector Script{}; + std::vector Script{ + "alter table " + TableName_ + " add column NasIdentifier TEXT;" + "alter table " + TableName_ + " add column AccountingInterval BIGINT;", + }; for (const auto &i : Script) { try { @@ -62,6 +67,8 @@ void ORM::DB(); Out.UsedBy = OpenWifi::RESTAPI_utils::to_object_array(In.get<11>()); Out.UseGWProxy = In.get<12>(); + Out.NasIdentifier = In.get<13>(); + Out.AccountingInterval = In.get<14>(); } template <> @@ -80,4 +87,6 @@ void ORM::DB(In.Index); Out.set<11>(OpenWifi::RESTAPI_utils::to_string(In.UsedBy)); Out.set<12>(In.UseGWProxy); + Out.set<13>(In.NasIdentifier); + Out.set<14>(In.AccountingInterval); } diff --git a/src/storage/storage_radius_endpoints.h b/src/storage/storage_radius_endpoints.h index db24478..2253915 100644 --- a/src/storage/storage_radius_endpoints.h +++ b/src/storage/storage_radius_endpoints.h @@ -22,7 +22,9 @@ namespace OpenWifi { std::string, std::string, std::string, - bool + bool, + std::string, + std::uint64_t > RadiusEndpointDbRecordType; class RadiusEndpointDB : public ORM::DB {