stephb9959
2023-01-08 10:46:29 -08:00
parent 6a1fa01235
commit 6312c7b1d8
12 changed files with 2740 additions and 2602 deletions

View File

@@ -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)

2
build
View File

@@ -1 +1 @@
33
2

View File

@@ -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);

View File

@@ -19,10 +19,9 @@
namespace OpenWifi {
static const std::string GitUCentralJSONSchemaFile{
"https://raw.githubusercontent.com/blogic/ucentral-schema/main/ucentral.schema.json"};
"https://raw.githubusercontent.com/Telecominfraproject/wlan-ucentral-schema/main/ucentral.schema.json"};
static json DefaultUCentralSchema = R"(
{
"$id": "https://openwrt.org/ucentral.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
@@ -49,7 +48,7 @@ static json DefaultUCentralSchema = R"(
"switch": {
"$ref": "#/$defs/switch"
},
"radiosgrep": {
"radios": {
"type": "array",
"items": {
"$ref": "#/$defs/radio"
@@ -201,7 +200,8 @@ static json DefaultUCentralSchema = R"(
]
},
"wireless-multimedia": {
"anyOf": [{
"anyOf": [
{
"$ref": "#/$defs/globals.wireless-multimedia.table"
},
{
@@ -395,7 +395,8 @@ static json DefaultUCentralSchema = R"(
]
},
"channel": {
"oneOf": [{
"oneOf": [
{
"type": "integer",
"maximum": 196,
"minimum": 1
@@ -1004,7 +1005,8 @@ static json DefaultUCentralSchema = R"(
}
},
"interface.broad-band": {
"oneOf": [{
"oneOf": [
{
"$ref": "#/$defs/interface.broad-band.wwan"
},
{
@@ -1261,7 +1263,8 @@ static json DefaultUCentralSchema = R"(
"minimum": 1
},
"value": {
"anyOf": [{
"anyOf": [
{
"type": "integer",
"maximum": 4294967295,
"minimum": 0
@@ -1272,7 +1275,8 @@ static json DefaultUCentralSchema = R"(
]
}
},
"examples": [{
"examples": [
{
"id": 27,
"value": 900
},
@@ -1336,7 +1340,8 @@ static json DefaultUCentralSchema = R"(
}
},
"authentication": {
"allOf": [{
"allOf": [
{
"$ref": "#/$defs/interface.ssid.radius.server"
},
{
@@ -1351,7 +1356,8 @@ static json DefaultUCentralSchema = R"(
]
},
"accounting": {
"allOf": [{
"allOf": [
{
"$ref": "#/$defs/interface.ssid.radius.server"
},
{
@@ -1554,13 +1560,15 @@ static json DefaultUCentralSchema = R"(
]
}
},
"examples": [{
"examples": [
{
"width": 32,
"height": 32,
"type": "image/png",
"language": "eng",
"icon": "R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
}]
}
]
}
},
"wan-metrics": {
@@ -1806,7 +1814,8 @@ static json DefaultUCentralSchema = R"(
}
},
"interface.tunnel": {
"oneOf": [{
"oneOf": [
{
"$ref": "#/$defs/interface.tunnel.mesh"
},
{
@@ -2630,12 +2639,12 @@ static json DefaultUCentralSchema = R"(
return;
std::string GitSchema;
if(MicroServiceConfigGetBool("ucentral.datamodel.internal",true)) {
// if(MicroServiceConfigGetBool("ucentral.datamodel.internal",true)) {
RootSchema_ = DefaultUCentralSchema;
poco_information(Logger(),"Using uCentral validation from built-in default.");
Initialized_ = Working_ = true;
return;
}
// }
try {
auto GitURI = MicroServiceConfigGetString("ucentral.datamodel.uri",GitUCentralJSONSchemaFile);
@@ -2749,7 +2758,7 @@ static json DefaultUCentralSchema = R"(
if(std::regex_match(value,host_regex))
return;
throw std::invalid_argument(value + " is not a proper FQDN.");
} else if(format == "fqdn") {
} else if(format == "fqdn" || format=="uc-fqdn") {
if(std::regex_match(value,host_regex))
return;
throw std::invalid_argument(value + " is not a proper FQDN.");

View File

@@ -365,6 +365,8 @@ namespace OpenWifi {
LoadMyConfig();
AllowExternalMicroServices_ = ConfigGetBool("allowexternalmicroservices",true);
InitializeSubSystemServers();
ServerApplication::initialize(self);
DaemonPostInitialization(self);

View File

@@ -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};

View File

@@ -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(),

View File

@@ -118,4 +118,9 @@ namespace OpenWifi {
void MicroServiceDeleteOverrideConfiguration() {
return MicroService::instance().DeleteOverrideConfiguration();
}
bool AllowExternalMicroServices() {
return MicroService::instance().AllowExternalMicroServices();
}
}

View File

@@ -53,4 +53,5 @@ namespace OpenWifi {
std::string MicroServiceSign(Poco::JWT::Token &T, const std::string &Algo);
std::string MicroServiceGetPublicAPIEndPoint();
void MicroServiceDeleteOverrideConfiguration();
bool AllowExternalMicroServices();
}

View File

@@ -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 ;

View File

@@ -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;

View File

@@ -231,6 +231,8 @@ 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";