mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
synced 2025-11-01 19:27:59 +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)
|
||||
project(owsec VERSION 2.8.0)
|
||||
project(owsec VERSION 2.9.0)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
|
||||
@@ -51,7 +51,13 @@ namespace OpenWifi {
|
||||
poco_information(Logger(),"Starting...");
|
||||
Running_=true;
|
||||
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;
|
||||
Params->setName("ws:alb");
|
||||
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();
|
||||
|
||||
AllowExternalMicroServices_ = ConfigGetBool("allowexternalmicroservices",true);
|
||||
|
||||
InitializeSubSystemServers();
|
||||
ServerApplication::initialize(self);
|
||||
DaemonPostInitialization(self);
|
||||
|
||||
@@ -163,6 +163,7 @@ namespace OpenWifi {
|
||||
static void SetSQLLogs(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);
|
||||
inline bool AllowExternalMicroServices() const { return AllowExternalMicroServices_; }
|
||||
|
||||
private:
|
||||
static MicroService * instance_;
|
||||
@@ -193,6 +194,7 @@ namespace OpenWifi {
|
||||
SubSystemVec SubSystems_;
|
||||
bool NoAPISecurity_=false;
|
||||
bool NoBuiltInCrypto_=false;
|
||||
bool AllowExternalMicroServices_=false;
|
||||
Poco::JWT::Signer Signer_;
|
||||
Poco::Logger &Logger_;
|
||||
Poco::ThreadPool TimerPool_{"timer:pool",2,32};
|
||||
|
||||
@@ -102,6 +102,48 @@ namespace OpenWifi {
|
||||
E.displayText(),
|
||||
E.message(),
|
||||
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) {
|
||||
poco_error(App_.logger(), fmt::format("Poco::RuntimeException thr_name={} thr_id={} code={} text={} msg={} what={}",
|
||||
t_name, t_id, E.code(),
|
||||
|
||||
@@ -118,4 +118,9 @@ namespace OpenWifi {
|
||||
void MicroServiceDeleteOverrideConfiguration() {
|
||||
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 MicroServiceGetPublicAPIEndPoint();
|
||||
void MicroServiceDeleteOverrideConfiguration();
|
||||
bool AllowExternalMicroServices();
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ namespace OpenWifi {
|
||||
Response->setChunkedTransferEncoding(true);
|
||||
Response->setContentType("application/json");
|
||||
auto Origin = Request->find("Origin");
|
||||
if (Origin != Request->end()) {
|
||||
if (Origin != Request->end() && !AllowExternalMicroServices()) {
|
||||
Response->set("Access-Control-Allow-Origin", Origin->second);
|
||||
} else {
|
||||
Response->set("Access-Control-Allow-Origin", "*");
|
||||
@@ -322,7 +322,7 @@ namespace OpenWifi {
|
||||
Response->setVersion(Poco::Net::HTTPMessage::HTTP_1_1);
|
||||
Response->setChunkedTransferEncoding(true);
|
||||
auto Origin = Request->find("Origin");
|
||||
if (Origin != Request->end()) {
|
||||
if (Origin != Request->end() && !AllowExternalMicroServices()) {
|
||||
Response->set("Access-Control-Allow-Origin", Origin->second);
|
||||
} else {
|
||||
Response->set("Access-Control-Allow-Origin", "*");
|
||||
@@ -633,6 +633,18 @@ namespace OpenWifi {
|
||||
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_; }
|
||||
|
||||
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) {
|
||||
std::lock_guard G(Mutex_);
|
||||
std::lock_guard G(LocalMutex_);
|
||||
|
||||
for(const auto &Client:Clients_) {
|
||||
if(Client.second->UserName_ == UserName) {
|
||||
@@ -139,7 +139,7 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
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_) {
|
||||
try {
|
||||
@@ -189,7 +189,6 @@ namespace OpenWifi {
|
||||
void UI_WebSocketClientServer::OnSocketReadable([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf) {
|
||||
|
||||
UI_WebSocketClientServer::ClientList::iterator Client;
|
||||
|
||||
std::lock_guard G(LocalMutex_);
|
||||
|
||||
try {
|
||||
@@ -295,6 +294,7 @@ namespace OpenWifi {
|
||||
|
||||
void UI_WebSocketClientServer::OnSocketShutdown([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf) {
|
||||
try {
|
||||
std::lock_guard G(LocalMutex_);
|
||||
auto Client = Clients_.find(pNf->socket().impl()->sockfd());
|
||||
if (Client == end(Clients_))
|
||||
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 InvalidURI{1152,"Invalid URI."};
|
||||
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 {
|
||||
|
||||
static const char * ANY = "any";
|
||||
|
||||
Reference in New Issue
Block a user