mirror of
				https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
				synced 2025-11-03 20:27:45 +00:00 
			
		
		
		
	Compare commits
	
		
			29 Commits
		
	
	
		
			v3.0.0-RC1
			...
			main
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					7ebb9dbe14 | ||
| 
						 | 
					b51148e9c6 | ||
| 
						 | 
					966ddd3cbf | ||
| 
						 | 
					2781342aa5 | ||
| 
						 | 
					b98dd457a6 | ||
| 
						 | 
					54fc3dc6c4 | ||
| 
						 | 
					9d3fe561a4 | ||
| 
						 | 
					3e13e18f6c | ||
| 
						 | 
					1977ecdfb7 | ||
| 
						 | 
					1d703e1737 | ||
| 
						 | 
					22ddb40d4c | ||
| 
						 | 
					791b72aec4 | ||
| 
						 | 
					46b9524903 | ||
| 
						 | 
					bb09f919e6 | ||
| 
						 | 
					8d04cbc059 | ||
| 
						 | 
					073856d385 | ||
| 
						 | 
					c782981ca7 | ||
| 
						 | 
					ca3691e665 | ||
| 
						 | 
					be2ffc86ec | ||
| 
						 | 
					75ebc0771c | ||
| 
						 | 
					d050635a99 | ||
| 
						 | 
					e3592b5fe6 | ||
| 
						 | 
					9eec54effb | ||
| 
						 | 
					6a7ae342dc | ||
| 
						 | 
					5b3205823e | ||
| 
						 | 
					db45a01bce | ||
| 
						 | 
					d2f70ec82d | ||
| 
						 | 
					2b01453970 | ||
| 
						 | 
					68ccc4da93 | 
							
								
								
									
										2
									
								
								.github/workflows/ci.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/ci.yml
									
									
									
									
										vendored
									
									
								
							@@ -21,7 +21,7 @@ defaults:
 | 
			
		||||
 | 
			
		||||
jobs:
 | 
			
		||||
  docker:
 | 
			
		||||
    runs-on: ubuntu-20.04
 | 
			
		||||
    runs-on: ubuntu-latest
 | 
			
		||||
    env:
 | 
			
		||||
      DOCKER_REGISTRY_URL: tip-tip-wlan-cloud-ucentral.jfrog.io
 | 
			
		||||
      DOCKER_REGISTRY_USERNAME: ucentral
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										62
									
								
								BUILDING.md
									
									
									
									
									
								
							
							
						
						
									
										62
									
								
								BUILDING.md
									
									
									
									
									
								
							@@ -1,6 +1,6 @@
 | 
			
		||||
# Building from source
 | 
			
		||||
 | 
			
		||||
In order to build the OWSEC, you will need to install its dependencies, which includes the following:
 | 
			
		||||
In order to build OWSEC, you will need to install its dependencies, which includes the following:
 | 
			
		||||
- cmake
 | 
			
		||||
- boost
 | 
			
		||||
- POCO 1.10.1 or later
 | 
			
		||||
@@ -13,43 +13,43 @@ In order to build the OWSEC, you will need to install its dependencies, which in
 | 
			
		||||
 | 
			
		||||
The build is done in 2 parts. The first part is to build a local copy of the framework tailored to your environment. This
 | 
			
		||||
framework is called [Poco](https://github.com/pocoproject/poco). The version used in this project has a couple of fixes
 | 
			
		||||
from the master copy needed for cmake. Please use the version of this [Poco fix](https://github.com/AriliaWireless/poco). Building
 | 
			
		||||
from the master copy needed for cmake. Please use the version of this [Poco fix](https://github.com/Telecominfraproject/wlan-cloud-lib-poco). Building
 | 
			
		||||
Poco may take several minutes depending on the platform you are building on.
 | 
			
		||||
 | 
			
		||||
## Ubuntu
 | 
			
		||||
These instructions have proven to work on Ubuntu 20.4.
 | 
			
		||||
```bash
 | 
			
		||||
sudo apt install git cmake g++ libssl-dev libmariadb-dev 
 | 
			
		||||
sudo apt install libpq-dev libaprutil1-dev apache2-dev libboost-all-dev
 | 
			
		||||
sudo apt install librdkafka-dev default-libmysqlclient-dev
 | 
			
		||||
sudo apt install nlohmann-json-dev
 | 
			
		||||
sudo apt install git cmake g++ libssl-dev libmariadb-dev \
 | 
			
		||||
    libpq-dev libaprutil1-dev apache2-dev libboost-all-dev \
 | 
			
		||||
    librdkafka-dev default-libmysqlclient-dev \
 | 
			
		||||
    nlohmann-json-dev
 | 
			
		||||
 | 
			
		||||
cd ~
 | 
			
		||||
git clone https://github.com/AriliaWireless/poco --branch poco-tip-v1
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-poco --branch poco-tip-v1 poco
 | 
			
		||||
cd poco
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
cd cmake-build
 | 
			
		||||
cmake ..
 | 
			
		||||
cmake --build . --config Release
 | 
			
		||||
sudo cmake --build . --target install
 | 
			
		||||
cd ../..
 | 
			
		||||
 | 
			
		||||
cd ~
 | 
			
		||||
git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka --branch tip-v1 cppkafka
 | 
			
		||||
cd cppkafka
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
cd cmake-build
 | 
			
		||||
cmake ..
 | 
			
		||||
cmake --build . --config Release
 | 
			
		||||
sudo cmake --build . --target install
 | 
			
		||||
cd ../..
 | 
			
		||||
 | 
			
		||||
cd ~
 | 
			
		||||
git clone https://github.com/AriliaWireless/valijson --branch tip-v1
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-valijson --branch tip-v1 valijson
 | 
			
		||||
cd valijson
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
cd cmake-build
 | 
			
		||||
cmake ..
 | 
			
		||||
cmake --build . --config Release
 | 
			
		||||
sudo cmake --build . --target install
 | 
			
		||||
cd ../..
 | 
			
		||||
 | 
			
		||||
git clone https://github.com/fmtlib/fmt --branch 9.0.0 /fmtlib
 | 
			
		||||
cd fmtlib
 | 
			
		||||
@@ -58,56 +58,59 @@ cd cmake-build
 | 
			
		||||
cmake ..
 | 
			
		||||
make
 | 
			
		||||
make install
 | 
			
		||||
cd ../..
 | 
			
		||||
 | 
			
		||||
cd ~
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-ucentralsec
 | 
			
		||||
cd wlan-cloud-ucentralsec
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
cd cmake-build
 | 
			
		||||
cmake ..
 | 
			
		||||
make -j 8
 | 
			
		||||
cd ../..
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Fedora
 | 
			
		||||
The following instructions have proven to work on Fedora 33
 | 
			
		||||
```bash
 | 
			
		||||
sudo yum install cmake g++ openssl-devel mysql-devel mysql apr-util-devel boost boost-devel
 | 
			
		||||
sudo yum install yaml-cpp-devel lua-devel 
 | 
			
		||||
sudo yum install cmake g++ openssl-devel mysql-devel mysql apr-util-devel boost boost-devel \
 | 
			
		||||
    yaml-cpp-devel lua-devel
 | 
			
		||||
sudo dnf install postgresql.x86_64 librdkafka-devel
 | 
			
		||||
sudo dnf install postgresql-devel json-devel
 | 
			
		||||
 | 
			
		||||
git clone https://github.com/AriliaWireless/poco --branch poco-tip-v1
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-poco --branch poco-tip-v1 poco
 | 
			
		||||
cd poco
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
cd cmake-build
 | 
			
		||||
cmake ..
 | 
			
		||||
cmake --build . --config Release
 | 
			
		||||
sudo cmake --build . --target install
 | 
			
		||||
cd ../..
 | 
			
		||||
 | 
			
		||||
git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka --branch tip-v1 cppkafka
 | 
			
		||||
cd cppkafka
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
cd cmake-build
 | 
			
		||||
cmake ..
 | 
			
		||||
cmake --build . --config Release
 | 
			
		||||
sudo cmake --build . --target install
 | 
			
		||||
cd ../..
 | 
			
		||||
 | 
			
		||||
cd ~
 | 
			
		||||
git clone https://github.com/AriliaWireless/valijson --branch tip-v1
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-valijson --branch tip-v1 valijson
 | 
			
		||||
cd valijson
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
cd cmake-build
 | 
			
		||||
cmake ..
 | 
			
		||||
cmake --build . --config Release
 | 
			
		||||
sudo cmake --build . --target install
 | 
			
		||||
cd ../..
 | 
			
		||||
 | 
			
		||||
cd ~
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-ucentralsec
 | 
			
		||||
cd wlan-cloud-ucentralsec
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
cd cmake-build
 | 
			
		||||
cmake ..
 | 
			
		||||
make
 | 
			
		||||
cd ../..
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## macOS Build
 | 
			
		||||
@@ -126,7 +129,7 @@ brew install openssl \
 | 
			
		||||
	nlohmann-json \
 | 
			
		||||
	fmt
 | 
			
		||||
 | 
			
		||||
git clone https://github.com/AriliaWireless/poco --branch poco-tip-v1
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-poco --branch poco-tip-v1 poco
 | 
			
		||||
pushd poco
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
push cmake-build
 | 
			
		||||
@@ -136,7 +139,7 @@ sudo cmake --build . --target install
 | 
			
		||||
popd
 | 
			
		||||
popd
 | 
			
		||||
 | 
			
		||||
git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka --branch tip-v1 cppkafka
 | 
			
		||||
pushd cppkafka
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
pushd cmake-build
 | 
			
		||||
@@ -146,10 +149,10 @@ sudo cmake --build . --target install
 | 
			
		||||
popd
 | 
			
		||||
popd
 | 
			
		||||
 | 
			
		||||
git clone https://github.com/AriliaWireless/valijson --branch tip-v1
 | 
			
		||||
cd valijson
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-valijson --branch tip-v1 valijson
 | 
			
		||||
pushd valijson
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
cd cmake-build
 | 
			
		||||
pushd cmake-build
 | 
			
		||||
cmake ..
 | 
			
		||||
cmake --build . --config Release
 | 
			
		||||
sudo cmake --build . --target install
 | 
			
		||||
@@ -172,20 +175,23 @@ support. You can build with only SQLite support by not installing the packages f
 | 
			
		||||
adding -DSMALL_BUILD=1 on the cmake build line.
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
sudo apt install git cmake g++ libssl-dev libaprutil1-dev apache2-dev libboost-all-dev libyaml-cpp-dev
 | 
			
		||||
git clone https://github.com/stephb9959/poco
 | 
			
		||||
sudo apt install git cmake g++ libssl-dev libaprutil1-dev apache2-dev \
 | 
			
		||||
    libboost-all-dev libyaml-cpp-dev
 | 
			
		||||
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-poco --branch poco-tip-v1 poco
 | 
			
		||||
cd poco
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
cd cmake-build
 | 
			
		||||
cmake ..
 | 
			
		||||
cmake --build . --config Release
 | 
			
		||||
sudo cmake --build . --target install
 | 
			
		||||
cd ../..
 | 
			
		||||
 | 
			
		||||
cd ~
 | 
			
		||||
git clone https://github.com/Telecominfraproject/wlan-cloud-ucentralsec
 | 
			
		||||
cd wlan-cloud-ucentralsec
 | 
			
		||||
mkdir cmake-build
 | 
			
		||||
cd cmake-build
 | 
			
		||||
cmake -DSMALL_BUILD=1 ..
 | 
			
		||||
make
 | 
			
		||||
cd ../..
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
cmake_minimum_required(VERSION 3.13)
 | 
			
		||||
project(owsec VERSION 3.0.0)
 | 
			
		||||
project(owsec VERSION 4.1.0)
 | 
			
		||||
 | 
			
		||||
set(CMAKE_CXX_STANDARD 17)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								Dockerfile
									
									
									
									
									
								
							@@ -15,8 +15,8 @@ FROM build-base AS poco-build
 | 
			
		||||
 | 
			
		||||
ARG POCO_VERSION
 | 
			
		||||
 | 
			
		||||
ADD https://api.github.com/repos/AriliaWireless/poco/git/refs/tags/${POCO_VERSION} version.json
 | 
			
		||||
RUN git clone https://github.com/AriliaWireless/poco --branch ${POCO_VERSION} /poco
 | 
			
		||||
ADD https://api.github.com/repos/Telecominfraproject/wlan-cloud-lib-poco/git/refs/tags/${POCO_VERSION} version.json
 | 
			
		||||
RUN git clone https://github.com/Telecominfraproject/wlan-cloud-lib-poco --branch ${POCO_VERSION} /poco
 | 
			
		||||
 | 
			
		||||
WORKDIR /poco
 | 
			
		||||
RUN mkdir cmake-build
 | 
			
		||||
@@ -29,8 +29,8 @@ FROM build-base AS cppkafka-build
 | 
			
		||||
 | 
			
		||||
ARG CPPKAFKA_VERSION
 | 
			
		||||
 | 
			
		||||
ADD https://api.github.com/repos/AriliaWireless/cppkafka/git/refs/tags/${CPPKAFKA_VERSION} version.json
 | 
			
		||||
RUN git clone https://github.com/AriliaWireless/cppkafka --branch ${CPPKAFKA_VERSION} /cppkafka
 | 
			
		||||
ADD https://api.github.com/repos/Telecominfraproject/wlan-cloud-lib-cppkafka/git/refs/tags/${CPPKAFKA_VERSION} version.json
 | 
			
		||||
RUN git clone https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka --branch ${CPPKAFKA_VERSION} /cppkafka
 | 
			
		||||
 | 
			
		||||
WORKDIR /cppkafka
 | 
			
		||||
RUN mkdir cmake-build
 | 
			
		||||
@@ -43,8 +43,8 @@ FROM build-base AS valijson-build
 | 
			
		||||
 | 
			
		||||
ARG VALIJASON_VERSION
 | 
			
		||||
 | 
			
		||||
ADD https://api.github.com/repos/AriliaWireless/valijson/git/refs/tags/${VALIJASON_VERSION} version.json
 | 
			
		||||
RUN git clone https://github.com/AriliaWireless/valijson --branch ${VALIJASON_VERSION} /valijson
 | 
			
		||||
ADD https://api.github.com/repos/Telecominfraproject/wlan-cloud-lib-valijson/git/refs/tags/${VALIJASON_VERSION} version.json
 | 
			
		||||
RUN git clone https://github.com/Telecominfraproject/wlan-cloud-lib-valijson --branch ${VALIJASON_VERSION} /valijson
 | 
			
		||||
 | 
			
		||||
WORKDIR /valijson
 | 
			
		||||
RUN mkdir cmake-build
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ fullnameOverride: ""
 | 
			
		||||
images:
 | 
			
		||||
  owsec:
 | 
			
		||||
    repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owsec
 | 
			
		||||
    tag: v3.0.0-RC1
 | 
			
		||||
    tag: main
 | 
			
		||||
    pullPolicy: Always
 | 
			
		||||
#    regcred:
 | 
			
		||||
#      registry: tip-tip-wlan-cloud-ucentral.jfrog.io
 | 
			
		||||
 
 | 
			
		||||
@@ -218,7 +218,7 @@ namespace OpenWifi {
 | 
			
		||||
				Expired = (WT.created_ + WT.expires_in_) < now;
 | 
			
		||||
				if (StorageService()->UserDB().GetUserById(UserId, UInfo.userinfo)) {
 | 
			
		||||
					UInfo.webtoken = WT;
 | 
			
		||||
					poco_debug(Logger(), fmt::format("TokenValidation success for TID={} Token={}",
 | 
			
		||||
					poco_trace(Logger(), fmt::format("TokenValidation success for TID={} Token={}",
 | 
			
		||||
													 TID, Utils::SanitizeToken(CallToken)));
 | 
			
		||||
					return true;
 | 
			
		||||
				}
 | 
			
		||||
 
 | 
			
		||||
@@ -587,6 +587,9 @@ namespace OpenWifi::ProvObjects {
 | 
			
		||||
		field_to_json(Obj, "locale", locale);
 | 
			
		||||
		field_to_json(Obj, "realMacAddress", realMacAddress);
 | 
			
		||||
		field_to_json(Obj, "doNotAllowOverrides", doNotAllowOverrides);
 | 
			
		||||
        field_to_json(Obj, "imported", imported);
 | 
			
		||||
        field_to_json(Obj, "connected", connected);
 | 
			
		||||
        field_to_json(Obj, "platform", platform);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) {
 | 
			
		||||
@@ -609,6 +612,9 @@ namespace OpenWifi::ProvObjects {
 | 
			
		||||
			field_from_json(Obj, "locale", locale);
 | 
			
		||||
			field_from_json(Obj, "realMacAddress", realMacAddress);
 | 
			
		||||
			field_from_json(Obj, "doNotAllowOverrides", doNotAllowOverrides);
 | 
			
		||||
            field_from_json(Obj, "imported", imported);
 | 
			
		||||
            field_from_json(Obj, "connected", connected);
 | 
			
		||||
            field_from_json(Obj, "platform", platform);
 | 
			
		||||
			return true;
 | 
			
		||||
		} catch (...) {
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -490,9 +490,11 @@ namespace OpenWifi::ProvObjects {
 | 
			
		||||
        std::string locale;
 | 
			
		||||
        std::string realMacAddress;
 | 
			
		||||
        bool doNotAllowOverrides = false;
 | 
			
		||||
        std::uint64_t imported=0;
 | 
			
		||||
        std::uint64_t connected=0;
 | 
			
		||||
        std::string platform{"AP"};
 | 
			
		||||
 | 
			
		||||
        void to_json(Poco::JSON::Object &Obj) const;
 | 
			
		||||
 | 
			
		||||
        bool from_json(const Poco::JSON::Object::Ptr &Obj);
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,8 +9,6 @@
 | 
			
		||||
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
	EventBusManager::EventBusManager(Poco::Logger &L) : Logger_(L) {}
 | 
			
		||||
 | 
			
		||||
	void EventBusManager::run() {
 | 
			
		||||
		Running_ = true;
 | 
			
		||||
		Utils::SetThreadName("fmwk:EventMgr");
 | 
			
		||||
@@ -18,9 +16,9 @@ namespace OpenWifi {
 | 
			
		||||
		KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg,
 | 
			
		||||
									false);
 | 
			
		||||
		while (Running_) {
 | 
			
		||||
			Poco::Thread::trySleep((unsigned long)MicroServiceDaemonBusTimer());
 | 
			
		||||
			if (!Running_)
 | 
			
		||||
			if(!Poco::Thread::trySleep((unsigned long)MicroServiceDaemonBusTimer())) {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
			Msg = (MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE));
 | 
			
		||||
			KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(),
 | 
			
		||||
										Msg, false);
 | 
			
		||||
@@ -31,7 +29,7 @@ namespace OpenWifi {
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	void EventBusManager::Start() {
 | 
			
		||||
		poco_information(Logger(), "Starting...");
 | 
			
		||||
		poco_information(Logger_, "Starting...");
 | 
			
		||||
		if (KafkaManager()->Enabled()) {
 | 
			
		||||
			Thread_.start(*this);
 | 
			
		||||
		}
 | 
			
		||||
@@ -39,11 +37,11 @@ namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
	void EventBusManager::Stop() {
 | 
			
		||||
		if (KafkaManager()->Enabled()) {
 | 
			
		||||
			poco_information(Logger(), "Stopping...");
 | 
			
		||||
			poco_information(Logger_, "Stopping...");
 | 
			
		||||
			Running_ = false;
 | 
			
		||||
			Thread_.wakeUp();
 | 
			
		||||
			Thread_.join();
 | 
			
		||||
			poco_information(Logger(), "Stopped...");
 | 
			
		||||
			poco_information(Logger_, "Stopped...");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,16 @@ namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
	class EventBusManager : public Poco::Runnable {
 | 
			
		||||
	  public:
 | 
			
		||||
		explicit EventBusManager(Poco::Logger &L);
 | 
			
		||||
		EventBusManager() :
 | 
			
		||||
			Logger_(Poco::Logger::create(
 | 
			
		||||
				"EventBusManager", Poco::Logger::root().getChannel(), Poco::Logger::root().getLevel())) {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		static auto instance() {
 | 
			
		||||
			static auto instance_ = new EventBusManager;
 | 
			
		||||
			return instance_;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		void run() final;
 | 
			
		||||
		void Start();
 | 
			
		||||
		void Stop();
 | 
			
		||||
@@ -24,4 +33,6 @@ namespace OpenWifi {
 | 
			
		||||
		Poco::Logger &Logger_;
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	inline auto EventBusManager() { return EventBusManager::instance(); }
 | 
			
		||||
 | 
			
		||||
} // namespace OpenWifi
 | 
			
		||||
 
 | 
			
		||||
@@ -79,8 +79,10 @@ namespace OpenWifi {
 | 
			
		||||
		Utils::SetThreadName("Kafka:Prod");
 | 
			
		||||
		cppkafka::Configuration Config(
 | 
			
		||||
			{{"client.id", MicroServiceConfigGetString("openwifi.kafka.client.id", "")},
 | 
			
		||||
			 {"metadata.broker.list",
 | 
			
		||||
			  MicroServiceConfigGetString("openwifi.kafka.brokerlist", "")}});
 | 
			
		||||
			 {"metadata.broker.list",MicroServiceConfigGetString("openwifi.kafka.brokerlist", "")} // ,
 | 
			
		||||
			 // {"send.buffer.bytes", KafkaManager()->KafkaManagerMaximumPayloadSize() }
 | 
			
		||||
			}
 | 
			
		||||
 		);
 | 
			
		||||
 | 
			
		||||
		AddKafkaSecurity(Config);
 | 
			
		||||
 | 
			
		||||
@@ -105,6 +107,19 @@ namespace OpenWifi {
 | 
			
		||||
					NewMessage.partition(0);
 | 
			
		||||
					NewMessage.payload(Msg->Payload());
 | 
			
		||||
					Producer.produce(NewMessage);
 | 
			
		||||
					if (Queue_.size() < 100) {
 | 
			
		||||
						// use flush when internal queue is lightly loaded, i.e. flush after each
 | 
			
		||||
						// message
 | 
			
		||||
						Producer.flush();
 | 
			
		||||
					}
 | 
			
		||||
					else {
 | 
			
		||||
						// use poll when internal queue is loaded to allow messages to be sent in
 | 
			
		||||
						// batches
 | 
			
		||||
						Producer.poll((std::chrono::milliseconds) 0);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
	                        if (Queue_.size() == 0) {
 | 
			
		||||
					// message queue is empty, flush all previously sent messages
 | 
			
		||||
					Producer.flush();
 | 
			
		||||
				}
 | 
			
		||||
			} catch (const cppkafka::HandleException &E) {
 | 
			
		||||
@@ -117,6 +132,7 @@ namespace OpenWifi {
 | 
			
		||||
			}
 | 
			
		||||
			Note = Queue_.waitDequeueNotification();
 | 
			
		||||
		}
 | 
			
		||||
		Producer.flush();
 | 
			
		||||
		poco_information(Logger_, "Stopped...");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -275,6 +291,7 @@ namespace OpenWifi {
 | 
			
		||||
	int KafkaManager::Start() {
 | 
			
		||||
		if (!KafkaEnabled_)
 | 
			
		||||
			return 0;
 | 
			
		||||
		MaxPayloadSize_ = MicroServiceConfigGetInt("openwifi.kafka.max.payload", 250000);
 | 
			
		||||
		ConsumerThr_.Start();
 | 
			
		||||
		ProducerThr_.Start();
 | 
			
		||||
		return 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -94,11 +94,14 @@ namespace OpenWifi {
 | 
			
		||||
			return ConsumerThr_.UnregisterTopicWatcher(Topic,Id);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		std::uint64_t KafkaManagerMaximumPayloadSize() const { return MaxPayloadSize_; }
 | 
			
		||||
 | 
			
		||||
	  private:
 | 
			
		||||
		bool KafkaEnabled_ = false;
 | 
			
		||||
		std::string SystemInfoWrapper_;
 | 
			
		||||
		KafkaProducer ProducerThr_;
 | 
			
		||||
		KafkaConsumer ConsumerThr_;
 | 
			
		||||
		std::uint64_t MaxPayloadSize_ = 250000;
 | 
			
		||||
 | 
			
		||||
		void PartitionAssignment(const cppkafka::TopicPartitionList &partitions);
 | 
			
		||||
		void PartitionRevocation(const cppkafka::TopicPartitionList &partitions);
 | 
			
		||||
 
 | 
			
		||||
@@ -29,13 +29,29 @@
 | 
			
		||||
#include "framework/WebSocketLogger.h"
 | 
			
		||||
#include "framework/utils.h"
 | 
			
		||||
 | 
			
		||||
#ifdef  USE_MEDUSA_CLIENT
 | 
			
		||||
#include <medusa/MedusaClient.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
	void MicroService::Exit(int Reason) { std::exit(Reason); }
 | 
			
		||||
	static std::string MakeServiceListString(const Types::MicroServiceMetaMap &Services) {
 | 
			
		||||
        std::string SvcList;
 | 
			
		||||
        for (const auto &Svc : Services) {
 | 
			
		||||
            if (SvcList.empty())
 | 
			
		||||
                SvcList = Svc.second.Type;
 | 
			
		||||
            else
 | 
			
		||||
                SvcList += ", " + Svc.second.Type;
 | 
			
		||||
        }
 | 
			
		||||
        return SvcList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	void MicroService::BusMessageReceived([[maybe_unused]] const std::string &Key,
 | 
			
		||||
										  const std::string &Payload) {
 | 
			
		||||
		std::lock_guard G(InfraMutex_);
 | 
			
		||||
 | 
			
		||||
		Poco::Logger &BusLogger = EventBusManager()->Logger();
 | 
			
		||||
 | 
			
		||||
		try {
 | 
			
		||||
			Poco::JSON::Parser P;
 | 
			
		||||
			auto Object = P.parse(Payload).extract<Poco::JSON::Object::Ptr>();
 | 
			
		||||
@@ -55,13 +71,10 @@ namespace OpenWifi {
 | 
			
		||||
							Object->has(KafkaTopics::ServiceEvents::Fields::KEY)) {
 | 
			
		||||
							auto PrivateEndPoint =
 | 
			
		||||
								Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE).toString();
 | 
			
		||||
							if (Event == KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE &&
 | 
			
		||||
								Services_.find(PrivateEndPoint) != Services_.end()) {
 | 
			
		||||
								Services_[PrivateEndPoint].LastUpdate = Utils::Now();
 | 
			
		||||
							} else if (Event == KafkaTopics::ServiceEvents::EVENT_LEAVE) {
 | 
			
		||||
							if (Event == KafkaTopics::ServiceEvents::EVENT_LEAVE) {
 | 
			
		||||
								Services_.erase(PrivateEndPoint);
 | 
			
		||||
								poco_debug(
 | 
			
		||||
									logger(),
 | 
			
		||||
								poco_information(
 | 
			
		||||
									BusLogger,
 | 
			
		||||
									fmt::format(
 | 
			
		||||
										"Service {} ID={} leaving system.",
 | 
			
		||||
										Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE)
 | 
			
		||||
@@ -69,14 +82,7 @@ namespace OpenWifi {
 | 
			
		||||
										ID));
 | 
			
		||||
							} else if (Event == KafkaTopics::ServiceEvents::EVENT_JOIN ||
 | 
			
		||||
									   Event == KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE) {
 | 
			
		||||
								poco_debug(
 | 
			
		||||
									logger(),
 | 
			
		||||
									fmt::format(
 | 
			
		||||
										"Service {} ID={} joining system.",
 | 
			
		||||
										Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE)
 | 
			
		||||
											.toString(),
 | 
			
		||||
										ID));
 | 
			
		||||
								Services_[PrivateEndPoint] = Types::MicroServiceMeta{
 | 
			
		||||
								auto ServiceInfo = Types::MicroServiceMeta{
 | 
			
		||||
									.Id = ID,
 | 
			
		||||
									.Type = Poco::toLower(
 | 
			
		||||
										Object->get(KafkaTopics::ServiceEvents::Fields::TYPE)
 | 
			
		||||
@@ -94,6 +100,22 @@ namespace OpenWifi {
 | 
			
		||||
												   .toString(),
 | 
			
		||||
									.LastUpdate = Utils::Now()};
 | 
			
		||||
 | 
			
		||||
                                auto s1 = MakeServiceListString(Services_);
 | 
			
		||||
								auto PreviousSize = Services_.size();
 | 
			
		||||
								Services_[PrivateEndPoint] = ServiceInfo;
 | 
			
		||||
								auto CurrentSize = Services_.size();
 | 
			
		||||
								if(Event == KafkaTopics::ServiceEvents::EVENT_JOIN) {
 | 
			
		||||
									if(!s1.empty()) {
 | 
			
		||||
										poco_information(
 | 
			
		||||
											BusLogger,
 | 
			
		||||
											fmt::format(
 | 
			
		||||
												"Service {} ID={} is joining the system.",
 | 
			
		||||
												Object
 | 
			
		||||
													->get(
 | 
			
		||||
														KafkaTopics::ServiceEvents::Fields::PRIVATE)
 | 
			
		||||
													.toString(),
 | 
			
		||||
												ID));
 | 
			
		||||
									}
 | 
			
		||||
									std::string SvcList;
 | 
			
		||||
									for (const auto &Svc : Services_) {
 | 
			
		||||
										if (SvcList.empty())
 | 
			
		||||
@@ -102,12 +124,22 @@ namespace OpenWifi {
 | 
			
		||||
											SvcList += ", " + Svc.second.Type;
 | 
			
		||||
									}
 | 
			
		||||
									poco_information(
 | 
			
		||||
									logger(),
 | 
			
		||||
										BusLogger,
 | 
			
		||||
										fmt::format("Current list of microservices: {}", SvcList));
 | 
			
		||||
								} else if(CurrentSize!=PreviousSize) {
 | 
			
		||||
									poco_information(
 | 
			
		||||
										BusLogger,
 | 
			
		||||
										fmt::format(
 | 
			
		||||
											"Service {} ID={} is being added back in.",
 | 
			
		||||
											Object
 | 
			
		||||
												->get(KafkaTopics::ServiceEvents::Fields::PRIVATE)
 | 
			
		||||
												.toString(),
 | 
			
		||||
											ID));
 | 
			
		||||
								}
 | 
			
		||||
							}
 | 
			
		||||
						} else {
 | 
			
		||||
							poco_error(
 | 
			
		||||
								logger(),
 | 
			
		||||
							poco_information(
 | 
			
		||||
								BusLogger,
 | 
			
		||||
								fmt::format("KAFKA-MSG: invalid event '{}', missing a field.",
 | 
			
		||||
											Event));
 | 
			
		||||
						}
 | 
			
		||||
@@ -118,32 +150,39 @@ namespace OpenWifi {
 | 
			
		||||
								Object->get(KafkaTopics::ServiceEvents::Fields::TOKEN).toString());
 | 
			
		||||
#endif
 | 
			
		||||
						} else {
 | 
			
		||||
							poco_error(
 | 
			
		||||
								logger(),
 | 
			
		||||
							poco_information(
 | 
			
		||||
								BusLogger,
 | 
			
		||||
								fmt::format("KAFKA-MSG: invalid event '{}', missing token", Event));
 | 
			
		||||
						}
 | 
			
		||||
					} else {
 | 
			
		||||
						poco_error(logger(),
 | 
			
		||||
						poco_information(BusLogger,
 | 
			
		||||
								   fmt::format("Unknown Event: {} Source: {}", Event, ID));
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			} else {
 | 
			
		||||
				poco_error(logger(), "Bad bus message.");
 | 
			
		||||
				std::ostringstream os;
 | 
			
		||||
				Object->stringify(std::cout);
 | 
			
		||||
				poco_error(BusLogger, fmt::format("Bad bus message: {}", os.str()));
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			auto i = Services_.begin();
 | 
			
		||||
			auto ServiceHint = Services_.begin();
 | 
			
		||||
			auto now = Utils::Now();
 | 
			
		||||
			for (; i != Services_.end();) {
 | 
			
		||||
				if ((now - i->second.LastUpdate) > 60) {
 | 
			
		||||
					i = Services_.erase(i);
 | 
			
		||||
            auto si1 = Services_.size();
 | 
			
		||||
            auto ss1 = MakeServiceListString(Services_);
 | 
			
		||||
			while(ServiceHint!=Services_.end()) {
 | 
			
		||||
				if ((now - ServiceHint->second.LastUpdate) > 120) {
 | 
			
		||||
					poco_information(BusLogger, fmt::format("ZombieService: Removing service {}, ", ServiceHint->second.PublicEndPoint));
 | 
			
		||||
					ServiceHint = Services_.erase(ServiceHint);
 | 
			
		||||
				} else
 | 
			
		||||
					++i;
 | 
			
		||||
					++ServiceHint;
 | 
			
		||||
			}
 | 
			
		||||
            if(Services_.size() != si1) {
 | 
			
		||||
                auto ss2 = MakeServiceListString(Services_);
 | 
			
		||||
                poco_information(BusLogger, fmt::format("Current list of microservices: {} -> {}", ss1, ss2));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
		} catch (const Poco::Exception &E) {
 | 
			
		||||
			logger().log(E);
 | 
			
		||||
			BusLogger.log(E);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -167,9 +206,11 @@ namespace OpenWifi {
 | 
			
		||||
			Res.push_back(ServiceRec);
 | 
			
		||||
		}
 | 
			
		||||
		return Res;
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void MicroService::LoadConfigurationFile() {
 | 
			
		||||
        if(ConfigContent_.empty()) {
 | 
			
		||||
            std::string Location = Poco::Environment::get(DAEMON_CONFIG_ENV_VAR, ".");
 | 
			
		||||
            ConfigFileName_ =
 | 
			
		||||
                ConfigFileName_.empty() ? Location + "/" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_;
 | 
			
		||||
@@ -183,9 +224,11 @@ namespace OpenWifi {
 | 
			
		||||
                          << std::endl;
 | 
			
		||||
                std::exit(Poco::Util::Application::EXIT_CONFIG);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
		// 	    loadConfiguration(ConfigFile.toString());
 | 
			
		||||
            PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration(ConfigFile.toString());
 | 
			
		||||
        } else {
 | 
			
		||||
            std::istringstream is(ConfigContent_);
 | 
			
		||||
            PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration(is);
 | 
			
		||||
        }
 | 
			
		||||
		configPtr()->addWriteable(PropConfigurationFile_, PRIO_DEFAULT);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -388,11 +431,13 @@ namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
	void DaemonPostInitialization(Poco::Util::Application &self);
 | 
			
		||||
 | 
			
		||||
	void MicroService::initialize(Poco::Util::Application &self) {
 | 
			
		||||
		// add the default services
 | 
			
		||||
    void MicroService::StartEverything(Poco::Util::Application &self) {
 | 
			
		||||
        LoadConfigurationFile();
 | 
			
		||||
        InitializeLoggingSystem();
 | 
			
		||||
 | 
			
		||||
        static bool InitializedBaseService=false;
 | 
			
		||||
        if(!InitializedBaseService) {
 | 
			
		||||
            InitializedBaseService = true;
 | 
			
		||||
            SubSystems_.push_back(KafkaManager());
 | 
			
		||||
            SubSystems_.push_back(ALBHealthCheckServer());
 | 
			
		||||
            SubSystems_.push_back(RESTAPI_ExtServer());
 | 
			
		||||
@@ -400,11 +445,13 @@ namespace OpenWifi {
 | 
			
		||||
#ifndef TIP_SECURITY_SERVICE
 | 
			
		||||
            SubSystems_.push_back(AuthClient());
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
            Poco::Net::initializeSSL();
 | 
			
		||||
            Poco::Net::HTTPStreamFactory::registerFactory();
 | 
			
		||||
            Poco::Net::HTTPSStreamFactory::registerFactory();
 | 
			
		||||
            Poco::Net::FTPStreamFactory::registerFactory();
 | 
			
		||||
            Poco::Net::FTPSStreamFactory::registerFactory();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Poco::File DataDir(ConfigPath("openwifi.system.data"));
 | 
			
		||||
        DataDir_ = DataDir.path();
 | 
			
		||||
@@ -412,7 +459,7 @@ namespace OpenWifi {
 | 
			
		||||
            try {
 | 
			
		||||
                DataDir.createDirectory();
 | 
			
		||||
            } catch (const Poco::Exception &E) {
 | 
			
		||||
				logger().log(E);
 | 
			
		||||
                Logger_.log(E);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        WWWAssetsDir_ = ConfigPath("openwifi.restapi.wwwassets", "");
 | 
			
		||||
@@ -433,6 +480,12 @@ namespace OpenWifi {
 | 
			
		||||
        KafkaManager()->RegisterTopicWatcher(KafkaTopics::SERVICE_EVENTS, F);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	void MicroService::initialize([[maybe_unused]] Poco::Util::Application &self) {
 | 
			
		||||
#ifndef USE_MEDUSA_CLIENT
 | 
			
		||||
        StartEverything(self);
 | 
			
		||||
#endif
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void MicroService::uninitialize() {
 | 
			
		||||
		// add your own uninitialization code here
 | 
			
		||||
		ServerApplication::uninitialize();
 | 
			
		||||
@@ -530,14 +583,12 @@ namespace OpenWifi {
 | 
			
		||||
		for (auto i : SubSystems_) {
 | 
			
		||||
			i->Start();
 | 
			
		||||
		}
 | 
			
		||||
		EventBusManager_ = std::make_unique<EventBusManager>(Poco::Logger::create(
 | 
			
		||||
			"EventBusManager", Poco::Logger::root().getChannel(), Poco::Logger::root().getLevel()));
 | 
			
		||||
		EventBusManager_->Start();
 | 
			
		||||
		EventBusManager()->Start();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void MicroService::StopSubSystemServers() {
 | 
			
		||||
		AddActivity("Stopping");
 | 
			
		||||
		EventBusManager_->Stop();
 | 
			
		||||
		EventBusManager()->Stop();
 | 
			
		||||
		for (auto i = SubSystems_.rbegin(); i != SubSystems_.rend(); ++i) {
 | 
			
		||||
			(*i)->Stop();
 | 
			
		||||
		}
 | 
			
		||||
@@ -697,7 +748,7 @@ namespace OpenWifi {
 | 
			
		||||
			auto APIKEY = Request.get("X-API-KEY");
 | 
			
		||||
			return APIKEY == MyHash_;
 | 
			
		||||
		} catch (const Poco::Exception &E) {
 | 
			
		||||
			logger().log(E);
 | 
			
		||||
			Logger_.log(E);
 | 
			
		||||
		}
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
@@ -718,6 +769,8 @@ namespace OpenWifi {
 | 
			
		||||
		MicroServiceErrorHandler ErrorHandler(*this);
 | 
			
		||||
		Poco::ErrorHandler::set(&ErrorHandler);
 | 
			
		||||
 | 
			
		||||
        Args_ = args;
 | 
			
		||||
 | 
			
		||||
		if (!HelpRequested_) {
 | 
			
		||||
			SavePID();
 | 
			
		||||
 | 
			
		||||
@@ -733,11 +786,18 @@ namespace OpenWifi {
 | 
			
		||||
				poco_information(logger, "Starting as a daemon.");
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
#ifdef USE_MEDUSA_CLIENT
 | 
			
		||||
            MedusaClient::instance()->SetSubSystems(SubSystems_);
 | 
			
		||||
            MedusaClient::instance()->Start();
 | 
			
		||||
			waitForTerminationRequest();
 | 
			
		||||
            MedusaClient::instance()->Stop();
 | 
			
		||||
#else
 | 
			
		||||
			poco_information(logger, fmt::format("System ID set to {}", ID_));
 | 
			
		||||
			StartSubSystemServers();
 | 
			
		||||
			waitForTerminationRequest();
 | 
			
		||||
			StopSubSystemServers();
 | 
			
		||||
			logger.notice(fmt::format("Stopped {}...", DAEMON_APP_NAME));
 | 
			
		||||
#endif
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return Application::EXIT_OK;
 | 
			
		||||
 
 | 
			
		||||
@@ -55,9 +55,6 @@ namespace OpenWifi {
 | 
			
		||||
#include "nlohmann/json.hpp"
 | 
			
		||||
#include "ow_version.h"
 | 
			
		||||
 | 
			
		||||
#define _OWDEBUG_ std::cout << __FILE__ << ":" << __LINE__ << std::endl;
 | 
			
		||||
// #define _OWDEBUG_ Logger().debug(Poco::format("%s: %lu",__FILE__,__LINE__));
 | 
			
		||||
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
	class MicroService : public Poco::Util::ServerApplication {
 | 
			
		||||
@@ -70,7 +67,6 @@ namespace OpenWifi {
 | 
			
		||||
			  SubSystems_(std::move(Subsystems)), Logger_(Poco::Logger::get("FRAMEWORK")) {
 | 
			
		||||
			instance_ = this;
 | 
			
		||||
			RandomEngine_.seed(std::chrono::steady_clock::now().time_since_epoch().count());
 | 
			
		||||
			// Logger_ = Poco::Logger::root().get("BASE-SVC");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		inline static const char *ExtraConfigurationFilename = "/configuration_override.json";
 | 
			
		||||
@@ -92,7 +88,7 @@ namespace OpenWifi {
 | 
			
		||||
		inline uint64_t DaemonBusTimer() const { return DAEMON_BUS_TIMER; };
 | 
			
		||||
		[[nodiscard]] const std::string &AppName() { return DAEMON_APP_NAME; }
 | 
			
		||||
		static inline uint64_t GetPID() { return Poco::Process::id(); };
 | 
			
		||||
		[[nodiscard]] inline const std::string GetPublicAPIEndPoint() {
 | 
			
		||||
		[[nodiscard]] inline std::string GetPublicAPIEndPoint() const {
 | 
			
		||||
			return MyPublicEndPoint_ + "/api/v1";
 | 
			
		||||
		};
 | 
			
		||||
		[[nodiscard]] inline const std::string &GetUIURI() const { return UIURI_; };
 | 
			
		||||
@@ -107,7 +103,8 @@ namespace OpenWifi {
 | 
			
		||||
		}
 | 
			
		||||
		static MicroService &instance() { return *instance_; }
 | 
			
		||||
 | 
			
		||||
		inline void Exit(int Reason);
 | 
			
		||||
		inline void Exit(int Reason) { std::exit(Reason); }
 | 
			
		||||
 | 
			
		||||
		void BusMessageReceived(const std::string &Key, const std::string &Payload);
 | 
			
		||||
		Types::MicroServiceMetaVec GetServices(const std::string &Type);
 | 
			
		||||
		Types::MicroServiceMetaVec GetServices();
 | 
			
		||||
@@ -115,6 +112,7 @@ namespace OpenWifi {
 | 
			
		||||
		void Reload();
 | 
			
		||||
		void LoadMyConfig();
 | 
			
		||||
		void initialize(Poco::Util::Application &self) override;
 | 
			
		||||
        void StartEverything(Poco::Util::Application &self);
 | 
			
		||||
		void uninitialize() override;
 | 
			
		||||
		void reinitialize(Poco::Util::Application &self) override;
 | 
			
		||||
		void defineOptions(Poco::Util::OptionSet &options) override;
 | 
			
		||||
@@ -132,7 +130,7 @@ namespace OpenWifi {
 | 
			
		||||
		void Reload(const std::string &Sub);
 | 
			
		||||
		Types::StringVec GetSubSystems() const;
 | 
			
		||||
		Types::StringPairVec GetLogLevels();
 | 
			
		||||
		const Types::StringVec &GetLogLevelNames();
 | 
			
		||||
		static const Types::StringVec &GetLogLevelNames();
 | 
			
		||||
		uint64_t ConfigGetInt(const std::string &Key, uint64_t Default);
 | 
			
		||||
		uint64_t ConfigGetInt(const std::string &Key);
 | 
			
		||||
		uint64_t ConfigGetBool(const std::string &Key, bool Default);
 | 
			
		||||
@@ -166,12 +164,16 @@ namespace OpenWifi {
 | 
			
		||||
								const std::string &FormatterPattern,
 | 
			
		||||
								const std::string &root_env_var);
 | 
			
		||||
		inline bool AllowExternalMicroServices() const { return AllowExternalMicroServices_; }
 | 
			
		||||
        const ArgVec &Args() const { return Args_; }
 | 
			
		||||
 | 
			
		||||
        inline void SetConfigContent(const std::string &Content) { ConfigContent_ = Content; }
 | 
			
		||||
 | 
			
		||||
	  private:
 | 
			
		||||
		static MicroService *instance_;
 | 
			
		||||
		bool HelpRequested_ = false;
 | 
			
		||||
		std::string LogDir_;
 | 
			
		||||
		std::string ConfigFileName_;
 | 
			
		||||
        std::string ConfigContent_;
 | 
			
		||||
		uint64_t ID_ = 1;
 | 
			
		||||
		Poco::SharedPtr<Poco::Crypto::RSAKey> AppKey_;
 | 
			
		||||
		bool DebugMode_ = false;
 | 
			
		||||
@@ -201,7 +203,7 @@ namespace OpenWifi {
 | 
			
		||||
		Poco::JWT::Signer Signer_;
 | 
			
		||||
		Poco::Logger &Logger_;
 | 
			
		||||
		Poco::ThreadPool TimerPool_{"timer:pool", 2, 32};
 | 
			
		||||
		std::unique_ptr<EventBusManager> EventBusManager_;
 | 
			
		||||
        ArgVec Args_;
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	inline MicroService *MicroService::instance_ = nullptr;
 | 
			
		||||
 
 | 
			
		||||
@@ -47,6 +47,8 @@ namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Poco::Data::SessionPool &Pool() { return *Pool_; }
 | 
			
		||||
 | 
			
		||||
	  private:
 | 
			
		||||
		inline int Setup_SQLite();
 | 
			
		||||
		inline int Setup_MySQL();
 | 
			
		||||
 
 | 
			
		||||
@@ -58,11 +58,9 @@ namespace OpenWifi {
 | 
			
		||||
	void UI_WebSocketClientServer::run() {
 | 
			
		||||
		Running_ = true;
 | 
			
		||||
		while (Running_) {
 | 
			
		||||
			Poco::Thread::trySleep(2000);
 | 
			
		||||
 | 
			
		||||
			if (!Running_)
 | 
			
		||||
			if(!Poco::Thread::trySleep(2000)) {
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
			std::lock_guard G(LocalMutex_);
 | 
			
		||||
			for (const auto i : ToBeRemoved_) {
 | 
			
		||||
				// std::cout << "Erasing old WS UI connection..." << std::endl;
 | 
			
		||||
 
 | 
			
		||||
@@ -576,8 +576,8 @@ namespace ORM {
 | 
			
		||||
		bool UpdateRecord(field_name_t FieldName, const T &Value, const RecordType &R) {
 | 
			
		||||
			try {
 | 
			
		||||
				assert(ValidFieldName(FieldName));
 | 
			
		||||
 | 
			
		||||
				Poco::Data::Session Session = Pool_.get();
 | 
			
		||||
                Session.begin();
 | 
			
		||||
				Poco::Data::Statement Update(Session);
 | 
			
		||||
 | 
			
		||||
				RecordTuple RT;
 | 
			
		||||
@@ -593,6 +593,7 @@ namespace ORM {
 | 
			
		||||
				Update.execute();
 | 
			
		||||
				if (Cache_)
 | 
			
		||||
					Cache_->UpdateCache(R);
 | 
			
		||||
                Session.commit();
 | 
			
		||||
				return true;
 | 
			
		||||
			} catch (const Poco::Exception &E) {
 | 
			
		||||
				Logger_.log(E);
 | 
			
		||||
@@ -662,6 +663,7 @@ namespace ORM {
 | 
			
		||||
				assert(ValidFieldName(FieldName));
 | 
			
		||||
 | 
			
		||||
				Poco::Data::Session Session = Pool_.get();
 | 
			
		||||
                Session.begin();
 | 
			
		||||
				Poco::Data::Statement Delete(Session);
 | 
			
		||||
 | 
			
		||||
				std::string St = "delete from " + TableName_ + " where " + FieldName + "=?";
 | 
			
		||||
@@ -671,6 +673,7 @@ namespace ORM {
 | 
			
		||||
				Delete.execute();
 | 
			
		||||
				if (Cache_)
 | 
			
		||||
					Cache_->Delete(FieldName, Value);
 | 
			
		||||
                Session.commit();
 | 
			
		||||
				return true;
 | 
			
		||||
			} catch (const Poco::Exception &E) {
 | 
			
		||||
				Logger_.log(E);
 | 
			
		||||
@@ -682,11 +685,13 @@ namespace ORM {
 | 
			
		||||
			try {
 | 
			
		||||
				assert(!WhereClause.empty());
 | 
			
		||||
				Poco::Data::Session Session = Pool_.get();
 | 
			
		||||
                Session.begin();
 | 
			
		||||
				Poco::Data::Statement Delete(Session);
 | 
			
		||||
 | 
			
		||||
				std::string St = "delete from " + TableName_ + " where " + WhereClause;
 | 
			
		||||
				Delete << St;
 | 
			
		||||
				Delete.execute();
 | 
			
		||||
                Session.commit();
 | 
			
		||||
				return true;
 | 
			
		||||
			} catch (const Poco::Exception &E) {
 | 
			
		||||
				Logger_.log(E);
 | 
			
		||||
 
 | 
			
		||||
@@ -565,6 +565,7 @@ namespace OpenWifi::RESTAPI::Protocol {
 | 
			
		||||
 | 
			
		||||
	static const char *TRANSFER = "transfer";
 | 
			
		||||
	static const char *CERTUPDATE = "certupdate";
 | 
			
		||||
	static const char *POWERCYCLE = "powercycle";
 | 
			
		||||
	static const char *RRM = "rrm";
 | 
			
		||||
 | 
			
		||||
	static const char *REQUIREMENTS = "requirements";
 | 
			
		||||
@@ -687,6 +688,7 @@ namespace OpenWifi::uCentralProtocol {
 | 
			
		||||
 | 
			
		||||
	static const char *TRANSFER = "transfer";
 | 
			
		||||
	static const char *CERTUPDATE = "certupdate";
 | 
			
		||||
	static const char *POWERCYCLE = "powercycle";
 | 
			
		||||
	static const char *RRM = "rrm";
 | 
			
		||||
	static const char *ACTIONS = "actions";
 | 
			
		||||
 | 
			
		||||
@@ -785,6 +787,7 @@ namespace OpenWifi::APCommands {
 | 
			
		||||
		rrm,
 | 
			
		||||
		certupdate,
 | 
			
		||||
		transfer,
 | 
			
		||||
		powercycle,
 | 
			
		||||
		unknown
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
@@ -799,7 +802,7 @@ namespace OpenWifi::APCommands {
 | 
			
		||||
		RESTAPI::Protocol::EVENTQUEUE,	 RESTAPI::Protocol::TELEMETRY,
 | 
			
		||||
		RESTAPI::Protocol::PING,		 RESTAPI::Protocol::SCRIPT,
 | 
			
		||||
		RESTAPI::Protocol::RRM,		 	 RESTAPI::Protocol::CERTUPDATE,
 | 
			
		||||
		RESTAPI::Protocol::TRANSFER
 | 
			
		||||
		RESTAPI::Protocol::TRANSFER,	 RESTAPI::Protocol::POWERCYCLE
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	inline const char *to_string(Commands Cmd) { return uCentralAPCommands[(uint8_t)Cmd]; }
 | 
			
		||||
 
 | 
			
		||||
@@ -316,5 +316,90 @@ namespace OpenWifi::Utils {
 | 
			
		||||
        uint32_t        Port;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
	class CompressedString {
 | 
			
		||||
	  public:
 | 
			
		||||
		CompressedString() {
 | 
			
		||||
			DecompressedSize_ = 0;
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		explicit CompressedString(const std::string &Data) : DecompressedSize_(Data.size()) {
 | 
			
		||||
			CompressIt(Data);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		CompressedString(const CompressedString &Data) {
 | 
			
		||||
			this->DecompressedSize_ = Data.DecompressedSize_;
 | 
			
		||||
			this->CompressedData_ = Data.CompressedData_;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		CompressedString& operator=(const CompressedString& rhs) {
 | 
			
		||||
			if (this != &rhs) {
 | 
			
		||||
				this->DecompressedSize_ = rhs.DecompressedSize_;
 | 
			
		||||
				this->CompressedData_ = rhs.CompressedData_;
 | 
			
		||||
			}
 | 
			
		||||
			return *this;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		CompressedString& operator=(CompressedString&& rhs) {
 | 
			
		||||
			if (this != &rhs) {
 | 
			
		||||
				this->DecompressedSize_ = rhs.DecompressedSize_;
 | 
			
		||||
				this->CompressedData_ = rhs.CompressedData_;
 | 
			
		||||
			}
 | 
			
		||||
			return *this;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		~CompressedString() = default;
 | 
			
		||||
 | 
			
		||||
		operator std::string() const {
 | 
			
		||||
			return DecompressIt();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		CompressedString &operator=(const std::string &Data) {
 | 
			
		||||
			DecompressedSize_ = Data.size();
 | 
			
		||||
			CompressIt(Data);
 | 
			
		||||
			return *this;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		auto CompressedSize() const { return CompressedData_.size(); }
 | 
			
		||||
		auto DecompressedSize() const { return DecompressedSize_; }
 | 
			
		||||
 | 
			
		||||
	  private:
 | 
			
		||||
		std::string     CompressedData_;
 | 
			
		||||
		std::size_t     DecompressedSize_;
 | 
			
		||||
 | 
			
		||||
		inline void CompressIt(const std::string &Data) {
 | 
			
		||||
			z_stream strm; // = {0};
 | 
			
		||||
			CompressedData_.resize(Data.size());
 | 
			
		||||
			strm.next_in = (Bytef *)Data.data();
 | 
			
		||||
			strm.avail_in = Data.size();
 | 
			
		||||
			strm.next_out = (Bytef *)CompressedData_.data();
 | 
			
		||||
			strm.avail_out = Data.size();
 | 
			
		||||
			strm.zalloc = Z_NULL;
 | 
			
		||||
			strm.zfree = Z_NULL;
 | 
			
		||||
			strm.opaque = Z_NULL;
 | 
			
		||||
			deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY);
 | 
			
		||||
			deflate(&strm, Z_FINISH);
 | 
			
		||||
			deflateEnd(&strm);
 | 
			
		||||
			CompressedData_.resize(strm.total_out);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		[[nodiscard]] std::string DecompressIt() const {
 | 
			
		||||
			std::string Result;
 | 
			
		||||
			if(DecompressedSize_!=0) {
 | 
			
		||||
				Result.resize(DecompressedSize_);
 | 
			
		||||
				z_stream strm ; //= {0};
 | 
			
		||||
				strm.next_in = (Bytef *)CompressedData_.data();
 | 
			
		||||
				strm.avail_in = CompressedData_.size();
 | 
			
		||||
				strm.next_out = (Bytef *)Result.data();
 | 
			
		||||
				strm.avail_out = Result.size();
 | 
			
		||||
				strm.zalloc = Z_NULL;
 | 
			
		||||
				strm.zfree = Z_NULL;
 | 
			
		||||
				strm.opaque = Z_NULL;
 | 
			
		||||
				inflateInit2(&strm, 15 + 32);
 | 
			
		||||
				inflate(&strm, Z_FINISH);
 | 
			
		||||
				inflateEnd(&strm);
 | 
			
		||||
			}
 | 
			
		||||
			return Result;
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
} // namespace OpenWifi::Utils
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user