mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
synced 2025-10-29 18:02:29 +00:00
Refactoring project layout
This commit is contained in:
@@ -52,10 +52,10 @@ include_directories(/usr/local/include /usr/local/opt/openssl/include src inclu
|
||||
|
||||
add_executable( owsec
|
||||
build
|
||||
src/APIServers.cpp
|
||||
src/Daemon.h src/Daemon.cpp
|
||||
src/framework/MicroService.h
|
||||
src/RESTAPI/RESTAPI_oauth2Handler.h src/RESTAPI/RESTAPI_oauth2Handler.cpp
|
||||
src/RESTAPI/RESTAPI_server.cpp src/RESTAPI/RESTAPI_server.h
|
||||
src/RESTObjects/RESTAPI_SecurityObjects.cpp src/RESTObjects/RESTAPI_SecurityObjects.h
|
||||
src/AuthService.h src/AuthService.cpp
|
||||
src/StorageService.cpp src/StorageService.h
|
||||
@@ -63,7 +63,6 @@ add_executable( owsec
|
||||
src/RESTAPI/RESTAPI_users_handler.cpp src/RESTAPI/RESTAPI_users_handler.h
|
||||
src/RESTAPI/RESTAPI_user_handler.cpp src/RESTAPI/RESTAPI_user_handler.h
|
||||
src/RESTAPI/RESTAPI_action_links.cpp src/RESTAPI/RESTAPI_action_links.h
|
||||
src/RESTAPI/RESTAPI_InternalServer.cpp src/RESTAPI/RESTAPI_InternalServer.h
|
||||
src/RESTAPI/RESTAPI_validateToken_handler.cpp src/RESTAPI/RESTAPI_validateToken_handler.h
|
||||
src/RESTAPI/RESTAPI_systemEndpoints_handler.cpp src/RESTAPI/RESTAPI_systemEndpoints_handler.h
|
||||
src/RESTAPI/RESTAPI_AssetServer.cpp src/RESTAPI/RESTAPI_AssetServer.h
|
||||
|
||||
47
src/APIServers.cpp
Normal file
47
src/APIServers.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-10-23.
|
||||
//
|
||||
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
#include "RESTAPI/RESTAPI_oauth2Handler.h"
|
||||
#include "RESTAPI/RESTAPI_user_handler.h"
|
||||
#include "RESTAPI/RESTAPI_users_handler.h"
|
||||
#include "RESTAPI/RESTAPI_action_links.h"
|
||||
#include "RESTAPI/RESTAPI_systemEndpoints_handler.h"
|
||||
#include "RESTAPI/RESTAPI_AssetServer.h"
|
||||
#include "RESTAPI/RESTAPI_avatarHandler.h"
|
||||
#include "RESTAPI/RESTAPI_email_handler.h"
|
||||
#include "RESTAPI/RESTAPI_sms_handler.h"
|
||||
#include "RESTAPI/RESTAPI_validateToken_handler.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
Poco::Net::HTTPRequestHandler * RESTAPI_external_server(const char *Path, RESTAPIHandler::BindingMap &Bindings,
|
||||
Poco::Logger & L, RESTAPI_GenericServer & S) {
|
||||
return RESTAPI_Router<
|
||||
RESTAPI_oauth2Handler,
|
||||
RESTAPI_users_handler,
|
||||
RESTAPI_user_handler,
|
||||
RESTAPI_system_command,
|
||||
RESTAPI_AssetServer,
|
||||
RESTAPI_systemEndpoints_handler,
|
||||
RESTAPI_action_links,
|
||||
RESTAPI_avatarHandler,
|
||||
RESTAPI_email_handler,
|
||||
RESTAPI_sms_handler
|
||||
>(Path, Bindings, L, S);
|
||||
}
|
||||
|
||||
Poco::Net::HTTPRequestHandler * RESTAPI_internal_server(const char *Path, RESTAPIHandler::BindingMap &Bindings,
|
||||
Poco::Logger & L, RESTAPI_GenericServer & S) {
|
||||
return RESTAPI_Router_I<
|
||||
RESTAPI_users_handler,
|
||||
RESTAPI_user_handler,
|
||||
RESTAPI_system_command,
|
||||
RESTAPI_action_links,
|
||||
RESTAPI_validateToken_handler,
|
||||
RESTAPI_sms_handler
|
||||
>(Path, Bindings, L, S);
|
||||
}
|
||||
}
|
||||
@@ -27,9 +27,7 @@
|
||||
#include <aws/s3/model/GetBucketAclRequest.h>
|
||||
|
||||
#include "StorageService.h"
|
||||
#include "RESTAPI/RESTAPI_server.h"
|
||||
#include "SMTPMailerService.h"
|
||||
#include "RESTAPI/RESTAPI_InternalServer.h"
|
||||
#include "AuthService.h"
|
||||
#include "SMSSender.h"
|
||||
|
||||
@@ -46,8 +44,6 @@ namespace OpenWifi {
|
||||
SubSystemVec{
|
||||
StorageService(),
|
||||
SMSSender(),
|
||||
RESTAPI_Server(),
|
||||
RESTAPI_InternalServer(),
|
||||
SMTPMailerService(),
|
||||
AuthService()
|
||||
});
|
||||
@@ -57,6 +53,9 @@ namespace OpenWifi {
|
||||
|
||||
void Daemon::initialize(Poco::Util::Application &self) {
|
||||
MicroService::initialize(*this);
|
||||
AsserDir_ = MicroService::instance().ConfigPath("openwifi.restapi.wwwassets");
|
||||
AccessPolicy_ = MicroService::instance().ConfigGetString("openwifi.document.policy.access", "/wwwassets/access_policy.html");
|
||||
PasswordPolicy_ = MicroService::instance().ConfigGetString("openwifi.document.policy.password", "/wwwassets/password_policy.html");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,14 @@ namespace OpenWifi {
|
||||
|
||||
void initialize(Poco::Util::Application &self) override;
|
||||
static Daemon *instance();
|
||||
inline const std::string & AssetDir() { return AsserDir_; }
|
||||
inline const std::string & GetPasswordPolicy() const { return PasswordPolicy_; }
|
||||
inline const std::string & GetAccessPolicy() const { return AccessPolicy_; }
|
||||
private:
|
||||
static Daemon *instance_;
|
||||
static Daemon *instance_;
|
||||
std::string AsserDir_;
|
||||
std::string PasswordPolicy_;
|
||||
std::string AccessPolicy_;
|
||||
};
|
||||
|
||||
inline Daemon * Daemon() { return Daemon::instance(); }
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
#include "Poco/File.h"
|
||||
#include "framework/RESTAPI_protocol.h"
|
||||
#include "framework/MicroService.h"
|
||||
#include "RESTAPI_server.h"
|
||||
#include "Daemon.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
void RESTAPI_AssetServer::DoGet() {
|
||||
Poco::File AssetFile;
|
||||
|
||||
if(Request->getURI().find("/favicon.ico") != std::string::npos) {
|
||||
AssetFile = RESTAPI_Server()->AssetDir() + "/favicon.ico";
|
||||
AssetFile = Daemon()->AssetDir() + "/favicon.ico";
|
||||
} else {
|
||||
std::string AssetName = GetBinding(RESTAPI::Protocol::ID, "");
|
||||
AssetFile = RESTAPI_Server()->AssetDir() + "/" + AssetName;
|
||||
AssetFile = Daemon()->AssetDir() + "/" + AssetName;
|
||||
}
|
||||
if(!AssetFile.isFile()) {
|
||||
return NotFound();
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-06-29.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/URI.h"
|
||||
|
||||
#include "RESTAPI_user_handler.h"
|
||||
#include "RESTAPI_users_handler.h"
|
||||
#include "RESTAPI_action_links.h"
|
||||
#include "RESTAPI_validateToken_handler.h"
|
||||
#include "RESTAPI_InternalServer.h"
|
||||
#include "RESTAPI_sms_handler.h"
|
||||
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class RESTAPI_InternalServer *RESTAPI_InternalServer::instance_ = nullptr;
|
||||
|
||||
RESTAPI_InternalServer::RESTAPI_InternalServer() noexcept:
|
||||
SubSystemServer("RESTAPIInternalServer", "REST-ISRV", "openwifi.internal.restapi")
|
||||
{
|
||||
}
|
||||
|
||||
int RESTAPI_InternalServer::Start() {
|
||||
Logger_.information("Starting.");
|
||||
Server_.InitLogging();
|
||||
|
||||
for(const auto & Svr: ConfigServersList_) {
|
||||
Logger_.information(Poco::format("Starting: %s:%s Keyfile:%s CertFile: %s", Svr.Address(), std::to_string(Svr.Port()),
|
||||
Svr.KeyFile(),Svr.CertFile()));
|
||||
|
||||
auto Sock{Svr.CreateSecureSocket(Logger_)};
|
||||
|
||||
Svr.LogCert(Logger_);
|
||||
if(!Svr.RootCA().empty())
|
||||
Svr.LogCas(Logger_);
|
||||
|
||||
auto Params = new Poco::Net::HTTPServerParams;
|
||||
Params->setMaxThreads(50);
|
||||
Params->setMaxQueued(200);
|
||||
Params->setKeepAlive(true);
|
||||
|
||||
auto NewServer = std::make_unique<Poco::Net::HTTPServer>(new InternalRequestHandlerFactory(Server_), Pool_, Sock, Params);
|
||||
NewServer->start();
|
||||
RESTServers_.push_back(std::move(NewServer));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RESTAPI_InternalServer::Stop() {
|
||||
Logger_.information("Stopping ");
|
||||
for( const auto & svr : RESTServers_ )
|
||||
svr->stop();
|
||||
RESTServers_.clear();
|
||||
}
|
||||
|
||||
void RESTAPI_InternalServer::reinitialize(Poco::Util::Application &self) {
|
||||
MicroService::instance().LoadConfigurationFile();
|
||||
Logger_.information("Reinitializing.");
|
||||
Stop();
|
||||
Start();
|
||||
}
|
||||
|
||||
Poco::Net::HTTPRequestHandler *InternalRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest & Request) {
|
||||
Poco::URI uri(Request.getURI());
|
||||
const auto & Path = uri.getPath();
|
||||
RESTAPIHandler::BindingMap Bindings;
|
||||
return RESTAPI_Router_I<
|
||||
RESTAPI_users_handler,
|
||||
RESTAPI_user_handler,
|
||||
RESTAPI_system_command,
|
||||
RESTAPI_action_links,
|
||||
RESTAPI_validateToken_handler,
|
||||
RESTAPI_sms_handler
|
||||
>(Path,Bindings,Logger_, Server_);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-06-29.
|
||||
//
|
||||
|
||||
#ifndef UCENTRALSEC_RESTAPI_INTERNALSERVER_H
|
||||
#define UCENTRALSEC_RESTAPI_INTERNALSERVER_H
|
||||
|
||||
#include "Poco/Net/HTTPServer.h"
|
||||
#include "Poco/Net/HTTPRequestHandler.h"
|
||||
#include "Poco/Net/HTTPRequestHandlerFactory.h"
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class RESTAPI_InternalServer : public SubSystemServer {
|
||||
public:
|
||||
RESTAPI_InternalServer() noexcept;
|
||||
|
||||
static RESTAPI_InternalServer *instance() {
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new RESTAPI_InternalServer;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
void reinitialize(Poco::Util::Application &self) override;
|
||||
|
||||
private:
|
||||
static RESTAPI_InternalServer *instance_;
|
||||
std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_;
|
||||
Poco::ThreadPool Pool_;
|
||||
RESTAPI_GenericServer Server_;
|
||||
};
|
||||
|
||||
inline RESTAPI_InternalServer * RESTAPI_InternalServer() { return RESTAPI_InternalServer::instance(); };
|
||||
|
||||
class InternalRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory {
|
||||
public:
|
||||
explicit InternalRequestHandlerFactory(RESTAPI_GenericServer & Server) :
|
||||
Logger_(RESTAPI_InternalServer()->Logger()),
|
||||
Server_(Server){}
|
||||
|
||||
Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &request) override;
|
||||
private:
|
||||
Poco::Logger & Logger_;
|
||||
RESTAPI_GenericServer & Server_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif //UCENTRALSEC_RESTAPI_INTERNALSERVER_H
|
||||
@@ -2,14 +2,13 @@
|
||||
// Created by stephane bourque on 2021-06-22.
|
||||
//
|
||||
|
||||
#include "RESTAPI_action_links.h"
|
||||
#include "StorageService.h"
|
||||
|
||||
#include "Poco/JSON/Parser.h"
|
||||
#include "Poco/Net/HTMLForm.h"
|
||||
#include "RESTAPI_server.h"
|
||||
|
||||
#include "RESTAPI_action_links.h"
|
||||
#include "StorageService.h"
|
||||
#include "framework/MicroService.h"
|
||||
#include "Daemon.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
void RESTAPI_action_links::DoGet() {
|
||||
@@ -38,7 +37,7 @@ namespace OpenWifi {
|
||||
|
||||
void RESTAPI_action_links::RequestResetPassword(std::string &Id) {
|
||||
Logger_.information(Poco::format("REQUEST-PASSWORD-RESET(%s): For ID=%s", Request->clientAddress().toString(), Id));
|
||||
Poco::File FormFile{ RESTAPI_Server()->AssetDir() + "/password_reset.html"};
|
||||
Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset.html"};
|
||||
Types::StringPairVec FormVars{ {"UUID", Id},
|
||||
{"PASSWORD_VALIDATION", AuthService()->PasswordValidationExpression()}};
|
||||
SendHTMLFileBack(FormFile,FormVars);
|
||||
@@ -53,7 +52,7 @@ namespace OpenWifi {
|
||||
auto Password2 = Form.get("password1","blu");
|
||||
Id = Form.get("id","");
|
||||
if(Password1!=Password2 || !AuthService()->ValidatePassword(Password2) || !AuthService()->ValidatePassword(Password1)) {
|
||||
Poco::File FormFile{ RESTAPI_Server()->AssetDir() + "/password_reset_error.html"};
|
||||
Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset_error.html"};
|
||||
Types::StringPairVec FormVars{ {"UUID", Id},
|
||||
{"ERROR_TEXT", "For some reason, the passwords entered do not match or they do not comply with"
|
||||
" accepted password creation restrictions. Please consult our on-line help"
|
||||
@@ -64,27 +63,27 @@ namespace OpenWifi {
|
||||
|
||||
SecurityObjects::UserInfo UInfo;
|
||||
if(!StorageService()->GetUserById(Id,UInfo)) {
|
||||
Poco::File FormFile{ RESTAPI_Server()->AssetDir() + "/password_reset_error.html"};
|
||||
Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset_error.html"};
|
||||
Types::StringPairVec FormVars{ {"UUID", Id},
|
||||
{"ERROR_TEXT", "This request does not contain a valid user ID. Please contact your system administrator."}};
|
||||
return SendHTMLFileBack(FormFile,FormVars);
|
||||
}
|
||||
|
||||
if(UInfo.blackListed || UInfo.suspended) {
|
||||
Poco::File FormFile{ RESTAPI_Server()->AssetDir() + "/password_reset_error.html"};
|
||||
Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset_error.html"};
|
||||
Types::StringPairVec FormVars{ {"UUID", Id},
|
||||
{"ERROR_TEXT", "Please contact our system administrators. We have identified an error in your account that must be resolved first."}};
|
||||
return SendHTMLFileBack(FormFile,FormVars);
|
||||
}
|
||||
|
||||
if(!AuthService()->SetPassword(Password1,UInfo)) {
|
||||
Poco::File FormFile{ RESTAPI_Server()->AssetDir() + "/password_reset_error.html"};
|
||||
Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset_error.html"};
|
||||
Types::StringPairVec FormVars{ {"UUID", Id},
|
||||
{"ERROR_TEXT", "You cannot reuse one of your recent passwords."}};
|
||||
return SendHTMLFileBack(FormFile,FormVars);
|
||||
}
|
||||
StorageService()->UpdateUserInfo(UInfo.email,Id,UInfo);
|
||||
Poco::File FormFile{ RESTAPI_Server()->AssetDir() + "/password_reset_success.html"};
|
||||
Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset_success.html"};
|
||||
Types::StringPairVec FormVars{ {"UUID", Id},
|
||||
{"USERNAME", UInfo.email},
|
||||
{"ACTION_LINK",MicroService::instance().GetUIURI()}};
|
||||
@@ -101,7 +100,7 @@ namespace OpenWifi {
|
||||
if (!StorageService()->GetUserById(Id, UInfo)) {
|
||||
Types::StringPairVec FormVars{{"UUID", Id},
|
||||
{"ERROR_TEXT", "This does not appear to be a valid email verification link.."}};
|
||||
Poco::File FormFile{RESTAPI_Server()->AssetDir() + "/email_verification_error.html"};
|
||||
Poco::File FormFile{Daemon()->AssetDir() + "/email_verification_error.html"};
|
||||
return SendHTMLFileBack(FormFile, FormVars);
|
||||
}
|
||||
|
||||
@@ -113,13 +112,13 @@ namespace OpenWifi {
|
||||
Types::StringPairVec FormVars{{"UUID", Id},
|
||||
{"USERNAME", UInfo.email},
|
||||
{"ACTION_LINK",MicroService::instance().GetUIURI()}};
|
||||
Poco::File FormFile{RESTAPI_Server()->AssetDir() + "/email_verification_success.html"};
|
||||
Poco::File FormFile{Daemon()->AssetDir() + "/email_verification_success.html"};
|
||||
SendHTMLFileBack(FormFile, FormVars);
|
||||
}
|
||||
|
||||
void RESTAPI_action_links::DoReturnA404() {
|
||||
Types::StringPairVec FormVars;
|
||||
Poco::File FormFile{RESTAPI_Server()->AssetDir() + "/404_error.html"};
|
||||
Poco::File FormFile{Daemon()->AssetDir() + "/404_error.html"};
|
||||
SendHTMLFileBack(FormFile, FormVars);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
#include "Poco/JSON/Parser.h"
|
||||
|
||||
#include "Daemon.h"
|
||||
#include "AuthService.h"
|
||||
#include "RESTAPI_oauth2Handler.h"
|
||||
#include "framework/RESTAPI_protocol.h"
|
||||
#include "RESTAPI_server.h"
|
||||
#include "MFAServer.h"
|
||||
#include "framework/RESTAPI_protocol.h"
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
@@ -57,8 +57,8 @@ namespace OpenWifi {
|
||||
Logger_.information(Poco::format("POLICY-REQUEST(%s): Request.", Request->clientAddress().toString()));
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set(RESTAPI::Protocol::PASSWORDPATTERN, AuthService()->PasswordValidationExpression());
|
||||
Answer.set(RESTAPI::Protocol::ACCESSPOLICY, RESTAPI_Server()->GetAccessPolicy());
|
||||
Answer.set(RESTAPI::Protocol::PASSWORDPOLICY, RESTAPI_Server()->GetPasswordPolicy());
|
||||
Answer.set(RESTAPI::Protocol::ACCESSPOLICY, Daemon()->GetAccessPolicy());
|
||||
Answer.set(RESTAPI::Protocol::PASSWORDPOLICY, Daemon()->GetPasswordPolicy());
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
//
|
||||
// License type: BSD 3-Clause License
|
||||
// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
|
||||
//
|
||||
// Created by Stephane Bourque on 2021-03-04.
|
||||
// Arilia Wireless Inc.
|
||||
//
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Poco/URI.h"
|
||||
|
||||
#include "RESTAPI_server.h"
|
||||
#include "RESTAPI_oauth2Handler.h"
|
||||
#include "RESTAPI_user_handler.h"
|
||||
#include "RESTAPI_users_handler.h"
|
||||
#include "RESTAPI_action_links.h"
|
||||
#include "RESTAPI_systemEndpoints_handler.h"
|
||||
#include "RESTAPI_AssetServer.h"
|
||||
#include "RESTAPI_avatarHandler.h"
|
||||
#include "RESTAPI_email_handler.h"
|
||||
#include "RESTAPI_sms_handler.h"
|
||||
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class RESTAPI_Server *RESTAPI_Server::instance_ = nullptr;
|
||||
|
||||
int RESTAPI_Server::Start() {
|
||||
Logger_.information("Starting.");
|
||||
Server_.InitLogging();
|
||||
|
||||
AsserDir_ = MicroService::instance().ConfigPath("openwifi.restapi.wwwassets");
|
||||
AccessPolicy_ = MicroService::instance().ConfigGetString("openwifi.document.policy.access", "/wwwassets/access_policy.html");
|
||||
PasswordPolicy_ = MicroService::instance().ConfigGetString("openwifi.document.policy.password", "/wwwassets/password_policy.html");
|
||||
|
||||
for(const auto & Svr: ConfigServersList_) {
|
||||
Logger_.information(Poco::format("Starting: %s:%s Keyfile:%s CertFile: %s", Svr.Address(), std::to_string(Svr.Port()),
|
||||
Svr.KeyFile(),Svr.CertFile()));
|
||||
|
||||
auto Sock{Svr.CreateSecureSocket(Logger_)};
|
||||
|
||||
Svr.LogCert(Logger_);
|
||||
if(!Svr.RootCA().empty())
|
||||
Svr.LogCas(Logger_);
|
||||
|
||||
auto Params = new Poco::Net::HTTPServerParams;
|
||||
Params->setMaxThreads(50);
|
||||
Params->setMaxQueued(200);
|
||||
Params->setKeepAlive(true);
|
||||
|
||||
auto NewServer = std::make_unique<Poco::Net::HTTPServer>(new RequestHandlerFactory(Server_), Pool_, Sock, Params);
|
||||
NewServer->start();
|
||||
RESTServers_.push_back(std::move(NewServer));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Poco::Net::HTTPRequestHandler *RequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest & Request) {
|
||||
Poco::URI uri(Request.getURI());
|
||||
const auto & Path = uri.getPath();
|
||||
RESTAPIHandler::BindingMap Bindings;
|
||||
return RESTAPI_Router<
|
||||
RESTAPI_oauth2Handler,
|
||||
RESTAPI_users_handler,
|
||||
RESTAPI_user_handler,
|
||||
RESTAPI_system_command,
|
||||
RESTAPI_AssetServer,
|
||||
RESTAPI_systemEndpoints_handler,
|
||||
RESTAPI_action_links,
|
||||
RESTAPI_avatarHandler,
|
||||
RESTAPI_email_handler,
|
||||
RESTAPI_sms_handler
|
||||
>(Path,Bindings,Logger_,Server_);
|
||||
}
|
||||
|
||||
void RESTAPI_Server::Stop() {
|
||||
Logger_.information("Stopping ");
|
||||
for( const auto & svr : RESTServers_ )
|
||||
svr->stop();
|
||||
RESTServers_.clear();
|
||||
}
|
||||
|
||||
void RESTAPI_Server::reinitialize(Poco::Util::Application &self) {
|
||||
MicroService::instance().LoadConfigurationFile();
|
||||
Logger_.information("Reinitializing.");
|
||||
Stop();
|
||||
Start();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -1,71 +0,0 @@
|
||||
//
|
||||
// License type: BSD 3-Clause License
|
||||
// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
|
||||
//
|
||||
// Created by Stephane Bourque on 2021-03-04.
|
||||
// Arilia Wireless Inc.
|
||||
//
|
||||
|
||||
#ifndef UCENTRAL_UCENTRALRESTAPISERVER_H
|
||||
#define UCENTRAL_UCENTRALRESTAPISERVER_H
|
||||
|
||||
#include "Poco/Net/HTTPServer.h"
|
||||
#include "Poco/Net/HTTPRequestHandler.h"
|
||||
#include "Poco/Net/HTTPRequestHandlerFactory.h"
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class RESTAPI_Server : public SubSystemServer {
|
||||
|
||||
public:
|
||||
static RESTAPI_Server *instance() {
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new RESTAPI_Server;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
void reinitialize(Poco::Util::Application &self) override;
|
||||
|
||||
inline const std::string & AssetDir() { return AsserDir_; }
|
||||
inline const std::string & GetPasswordPolicy() const { return PasswordPolicy_; }
|
||||
inline const std::string & GetAccessPolicy() const { return AccessPolicy_; }
|
||||
private:
|
||||
static RESTAPI_Server *instance_;
|
||||
std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_;
|
||||
Poco::ThreadPool Pool_;
|
||||
std::string AsserDir_;
|
||||
std::string PasswordPolicy_;
|
||||
std::string AccessPolicy_;
|
||||
RESTAPI_GenericServer Server_;
|
||||
|
||||
RESTAPI_Server() noexcept:
|
||||
SubSystemServer("RESTAPIServer", "REST-SRV", "openwifi.restapi")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
inline RESTAPI_Server * RESTAPI_Server() { return RESTAPI_Server::instance(); };
|
||||
|
||||
class RequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory {
|
||||
public:
|
||||
RequestHandlerFactory(RESTAPI_GenericServer &Server) :
|
||||
Logger_(RESTAPI_Server()->Logger()),
|
||||
Server_(Server){}
|
||||
|
||||
Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &request) override;
|
||||
private:
|
||||
Poco::Logger & Logger_;
|
||||
RESTAPI_GenericServer &Server_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif //UCENTRAL_UCENTRALRESTAPISERVER_H
|
||||
@@ -2097,6 +2097,181 @@ namespace OpenWifi {
|
||||
inline ALBHealthCheckServer * ALBHealthCheckServer() { return ALBHealthCheckServer::instance(); }
|
||||
inline class ALBHealthCheckServer * ALBHealthCheckServer::instance_ = nullptr;
|
||||
|
||||
Poco::Net::HTTPRequestHandler * RESTAPI_external_server(const char *Path, RESTAPIHandler::BindingMap &Bindings,
|
||||
Poco::Logger & L, RESTAPI_GenericServer & S);
|
||||
|
||||
Poco::Net::HTTPRequestHandler * RESTAPI_internal_server(const char *Path, RESTAPIHandler::BindingMap &Bindings,
|
||||
Poco::Logger & L, RESTAPI_GenericServer & S);
|
||||
|
||||
|
||||
class RESTAPI_server : public SubSystemServer {
|
||||
public:
|
||||
static RESTAPI_server *instance() {
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new RESTAPI_server;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
int Start() override;
|
||||
inline void Stop() override {
|
||||
Logger_.information("Stopping ");
|
||||
for( const auto & svr : RESTServers_ )
|
||||
svr->stop();
|
||||
RESTServers_.clear();
|
||||
|
||||
}
|
||||
inline void reinitialize(Poco::Util::Application &self) override;
|
||||
|
||||
inline Poco::Net::HTTPRequestHandler *CallServer(const char *Path) {
|
||||
RESTAPIHandler::BindingMap Bindings;
|
||||
return RESTAPI_external_server(Path, Bindings, Logger_, Server_);
|
||||
}
|
||||
|
||||
private:
|
||||
static RESTAPI_server *instance_;
|
||||
std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_;
|
||||
Poco::ThreadPool Pool_;
|
||||
RESTAPI_GenericServer Server_;
|
||||
|
||||
RESTAPI_server() noexcept:
|
||||
SubSystemServer("RESTAPIServer", "RESTAPIServer", "openwifi.restapi")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
inline RESTAPI_server * RESTAPI_server() { return RESTAPI_server::instance(); };
|
||||
|
||||
class RequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory {
|
||||
public:
|
||||
RequestHandlerFactory(RESTAPI_GenericServer & Server) :
|
||||
Logger_(RESTAPI_server::instance()->Logger()),
|
||||
Server_(Server)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override {
|
||||
Poco::URI uri(Request.getURI());
|
||||
auto *Path = uri.getPath().c_str();
|
||||
return RESTAPI_server()->CallServer(Path);
|
||||
}
|
||||
|
||||
private:
|
||||
Poco::Logger &Logger_;
|
||||
RESTAPI_GenericServer &Server_;
|
||||
};
|
||||
|
||||
|
||||
inline class RESTAPI_server *RESTAPI_server::instance_ = nullptr;
|
||||
|
||||
inline int RESTAPI_server::Start() {
|
||||
Logger_.information("Starting.");
|
||||
Server_.InitLogging();
|
||||
|
||||
for(const auto & Svr: ConfigServersList_) {
|
||||
Logger_.information(Poco::format("Starting: %s:%s Keyfile:%s CertFile: %s", Svr.Address(), std::to_string(Svr.Port()),
|
||||
Svr.KeyFile(),Svr.CertFile()));
|
||||
|
||||
auto Sock{Svr.CreateSecureSocket(Logger_)};
|
||||
|
||||
Svr.LogCert(Logger_);
|
||||
if(!Svr.RootCA().empty())
|
||||
Svr.LogCas(Logger_);
|
||||
|
||||
auto Params = new Poco::Net::HTTPServerParams;
|
||||
Params->setMaxThreads(50);
|
||||
Params->setMaxQueued(200);
|
||||
Params->setKeepAlive(true);
|
||||
|
||||
auto NewServer = std::make_unique<Poco::Net::HTTPServer>(new RequestHandlerFactory(Server_), Pool_, Sock, Params);
|
||||
NewServer->start();
|
||||
RESTServers_.push_back(std::move(NewServer));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
class RESTAPI_InternalServer : public SubSystemServer {
|
||||
|
||||
public:
|
||||
static RESTAPI_InternalServer *instance() {
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new RESTAPI_InternalServer;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
inline int Start() override;
|
||||
inline void Stop() override {
|
||||
Logger_.information("Stopping ");
|
||||
for( const auto & svr : RESTServers_ )
|
||||
svr->stop();
|
||||
RESTServers_.clear();
|
||||
}
|
||||
|
||||
inline void reinitialize(Poco::Util::Application &self) override;
|
||||
|
||||
inline Poco::Net::HTTPRequestHandler *CallServer(const char *Path) {
|
||||
RESTAPIHandler::BindingMap Bindings;
|
||||
return RESTAPI_internal_server(Path, Bindings, Logger_, Server_);
|
||||
}
|
||||
private:
|
||||
static RESTAPI_InternalServer *instance_;
|
||||
std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_;
|
||||
Poco::ThreadPool Pool_;
|
||||
RESTAPI_GenericServer Server_;
|
||||
|
||||
RESTAPI_InternalServer() noexcept: SubSystemServer("RESTAPIInternalServer", "REST-ISRV", "openwifi.internal.restapi")
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
inline RESTAPI_InternalServer * RESTAPI_InternalServer() { return RESTAPI_InternalServer::instance(); };
|
||||
|
||||
class InternalRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory {
|
||||
public:
|
||||
InternalRequestHandlerFactory(RESTAPI_GenericServer & Server) :
|
||||
Logger_(RESTAPI_InternalServer()->Logger()),
|
||||
Server_(Server){}
|
||||
|
||||
inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override {
|
||||
Poco::URI uri(Request.getURI());
|
||||
auto *Path = uri.getPath().c_str();
|
||||
return RESTAPI_InternalServer()->CallServer(Path);
|
||||
}
|
||||
private:
|
||||
Poco::Logger & Logger_;
|
||||
RESTAPI_GenericServer &Server_;
|
||||
};
|
||||
|
||||
inline int RESTAPI_InternalServer::Start() {
|
||||
Logger_.information("Starting.");
|
||||
Server_.InitLogging();
|
||||
|
||||
for(const auto & Svr: ConfigServersList_) {
|
||||
Logger_.information(Poco::format("Starting: %s:%s Keyfile:%s CertFile: %s", Svr.Address(), std::to_string(Svr.Port()),
|
||||
Svr.KeyFile(),Svr.CertFile()));
|
||||
|
||||
auto Sock{Svr.CreateSecureSocket(Logger_)};
|
||||
|
||||
Svr.LogCert(Logger_);
|
||||
if(!Svr.RootCA().empty())
|
||||
Svr.LogCas(Logger_);
|
||||
auto Params = new Poco::Net::HTTPServerParams;
|
||||
Params->setMaxThreads(50);
|
||||
Params->setMaxQueued(200);
|
||||
Params->setKeepAlive(true);
|
||||
|
||||
auto NewServer = std::make_unique<Poco::Net::HTTPServer>(new InternalRequestHandlerFactory(Server_), Pool_, Sock, Params);
|
||||
NewServer->start();
|
||||
RESTServers_.push_back(std::move(NewServer));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
struct MicroServiceMeta {
|
||||
uint64_t Id=0;
|
||||
std::string Type;
|
||||
@@ -2355,6 +2530,7 @@ namespace OpenWifi {
|
||||
// add the default services
|
||||
SubSystems_.push_back(KafkaManager());
|
||||
SubSystems_.push_back(ALBHealthCheckServer());
|
||||
SubSystems_.push_back(RESTAPI_server());
|
||||
|
||||
Poco::Net::initializeSSL();
|
||||
Poco::Net::HTTPStreamFactory::registerFactory();
|
||||
@@ -2873,6 +3049,20 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
inline void RESTAPI_server::reinitialize(Poco::Util::Application &self) {
|
||||
MicroService::instance().LoadConfigurationFile();
|
||||
Logger_.information("Reinitializing.");
|
||||
Stop();
|
||||
Start();
|
||||
}
|
||||
|
||||
void RESTAPI_InternalServer::reinitialize(Poco::Util::Application &self) {
|
||||
MicroService::instance().LoadConfigurationFile();
|
||||
Logger_.information("Reinitializing.");
|
||||
Stop();
|
||||
Start();
|
||||
}
|
||||
|
||||
class RESTAPI_system_command : public RESTAPIHandler {
|
||||
public:
|
||||
RESTAPI_system_command(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal)
|
||||
|
||||
Reference in New Issue
Block a user