Compare commits

..

4 Commits

75 changed files with 1043 additions and 7800 deletions

View File

@@ -21,7 +21,7 @@ defaults:
jobs:
docker:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
env:
DOCKER_REGISTRY_URL: tip-tip-wlan-cloud-ucentral.jfrog.io
DOCKER_REGISTRY_USERNAME: ucentral

View File

@@ -11,7 +11,7 @@ defaults:
jobs:
helm-package:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
env:
HELM_REPO_URL: https://tip.jfrog.io/artifactory/tip-wlan-cloud-ucentral-helm/
HELM_REPO_USERNAME: ucentral

6
.gitignore vendored
View File

@@ -21,14 +21,10 @@ _deps
/docker-compose/.env
/docker-compose/.env_*
/cmake-build/
/uploads/
test_scripts/curl/token.json
.vscode/c_cpp_properties.json
test_scripts/curl/result.json
*.swp
helm/charts/*
!helm/charts/.gitkeep
/portal-test/
/src/ow_version.h
.vscode/*
# Build dependencies temporary folder
.build-deps/

2
.idea/.gitignore generated vendored
View File

@@ -6,5 +6,3 @@
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
# GitHub Copilot persisted chat sessions
/copilot/chatSessions

3
.idea/misc.xml generated
View File

@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.9 (wlan-cloud-ucentralgw)" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="CidrRootsConfiguration">
<excludeRoots>

View File

@@ -1,79 +1,54 @@
# Building from source
## Quick Build (Recommended - Using Container)
The easiest way to build OWGW is using the provided build script that creates a Debian Bookworm container with all dependencies:
```bash
./build-ucentralgw.sh
```
This script will:
- Build all dependencies (POCO, cppkafka, valijson) in a Debian Bookworm container
- Store dependency builds in `.build-deps/` (gitignored, cached for faster rebuilds)
- Build the OWGW binary and place it in `./cmake-build/owgw`
- Work entirely within the repository - no system-wide installation needed
**Requirements:**
- Docker installed and running
- Git
**Clean rebuild (if needed):**
```bash
rm -rf .build-deps/build-cache
./build-ucentralgw.sh
```
## Manual Build from Source
If you prefer to build manually without Docker, you will need to install the following dependencies:
In order to build the OWGW, you will need to install its dependencies, which includes the following:
- cmake
- boost
- POCO 1.10.1 or later
- a C++17 compiler
- openssl
- libpq-dev (PostgreSQL development libraries)
- libpq-dev (PortgreSQL development libraries)
- mysql-client (MySQL client)
- librdkafka
- cppkafka
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/Telecominfraproject/wlan-cloud-lib-poco). Building
from the master copy needed for cmake. Please use the version of this [Poco fix](https://github.com/AriliaWireless/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 \
libpq-dev libaprutil1-dev apache2-dev libboost-all-dev \
librdkafka-dev default-libmysqlclient-dev \
nlohmann-json-dev
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
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-poco --branch poco-tip-v1 poco
cd ~
git clone https://github.com/AriliaWireless/poco --branch poco-tip-v2
cd poco
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
cd ../..
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka --branch tip-v1 cppkafka
cd ~
git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1
cd cppkafka
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
cd ../..
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-valijson --branch tip-v1 valijson
cd ~
git clone https://github.com/AriliaWireless/valijson --branch tip-v1
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
@@ -82,59 +57,56 @@ cd cmake-build
cmake ..
make
make install
cd ../..
cd ~
git clone https://github.com/Telecominfraproject/wlan-cloud-ucentralgw
cd wlan-cloud-ucentralgw
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 \
yaml-cpp-devel lua-devel
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 dnf install postgresql.x86_64 librdkafka-devel
sudo dnf install postgresql-devel json-devel
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-poco --branch poco-tip-v1 poco
git clone https://github.com/AriliaWireless/poco --branch poco-tip-v2
cd poco
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
cd ../..
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka --branch tip-v1 cppkafka
git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1
cd cppkafka
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
cd ../..
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-valijson --branch tip-v1 valijson
cd ~
git clone https://github.com/AriliaWireless/valijson --branch tip-v1
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-ucentralgw
cd wlan-cloud-ucentralgw
mkdir cmake-build
cd cmake-build
cmake ..
make
cd ../..
```
## macOS Build
@@ -153,7 +125,7 @@ brew install openssl \
nlohmann-json \
fmt
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-poco --branch poco-tip-v1 poco
git clone https://github.com/AriliaWireless/poco --branch poco-tip-v2
pushd poco
mkdir cmake-build
push cmake-build
@@ -163,7 +135,7 @@ sudo cmake --build . --target install
popd
popd
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka --branch tip-v1 cppkafka
git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1
pushd cppkafka
mkdir cmake-build
pushd cmake-build
@@ -173,10 +145,10 @@ sudo cmake --build . --target install
popd
popd
git clone https://github.com/Telecominfraproject/wlan-cloud-lib-valijson --branch tip-v1 valijson
pushd valijson
git clone https://github.com/AriliaWireless/valijson --branch tip-v1
cd valijson
mkdir cmake-build
pushd cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
@@ -199,23 +171,20 @@ 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/Telecominfraproject/wlan-cloud-lib-poco --branch poco-tip-v1 poco
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
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-ucentralgw
cd wlan-cloud-ucentralgw
mkdir cmake-build
cd cmake-build
cmake -DSMALL_BUILD=1 ..
make
cd ../..
```

View File

@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.13)
project(owgw VERSION 4.2.2)
project(owgw VERSION 3.0.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 17)
if(UNIX AND APPLE)
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)
@@ -149,7 +148,6 @@ add_executable( owgw
src/RESTAPI/RESTAPI_script_handler.cpp src/RESTAPI/RESTAPI_script_handler.h
src/RESTAPI/RESTAPI_regulatory.cpp src/RESTAPI/RESTAPI_regulatory.h
src/RESTAPI/RESTAPI_radiussessions_handler.cpp src/RESTAPI/RESTAPI_radiussessions_handler.h
src/storage/storage_blacklist.cpp src/storage/storage_tables.cpp src/storage/storage_logs.cpp
src/storage/storage_command.cpp src/storage/storage_healthcheck.cpp src/storage/storage_statistics.cpp
src/storage/storage_device.cpp src/storage/storage_capabilities.cpp src/storage/storage_defconfig.cpp

View File

@@ -1,7 +1,7 @@
ARG DEBIAN_VERSION=bookworm
ARG POCO_VERSION=poco-tip-v4-tag
ARG DEBIAN_VERSION=11.5-slim
ARG POCO_VERSION=poco-tip-v2
ARG CPPKAFKA_VERSION=tip-v1
ARG VALIJASON_VERSION=tip-v1.0.2
ARG VALIJASON_VERSION=tip-v1
ARG APP_NAME=owgw
ARG APP_HOME_DIR=/openwifi
@@ -17,8 +17,8 @@ FROM build-base AS poco-build
ARG POCO_VERSION
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
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
WORKDIR /poco
RUN mkdir cmake-build
@@ -31,8 +31,8 @@ FROM build-base AS cppkafka-build
ARG CPPKAFKA_VERSION
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
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
WORKDIR /cppkafka
RUN mkdir cmake-build
@@ -45,8 +45,8 @@ FROM build-base AS valijson-build
ARG VALIJASON_VERSION
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
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
WORKDIR /valijson
RUN mkdir cmake-build
@@ -100,7 +100,7 @@ RUN mkdir -p $APP_ROOT $APP_CONFIG && \
RUN apt-get update && apt-get install --no-install-recommends -y \
librdkafka++1 gosu gettext ca-certificates bash jq curl wget \
libmariadb-dev-compat libpq5 unixodbc postgresql-client libfmt9 sqlite3
libmariadb-dev-compat libpq5 unixodbc postgresql-client libfmt7 sqlite3
COPY readiness_check /readiness_check
COPY test_scripts/curl/cli /cli

View File

@@ -306,54 +306,8 @@ The device should answer:
},
"id" : <same number>
}
```
#### Controller wants the device to apply a given fixed configuration
Controller sends this command when it requires the device to apply fixed configuration, eg. country code. The device
should respond with message indicating failure or success.
```json
{ "jsonrpc" : "2.0",
"method" : "fixedconfig",
"params" : {
"serial" : <serial number>,
"when" : Optional - <UTC time when to apply this config, 0 means immediate, this is a suggestion>
"country" : "<country-code>"
},
}
```
If AP supports compressed configuration feature by inidcating `compress_cmd=true` in its capabilities, controller
will send a compressed configuration message where configuration payload (i.e. contents of `params`) is compressed
and encoded in base64 format:
```json
{ "jsonrpc" : "2.0",
"method" : "configure",
"params" : {
"compress_64" : "<b64 encoded zlib compressed payload>",
"compress_sz" : "<size of uncompressed data in bytes>"
},
"id" : <some number>
}
```
The device should answer:
```json
{ "jsonrpc" : "2.0",
"result" : {
"serial": <serial number>,
"status": {
"error": 0 or an error number,
"text": <description of the error or success, eg. "Applied fixed config, rebooting">
},
"uuid": <UUID>
}
}
```
##### The Answer
The device can answer and tell the controller it has rejected certain parts of the config and potentially replaced them with
appropriate values. This could be used to allow a device to replace frequencies for the regions it is located in. The device
@@ -401,39 +355,6 @@ The device should answer:
- 1 : the device is busy but will reboot soon. `text` may indicate why.
- 2 : the device will not reboot. `text` contains information as to why.
#### Controller wants to power-cycle PoE port(s)
Controller sends this command to power-cycle 1 or more PoE ports
```json
{ "jsonrpc" : "2.0" ,
"method" : "powercycle" ,
"params" : {
"serial" : <serial number> ,
"ports" : [ { "name" : "Ethernet1", "cycle" : 5000}, { "name" : "Ethernet8", "cycle" : 10000 } ],
"when" : Optional - <UTC time when to reboot, 0 mean immediately, this is a suggestion>
},
"id" : <some number>
}
```
The device should answer:
```json
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
"status" : {
"error" : 0 or an error number,
"text" : [ "Error 1" , "Error 2" ],
"when" : <time when this will be performed as UTC seconds>,
},
"id" : <same id from request>
}
```
###### Error codes
- 0 : is rebooting at `when` seconds.
- 1 : the device is busy but will reboot soon. `text` may indicate why.
- 2 : the device will not reboot. `text` contains information as to why.
#### Controller wants the device to upgrade its firmware
Controller sends this command when it believes the device should upgrade its firmware.
```json
@@ -880,32 +801,6 @@ The device should answer:
}
```
#### Controller wants the device to perform re-enrollment
Controller sends this command to trigger re-enrollment, i.e. update of operational certificate. Extreme care must be taken.
```json
{ "jsonrpc" : "2.0" ,
"method" : "reenroll" ,
"params" : {
"serial" : <serial number>,
"when" : Optional - <UTC time when to apply this config, 0 mean immediate, this is a suggestion>
},
"id" : <some number>
}
```
The device should answer:
```json
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
"status" : {
"error" : <0 or the value of $? from the shell running the command, 255 signifies a timeout>,
"txt" : <text describing the error or success>
},
"id" : <same number as request>
}
```
#### Controller wants the device to switch to another controller
Controller sends this when the device should change the controller it connects to without looking up a new redirector.

2
build
View File

@@ -1 +1 @@
3
65

View File

@@ -1,243 +0,0 @@
#!/bin/bash
# Script to build wlan-cloud-ucentralgw project in a Debian Bookworm container
# Dependencies are built in a temporary folder within the repo
set -e
# Configuration
POCO_VERSION="poco-tip-v4-tag"
CPPKAFKA_VERSION="tip-v1"
VALIJSON_VERSION="tip-v1.0.2"
DEBIAN_VERSION="bookworm"
TEMP_BUILD_DIR=".build-deps"
OUTPUT_DIR="./cmake-build"
BINARY_NAME="owgw"
CONTAINER_NAME="ucentralgw-builder-$$"
IMAGE_NAME="ucentralgw-build-env:${DEBIAN_VERSION}"
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${GREEN}=== Building wlan-cloud-ucentralgw in Debian ${DEBIAN_VERSION} container ===${NC}"
# Check if Docker is available
if ! command -v docker >/dev/null 2>&1; then
echo -e "${RED}Error: Docker is not installed or not in PATH${NC}"
exit 1
fi
# Create temporary build directory structure
echo -e "${YELLOW}Creating temporary build directory: ${TEMP_BUILD_DIR}${NC}"
mkdir -p "${TEMP_BUILD_DIR}"
mkdir -p "${OUTPUT_DIR}"
# Create Dockerfile for build environment
echo -e "${YELLOW}Creating build environment Dockerfile...${NC}"
cat > "${TEMP_BUILD_DIR}/Dockerfile.build" <<EOF
FROM debian:${DEBIAN_VERSION}
# Install build dependencies
RUN apt-get update && apt-get install --no-install-recommends -y \\
make cmake g++ git \\
libpq-dev libmariadb-dev libmariadbclient-dev-compat \\
librdkafka-dev libboost-all-dev libssl-dev \\
zlib1g-dev nlohmann-json3-dev ca-certificates libfmt-dev
# Set working directory
WORKDIR /build
# Copy build script into container
COPY build-in-container.sh /build/
RUN chmod +x /build/build-in-container.sh
# Entry point
ENTRYPOINT ["/build/build-in-container.sh"]
EOF
# Create the build script that runs inside the container
echo -e "${YELLOW}Creating in-container build script...${NC}"
cat > "${TEMP_BUILD_DIR}/build-in-container.sh" <<'EOFSCRIPT'
#!/bin/bash
set -e
POCO_VERSION="poco-tip-v4-tag"
CPPKAFKA_VERSION="tip-v1"
VALIJSON_VERSION="tip-v1.0.2"
BUILD_DIR="/build/deps"
INSTALL_PREFIX="/build/install"
REPO_DIR="/repo"
OUTPUT_DIR="/repo/cmake-build"
# Number of parallel jobs
JOBS=$(nproc 2>/dev/null || echo 4)
echo "=== Building dependencies in container ==="
echo "Using ${JOBS} parallel jobs"
# Function to build a dependency
build_dependency() {
local name=$1
local repo=$2
local branch=$3
local build_dir="${BUILD_DIR}/${name}"
echo "Building ${name}..."
if [ ! -d "${build_dir}" ]; then
echo "Cloning ${name} from ${repo} (branch: ${branch})"
git clone --depth 1 --branch "${branch}" "${repo}" "${build_dir}"
fi
mkdir -p "${build_dir}/cmake-build"
cd "${build_dir}/cmake-build"
echo "Configuring ${name}..."
if [ "${name}" = "poco" ]; then
# POCO needs special configuration to enable all required components
cmake -DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
-DENABLE_JSON=ON \
-DENABLE_CRYPTO=ON \
-DENABLE_JWT=ON \
-DENABLE_NET=ON \
-DENABLE_NETSSL=ON \
-DENABLE_UTIL=ON \
-DENABLE_DATA=ON \
-DENABLE_DATA_SQLITE=ON \
-DENABLE_DATA_POSTGRESQL=ON \
-DENABLE_DATA_MYSQL=ON \
..
else
cmake -DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" ..
fi
echo "Building ${name}..."
cmake --build . --config Release -j${JOBS}
echo "Installing ${name}..."
cmake --build . --target install
# For POCO, create symlinks if needed and show what was installed
if [ "${name}" = "poco" ]; then
echo "POCO libraries installed:"
find "${INSTALL_PREFIX}/lib" -name "libPoco*" -type f || true
# Run ldconfig to update library cache
cd "${INSTALL_PREFIX}/lib"
# Create missing symlinks if needed
for lib in libPocoJSON.so libPocoCrypto.so libPocoNet.so libPocoNetSSL.so libPocoUtil.so libPocoFoundation.so libPocoData.so libPocoDataSQLite.so libPocoDataPostgreSQL.so libPocoDataMySQL.so libPocoJWT.so; do
if [ ! -e "${lib}" ]; then
# Find versioned library and create symlink
versioned=$(find . -maxdepth 1 -name "${lib}.*" | head -n 1)
if [ -n "$versioned" ]; then
echo "Creating symlink: ${lib} -> ${versioned}"
ln -sf "$(basename ${versioned})" "${lib}"
fi
fi
done
fi
echo "${name} built successfully"
}
# Create directories
mkdir -p "${BUILD_DIR}"
mkdir -p "${INSTALL_PREFIX}"
# Build POCO
build_dependency \
"poco" \
"https://github.com/Telecominfraproject/wlan-cloud-lib-poco" \
"${POCO_VERSION}"
# Build cppkafka
build_dependency \
"cppkafka" \
"https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka" \
"${CPPKAFKA_VERSION}"
# Build valijson
build_dependency \
"valijson" \
"https://github.com/Telecominfraproject/wlan-cloud-lib-valijson" \
"${VALIJSON_VERSION}"
# Build the main application
echo "=== Building owgw ==="
cd "${REPO_DIR}"
# Configure git to trust the repository directory (needed for mounted volumes)
git config --global --add safe.directory /repo
# Clean the build directory to avoid CMake cache conflicts
if [ -d "${OUTPUT_DIR}" ]; then
echo "Cleaning existing build directory..."
rm -rf "${OUTPUT_DIR}"
fi
mkdir -p "${OUTPUT_DIR}"
cd "${OUTPUT_DIR}"
echo "Configuring owgw..."
export CMAKE_PREFIX_PATH="${INSTALL_PREFIX}"
export PKG_CONFIG_PATH="${INSTALL_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}"
export LD_LIBRARY_PATH="${INSTALL_PREFIX}/lib:${LD_LIBRARY_PATH}"
# Debug: show what libraries are available
echo "Installed libraries in ${INSTALL_PREFIX}/lib:"
ls -la "${INSTALL_PREFIX}/lib" || true
cmake \
-DCMAKE_PREFIX_PATH="${INSTALL_PREFIX}" \
-DCMAKE_LIBRARY_PATH="${INSTALL_PREFIX}/lib" \
-DPoco_DIR="${INSTALL_PREFIX}/lib/cmake/Poco" \
-DCppKafka_DIR="${INSTALL_PREFIX}/lib/cmake/CppKafka" \
..
echo "Building owgw..."
echo "Library search paths:"
echo " LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
echo " CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
# Build with explicit library path
LIBRARY_PATH="${INSTALL_PREFIX}/lib:${LIBRARY_PATH}" \
cmake --build . --config Release -j${JOBS}
echo "=== Build completed successfully ==="
EOFSCRIPT
# Build the Docker image
echo -e "${YELLOW}Building Docker image (this may take a while on first run)...${NC}"
docker build \
-t "${IMAGE_NAME}" \
-f "${TEMP_BUILD_DIR}/Dockerfile.build" \
"${TEMP_BUILD_DIR}"
# Run the build in the container
echo -e "${YELLOW}Running build in container...${NC}"
docker run --rm \
--name "${CONTAINER_NAME}" \
-v "$(pwd):/repo" \
-v "$(pwd)/${TEMP_BUILD_DIR}/build-cache:/build/deps" \
"${IMAGE_NAME}"
echo -e "${GREEN}=== Build completed successfully! ===${NC}"
echo -e "${GREEN}Binary location: ${OUTPUT_DIR}/${BINARY_NAME}${NC}"
echo ""
echo "To run the binary, you'll need the dependencies installed or use the container."
echo ""
echo "To clean up build dependencies:"
echo -e "${YELLOW} rm -rf ${TEMP_BUILD_DIR}${NC}"
echo ""
echo "To remove the Docker image:"
echo -e "${YELLOW} docker rmi ${IMAGE_NAME}${NC}"
echo ""
echo "Note: The temporary build directory (${TEMP_BUILD_DIR}) is excluded from git."
exit 0

View File

@@ -14,7 +14,6 @@ if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
WEBSOCKET_HOST_CAS=${WEBSOCKET_HOST_CAS:-"\${APP_ROOT}/certs/cas"} \
WEBSOCKET_HOST_PORT=${WEBSOCKET_HOST_PORT:-"15002"} \
WEBSOCKET_HOST_KEY_PASSWORD=${WEBSOCKET_HOST_KEY_PASSWORD:-"mypassword"} \
WEBSOCKET_HOST_SECURITY=${WEBSOCKET_HOST_SECURITY:-"strict"} \
RESTAPI_HOST_ROOTCA=${RESTAPI_HOST_ROOTCA:-"\${APP_ROOT}/certs/restapi-ca.pem"} \
RESTAPI_HOST_PORT=${RESTAPI_HOST_PORT:-"16002"} \
RESTAPI_HOST_CERT=${RESTAPI_HOST_CERT:-"\${APP_ROOT}/certs/restapi-cert.pem"} \
@@ -33,7 +32,6 @@ if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
FILEUPLOADER_HOST_KEY_PASSWORD=${FILEUPLOADER_HOST_KEY_PASSWORD:-"mypassword"} \
FILEUPLOADER_PATH=${FILEUPLOADER_PATH:-"\${APP_ROOT}/uploads"} \
FILEUPLOADER_URI=${FILEUPLOADER_URI:-"https://localhost:16003"} \
FILEUPLOADER_MAXSIZE=${FILEUPLOADER_MAXSIZE:-"10000"} \
SERVICE_KEY=${SERVICE_KEY:-"\${APP_ROOT}/certs/restapi-key.pem"} \
SERVICE_KEY_PASSWORD=${SERVICE_KEY_PASSWORD:-"mypassword"} \
SYSTEM_DATA=${SYSTEM_DATA:-"\${APP_ROOT}/data"} \
@@ -78,7 +76,6 @@ if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
CERTIFICATES_ALLOWMISMATCH=${CERTIFICATES_ALLOWMISMATCH:-"false"} \
IPINFO_DEFAULT_COUNTRY=${IPINFO_DEFAULT_COUNTRY:-"US"} \
DEVICE_SESSION_TIMEOUT=${DEVICE_SESSION_TIMEOUT:-"600"} \
LOGGING_LEVEL=${LOGGING_LEVEL:-"information"} \
envsubst < /"${APP_NAME}".properties.tmpl > "${APP_CONFIG}"/"${APP_NAME}".properties
fi

View File

@@ -9,7 +9,7 @@ fullnameOverride: ""
images:
owgw:
repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owgw
tag: master
tag: v3.0.0-RC2
pullPolicy: Always
# regcred:
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io

View File

@@ -1,85 +0,0 @@
{
"ethernet": [
{
"select-ports": [
"Ethernet0",
"Ethernet1",
"Ethernet2",
"Ethernet3",
"Ethernet4",
"Ethernet5",
"Ethernet6",
"Ethernet7"
],
"speed": 2500,
"duplex": "full",
"enabled": true,
"poe": {
"admin-mode": true,
"power-limit": 60000
}
},
{
"select-ports": [
"Ethernet8",
"Ethernet9"
],
"speed": 10000,
"duplex": "full",
"media": "sfp-forced-1000sfp"
}
],
"interfaces": [
{
"name": "VLAN1",
"vlan": {
"id": 1
},
"ipv4": {
"addressing": "dynamic"
},
"ethernet": [
{
"select-ports": [
"Ethernet0",
"Ethernet1",
"Ethernet2",
"Ethernet3",
"Ethernet4",
"Ethernet5",
"Ethernet6",
"Ethernet7",
"Ethernet8",
"Ethernet9"
],
"vlan-tag": "un-tagged"
}
]
}
],
"metrics": {
"dhcp-snooping": {
"filters": [
"ack",
"discover",
"offer",
"request",
"solicit",
"reply",
"renew"
]
},
"health": {
"interval": 60
},
"statistics": {
"interval": 120,
"types": []
}
},
"unit": {
"leds-active": true,
"usage-threshold": 95
},
"uuid": 1678263900
}

View File

@@ -12,7 +12,7 @@ info:
url: https://www.ucentral.info/support
servers:
- url: 'https://localhost:16002/api/v1'
- url: 'https://localhost:16001/api/v1'
security:
- bearerAuth: []
@@ -42,10 +42,12 @@ components:
schemas:
DeviceType:
type: string
default: ap
default: AP
enum:
- ap
- switch
- AP
- SWITCH
- IOT
- MESH
DeviceRestrictionsKeyInfo:
type: object
@@ -155,9 +157,6 @@ components:
lastRecordedContact:
type: integer
format: int64
blackListed:
type: boolean
readOnly: true
DeviceWithStatus:
type: object
@@ -282,9 +281,6 @@ components:
format: float
connectReason:
type: string
blackListed:
type: boolean
readOnly: true
DeviceList:
type: object
@@ -549,12 +545,6 @@ components:
lastModified:
type: integer
format: int64
platform:
type: string
enum:
- ap
- switch
default: ap
DefaultConfigurationList:
properties:
@@ -1576,107 +1566,6 @@ components:
format: base64
description: This is a base64 encoded string of the certificate bundle (the current bundle .tar.gz file from the PKI portal)
ReenrollRequest:
type: object
properties:
serialNumber:
type: string
when:
type: integer
format: int64
PowerCycleRequest:
type: object
properties:
serial:
type: string
when:
type: integer
format: int64
ports:
type: array
items:
type: object
properties:
name:
type: string
example:
- Ethernet0
cycle:
type: integer
default: 10000
minimum: 1
maximum: 60000
description: off time in milliseconds
PackageGetResponse:
type: object
properties:
serial:
type: string
status:
type: object
properties:
package:
type: string
text:
type: string
uuid:
type: number
PackageInstallRequest:
type: object
properties:
serialNumber:
type: string
packages:
type: array
items:
type: object
properties:
name:
type: string
url:
type: string
PackageInstallResponse:
type: object
properties:
serial:
type: string
status:
type: object
properties:
error:
type: number
packages:
type: array
items:
type: object
properties:
name:
type: string
result:
type: string
text:
type: string
uuid:
type: number
PackageRemoveRequest:
type: object
properties:
serialNumber:
type: string
packages:
type: array
items:
type: object
properties:
name:
type: string
paths:
/devices:
get:
@@ -1768,22 +1657,6 @@ paths:
type: integer
default: 70
required: false
- in: query
description: return only devices matching a certain platform of AP or SWITCH
name: platform
schema:
type: string
default: ALL
enum:
- all
- ap
- switch
required: false
- in: query
description: only devices which are not provisioned
name: includeProvisioned
schema:
type: boolean
responses:
200:
description: List devices
@@ -3133,152 +3006,6 @@ paths:
404:
$ref: '#/components/responses/NotFound'
/device/{serialNumber}/reenroll:
post:
tags:
- Commands
summary: Reenroll operational certificate for the device.
operationId: reenrollCertificate
parameters:
- in: path
name: serialNumber
schema:
type: string
required: true
requestBody:
description: Reenroll operational certificate for the device
content:
application/json:
schema:
$ref: '#/components/schemas/ReenrollRequest'
responses:
200:
$ref: '#/components/responses/Success'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
/device/{serialNumber}/powercycle:
post:
tags:
- Commands
summary: Perform PoE power cycle for some PoE ports.
operationId: performPowerCycle
parameters:
- in: path
name: serialNumber
schema:
type: string
required: true
requestBody:
description: Certificate update details
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/PowerCycleRequest'
responses:
200:
$ref: '#/components/responses/Success'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
/device/{serialNumber}/package:
get:
tags:
- Commands
summary: Get package installed on the remote device.
operationId: getDevicePackages
parameters:
- in: path
name: serialNumber
schema:
type: string
required: true
- in: query
name: pkgName
schema:
type: string
required: true
description: The name or identifier of the package to retrieve.
responses:
200:
description: Successful command execution
content:
application/json:
schema:
$ref: '#/components/schemas/PackageGetResponse'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
post:
tags:
- Commands
summary: Install IPK files to remote device.
operationId: postDevicePackages
parameters:
- in: path
name: serialNumber
schema:
type: string
required: true
requestBody:
description: Packages to be installed
content:
application/json:
schema:
$ref: '#/components/schemas/PackageInstallRequest'
responses:
200:
description: Successful command execution
content:
application/json:
schema:
$ref: '#/components/schemas/PackageInstallResponse'
400:
$ref: '#/components/responses/BadRequest'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
delete:
tags:
- Commands
summary: Remove install packages from remote device.
operationId: deleteDevicePackages
parameters:
- in: path
name: serialNumber
schema:
type: string
required: true
requestBody:
description: Packages to be removed
content:
application/json:
schema:
$ref: '#/components/schemas/PackageRemoveRequest'
responses:
200:
content:
application/json:
schema:
$ref: '#/components/schemas/PackageInstallResponse'
400:
$ref: '#/components/responses/BadRequest'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
/ouis:
get:
tags:

View File

@@ -12,7 +12,7 @@ ucentral.websocket.host.0.clientcas = ${WEBSOCKET_HOST_CLIENTCAS}
ucentral.websocket.host.0.cas = ${WEBSOCKET_HOST_CAS}
ucentral.websocket.host.0.address = *
ucentral.websocket.host.0.port = ${WEBSOCKET_HOST_PORT}
ucentral.websocket.host.0.security = ${WEBSOCKET_HOST_SECURITY}
ucentral.websocket.host.0.security = strict
ucentral.websocket.host.0.key.password = ${WEBSOCKET_HOST_KEY_PASSWORD}
ucentral.websocket.maxreactors = 20
@@ -52,8 +52,7 @@ openwifi.fileuploader.host.0.cert = ${FILEUPLOADER_HOST_CERT}
openwifi.fileuploader.host.0.key = ${FILEUPLOADER_HOST_KEY}
openwifi.fileuploader.host.0.key.password = ${FILEUPLOADER_HOST_KEY_PASSWORD}
openwifi.fileuploader.path = ${FILEUPLOADER_PATH}
# maxsize in KB
openwifi.fileuploader.maxsize = ${FILEUPLOADER_MAXSIZE}
openwifi.fileuploader.maxsize = 10000
openwifi.fileuploader.uri = ${FILEUPLOADER_URI}
#
@@ -183,4 +182,4 @@ archiver.db.3.keep = 7
########################################################################
logging.type = console
logging.path = $OWGW_ROOT/logs
logging.level = ${LOGGING_LEVEL}
logging.level = information

View File

@@ -9,14 +9,14 @@
namespace OpenWifi {
int AP_WS_ConfigAutoUpgradeAgent::Start() {
int AP_WS_ConfigAutoUpgrader::Start() {
poco_notice(Logger(), "Starting...");
QueueManager_.start(*this);
return 0;
}
void AP_WS_ConfigAutoUpgradeAgent::Stop() {
void AP_WS_ConfigAutoUpgrader::Stop() {
poco_notice(Logger(), "Stopping...");
Running_ = false;
Queue_.wakeUpAll();
@@ -24,7 +24,7 @@ namespace OpenWifi {
poco_notice(Logger(), "Stopped...");
}
void AP_WS_ConfigAutoUpgradeAgent::run() {
void AP_WS_ConfigAutoUpgrader::run() {
Utils::SetThreadName("auto:cfgmgr");
Running_ = true;

View File

@@ -28,14 +28,14 @@ namespace OpenWifi {
std::uint64_t pending_config_=0;
};
class AP_WS_ConfigAutoUpgradeAgent : public SubSystemServer, Poco::Runnable {
class AP_WS_ConfigAutoUpgrader : public SubSystemServer, Poco::Runnable {
public:
int Start() final;
void Stop() final;
void run() final;
static auto instance() {
static auto instance = new AP_WS_ConfigAutoUpgradeAgent;
static auto instance = new AP_WS_ConfigAutoUpgrader;
return instance;
}
@@ -126,12 +126,12 @@ namespace OpenWifi {
mutable std::mutex CacheMutex_;
std::map<std::uint64_t, ConfigurationCacheEntry> Cache_;
AP_WS_ConfigAutoUpgradeAgent() noexcept
AP_WS_ConfigAutoUpgrader() noexcept
: SubSystemServer("AutoConfigUpgrade", "AUTO-CFG-MGR", "auto.config.updater") {
}
};
inline auto AP_WS_ConfigAutoUpgradeAgent() { return AP_WS_ConfigAutoUpgradeAgent::instance(); }
inline auto AP_WS_ConfigAutoUpgrader() { return AP_WS_ConfigAutoUpgrader::instance(); }
} // namespace OpenWifi

View File

@@ -2,33 +2,37 @@
// Created by stephane bourque on 2022-02-03.
//
#include "AP_WS_Connection.h"
#include <Poco/Base64Decoder.h>
#include <Poco/Net/Context.h>
#include <Poco/Net/HTTPServerRequestImpl.h>
#include <Poco/Net/HTTPServerResponseImpl.h>
#include <Poco/JSON/JSONException.h>
#include <Poco/Net/NetException.h>
#include <Poco/Net/SSLException.h>
#include <Poco/Net/SecureStreamSocketImpl.h>
#include <Poco/Net/WebSocketImpl.h>
#include "Poco/Base64Decoder.h"
#include "Poco/Net/Context.h"
#include "Poco/Net/HTTPServerRequestImpl.h"
#include "Poco/Net/HTTPServerResponseImpl.h"
#include "Poco/Net/NetException.h"
#include "Poco/Net/SSLException.h"
#include "Poco/Net/SecureStreamSocketImpl.h"
#include "Poco/Net/WebSocketImpl.h"
#include "Poco/zlib.h"
#include <framework/KafkaManager.h>
#include <framework/MicroServiceFuncs.h>
#include <framework/utils.h>
#include <framework/ow_constants.h>
#include "AP_WS_Server.h"
#include "CentralConfig.h"
#include "CommandManager.h"
#include "ConfigurationCache.h"
#include "StorageService.h"
#include "TelemetryStream.h"
#include <fmt/format.h>
#include "GWKafkaEvents.h"
#include "UI_GW_WebSocketNotifications.h"
#include "framework/KafkaManager.h"
#include "framework/MicroServiceFuncs.h"
#include "framework/utils.h"
#include <AP_WS_Connection.h>
#include <AP_WS_Server.h>
#include <CentralConfig.h>
#include <CommandManager.h>
#include <StorageService.h>
#include <RADIUSSessionTracker.h>
#include <RADIUS_proxy_server.h>
#include <GWKafkaEvents.h>
#include <UI_GW_WebSocketNotifications.h>
#include "fmt/format.h"
#include "framework/ow_constants.h"
#include "RADIUSSessionTracker.h"
#include "RADIUS_proxy_server.h"
namespace OpenWifi {
@@ -40,7 +44,7 @@ namespace OpenWifi {
Poco::Net::HTTPServerResponse &response,
uint64_t session_id, Poco::Logger &L,
std::pair<std::shared_ptr<Poco::Net::SocketReactor>, std::shared_ptr<LockedDbSession>> R)
: Logger_(L), IncomingFrame_(0) {
: Logger_(L) {
Reactor_ = R.first;
DbSession_ = R.second;
@@ -55,10 +59,7 @@ namespace OpenWifi {
WS_->setNoDelay(false);
WS_->setKeepAlive(true);
WS_->setBlocking(false);
IncomingFrame_.resize(0);
uuid_ = MicroServiceRandom(std::numeric_limits<std::uint64_t>::max()-1);
AP_WS_Server()->IncrementConnectionCount();
}
void AP_WS_Connection::Start() {
@@ -78,11 +79,14 @@ namespace OpenWifi {
}
AP_WS_Connection::~AP_WS_Connection() {
// poco_information(Logger_, fmt::format("DESTRUCTOR({}): 0 - Session={} Connection closed.", SerialNumber_,
// State_.sessionId));
std::lock_guard G(ConnectionMutex_);
AP_WS_Server()->DecrementConnectionCount();
EndConnection();
// poco_information(Logger_, fmt::format("DESTRUCTOR({}): 1 - Session={} Connection closed.", SerialNumber_,
// State_.sessionId));
EndConnection(false);
poco_debug(Logger_, fmt::format("TERMINATION({}): Session={}, Connection removed.", SerialNumber_,
State_.sessionId));
State_.sessionId));
}
static void NotifyKafkaDisconnect(const std::string &SerialNumber, std::uint64_t uuid) {
@@ -98,7 +102,7 @@ namespace OpenWifi {
}
}
void AP_WS_Connection::EndConnection() {
void AP_WS_Connection::EndConnection(bool Clean) {
bool expectedValue=false;
if (Dead_.compare_exchange_strong(expectedValue,true,std::memory_order_release,std::memory_order_relaxed)) {
@@ -124,7 +128,9 @@ namespace OpenWifi {
if(!SerialNumber_.empty()) {
DeviceDisconnectionCleanup(SerialNumber_, uuid_);
}
AP_WS_Server()->AddCleanupSession(State_.sessionId, SerialNumberInt_);
if(Clean)
AP_WS_Server()->EndSession(State_.sessionId, SerialNumberInt_);
}
}
@@ -215,7 +221,6 @@ namespace OpenWifi {
}
State_.certificateExpiryDate = PeerCert.expiresOn().timestamp().epochTime();
State_.certificateIssuerName = PeerCert.issuerName();
poco_trace(Logger_,
fmt::format("TLS-CONNECTION({}): Session={} CN={} Completed. (t={})", CId_,
@@ -564,14 +569,14 @@ namespace OpenWifi {
void AP_WS_Connection::OnSocketShutdown(
[[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf) {
poco_trace(Logger_, fmt::format("SOCKET-SHUTDOWN({}): Closing.", CId_));
// std::lock_guard G(ConnectionMutex_);
std::lock_guard G(ConnectionMutex_);
return EndConnection();
}
void AP_WS_Connection::OnSocketError(
[[maybe_unused]] const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf) {
poco_trace(Logger_, fmt::format("SOCKET-ERROR({}): Closing.", CId_));
// std::lock_guard G(ConnectionMutex_);
std::lock_guard G(ConnectionMutex_);
return EndConnection();
}
@@ -581,7 +586,7 @@ namespace OpenWifi {
if (Dead_) // we are dead, so we do not process anything.
return;
std::lock_guard G(ConnectionMutex_);
std::lock_guard DeviceLock(ConnectionMutex_);
State_.LastContact = LastContact_ = Utils::Now();
if (AP_WS_Server()->Running() && (DeviceValidated_ || ValidatedDevice())) {
@@ -602,95 +607,36 @@ namespace OpenWifi {
EndConnection();
}
void AP_WS_Connection::ProcessWSFinalPayload() {
auto IncomingSize = IncomingFrame_.size();
if (IncomingSize == 0) {
poco_debug(Logger_,
fmt::format("ProcessWSFrame({}): Final Acc. Frame received but empty",
CId_));
return;
}
IncomingFrame_.append(0);
poco_trace(Logger_,
fmt::format("ProcessWSFrame({}): Final Acc. Frame received (len={}, Msg={}",
CId_, IncomingSize, IncomingFrame_.begin()));
Poco::JSON::Parser parser;
auto ParsedMessage = parser.parse(IncomingFrame_.begin());
auto IncomingJSON = ParsedMessage.extract<Poco::JSON::Object::Ptr>();
if (IncomingJSON->has(uCentralProtocol::JSONRPC)) {
if (IncomingJSON->has(uCentralProtocol::METHOD) &&
IncomingJSON->has(uCentralProtocol::PARAMS)) {
ProcessJSONRPCEvent(IncomingJSON);
} else if (IncomingJSON->has(uCentralProtocol::RESULT) &&
IncomingJSON->has(uCentralProtocol::ID)) {
poco_trace(Logger_, fmt::format("RPC-RESULT({}): payload: {}", CId_,
IncomingFrame_.begin()));
ProcessJSONRPCResult(IncomingJSON);
} else {
poco_warning(
Logger_,
fmt::format("INVALID-PAYLOAD({}): Payload is not JSON-RPC 2.0: {}",
CId_, IncomingFrame_.begin()));
}
} else if (IncomingJSON->has(uCentralProtocol::RADIUS)) {
ProcessIncomingRadiusData(IncomingJSON);
} else {
std::ostringstream iS;
IncomingJSON->stringify(iS);
poco_warning(
Logger_,
fmt::format("FRAME({}): illegal transaction header, missing 'jsonrpc': {}",
CId_, iS.str()));
Errors_++;
}
IncomingFrame_.clear();
IncomingFrame_.resize(0);
}
void AP_WS_Connection::ProcessIncomingFrame() {
Poco::Buffer<char> CurrentFrame(0);
bool KillConnection = false;
int flags = 0;
int IncomingSize = 0;
Poco::Buffer<char> IncomingFrame(0);
bool KillConnection=false;
try {
IncomingSize = WS_->receiveFrame(CurrentFrame, flags);
int Op;
int Op, flags;
auto IncomingSize = WS_->receiveFrame(IncomingFrame, flags);
Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
if (IncomingSize < 0 && flags == 0) {
poco_trace(Logger_,
fmt::format("EMPTY({}): Non-blocking try-again empty frame (len={}, flags={})",
CId_, IncomingSize, flags));
} else if (IncomingSize == 0 && flags == 0) {
if (IncomingSize == 0 && flags == 0 && Op == 0) {
poco_information(Logger_,
fmt::format("DISCONNECT({}): device has disconnected. Session={}",
CId_, State_.sessionId));
return EndConnection();
}
if (IncomingSize > 0) {
State_.RX += IncomingSize;
AP_WS_Server()->AddRX(IncomingSize);
IncomingFrame_.append(CurrentFrame);
}
IncomingFrame.append(0);
State_.RX += IncomingSize;
AP_WS_Server()->AddRX(IncomingSize);
State_.MessageCount++;
State_.LastContact = Utils::Now();
poco_trace(Logger_,
fmt::format("FRAME({}): Frame rx (op={} len={}, flags={}, acc.len={})",
CId_, Op, IncomingSize, flags, IncomingFrame_.size()));
switch (Op) {
case Poco::Net::WebSocket::FRAME_OP_PING: {
poco_trace(Logger_, fmt::format("PING({}): received. PONG sent back.", CId_));
poco_trace(Logger_, fmt::format("WS-PING({}): received. PONG sent back.", CId_));
WS_->sendFrame("", 0,
(int)Poco::Net::WebSocket::FRAME_OP_PONG |
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
if (KafkaManager()->Enabled()) {
Poco::JSON::Object PingObject;
@@ -704,32 +650,49 @@ namespace OpenWifi {
PingDetails.set("locale", State_.locale);
PingObject.set(uCentralProtocol::PING, PingDetails);
poco_trace(Logger_,fmt::format("Sending PING for {}", SerialNumber_));
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber_,
PingObject);
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber_,PingObject);
}
return;
} break;
case Poco::Net::WebSocket::FRAME_OP_PONG: {
poco_trace(Logger_, fmt::format("PONG({}): received and ignored.", CId_));
return;
} break;
case Poco::Net::WebSocket::FRAME_OP_CONT: {
poco_trace(Logger_, fmt::format("CONTINUATION({}): registered.", CId_));
} break;
case Poco::Net::WebSocket::FRAME_OP_BINARY: {
poco_trace(Logger_, fmt::format("BINARY({}): Invalid frame type.", CId_));
KillConnection=true;
return;
} break;
case Poco::Net::WebSocket::FRAME_OP_TEXT: {
poco_trace(Logger_,
fmt::format("TEXT({}): Frame received (len={}, flags={}). Msg={}",
CId_, IncomingSize, flags,
CurrentFrame.begin() == nullptr ? "" : CurrentFrame.begin()));
fmt::format("FRAME({}): Frame received (length={}, flags={}). Msg={}",
CId_, IncomingSize, flags, IncomingFrame.begin()));
Poco::JSON::Parser parser;
auto ParsedMessage = parser.parse(IncomingFrame.begin());
auto IncomingJSON = ParsedMessage.extract<Poco::JSON::Object::Ptr>();
if (IncomingJSON->has(uCentralProtocol::JSONRPC)) {
if (IncomingJSON->has(uCentralProtocol::METHOD) &&
IncomingJSON->has(uCentralProtocol::PARAMS)) {
ProcessJSONRPCEvent(IncomingJSON);
} else if (IncomingJSON->has(uCentralProtocol::RESULT) &&
IncomingJSON->has(uCentralProtocol::ID)) {
poco_trace(Logger_, fmt::format("RPC-RESULT({}): payload: {}", CId_,
IncomingFrame.begin()));
ProcessJSONRPCResult(IncomingJSON);
} else {
poco_warning(
Logger_,
fmt::format("INVALID-PAYLOAD({}): Payload is not JSON-RPC 2.0: {}",
CId_, IncomingFrame.begin()));
}
} else if (IncomingJSON->has(uCentralProtocol::RADIUS)) {
ProcessIncomingRadiusData(IncomingJSON);
} else {
std::ostringstream iS;
IncomingJSON->stringify(iS);
poco_warning(
Logger_,
fmt::format("FRAME({}): illegal transaction header, missing 'jsonrpc': {}",
CId_, iS.str()));
Errors_++;
}
} break;
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
@@ -745,31 +708,25 @@ namespace OpenWifi {
return;
}
}
// Check for final frame and process accumulated payload
if (!KillConnection && (flags & Poco::Net::WebSocket::FRAME_FLAG_FIN) != 0) {
ProcessWSFinalPayload();
}
} catch (const Poco::Net::ConnectionResetException &E) {
poco_warning(Logger_,
fmt::format("ConnectionResetException({}): Text:{} Payload:{} Session:{}",
CId_, E.displayText(),
CurrentFrame.begin() == nullptr ? "" : CurrentFrame.begin(),
IncomingFrame.begin() == nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
KillConnection=true;
} catch (const Poco::JSON::JSONException &E) {
poco_warning(Logger_,
fmt::format("JSONException({}): Text:{} Payload:{} Session:{}", CId_,
E.displayText(),
CurrentFrame.begin() == nullptr ? "" : CurrentFrame.begin(),
IncomingFrame.begin() == nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
KillConnection=true;
} catch (const Poco::Net::WebSocketException &E) {
poco_warning(Logger_,
fmt::format("WebSocketException({}): Text:{} Payload:{} Session:{}", CId_,
E.displayText(),
CurrentFrame.begin() == nullptr ? "" : CurrentFrame.begin(),
IncomingFrame.begin() == nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
KillConnection=true;
} catch (const Poco::Net::SSLConnectionUnexpectedlyClosedException &E) {
@@ -778,42 +735,42 @@ namespace OpenWifi {
fmt::format(
"SSLConnectionUnexpectedlyClosedException({}): Text:{} Payload:{} Session:{}",
CId_, E.displayText(),
CurrentFrame.begin() == nullptr ? "" : CurrentFrame.begin(),
IncomingFrame.begin() == nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
KillConnection=true;
} catch (const Poco::Net::SSLException &E) {
poco_warning(Logger_,
fmt::format("SSLException({}): Text:{} Payload:{} Session:{}", CId_,
E.displayText(),
CurrentFrame.begin() == nullptr ? "" : CurrentFrame.begin(),
IncomingFrame.begin() == nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
KillConnection=true;
} catch (const Poco::Net::NetException &E) {
poco_warning(Logger_,
fmt::format("NetException({}): Text:{} Payload:{} Session:{}", CId_,
E.displayText(),
CurrentFrame.begin() == nullptr ? "" : CurrentFrame.begin(),
IncomingFrame.begin() == nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
KillConnection=true;
} catch (const Poco::IOException &E) {
poco_warning(Logger_,
fmt::format("IOException({}): Text:{} Payload:{} Session:{}", CId_,
E.displayText(),
CurrentFrame.begin() == nullptr ? "" : CurrentFrame.begin(),
IncomingFrame.begin() == nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
KillConnection=true;
} catch (const Poco::Exception &E) {
poco_warning(Logger_,
fmt::format("Exception({}): Text:{} Payload:{} Session:{}", CId_,
E.displayText(),
CurrentFrame.begin() == nullptr ? "" : CurrentFrame.begin(),
IncomingFrame.begin() == nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
KillConnection=true;
} catch (const std::exception &E) {
poco_warning(Logger_,
fmt::format("std::exception({}): Text:{} Payload:{} Session:{}", CId_,
E.what(),
CurrentFrame.begin() == nullptr ? "" : CurrentFrame.begin(),
IncomingFrame.begin() == nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
KillConnection=true;
} catch (...) {
@@ -826,9 +783,7 @@ namespace OpenWifi {
if (!KillConnection && Errors_ < 10)
return;
poco_warning(Logger_,
fmt::format("DISCONNECTING({}): ConnectionException: {} Errors: {}",
CId_, KillConnection, Errors_ ));
poco_warning(Logger_, fmt::format("DISCONNECTING({}): ConnectionException: {} Errors: {}", CId_, KillConnection, Errors_ ));
EndConnection();
}
@@ -947,25 +902,25 @@ namespace OpenWifi {
try {
Poco::JSON::Parser P;
auto Stats = P.parse(LastStats).extract<Poco::JSON::Object::Ptr>();
State_.hasGPS = Stats->isObject("gps");
hasGPS_ = Stats->isObject("gps");
auto Unit = Stats->getObject("unit");
auto Memory = Unit->getObject("memory");
std::uint64_t TotalMemory = Memory->get("total");
std::uint64_t FreeMemory = Memory->get("free");
if (TotalMemory > 0) {
State_.memoryUsed =
memory_used_ =
(100.0 * ((double)TotalMemory - (double)FreeMemory)) / (double)TotalMemory;
}
if (Unit->isArray("load")) {
Poco::JSON::Array::Ptr Load = Unit->getArray("load");
if (Load->size() > 1) {
State_.load = Load->get(1);
cpu_load_ = Load->get(1);
}
}
if (Unit->isArray("temperature")) {
Poco::JSON::Array::Ptr Temperature = Unit->getArray("temperature");
if (Temperature->size() > 1) {
State_.temperature = Temperature->get(0);
temperature_ = Temperature->get(0);
}
}
} catch (const Poco::Exception &E) {
@@ -973,4 +928,4 @@ namespace OpenWifi {
}
}
} // namespace OpenWifi
} // namespace OpenWifi

View File

@@ -22,7 +22,7 @@
namespace OpenWifi {
class AP_WS_Connection {
static constexpr int BufSize = 512000;
static constexpr int BufSize = 256000;
public:
explicit AP_WS_Connection(Poco::Net::HTTPServerRequest &request,
@@ -30,10 +30,9 @@ namespace OpenWifi {
Poco::Logger &L, std::pair<std::shared_ptr<Poco::Net::SocketReactor>, std::shared_ptr<LockedDbSession>> R);
~AP_WS_Connection();
void EndConnection();
void EndConnection(bool Clean = true);
void ProcessJSONRPCEvent(Poco::JSON::Object::Ptr &Doc);
void ProcessJSONRPCResult(Poco::JSON::Object::Ptr Doc);
void ProcessWSFinalPayload();
void ProcessIncomingFrame();
void ProcessIncomingRadiusData(const Poco::JSON::Object::Ptr &Doc);
@@ -80,14 +79,14 @@ namespace OpenWifi {
}
}
inline GWObjects::DeviceRestrictions GetRestrictions() {
std::lock_guard G(ConnectionMutex_);
return Restrictions_;
}
[[nodiscard]] inline bool HasGPS() const { return hasGPS_; }
[[nodiscard]] bool ValidatedDevice();
inline void GetRestrictions(GWObjects::DeviceRestrictions &R) {
std::lock_guard G(ConnectionMutex_);
R = Restrictions_;
}
inline bool GetTelemetryParameters(bool &Reporting, uint64_t &Interval,
uint64_t &WebSocketTimer, uint64_t &KafkaTimer,
uint64_t &WebSocketCount, uint64_t &KafkaCount,
@@ -106,10 +105,14 @@ namespace OpenWifi {
friend class AP_WS_Server;
inline GWObjects::DeviceRestrictions Restrictions() {
std::lock_guard G(ConnectionMutex_);
return Restrictions_;
}
void Start();
private:
mutable std::recursive_mutex ConnectionMutex_;
std::recursive_mutex ConnectionMutex_;
std::mutex TelemetryMutex_;
Poco::Logger &Logger_;
std::shared_ptr<Poco::Net::SocketReactor> Reactor_;
@@ -145,8 +148,7 @@ namespace OpenWifi {
std::double_t memory_used_=0.0, cpu_load_ = 0.0, temperature_ = 0.0;
std::uint64_t uuid_=0;
bool Simulated_=false;
std::atomic_uint64_t LastContact_=0;
Poco::Buffer<char> IncomingFrame_;
std::uint64_t LastContact_=0;
static inline std::atomic_uint64_t ConcurrentStartingDevices_ = 0;
@@ -177,4 +179,4 @@ namespace OpenWifi {
};
} // namespace OpenWifi
} // namespace OpenWifi

View File

@@ -11,101 +11,78 @@ namespace OpenWifi {
if (UUID == 0)
return false;
uint64_t GoodConfig = GetCurrentConfigurationID(SerialNumberInt_);
uint64_t GoodConfig = ConfigurationCache().CurrentConfig(SerialNumberInt_);
if (GoodConfig && (GoodConfig == UUID || GoodConfig == State_.PendingUUID)) {
UpgradedUUID = UUID;
State_.PendingUUID = 0;
return false;
}
GWObjects::Device D;
if (!StorageService()->GetDevice(Session,SerialNumber_, D)) {
return false;
}
if (StorageService()->GetDevice(Session,SerialNumber_, D)) {
if(D.pendingUUID!=0 && UUID==D.pendingUUID) {
// so we sent an upgrade to a device, and now it is completing now...
UpgradedUUID = D.pendingUUID;
StorageService()->CompleteDeviceConfigurationChange(Session, SerialNumber_);
return true;
}
// This is the case where the cache is empty after a restart. So GoodConfig will 0. If
// the device already has the right UUID, we just return.
if (D.UUID == UUID) {
UpgradedUUID = UUID;
ConfigurationCache().Add(SerialNumberInt_, UUID);
return false;
}
Config::Config Cfg(D.Configuration);
if (UUID > D.UUID) {
// so we have a problem, the device has a newer config than we have. So we need to
// make sure our config is newer.
D.UUID = UUID + 2;
UpgradedUUID = D.UUID;
}
Cfg.SetUUID(D.UUID);
D.Configuration = Cfg.get();
State_.PendingUUID = UpgradedUUID = D.UUID;
GWObjects::CommandDetails Cmd;
Cmd.SerialNumber = SerialNumber_;
Cmd.UUID = MicroServiceCreateUUID();
Cmd.SubmittedBy = uCentralProtocol::SUBMITTED_BY_SYSTEM;
Cmd.Status = uCentralProtocol::PENDING;
Cmd.Command = uCentralProtocol::CONFIGURE;
Poco::JSON::Parser P;
auto ParsedConfig = P.parse(D.Configuration).extract<Poco::JSON::Object::Ptr>();
Poco::JSON::Object Params;
Params.set(uCentralProtocol::SERIAL, SerialNumber_);
Params.set(uCentralProtocol::UUID, D.UUID);
Params.set(uCentralProtocol::WHEN, 0);
Params.set(uCentralProtocol::CONFIG, ParsedConfig);
std::ostringstream O;
Poco::JSON::Stringifier::stringify(Params, O);
Cmd.Details = O.str();
poco_information(Logger_,
fmt::format("CFG-UPGRADE({}): Current ID: {}, newer configuration {}.",
CId_, UUID, D.UUID));
bool Sent;
StorageService()->AddCommand(SerialNumber_, Cmd,
Storage::CommandExecutionType::COMMAND_EXECUTED);
CommandManager()->PostCommand(
CommandManager()->Next_RPC_ID(), APCommands::to_apcommand(Cmd.Command.c_str()),
SerialNumber_, Cmd.Command, Params, Cmd.UUID, Sent, false, false);
GWWebSocketNotifications::SingleDeviceConfigurationChange_t Notification;
Notification.content.serialNumber = D.SerialNumber;
Notification.content.oldUUID = UUID;
Notification.content.newUUID = UpgradedUUID;
GWWebSocketNotifications::DeviceConfigurationChange(Notification);
if(State_.PendingUUID!=0 && UUID==State_.PendingUUID) {
// so we sent an upgrade to a device, and now it is completing now...
UpgradedUUID = UUID;
StorageService()->CompleteDeviceConfigurationChange(Session, SerialNumber_);
State_.PendingUUID = 0;
return true;
}
// dont upgrade a switch if it does not have a real config. Config will always be more than 20 characters
if (D.DeviceType==Platforms::SWITCH && D.Configuration.size()<20) {
return false;
}
Config::Config Cfg(D.Configuration);
// if this is a broken device (UUID==0) just fix it
auto StoredConfigurationUUID = Cfg.UUID();
if(D.UUID==0) {
D.UUID = StoredConfigurationUUID;
}
if (D.UUID == UUID) {
D.UUID = UpgradedUUID = UUID;
State_.PendingUUID = D.pendingUUID = 0;
D.pendingConfiguration.clear();
D.pendingConfigurationCmd.clear();
StorageService()->UpdateDevice(Session, D);
SetCurrentConfigurationID(SerialNumberInt_, UUID);
// std::cout << __LINE__ << ": " << SerialNumber_ << " GoodConfig: " << GoodConfig << " UUID:" << UUID << " Pending:" << State_.PendingUUID << std::endl;
return false;
}
if (UUID > D.UUID) {
// so we have a problem, the device has a newer config than we have. So we need to
// make sure our config is newer.
D.UUID = UUID + 2;
UpgradedUUID = D.UUID;
// std::cout << __LINE__ << ": " << SerialNumber_ << " GoodConfig: " << GoodConfig << " UUID:" << UUID << " Pending:" << State_.PendingUUID << std::endl;
}
Cfg.SetUUID(D.UUID);
D.Configuration = Cfg.get();
D.pendingUUID = State_.PendingUUID = UpgradedUUID = D.UUID;
StorageService()->UpdateDevice(Session, D);
GWObjects::CommandDetails Cmd;
Cmd.SerialNumber = SerialNumber_;
Cmd.UUID = MicroServiceCreateUUID();
Cmd.SubmittedBy = uCentralProtocol::SUBMITTED_BY_SYSTEM;
Cmd.Status = uCentralProtocol::PENDING;
Cmd.Command = uCentralProtocol::CONFIGURE;
Poco::JSON::Parser P;
auto ParsedConfig = P.parse(D.Configuration).extract<Poco::JSON::Object::Ptr>();
Poco::JSON::Object Params;
Params.set(uCentralProtocol::SERIAL, SerialNumber_);
Params.set(uCentralProtocol::UUID, D.UUID);
Params.set(uCentralProtocol::WHEN, 0);
Params.set(uCentralProtocol::CONFIG, ParsedConfig);
std::ostringstream O;
Poco::JSON::Stringifier::stringify(Params, O);
Cmd.Details = O.str();
poco_information(Logger_,
fmt::format("CFG-UPGRADE({}): Current ID: {}, newer configuration {}.",
CId_, UUID, D.UUID));
bool Sent;
StorageService()->AddCommand(SerialNumber_, Cmd,
Storage::CommandExecutionType::COMMAND_EXECUTED);
CommandManager()->PostCommand(
CommandManager()->Next_RPC_ID(), APCommands::to_apcommand(Cmd.Command.c_str()),
SerialNumber_, Cmd.Command, Params, Cmd.UUID, Sent, false, false);
GWWebSocketNotifications::SingleDeviceConfigurationChange_t Notification;
Notification.content.serialNumber = D.SerialNumber;
Notification.content.oldUUID = UUID;
Notification.content.newUUID = UpgradedUUID;
GWWebSocketNotifications::DeviceConfigurationChange(Notification);
// std::cout << __LINE__ << ": " << SerialNumber_ << " GoodConfig: " << GoodConfig << " UUID:" << UUID <<
// " Pending:" << State_.PendingUUID << " Upgraded:" << UpgradedUUID << std::endl;
return true;
return false;
}
}

View File

@@ -83,8 +83,6 @@ namespace OpenWifi {
State_.Address = Utils::FormatIPv6(WS_->peerAddress().toString());
CId_ = SerialNumber_ + "@" + CId_;
auto Platform = Poco::toLower(Caps.Platform());
if(ParamsObj->has("reason")) {
State_.connectReason = ParamsObj->get("reason").toString();
}
@@ -105,7 +103,7 @@ namespace OpenWifi {
Restrictions_.developer = Capabilities->getValue<bool>("developer");
}
if (Capabilities->has("secure-rtty")) {
if(Capabilities->has("secure-rtty")) {
RTTYMustBeSecure_ = Capabilities->getValue<bool>("secure-rtty");
}
@@ -206,13 +204,8 @@ namespace OpenWifi {
++Updated;
}
if (Compatible_ != DeviceInfo.Compatible) {
DeviceInfo.Compatible = Compatible_;
++Updated;
}
if (Platform != DeviceInfo.DeviceType) {
DeviceInfo.DeviceType = Platform;
if (Compatible_ != DeviceInfo.DeviceType) {
DeviceInfo.DeviceType = Compatible_;
++Updated;
}
@@ -234,11 +227,10 @@ namespace OpenWifi {
if (Updated) {
StorageService()->UpdateDevice(DbSession_->Session(), DeviceInfo);
}
}
if(!Simulated_) {
uint64_t UpgradedUUID = 0;
if (LookForUpgrade(DbSession_->Session(), UUID, UpgradedUUID)) {
if(!Simulated_) {
uint64_t UpgradedUUID = 0;
LookForUpgrade(DbSession_->Session(), UUID, UpgradedUUID);
State_.UUID = UpgradedUUID;
}
}

View File

@@ -26,7 +26,6 @@ namespace OpenWifi {
uint64_t UUID = ParamsObj->get(uCentralProtocol::UUID);
auto Sanity = ParamsObj->get(uCentralProtocol::SANITY);
State_.sanity = Sanity;
auto CheckData = ParamsObj->get(uCentralProtocol::DATA).toString();
if (CheckData.empty())
CheckData = uCentralProtocol::EMPTY_JSON_DOC;

View File

@@ -7,12 +7,10 @@
#include <mutex>
#include <string>
#include <framework/utils.h>
#include <Poco/Environment.h>
#include <Poco/Net/SocketAcceptor.h>
#include "Poco/Environment.h"
#include "Poco/Net/SocketAcceptor.h"
#include <Poco/Data/SessionPool.h>
#include "framework/utils.h"
#include <StorageService.h>
namespace OpenWifi {
@@ -57,7 +55,7 @@ namespace OpenWifi {
DbSessions_.clear();
}
auto NextReactor() {
std::pair<std::shared_ptr<Poco::Net::SocketReactor>, std::shared_ptr<LockedDbSession> > NextReactor() {
std::lock_guard Lock(Mutex_);
NextReactor_++;
NextReactor_ %= NumberOfThreads_;

View File

@@ -6,23 +6,21 @@
// Arilia Wireless Inc.
//
#include <Poco/Net/Context.h>
#include <Poco/Net/HTTPHeaderStream.h>
#include <Poco/Net/HTTPServerRequest.h>
#include "Poco/Net/Context.h"
#include "Poco/Net/HTTPHeaderStream.h"
#include "Poco/Net/HTTPServerRequest.h"
#include <AP_WS_Connection.h>
#include <AP_WS_Server.h>
#include <ConfigurationCache.h>
#include <TelemetryStream.h>
#include "AP_WS_Connection.h"
#include "AP_WS_Server.h"
#include "ConfigurationCache.h"
#include "TelemetryStream.h"
#include <fmt/format.h>
#include <framework/MicroServiceFuncs.h>
#include <framework/utils.h>
#include "UI_GW_WebSocketNotifications.h"
#include "fmt/format.h"
#include "framework/MicroServiceFuncs.h"
#include "framework/utils.h"
#include <framework/KafkaManager.h>
#include <UI_GW_WebSocketNotifications.h>
namespace OpenWifi {
class AP_WS_RequestHandler : public Poco::Net::HTTPRequestHandler {
@@ -71,18 +69,14 @@ namespace OpenWifi {
bool AP_WS_Server::ValidateCertificate(const std::string &ConnectionId,
const Poco::Crypto::X509Certificate &Certificate) {
if (IsCertOk()) {
// validate certificate agains trusted chain
for (const auto &cert : ClientCasCerts_) {
if (Certificate.issuedBy(cert)) {
return true;
}
}
poco_warning(
if (!Certificate.issuedBy(*IssuerCert_)) {
poco_warning(
Logger(),
fmt::format(
"CERTIFICATE({}): issuer mismatch. Certificate not issued by any trusted CA",
ConnectionId)
);
fmt::format("CERTIFICATE({}): issuer mismatch. Local='{}' Incoming='{}'",
ConnectionId, IssuerCert_->issuerName(), Certificate.issuerName()));
return false;
}
return true;
}
return false;
}
@@ -120,6 +114,7 @@ namespace OpenWifi {
P.verificationDepth = 9;
P.loadDefaultCAs = Svr.RootCA().empty();
P.cipherList = "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH";
P.dhUse2048Bits = true;
P.caLocation = Svr.Cas();
auto Context = Poco::AutoPtr<Poco::Net::Context>(
@@ -136,13 +131,6 @@ namespace OpenWifi {
Context->addChainCertificate(Issuing);
Context->addCertificateAuthority(Issuing);
// add certificates from clientcas to trust chain
ClientCasCerts_ = Poco::Net::X509Certificate::readPEM(Svr.ClientCas());
for (const auto &cert : ClientCasCerts_) {
Context->addChainCertificate(cert);
Context->addCertificateAuthority(cert);
}
Poco::Crypto::RSAKey Key("", Svr.KeyFile(), Svr.KeyFilePassword());
Context->usePrivateKey(Key);
@@ -210,53 +198,9 @@ namespace OpenWifi {
Running_ = true;
GarbageCollector_.setName("ws:garbage");
GarbageCollector_.start(*this);
std::thread CleanupThread([this](){ CleanupSessions(); });
CleanupThread.detach();
return 0;
}
bool AP_WS_Server::Disconnect(uint64_t SerialNumber) {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == SerialNumbers_[hashIndex].end() || DeviceHint->second == nullptr) {
return false;
}
Connection = DeviceHint->second;
SerialNumbers_[hashIndex].erase(DeviceHint);
}
{
auto H = SessionHash::Hash(Connection->State_.sessionId);
std::lock_guard SessionLock(SessionMutex_[H]);
Sessions_[H].erase(Connection->State_.sessionId);
}
return true;
}
void AP_WS_Server::CleanupSessions() {
while(Running_) {
std::this_thread::sleep_for(std::chrono::seconds(10));
while(Running_ && !CleanupSessions_.empty()) {
std::pair<uint64_t, uint64_t> Session;
{
std::lock_guard G(CleanupMutex_);
Session = CleanupSessions_.front();
CleanupSessions_.pop_front();
}
poco_trace(this->Logger(),fmt::format("Cleaning up session: {} for device: {}", Session.first, Utils::IntToSerialNumber(Session.second)));
EndSession(Session.first, Session.second);
}
}
}
void AP_WS_Server::run() {
uint64_t last_log = Utils::Now(),
last_zombie_run = 0,
@@ -279,6 +223,7 @@ namespace OpenWifi {
try {
poco_information(LocalLogger,
fmt::format("Garbage collecting zombies... (step 1)"));
NumberOfConnectedDevices_ = 0;
NumberOfConnectingDevices_ = 0;
AverageDeviceConnectionTime_ = 0;
int waits = 0;
@@ -290,49 +235,55 @@ namespace OpenWifi {
waits = 0;
auto hint = SerialNumbers_[hashIndex].begin();
while (hint != end(SerialNumbers_[hashIndex])) {
if (hint->second == nullptr) {
poco_information(
LocalLogger,
fmt::format("Dead device found in hash index {}", hashIndex));
hint = SerialNumbers_[hashIndex].erase(hint);
} else {
auto Device = hint->second;
// hint = SerialNumbers_[hashIndex].erase(hint);
hint++;
continue;
}
auto Device = hint->second;
if(Device->ConnectionMutex_.try_lock()) {
auto RightNow = Utils::Now();
if (Device->Dead_) {
AddCleanupSession(Device->State_.sessionId, Device->SerialNumberInt_);
++hint;
// hint = SerialNumbers_[hashIndex].erase(hint);
} else if (RightNow > Device->LastContact_ &&
(RightNow - Device->LastContact_) > SessionTimeOut_) {
if (RightNow > Device->LastContact_ &&
(RightNow - Device->LastContact_) > SessionTimeOut_) {
poco_information(
LocalLogger,
fmt::format(
"{}: Session seems idle. Controller disconnecting device.",
Device->SerialNumber_));
// hint = SerialNumbers_[hashIndex].erase(hint);
AddCleanupSession(Device->State_.sessionId, Device->SerialNumberInt_);
fmt::format("{}: Session seems idle. Controller disconnecting device.",
Device->SerialNumber_));
hint = SerialNumbers_[hashIndex].erase(hint);
} else if (Device->State_.Connected) {
NumberOfConnectedDevices_++;
total_connected_time +=
(RightNow - Device->State_.started);
++hint;
} else {
if (Device->State_.Connected) {
total_connected_time +=
(RightNow - Device->State_.started);
}
++hint;
}
Device->ConnectionMutex_.unlock();
continue;
} else {
poco_warning(LocalLogger, fmt::format("Could not lock device mutex for {}",
Device->SerialNumber_));
}
++NumberOfConnectingDevices_;
++hint;
}
SerialNumbersMutex_[hashIndex].unlock();
break;
} else if (waits < 5) {
waits++;
Poco::Thread::trySleep(10);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
} else {
break;
}
}
}
poco_information(LocalLogger, fmt::format("Garbage collecting zombies... (step 2)"));
poco_information(LocalLogger,
fmt::format("Garbage collecting zombies... (step 2)"));
LeftOverSessions_ = 0;
for (int i = 0; i < SessionHash::HashMax(); i++) {
waits = 0;
@@ -344,10 +295,6 @@ namespace OpenWifi {
while (hint != end(Sessions_[i])) {
if (hint->second == nullptr) {
hint = Sessions_[i].erase(hint);
} else if (hint->second->Dead_) {
// hint = Sessions_[i].erase(hint);
AddCleanupSession(hint->second->State_.sessionId, hint->second->SerialNumberInt_);
++hint;
} else if (RightNow > hint->second->LastContact_ &&
(RightNow - hint->second->LastContact_) >
SessionTimeOut_) {
@@ -355,9 +302,7 @@ namespace OpenWifi {
LocalLogger,
fmt::format("{}: Session seems idle. Controller disconnecting device.",
hint->second->SerialNumber_));
AddCleanupSession(hint->second->State_.sessionId, hint->second->SerialNumberInt_);
++hint;
// hint = Sessions_[i].erase(hint);
hint = Sessions_[i].erase(hint);
} else {
++LeftOverSessions_;
++hint;
@@ -366,7 +311,7 @@ namespace OpenWifi {
SessionMutex_[i].unlock();
break;
} else if (waits < 5) {
Poco::Thread::trySleep(10);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
waits++;
} else {
break;
@@ -374,9 +319,10 @@ namespace OpenWifi {
}
}
AverageDeviceConnectionTime_ = NumberOfConnectedDevices_ > 0
? total_connected_time / NumberOfConnectedDevices_
: 0;
AverageDeviceConnectionTime_ =
NumberOfConnectedDevices_ > 0
? total_connected_time / NumberOfConnectedDevices_
: 0;
poco_information(LocalLogger, fmt::format("Garbage collecting zombies done..."));
} catch (const Poco::Exception &E) {
poco_error(LocalLogger, fmt::format("Poco::Exception: Garbage collecting zombies failed: {}", E.displayText()));
@@ -386,49 +332,47 @@ namespace OpenWifi {
poco_error(LocalLogger, fmt::format("exception:Garbage collecting zombies failed: {}", "unknown"));
}
}
if(NumberOfConnectedDevices_) {
if (last_garbage_run > 0) {
AverageDeviceConnectionTime_ += (now - last_garbage_run);
} else {
NumberOfConnectedDevices_=0;
for(int i=0;i<MACHash::HashMax();i++) {
std::lock_guard Lock(SerialNumbersMutex_[i]);
NumberOfConnectedDevices_ += SerialNumbers_[i].size();
}
if(NumberOfConnectedDevices_) {
if (last_garbage_run > 0) {
AverageDeviceConnectionTime_ += (now - last_garbage_run);
}
} else {
AverageDeviceConnectionTime_ = 0;
}
}
try {
if ((now - last_log) > 60) {
last_log = now;
poco_information(
LocalLogger,
fmt::format("Active AP connections: {} Connecting: {} Average connection time: {} seconds. Left Over Sessions: {}",
NumberOfConnectedDevices_, NumberOfConnectingDevices_,
AverageDeviceConnectionTime_, LeftOverSessions_));
}
GWWebSocketNotifications::NumberOfConnection_t Notification;
Notification.content.numberOfConnectingDevices = NumberOfConnectingDevices_;
Notification.content.numberOfDevices = NumberOfConnectedDevices_;
Notification.content.averageConnectedTime = AverageDeviceConnectionTime_;
GetTotalDataStatistics(Notification.content.tx, Notification.content.rx);
GWWebSocketNotifications::NumberOfConnections(Notification);
Poco::JSON::Object KafkaNotification;
Notification.to_json(KafkaNotification);
Poco::JSON::Object FullEvent;
FullEvent.set("type", "load-update");
FullEvent.set("timestamp", now);
FullEvent.set("payload", KafkaNotification);
KafkaManager()->PostMessage(KafkaTopics::DEVICE_EVENT_QUEUE, "system", FullEvent);
LocalLogger.information(fmt::format("Garbage collection finished run."));
last_garbage_run = now;
} catch (const Poco::Exception &E) {
LocalLogger.error(fmt::format("Poco::Exception: Garbage collecting failed: {}", E.displayText()));
} catch (const std::exception &E) {
LocalLogger.error(fmt::format("std::exception: Garbage collecting failed: {}", E.what()));
} catch (...) {
LocalLogger.error(fmt::format("exception:Garbage collecting failed: {}", "unknown"));
if ((now - last_log) > 60) {
last_log = now;
poco_information(LocalLogger,
fmt::format("Active AP connections: {} Connecting: {} Average connection time: {} seconds. Left Over Sessions: {}",
NumberOfConnectedDevices_, NumberOfConnectingDevices_,
AverageDeviceConnectionTime_, LeftOverSessions_));
}
GWWebSocketNotifications::NumberOfConnection_t Notification;
Notification.content.numberOfConnectingDevices = NumberOfConnectingDevices_;
Notification.content.numberOfDevices = NumberOfConnectedDevices_;
Notification.content.averageConnectedTime = AverageDeviceConnectionTime_;
GetTotalDataStatistics(Notification.content.tx,Notification.content.rx);
GWWebSocketNotifications::NumberOfConnections(Notification);
Poco::JSON::Object KafkaNotification;
Notification.to_json(KafkaNotification);
Poco::JSON::Object FullEvent;
FullEvent.set("type", "load-update");
FullEvent.set("timestamp", now);
FullEvent.set("payload", KafkaNotification);
KafkaManager()->PostMessage(KafkaTopics::DEVICE_EVENT_QUEUE, "system", FullEvent);
LocalLogger.information(fmt::format("Garbage collection finished run." ));
last_garbage_run = now;
}
LocalLogger.information(fmt::format("Garbage collector done for the day." ));
}
@@ -465,17 +409,15 @@ namespace OpenWifi {
}
bool AP_WS_Server::GetStatistics(uint64_t SerialNumber, std::string &Statistics) const {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == SerialNumbers_[hashIndex].end() || DeviceHint->second == nullptr) {
return false;
}
Connection = DeviceHint->second;
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard Lock(SerialNumbersMutex_[hashIndex]);
auto Device = SerialNumbers_[hashIndex].find(SerialNumber);
if (Device == SerialNumbers_[hashIndex].end() || Device->second == nullptr) {
return false;
}
Connection->GetLastStats(Statistics);
Device->second->GetLastStats(Statistics);
return true;
}
@@ -497,63 +439,49 @@ namespace OpenWifi {
bool AP_WS_Server::GetHealthcheck(uint64_t SerialNumber,
GWObjects::HealthCheck &CheckData) const {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto Device = SerialNumbers_[hashIndex].find(SerialNumber);
if (Device == SerialNumbers_[hashIndex].end() || Device->second == nullptr) {
return false;
}
Connection = Device->second;
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard Lock(SerialNumbersMutex_[hashIndex]);
auto Device = SerialNumbers_[hashIndex].find(SerialNumber);
if (Device == SerialNumbers_[hashIndex].end() || Device->second == nullptr) {
return false;
}
Connection->GetLastHealthCheck(CheckData);
Device->second->GetLastHealthCheck(CheckData);
return true;
}
void AP_WS_Server::StartSession(uint64_t session_id, uint64_t SerialNumber) {
auto sessionHash = SessionHash::Hash(session_id);
std::shared_ptr<AP_WS_Connection> Connection;
{
std::lock_guard SessionLock(SessionMutex_[sessionHash]);
auto SessionHint = Sessions_[sessionHash].find(session_id);
if (SessionHint == end(Sessions_[sessionHash])) {
return;
}
Connection = SessionHint->second;
Sessions_[sessionHash].erase(SessionHint);
}
auto deviceHash = MACHash::Hash(SerialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[deviceHash]);
SerialNumbers_[deviceHash][SerialNumber] = Connection;
auto sessionHash = SessionHash::Hash(session_id);
std::lock_guard SessionLock(SessionMutex_[sessionHash]);
auto SessionHint = Sessions_[sessionHash].find(session_id);
if (SessionHint != end(Sessions_[sessionHash])) {
std::lock_guard Lock(SerialNumbersMutex_[deviceHash]);
SerialNumbers_[deviceHash][SerialNumber] = SessionHint->second;
Sessions_[sessionHash].erase(SessionHint);
} else {
poco_error(Logger(), fmt::format("StartSession: Could not find session '{}'", session_id));
}
}
bool AP_WS_Server::EndSession(uint64_t session_id, uint64_t SerialNumber) {
{
poco_trace(Logger(), fmt::format("Ending session 1: {} for device: {}", session_id, Utils::IntToSerialNumber(SerialNumber)));
auto sessionHash = SessionHash::Hash(session_id);
std::lock_guard SessionLock(SessionMutex_[sessionHash]);
Sessions_[sessionHash].erase(session_id);
poco_trace(Logger(), fmt::format("Ended session 1: {} for device: {}", session_id, Utils::IntToSerialNumber(SerialNumber)));
}
{
auto hashIndex = MACHash::Hash(SerialNumber);
poco_trace(Logger(), fmt::format("Ending session 2.0: {} for device: {} hi:{}", session_id, Utils::IntToSerialNumber(SerialNumber), hashIndex));
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
poco_trace(Logger(), fmt::format("Ending session 2.1: {} for device: {} hi:{}", session_id, Utils::IntToSerialNumber(SerialNumber), hashIndex));
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
poco_trace(Logger(), fmt::format("Ending session 2.2: {} for device: {} hi:{}", session_id, Utils::IntToSerialNumber(SerialNumber), hashIndex));
if (DeviceHint == SerialNumbers_[hashIndex].end()
|| DeviceHint->second == nullptr
|| DeviceHint->second->State_.sessionId != session_id) {
poco_trace(Logger(), fmt::format("Did not end session 2: {} for device: {}", session_id, Utils::IntToSerialNumber(SerialNumber)));
return false;
}
SerialNumbers_[hashIndex].erase(DeviceHint);
poco_trace(Logger(), fmt::format("Ended session 2: {} for device: {}", session_id, Utils::IntToSerialNumber(SerialNumber)));
}
return true;
}
@@ -561,62 +489,47 @@ namespace OpenWifi {
bool AP_WS_Server::Connected(uint64_t SerialNumber,
GWObjects::DeviceRestrictions &Restrictions) const {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return false;
}
Connection = DeviceHint->second;
}
if(Connection->Dead_) {
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return false;
}
Restrictions = Connection->GetRestrictions();
return Connection->State_.Connected;
if(!DeviceHint->second->Dead_) {
DeviceHint->second->GetRestrictions(Restrictions);
return DeviceHint->second->State_.Connected;
}
return false;
}
bool AP_WS_Server::Connected(uint64_t SerialNumber) const {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return false;
}
Connection = DeviceHint->second;
}
if(Connection->Dead_) {
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard Lock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return false;
}
return Connection->State_.Connected;
if(!DeviceHint->second->Dead_) {
return DeviceHint->second->State_.Connected;
}
return false;
}
bool AP_WS_Server::SendFrame(uint64_t SerialNumber, const std::string &Payload) const {
auto hashIndex = MACHash::Hash(SerialNumber);
std::shared_ptr<AP_WS_Connection> Connection;
{
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return false;
}
Connection = DeviceHint->second;
std::lock_guard Lock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return false;
}
if(Connection->Dead_) {
if(DeviceHint->second->Dead_) {
return false;
}
try {
return Connection->Send(Payload);
return DeviceHint->second->Send(Payload);
} catch (...) {
poco_debug(Logger(), fmt::format(": SendFrame: Could not send data to device '{}'",
Utils::IntToSerialNumber(SerialNumber)));
@@ -625,64 +538,48 @@ namespace OpenWifi {
}
void AP_WS_Server::StopWebSocketTelemetry(uint64_t RPCID, uint64_t SerialNumber) {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto Device = SerialNumbers_[hashIndex].find(SerialNumber);
if (Device == end(SerialNumbers_[hashIndex]) || Device->second == nullptr) {
return;
}
Connection = Device->second;
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard Lock(SerialNumbersMutex_[hashIndex]);
auto Device = SerialNumbers_[hashIndex].find(SerialNumber);
if (Device == end(SerialNumbers_[hashIndex]) || Device->second == nullptr) {
return;
}
Connection->StopWebSocketTelemetry(RPCID);
Device->second->StopWebSocketTelemetry(RPCID);
}
void
AP_WS_Server::SetWebSocketTelemetryReporting(uint64_t RPCID, uint64_t SerialNumber,
uint64_t Interval, uint64_t Lifetime,
const std::vector<std::string> &TelemetryTypes) {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return;
}
Connection = DeviceHint->second;
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return;
}
Connection->SetWebSocketTelemetryReporting(RPCID, Interval, Lifetime, TelemetryTypes);
DeviceHint->second->SetWebSocketTelemetryReporting(RPCID, Interval, Lifetime, TelemetryTypes);
}
void AP_WS_Server::SetKafkaTelemetryReporting(uint64_t RPCID, uint64_t SerialNumber,
uint64_t Interval, uint64_t Lifetime,
const std::vector<std::string> &TelemetryTypes) {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return;
}
Connection = DeviceHint->second;
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard Lock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return;
}
Connection->SetKafkaTelemetryReporting(RPCID, Interval, Lifetime, TelemetryTypes);
DeviceHint->second->SetKafkaTelemetryReporting(RPCID, Interval, Lifetime, TelemetryTypes);
}
void AP_WS_Server::StopKafkaTelemetry(uint64_t RPCID, uint64_t SerialNumber) {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DevicesLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return;
}
Connection = DeviceHint->second;
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DevicesLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return;
}
Connection->StopKafkaTelemetry(RPCID);
DeviceHint->second->StopKafkaTelemetry(RPCID);
}
void AP_WS_Server::GetTelemetryParameters(
@@ -691,18 +588,14 @@ namespace OpenWifi {
uint64_t &TelemetryWebSocketCount, uint64_t &TelemetryKafkaCount,
uint64_t &TelemetryWebSocketPackets, uint64_t &TelemetryKafkaPackets) {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DevicesLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return;
}
Connection = DeviceHint->second;
auto hashIndex = MACHash::Hash(SerialNumber);
std::lock_guard DevicesLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return;
}
Connection->GetTelemetryParameters(TelemetryRunning, TelemetryInterval,
DeviceHint->second->GetTelemetryParameters(TelemetryRunning, TelemetryInterval,
TelemetryWebSocketTimer, TelemetryKafkaTimer,
TelemetryWebSocketCount, TelemetryKafkaCount,
TelemetryWebSocketPackets, TelemetryKafkaPackets);
@@ -711,24 +604,20 @@ namespace OpenWifi {
bool AP_WS_Server::SendRadiusAccountingData(const std::string &SerialNumber,
const unsigned char *buffer, std::size_t size) {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto IntSerialNumber = Utils::SerialNumberToInt(SerialNumber);
auto hashIndex = MACHash::Hash(IntSerialNumber);
std::lock_guard DevicesLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(IntSerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return false;
}
Connection = DeviceHint->second;
auto IntSerialNumber = Utils::SerialNumberToInt(SerialNumber);
auto hashIndex = MACHash::Hash(IntSerialNumber);
std::lock_guard DevicesLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(IntSerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return false;
}
if(Connection->Dead_) {
if(DeviceHint->second->Dead_) {
return false;
}
try {
return Connection->SendRadiusAccountingData(buffer, size);
return DeviceHint->second->SendRadiusAccountingData(buffer, size);
} catch (...) {
poco_debug(
Logger(),
@@ -740,24 +629,20 @@ namespace OpenWifi {
bool AP_WS_Server::SendRadiusAuthenticationData(const std::string &SerialNumber,
const unsigned char *buffer, std::size_t size) {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto IntSerialNumber = Utils::SerialNumberToInt(SerialNumber);
auto hashIndex = MACHash::Hash(IntSerialNumber);
std::lock_guard DevicesLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(IntSerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return false;
}
Connection = DeviceHint->second;
auto IntSerialNumber = Utils::SerialNumberToInt(SerialNumber);
auto hashIndex = MACHash::Hash(IntSerialNumber);
std::lock_guard DevicesLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(IntSerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return false;
}
if(Connection->Dead_) {
if(DeviceHint->second->Dead_) {
return false;
}
try {
return Connection->SendRadiusAuthenticationData(buffer, size);
return DeviceHint->second->SendRadiusAuthenticationData(buffer, size);
} catch (...) {
poco_debug(
Logger(),
@@ -769,23 +654,19 @@ namespace OpenWifi {
bool AP_WS_Server::SendRadiusCoAData(const std::string &SerialNumber,
const unsigned char *buffer, std::size_t size) {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto IntSerialNumber = Utils::SerialNumberToInt(SerialNumber);
auto hashIndex = MACHash::Hash(IntSerialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(IntSerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return false;
}
Connection = DeviceHint->second;
auto IntSerialNumber = Utils::SerialNumberToInt(SerialNumber);
auto hashIndex = MACHash::Hash(IntSerialNumber);
std::lock_guard DevicesGuard(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(IntSerialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr) {
return false;
}
if(Connection->Dead_) {
if(DeviceHint->second->Dead_) {
return false;
}
try {
return Connection->SendRadiusCoAData(buffer, size);
return DeviceHint->second->SendRadiusCoAData(buffer, size);
} catch (...) {
poco_debug(Logger(),
fmt::format(": SendRadiusCoAData: Could not send data to device '{}'",
@@ -794,4 +675,32 @@ namespace OpenWifi {
return false;
}
} // namespace OpenWifi
bool AP_WS_Server::ExtendedAttributes(const std::string &serialNumber,
bool & hasGPS,
std::uint64_t &Sanity,
std::double_t &MemoryUsed,
std::double_t &Load,
std::double_t &Temperature
) {
auto serialNumberInt = Utils::SerialNumberToInt(serialNumber);
auto hashIndex = MACHash::Hash(serialNumberInt);
std::lock_guard DevicesGuard(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(Utils::SerialNumberToInt(serialNumber));
if(DeviceHint==end(SerialNumbers_[hashIndex])) {
return false;
}
if(DeviceHint->second->Dead_) {
return false;
}
std::lock_guard DeviceGuard(DeviceHint->second->ConnectionMutex_);
hasGPS = DeviceHint->second->hasGPS_;
Sanity = DeviceHint->second->RawLastHealthcheck_.Sanity;
MemoryUsed = DeviceHint->second->memory_used_;
Load = DeviceHint->second->cpu_load_;
Temperature = DeviceHint->second->temperature_;
return true;
}
} // namespace OpenWifi

View File

@@ -103,23 +103,20 @@ namespace OpenWifi {
inline void AddConnection(std::shared_ptr<AP_WS_Connection> Connection) {
std::uint64_t sessionHash = SessionHash::Hash(Connection->State_.sessionId);
std::lock_guard SessionLock(SessionMutex_[sessionHash]);
std::lock_guard Lock(SessionMutex_[sessionHash]);
if(Sessions_[sessionHash].find(Connection->State_.sessionId)==end(Sessions_[sessionHash])) {
Sessions_[sessionHash][Connection->State_.sessionId] = std::move(Connection);
}
}
[[nodiscard]] inline bool DeviceRequiresSecureRTTY(uint64_t serialNumber) const {
std::shared_ptr<AP_WS_Connection> Connection;
{
auto hashIndex = MACHash::Hash(serialNumber);
std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]);
auto DeviceHint = SerialNumbers_[hashIndex].find(serialNumber);
if (DeviceHint == end(SerialNumbers_[hashIndex]) || DeviceHint->second == nullptr)
return false;
Connection = DeviceHint->second;
}
return Connection->RTTYMustBeSecure_;
auto hashIndex = MACHash::Hash(serialNumber);
std::lock_guard G(SerialNumbersMutex_[hashIndex]);
auto Connection = SerialNumbers_[hashIndex].find(serialNumber);
if (Connection==end(SerialNumbers_[hashIndex]) || Connection->second==nullptr)
return false;
return Connection->second->RTTYMustBeSecure_;
}
inline bool GetStatistics(const std::string &SerialNumber, std::string &Statistics) const {
@@ -141,7 +138,6 @@ namespace OpenWifi {
bool Connected(uint64_t SerialNumber, GWObjects::DeviceRestrictions &Restrictions) const;
bool Connected(uint64_t SerialNumber) const;
bool Disconnect(uint64_t SerialNumber);
bool SendFrame(uint64_t SerialNumber, const std::string &Payload) const;
bool SendRadiusAuthenticationData(const std::string &SerialNumber,
const unsigned char *buffer, std::size_t size);
@@ -169,8 +165,8 @@ namespace OpenWifi {
uint64_t &TelemetryKafkaPackets);
bool GetHealthDevices(std::uint64_t lowLimit, std::uint64_t highLimit, std::vector<std::string> & SerialNumbers);
// bool ExtendedAttributes(const std::string &serialNumber, bool & hasGPS, std::uint64_t &Sanity,
// std::double_t &MemoryUsed, std::double_t &Load, std::double_t &Temperature);
bool ExtendedAttributes(const std::string &serialNumber, bool & hasGPS, std::uint64_t &Sanity,
std::double_t &MemoryUsed, std::double_t &Load, std::double_t &Temperature);
inline void AverageDeviceStatistics(uint64_t &Connections, uint64_t &AverageConnectionTime,
uint64_t &NumberOfConnectingDevices) const {
@@ -199,31 +195,15 @@ namespace OpenWifi {
bool KafkaDisableState() const { return KafkaDisableState_; }
bool KafkaDisableHealthChecks() const { return KafkaDisableHealthChecks_; }
inline void IncrementConnectionCount() {
++NumberOfConnectedDevices_;
}
inline void DecrementConnectionCount() {
--NumberOfConnectedDevices_;
}
inline void AddCleanupSession(uint64_t session_id, uint64_t SerialNumber) {
std::lock_guard G(CleanupMutex_);
CleanupSessions_.emplace_back(session_id, SerialNumber);
}
void CleanupSessions();
private:
std::array<std::mutex,SessionHashMax> SessionMutex_;
std::array<std::map<std::uint64_t, std::shared_ptr<AP_WS_Connection>>,SessionHashMax> Sessions_;
using SerialNumberMap = std::map<uint64_t /* serial number */,
std::shared_ptr<AP_WS_Connection>>;
std::array<SerialNumberMap,MACHashMax> SerialNumbers_;
mutable std::array<std::mutex,MACHashMax> SerialNumbersMutex_;
mutable std::array<std::recursive_mutex,MACHashMax> SerialNumbersMutex_;
std::unique_ptr<Poco::Crypto::X509Certificate> IssuerCert_;
std::vector<Poco::Crypto::X509Certificate> ClientCasCerts_;
std::list<std::unique_ptr<Poco::Net::HTTPServer>> WebServers_;
Poco::ThreadPool DeviceConnectionPool_{"ws:dev-pool", 4, 256};
Poco::Net::SocketReactor Reactor_;
@@ -234,17 +214,12 @@ namespace OpenWifi {
bool SimulatorEnabled_ = false;
bool AllowSerialNumberMismatch_ = true;
Poco::Thread CleanupThread_;
std::mutex CleanupMutex_;
std::deque<std::pair<uint64_t, uint64_t>> CleanupSessions_;
std::unique_ptr<AP_WS_ReactorThreadPool> Reactor_pool_;
std::atomic_bool Running_ = false;
std::uint64_t MismatchDepth_ = 2;
std::atomic_uint64_t NumberOfConnectedDevices_ = 0;
std::atomic_uint64_t AverageDeviceConnectionTime_ = 0;
std::uint64_t NumberOfConnectedDevices_ = 0;
std::uint64_t AverageDeviceConnectionTime_ = 0;
std::uint64_t NumberOfConnectingDevices_ = 0;
std::uint64_t SessionTimeOut_ = 10*60;
std::uint64_t LeftOverSessions_ = 0;

View File

@@ -10,7 +10,6 @@
#include <string>
#include "framework/MicroServiceFuncs.h"
#include "framework/ow_constants.h"
#include "CentralConfig.h"
#include "nlohmann/json.hpp"
@@ -35,7 +34,7 @@ namespace OpenWifi {
std::lock_guard G(Mutex_);
if (!PlatformsLoaded_)
LoadPlatforms();
auto P = Poco::toLower(Caps.Platform());
auto P = Poco::toUpper(Caps.Platform());
auto Hint = Platforms_.find(Caps.Compatible());
if (Hint == Platforms_.end()) {
Platforms_.insert(std::make_pair(Caps.Compatible(), P));
@@ -69,7 +68,7 @@ namespace OpenWifi {
auto Hint = Platforms_.find(DeviceType);
if (Hint == Platforms_.end())
return Platforms::AP;
return "AP";
return Hint->second;
}
@@ -111,7 +110,7 @@ namespace OpenWifi {
i >> cache;
for (const auto &[Type, Platform] : cache.items()) {
Platforms_[Type] = Poco::toLower(Platform.get<std::string>());
Platforms_[Type] = Platform;
}
} catch (...) {
}

View File

@@ -204,17 +204,6 @@ namespace OpenWifi::Config {
return false;
}
std::uint64_t Config::UUID() {
try {
Poco::JSON::Parser Parser;
auto object = Parser.parse(Config_).extract<Poco::JSON::Object::Ptr>();
if (object->has("uuid"))
return object->get("uuid");
} catch (...) {
}
return 0;
}
bool Config::Valid() {
try {
Poco::JSON::Parser Parser;
@@ -265,11 +254,7 @@ namespace OpenWifi::Config {
Model_ = Caps->get("model").toString();
if (Caps->has("platform"))
Platform_ = Poco::toLower(Caps->get("platform").toString());
if(Compatible_.empty()) {
Compatible_ = Model_;
}
Platform_ = Caps->get("platform").toString();
std::ostringstream OS;
Caps->stringify(OS);

View File

@@ -23,7 +23,6 @@ namespace OpenWifi::Config {
[[nodiscard]] std::string get() { return Config_; };
[[nodiscard]] std::string Default();
[[nodiscard]] Poco::JSON::Object::Ptr to_json();
[[nodiscard]] std::uint64_t UUID();
private:
void Init();

View File

@@ -11,12 +11,12 @@
namespace OpenWifi {
class ConfigurationCache {
public:
static auto instance() {
static auto instance = new ConfigurationCache;
static ConfigurationCache &instance() {
static ConfigurationCache instance;
return instance;
}
inline uint64_t GetCurrentConfig(std::uint64_t SerialNumber) {
inline uint64_t CurrentConfig(uint64_t SerialNumber) {
std::lock_guard G(Mutex_);
const auto Hint = Cache_.find(SerialNumber);
if (Hint == end(Cache_))
@@ -24,25 +24,25 @@ namespace OpenWifi {
return Hint->second;
}
inline void SetCurrentConfig(std::uint64_t SerialNumber, uint64_t Id) {
inline void Add(uint64_t SerialNumber, uint64_t Id) {
std::lock_guard G(Mutex_);
Cache_[SerialNumber] = Id;
}
private:
std::mutex Mutex_;
std::recursive_mutex Mutex_;
std::map<uint64_t, uint64_t> Cache_;
};
inline auto GetCurrentConfigurationID(std::uint64_t SerialNumber) {
return ConfigurationCache::instance()->GetCurrentConfig(SerialNumber);
inline uint64_t GetCurrentConfigurationID(uint64_t SerialNumber) {
return ConfigurationCache::instance().CurrentConfig(SerialNumber);
}
inline void SetCurrentConfigurationID(const std::string &SerialNumber, std::uint64_t ID) {
return ConfigurationCache::instance()->SetCurrentConfig(Utils::SerialNumberToInt(SerialNumber), ID);
inline void SetCurrentConfigurationID(const std::string &SerialNumber, uint64_t ID) {
return ConfigurationCache::instance().Add(Utils::SerialNumberToInt(SerialNumber), ID);
}
inline void SetCurrentConfigurationID(uint64_t SerialNumber, std::uint64_t ID) {
return ConfigurationCache::instance()->SetCurrentConfig(SerialNumber, ID);
inline void SetCurrentConfigurationID(uint64_t SerialNumber, uint64_t ID) {
return ConfigurationCache::instance().Add(SerialNumber, ID);
}
} // namespace OpenWifi

View File

@@ -49,7 +49,7 @@ namespace OpenWifi {
SignatureManager(), AP_WS_Server(),
RegulatoryInfo(),
RADIUSSessionTracker(),
AP_WS_ConfigAutoUpgradeAgent(),
AP_WS_ConfigAutoUpgrader(),
FirmwareRevisionCache()
});
return &instance;
@@ -78,7 +78,7 @@ namespace OpenWifi {
if (Id == DeviceType)
return Type;
}
return Platforms::AP;
return "AP";
}
void DaemonPostInitialization(Poco::Util::Application &self) {

View File

@@ -315,4 +315,4 @@ namespace OpenWifi {
poco_notice(Logger(), "Stopped...");
}
} // namespace OpenWifi
} // namespace OpenWifi

View File

@@ -8,12 +8,12 @@
#pragma once
#include <Poco/Net/HTTPRequestHandler.h>
#include <Poco/Net/HTTPRequestHandlerFactory.h>
#include <Poco/Net/HTTPServer.h>
#include <Poco/Net/HTTPServerRequest.h>
#include "Poco/Net/HTTPRequestHandler.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPServer.h"
#include "Poco/Net/HTTPServerRequest.h"
#include <framework/SubSystemServer.h>
#include "framework/SubSystemServer.h"
namespace OpenWifi {

View File

@@ -50,22 +50,12 @@ namespace OpenWifi {
class DeviceConfigurationChangeKafkaEvent : public GWKafkaEvents {
public:
DeviceConfigurationChangeKafkaEvent(std::uint64_t serialNumber,
std::uint64_t timestamp,
const Poco::JSON::Object::Ptr config)
std::uint64_t timestamp, const Poco::JSON::Object::Ptr config)
: GWKafkaEvents(serialNumber, "unit.configuration_change", timestamp), config_(config) {
}
~DeviceConfigurationChangeKafkaEvent() {
if(config_!= nullptr) {
std::ostringstream os;
config_->stringify(os);
if(os.str().size()> KafkaManager()->KafkaManagerMaximumPayloadSize()) {
payload_->set("configuration", "{}");
payload_->set("configurationTooBig", true);
} else {
payload_->set("configuration", *config_);
}
}
payload_->set("configuration", *config_);
Send();
}

View File

@@ -75,10 +75,8 @@ namespace OpenWifi {
} else if ((Utils::Now() - LastKeepAlive) > Pool_.radsecKeepAlive) {
RADIUS::RadiusOutputPacket P(Pool_.authConfig.servers[ServerIndex_].radsecSecret);
P.MakeStatusMessage(Pool_.authConfig.servers[ServerIndex_].name);
if(Type_!=GWObjects::RadiusEndpointType::generic) {
poco_trace(Logger_, fmt::format("{}: Keep-Alive message.", Pool_.authConfig.servers[ServerIndex_].name));
Socket_->sendBytes(P.Data(), P.Len());
}
poco_trace(Logger_, fmt::format("{}: Keep-Alive message.", Pool_.authConfig.servers[ServerIndex_].name));
Socket_->sendBytes(P.Data(), P.Len());
LastKeepAlive = Utils::Now();
}
Poco::Thread::trySleep(2000);
@@ -165,16 +163,17 @@ namespace OpenWifi {
fmt::format("Unknown packet: Type: {} (type={}) Length={}",
P.PacketType(), P.PacketTypeInt(), P.BufferLen()));
}
return;
} else {
poco_warning(Logger_, "Invalid packet received. Resetting the connection.");
Disconnect();
}
} catch (const Poco::Exception &E) {
Logger_.log(E);
Disconnect();
} catch (...) {
Disconnect();
poco_warning(Logger_, "Exception occurred. Resetting the connection.");
}
Disconnect();
}
inline void
@@ -325,7 +324,7 @@ namespace OpenWifi {
ofs << OpenRoamingRootCert;
ofs.close();
auto SecureContext = Poco::AutoPtr<Poco::Net::Context>(
Poco::Net::Context::Ptr SecureContext = Poco::AutoPtr<Poco::Net::Context>(
new Poco::Net::Context(Poco::Net::Context::TLS_CLIENT_USE, ""));
if (Pool_.acctConfig.servers[ServerIndex_].allowSelfSigned) {
@@ -431,7 +430,7 @@ namespace OpenWifi {
DecodeFile(CaCertFiles_[CaCertFiles_.size() - 1]->path(), cert);
}
auto SecureContext =
Poco::Net::Context::Ptr SecureContext =
Poco::AutoPtr<Poco::Net::Context>(new Poco::Net::Context(
Poco::Net::Context::TLS_CLIENT_USE, KeyFile_.path(), CertFile_.path(), ""));
if (Pool_.acctConfig.servers[ServerIndex_].allowSelfSigned) {
@@ -499,9 +498,7 @@ namespace OpenWifi {
}
inline bool Connect_Generic() {
poco_information(Logger_, fmt::format("Connecting {}", Pool_.name));
if (TryAgain_ && !Connected_) {
if (TryAgain_) {
std::lock_guard G(LocalMutex_);
Poco::Net::SocketAddress AuthSockAddrV4(
@@ -523,6 +520,26 @@ namespace OpenWifi {
MicroServiceConfigGetInt("radius.proxy.coa.port", DEFAULT_RADIUS_CoA_PORT));
CoASocketV4_ = std::make_unique<Poco::Net::DatagramSocket>(CoASockAddrV4, true, true);
/*
AuthenticationSocketV6_ =
std::make_unique<Poco::Net::DatagramSocket>(AuthSockAddrV6, true, true);
Poco::Net::SocketAddress AuthSockAddrV6(
Poco::Net::AddressFamily::IPv6,
MicroServiceConfigGetInt("radius.proxy.authentication.port",
DEFAULT_RADIUS_AUTHENTICATION_PORT));
Poco::Net::SocketAddress AcctSockAddrV6(
Poco::Net::AddressFamily::IPv6,
MicroServiceConfigGetInt("radius.proxy.accounting.port",
DEFAULT_RADIUS_ACCOUNTING_PORT));
AccountingSocketV6_ =
std::make_unique<Poco::Net::DatagramSocket>(AcctSockAddrV6, true, true);
Poco::Net::SocketAddress CoASockAddrV6(
Poco::Net::AddressFamily::IPv6,
MicroServiceConfigGetInt("radius.proxy.coa.port", DEFAULT_RADIUS_CoA_PORT));
CoASocketV6_ = std::make_unique<Poco::Net::DatagramSocket>(CoASockAddrV6, true, true);
*/
Reactor_.addEventHandler(
*AuthenticationSocketV4_,
Poco::NObserver<RADIUS_Destination, Poco::Net::ReadableNotification>(
@@ -534,27 +551,7 @@ namespace OpenWifi {
Reactor_.addEventHandler(
*CoASocketV4_, Poco::NObserver<RADIUS_Destination, Poco::Net::ReadableNotification>(
*this, &RADIUS_Destination::OnCoASocketReadable));
/*
Poco::Net::SocketAddress AuthSockAddrV6(
Poco::Net::AddressFamily::IPv6,
MicroServiceConfigGetInt("radius.proxy.authentication.port",
DEFAULT_RADIUS_AUTHENTICATION_PORT));
AuthenticationSocketV6_ =
std::make_unique<Poco::Net::DatagramSocket>(AuthSockAddrV6, true, true);
Poco::Net::SocketAddress AcctSockAddrV6(
Poco::Net::AddressFamily::IPv6,
MicroServiceConfigGetInt("radius.proxy.accounting.port",
DEFAULT_RADIUS_AUTHENTICATION_PORT));
AccountingSocketV6_ =
std::make_unique<Poco::Net::DatagramSocket>(AcctSockAddrV6, true, true);
Poco::Net::SocketAddress CoASockAddrV6(
Poco::Net::AddressFamily::IPv6,
MicroServiceConfigGetInt("radius.proxy.coa.port", DEFAULT_RADIUS_CoA_PORT));
CoASocketV6_ = std::make_unique<Poco::Net::DatagramSocket>(CoASockAddrV6, true, true);
Reactor_.addEventHandler(
*AuthenticationSocketV6_,
Poco::NObserver<RADIUS_Destination, Poco::Net::ReadableNotification>(
@@ -568,7 +565,6 @@ namespace OpenWifi {
*CoASocketV6_, Poco::NObserver<RADIUS_Destination, Poco::Net::ReadableNotification>(
*this, &RADIUS_Destination::OnCoASocketReadable));
*/
Connected_ = true;
}
return true;
}
@@ -594,8 +590,6 @@ namespace OpenWifi {
if (Connected_) {
std::lock_guard G(LocalMutex_);
if(Type_==GWObjects::RadiusEndpointType::generic) {
poco_information(Logger_, fmt::format("Disconnecting {} generic server. Releasing all UDP resources.", Pool_.name));
if(AuthenticationSocketV4_) {
Reactor_.removeEventHandler(
*AuthenticationSocketV4_,
@@ -623,8 +617,7 @@ namespace OpenWifi {
CoASocketV4_.reset();
}
/*
if(AuthenticationSocketV6_) {
/* if(AuthenticationSocketV6_) {
Reactor_.removeEventHandler(
*AuthenticationSocketV6_,
Poco::NObserver<RADIUS_Destination, Poco::Net::ReadableNotification>(
@@ -653,6 +646,7 @@ namespace OpenWifi {
*/
} else {
if(Socket_!=nullptr) {
std::lock_guard G(LocalMutex_);
Reactor_.removeEventHandler(
*Socket_, Poco::NObserver<RADIUS_Destination, Poco::Net::ReadableNotification>(
*this, &RADIUS_Destination::onData));
@@ -666,9 +660,9 @@ namespace OpenWifi {
Socket_->close();
}
}
Connected_ = false;
}
poco_information(Logger_, fmt::format("Disconnecting {}", Pool_.name));
Connected_ = false;
poco_information(Logger_, "Disconnecting.");
}
static void DecodeFile(const std::string &filename, const std::string &s) {
@@ -730,8 +724,7 @@ namespace OpenWifi {
std::unique_ptr<Poco::Net::DatagramSocket> AuthenticationSocketV4_;
std::unique_ptr<Poco::Net::DatagramSocket> CoASocketV4_;
/*
std::unique_ptr<Poco::Net::DatagramSocket> CoASocketV6_;
/* std::unique_ptr<Poco::Net::DatagramSocket> CoASocketV6_;
std::unique_ptr<Poco::Net::DatagramSocket> AccountingSocketV6_;
std::unique_ptr<Poco::Net::DatagramSocket> AuthenticationSocketV6_;
*/

View File

@@ -25,23 +25,9 @@ namespace OpenWifi::RESTAPI_RPC {
if (StorageService()->AddCommand(Cmd.SerialNumber, Cmd, Status)) {
Poco::JSON::Object RetObj;
Cmd.to_json(RetObj);
if (Handler == nullptr) {
// nothing to process/return
return;
}
Poco::Net::HTTPResponse::HTTPStatus cmd_status = Poco::Net::HTTPResponse::HTTP_OK;
if (Cmd.ErrorCode > 0) {
// command returned error
cmd_status = Poco::Net::HTTPResponse::HTTP_BAD_REQUEST;
if (Cmd.Command == uCentralProtocol::CONFIGURE) {
// special handling for configure command
if (!Handler->GetBoolParameter("strict", false)) {
// in non-strict mode return success for failed configure command
cmd_status = Poco::Net::HTTPResponse::HTTP_OK;
}
}
}
return Handler->ReturnObject(RetObj, cmd_status);
if (Handler != nullptr)
return Handler->ReturnObject(RetObj);
return;
}
if (Handler != nullptr)
return Handler->ReturnStatus(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
@@ -54,8 +40,8 @@ namespace OpenWifi::RESTAPI_RPC {
std::chrono::milliseconds WaitTimeInMs, Poco::JSON::Object *ObjectToReturn,
RESTAPIHandler *Handler, Poco::Logger &Logger, bool Deferred) {
Logger.information(fmt::format("{},{}: New {} command. User={} Serial={} Details={}. ", Cmd.UUID,
RPCID, Cmd.Command, Cmd.SubmittedBy, Cmd.SerialNumber, Cmd.Details));
Logger.information(fmt::format("{},{}: New {} command. User={} Serial={}. ", Cmd.UUID,
RPCID, Cmd.Command, Cmd.SubmittedBy, Cmd.SerialNumber));
Cmd.Submitted = Utils::Now();
Cmd.Executed = 0;
@@ -181,20 +167,6 @@ namespace OpenWifi::RESTAPI_RPC {
Cmd.AttachType = "";
}
// If the command fails on the device we should show it as failed and not return 200 OK
// exception is configure command which only reported failed in strict validation mode
if (Cmd.ErrorCode &&
(Cmd.Command != uCentralProtocol::CONFIGURE ||
(Cmd.Command == uCentralProtocol::CONFIGURE && Handler->GetBoolParameter("strict", false))
))
{
Logger.information(fmt::format(
"Command failed with error on device: {} Reason: {}.",
Cmd.ErrorCode, Cmd.ErrorText));
return SetCommandStatus(Cmd, Request, Response, Handler,
Storage::CommandExecutionType::COMMAND_FAILED, Logger);
}
if (Cmd.ErrorCode == 0 && Cmd.Command == uCentralProtocol::CONFIGURE) {
// we need to post a kafka event for this.
if (Params.has(uCentralProtocol::CONFIG) && Params.isObject(uCentralProtocol::CONFIG)) {
@@ -203,7 +175,6 @@ namespace OpenWifi::RESTAPI_RPC {
DeviceConfigurationChangeKafkaEvent KEvent(
Utils::SerialNumberToInt(Cmd.SerialNumber), Utils::Now(),
Config);
}
}

View File

@@ -56,27 +56,17 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if (DefConfig.models.empty()) {
if (DefConfig.Models.empty()) {
return BadRequest(RESTAPI::Errors::ModelIDListCannotBeEmpty);
}
DefConfig.platform = DefConfig.platform.empty() ? Platforms::AP : DefConfig.platform;
if(DefConfig.platform != Platforms::AP && DefConfig.platform != Platforms::SWITCH) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
if(DefConfig.configuration.empty()) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
std::string Error;
if (!ValidateUCentralConfiguration(ConfigurationValidator::GetType(DefConfig.platform),
DefConfig.configuration, Error,
std::vector<std::string> Error;
if (!ValidateUCentralConfiguration(DefConfig.Configuration, Error,
GetBoolParameter("strict", false))) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid, Error);
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
}
DefConfig.created = DefConfig.lastModified = Utils::Now();
DefConfig.Created = DefConfig.LastModified = Utils::Now();
if (StorageService()->CreateDefaultConfiguration(Name, DefConfig)) {
return OK();
}
@@ -98,31 +88,19 @@ namespace OpenWifi {
return NotFound();
}
if(Existing.platform.empty()) {
Existing.platform = Platforms::AP;
}
if(ParsedBody_->has("platform")) {
if(NewConfig.platform.empty() || (NewConfig.platform != Platforms::AP && NewConfig.platform != Platforms::SWITCH)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
Existing.platform = NewConfig.platform;
}
if (!NewConfig.configuration.empty()) {
std::string Error;
if (!ValidateUCentralConfiguration(ConfigurationValidator::GetType(Existing.platform),
NewConfig.configuration, Error,
if (!NewConfig.Configuration.empty()) {
std::vector<std::string> Error;
if (!ValidateUCentralConfiguration(NewConfig.Configuration, Error,
GetBoolParameter("strict", false))) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid, Error);
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
}
Existing.configuration = NewConfig.configuration;
Existing.Configuration = NewConfig.Configuration;
}
Existing.lastModified = Utils::Now();
AssignIfPresent(Obj, "description", Existing.description);
Existing.LastModified = Utils::Now();
AssignIfPresent(Obj, "description", Existing.Description);
if (Obj->has("modelIds"))
Existing.models = NewConfig.models;
Existing.Models = NewConfig.Models;
if (StorageService()->UpdateDefaultConfiguration(Name, Existing)) {
GWObjects::DefaultConfiguration ModifiedConfig;

View File

@@ -91,31 +91,6 @@ namespace OpenWifi {
TransactionId_, UUID, RPC, Poco::Thread::current()->id()));
return Rtty(UUID, RPC, 60000ms, Restrictions);
};
case APCommands::Commands::package:{
GWObjects::DeviceRestrictions Restrictions;
std::string pkg_name = "";
if (!AP_WS_Server()->Connected(SerialNumberInt_, Restrictions)) {
CallCanceled(Command_.c_str(), RESTAPI::Errors::DeviceNotConnected);
return BadRequest(RESTAPI::Errors::DeviceNotConnected);
}
Poco::URI uri(Request->getURI());
for (const auto &param : uri.getQueryParameters()) {
if (param.first == "pkgName") {
pkg_name = param.second;
}
}
if (pkg_name.empty()) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
auto UUID = MicroServiceCreateUUID();
auto RPC = CommandManager()->Next_RPC_ID();
poco_debug(
Logger_,
fmt::format(
"Command Package TID={} can proceed. Identified as {} and RPCID as {}. thr_id={}",
TransactionId_, UUID, RPC, Poco::Thread::current()->id()));
return GetPackages(UUID, RPC, pkg_name, 300000ms, Restrictions);
}
default:
return BadRequest(RESTAPI::Errors::InvalidCommand);
}
@@ -153,21 +128,6 @@ namespace OpenWifi {
return DeleteChecks();
case APCommands::Commands::statistics:
return DeleteStatistics();
case APCommands::Commands::package: {
GWObjects::DeviceRestrictions Restrictions;
if (!AP_WS_Server()->Connected(SerialNumberInt_, Restrictions)) {
CallCanceled(Command_.c_str(), RESTAPI::Errors::DeviceNotConnected);
return BadRequest(RESTAPI::Errors::DeviceNotConnected);
}
auto UUID = MicroServiceCreateUUID();
auto RPC = CommandManager()->Next_RPC_ID();
poco_debug(
Logger_,
fmt::format(
"Command RTTY TID={} can proceed. Identified as {} and RPCID as {}. thr_id={}",
TransactionId_, UUID, RPC, Poco::Thread::current()->id()));
return DeletePackages(UUID, RPC, 300000ms, Restrictions);
}
default:
return BadRequest(RESTAPI::Errors::InvalidCommand);
}
@@ -206,12 +166,7 @@ namespace OpenWifi {
{APCommands::Commands::rrm, false, true, &RESTAPI_device_commandHandler::RRM, 60000ms},
{APCommands::Commands::certupdate, false, true, &RESTAPI_device_commandHandler::CertUpdate, 60000ms},
{APCommands::Commands::transfer, false, true, &RESTAPI_device_commandHandler::Transfer, 60000ms},
{APCommands::Commands::script, false, true, &RESTAPI_device_commandHandler::Script, 60000ms},
{APCommands::Commands::powercycle, false, true, &RESTAPI_device_commandHandler::PowerCycle, 60000ms},
{APCommands::Commands::fixedconfig, false, true, &RESTAPI_device_commandHandler::FixedConfig, 120000ms},
{APCommands::Commands::cablediagnostics, false, true, &RESTAPI_device_commandHandler::CableDiagnostics, 120000ms},
{APCommands::Commands::reenroll, false, true, &RESTAPI_device_commandHandler::ReEnroll, 120000ms},
{APCommands::Commands::package, false, true, &RESTAPI_device_commandHandler::PackageInstall, 120000ms},
{APCommands::Commands::script, false, true, &RESTAPI_device_commandHandler::Script, 60000ms}
};
void RESTAPI_device_commandHandler::DoPost() {
@@ -449,210 +404,6 @@ namespace OpenWifi {
BadRequest(RESTAPI::Errors::NoRecordsDeleted);
}
void RESTAPI_device_commandHandler::GetPackages(const std::string &CMD_UUID, uint64_t CMD_RPC,
const std::string pkg_name,
[[maybe_unused]] std::chrono::milliseconds timeout,
[[maybe_unused]] const GWObjects::DeviceRestrictions &Restrictions) {
poco_debug(Logger_, fmt::format("GET-PACKAGES: TID={}, user={} serial={}. thr_id={}",
TransactionId_, Requester(), SerialNumber_,
Poco::Thread::current()->id()));
if (IsDeviceSimulated(SerialNumber_)) {
return BadRequest(RESTAPI::Errors::SimulatedDeviceNotSupported);
}
Poco::JSON::Object Params;
Params.set(uCentralProtocol::OPERATION, "list");
Params.set(uCentralProtocol::SERIAL, SerialNumber_);
Params.set(uCentralProtocol::PACKAGE, pkg_name);
std::stringstream ParamStream;
Params.stringify(ParamStream);
GWObjects::CommandDetails Cmd;
Cmd.SerialNumber = SerialNumber_;
Cmd.UUID = CMD_UUID;
Cmd.SubmittedBy = Requester();
Cmd.Command = uCentralProtocol::PACKAGE;
Cmd.RunAt = 0;
Cmd.Details = ParamStream.str();
RESTAPI_RPC::WaitForCommand(CMD_RPC, APCommands::Commands::package, false, Cmd, Params,
*Request, *Response, timeout, nullptr, nullptr, Logger_);
Poco::JSON::Object O, P;
Cmd.to_json(O);
Poco::Dynamic::Var resultsVar = O.get("results");
Poco::JSON::Object::Ptr resultsObj = resultsVar.extract<Poco::JSON::Object::Ptr>();
return ReturnObject(*resultsObj);
}
void RESTAPI_device_commandHandler::PackageInstall(
const std::string &CMD_UUID, uint64_t CMD_RPC,
[[maybe_unused]] std::chrono::milliseconds timeout,
[[maybe_unused]] const GWObjects::DeviceRestrictions &Restrictions) {
if (UserInfo_.userinfo.userRole != SecurityObjects::ROOT &&
UserInfo_.userinfo.userRole != SecurityObjects::ADMIN) {
CallCanceled("INSTALLPACKAGE", CMD_UUID, CMD_RPC, RESTAPI::Errors::ACCESS_DENIED);
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
}
poco_debug(Logger_, fmt::format("INSTALL-PACKAGES({},{}): TID={} user={} serial={}", CMD_UUID,
CMD_RPC, TransactionId_, Requester(), SerialNumber_));
if (IsDeviceSimulated(SerialNumber_)) {
CallCanceled("INSTALL-PACKAGES", CMD_UUID, CMD_RPC, RESTAPI::Errors::SimulatedDeviceNotSupported);
return BadRequest(RESTAPI::Errors::SimulatedDeviceNotSupported);
}
const auto &Obj = ParsedBody_;
if (!Obj->has(RESTAPI::Protocol::SERIALNUMBER)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
auto SNum = Obj->get(RESTAPI::Protocol::SERIALNUMBER).toString();
if (SerialNumber_ != SNum) {
CallCanceled("INSTALL-PACKAGES", CMD_UUID, CMD_RPC, RESTAPI::Errors::SerialNumberMismatch);
return BadRequest(RESTAPI::Errors::SerialNumberMismatch);
}
std::ostringstream os;
ParsedBody_->stringify(os);
poco_information(Logger_, fmt::format("INSTALL_OBJECT: {} for device {}", os.str(), SerialNumber_));
GWObjects::PackageInstall PI;
if (!PI.from_json(ParsedBody_)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
Poco::JSON::Array::Ptr ArrayObj = Poco::SharedPtr<Poco::JSON::Array>(new Poco::JSON::Array);
for (const auto &i : PI.pkgs) {
Poco::JSON::Object::Ptr Obj =
Poco::SharedPtr<Poco::JSON::Object>(new Poco::JSON::Object);
i.to_json(*Obj);
ArrayObj->add(Obj);
}
Poco::JSON::Object Params;
Params.set(uCentralProtocol::OPERATION, "install");
Params.set(uCentralProtocol::SERIAL, SerialNumber_);
Params.set(uCentralProtocol::PACKAGES, ArrayObj);
std::ostringstream os2;
Params.stringify(os2);
poco_information(Logger_, fmt::format("INSTALL_OBJECT2: {} for device {}", os2.str(), SerialNumber_));
std::stringstream ParamStream;
Params.stringify(ParamStream);
GWObjects::CommandDetails Cmd;
Cmd.SerialNumber = SerialNumber_;
Cmd.UUID = CMD_UUID;
Cmd.SubmittedBy = Requester();
Cmd.Command = uCentralProtocol::PACKAGE;
Cmd.RunAt = 0;
Cmd.Details = ParamStream.str();
RESTAPI_RPC::WaitForCommand(CMD_RPC, APCommands::Commands::package, false, Cmd, Params,
*Request, *Response, timeout, nullptr, nullptr, Logger_);
Poco::JSON::Object O, P;
Cmd.to_json(O);
Poco::Dynamic::Var resultsVar = O.get("results");
Poco::JSON::Object::Ptr resultsObj = resultsVar.extract<Poco::JSON::Object::Ptr>();
return ReturnObject(*resultsObj);
}
void RESTAPI_device_commandHandler::DeletePackages(
const std::string &CMD_UUID, uint64_t CMD_RPC,
[[maybe_unused]] std::chrono::milliseconds timeout,
[[maybe_unused]] const GWObjects::DeviceRestrictions &Restrictions) {
if (UserInfo_.userinfo.userRole != SecurityObjects::ROOT &&
UserInfo_.userinfo.userRole != SecurityObjects::ADMIN) {
CallCanceled("DELETE-PACKAGES", CMD_UUID, CMD_RPC, RESTAPI::Errors::ACCESS_DENIED);
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
}
poco_debug(Logger_, fmt::format("DELETE-PACKAGES({},{}): TID={} user={} serial={}", CMD_UUID,
CMD_RPC, TransactionId_, Requester(), SerialNumber_));
if (IsDeviceSimulated(SerialNumber_)) {
CallCanceled("DELETE-PACKAGES", CMD_UUID, CMD_RPC, RESTAPI::Errors::SimulatedDeviceNotSupported);
return BadRequest(RESTAPI::Errors::SimulatedDeviceNotSupported);
}
const auto &Obj = ParsedBody_;
if (!Obj->has(RESTAPI::Protocol::SERIALNUMBER)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
auto SNum = Obj->get(RESTAPI::Protocol::SERIALNUMBER).toString();
if (SerialNumber_ != SNum) {
CallCanceled("DELETE-PACKAGES", CMD_UUID, CMD_RPC, RESTAPI::Errors::SerialNumberMismatch);
return BadRequest(RESTAPI::Errors::SerialNumberMismatch);
}
std::ostringstream os;
ParsedBody_->stringify(os);
poco_information(Logger_, fmt::format("DELETE_OBJECT: {} for device {}", os.str(), SerialNumber_));
GWObjects::PackageRemove PR;
if (!PR.from_json(ParsedBody_)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
Poco::JSON::Array::Ptr ArrayObj = Poco::SharedPtr<Poco::JSON::Array>(new Poco::JSON::Array);
for (const auto &i : PR.pkgs) {
Poco::JSON::Object::Ptr Obj =
Poco::SharedPtr<Poco::JSON::Object>(new Poco::JSON::Object);
i.to_json(*Obj);
ArrayObj->add(Obj);
}
Poco::JSON::Object Params;
Params.set(uCentralProtocol::OPERATION, "delete");
Params.set(uCentralProtocol::SERIAL, SerialNumber_);
Params.set(uCentralProtocol::PACKAGES, ArrayObj);
std::ostringstream os2;
Params.stringify(os2);
poco_information(Logger_, fmt::format("DELETE_OBJECT2: {} for device {}", os2.str(), SerialNumber_));
std::stringstream ParamStream;
Params.stringify(ParamStream);
GWObjects::CommandDetails Cmd;
Cmd.SerialNumber = SerialNumber_;
Cmd.UUID = CMD_UUID;
Cmd.SubmittedBy = Requester();
Cmd.Command = uCentralProtocol::PACKAGE;
Cmd.RunAt = 0;
Cmd.Details = ParamStream.str();
RESTAPI_RPC::WaitForCommand(CMD_RPC, APCommands::Commands::package, false, Cmd, Params,
*Request, *Response, timeout, nullptr, nullptr, Logger_);
Poco::JSON::Object O, P;
Cmd.to_json(O);
Poco::Dynamic::Var resultsVar = O.get("results");
Poco::JSON::Object::Ptr resultsObj = resultsVar.extract<Poco::JSON::Object::Ptr>();
return ReturnObject(*resultsObj);
}
void RESTAPI_device_commandHandler::Ping(
const std::string &CMD_UUID, uint64_t CMD_RPC, std::chrono::milliseconds timeout,
[[maybe_unused]] const GWObjects::DeviceRestrictions &Restrictions) {
@@ -902,18 +653,13 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::SerialNumberMismatch);
}
GWObjects::Device DeviceInfo;
if (!StorageService()->GetDevice(SerialNumber_, DeviceInfo)) {
return NotFound();
}
auto Configuration =
GetS(RESTAPI::Protocol::CONFIGURATION, Obj, uCentralProtocol::EMPTY_JSON_DOC);
std::string Error;
if (!ValidateUCentralConfiguration(ConfigurationValidator::GetType(DeviceInfo.DeviceType),
Configuration, Error,
std::vector<std::string> Error;
if (!ValidateUCentralConfiguration(Configuration, Error,
GetBoolParameter("strict", false))) {
CallCanceled("CONFIGURE", CMD_UUID, CMD_RPC, RESTAPI::Errors::ConfigBlockInvalid);
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid, Error);
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
}
auto When = GetWhen(Obj);
@@ -939,31 +685,9 @@ namespace OpenWifi {
Params.stringify(ParamStream);
Cmd.Details = ParamStream.str();
// retrieve capabilities and encode/compress parameters, if required
Poco::JSON::Object ConfigParams = Params;
GWObjects::Capabilities Caps;
if (StorageService()->GetDeviceCapabilities(SerialNumber_, Caps)) {
Poco::JSON::Object CapsJson;
Caps.to_json(CapsJson);
auto DeviceCaps = CapsJson.getObject(uCentralProtocol::CAPABILITIES);
if (DeviceCaps->has("compress_cmd") && DeviceCaps->get("compress_cmd")) {
// compressed command capability present and it is set, compress parameters
Poco::JSON::Object CompressedParams;
std::string CompressedBase64Data;
std::uint64_t UncompressedDataLen = ParamStream.str().length();
if (Utils::CompressAndEncodeBase64(ParamStream.str(), CompressedBase64Data)) {
// set compressed, base 64 encoded data and length of uncompressed data
CompressedParams.set(uCentralProtocol::COMPRESS_64, CompressedBase64Data);
CompressedParams.set(uCentralProtocol::COMPRESS_SZ, UncompressedDataLen);
ConfigParams = CompressedParams;
}
}
}
// AP_WS_Server()->SetPendingUUID(SerialNumber_, NewUUID);
RESTAPI_RPC::WaitForCommand(CMD_RPC, APCommands::Commands::configure, true,
Cmd, ConfigParams, *Request, *Response, timeout,
Cmd, Params, *Request, *Response, timeout,
nullptr, this, Logger_);
if(!Cmd.Executed) {
@@ -1677,9 +1401,9 @@ namespace OpenWifi {
Cmd.WaitingForFile = 0;
Cmd.Status= "completed";
if(CommandManager()->FireAndForget(SerialNumber_, uCentralProtocol::RRM, Params)) {
Cmd.Status= "completed";
StorageService()->AddCommand(SerialNumber_, Cmd,
Storage::CommandExecutionType::COMMAND_COMPLETED);
Cmd.Status= "completed";
return OK();
}
Cmd.Status= "failed"; // should never happen
@@ -1777,164 +1501,4 @@ namespace OpenWifi {
}
void RESTAPI_device_commandHandler::PowerCycle(
const std::string &CMD_UUID, uint64_t CMD_RPC,
[[maybe_unused]] std::chrono::milliseconds timeout,
[[maybe_unused]] const GWObjects::DeviceRestrictions &Restrictions) {
if(UserInfo_.userinfo.userRole != SecurityObjects::ROOT &&
UserInfo_.userinfo.userRole != SecurityObjects::ADMIN) {
CallCanceled("RRM", CMD_UUID, CMD_RPC, RESTAPI::Errors::ACCESS_DENIED);
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
}
poco_debug(Logger_, fmt::format("POWERCYCLE({},{}): TID={} user={} serial={}", CMD_UUID,
CMD_RPC, TransactionId_, Requester(), SerialNumber_));
if(IsDeviceSimulated(SerialNumber_)) {
CallCanceled("RRM", CMD_UUID, CMD_RPC, RESTAPI::Errors::SimulatedDeviceNotSupported);
return BadRequest(RESTAPI::Errors::SimulatedDeviceNotSupported);
}
GWObjects::PowerCycleRequest PR;
if(!PR.from_json(ParsedBody_)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
GWObjects::CommandDetails Cmd;
Cmd.SerialNumber = SerialNumber_;
Cmd.SubmittedBy = Requester();
Cmd.UUID = CMD_UUID;
Cmd.Command = uCentralProtocol::POWERCYCLE;
std::ostringstream os;
ParsedBody_->stringify(os);
Cmd.Details = os.str();
Cmd.RunAt = PR.when;
Cmd.ErrorCode = 0;
Cmd.WaitingForFile = 0;
return RESTAPI_RPC::WaitForCommand(CMD_RPC, APCommands::Commands::powercycle, false, Cmd,
*ParsedBody_, *Request, *Response, timeout, nullptr, this,
Logger_);
}
// `fixedconfig` command is used set country propery on AP
// This handler uses `fixedconfig` command definitions
void RESTAPI_device_commandHandler::FixedConfig(
const std::string &CMD_UUID, uint64_t CMD_RPC, std::chrono::milliseconds timeout,
[[maybe_unused]] const GWObjects::DeviceRestrictions &Restrictions) {
poco_debug(Logger_, fmt::format("FIXEDCONFIG({},{}): TID={} user={} serial={}", CMD_UUID, CMD_RPC,
TransactionId_, Requester(), SerialNumber_));
// do not allow `fixedconfig` command for simulated devices
if(IsDeviceSimulated(SerialNumber_)) {
CallCanceled("FIXEDCONFIG", CMD_UUID, CMD_RPC, RESTAPI::Errors::SimulatedDeviceNotSupported);
return BadRequest(RESTAPI::Errors::SimulatedDeviceNotSupported);
}
// setup and validate fixedconfig object
GWObjects::FixedConfig fixed_config;
if(!fixed_config.from_json(ParsedBody_)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
// setup command message
GWObjects::CommandDetails Cmd;
Cmd.SerialNumber = SerialNumber_;
Cmd.SubmittedBy = Requester();
Cmd.UUID = CMD_UUID;
Cmd.Command = uCentralProtocol::FIXEDCONFIG;
std::ostringstream os;
ParsedBody_->stringify(os);
Cmd.Details = os.str();
Cmd.RunAt = 0;
Cmd.ErrorCode = 0;
Cmd.WaitingForFile = 0;
// send fixedconfig command to device and return status
return RESTAPI_RPC::WaitForCommand(CMD_RPC, APCommands::Commands::fixedconfig, false, Cmd,
*ParsedBody_, *Request, *Response, timeout, nullptr, this,
Logger_);
}
void RESTAPI_device_commandHandler::CableDiagnostics(
const std::string &CMD_UUID, uint64_t CMD_RPC,
[[maybe_unused]] std::chrono::milliseconds timeout,
[[maybe_unused]] const GWObjects::DeviceRestrictions &Restrictions) {
if(UserInfo_.userinfo.userRole != SecurityObjects::ROOT &&
UserInfo_.userinfo.userRole != SecurityObjects::ADMIN) {
CallCanceled("CABLEDIAGNOSTICS", CMD_UUID, CMD_RPC, RESTAPI::Errors::ACCESS_DENIED);
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
}
poco_debug(Logger_, fmt::format("CABLEDIAGNOSTICS({},{}): TID={} user={} serial={}", CMD_UUID,
CMD_RPC, TransactionId_, Requester(), SerialNumber_));
if(IsDeviceSimulated(SerialNumber_)) {
CallCanceled("CABLEDIAGNOSTICS", CMD_UUID, CMD_RPC, RESTAPI::Errors::SimulatedDeviceNotSupported);
return BadRequest(RESTAPI::Errors::SimulatedDeviceNotSupported);
}
GWObjects::CableDiagnostics PR;
if(!PR.from_json(ParsedBody_)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
GWObjects::CommandDetails Cmd;
Cmd.SerialNumber = SerialNumber_;
Cmd.SubmittedBy = Requester();
Cmd.UUID = CMD_UUID;
Cmd.Command = uCentralProtocol::CABLEDIAGNOSTICS;
std::ostringstream os;
ParsedBody_->stringify(os);
Cmd.Details = os.str();
Cmd.RunAt = PR.when;
Cmd.ErrorCode = 0;
Cmd.WaitingForFile = 0;
return RESTAPI_RPC::WaitForCommand(CMD_RPC, APCommands::Commands::cablediagnostics, false, Cmd,
*ParsedBody_, *Request, *Response, timeout, nullptr, this,
Logger_);
}
void RESTAPI_device_commandHandler::ReEnroll(
const std::string &CMD_UUID, uint64_t CMD_RPC,
[[maybe_unused]] std::chrono::milliseconds timeout,
[[maybe_unused]] const GWObjects::DeviceRestrictions &Restrictions) {
if(UserInfo_.userinfo.userRole != SecurityObjects::ROOT &&
UserInfo_.userinfo.userRole != SecurityObjects::ADMIN) {
CallCanceled("REENROLL", CMD_UUID, CMD_RPC, RESTAPI::Errors::ACCESS_DENIED);
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
}
poco_debug(Logger_, fmt::format("REENROLL({},{}): TID={} user={} serial={}", CMD_UUID,
CMD_RPC, TransactionId_, Requester(), SerialNumber_));
if(IsDeviceSimulated(SerialNumber_)) {
CallCanceled("REENROLL", CMD_UUID, CMD_RPC, RESTAPI::Errors::SimulatedDeviceNotSupported);
return BadRequest(RESTAPI::Errors::SimulatedDeviceNotSupported);
}
GWObjects::ReEnroll PR;
if(!PR.from_json(ParsedBody_)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
GWObjects::CommandDetails Cmd;
Cmd.SerialNumber = SerialNumber_;
Cmd.SubmittedBy = Requester();
Cmd.UUID = CMD_UUID;
Cmd.Command = uCentralProtocol::REENROLL;
std::ostringstream os;
ParsedBody_->stringify(os);
Cmd.Details = os.str();
Cmd.RunAt = PR.when;
Cmd.ErrorCode = 0;
Cmd.WaitingForFile = 0;
return RESTAPI_RPC::WaitForCommand(CMD_RPC, APCommands::Commands::reenroll, false, Cmd,
*ParsedBody_, *Request, *Response, timeout, nullptr, this,
Logger_);
}
} // namespace OpenWifi

View File

@@ -33,13 +33,6 @@ namespace OpenWifi {
void GetStatus();
void GetChecks();
void DeleteChecks();
void GetPackages(const std::string &UUID, uint64_t RPC,
std::string pkg_name,
std::chrono::milliseconds timeout,
const GWObjects::DeviceRestrictions &R);
void DeletePackages(const std::string &UUID, uint64_t RPC,
std::chrono::milliseconds timeout,
const GWObjects::DeviceRestrictions &R);
bool IsDeviceSimulated(std::string &Serial);
@@ -75,16 +68,6 @@ namespace OpenWifi {
const GWObjects::DeviceRestrictions &R);
void Transfer(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout,
const GWObjects::DeviceRestrictions &R);
void PowerCycle(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout,
const GWObjects::DeviceRestrictions &R);
void FixedConfig(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout,
const GWObjects::DeviceRestrictions &R);
void CableDiagnostics(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout,
const GWObjects::DeviceRestrictions &R);
void ReEnroll(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout,
const GWObjects::DeviceRestrictions &R);
void PackageInstall(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout,
const GWObjects::DeviceRestrictions &R);
static auto PathName() {
return std::list<std::string>{"/api/v1/device/{serialNumber}/{command}"};

View File

@@ -17,8 +17,6 @@
#include "RESTAPI_device_helper.h"
#include "AP_WS_Server.h"
namespace OpenWifi {
void RESTAPI_device_handler::DoGet() {
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
@@ -82,9 +80,6 @@ namespace OpenWifi {
return OK();
} else if (StorageService()->DeleteDevice(SerialNumber)) {
if(AP_WS_Server()->Connected(Utils::SerialNumberToInt(SerialNumber))) {
AP_WS_Server()->Disconnect(Utils::SerialNumberToInt(SerialNumber));
}
return OK();
}
@@ -106,10 +101,9 @@ namespace OpenWifi {
}
auto Config = Obj->get("configuration").toString();
Poco::JSON::Object Answer;
std::string Error;
auto DeviceType = Poco::toLower(GetParameter("deviceType", Platforms::AP));
std::vector<std::string> Error;
auto Res =
ValidateUCentralConfiguration(ConfigurationValidator::GetType(DeviceType),Config, Error, GetBoolParameter("strict", false));
ValidateUCentralConfiguration(Config, Error, GetBoolParameter("strict", false));
Answer.set("valid", Res);
if (!Error.empty())
Answer.set("error", Error);
@@ -129,13 +123,12 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::SerialNumberMismatch);
}
std::string Error;
std::vector<std::string> Error;
if (Device.Configuration.empty() ||
(!Device.Configuration.empty() &&
!ValidateUCentralConfiguration(ConfigurationValidator::GetType(Device.DeviceType),
Device.Configuration, Error,
!ValidateUCentralConfiguration(Device.Configuration, Error,
GetBoolParameter("strict", false)))) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid, Error);
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
}
for (auto &i : Device.Notes) {
@@ -176,11 +169,10 @@ namespace OpenWifi {
}
if (!NewDevice.Configuration.empty()) {
std::string Error;
if (!ValidateUCentralConfiguration(ConfigurationValidator::GetType(Existing.DeviceType),
NewDevice.Configuration, Error,
std::vector<std::string> Error;
if (!ValidateUCentralConfiguration(NewDevice.Configuration, Error,
GetBoolParameter("strict", false))) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid, Error);
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
}
Config::Config NewConfig(NewDevice.Configuration);
uint64_t NewConfigUUID = Utils::Now();

View File

@@ -82,24 +82,15 @@ namespace OpenWifi {
}
}
auto platform = Poco::toLower(GetParameter("platform", ""));
auto serialOnly = GetBoolParameter(RESTAPI::Protocol::SERIALONLY, false);
auto deviceWithStatus = GetBoolParameter(RESTAPI::Protocol::DEVICEWITHSTATUS, false);
auto completeInfo = GetBoolParameter("completeInfo", false);
auto includeProvisioned = GetBoolParameter("includeProvisioned", true);
if(!platform.empty() && (platform!=Platforms::AP && platform!=Platforms::SWITCH && platform!="all")) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
if(platform=="all")
platform="";
Poco::JSON::Object RetObj;
if (!QB_.Select.empty()) {
Poco::JSON::Array Objects;
for (auto &i : SelectedRecords()) {
auto &SerialNumber = i;
auto SerialNumber = i;
if (!Utils::ValidSerialNumber(i))
continue;
GWObjects::Device D;
@@ -125,14 +116,14 @@ namespace OpenWifi {
else
RetObj.set(RESTAPI::Protocol::DEVICES, Objects);
} else if (QB_.CountOnly) {
} else if (QB_.CountOnly == true) {
uint64_t Count = 0;
if (StorageService()->GetDeviceCount(Count, platform)) {
if (StorageService()->GetDeviceCount(Count)) {
return ReturnCountOnly(Count);
}
} else if (serialOnly) {
std::vector<std::string> SerialNumbers;
StorageService()->GetDeviceSerialNumbers(QB_.Offset, QB_.Limit, SerialNumbers, OrderBy, platform, includeProvisioned);
StorageService()->GetDeviceSerialNumbers(QB_.Offset, QB_.Limit, SerialNumbers, OrderBy);
Poco::JSON::Array Objects;
for (const auto &i : SerialNumbers) {
Objects.add(i);
@@ -150,7 +141,7 @@ namespace OpenWifi {
RetObj.set("serialNumbers", Objects);
} else {
std::vector<GWObjects::Device> Devices;
StorageService()->GetDevices(QB_.Offset, QB_.Limit, Devices, OrderBy, platform, includeProvisioned);
StorageService()->GetDevices(QB_.Offset, QB_.Limit, Devices, OrderBy);
Poco::JSON::Array Objects;
for (const auto &i : Devices) {
Poco::JSON::Object Obj;

View File

@@ -22,15 +22,9 @@ namespace OpenWifi {
std::string FileType;
std::string FileContent;
int WaitingForFile = 0;
if (!StorageService()->GetAttachedFileContent(UUID, SerialNumber, FileContent, FileType, WaitingForFile) && !WaitingForFile) {
if (!StorageService()->GetAttachedFileContent(UUID, SerialNumber, FileContent, FileType) || FileContent.empty()) {
return NotFound();
}
else if (WaitingForFile) {
// waiting for file to be uploaded, return Accepted
return Accepted();
}
if (FileType == "pcap") {
SendFileContent(FileContent, "application/vnd.tcpdump.pcap", UUID + ".pcap");
}

View File

@@ -8,7 +8,7 @@
#pragma once
#include <framework/RESTAPI_Handler.h>
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi {
class RESTAPI_file : public RESTAPIHandler {

View File

@@ -7,7 +7,6 @@
#include "RESTAPI_ProvObjects.h"
#include "framework/utils.h"
#include <vector>
#include "framework/ow_constants.h"
namespace OpenWifi {

View File

@@ -14,7 +14,6 @@
#include "AP_WS_Server.h"
#include "CapabilitiesCache.h"
#include "RADIUSSessionTracker.h"
#include "StorageService.h"
#endif
#include "RESTAPI_GWobjects.h"
@@ -30,9 +29,8 @@ namespace OpenWifi::GWObjects {
void Device::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj, "serialNumber", SerialNumber);
#ifdef TIP_GATEWAY_SERVICE
field_to_json(Obj, "deviceType", StorageService()->GetPlatform(SerialNumber));
field_to_json(Obj, "blackListed",
StorageService()->IsBlackListed(Utils::MACToInt(SerialNumber)));
field_to_json(Obj, "deviceType", CapabilitiesCache::instance()->GetPlatform(Compatible));
field_to_json(Obj, "hasRADIUSSessions", RADIUSSessionTracker()->HasSessions(SerialNumber));
#endif
field_to_json(Obj, "macAddress", MACAddress);
field_to_json(Obj, "manufacturer", Manufacturer);
@@ -70,14 +68,9 @@ namespace OpenWifi::GWObjects {
#ifdef TIP_GATEWAY_SERVICE
ConnectionState ConState;
#ifdef USE_MEDUSA_CLIENT
auto Res = GS()->GetState(SerialNumber);
if (Res.has_value()) {
Res.value().to_json(SerialNumber, Obj);
#else
if (AP_WS_Server()->GetState(SerialNumber, ConState)) {
ConState.to_json(SerialNumber, Obj);
#endif
ConState.to_json(SerialNumber,Obj);
} else {
field_to_json(Obj, "ipAddress", "");
field_to_json(Obj, "txBytes", (uint64_t)0);
@@ -173,15 +166,13 @@ namespace OpenWifi::GWObjects {
field_to_json(Obj, "recorded", Recorded);
}
bool HealthCheck::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "UUID", UUID);
field_from_json(Obj, "sanity", Sanity);
field_from_json(Obj, "recorded", Recorded);
return true;
} catch (...) {
}
return false;
void DefaultConfiguration::to_json(Poco::JSON::Object &Obj) const {
EmbedDocument("configuration", Obj, Configuration);
field_to_json(Obj, "name", Name);
field_to_json(Obj, "modelIds", Models);
field_to_json(Obj, "description", Description);
field_to_json(Obj, "created", Created);
field_to_json(Obj, "lastModified", LastModified);
}
void DefaultFirmware::to_json(Poco::JSON::Object &Obj) const {
@@ -231,25 +222,12 @@ namespace OpenWifi::GWObjects {
field_to_json(Obj, "deferred", deferred);
}
void DefaultConfiguration::to_json(Poco::JSON::Object &Obj) const {
EmbedDocument("configuration", Obj, configuration);
field_to_json(Obj, "name", name);
field_to_json(Obj, "modelIds", models);
field_to_json(Obj, "description", description);
field_to_json(Obj, "created", created);
field_to_json(Obj, "lastModified", lastModified);
field_to_json(Obj, "platform", platform);
}
bool DefaultConfiguration::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "configuration", configuration);
field_from_json(Obj, "name", name);
field_from_json(Obj, "modelIds", models);
field_from_json(Obj, "description", description);
field_from_json(Obj, "created", created);
field_from_json(Obj, "lastModified", lastModified);
field_from_json(Obj, "platform", platform);
field_from_json(Obj, "name", Name);
field_from_json(Obj, "configuration", Configuration);
field_from_json(Obj, "modelIds", Models);
field_from_json(Obj, "description", Description);
return true;
} catch (const Poco::Exception &E) {
}
@@ -275,8 +253,7 @@ namespace OpenWifi::GWObjects {
return false;
}
void ConnectionState::to_json([[maybe_unused]] const std::string &SerialNumber,
Poco::JSON::Object &Obj) {
void ConnectionState::to_json([[maybe_unused]] const std::string &SerialNumber, Poco::JSON::Object &Obj) {
field_to_json(Obj, "ipAddress", Address);
field_to_json(Obj, "txBytes", TX);
field_to_json(Obj, "rxBytes", RX);
@@ -298,15 +275,17 @@ namespace OpenWifi::GWObjects {
field_to_json(Obj, "connectionCompletionTime", connectionCompletionTime);
field_to_json(Obj, "totalConnectionTime", Utils::Now() - started);
field_to_json(Obj, "certificateExpiryDate", certificateExpiryDate);
field_to_json(Obj, "certificateIssuerName", certificateIssuerName);
field_to_json(Obj, "connectReason", connectReason);
field_to_json(Obj, "uptime", uptime);
field_to_json(Obj, "compatible", Compatible);
#ifdef TIP_GATEWAY_SERVICE
hasRADIUSSessions = RADIUSSessionTracker()->HasSessions(SerialNumber);
AP_WS_Server()->ExtendedAttributes(SerialNumber, hasGPS, sanity,
memoryUsed,
load,
temperature);
#endif
field_to_json(Obj, "hasRADIUSSessions", hasRADIUSSessions);
field_to_json(Obj, "hasRADIUSSessions", hasRADIUSSessions );
field_to_json(Obj, "hasGPS", hasGPS);
field_to_json(Obj, "sanity", sanity);
field_to_json(Obj, "memoryUsed", memoryUsed);
@@ -336,46 +315,6 @@ namespace OpenWifi::GWObjects {
}
}
bool ConnectionState::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "compatible", Compatible);
field_from_json(Obj, "ipAddress", Address);
field_from_json(Obj, "txBytes", TX);
field_from_json(Obj, "rxBytes", RX);
field_from_json(Obj, "messageCount", MessageCount);
field_from_json(Obj, "UUID", UUID);
field_from_json(Obj, "connected", Connected);
field_from_json(Obj, "firmware", Firmware);
field_from_json(Obj, "lastContact", LastContact);
field_from_json(Obj, "associations_2G", Associations_2G);
field_from_json(Obj, "associations_5G", Associations_5G);
field_from_json(Obj, "associations_6G", Associations_6G);
field_from_json(Obj, "webSocketClients", webSocketClients);
field_from_json(Obj, "websocketPackets", websocketPackets);
field_from_json(Obj, "kafkaClients", kafkaClients);
field_from_json(Obj, "kafkaPackets", kafkaPackets);
field_from_json(Obj, "locale", locale);
field_from_json(Obj, "started", started);
field_from_json(Obj, "sessionId", sessionId);
field_from_json(Obj, "connectionCompletionTime", connectionCompletionTime);
field_from_json(Obj, "totalConnectionTime", totalConnectionTime);
field_from_json(Obj, "certificateExpiryDate", certificateExpiryDate);
field_from_json(Obj, "certificateIssuerName", certificateIssuerName);
field_from_json(Obj, "connectReason", connectReason);
field_from_json(Obj, "uptime", uptime);
field_from_json(Obj, "hasRADIUSSessions", hasRADIUSSessions);
field_from_json(Obj, "hasGPS", hasGPS);
field_from_json(Obj, "sanity", sanity);
field_from_json(Obj, "memoryUsed", memoryUsed);
field_from_json(Obj, "sanity", sanity);
field_from_json(Obj, "load", load);
field_from_json(Obj, "temperature", temperature);
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
void DeviceConnectionStatistics::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj, "averageConnectionTime", averageConnectionTime);
field_to_json(Obj, "connectedDevices", connectedDevices);
@@ -773,7 +712,7 @@ namespace OpenWifi::GWObjects {
bool DeviceCertificateUpdateRequest::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "serial", serialNumber);
field_from_json(Obj, "serialNumber", serialNumber);
field_from_json(Obj, "encodedCertificate", encodedCertificate);
return true;
} catch (const Poco::Exception &E) {
@@ -781,144 +720,4 @@ namespace OpenWifi::GWObjects {
return false;
}
bool PowerCyclePort::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "name", name);
field_from_json(Obj, "cycle", cycle);
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
bool PowerCycleRequest::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "serial", serialNumber);
field_from_json(Obj, "when", when);
field_from_json(Obj, "ports", ports);
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
bool FixedConfig::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "serial", serialNumber);
field_from_json(Obj, "country", country);
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
bool CableDiagnostics::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "serial", serialNumber);
field_from_json(Obj, "when", when);
field_from_json(Obj, "ports", ports);
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
bool ReEnroll::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "serial", serialNumber);
field_from_json(Obj, "when", when);
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
bool PackageInfo::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "name", name);
field_from_json(Obj, "version", version);
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
void PackageInfo::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj, "name", name);
field_to_json(Obj, "version", version);
}
void PackageList::to_json(Poco::JSON::Object &Obj) const {
Obj.set("serialNumber", serialNumber);
Poco::JSON::Array packageJsonArray;
for (const auto &pkg : packageArray) {
Poco::JSON::Object pkgObj;
pkg.to_json(pkgObj);
packageJsonArray.add(pkgObj);
}
Obj.set("packageArray", packageJsonArray);
Obj.set("FirstUpdate", Poco::UInt64(FirstUpdate));
Obj.set("LastUpdate", Poco::UInt64(LastUpdate));
}
bool ToBeInstalled::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "name", name);
field_from_json(Obj, "url", url);
Poco::URI uri(url);
std::string scheme = uri.getScheme();
if (scheme != "http" && scheme != "https") {
return false;
}
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
void ToBeInstalled::to_json(Poco::JSON::Object &Obj) const {
Obj.set("name", name);
Obj.set("url", url);
}
bool PackageInstall::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "serialNumber", serialNumber);
field_from_json(Obj, "when", when);
field_from_json(Obj, "packages", pkgs);
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
bool ToBeRemoved::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "name", name);
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
void ToBeRemoved::to_json(Poco::JSON::Object &Obj) const {
Obj.set("name", name);
}
bool PackageRemove::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "serialNumber", serialNumber);
field_from_json(Obj, "packages", pkgs);
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
} // namespace OpenWifi::GWObjects

View File

@@ -42,7 +42,6 @@ namespace OpenWifi::GWObjects {
uint64_t sessionId = 0;
double connectionCompletionTime = 0.0;
std::uint64_t certificateExpiryDate = 0;
std::string certificateIssuerName;
std::uint64_t hasRADIUSSessions = 0;
bool hasGPS = false;
std::uint64_t sanity=0;
@@ -51,10 +50,8 @@ namespace OpenWifi::GWObjects {
std::double_t temperature=0.0;
std::string connectReason;
std::uint64_t uptime=0;
std::uint64_t totalConnectionTime=0;
void to_json(const std::string &SerialNumber, Poco::JSON::Object &Obj) ;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct DeviceRestrictionsKeyInfo {
@@ -116,7 +113,6 @@ namespace OpenWifi::GWObjects {
std::uint64_t lastRecordedContact=0;
std::uint64_t certificateExpiryDate = 0;
std::string connectReason;
bool blackListed=false;
void to_json(Poco::JSON::Object &Obj) const;
void to_json_with_status(Poco::JSON::Object &Obj) const;
@@ -142,15 +138,13 @@ namespace OpenWifi::GWObjects {
};
struct HealthCheck {
std::string SerialNumber;
uint64_t UUID = 0;
std::string Data;
uint64_t Recorded = 0;
uint64_t Sanity = 0;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
std::string SerialNumber;
uint64_t UUID = 0;
std::string Data;
uint64_t Recorded = 0;
uint64_t Sanity = 0;
void to_json(Poco::JSON::Object &Obj) const;
};
struct Capabilities {
std::string Capabilities;
@@ -181,13 +175,12 @@ namespace OpenWifi::GWObjects {
};
struct DefaultConfiguration {
std::string name;
std::string configuration;
Types::StringVec models;
std::string description;
uint64_t created;
uint64_t lastModified;
std::string platform;
std::string Name;
std::string Configuration;
Types::StringVec Models;
std::string Description;
uint64_t Created;
uint64_t LastModified;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
@@ -521,82 +514,4 @@ namespace OpenWifi::GWObjects {
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct PowerCyclePort {
std::string name;
std::uint64_t cycle=10000;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct PowerCycleRequest {
std::string serialNumber;
std::uint64_t when;
std::vector<PowerCyclePort> ports;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct FixedConfig {
std::string serialNumber;
std::string country;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct CableDiagnostics {
std::string serialNumber;
std::uint64_t when;
std::vector<std::string> ports;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct ReEnroll {
std::string serialNumber;
std::uint64_t when;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct PackageInfo {
std::string name;
std::string version;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
void to_json(Poco::JSON::Object &Obj) const;
};
struct PackageList {
std::string serialNumber;
std::vector<PackageInfo> packageArray;
uint64_t FirstUpdate = 0;
uint64_t LastUpdate = 0;
std::string packageStringArray;
bool from_json(const Poco::JSON::Array::Ptr &Obj);
void to_json(Poco::JSON::Object &Obj) const;
};
struct ToBeInstalled {
std::string name;
std::string url;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
void to_json(Poco::JSON::Object &Obj) const;
};
struct PackageInstall {
std::string serialNumber;
std::uint64_t when;
std::vector<ToBeInstalled> pkgs;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
void to_json(Poco::JSON::Object &Obj) const;
};
struct ToBeRemoved {
std::string name;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
void to_json(Poco::JSON::Object &Obj) const;
};
struct PackageRemove {
std::string serialNumber;
std::uint64_t when;
std::vector<ToBeRemoved> pkgs;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
} // namespace OpenWifi::GWObjects

View File

@@ -587,9 +587,6 @@ 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) {
@@ -612,9 +609,6 @@ 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 (...) {
}

View File

@@ -490,11 +490,9 @@ 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{Platforms::AP};
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};

View File

@@ -22,8 +22,6 @@ namespace OpenWifi {
ScriptDB_->Create();
ScriptDB_->Initialize();
FixDeviceTypeBug();
return 0;
}

View File

@@ -143,31 +143,26 @@ namespace OpenWifi {
bool simulated);
bool CreateDevice(Poco::Data::Session &Sess, GWObjects::Device &DeviceDetails);
bool GetDevice(LockedDbSession &Session, const std::string &SerialNumber, GWObjects::Device &);
bool GetDevice(Poco::Data::Session &Session, const std::string &SerialNumber, GWObjects::Device &DeviceDetails);
bool GetDevice(const std::string &SerialNumber, GWObjects::Device &);
bool GetDevice(LockedDbSession &Session, std::string &SerialNumber, GWObjects::Device &);
bool GetDevice(Poco::Data::Session &Session, std::string &SerialNumber, GWObjects::Device &DeviceDetails);
bool GetDevice(std::string &SerialNumber, GWObjects::Device &);
bool GetDevices(uint64_t From, uint64_t HowMany, std::vector<GWObjects::Device> &Devices,
const std::string &orderBy = "",
const std::string &platform = "",
bool includeProvisioned = true);
const std::string &orderBy = "");
// bool GetDevices(uint64_t From, uint64_t HowMany, const std::string & Select,
// std::vector<GWObjects::Device> &Devices, const std::string & orderBy="");
bool DeleteDevice(std::string &SerialNumber);
bool DeleteDevices(std::string &SerialPattern, bool SimulatedOnly);
bool DeleteDevices(std::uint64_t OlderContact, bool SimulatedOnly);
std::string GetPlatform(const std::string &SerialNumber);
bool UpdateDevice(GWObjects::Device &);
bool UpdateDevice(LockedDbSession &Session, GWObjects::Device &);
bool UpdateDevice(Poco::Data::Session &Sess, GWObjects::Device &NewDeviceDetails);
bool DeviceExists(std::string &SerialNumber);
bool SetConnectInfo(std::string &SerialNumber, std::string &Firmware);
bool GetDeviceCount(uint64_t &Count, const std::string &platform = "");
bool GetDeviceCount(uint64_t &Count);
bool GetDeviceSerialNumbers(uint64_t From, uint64_t HowMany,
std::vector<std::string> &SerialNumbers,
const std::string &orderBy = "",
const std::string &platform = "",
bool includeProvisioned = true);
const std::string &orderBy = "");
bool GetDeviceFWUpdatePolicy(std::string &SerialNumber, std::string &Policy);
bool SetDevicePassword(LockedDbSession &Session, std::string &SerialNumber, std::string &Password);
bool UpdateSerialNumberCache();
@@ -203,7 +198,6 @@ namespace OpenWifi {
bool GetDefaultConfigurations(uint64_t From, uint64_t HowMany,
std::vector<GWObjects::DefaultConfiguration> &Devices);
bool FindDefaultConfigurationForModel(const std::string &Model,
const std::string &Platform,
GWObjects::DefaultConfiguration &DefConfig);
uint64_t GetDefaultConfigurationsCount();
bool DefaultConfigurationAlreadyExists(std::string &Name);
@@ -243,7 +237,7 @@ namespace OpenWifi {
const std::string &Type);
bool CancelWaitFile(std::string &UUID, std::string &ErrorText);
bool GetAttachedFileContent(std::string &UUID, const std::string &SerialNumber,
std::string &FileContent, std::string &Type, int& WaitingForFile);
std::string &FileContent, std::string &Type);
bool RemoveAttachedFile(std::string &UUID);
bool SetCommandResult(std::string &UUID, std::string &Result);
bool GetNewestCommands(std::string &SerialNumber, uint64_t HowMany,
@@ -297,8 +291,6 @@ namespace OpenWifi {
bool AnalyzeCommands(Types::CountedMap &R);
bool AnalyzeDevices(GWObjects::Dashboard &D);
void FixDeviceTypeBug();
int Start() override;
void Stop() override;

View File

@@ -120,16 +120,14 @@ namespace OpenWifi {
Poco::Buffer<char> IncomingFrame(0);
try {
int Op, flags, IncomingSize;
int Op, flags;
int IncomingSize;
IncomingSize = WS_->receiveFrame(IncomingFrame, flags);
Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
if (IncomingSize == -1) {
poco_trace(Logger(),
fmt::format("TELEMETRY-EMPTY({}): Empty frame, non-blocking try-again.", CId_));
} else if (IncomingSize == 0 && flags == 0 && Op == 0) {
poco_information(Logger(),
if (IncomingSize == 0 && flags == 0 && Op == 0) {
poco_information(
Logger(),
fmt::format("TELEMETRY-DISCONNECT({}): device has disconnected.", CId_));
MustDisconnect = true;
} else {
@@ -138,14 +136,12 @@ namespace OpenWifi {
fmt::format("TELEMETRY-WS-PING({}): received. PONG sent back.", CId_));
WS_->sendFrame("", 0,
(int)Poco::Net::WebSocket::FRAME_OP_PONG |
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
} else if (Op == Poco::Net::WebSocket::FRAME_OP_CLOSE) {
poco_information(Logger(),
poco_information(
Logger(),
fmt::format("TELEMETRY-DISCONNECT({}): device wants to disconnect.", CId_));
MustDisconnect = true;
} else if (Op == Poco::Net::WebSocket::FRAME_OP_CONT) {
poco_information(Logger(),
fmt::format("TELEMETRY-CONT({}): rx {} bytes.", CId_, IncomingSize));
}
}
} catch (...) {
@@ -158,4 +154,4 @@ namespace OpenWifi {
SendTelemetryShutdown();
}
} // namespace OpenWifi
} // namespace OpenWifi

View File

@@ -111,6 +111,7 @@ namespace OpenWifi {
}
} break;
case TelemetryNotification::NotificationType::unregister: {
std::lock_guard G(Mutex_);
auto client = Clients_.find(Notification->Data_);
if (client != Clients_.end()) {

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,7 @@
#pragma once
#include "framework/SubSystemServer.h"
#include "framework/ow_constants.h"
#include <valijson/adapters/poco_json_adapter.hpp>
#include <valijson/constraints/constraint.hpp>
#include <valijson/constraints/constraint_visitor.hpp>
@@ -17,42 +17,33 @@
namespace OpenWifi {
class ConfigurationValidator : public SubSystemServer {
public:
enum class ConfigurationType { AP = 0 , SWITCH = 1};
static auto instance() {
static auto instance_ = new ConfigurationValidator;
return instance_;
}
bool Validate(ConfigurationType Type, const std::string &C, std::string &Errors, bool Strict);
bool Validate(const std::string &C, std::vector<std::string> &Errors, bool Strict);
int Start() override;
void Stop() override;
void reinitialize(Poco::Util::Application &self) override;
inline static ConfigurationType GetType(const std::string &type) {
std::string Type = Poco::toLower(type);
if (Type == Platforms::AP)
return ConfigurationType::AP;
if (Type == Platforms::SWITCH)
return ConfigurationType::SWITCH;
return ConfigurationType::AP;
}
private:
bool Initialized_ = false;
bool Working_ = false;
void Init();
std::array<valijson::Schema,2> RootSchema_;
bool SetSchema(ConfigurationType Type, const std::string &SchemaStr);
std::unique_ptr<valijson::Schema> RootSchema_;
std::unique_ptr<valijson::SchemaParser> SchemaParser_;
std::unique_ptr<valijson::adapters::PocoJsonAdapter> PocoJsonAdapter_;
Poco::JSON::Object::Ptr SchemaDocPtr_;
bool SetSchema(const std::string &SchemaStr);
ConfigurationValidator()
: SubSystemServer("ConfigValidator", "CFG-VALIDATOR", "config.validator") {}
};
inline auto ConfigurationValidator() { return ConfigurationValidator::instance(); }
inline bool ValidateUCentralConfiguration(ConfigurationValidator::ConfigurationType Type, const std::string &C, std::string &Errors,
inline bool ValidateUCentralConfiguration(const std::string &C, std::vector<std::string> &Error,
bool strict) {
return ConfigurationValidator::instance()->Validate(Type, C, Errors, strict);
return ConfigurationValidator::instance()->Validate(C, Error, strict);
}
} // namespace OpenWifi

View File

@@ -16,9 +16,9 @@ namespace OpenWifi {
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg,
false);
while (Running_) {
if(!Poco::Thread::trySleep((unsigned long)MicroServiceDaemonBusTimer())) {
break;
}
Poco::Thread::trySleep((unsigned long)MicroServiceDaemonBusTimer());
if (!Running_)
break;
Msg = (MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE));
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(),
Msg, false);
@@ -29,7 +29,7 @@ namespace OpenWifi {
};
void EventBusManager::Start() {
poco_information(Logger_, "Starting...");
poco_information(Logger(), "Starting...");
if (KafkaManager()->Enabled()) {
Thread_.start(*this);
}
@@ -37,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...");
}
}

View File

@@ -22,6 +22,7 @@ namespace OpenWifi {
return instance_;
}
explicit EventBusManager(Poco::Logger &L);
void run() final;
void Start();
void Stop();

View File

@@ -79,10 +79,8 @@ namespace OpenWifi {
Utils::SetThreadName("Kafka:Prod");
cppkafka::Configuration Config(
{{"client.id", MicroServiceConfigGetString("openwifi.kafka.client.id", "")},
{"metadata.broker.list",MicroServiceConfigGetString("openwifi.kafka.brokerlist", "")} // ,
// {"send.buffer.bytes", KafkaManager()->KafkaManagerMaximumPayloadSize() }
}
);
{"metadata.broker.list",
MicroServiceConfigGetString("openwifi.kafka.brokerlist", "")}});
AddKafkaSecurity(Config);
@@ -107,19 +105,6 @@ 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) {
@@ -132,7 +117,6 @@ namespace OpenWifi {
}
Note = Queue_.waitDequeueNotification();
}
Producer.flush();
poco_information(Logger_, "Stopped...");
}
@@ -291,7 +275,6 @@ namespace OpenWifi {
int KafkaManager::Start() {
if (!KafkaEnabled_)
return 0;
MaxPayloadSize_ = MicroServiceConfigGetInt("openwifi.kafka.max.payload", 250000);
ConsumerThr_.Start();
ProducerThr_.Start();
return 0;
@@ -338,4 +321,4 @@ namespace OpenWifi {
partitions.front().get_partition()));
}
} // namespace OpenWifi
} // namespace OpenWifi

View File

@@ -94,14 +94,11 @@ 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);

View File

@@ -1,5 +1,4 @@
//
//
// Created by stephane bourque on 2022-10-26.
//
@@ -30,13 +29,11 @@
#include "framework/WebSocketLogger.h"
#include "framework/utils.h"
#ifdef USE_MEDUSA_CLIENT
#include <medusa/MedusaClient.h>
#endif
namespace OpenWifi {
static std::string MakeServiceListString(const Types::MicroServiceMetaMap &Services) {
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())
@@ -207,29 +204,25 @@ 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_;
Poco::Path ConfigFile(ConfigFileName_);
std::string Location = Poco::Environment::get(DAEMON_CONFIG_ENV_VAR, ".");
ConfigFileName_ =
ConfigFileName_.empty() ? Location + "/" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_;
Poco::Path ConfigFile(ConfigFileName_);
if (!ConfigFile.isFile()) {
std::cerr << DAEMON_APP_NAME << ": Configuration " << ConfigFile.toString()
<< " does not seem to exist. Please set " + DAEMON_CONFIG_ENV_VAR +
" env variable the path of the " + DAEMON_PROPERTIES_FILENAME +
" file."
<< std::endl;
std::exit(Poco::Util::Application::EXIT_CONFIG);
}
PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration(ConfigFile.toString());
} else {
std::istringstream is(ConfigContent_);
PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration(is);
}
if (!ConfigFile.isFile()) {
std::cerr << DAEMON_APP_NAME << ": Configuration " << ConfigFile.toString()
<< " does not seem to exist. Please set " + DAEMON_CONFIG_ENV_VAR +
" env variable the path of the " + DAEMON_PROPERTIES_FILENAME +
" file."
<< std::endl;
std::exit(Poco::Util::Application::EXIT_CONFIG);
}
// loadConfiguration(ConfigFile.toString());
PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration(ConfigFile.toString());
configPtr()->addWriteable(PropConfigurationFile_, PRIO_DEFAULT);
}
@@ -432,69 +425,49 @@ namespace OpenWifi {
void DaemonPostInitialization(Poco::Util::Application &self);
void MicroService::StartEverything(Poco::Util::Application &self) {
LoadConfigurationFile();
InitializeLoggingSystem();
void MicroService::initialize(Poco::Util::Application &self) {
// add the default services
LoadConfigurationFile();
InitializeLoggingSystem();
static bool InitializedBaseService=false;
if(!InitializedBaseService) {
InitializedBaseService = true;
SubSystems_.push_back(KafkaManager());
SubSystems_.push_back(ALBHealthCheckServer());
SubSystems_.push_back(RESTAPI_ExtServer());
SubSystems_.push_back(RESTAPI_IntServer());
SubSystems_.push_back(KafkaManager());
SubSystems_.push_back(ALBHealthCheckServer());
SubSystems_.push_back(RESTAPI_ExtServer());
SubSystems_.push_back(RESTAPI_IntServer());
#ifndef TIP_SECURITY_SERVICE
SubSystems_.push_back(AuthClient());
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::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();
if (!DataDir.exists()) {
try {
DataDir.createDirectory();
} catch (const Poco::Exception &E) {
Logger_.log(E);
}
}
WWWAssetsDir_ = ConfigPath("openwifi.restapi.wwwassets", "");
if (WWWAssetsDir_.empty())
WWWAssetsDir_ = DataDir_;
Poco::File DataDir(ConfigPath("openwifi.system.data"));
DataDir_ = DataDir.path();
if (!DataDir.exists()) {
try {
DataDir.createDirectory();
} catch (const Poco::Exception &E) {
Logger_.log(E);
}
}
WWWAssetsDir_ = ConfigPath("openwifi.restapi.wwwassets", "");
if (WWWAssetsDir_.empty())
WWWAssetsDir_ = DataDir_;
LoadMyConfig();
LoadMyConfig();
AllowExternalMicroServices_ = ConfigGetBool("allowexternalmicroservices", true);
AllowExternalMicroServices_ = ConfigGetBool("allowexternalmicroservices", true);
InitializeSubSystemServers();
ServerApplication::initialize(self);
DaemonPostInitialization(self);
InitializeSubSystemServers();
ServerApplication::initialize(self);
DaemonPostInitialization(self);
Types::TopicNotifyFunction F = [this](const std::string &Key, const std::string &Payload) {
this->BusMessageReceived(Key, Payload);
};
KafkaManager()->RegisterTopicWatcher(KafkaTopics::SERVICE_EVENTS, F);
}
void MicroService::StopEverything([[maybe_unused]] Poco::Util::Application &self) {
LoadConfigurationFile();
InitializeLoggingSystem();
Types::TopicNotifyFunction F = [this](const std::string &Key, const std::string &Payload) {
this->BusMessageReceived(Key, Payload);
};
KafkaManager()->RegisterTopicWatcher(KafkaTopics::SERVICE_EVENTS, F);
}
void MicroService::initialize([[maybe_unused]] Poco::Util::Application &self) {
#ifndef USE_MEDUSA_CLIENT
StartEverything(self);
#endif
Types::TopicNotifyFunction F = [this](const std::string &Key, const std::string &Payload) {
this->BusMessageReceived(Key, Payload);
};
KafkaManager()->RegisterTopicWatcher(KafkaTopics::SERVICE_EVENTS, F);
}
void MicroService::uninitialize() {
@@ -780,8 +753,6 @@ namespace OpenWifi {
MicroServiceErrorHandler ErrorHandler(*this);
Poco::ErrorHandler::set(&ErrorHandler);
Args_ = args;
if (!HelpRequested_) {
SavePID();
@@ -797,18 +768,11 @@ 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;
@@ -845,4 +809,4 @@ namespace OpenWifi {
}
}
} // namespace OpenWifi
} // namespace OpenWifi

View File

@@ -14,7 +14,6 @@
#include <iostream>
#include <random>
#include <vector>
#include <optional>
// This must be defined for poco_debug and poco_trace macros to function.
@@ -41,7 +40,6 @@ namespace OpenWifi {
#include "Poco/Util/OptionSet.h"
#include "Poco/Util/PropertyFileConfiguration.h"
#include "Poco/Util/ServerApplication.h"
#include "Poco/ThreadPool.h"
#include "framework/OpenWifiTypes.h"
@@ -57,6 +55,9 @@ 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 {
@@ -69,6 +70,7 @@ 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";
@@ -90,7 +92,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 std::string GetPublicAPIEndPoint() const {
[[nodiscard]] inline const std::string GetPublicAPIEndPoint() {
return MyPublicEndPoint_ + "/api/v1";
};
[[nodiscard]] inline const std::string &GetUIURI() const { return UIURI_; };
@@ -105,8 +107,7 @@ namespace OpenWifi {
}
static MicroService &instance() { return *instance_; }
inline void Exit(int Reason) { std::exit(Reason); }
inline void Exit(int Reason);
void BusMessageReceived(const std::string &Key, const std::string &Payload);
Types::MicroServiceMetaVec GetServices(const std::string &Type);
Types::MicroServiceMetaVec GetServices();
@@ -114,9 +115,7 @@ namespace OpenWifi {
void Reload();
void LoadMyConfig();
void initialize(Poco::Util::Application &self) override;
void StartEverything(Poco::Util::Application &self);
void StopEverything(Poco::Util::Application &self);
void uninitialize() override;
void uninitialize() override;
void reinitialize(Poco::Util::Application &self) override;
void defineOptions(Poco::Util::OptionSet &options) override;
void handleHelp(const std::string &name, const std::string &value);
@@ -133,7 +132,7 @@ namespace OpenWifi {
void Reload(const std::string &Sub);
Types::StringVec GetSubSystems() const;
Types::StringPairVec GetLogLevels();
static const Types::StringVec &GetLogLevelNames();
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);
@@ -167,25 +166,12 @@ 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; }
inline std::optional<OpenWifi::Types::MicroServiceMeta> GetPrivateEndPointServiceKey( const std::string & ServicePrivateEndPoint ) {
std::lock_guard G(InfraMutex_);
auto K = Services_.find(ServicePrivateEndPoint);
if(K==end(Services_)) {
return std::nullopt;
}
return K->second;
}
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;
@@ -215,7 +201,6 @@ namespace OpenWifi {
Poco::JWT::Signer Signer_;
Poco::Logger &Logger_;
Poco::ThreadPool TimerPool_{"timer:pool", 2, 32};
ArgVec Args_;
};
inline MicroService *MicroService::instance_ = nullptr;

View File

@@ -133,8 +133,4 @@ namespace OpenWifi {
return MicroService::instance().Hash();
}
std::optional<OpenWifi::Types::MicroServiceMeta> MicroServicePrivateAccessKey(const std::string &servicePrivateEndPoint) {
return MicroService::instance().GetPrivateEndPointServiceKey(servicePrivateEndPoint);
}
} // namespace OpenWifi

View File

@@ -5,7 +5,6 @@
#pragma once
#include <string>
#include <optional>
#include "framework/OpenWifiTypes.h"
@@ -24,9 +23,7 @@ namespace OpenWifi {
std::string MicroServiceConfigGetString(const std::string &Key,
const std::string &DefaultValue);
std::string MicroServiceAccessKey();
std::optional<OpenWifi::Types::MicroServiceMeta> MicroServicePrivateAccessKey(const std::string &servicePrivateEndPoint);
bool MicroServiceConfigGetBool(const std::string &Key, bool DefaultValue);
bool MicroServiceConfigGetBool(const std::string &Key, bool DefaultValue);
std::uint64_t MicroServiceConfigGetInt(const std::string &Key, std::uint64_t DefaultValue);
std::string MicroServicePrivateEndPoint();
std::uint64_t MicroServiceID();

View File

@@ -431,11 +431,6 @@ namespace OpenWifi {
}
}
inline void Accepted() {
PrepareResponse(Poco::Net::HTTPResponse::HTTP_ACCEPTED);
Response->send();
}
inline void SendCompressedTarFile(const std::string &FileName, const std::string &Content) {
Response->setStatus(Poco::Net::HTTPResponse::HTTPStatus::HTTP_OK);
SetCommonHeaders();
@@ -557,8 +552,8 @@ namespace OpenWifi {
inline bool IsAuthorized(bool &Expired, bool &Contacted, bool SubOnly = false);
inline void ReturnObject(Poco::JSON::Object &Object, Poco::Net::HTTPResponse::HTTPStatus Status = Poco::Net::HTTPResponse::HTTP_OK) {
PrepareResponse(Status);
inline void ReturnObject(Poco::JSON::Object &Object) {
PrepareResponse();
if (Request != nullptr) {
// can we compress ???
auto AcceptedEncoding = Request->find("Accept-Encoding");

View File

@@ -35,6 +35,7 @@ namespace OpenWifi {
P.verificationDepth = 9;
P.loadDefaultCAs = root_ca_.empty();
P.cipherList = "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH";
P.dhUse2048Bits = true;
P.caLocation = cas_;
// P.securityLevel =
@@ -67,16 +68,6 @@ namespace OpenWifi {
Context->addCertificateAuthority(Issuing);
}
if (!client_cas_.empty()) {
// add certificates specified in clientcas
std::vector<Poco::Crypto::X509Certificate> Certs =
Poco::Net::X509Certificate::readPEM(client_cas_);
for (const auto &cert : Certs) {
Context->addChainCertificate(cert);
Context->addCertificateAuthority(cert);
}
}
Poco::Crypto::RSAKey Key("", key_file_, key_file_password_);
Context->usePrivateKey(Key);
@@ -343,4 +334,4 @@ namespace OpenWifi {
}
}
} // namespace OpenWifi
} // namespace OpenWifi

View File

@@ -45,7 +45,6 @@ namespace OpenWifi {
[[nodiscard]] inline auto KeyFile() const { return key_file_; };
[[nodiscard]] inline auto CertFile() const { return cert_file_; };
[[nodiscard]] inline auto RootCA() const { return root_ca_; };
[[nodiscard]] inline auto ClientCas() const { return client_cas_; };
[[nodiscard]] inline auto KeyFilePassword() const { return key_file_password_; };
[[nodiscard]] inline auto IssuerCertFile() const { return issuer_cert_file_; };
[[nodiscard]] inline auto Name() const { return name_; };

View File

@@ -58,9 +58,11 @@ namespace OpenWifi {
void UI_WebSocketClientServer::run() {
Running_ = true;
while (Running_) {
if(!Poco::Thread::trySleep(2000)) {
break;
}
Poco::Thread::trySleep(2000);
if (!Running_)
break;
std::lock_guard G(LocalMutex_);
for (const auto i : ToBeRemoved_) {
// std::cout << "Erasing old WS UI connection..." << std::endl;
@@ -210,16 +212,10 @@ namespace OpenWifi {
n = Client->second->WS_->receiveFrame(IncomingFrame, flags);
auto Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
if (n == -1) {
poco_warning(Logger(),
fmt::format("UI-EMPTY({}): {} Empty Frame flags {}.",
Client->second->Id_, Client->second->UserName_, flags));
return;
}
if (n == 0) {
poco_debug(Logger(),
fmt::format("CLOSE({}): {} UI Client is closing WS connection.",
Client->second->Id_, Client->second->UserName_));
fmt::format("CLOSE({}): {} UI Client is closing WS connection.",
Client->second->Id_, Client->second->UserName_));
return EndConnection(Client);
}
@@ -227,7 +223,7 @@ namespace OpenWifi {
case Poco::Net::WebSocket::FRAME_OP_PING: {
Client->second->WS_->sendFrame("", 0,
(int)Poco::Net::WebSocket::FRAME_OP_PONG |
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
} break;
case Poco::Net::WebSocket::FRAME_OP_PONG: {
} break;
@@ -237,11 +233,6 @@ namespace OpenWifi {
Client->second->Id_, Client->second->UserName_));
return EndConnection(Client);
} break;
case Poco::Net::WebSocket::FRAME_OP_CONT: {
poco_warning(Logger(),
fmt::format("CONT({}): {} Unexpected CONT Frame - Ignoring.",
Client->second->Id_, Client->second->UserName_));
} break;
case Poco::Net::WebSocket::FRAME_OP_TEXT: {
constexpr const char *DropMessagesCommand = "drop-notifications";
IncomingFrame.append(0);
@@ -330,4 +321,4 @@ namespace OpenWifi {
}
}
} // namespace OpenWifi
} // namespace OpenWifi

View File

@@ -7,59 +7,57 @@
#include <vector>
#include <string>
#include "ow_constants.h"
namespace OpenWifi {
inline const std::vector<std::pair<std::string, std::string>> DefaultDeviceTypeList{
{"actiontec_web7200", Platforms::AP},
{"cig_wf186w", Platforms::AP},
{"cig_wf188n", Platforms::AP},
{"cig_wf194c4", Platforms::AP},
{"cig_wf196", Platforms::AP},
{"cig_wf196-ca", Platforms::AP},
{"cig_wf196-ca-ath12", Platforms::AP},
{"cig_wf196-us", Platforms::AP},
{"cig_wf610d", Platforms::AP},
{"cig_wf660a", Platforms::AP},
{"cig_wf808", Platforms::AP},
{"cybertan_eww622-a1", Platforms::AP},
{"edgecore_eap101", Platforms::AP},
{"edgecore_eap101-ath12", Platforms::AP},
{"edgecore_eap102", Platforms::AP},
{"edgecore_eap104", Platforms::AP},
{"edgecore_eap104-ath12", Platforms::AP},
{"edgecore_ecs4100-12ph", Platforms::AP},
{"edgecore_ecw5211", Platforms::AP},
{"edgecore_ecw5410", Platforms::AP},
{"edgecore_oap100", Platforms::AP},
{"edgecore_spw2ac1200", Platforms::SWITCH},
{"edgecore_spw2ac1200-lan-poe", Platforms::SWITCH},
{"edgecore_ssw2ac2600", Platforms::SWITCH},
{"hfcl_ion4", Platforms::AP},
{"hfcl_ion4x", Platforms::AP},
{"hfcl_ion4x_2", Platforms::AP},
{"hfcl_ion4xe", Platforms::AP},
{"hfcl_ion4xi", Platforms::AP},
{"indio_um-305ac", Platforms::AP},
{"indio_um-305ax", Platforms::AP},
{"indio_um-310ax-v1", Platforms::AP},
{"indio_um-325ac", Platforms::AP},
{"indio_um-510ac-v3", Platforms::AP},
{"indio_um-510axm-v1", Platforms::AP},
{"indio_um-510axp-v1", Platforms::AP},
{"indio_um-550ac", Platforms::AP},
{"linksys_e8450-ubi", Platforms::AP},
{"linksys_ea6350-v4", Platforms::AP},
{"linksys_ea8300", Platforms::AP},
{"liteon_wpx8324", Platforms::AP},
{"meshpp_s618_cp01", Platforms::AP},
{"meshpp_s618_cp03", Platforms::AP},
{"udaya_a5-id2", Platforms::AP},
{"wallys_dr40x9", Platforms::AP},
{"wallys_dr6018", Platforms::AP},
{"wallys_dr6018_v4", Platforms::AP},
{"x64_vm", Platforms::AP},
{"yuncore_ax840", Platforms::AP},
{"yuncore_fap640", Platforms::AP},
{"yuncore_fap650", Platforms::AP}};
{"actiontec_web7200", "AP"},
{"cig_wf186w", "AP"},
{"cig_wf188n", "AP"},
{"cig_wf194c4", "AP"},
{"cig_wf196", "AP"},
{"cig_wf196-ca", "AP"},
{"cig_wf196-ca-ath12", "AP"},
{"cig_wf196-us", "AP"},
{"cig_wf610d", "AP"},
{"cig_wf660a", "AP"},
{"cig_wf808", "AP"},
{"cybertan_eww622-a1", "AP"},
{"edgecore_eap101", "AP"},
{"edgecore_eap101-ath12", "AP"},
{"edgecore_eap102", "AP"},
{"edgecore_eap104", "AP"},
{"edgecore_eap104-ath12", "AP"},
{"edgecore_ecs4100-12ph", "AP"},
{"edgecore_ecw5211", "AP"},
{"edgecore_ecw5410", "AP"},
{"edgecore_oap100", "AP"},
{"edgecore_spw2ac1200", "SWITCH"},
{"edgecore_spw2ac1200-lan-poe", "SWITCH"},
{"edgecore_ssw2ac2600", "SWITCH"},
{"hfcl_ion4", "AP"},
{"hfcl_ion4x", "AP"},
{"hfcl_ion4x_2", "AP"},
{"hfcl_ion4xe", "AP"},
{"hfcl_ion4xi", "AP"},
{"indio_um-305ac", "AP"},
{"indio_um-305ax", "AP"},
{"indio_um-310ax-v1", "AP"},
{"indio_um-325ac", "AP"},
{"indio_um-510ac-v3", "AP"},
{"indio_um-510axm-v1", "AP"},
{"indio_um-510axp-v1", "AP"},
{"indio_um-550ac", "AP"},
{"linksys_e8450-ubi", "AP"},
{"linksys_ea6350-v4", "AP"},
{"linksys_ea8300", "AP"},
{"liteon_wpx8324", "AP"},
{"meshpp_s618_cp01", "AP"},
{"meshpp_s618_cp03", "AP"},
{"udaya_a5-id2", "AP"},
{"wallys_dr40x9", "AP"},
{"wallys_dr6018", "AP"},
{"wallys_dr6018_v4", "AP"},
{"x64_vm", "AP"},
{"yuncore_ax840", "AP"},
{"yuncore_fap640", "AP"},
{"yuncore_fap650", "AP"}};
}

View File

@@ -433,10 +433,6 @@ namespace OpenWifi::RESTAPI::Errors {
static const struct msg InvalidRRMAction { 1192, "Invalid RRM Action." };
static const struct msg InvalidPackageURL { 1193, "Invalid URL, must start with http:// or https://." };
static const struct msg FailedToDownload { 1194, "Failed to download package." };
static const struct msg FailedToDecompress { 1195, "Failed to decompress package data."};
static const struct msg SimulationDoesNotExist {
7000, "Simulation Instance ID does not exist."
};
@@ -554,10 +550,6 @@ namespace OpenWifi::RESTAPI::Protocol {
static const char *DEBUG = "debug";
static const char *SCRIPT = "script";
static const char *TIMEOUT = "timeout";
static const char *PACKAGE = "package";
static const char *PACKAGES = "packages";
static const char *PACKAGEINST = "packageInstall";
static const char *PACKAGEDEL = "packageDelete";
static const char *NEWPASSWORD = "newPassword";
static const char *USERS = "users";
@@ -573,7 +565,6 @@ 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";
@@ -588,10 +579,6 @@ namespace OpenWifi::RESTAPI::Protocol {
static const char *INTERVAL = "interval";
static const char *UI = "UI";
static const char *BANDWIDTH = "bandwidth";
static const char *FIXEDCONFIG = "fixedconfig";
static const char *CABLEDIAGNOSTICS = "cable-diagnostics";
static const char *REENROLL = "reenroll";
} // namespace OpenWifi::RESTAPI::Protocol
namespace OpenWifi::uCentralProtocol {
@@ -620,7 +607,6 @@ namespace OpenWifi::uCentralProtocol {
static const char *CFGPENDING = "cfgpending";
static const char *RECOVERY = "recovery";
static const char *COMPRESS_64 = "compress_64";
static const char *COMPRESS_SZ = "compress_sz";
static const char *CAPABILITIES = "capabilities";
static const char *REQUEST_UUID = "request_uuid";
static const char *SANITY = "sanity";
@@ -677,9 +663,6 @@ namespace OpenWifi::uCentralProtocol {
static const char *SIGNATURE = "signature";
static const char *INFO = "info";
static const char *DATE = "date";
static const char *PACKAGE = "package";
static const char *PACKAGES = "packages";
static const char *CATEGORY = "category";
static const char *SERIALNUMBER = "serialNumber";
static const char *COMPATIBLE = "compatible";
@@ -704,15 +687,9 @@ 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";
static const char *FIXEDCONFIG = "fixedconfig";
static const char *CABLEDIAGNOSTICS = "cable-diagnostics";
static const char *REENROLL = "reenroll";
static const char *OPERATION = "op";
} // namespace OpenWifi::uCentralProtocol
namespace OpenWifi::uCentralProtocol::Events {
@@ -747,7 +724,7 @@ namespace OpenWifi::uCentralProtocol::Events {
ET_EVENT,
ET_WIFISCAN,
ET_ALARM,
ET_REBOOTLOG,
ET_REBOOTLOG
};
inline EVENT_MSG EventFromString(const std::string &Method) {
@@ -808,11 +785,6 @@ namespace OpenWifi::APCommands {
rrm,
certupdate,
transfer,
powercycle,
fixedconfig,
cablediagnostics,
reenroll,
package,
unknown
};
@@ -827,9 +799,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::POWERCYCLE,
RESTAPI::Protocol::FIXEDCONFIG, RESTAPI::Protocol::CABLEDIAGNOSTICS,
RESTAPI::Protocol::REENROLL, RESTAPI::Protocol::PACKAGE
RESTAPI::Protocol::TRANSFER
};
inline const char *to_string(Commands Cmd) { return uCentralAPCommands[(uint8_t)Cmd]; }
@@ -858,11 +828,6 @@ namespace OpenWifi::Provisioning::DeviceClass {
} // namespace OpenWifi::Provisioning::DeviceClass
namespace OpenWifi::Platforms {
static const std::string AP = "ap";
static const std::string SWITCH = "switch";
}
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

View File

@@ -590,26 +590,6 @@ namespace OpenWifi::Utils {
return false;
}
//
// Compress given data using utility function and encode it in base64 format.
//
bool CompressAndEncodeBase64(const std::string& UnCompressedData, std::string& CompressedBase64Data) {
unsigned long CompressedDataSize = UnCompressedData.size();
std::vector<Bytef> CompressedData(CompressedDataSize);
auto status = compress(&CompressedData[0], &CompressedDataSize,
(Bytef*) UnCompressedData.c_str(), UnCompressedData.size());
if (status == Z_OK) {
CompressedBase64Data = OpenWifi::Utils::base64encode(&CompressedData[0], CompressedDataSize);
}
else {
// failed to compress data
return false;
}
return true;
}
bool IsAlphaNumeric(const std::string &s) {
return std::all_of(s.begin(), s.end(), [](char c) -> bool { return isalnum(c); });
}
@@ -888,15 +868,78 @@ namespace OpenWifi::Utils {
return password;
}
/*
Note that these 2 functions aren't used. They have been removed due to this deprecation warning:
// Function to query NAPTR records for a domain and return them in a vector
#47 3.825 /owgw/src/framework/utils.cpp: In function 'std::vector<OpenWifi::Utils::NAPTRRecord> OpenWifi::Utils::getNAPTRRecords(const std::string&)':
#47 3.825 /owgw/src/framework/utils.cpp:915:28: warning: 'int ns_sprintrr(const ns_msg*, const ns_rr*, const char*, const char*, char*, size_t)' is deprecated [-Wdeprecated-declarations]
// Function to query NAPTR records for a domain and return them in a vector
std::vector<NAPTRRecord> getNAPTRRecords(const std::string& domain) {
std::vector<NAPTRRecord> naptrRecords;
unsigned char buf[4096];
ns_msg handle;
ns_initparse(buf, NS_PACKETSZ, &handle);
// Query NAPTR records for the given domain
int response = res_query(domain.c_str(), ns_c_in, ns_t_naptr, buf, sizeof(buf));
if (response < 0) {
return naptrRecords;
}
if(ns_initparse(buf, response, &handle) < 0) {
return naptrRecords;
}
// Iterate through the DNS response and extract NAPTR records
int count = ns_msg_count(handle, ns_s_an);
for (int i = 0; i < count; ++i) {
ns_rr rr;
if (ns_parserr(&handle, ns_s_an, i, &rr) == 0) {
char rdata[256];
ns_sprintrr(&handle, &rr, nullptr, nullptr, rdata, sizeof(rdata));
NAPTRRecord record;
std::istringstream os(rdata);
os >> record.name >> record.ttl >> record.rclass >> record.rtype >> record.order >> record.preference >> record.flags
>> record.service >> record.regexp >> record.replacement;
naptrRecords.push_back(record);
}
}
return naptrRecords;
}
std::vector<SrvRecord> getSRVRecords(const std::string& domain) {
#47 3.833 /owgw/src/framework/utils.cpp: In function 'std::vector<OpenWifi::Utils::SrvRecord> OpenWifi::Utils::getSRVRecords(const std::string&)':
#47 3.833 /owgw/src/framework/utils.cpp:952:28: warning: 'int ns_sprintrr(const ns_msg*, const ns_rr*, const char*, const char*, char*, size_t)' is deprecated [-Wdeprecated-declarations]
*/
std::vector<SrvRecord> srvRecords;
// Buffer to hold the DNS response
unsigned char buf[4096];
ns_msg handle;
ns_initparse(buf, NS_PACKETSZ, &handle);
// Query NAPTR records for the given domain
int response = res_query(domain.c_str(), ns_c_in, ns_t_srv, buf, sizeof(buf));
if (response < 0) {
std::cerr << "DNS query failed for " << domain << ": " << hstrerror(h_errno) << std::endl;
return srvRecords;
}
if(ns_initparse(buf, response, &handle) < 0) {
return srvRecords;
}
// Iterate through the DNS response and extract NAPTR records
int count = ns_msg_count(handle, ns_s_an);
for (int i = 0; i < count; ++i) {
ns_rr rr;
if (ns_parserr(&handle, ns_s_an, i, &rr) == 0) {
char rdata[256];
ns_sprintrr(&handle, &rr, nullptr, nullptr, rdata, sizeof(rdata));
SrvRecord record;
std::istringstream os(rdata);
os >> record.name >> record.ttl >> record.rclass >> record.rtype >> record.pref >> record.weight >>
record.port >> record.srvname ;
srvRecords.push_back(record);
}
}
return srvRecords;
}
} // namespace OpenWifi::Utils

View File

@@ -151,8 +151,6 @@ namespace OpenWifi::Utils {
bool ExtractBase64CompressedData(const std::string &CompressedData,
std::string &UnCompressedData, uint64_t compress_sz);
bool CompressAndEncodeBase64(const std::string& UnCompressedData, std::string& CompressedData);
inline bool match(const char* first, const char* second)
{
// If we reach at the end of both strings, we are done
@@ -298,10 +296,8 @@ namespace OpenWifi::Utils {
std::string replacement;
};
// removed due to deprecation: see utils.cpp
// Function to query NAPTR records for a domain and return them in a vector
//std::vector<NAPTRRecord> getNAPTRRecords(const std::string& domain);
// Function to query NAPTR records for a domain and return them in a vector
std::vector<NAPTRRecord> getNAPTRRecords(const std::string& domain);
struct SrvRecord {
std::string name;
std::string ttl;
@@ -313,8 +309,7 @@ namespace OpenWifi::Utils {
std::string srvname;
};
// removed due to deprecation: see utils.cpp
// std::vector<SrvRecord> getSRVRecords(const std::string& domain);
std::vector<SrvRecord> getSRVRecords(const std::string& domain);
struct HostNameServerResult{
std::string Hostname;

View File

@@ -14,7 +14,6 @@
#include "nlohmann/json.hpp"
#include "Poco/NObserver.h"
#include <Poco/Net/Context.h>
#include "Poco/Net/SocketNotification.h"
#include "Poco/Net/NetException.h"
#include "Poco/Net/WebSocketImpl.h"
@@ -72,7 +71,6 @@ namespace OpenWifi {
const auto &RootCas =
MicroServiceConfigPath("ucentral.websocket.host.0.rootca", "");
const auto &Cas = MicroServiceConfigPath("ucentral.websocket.host.0.cas", "");
const auto &ClientCasFile = MicroServiceConfigPath("ucentral.websocket.host.0.clientcas", "");
Poco::Net::Context::Params P;
@@ -88,7 +86,6 @@ namespace OpenWifi {
Poco::Crypto::X509Certificate Cert(CertFileName);
Poco::Crypto::X509Certificate Root(RootCaFileName);
Poco::Crypto::X509Certificate Issuing(IssuerFileName);
std::vector<Poco::Crypto::X509Certificate> ClientCasCerts;
Poco::Crypto::RSAKey Key("", KeyFileName, KeyPassword);
DeviceSecureContext->useCertificate(Cert);
@@ -96,11 +93,7 @@ namespace OpenWifi {
DeviceSecureContext->addCertificateAuthority(Root);
DeviceSecureContext->addChainCertificate(Issuing);
DeviceSecureContext->addCertificateAuthority(Issuing);
ClientCasCerts = Poco::Net::X509Certificate::readPEM(ClientCasFile);
for (const auto &cert : ClientCasCerts) {
DeviceSecureContext->addChainCertificate(cert);
DeviceSecureContext->addCertificateAuthority(cert);
}
DeviceSecureContext->addCertificateAuthority(Root);
DeviceSecureContext->enableSessionCache(true);
DeviceSecureContext->setSessionCacheSize(0);
DeviceSecureContext->setSessionTimeout(120);
@@ -580,16 +573,14 @@ namespace OpenWifi {
try {
Client = Clients_.find(pNf->socket().impl()->sockfd());
if (Client == end(Clients_)) {
poco_warning(Logger(),
fmt::format("Cannot find client socket: {}",
pNf->socket().impl()->sockfd()));
poco_warning(Logger(), fmt::format("Cannot find client socket: {}",
pNf->socket().impl()->sockfd()));
return;
}
Connection = Client->second;
if(Connection->WSSocket_==nullptr || Connection->WSSocket_->impl()==nullptr) {
poco_warning(Logger(),
fmt::format("WebSocket is not valid: {}",
Connection->SerialNumber_));
poco_warning(Logger(), fmt::format("WebSocket is no valid: {}",
Connection->SerialNumber_));
return;
}
@@ -598,25 +589,15 @@ namespace OpenWifi {
auto ReceivedBytes = Connection->WSSocket_->receiveFrame(FrameBuffer, sizeof(FrameBuffer), flags);
auto Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
if (ReceivedBytes == -1) {
poco_trace(Logger(),
fmt::format("WS-EMPTY{}: Non-blocking try-again empty Frame: flags {}",
Connection->SerialNumber_, flags));
return;
}
switch (Op) {
case Poco::Net::WebSocket::FRAME_OP_PING: {
Connection->WSSocket_->sendFrame("", 0,
(int)Poco::Net::WebSocket::FRAME_OP_PONG |
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
(int)Poco::Net::WebSocket::FRAME_OP_PONG |
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
} break;
case Poco::Net::WebSocket::FRAME_OP_PONG: {
} break;
case Poco::Net::WebSocket::FRAME_OP_TEXT: {
if (ReceivedBytes == 0) {
EndConnection(Connection,__func__,__LINE__);
@@ -643,29 +624,19 @@ namespace OpenWifi {
}
}
} break;
case Poco::Net::WebSocket::FRAME_OP_BINARY: {
if (ReceivedBytes == 0) {
EndConnection(Connection,__func__,__LINE__);
return;
} else {
poco_trace(Logger(),
fmt::format("Sending {} key strokes to device.", ReceivedBytes));
fmt::format("Sending {} key strokes to device.", ReceivedBytes));
if (!RTTYS_server().KeyStrokes(Connection, FrameBuffer, ReceivedBytes)) {
EndConnection(Connection,__func__,__LINE__);
return;
}
}
} break;
case Poco::Net::WebSocket::FRAME_OP_CONT: {
// may have to handle this, but not sure whether it's a continuation for text or
// binary, seems to be a hole in the protocol.
poco_warning(Logger(),
fmt::format("CONT Frame {} received, ignoring for now.",
ReceivedBytes));
}
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
EndConnection(Connection,__func__,__LINE__);
return;
@@ -711,8 +682,8 @@ namespace OpenWifi {
if (Connection->WSSocket_ != nullptr && Connection->WSSocket_->impl()!= nullptr) {
try {
Connection->WSSocket_->sendFrame(Buf, len,
(int) Poco::Net::WebSocket::FRAME_FLAG_FIN |
(int) Poco::Net::WebSocket::FRAME_OP_BINARY);
Poco::Net::WebSocket::FRAME_FLAG_FIN |
Poco::Net::WebSocket::FRAME_OP_BINARY);
return;
} catch (...) {
poco_error(Logger(), "SendData shutdown.");
@@ -1014,9 +985,8 @@ namespace OpenWifi {
}
bool RTTYS_server::SendToClient(Poco::Net::WebSocket &WebSocket, const u_char *Buf, int len) {
WebSocket.sendFrame(Buf, len,
(int) Poco::Net::WebSocket::FRAME_FLAG_FIN |
(int) Poco::Net::WebSocket::FRAME_OP_BINARY);
WebSocket.sendFrame(
Buf, len, Poco::Net::WebSocket::FRAME_FLAG_FIN | Poco::Net::WebSocket::FRAME_OP_BINARY);
return true;
}
@@ -1147,4 +1117,4 @@ namespace OpenWifi {
RTTYS_EndPoint::~RTTYS_EndPoint() {
}
} // namespace OpenWifi
} // namespace OpenWifi

View File

@@ -644,7 +644,21 @@ namespace OpenWifi {
uint64_t Size = FileContent.str().size();
Poco::Data::Session Sess = Pool_->get();
Sess.begin();
Poco::Data::Statement Statement(Sess);
std::string StatementStr;
// Get the existing command
StatementStr =
"UPDATE CommandList SET WaitingForFile=?, AttachDate=?, AttachSize=? WHERE UUID=?";
Statement << ConvertParams(StatementStr), Poco::Data::Keywords::use(WaitForFile),
Poco::Data::Keywords::use(Now), Poco::Data::Keywords::use(Size),
Poco::Data::Keywords::use(UUID);
Statement.execute();
Sess.commit();
if (Size < FileUploader()->MaxSize()) {
Poco::Data::BLOB TheBlob;
@@ -664,24 +678,9 @@ namespace OpenWifi {
Insert.execute();
Sess.commit();
} else {
poco_warning(Logger(),
fmt::format("File {} is too large ({} >= {} max bytes).",
UUID, Size, FileUploader()->MaxSize()));
poco_warning(Logger(), fmt::format("File {} is too large.", UUID));
}
// update CommandList here to ensure that file us uploaded
Sess.begin();
Poco::Data::Statement Statement(Sess);
std::string StatementStr;
StatementStr =
"UPDATE CommandList SET WaitingForFile=?, AttachDate=?, AttachSize=? WHERE UUID=?";
Statement << ConvertParams(StatementStr), Poco::Data::Keywords::use(WaitForFile),
Poco::Data::Keywords::use(Now), Poco::Data::Keywords::use(Size),
Poco::Data::Keywords::use(UUID);
Statement.execute();
Sess.commit();
return true;
} catch (const Poco::Exception &E) {
Logger().log(E);
@@ -690,7 +689,7 @@ namespace OpenWifi {
}
bool Storage::GetAttachedFileContent(std::string &UUID, const std::string &SerialNumber,
std::string &FileContent, std::string &Type, int &WaitingForFile) {
std::string &FileContent, std::string &Type) {
try {
Poco::Data::BLOB L;
/*
@@ -703,10 +702,10 @@ namespace OpenWifi {
Poco::Data::Statement Select1(Sess);
std::string TmpSerialNumber;
std::string st1{"SELECT SerialNumber, Command , WaitingForFile FROM CommandList WHERE UUID=?"};
std::string st1{"SELECT SerialNumber, Command FROM CommandList WHERE UUID=?"};
std::string Command;
Select1 << ConvertParams(st1), Poco::Data::Keywords::into(TmpSerialNumber),
Poco::Data::Keywords::into(Command), Poco::Data::Keywords::into(WaitingForFile), Poco::Data::Keywords::use(UUID);
Poco::Data::Keywords::into(Command), Poco::Data::Keywords::use(UUID);
Select1.execute();
if (TmpSerialNumber != SerialNumber) {
@@ -826,4 +825,4 @@ namespace OpenWifi {
return false;
}
} // namespace OpenWifi
} // namespace OpenWifi

View File

@@ -19,39 +19,37 @@ namespace OpenWifi {
"Models TEXT, "
"Description TEXT, "
"Created BIGINT , "
"LastModified BIGINT, Platform TEXT )"};
"LastModified BIGINT)"};
const static std::string DB_DefConfig_SelectFields{"Name, "
"Configuration, "
"Models, "
"Description, "
"Created, "
"LastModified, Platform "};
"LastModified "};
const static std::string DB_DefConfig_InsertValues{"?,?,?,?,?,?,?"};
const static std::string DB_DefConfig_InsertValues{"?,?,?,?,?,?"};
typedef Poco::Tuple<std::string, std::string, std::string, std::string, uint64_t, uint64_t, std::string>
typedef Poco::Tuple<std::string, std::string, std::string, std::string, uint64_t, uint64_t>
DefConfigRecordTuple;
typedef std::vector<DefConfigRecordTuple> DefConfigRecordList;
void Convert(const DefConfigRecordTuple &R, GWObjects::DefaultConfiguration &T) {
T.name = R.get<0>();
T.configuration = R.get<1>();
T.models = RESTAPI_utils::to_object_array(R.get<2>());
T.description = R.get<3>();
T.created = R.get<4>();
T.lastModified = R.get<5>();
T.platform = R.get<6>();
T.Name = R.get<0>();
T.Configuration = R.get<1>();
T.Models = RESTAPI_utils::to_object_array(R.get<2>());
T.Description = R.get<3>();
T.Created = R.get<4>();
T.LastModified = R.get<5>();
}
void Convert(const GWObjects::DefaultConfiguration &R, DefConfigRecordTuple &T) {
T.set<0>(R.name);
T.set<1>(R.configuration);
T.set<2>(RESTAPI_utils::to_string(R.models));
T.set<3>(R.description);
T.set<4>(R.created);
T.set<5>(R.lastModified);
T.set<6>(R.platform);
T.set<0>(R.Name);
T.set<1>(R.Configuration);
T.set<2>(RESTAPI_utils::to_string(R.Models));
T.set<3>(R.Description);
T.set<4>(R.Created);
T.set<5>(R.LastModified);
}
bool Storage::CreateDefaultConfiguration(std::string &Name,
@@ -71,7 +69,7 @@ namespace OpenWifi {
if (!TmpName.empty())
return false;
Config::Config Cfg(DefConfig.configuration);
Config::Config Cfg(DefConfig.Configuration);
if (Cfg.Valid()) {
Sess.begin();
@@ -126,10 +124,10 @@ namespace OpenWifi {
Poco::Data::Session Sess = Pool_->get();
Sess.begin();
Poco::Data::Statement Update(Sess);
DefConfig.lastModified = Now;
DefConfig.LastModified = Now;
std::string St{"UPDATE DefaultConfigs SET Name=?, Configuration=?, Models=?, "
"Description=?, Created=? , LastModified=? , Platform=? WHERE Name=?"};
"Description=?, Created=? , LastModified=? WHERE Name=?"};
DefConfigRecordTuple R;
Convert(DefConfig, R);
@@ -221,30 +219,31 @@ namespace OpenWifi {
return false;
}
bool Storage::FindDefaultConfigurationForModel(const std::string &DeviceModel, const std::string &Platform,
GWObjects::DefaultConfiguration &Config) {
bool Storage::FindDefaultConfigurationForModel(const std::string &Model,
GWObjects::DefaultConfiguration &DefConfig) {
try {
DefConfigRecordList DefConfigs;
DefConfigRecordList Records;
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement Select(Sess);
Select << "SELECT " + DB_DefConfig_SelectFields + " FROM DefaultConfigs",
Poco::Data::Keywords::into(DefConfigs);
Poco::Data::Keywords::into(Records);
Select.execute();
for (const auto &DefConfig : DefConfigs) {
GWObjects::DefaultConfiguration C;
Convert(DefConfig, C);
for (const auto &Model : C.models) {
if ((Model == "*" || Model == DeviceModel) && (Config.platform == Platform)){
Config = C;
for (const auto &i : Records) {
GWObjects::DefaultConfiguration Config;
Convert(i, Config);
for (const auto &j : Config.Models) {
if (j == "*" || j == Model) {
DefConfig = Config;
return true;
}
}
}
Logger().information(
fmt::format("AUTO-PROVISIONING: no default configuration for model:{}", DeviceModel));
fmt::format("AUTO-PROVISIONING: no default configuration for model:{}", Model));
return false;
} catch (const Poco::Exception &E) {
poco_warning(Logger(), fmt::format("{}: Failed with: {}", std::string(__func__),
E.displayText()));

View File

@@ -172,18 +172,14 @@ namespace OpenWifi {
R.set<30>(D.connectReason);
}
bool Storage::GetDeviceCount(uint64_t &Count, const std::string &platform) {
bool Storage::GetDeviceCount(uint64_t &Count) {
try {
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement Select(Sess);
if(!platform.empty()) {
std::string st{"SELECT COUNT(*) FROM Devices WHERE DeviceType='" + platform + "'"};
Select << st, Poco::Data::Keywords::into(Count);
} else {
std::string st{"SELECT COUNT(*) FROM Devices"};
Select << st, Poco::Data::Keywords::into(Count);
}
std::string st{"SELECT COUNT(*) FROM Devices"};
Select << st, Poco::Data::Keywords::into(Count);
Select.execute();
return true;
} catch (const Poco::Exception &E) {
@@ -194,36 +190,16 @@ namespace OpenWifi {
bool Storage::GetDeviceSerialNumbers(uint64_t From, uint64_t HowMany,
std::vector<std::string> &SerialNumbers,
const std::string &orderBy,
const std::string &platform, bool includeProvisioned) {
const std::string &orderBy) {
try {
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement Select(Sess);
std::string st;
std::string whereClause = "";
if (!platform.empty()) {
if (includeProvisioned == false) {
//whereClause = fmt::format("WHERE entity='' and venue='' and DeviceType='" + platform + "'");
whereClause = fmt::format("WHERE entity='' and venue='' and DeviceType='{}'", platform);
} else {
//whereClause = fmt::format("WHERE DeviceType='" + platform + "'");
whereClause = fmt::format("WHERE DeviceType='{}'", platform);
}
//st = "SELECT SerialNumber From Devices WHERE DeviceType='" + platform + "' ";
} else {
if (includeProvisioned == false) {
whereClause = fmt::format("WHERE entity='' and venue=''");
}
//st = "SELECT SerialNumber From Devices ";
}
st = fmt::format("SELECT SerialNumber From Devices {}", whereClause);
if (orderBy.empty())
st += " ORDER BY SerialNumber ASC ";
st = "SELECT SerialNumber From Devices ORDER BY SerialNumber ASC ";
else
st += orderBy;
st = "SELECT SerialNumber From Devices " + orderBy;
Select << st + ComputeRange(From, HowMany), Poco::Data::Keywords::into(SerialNumbers);
Select.execute();
@@ -289,7 +265,7 @@ namespace OpenWifi {
D.pendingUUID = 0;
D.LastConfigurationChange = Utils::Now();
SetCurrentConfigurationID(Utils::SerialNumberToInt(SerialNumber), D.UUID);
ConfigurationCache().Add(Utils::SerialNumberToInt(SerialNumber), D.UUID);
Poco::Data::Session Sess = Pool_->get();
Sess.begin();
@@ -322,30 +298,19 @@ namespace OpenWifi {
bool Storage::CompleteDeviceConfigurationChange(Poco::Data::Session & Session, std::string & SerialNumber) {
try {
GWObjects::Device D;
if (!GetDevice(SerialNumber, D))
return false;
if(!D.pendingConfiguration.empty()) {
D.Configuration = D.pendingConfiguration;
D.pendingConfiguration.clear();
}
if(D.pendingUUID!=0) {
D.UUID = D.pendingUUID;
D.pendingUUID = 0;
}
// if this is a broken device, fix it...
if(D.UUID==0) {
Config::Config Cfg(D.Configuration);
if(Cfg.Valid()) {
D.UUID = Cfg.UUID();
}
}
if(D.pendingConfiguration.empty())
return true;
D.Configuration = D.pendingConfiguration;
D.pendingConfiguration.clear();
D.UUID = D.pendingUUID;
D.pendingUUID = 0;
D.LastConfigurationChange = Utils::Now();
SetCurrentConfigurationID(Utils::SerialNumberToInt(SerialNumber), D.UUID);
ConfigurationCache().Add(Utils::SerialNumberToInt(SerialNumber), D.UUID);
Session.begin();
Poco::Data::Statement Update(Session);
@@ -560,7 +525,7 @@ namespace OpenWifi {
} catch (const Poco::Exception &E) {
Logger().log(E);
}
return false;
return true;
}
bool Storage::CreateDefaultDevice(Poco::Data::Session &Session, std::string &SerialNumber, const Config::Capabilities &Caps,
@@ -592,31 +557,21 @@ namespace OpenWifi {
}
if (!Found && AP_WS_Server()->UseDefaults() &&
FindDefaultConfigurationForModel(Caps.Compatible(), Caps.Platform(), DefConfig)) {
Config::Config NewConfig(DefConfig.configuration);
FindDefaultConfigurationForModel(Caps.Compatible(), DefConfig)) {
Config::Config NewConfig(DefConfig.Configuration);
NewConfig.SetUUID(Now);
D.Configuration = NewConfig.get();
} else if (!Found) {
if(Caps.Platform()==Platforms::AP) {
Config::Config NewConfig;
NewConfig.SetUUID(Now);
D.Configuration = NewConfig.get();
} else {
Poco::JSON::Object Obj;
Obj.set("uuid", Now);
std::ostringstream os;
Obj.stringify(os);
D.Configuration = os.str();
}
Config::Config NewConfig;
NewConfig.SetUUID(Now);
D.Configuration = NewConfig.get();
}
// We need to insert the country code according to the IP in the radios section...
D.locale = InsertRadiosCountyRegulation(D.Configuration, IPAddress);
D.SerialNumber = Poco::toLower(SerialNumber);
D.Compatible = Caps.Compatible();
if(D.Compatible.empty())
D.Compatible = Caps.Model();
D.DeviceType = Poco::toLower(Caps.Platform());
D.DeviceType = Daemon()->IdentifyDevice(D.Compatible);
D.MACAddress = Utils::SerialToMAC(SerialNumber);
D.Manufacturer = Caps.Model();
D.Firmware = Firmware;
@@ -665,22 +620,6 @@ namespace OpenWifi {
return false;
}
std::string Storage::GetPlatform(const std::string &SerialNumber) {
try {
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement Select(Sess);
std::string St = fmt::format("SELECT DeviceType FROM Devices WHERE SerialNumber='{}'", SerialNumber);
std::string Platform;
Select << ConvertParams(St), Poco::Data::Keywords::into(Platform);
Select.execute();
return Platform;
} catch (const Poco::Exception &E) {
Logger().log(E);
}
return "";
}
bool Storage::DeleteDevice(std::string &SerialNumber) {
try {
std::vector<std::string> TableNames{"Devices", "Statistics", "CommandList",
@@ -769,14 +708,17 @@ namespace OpenWifi {
return false;
}
bool Storage::GetDevice(Poco::Data::Session &Session, const std::string &SerialNumber, GWObjects::Device &DeviceDetails) {
bool Storage::GetDevice(Poco::Data::Session &Session, std::string &SerialNumber, GWObjects::Device &DeviceDetails) {
try {
Poco::Data::Statement Select(Session);
std::string St = fmt::format("SELECT {} FROM Devices WHERE SerialNumber='{}'", DB_DeviceSelectFields, SerialNumber);
std::string St{"SELECT " + DB_DeviceSelectFields +
" FROM Devices WHERE SerialNumber=?"};
DeviceRecordTuple R;
Select << St, Poco::Data::Keywords::into(R);
Select << ConvertParams(St), Poco::Data::Keywords::into(R),
Poco::Data::Keywords::use(SerialNumber);
Select.execute();
if (Select.rowsExtracted() == 0)
return false;
ConvertDeviceRecord(R, DeviceDetails);
@@ -787,7 +729,7 @@ namespace OpenWifi {
return false;
}
bool Storage::GetDevice(const std::string &SerialNumber, GWObjects::Device &DeviceDetails) {
bool Storage::GetDevice(std::string &SerialNumber, GWObjects::Device &DeviceDetails) {
try {
auto Sess = Pool_->get();
return GetDevice(Sess, SerialNumber, DeviceDetails);
@@ -797,7 +739,7 @@ namespace OpenWifi {
return false;
}
bool Storage::GetDevice(LockedDbSession &Session, const std::string &SerialNumber, GWObjects::Device &DeviceDetails) {
bool Storage::GetDevice(LockedDbSession &Session, std::string &SerialNumber, GWObjects::Device &DeviceDetails) {
try {
std::lock_guard Lock(Session.Mutex());
return GetDevice(Session.Session(), SerialNumber, DeviceDetails);
@@ -875,37 +817,17 @@ namespace OpenWifi {
}
bool Storage::GetDevices(uint64_t From, uint64_t HowMany,
std::vector<GWObjects::Device> &Devices, const std::string &orderBy, const std::string &platform,
bool includeProvisioned) {
std::vector<GWObjects::Device> &Devices, const std::string &orderBy) {
DeviceRecordList Records;
try {
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement Select(Sess);
std::string st;
std::string whereClause = "";
if(platform.empty()) {
if (includeProvisioned == false) {
whereClause = fmt::format("WHERE entity='' and venue=''");
}
} else {
if (includeProvisioned == false) {
whereClause = fmt::format("WHERE DeviceType='{}' and entity='' and venue=''",platform);
} else {
whereClause = fmt::format("WHERE DeviceType='{}'", platform);
}
}
st =
fmt::format("SELECT {} FROM Devices {} {} {}", DB_DeviceSelectFields, whereClause,
orderBy.empty() ? " ORDER BY SerialNumber ASC " : orderBy,
ComputeRange(From, HowMany));
//Logger().information(fmt::format(" GetDevices st is {} ", st));
// std::string st{"SELECT " + DB_DeviceSelectFields + " FROM Devices " + orderBy.empty()
// ? " ORDER BY SerialNumber ASC " + ComputeRange(From, HowMany)};
std::string st = fmt::format("SELECT {} FROM Devices {} {}", DB_DeviceSelectFields,
orderBy.empty() ? " ORDER BY SerialNumber ASC " : orderBy,
ComputeRange(From, HowMany));
Select << ConvertParams(st), Poco::Data::Keywords::into(Records);
Select.execute();
@@ -1160,25 +1082,4 @@ namespace OpenWifi {
FieldList.push_back(field);
}
void Storage::FixDeviceTypeBug() {
try {
std::vector<std::string> ScriptLines{
"update devices set devicetype='ap' where devicetype='AP';",
"update devices set devicetype='switch' where devicetype='SWITCH';",
"update devices set devicetype='ap' where devicetype!='ap' and devicetype!='switch';"
};
for (const auto &ScriptLine : ScriptLines) {
try {
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement SqlStatement(Sess);
SqlStatement << ScriptLine, Poco::Data::Keywords::now;
} catch (...) {
}
}
} catch (const Poco::Exception &E) {
Logger().log(E);
}
}
} // namespace OpenWifi

View File

@@ -49,7 +49,8 @@ namespace OpenWifi {
"Data TEXT, "
"Recorded BIGINT, "
"INDEX StatSerial0 (SerialNumber)), ",
"INDEX StatSerial (SerialNumber ASC, Recorded ASC))", Poco::Data::Keywords::now;
"INDEX StatSerial (SerialNumber ASC, Recorded ASC))",
Poco::Data::Keywords::now;
}
return 0;
} catch (const Poco::Exception &E) {
@@ -153,7 +154,8 @@ namespace OpenWifi {
"alter table devices add column lastRecordedContact bigint",
"alter table devices add column simulated boolean",
"alter table devices add column certificateExpiryDate bigint",
"alter table devices add column connectReason TEXT"};
"alter table devices add column connectReason TEXT"
};
for (const auto &i : Script) {
try {
@@ -273,19 +275,9 @@ namespace OpenWifi {
"Models TEXT, "
"Description TEXT, "
"Created BIGINT , "
"LastModified BIGINT, Platform TEXT)",
"LastModified BIGINT)",
Poco::Data::Keywords::now;
}
std::vector<std::string> Script{"alter table DefaultConfigs add column Platform text"};
for (const auto &i : Script) {
try {
Sess << i, Poco::Data::Keywords::now;
} catch (...) {
}
}
return 0;
} catch (const Poco::Exception &E) {
Logger().log(E);