Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-7831
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Oct 4, 2023
1 parent fcce87d commit a8581f8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 80 deletions.
36 changes: 0 additions & 36 deletions src/RESTAPI/RESTAPI_radius_endpoint_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,49 +111,13 @@ namespace OpenWifi {
if(!StorageService()->OrionAccountsDB().Exists("id",Server.UseOpenRoamingAccount)) {
return BadRequest(RESTAPI::Errors::OrionAccountMustExist);
}
if(Server.Certificate.empty() || !Utils::ValidX509Certificate(Server.Certificate)) {
return BadRequest(RESTAPI::Errors::InvalidRadsecMainCertificate);
}
if(Server.CaCerts.empty() || !Utils::ValidX509Certificate(Server.CaCerts)) {
return BadRequest(RESTAPI::Errors::InvalidRadsecCaCertificate);
}
if(Server.PrivateKey.empty() || !Utils::VerifyPrivateKey(Server.PrivateKey)) {
return BadRequest(RESTAPI::Errors::InvalidRadsecPrivteKey);
}
if(!Utils::ValidIP(Server.IP)) {
return BadRequest(RESTAPI::Errors::InvalidRadsecIPAddress);
}
if(!(Server.Port>0 && Server.Port<65535)) {
return BadRequest(RESTAPI::Errors::InvalidRadsecPort);
}
if(Server.Secret.empty()) {
return BadRequest(RESTAPI::Errors::InvalidRadsecSecret);
}
}
} break;
case RadiusEndpointDB::EndpointType::globalreach: {
for(const auto &Server:NewRecord.RadsecServers) {
if(!StorageService()->GLBLRCertsDB().Exists("id",Server.UseOpenRoamingAccount)) {
return BadRequest(RESTAPI::Errors::GlobalReachCertMustExist);
}
if(Server.Certificate.empty() || !Utils::ValidX509Certificate(Server.Certificate)) {
return BadRequest(RESTAPI::Errors::InvalidRadsecMainCertificate);
}
if(Server.CaCerts.empty() || !Utils::ValidX509Certificate(Server.CaCerts)) {
return BadRequest(RESTAPI::Errors::InvalidRadsecCaCertificate);
}
if(Server.PrivateKey.empty() || !Utils::VerifyPrivateKey(Server.PrivateKey)) {
return BadRequest(RESTAPI::Errors::InvalidRadsecPrivteKey);
}
if(!Utils::ValidIP(Server.IP)) {
return BadRequest(RESTAPI::Errors::InvalidRadsecIPAddress);
}
if(!(Server.Port>0 && Server.Port<65535)) {
return BadRequest(RESTAPI::Errors::InvalidRadsecPort);
}
if(Server.Secret.empty()) {
return BadRequest(RESTAPI::Errors::InvalidRadsecSecret);
}
}
} break;
case RadiusEndpointDB::EndpointType::radsec: {
Expand Down
2 changes: 1 addition & 1 deletion src/RadiusEndpointTypes/GlobalReach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ namespace OpenWifi {
return false;
}

std::vector<Utils::HostNameServerResult> GetServers() {
std::vector<Utils::HostNameServerResult> OpenRoaming::GetServers() {
const std::string &domain = "openro.am";
auto Naptrs = Utils::getNAPTRRecords(domain);
std::vector<Utils::HostNameServerResult> Results;
Expand Down
2 changes: 1 addition & 1 deletion src/RadiusEndpointTypes/GlobalReach.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace OpenWifi {
void InitCache();

bool Render(const OpenWifi::ProvObjects::RADIUSEndPoint &RE, const std::string & SerialNUmber, Poco::JSON::Object &Result);
std::vector<Utils::HostNameServerResult> GetServers();

private:
std::string MakeToken(const std::string &GlobalReachAccountId, const std::string &PrivateKey = "");
Expand All @@ -48,7 +49,6 @@ namespace OpenWifi {
}
};

std::vector<Utils::HostNameServerResult> GetServers();
}

inline auto OpenRoaming_GlobalReach() { return GlobalReach::OpenRoaming::instance(); }
Expand Down
4 changes: 4 additions & 0 deletions src/RadiusEndpointUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <framework/AppServiceRegistry.h>
#include <framework/utils.h>
#include <StorageService.h>
#include <RadiusEndpointTypes/OrionWifi.h>
#include <RadiusEndpointTypes/GlobalReach.h>

namespace OpenWifi {
class RadiusEndpointUpdater {
Expand All @@ -26,12 +28,14 @@ namespace OpenWifi {
PoolEntry.set("radsecPoolKeepAlive",25);
if(Endpoint.Type=="orion") {
PoolEntry.set("radsecPoolType","orion");
auto Servers = OpenRoaming_Orion()->GetServers();
} else if(Endpoint.Type=="radsec") {
PoolEntry.set("radsecPoolType","radsec");
} else if(Endpoint.Type=="radius") {
PoolEntry.set("radsecPoolType","generic");
} else if(Endpoint.Type=="globalreach") {
PoolEntry.set("radsecPoolType","globalreach");
auto Servers = OpenRoaming_GlobalReach()->GetServers();
}
RadiusPools.add(PoolEntry);
}
Expand Down
79 changes: 37 additions & 42 deletions src/framework/AppServiceRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

#include "Poco/File.h"
#include "Poco/StreamCopier.h"
#include "Poco/JSON/Object.h"
#include "Poco/JSON/Parser.h"

#include "framework/MicroServiceFuncs.h"

#include "nlohmann/json.hpp"
// #include "nlohmann/json.hpp"

namespace OpenWifi {

Expand All @@ -28,11 +30,11 @@ namespace OpenWifi {
if (F.exists()) {
std::ostringstream OS;
std::ifstream IF(FileName);
Poco::StreamCopier::copyStream(IF, OS);
Registry_ = nlohmann::json::parse(OS.str());
Poco::JSON::Parser P;
Registry_ = P.parse(IF).extract<Poco::JSON::Object::Ptr>();
}
} catch (...) {
Registry_ = nlohmann::json::parse("{}");
Registry_ = Poco::makeShared<Poco::JSON::Object>();
}
}

Expand All @@ -44,54 +46,47 @@ namespace OpenWifi {
inline ~AppServiceRegistry() { Save(); }

inline void Save() {
std::istringstream IS(to_string(Registry_));
std::ofstream OF;
OF.open(FileName, std::ios::binary | std::ios::trunc);
Poco::StreamCopier::copyStream(IS, OF);
Registry_->stringify(OF);
}

inline void Set(const char *Key, uint64_t Value) {
Registry_[Key] = Value;
void Set(const char *key, const std::vector<std::string> &V) {
Poco::JSON::Array Arr;
for(const auto &s:V) {
Arr.add(s);
}
Registry_->set(key,Arr);
Save();
}

template<class T> void Set(const char *key, const T &Value) {
Registry_->set(key,Value);
Save();
}

inline void Set(const char *Key, const std::string &Value) {
Registry_[Key] = Value;
Save();
}

inline void Set(const char *Key, bool Value) {
Registry_[Key] = Value;
Save();
}

inline bool Get(const char *Key, bool &Value) {
if (Registry_[Key].is_boolean()) {
Value = Registry_[Key].get<bool>();
return true;
}
return false;
}

inline bool Get(const char *Key, uint64_t &Value) {
if (Registry_[Key].is_number_unsigned()) {
Value = Registry_[Key].get<uint64_t>();
return true;
}
return false;
}

inline bool Get(const char *Key, std::string &Value) {
if (Registry_[Key].is_string()) {
Value = Registry_[Key].get<std::string>();
return true;
}
return false;
}
bool Get(const char *key, std::vector<std::string> &Value) {
if(Registry_->has(key) && Registry_->isArray(key)) {
auto Arr = Registry_->get(key);
for(const auto &v:Arr) {
Value.emplace_back(v);
}
return true;
}
return false;
}

template<class T> bool Get(const char *key, T &Value) {
if(Registry_->has(key)) {
Value = Registry_->getValue<T>(key);
return true;
}
return false;
}

private:
std::string FileName;
nlohmann::json Registry_;
Poco::JSON::Object::Ptr Registry_;
};

inline auto AppServiceRegistry() { return AppServiceRegistry::instance(); }
Expand Down

0 comments on commit a8581f8

Please sign in to comment.