mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-30 02:02:36 +00:00
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
@@ -111,24 +111,6 @@ 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: {
|
||||
@@ -136,24 +118,6 @@ namespace OpenWifi {
|
||||
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: {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = "");
|
||||
@@ -48,7 +49,6 @@ namespace OpenWifi {
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<Utils::HostNameServerResult> GetServers();
|
||||
}
|
||||
|
||||
inline auto OpenRoaming_GlobalReach() { return GlobalReach::OpenRoaming::instance(); }
|
||||
|
||||
@@ -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 {
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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(); }
|
||||
|
||||
Reference in New Issue
Block a user