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 Sep 11, 2023
1 parent b950694 commit 5cc00a2
Show file tree
Hide file tree
Showing 16 changed files with 596 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ add_executable(owprov
src/ProvWebSocketClient.cpp src/ProvWebSocketClient.h
src/Tasks/VenueRebooter.h src/Tasks/VenueUpgrade.h
src/sdks/SDK_fms.cpp src/sdks/SDK_fms.h
src/RESTAPI/RESTAPI_overrides_handler.cpp src/RESTAPI/RESTAPI_overrides_handler.h)
src/RESTAPI/RESTAPI_overrides_handler.cpp src/RESTAPI/RESTAPI_overrides_handler.h src/OpenRoamin_GlobalReach.cpp src/OpenRoamin_GlobalReach.h src/storage/storage_glblraccounts.cpp src/storage/storage_glblraccounts.h src/storage/storage_glblrcerts.cpp src/storage/storage_glblrcerts.h)

target_link_libraries(owprov PUBLIC
${Poco_LIBRARIES}
Expand Down
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4
12
5 changes: 4 additions & 1 deletion src/Daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "UI_Prov_WebSocketNotifications.h"
#include "framework/ConfigurationValidator.h"
#include "framework/UI_WebSocketClientServer.h"
#include "OpenRoamin_GlobalReach.h"

namespace OpenWifi {
class Daemon *Daemon::instance_ = nullptr;
Expand All @@ -35,7 +36,9 @@ namespace OpenWifi {
ConfigurationValidator(), SerialNumberCache(),
AutoDiscovery(), JobController(),
UI_WebSocketClientServer(), FindCountryFromIP(),
Signup(), FileDownloader()});
Signup(), FileDownloader(),
OpenRoaming_GlobalReach()
});
}
return instance_;
}
Expand Down
85 changes: 85 additions & 0 deletions src/OpenRoamin_GlobalReach.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// Created by stephane bourque on 2023-09-11.
//

#include "OpenRoamin_GlobalReach.h"

namespace OpenWifi {

int OpenRoaming_GlobalReach::Start() {
poco_information(Logger(), "Starting...");
return 0;
}

void OpenRoaming_GlobalReach::Stop() {
poco_information(Logger(), "Stopping...");
poco_information(Logger(), "Stopped...");
}

bool OpenRoaming_GlobalReach::GetAccountInfo(const std::string &AccountName, ProvObjects::GLBLRAccountInfo &Account) {
/* Poco::URI URI{"https://config.openro.am/v1/config"};
std::string Path(URI.getPathAndQuery());
Poco::Net::HTTPRequest Request(Poco::Net::HTTPRequest::HTTP_GET, Path,
Poco::Net::HTTPMessage::HTTP_1_1);
Request.add("Authorization", "Bearer " + BearerToken);
Poco::Net::HTTPSClientSession Session(URI.getHost(), URI.getPort());
Session.setTimeout(Poco::Timespan(10000, 10000));
Session.sendRequest(Request);
Poco::Net::HTTPResponse Response;
std::istream &is = Session.receiveResponse(Response);
Poco::JSON::Parser P;
Result= P.parse(is).extract<Poco::JSON::Object::Ptr>();
std::cout << Response.getStatus() << " : " ;
Result->stringify(std::cout);
std::cout << std::endl;
*/
return true;
}

bool OpenRoaming_GlobalReach::CreateRadsecCertificate(const std::string &AccountName, ProvObjects::GLBLRCertificateInfo &NewCertificate) {
/*
Poco::URI URI{"https://config.openro.am/v1/radsec/issue"};
std::string Path(URI.getPathAndQuery());
Poco::Net::HTTPRequest Request(Poco::Net::HTTPRequest::HTTP_POST, Path,
Poco::Net::HTTPMessage::HTTP_1_1);
Request.add("Authorization", "Bearer " + BearerToken);
Poco::Net::HTTPSClientSession Session(URI.getHost(), URI.getPort());
Session.setTimeout(Poco::Timespan(10000, 10000));
std::ostringstream os;
Body.stringify(os);
Request.setContentType("application/json");
Request.setContentLength(os.str().size());
auto &body = Session.sendRequest(Request);
body << os.str();
Poco::Net::HTTPResponse Response;
std::istream &is = Session.receiveResponse(Response);
Poco::JSON::Parser P;
Result= P.parse(is).extract<Poco::JSON::Object::Ptr>();
std::cout << Response.getStatus() << " : " ;
Result->stringify(std::cout);
std::cout << std::endl;
*/
return true;
}

bool OpenRoaming_GlobalReach::GetRadsecCertificate(const std::string &AccountName, std::string &CertificateId,
ProvObjects::GLBLRCertificateInfo &NewCertificate) {
return true;
}

} // OpenWifi
37 changes: 37 additions & 0 deletions src/OpenRoamin_GlobalReach.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Created by stephane bourque on 2023-09-11.
//

#pragma once

#include "framework/SubSystemServer.h"
#include "Poco/JSON/Object.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"

namespace OpenWifi {

class OpenRoaming_GlobalReach : public SubSystemServer {
public:
static auto instance() {
static auto instance_ = new OpenRoaming_GlobalReach;
return instance_;
}

int Start() override;
void Stop() override;
bool GetAccountInfo(const std::string &AccountName, ProvObjects::GLBLRAccountInfo &Account);
bool CreateRadsecCertificate(const std::string &AccountName, ProvObjects::GLBLRCertificateInfo &NewCertificate);
bool GetRadsecCertificate(const std::string &AccountName, std::string & CertificateId, ProvObjects::GLBLRCertificateInfo &NewCertificate);

private:
std::string CreateJWTToken(const std::string &AccountName);

OpenRoaming_GlobalReach() noexcept
: SubSystemServer("OpenRoaming_GlobalReach", "GLBL-REACH", "globalreach") {
}
};

inline auto OpenRoaming_GlobalReach() { return OpenRoaming_GlobalReach::instance(); }

} // OpenWifi

56 changes: 56 additions & 0 deletions src/RESTObjects/RESTAPI_ProvObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,4 +1194,60 @@ namespace OpenWifi::ProvObjects {
return false;
}

void GLBLRAccountInfo::to_json(Poco::JSON::Object &Obj) const {
info.to_json(Obj);
field_to_json(Obj, "privateKey", privateKey);
field_to_json(Obj, "country", country);
field_to_json(Obj, "province", province);
field_to_json(Obj, "city", city);
field_to_json(Obj, "organization", organization);
field_to_json(Obj, "commonName", commonName);
}

bool GLBLRAccountInfo::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
info.from_json(Obj);
field_from_json(Obj, "privateKey", privateKey);
field_from_json(Obj, "country", country);
field_from_json(Obj, "province", province);
field_from_json(Obj, "city", city);
field_from_json(Obj, "organization", organization);
field_from_json(Obj, "commonName", commonName);
return true;
} catch (const Poco::Exception &E) {

}
return false;
}

void GLBLRCertificateInfo::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj, "id", id);
field_to_json(Obj, "name", name);
field_to_json(Obj, "accountId", accountId);
field_to_json(Obj, "csr", csr);
field_to_json(Obj, "certificate", certificate);
field_to_json(Obj, "certificateChain", certificateChain);
field_to_json(Obj, "certificateId", certificateId);
field_to_json(Obj, "expiresAt", expiresAt);
field_to_json(Obj, "created", created);
}

bool GLBLRCertificateInfo::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "id", id);
field_from_json(Obj, "name", name);
field_from_json(Obj, "accountId", accountId);
field_from_json(Obj, "csr", csr);
field_from_json(Obj, "certificate", certificate);
field_from_json(Obj, "certificateChain", certificateChain);
field_from_json(Obj, "certificateId", certificateId);
field_from_json(Obj, "expiresAt", expiresAt);
field_from_json(Obj, "created", created);
return true;
} catch (const Poco::Exception &E) {

}
return false;
}

} // namespace OpenWifi::ProvObjects
25 changes: 25 additions & 0 deletions src/RESTObjects/RESTAPI_ProvObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -746,4 +746,29 @@ namespace OpenWifi::ProvObjects {
bool CreateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U,
ObjectInfo &I);
bool CreateObjectInfo(const SecurityObjects::UserInfo &U, ObjectInfo &I);

struct GLBLRAccountInfo {
ObjectInfo info;
std::string privateKey;
std::string country, province, city, organization, commonName;

void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};

struct GLBLRCertificateInfo {
std::string id;
std::string name;
std::string accountId;
std::string csr;
std::string certificate;
std::string certificateChain;
std::string certificateId;
std::uint64_t expiresAt=0;
std::uint64_t created=0;

void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};

}; // namespace OpenWifi::ProvObjects
26 changes: 26 additions & 0 deletions src/StorageService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace OpenWifi {
OpLocationDB_ = std::make_unique<OpenWifi::OpLocationDB>(dbType_, *Pool_, Logger());
OpContactDB_ = std::make_unique<OpenWifi::OpContactDB>(dbType_, *Pool_, Logger());
OverridesDB_ = std::make_unique<OpenWifi::OverridesDB>(dbType_, *Pool_, Logger());
GLBLRAccountInfoDB_ = std::make_unique<OpenWifi::GLBLRAccountInfoDB>(dbType_, *Pool_, Logger());
GLBLRCertsDB_ = std::make_unique<OpenWifi::GLBLRCertsDB>(dbType_, *Pool_, Logger());

EntityDB_->Create();
PolicyDB_->Create();
Expand All @@ -59,6 +61,8 @@ namespace OpenWifi {
OpLocationDB_->Create();
OpContactDB_->Create();
OverridesDB_->Create();
GLBLRAccountInfoDB_->Create();
GLBLRCertsDB_->Create();

ExistFunc_[EntityDB_->Prefix()] = [=](const char *F, std::string &V) -> bool {
return EntityDB_->Exists(F, V);
Expand Down Expand Up @@ -117,6 +121,14 @@ namespace OpenWifi {
ExistFunc_[OverridesDB_->Prefix()] = [=](const char *F, std::string &V) -> bool {
return OverridesDB_->Exists(F, V);
};
ExistFunc_[GLBLRAccountInfoDB_->Prefix()] = [=](const char *F, std::string &V) -> bool {
return GLBLRAccountInfoDB_->Exists(F, V);
};
ExistFunc_[GLBLRCertsDB_->Prefix()] = [=](const char *F, std::string &V) -> bool {
return GLBLRCertsDB_->Exists(F, V);
};



ExpandFunc_[EntityDB_->Prefix()] = [=](const char *F, std::string &V, std::string &Name,
std::string &Description) -> bool {
Expand Down Expand Up @@ -207,6 +219,20 @@ namespace OpenWifi {
[[maybe_unused]] std::string &Name,
[[maybe_unused]] std::string &Description) -> bool { return false; };

ExpandFunc_[GLBLRAccountInfoDB_->Prefix()] =
[=]([[maybe_unused]] const char *F, [[maybe_unused]] std::string &V,
[[maybe_unused]] std::string &Name,
[[maybe_unused]] std::string &Description) -> bool { return false; };
ExpandFunc_[OverridesDB_->Prefix()] =
[=]([[maybe_unused]] const char *F, [[maybe_unused]] std::string &V,
[[maybe_unused]] std::string &Name,
[[maybe_unused]] std::string &Description) -> bool { return false; };

ExpandFunc_[GLBLRCertsDB_->Prefix()] =
[=]([[maybe_unused]] const char *F, [[maybe_unused]] std::string &V,
[[maybe_unused]] std::string &Name,
[[maybe_unused]] std::string &Description) -> bool { return false; };

InventoryDB_->InitializeSerialCache();

ConsistencyCheck();
Expand Down
44 changes: 25 additions & 19 deletions src/StorageService.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "storage/storage_tags.h"
#include "storage/storage_variables.h"
#include "storage/storage_venue.h"
#include "storage/storage_glblraccounts.h"
#include "storage/storage_glblrcerts.h"

#include "Poco/URI.h"
#include "framework/ow_constants.h"
Expand All @@ -47,25 +49,27 @@ namespace OpenWifi {
typedef std::list<ProvObjects::ExpandedUseEntry> ExpandedInUseList;
typedef std::map<std::string, ProvObjects::ExpandedUseEntryList> ExpandedListMap;

OpenWifi::EntityDB &EntityDB() { return *EntityDB_; };
OpenWifi::PolicyDB &PolicyDB() { return *PolicyDB_; };
OpenWifi::VenueDB &VenueDB() { return *VenueDB_; };
OpenWifi::LocationDB &LocationDB() { return *LocationDB_; };
OpenWifi::ContactDB &ContactDB() { return *ContactDB_; };
OpenWifi::InventoryDB &InventoryDB() { return *InventoryDB_; };
OpenWifi::ManagementRoleDB &RolesDB() { return *RolesDB_; };
OpenWifi::ConfigurationDB &ConfigurationDB() { return *ConfigurationDB_; };
OpenWifi::TagsDictionaryDB &TagsDictionaryDB() { return *TagsDictionaryDB_; };
OpenWifi::TagsObjectDB &TagsObjectDB() { return *TagsObjectDB_; };
OpenWifi::MapDB &MapDB() { return *MapDB_; };
OpenWifi::SignupDB &SignupDB() { return *SignupDB_; };
OpenWifi::VariablesDB &VariablesDB() { return *VariablesDB_; };
OpenWifi::OperatorDB &OperatorDB() { return *OperatorDB_; };
OpenWifi::ServiceClassDB &ServiceClassDB() { return *ServiceClassDB_; };
OpenWifi::SubscriberDeviceDB &SubscriberDeviceDB() { return *SubscriberDeviceDB_; };
OpenWifi::OpLocationDB &OpLocationDB() { return *OpLocationDB_; };
OpenWifi::OpContactDB &OpContactDB() { return *OpContactDB_; };
OpenWifi::OverridesDB &OverridesDB() { return *OverridesDB_; };
inline OpenWifi::EntityDB &EntityDB() { return *EntityDB_; };
inline OpenWifi::PolicyDB &PolicyDB() { return *PolicyDB_; };
inline OpenWifi::VenueDB &VenueDB() { return *VenueDB_; };
inline OpenWifi::LocationDB &LocationDB() { return *LocationDB_; };
inline OpenWifi::ContactDB &ContactDB() { return *ContactDB_; };
inline OpenWifi::InventoryDB &InventoryDB() { return *InventoryDB_; };
inline OpenWifi::ManagementRoleDB &RolesDB() { return *RolesDB_; };
inline OpenWifi::ConfigurationDB &ConfigurationDB() { return *ConfigurationDB_; };
inline OpenWifi::TagsDictionaryDB &TagsDictionaryDB() { return *TagsDictionaryDB_; };
inline OpenWifi::TagsObjectDB &TagsObjectDB() { return *TagsObjectDB_; };
inline OpenWifi::MapDB &MapDB() { return *MapDB_; };
inline OpenWifi::SignupDB &SignupDB() { return *SignupDB_; };
inline OpenWifi::VariablesDB &VariablesDB() { return *VariablesDB_; };
inline OpenWifi::OperatorDB &OperatorDB() { return *OperatorDB_; };
inline OpenWifi::ServiceClassDB &ServiceClassDB() { return *ServiceClassDB_; };
inline OpenWifi::SubscriberDeviceDB &SubscriberDeviceDB() { return *SubscriberDeviceDB_; };
inline OpenWifi::OpLocationDB &OpLocationDB() { return *OpLocationDB_; };
inline OpenWifi::OpContactDB &OpContactDB() { return *OpContactDB_; };
inline OpenWifi::OverridesDB &OverridesDB() { return *OverridesDB_; };
inline OpenWifi::GLBLRAccountInfoDB &GLBLRAccountInfoDB() { return *GLBLRAccountInfoDB_; }
inline OpenWifi::GLBLRCertsDB &GLBLRCertsDB() { return *GLBLRCertsDB_; }

bool Validate(const Poco::URI::QueryParameters &P, RESTAPI::Errors::msg &Error);
bool Validate(const Types::StringVec &P, std::string &Error);
Expand Down Expand Up @@ -125,6 +129,8 @@ namespace OpenWifi {
std::unique_ptr<OpenWifi::OpLocationDB> OpLocationDB_;
std::unique_ptr<OpenWifi::OpContactDB> OpContactDB_;
std::unique_ptr<OpenWifi::OverridesDB> OverridesDB_;
std::unique_ptr<OpenWifi::GLBLRAccountInfoDB> GLBLRAccountInfoDB_;
std::unique_ptr<OpenWifi::GLBLRCertsDB> GLBLRCertsDB_;
std::string DefaultOperator_;

typedef std::function<bool(const char *FieldName, std::string &Value)> exist_func;
Expand Down
1 change: 1 addition & 0 deletions src/framework/ow_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace OpenWifi {
};
}

#define DBGLINE std::cout << __LINE__ << ":" << __FILE__ << ", " << __func__ << std::endl;
namespace OpenWifi::RESTAPI::Errors {
struct msg {
uint64_t err_num;
Expand Down
Loading

0 comments on commit 5cc00a2

Please sign in to comment.