stephb9959
2023-10-09 12:52:52 -07:00
parent 91826d136a
commit 2c7b9cf1bd
4 changed files with 83 additions and 76 deletions

View File

@@ -4,6 +4,7 @@
#include "RESTAPI_radius_endpoint_handler.h"
#include <storage/storage_orion_accounts.h>
#include <RESTObjects/RESTAPI_GWobjects.h>
namespace OpenWifi {
@@ -61,27 +62,27 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if(RadiusEndpointDB::EndpointType(NewRecord.Type)==RadiusEndpointDB::EndpointType::unknown) {
if(GWObjects::RadiusEndpointType(NewRecord.Type)==GWObjects::RadiusEndpointType::unknown) {
return BadRequest(RESTAPI::Errors::InvalidRadiusTypeEndpoint);
}
if(RadiusEndpointDB::PoolStrategy(NewRecord.PoolStrategy)==RadiusEndpointDB::PoolStrategy::unknown) {
if(GWObjects::RadiusPoolStrategy(NewRecord.PoolStrategy)==GWObjects::RadiusPoolStrategy::unknown) {
return BadRequest(RESTAPI::Errors::InvalidRadiusEndpointPoolStrategy);
}
if(!NewRecord.RadiusServers.empty() && !NewRecord.RadsecServers.empty()) {
return BadRequest(RESTAPI::Errors::EndpointMustHaveOneTypeOfServers);
}
auto EndPointType = RadiusEndpointDB::EndpointType(NewRecord.Type);
auto EndPointType = GWObjects::RadiusEndpointType(NewRecord.Type);
switch(EndPointType) {
case RadiusEndpointDB::EndpointType::radsec:
case RadiusEndpointDB::EndpointType::orion:
case RadiusEndpointDB::EndpointType::globalreach:
case GWObjects::RadiusEndpointType::radsec:
case GWObjects::RadiusEndpointType::orion:
case GWObjects::RadiusEndpointType::globalreach:
{
if(NewRecord.RadsecServers.empty()) {
return BadRequest(RESTAPI::Errors::EndpointMustHaveOneTypeOfServers);
}
} break;
case RadiusEndpointDB::EndpointType::generic: {
case GWObjects::RadiusEndpointType::generic: {
if(NewRecord.RadiusServers.empty()) {
return BadRequest(RESTAPI::Errors::EndpointMustHaveOneTypeOfServers);
}
@@ -100,7 +101,7 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::RadiusEndpointIndexInvalid);
}
if(EndPointType==RadiusEndpointDB::EndpointType::generic) {
if(EndPointType==GWObjects::RadiusEndpointType::generic) {
for(const auto &Server:NewRecord.RadiusServers) {
if(!ValidRadiusServer(Server.Authentication) ||
!ValidRadiusServer(Server.Accounting) ||
@@ -110,21 +111,21 @@ namespace OpenWifi {
}
} else {
switch(EndPointType) {
case RadiusEndpointDB::EndpointType::orion: {
case GWObjects::RadiusEndpointType::orion: {
for(const auto &Server:NewRecord.RadsecServers) {
if(!StorageService()->OrionAccountsDB().Exists("id",Server.UseOpenRoamingAccount)) {
return BadRequest(RESTAPI::Errors::OrionAccountMustExist);
}
}
} break;
case RadiusEndpointDB::EndpointType::globalreach: {
case GWObjects::RadiusEndpointType::globalreach: {
for(const auto &Server:NewRecord.RadsecServers) {
if(!StorageService()->GLBLRCertsDB().Exists("id",Server.UseOpenRoamingAccount)) {
return BadRequest(RESTAPI::Errors::GlobalReachCertMustExist);
}
}
} break;
case RadiusEndpointDB::EndpointType::radsec: {
case GWObjects::RadiusEndpointType::radsec: {
for(const auto &Server:NewRecord.RadsecServers) {
if(Server.Certificate.empty() || !Utils::ValidX509Certificate(Server.Certificate)) {
return BadRequest(RESTAPI::Errors::InvalidRadsecMainCertificate);

View File

@@ -452,4 +452,48 @@ namespace OpenWifi::GWObjects {
void to_json(Poco::JSON::Object &Obj) const;
};
enum class RadiusPoolStrategy {
round_robbin, random, weighted, unknown
};
enum class RadiusEndpointType {
generic, radsec, globalreach, orion, unknown
};
static inline RadiusEndpointType RadiusEndpointType(const std::string &T) {
if(T=="generic") return RadiusEndpointType::generic;
if(T=="radsec") return RadiusEndpointType::radsec;
if(T=="globalreach") return RadiusEndpointType::globalreach;
if(T=="orion") return RadiusEndpointType::orion;
return RadiusEndpointType::unknown;
}
static inline RadiusPoolStrategy RadiusPoolStrategy(const std::string &T) {
if(T=="round_robbin") return RadiusPoolStrategy::round_robbin;
if(T=="random") return RadiusPoolStrategy::random;
if(T=="weighted") return RadiusPoolStrategy::weighted;
return RadiusPoolStrategy::unknown;
}
static inline std::string to_string(enum RadiusEndpointType T) {
switch(T) {
case RadiusEndpointType::generic: return "generic";
case RadiusEndpointType::radsec: return "radsec";
case RadiusEndpointType::globalreach: return "globalreach";
case RadiusEndpointType::orion: return "orion";
default:
return "unknown";
}
}
static inline std::string to_string(enum RadiusPoolStrategy T) {
switch(T) {
case RadiusPoolStrategy::round_robbin: return "round_robbin";
case RadiusPoolStrategy::random: return "random";
case RadiusPoolStrategy::weighted: return "weighted";
default:
return "unknown";
}
}
} // namespace OpenWifi::GWObjects

View File

@@ -3,6 +3,8 @@
//
#pragma once
#include <vector>
#include <utility>
#include <framework/AppServiceRegistry.h>
#include <framework/utils.h>
#include <StorageService.h>
@@ -41,6 +43,27 @@ namespace OpenWifi {
}
}
void UpdateRadiusServerEntry( GWObjects::RadiusProxyServerConfig &Config,
const ProvObjects::RADIUSEndPoint &Endpoint,
const std::vector<ProvObjects::RADIUSServer> &Servers) {
Config.monitor = false;
Config.strategy = Endpoint.PoolStrategy;
Config.monitorMethod = "none";
Config.strategy = "random";
for (const auto &Server: Servers) {
GWObjects::RadiusProxyServerEntry PE;
PE.radsec = false;
PE.name = Server.Hostname;
PE.ignore = false;
PE.ip = Server.IP;
PE.port = PE.radsecPort = Server.Port;
PE.allowSelfSigned = false;
PE.weight = 10;
PE.secret = PE.radsecSecret = "radsec";
Config.servers.emplace_back(PE);
}
}
inline bool UpdateEndpoints( RESTAPIHandler *Client, std::uint64_t & ErrorCode,
std::string & ErrorDetails,
std::string & ErrorDescription) {
@@ -156,28 +179,11 @@ namespace OpenWifi {
Pools.pools.emplace_back(PP);
} else if(Endpoint.Type=="generic" && !Endpoint.RadiusServers.empty()) {
PP.radsecPoolType="generic";
/* const auto &server = Endpoint.RadiusServers[0];
for(auto &[ServerType,ServerInfo] : {
{}AUTH, Endpoint.RadiusServers[0].Authentication[0]) ,
std::pair(ACCT, Endpoint.RadiusServers[0].Accounting[0] ),
std::pair(COA, Endpoint.RadiusServers[0].Accounting[0]) }
) {
ServerType.
ServerType.monitor = false;
ServerType.strategy = Endpoint.PoolStrategy;
GWObjects::RadiusProxyServerEntry PE;
PE.radsec = false;
PE.name = ServerInfo.Hostname;
PE.ignore = false;
PE.ip = ServerInfo.IP;
PE.port = PE.radsecPort = ServerInfo.Port;
PE.allowSelfSigned = false;
PE.weight = 10;
PE.secret = PE.radsecSecret = "radsec";
ServerType.servers.emplace_back(PE);
}
UpdateRadiusServerEntry(PP.authConfig, Endpoint, Endpoint.RadiusServers[0].Authentication);
UpdateRadiusServerEntry(PP.acctConfig, Endpoint, Endpoint.RadiusServers[0].Accounting);
UpdateRadiusServerEntry(PP.coaConfig, Endpoint, Endpoint.RadiusServers[0].CoA);
Pools.pools.emplace_back(PP);
*/ }
}
}
/*

View File

@@ -33,50 +33,6 @@ namespace OpenWifi {
virtual ~RadiusEndpointDB(){};
bool Upgrade(uint32_t from, uint32_t &to) override;
enum class PoolStrategy {
round_robbin, random, weighted, unknown
};
enum class EndpointType {
generic, radsec, globalreach, orion, unknown
};
static inline EndpointType EndpointType(const std::string &T) {
if(T=="generic") return EndpointType::generic;
if(T=="radsec") return EndpointType::radsec;
if(T=="globalreach") return EndpointType::globalreach;
if(T=="orion") return EndpointType::orion;
return EndpointType::unknown;
}
static inline PoolStrategy PoolStrategy(const std::string &T) {
if(T=="round_robbin") return PoolStrategy::round_robbin;
if(T=="random") return PoolStrategy::random;
if(T=="weighted") return PoolStrategy::weighted;
return PoolStrategy::unknown;
}
static inline std::string to_string(enum EndpointType T) {
switch(T) {
case EndpointType::generic: return "generic";
case EndpointType::radsec: return "radsec";
case EndpointType::globalreach: return "globalreach";
case EndpointType::orion: return "orion";
default:
return "unknown";
}
}
static inline std::string to_string(enum PoolStrategy T) {
switch(T) {
case PoolStrategy::round_robbin: return "round_robbin";
case PoolStrategy::random: return "random";
case PoolStrategy::weighted: return "weighted";
default:
return "unknown";
}
}
static inline bool ValidIndex(const std::string &I) {
static uint32_t Low = Utils::IPtoInt("0.0.1.1");
static uint32_t High = Utils::IPtoInt("0.0.2.254");