mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
synced 2025-10-31 18:57:51 +00:00
Compare commits
19 Commits
v2.6.0-RC2
...
release/v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
830750f857 | ||
|
|
f8d3079f44 | ||
|
|
81cec762f7 | ||
|
|
a430ad7e71 | ||
|
|
d1c13ad2dd | ||
|
|
b837e41569 | ||
|
|
5e39987e36 | ||
|
|
890eb7311a | ||
|
|
fc509adf01 | ||
|
|
f43198f874 | ||
|
|
767331f575 | ||
|
|
d26ef6eeba | ||
|
|
8c672f058f | ||
|
|
3134947b57 | ||
|
|
448563ab06 | ||
|
|
2a22a35e58 | ||
|
|
e745d4efe7 | ||
|
|
701e0b50ff | ||
|
|
df082a969e |
8
.github/workflows/cleanup.yml
vendored
8
.github/workflows/cleanup.yml
vendored
@@ -17,4 +17,10 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- run: |
|
- run: |
|
||||||
export PR_BRANCH_TAG=$(echo ${GITHUB_HEAD_REF#refs/heads/} | tr '/' '-')
|
export PR_BRANCH_TAG=$(echo ${GITHUB_HEAD_REF#refs/heads/} | tr '/' '-')
|
||||||
curl -uucentral:${{ secrets.DOCKER_REGISTRY_PASSWORD }} -X DELETE "https://tip.jfrog.io/artifactory/tip-wlan-cloud-ucentral/owsec/$PR_BRANCH_TAG"
|
|
||||||
|
if [[ ! $PR_BRANCH_TAG =~ (main|master|release-*) ]]; then
|
||||||
|
echo "PR branch is $PR_BRANCH_TAG, deleting Docker image"
|
||||||
|
curl -s -uucentral:${{ secrets.DOCKER_REGISTRY_PASSWORD }} -X DELETE "https://tip.jfrog.io/artifactory/tip-wlan-cloud-ucentral/owsec/$PR_BRANCH_TAG"
|
||||||
|
else
|
||||||
|
echo "PR branch is $PR_BRANCH_TAG, not deleting Docker image"
|
||||||
|
fi
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ if [ "$SELFSIGNED_CERTS" = 'true' ]; then
|
|||||||
update-ca-certificates
|
update-ca-certificates
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$TEMPLATE_CONFIG" = 'true' && ! -f "$OWSEC_CONFIG"/owsec.properties ]]; then
|
if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
|
||||||
RESTAPI_HOST_ROOTCA=${RESTAPI_HOST_ROOTCA:-"\$OWSEC_ROOT/certs/restapi-ca.pem"} \
|
RESTAPI_HOST_ROOTCA=${RESTAPI_HOST_ROOTCA:-"\$OWSEC_ROOT/certs/restapi-ca.pem"} \
|
||||||
RESTAPI_HOST_PORT=${RESTAPI_HOST_PORT:-"16001"} \
|
RESTAPI_HOST_PORT=${RESTAPI_HOST_PORT:-"16001"} \
|
||||||
RESTAPI_HOST_CERT=${RESTAPI_HOST_CERT:-"\$OWSEC_ROOT/certs/restapi-cert.pem"} \
|
RESTAPI_HOST_CERT=${RESTAPI_HOST_CERT:-"\$OWSEC_ROOT/certs/restapi-cert.pem"} \
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ fullnameOverride: ""
|
|||||||
images:
|
images:
|
||||||
owsec:
|
owsec:
|
||||||
repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owsec
|
repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owsec
|
||||||
tag: v2.6.0-RC2
|
tag: v2.6.0
|
||||||
pullPolicy: Always
|
pullPolicy: Always
|
||||||
# regcred:
|
# regcred:
|
||||||
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io
|
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
void ActionLinkManager::run() {
|
void ActionLinkManager::run() {
|
||||||
Running_ = true ;
|
Running_ = true ;
|
||||||
|
Utils::SetThreadName("action-mgr");
|
||||||
|
|
||||||
while(Running_) {
|
while(Running_) {
|
||||||
Poco::Thread::trySleep(2000);
|
Poco::Thread::trySleep(2000);
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ namespace OpenWifi {
|
|||||||
void OpenWifi::RESTAPI_sms_handler::DoPost() {
|
void OpenWifi::RESTAPI_sms_handler::DoPost() {
|
||||||
const auto &Obj = ParsedBody_;
|
const auto &Obj = ParsedBody_;
|
||||||
|
|
||||||
|
if(!SMSSender()->Enabled()) {
|
||||||
|
return BadRequest(RESTAPI::Errors::SMSMFANotEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
std::string Arg;
|
std::string Arg;
|
||||||
if(HasParameter("validateNumber",Arg) && Arg=="true" && Obj->has("to")) {
|
if(HasParameter("validateNumber",Arg) && Arg=="true" && Obj->has("to")) {
|
||||||
auto Number = Obj->get("to").toString();
|
auto Number = Obj->get("to").toString();
|
||||||
|
|||||||
@@ -76,12 +76,21 @@ namespace OpenWifi {
|
|||||||
return BadRequest(RESTAPI::Errors::SMSMissingPhoneNumber);
|
return BadRequest(RESTAPI::Errors::SMSMissingPhoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!SMSSender()->Enabled()) {
|
||||||
|
return BadRequest(RESTAPI::Errors::SMSMFANotEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
if (SMSSender()->StartValidation(MFC.sms, UserInfo_.userinfo.email)) {
|
if (SMSSender()->StartValidation(MFC.sms, UserInfo_.userinfo.email)) {
|
||||||
return OK();
|
return OK();
|
||||||
} else {
|
} else {
|
||||||
return InternalError(RESTAPI::Errors::SMSTryLater);
|
return InternalError(RESTAPI::Errors::SMSTryLater);
|
||||||
}
|
}
|
||||||
} else if (GetBoolParameter("completeValidation", false)) {
|
} else if (GetBoolParameter("completeValidation", false)) {
|
||||||
|
|
||||||
|
if(!SMSSender()->Enabled()) {
|
||||||
|
return BadRequest(RESTAPI::Errors::SMSMFANotEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
auto ChallengeCode = GetParameter("challengeCode", "");
|
auto ChallengeCode = GetParameter("challengeCode", "");
|
||||||
if (ChallengeCode.empty()) {
|
if (ChallengeCode.empty()) {
|
||||||
return BadRequest(RESTAPI::Errors::SMSMissingChallenge);
|
return BadRequest(RESTAPI::Errors::SMSMissingChallenge);
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
bool SMSSender::StartValidation(const std::string &Number, const std::string &UserName) {
|
bool SMSSender::StartValidation(const std::string &Number, const std::string &UserName) {
|
||||||
std::lock_guard G(Mutex_);
|
std::lock_guard G(Mutex_);
|
||||||
|
if(!Enabled_)
|
||||||
|
return false;
|
||||||
CleanCache();
|
CleanCache();
|
||||||
uint64_t Now=OpenWifi::Now();
|
uint64_t Now=OpenWifi::Now();
|
||||||
auto Challenge = MFAServer::MakeChallenge();
|
auto Challenge = MFAServer::MakeChallenge();
|
||||||
@@ -56,6 +58,9 @@ namespace OpenWifi {
|
|||||||
bool SMSSender::IsNumberValid(const std::string &Number, const std::string &UserName) {
|
bool SMSSender::IsNumberValid(const std::string &Number, const std::string &UserName) {
|
||||||
std::lock_guard G(Mutex_);
|
std::lock_guard G(Mutex_);
|
||||||
|
|
||||||
|
if(!Enabled_)
|
||||||
|
return false;
|
||||||
|
|
||||||
for(const auto &i:Cache_) {
|
for(const auto &i:Cache_) {
|
||||||
if(i.Number==Number && i.UserName==UserName)
|
if(i.Number==Number && i.UserName==UserName)
|
||||||
return i.Validated;
|
return i.Validated;
|
||||||
@@ -66,6 +71,9 @@ namespace OpenWifi {
|
|||||||
bool SMSSender::CompleteValidation(const std::string &Number, const std::string &Code, const std::string &UserName) {
|
bool SMSSender::CompleteValidation(const std::string &Number, const std::string &Code, const std::string &UserName) {
|
||||||
std::lock_guard G(Mutex_);
|
std::lock_guard G(Mutex_);
|
||||||
|
|
||||||
|
if(!Enabled_)
|
||||||
|
return false;
|
||||||
|
|
||||||
for(auto &i:Cache_) {
|
for(auto &i:Cache_) {
|
||||||
if(i.Code==Code && i.Number==Number && i.UserName==UserName) {
|
if(i.Code==Code && i.Number==Number && i.UserName==UserName) {
|
||||||
i.Validated=true;
|
i.Validated=true;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
void SMTPMailerService::run() {
|
void SMTPMailerService::run() {
|
||||||
Running_ = true;
|
Running_ = true;
|
||||||
|
Utils::SetThreadName("smtp-mailer");
|
||||||
while(Running_) {
|
while(Running_) {
|
||||||
|
|
||||||
Poco::Thread::trySleep(10000);
|
Poco::Thread::trySleep(10000);
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Archiver::onTimer([[maybe_unused]] Poco::Timer &timer) {
|
void Archiver::onTimer([[maybe_unused]] Poco::Timer &timer) {
|
||||||
|
Utils::SetThreadName("archiver");
|
||||||
Poco::Logger &logger = Poco::Logger::get("STORAGE-ARCHIVER");
|
Poco::Logger &logger = Poco::Logger::get("STORAGE-ARCHIVER");
|
||||||
logger.information("Squiggy the DB: removing old tokens.");
|
logger.information("Squiggy the DB: removing old tokens.");
|
||||||
StorageService()->SubTokenDB().CleanExpiredTokens();
|
StorageService()->SubTokenDB().CleanExpiredTokens();
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ namespace OpenWifi {
|
|||||||
inline uint64_t Now() { return std::time(nullptr); };
|
inline uint64_t Now() { return std::time(nullptr); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace OpenWifi::Utils {
|
||||||
|
std::vector<unsigned char> base64decode(const std::string& input);
|
||||||
|
std::string base64encode(const unsigned char *input, uint32_t size);
|
||||||
|
}
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
#include "Poco/Util/Application.h"
|
#include "Poco/Util/Application.h"
|
||||||
@@ -238,6 +243,11 @@ namespace OpenWifi::RESTAPI_utils {
|
|||||||
Obj.set(Field,Value);
|
Obj.set(Field,Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Poco::Data::BLOB &Value) {
|
||||||
|
auto Result = Utils::base64encode((const unsigned char *)Value.rawContent(),Value.size());
|
||||||
|
Obj.set(Field,Result);
|
||||||
|
}
|
||||||
|
|
||||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::StringPairVec & S) {
|
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::StringPairVec & S) {
|
||||||
Poco::JSON::Array Array;
|
Poco::JSON::Array Array;
|
||||||
for(const auto &i:S) {
|
for(const auto &i:S) {
|
||||||
@@ -377,6 +387,13 @@ namespace OpenWifi::RESTAPI_utils {
|
|||||||
Value = (uint64_t)Obj->get(Field);
|
Value = (uint64_t)Obj->get(Field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, Poco::Data::BLOB &Value) {
|
||||||
|
if(Obj->has(Field) && !Obj->isNull(Field)) {
|
||||||
|
auto Result = Utils::base64decode(Obj->get(Field).toString());
|
||||||
|
Value.assignRaw((const unsigned char *)&Result[0],Result.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, Types::StringPairVec &Vec) {
|
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, Types::StringPairVec &Vec) {
|
||||||
if(Obj->isArray(Field) && !Obj->isNull(Field)) {
|
if(Obj->isArray(Field) && !Obj->isNull(Field)) {
|
||||||
auto O = Obj->getArray(Field);
|
auto O = Obj->getArray(Field);
|
||||||
@@ -643,6 +660,27 @@ namespace OpenWifi::RESTAPI_utils {
|
|||||||
|
|
||||||
namespace OpenWifi::Utils {
|
namespace OpenWifi::Utils {
|
||||||
|
|
||||||
|
inline void SetThreadName(const char *name) {
|
||||||
|
#ifdef __linux__
|
||||||
|
Poco::Thread::current()->setName(name);
|
||||||
|
pthread_setname_np(pthread_self(), name);
|
||||||
|
#endif
|
||||||
|
#ifdef __APPLE__
|
||||||
|
Poco::Thread::current()->setName(name);
|
||||||
|
pthread_setname_np(name);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void SetThreadName(Poco::Thread &thr, const char *name) {
|
||||||
|
#ifdef __linux__
|
||||||
|
thr.setName(name);
|
||||||
|
pthread_setname_np(thr.tid(), name);
|
||||||
|
#endif
|
||||||
|
#ifdef __APPLE__
|
||||||
|
thr.setName(name);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
enum MediaTypeEncodings {
|
enum MediaTypeEncodings {
|
||||||
PLAIN,
|
PLAIN,
|
||||||
BINARY,
|
BINARY,
|
||||||
@@ -1167,6 +1205,7 @@ namespace OpenWifi {
|
|||||||
static const std::string uSERVICE_SUBCRIBER{ "owsub"};
|
static const std::string uSERVICE_SUBCRIBER{ "owsub"};
|
||||||
static const std::string uSERVICE_INSTALLER{ "owinst"};
|
static const std::string uSERVICE_INSTALLER{ "owinst"};
|
||||||
static const std::string uSERVICE_ANALYTICS{ "owanalytics"};
|
static const std::string uSERVICE_ANALYTICS{ "owanalytics"};
|
||||||
|
static const std::string uSERVICE_OWRRM{ "owrrm"};
|
||||||
|
|
||||||
class ConfigurationEntry {
|
class ConfigurationEntry {
|
||||||
public:
|
public:
|
||||||
@@ -1315,7 +1354,7 @@ namespace OpenWifi {
|
|||||||
inline void Start();
|
inline void Start();
|
||||||
inline void Stop();
|
inline void Stop();
|
||||||
private:
|
private:
|
||||||
std::atomic_bool Running_ = false;
|
mutable std::atomic_bool Running_ = false;
|
||||||
Poco::Thread Thread_;
|
Poco::Thread Thread_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1846,7 +1885,8 @@ namespace OpenWifi {
|
|||||||
Request = &RequestIn;
|
Request = &RequestIn;
|
||||||
Response = &ResponseIn;
|
Response = &ResponseIn;
|
||||||
|
|
||||||
Poco::Thread::current()->setName("WebServerThread_" + std::to_string(TransactionId_));
|
std::string th_name = "restsvr_" + std::to_string(TransactionId_);
|
||||||
|
Utils::SetThreadName(th_name.c_str());
|
||||||
|
|
||||||
if(Request->getContentLength()>0) {
|
if(Request->getContentLength()>0) {
|
||||||
if(Request->getContentType().find("application/json")!=std::string::npos) {
|
if(Request->getContentType().find("application/json")!=std::string::npos) {
|
||||||
@@ -1895,28 +1935,24 @@ namespace OpenWifi {
|
|||||||
[[nodiscard]] inline bool NeedAdditionalInfo() const { return QB_.AdditionalInfo; }
|
[[nodiscard]] inline bool NeedAdditionalInfo() const { return QB_.AdditionalInfo; }
|
||||||
[[nodiscard]] inline const std::vector<std::string> & SelectedRecords() const { return QB_.Select; }
|
[[nodiscard]] inline const std::vector<std::string> & SelectedRecords() const { return QB_.Select; }
|
||||||
|
|
||||||
/* [[nodiscard]] inline const Poco::JSON::Object::Ptr ParseStream() {
|
|
||||||
return IncomingParser_.parse(Request->stream()).extract<Poco::JSON::Object::Ptr>();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
inline static bool ParseBindings(const std::string & Request, const std::list<std::string> & EndPoints, BindingMap &bindings) {
|
inline static bool ParseBindings(const std::string & Request, const std::list<std::string> & EndPoints, BindingMap &bindings) {
|
||||||
bindings.clear();
|
bindings.clear();
|
||||||
std::vector<std::string> PathItems = Utils::Split(Request, '/');
|
auto PathItems = Poco::StringTokenizer(Request, "/");
|
||||||
|
|
||||||
for(const auto &EndPoint:EndPoints) {
|
for(const auto &EndPoint:EndPoints) {
|
||||||
std::vector<std::string> ParamItems = Utils::Split(EndPoint, '/');
|
auto ParamItems = Poco::StringTokenizer(EndPoint, "/");
|
||||||
if (PathItems.size() != ParamItems.size())
|
if (PathItems.count() != ParamItems.count())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool Matched = true;
|
bool Matched = true;
|
||||||
for (size_t i = 0; i != PathItems.size() && Matched; i++) {
|
for (size_t i = 0; i < PathItems.count(); i++) {
|
||||||
if (PathItems[i] != ParamItems[i]) {
|
if (PathItems[i] != ParamItems[i]) {
|
||||||
if (ParamItems[i][0] == '{') {
|
if (ParamItems[i][0] == '{') {
|
||||||
auto ParamName = ParamItems[i].substr(1, ParamItems[i].size() - 2);
|
auto ParamName = ParamItems[i].substr(1, ParamItems[i].size() - 2);
|
||||||
bindings[Poco::toLower(ParamName)] = PathItems[i];
|
bindings[Poco::toLower(ParamName)] = PathItems[i];
|
||||||
} else {
|
} else {
|
||||||
Matched = false;
|
Matched = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2045,6 +2081,17 @@ namespace OpenWifi {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool AssignIfPresent(const Poco::JSON::Object::Ptr &O, const std::string &Field, Poco::Data::BLOB &Value) {
|
||||||
|
if(O->has(Field)) {
|
||||||
|
std::string Content = O->get(Field).toString();
|
||||||
|
auto DecodedBlob = Utils::base64decode(Content);
|
||||||
|
Value.assignRaw((const unsigned char *)&DecodedBlob[0],DecodedBlob.size());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T> bool AssignIfPresent(const Poco::JSON::Object::Ptr &O, const std::string &Field, const T &value, T & assignee) {
|
template <typename T> bool AssignIfPresent(const Poco::JSON::Object::Ptr &O, const std::string &Field, const T &value, T & assignee) {
|
||||||
if(O->has(Field)) {
|
if(O->has(Field)) {
|
||||||
assignee = value;
|
assignee = value;
|
||||||
@@ -2582,7 +2629,7 @@ namespace OpenWifi {
|
|||||||
private:
|
private:
|
||||||
std::recursive_mutex Mutex_;
|
std::recursive_mutex Mutex_;
|
||||||
Poco::Thread Worker_;
|
Poco::Thread Worker_;
|
||||||
std::atomic_bool Running_=false;
|
mutable std::atomic_bool Running_=false;
|
||||||
Poco::NotificationQueue Queue_;
|
Poco::NotificationQueue Queue_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2608,7 +2655,7 @@ namespace OpenWifi {
|
|||||||
private:
|
private:
|
||||||
std::recursive_mutex Mutex_;
|
std::recursive_mutex Mutex_;
|
||||||
Poco::Thread Worker_;
|
Poco::Thread Worker_;
|
||||||
std::atomic_bool Running_=false;
|
mutable std::atomic_bool Running_=false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class KafkaDispatcher : public Poco::Runnable {
|
class KafkaDispatcher : public Poco::Runnable {
|
||||||
@@ -2665,6 +2712,7 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
inline void run() override {
|
inline void run() override {
|
||||||
Poco::AutoPtr<Poco::Notification> Note(Queue_.waitDequeueNotification());
|
Poco::AutoPtr<Poco::Notification> Note(Queue_.waitDequeueNotification());
|
||||||
|
Utils::SetThreadName("kafka-dispatch");
|
||||||
while(Note && Running_) {
|
while(Note && Running_) {
|
||||||
auto Msg = dynamic_cast<KafkaMessage*>(Note.get());
|
auto Msg = dynamic_cast<KafkaMessage*>(Note.get());
|
||||||
if(Msg!= nullptr) {
|
if(Msg!= nullptr) {
|
||||||
@@ -2690,7 +2738,7 @@ namespace OpenWifi {
|
|||||||
std::recursive_mutex Mutex_;
|
std::recursive_mutex Mutex_;
|
||||||
Types::NotifyTable Notifiers_;
|
Types::NotifyTable Notifiers_;
|
||||||
Poco::Thread Worker_;
|
Poco::Thread Worker_;
|
||||||
std::atomic_bool Running_=false;
|
mutable std::atomic_bool Running_=false;
|
||||||
uint64_t FunctionId_=1;
|
uint64_t FunctionId_=1;
|
||||||
Poco::NotificationQueue Queue_;
|
Poco::NotificationQueue Queue_;
|
||||||
};
|
};
|
||||||
@@ -2885,6 +2933,7 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
void handleRequest(Poco::Net::HTTPServerRequest& Request, Poco::Net::HTTPServerResponse& Response) override
|
void handleRequest(Poco::Net::HTTPServerRequest& Request, Poco::Net::HTTPServerResponse& Response) override
|
||||||
{
|
{
|
||||||
|
Utils::SetThreadName("alb-request");
|
||||||
try {
|
try {
|
||||||
if((id_ % 100) == 0) {
|
if((id_ % 100) == 0) {
|
||||||
Logger_.debug(fmt::format("ALB-REQUEST({}): ALB Request {}.",
|
Logger_.debug(fmt::format("ALB-REQUEST({}): ALB Request {}.",
|
||||||
@@ -2953,7 +3002,7 @@ namespace OpenWifi {
|
|||||||
std::unique_ptr<Poco::Net::HTTPServer> Server_;
|
std::unique_ptr<Poco::Net::HTTPServer> Server_;
|
||||||
std::unique_ptr<Poco::Net::ServerSocket> Socket_;
|
std::unique_ptr<Poco::Net::ServerSocket> Socket_;
|
||||||
int Port_ = 0;
|
int Port_ = 0;
|
||||||
std::atomic_bool Running_=false;
|
mutable std::atomic_bool Running_=false;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline auto ALBHealthCheckServer() { return ALBHealthCheckServer::instance(); }
|
inline auto ALBHealthCheckServer() { return ALBHealthCheckServer::instance(); }
|
||||||
@@ -2985,7 +3034,7 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) {
|
inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) {
|
||||||
RESTAPIHandler::BindingMap Bindings;
|
RESTAPIHandler::BindingMap Bindings;
|
||||||
Poco::Thread::current()->setName(fmt::format("RESTAPI_ExtServer_{}",Id));
|
Utils::SetThreadName(fmt::format("rest_ext_{}",Id).c_str());
|
||||||
return RESTAPI_ExtRouter(Path, Bindings, Logger(), Server_, Id);
|
return RESTAPI_ExtRouter(Path, Bindings, Logger(), Server_, Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3009,7 +3058,7 @@ namespace OpenWifi {
|
|||||||
inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override {
|
inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override {
|
||||||
try {
|
try {
|
||||||
Poco::URI uri(Request.getURI());
|
Poco::URI uri(Request.getURI());
|
||||||
Poco::Thread::current()->setName(fmt::format("ExtWebServer_{}",TransactionId_));
|
Utils::SetThreadName(fmt::format("rest_ext_{}",TransactionId_).c_str());
|
||||||
return RESTAPI_ExtServer()->CallServer(uri.getPath(), TransactionId_++);
|
return RESTAPI_ExtServer()->CallServer(uri.getPath(), TransactionId_++);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|
||||||
@@ -3118,7 +3167,7 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) {
|
inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) {
|
||||||
RESTAPIHandler::BindingMap Bindings;
|
RESTAPIHandler::BindingMap Bindings;
|
||||||
Poco::Thread::current()->setName(fmt::format("RESTAPI_IntServer_{}",Id));
|
Utils::SetThreadName(fmt::format("rest_int_{}",Id).c_str());
|
||||||
return RESTAPI_IntRouter(Path, Bindings, Logger(), Server_, Id);
|
return RESTAPI_IntRouter(Path, Bindings, Logger(), Server_, Id);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
@@ -3527,6 +3576,8 @@ namespace OpenWifi {
|
|||||||
void DaemonPostInitialization(Poco::Util::Application &self);
|
void DaemonPostInitialization(Poco::Util::Application &self);
|
||||||
|
|
||||||
inline void MicroService::initialize(Poco::Util::Application &self) {
|
inline void MicroService::initialize(Poco::Util::Application &self) {
|
||||||
|
// Utils::SetThreadName("microservice");
|
||||||
|
|
||||||
// add the default services
|
// add the default services
|
||||||
LoadConfigurationFile();
|
LoadConfigurationFile();
|
||||||
InitializeLoggingSystem();
|
InitializeLoggingSystem();
|
||||||
@@ -3922,6 +3973,7 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
inline int MicroService::main([[maybe_unused]] const ArgVec &args) {
|
inline int MicroService::main([[maybe_unused]] const ArgVec &args) {
|
||||||
|
|
||||||
|
// Utils::SetThreadName("main");
|
||||||
MyErrorHandler ErrorHandler(*this);
|
MyErrorHandler ErrorHandler(*this);
|
||||||
Poco::ErrorHandler::set(&ErrorHandler);
|
Poco::ErrorHandler::set(&ErrorHandler);
|
||||||
|
|
||||||
@@ -4037,6 +4089,7 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
inline void BusEventManager::run() {
|
inline void BusEventManager::run() {
|
||||||
Running_ = true;
|
Running_ = true;
|
||||||
|
Utils::SetThreadName("BusEventManager");
|
||||||
auto Msg = MicroService::instance().MakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN);
|
auto Msg = MicroService::instance().MakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN);
|
||||||
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS,MicroService::instance().PrivateEndPoint(),Msg, false);
|
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS,MicroService::instance().PrivateEndPoint(),Msg, false);
|
||||||
while(Running_) {
|
while(Running_) {
|
||||||
@@ -4122,6 +4175,8 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void KafkaProducer::run() {
|
inline void KafkaProducer::run() {
|
||||||
|
|
||||||
|
Utils::SetThreadName("KafkaProducer");
|
||||||
cppkafka::Configuration Config({
|
cppkafka::Configuration Config({
|
||||||
{ "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") },
|
{ "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") },
|
||||||
{ "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") }
|
{ "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") }
|
||||||
@@ -4160,6 +4215,8 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void KafkaConsumer::run() {
|
inline void KafkaConsumer::run() {
|
||||||
|
Utils::SetThreadName("KafkaConsumer");
|
||||||
|
|
||||||
cppkafka::Configuration Config({
|
cppkafka::Configuration Config({
|
||||||
{ "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") },
|
{ "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") },
|
||||||
{ "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") },
|
{ "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") },
|
||||||
@@ -4818,7 +4875,7 @@ namespace OpenWifi {
|
|||||||
[[nodiscard]] bool SendToUser(const std::string &userName, const std::string &Payload);
|
[[nodiscard]] bool SendToUser(const std::string &userName, const std::string &Payload);
|
||||||
void SendToAll(const std::string &Payload);
|
void SendToAll(const std::string &Payload);
|
||||||
private:
|
private:
|
||||||
std::atomic_bool Running_ = false;
|
mutable std::atomic_bool Running_ = false;
|
||||||
Poco::Thread Thr_;
|
Poco::Thread Thr_;
|
||||||
// std::unique_ptr<MyParallelSocketReactor> ReactorPool_;
|
// std::unique_ptr<MyParallelSocketReactor> ReactorPool_;
|
||||||
Poco::Net::SocketReactor Reactor_;
|
Poco::Net::SocketReactor Reactor_;
|
||||||
@@ -4915,6 +4972,7 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
inline void WebSocketClientServer::run() {
|
inline void WebSocketClientServer::run() {
|
||||||
Running_ = true ;
|
Running_ = true ;
|
||||||
|
Utils::SetThreadName("ws:clnt-svr");
|
||||||
while(Running_) {
|
while(Running_) {
|
||||||
Poco::Thread::trySleep(2000);
|
Poco::Thread::trySleep(2000);
|
||||||
|
|
||||||
@@ -4962,8 +5020,12 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
for(const auto &client:Clients_) {
|
for(const auto &client:Clients_) {
|
||||||
if(client.second.second == UserName) {
|
if(client.second.second == UserName) {
|
||||||
|
try {
|
||||||
if (client.second.first->Send(Payload))
|
if (client.second.first->Send(Payload))
|
||||||
Sent++;
|
Sent++;
|
||||||
|
} catch (...) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Sent>0;
|
return Sent>0;
|
||||||
@@ -4985,6 +5047,7 @@ namespace OpenWifi {
|
|||||||
int flags;
|
int flags;
|
||||||
int n;
|
int n;
|
||||||
bool Done=false;
|
bool Done=false;
|
||||||
|
try {
|
||||||
Poco::Buffer<char> IncomingFrame(0);
|
Poco::Buffer<char> IncomingFrame(0);
|
||||||
n = WS_->receiveFrame(IncomingFrame, flags);
|
n = WS_->receiveFrame(IncomingFrame, flags);
|
||||||
auto Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
|
auto Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
|
||||||
@@ -4998,23 +5061,21 @@ namespace OpenWifi {
|
|||||||
WS_->sendFrame("", 0,
|
WS_->sendFrame("", 0,
|
||||||
(int)Poco::Net::WebSocket::FRAME_OP_PONG |
|
(int)Poco::Net::WebSocket::FRAME_OP_PONG |
|
||||||
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
|
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
case Poco::Net::WebSocket::FRAME_OP_PONG: {
|
case Poco::Net::WebSocket::FRAME_OP_PONG: {
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
|
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
|
||||||
Logger().warning(Poco::format("CLOSE(%s): Client is closing its connection.", Id_));
|
Logger().warning(Poco::format("CLOSE(%s): Client is closing its connection.", Id_));
|
||||||
Done = true;
|
Done = true;
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
case Poco::Net::WebSocket::FRAME_OP_TEXT: {
|
case Poco::Net::WebSocket::FRAME_OP_TEXT: {
|
||||||
IncomingFrame.append(0);
|
IncomingFrame.append(0);
|
||||||
if (!Authenticated_) {
|
if (!Authenticated_) {
|
||||||
std::string Frame{IncomingFrame.begin()};
|
std::string Frame{IncomingFrame.begin()};
|
||||||
auto Tokens = Utils::Split(Frame, ':');
|
auto Tokens = Utils::Split(Frame, ':');
|
||||||
bool Expired = false, Contacted = false;
|
bool Expired = false, Contacted = false;
|
||||||
if(Tokens.size()==2 && AuthClient()->IsAuthorized(Tokens[1], UserInfo_, Expired, Contacted)) {
|
if (Tokens.size() == 2 &&
|
||||||
|
AuthClient()->IsAuthorized(Tokens[1], UserInfo_, Expired, Contacted)) {
|
||||||
Authenticated_ = true;
|
Authenticated_ = true;
|
||||||
std::string S{"Welcome! Bienvenue! Bienvenidos!"};
|
std::string S{"Welcome! Bienvenue! Bienvenidos!"};
|
||||||
WS_->sendFrame(S.c_str(), S.size());
|
WS_->sendFrame(S.c_str(), S.size());
|
||||||
@@ -5028,8 +5089,8 @@ namespace OpenWifi {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Poco::JSON::Parser P;
|
Poco::JSON::Parser P;
|
||||||
auto Obj = P.parse(IncomingFrame.begin())
|
auto Obj =
|
||||||
.extract<Poco::JSON::Object::Ptr>();
|
P.parse(IncomingFrame.begin()).extract<Poco::JSON::Object::Ptr>();
|
||||||
std::string Answer;
|
std::string Answer;
|
||||||
if (Processor_ != nullptr)
|
if (Processor_ != nullptr)
|
||||||
Processor_->Processor(Obj, Answer, Done);
|
Processor_->Processor(Obj, Answer, Done);
|
||||||
@@ -5040,14 +5101,15 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
} catch (const Poco::JSON::JSONException &E) {
|
} catch (const Poco::JSON::JSONException &E) {
|
||||||
Logger().log(E);
|
Logger().log(E);
|
||||||
|
Done=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} break;
|
||||||
|
default: {
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} catch (...) {
|
||||||
|
Done=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Done) {
|
if(Done) {
|
||||||
|
|||||||
@@ -133,6 +133,37 @@ namespace ORM {
|
|||||||
return R;
|
return R;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::string WHERE_AND_(std::string Result) {
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename... Args> std::string WHERE_AND_(std::string Result, const char *fieldName, const T &Value, Args... args) {
|
||||||
|
if constexpr(std::is_same_v<T,std::string>)
|
||||||
|
{
|
||||||
|
if(!Value.empty()) {
|
||||||
|
if(!Result.empty())
|
||||||
|
Result += " and ";
|
||||||
|
Result += fieldName;
|
||||||
|
Result += '=';
|
||||||
|
Result += "'";
|
||||||
|
Result += Escape(Value);
|
||||||
|
Result += "'";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(!Result.empty())
|
||||||
|
Result += " and ";
|
||||||
|
Result += fieldName ;
|
||||||
|
Result += '=';
|
||||||
|
Result += std::to_string(Value);
|
||||||
|
}
|
||||||
|
return WHERE_AND_(Result,args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args> std::string WHERE_AND(Args... args) {
|
||||||
|
std::string Result;
|
||||||
|
return WHERE_AND_(Result, args...);
|
||||||
|
}
|
||||||
|
|
||||||
enum SqlComparison { EQ = 0, NEQ, LT, LTE, GT, GTE };
|
enum SqlComparison { EQ = 0, NEQ, LT, LTE, GT, GTE };
|
||||||
enum SqlBinaryOp { AND = 0 , OR };
|
enum SqlBinaryOp { AND = 0 , OR };
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user