diff --git a/src/RESTAPI/RESTAPI_radius_endpoint_handler.cpp b/src/RESTAPI/RESTAPI_radius_endpoint_handler.cpp index 36f42ef..d3f5d82 100644 --- a/src/RESTAPI/RESTAPI_radius_endpoint_handler.cpp +++ b/src/RESTAPI/RESTAPI_radius_endpoint_handler.cpp @@ -5,6 +5,14 @@ #include "RESTAPI_radius_endpoint_handler.h" namespace OpenWifi { + static inline bool ValidEndpointTypes(const std::string &T) { + return T=="radius" || T=="radsec"; + } + + static inline bool ValidPoolStrategy(const std::string &T) { + return T=="none" || T=="tandom" || T=="weighted"; + } + void RESTAPI_radius_endpoint_handler::DoGet() { auto id = GetBinding("id"); if(id.empty()) { @@ -44,6 +52,19 @@ namespace OpenWifi { return BadRequest(RESTAPI::Errors::InvalidJSONDocument); } + if(!ValidEndpointTypes(NewRecord.Type)) { + return BadRequest(RESTAPI::Errors::InvalidRadiusTypeEndpoint); + } + if(!ValidPoolStrategy(NewRecord.PoolStrategy)) { + return BadRequest(RESTAPI::Errors::InvalidRadiusEndpointPoolStrategy); + } + if(!NewRecord.RadiusServers.empty() && !NewRecord.RadsecServers.empty()) { + return BadRequest(RESTAPI::Errors::EndpointMustHaveOneTypeOfServers); + } + if(NewRecord.Index.empty()) { + return BadRequest(RESTAPI::Errors::RadiusEndpointIndexInvalid); + } + ProvObjects::CreateObjectInfo(RawObject,UserInfo_.userinfo,NewRecord.info); if(DB_.CreateRecord(NewRecord)) { RecordType AddedRecord; diff --git a/src/framework/ow_constants.h b/src/framework/ow_constants.h index 370ab40..870dfc5 100644 --- a/src/framework/ow_constants.h +++ b/src/framework/ow_constants.h @@ -414,10 +414,12 @@ namespace OpenWifi::RESTAPI::Errors { }; static const struct msg DefFirmwareNameExists { 1175, "Firmware name already exists." }; - static const struct msg NotAValidECKey { 1176, "Not a valid Signing Key." }; - static const struct msg NotAValidRadiusPoolType { 1177, "Not a valid RADIUS pool type." }; + static const struct msg InvalidRadiusTypeEndpoint { 1178, "Invalid RADIUS Server Endpoint type." }; + static const struct msg InvalidRadiusEndpointPoolStrategy { 1179, "Invalid RADIUS Server Endpoint Pool strategy." }; + static const struct msg EndpointMustHaveOneTypeOfServers { 1180, "All servers must be either RADIUS or RADSEC." }; + static const struct msg RadiusEndpointIndexInvalid { 1181, "Index must be an address between 0.0.1.1 and 0.0.2.254" }; static const struct msg SimulationDoesNotExist { 7000, "Simulation Instance ID does not exist."