stephb9959
2023-10-03 21:52:56 -07:00
parent 7dd33ca841
commit 69e507a5bd
10 changed files with 120 additions and 50 deletions

View File

@@ -227,8 +227,8 @@ add_executable(owprov
src/RESTAPI/RESTAPI_radius_endpoint_handler.h src/RESTAPI/RESTAPI_radius_endpoint_handler.h
src/RadiusEndpointTypes/GlobalReach.cpp src/RadiusEndpointTypes/GlobalReach.h src/RadiusEndpointTypes/GlobalReach.cpp src/RadiusEndpointTypes/GlobalReach.h
src/RadiusEndpointTypes/OrionWifi.h src/RadiusEndpointTypes/OrionWifi.h
src/RadiusEndpoint.cpp src/RadiusEndpointUpdater.cpp
src/RadiusEndpoint.h src/RadiusEndpointUpdater.h
) )
target_link_libraries(owprov PUBLIC target_link_libraries(owprov PUBLIC

2
build
View File

@@ -1 +1 @@
67 70

View File

@@ -165,15 +165,58 @@ paths:
schema: schema:
type: boolean type: boolean
required: false required: false
- in: query
description: return the last update time
name: lastUpdate
schema:
type: boolean
required: false
responses: responses:
200: 200:
description: The list of endpoints description: The list of endpoints
content: content:
application/json: application/json:
schema: schema:
type: array oneOf:
- type: array
items: items:
$ref: '#/components/schemas/RADIUSEndPoint' $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: 400:
$ref: '#/components/responses/BadRequest' $ref: '#/components/responses/BadRequest'
403: 403:

View File

@@ -59,26 +59,19 @@ namespace OpenWifi {
} }
bool APConfig::InsertRadiusEndPoint(const ProvObjects::RADIUSEndPoint &RE, Poco::JSON::Object &Result) { bool APConfig::InsertRadiusEndPoint(const ProvObjects::RADIUSEndPoint &RE, Poco::JSON::Object &Result) {
DBGLINE
if(RE.UseGWProxy) { if(RE.UseGWProxy) {
DBGLINE
Poco::JSON::Object ServerSettings; Poco::JSON::Object ServerSettings;
if (RE.Type == "orion") { if (RE.Type == "orion") {
DBGLINE
return OpenRoaming_Orion()->Render(RE, Result); return OpenRoaming_Orion()->Render(RE, Result);
} else if (RE.Type == "globalreach") { } else if (RE.Type == "globalreach") {
DBGLINE
return OpenRoaming_GlobalReach()->Render(RE, Result); return OpenRoaming_GlobalReach()->Render(RE, Result);
} else if (RE.Type == "radsec") { } else if (RE.Type == "radsec") {
DBGLINE
} else if (RE.Type == "radius") { } else if (RE.Type == "radius") {
DBGLINE
} }
Result.set( "radius" , ServerSettings); Result.set( "radius" , ServerSettings);
} }
DBGLINE
return false; return false;
} }
@@ -87,7 +80,6 @@ namespace OpenWifi {
// get all the names and expand // get all the names and expand
auto Names = Original.getNames(); auto Names = Original.getNames();
for (const auto &i : Names) { for (const auto &i : Names) {
DBGLINE
if (i == "__variableBlock") { if (i == "__variableBlock") {
if (Original.isArray(i)) { if (Original.isArray(i)) {
auto UUIDs = Original.getArray(i); auto UUIDs = Original.getArray(i);
@@ -101,13 +93,14 @@ namespace OpenWifi {
auto VarNames = VariableBlockInfo->getNames(); auto VarNames = VariableBlockInfo->getNames();
for (const auto &j: VarNames) { for (const auto &j: VarNames) {
std::cout << "Name: " << j << std::endl; std::cout << "Name: " << j << std::endl;
Poco::JSON::Object InnerEval;
if(VariableBlockInfo->isArray(j)) { if(VariableBlockInfo->isArray(j)) {
auto Arr = VariableBlockInfo->getArray(j); auto Elements = VariableBlockInfo->getArray(j);
// ReplaceVariablesInObject(,InnerEval); Poco::JSON::Array InnerArray;
// Result->set(j, InnerEval); ReplaceVariablesInArray(*Elements,InnerArray);
Result.set(j,InnerArray);
std::cout << "Array!!!" << std::endl; std::cout << "Array!!!" << std::endl;
} else if(VariableBlockInfo->isObject(j)) { } else if(VariableBlockInfo->isObject(j)) {
Poco::JSON::Object InnerEval;
std::cout << "Visiting object " << j << std::endl; std::cout << "Visiting object " << j << std::endl;
auto O = VariableBlockInfo->getObject(j); auto O = VariableBlockInfo->getObject(j);
ReplaceVariablesInObject(*O,InnerEval); ReplaceVariablesInObject(*O,InnerEval);
@@ -121,40 +114,27 @@ namespace OpenWifi {
} }
} }
} else if (i == "__radiusEndpoint") { } else if (i == "__radiusEndpoint") {
DBGLINE
auto EndPointId = Original.get(i).toString(); auto EndPointId = Original.get(i).toString();
DBGLINE
ProvObjects::RADIUSEndPoint RE; ProvObjects::RADIUSEndPoint RE;
DBGLINE
std::cout << "ID->" << EndPointId << std::endl; std::cout << "ID->" << EndPointId << std::endl;
if(StorageService()->RadiusEndpointDB().GetRecord("id",EndPointId,RE)) { if(StorageService()->RadiusEndpointDB().GetRecord("id",EndPointId,RE)) {
DBGLINE
InsertRadiusEndPoint(RE, Result); InsertRadiusEndPoint(RE, Result);
DBGLINE
} else { } else {
DBGLINE
poco_error(Logger_, fmt::format("RADIUS Endpoint {} could not be found. Please delete this configuration and recreate it.")); poco_error(Logger_, fmt::format("RADIUS Endpoint {} could not be found. Please delete this configuration and recreate it."));
return false; return false;
} }
DBGLINE
} else if (Original.isArray(i)) { } else if (Original.isArray(i)) {
DBGLINE
Poco::JSON::Array Arr; Poco::JSON::Array Arr;
auto Obj = Original.getArray(i); auto Obj = Original.getArray(i);
ReplaceVariablesInArray(*Obj, Arr); ReplaceVariablesInArray(*Obj, Arr);
Result.set(i, Arr); Result.set(i, Arr);
DBGLINE
} else if (Original.isObject(i)) { } else if (Original.isObject(i)) {
DBGLINE
Poco::JSON::Object Expanded; Poco::JSON::Object Expanded;
auto Obj = Original.getObject(i); auto Obj = Original.getObject(i);
ReplaceVariablesInObject(*Obj, Expanded); ReplaceVariablesInObject(*Obj, Expanded);
Result.set(i, Expanded); Result.set(i, Expanded);
DBGLINE
} else { } else {
DBGLINE
Result.set(i, Original.get(i)); Result.set(i, Original.get(i));
DBGLINE
} }
} }
return true; return true;

View File

@@ -12,6 +12,17 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); 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); auto Where = fmt::format(" accountId='{}'", Account);
if(GetBoolParameter("countOnly")) { if(GetBoolParameter("countOnly")) {
return ReturnCountOnly(DB_.Count(Where)); return ReturnCountOnly(DB_.Count(Where));

View File

@@ -3,10 +3,20 @@
// //
#include "RESTAPI_radiusendpoint_list_handler.h" #include "RESTAPI_radiusendpoint_list_handler.h"
#include "framework/AppServiceRegistry.h"
#include "RadiusEndpointUpdater.h"
namespace OpenWifi { namespace OpenWifi {
void RESTAPI_radiusendpoint_list_handler::DoGet() { 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) { if(QB_.CountOnly) {
return ReturnCountOnly(DB_.Count()); return ReturnCountOnly(DB_.Count());
} }
@@ -15,4 +25,25 @@ namespace OpenWifi {
return ReturnObject(Records); 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 } // OpenWifi

View File

@@ -14,6 +14,7 @@ namespace OpenWifi {
bool Internal) bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_PUT,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, TransactionId, Internal) {} Server, TransactionId, Internal) {}
static auto PathName() { return std::list<std::string>{"/api/v1/RADIUSEndPoints"}; }; static auto PathName() { return std::list<std::string>{"/api/v1/RADIUSEndPoints"}; };
@@ -23,7 +24,7 @@ namespace OpenWifi {
RadiusEndpointDB &DB_ = StorageService()->RadiusEndpointDB(); RadiusEndpointDB &DB_ = StorageService()->RadiusEndpointDB();
void DoGet() final; void DoGet() final;
void DoPost() final{}; void DoPost() final{};
void DoPut() final{}; void DoPut() final;
void DoDelete() final{}; void DoDelete() final{};
}; };
} // namespace OpenWifi } // namespace OpenWifi

View File

@@ -1,8 +0,0 @@
//
// Created by stephane bourque on 2023-10-02.
//
#include "RadiusEndpoint.h"
namespace OpenWifi {
} // OpenWifi

View File

@@ -0,0 +1,5 @@
//
// Created by stephane bourque on 2023-10-02.
//
#include "RadiusEndpointUpdater.h"

View File

@@ -2,8 +2,9 @@
// Created by stephane bourque on 2023-10-02. // Created by stephane bourque on 2023-10-02.
// //
#ifndef OWPROV_RADIUSENDPOINT_H #pragma once
#define OWPROV_RADIUSENDPOINT_H #include <framework/AppServiceRegistry.h>
#include <framework/utils.h>
/* /*
@@ -110,12 +111,18 @@
*/ */
namespace OpenWifi { #include <string>
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 } // OpenWifi
#endif //OWPROV_RADIUSENDPOINT_H