mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
synced 2025-11-02 03:37:51 +00:00
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
project(owsec VERSION 2.8.0)
|
project(owsec VERSION 2.9.0)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,13 @@ namespace OpenWifi {
|
|||||||
poco_information(Logger(),"Starting...");
|
poco_information(Logger(),"Starting...");
|
||||||
Running_=true;
|
Running_=true;
|
||||||
Port_ = (int)MicroServiceConfigGetInt("alb.port",15015);
|
Port_ = (int)MicroServiceConfigGetInt("alb.port",15015);
|
||||||
Socket_ = std::make_unique<Poco::Net::ServerSocket>(Port_);
|
Poco::Net::IPAddress Addr(Poco::Net::IPAddress::wildcard(
|
||||||
|
Poco::Net::Socket::supportsIPv6() ? Poco::Net::AddressFamily::IPv6
|
||||||
|
: Poco::Net::AddressFamily::IPv4));
|
||||||
|
Poco::Net::SocketAddress SockAddr(Addr, Port_);
|
||||||
|
Poco::Net::ServerSocket ClientSocket(SockAddr, 64);
|
||||||
|
|
||||||
|
Socket_ = std::make_unique<Poco::Net::ServerSocket>(SockAddr, Port_);
|
||||||
auto Params = new Poco::Net::HTTPServerParams;
|
auto Params = new Poco::Net::HTTPServerParams;
|
||||||
Params->setName("ws:alb");
|
Params->setName("ws:alb");
|
||||||
Server_ = std::make_unique<Poco::Net::HTTPServer>(new ALBRequestHandlerFactory(Logger()), *Socket_, Params);
|
Server_ = std::make_unique<Poco::Net::HTTPServer>(new ALBRequestHandlerFactory(Logger()), *Socket_, Params);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -365,6 +365,8 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
LoadMyConfig();
|
LoadMyConfig();
|
||||||
|
|
||||||
|
AllowExternalMicroServices_ = ConfigGetBool("allowexternalmicroservices",true);
|
||||||
|
|
||||||
InitializeSubSystemServers();
|
InitializeSubSystemServers();
|
||||||
ServerApplication::initialize(self);
|
ServerApplication::initialize(self);
|
||||||
DaemonPostInitialization(self);
|
DaemonPostInitialization(self);
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ namespace OpenWifi {
|
|||||||
static void SetSQLLogs(bool UseAsync, bool AllowWebSocket, const std::string & FormatterPattern);
|
static void SetSQLLogs(bool UseAsync, bool AllowWebSocket, const std::string & FormatterPattern);
|
||||||
static void SetSyslogLogs(bool UseAsync, bool AllowWebSocket, const std::string & FormatterPattern);
|
static void SetSyslogLogs(bool UseAsync, bool AllowWebSocket, const std::string & FormatterPattern);
|
||||||
static void SetFileLogs(bool UseAsync, bool AllowWebSocket, const std::string & FormatterPattern, const std::string & root_env_var);
|
static void SetFileLogs(bool UseAsync, bool AllowWebSocket, const std::string & FormatterPattern, const std::string & root_env_var);
|
||||||
|
inline bool AllowExternalMicroServices() const { return AllowExternalMicroServices_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static MicroService * instance_;
|
static MicroService * instance_;
|
||||||
@@ -193,6 +194,7 @@ namespace OpenWifi {
|
|||||||
SubSystemVec SubSystems_;
|
SubSystemVec SubSystems_;
|
||||||
bool NoAPISecurity_=false;
|
bool NoAPISecurity_=false;
|
||||||
bool NoBuiltInCrypto_=false;
|
bool NoBuiltInCrypto_=false;
|
||||||
|
bool AllowExternalMicroServices_=false;
|
||||||
Poco::JWT::Signer Signer_;
|
Poco::JWT::Signer Signer_;
|
||||||
Poco::Logger &Logger_;
|
Poco::Logger &Logger_;
|
||||||
Poco::ThreadPool TimerPool_{"timer:pool",2,32};
|
Poco::ThreadPool TimerPool_{"timer:pool",2,32};
|
||||||
|
|||||||
@@ -102,6 +102,48 @@ namespace OpenWifi {
|
|||||||
E.displayText(),
|
E.displayText(),
|
||||||
E.message(),
|
E.message(),
|
||||||
E.what()));
|
E.what()));
|
||||||
|
} catch (const Poco::TimeoutException &E) {
|
||||||
|
poco_error(App_.logger(), fmt::format("Poco::TimeoutException thr_name={} thr_id={} code={} text={} msg={} what={}",
|
||||||
|
t_name, t_id, E.code(),
|
||||||
|
E.displayText(),
|
||||||
|
E.message(),
|
||||||
|
E.what()));
|
||||||
|
} catch (const Poco::NoThreadAvailableException &E) {
|
||||||
|
poco_error(App_.logger(), fmt::format("Poco::NoThreadAvailableException thr_name={} thr_id={} code={} text={} msg={} what={}",
|
||||||
|
t_name, t_id, E.code(),
|
||||||
|
E.displayText(),
|
||||||
|
E.message(),
|
||||||
|
E.what()));
|
||||||
|
} catch (const Poco::OutOfMemoryException &E) {
|
||||||
|
poco_error(App_.logger(), fmt::format("Poco::OutOfMemoryException thr_name={} thr_id={} code={} text={} msg={} what={}",
|
||||||
|
t_name, t_id, E.code(),
|
||||||
|
E.displayText(),
|
||||||
|
E.message(),
|
||||||
|
E.what()));
|
||||||
|
} catch (const Poco::BadCastException &E) {
|
||||||
|
poco_error(App_.logger(), fmt::format("Poco::BadCastException thr_name={} thr_id={} code={} text={} msg={} what={}",
|
||||||
|
t_name, t_id, E.code(),
|
||||||
|
E.displayText(),
|
||||||
|
E.message(),
|
||||||
|
E.what()));
|
||||||
|
} catch (const Poco::DataException &E) {
|
||||||
|
poco_error(App_.logger(), fmt::format("Poco::DataException thr_name={} thr_id={} code={} text={} msg={} what={}",
|
||||||
|
t_name, t_id, E.code(),
|
||||||
|
E.displayText(),
|
||||||
|
E.message(),
|
||||||
|
E.what()));
|
||||||
|
} catch (const Poco::PoolOverflowException &E) {
|
||||||
|
poco_error(App_.logger(), fmt::format("Poco::PoolOverflowException thr_name={} thr_id={} code={} text={} msg={} what={}",
|
||||||
|
t_name, t_id, E.code(),
|
||||||
|
E.displayText(),
|
||||||
|
E.message(),
|
||||||
|
E.what()));
|
||||||
|
} catch (const Poco::SystemException &E) {
|
||||||
|
poco_error(App_.logger(), fmt::format("Poco::SystemException thr_name={} thr_id={} code={} text={} msg={} what={}",
|
||||||
|
t_name, t_id, E.code(),
|
||||||
|
E.displayText(),
|
||||||
|
E.message(),
|
||||||
|
E.what()));
|
||||||
} catch (const Poco::RuntimeException &E) {
|
} catch (const Poco::RuntimeException &E) {
|
||||||
poco_error(App_.logger(), fmt::format("Poco::RuntimeException thr_name={} thr_id={} code={} text={} msg={} what={}",
|
poco_error(App_.logger(), fmt::format("Poco::RuntimeException thr_name={} thr_id={} code={} text={} msg={} what={}",
|
||||||
t_name, t_id, E.code(),
|
t_name, t_id, E.code(),
|
||||||
|
|||||||
@@ -118,4 +118,9 @@ namespace OpenWifi {
|
|||||||
void MicroServiceDeleteOverrideConfiguration() {
|
void MicroServiceDeleteOverrideConfiguration() {
|
||||||
return MicroService::instance().DeleteOverrideConfiguration();
|
return MicroService::instance().DeleteOverrideConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AllowExternalMicroServices() {
|
||||||
|
return MicroService::instance().AllowExternalMicroServices();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,4 +53,5 @@ namespace OpenWifi {
|
|||||||
std::string MicroServiceSign(Poco::JWT::Token &T, const std::string &Algo);
|
std::string MicroServiceSign(Poco::JWT::Token &T, const std::string &Algo);
|
||||||
std::string MicroServiceGetPublicAPIEndPoint();
|
std::string MicroServiceGetPublicAPIEndPoint();
|
||||||
void MicroServiceDeleteOverrideConfiguration();
|
void MicroServiceDeleteOverrideConfiguration();
|
||||||
|
bool AllowExternalMicroServices();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ namespace OpenWifi {
|
|||||||
Response->setChunkedTransferEncoding(true);
|
Response->setChunkedTransferEncoding(true);
|
||||||
Response->setContentType("application/json");
|
Response->setContentType("application/json");
|
||||||
auto Origin = Request->find("Origin");
|
auto Origin = Request->find("Origin");
|
||||||
if (Origin != Request->end()) {
|
if (Origin != Request->end() && !AllowExternalMicroServices()) {
|
||||||
Response->set("Access-Control-Allow-Origin", Origin->second);
|
Response->set("Access-Control-Allow-Origin", Origin->second);
|
||||||
} else {
|
} else {
|
||||||
Response->set("Access-Control-Allow-Origin", "*");
|
Response->set("Access-Control-Allow-Origin", "*");
|
||||||
@@ -322,7 +322,7 @@ namespace OpenWifi {
|
|||||||
Response->setVersion(Poco::Net::HTTPMessage::HTTP_1_1);
|
Response->setVersion(Poco::Net::HTTPMessage::HTTP_1_1);
|
||||||
Response->setChunkedTransferEncoding(true);
|
Response->setChunkedTransferEncoding(true);
|
||||||
auto Origin = Request->find("Origin");
|
auto Origin = Request->find("Origin");
|
||||||
if (Origin != Request->end()) {
|
if (Origin != Request->end() && !AllowExternalMicroServices()) {
|
||||||
Response->set("Access-Control-Allow-Origin", Origin->second);
|
Response->set("Access-Control-Allow-Origin", Origin->second);
|
||||||
} else {
|
} else {
|
||||||
Response->set("Access-Control-Allow-Origin", "*");
|
Response->set("Access-Control-Allow-Origin", "*");
|
||||||
@@ -633,6 +633,18 @@ namespace OpenWifi {
|
|||||||
ReturnObject(Answer);
|
ReturnObject(Answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T> void Object(const char *Name, const std::vector<T> & Objects) {
|
||||||
|
Poco::JSON::Object Answer;
|
||||||
|
RESTAPI_utils::field_to_json(Answer,Name,Objects);
|
||||||
|
ReturnObject(Answer);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> void Object(const T &O) {
|
||||||
|
Poco::JSON::Object Answer;
|
||||||
|
O.to_json(Answer);
|
||||||
|
ReturnObject(Answer);
|
||||||
|
}
|
||||||
|
|
||||||
Poco::Logger & Logger() { return Logger_; }
|
Poco::Logger & Logger() { return Logger_; }
|
||||||
|
|
||||||
virtual void DoGet() = 0 ;
|
virtual void DoGet() = 0 ;
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool UI_WebSocketClientServer::SendToUser(const std::string &UserName, std::uint64_t id, const std::string &Payload) {
|
bool UI_WebSocketClientServer::SendToUser(const std::string &UserName, std::uint64_t id, const std::string &Payload) {
|
||||||
std::lock_guard G(Mutex_);
|
std::lock_guard G(LocalMutex_);
|
||||||
|
|
||||||
for(const auto &Client:Clients_) {
|
for(const auto &Client:Clients_) {
|
||||||
if(Client.second->UserName_ == UserName) {
|
if(Client.second->UserName_ == UserName) {
|
||||||
@@ -139,7 +139,7 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UI_WebSocketClientServer::SendToAll(std::uint64_t id, const std::string &Payload) {
|
void UI_WebSocketClientServer::SendToAll(std::uint64_t id, const std::string &Payload) {
|
||||||
std::lock_guard G(Mutex_);
|
std::lock_guard G(LocalMutex_);
|
||||||
|
|
||||||
for(const auto &Client:Clients_) {
|
for(const auto &Client:Clients_) {
|
||||||
try {
|
try {
|
||||||
@@ -189,7 +189,6 @@ namespace OpenWifi {
|
|||||||
void UI_WebSocketClientServer::OnSocketReadable([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf) {
|
void UI_WebSocketClientServer::OnSocketReadable([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf) {
|
||||||
|
|
||||||
UI_WebSocketClientServer::ClientList::iterator Client;
|
UI_WebSocketClientServer::ClientList::iterator Client;
|
||||||
|
|
||||||
std::lock_guard G(LocalMutex_);
|
std::lock_guard G(LocalMutex_);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -295,6 +294,7 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
void UI_WebSocketClientServer::OnSocketShutdown([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf) {
|
void UI_WebSocketClientServer::OnSocketShutdown([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf) {
|
||||||
try {
|
try {
|
||||||
|
std::lock_guard G(LocalMutex_);
|
||||||
auto Client = Clients_.find(pNf->socket().impl()->sockfd());
|
auto Client = Clients_.find(pNf->socket().impl()->sockfd());
|
||||||
if (Client == end(Clients_))
|
if (Client == end(Clients_))
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -231,7 +231,9 @@ namespace OpenWifi::RESTAPI::Errors {
|
|||||||
static const struct msg DeviceIsRestricted{1151,"Device is protected by regulation. This function is not allowed."};
|
static const struct msg DeviceIsRestricted{1151,"Device is protected by regulation. This function is not allowed."};
|
||||||
static const struct msg InvalidURI{1152,"Invalid URI."};
|
static const struct msg InvalidURI{1152,"Invalid URI."};
|
||||||
static const struct msg InvalidScriptSelection{1153,"Only script or scriptId must be specified. Not both."};
|
static const struct msg InvalidScriptSelection{1153,"Only script or scriptId must be specified. Not both."};
|
||||||
}
|
|
||||||
|
static const struct msg NoDeviceStatisticsYet{1154,"Device statistics not available yet."};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -526,6 +528,63 @@ namespace OpenWifi::uCentralProtocol::Events {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace OpenWifi::APCommands {
|
||||||
|
enum class Commands:uint8_t {
|
||||||
|
capabilities,
|
||||||
|
logs,
|
||||||
|
healthchecks,
|
||||||
|
statistics,
|
||||||
|
status,
|
||||||
|
rtty,
|
||||||
|
configure,
|
||||||
|
upgrade,
|
||||||
|
reboot,
|
||||||
|
factory,
|
||||||
|
leds,
|
||||||
|
trace,
|
||||||
|
request,
|
||||||
|
wifiscan,
|
||||||
|
eventqueue,
|
||||||
|
telemetry,
|
||||||
|
ping,
|
||||||
|
script,
|
||||||
|
unknown
|
||||||
|
};
|
||||||
|
|
||||||
|
inline static const std::vector<const char *> uCentralAPCommands {
|
||||||
|
RESTAPI::Protocol::CAPABILITIES,
|
||||||
|
RESTAPI::Protocol::LOGS,
|
||||||
|
RESTAPI::Protocol::HEALTHCHECKS,
|
||||||
|
RESTAPI::Protocol::STATISTICS,
|
||||||
|
RESTAPI::Protocol::STATUS,
|
||||||
|
RESTAPI::Protocol::RTTY,
|
||||||
|
RESTAPI::Protocol::CONFIGURE,
|
||||||
|
RESTAPI::Protocol::UPGRADE,
|
||||||
|
RESTAPI::Protocol::REBOOT,
|
||||||
|
RESTAPI::Protocol::FACTORY,
|
||||||
|
RESTAPI::Protocol::LEDS,
|
||||||
|
RESTAPI::Protocol::TRACE,
|
||||||
|
RESTAPI::Protocol::REQUEST,
|
||||||
|
RESTAPI::Protocol::WIFISCAN,
|
||||||
|
RESTAPI::Protocol::EVENTQUEUE,
|
||||||
|
RESTAPI::Protocol::TELEMETRY,
|
||||||
|
RESTAPI::Protocol::PING,
|
||||||
|
RESTAPI::Protocol::SCRIPT};
|
||||||
|
|
||||||
|
inline const char * to_string(Commands Cmd) {
|
||||||
|
return uCentralAPCommands[(uint8_t)Cmd];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Commands to_apcommand(const char *cmd) {
|
||||||
|
for(auto i=(uint8_t)Commands::capabilities;i!=(uint8_t)Commands::unknown;++i) {
|
||||||
|
if(strcmp(uCentralAPCommands[i],cmd)==0)
|
||||||
|
return (Commands)i;
|
||||||
|
}
|
||||||
|
return Commands::unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
namespace OpenWifi::Provisioning::DeviceClass {
|
namespace OpenWifi::Provisioning::DeviceClass {
|
||||||
|
|
||||||
static const char * ANY = "any";
|
static const char * ANY = "any";
|
||||||
|
|||||||
Reference in New Issue
Block a user