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/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

2
build
View File

@@ -1 +1 @@
67
70

View File

@@ -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:

View File

@@ -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;

View File

@@ -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));

View File

@@ -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

View File

@@ -14,6 +14,7 @@ namespace OpenWifi {
bool Internal)
: RESTAPIHandler(bindings, L,
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_PUT,
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, TransactionId, Internal) {}
static auto PathName() { return std::list<std::string>{"/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

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.
//
#ifndef OWPROV_RADIUSENDPOINT_H
#define OWPROV_RADIUSENDPOINT_H
#pragma once
#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
#endif //OWPROV_RADIUSENDPOINT_H