Compare commits

..

8 Commits

Author SHA1 Message Date
TIP Automation User
b882f07eef Chg: update image tag in helm values to v2.6.0-RC2 2022-06-17 13:39:08 +00:00
Stephane Bourque
8f4e585c88 Merge pull request #97 from Telecominfraproject/WIFI-9537
Wifi 9537
2022-06-15 16:07:39 -07:00
stephb9959
bb519eb84b Resolve conflict
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-06-15 13:17:24 -07:00
Dmitry Dunaev
07ed169c08 Merge pull request #95 from Telecominfraproject/fix/wifi-9174--dep-charts-2.6
[WIFI-9174] Fix: switch from deprecated bitnami charts to mirrored ones
2022-06-03 15:48:45 +03:00
Dmitry Dunaev
f33b6c94be [WIFI-9174] Fix: switch from deprecated bitnami charts to mirrored ones
Signed-off-by: Dmitry Dunaev <dmitry@opsfleet.com>
2022-06-03 15:47:27 +03:00
Stephane Bourque
8ed351ad17 Merge pull request #93 from Telecominfraproject/WIFI8096
Fix: https://telecominfraproject.atlassian.net/browse/WIFI-8096
2022-05-26 23:51:20 -07:00
stephb9959
4a71be0558 Fix: https://telecominfraproject.atlassian.net/browse/WIFI-8096
Signed-off-by: Stephane Bourque <stephane.bourque@arilia.com>
2022-05-26 23:12:44 -07:00
TIP Automation User
e3375a4510 Chg: update image tag in helm values to v2.6.0-RC1 2022-05-23 12:12:39 +00:00
116 changed files with 4325 additions and 9708 deletions

View File

@@ -17,10 +17,4 @@ jobs:
- name: Cleanup Docker image with PR branch tag
run: |
export PR_BRANCH_TAG=$(echo ${GITHUB_HEAD_REF#refs/heads/} | tr '/' '-')
if [[ ! $PR_BRANCH_TAG =~ (main|master|release-*) ]]; then
echo "PR branch is $PR_BRANCH_TAG, deleting Docker image"
curl -s -uucentral:${{ secrets.DOCKER_REGISTRY_PASSWORD }} -X DELETE "https://tip.jfrog.io/artifactory/tip-wlan-cloud-ucentral/owgw/$PR_BRANCH_TAG"
else
echo "PR branch is $PR_BRANCH_TAG, not deleting Docker image"
fi
curl -uucentral:${{ secrets.DOCKER_REGISTRY_PASSWORD }} -X DELETE "https://tip.jfrog.io/artifactory/tip-wlan-cloud-ucentral/owgw/$PR_BRANCH_TAG"

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13)
project(owgw VERSION 2.7.0)
project(owgw VERSION 2.6.0)
set(CMAKE_CXX_STANDARD 17)
@@ -30,13 +30,6 @@ else()
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/build ${BUILD_NUM})
endif()
if(ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
add_compile_options(-fsanitize=undefined)
add_link_options(-fsanitize=undefined)
endif()
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} describe --always --tags
@@ -49,7 +42,7 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
string(REGEX REPLACE "\n$" "" GIT_HASH "${GIT_HASH}")
endif()
add_definitions(-DTIP_GATEWAY_SERVICE="1" -DPOCO_LOG_DEBUG="1")
add_definitions(-DTIP_GATEWAY_SERVICE="1")
find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
@@ -71,6 +64,10 @@ include_directories(/usr/local/include /usr/local/opt/openssl/include src inclu
configure_file(src/ow_version.h.in ${PROJECT_SOURCE_DIR}/src/ow_version.h @ONLY)
add_compile_options(-Wall -Wextra)
if(ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()
add_executable( owgw
build
@@ -79,10 +76,8 @@ add_executable( owgw
src/framework/KafkaTopics.h
src/framework/MicroService.h
src/framework/OpenWifiTypes.h
src/framework/MicroServiceErrorHandler.h
src/framework/orm.h
src/framework/StorageClass.h
src/framework/MicroServiceErrorHandler.h
src/RESTObjects/RESTAPI_SecurityObjects.h src/RESTObjects/RESTAPI_SecurityObjects.cpp
src/RESTObjects/RESTAPI_ProvObjects.cpp src/RESTObjects/RESTAPI_ProvObjects.h
src/RESTObjects/RESTAPI_GWobjects.h src/RESTObjects/RESTAPI_GWobjects.cpp
@@ -108,9 +103,9 @@ add_executable( owgw
src/storage/storage_tables.cpp
src/RESTAPI/RESTAPI_routers.cpp
src/Daemon.cpp src/Daemon.h
src/AP_WS_Server.cpp src/AP_WS_Server.h
src/WS_Server.cpp src/WS_Server.h
src/StorageService.cpp src/StorageService.h
# src/DeviceRegistry.cpp src/DeviceRegistry.h
src/DeviceRegistry.cpp src/DeviceRegistry.h
src/CommandManager.cpp src/CommandManager.h
src/CentralConfig.cpp src/CentralConfig.h
src/FileUploader.cpp src/FileUploader.h
@@ -121,20 +116,7 @@ add_executable( owgw
src/TelemetryStream.cpp src/TelemetryStream.h
src/framework/ConfigurationValidator.cpp src/framework/ConfigurationValidator.h
src/ConfigurationCache.h
src/CapabilitiesCache.h src/FindCountry.h
src/rttys/RTTYS_server.cpp
src/rttys/RTTYS_server.h
src/rttys/RTTYS_device.cpp
src/rttys/RTTYS_device.h
src/rttys/RTTYS_ClientConnection.cpp
src/rttys/RTTYS_ClientConnection.h
src/rttys/RTTYS_WebServer.cpp
src/rttys/RTTYS_WebServer.h src/RESTAPI/RESTAPI_device_helper.h src/SDKcalls.cpp src/SDKcalls.h src/StateUtils.cpp src/StateUtils.h src/AP_WS_ReactorPool.h src/AP_WS_Connection.h src/AP_WS_Connection.cpp src/TelemetryClient.h src/TelemetryClient.cpp src/RESTAPI/RESTAPI_iptocountry_handler.cpp src/RESTAPI/RESTAPI_iptocountry_handler.h src/framework/ow_constants.h src/GwWebSocketClient.cpp src/GwWebSocketClient.h src/framework/WebSocketClientNotifications.h src/RADIUS_proxy_server.cpp src/RADIUS_proxy_server.h src/RESTAPI/RESTAPI_radiusProxyConfig_handler.cpp src/RESTAPI/RESTAPI_radiusProxyConfig_handler.h src/ParseWifiScan.h src/RADIUS_helpers.h src/VenueBroadcaster.h src/sdks/sdk_prov.h
src/AP_WS_Process_connect.cpp
src/AP_WS_Process_state.cpp
src/AP_WS_Process_healthcheck.cpp
src/AP_WS_Process_log.cpp
src/AP_WS_Process_crashlog.cpp src/AP_WS_Process_ping.cpp src/AP_WS_Process_cfgpending.cpp src/AP_WS_Process_recovery.cpp src/AP_WS_Process_deviceupdate.cpp src/AP_WS_Process_telemetry.cpp src/AP_WS_Process_venuebroadcast.cpp src/RADSECserver.h)
src/CapabilitiesCache.h src/FindCountry.h src/rttys/RTTYS_server.cpp src/rttys/RTTYS_server.h src/rttys/RTTYS_device.cpp src/rttys/RTTYS_device.h src/rttys/RTTYS_ClientConnection.cpp src/rttys/RTTYS_ClientConnection.h src/rttys/RTTYS_WebServer.cpp src/rttys/RTTYS_WebServer.h src/RESTAPI/RESTAPI_device_helper.h src/SDKcalls.cpp src/SDKcalls.h src/StateUtils.cpp src/StateUtils.h src/WS_ReactorPool.h src/WS_Connection.h src/WS_Connection.cpp src/TelemetryClient.h src/TelemetryClient.cpp src/RESTAPI/RESTAPI_iptocountry_handler.cpp src/RESTAPI/RESTAPI_iptocountry_handler.h src/framework/ow_constants.h src/GwWebSocketClient.cpp src/GwWebSocketClient.h src/framework/WebSocketClientNotifications.h src/RADIUS_proxy_server.cpp src/RADIUS_proxy_server.h src/RESTAPI/RESTAPI_radiusProxyConfig_handler.cpp src/RESTAPI/RESTAPI_radiusProxyConfig_handler.h src/ParseWifiScan.h)
if(NOT SMALL_BUILD)

View File

@@ -1,23 +1,15 @@
ARG DEBIAN_VERSION=11.4-slim
ARG POCO_VERSION=poco-tip-v1
ARG FMTLIB_VERSION=9.0.0
ARG CPPKAFKA_VERSION=tip-v1
ARG JSON_VALIDATOR_VERSION=2.1.0
FROM alpine:3.15 AS build-base
FROM debian:$DEBIAN_VERSION AS build-base
RUN apt-get update && apt-get install --no-install-recommends -y \
RUN apk add --update --no-cache \
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
unixodbc-dev postgresql-dev mariadb-dev \
librdkafka-dev boost-dev openssl-dev \
zlib-dev nlohmann-json
FROM build-base AS poco-build
ARG POCO_VERSION
ADD https://api.github.com/repos/AriliaWireless/poco/git/refs/tags/${POCO_VERSION} version.json
RUN git clone https://github.com/AriliaWireless/poco --branch ${POCO_VERSION} /poco
ADD https://api.github.com/repos/stephb9959/poco/git/refs/heads/master version.json
RUN git clone https://github.com/stephb9959/poco /poco
WORKDIR /poco
RUN mkdir cmake-build
@@ -28,10 +20,8 @@ RUN cmake --build . --target install
FROM build-base AS fmtlib-build
ARG FMTLIB_VERSION
ADD https://api.github.com/repos/fmtlib/fmt/git/refs/tags/${FMTLIB_VERSION} version.json
RUN git clone https://github.com/fmtlib/fmt --branch ${FMTLIB_VERSION} /fmtlib
ADD https://api.github.com/repos/fmtlib/fmt/git/refs/heads/master version.json
RUN git clone https://github.com/fmtlib/fmt /fmtlib
WORKDIR /fmtlib
RUN mkdir cmake-build
@@ -42,10 +32,8 @@ RUN make install
FROM build-base AS cppkafka-build
ARG CPPKAFKA_VERSION
ADD https://api.github.com/repos/AriliaWireless/cppkafka/git/refs/tags/${CPPKAFKA_VERSION} version.json
RUN git clone https://github.com/AriliaWireless/cppkafka --branch ${CPPKAFKA_VERSION} /cppkafka
ADD https://api.github.com/repos/stephb9959/cppkafka/git/refs/heads/master version.json
RUN git clone https://github.com/stephb9959/cppkafka /cppkafka
WORKDIR /cppkafka
RUN mkdir cmake-build
@@ -56,10 +44,8 @@ RUN cmake --build . --target install
FROM build-base AS json-schema-validator-build
ARG JSON_VALIDATOR_VERSION
ADD https://api.github.com/repos/pboettch/json-schema-validator/git/refs/tags/${JSON_VALIDATOR_VERSION} version.json
RUN git clone https://github.com/pboettch/json-schema-validator --branch ${JSON_VALIDATOR_VERSION} /json-schema-validator
ADD https://api.github.com/repos/pboettch/json-schema-validator/git/refs/heads/master version.json
RUN git clone https://github.com/pboettch/json-schema-validator /json-schema-validator
WORKDIR /json-schema-validator
RUN mkdir cmake-build
@@ -90,21 +76,21 @@ WORKDIR /owgw/cmake-build
RUN cmake ..
RUN cmake --build . --config Release -j8
FROM debian:$DEBIAN_VERSION
FROM alpine:3.15
ENV OWGW_USER=owgw \
OWGW_ROOT=/owgw-data \
OWGW_CONFIG=/owgw-data
RUN useradd "$OWGW_USER"
RUN addgroup -S "$OWGW_USER" && \
adduser -S -G "$OWGW_USER" "$OWGW_USER"
RUN mkdir /openwifi
RUN mkdir -p "$OWGW_ROOT" "$OWGW_CONFIG" && \
chown "$OWGW_USER": "$OWGW_ROOT" "$OWGW_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
RUN apk add --update --no-cache librdkafka su-exec gettext ca-certificates bash jq curl \
mariadb-connector-c libpq unixodbc postgresql-client
COPY readiness_check /readiness_check
COPY test_scripts/curl/cli /cli
@@ -114,14 +100,12 @@ COPY docker-entrypoint.sh /
COPY wait-for-postgres.sh /
COPY rtty_ui /dist/rtty_ui
RUN wget https://raw.githubusercontent.com/Telecominfraproject/wlan-cloud-ucentral-deploy/main/docker-compose/certs/restapi-ca.pem \
-O /usr/local/share/ca-certificates/restapi-ca-selfsigned.crt
-O /usr/local/share/ca-certificates/restapi-ca-selfsigned.pem
COPY --from=owgw-build /owgw/cmake-build/owgw /openwifi/owgw
COPY --from=cppkafka-build /cppkafka/cmake-build/src/lib /usr/local/lib/
COPY --from=poco-build /poco/cmake-build/lib /usr/local/lib
RUN ldconfig
EXPOSE 15002 16002 16003 17002 16102
ENTRYPOINT ["/docker-entrypoint.sh"]

View File

@@ -18,29 +18,17 @@ System messages are what maintains the collection of micro-services working on t
}
```
### Responsibilities
Each micro service is responsible to generate its own messages and keep track of messages coming from other
micro services. This is necessary so that any micro service may reach our any other micro service. This provides
discovery for any micro service. All current micro services provided in OpenWiFi perform these functions. If you leverage
the C++ framework, this functionality if performed automatically.
### `event-type`
Each micro service is responsible to generate and consume these events
#### `join` event
When a service start and joins the bus, it should generate an event-type of `join`.
### `leave` event
When a service shuts down, it should generate a `leave` event-type.
### `keep-alive` event
Every 30 seconds, a service should generate a `keep-alive` message.
When a service joins the bus, it should generate an event-type of `join`. When a service shutdown, it should generate a `leave` event-type. Every 30 seconds, a service
should generate a `keep-alive` message.
### `id`
You should generate a random number from some unique factor for the system. This ID is used to identify different services. You should reuse that ID
when you restart.
## Micro-service maintaining bus state
A micro-service should maintain its own lists of available micro-services by looking at the messages it receives and keep a list.
## The `type`
The `type` in the system message is oen of the following:
```c++
@@ -59,11 +47,11 @@ The `type` in the system message is oen of the following:
The `type` is what you should use to find the `privateEndPoint` you are looking to communicate with.
### Example
Assume you want to communicate with the gateway to configure a device.
Assume you want to communicate with the gateway t pconfigure a device.
```text
1. Look into my list of current Micro-services for the type=owgw.
2. Use the privateEndPoint associated with that entry
2. Use the priovateEndPoint associated with that entry
```
## REST API calls on the private interface
@@ -84,9 +72,9 @@ This is the `publicEndPoint` you included in your `system-messages`.
This method can _only_ be used to any another `privateEndPoint` in the system. You can use the exact same EndPoints provided in the OpenAPI files for any of the services.
## OpenAPI Integration
To appear in the UI consoles, a microservice should be able to handle a get to the `/api/v1/system` endpoint on its `publicEndPoint` interface.
To appear in the UI consoles, a micro-service should ne able to handle a get to the `/api/v1/system` endpoint on its `publicEndPoint` interface.
Here is a brief description of what the microservice should answer:
Here is a brief description of what the micro-service should answer:
```yaml
/system:
get:

View File

@@ -30,7 +30,7 @@ In this RPC, here are some common interpretations:
#### Connection event
Device Sends connection notification to the controller after establishing a connection. The controller
my decide to send the AP a newer configuration. The controller will record the device capabilities provided.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "connect" ,
"params" : {
@@ -47,7 +47,7 @@ my decide to send the AP a newer configuration. The controller will record the d
#### State event
The device sends device state information periodically. If the controller detects that it has a newer configuration, it
may decide to send this new configuration to the AP.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "state" ,
"params" : {
@@ -62,7 +62,7 @@ may decide to send this new configuration to the AP.
#### Healthcheck event
Device sends a `healthcheck` periodically. This message contains information about how vital subsystems are operating and
if they need attention.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "healthcheck" ,
"params" : {
@@ -77,7 +77,7 @@ if they need attention.
#### Log event
Device sends a log message whenever necessary. The controller will log this message to the log system for the device.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "log" ,
"params" : {
@@ -102,7 +102,7 @@ The `severity` matches the `syslog` levels. Here are the details:
#### Crash Log event
Device may send a crash log event after rebooting after a crash. The event cannot be sent until a connection event has been sent.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "crashlog" ,
"params" : {
@@ -117,7 +117,7 @@ Device may send a crash log event after rebooting after a crash. The event canno
Device sends this message to tell the controller that the device
has received a configuration but is still running an older configuration. The controller will not
reply to this message.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "cfgpending" ,
"params" : {
@@ -131,7 +131,7 @@ reply to this message.
#### DeviceUpdate event
Device sends this message to tell the controller it is changing something is its configuration because
of some requirement or some changes.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "deviceupdate" ,
"params" : {
@@ -145,7 +145,7 @@ of some requirement or some changes.
#### Send a keepalive to the controller event
Device sends a keepalive whenever necessary. The device will send this message to tell the controller
which version it is running. The Controller may decide to send the device a newer configuration.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "ping" ,
"params" : {
@@ -157,7 +157,7 @@ which version it is running. The Controller may decide to send the device a newe
#### Recovery Event
Device may decide it has to do into recovery mode. This event should be used.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "recovery" ,
"params" : {
@@ -170,34 +170,6 @@ Device may decide it has to do into recovery mode. This event should be used.
}
```
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>
}
},
"id" : <same number>
}
```
#### Device requests a venue broadcast message
Device send this message when it wants to reach out to all other APs in the same venue. The GW will find the
venue where this device belongs and resend the same message to all other devices in the venue.
```json
{ "jsonrpc" : "2.0" ,
"method" : "venue_broadcast" ,
"params" : {
"serial" : <serial number> ,
"timestamp" : <the UTC timestamp when the message was sent>,
"data" : <an opaque string from the AP. This could be Zipped and so on and most likely base64 encoded>
}
}
```
Upon receiving a `venue_broadcast` message, the GW will simply resent the message to all the APs in the venue.
### Controller commands
Most controller commands include a `when` member. This is a UTC clock time asking the AP
@@ -208,7 +180,7 @@ always a numeric parameter.
#### Controller wants the device to apply a given configuration
Controller sends this command when it believes the device should load a new configuration. The device
should send message with `pending change` events until this version has been applied and running.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "configure" ,
"params" : {
@@ -222,7 +194,7 @@ should send message with `pending change` events until this version has been app
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -261,7 +233,7 @@ The rejected section is an array containing the following:
#### Controller wants the device to reboot
Controller sends this command when it believes the device should reboot.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "reboot" ,
"params" : {
@@ -273,7 +245,7 @@ Controller sends this command when it believes the device should reboot.
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -292,7 +264,7 @@ The device should answer:
#### Controller wants the device to upgrade its firmware
Controller sends this command when it believes the device should upgrade its firmware.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "upgrade" ,
"params" : {
@@ -305,7 +277,7 @@ Controller sends this command when it believes the device should upgrade its fir
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -321,7 +293,7 @@ The device should answer:
#### Controller wants the device to perform a factory reset
Controller sends this command when it believes the device should upgrade its firmware.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "factory" ,
"params" : {
@@ -334,7 +306,7 @@ Controller sends this command when it believes the device should upgrade its fir
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -348,50 +320,9 @@ The device should answer:
}
```
#### Controller issuing RRM commands to the AP
Controller sends this command to perform several RRM commands.
```json
{ "jsonrpc" : "2.0" ,
"method" : "rrm" ,
"params" : {
"serial" : <serial number> ,
"actions": [
{
"type": "roam",
"bss": [ "00:11:22:33:44:55", ... ],
"params" : { action specific data }
}, {
"type": "tx-power",
"bss": [ "00:11:22:33:44:55", ... ],
params: { action specific data }
}, {
"type": "beacon-request",
"bss": [ "00:11:22:33:44:55", ... ],
"params": { action specific data }
}
]
},
"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>,
}
},
"id" : <same number>
}
```
#### Controller wants the device to flash its LEDs
Controller sends this command when it wants the device to flash its LEDs.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "leds" ,
"params" : {
@@ -405,13 +336,14 @@ Controller sends this command when it wants the device to flash its LEDs.
```
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>,
"when" : <time when this will be performed as UTC seconds>,
}
},
"id" : <same number>
@@ -426,7 +358,7 @@ The device should answer:
#### Controller sends a device specific command
Controller sends this command specific to this device. The command is proprietary and must be agreed upon by the device
and the controller.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "perform" ,
"params" : {
@@ -440,7 +372,7 @@ and the controller.
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -463,7 +395,7 @@ The device should answer with teh above message. The `error` value should be int
#### Controller wants the device to perform a trace
Controller sends this command when it needs the device to perform a trace (i.e. tcpdump).
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "trace" ,
"params" : {
@@ -480,7 +412,7 @@ Controller sends this command when it needs the device to perform a trace (i.e.
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -506,7 +438,7 @@ uploaded or the timeout occurs, the upload will be rejected.
#### Controller wants the device to perform a WiFi Scan
Controller sends this command when it needs the device to perform a WiFi Scan.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "wifiscan" ,
"params" : {
@@ -523,7 +455,7 @@ Controller sends this command when it needs the device to perform a WiFi Scan.
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -546,7 +478,7 @@ Controller sends this command when it needs the device to provide a message back
supported messages are "state" and "healthcheck". More messages maybe added later. The messages will
be returned the usual way. The RPC response to this message just says that the request has been accepted and the
message will be returned "soon".
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "request" ,
"params" : {
@@ -560,7 +492,7 @@ message will be returned "soon".
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -576,7 +508,7 @@ The device should answer:
#### Controller requesting eventqueue buffers
Controller sends this command when it needs the device to provide the content of ist ring buffers.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "event" ,
"params" : {
@@ -590,7 +522,7 @@ Controller sends this command when it needs the device to provide the content of
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -606,7 +538,7 @@ The device should answer:
#### Controller requesting telemetry stream information
Controller sends this command when it needs the device to telemetry streaming.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "telemetry" ,
"params" : {
@@ -619,7 +551,7 @@ Controller sends this command when it needs the device to telemetry streaming.
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -633,7 +565,7 @@ The device should answer:
```
When the interval is greater than 0, the gateway will start to receive messages
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "telemetry" ,
"params" : {
@@ -648,7 +580,7 @@ The device will stop sending data after 30 minutes or if it receives a `telemetr
#### Controller requesting an `rtty` session
Controller sends this command an administrator requests to start an `rtty` session with the AP.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "remote_access" ,
"params" : {
@@ -666,7 +598,7 @@ Controller sends this command an administrator requests to start an `rtty` sessi
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -682,7 +614,7 @@ The device should answer:
#### Controller wants to ping the device
Controller sends this command when it tries to establish latency to the device.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "ping" ,
"params" : {
@@ -693,7 +625,7 @@ Controller sends this command when it tries to establish latency to the device.
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -706,7 +638,7 @@ The device should answer:
#### Controller wants the device to perform a script
Controller sends this command to run a predefined script. Extreme care must be taken.
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "script" ,
"params" : {
@@ -721,7 +653,7 @@ Controller sends this command to run a predefined script. Extreme care must be t
```
The device should answer:
```json
```
{ "jsonrpc" : "2.0" ,
"result" : {
"serial" : <serial number> ,
@@ -749,21 +681,17 @@ Should other messages get larger, the client may decide to compress the. Only me
#### Identifying a compressed message
A compressed message has a single member to the `params` field. It's only parameter must be called `compress_64`. Any other elements under
params will be dropped. Additional compression schemes may be developed later. The device should also include
a hint to the actual size of the uncompressed data. This would allow listeners to create sufficiently sized
buffers right away instead of guessing. If the device includes `compressed_sz` as the second field in the
params objects. This should be an unsigned int representing the total size of the uncompressed data.
params will be dropped. Additional compression schemes may be developed later.
#### How to compress
The original `params` element should be run through `zlib:compress` and then encoded using base64, and passed as a string. Here is an example
of the completed message. The following should how the `state` event could be compressed:
```json
```
{ "jsonrpc" : "2.0" ,
"method" : "state" ,
"params" : {
"compress_64" : "kqlwhfoihffhwleihfi3uhfkjehfqlkwhfqkhfiu3hffhkjwehfqkwjehfqwiefkjehq.....qwjqkfhqjwk",
"compress_sz" : 212322
"compress_64" : "kqlwhfoihffhwleihfi3uhfkjehfqlkwhfqkhfiu3hffhkjwehfqkwjehfqwiefkjehq.....qwjqkfhqjwk"
}
}
```
@@ -772,10 +700,13 @@ of the completed message. The following should how the `state` event could be co
The gateway can receive RADIUS messages from the device and forward them. It can also receive messages
on its behalf and send them to the device.
```json
```
{
"radius" : <type, can be auth, acct, coa> ,
"radius" : <type, can be auth, acct, das> ,
"data" : <base 64 encoded raw RADIUS payload>
"dst" : <ip:port> as a string - optional. If this is supplied, the GW will send the data to that destination,
if not provided, the GW will use one of the radius servers it has in its configuration. This is only
valid for messages coming from the device.
}
```
@@ -786,10 +717,11 @@ identify the destination for its messages.
The GW must be configured with the following:
```asm
radius.proxy.enable = true
radius.proxy.accounting.port = 1813
radius.proxy.authentication.port = 1812
radius.proxy.coa.port = 3799
radius.incoming.proxy.enable = true
radius.incoming.proxy.accounting.port = 1813
radius.incoming.proxy.auth.port = 1812
radius.incoming.proxy.das.port = 1814
radius.incoming.serialnumbertlv = 127
```

View File

@@ -11,16 +11,16 @@ In order to build the uCentralGW, you will need to install its dependencies, whi
- boost
- POCO 1.10.1 or later
- a C++17 compiler
- libyaml
- openssl
- 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/AriliaWireless/poco). Building
from the master copy needed for cmake. Please use the version of this [Poco fix](https://github.com/stephb9959/poco). Building
Poco may take several minutes depending on the platform you are building on.
### Ubuntu
@@ -29,10 +29,9 @@ These instructions have proven to work on Ubuntu 20.4.
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
cd ~
git clone https://github.com/AriliaWireless/poco --branch poco-tip-v1
git clone https://github.com/stephb9959/poco
cd poco
mkdir cmake-build
cd cmake-build
@@ -41,7 +40,7 @@ cmake --build . --config Release
sudo cmake --build . --target install
cd ~
git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1
git clone https://github.com/stephb9959/cppkafka
cd cppkafka
mkdir cmake-build
cd cmake-build
@@ -50,21 +49,23 @@ cmake --build . --config Release
sudo cmake --build . --target install
cd ~
git clone https://github.com/pboettch/json-schema-validator.git --branch 2.1.0
cd json-schema-validator
git clone https://github.com/nlohmann/json.git
cd json
git checkout tags/v3.10.2
mkdir cmake-build
cd cmake-build
cmake ..
make -j
sudo make install
git clone https://github.com/fmtlib/fmt --branch 9.0.0 /fmtlib
cd fmtlib
cd ~
git clone https://github.com/pboettch/json-schema-validator.git
cd json-schema-validator
mkdir cmake-build
cd cmake-build
cmake ..
make
make install
make -j
sudo make install
cd ~
git clone https://github.com/Telecominfraproject/wlan-cloud-ucentralgw
@@ -80,12 +81,12 @@ make -j 8
### Fedora
The following instructions have proven to work on Fedora 33
```
sudo yum install cmake g++ openssl-devel mysql-devel mysql apr-util-devel boost boost-devel
sudo yum install cmake g++ openssl-devel unixODBC-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
sudo dnf install postgresql-devel
git clone https://github.com/AriliaWireless/poco --branch poco-tip-v1
git clone https://github.com/stephb9959/poco
cd poco
mkdir cmake-build
cd cmake-build
@@ -93,7 +94,7 @@ cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1
git clone https://github.com/stephb9959/cppkafka
cd cppkafka
mkdir cmake-build
cd cmake-build
@@ -101,15 +102,6 @@ cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
cd ~
git clone https://github.com/pboettch/json-schema-validator.git --branch 2.1.0
cd json-schema-validator
mkdir cmake-build
cd cmake-build
cmake ..
make -j
sudo make install
cd ~
git clone https://github.com/Telecominfraproject/wlan-cloud-ucentralgw
cd wlan-cloud-ucentralgw
@@ -132,18 +124,18 @@ brew install apr-util
brew install boost
brew install yaml-cpp
brew install postgresql
brew install unixodbc
brew install librdkafka
brew install nlohmann-json
git clone https://github.com/AriliaWireless/poco --branch poco-tip-v1
git clone https://github.com/stephb9959/poco
cd poco
mkdir cmake-build
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
cmake --build . --config Release -j
sudo cmake --build . --target install
git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1
git clone https://github.com/stephb9959/cppkafka
cd cppkafka
mkdir cmake-build
cd cmake-build
@@ -151,15 +143,6 @@ cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
cd ~
git clone https://github.com/pboettch/json-schema-validator.git --branch 2.1.0
cd json-schema-validator
mkdir cmake-build
cd cmake-build
cmake ..
make -j
sudo make install
cd ~
git clone https://github.com/Telecominfraproject/wlan-cloud-ucentralgw
cd wlan-cloud-ucentralgw
@@ -266,7 +249,7 @@ little changes if you keep the suggested directory structure. For the sample con
environment variables.
```
export OWGW_ROOT=`pwd`
export OWGW_CONFIG=`pwd`
export UCENTRALGW_CONFIG=`pwd`
```
If you current working directory is the root of the project, this will set the variables properly. Otherwise, you can set the variables
to point to wherever is necessary.
@@ -578,31 +561,6 @@ Toe read more about Kafka, follow the [document](https://github.com/Telecominfra
#### Securing `kafka`
This is beyond the scope of this document. As it stands today, the communication between the gateway and `kafka` is expected to be behind a firewall.
#### `iptocountry` feature
In the UI, you will notice the presence of small flags showing where the device connections are from. This feature is
available through the `iptocountry` settings in the configuration. This feature is then also available through the `OpenAPI` for the CLI
and other applications.
##### Config file entries
In the configuration file, you must include the following lines:
```asm
iptocountry.default = US
iptocountry.provider = ipinfo
#iptocountry.provider = ipdata
#iptocountry.provider = ipdata
iptocountry.ipinfo.token =
#ip2location.ipinfo.token =
#iptocountry.ipdata.apikey =
#iptocountry.ip2location.apikey =
```
So you select your provider with the `iptocountry.provider` be specifying ipinfo, or ipdata, or ip2location.
And then you provide the corresponding api key or token.
Only select one. If you select 2, undefined behaviour. All the line you do not need, just put a `#` before to comment it
out.
You will find the supported providers at: `ip2location.com`, `ipinfo.io`, or `ipdata.co`. You MUST supply a valid default
country code in `iptocountry.default`.
## Contributors
We love ya! We need more of ya! If you want to contribute, make sure you review
the [coding style](https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/CODING_STYLE.md) document.

2
build
View File

@@ -1 +1 @@
148
74

View File

@@ -1,11 +1,11 @@
#!/bin/bash
#!/bin/sh
set -e
if [ "$SELFSIGNED_CERTS" = 'true' ]; then
update-ca-certificates
fi
if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
if [[ "$TEMPLATE_CONFIG" = 'true' && ! -f "$OWGW_CONFIG"/owgw.properties ]]; then
WEBSOCKET_HOST_ROOTCA=${WEBSOCKET_HOST_ROOTCA:-"\$OWGW_ROOT/certs/root.pem"} \
WEBSOCKET_HOST_ISSUER=${WEBSOCKET_HOST_ISSUER:-"\$OWGW_ROOT/certs/issuer.pem"} \
WEBSOCKET_HOST_CERT=${WEBSOCKET_HOST_CERT:-"\$OWGW_ROOT/certs/websocket-cert.pem"} \
@@ -38,12 +38,7 @@ if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
SYSTEM_URI_PRIVATE=${SYSTEM_URI_PRIVATE:-"https://localhost:17002"} \
SYSTEM_URI_PUBLIC=${SYSTEM_URI_PUBLIC:-"https://localhost:16002"} \
SYSTEM_URI_UI=${SYSTEM_URI_UI:-"http://localhost"} \
SECURITY_RESTAPI_DISABLE=${SECURITY_RESTAPI_DISABLE:-"false"} \
SIMULATORID=${SIMULATORID:-""} \
IPTOCOUNTRY_PROVIDER=${IPTOCOUNTRY_PROVIDER:-"ipinfo"} \
IPTOCOUNTRY_IPINFO_TOKEN=${IPTOCOUNTRY_IPINFO_TOKEN:-""} \
IPTOCOUNTRY_IPDATA_APIKEY=${IPTOCOUNTRY_IPDATA_APIKEY:-""} \
AUTOPROVISIONING_PROCESS=${AUTOPROVISIONING_PROCESS:-"prov,default"} \
RTTY_INTERNAL=${RTTY_INTERNAL:-"true"} \
RTTY_ENABLED=${RTTY_ENABLED:-"true"} \
RTTY_SERVER=${RTTY_SERVER:-"localhost"} \
@@ -52,10 +47,6 @@ if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
RTTY_TIMEOUT=${RTTY_TIMEOUT:-"60"} \
RTTY_VIEWPORT=${RTTY_VIEWPORT:-"5913"} \
RTTY_ASSETS=${RTTY_ASSETS:-"\$OWGW_ROOT/rtty_ui"} \
RADIUS_PROXY_ENABLE=${RADIUS_PROXY_ENABLE:-"false"} \
RADIUS_PROXY_ACCOUNTING_PORT=${RADIUS_PROXY_ACCOUNTING_PORT:-"1813"} \
RADIUS_PROXY_AUTHENTICATION_PORT=${RADIUS_PROXY_AUTHENTICATION_PORT:-"1812"} \
RADIUS_PROXY_COA_PORT=${RADIUS_PROXY_COA_PORT:-"3799"} \
KAFKA_ENABLE=${KAFKA_ENABLE:-"true"} \
KAFKA_BROKERLIST=${KAFKA_BROKERLIST:-"localhost:9092"} \
KAFKA_SSL_CA_LOCATION=${KAFKA_SSL_CA_LOCATION:-""} \
@@ -95,7 +86,7 @@ if [ "$1" = '/openwifi/owgw' -a "$(id -u)" = '0' ]; then
if [ "$RUN_CHOWN" = 'true' ]; then
chown -R "$OWGW_USER": "$OWGW_ROOT" "$OWGW_CONFIG"
fi
exec gosu "$OWGW_USER" "$@"
exec su-exec "$OWGW_USER" "$@"
fi
exec "$@"

View File

@@ -79,8 +79,7 @@ The following table lists the configurable parameters of the chart and their def
| persistence.size | string | Defines PV size | `'10Gi'` |
| public_env_variables | hash | Defines list of environment variables to be passed to the Gateway | |
| configProperties | hash | Configuration properties that should be passed to the application in `owgw.properties`. May be passed by key in set (i.e. `configProperties."rtty\.token"`) | |
| existingCertsSecret | string | Existing Kubernetes secret containing all required certificates and private keys for microservice operation. If set, certificates from `certs` key are ignored | `""` |
| certs | hash | Defines files (keys and certificates) that should be passed to the Gateway (PEM format is adviced to be used) (see `volumes.owgw` on where it is mounted). If `existingCertsSecret` is set, certificates passed this way will not be used. | |
| certs | hash | Defines files (keys and certificates) that should be passed to the Gateway (PEM format is adviced to be used) (see `volumes.owgw` on where it is mounted) | |
| certsCAs | hash | Defines files with CAs that should be passed to the Gateway (see `volumes.owgw` on where it is mounted) | |

View File

@@ -1,5 +1,4 @@
{{- $root := . -}}
{{- $storageType := index .Values.configProperties "storage.type" -}}
---
apiVersion: apps/v1
kind: Deployment
@@ -49,38 +48,6 @@ spec:
- tcp://{{ index .Values.configProperties "openwifi.kafka.brokerlist" }}
- -timeout
- 600s
{{- if eq $storageType "postgresql" }}
- name: wait-postgres
image: "{{ .Values.images.owgw.repository }}:{{ .Values.images.owgw.tag }}"
imagePullPolicy: {{ .Values.images.owgw.pullPolicy }}
command:
- /wait-for-postgres.sh
- {{ index .Values.configProperties "storage.type.postgresql.host" }}
- echo
- "PostgreSQL is ready"
env:
- name: KUBERNETES_DEPLOYED
value: "{{ now }}"
{{- range $key, $value := .Values.public_env_variables }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- range $key, $value := .Values.secret_env_variables }}
- name: {{ $key }}
valueFrom:
secretKeyRef:
name: {{ include "owgw.fullname" $root }}-env
key: {{ $key }}
{{- end }}
volumeMounts:
{{- range .Values.volumes.owgw }}
- name: {{ .name }}
mountPath: {{ .mountPath }}
{{- if .subPath }}
subPath: {{ .subPath }}
{{- end }}
{{- end }}
{{- end }}
containers:
@@ -109,11 +76,6 @@ spec:
containerPort: {{ $portValue.targetPort }}
protocol: {{ $portValue.protocol }}
{{- end }}
{{- range $port, $portValue := .Values.services.radius.ports }}
- name: {{ $port }}
containerPort: {{ $portValue.targetPort }}
protocol: {{ $portValue.protocol }}
{{- end }}
volumeMounts:
{{- range .Values.volumes.owgw }}

View File

@@ -9,7 +9,7 @@ fullnameOverride: ""
images:
owgw:
repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owgw
tag: v2.7.0
tag: v2.6.0-RC2
pullPolicy: Always
# regcred:
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io
@@ -46,21 +46,6 @@ services:
rttys-view:
servicePort: 5913
targetPort: 5913
radius:
type: ClusterIP
ports:
acc:
servicePort: 1813
targetPort: 1813
protocol: UDP
auth:
servicePort: 1812
targetPort: 1812
protocol: UDP
coa:
servicePort: 3799
targetPort: 3799
protocol: UDP
checks:
owgw:
@@ -112,7 +97,7 @@ volumes:
mountPath: /owgw-data/certs
volumeDefinition: |
secret:
secretName: {{ if .Values.existingCertsSecret }}{{ .Values.existingCertsSecret }}{{ else }}{{ include "owgw.fullname" . }}-certs{{ end }}
secretName: {{ include "owgw.fullname" . }}-certs
- name: certs-cas
mountPath: /owgw-data/certs/cas
volumeDefinition: |
@@ -138,7 +123,7 @@ resources: {}
# memory: 128Mi
securityContext:
fsGroup: 1000
fsGroup: 101
# Usage of unsafe sysctls requires multiple things:
# - allow these unsafe sysctls on kubelet level (by adding --allowed-unsafe-sysctls flag)
# - enabling addition of PodSecurityContext setting podSecurityPolicy.enabled to "true" below
@@ -230,7 +215,7 @@ configProperties:
openwifi.devicetypes.0: AP:linksys_ea8300,edgecore_eap101,linksys_e8450-ubi
openwifi.devicetypes.1: SWITCH:edgecore_ecs4100-12ph
openwifi.devicetypes.2: IOT:esp32
oui.download.uri: https://standards-oui.ieee.org/oui/oui.txt
oui.download.uri: https://linuxnet.ca/ieee/oui.txt
firmware.autoupdate.policy.default: auto
iptocountry.provider: ipinfo
# Callback
@@ -246,11 +231,6 @@ configProperties:
rtty.timeout: 60
rtty.viewport: 5913
rtty.assets: $OWGW_ROOT/rtty_ui
# RADIUS proxy
radius.proxy.enable: "true"
radius.proxy.accounting.port: 1813
radius.proxy.authentication.port: 1812
radius.proxy.coa.port: 3799
# ALB
alb.enable: "true"
alb.port: 16102
@@ -291,12 +271,11 @@ configProperties:
openwifi.system.debug: "true"
openwifi.system.uri.private: https://localhost:17002
openwifi.system.uri.public: https://localhost:16002
openwifi.system.uri.ui: https://localhost
openwifi.system.commandchannel: /tmp/app_owgw
# Logging
logging.type: console
logging.path: $OWGW_ROOT/logs
logging.level: information
logging.level: debug
# Archiving
archiver.enabled: "true"
archiver.schedule: 03:00
@@ -331,22 +310,166 @@ configProperties:
storage.type.mysql.username: stephb
storage.type.mysql.password: snoopy99
# NOTE: List of required certificates may be found in "certs" key. Alternative way to pass required certificates is to create external secret with all required certificates and set secret name in "existingCertsSecret" key. Details may be found in https://github.com/Telecominfraproject/wlan-cloud-ucentral-deploy/tree/main/chart#tldr
existingCertsSecret: ""
certs:
clientcas.pem: ""
issuer.pem: ""
restapi-ca.pem: ""
restapi-cert.pem: ""
restapi-key.pem: ""
root.pem: ""
websocket-cert.pem: ""
websocket-key.pem: ""
clientcas.pem: |
-----BEGIN CERTIFICATE-----
MIIEnDCCA4SgAwIBAgIUVpyCUx1MUeUwxg+7I1BvGFTz7HkwDQYJKoZIhvcNAQEL
BQAwaTELMAkGA1UEBhMCVVMxJDAiBgNVBAoTG1RlbGVjb20gSW5mcmEgUHJvamVj
dCwgSW5jLjEMMAoGA1UECxMDVElQMSYwJAYDVQQDEx1UZWxlY29tIEluZnJhIFBy
b2plY3QgUm9vdCBDQTAeFw0yMTA0MTMyMjUxMjZaFw0yNjA0MTMyMjM4NDZaMGwx
CzAJBgNVBAYTAlVTMSQwIgYDVQQKExtUZWxlY29tIEluZnJhIFByb2plY3QsIElu
Yy4xDDAKBgNVBAsTA1RJUDEpMCcGA1UEAxMgVGVsZWNvbSBJbmZyYSBQcm9qZWN0
IElzc3VpbmcgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDtKBrq
qd2aKVSk25KfL5xHu8X7/8rJrz3IvyPuVKWhk/N1zabot3suBcGaYNKjnRHxg78R
yKwKzajKYWtiQFqztu24g16LQeAnoUxZnF6a0z3JkkRPsz14A2y8TUhdEe1tx+UU
4VGsk3n+FMmOQHL+79FO57zQC1LwylgfLSltrI6mF3jowVUQvnwzKhUzT87AJ6EO
ndK/q0T/Bgi+aI39zfVOjJjsTJwghvrmYW3iarP1THSKxeib2s02bZKrvvHa5HL4
UI8+LvREpVZl4mzt1z6Nl344Y6f+UeJlYa/Ci0jJqaXJmyVnUbAz+c0i5JfwAVn3
YQzfC4eLnZCmdF8zAgMBAAGjggE3MIIBMzAPBgNVHRMBAf8EBTADAQH/MB0GA1Ud
DgQWBBSzG1S44EerPfM4gOQ85f0AYW3R6DAfBgNVHSMEGDAWgBQCRpZgebFT9qny
98WfIUDk6ZEB+jAOBgNVHQ8BAf8EBAMCAYYwgYMGCCsGAQUFBwEBBHcwdTAoBggr
BgEFBQcwAYYcaHR0cDovL29jc3Aub25lLmRpZ2ljZXJ0LmNvbTBJBggrBgEFBQcw
AoY9aHR0cDovL2NhY2VydHMub25lLmRpZ2ljZXJ0LmNvbS9UZWxlY29tSW5mcmFQ
cm9qZWN0Um9vdENBLmNydDBKBgNVHR8EQzBBMD+gPaA7hjlodHRwOi8vY3JsLm9u
ZS5kaWdpY2VydC5jb20vVGVsZWNvbUluZnJhUHJvamVjdFJvb3RDQS5jcmwwDQYJ
KoZIhvcNAQELBQADggEBAFbz+K94bHIkBMJqps0dApniUmOn0pO6Q6cGh47UP/kX
IiPIsnYgG+hqYD/qtsiqJhaWi0hixRWn38UmvZxMRk27aSTGE/TWx0JTC3qDGsSe
XkUagumbSfmS0ZyiTwMPeGAjXwyzGorqZWeA95eKfImntMiOf3E7//GK0K7HpCx8
IPCnLZsZD2q/mLyBsduImFIRQJbLAhwIxpcd1qYJk+BlGFL+HtBpEbq6JxW2Xy+v
DpNWc2WIsUTle0rTc9JNJrLX4ChUJmKqf8obKHap3Xh3//qw/jDB9pOAinA33FLJ
EmCnwBvQr9mfNmPBGMYZVU8cPruDQJ57GjmmvdisbJY=
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIDojCCAoqgAwIBAgIUPVYBpqNbcLYygF6Mx+qxSWwQyFowDQYJKoZIhvcNAQEL
BQAwaTELMAkGA1UEBhMCVVMxJDAiBgNVBAoTG1RlbGVjb20gSW5mcmEgUHJvamVj
dCwgSW5jLjEMMAoGA1UECxMDVElQMSYwJAYDVQQDEx1UZWxlY29tIEluZnJhIFBy
b2plY3QgUm9vdCBDQTAeFw0yMTA0MTMyMjQyNDRaFw0zMTA0MTMyMjM4NDZaMGkx
CzAJBgNVBAYTAlVTMSQwIgYDVQQKExtUZWxlY29tIEluZnJhIFByb2plY3QsIElu
Yy4xDDAKBgNVBAsTA1RJUDEmMCQGA1UEAxMdVGVsZWNvbSBJbmZyYSBQcm9qZWN0
IFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDIGCibwf5u
AAwZ+1H8U0e3u2V+0d2gSctucoK86XwUmfe1V2a/qlCYZd29r80IuN1IIeB0naIm
KnK/MzXW87clF6tFd1+HzEvmlY/W4KyIXalVCTEzirFSvBEG2oZpM0yC3AefytAO
aOpA00LaM3xTfTqMKIRhJBuLy0I4ANUVG6ixVebbGuc78IodleqiLoWy2Q9QHyEO
t/7hZndJhiVogh0PveRhho45EbsACu7ymDY+JhlIleevqwlE3iQoq0YcmYADHno6
Eq8vcwLpZFxihupUafkd1T3WJYQAJf9coCjBu2qIhNgrcrGD8R9fGswwNRzMRMpX
720+GjcDW3bJAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFAJG
lmB5sVP2qfL3xZ8hQOTpkQH6MA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0BAQsF
AAOCAQEAVjl9dm4epG9NUYnagT9sg7scVQEPfz3Lt6w1NXJXgD8mAUlK0jXmEyvM
dCPD4514n+8+lM7US8fh+nxc7jO//LwK17Wm9FblgjNFR7+anv0Q99T9fP19DLlF
PSNHL2emogy1bl1lLTAoj8nxg2wVKPDSHBGviQ5LR9fsWUIJDv9Bs5k0qWugWYSj
19S6qnHeskRDB8MqRLhKMG82oDVLerSnhD0P6HjySBHgTTU7/tYS/OZr1jI6MPbG
L+/DtiR5fDVMNdBSGU89UNTi0wHY9+RFuNlIuvZC+x/swF0V9R5mN+ywquTPtDLA
5IOM7ItsRmen6u3qu+JXros54e4juQ==
-----END CERTIFICATE-----
issuer.pem: |
-----BEGIN CERTIFICATE-----
MIIEnDCCA4SgAwIBAgIUVpyCUx1MUeUwxg+7I1BvGFTz7HkwDQYJKoZIhvcNAQEL
BQAwaTELMAkGA1UEBhMCVVMxJDAiBgNVBAoTG1RlbGVjb20gSW5mcmEgUHJvamVj
dCwgSW5jLjEMMAoGA1UECxMDVElQMSYwJAYDVQQDEx1UZWxlY29tIEluZnJhIFBy
b2plY3QgUm9vdCBDQTAeFw0yMTA0MTMyMjUxMjZaFw0yNjA0MTMyMjM4NDZaMGwx
CzAJBgNVBAYTAlVTMSQwIgYDVQQKExtUZWxlY29tIEluZnJhIFByb2plY3QsIElu
Yy4xDDAKBgNVBAsTA1RJUDEpMCcGA1UEAxMgVGVsZWNvbSBJbmZyYSBQcm9qZWN0
IElzc3VpbmcgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDtKBrq
qd2aKVSk25KfL5xHu8X7/8rJrz3IvyPuVKWhk/N1zabot3suBcGaYNKjnRHxg78R
yKwKzajKYWtiQFqztu24g16LQeAnoUxZnF6a0z3JkkRPsz14A2y8TUhdEe1tx+UU
4VGsk3n+FMmOQHL+79FO57zQC1LwylgfLSltrI6mF3jowVUQvnwzKhUzT87AJ6EO
ndK/q0T/Bgi+aI39zfVOjJjsTJwghvrmYW3iarP1THSKxeib2s02bZKrvvHa5HL4
UI8+LvREpVZl4mzt1z6Nl344Y6f+UeJlYa/Ci0jJqaXJmyVnUbAz+c0i5JfwAVn3
YQzfC4eLnZCmdF8zAgMBAAGjggE3MIIBMzAPBgNVHRMBAf8EBTADAQH/MB0GA1Ud
DgQWBBSzG1S44EerPfM4gOQ85f0AYW3R6DAfBgNVHSMEGDAWgBQCRpZgebFT9qny
98WfIUDk6ZEB+jAOBgNVHQ8BAf8EBAMCAYYwgYMGCCsGAQUFBwEBBHcwdTAoBggr
BgEFBQcwAYYcaHR0cDovL29jc3Aub25lLmRpZ2ljZXJ0LmNvbTBJBggrBgEFBQcw
AoY9aHR0cDovL2NhY2VydHMub25lLmRpZ2ljZXJ0LmNvbS9UZWxlY29tSW5mcmFQ
cm9qZWN0Um9vdENBLmNydDBKBgNVHR8EQzBBMD+gPaA7hjlodHRwOi8vY3JsLm9u
ZS5kaWdpY2VydC5jb20vVGVsZWNvbUluZnJhUHJvamVjdFJvb3RDQS5jcmwwDQYJ
KoZIhvcNAQELBQADggEBAFbz+K94bHIkBMJqps0dApniUmOn0pO6Q6cGh47UP/kX
IiPIsnYgG+hqYD/qtsiqJhaWi0hixRWn38UmvZxMRk27aSTGE/TWx0JTC3qDGsSe
XkUagumbSfmS0ZyiTwMPeGAjXwyzGorqZWeA95eKfImntMiOf3E7//GK0K7HpCx8
IPCnLZsZD2q/mLyBsduImFIRQJbLAhwIxpcd1qYJk+BlGFL+HtBpEbq6JxW2Xy+v
DpNWc2WIsUTle0rTc9JNJrLX4ChUJmKqf8obKHap3Xh3//qw/jDB9pOAinA33FLJ
EmCnwBvQr9mfNmPBGMYZVU8cPruDQJ57GjmmvdisbJY=
-----END CERTIFICATE-----
# restapi-ca.pem: ""
# restapi-cert.pem: ""
# restapi-key.pem: ""
root.pem: |
-----BEGIN CERTIFICATE-----
MIIDojCCAoqgAwIBAgIUPVYBpqNbcLYygF6Mx+qxSWwQyFowDQYJKoZIhvcNAQEL
BQAwaTELMAkGA1UEBhMCVVMxJDAiBgNVBAoTG1RlbGVjb20gSW5mcmEgUHJvamVj
dCwgSW5jLjEMMAoGA1UECxMDVElQMSYwJAYDVQQDEx1UZWxlY29tIEluZnJhIFBy
b2plY3QgUm9vdCBDQTAeFw0yMTA0MTMyMjQyNDRaFw0zMTA0MTMyMjM4NDZaMGkx
CzAJBgNVBAYTAlVTMSQwIgYDVQQKExtUZWxlY29tIEluZnJhIFByb2plY3QsIElu
Yy4xDDAKBgNVBAsTA1RJUDEmMCQGA1UEAxMdVGVsZWNvbSBJbmZyYSBQcm9qZWN0
IFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDIGCibwf5u
AAwZ+1H8U0e3u2V+0d2gSctucoK86XwUmfe1V2a/qlCYZd29r80IuN1IIeB0naIm
KnK/MzXW87clF6tFd1+HzEvmlY/W4KyIXalVCTEzirFSvBEG2oZpM0yC3AefytAO
aOpA00LaM3xTfTqMKIRhJBuLy0I4ANUVG6ixVebbGuc78IodleqiLoWy2Q9QHyEO
t/7hZndJhiVogh0PveRhho45EbsACu7ymDY+JhlIleevqwlE3iQoq0YcmYADHno6
Eq8vcwLpZFxihupUafkd1T3WJYQAJf9coCjBu2qIhNgrcrGD8R9fGswwNRzMRMpX
720+GjcDW3bJAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFAJG
lmB5sVP2qfL3xZ8hQOTpkQH6MA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0BAQsF
AAOCAQEAVjl9dm4epG9NUYnagT9sg7scVQEPfz3Lt6w1NXJXgD8mAUlK0jXmEyvM
dCPD4514n+8+lM7US8fh+nxc7jO//LwK17Wm9FblgjNFR7+anv0Q99T9fP19DLlF
PSNHL2emogy1bl1lLTAoj8nxg2wVKPDSHBGviQ5LR9fsWUIJDv9Bs5k0qWugWYSj
19S6qnHeskRDB8MqRLhKMG82oDVLerSnhD0P6HjySBHgTTU7/tYS/OZr1jI6MPbG
L+/DtiR5fDVMNdBSGU89UNTi0wHY9+RFuNlIuvZC+x/swF0V9R5mN+ywquTPtDLA
5IOM7ItsRmen6u3qu+JXros54e4juQ==
-----END CERTIFICATE-----
# websocket-cert.pem: ""
# websocket-key.pem: ""
certsCAs:
issuer.pem: ""
root.pem: ""
issuer.pem: |
-----BEGIN CERTIFICATE-----
MIIEnDCCA4SgAwIBAgIUVpyCUx1MUeUwxg+7I1BvGFTz7HkwDQYJKoZIhvcNAQEL
BQAwaTELMAkGA1UEBhMCVVMxJDAiBgNVBAoTG1RlbGVjb20gSW5mcmEgUHJvamVj
dCwgSW5jLjEMMAoGA1UECxMDVElQMSYwJAYDVQQDEx1UZWxlY29tIEluZnJhIFBy
b2plY3QgUm9vdCBDQTAeFw0yMTA0MTMyMjUxMjZaFw0yNjA0MTMyMjM4NDZaMGwx
CzAJBgNVBAYTAlVTMSQwIgYDVQQKExtUZWxlY29tIEluZnJhIFByb2plY3QsIElu
Yy4xDDAKBgNVBAsTA1RJUDEpMCcGA1UEAxMgVGVsZWNvbSBJbmZyYSBQcm9qZWN0
IElzc3VpbmcgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDtKBrq
qd2aKVSk25KfL5xHu8X7/8rJrz3IvyPuVKWhk/N1zabot3suBcGaYNKjnRHxg78R
yKwKzajKYWtiQFqztu24g16LQeAnoUxZnF6a0z3JkkRPsz14A2y8TUhdEe1tx+UU
4VGsk3n+FMmOQHL+79FO57zQC1LwylgfLSltrI6mF3jowVUQvnwzKhUzT87AJ6EO
ndK/q0T/Bgi+aI39zfVOjJjsTJwghvrmYW3iarP1THSKxeib2s02bZKrvvHa5HL4
UI8+LvREpVZl4mzt1z6Nl344Y6f+UeJlYa/Ci0jJqaXJmyVnUbAz+c0i5JfwAVn3
YQzfC4eLnZCmdF8zAgMBAAGjggE3MIIBMzAPBgNVHRMBAf8EBTADAQH/MB0GA1Ud
DgQWBBSzG1S44EerPfM4gOQ85f0AYW3R6DAfBgNVHSMEGDAWgBQCRpZgebFT9qny
98WfIUDk6ZEB+jAOBgNVHQ8BAf8EBAMCAYYwgYMGCCsGAQUFBwEBBHcwdTAoBggr
BgEFBQcwAYYcaHR0cDovL29jc3Aub25lLmRpZ2ljZXJ0LmNvbTBJBggrBgEFBQcw
AoY9aHR0cDovL2NhY2VydHMub25lLmRpZ2ljZXJ0LmNvbS9UZWxlY29tSW5mcmFQ
cm9qZWN0Um9vdENBLmNydDBKBgNVHR8EQzBBMD+gPaA7hjlodHRwOi8vY3JsLm9u
ZS5kaWdpY2VydC5jb20vVGVsZWNvbUluZnJhUHJvamVjdFJvb3RDQS5jcmwwDQYJ
KoZIhvcNAQELBQADggEBAFbz+K94bHIkBMJqps0dApniUmOn0pO6Q6cGh47UP/kX
IiPIsnYgG+hqYD/qtsiqJhaWi0hixRWn38UmvZxMRk27aSTGE/TWx0JTC3qDGsSe
XkUagumbSfmS0ZyiTwMPeGAjXwyzGorqZWeA95eKfImntMiOf3E7//GK0K7HpCx8
IPCnLZsZD2q/mLyBsduImFIRQJbLAhwIxpcd1qYJk+BlGFL+HtBpEbq6JxW2Xy+v
DpNWc2WIsUTle0rTc9JNJrLX4ChUJmKqf8obKHap3Xh3//qw/jDB9pOAinA33FLJ
EmCnwBvQr9mfNmPBGMYZVU8cPruDQJ57GjmmvdisbJY=
-----END CERTIFICATE-----
root.pem: |
-----BEGIN CERTIFICATE-----
MIIDojCCAoqgAwIBAgIUPVYBpqNbcLYygF6Mx+qxSWwQyFowDQYJKoZIhvcNAQEL
BQAwaTELMAkGA1UEBhMCVVMxJDAiBgNVBAoTG1RlbGVjb20gSW5mcmEgUHJvamVj
dCwgSW5jLjEMMAoGA1UECxMDVElQMSYwJAYDVQQDEx1UZWxlY29tIEluZnJhIFBy
b2plY3QgUm9vdCBDQTAeFw0yMTA0MTMyMjQyNDRaFw0zMTA0MTMyMjM4NDZaMGkx
CzAJBgNVBAYTAlVTMSQwIgYDVQQKExtUZWxlY29tIEluZnJhIFByb2plY3QsIElu
Yy4xDDAKBgNVBAsTA1RJUDEmMCQGA1UEAxMdVGVsZWNvbSBJbmZyYSBQcm9qZWN0
IFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDIGCibwf5u
AAwZ+1H8U0e3u2V+0d2gSctucoK86XwUmfe1V2a/qlCYZd29r80IuN1IIeB0naIm
KnK/MzXW87clF6tFd1+HzEvmlY/W4KyIXalVCTEzirFSvBEG2oZpM0yC3AefytAO
aOpA00LaM3xTfTqMKIRhJBuLy0I4ANUVG6ixVebbGuc78IodleqiLoWy2Q9QHyEO
t/7hZndJhiVogh0PveRhho45EbsACu7ymDY+JhlIleevqwlE3iQoq0YcmYADHno6
Eq8vcwLpZFxihupUafkd1T3WJYQAJf9coCjBu2qIhNgrcrGD8R9fGswwNRzMRMpX
720+GjcDW3bJAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFAJG
lmB5sVP2qfL3xZ8hQOTpkQH6MA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0BAQsF
AAOCAQEAVjl9dm4epG9NUYnagT9sg7scVQEPfz3Lt6w1NXJXgD8mAUlK0jXmEyvM
dCPD4514n+8+lM7US8fh+nxc7jO//LwK17Wm9FblgjNFR7+anv0Q99T9fP19DLlF
PSNHL2emogy1bl1lLTAoj8nxg2wVKPDSHBGviQ5LR9fsWUIJDv9Bs5k0qWugWYSj
19S6qnHeskRDB8MqRLhKMG82oDVLerSnhD0P6HjySBHgTTU7/tYS/OZr1jI6MPbG
L+/DtiR5fDVMNdBSGU89UNTi0wHY9+RFuNlIuvZC+x/swF0V9R5mN+ywquTPtDLA
5IOM7ItsRmen6u3qu+JXros54e4juQ==
-----END CERTIFICATE-----
# PostgreSQL (https://github.com/bitnami/charts/tree/master/bitnami/postgresql)
postgresql:

View File

@@ -31,13 +31,58 @@ components:
responses:
NotFound:
$ref: 'https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml#/components/responses/NotFound'
description: The specified resource was not found.
content:
application/json:
schema:
properties:
ErrorCode:
type: integer
ErrorDetails:
type: string
ErrorDescription:
type: string
Unauthorized:
$ref: 'https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml#/components/responses/Unauthorized'
description: The requested does not have sufficient rights to perform the operation.
content:
application/json:
schema:
properties:
ErrorCode:
type: integer
enum:
- 0 # Success
- 1 # PASSWORD_CHANGE_REQUIRED,
- 2 # INVALID_CREDENTIALS,
- 3 # PASSWORD_ALREADY_USED,
- 4 # USERNAME_PENDING_VERIFICATION,
- 5 # PASSWORD_INVALID,
- 6 # INTERNAL_ERROR,
- 7 # ACCESS_DENIED,
- 8 # INVALID_TOKEN
- 9 # EXPIRED_TOKEN
- 10 # RATE_LIMIT_EXCEEDED
- 11 # BAD_MFA_TRANSACTION
- 12 # MFA_FAILURE
- 13 # SECURITY_SERVICE_UNREACHABLE
ErrorDetails:
type: string
ErrorDescription:
type: string
Success:
$ref: 'https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml#/components/responses/Success'
BadRequest:
$ref: 'https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml#/components/responses/BadRequest'
description: The requested operation was performed.
content:
application/json:
schema:
properties:
Operation:
type: string
Details:
type: string
Code:
type: integer
schemas:
DeviceType:
@@ -190,18 +235,6 @@ components:
type: string
minLength: 2
maxLength: 2
started:
type: integer
format: int64
sessionId:
type: integer
format: int64
connectionCompletionTime:
type: number
format: double
totalConnectionTime:
type: integer
format: int64
DeviceList:
type: object
@@ -294,17 +327,6 @@ components:
type: integer
format: int64
DeviceConnectionStatistics:
type: object
description: Return some basic device statistics.
properties:
connectedDevices:
type: integer
format: int64
averageConnectionTime:
type: integer
format: int64
StatisticsDetails:
type: object
properties:
@@ -1068,37 +1090,6 @@ components:
type: integer
weight:
type: integer
secret:
type: string
certificate:
type: string
radsec:
type: boolean
default: false
radsecPort:
type: integer
minimum: 1
maximum: 65535
radsecSecret:
type: string
radsecCacerts:
type: array
items:
type: string
radsecCert:
type: string
description: this must be the base64 encoded of the entire content of the certificate file, including the -----BEGIN lines
radsecKey:
type: string
description: this must be the base64 encoded of the entire content of the key file, including the -----BEGIN lines
radsecRealms:
description: each entry must be the base64 encoded of the entire content of the ca files, including the -----BEGIN lines
type: array
items:
type: string
ignore:
type: boolean
default: false
RadiusProxyServerConfig:
type: object
@@ -1138,8 +1129,6 @@ components:
$ref: '#/components/schemas/RadiusProxyServerConfig'
acctConfig:
$ref: '#/components/schemas/RadiusProxyServerConfig'
coaConfig:
$ref: '#/components/schemas/RadiusProxyServerConfig'
RadiusProxyPoolList:
type: object
@@ -1212,13 +1201,6 @@ paths:
type: boolean
default: false
required: false
- in: query
description: return extended information
name: connectionStatistics
schema:
type: boolean
default: false
required: false
responses:
200:
description: List devices
@@ -1230,7 +1212,6 @@ paths:
- $ref: '#/components/schemas/DeviceListWithStatus'
- $ref: '#/components/schemas/SerialNumberList'
- $ref: '#/components/schemas/DeviceCount'
- $ref: '#/components/schemas/DeviceConnectionStatistics'
403:
$ref: '#/components/responses/Unauthorized'
404:
@@ -2611,16 +2592,6 @@ paths:
403:
$ref: '#/components/responses/Unauthorized'
delete:
tags:
- RADIUSProxy
summary: Delete RADIUS Proxy configuration.
operationId: deleteRadiusProxyConfig
responses:
204:
$ref: '#/components/responses/Success'
403:
$ref: '#/components/responses/Unauthorized'
/deviceDashboard:
get:

View File

@@ -65,7 +65,6 @@ openwifi.system.debug = true
openwifi.system.uri.private = https://localhost:17002
openwifi.system.uri.public = https://ucentral.dpaas.arilia.com:16002
openwifi.system.uri.ui = https://ucentral-ui.arilia.com
openwifi.security.restapi.disable = false
openwifi.system.commandchannel = /tmp/app.ucentralgw
#
@@ -97,12 +96,6 @@ rtty.timeout = 60
rtty.viewport = 5913
rtty.assets = $OWGW_ROOT/rtty_ui
### RADIUS proxy config
radius.proxy.enable = false
radius.proxy.accounting.port = 1813
radius.proxy.authentication.port = 1812
radius.proxy.coa.port = 3799
#############################
# Generic information for all micro services
#############################
@@ -178,4 +171,4 @@ archiver.db.3.keep = 7
########################################################################
logging.type = file
logging.path = $OWGW_ROOT/logs
logging.level = information
logging.level = debug

View File

@@ -52,8 +52,8 @@ 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}
openwifi.fileuploader.maxsize = 10000
openwifi.fileuploader.uri = ${FILEUPLOADER_URI}
openwifi.fileuploader.maxsize = 10000
#
# Generic section that all microservices must have
@@ -65,7 +65,6 @@ openwifi.system.debug = true
openwifi.system.uri.private = ${SYSTEM_URI_PRIVATE}
openwifi.system.uri.public = ${SYSTEM_URI_PUBLIC}
openwifi.system.uri.ui = ${SYSTEM_URI_UI}
openwifi.security.restapi.disable = ${SECURITY_RESTAPI_DISABLE}
openwifi.system.commandchannel = /tmp/app.ucentralgw
#
@@ -76,13 +75,8 @@ openwifi.devicetypes.0 = AP:linksys_ea8300,edgecore_eap101,linksys_e8450-ubi
openwifi.devicetypes.1 = SWITCH:edgecore_ecs4100-12ph
openwifi.devicetypes.2 = IOT:esp32
oui.download.uri = https://standards-oui.ieee.org/oui/oui.txt
firmware.autoupdate.policy.default = auto
simulatorid = ${SIMULATORID}
iptocountry.default = US
iptocountry.provider = ${IPTOCOUNTRY_PROVIDER}
iptocountry.ipinfo.token = ${IPTOCOUNTRY_IPINFO_TOKEN}
iptocountry.ipdata.apikey = ${IPTOCOUNTRY_IPDATA_APIKEY}
autoprovisioning.process = ${AUTOPROVISIONING_PROCESS}
#
# rtty
@@ -96,12 +90,6 @@ rtty.timeout = ${RTTY_TIMEOUT}
rtty.viewport = ${RTTY_VIEWPORT}
rtty.assets = ${RTTY_ASSETS}
### RADIUS proxy config
radius.proxy.enable = ${RADIUS_PROXY_ENABLE}
radius.proxy.accounting.port = ${RADIUS_PROXY_ACCOUNTING_PORT}
radius.proxy.authentication.port = ${RADIUS_PROXY_AUTHENTICATION_PORT}
radius.proxy.coa.port = ${RADIUS_PROXY_COA_PORT}
#############################
# Generic information for all micro services
#############################
@@ -120,7 +108,6 @@ openwifi.kafka.enable = ${KAFKA_ENABLE}
openwifi.kafka.brokerlist = ${KAFKA_BROKERLIST}
openwifi.kafka.auto.commit = false
openwifi.kafka.queue.buffering.max.ms = 50
openwifi.kafka.ssl.ca.location = ${KAFKA_SSL_CA_LOCATION}
openwifi.kafka.ssl.certificate.location = ${KAFKA_SSL_CERTIFICATE_LOCATION}
openwifi.kafka.ssl.key.location = ${KAFKA_SSL_KEY_LOCATION}
@@ -174,4 +161,4 @@ archiver.db.3.keep = 7
########################################################################
logging.type = console
logging.path = $OWGW_ROOT/logs
logging.level = information
logging.level = debug

View File

@@ -1 +0,0 @@
192.168.178.1

View File

@@ -1,205 +0,0 @@
{
"interfaces": [
{
"ethernet": [
{
"select-ports": [
"WAN*"
]
}
],
"ipv4": {
"addressing": "dynamic"
},
"ipv6": {
"addressing": "dynamic"
},
"name": "wan",
"role": "upstream",
"services": [
"ssh"
],
"ssids": []
},
{
"ethernet": [
{
"select-ports": [
"LAN*"
]
}
],
"ipv4": {
"addressing": "static",
"dhcp": {
"lease-count": 100,
"lease-first": 10,
"lease-time": "6h"
},
"gateway": "192.168.1.1",
"send-hostname": true,
"subnet": "192.168.1.1/24",
"use-dns": []
},
"ipv6": {
"addressing": "dynamic"
},
"name": "lan",
"role": "downstream",
"services": [
"wifi-steering",
"ssh"
],
"ssids": [
{
"bss-mode": "ap",
"encryption": {
"ieee80211w": "required",
"proto": "wpa"
},
"hidden-ssid": false,
"isolate-clients": false,
"maximum-clients": 64,
"name": "arilia-rad",
"radius": {
"authentication": {
"host": "0.0.0.0",
"port": 1812,
"secret": "radsec"
},
"accounting": {
"host": "0.0.0.0",
"port": 1813,
"secret": "radsec"
}
},
"services": [
"radius-gw-proxy"
],
"wifi-bands": [
"2G",
"5G"
],
"pass-point": {
"venue-name": [
"eng:Example passpoint_venue",
"fra:Exemple de lieu"
],
"domain-name": [
"onboard.almondlabs.net",
"test.com"
],
"asra": false,
"internet": true,
"esr": false,
"uesa": false,
"access-network-type": 0,
"hessid":"11:22:33:44:55:66",
"venue-group": 2,
"venue-type": 8,
"connection-capability":[
"1:0:2",
"6:22:1",
"17:5060:0"
],
"roaming-consortium": [
"F4F5E8F5F4",
"BAA2D00100",
"BAA2D00000"
],
"disable-dgaf": true,
"anqp-domain": 8888,
"ipaddr-type-available": 14,
"nai-realm": [
],
"osen": false,
"anqp-3gpp-cell-net": [
],
"friendly-name": [
"eng:AlmondLabs",
"fra:AlmondLabs"
],
"venue-url": [
"http://www.example.com/info-fra",
"http://www.example.com/info-eng"
],
"auth-type": {
"type": "terms-and-conditions"
}
}
}
]
}
],
"metrics": {
"dhcp-snooping": {
"filters": [
"ack",
"discover",
"offer",
"request",
"solicit",
"reply",
"renew"
]
},
"health": {
"interval": 60
},
"statistics": {
"interval": 60,
"types": [
"ssids",
"lldp",
"clients"
]
},
"wifi-frames": {
"filters": [
"probe",
"auth",
"assoc",
"disassoc",
"deauth",
"local-deauth",
"inactive-deauth",
"key-mismatch",
"beacon-report",
"radar-detected"
]
}
},
"radios": [
{
"band": "2G",
"bandwidth": 10,
"beacon-interval": 100,
"channel": "auto",
"channel-mode": "HT",
"channel-width": 20,
"country": "CA",
"dtim-period": 2,
"maximum-clients": 64,
"tx-power": 0
},
{
"band": "5G",
"bandwidth": 20,
"beacon-interval": 100,
"channel": "auto",
"channel-mode": "HE",
"channel-width": 40,
"country": "CA",
"dtim-period": 2,
"maximum-clients": 64,
"tx-power": 0
}
],
"services": {
"ssh": {
"password-authentication": true,
"port": 22
}
},
"uuid": 1661312631
}

View File

@@ -1,72 +0,0 @@
{
"pools" : [
{
"name" : "master" ,
"description" : "master pool",
"useByDefault" : true,
"authConfig" : {
"strategy" : "weighted",
"monitor" : false,
"monitorMethod" : "none",
"methodParameters" : [],
"servers" : [ {
"name" : "svr1",
"ip" : "10.100.0.1",
"port" : 1812,
"weight" : 10,
"secret" : "my_secret!"
},
{
"name" : "svr2",
"ip" : "10.100.10.1",
"port" : 1812,
"weight" : 20,
"secret" : "my_secret!"
}
]
},
"acctConfig" : {
"strategy" : "random",
"monitor" : false,
"monitorMethod" : "none",
"methodParameters" : [],
"servers" : [ {
"name" : "svr1",
"ip" : "10.100.0.1",
"port" : 1813,
"weight" : 10,
"secret" : "my_secret!"
},
{
"name" : "svr2",
"ip" : "10.100.10.1",
"port" : 1813,
"weight" : 20,
"secret" : "my_secret!"
}
]
},
"coaConfig" : {
"strategy" : "round_robin",
"monitor" : false,
"monitorMethod" : "none",
"methodParameters" : [],
"servers" : [ {
"name" : "svr1",
"ip" : "10.100.0.1",
"port" : 3799,
"weight" : 10,
"secret" : "my_secret!"
},
{
"name" : "svr2",
"ip" : "10.100.10.1",
"port" : 3799,
"weight" : 20,
"secret" : "my_secret!"
}
]
}
}
]
}

View File

@@ -1,32 +0,0 @@
{
"pools" : [
{
"name" : "master" ,
"description" : "master pool",
"useByDefault" : true,
"authConfig" : {
"strategy" : "weighted",
"monitor" : false,
"monitorMethod" : "none",
"methodParameters" : [],
"servers" : [ {
"name" : "orion",
"ip" : "216.239.32.91",
"port" : 2083,
"weight" : 10,
"radsec" : true,
"radsecPort" : 2083,
"radsecSecret" : "radsec",
"radsecKey" : "LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IY0NBUUVFSUR6RnpXeTZlYXg0QVoxTySG9VUURRZ0FFS3BnWVBHMktPTVd2S0w1Z3NMRXpUc09rREg1M3NHaEQyS3RsRXBDTXVnNDNIZlFnTFVpUgpTR1R2S1l0bDFmbmJaU1lnY0RJdncxdjNYRy9hVDhOY2JBPT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQo=",
"radsecCert" : "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNRVENDQWVpZ0F3SUJBZ0lVY3BKS3pVM0Ba0dBMVVFQmhNQ1ZWTXhFekFSQmdOVkJBb1RDa0oxZEhSdmJuZHZiMlF4SFRBYkJnTlZCQU1URkVKMQpkSFJ2Ym5kdmIyUWdVbUZrYzJWaklFTkJNQjRYRFRJeU1EY3dNekExTWpVeE5Gb1hEVEkzTURVeE9UQTFNalV4Ck5Gb3dkVEVMTUFrR0ExVUVCaE1DVlZNeEV6QVJCZ05WQkFvVENrSjFkSFJ2Ym5kdmIyUXhOakEwQmdOVkJBTVQKTFdGeWFXeHBZUzVqWWpFd2FtTnVjemgxYlhCbk9HWnBjRFowTUM1dmNtbHZiaTVoY21WaE1USXdMbU52YlRFWgpNQmNHQ2dtU0pvbVQ4aXhrQVFFVENVZHZiMmRzWlRwVlV6QlpNQk1HQnlxR1NNNDlBZ0VHQ0NxR1NNNDlBd0VICkEwSUFCQ3FZR0R4dGlqakZyeWkrWUxDeE0wN0RwQXgrZDdCb1E5aXJaUktRakxvT054MzBJQzFJa1Voazd5bUwKWmRYNTIyVW1JSEF5TDhOYjkxeHYyay9EWEd5amdZa3dnWVl3RGdZRFZSMFBBUUgvQkFRREFnZUFNQk1HQTFVZApKUVFNTUFvR0NDc0dBUVVGQndNQ01Bd0dBMVVkRXdFQi93UUNNQUF3T0FZRFZSMFJCREV3TDRJdFlYSnBiR2xoCkxtTmlNVEJxWTI1ek9IVnRjR2M0Wm1sd05uUXdMbTl5YVc5dUxtRnlaV0V4TWpBdVkyOXRNQmNHQTFVZElBUVEKTUE0d0RBWUtLd1lCQkFIdUtnRUJCVEFLQmdncWhrak9QUVFEQWdOSEFEQkVBaUFwTmM1dUNBSkp6KzVyakdqdwpCWGtOdHE3UU83bWU5dUg5bkNsTDZnSVE5Z0lnUHM2VkVKVW5CcEZ0RktXbFF4eWJ1YlBxYnpJNjBPSERHQ0ExCmhXUk1PS1U9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K",
"radsecCacerts" : [
"LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJ0akNDQVZ1Z0F3SUJBZ0lCQyOXZaREVkTUJzR0ExVUVBeE1VUW5WMGRHOXVkMjl2WkNCU1lXUnpaV01nUTBFdwpJQmNOTVRrd05qQTJNVFV4TlRNeVdoZ1BNalV4T1RBMk1EY3hOVEUxTXpKYU1FRXhDekFKQmdOVkJBWVRBbFZUCk1STXdFUVlEVlFRS0V3cENkWFIwYjI1M2IyOWtNUjB3R3dZRFZRUURFeFJDZFhSMGIyNTNiMjlrSUZKaFpITmwKWXlCRFFUQlpNQk1HQnlxR1NNNDlBZ0VHQ0NxR1NNNDlBd0VIQTBJQUJJUW40QVBKaXdvUVFQblR1cFgrZTk1Ugp0ZzVoQVFVbUhCN1E0UkpwSG4welF6TUJpMDdSejkxV05RamFHeERydktLVlQ1OThIM2dxYkI4TTViOHN3aytqClFqQkFNQTRHQTFVZER3RUIvd1FFQXdJQ2hEQWRCZ05WSFNVRUZqQVVCZ2dyQmdFRkJRY0RBZ1lJS3dZQkJRVUgKQXdFd0R3WURWUjBUQVFIL0JBVXdBd0VCL3pBS0JnZ3Foa2pPUFFRREFnTkpBREJHQWlFQTkrbHUwN2NlaGc1OQpxSi81dWtzN05oL3F2aXFHWCs1WDFwSVVxdENGVlJjQ0lRREZmUGhwZzZJOFE0SUdBbzNuamlHRTdDWC9nMm56CkRzSW5FcG9vRlkxV0xRPT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo="
],
"radsecRealms" : [],
"ignore" : false
}
]
}
}
]
}

View File

@@ -1,814 +0,0 @@
//
// Created by stephane bourque on 2022-02-03.
//
#include "AP_WS_Connection.h"
#include "Poco/Net/SecureStreamSocketImpl.h"
#include "Poco/Net/HTTPServerResponseImpl.h"
#include "Poco/Net/HTTPServerRequestImpl.h"
#include "Poco/Net/NetException.h"
#include "Poco/Net/SSLException.h"
#include "Poco/Net/Context.h"
#include "Poco/Base64Decoder.h"
#include "Poco/zlib.h"
#include "AP_WS_Server.h"
#include "CentralConfig.h"
#include "CommandManager.h"
#include "ConfigurationCache.h"
#include "StorageService.h"
#include "TelemetryStream.h"
#include "framework/WebSocketClientNotifications.h"
#include "Poco/Net/WebSocketImpl.h"
#include "RADIUS_proxy_server.h"
namespace OpenWifi {
#define DBL { std::cout << __LINE__ << " ID: " << ConnectionId_ << " Ser: " << SerialNumber_ << std::endl; }
void AP_WS_Connection::LogException(const Poco::Exception &E) {
poco_information(Logger_,fmt::format("EXCEPTION({}): {}", CId_, E.displayText()));
}
AP_WS_Connection::AP_WS_Connection(Poco::Net::HTTPServerRequest &request,
Poco::Net::HTTPServerResponse &response,
std::uint64_t connection_id,
Poco::Logger &L,
Poco::Net::SocketReactor &R)
: Logger_(L) ,
Reactor_(R)
{
State_.sessionId = connection_id;
WS_ = std::make_unique<Poco::Net::WebSocket>(request,response);
auto TS = Poco::Timespan(360, 0);
WS_->setMaxPayloadSize(BufSize);
WS_->setReceiveTimeout(TS);
WS_->setNoDelay(true);
WS_->setKeepAlive(true);
WS_->setBlocking(false);
Reactor_.addEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ReadableNotification>(
*this, &AP_WS_Connection::OnSocketReadable));
Reactor_.addEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ShutdownNotification>(
*this, &AP_WS_Connection::OnSocketShutdown));
Reactor_.addEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ErrorNotification>(
*this, &AP_WS_Connection::OnSocketError));
Registered_ = true;
Valid_ = true;
}
class ThreadedCounter {
public:
ThreadedCounter(bool T, std::atomic_uint64_t &C) :
C_(C),
Threaded_(T) {
if(Threaded_) {
C_++;
}
}
~ThreadedCounter() {
if(Threaded_ && C_>0) {
C_--;
}
}
private:
std::atomic_uint64_t &C_;
bool Threaded_;
};
bool AP_WS_Connection::ValidatedDevice() {
if(DeviceValidated_)
return true;
if(!Valid_)
return false;
try {
auto SockImpl = dynamic_cast<Poco::Net::WebSocketImpl *>(WS_->impl());
auto SS = dynamic_cast<Poco::Net::SecureStreamSocketImpl*>(SockImpl->streamSocketImpl());
PeerAddress_ = SS->peerAddress().host();
CId_ = Utils::FormatIPv6(SS->peerAddress().toString());
State_.started = OpenWifi::Now();
if (!SS->secure()) {
poco_warning(Logger_,fmt::format("TLS-CONNECTION({}): Session={} Connection is NOT secure. Device is not allowed.", CId_, State_.sessionId ));
EndConnection();
return false;
}
poco_debug(Logger_,fmt::format("TLS-CONNECTION({}): Session={} Connection is secure.", CId_, State_.sessionId ));
if (!SS->havePeerCertificate()) {
State_.VerifiedCertificate = GWObjects::NO_CERTIFICATE;
poco_warning(Logger_,fmt::format("TLS-CONNECTION({}): Session={} No certificates available..", CId_, State_.sessionId ));
EndConnection();
return false;
}
Poco::Crypto::X509Certificate PeerCert(SS->peerCertificate());
if (!AP_WS_Server()->ValidateCertificate(CId_, PeerCert)) {
State_.VerifiedCertificate = GWObjects::NO_CERTIFICATE;
poco_warning(Logger_, fmt::format("TLS-CONNECTION({}): Session={} Device certificate is not valid. Device is not allowed.",
CId_, State_.sessionId ));
EndConnection();
return false;
}
CN_ = Poco::trim(Poco::toLower(PeerCert.commonName()));
State_.VerifiedCertificate = GWObjects::VALID_CERTIFICATE;
poco_debug(Logger_,
fmt::format("TLS-CONNECTION({}): Session={} Valid certificate: CN={}", CId_, State_.sessionId , CN_));
if (AP_WS_Server::IsSim(CN_) && !AP_WS_Server()->IsSimEnabled()) {
poco_warning(
Logger_,
fmt::format("TLS-CONNECTION({}): Session={} Sim Device {} is not allowed. Disconnecting.",
CId_, State_.sessionId , CN_));
EndConnection();
return false;
}
if (!CN_.empty() && StorageService()->IsBlackListed(SerialNumber_)) {
poco_warning(
Logger_,
fmt::format("TLS-CONNECTION({}): Session={} Device {} is black listed. Disconnecting.",
CId_, State_.sessionId , CN_));
EndConnection();
return false;
}
SerialNumber_ = CN_;
SerialNumberInt_ = Utils::SerialNumberToInt(SerialNumber_);
poco_debug(Logger_, fmt::format("TLS-CONNECTION({}): Session={} CN={} Completed. (t={})", CId_, State_.sessionId , CN_, ConcurrentStartingDevices_));
DeviceValidated_ = true;
return true;
} catch (const Poco::Net::CertificateValidationException &E) {
poco_error(Logger_,fmt::format("CONNECTION({}): Session:{} Poco::CertificateValidationException Certificate Validation failed during connection. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (const Poco::Net::WebSocketException &E) {
poco_error(Logger_,fmt::format("CONNECTION({}): Session:{} Poco::WebSocketException WebSocket error during connection. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (const Poco::Net::ConnectionAbortedException &E) {
poco_error(Logger_,fmt::format("CONNECTION({}):Session:{} Poco::ConnectionAbortedException Connection was aborted during connection. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (const Poco::Net::ConnectionResetException &E) {
poco_error(Logger_,fmt::format("CONNECTION({}): Session:{} Poco::ConnectionResetException Connection was reset during connection. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (const Poco::Net::InvalidCertificateException &E) {
poco_error(Logger_,fmt::format(
"CONNECTION({}): Session:{} Poco::InvalidCertificateException Invalid certificate. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (const Poco::Net::SSLException &E) {
poco_error(Logger_,fmt::format("CONNECTION({}): Session:{} Poco::SSLException SSL Exception during connection. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (const Poco::Exception &E) {
poco_error(Logger_,fmt::format("CONNECTION({}): Session:{} Poco::Exception caught during device connection. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (...) {
poco_error(Logger_,fmt::format("CONNECTION({}): Session:{} Exception caught during device connection. Device will have to retry. Unsecure connect denied.",
CId_, State_.sessionId ));
}
EndConnection();
return false;
}
static void NotifyKafkaDisconnect(const std::string & SerialNumber) {
try {
Poco::JSON::Object Disconnect;
Poco::JSON::Object Details;
Details.set(uCentralProtocol::SERIALNUMBER, SerialNumber);
Details.set(uCentralProtocol::TIMESTAMP, OpenWifi::Now());
Disconnect.set(uCentralProtocol::DISCONNECTION, Details);
Poco::JSON::Stringifier Stringify;
std::ostringstream OS;
Stringify.condense(Disconnect, OS);
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber, OS.str());
} catch (...) {
}
}
AP_WS_Connection::~AP_WS_Connection() {
std::cout << "Deleting session=" << State_.sessionId << std::endl;
Valid_=false;
EndConnection();
}
void AP_WS_Connection::EndConnection() {
Valid_=false;
if(!Dead_.test_and_set()) {
if (Registered_) {
Registered_ = false;
Reactor_.removeEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ReadableNotification>(
*this, &AP_WS_Connection::OnSocketReadable));
Reactor_.removeEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ShutdownNotification>(
*this, &AP_WS_Connection::OnSocketShutdown));
Reactor_.removeEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ErrorNotification>(
*this, &AP_WS_Connection::OnSocketError));
}
WS_->close();
if (KafkaManager()->Enabled() && !SerialNumber_.empty()) {
std::string s(SerialNumber_);
std::thread t([s]() { NotifyKafkaDisconnect(s); });
t.detach();
}
auto SessionDeleted = AP_WS_Server()->EndSession(State_.sessionId, SerialNumberInt_);
if (SessionDeleted)
WebSocketClientNotificationDeviceDisconnected(SerialNumber_);
}
}
bool AP_WS_Connection::LookForUpgrade(const uint64_t UUID, uint64_t & UpgradedUUID) {
// A UUID of zero means ignore updates for that connection.
if (UUID == 0)
return false;
uint64_t GoodConfig = ConfigurationCache().CurrentConfig(SerialNumberInt_);
if (GoodConfig && (GoodConfig == UUID || GoodConfig == State_.PendingUUID)) {
UpgradedUUID = UUID;
return false;
}
GWObjects::Device D;
if (StorageService()->GetDevice(SerialNumber_, D)) {
// 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;
}
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.
Config::Config Cfg(D.Configuration);
D.UUID = UUID+2;
UpgradedUUID = D.UUID;
Cfg.SetUUID(D.UUID);
D.Configuration = Cfg.get();
StorageService()->UpdateDevice(D);
}
UpgradedUUID = D.UUID;
State_.PendingUUID = D.UUID;
GWObjects::CommandDetails Cmd;
Cmd.SerialNumber = SerialNumber_;
Cmd.UUID = MicroService::CreateUUID();
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()->NextRPCId(),SerialNumber_, Cmd.Command, Params, Cmd.UUID, Sent);
WebSocketClientNotificationDeviceConfigurationChange(D.SerialNumber, UUID, UpgradedUUID);
return true;
}
return false;
}
void AP_WS_Connection::ProcessJSONRPCResult(Poco::JSON::Object::Ptr Doc) {
poco_debug(Logger_,fmt::format("RECEIVED-RPC({}): {}.", CId_, Doc->get(uCentralProtocol::ID).toString()));
CommandManager()->PostCommandResult(SerialNumber_, *Doc);
}
void AP_WS_Connection::ProcessJSONRPCEvent(Poco::JSON::Object::Ptr &Doc) {
auto Method = Doc->get(uCentralProtocol::METHOD).toString();
auto EventType = uCentralProtocol::Events::EventFromString(Method);
if (EventType == uCentralProtocol::Events::ET_UNKNOWN) {
poco_warning(Logger_,fmt::format("ILLEGAL-PROTOCOL({}): Unknown message type '{}'", CId_, Method));
Errors_++;
return;
}
if (!Doc->isObject(uCentralProtocol::PARAMS)) {
poco_warning(Logger_,fmt::format("MISSING-PARAMS({}): params must be an object.", CId_));
Errors_++;
return;
}
// expand params if necessary
auto ParamsObj = Doc->get(uCentralProtocol::PARAMS).extract<Poco::JSON::Object::Ptr>();
if (ParamsObj->has(uCentralProtocol::COMPRESS_64)) {
std::string UncompressedData;
try {
auto CompressedData = ParamsObj->get(uCentralProtocol::COMPRESS_64).toString();
uint64_t compress_sz = 0 ;
if(ParamsObj->has("compress_sz")) {
compress_sz = ParamsObj->get("compress_sz");
}
if (Utils::ExtractBase64CompressedData(CompressedData, UncompressedData, compress_sz)) {
poco_trace(Logger_,fmt::format("EVENT({}): Found compressed payload expanded to '{}'.",
CId_, UncompressedData));
Poco::JSON::Parser Parser;
ParamsObj = Parser.parse(UncompressedData).extract<Poco::JSON::Object::Ptr>();
} else {
poco_warning(Logger_,fmt::format("INVALID-COMPRESSED-DATA({}): Compressed cannot be uncompressed - content must be corrupt..: size={}",
CId_, CompressedData.size()));
Errors_++;
return;
}
} catch (const Poco::Exception &E) {
poco_warning(Logger_,fmt::format("INVALID-COMPRESSED-JSON-DATA({}): Compressed cannot be parsed - JSON must be corrupt..",
CId_));
Logger_.log(E);
return;
}
}
if (!ParamsObj->has(uCentralProtocol::SERIAL)) {
poco_warning(Logger_,fmt::format("MISSING-PARAMS({}): Serial number is missing in message.", CId_));
return;
}
auto Serial = Poco::trim(Poco::toLower(ParamsObj->get(uCentralProtocol::SERIAL).toString()));
if (!Utils::ValidSerialNumber(Serial)) {
Poco::Exception E(
fmt::format(
"ILLEGAL-DEVICE-NAME({}): device name is illegal and not allowed to connect.",
Serial),
EACCES);
E.rethrow();
}
if (StorageService()->IsBlackListed(Serial)) {
Poco::Exception E(
fmt::format("BLACKLIST({}): device is blacklisted and not allowed to connect.",
Serial),
EACCES);
E.rethrow();
}
switch (EventType) {
case uCentralProtocol::Events::ET_CONNECT: {
Process_connect(ParamsObj, Serial);
} break;
case uCentralProtocol::Events::ET_STATE: {
Process_state(ParamsObj);
} break;
case uCentralProtocol::Events::ET_HEALTHCHECK: {
Process_healthcheck(ParamsObj);
} break;
case uCentralProtocol::Events::ET_LOG: {
Process_log(ParamsObj);
} break;
case uCentralProtocol::Events::ET_CRASHLOG: {
Process_crashlog(ParamsObj);
} break;
case uCentralProtocol::Events::ET_PING: {
Process_ping(ParamsObj);
} break;
case uCentralProtocol::Events::ET_CFGPENDING: {
Process_cfgpending(ParamsObj);
} break;
case uCentralProtocol::Events::ET_RECOVERY: {
Process_recovery(ParamsObj);
} break;
case uCentralProtocol::Events::ET_DEVICEUPDATE: {
Process_deviceupdate(ParamsObj, Serial);
} break;
case uCentralProtocol::Events::ET_TELEMETRY: {
Process_telemetry(ParamsObj);
} break;
case uCentralProtocol::Events::ET_VENUEBROADCAST: {
Process_venuebroadcast(ParamsObj);
} break;
// this will never be called but some compilers will complain if we do not have a case for
// every single values of an enum
case uCentralProtocol::Events::ET_UNKNOWN: {
poco_warning(Logger_, fmt::format("ILLEGAL-EVENT({}): Event '{}' unknown. CN={}", CId_, Method, CN_));
Errors_++;
}
}
}
bool AP_WS_Connection::StartTelemetry(std::uint64_t RPCID) {
poco_information(Logger_, fmt::format("TELEMETRY({}): Starting.", CId_));
Poco::JSON::Object StartMessage;
StartMessage.set("jsonrpc", "2.0");
StartMessage.set("method", "telemetry");
Poco::JSON::Object Params;
Params.set("serial", SerialNumber_);
Params.set("interval", TelemetryInterval_);
Poco::JSON::Array Types;
Types.add("wifi-frames");
Types.add("dhcp-snooping");
Types.add("state");
Params.set(RESTAPI::Protocol::TYPES, Types);
StartMessage.set("id", RPCID);
StartMessage.set("params", Params);
Poco::JSON::Stringifier Stringify;
std::ostringstream OS;
Stringify.condense(StartMessage, OS);
return Send(OS.str());
}
bool AP_WS_Connection::StopTelemetry(std::uint64_t RPCID) {
poco_information(Logger_, fmt::format("TELEMETRY({}): Stopping.", CId_));
Poco::JSON::Object StopMessage;
StopMessage.set("jsonrpc", "2.0");
StopMessage.set("method", "telemetry");
Poco::JSON::Object Params;
Params.set("serial", SerialNumber_);
Params.set("interval", 0);
StopMessage.set("id", RPCID);
StopMessage.set("params", Params);
Poco::JSON::Stringifier Stringify;
std::ostringstream OS;
Stringify.condense(StopMessage, OS);
TelemetryKafkaPackets_ = TelemetryWebSocketPackets_ = TelemetryInterval_ =
TelemetryKafkaTimer_ = TelemetryWebSocketTimer_ = 0;
return Send(OS.str());
}
void AP_WS_Connection::UpdateCounts() {
State_.kafkaClients = TelemetryKafkaRefCount_;
State_.webSocketClients = TelemetryWebSocketRefCount_;
}
bool AP_WS_Connection::SetWebSocketTelemetryReporting(std::uint64_t RPCID, uint64_t Interval,
uint64_t LifeTime) {
std::unique_lock Lock(TelemetryMutex_);
TelemetryWebSocketRefCount_++;
TelemetryInterval_ = TelemetryInterval_ ? std::min(Interval, TelemetryInterval_) : Interval;
auto TelemetryWebSocketTimer = LifeTime + OpenWifi::Now();
TelemetryWebSocketTimer_ = std::max(TelemetryWebSocketTimer, TelemetryWebSocketTimer_);
UpdateCounts();
if (!TelemetryReporting_) {
TelemetryReporting_ = true;
return StartTelemetry(RPCID);
}
return true;
}
bool AP_WS_Connection::SetKafkaTelemetryReporting(std::uint64_t RPCID, uint64_t Interval, uint64_t LifeTime) {
std::unique_lock Lock(TelemetryMutex_);
TelemetryKafkaRefCount_++;
TelemetryInterval_ = TelemetryInterval_ ? std::min(Interval, TelemetryInterval_) : Interval;
auto TelemetryKafkaTimer = LifeTime + OpenWifi::Now();
TelemetryKafkaTimer_ = std::max(TelemetryKafkaTimer, TelemetryKafkaTimer_);
UpdateCounts();
if (!TelemetryReporting_) {
TelemetryReporting_ = true;
return StartTelemetry(RPCID);
}
return true;
}
bool AP_WS_Connection::StopWebSocketTelemetry(std::uint64_t RPCID) {
std::unique_lock Lock(TelemetryMutex_);
if (TelemetryWebSocketRefCount_)
TelemetryWebSocketRefCount_--;
UpdateCounts();
if (TelemetryWebSocketRefCount_ == 0 && TelemetryKafkaRefCount_ == 0) {
TelemetryReporting_ = false;
StopTelemetry(RPCID);
}
return true;
}
bool AP_WS_Connection::StopKafkaTelemetry(std::uint64_t RPCID) {
std::unique_lock Lock(TelemetryMutex_);
if (TelemetryKafkaRefCount_)
TelemetryKafkaRefCount_--;
UpdateCounts();
if (TelemetryWebSocketRefCount_ == 0 && TelemetryKafkaRefCount_ == 0) {
TelemetryReporting_ = false;
StopTelemetry(RPCID);
}
return true;
}
void AP_WS_Connection::OnSocketShutdown([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf) {
poco_trace(Logger_, fmt::format("SOCKET-SHUTDOWN({}): Closing.", CId_));
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_));
return EndConnection();
}
void AP_WS_Connection::OnSocketReadable([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf) {
if(!Valid_)
return;
if(!AP_WS_Server()->Running())
return EndConnection();
if(!ValidatedDevice())
return;
try {
return ProcessIncomingFrame();
} catch (const Poco::Exception &E) {
Logger_.log(E);
return EndConnection();
} catch (const std::exception &E) {
std::string W = E.what();
poco_information(Logger_, fmt::format("std::exception caught: {}. Connection terminated with {}", W, CId_));
return EndConnection();
} catch (...) {
poco_information(Logger_, fmt::format("Unknown exception for {}. Connection terminated.", CId_));
return EndConnection();
}
}
void AP_WS_Connection::ProcessIncomingFrame() {
Poco::Buffer<char> IncomingFrame(0);
try {
int Op, flags;
auto IncomingSize = WS_->receiveFrame(IncomingFrame, flags);
Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
if (IncomingSize == 0 && flags == 0 && Op == 0) {
poco_information(Logger_, fmt::format("DISCONNECT({}): device has disconnected. Session={}", CId_, State_.sessionId));
return EndConnection();
}
IncomingFrame.append(0);
State_.RX += IncomingSize;
State_.MessageCount++;
State_.LastContact = OpenWifi::Now();
switch (Op) {
case Poco::Net::WebSocket::FRAME_OP_PING: {
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);
State_.MessageCount++;
if (KafkaManager()->Enabled()) {
Poco::JSON::Object PingObject;
Poco::JSON::Object PingDetails;
PingDetails.set(uCentralProtocol::FIRMWARE, State_.Firmware);
PingDetails.set(uCentralProtocol::SERIALNUMBER, SerialNumber_);
PingDetails.set(uCentralProtocol::COMPATIBLE, Compatible_);
PingDetails.set(uCentralProtocol::CONNECTIONIP, CId_);
PingDetails.set(uCentralProtocol::TIMESTAMP, OpenWifi::Now());
PingDetails.set("locale", State_.locale );
PingObject.set(uCentralProtocol::PING, PingDetails);
Poco::JSON::Stringifier Stringify;
std::ostringstream OS;
Stringify.condense(PingObject, OS);
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber_, OS.str());
}
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_TEXT: {
poco_trace(Logger_, 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);
std::cout << iS.str() << std::endl;
poco_warning(Logger_, fmt::format(
"FRAME({}): illegal transaction header, missing 'jsonrpc'", CId_));
Errors_++;
}
return;
} break;
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
poco_information(Logger_,
fmt::format("CLOSE({}): Device is closing its connection.", CId_));
return EndConnection();
} break;
default: {
poco_warning(Logger_, fmt::format("UNKNOWN({}): unknown WS Frame operation: {}", CId_,
std::to_string(Op)));
} break;
}
} catch (const Poco::Net::ConnectionResetException &E) {
poco_warning(Logger_, fmt::format("ConnectionResetException({}): Text:{} Payload:{} Session:{}",
CId_,
E.displayText(),
IncomingFrame.begin()==nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
return EndConnection();
} catch (const Poco::JSON::JSONException &E) {
poco_warning(Logger_, fmt::format("JSONException({}): Text:{} Payload:{} Session:{}",
CId_,
E.displayText(),
IncomingFrame.begin()==nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
return EndConnection();
} catch (const Poco::Net::WebSocketException &E) {
poco_warning(Logger_, fmt::format("WebSocketException({}): Text:{} Payload:{} Session:{}",
CId_,
E.displayText(),
IncomingFrame.begin()==nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
return EndConnection();
} catch (const Poco::Net::SSLConnectionUnexpectedlyClosedException &E) {
poco_warning(Logger_, fmt::format("SSLConnectionUnexpectedlyClosedException({}): Text:{} Payload:{} Session:{}",
CId_,
E.displayText(),
IncomingFrame.begin()==nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
return EndConnection();
} catch (const Poco::Net::SSLException &E) {
poco_warning(Logger_, fmt::format("SSLException({}): Text:{} Payload:{} Session:{}",
CId_,
E.displayText(),
IncomingFrame.begin()==nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
return EndConnection();
} catch (const Poco::Net::NetException &E) {
poco_warning(Logger_, fmt::format("NetException({}): Text:{} Payload:{} Session:{}",
CId_,
E.displayText(),
IncomingFrame.begin()==nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
return EndConnection();
} catch (const Poco::IOException &E) {
poco_warning(Logger_, fmt::format("IOException({}): Text:{} Payload:{} Session:{}",
CId_,
E.displayText(),
IncomingFrame.begin()==nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
return EndConnection();
} catch (const Poco::Exception &E) {
poco_warning(Logger_, fmt::format("Exception({}): Text:{} Payload:{} Session:{}",
CId_,
E.displayText(),
IncomingFrame.begin()==nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
return EndConnection();
} catch (const std::exception &E) {
poco_warning(Logger_, fmt::format("std::exception({}): Text:{} Payload:{} Session:{}",
CId_,
E.what(),
IncomingFrame.begin()==nullptr ? "" : IncomingFrame.begin(),
State_.sessionId));
return EndConnection();
} catch (...) {
poco_error(Logger_,fmt::format("UnknownException({}): Device must be disconnected. Unknown exception. Session:{}", CId_, State_.sessionId));
return EndConnection();
}
if (Errors_ < 10)
return;
poco_warning(Logger_, fmt::format("DISCONNECTING({}): Too many errors", CId_));
return EndConnection();
}
bool AP_WS_Connection::Send(const std::string &Payload) {
try {
size_t BytesSent = WS_->sendFrame(Payload.c_str(), (int)Payload.size());
State_.TX += BytesSent;
return BytesSent == Payload.size();
} catch(const Poco::Exception &E) {
Logger_.log(E);
}
return false;
}
std::string Base64Encode(const unsigned char *buffer, std::size_t size) {
return Utils::base64encode(buffer,size);
}
std::string Base64Decode(const std::string &F) {
std::istringstream ifs(F);
Poco::Base64Decoder b64in(ifs);
std::ostringstream ofs;
Poco::StreamCopier::copyStream(b64in, ofs);
return ofs.str();
}
bool AP_WS_Connection::SendRadiusAuthenticationData(const unsigned char * buffer, std::size_t size) {
Poco::JSON::Object Answer;
Answer.set(uCentralProtocol::RADIUS,uCentralProtocol::RADIUSAUTH);
Answer.set(uCentralProtocol::RADIUSDATA, Base64Encode(buffer,size));
std::ostringstream Payload;
Answer.stringify(Payload);
return Send(Payload.str());
}
bool AP_WS_Connection::SendRadiusAccountingData(const unsigned char * buffer, std::size_t size) {
Poco::JSON::Object Answer;
Answer.set(uCentralProtocol::RADIUS,uCentralProtocol::RADIUSACCT);
Answer.set(uCentralProtocol::RADIUSDATA, Base64Encode(buffer,size));
std::ostringstream Payload;
Answer.stringify(Payload);
return Send(Payload.str());
}
bool AP_WS_Connection::SendRadiusCoAData(const unsigned char * buffer, std::size_t size) {
Poco::JSON::Object Answer;
Answer.set(uCentralProtocol::RADIUS,uCentralProtocol::RADIUSCOA);
Answer.set(uCentralProtocol::RADIUSDATA, Base64Encode(buffer,size));
std::ostringstream Payload;
Answer.stringify(Payload);
return Send(Payload.str());
}
void AP_WS_Connection::ProcessIncomingRadiusData(const Poco::JSON::Object::Ptr &Doc) {
if( Doc->has(uCentralProtocol::RADIUSDATA)) {
auto Type = Doc->get(uCentralProtocol::RADIUS).toString();
if(Type==uCentralProtocol::RADIUSACCT) {
auto Data = Doc->get(uCentralProtocol::RADIUSDATA).toString();
auto DecodedData = Base64Decode(Data);
RADIUS_proxy_server()->SendAccountingData(SerialNumber_,DecodedData.c_str(),DecodedData.size());
} else if(Type==uCentralProtocol::RADIUSAUTH) {
auto Data = Doc->get(uCentralProtocol::RADIUSDATA).toString();
auto DecodedData = Base64Decode(Data);
RADIUS_proxy_server()->SendAuthenticationData(SerialNumber_,DecodedData.c_str(),DecodedData.size());
} else if(Type==uCentralProtocol::RADIUSCOA) {
auto Data = Doc->get(uCentralProtocol::RADIUSDATA).toString();
auto DecodedData = Base64Decode(Data);
RADIUS_proxy_server()->SendCoAData(SerialNumber_,DecodedData.c_str(),DecodedData.size());
}
}
}
}

View File

@@ -1,128 +0,0 @@
//
// Created by stephane bourque on 2022-02-03.
//
#pragma once
#include <string>
#include <shared_mutex>
#include "Poco/Net/SocketReactor.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/JSON/Object.h"
#include "Poco/Net/SocketNotification.h"
#include "Poco/Logger.h"
#include "Poco/Net/WebSocket.h"
#include "RESTObjects/RESTAPI_GWobjects.h"
namespace OpenWifi {
class AP_WS_Connection {
static constexpr int BufSize = 256000;
public:
explicit AP_WS_Connection( Poco::Net::HTTPServerRequest &request,
Poco::Net::HTTPServerResponse &response,
std::uint64_t connection_id,
Poco::Logger &L,
Poco::Net::SocketReactor &R);
~AP_WS_Connection();
void EndConnection();
void ProcessJSONRPCEvent(Poco::JSON::Object::Ptr & Doc);
void ProcessJSONRPCResult(Poco::JSON::Object::Ptr Doc);
void ProcessIncomingFrame();
void ProcessIncomingRadiusData(const Poco::JSON::Object::Ptr &Doc);
bool Send(const std::string &Payload);
bool SendRadiusAuthenticationData(const unsigned char * buffer, std::size_t size);
bool SendRadiusAccountingData(const unsigned char * buffer, std::size_t size);
bool SendRadiusCoAData(const unsigned char * buffer, std::size_t size);
void OnSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
void OnSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf);
void OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification>& pNf);
bool LookForUpgrade(const uint64_t UUID, uint64_t & UpgradedUUID);
static bool ExtractBase64CompressedData(const std::string & CompressedData, std::string & UnCompressedData, uint64_t compress_sz);
void LogException(const Poco::Exception &E);
inline Poco::Logger & Logger() { return Logger_; }
bool SetWebSocketTelemetryReporting(std::uint64_t RPCID, uint64_t interval, uint64_t TelemetryWebSocketTimer);
bool SetKafkaTelemetryReporting(std::uint64_t RPCID, uint64_t interval, uint64_t TelemetryKafkaTimer);
bool StopWebSocketTelemetry(std::uint64_t RPCID);
bool StopKafkaTelemetry(std::uint64_t RPCID);
void Process_connect(Poco::JSON::Object::Ptr ParamsObj, const std::string &Serial);
void Process_state(Poco::JSON::Object::Ptr ParamsObj);
void Process_healthcheck(Poco::JSON::Object::Ptr ParamsObj);
void Process_log(Poco::JSON::Object::Ptr ParamsObj);
void Process_crashlog(Poco::JSON::Object::Ptr ParamsObj);
void Process_ping(Poco::JSON::Object::Ptr ParamsObj);
void Process_cfgpending(Poco::JSON::Object::Ptr ParamsObj);
void Process_recovery(Poco::JSON::Object::Ptr ParamsObj);
void Process_deviceupdate(Poco::JSON::Object::Ptr ParamsObj, std::string &Serial);
void Process_telemetry(Poco::JSON::Object::Ptr ParamsObj);
void Process_venuebroadcast(Poco::JSON::Object::Ptr ParamsObj);
bool ValidatedDevice();
inline bool GetTelemetryParameters(bool & Reporting, uint64_t & Interval,
uint64_t & WebSocketTimer, uint64_t & KafkaTimer,
uint64_t &WebSocketCount, uint64_t & KafkaCount,
uint64_t &WebSocketPackets,
uint64_t &KafkaPackets ) const {
Reporting = TelemetryReporting_;
WebSocketTimer = TelemetryWebSocketTimer_;
KafkaTimer = TelemetryKafkaTimer_;
WebSocketCount = TelemetryWebSocketRefCount_;
KafkaCount = TelemetryKafkaRefCount_;
Interval = TelemetryInterval_;
WebSocketPackets = TelemetryWebSocketPackets_;
KafkaPackets = TelemetryKafkaPackets_;
return true;
}
friend class DeviceRegistry;
friend class AP_WS_Server;
private:
// std::recursive_mutex LocalMutex_;
std::shared_mutex TelemetryMutex_;
Poco::Logger &Logger_;
Poco::Net::SocketReactor &Reactor_;
std::unique_ptr<Poco::Net::WebSocket> WS_;
std::string SerialNumber_;
uint64_t SerialNumberInt_=0;
std::string Compatible_;
std::atomic_bool Registered_ = false ;
std::string CId_;
std::string CN_;
uint64_t Errors_=0;
Poco::Net::IPAddress PeerAddress_;
std::atomic_bool TelemetryReporting_ = false;
std::atomic_uint64_t TelemetryWebSocketRefCount_ = 0;
std::atomic_uint64_t TelemetryKafkaRefCount_ = 0;
uint64_t TelemetryWebSocketTimer_ = 0;
uint64_t TelemetryKafkaTimer_ = 0 ;
uint64_t TelemetryInterval_ = 0;
std::atomic_uint64_t TelemetryWebSocketPackets_=0;
std::atomic_uint64_t TelemetryKafkaPackets_=0;
GWObjects::ConnectionState State_;
std::string LastStats_;
GWObjects::HealthCheck LastHealthcheck_;
std::chrono::time_point<std::chrono::high_resolution_clock> ConnectionStart_ = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> ConnectionCompletionTime_{0.0};
bool Threaded_=false;
std::atomic_flag Dead_=false;
std::atomic_bool DeviceValidated_=false;
std::atomic_bool Valid_=false;
static inline std::atomic_uint64_t ConcurrentStartingDevices_=0;
bool StartTelemetry(std::uint64_t RPCID);
bool StopTelemetry(std::uint64_t RPCID);
void UpdateCounts();
};
}

View File

@@ -1,26 +0,0 @@
//
// Created by stephane bourque on 2022-07-26.
//
#include "AP_WS_Connection.h"
#include "fmt/format.h"
#include "framework/ow_constants.h"
namespace OpenWifi {
void AP_WS_Connection::Process_cfgpending(Poco::JSON::Object::Ptr ParamsObj) {
if (!State_.Connected) {
poco_warning(Logger_, fmt::format(
"INVALID-PROTOCOL({}): Device '{}' is not following protocol", CId_, CN_));
Errors_++;
return;
}
if (ParamsObj->has(uCentralProtocol::UUID) && ParamsObj->has(uCentralProtocol::ACTIVE)) {
[[maybe_unused]] uint64_t UUID = ParamsObj->get(uCentralProtocol::UUID);
[[maybe_unused]] uint64_t Active = ParamsObj->get(uCentralProtocol::ACTIVE);
poco_trace(Logger_, fmt::format("CFG-PENDING({}): Active: {} Target: {}", CId_, Active, UUID));
} else {
poco_warning(Logger_, fmt::format("CFG-PENDING({}): Missing some parameters", CId_));
}
}
}

View File

@@ -1,129 +0,0 @@
//
// Created by stephane bourque on 2022-07-26.
//
#include "AP_WS_Connection.h"
#include "AP_WS_Server.h"
#include "StorageService.h"
#include "FindCountry.h"
#include "framework/WebSocketClientNotifications.h"
#include "Daemon.h"
#include "CentralConfig.h"
#include "CommandManager.h"
namespace OpenWifi {
void AP_WS_Connection::Process_connect(Poco::JSON::Object::Ptr ParamsObj, const std::string &Serial) {
if (ParamsObj->has(uCentralProtocol::UUID) &&
ParamsObj->has(uCentralProtocol::FIRMWARE) &&
ParamsObj->has(uCentralProtocol::CAPABILITIES)) {
uint64_t UUID = ParamsObj->get(uCentralProtocol::UUID);
auto Firmware = ParamsObj->get(uCentralProtocol::FIRMWARE).toString();
auto CapabilitiesString = ParamsObj->get(uCentralProtocol::CAPABILITIES).toString();
Config::Capabilities Caps(CapabilitiesString);
Compatible_ = Caps.Compatible();
SerialNumber_ = Serial;
SerialNumberInt_ = Utils::SerialNumberToInt(SerialNumber_);
CommandManager()->ClearQueue(SerialNumberInt_);
AP_WS_Server()->SetSessionDetails(State_.sessionId,SerialNumberInt_);
State_.UUID = UUID;
State_.Firmware = Firmware;
State_.PendingUUID = 0;
State_.Address = Utils::FormatIPv6(WS_->peerAddress().toString());
CId_ = SerialNumber_ + "@" + CId_;
auto IP = PeerAddress_.toString();
if(IP.substr(0,7)=="::ffff:") {
IP = IP.substr(7);
}
State_.locale = FindCountryFromIP()->Get(IP);
GWObjects::Device DeviceInfo;
auto DeviceExists = StorageService()->GetDevice(SerialNumber_,DeviceInfo);
if (Daemon()->AutoProvisioning() && !DeviceExists) {
StorageService()->CreateDefaultDevice(SerialNumber_, CapabilitiesString, Firmware,
Compatible_, PeerAddress_);
} else if (DeviceExists) {
StorageService()->UpdateDeviceCapabilities(SerialNumber_, CapabilitiesString,
Compatible_);
bool Updated = false;
if(!Firmware.empty() && Firmware!=DeviceInfo.Firmware) {
DeviceInfo.Firmware = Firmware;
Updated = true;
WebSocketClientNotificationDeviceFirmwareUpdated(SerialNumber_, Firmware);
}
if(DeviceInfo.locale != State_.locale) {
DeviceInfo.locale = State_.locale;
Updated = true;
}
if(Compatible_ != DeviceInfo.DeviceType) {
DeviceInfo.DeviceType = Compatible_;
Updated = true;
}
if(Updated) {
StorageService()->UpdateDevice(DeviceInfo);
}
uint64_t UpgradedUUID=0;
LookForUpgrade(UUID,UpgradedUUID);
State_.UUID = UpgradedUUID;
}
State_.Compatible = Compatible_;
State_.Connected = true;
ConnectionCompletionTime_ = std::chrono::high_resolution_clock::now() - ConnectionStart_;
State_.connectionCompletionTime = ConnectionCompletionTime_.count();
if(State_.VerifiedCertificate == GWObjects::VALID_CERTIFICATE) {
if (( Utils::SerialNumberMatch(CN_, SerialNumber_, AP_WS_Server()->MismatchDepth())) ||
AP_WS_Server()->IsSimSerialNumber(CN_)) {
State_.VerifiedCertificate = GWObjects::VERIFIED;
poco_information(Logger_, fmt::format("CONNECT({}): Fully validated and authenticated device. Session={} ConnectionCompletion Time={}",
CId_,
State_.sessionId,
State_.connectionCompletionTime ));
} else {
State_.VerifiedCertificate = GWObjects::MISMATCH_SERIAL;
if(AP_WS_Server()->AllowSerialNumberMismatch()) {
poco_information(
Logger_, fmt::format("CONNECT({}): Serial number mismatch allowed. CN={} Serial={} Session={} ConnectionCompletion Time={}",
CId_, CN_, SerialNumber_, State_.sessionId,
State_.connectionCompletionTime));
} else {
poco_information(
Logger_, fmt::format("CONNECT({}): Serial number mismatch disallowed. Device rejected. CN={} Serial={} Session={} ConnectionCompletion Time={}",
CId_, CN_, SerialNumber_, State_.sessionId,
State_.connectionCompletionTime));
return EndConnection();
}
}
}
WebSocketClientNotificationDeviceConnected(SerialNumber_);
// std::cout << "Serial: " << SerialNumber_ << "Session: " << State_.sessionId << std::endl;
if (KafkaManager()->Enabled()) {
Poco::JSON::Stringifier Stringify;
ParamsObj->set(uCentralProtocol::CONNECTIONIP, CId_);
ParamsObj->set("locale", State_.locale );
ParamsObj->set(uCentralProtocol::TIMESTAMP, OpenWifi::Now());
std::ostringstream OS;
Stringify.condense(ParamsObj, OS);
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber_, OS.str());
}
} else {
poco_warning(Logger_,fmt::format("INVALID-PROTOCOL({}): Missing one of uuid, firmware, or capabilities", CId_));
Errors_++;
}
}
}

View File

@@ -1,34 +0,0 @@
//
// Created by stephane bourque on 2022-07-26.
//
#include "AP_WS_Connection.h"
#include "StorageService.h"
namespace OpenWifi {
void AP_WS_Connection::Process_crashlog(Poco::JSON::Object::Ptr ParamsObj) {
if (ParamsObj->has(uCentralProtocol::UUID) && ParamsObj->has(uCentralProtocol::LOGLINES)) {
poco_trace(Logger_, fmt::format("CRASH-LOG({}): new entry.", CId_));
auto LogLines = ParamsObj->get(uCentralProtocol::LOGLINES);
std::string LogText;
if (LogLines.isArray()) {
auto LogLinesArray = LogLines.extract<Poco::JSON::Array::Ptr>();
for (const auto &i : *LogLinesArray)
LogText += i.toString() + "\r\n";
}
GWObjects::DeviceLog DeviceLog{.SerialNumber = SerialNumber_,
.Log = LogText,
.Data = "",
.Severity = GWObjects::DeviceLog::LOG_EMERG,
.Recorded = (uint64_t)time(nullptr),
.LogType = 1,
.UUID = 0};
StorageService()->AddLog(DeviceLog);
} else {
poco_warning(Logger_, fmt::format("LOG({}): Missing parameters.", CId_));
return;
}
}
}

View File

@@ -1,25 +0,0 @@
//
// Created by stephane bourque on 2022-07-26.
//
#include "AP_WS_Connection.h"
#include "StorageService.h"
namespace OpenWifi {
void AP_WS_Connection::Process_deviceupdate(Poco::JSON::Object::Ptr ParamsObj, std::string &Serial) {
if (!State_.Connected) {
poco_warning(Logger_, fmt::format(
"INVALID-PROTOCOL({}): Device '{}' is not following protocol", CId_, CN_));
Errors_++;
return;
}
if (ParamsObj->has("currentPassword")) {
auto Password = ParamsObj->get("currentPassword").toString();
StorageService()->SetDevicePassword(Serial, Password);
poco_trace(Logger_, fmt::format("DEVICEUPDATE({}): Device is updating its login password.", Serial));
}
}
}

View File

@@ -1,71 +0,0 @@
//
// Created by stephane bourque on 2022-07-26.
//
#include "AP_WS_Connection.h"
#include "StorageService.h"
namespace OpenWifi {
void AP_WS_Connection::Process_healthcheck(Poco::JSON::Object::Ptr ParamsObj) {
if (!State_.Connected) {
poco_warning(Logger_, fmt::format(
"INVALID-PROTOCOL({}): Device '{}' is not following protocol", CId_, CN_));
Errors_++;
return;
}
if (ParamsObj->has(uCentralProtocol::UUID) && ParamsObj->has(uCentralProtocol::SANITY) &&
ParamsObj->has(uCentralProtocol::DATA)) {
uint64_t UUID = ParamsObj->get(uCentralProtocol::UUID);
auto Sanity = ParamsObj->get(uCentralProtocol::SANITY);
auto CheckData = ParamsObj->get(uCentralProtocol::DATA).toString();
if (CheckData.empty())
CheckData = uCentralProtocol::EMPTY_JSON_DOC;
std::string request_uuid;
if (ParamsObj->has(uCentralProtocol::REQUEST_UUID))
request_uuid = ParamsObj->get(uCentralProtocol::REQUEST_UUID).toString();
if (request_uuid.empty()) {
poco_trace(Logger_,
fmt::format("HEALTHCHECK({}): UUID={} Updating.", CId_, UUID));
} else {
poco_trace(Logger_,
fmt::format("HEALTHCHECK({}): UUID={} Updating for CMD={}.", CId_,
UUID, request_uuid));
}
uint64_t UpgradedUUID;
LookForUpgrade(UUID,UpgradedUUID);
State_.UUID = UpgradedUUID;
GWObjects::HealthCheck Check;
Check.SerialNumber = SerialNumber_;
Check.Recorded = OpenWifi::Now();
Check.UUID = UUID;
Check.Data = CheckData;
Check.Sanity = Sanity;
StorageService()->AddHealthCheckData(Check);
if (!request_uuid.empty()) {
StorageService()->SetCommandResult(request_uuid, CheckData);
}
LastHealthcheck_ = Check;
if (KafkaManager()->Enabled()) {
Poco::JSON::Stringifier Stringify;
std::ostringstream OS;
ParamsObj->set("timestamp", OpenWifi::Now());
Stringify.condense(ParamsObj, OS);
KafkaManager()->PostMessage(KafkaTopics::HEALTHCHECK, SerialNumber_, OS.str());
}
} else {
poco_warning(Logger_, fmt::format("HEALTHCHECK({}): Missing parameter", CId_));
return;
}
}
}

View File

@@ -1,41 +0,0 @@
//
// Created by stephane bourque on 2022-07-26.
//
#include "AP_WS_Connection.h"
#include "StorageService.h"
namespace OpenWifi {
void AP_WS_Connection::Process_log(Poco::JSON::Object::Ptr ParamsObj) {
if (!State_.Connected) {
poco_warning(
Logger_,
fmt::format("INVALID-PROTOCOL({}): Device '{}' is not following protocol", CId_, CN_));
Errors_++;
return;
}
if (ParamsObj->has(uCentralProtocol::LOG) && ParamsObj->has(uCentralProtocol::SEVERITY)) {
poco_trace(Logger_, fmt::format("LOG({}): new entry.", CId_));
auto Log = ParamsObj->get(uCentralProtocol::LOG).toString();
auto Severity = ParamsObj->get(uCentralProtocol::SEVERITY);
std::string DataStr = uCentralProtocol::EMPTY_JSON_DOC;
if (ParamsObj->has(uCentralProtocol::DATA)) {
auto DataObj = ParamsObj->get(uCentralProtocol::DATA);
if (DataObj.isStruct())
DataStr = DataObj.toString();
}
GWObjects::DeviceLog DeviceLog{.SerialNumber = SerialNumber_,
.Log = Log,
.Data = DataStr,
.Severity = Severity,
.Recorded = (uint64_t)time(nullptr),
.LogType = 0,
.UUID = State_.UUID};
StorageService()->AddLog(DeviceLog);
} else {
poco_warning(Logger_, fmt::format("LOG({}): Missing parameters.", CId_));
return;
}
}
}

View File

@@ -1,18 +0,0 @@
//
// Created by stephane bourque on 2022-07-26.
//
#include "AP_WS_Connection.h"
#include "fmt/format.h"
#include "framework/ow_constants.h"
namespace OpenWifi {
void AP_WS_Connection::Process_ping(Poco::JSON::Object::Ptr ParamsObj) {
if (ParamsObj->has(uCentralProtocol::UUID)) {
[[maybe_unused]] uint64_t UUID = ParamsObj->get(uCentralProtocol::UUID);
poco_trace(Logger_, fmt::format("PING({}): Current config is {}", CId_, UUID));
} else {
poco_warning(Logger_, fmt::format("PING({}): Missing parameter.", CId_));
}
}
}

View File

@@ -1,62 +0,0 @@
//
// Created by stephane bourque on 2022-07-26.
//
#include "AP_WS_Connection.h"
#include "StorageService.h"
#include "CommandManager.h"
namespace OpenWifi {
void AP_WS_Connection::Process_recovery(Poco::JSON::Object::Ptr ParamsObj) {
if (ParamsObj->has(uCentralProtocol::SERIAL) &&
ParamsObj->has(uCentralProtocol::FIRMWARE) && ParamsObj->has(uCentralProtocol::UUID) &&
ParamsObj->has(uCentralProtocol::REBOOT) &&
ParamsObj->has(uCentralProtocol::LOGLINES)) {
auto LogLines = ParamsObj->get(uCentralProtocol::LOGLINES);
std::string LogText;
LogText = "Firmware: " + ParamsObj->get(uCentralProtocol::FIRMWARE).toString() + "\r\n";
if (LogLines.isArray()) {
auto LogLinesArray = LogLines.extract<Poco::JSON::Array::Ptr>();
for (const auto &i : *LogLinesArray)
LogText += i.toString() + "\r\n";
}
GWObjects::DeviceLog DeviceLog{.SerialNumber = SerialNumber_,
.Log = LogText,
.Data = "",
.Severity = GWObjects::DeviceLog::LOG_EMERG,
.Recorded = (uint64_t)time(nullptr),
.LogType = 1,
.UUID = 0};
StorageService()->AddLog(DeviceLog);
if (ParamsObj->get(uCentralProtocol::REBOOT).toString() == "true") {
GWObjects::CommandDetails Cmd;
Cmd.SerialNumber = SerialNumber_;
Cmd.UUID = MicroService::CreateUUID();
Cmd.SubmittedBy = uCentralProtocol::SUBMITTED_BY_SYSTEM;
Cmd.Status = uCentralProtocol::PENDING;
Cmd.Command = uCentralProtocol::REBOOT;
Poco::JSON::Object Params;
Params.set(uCentralProtocol::SERIAL, SerialNumber_);
Params.set(uCentralProtocol::WHEN, 0);
std::ostringstream O;
Poco::JSON::Stringifier::stringify(Params, O);
Cmd.Details = O.str();
bool Sent;
CommandManager()->PostCommand(CommandManager()->NextRPCId(),SerialNumber_, Cmd.Command, Params, Cmd.UUID, Sent);
StorageService()->AddCommand(SerialNumber_, Cmd, Storage::CommandExecutionType::COMMAND_EXECUTED);
poco_information(Logger_, fmt::format("RECOVERY({}): Recovery mode received, need for a reboot.", CId_));
} else {
poco_information(Logger_, fmt::format(
"RECOVERY({}): Recovery mode received, no need for a reboot.", CId_));
}
} else {
poco_warning(Logger_, fmt::format("RECOVERY({}): Recovery missing one of serialnumber, firmware, uuid, loglines, reboot",
CId_));
}
}
}

View File

@@ -1,67 +0,0 @@
//
// Created by stephane bourque on 2022-07-26.
//
#include "AP_WS_Connection.h"
#include "StorageService.h"
#include "framework/WebSocketClientNotifications.h"
#include "StateUtils.h"
namespace OpenWifi {
void AP_WS_Connection::Process_state(Poco::JSON::Object::Ptr ParamsObj) {
if (!State_.Connected) {
poco_warning(Logger_, fmt::format(
"INVALID-PROTOCOL({}): Device '{}' is not following protocol", CId_, CN_));
Errors_++;
return;
}
if (ParamsObj->has(uCentralProtocol::UUID) && ParamsObj->has(uCentralProtocol::STATE)) {
uint64_t UUID = ParamsObj->get(uCentralProtocol::UUID);
auto StateStr = ParamsObj->get(uCentralProtocol::STATE).toString();
auto StateObj = ParamsObj->getObject(uCentralProtocol::STATE);
std::string request_uuid;
if (ParamsObj->has(uCentralProtocol::REQUEST_UUID))
request_uuid = ParamsObj->get(uCentralProtocol::REQUEST_UUID).toString();
if (request_uuid.empty()) {
poco_trace(Logger_, fmt::format("STATE({}): UUID={} Updating.", CId_, UUID));
} else {
poco_trace(Logger_, fmt::format("STATE({}): UUID={} Updating for CMD={}.",
CId_, UUID, request_uuid));
}
uint64_t UpgradedUUID;
LookForUpgrade(UUID,UpgradedUUID);
State_.UUID = UpgradedUUID;
LastStats_ = StateStr;
GWObjects::Statistics Stats{
.SerialNumber = SerialNumber_, .UUID = UUID, .Data = StateStr};
Stats.Recorded = OpenWifi::Now();
StorageService()->AddStatisticsData(Stats);
if (!request_uuid.empty()) {
StorageService()->SetCommandResult(request_uuid, StateStr);
}
StateUtils::ComputeAssociations(StateObj, State_.Associations_2G,
State_.Associations_5G);
if (KafkaManager()->Enabled()) {
Poco::JSON::Stringifier Stringify;
std::ostringstream OS;
Stringify.condense(ParamsObj, OS);
KafkaManager()->PostMessage(KafkaTopics::STATE, SerialNumber_, OS.str());
}
WebSocketNotification<WebNotificationSingleDevice> N;
N.content.serialNumber = SerialNumber_;
N.type = "device_statistics";
WebSocketClientServer()->SendNotification(N);
} else {
poco_warning(Logger_, fmt::format("STATE({}): Invalid request. Missing serial, uuid, or state", CId_));
}
}
}

View File

@@ -1,54 +0,0 @@
//
// Created by stephane bourque on 2022-07-26.
//
#include "AP_WS_Connection.h"
#include "TelemetryStream.h"
#include "CommandManager.h"
namespace OpenWifi {
void AP_WS_Connection::Process_telemetry(Poco::JSON::Object::Ptr ParamsObj) {
if (!State_.Connected) {
poco_warning(Logger_, fmt::format(
"INVALID-PROTOCOL({}): Device '{}' is not following protocol", CId_, CN_));
Errors_++;
return;
}
if (TelemetryReporting_) {
if (ParamsObj->has("data")) {
auto Payload = ParamsObj->get("data").extract<Poco::JSON::Object::Ptr>();
Payload->set("timestamp", OpenWifi::Now());
std::ostringstream SS;
Payload->stringify(SS);
auto now=OpenWifi::Now();
if (TelemetryWebSocketRefCount_) {
if(now<TelemetryWebSocketTimer_) {
// std::cout << SerialNumber_ << ": Updating WebSocket telemetry" << std::endl;
TelemetryWebSocketPackets_++;
State_.websocketPackets = TelemetryWebSocketPackets_;
TelemetryStream()->UpdateEndPoint(SerialNumberInt_, SS.str());
} else {
StopWebSocketTelemetry(CommandManager()->NextRPCId());
}
}
if (TelemetryKafkaRefCount_) {
if(KafkaManager()->Enabled() && now<TelemetryKafkaTimer_) {
// std::cout << SerialNumber_ << ": Updating Kafka telemetry" << std::endl;
TelemetryKafkaPackets_++;
State_.kafkaPackets = TelemetryKafkaPackets_;
KafkaManager()->PostMessage(KafkaTopics::DEVICE_TELEMETRY, SerialNumber_,
SS.str());
} else {
StopKafkaTelemetry(CommandManager()->NextRPCId());
}
}
} else {
poco_debug(Logger_,fmt::format("TELEMETRY({}): Invalid telemetry packet.",SerialNumber_));
}
} else {
// if we are ignoring telemetry, then close it down on the device.
poco_debug(Logger_,fmt::format("TELEMETRY({}): Stopping runaway telemetry.",SerialNumber_));
StopTelemetry(CommandManager()->NextRPCId());
}
}
}

View File

@@ -1,17 +0,0 @@
//
// Created by stephane bourque on 2022-07-26.
//
#include "AP_WS_Connection.h"
#include "VenueBroadcaster.h"
namespace OpenWifi {
void AP_WS_Connection::Process_venuebroadcast(Poco::JSON::Object::Ptr ParamsObj) {
if(ParamsObj->has("data") && ParamsObj->has("serial") && ParamsObj->has("timestamp")) {
VenueBroadcaster()->Broadcast(
ParamsObj->get("serial").toString(),
ParamsObj->get("data").toString(),
ParamsObj->get("timestamp"));
}
}
}

View File

@@ -1,410 +0,0 @@
//
// License type: BSD 3-Clause License
// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
//
// Created by Stephane Bourque on 2021-03-04.
// Arilia Wireless Inc.
//
#include "Poco/Net/HTTPHeaderStream.h"
#include "Poco/JSON/Array.h"
#include "Poco/Net/Context.h"
#include "AP_WS_Server.h"
#include "AP_WS_Connection.h"
#include "ConfigurationCache.h"
#include "TelemetryStream.h"
#include "framework/WebSocketClientNotifications.h"
namespace OpenWifi {
void AP_WS_RequestHandler::handleRequest(Poco::Net::HTTPServerRequest &request,
Poco::Net::HTTPServerResponse &response) {
try {
AP_WS_Server()->AddConnection(id_,std::make_shared<AP_WS_Connection>(request,response,id_, Logger_, AP_WS_Server()->NextReactor()));
} catch (...) {
poco_warning(Logger_,"Exception during WS creation");
}
};
bool AP_WS_Server::ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate) {
if(IsCertOk()) {
if(!Certificate.issuedBy(*IssuerCert_)) {
poco_warning(Logger(),fmt::format("CERTIFICATE({}): issuer mismatch. Local='{}' Incoming='{}'", ConnectionId, IssuerCert_->issuerName(), Certificate.issuerName()));
return false;
}
return true;
}
return false;
}
int AP_WS_Server::Start() {
AllowSerialNumberMismatch_ = MicroService::instance().ConfigGetBool("openwifi.certificates.allowmismatch",true);
MismatchDepth_ = MicroService::instance().ConfigGetInt("openwifi.certificates.mismatchdepth",2);
Reactor_pool_ = std::make_unique<AP_WS_ReactorThreadPool>();
Reactor_pool_->Start();
for(const auto & Svr : ConfigServersList_ ) {
poco_notice(Logger(),fmt::format("Starting: {}:{} Keyfile:{} CertFile: {}", Svr.Address(),
Svr.Port(), Svr.KeyFile(), Svr.CertFile()));
Svr.LogCert(Logger());
if (!Svr.RootCA().empty())
Svr.LogCas(Logger());
if (!IsCertOk()) {
IssuerCert_ = std::make_unique<Poco::Crypto::X509Certificate>(Svr.IssuerCertFile());
poco_information(Logger(),
fmt::format("Certificate Issuer Name:{}", IssuerCert_->issuerName()));
}
Poco::Net::Context::Params P;
P.verificationMode = Poco::Net::Context::VERIFY_ONCE;
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>(new Poco::Net::Context(Poco::Net::Context::TLS_SERVER_USE, P));
if(!Svr.KeyFilePassword().empty()) {
auto PassphraseHandler = Poco::SharedPtr<MyPrivateKeyPassphraseHandler>( new MyPrivateKeyPassphraseHandler(Svr.KeyFilePassword(),Logger()));
Poco::Net::SSLManager::instance().initializeServer(PassphraseHandler, nullptr,Context);
}
Poco::Crypto::X509Certificate Cert(Svr.CertFile());
Poco::Crypto::X509Certificate Root(Svr.RootCA());
Context->useCertificate(Cert);
Context->addChainCertificate(Root);
Context->addCertificateAuthority(Root);
Poco::Crypto::X509Certificate Issuing(Svr.IssuerCertFile());
Context->addChainCertificate(Issuing);
Context->addCertificateAuthority(Issuing);
Poco::Crypto::RSAKey Key("", Svr.KeyFile(), Svr.KeyFilePassword());
Context->usePrivateKey(Key);
Context->setSessionCacheSize(0);
Context->setSessionTimeout(120);
Context->flushSessionCache();
Context->enableSessionCache(true);
Context->enableExtendedCertificateVerification(false);
// Context->disableStatelessSessionResumption();
Context->disableProtocols(Poco::Net::Context::PROTO_TLSV1 | Poco::Net::Context::PROTO_TLSV1_1);
auto WebServerHttpParams = new Poco::Net::HTTPServerParams;
WebServerHttpParams->setMaxThreads(50);
WebServerHttpParams->setMaxQueued(200);
WebServerHttpParams->setKeepAlive(true);
WebServerHttpParams->setName("ws:ap_dispatch");
if (Svr.Address() == "*") {
Poco::Net::IPAddress Addr(Poco::Net::IPAddress::wildcard(
Poco::Net::Socket::supportsIPv6() ? Poco::Net::AddressFamily::IPv6
: Poco::Net::AddressFamily::IPv4));
Poco::Net::SocketAddress SockAddr(Addr, Svr.Port());
auto NewWebServer = std::make_unique<Poco::Net::HTTPServer>(
new AP_WS_RequestHandlerFactory(Logger()), DeviceConnectionPool_, Poco::Net::SecureServerSocket(SockAddr, Svr.Backlog(), Context), WebServerHttpParams);
WebServers_.push_back(std::move(NewWebServer));
} else {
Poco::Net::IPAddress Addr(Svr.Address());
Poco::Net::SocketAddress SockAddr(Addr, Svr.Port());
auto NewWebServer = std::make_unique<Poco::Net::HTTPServer>(
new AP_WS_RequestHandlerFactory(Logger()), DeviceConnectionPool_, Poco::Net::SecureServerSocket(SockAddr, Svr.Backlog(), Context), WebServerHttpParams);
WebServers_.push_back(std::move(NewWebServer));
}
}
for(auto &server:WebServers_) {
server->start();
}
ReactorThread_.start(Reactor_);
auto ProvString = MicroService::instance().ConfigGetString("autoprovisioning.process","default");
if(ProvString!="default") {
auto Tokens = Poco::StringTokenizer(ProvString, ",");
for (const auto &i : Tokens) {
if (i == "prov")
LookAtProvisioning_ = true;
else
UseDefaultConfig_ = true;
}
} else {
UseDefaultConfig_ = true;
}
SimulatorId_ = MicroService::instance().ConfigGetString("simulatorid","");
SimulatorEnabled_ = !SimulatorId_.empty();
Utils::SetThreadName(ReactorThread_,"dev:react:head");
GarbageCollectorCallback_ = std::make_unique<Poco::TimerCallback<AP_WS_Server>>(*this,&AP_WS_Server::onGarbageCollecting);
Timer_.setStartInterval(10 * 1000);
Timer_.setPeriodicInterval(5 * 1000); // every minute
Timer_.start(*GarbageCollectorCallback_, MicroService::instance().TimerPool());
Running_ = true;
return 0;
}
void AP_WS_Server::onGarbageCollecting([[maybe_unused]] Poco::Timer &timer) {
std::lock_guard Lock(LocalMutex_);
if(Garbage_.size()>0) {
std::cout << "Removing " << Garbage_.size() << " old connections." << std::endl;
Garbage_.clear();
}
static std::uint64_t last_log = OpenWifi::Now();
NumberOfConnectedDevices_ = 0;
NumberOfConnectingDevices_ = 0;
AverageDeviceConnectionTime_ = 0;
std::uint64_t total_connected_time=0;
auto now = OpenWifi::Now();
for (auto connection=SerialNumbers_.begin(); connection!=SerialNumbers_.end();) {
if(connection->second.second== nullptr) {
connection++;
continue;
}
if (connection->second.second->State_.Connected) {
NumberOfConnectedDevices_++;
total_connected_time += (now - connection->second.second->State_.started);
connection++;
} else {
NumberOfConnectingDevices_++;
connection++;
}
}
AverageDeviceConnectionTime_ = (NumberOfConnectedDevices_!=0) ? total_connected_time/NumberOfConnectedDevices_ : 0;
if((now-last_log)>120) {
last_log = now;
poco_information(Logger(),
fmt::format("Active AP connections: {} Connecting: {} Average connection time: {} seconds",
NumberOfConnectedDevices_, NumberOfConnectingDevices_, AverageDeviceConnectionTime_));
}
WebSocketClientNotificationNumberOfConnections(NumberOfConnectedDevices_,
AverageDeviceConnectionTime_,
NumberOfConnectingDevices_);
}
void AP_WS_Server::Stop() {
poco_information(Logger(),"Stopping...");
Running_ = false;
Timer_.stop();
for(auto &server:WebServers_) {
server->stopAll();
}
Reactor_pool_->Stop();
Reactor_.stop();
ReactorThread_.join();
poco_information(Logger(),"Stopped...");
}
bool AP_WS_Server::GetStatistics(std::uint64_t SerialNumber, std::string &Statistics) const {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device == SerialNumbers_.end() || Device->second.second==nullptr)
return false;
Statistics = Device->second.second->LastStats_;
return true;
}
bool AP_WS_Server::GetState(uint64_t SerialNumber, GWObjects::ConnectionState & State) const {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device == SerialNumbers_.end() || Device->second.second==nullptr)
return false;
State = Device->second.second->State_;
return true;
}
bool AP_WS_Server::GetHealthcheck(uint64_t SerialNumber, GWObjects::HealthCheck & CheckData) const {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device == SerialNumbers_.end() || Device->second.second==nullptr)
return false;
CheckData = Device->second.second->LastHealthcheck_;
return true;
}
void AP_WS_Server::SetSessionDetails(std::uint64_t connection_id, uint64_t SerialNumber) {
std::lock_guard Lock(LocalMutex_);
auto Conn = Sessions_.find(connection_id);
if(Conn == end(Sessions_))
return;
auto CurrentSerialNumber = SerialNumbers_.find(SerialNumber);
if( (CurrentSerialNumber==SerialNumbers_.end()) ||
(CurrentSerialNumber->second.first<connection_id)) {
SerialNumbers_[SerialNumber] = std::make_pair(connection_id, Conn->second.first);
return;
}
}
bool AP_WS_Server::EndSession(std::uint64_t session_id, std::uint64_t serial_number) {
std::unique_lock G(LocalMutex_);
auto Session = Sessions_.find(session_id);
if(Session==end(Sessions_))
return false;
Garbage_.push_back(Session->second.first);
auto Device = SerialNumbers_.find(serial_number);
if (Device == end(SerialNumbers_)) {
Sessions_.erase(Session);
return false;
}
if(Device->second.first==session_id) {
Sessions_.erase(Session);
SerialNumbers_.erase(Device);
return true;
}
Sessions_.erase(Session);
return false;
}
bool AP_WS_Server::Connected(uint64_t SerialNumber) const {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second== nullptr)
return false;
return Device->second.second->State_.Connected;
}
bool AP_WS_Server::SendFrame(uint64_t SerialNumber, const std::string & Payload) const {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==SerialNumbers_.end() || Device->second.second== nullptr)
return false;
try {
// std::cout << "Device connection pointer: " << (std::uint64_t) Device->second.second << std::endl;
return Device->second.second->Send(Payload);
} catch (...) {
poco_debug(Logger(),fmt::format(": SendFrame: Could not send data to device '{}'", Utils::IntToSerialNumber(SerialNumber)));
}
return false;
}
void AP_WS_Server::StopWebSocketTelemetry(std::uint64_t RPCID, uint64_t SerialNumber) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second==nullptr)
return;
Device->second.second->StopWebSocketTelemetry(RPCID);
}
void AP_WS_Server::SetWebSocketTelemetryReporting(std::uint64_t RPCID, uint64_t SerialNumber, uint64_t Interval, uint64_t Lifetime) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second==nullptr)
return;
Device->second.second->SetWebSocketTelemetryReporting(RPCID, Interval, Lifetime);
}
void AP_WS_Server::SetKafkaTelemetryReporting(std::uint64_t RPCID, uint64_t SerialNumber, uint64_t Interval, uint64_t Lifetime) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second== nullptr)
return;
Device->second.second->SetKafkaTelemetryReporting(RPCID, Interval, Lifetime);
}
void AP_WS_Server::StopKafkaTelemetry(std::uint64_t RPCID, uint64_t SerialNumber) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second== nullptr)
return;
Device->second.second->StopKafkaTelemetry(RPCID);
}
void AP_WS_Server::GetTelemetryParameters(uint64_t SerialNumber , bool & TelemetryRunning,
uint64_t & TelemetryInterval,
uint64_t & TelemetryWebSocketTimer,
uint64_t & TelemetryKafkaTimer,
uint64_t & TelemetryWebSocketCount,
uint64_t & TelemetryKafkaCount,
uint64_t & TelemetryWebSocketPackets,
uint64_t & TelemetryKafkaPackets) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_)|| Device->second.second== nullptr)
return;
Device->second.second->GetTelemetryParameters(TelemetryRunning,
TelemetryInterval,
TelemetryWebSocketTimer,
TelemetryKafkaTimer,
TelemetryWebSocketCount,
TelemetryKafkaCount,
TelemetryWebSocketPackets,
TelemetryKafkaPackets);
}
bool AP_WS_Server::SendRadiusAccountingData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(Utils::SerialNumberToInt(SerialNumber));
if(Device==SerialNumbers_.end() || Device->second.second== nullptr)
return false;
try {
return Device->second.second->SendRadiusAccountingData(buffer,size);
} catch (...) {
poco_debug(Logger(),fmt::format(": SendRadiusAuthenticationData: Could not send data to device '{}'", SerialNumber));
}
return false;
}
bool AP_WS_Server::SendRadiusAuthenticationData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(Utils::SerialNumberToInt(SerialNumber));
if(Device==SerialNumbers_.end() || Device->second.second== nullptr)
return false;
try {
return Device->second.second->SendRadiusAuthenticationData(buffer,size);
} catch (...) {
poco_debug(Logger(),fmt::format(": SendRadiusAuthenticationData: Could not send data to device '{}'", SerialNumber));
}
return false;
}
bool AP_WS_Server::SendRadiusCoAData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(Utils::SerialNumberToInt(SerialNumber));
if(Device==SerialNumbers_.end() || Device->second.second== nullptr)
return false;
try {
return Device->second.second->SendRadiusCoAData(buffer,size);
} catch (...) {
poco_debug(Logger(),fmt::format(": SendRadiusCoAData: Could not send data to device '{}'", SerialNumber));
}
return false;
}
} //namespace

View File

@@ -1,203 +0,0 @@
//
// License type: BSD 3-Clause License
// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
//
// Created by Stephane Bourque on 2021-03-04.
// Arilia Wireless Inc.
//
#pragma once
#include <mutex>
#include <thread>
#include <array>
#include <ctime>
#include "framework/MicroService.h"
#include "Poco/AutoPtr.h"
#include "Poco/Net/SocketReactor.h"
#include "Poco/Net/ParallelSocketAcceptor.h"
#include "Poco/Net/SocketAcceptor.h"
#include "Poco/Timer.h"
#include "AP_WS_Connection.h"
#include "AP_WS_ReactorPool.h"
namespace OpenWifi {
class AP_WS_RequestHandler : public Poco::Net::HTTPRequestHandler {
public:
explicit AP_WS_RequestHandler(Poco::Logger &L, std::uint64_t id)
: Logger_(L),
id_(id){
};
void handleRequest(Poco::Net::HTTPServerRequest &request,
Poco::Net::HTTPServerResponse &response) override;
private:
Poco::Logger &Logger_;
std::uint64_t id_=0;
};
class AP_WS_RequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory {
public:
inline explicit AP_WS_RequestHandlerFactory(Poco::Logger &L)
: Logger_(L) {
}
inline Poco::Net::HTTPRequestHandler *
createRequestHandler(const Poco::Net::HTTPServerRequest &request) override {
if (request.find("Upgrade") != request.end() &&
Poco::icompare(request["Upgrade"], "websocket") == 0) {
Utils::SetThreadName("ws:conn-init");
return new AP_WS_RequestHandler(Logger_,id_++);
} else {
return nullptr;
}
}
private:
Poco::Logger &Logger_;
inline static std::uint64_t id_=1;
};
class AP_WS_Server : public SubSystemServer {
public:
static auto instance() {
static auto instance_ = new AP_WS_Server;
return instance_;
}
int Start() override;
void Stop() override;
bool IsCertOk() { return IssuerCert_!= nullptr; }
bool ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate);
// Poco::Net::SocketReactor & GetNextReactor() { return ReactorPool_.NextReactor(); }
inline bool IsSimSerialNumber(const std::string & SerialNumber) const {
return IsSim(Poco::toLower(SerialNumber)) && Poco::toLower(SerialNumber) == Poco::toLower(SimulatorId_);
}
inline static bool IsSim(const std::string & SerialNumber) {
return SerialNumber.substr(0,6) == "53494d";
}
inline bool IsSimEnabled() const {
return SimulatorEnabled_;
}
inline bool AllowSerialNumberMismatch() const {
return AllowSerialNumberMismatch_;
}
inline std::uint64_t MismatchDepth() const {
return MismatchDepth_;
}
inline bool UseProvisioning() const { return LookAtProvisioning_; }
inline bool UseDefaults() const { return UseDefaultConfig_; }
[[nodiscard]] inline Poco::Net::SocketReactor & NextReactor() { return Reactor_pool_->NextReactor(); }
[[nodiscard]] inline bool Running() const { return Running_; }
inline void AddConnection(std::uint64_t session_id, std::shared_ptr<AP_WS_Connection> Connection ) {
std::lock_guard Lock(LocalMutex_);
Sessions_[session_id] = std::make_pair(std::move(Connection),false);
}
inline std::shared_ptr<AP_WS_Connection> FindConnection(std::uint64_t session_id) const {
std::lock_guard Lock(LocalMutex_);
auto Connection = Sessions_.find(session_id);
if(Connection!=end(Sessions_))
return Connection->second.first;
return nullptr;
}
inline bool GetStatistics(const std::string &SerialNumber, std::string & Statistics) const {
return GetStatistics(Utils::SerialNumberToInt(SerialNumber),Statistics);
}
bool GetStatistics(std::uint64_t SerialNumber, std::string & Statistics) const ;
inline bool GetState(const std::string & SerialNumber, GWObjects::ConnectionState & State) const {
return GetState(Utils::SerialNumberToInt(SerialNumber), State);
}
bool GetState(std::uint64_t SerialNumber, GWObjects::ConnectionState & State) const;
inline bool GetHealthcheck(const std::string &SerialNumber, GWObjects::HealthCheck & CheckData) const {
return GetHealthcheck(Utils::SerialNumberToInt(SerialNumber), CheckData);
}
bool GetHealthcheck(std::uint64_t SerialNumber, GWObjects::HealthCheck & CheckData) const ;
bool Connected(uint64_t SerialNumber) const ;
inline bool SendFrame(const std::string & SerialNumber, const std::string & Payload) const {
return SendFrame(Utils::SerialNumberToInt(SerialNumber), Payload);
}
bool SendFrame(std::uint64_t SerialNumber, const std::string & Payload) const ;
bool SendRadiusAuthenticationData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size);
bool SendRadiusAccountingData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size);
bool SendRadiusCoAData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size);
void SetSessionDetails(std::uint64_t connection_id, uint64_t SerialNumber);
bool EndSession(std::uint64_t connection_id, std::uint64_t serial_number);
void SetWebSocketTelemetryReporting(std::uint64_t RPCID, uint64_t SerialNumber, uint64_t Interval, uint64_t Lifetime);
void StopWebSocketTelemetry(std::uint64_t RPCID, uint64_t SerialNumber);
void SetKafkaTelemetryReporting(std::uint64_t RPCID, uint64_t SerialNumber, uint64_t Interval, uint64_t Lifetime);
void StopKafkaTelemetry(std::uint64_t RPCID, uint64_t SerialNumber);
void GetTelemetryParameters(uint64_t SerialNumber , bool & TelemetryRunning,
uint64_t & TelemetryInterval,
uint64_t & TelemetryWebSocketTimer,
uint64_t & TelemetryKafkaTimer,
uint64_t & TelemetryWebSocketCount,
uint64_t & TelemetryKafkaCount,
uint64_t & TelemetryWebSocketPackets,
uint64_t & TelemetryKafkaPackets);
void onGarbageCollecting(Poco::Timer & timer);
inline void AverageDeviceStatistics( std::uint64_t & Connections, std::uint64_t & AverageConnectionTime, std::uint64_t & NumberOfConnectingDevices) const {
Connections = NumberOfConnectedDevices_;
AverageConnectionTime = AverageDeviceConnectionTime_;
NumberOfConnectingDevices = NumberOfConnectingDevices_;
}
private:
mutable std::recursive_mutex LocalMutex_;
std::unique_ptr<Poco::Crypto::X509Certificate> IssuerCert_;
std::list<std::unique_ptr<Poco::Net::HTTPServer>> WebServers_;
Poco::Net::SocketReactor Reactor_;
Poco::Thread ReactorThread_;
std::string SimulatorId_;
Poco::ThreadPool DeviceConnectionPool_{"ws:dev-pool", 2, 64};
bool LookAtProvisioning_ = false;
bool UseDefaultConfig_ = true;
bool SimulatorEnabled_=false;
std::unique_ptr<AP_WS_ReactorThreadPool> Reactor_pool_;
std::atomic_bool Running_=false;
std::map<std::uint64_t, std::pair<std::shared_ptr<AP_WS_Connection>,bool>> Sessions_;
std::map<std::uint64_t, std::pair<std::uint64_t,std::shared_ptr<AP_WS_Connection>>> SerialNumbers_;
std::atomic_bool AllowSerialNumberMismatch_=true;
std::atomic_uint64_t MismatchDepth_=2;
std::atomic_uint64_t NumberOfConnectedDevices_=0;
std::atomic_uint64_t AverageDeviceConnectionTime_=0;
std::atomic_uint64_t NumberOfConnectingDevices_=0;
std::vector<std::shared_ptr<AP_WS_Connection>> Garbage_;
std::unique_ptr<Poco::TimerCallback<AP_WS_Server>> GarbageCollectorCallback_;
Poco::Timer Timer_;
Poco::Thread GarbageCollector_;
AP_WS_Server() noexcept:
SubSystemServer("WebSocketServer", "WS-SVR", "ucentral.websocket") {
}
};
inline auto AP_WS_Server() { return AP_WS_Server::instance(); }
} //namespace

View File

@@ -5,7 +5,6 @@
#pragma once
#include "framework/MicroService.h"
#include "nlohmann/json.hpp"
namespace OpenWifi {

View File

@@ -7,148 +7,115 @@
//
#include <fstream>
#include "framework/MicroService.h"
#include "Poco/JSON/Object.h"
#include "Poco/JSON/Parser.h"
#include "Poco/File.h"
#include "CentralConfig.h"
#include "framework/MicroService.h"
#include "Daemon.h"
namespace OpenWifi::Config {
const static std::string BasicConfig {
R"lit(
{
"interfaces": [
{
"ethernet": [
{
"select-ports": [
"WAN*"
]
}
],
"ipv4": {
"addressing": "dynamic"
},
"name": "WAN",
"role": "upstream",
"services": [
"ssh",
"lldp",
"dhcp-snooping"
],
"ssids": [
{
"bss-mode": "ap",
"encryption": {
"ieee80211w": "optional",
"key": "OpenWifi",
"proto": "psk2"
},
"name": "OpenWifi",
"services": [
"wifi-frames"
],
"wifi-bands": [
"2G","5G"
]
}
]
},
{
"ethernet": [
{
"select-ports": [
"LAN*"
]
}
],
"ipv4": {
"addressing": "static",
"dhcp": {
"lease-count": 10000,
"lease-first": 10,
"lease-time": "6h"
},
"subnet": "192.168.1.1/16"
},
"name": "LAN",
"role": "downstream",
"services": [
"ssh",
"lldp",
"dhcp-snooping"
]
}
],
"metrics": {
"dhcp-snooping": {
"filters": [
"ack",
"discover",
"offer",
"request",
"solicit",
"reply",
"renew"
]
},
"health": {
"interval": 120
},
"statistics": {
"interval": 60,
"types": [
"ssids",
"lldp",
"clients"
]
},
"wifi-frames": {
"filters": [
"probe",
"auth",
"assoc",
"disassoc",
"deauth",
"local-deauth",
"inactive-deauth",
"key-mismatch",
"beacon-report",
"radar-detected"
]
}
},
"radios": [
{
"band": "2G",
"channel": "auto",
"channel-mode": "HE",
"country": "CA"
},
{
"allow-dfs": true,
"band": "5G",
"channel": "auto",
"channel-mode": "HE",
"country": "CA"
}
],
"services": {
"lldp": {
"describe": "TIP OpenWiFi",
"location": "QA"
},
"ssh": {
"port": 22
}
},
"uuid": 2
}
)lit"};
R"lit({
"uuid": 1,
"radios": [
{
"band": "5G",
"country": "CA",
"channel-mode": "HE",
"channel-width": 80,
"channel": 32
}
],
"interfaces": [
{
"name": "WAN",
"role": "upstream",
"services": [ "lldp" ],
"ethernet": [
{
"select-ports": [
"WAN*"
]
}
],
"ipv4": {
"addressing": "dynamic"
},
"ssids": [
{
"name": "OpenWifi",
"wifi-bands": [
"5G"
],
"bss-mode": "ap",
"encryption": {
"proto": "psk2",
"key": "OpenWifi",
"ieee80211w": "optional"
}
}
]
},
{
"name": "LAN",
"role": "downstream",
"services": [ "ssh", "lldp" ],
"ethernet": [
{
"select-ports": [
"LAN*"
]
}
],
"ipv4": {
"addressing": "static",
"subnet": "192.168.1.1/24",
"dhcp": {
"lease-first": 10,
"lease-count": 100,
"lease-time": "6h"
}
},
"ssids": [
{
"name": "OpenWifi",
"wifi-bands": [
"5G"
],
"bss-mode": "ap",
"encryption": {
"proto": "psk2",
"key": "OpenWifi",
"ieee80211w": "optional"
}
}
]
}
],
"metrics": {
"statistics": {
"interval": 120,
"types": [ "ssids", "lldp", "clients" ]
},
"health": {
"interval": 120
}
},
"services": {
"lldp": {
"describe": "uCentral",
"location": "universe"
},
"ssh": {
"port": 22
}
}
})lit"};
void Config::SetBasicConfigFile() {
try {

View File

@@ -8,277 +8,223 @@
#include <algorithm>
#include "framework/MicroService.h"
#include "Poco/JSON/Parser.h"
#include "CommandManager.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
#include "StorageService.h"
#include "framework/MicroService.h"
#include "framework/ow_constants.h"
namespace OpenWifi {
void CommandManager::run() {
Utils::SetThreadName("cmd:mgr");
Running_ = true;
Poco::AutoPtr<Poco::Notification> NextMsg(ResponseQueue_.waitDequeueNotification());
while(NextMsg && Running_) {
auto Resp = dynamic_cast<RPCResponseNotification*>(NextMsg.get());
Poco::AutoPtr<Poco::Notification> NextMsg(ResponseQueue_.waitDequeueNotification());
while (NextMsg && Running_) {
auto Resp = dynamic_cast<RPCResponseNotification *>(NextMsg.get());
if(Resp!= nullptr) {
const Poco::JSON::Object & Payload = Resp->Payload_;
const std::string & SerialNumber = Resp->SerialNumber_;
try {
if (Resp != nullptr) {
const Poco::JSON::Object &Payload = Resp->Payload_;
const std::string &SerialNumber = Resp->SerialNumber_;
std::ostringstream SS;
Payload.stringify(SS);
std::ostringstream SS;
Payload.stringify(SS);
if (!Payload.has(uCentralProtocol::ID)) {
poco_error(Logger(), fmt::format("({}): Invalid RPC response.", SerialNumber));
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
// std::cout << "Got RPC Answer: " << SerialNumber << " Payload:" << SS.str() << std::endl;
Logger().debug(fmt::format("({}): RPC Response received.", SerialNumber));
if(!Payload.has(uCentralProtocol::ID)){
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
Logger().error(fmt::format("({}): Invalid RPC response.", SerialNumber));
} else {
uint64_t ID = Payload.get(uCentralProtocol::ID);
if (ID < 2) {
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
Logger().debug(fmt::format("({}): Ignoring RPC response.", SerialNumber));
} else {
uint64_t ID = Payload.get(uCentralProtocol::ID);
poco_debug(Logger(),fmt::format("({}): Processing {} response.", SerialNumber, ID));
if (ID > 1) {
std::lock_guard Lock(LocalMutex_);
auto RPC = OutStandingRequests_.find(ID);
if (RPC == OutStandingRequests_.end() ||
RPC->second.SerialNumber !=
Utils::SerialNumberToInt(Resp->SerialNumber_)) {
poco_debug(Logger(),
fmt::format("({}): RPC {} completed.", SerialNumber, ID));
} else {
std::chrono::duration<double, std::milli> rpc_execution_time =
std::chrono::high_resolution_clock::now() -
RPC->second.submitted;
StorageService()->CommandCompleted(RPC->second.UUID, Payload,
rpc_execution_time, true);
if (RPC->second.rpc_entry) {
RPC->second.rpc_entry->set_value(Payload);
}
poco_debug(Logger(),
fmt::format("({}): Received RPC answer {}. Command={}",
SerialNumber, ID, RPC->second.Command));
OutStandingRequests_.erase(ID);
auto Idx = CommandTagIndex{.Id = ID, .SerialNumber = SerialNumber};
std::lock_guard G(Mutex_);
auto RPC = OutStandingRequests_.find(Idx);
if (RPC == OutStandingRequests_.end()) {
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
Logger().warning(
fmt::format("({}): Outdated RPC {}", SerialNumber, ID));
} else {
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
std::chrono::duration<double, std::milli> rpc_execution_time =
std::chrono::high_resolution_clock::now() - RPC->second->submitted;
StorageService()->CommandCompleted(RPC->second->uuid, Payload,
rpc_execution_time, true);
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
if (RPC->second->rpc_entry) {
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
RPC->second->rpc_entry->set_value(Payload);
}
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
OutstandingUUIDs_.erase(RPC->second->uuid);
OutStandingRequests_.erase(Idx);
Logger().information(
fmt::format("({}): Received RPC answer {}", SerialNumber, ID));
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
}
}
}
} catch (const Poco::Exception &E) {
Logger().log(E);
} catch (...) {
poco_warning(Logger(),"Exception occurred during run.");
}
NextMsg = ResponseQueue_.waitDequeueNotification();
}
poco_information(Logger(),"RPC Command processor stopping.");
}
int CommandManager::Start() {
poco_notice(Logger(),"Starting...");
ManagerThread.start(*this);
Logger().notice("Starting...");
ManagerThread.setStackSize(2000000);
ManagerThread.setName("CMD-MGR");
ManagerThread.start(*this);
JanitorCallback_ = std::make_unique<Poco::TimerCallback<CommandManager>>(*this,&CommandManager::onJanitorTimer);
JanitorTimer_.setStartInterval( 10000 );
JanitorTimer_.setPeriodicInterval(10 * 60 * 1000); // 1 hours
JanitorTimer_.start(*JanitorCallback_, MicroService::instance().TimerPool());
JanitorTimer_.start(*JanitorCallback_);
CommandRunnerCallback_ = std::make_unique<Poco::TimerCallback<CommandManager>>(*this,&CommandManager::onCommandRunnerTimer);
CommandRunnerTimer_.setStartInterval( 10000 );
CommandRunnerTimer_.setPeriodicInterval(30 * 1000); // 1 hours
CommandRunnerTimer_.start(*CommandRunnerCallback_, MicroService::instance().TimerPool());
CommandRunnerTimer_.start(*CommandRunnerCallback_);
// RPCResponseQueue_->Readable_ += Poco::delegate(this,&CommandManager::onRPCAnswer);
// RPCResponseQueue_->Writable_ += Poco::delegate(this,&CommandManager::onRPCAnswer);
return 0;
}
void CommandManager::Stop() {
poco_notice(Logger(),"Stopping...");
Logger().notice("Stopping...");
// RPCResponseQueue_->Readable_ -= Poco::delegate(this,&CommandManager::onRPCAnswer);
// RPCResponseQueue_->Writable_ -= Poco::delegate(this,&CommandManager::onRPCAnswer);
Running_ = false;
JanitorTimer_.stop();
CommandRunnerTimer_.stop();
ResponseQueue_.wakeUpAll();
ManagerThread.wakeUp();
ManagerThread.join();
poco_notice(Logger(),"Stopped...");
}
void CommandManager::WakeUp() {
poco_notice(Logger(),"Waking up...");
Logger().notice("Waking up...");
ManagerThread.wakeUp();
}
void CommandManager::onJanitorTimer([[maybe_unused]] Poco::Timer & timer) {
std::lock_guard Lock(LocalMutex_);
Utils::SetThreadName("cmd:janitor");
Poco::Logger & MyLogger = Poco::Logger::get("CMD-MGR-JANITOR");
std::lock_guard G(Mutex_);
Logger().information(
fmt::format("Removing expired commands: start. {} outstanding-requests {} outstanding-uuids commands.",
OutStandingRequests_.size(), OutstandingUUIDs_.size() ));
auto now = std::chrono::high_resolution_clock::now();
for(auto request=OutStandingRequests_.begin();request!=OutStandingRequests_.end();) {
std::chrono::duration<double, std::milli> delta = now - request->second.submitted;
if(delta > 10min) {
MyLogger.debug(fmt::format("{}: Command={} for {} Timed out.",
request->second.UUID,
request->second.Command,
Utils::IntToSerialNumber(request->second.SerialNumber)));
request = OutStandingRequests_.erase(request);
for(auto i=OutStandingRequests_.begin();i!=OutStandingRequests_.end();) {
std::chrono::duration<double, std::milli> delta = now - i->second->submitted;
if(delta > 6000000ms) {
Logger().debug(fmt::format("{}: Timed out.", i->second->uuid));
OutstandingUUIDs_.erase(i->second->uuid);
i = OutStandingRequests_.erase(i);
} else {
++request;
++i;
}
}
poco_information(MyLogger,
fmt::format("Outstanding-requests {}", OutStandingRequests_.size()));
}
bool CommandManager::IsCommandRunning(const std::string &C) {
std::lock_guard Lock(LocalMutex_);
for (const auto &request : OutStandingRequests_) {
if (request.second.UUID == C) {
return true;
}
}
return false;
Logger().information("Removing expired commands: done.");
}
void CommandManager::onCommandRunnerTimer([[maybe_unused]] Poco::Timer &timer) {
Utils::SetThreadName("cmd:schdlr");
Poco::Logger &MyLogger = Poco::Logger::get("CMD-MGR-SCHEDULER");
poco_trace(MyLogger,"Scheduler starting.");
try {
StorageService()->RemovedExpiredCommands();
StorageService()->RemoveTimedOutCommands();
std::vector<GWObjects::CommandDetails> Commands;
if (StorageService()->GetReadyToExecuteCommands(0, 200, Commands)) {
poco_trace(MyLogger,fmt::format("Scheduler about to process {} commands.", Commands.size()));
for (auto &Cmd : Commands) {
if (!Running_) {
poco_warning(MyLogger,"Scheduler quitting because service is stopping.");
break;
std::vector<GWObjects::CommandDetails> Commands;
if(StorageService()->GetReadyToExecuteCommands(0,200,Commands))
{
for(auto & Cmd: Commands)
{
if(!Running_)
break;
try {
{
std::lock_guard M(Mutex_);
if(OutstandingUUIDs_.find(Cmd.UUID)!=OutstandingUUIDs_.end())
continue;
}
poco_trace(
MyLogger, fmt::format("{}: Serial={} Command={} Starting processing.",
Cmd.UUID, Cmd.SerialNumber, Cmd.Command));
try {
// Skip an already running command
if(IsCommandRunning(Cmd.UUID))
continue;
auto now = OpenWifi::Now();
// 2 hour timeout for commands
if ((now - Cmd.Submitted) > (1 * 60 * 60)) {
poco_information(
MyLogger, fmt::format("{}: Serial={} Command={} has expired.",
Cmd.UUID, Cmd.SerialNumber, Cmd.Command));
StorageService()->SetCommandTimedOut(Cmd.UUID);
continue;
}
if (!AP_WS_Server()->Connected(
Utils::SerialNumberToInt(Cmd.SerialNumber))) {
poco_trace(
MyLogger,
fmt::format(
"{}: Serial={} Command={} Device is not connected.",
Cmd.UUID, Cmd.SerialNumber, Cmd.Command));
continue;
}
std::string ExecutingCommand, ExecutingUUID;
if (CommandRunningForDevice(Utils::SerialNumberToInt(Cmd.SerialNumber),
ExecutingUUID, ExecutingCommand)) {
poco_trace(
MyLogger,
fmt::format(
"{}: Serial={} Command={} Device is already busy with command {} (Command={})."
, Cmd.UUID, Cmd.SerialNumber, Cmd.Command,ExecutingUUID, ExecutingCommand));
continue;
}
Poco::JSON::Parser P;
bool Sent;
poco_information(MyLogger, fmt::format("{}: Serial={} Command={} Preparing execution.",
Cmd.UUID, Cmd.SerialNumber, Cmd.Command));
auto Params = P.parse(Cmd.Details).extract<Poco::JSON::Object::Ptr>();
auto Result = PostCommandDisk(NextRPCId(), Cmd.SerialNumber, Cmd.Command,
*Params, Cmd.UUID, Sent);
if (Sent) {
StorageService()->SetCommandExecuted(Cmd.UUID);
poco_debug(MyLogger,
fmt::format("{}: Serial={} Command={} Sent.",
Cmd.UUID, Cmd.SerialNumber, Cmd.Command));
} else {
poco_debug(MyLogger,
fmt::format("{}: Serial={} Command={} Re-queued command.",
Cmd.UUID, Cmd.SerialNumber, Cmd.Command));
}
} catch (const Poco::Exception &E) {
poco_debug(MyLogger,
fmt::format("{}: Serial={} Command={} Failed. Command marked as completed.",
Cmd.UUID, Cmd.SerialNumber, Cmd.Command));
MyLogger.log(E);
StorageService()->SetCommandExecuted(Cmd.UUID);
} catch (...) {
poco_debug(MyLogger,
fmt::format("{}: Serial={} Command={} Hard failure. Command marked as completed.",
Cmd.UUID, Cmd.SerialNumber, Cmd.Command));
Poco::JSON::Parser P;
bool Sent;
Logger().information(fmt::format("{}-{}: Processing.", Cmd.SerialNumber, Cmd.UUID));
auto Params = P.parse(Cmd.Details).extract<Poco::JSON::Object::Ptr>();
auto Result = PostCommandDisk( Cmd.SerialNumber,
Cmd.Command,
*Params,
Cmd.UUID,
Sent);
if(Sent) {
StorageService()->SetCommandExecuted(Cmd.UUID);
OutstandingUUIDs_.insert(Cmd.UUID);
Logger().information(fmt::format("{}-{}: Sent command {}.", Cmd.SerialNumber, Cmd.UUID, Cmd.Command));
} else {
Logger().information(fmt::format("{}-{}: Could not Send command {}.", Cmd.SerialNumber, Cmd.UUID, Cmd.Command));
}
} catch (const Poco::Exception &E) {
Logger().information(fmt::format("{}-{}: Failed command {}.", Cmd.SerialNumber, Cmd.UUID, Cmd.Command));
Logger().log(E);
StorageService()->SetCommandExecuted(Cmd.UUID);
} catch (...) {
Logger().information(fmt::format("{}-{}: Hard failed command {}.", Cmd.SerialNumber, Cmd.UUID, Cmd.Command));
StorageService()->SetCommandExecuted(Cmd.UUID);
}
}
} catch (Poco::Exception &E) {
MyLogger.log(E);
} catch (...) {
poco_warning(MyLogger,"Exception during command processing.");
}
poco_trace(MyLogger,"Scheduler done.");
}
std::shared_ptr<CommandManager::promise_type_t> CommandManager::PostCommand(
uint64_t RPCID,
const std::string &SerialNumber,
const std::string &Command,
const Poco::JSON::Object &Params,
const std::string &UUID,
bool oneway_rpc,
bool disk_only,
bool & Sent) {
std::shared_ptr<CommandManager::promise_type_t> CommandManager::PostCommand(const std::string &SerialNumber,
const std::string &Method,
const Poco::JSON::Object &Params,
const std::string &UUID,
bool oneway_rpc,
bool disk_only,
bool & Sent) {
auto SerialNumberInt = Utils::SerialNumberToInt(SerialNumber);
Sent=false;
std::stringstream ToSend;
CommandInfo Idx;
Idx.Id = oneway_rpc ? 1 : RPCID;
Idx.SerialNumber = SerialNumberInt;
Idx.Command = Command;
Idx.UUID = UUID;
Poco::JSON::Object CompleteRPC;
CompleteRPC.set(uCentralProtocol::JSONRPC, uCentralProtocol::JSONRPC_VERSION);
CompleteRPC.set(uCentralProtocol::ID, RPCID);
CompleteRPC.set(uCentralProtocol::METHOD, Command);
CompleteRPC.set(uCentralProtocol::PARAMS, Params);
Poco::JSON::Stringifier::stringify(CompleteRPC, ToSend);
Idx.rpc_entry = disk_only ? nullptr : std::make_shared<CommandManager::promise_type_t>();
poco_debug(Logger(), fmt::format("{}: Sending command. ID: {}", UUID, RPCID));
if(AP_WS_Server()->SendFrame(SerialNumber, ToSend.str())) {
if(!oneway_rpc) {
std::lock_guard M(Mutex_);
OutStandingRequests_[RPCID] = Idx;
}
poco_debug(Logger(), fmt::format("{}: Sent command. ID: {}", UUID, RPCID));
Sent=true;
return Idx.rpc_entry;
if(!DeviceRegistry()->Connected(SerialNumber)) {
return nullptr;
}
poco_warning(Logger(), fmt::format("{}: Failed to send command. ID: {}", UUID, RPCID));
std::stringstream ToSend;
auto Object = std::make_shared<RpcObject>();
CommandTagIndex Idx;
{
std::lock_guard M(Mutex_);
if (oneway_rpc)
Idx.Id = 1;
else
Idx.Id = ++Id_;
Idx.SerialNumber = SerialNumber;
Poco::JSON::Object CompleteRPC;
CompleteRPC.set(uCentralProtocol::JSONRPC, uCentralProtocol::JSONRPC_VERSION);
CompleteRPC.set(uCentralProtocol::ID, Idx.Id);
CompleteRPC.set(uCentralProtocol::METHOD, Method);
CompleteRPC.set(uCentralProtocol::PARAMS, Params);
Poco::JSON::Stringifier::stringify(CompleteRPC, ToSend);
Logger().information(
fmt::format("{}-{}: Sending command {}, ID: {}", SerialNumber, UUID, Method, Idx.Id));
Object->submitted = std::chrono::high_resolution_clock::now();
Object->uuid = UUID;
if(disk_only) {
Object->rpc_entry = nullptr;
} else {
Object->rpc_entry = std::make_shared<CommandManager::promise_type_t>();
}
if(!oneway_rpc) {
OutStandingRequests_[Idx] = Object;
OutstandingUUIDs_.insert(UUID);
}
}
if(DeviceRegistry()->SendFrame(SerialNumber, ToSend.str())) {
Sent=true;
return Object->rpc_entry;
}
return nullptr;
}
} // namespace

View File

@@ -13,9 +13,6 @@
#include <map>
#include <utility>
#include <functional>
#include <shared_mutex>
#include "framework/MicroService.h"
#include "Poco/JSON/Object.h"
#include "Poco/Net/HTTPServerRequest.h"
@@ -23,9 +20,29 @@
#include "Poco/Timer.h"
#include "RESTObjects/RESTAPI_GWobjects.h"
#include "framework/MicroService.h"
namespace OpenWifi {
struct CommandTagIndex {
uint64_t Id=0;
std::string SerialNumber;
};
inline bool operator <(const CommandTagIndex& lhs, const CommandTagIndex& rhs) {
if(lhs.Id<rhs.Id)
return true;
if(lhs.Id>rhs.Id)
return false;
return lhs.SerialNumber<rhs.SerialNumber;
}
inline bool operator ==(const CommandTagIndex& lhs, const CommandTagIndex& rhs) {
if(lhs.Id == rhs.Id && lhs.SerialNumber == rhs.SerialNumber)
return true;
return false;
}
class RPCResponseNotification: public Poco::Notification {
public:
RPCResponseNotification(const std::string &ser,
@@ -44,12 +61,8 @@ namespace OpenWifi {
public:
typedef Poco::JSON::Object objtype_t;
typedef std::promise<objtype_t> promise_type_t;
struct CommandInfo {
std::uint64_t Id=0;
std::uint64_t SerialNumber=0;
std::string Command;
std::string UUID;
struct RpcObject {
std::string uuid;
std::chrono::time_point<std::chrono::high_resolution_clock> submitted = std::chrono::high_resolution_clock::now();
std::shared_ptr<promise_type_t> rpc_entry;
};
@@ -69,17 +82,18 @@ namespace OpenWifi {
void Stop() override;
void WakeUp();
inline void PostCommandResult(const std::string &SerialNumber, const Poco::JSON::Object &Obj) {
std::lock_guard G(Mutex_);
// RPCResponseQueue_->Write(RPCResponse{.serialNumber=SerialNumber, .payload = Obj});
ResponseQueue_.enqueueNotification(new RPCResponseNotification(SerialNumber,Obj));
}
std::shared_ptr<promise_type_t> PostCommandOneWayDisk(uint64_t RPCID,
std::shared_ptr<promise_type_t> PostCommandOneWayDisk(
const std::string &SerialNumber,
const std::string &Method,
const Poco::JSON::Object &Params,
const std::string &UUID,
bool & Sent) {
return PostCommand(RPCID, SerialNumber,
return PostCommand(SerialNumber,
Method,
Params,
UUID,
@@ -87,14 +101,12 @@ namespace OpenWifi {
}
std::shared_ptr<promise_type_t> PostCommandDisk(
uint64_t RPCID,
const std::string &SerialNumber,
const std::string &Method,
const Poco::JSON::Object &Params,
const std::string &UUID,
bool & Sent) {
return PostCommand(RPCID,
SerialNumber,
return PostCommand(SerialNumber,
Method,
Params,
UUID,
@@ -102,13 +114,12 @@ namespace OpenWifi {
}
std::shared_ptr<promise_type_t> PostCommand(
uint64_t RPCID,
const std::string &SerialNumber,
const std::string &Method,
const Poco::JSON::Object &Params,
const std::string &UUID,
bool & Sent) {
return PostCommand(RPCID, SerialNumber,
return PostCommand(SerialNumber,
Method,
Params,
UUID,
@@ -117,14 +128,12 @@ namespace OpenWifi {
}
std::shared_ptr<promise_type_t> PostCommandOneWay(
uint64_t RPCID,
const std::string &SerialNumber,
const std::string &Method,
const Poco::JSON::Object &Params,
const std::string &UUID,
bool & Sent) {
return PostCommand(RPCID,
SerialNumber,
return PostCommand(SerialNumber,
Method,
Params,
UUID,
@@ -132,8 +141,6 @@ namespace OpenWifi {
false, Sent );
}
bool IsCommandRunning(const std::string &C);
void run() override;
static auto instance() {
@@ -145,50 +152,21 @@ namespace OpenWifi {
void onJanitorTimer(Poco::Timer & timer);
void onCommandRunnerTimer(Poco::Timer & timer);
void onRPCAnswer(bool& b);
inline uint64_t NextRPCId() { return ++Id_; }
void RemovePendingCommand(std::uint64_t Id) {
std::unique_lock Lock(LocalMutex_);
OutStandingRequests_.erase(Id);
}
inline bool CommandRunningForDevice(std::uint64_t SerialNumber, std::string & uuid, std::string &command) {
std::lock_guard Lock(LocalMutex_);
for(const auto &[Request,Command]:OutStandingRequests_) {
if(Command.SerialNumber==SerialNumber) {
uuid = Command.UUID;
command = Command.Command;
return true;
}
}
return false;
}
inline void ClearQueue(std::uint64_t SerialNumber) {
std::lock_guard Lock(LocalMutex_);
for(auto Request = OutStandingRequests_.begin(); Request != OutStandingRequests_.end() ; ) {
if(Request->second.SerialNumber==SerialNumber)
Request = OutStandingRequests_.erase(Request);
else
++Request;
}
}
private:
mutable std::recursive_mutex LocalMutex_;
std::atomic_bool Running_ = false;
Poco::Thread ManagerThread;
std::atomic_uint64_t Id_=3; // do not start @1. We ignore ID=1 & 0 is illegal..
std::map<std::uint64_t , CommandInfo> OutStandingRequests_;
uint64_t Id_=3; // do not start @1. We ignore ID=1 & 0 is illegal..
std::map<CommandTagIndex,std::shared_ptr<RpcObject>> OutStandingRequests_;
std::set<std::string> OutstandingUUIDs_;
Poco::Timer JanitorTimer_;
std::unique_ptr<Poco::TimerCallback<CommandManager>> JanitorCallback_;
Poco::Timer CommandRunnerTimer_;
std::unique_ptr<Poco::TimerCallback<CommandManager>> CommandRunnerCallback_;
// std::unique_ptr<FIFO<RPCResponse>> RPCResponseQueue_=std::make_unique<FIFO<RPCResponse>>(100);
Poco::NotificationQueue ResponseQueue_;
std::shared_ptr<promise_type_t> PostCommand(
uint64_t RPCID,
const std::string &SerialNumber,
const std::string &Method,
const Poco::JSON::Object &Params,

View File

@@ -6,28 +6,25 @@
// Arilia Wireless Inc.
//
#include "framework/MicroService.h"
#include "Poco/Util/Application.h"
#include "Poco/Util/Option.h"
#include "Poco/Environment.h"
#include "Poco/Net/SSLManager.h"
#include "AP_WS_Server.h"
#include "CommandManager.h"
#include "Daemon.h"
#include "DeviceRegistry.h"
#include "FileUploader.h"
#include "FindCountry.h"
#include "OUIServer.h"
#include "RADIUS_proxy_server.h"
#include "SerialNumberCache.h"
#include "StorageArchiver.h"
#include "StorageService.h"
#include "TelemetryStream.h"
#include "VenueBroadcaster.h"
#include "WS_Server.h"
#include "framework/ConfigurationValidator.h"
#include "framework/MicroService.h"
#include "FindCountry.h"
#include "rttys/RTTYS_server.h"
#include "RADIUS_proxy_server.h"
namespace OpenWifi {
class Daemon *Daemon::instance() {
@@ -43,15 +40,14 @@ namespace OpenWifi {
WebSocketClientServer(),
OUIServer(),
FindCountryFromIP(),
// DeviceRegistry(),
DeviceRegistry(),
CommandManager(),
FileUploader(),
StorageArchiver(),
TelemetryStream(),
RTTYS_server(),
RADIUS_proxy_server(),
VenueBroadcaster(),
AP_WS_Server()
WebSocketServer(),
RADIUS_proxy_server()
});
return &instance;
}
@@ -107,25 +103,16 @@ namespace OpenWifi {
}
int main(int argc, char **argv) {
int ExitCode;
try {
Poco::Net::SSLManager::instance().initializeServer(nullptr, nullptr, nullptr);
auto App = OpenWifi::Daemon::instance();
ExitCode = App->run(argc, argv);
Poco::Net::SSLManager::instance().shutdown();
} catch (Poco::Exception &exc) {
ExitCode = Poco::Util::Application::EXIT_SOFTWARE;
std::cout << exc.displayText() << std::endl;
} catch (std::exception &exc) {
ExitCode = Poco::Util::Application::EXIT_TEMPFAIL;
std::cout << exc.what() << std::endl;
} catch (...) {
ExitCode = Poco::Util::Application::EXIT_TEMPFAIL;
std::cout << "Exception on closure" << std::endl;
}
std::cout << "Exitcode: " << ExitCode << std::endl;
return ExitCode;
auto App = OpenWifi::Daemon::instance();
auto ExitCode = App->run(argc, argv);
return ExitCode;
} catch (Poco::Exception &exc) {
std::cerr << exc.displayText() << std::endl;
return Poco::Util::Application::EXIT_SOFTWARE;
}
}
// end of namespace

View File

@@ -14,8 +14,6 @@
#include <vector>
#include <set>
#include "framework/MicroService.h"
#include "Poco/Util/Application.h"
#include "Poco/Util/ServerApplication.h"
#include "Poco/Util/Option.h"
@@ -27,6 +25,7 @@
#include "Poco/Crypto/Cipher.h"
#include "Dashboard.h"
#include "framework/MicroService.h"
#include "framework/OpenWifiTypes.h"
#include "GwWebSocketClient.h"

View File

@@ -3,6 +3,7 @@
//
#include "Dashboard.h"
#include "DeviceRegistry.h"
#include "StorageService.h"
namespace OpenWifi {

View File

@@ -7,258 +7,178 @@
//
#include "Poco/JSON/Object.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
#include "CommandManager.h"
#include "Poco/JSON/Parser.h"
#include "framework/WebSocketClientNotifications.h"
#include "DeviceRegistry.h"
#include "WS_Server.h"
#include "OUIServer.h"
namespace OpenWifi {
int DeviceRegistry::Start() {
std::lock_guard Guard(Mutex_);
poco_notice(Logger(),"Starting");
ArchiverCallback_ = std::make_unique<Poco::TimerCallback<DeviceRegistry>>(*this,&DeviceRegistry::onConnectionJanitor);
Timer_.setStartInterval(60 * 1000);
Timer_.setPeriodicInterval(20 * 1000); // every minute
Timer_.start(*ArchiverCallback_, MicroService::instance().TimerPool());
return 0;
Logger().notice("Starting ");
return 0;
}
void DeviceRegistry::Stop() {
poco_notice(Logger(),"Stopping...");
std::lock_guard Guard(Mutex_);
Timer_.stop();
poco_notice(Logger(),"Stopped...");
Logger().notice("Stopping ");
}
void DeviceRegistry::onConnectionJanitor([[maybe_unused]] Poco::Timer &timer) {
static std::uint64_t last_log = OpenWifi::Now();
std::shared_lock Guard(LocalMutex_);
NumberOfConnectedDevices_ = 0;
NumberOfConnectingDevices_ = 0;
AverageDeviceConnectionTime_ = 0;
std::uint64_t total_connected_time=0;
auto now = OpenWifi::Now();
for (auto connection=SerialNumbers_.begin(); connection!=SerialNumbers_.end();) {
if(connection->second.second== nullptr) {
connection++;
continue;
}
if (connection->second.second->State_.Connected) {
NumberOfConnectedDevices_++;
total_connected_time += (now - connection->second.second->State_.started);
connection++;
} else {
NumberOfConnectingDevices_++;
connection++;
}
}
AverageDeviceConnectionTime_ = (NumberOfConnectedDevices_!=0) ? total_connected_time/NumberOfConnectedDevices_ : 0;
if((now-last_log)>120) {
last_log = now;
poco_information(Logger(),
fmt::format("Active AP connections: {} Connecting: {} Average connection time: {} seconds",
NumberOfConnectedDevices_, NumberOfConnectingDevices_, AverageDeviceConnectionTime_));
}
WebSocketClientNotificationNumberOfConnections(NumberOfConnectedDevices_,
AverageDeviceConnectionTime_,
NumberOfConnectingDevices_);
}
bool DeviceRegistry::GetStatistics(uint64_t SerialNumber, std::string & Statistics) const {
std::shared_lock Guard(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device == SerialNumbers_.end() || Device->second.second==nullptr)
bool DeviceRegistry::GetStatistics(uint64_t SerialNumber, std::string & Statistics) {
std::lock_guard Guard(Mutex_);
auto Device = Devices_.find(SerialNumber);
if(Device == Devices_.end())
return false;
Statistics = Device->second.second->LastStats_;
Statistics = Device->second->LastStats;
return true;
}
bool DeviceRegistry::GetState(uint64_t SerialNumber, GWObjects::ConnectionState & State) const {
std::shared_lock Guard(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device == SerialNumbers_.end() || Device->second.second==nullptr)
void DeviceRegistry::SetStatistics(uint64_t SerialNumber, const std::string &Statistics) {
std::lock_guard Guard(Mutex_);
auto Device = Devices_.find(SerialNumber);
if(Device != Devices_.end())
{
Device->second->Conn_.LastContact = time(nullptr);
Device->second->LastStats = Statistics;
}
}
bool DeviceRegistry::GetState(uint64_t SerialNumber, GWObjects::ConnectionState & State) {
std::lock_guard Guard(Mutex_);
auto Device = Devices_.find(SerialNumber);
if(Device == Devices_.end())
return false;
State = Device->second.second->State_;
State = Device->second->Conn_;
return true;
}
bool DeviceRegistry::GetHealthcheck(uint64_t SerialNumber, GWObjects::HealthCheck & CheckData) const {
std::shared_lock Guard(LocalMutex_);
void DeviceRegistry::SetState(uint64_t SerialNumber, const GWObjects::ConnectionState & State) {
std::lock_guard Guard(Mutex_);
auto Device = Devices_.find(SerialNumber);
if(Device != Devices_.end())
{
Device->second->Conn_.LastContact = time(nullptr);
Device->second->Conn_ = State;
}
}
auto Device = SerialNumbers_.find(SerialNumber);
if(Device == SerialNumbers_.end() || Device->second.second==nullptr)
return false;
bool DeviceRegistry::GetHealthcheck(uint64_t SerialNumber, GWObjects::HealthCheck & CheckData) {
std::lock_guard Guard(Mutex_);
CheckData = Device->second.second->LastHealthcheck_;
return true;
}
bool DeviceRegistry::EndSession(std::uint64_t connection_id, std::uint64_t serial_number) {
std::unique_lock G(LocalMutex_);
auto Connection = SerialNumbers_.find(serial_number);
if (Connection == end(SerialNumbers_)) {
return false;
}
if (Connection->second.first != connection_id) {
return false;
}
SerialNumbers_.erase(Connection);
return true;
}
void DeviceRegistry::SetSessionDetails(std::uint64_t connection_id, uint64_t SerialNumber) {
auto Connection = AP_WS_Server()->FindConnection(connection_id);
if(Connection== nullptr)
return;
std::unique_lock G(LocalMutex_);
auto CurrentSerialNumber = SerialNumbers_.find(SerialNumber);
if( (CurrentSerialNumber==SerialNumbers_.end()) ||
(CurrentSerialNumber->second.first<connection_id)) {
SerialNumbers_[SerialNumber] = std::make_pair(connection_id, Connection);
return;
}
}
bool DeviceRegistry::Connected(uint64_t SerialNumber) const {
std::shared_lock Guard(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second== nullptr)
return false;
return Device->second.second->State_.Connected;
}
bool DeviceRegistry::SendFrame(uint64_t SerialNumber, const std::string & Payload) const {
std::shared_lock Guard(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==SerialNumbers_.end() || Device->second.second== nullptr)
return false;
try {
// std::cout << "Device connection pointer: " << (std::uint64_t) Device->second.second << std::endl;
return Device->second.second->Send(Payload);
} catch (...) {
poco_debug(Logger(),fmt::format(": SendFrame: Could not send data to device '{}'", Utils::IntToSerialNumber(SerialNumber)));
auto Device = Devices_.find(SerialNumber);
if(Device != Devices_.end()) {
CheckData = Device->second->LastHealthcheck;
return true;
}
return false;
}
void DeviceRegistry::StopWebSocketTelemetry(std::uint64_t RPCID, uint64_t SerialNumber) {
std::shared_lock Guard(LocalMutex_);
void DeviceRegistry::SetHealthcheck(uint64_t SerialNumber, const GWObjects::HealthCheck & CheckData) {
std::lock_guard Guard(Mutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second==nullptr)
return;
Device->second.second->StopWebSocketTelemetry(RPCID);
auto Device = Devices_.find(SerialNumber);
if(Device != Devices_.end())
{
Device->second->LastHealthcheck = CheckData;
}
}
void DeviceRegistry::SetWebSocketTelemetryReporting(std::uint64_t RPCID, uint64_t SerialNumber, uint64_t Interval, uint64_t Lifetime) {
std::shared_lock Guard(LocalMutex_);
std::shared_ptr<DeviceRegistry::ConnectionEntry> DeviceRegistry::Register(uint64_t SerialNumber, WSConnection *Ptr, uint64_t & ConnectionId )
{
std::lock_guard Guard(Mutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second==nullptr)
return;
Device->second.second->SetWebSocketTelemetryReporting(RPCID, Interval, Lifetime);
const auto & E = Devices_[SerialNumber] = std::make_shared<ConnectionEntry>();
E->WSConn_ = Ptr;
E->Conn_.LastContact = OpenWifi::Now();
E->Conn_.Connected = true ;
E->Conn_.UUID = 0 ;
E->Conn_.MessageCount = 0 ;
E->Conn_.Address = "";
E->Conn_.TX = 0 ;
E->Conn_.RX = 0;
E->Conn_.VerifiedCertificate = GWObjects::CertificateValidation::NO_CERTIFICATE;
ConnectionId = E->ConnectionId = ++Id_;
return E;
}
bool DeviceRegistry::Connected(uint64_t SerialNumber) {
std::lock_guard Guard(Mutex_);
auto Device = Devices_.find(SerialNumber);
if(Device == Devices_.end())
return false;
return Device->second->Conn_.Connected;
}
void DeviceRegistry::UnRegister(uint64_t SerialNumber, uint64_t ConnectionId) {
std::lock_guard Guard(Mutex_);
auto It = Devices_.find(SerialNumber);
if(It!=Devices_.end()) {
if(It->second->ConnectionId == ConnectionId)
Devices_.erase(SerialNumber);
}
}
void DeviceRegistry::SetKafkaTelemetryReporting(std::uint64_t RPCID, uint64_t SerialNumber, uint64_t Interval, uint64_t Lifetime) {
std::shared_lock Guard(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second== nullptr)
return;
Device->second.second->SetKafkaTelemetryReporting(RPCID, Interval, Lifetime);
}
void DeviceRegistry::StopKafkaTelemetry(std::uint64_t RPCID, uint64_t SerialNumber) {
std::shared_lock Guard(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second== nullptr)
return;
Device->second.second->StopKafkaTelemetry(RPCID);
}
void DeviceRegistry::GetTelemetryParameters(uint64_t SerialNumber , bool & TelemetryRunning,
uint64_t & TelemetryInterval,
uint64_t & TelemetryWebSocketTimer,
uint64_t & TelemetryKafkaTimer,
uint64_t & TelemetryWebSocketCount,
uint64_t & TelemetryKafkaCount,
uint64_t & TelemetryWebSocketPackets,
uint64_t & TelemetryKafkaPackets) {
std::shared_lock Guard(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_)|| Device->second.second== nullptr)
return;
Device->second.second->GetTelemetryParameters(TelemetryRunning,
TelemetryInterval,
TelemetryWebSocketTimer,
TelemetryKafkaTimer,
TelemetryWebSocketCount,
TelemetryKafkaCount,
TelemetryWebSocketPackets,
TelemetryKafkaPackets);
bool DeviceRegistry::SendFrame(uint64_t SerialNumber, const std::string & Payload) {
std::lock_guard Guard(Mutex_);
auto Device = Devices_.find(SerialNumber);
if(Device!=Devices_.end() && Device->second->WSConn_!= nullptr) {
try {
return Device->second->WSConn_->Send(Payload);
} catch (...) {
Logger().debug(fmt::format("Could not send data to device '{}'", SerialNumber));
Device->second->Conn_.Address = "";
Device->second->WSConn_ = nullptr;
Device->second->Conn_.Connected = false;
Device->second->Conn_.VerifiedCertificate = GWObjects::NO_CERTIFICATE;
}
}
return false;
}
bool DeviceRegistry::SendRadiusAccountingData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size) {
std::shared_lock Guard(LocalMutex_);
auto Device = SerialNumbers_.find(Utils::SerialNumberToInt(SerialNumber));
if(Device==SerialNumbers_.end() || Device->second.second== nullptr)
return false;
try {
return Device->second.second->SendRadiusAccountingData(buffer,size);
} catch (...) {
poco_debug(Logger(),fmt::format(": SendRadiusAuthenticationData: Could not send data to device '{}'", SerialNumber));
std::lock_guard Guard(Mutex_);
auto Device = Devices_.find(Utils::SerialNumberToInt(SerialNumber));
if(Device!=Devices_.end() && Device->second->WSConn_!= nullptr) {
try {
return Device->second->WSConn_->SendRadiusAccountingData(buffer,size);
} catch (...) {
Logger().debug(fmt::format("Could not send data to device '{}'", SerialNumber));
Device->second->Conn_.Address = "";
Device->second->WSConn_ = nullptr;
Device->second->Conn_.Connected = false;
Device->second->Conn_.VerifiedCertificate = GWObjects::NO_CERTIFICATE;
}
}
return false;
}
bool DeviceRegistry::SendRadiusAuthenticationData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size) {
std::shared_lock Guard(LocalMutex_);
auto Device = SerialNumbers_.find(Utils::SerialNumberToInt(SerialNumber));
if(Device==SerialNumbers_.end() || Device->second.second== nullptr)
return false;
try {
return Device->second.second->SendRadiusAuthenticationData(buffer,size);
} catch (...) {
poco_debug(Logger(),fmt::format(": SendRadiusAuthenticationData: Could not send data to device '{}'", SerialNumber));
std::lock_guard Guard(Mutex_);
auto Device = Devices_.find(Utils::SerialNumberToInt(SerialNumber));
if(Device!=Devices_.end() && Device->second->WSConn_!= nullptr) {
try {
return Device->second->WSConn_->SendRadiusAuthenticationData(buffer,size);
} catch (...) {
Logger().debug(fmt::format("Could not send data to device '{}'", SerialNumber));
Device->second->Conn_.Address = "";
Device->second->WSConn_ = nullptr;
Device->second->Conn_.Connected = false;
Device->second->Conn_.VerifiedCertificate = GWObjects::NO_CERTIFICATE;
}
}
return false;
}
bool DeviceRegistry::SendRadiusCoAData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size) {
std::shared_lock Guard(LocalMutex_);
auto Device = SerialNumbers_.find(Utils::SerialNumberToInt(SerialNumber));
if(Device==SerialNumbers_.end() || Device->second.second== nullptr)
return false;
try {
return Device->second.second->SendRadiusCoAData(buffer,size);
} catch (...) {
poco_debug(Logger(),fmt::format(": SendRadiusCoAData: Could not send data to device '{}'", SerialNumber));
void DeviceRegistry::SetPendingUUID(uint64_t SerialNumber, uint64_t PendingUUID) {
std::lock_guard Guard(Mutex_);
auto Device = Devices_.find(SerialNumber);
if(Device!=Devices_.end()) {
Device->second->Conn_.PendingUUID = PendingUUID;
}
return false;
}
} // namespace

View File

@@ -8,23 +8,25 @@
#pragma once
#include <shared_mutex>
#include "Poco/JSON/Object.h"
#include "RESTObjects//RESTAPI_GWobjects.h"
#include "framework/MicroService.h"
#include "Poco/JSON/Object.h"
#include "Poco/Timer.h"
#include "RESTObjects//RESTAPI_GWobjects.h"
// class uCentral::WebSocket::WSConnection;
namespace OpenWifi {
class AP_WS_Connection;
class WSConnection;
class DeviceRegistry : public SubSystemServer {
public:
DeviceRegistry() noexcept:
SubSystemServer("DeviceRegistry", "DevStatus", "devicestatus") {
}
struct ConnectionEntry {
WSConnection * WSConn_ = nullptr;
GWObjects::ConnectionState Conn_;
std::string LastStats;
GWObjects::HealthCheck LastHealthcheck;
uint64_t ConnectionId=0;
};
static auto instance() {
static auto instance_ = new DeviceRegistry;
@@ -34,68 +36,83 @@ namespace OpenWifi {
int Start() override;
void Stop() override;
inline bool GetStatistics(const std::string &SerialNumber, std::string & Statistics) const {
inline bool GetStatistics(const std::string &SerialNumber, std::string & Statistics) {
return GetStatistics(Utils::SerialNumberToInt(SerialNumber),Statistics);
}
bool GetStatistics(std::uint64_t SerialNumber, std::string & Statistics) const;
bool GetStatistics(uint64_t SerialNumber, std::string & Statistics);
inline bool GetState(const std::string & SerialNumber, GWObjects::ConnectionState & State) const {
inline void SetStatistics(const std::string &SerialNumber, const std::string &Statistics) {
return SetStatistics(Utils::SerialNumberToInt(SerialNumber),Statistics);
}
void SetStatistics(uint64_t SerialNumber, const std::string &stats);
inline bool GetState(const std::string & SerialNumber, GWObjects::ConnectionState & State) {
return GetState(Utils::SerialNumberToInt(SerialNumber), State);
}
bool GetState(std::uint64_t SerialNumber, GWObjects::ConnectionState & State) const;
bool GetState(uint64_t SerialNumber, GWObjects::ConnectionState & State);
inline bool GetHealthcheck(const std::string &SerialNumber, GWObjects::HealthCheck & CheckData) const {
inline void SetState(const std::string & SerialNumber, const GWObjects::ConnectionState & State) {
return SetState(Utils::SerialNumberToInt(SerialNumber), State);
}
void SetState(uint64_t SerialNumber, const GWObjects::ConnectionState & State);
inline bool GetHealthcheck(const std::string &SerialNumber, GWObjects::HealthCheck & CheckData) {
return GetHealthcheck(Utils::SerialNumberToInt(SerialNumber), CheckData);
}
bool GetHealthcheck(std::uint64_t SerialNumber, GWObjects::HealthCheck & CheckData) const ;
bool GetHealthcheck(uint64_t SerialNumber, GWObjects::HealthCheck & CheckData);
bool Connected(uint64_t SerialNumber) const ;
inline void SetHealthcheck(const std::string &SerialNumber, const GWObjects::HealthCheck &H) {
return SetHealthcheck(Utils::SerialNumberToInt(SerialNumber),H);
}
void SetHealthcheck(uint64_t SerialNumber, const GWObjects::HealthCheck &H);
inline bool SendFrame(const std::string & SerialNumber, const std::string & Payload) const {
std::shared_ptr<ConnectionEntry> Register(uint64_t SerialNumber, WSConnection *Conn, uint64_t & ConnectionId);
inline void UnRegister(const std::string & SerialNumber, uint64_t ConnectionId) {
return UnRegister(Utils::SerialNumberToInt(SerialNumber),ConnectionId);
}
void UnRegister(uint64_t SerialNumber, uint64_t ConnectionId);
inline bool Connected(const std::string & SerialNumber) {
return Connected(Utils::SerialNumberToInt(SerialNumber));
}
bool Connected(uint64_t SerialNumber);
inline bool SendFrame(const std::string & SerialNumber, const std::string & Payload) {
return SendFrame(Utils::SerialNumberToInt(SerialNumber), Payload);
}
bool SendFrame(std::uint64_t SerialNumber, const std::string & Payload) const ;
bool SendFrame(uint64_t SerialNumber, const std::string & Payload);
inline void SetPendingUUID(const std::string & SerialNumber, uint64_t PendingUUID) {
return SetPendingUUID(Utils::SerialNumberToInt(SerialNumber), PendingUUID);
}
void SetPendingUUID(uint64_t SerialNumber, uint64_t PendingUUID);
[[nodiscard]] inline std::shared_ptr<ConnectionEntry> GetDeviceConnection(const std::string & SerialNumber) {
return GetDeviceConnection(Utils::SerialNumberToInt(SerialNumber));
}
[[nodiscard]] inline std::shared_ptr<ConnectionEntry> GetDeviceConnection(uint64_t SerialNumber) {
std::lock_guard Guard(Mutex_);
auto Device = Devices_.find(SerialNumber);
if(Device!=Devices_.end() && Device->second->WSConn_!= nullptr) {
return Device->second;
}
return nullptr;
}
bool SendRadiusAuthenticationData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size);
bool SendRadiusAccountingData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size);
bool SendRadiusCoAData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size);
void SetSessionDetails(std::uint64_t connection_id, uint64_t SerialNumber);
bool EndSession(std::uint64_t connection_id, std::uint64_t serial_number);
void SetWebSocketTelemetryReporting(std::uint64_t RPCID, uint64_t SerialNumber, uint64_t Interval, uint64_t Lifetime);
void StopWebSocketTelemetry(std::uint64_t RPCID, uint64_t SerialNumber);
void SetKafkaTelemetryReporting(std::uint64_t RPCID, uint64_t SerialNumber, uint64_t Interval, uint64_t Lifetime);
void StopKafkaTelemetry(std::uint64_t RPCID, uint64_t SerialNumber);
void GetTelemetryParameters(uint64_t SerialNumber , bool & TelemetryRunning,
uint64_t & TelemetryInterval,
uint64_t & TelemetryWebSocketTimer,
uint64_t & TelemetryKafkaTimer,
uint64_t & TelemetryWebSocketCount,
uint64_t & TelemetryKafkaCount,
uint64_t & TelemetryWebSocketPackets,
uint64_t & TelemetryKafkaPackets);
void onConnectionJanitor(Poco::Timer & timer);
inline void AverageDeviceStatistics( std::uint64_t & Connections, std::uint64_t & AverageConnectionTime, std::uint64_t & NumberOfConnectingDevices) const {
Connections = NumberOfConnectedDevices_;
AverageConnectionTime = AverageDeviceConnectionTime_;
NumberOfConnectingDevices = NumberOfConnectingDevices_;
}
private:
mutable std::shared_mutex LocalMutex_;
std::map<std::uint64_t, std::pair<std::uint64_t,std::shared_ptr<AP_WS_Connection>>> SerialNumbers_;
std::unique_ptr<Poco::TimerCallback<DeviceRegistry>> ArchiverCallback_;
Poco::Timer Timer_;
Poco::Thread ConnectionJanitor_;
std::atomic_uint64_t NumberOfConnectedDevices_=0;
std::atomic_uint64_t AverageDeviceConnectionTime_=0;
std::atomic_uint64_t NumberOfConnectingDevices_=0;
inline static std::atomic_uint64_t Id_=1;
std::map<uint64_t ,std::shared_ptr<ConnectionEntry>> Devices_;
DeviceRegistry() noexcept:
SubSystemServer("DeviceRegistry", "DevStatus", "devicestatus") {
}
};
inline auto DeviceRegistry() { return DeviceRegistry::instance(); }

View File

@@ -7,8 +7,8 @@
//
#include <iostream>
#include "framework/MicroService.h"
#include <fstream>
#include <cstdio>
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Net/HTTPServerResponse.h"
@@ -22,13 +22,14 @@
#include "FileUploader.h"
#include "StorageService.h"
#include "framework/MicroService.h"
namespace OpenWifi {
static const std::string URI_BASE{"/v1/upload/"};
int FileUploader::Start() {
poco_notice(Logger(),"Starting.");
Logger().notice("Starting.");
Poco::File UploadsDir(MicroService::instance().ConfigPath("openwifi.fileuploader.path","/tmp"));
Path_ = UploadsDir.path();
@@ -43,14 +44,13 @@ namespace OpenWifi {
for(const auto & Svr: ConfigServersList_) {
if(MicroService::instance().NoAPISecurity()) {
poco_notice(Logger(), fmt::format("Starting: {}:{}",Svr.Address(),Svr.Port()));
Logger().information(fmt::format("Starting: {}:{}",Svr.Address(),Svr.Port()));
auto Sock{Svr.CreateSocket(Logger())};
auto Params = new Poco::Net::HTTPServerParams;
Params->setMaxThreads(16);
Params->setMaxQueued(100);
Params->setName("ws:upldr");
if (FullName_.empty()) {
std::string TmpName =
@@ -61,18 +61,17 @@ namespace OpenWifi {
} else {
FullName_ = TmpName + URI_BASE;
}
poco_information(Logger(),fmt::format("Uploader URI base is '{}'", FullName_));
Logger().information(fmt::format("Uploader URI base is '{}'", FullName_));
}
auto NewServer = std::make_unique<Poco::Net::HTTPServer>(
new FileUpLoaderRequestHandlerFactory(Logger()), Sock, Params);
Params->setName("file-upldr");
NewServer->start();
Servers_.push_back(std::move(NewServer));
} else {
std::string l{"Starting: " + Svr.Address() + ":" + std::to_string(Svr.Port()) +
" key:" + Svr.KeyFile() + " cert:" + Svr.CertFile()};
poco_information(Logger(),l);
Logger().information(l);
auto Sock{Svr.CreateSecureSocket(Logger())};
@@ -83,7 +82,6 @@ namespace OpenWifi {
auto Params = new Poco::Net::HTTPServerParams;
Params->setMaxThreads(16);
Params->setMaxQueued(100);
Params->setName("ws:upldr");
if (FullName_.empty()) {
std::string TmpName =
@@ -94,7 +92,7 @@ namespace OpenWifi {
} else {
FullName_ = TmpName + URI_BASE;
}
poco_information(Logger(), fmt::format("Uploader URI base is '{}'", FullName_));
Logger().information(fmt::format("Uploader URI base is '{}'", FullName_));
}
auto NewServer = std::make_unique<Poco::Net::HTTPServer>(
@@ -111,7 +109,7 @@ namespace OpenWifi {
void FileUploader::reinitialize([[maybe_unused]] Poco::Util::Application &self) {
MicroService::instance().LoadConfigurationFile();
poco_information(Logger(),"Reinitializing.");
Logger().information("Reinitializing.");
Stop();
Start();
}
@@ -196,11 +194,10 @@ namespace OpenWifi {
void handleRequest(Poco::Net::HTTPServerRequest& Request, Poco::Net::HTTPServerResponse& Response) final {
Utils::SetThreadName("FileUploader");
const auto ContentType = Request.getContentType();
const auto Tokens = Poco::StringTokenizer(ContentType,";",Poco::StringTokenizer::TOK_TRIM);
poco_debug(Logger(),fmt::format("{}: Preparing to upload trace file.",UUID_));
Logger().debug(fmt::format("{}: Preparing to upload trace file.",UUID_));
Poco::JSON::Object Answer;
try {
@@ -225,7 +222,7 @@ namespace OpenWifi {
Poco::StreamCopier::copyStream(Reader.stream(), FileContent);
Answer.set("filename", UUID_);
Answer.set("error", 0);
poco_debug(Logger(),fmt::format("{}: Trace file uploaded.", UUID_));
Logger().debug(fmt::format("{}: Trace file uploaded.", UUID_));
StorageService()->AttachFileDataToCommand(UUID_, FileContent);
std::ostream &ResponseStream = Response.send();
Poco::JSON::Stringifier::stringify(Answer, ResponseStream);
@@ -243,10 +240,10 @@ namespace OpenWifi {
} catch (const Poco::Exception &E) {
Logger().log(E);
} catch (...) {
poco_debug(Logger(),"Exception while receiving trace file.");
Logger().debug("Exception while receiving trace file.");
}
poco_debug(Logger(),fmt::format("{}: Failed to upload trace file.",UUID_));
Logger().debug(fmt::format("{}: Failed to upload trace file.",UUID_));
std::string Error{"Trace file rejected"};
StorageService()->CancelWaitFile(UUID_, Error);
Answer.set("filename", UUID_);
@@ -266,13 +263,7 @@ namespace OpenWifi {
Poco::Net::HTTPRequestHandler *FileUpLoaderRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest & Request) {
poco_debug(Logger(),fmt::format("REQUEST({}): {} {}", Utils::FormatIPv6(Request.clientAddress().toString()), Request.getMethod(), Request.getURI()));
if(Request.getMethod()!=Poco::Net::HTTPRequest::HTTP_POST ||
Request.getURI().size()<(URI_BASE.size()+36)) {
poco_warning(Logger(),fmt::format("ILLEGAL-REQUEST({}): {} {}. Dropped.", Utils::FormatIPv6(Request.clientAddress().toString()), Request.getMethod(), Request.getURI()));
return nullptr;
}
Logger().debug(fmt::format("REQUEST({}): {} {}", Utils::FormatIPv6(Request.clientAddress().toString()), Request.getMethod(), Request.getURI()));
// The UUID should be after the /v1/upload/ part...
auto UUIDLocation = Request.getURI().find_first_of(URI_BASE);
@@ -288,18 +279,17 @@ namespace OpenWifi {
}
else
{
poco_warning(Logger(),fmt::format("Unknown UUID={}",UUID));
Logger().warning(fmt::format("Unknown UUID={}",UUID));
}
}
return nullptr;
}
void FileUploader::Stop() {
poco_notice(Logger(),"Stopping...");
Logger().notice("Stopping ");
for( const auto & svr : Servers_ )
svr->stopAll(true);
svr->stop();
Servers_.clear();
poco_notice(Logger(),"Stopped...");
}
} // Namespace

View File

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

View File

@@ -5,7 +5,6 @@
#pragma once
#include "framework/MicroService.h"
#include "Poco/Net/IPAddress.h"
#include "nlohmann/json.hpp"
@@ -134,7 +133,6 @@ namespace OpenWifi {
}
inline int Start() final {
poco_notice(Logger(),"Starting...");
ProviderName_ = MicroService::instance().ConfigGetString("iptocountry.provider","");
if(!ProviderName_.empty()) {
Provider_ = IPLocationProvider<IPToCountryProvider, IPInfo, IPData, IP2Location>(ProviderName_);
@@ -147,9 +145,6 @@ namespace OpenWifi {
}
inline void Stop() final {
poco_notice(Logger(),"Stopping...");
// Nothing to do - just to provide the same look at the others.
poco_notice(Logger(),"Stopped...");
}
[[nodiscard]] static inline std::string ReformatAddress(const std::string & I )

View File

@@ -37,6 +37,7 @@ namespace OpenWifi {
bool &Done, std::string &Answer) {
Done = false;
auto Prefix = O->get("serial_prefix").toString();
Logger().information(Poco::format("serial_number_search: %s", Prefix));
if (!Prefix.empty() && Prefix.length() < 13) {
std::vector<uint64_t> Numbers;
SerialNumberCache()->FindNumbers(Prefix, 50, Numbers);

View File

@@ -5,10 +5,13 @@
#include <fstream>
#include <vector>
#include "OUIServer.h"
#include "Poco/String.h"
#include "Poco/StringTokenizer.h"
#include "Poco/URIStreamOpener.h"
#include "Poco/StreamCopier.h"
#include "Poco/URI.h"
#include "Poco/File.h"
#include "OUIServer.h"
@@ -21,41 +24,21 @@ namespace OpenWifi {
LatestOUIFileName_ = MicroService::instance().DataDir() + "/newOUIFile.txt";
CurrentOUIFileName_ = MicroService::instance().DataDir() + "/current_oui.txt";
bool Recovered = false;
Poco::File OuiFile(CurrentOUIFileName_);
if(OuiFile.exists()) {
std::unique_lock Lock(LocalMutex_);
Recovered = ProcessFile(CurrentOUIFileName_,OUIs_);
if(Recovered) {
poco_notice(Logger(),
fmt::format("Recovered last OUI file - {}", CurrentOUIFileName_));
}
} else {
poco_notice(Logger(),
fmt::format("No existing OUIFile.", CurrentOUIFileName_));
}
UpdaterCallBack_ = std::make_unique<Poco::TimerCallback<OUIServer>>(*this, &OUIServer::onTimer);
if(Recovered) {
Timer_.setStartInterval(60 * 60 * 1000); // first run in 1 hour
} else {
Timer_.setStartInterval(30 * 1000); // first run in 5 minutes
}
Timer_.setStartInterval(30 * 1000); // first run in 5 minutes
Timer_.setPeriodicInterval(7 * 24 * 60 * 60 * 1000);
Timer_.start(*UpdaterCallBack_, MicroService::instance().TimerPool());
Timer_.start(*UpdaterCallBack_);
return 0;
}
void OUIServer::Stop() {
poco_notice(Logger(),"Stopping...");
Running_=false;
Timer_.stop();
poco_notice(Logger(),"Stopped...");
}
void OUIServer::reinitialize([[maybe_unused]] Poco::Util::Application &self) {
MicroService::instance().LoadConfigurationFile();
poco_information(Logger(),"Reinitializing.");
Logger().information("Reinitializing.");
Stop();
Start();
}
@@ -63,14 +46,14 @@ namespace OpenWifi {
bool OUIServer::GetFile(const std::string &FileName) {
try {
LastUpdate_ = OpenWifi::Now();
poco_information(Logger(), fmt::format("Start: Retrieving OUI file: {}",MicroService::instance().ConfigGetString("oui.download.uri")));
Logger().information(fmt::format("Start: Retrieving OUI file: {}",MicroService::instance().ConfigGetString("oui.download.uri")));
std::unique_ptr<std::istream> pStr(
Poco::URIStreamOpener::defaultOpener().open(MicroService::instance().ConfigGetString("oui.download.uri")));
std::ofstream OS;
OS.open(FileName);
Poco::StreamCopier::copyStream(*pStr, OS);
OS.close();
poco_information(Logger(), fmt::format("Done: Retrieving OUI file: {}",MicroService::instance().ConfigGetString("oui.download.uri")));
Logger().information(fmt::format("Done: Retrieving OUI file: {}",MicroService::instance().ConfigGetString("oui.download.uri")));
return true;
} catch (const Poco::Exception &E) {
Logger().log(E);
@@ -115,13 +98,10 @@ namespace OpenWifi {
}
void OUIServer::onTimer([[maybe_unused]] Poco::Timer & timer) {
Utils::SetThreadName("ouisvr-timer");
if(Updating_)
return;
Updating_ = true;
poco_information(Logger(),"Starting to process OUI file...");
// fetch data from server, if not available, just use the file we already have.
Poco::File Current(CurrentOUIFileName_);
if(Current.exists()) {
@@ -130,7 +110,7 @@ namespace OpenWifi {
if(ProcessFile(CurrentOUIFileName_, OUIs_)) {
Initialized_ = true;
Updating_=false;
poco_information(Logger(), "Using cached file.");
Logger().information("Using cached file.");
return;
}
} else {
@@ -142,7 +122,7 @@ namespace OpenWifi {
OUIMap TmpOUIs;
if(GetFile(LatestOUIFileName_) && ProcessFile(LatestOUIFileName_, TmpOUIs)) {
std::unique_lock G(LocalMutex_);
std::lock_guard G(Mutex_);
OUIs_ = std::move(TmpOUIs);
LastUpdate_ = OpenWifi::Now();
Poco::File F1(CurrentOUIFileName_);
@@ -150,22 +130,20 @@ namespace OpenWifi {
F1.remove();
Poco::File F2(LatestOUIFileName_);
F2.renameTo(CurrentOUIFileName_);
poco_information(Logger(), fmt::format("New OUI file {} downloaded.",LatestOUIFileName_));
Logger().information(fmt::format("New OUI file {} downloaded.",LatestOUIFileName_));
} else if(OUIs_.empty()) {
if(ProcessFile(CurrentOUIFileName_, TmpOUIs)) {
LastUpdate_ = OpenWifi::Now();
std::unique_lock G(LocalMutex_);
std::lock_guard G(Mutex_);
OUIs_ = std::move(TmpOUIs);
}
}
Initialized_=true;
Updating_ = false;
poco_information(Logger(),"Done processing OUI file...");
}
std::string OUIServer::GetManufacturer(const std::string &MAC) {
std::shared_lock Lock(LocalMutex_);
std::lock_guard Guard(Mutex_);
auto Manufacturer = OUIs_.find(Utils::SerialNumberToOUI(MAC));
if(Manufacturer != OUIs_.end())
return Manufacturer->second;

View File

@@ -4,8 +4,6 @@
#pragma once
#include <shared_mutex>
#include "framework/MicroService.h"
#include "Poco/Timer.h"
@@ -32,12 +30,11 @@ namespace OpenWifi {
[[nodiscard]] bool ProcessFile(const std::string &FileName, OUIMap &Map);
private:
std::shared_mutex LocalMutex_;
uint64_t LastUpdate_ = 0 ;
bool Initialized_ = false;
OUIMap OUIs_;
volatile std::atomic_bool Updating_=false;
volatile std::atomic_bool Running_=false;
std::atomic_bool Updating_=false;
std::atomic_bool Running_=false;
Poco::Timer Timer_;
std::unique_ptr<Poco::TimerCallback<OUIServer>> UpdaterCallBack_;
std::string LatestOUIFileName_,CurrentOUIFileName_;

View File

@@ -1565,7 +1565,6 @@ namespace OpenWifi {
ie["TLV Block"] = BufferToHex(&b[offset],l-offset);
} break;
default:
ie["Data"] = BufferToHex(&b[1],l-1);
break;
}
}
@@ -1613,7 +1612,7 @@ namespace OpenWifi {
inline nlohmann::json dissect_vendor_ie_wfa(const unsigned char *b, uint l) {
nlohmann::json ie;
ie["vendor"] = "Wi-Fi Alliance";
ie["Data"] = BufferToHex(&b[1],l-1);
b++;l++;
return ie;
}
@@ -1621,7 +1620,6 @@ namespace OpenWifi {
inline nlohmann::json dissect_vendor_ie_aironet(const unsigned char *b, uint l) {
nlohmann::json ie;
ie["vendor"] = "Cisco Wireless (Aironet)";
ie["Data"] = BufferToHex(&b[1],l-1);
b++;l++;
return ie;
}
@@ -1629,7 +1627,6 @@ namespace OpenWifi {
inline nlohmann::json dissect_vendor_ie_marvell(const unsigned char *b, uint l) {
nlohmann::json ie;
ie["vendor"] = "Marvell Semiconductor";
ie["Data"] = BufferToHex(&b[1],l-1);
b++;l++;
return ie;
}
@@ -1637,7 +1634,6 @@ namespace OpenWifi {
inline nlohmann::json dissect_vendor_ie_atheros(const unsigned char *b, uint l) {
nlohmann::json ie;
ie["vendor"] = "Atheros Communications";
ie["Data"] = BufferToHex(&b[1],l-1);
b++;l++;
return ie;
}
@@ -1645,7 +1641,6 @@ namespace OpenWifi {
inline nlohmann::json dissect_vendor_ie_aruba(const unsigned char *b, uint l) {
nlohmann::json ie;
ie["vendor"] = "Aruba Networks";
ie["Data"] = BufferToHex(&b[1],l-1);
b++;l++;
return ie;
}
@@ -1653,7 +1648,6 @@ namespace OpenWifi {
inline nlohmann::json dissect_vendor_ie_nintendo(const unsigned char *b, uint l) {
nlohmann::json ie;
ie["vendor"] = "Nintendo";
ie["Data"] = BufferToHex(&b[1],l-1);
b++;l++;
return ie;
}
@@ -1711,21 +1705,18 @@ namespace OpenWifi {
nlohmann::json new_ie;
nlohmann::json content;
// std::cout << BufferToHex(&data[0],data.size()) << std::endl;
std::cout << BufferToHex(&data[0],data.size()) << std::endl;
uint offset=0;
auto sub_ie = data[offset++];
switch (sub_ie) {
case WLAN_EID_EXT_HE_CAPABILITY: {
content["Extension EID"] = BufferToHex(&data[0],1);
content["Block"] = BufferToHex(&data[1],data.size()-1);
} break;
case WLAN_EID_EXT_HE_OPERATION: {
content["Extension EID"] = BufferToHex(&data[0],1);
content["Block"] = BufferToHex(&data[1],data.size()-1);
} break;
case WLAN_EID_EXT_HE_MU_EDCA: {
content["Extension EID"] = BufferToHex(&data[0],1);
content["Block"] = BufferToHex(&data[1],data.size()-1);
} break;
default:
content["Extension EID"] = BufferToHex(&data[0],1);
@@ -1743,112 +1734,92 @@ namespace OpenWifi {
std::ostringstream ofs;
Obj->stringify(ofs);
try {
nlohmann::json D = nlohmann::json::parse(ofs.str());
// std::cout << "Start of parsing wifi" << std::endl;
if (D.contains("status")) {
auto Status = D["status"];
if (Status.contains("scan") && Status["scan"].is_array()) {
nlohmann::json ScanArray = Status["scan"];
nlohmann::json ParsedScan = nlohmann::json::array();
for (auto &scan_entry : ScanArray) {
if (scan_entry.contains("ies") && scan_entry["ies"].is_array()) {
auto ies = scan_entry["ies"];
nlohmann::json new_ies = nlohmann::json::array();
for (auto &ie : ies) {
try {
if (ie.contains("type") && ie.contains("data")) {
uint64_t ie_type = ie["type"];
std::string ie_data = ie["data"];
// std::cout << "TYPE:" << ie_type << " DATA:" << ie_data << std::endl;
auto data = Base64Decode2Vec(ie_data);
if (ie_type == ieee80211_eid::WLAN_EID_COUNTRY) {
new_ies.push_back(WFS_WLAN_EID_COUNTRY(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_SUPP_RATES) {
new_ies.push_back(WFS_WLAN_EID_SUPP_RATES(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_FH_PARAMS) {
new_ies.push_back(WFS_WLAN_EID_FH_PARAMS(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_DS_PARAMS) {
new_ies.push_back(WFS_WLAN_EID_DS_PARAMS(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_TIM) {
new_ies.push_back(WFS_WLAN_EID_TIM(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_QBSS_LOAD) {
new_ies.push_back(WFS_WLAN_EID_QBSS_LOAD(data));
} else if (ie_type ==
ieee80211_eid::WLAN_EID_PWR_CONSTRAINT) {
new_ies.push_back(WFS_WLAN_EID_PWR_CONSTRAINT(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_ERP_INFO) {
new_ies.push_back(WFS_WLAN_EID_ERP_INFO(data));
} else if (ie_type ==
ieee80211_eid::
WLAN_EID_SUPPORTED_REGULATORY_CLASSES) {
new_ies.push_back(
WFS_WLAN_EID_SUPPORTED_REGULATORY_CLASSES(data));
} else if (ie_type ==
ieee80211_eid::WLAN_EID_HT_CAPABILITY) {
new_ies.push_back(WFS_WLAN_EID_HT_CAPABILITY(data));
} else if (ie_type ==
ieee80211_eid::WLAN_EID_EXT_SUPP_RATES) {
new_ies.push_back(WFS_WLAN_EID_EXT_SUPP_RATES(data));
} else if (ie_type ==
ieee80211_eid::WLAN_EID_TX_POWER_ENVELOPE) {
new_ies.push_back(WFS_WLAN_EID_TX_POWER_ENVELOPE(data));
} else if (ie_type ==
ieee80211_eid::WLAN_EID_VHT_CAPABILITY) {
new_ies.push_back(WFS_WLAN_EID_VHT_CAPABILITY(data));
} else if (ie_type ==
ieee80211_eid::
WLAN_EID_RRM_ENABLED_CAPABILITIES) {
new_ies.push_back(
WFS_WLAN_EID_RRM_ENABLED_CAPABILITIES(data));
} else if (ie_type ==
ieee80211_eid::WLAN_EID_EXT_CAPABILITY) {
new_ies.push_back(WFS_WLAN_EID_EXT_CAPABILITY(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_TPC_REPORT) {
new_ies.push_back(WFS_WLAN_EID_TPC_REPORT(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_RSN) {
new_ies.push_back(WFS_WLAN_EID_RSN(data));
} else if (ie_type ==
ieee80211_eid::WLAN_EID_VENDOR_SPECIFIC) {
new_ies.push_back(WFS_WLAN_EID_VENDOR_SPECIFIC(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_EXTENSION) {
new_ies.push_back(WFS_WLAN_EID_EXTENSION(data));
} else {
// std::cout
// << "Skipping IE: no parsing available: " << ie_type
// << std::endl;
new_ies.push_back(ie);
}
nlohmann::json D = nlohmann::json::parse(ofs.str());
std::cout << "Start of parsing wifi" << std::endl;
if (D.contains("status")) {
auto Status = D["status"];
if (Status.contains("scan") && Status["scan"].is_array()) {
nlohmann::json ScanArray = Status["scan"];
nlohmann::json ParsedScan = nlohmann::json::array();
for (auto &scan_entry : ScanArray) {
if (scan_entry.contains("ies") && scan_entry["ies"].is_array()) {
auto ies = scan_entry["ies"];
nlohmann::json new_ies=nlohmann::json::array();
for (auto &ie : ies) {
try {
if (ie.contains("type") && ie.contains("data")) {
uint64_t ie_type = ie["type"];
std::string ie_data = ie["data"];
// std::cout << "TYPE:" << ie_type << " DATA:" << ie_data << std::endl;
auto data = Base64Decode2Vec(ie_data);
if (ie_type == ieee80211_eid::WLAN_EID_COUNTRY) {
new_ies.push_back(WFS_WLAN_EID_COUNTRY(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_SUPP_RATES) {
new_ies.push_back(WFS_WLAN_EID_SUPP_RATES(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_FH_PARAMS) {
new_ies.push_back(WFS_WLAN_EID_FH_PARAMS(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_DS_PARAMS) {
new_ies.push_back(WFS_WLAN_EID_DS_PARAMS(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_TIM) {
new_ies.push_back(WFS_WLAN_EID_TIM(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_QBSS_LOAD) {
new_ies.push_back(WFS_WLAN_EID_QBSS_LOAD(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_PWR_CONSTRAINT) {
new_ies.push_back(WFS_WLAN_EID_PWR_CONSTRAINT(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_ERP_INFO) {
new_ies.push_back(WFS_WLAN_EID_ERP_INFO(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_SUPPORTED_REGULATORY_CLASSES) {
new_ies.push_back(WFS_WLAN_EID_SUPPORTED_REGULATORY_CLASSES(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_HT_CAPABILITY) {
new_ies.push_back(WFS_WLAN_EID_HT_CAPABILITY(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_EXT_SUPP_RATES) {
new_ies.push_back(WFS_WLAN_EID_EXT_SUPP_RATES(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_TX_POWER_ENVELOPE) {
new_ies.push_back(WFS_WLAN_EID_TX_POWER_ENVELOPE(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_VHT_CAPABILITY) {
new_ies.push_back(WFS_WLAN_EID_VHT_CAPABILITY(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_RRM_ENABLED_CAPABILITIES) {
new_ies.push_back(WFS_WLAN_EID_RRM_ENABLED_CAPABILITIES(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_EXT_CAPABILITY) {
new_ies.push_back(WFS_WLAN_EID_EXT_CAPABILITY(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_TPC_REPORT) {
new_ies.push_back(WFS_WLAN_EID_TPC_REPORT(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_RSN) {
new_ies.push_back(WFS_WLAN_EID_RSN(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_VENDOR_SPECIFIC) {
new_ies.push_back(WFS_WLAN_EID_VENDOR_SPECIFIC(data));
} else if (ie_type == ieee80211_eid::WLAN_EID_EXTENSION) {
new_ies.push_back(WFS_WLAN_EID_EXTENSION(data));
} else {
// std::cout << "Skipping IE: no data and type" << std::endl;
std::cout
<< "Skipping IE: no parsing available: " << ie_type
<< std::endl;
new_ies.push_back(ie);
}
} catch (...) {
// std::cout << "Skipping IE: exception" << std::endl;
Logger.information(fmt::format("Error parsing IEs"));
} else {
std::cout << "Skipping IE: no data and type" << std::endl;
new_ies.push_back(ie);
}
} catch (...) {
std::cout << "Skipping IE: exception" << std::endl;
Logger.information(fmt::format("Error parsing IEs"));
new_ies.push_back(ie);
}
scan_entry["ies"] = new_ies;
ParsedScan.push_back(scan_entry);
} else {
// std::cout << "Skipping scan" << std::endl;
ParsedScan.push_back(scan_entry);
}
scan_entry["ies"] = new_ies;
ParsedScan.push_back(scan_entry);
} else {
std::cout << "Skipping scan" << std::endl;
ParsedScan.push_back(scan_entry);
}
Status["scan"] = ParsedScan;
D["status"] = Status;
}
Status["scan"] = ParsedScan;
D["status"] = Status;
}
Result << to_string(D);
// std::cout << "End of parsing wifi" << std::endl;
return true;
} catch (const Poco::Exception &E) {
Logger.log(E);
Logger.error(fmt::format("Failure to parse WifiScan."));
} catch (...) {
Logger.error(fmt::format("Failure to parse WifiScan."));
}
Result << to_string(D);
std::cout << "End of parsing wifi" << std::endl;
return false;
}

View File

@@ -1,672 +0,0 @@
//
// Created by stephane bourque on 2022-06-20.
//
#pragma once
#include <list>
#include <string>
#include <iostream>
#include <iomanip>
#include "Poco/HMACEngine.h"
#include "Poco/MD5Engine.h"
namespace OpenWifi::RADIUS {
#define RADCMD_ACCESS_REQ 1 /* Access-Request */
#define RADCMD_ACCESS_ACC 2 /* Access-Accept */
#define RADCMD_ACCESS_REJ 3 /* Access-Reject */
#define RADCMD_ACCOUN_REQ 4 /* Accounting-Request */
#define RADCMD_ACCOUN_RES 5 /* Accounting-Response */
#define RADCMD_ACCOUN_STATUS 6 /* Accounting-Status */
#define RADCMD_PASSWORD_REQUEST 7 /* Password-Request [RFC3575] */
#define RADCMD_PASSWORD_ACK 8 /* Password-Ack [RFC3575] */
#define RADCMD_PASSWORD_REJECT 9 /* Password-Reject [RFC3575] */
#define RADCMD_ACCOUN_MESSAGE 10 /* Accounting-Message [RFC3575] */
#define RADCMD_RES_FREE_REQ 21 /* Resource-Free-Request [RFC3575] */
#define RADCMD_RES_FREE_RES 22 /* Resource-Free-Response [RFC3575] */
#define RADCMD_RES_QUERY_REQ 23 /* Resource-Query-Request [RFC3575] */
#define RADCMD_RES_QUERY_RES 24 /* Resource-Query-Response [RFC3575] */
#define RADCMD_RES_ALT_RECLAIM_REQ 25 /* Alternate-Resource-Reclaim-Request [RFC3575] */
#define RADCMD_ACCESS_CHA 11 /* Access-Challenge */
#define RADCMD_STATUS_SER 12 /* Status-Server */
#define RADCMD_STATUS_CLI 13 /* Status-Client */
#define RADCMD_DISCON_REQ 40 /* Disconnect-Request */
#define RADCMD_DISCON_ACK 41 /* Disconnect-ACK */
#define RADCMD_DISCON_NAK 42 /* Disconnect-NAK */
#define RADCMD_COA_REQ 43 /* CoA-Request */
#define RADCMD_COA_ACK 44 /* CoA-ACK */
#define RADCMD_COA_NAK 45 /* CoA-NAK */
#define RADCMD_RESERVED 255 /* Reserved */
/*
21 Resource-Free-Request [RFC3575]
22 Resource-Free-Response [RFC3575]
23 Resource-Query-Request [RFC3575]
24 Resource-Query-Response [RFC3575]
25 Alternate-Resource-Reclaim-Request [RFC3575]
26 NAS-Reboot-Request [RFC3575]
27 NAS-Reboot-Response [RFC3575]
28 Reserved
29 Next-Passcode [RFC3575]
30 New-Pin [RFC3575]
31 Terminate-Session [RFC3575]
32 Password-Expired [RFC3575]
33 Event-Request [RFC3575]
34 Event-Response [RFC3575]
35-39 Unassigned
40 Disconnect-Request [RFC3575][RFC5176]
41 Disconnect-ACK [RFC3575][RFC5176]
42 Disconnect-NAK [RFC3575][RFC5176]
43 CoA-Request [RFC3575][RFC5176]
44 CoA-ACK [RFC3575][RFC5176]
45 CoA-NAK [RFC3575][RFC5176]
46-49 Unassigned
50 IP-Address-Allocate [RFC3575]
51 IP-Address-Release [RFC3575]
52 Protocol-Error [RFC7930]
53-249 Unassigned
250-253 Experimental Use [RFC3575]
254 Reserved [RFC3575]
255 Reserved [RFC3575]
*/
struct tok {
uint cmd;
const char * name;
};
/*
Radius commands
char const *fr_packet_codes[FR_MAX_PACKET_CODE] = {
"", //!< 0
"Access-Request",
"Access-Accept",
"Access-Reject",
"Accounting-Request",
"Accounting-Response",
"Accounting-Status",
"Password-Request",
"Password-Accept",
"Password-Reject",
"Accounting-Message", //!< 10
"Access-Challenge",
"Status-Server",
"Status-Client",
"14",
"15",
"16",
"17",
"18",
"19",
"20", //!< 20
"Resource-Free-Request",
"Resource-Free-Response",
"Resource-Query-Request",
"Resource-Query-Response",
"Alternate-Resource-Reclaim-Request",
"NAS-Reboot-Request",
"NAS-Reboot-Response",
"28",
"Next-Passcode",
"New-Pin", //!< 30
"Terminate-Session",
"Password-Expired",
"Event-Request",
"Event-Response",
"35",
"36",
"37",
"38",
"39",
"Disconnect-Request", //!< 40
"Disconnect-ACK",
"Disconnect-NAK",
"CoA-Request",
"CoA-ACK",
"CoA-NAK",
"46",
"47",
"48",
"49",
"IP-Address-Allocate",
"IP-Address-Release", //!< 50
};
*/
static const struct tok radius_command_values[] = {
{ RADCMD_ACCESS_REQ, "Access-Request" },
{ RADCMD_ACCESS_ACC, "Access-Accept" },
{ RADCMD_ACCESS_REJ, "Access-Reject" },
{ RADCMD_ACCOUN_REQ, "Accounting-Request" },
{ RADCMD_ACCOUN_RES, "Accounting-Response" },
{ RADCMD_ACCESS_CHA, "Access-Challenge" },
{ RADCMD_STATUS_SER, "Status-Server" },
{ RADCMD_STATUS_CLI, "Status-Client" },
{ RADCMD_DISCON_REQ, "Disconnect-Request" },
{ RADCMD_DISCON_ACK, "Disconnect-ACK" },
{ RADCMD_DISCON_NAK, "Disconnect-NAK" },
{ RADCMD_COA_REQ, "CoA-Request" },
{ RADCMD_COA_ACK, "CoA-ACK" },
{ RADCMD_COA_NAK, "CoA-NAK" },
{ RADCMD_RESERVED, "Reserved" },
{ RADCMD_ACCOUN_STATUS, "Accounting-Status"},
{ RADCMD_PASSWORD_REQUEST, "Password-Request"},
{ RADCMD_PASSWORD_ACK, "Password-Ack"},
{ RADCMD_PASSWORD_REJECT, "Password-Reject"},
{ RADCMD_ACCOUN_MESSAGE, "Accounting-Message"},
{ RADCMD_RES_FREE_REQ, "Resource-Free-Request"},
{ RADCMD_RES_FREE_RES, "Resource-Free-Response"},
{ RADCMD_RES_QUERY_REQ, "Resource-Query-Request"},
{ RADCMD_RES_QUERY_RES, "Resource-Query-Response"},
{ RADCMD_RES_ALT_RECLAIM_REQ, "Alternate-Resource-Reclaim-Request"},
{ 0, nullptr}
};
static const struct tok radius_attribute_names[] = {
{1,"User-Name"},
{2,"User-Password"},
{3,"CHAP-Password"},
{4,"NAS-IP Address"},
{5,"NAS-Port"},
{6,"Service-Type"},
{7,"Framed-Protocol"},
{8,"Framed-IP-Address"},
{9,"Framed-IP-Netmask"},
{10,"Framed-Routing"},
{11,"Filter-Id"},
{12,"Framed-MTU"},
{13,"Framed-Compression"},
{14,"Login-IP-Host"},
{15,"Login-Service"},
{16,"Login-TCP-Port"},
{18,"Reply-Message"},
{19,"Callback-Number"},
{20,"Callback-ID"},
{22,"Framed-Route"},
{23,"Framed-IPX-Network"},
{24,"State"},
{25,"Class"},
{26,"Vendor-Specific"},
{27,"Session-Timeout"},
{28,"Idle-Timeout"},
{29,"Termination-Action"},
{30,"Called-Station-Id"},
{31,"Calling-Station-Id"},
{32,"NAS-Identifier"},
{33,"Proxy-State"},
{34,"Login-LAT-Service"},
{35,"Login-LAT-Node"},
{36,"Login-LAT-Group"},
{37,"Framed-AppleTalk-Link"},
{38,"Framed-AppleTalk-Network"},
{39,"Framed-AppleTalk-Zone"},
{40,"Acct-Status-Type"},
{41,"Acct-Delay-Time"},
{42,"Acct-Input-Octets"},
{43,"Acct-Output-Octets"},
{44,"Acct-Session-Id"},
{45,"Acct-Authentic"},
{46,"Acct-Session-Time"},
{47,"Acct-Input-Packets"},
{48,"Acct-Output-Packets"},
{49,"Acct-Terminate-Cause"},
{50,"Acct-Multi-Session-Id"},
{51,"Acct-Link-Count"},
{52,"Acct-Input-Gigawords"},
{53,"Acct-Output-Gigawords"},
{55,"Event-Timestamp"},
{60,"CHAP-Challenge"},
{61,"NAS-Port-Type"},
{62,"Port-Limit"},
{63,"Login-LAT-Port"},
{64,"Tunnel-Type3"},
{65,"Tunnel-Medium-Type1"},
{66,"Tunnel-Client-Endpoint"},
{67,"Tunnel-Server-Endpoint1"},
{68,"Acct-Tunnel-Connection-ID"},
{69,"Tunnel-Password1"},
{70,"ARAP-Password"},
{71,"ARAP-Features"},
{72,"ARAP-Zone-Access"},
{73,"ARAP-Security"},
{74,"ARAP-Security-Data"},
{75,"Password-Retry"},
{76,"Prompt"},
{77,"Connect-Info"},
{78,"Configuration-Token"},
{79,"EAP-Message"},
{80,"Message-Authenticator"},
{81,"Tunnel-Private-Group-ID"},
{82,"Tunnel-Assignment-ID1"},
{83,"Tunnel-Preference"},
{84,"ARAP-Challenge-Response"},
{85,"Acct-Interim-Interval"},
{86,"Acct-Tunnel-Packets-Lost"},
{87,"NAS-Port-ID"},
{88,"Framed-Pool"},
{90,"Tunnel-Client-Auth-ID"},
{91,"Tunnel-Server-Auth-ID"},
{0, nullptr}
};
#pragma pack(push,1)
struct RadiusAttribute {
unsigned char type{0};
uint16_t pos{0};
unsigned len{0};
};
struct RawRadiusPacket {
unsigned char code{1};
unsigned char identifier{0};
uint16_t rawlen{0};
unsigned char authenticator[16]{0};
unsigned char attributes[4096]{0};
};
#pragma pack(pop)
constexpr unsigned char Access_Request = 1;
constexpr unsigned char Access_Accept = 2;
constexpr unsigned char Access_Reject = 3;
constexpr unsigned char Access_Challenge = 11;
constexpr unsigned char Accounting_Request = 4;
constexpr unsigned char Accounting_Response = 5;
constexpr unsigned char Accounting_Status = 6;
constexpr unsigned char Accounting_Message = 10;
constexpr unsigned char Disconnect_Request = 40;
constexpr unsigned char Disconnect_ACK = 41;
constexpr unsigned char Disconnect_NAK = 42;
constexpr unsigned char CoA_Request = 43;
constexpr unsigned char CoA_ACK = 44;
constexpr unsigned char CoA_NAK = 45;
inline bool IsAuthentication(unsigned char t) {
return (t == RADIUS::Access_Request ||
t == RADIUS::Access_Accept ||
t == RADIUS::Access_Challenge ||
t == RADIUS::Access_Reject);
}
inline bool IsAccounting(unsigned char t) {
return (t == RADIUS::Accounting_Request ||
t == RADIUS::Accounting_Response ||
t == RADIUS::Accounting_Status ||
t == RADIUS::Accounting_Message);
}
inline bool IsAuthority(unsigned char t) {
return (t == RADIUS::Disconnect_Request ||
t == RADIUS::Disconnect_ACK ||
t == RADIUS::Disconnect_NAK ||
t == RADIUS::CoA_Request ||
t == RADIUS::CoA_ACK ||
t == RADIUS::CoA_NAK);
}
inline const char * CommandName(uint cmd) {
auto cmds = radius_command_values;
while(cmds->cmd && (cmds->cmd!=cmd))
cmds++;
if(cmds->cmd==cmd) return cmds->name;
return "Unknown";
}
inline const char * AttributeName(uint cmd) {
auto cmds = radius_attribute_names;
while(cmds->cmd && (cmds->cmd!=cmd))
cmds++;
if(cmds->cmd==cmd) return cmds->name;
return "Unknown";
}
//
// From: https://github.com/Telecominfraproject/wlan-dictionary/blob/main/dictionary.tip
//
static const uint32_t TIP_vendor_id = 58888;
static const unsigned char TIP_serial = 1;
static const unsigned char TIP_AAAipaddr = 2;
static const unsigned char TIP_AAAipv6addr = 3;
using AttributeList = std::list<RadiusAttribute>;
inline std::ostream &operator<<(std::ostream &os, AttributeList const &P) {
for(const auto &attr:P) {
os << "\tAttr: " << (uint16_t) attr.type << " Size: " << (uint16_t) attr.len << std::endl;
}
return os;
}
inline bool ParseRadius(uint32_t offset, const unsigned char *Buffer, uint16_t Size, AttributeList &Attrs) {
Attrs.clear();
uint16_t pos=0;
auto x=25;
while(pos<Size && x) {
RadiusAttribute Attr{ .type=Buffer[pos], .pos=(uint16_t)(pos+2+offset), .len=(unsigned int)(Buffer[pos+1]-2)};
if(pos+Attr.len<=Size) {
Attrs.emplace_back(Attr);
} else {
std::cout << "Bad parse1: " << (uint32_t) (pos+Attr.len) << " S:" << Size << std::endl;
return false;
}
if(Buffer[pos+1]==0) {
std::cout << "Bad parse2: " << (uint32_t) (pos+Attr.len) << " S:" << Size << std::endl;
return false;
}
pos+=Buffer[pos+1];
x--;
}
return true;
}
class RadiusPacket {
public:
explicit RadiusPacket(const Poco::Buffer<char> & Buf) {
if(Buf.size() >= sizeof(RawRadiusPacket)) {
Valid_ = false;
return;
}
memcpy((void *)&P_,Buf.begin(), Buf.size());
Size_=Buf.size();
Valid_ = (Size_== htons(P_.rawlen));
if(Valid_)
Valid_ = ParseRadius(0,(unsigned char *)&P_.attributes[0],Size_-20,Attrs_);
}
explicit RadiusPacket(const unsigned char *buffer, uint16_t size) {
if(size >= sizeof(RawRadiusPacket)) {
Valid_ = false;
return;
}
memcpy((void *)&P_,buffer, size);
Size_=size;
Valid_ = (Size_== htons(P_.rawlen));
if(Valid_)
Valid_ = ParseRadius(0,(unsigned char *)&P_.attributes[0],Size_-20,Attrs_);
}
explicit RadiusPacket(const std::string &p) {
if(p.size() >= sizeof(RawRadiusPacket)) {
Valid_ = false;
return;
}
memcpy((void *)&P_,(const unsigned char*) p.c_str(), p.size());
Size_=p.size();
Valid_ = (Size_== htons(P_.rawlen));
if(Valid_)
Valid_ = ParseRadius(0,(unsigned char *)&P_.attributes[0],Size_-20,Attrs_);
}
explicit RadiusPacket(const RadiusPacket &P) {
Valid_ = P.Valid_;
Size_ = P.Size_;
P_ = P.P_;
Attrs_ = P.Attrs_;
}
explicit RadiusPacket() = default;
unsigned char * Buffer() { return (unsigned char *)&P_; }
[[nodiscard]] uint16_t BufferLen() const { return sizeof(P_);}
void Evaluate(uint16_t size) {
Size_ = size;
Valid_ = ParseRadius(0,(unsigned char *)&P_.attributes[0],Size_-20,Attrs_);
}
[[nodiscard]] uint16_t Len() const { return htons(P_.rawlen); }
[[nodiscard]] uint16_t Size() const { return Size_; }
friend std::ostream &operator<<(std::ostream &os, RadiusPacket const &P);
inline bool IsAuthentication() {
return (P_.code == RADIUS::Access_Request ||
P_.code == RADIUS::Access_Accept ||
P_.code == RADIUS::Access_Challenge ||
P_.code == RADIUS::Access_Reject ||
P_.code == RADCMD_RES_FREE_REQ ||
P_.code == RADCMD_RES_FREE_RES ||
P_.code == RADCMD_RES_QUERY_REQ ||
P_.code == RADCMD_RES_QUERY_RES ||
P_.code == RADCMD_RES_ALT_RECLAIM_REQ);
}
inline bool IsAccounting() {
return (P_.code == RADIUS::Accounting_Request ||
P_.code == RADIUS::Accounting_Response ||
P_.code == RADIUS::Accounting_Status ||
P_.code == RADIUS::Accounting_Message);
}
inline bool IsAuthority() {
return (P_.code == RADIUS::Disconnect_Request ||
P_.code == RADIUS::Disconnect_ACK ||
P_.code == RADIUS::Disconnect_NAK ||
P_.code == RADIUS::CoA_Request ||
P_.code == RADIUS::CoA_ACK ||
P_.code == RADIUS::CoA_NAK);
}
void Log(std::ostream &os) {
uint16_t p = 0;
while(p<Size_) {
os << std::setfill('0') << std::setw(4) << p << ": ";
uint16_t v=0;
while(v<16 && p+v<Size_) {
os << std::setfill('0') << std::setw(2) << std::right << std::hex << (uint16_t )((const unsigned char *)&P_)[p+v] << " ";
v++;
}
os << std::endl;
p+=16;
}
os << std::dec << std::endl << std::endl;
Print(os);
}
inline const char * PacketType() {
return CommandName(P_.code);
}
inline int PacketTypeInt() {
return (int)(P_.code);
}
void ComputeMessageAuthenticator(const std::string &secret) {
RawRadiusPacket P = P_;
if(P_.code==1) {
unsigned char OldAuthenticator[16]{0};
for (const auto &attr : Attrs_) {
if (attr.type == 80) {
memcpy(OldAuthenticator, &P_.attributes[attr.pos], 16);
memset(&P.attributes[attr.pos], 0, 16);
}
}
unsigned char NewAuthenticator[16]{0};
Poco::HMACEngine<Poco::MD5Engine> H(secret);
H.update((const unsigned char *)&P, Size_);
auto digest = H.digest();
int p = 0;
for (const auto &i : digest)
NewAuthenticator[p++] = i;
if (memcmp(OldAuthenticator, NewAuthenticator, 16) == 0) {
std::cout << "Authenticator match..." << std::endl;
} else {
std::cout << "Authenticator MIS-match..." << std::endl;
for (const auto &attr : Attrs_) {
if (attr.type == 80) {
memcpy(&P_.attributes[attr.pos], NewAuthenticator, 16);
}
}
}
}
}
bool VerifyMessageAuthenticator(const std::string &secret) {
RawRadiusPacket P = P_;
if(P_.code==1) {
unsigned char OldAuthenticator[16]{0};
for (const auto &attr : Attrs_) {
if (attr.type == 80) {
memcpy(OldAuthenticator, &P_.attributes[attr.pos], 16);
memset(&P.attributes[attr.pos], 0, 16);
}
}
unsigned char NewAuthenticator[16]{0};
Poco::HMACEngine<Poco::MD5Engine> H(secret);
H.update((const unsigned char *)&P, Size_);
auto digest = H.digest();
int p = 0;
for (const auto &i : digest)
NewAuthenticator[p++] = i;
return memcmp(OldAuthenticator, NewAuthenticator, 16) == 0;
}
return true;
}
static void BufLog(std::ostream & os, const char * pre, const unsigned char *b, uint s) {
uint16_t p = 0;
while(p<s) {
os << pre << std::setfill('0') << std::setw(4) << p << ": ";
uint16_t v=0;
while(v<16 && p+v<s) {
os << std::setfill('0') << std::setw(2) << std::right << std::hex << (uint16_t )b[p+v] << " ";
v++;
}
os << std::endl;
p+=16;
}
os << std::dec ;
}
inline void Print(std::ostream &os) {
os << "Packet type: (" << (uint) P_.code << ") " << CommandName(P_.code) << std::endl;
os << " Identifier: " << (uint) P_.identifier << std::endl;
os << " Length: " << Size_ << std::endl;
os << " Authenticator: " ;
BufLog(os, "", P_.authenticator, sizeof(P_.authenticator));
os << " Attributes: " << std::endl;
for(const auto &attr:Attrs_) {
os << " " << std::setfill(' ') << "(" << std::setw(4) << (uint) attr.type << ") " << AttributeName(attr.type) << " Len:" << attr.len << std::endl;
BufLog(os, " " , &P_.attributes[attr.pos], attr.len);
}
os << std::dec << std::endl << std::endl;
}
std::string ExtractSerialNumberTIP() {
std::string R;
for(const auto &attribute:Attrs_) {
if(attribute.type==26) {
AttributeList VendorAttributes;
uint32_t VendorId = htonl( *(const uint32_t *)&(P_.attributes[attribute.pos]));
// std::cout << VendorId << std::endl;
if(VendorId==TIP_vendor_id && attribute.len>(4+2)) {
if (ParseRadius(attribute.pos + 4, &P_.attributes[attribute.pos + 4], attribute.len - 4 - 2,
VendorAttributes)) {
// std::cout << VendorAttributes << std::endl;
for (const auto &vendorAttr: VendorAttributes) {
if (vendorAttr.type == TIP_serial) {
for (uint16_t i = 0; i < vendorAttr.len; i++) {
if (P_.attributes[vendorAttr.pos + i] == '-')
continue;
R += (char) P_.attributes[vendorAttr.pos + i];
}
return R;
}
}
}
}
}
}
return R;
}
std::string ExtractSerialNumberFromProxyState() {
std::string Result;
for(const auto &attribute:Attrs_) {
if(attribute.type==33) {
const char * SN = (const char *)&P_.attributes[attribute.pos];
auto i=0;
while(*SN!=':' && i<12) {
Result+=*SN++;
i++;
}
return Result;
}
}
return Result;
}
std::string ExtractProxyStateDestination() {
std::string Result;
for(const auto &attribute:Attrs_) {
if(attribute.type==33 && attribute.len>2) {
std::string Attr33;
// format is serial:IP:port:interface
Attr33.assign((const char *)(const char *)&P_.attributes[attribute.pos],attribute.len-2);
auto Parts = Poco::StringTokenizer(Attr33,":");
if(Parts.count()==4)
return Parts[1]+":"+Parts[2];
return Result;
}
}
return Result;
}
std::string ExtractCallingStationID() {
std::string Result;
for(const auto &attribute:Attrs_) {
if(attribute.type==31 && attribute.len>2) {
Result.assign((const char *)(const char *)&P_.attributes[attribute.pos],attribute.len-2);
return Result;
}
}
return Result;
}
std::string ExtractCalledStationID() {
std::string Result;
for(const auto &attribute:Attrs_) {
if(attribute.type==30 && attribute.len>2) {
Result.assign((const char *)(const char *)&P_.attributes[attribute.pos],attribute.len-2);
return Result;
}
}
return Result;
}
[[nodiscard]] std::string UserName() const {
for(const auto &attr:Attrs_) {
if(attr.type==1) {
std::string user_name{(const char *)&P_.attributes[attr.pos],attr.len};
return user_name;
}
}
return "";
}
private:
RawRadiusPacket P_;
uint16_t Size_{0};
AttributeList Attrs_;
bool Valid_=false;
};
inline std::ostream &operator<<(std::ostream &os, RadiusPacket const &P) {
os << P.Attrs_ ;
return os;
}
}

View File

@@ -3,25 +3,18 @@
//
#include "RADIUS_proxy_server.h"
#include "RADIUS_helpers.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
namespace OpenWifi {
const int SMALLEST_RADIUS_PACKET = 20+19+4;
const int RADIUS_BUFFER_SIZE = 2048;
const int DEFAULT_RADIUS_AUTHENTICATION_PORT = 1812;
const int DEFAULT_RADIUS_ACCOUNTING_PORT = 1813;
const int DEFAULT_RADIUS_CoA_PORT = 3799;
int RADIUS_proxy_server::Start() {
ConfigFilename_ = MicroService::instance().DataDir()+"/radius_pool_config.json";
Poco::File Config(ConfigFilename_);
enabled_ = MicroService::instance().ConfigGetBool("radius.proxy.enable",false);
if(!enabled_ && !Config.exists())
return 0;
enabled_ = true;
Poco::Net::SocketAddress AuthSockAddrV4(Poco::Net::AddressFamily::IPv4,
MicroService::instance().ConfigGetInt("radius.proxy.authentication.port",DEFAULT_RADIUS_AUTHENTICATION_PORT));
@@ -37,282 +30,151 @@ namespace OpenWifi {
MicroService::instance().ConfigGetInt("radius.proxy.accounting.port",DEFAULT_RADIUS_ACCOUNTING_PORT));
AccountingSocketV6_ = std::make_unique<Poco::Net::DatagramSocket>(AcctSockAddrV6,true);
Poco::Net::SocketAddress CoASockAddrV4(Poco::Net::AddressFamily::IPv4,
MicroService::instance().ConfigGetInt("radius.proxy.coa.port",DEFAULT_RADIUS_CoA_PORT));
CoASocketV4_ = std::make_unique<Poco::Net::DatagramSocket>(CoASockAddrV4,true);
Poco::Net::SocketAddress CoASockAddrV6(Poco::Net::AddressFamily::IPv6,
MicroService::instance().ConfigGetInt("radius.proxy.coa.port",DEFAULT_RADIUS_CoA_PORT));
CoASocketV6_ = std::make_unique<Poco::Net::DatagramSocket>(CoASockAddrV6,true);
RadiusReactor_.addEventHandler(*AuthenticationSocketV4_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
AuthenticationReactor_.addEventHandler(*AuthenticationSocketV4_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
RadiusReactor_.addEventHandler(*AuthenticationSocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
RadiusReactor_.addEventHandler(*AccountingSocketV4_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
AccountingReactor_.addEventHandler(*AccountingSocketV4_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
RadiusReactor_.addEventHandler(*AccountingSocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
AuthenticationReactor_.addEventHandler(*AuthenticationSocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
AccountingReactor_.addEventHandler(*AccountingSocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
RadiusReactor_.addEventHandler(*CoASocketV4_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnCoASocketReadable));
RadiusReactor_.addEventHandler(*CoASocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnCoASocketReadable));
ParseConfig();
// start RADSEC servers...
StartRADSECServers();
RadiusReactorThread_.start(RadiusReactor_);
Utils::SetThreadName(RadiusReactorThread_,"rad:reactor");
running_ = true;
AuthenticationReactorThread_.start(AuthenticationReactor_);
AccountingReactorThread_.start(AccountingReactor_);
return 0;
}
void RADIUS_proxy_server::Stop() {
poco_information(Logger(),"Stopping...");
if(enabled_ && running_) {
RadiusReactor_.removeEventHandler(
*AuthenticationSocketV4_,
Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
RadiusReactor_.removeEventHandler(
*AuthenticationSocketV6_,
Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
AuthenticationReactor_.removeEventHandler(*AuthenticationSocketV4_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
AccountingReactor_.removeEventHandler(*AccountingSocketV4_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
AuthenticationReactor_.removeEventHandler(*AuthenticationSocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
AccountingReactor_.removeEventHandler(*AccountingSocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
RadiusReactor_.removeEventHandler(
*AccountingSocketV4_,
Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
RadiusReactor_.removeEventHandler(
*AccountingSocketV6_,
Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
AuthenticationReactor_.stop();
AuthenticationReactorThread_.join();
RadiusReactor_.removeEventHandler(
*CoASocketV4_,
Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnCoASocketReadable));
RadiusReactor_.removeEventHandler(
*CoASocketV6_,
Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
*this, &RADIUS_proxy_server::OnCoASocketReadable));
for(auto &[_,radsec_server]:RADSECservers_)
radsec_server->Stop();
RadiusReactor_.stop();
RadiusReactorThread_.join();
enabled_=false;
running_=false;
}
poco_information(Logger(),"Stopped...");
AccountingReactor_.stop();
AccountingReactorThread_.join();
}
void RADIUS_proxy_server::StartRADSECServers() {
for(const auto &pool:PoolList_.pools) {
for(const auto &entry:pool.authConfig.servers) {
if(entry.radsec) {
StartRADSECServer(entry);
std::string ExtractSerialNumber(const unsigned char *b, uint32_t s) {
std::string result;
try {
uint32_t pos=0;
while(pos<s) {
auto len = b[pos+1];
if(b[pos] != 26) {
pos += len;
continue;
}
uint32_t vendor_id = b[pos+2] * 256 * 256 * 256 + b[pos+3] * 256 * 256 + b[pos+4] * 256+ b[pos+5];
if(vendor_id!=58888) {
pos += len;
continue;
}
auto tpos0 = pos + 6;
auto tend0 = tpos0 + b[tpos0+1];
while (tpos0<tend0) {
if (b[tpos0] == 71) {
auto tpos1 = tpos0+2;
auto tlen1 = b[tpos0+1];
auto tend1 = tpos1 + tlen1;
while (tpos1 < tend1) {
if (b[tpos1] == 0x01) {
uint32_t tlen = b[tpos1 + 1] - 2;
tpos1 += 2;
while (tlen) {
if (b[tpos1] != '-') {
result += (char) b[tpos1];
}
tlen--;
tpos1++;
}
if (result.size() == 12)
return result;
return "";
} else {
tpos1 += b[tpos1+1];
}
}
} else {
tpos0 += b[tpos0 + 1];
}
}
pos += len;
}
} catch (...) {
}
return result;
}
void RADIUS_proxy_server::StartRADSECServer(const GWObjects::RadiusProxyServerEntry &E) {
RADSECservers_[ Poco::Net::SocketAddress(E.ip,0) ] = std::make_unique<RADSECserver>(RadiusReactor_,E);
}
void RADIUS_proxy_server::OnAccountingSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf) {
Poco::Net::SocketAddress Sender;
RADIUS::RadiusPacket P;
unsigned char Buffer[RADIUS_BUFFER_SIZE];
auto ReceiveSize = pNf->socket().impl()->receiveBytes(P.Buffer(),P.BufferLen());
if(ReceiveSize<SMALLEST_RADIUS_PACKET) {
poco_warning(Logger(),"Accounting: bad packet received.");
auto ReceiveSize = pNf.get()->socket().impl()->receiveBytes(Buffer,sizeof(Buffer));
if(ReceiveSize<SMALLEST_RADIUS_PACKET)
return;
}
P.Evaluate(ReceiveSize);
auto SerialNumber = P.ExtractSerialNumberFromProxyState();
if(SerialNumber.empty()) {
poco_warning(Logger(),"Accounting: missing serial number.");
return;
}
auto CallingStationID = P.ExtractCallingStationID();
auto CalledStationID = P.ExtractCalledStationID();
poco_information(Logger(), fmt::format("Accounting Packet received for {}, CalledStationID: {}, CallingStationID:{}",SerialNumber, CalledStationID, CallingStationID));
AP_WS_Server()->SendRadiusAccountingData(SerialNumber,P.Buffer(),P.Size());
auto SerialNumber = ExtractSerialNumber(&Buffer[20],ReceiveSize);
Logger().information(fmt::format("Accounting Packet received for {}",SerialNumber));
std::cout << "Received an Accounting packet for :" << SerialNumber << std::endl;
DeviceRegistry()->SendRadiusAccountingData(SerialNumber,Buffer,ReceiveSize);
}
void RADIUS_proxy_server::OnAuthenticationSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf) {
Poco::Net::SocketAddress Sender;
RADIUS::RadiusPacket P;
unsigned char Buffer[RADIUS_BUFFER_SIZE];
auto ReceiveSize = pNf->socket().impl()->receiveBytes(P.Buffer(),P.BufferLen());
if(ReceiveSize<SMALLEST_RADIUS_PACKET) {
poco_warning(Logger(),"Authentication: bad packet received.");
auto ReceiveSize = pNf.get()->socket().impl()->receiveBytes(Buffer,sizeof(Buffer));
if(ReceiveSize<SMALLEST_RADIUS_PACKET)
return;
}
P.Evaluate(ReceiveSize);
auto SerialNumber = P.ExtractSerialNumberFromProxyState();
if(SerialNumber.empty()) {
poco_warning(Logger(),"Authentication: missing serial number.");
return;
}
auto CallingStationID = P.ExtractCallingStationID();
auto CalledStationID = P.ExtractCalledStationID();
poco_information(Logger(), fmt::format("Authentication Packet received for {}, CalledStationID: {}, CallingStationID:{}",SerialNumber, CalledStationID, CallingStationID));
AP_WS_Server()->SendRadiusAuthenticationData(SerialNumber,P.Buffer(),P.Size());
auto SerialNumber = ExtractSerialNumber(&Buffer[20],ReceiveSize);
Logger().information(fmt::format("Authentication Packet received for {}",SerialNumber));
std::cout << "Received an Authentication packet for :" << SerialNumber << std::endl;
DeviceRegistry()->SendRadiusAuthenticationData(SerialNumber,Buffer,ReceiveSize);
}
void RADIUS_proxy_server::OnCoASocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf) {
Poco::Net::SocketAddress Sender;
RADIUS::RadiusPacket P;
auto ReceiveSize = pNf.get()->socket().impl()->receiveBytes(P.Buffer(),P.BufferLen());
if(ReceiveSize<SMALLEST_RADIUS_PACKET) {
poco_warning(Logger(),"CoA/DM: bad packet received.");
return;
}
P.Evaluate(ReceiveSize);
auto SerialNumber = P.ExtractSerialNumberTIP();
if(SerialNumber.empty()) {
poco_warning(Logger(),"CoA/DM: missing serial number.");
return;
}
auto CallingStationID = P.ExtractCallingStationID();
auto CalledStationID = P.ExtractCalledStationID();
poco_information(Logger(), fmt::format("CoA Packet received for {}, CalledStationID: {}, CallingStationID:{}",SerialNumber, CalledStationID, CallingStationID));
AP_WS_Server()->SendRadiusCoAData(SerialNumber,P.Buffer(),P.Size());
}
void RADIUS_proxy_server::SendAccountingData(const std::string &serialNumber, const char *buffer, std::size_t size) {
if(Pools_.empty())
return;
RADIUS::RadiusPacket P((unsigned char *)buffer,size);
auto Destination = P.ExtractProxyStateDestination();
auto CallingStationID = P.ExtractCallingStationID();
auto CalledStationID = P.ExtractCalledStationID();
void RADIUS_proxy_server::SendAccountingData(const std::string &serialNumber, const std::string &Destination,const char *buffer, std::size_t size) {
Poco::Net::SocketAddress Dst(Destination);
std::lock_guard G(Mutex_);
bool UseRADSEC = false;
auto FinalDestination = Route(radius_type::acct, Dst, P, UseRADSEC);
if(UseRADSEC) {
Poco::Net::SocketAddress RSP(FinalDestination.host(),0);
auto DestinationServer = RADSECservers_.find(RSP);
if(DestinationServer!=end(RADSECservers_)) {
DestinationServer->second->SendData(serialNumber, (const unsigned char *)buffer, size);
}
} else {
auto AllSent =
SendData(Dst.family() == Poco::Net::SocketAddress::IPv4 ? *AccountingSocketV4_
: *AccountingSocketV6_,
(const unsigned char *)buffer, size, FinalDestination);
if (!AllSent)
poco_error(Logger(),fmt::format("{}: Could not send Accounting packet packet to {}.",
serialNumber, Destination));
else
poco_information(Logger(), fmt::format(
"{}: Sending Accounting Packet to {}, CalledStationID: {}, CallingStationID:{}",
serialNumber, FinalDestination.toString(), CalledStationID, CallingStationID));
}
if(Dst.af()==Poco::Net::AddressFamily::IPv4)
AccountingSocketV4_->sendTo(buffer,(int)size,Route(Dst,AcctPoolsV4_,AcctPoolsIndexV4_));
else
AccountingSocketV6_->sendTo(buffer,(int)size,Route(Dst,AcctPoolsV6_,AcctPoolsIndexV6_));
Logger().information(fmt::format("{}: Sending Accounting Packet to {}", serialNumber, Destination));
std::cout << "Sending Accounting data to " << Destination << std::endl;
}
bool RADIUS_proxy_server::SendData( Poco::Net::DatagramSocket & Sock, const unsigned char *buf , std::size_t size, const Poco::Net::SocketAddress &S) {
return Sock.sendTo(buf, size, S)==(int)size;
}
void RADIUS_proxy_server::SendAuthenticationData(const std::string &serialNumber, const char *buffer, std::size_t size) {
if(Pools_.empty())
return;
RADIUS::RadiusPacket P((unsigned char *)buffer,size);
auto Destination = P.ExtractProxyStateDestination();
auto CallingStationID = P.ExtractCallingStationID();
auto CalledStationID = P.ExtractCalledStationID();
void RADIUS_proxy_server::SendAuthenticationData(const std::string &serialNumber, const std::string &Destination,const char *buffer, std::size_t size) {
Poco::Net::SocketAddress Dst(Destination);
std::lock_guard G(Mutex_);
bool UseRADSEC = false;
auto FinalDestination = Route(radius_type::auth, Dst, P, UseRADSEC);
if(UseRADSEC) {
Poco::Net::SocketAddress RSP(FinalDestination.host(),0);
auto DestinationServer = RADSECservers_.find(RSP);
if(DestinationServer!=end(RADSECservers_)) {
DestinationServer->second->SendData(serialNumber, (const unsigned char *)buffer, size);
}
} else {
auto AllSent =
SendData(Dst.family() == Poco::Net::SocketAddress::IPv4 ? *AuthenticationSocketV4_
: *AuthenticationSocketV6_,
(const unsigned char *)buffer, size, FinalDestination);
if (!AllSent)
poco_error(Logger(),fmt::format("{}: Could not send Authentication packet packet to {}.",
serialNumber, Destination));
else
poco_information(Logger(), fmt::format("{}: Sending Authentication Packet to {}, CalledStationID: {}, CallingStationID:{}",
serialNumber, FinalDestination.toString(),
CalledStationID, CallingStationID));
}
if(Dst.af()==Poco::Net::AddressFamily::IPv4)
AuthenticationSocketV4_->sendTo(buffer,(int)size,Route(Dst,AuthPoolsV4_,AuthPoolsIndexV4_));
else
AuthenticationSocketV6_->sendTo(buffer,(int)size,Route(Dst,AuthPoolsV6_,AuthPoolsIndexV6_));
Logger().information(fmt::format("{}: Sending Authentication Packet to {}", serialNumber, Destination));
std::cout << "Sending Authentication data to " << Destination << std::endl;
}
void RADIUS_proxy_server::SendCoAData(const std::string &serialNumber, const char *buffer, std::size_t size) {
void RADIUS_proxy_server::ParseServerList(const GWObjects::RadiusProxyServerConfig & Config, PoolIndexMap_t &MapV4, PoolIndexMap_t &MapV6, PoolIndexVec_t &VecV4, PoolIndexVec_t &VecV6) {
if(Pools_.empty())
return;
RADIUS::RadiusPacket P((unsigned char *)buffer,size);
auto Destination = P.ExtractProxyStateDestination();
if(Destination.empty()) {
Destination = "0.0.0.0:0";
}
Poco::Net::SocketAddress Dst(Destination);
std::lock_guard G(Mutex_);
bool UseRADSEC = false;
auto FinalDestination = Route(radius_type::coa, Dst, P, UseRADSEC);
if(UseRADSEC) {
Poco::Net::SocketAddress RSP(FinalDestination.host(),0);
auto DestinationServer = RADSECservers_.find(RSP);
if(DestinationServer!=end(RADSECservers_)) {
DestinationServer->second->SendData(serialNumber, (const unsigned char *)buffer, size);
}
} else {
auto AllSent = SendData(Dst.family() == Poco::Net::SocketAddress::IPv4 ? *CoASocketV4_
: *CoASocketV6_,
(const unsigned char *)buffer, size, FinalDestination);
if (!AllSent)
poco_error(Logger(),fmt::format("{}: Could not send CoA packet packet to {}.",
serialNumber, Destination));
else
poco_information(Logger(), fmt::format("{}: Sending CoA Packet to {}", serialNumber,
FinalDestination.toString()));
}
}
void RADIUS_proxy_server::ParseServerList(const GWObjects::RadiusProxyServerConfig & Config, std::vector<Destination> &V4, std::vector<Destination> &V6, bool setAsDefault) {
std::vector<Destination> DestsV4,DestsV6;
uint64_t TotalV4=0, TotalV6=0;
for(const auto &server:Config.servers) {
Poco::Net::IPAddress a;
if(!Poco::Net::IPAddress::tryParse(server.ip,a)) {
poco_error(Logger(),fmt::format("RADIUS-PARSE Config: server address {} is nto a valid address in v4 or v6. Entry skipped.",server.ip));
continue;
}
auto S = Poco::Net::SocketAddress(fmt::format("{}:{}",server.ip,server.port));
auto S = Poco::Net::SocketAddress(fmt::format("{}:{}",server.name,server.port));
Destination D{
.Addr = S,
.state = 0,
@@ -322,39 +184,32 @@ namespace OpenWifi {
.strategy = Config.strategy,
.monitor = Config. monitor,
.monitorMethod = Config.monitorMethod,
.methodParameters = Config.methodParameters,
.useAsDefault = setAsDefault,
.useRADSEC = server.radsec,
.realms = server.radsecRealms
.methodParameters = Config.methodParameters
};
if(setAsDefault && D.useRADSEC)
defaultIsRADSEC_ = true;
if(S.family()==Poco::Net::IPAddress::IPv4) {
if(S.af()==Poco::Net::AddressFamily::IPv4) {
TotalV4 += server.weight;
V4.push_back(D);
DestsV4.push_back(D);
MapV4[S] = VecV4.size();
} else {
TotalV6 += server.weight;
V6.push_back(D);
DestsV6.push_back(D);
MapV6[S] = VecV6.size();
}
}
for(auto &i:V4) {
if(TotalV4==0) {
i.step = 1000;
} else {
i.step = 1000 - ((1000 * i.weight) / TotalV4);
}
for(auto &i:DestsV4) {
i.step = 1000 - ((1000*i.weight)/TotalV4);
}
for(auto &i:V6) {
if(TotalV6==0) {
i.step = 1000;
} else {
i.step = 1000 - ((1000 * i.weight) / TotalV6);
}
for(auto &i:DestsV6) {
i.step = 1000 - ((1000*i.weight)/TotalV6);
}
if(!DestsV4.empty())
VecV4.push_back(DestsV4);
if(!DestsV6.empty())
VecV6.push_back((DestsV6));
}
void RADIUS_proxy_server::ParseConfig() {
@@ -373,135 +228,36 @@ namespace OpenWifi {
ResetConfig();
PoolList_ = RPC;
for(const auto &pool:RPC.pools) {
RadiusPool NewPool;
ParseServerList(pool.authConfig, NewPool.AuthV4, NewPool.AuthV6, pool.useByDefault);
ParseServerList(pool.acctConfig, NewPool.AcctV4, NewPool.AcctV6, pool.useByDefault);
ParseServerList(pool.coaConfig, NewPool.CoaV4, NewPool.CoaV6, pool.useByDefault);
Pools_.push_back(NewPool);
ParseServerList(pool.authConfig,AuthPoolsIndexV4_, AuthPoolsIndexV6_, AuthPoolsV4_, AuthPoolsV6_);
ParseServerList(pool.acctConfig,AcctPoolsIndexV4_, AcctPoolsIndexV6_, AcctPoolsV4_, AcctPoolsV6_);
}
} else {
poco_warning(Logger(),fmt::format("Configuration file '{}' is bad.",ConfigFilename_));
Logger().warning(fmt::format("Configuration file '{}' is bad.",ConfigFilename_));
}
} else {
poco_warning(Logger(),fmt::format("No configuration file '{}' exists.",ConfigFilename_));
Logger().warning(fmt::format("No configuration file '{}' exists.",ConfigFilename_));
}
} catch (const Poco::Exception &E) {
Logger().log(E);
} catch (...) {
poco_error(Logger(),fmt::format("Error while parsing configuration file '{}'",ConfigFilename_));
Logger().error(fmt::format("Error while parsing configuration file '{}'",ConfigFilename_));
}
}
static bool RealmMatch(const std::string &user_realm, const std::string & realm) {
if(realm.find_first_of('*') == std::string::npos)
return user_realm == realm;
return realm.find(user_realm) != std::string::npos;
}
Poco::Net::SocketAddress RADIUS_proxy_server::DefaultRoute(radius_type rtype, const Poco::Net::SocketAddress &RequestedAddress, const RADIUS::RadiusPacket &P, bool &UseRADSEC) {
bool IsV4 = RequestedAddress.family()==Poco::Net::SocketAddress::IPv4;
// find the realm...
auto UserName = P.UserName();
if(!UserName.empty()) {
auto UserTokens = Poco::StringTokenizer(UserName, "@");
auto UserRealm = ((UserTokens.count() > 1) ? UserTokens[1] : UserName);
Poco::toLowerInPlace(UserRealm);
for(const auto &pool:Pools_) {
for(const auto &server:pool.AuthV4) {
if(!server.realms.empty()) {
for(const auto &realm:server.realms) {
if (RealmMatch(UserRealm,realm)) {
std::cout << "Realm match..." << std::endl;
UseRADSEC = true;
return server.Addr;
}
}
}
}
}
}
if(defaultIsRADSEC_) {
UseRADSEC = true;
return (IsV4 ? Pools_[defaultPoolIndex_].AuthV4[0].Addr : Pools_[defaultPoolIndex_].AuthV6[0].Addr );
}
switch(rtype) {
case radius_type::auth: {
return ChooseAddress(IsV4 ? Pools_[defaultPoolIndex_].AuthV4
: Pools_[defaultPoolIndex_].AuthV6,
RequestedAddress);
}
case radius_type::acct:
default: {
return ChooseAddress(IsV4 ? Pools_[defaultPoolIndex_].AcctV4
: Pools_[defaultPoolIndex_].AcctV6,
RequestedAddress);
}
case radius_type::coa: {
return ChooseAddress(IsV4 ? Pools_[defaultPoolIndex_].CoaV4
: Pools_[defaultPoolIndex_].CoaV6,
RequestedAddress);
}
}
}
Poco::Net::SocketAddress RADIUS_proxy_server::Route([[maybe_unused]] radius_type rtype, const Poco::Net::SocketAddress &RequestedAddress, const RADIUS::RadiusPacket &P, bool &UseRADSEC) {
Poco::Net::SocketAddress RADIUS_proxy_server::Route(const Poco::Net::SocketAddress &A, PoolIndexVec_t & P, PoolIndexMap_t &M) {
std::lock_guard G(Mutex_);
if(Pools_.empty()) {
UseRADSEC = false;
return RequestedAddress;
}
if(PoolList_.pools.empty())
return A;
bool IsV4 = RequestedAddress.family()==Poco::Net::SocketAddress::IPv4;
bool useDefault;
useDefault = IsV4 ? RequestedAddress.host() == Poco::Net::IPAddress::wildcard(Poco::Net::IPAddress::IPv4) : RequestedAddress.host() == Poco::Net::IPAddress::wildcard(Poco::Net::IPAddress::IPv6) ;
auto It = M.find(A);
if(It==M.end())
return A;
auto Index = It->second;
auto Pool = P[Index];
if(useDefault) {
return DefaultRoute(rtype, RequestedAddress, P, UseRADSEC);
}
auto isAddressInPool = [&](const std::vector<Destination> & D, bool &UseRADSEC) -> bool {
for(const auto &entry:D)
if(entry.Addr.host()==RequestedAddress.host()) {
UseRADSEC = entry.useRADSEC;
return true;
}
return false;
};
for(auto &i:Pools_) {
switch(rtype) {
case radius_type::coa: {
if (isAddressInPool((IsV4 ? i.CoaV4 : i.CoaV6), UseRADSEC)) {
return ChooseAddress(IsV4 ? i.CoaV4 : i.CoaV6, RequestedAddress);
}
} break;
case radius_type::auth: {
if (isAddressInPool((IsV4 ? i.AuthV4 : i.AuthV6), UseRADSEC)) {
return ChooseAddress(IsV4 ? i.AuthV4 : i.AuthV6, RequestedAddress);
}
} break;
case radius_type::acct: {
if (isAddressInPool((IsV4 ? i.AcctV4 : i.AcctV6), UseRADSEC)) {
return ChooseAddress(IsV4 ? i.AcctV4 : i.AcctV6, RequestedAddress);
}
} break;
}
}
return DefaultRoute(rtype, RequestedAddress, P, UseRADSEC);
}
Poco::Net::SocketAddress RADIUS_proxy_server::ChooseAddress(std::vector<Destination> &Pool, const Poco::Net::SocketAddress & OriginalAddress) {
if(Pool.size()==1) {
return Pool[0].Addr;
}
if (Pool[0].strategy == "weighted") {
// is there anything of the same af ?
if(Pool[0].strategy=="weighted") {
bool found = false;
uint64_t cur_state = std::numeric_limits<uint64_t>::max();
std::size_t pos = 0, index = 0;
@@ -518,13 +274,12 @@ namespace OpenWifi {
pos++;
}
if (!found) {
return OriginalAddress;
}
if (!found)
return A;
Pool[index].state += Pool[index].step;
return Pool[index].Addr;
} else if (Pool[0].strategy == "round_robin") {
} else if (Pool[0].strategy=="round_robin") {
bool found = false;
uint64_t cur_state = std::numeric_limits<uint64_t>::max();
std::size_t pos = 0, index = 0;
@@ -541,20 +296,19 @@ namespace OpenWifi {
pos++;
}
if (!found) {
return OriginalAddress;
}
if (!found)
return A;
Pool[index].state += 1;
return Pool[index].Addr;
} else if (Pool[0].strategy == "random") {
if (Pool.size() > 1) {
return Pool[std::rand() % Pool.size()].Addr;
} else if (Pool[0].strategy=="random") {
if(Pool.size()>1) {
return Pool[ std::rand() % Pool.size() ].Addr;
} else {
return OriginalAddress;
return A;
}
}
return OriginalAddress;
return A;
}
void RADIUS_proxy_server::SetConfig(const GWObjects::RadiusProxyPoolList &C) {
@@ -568,17 +322,19 @@ namespace OpenWifi {
Disk.stringify(ofs);
ofs.close();
if(!running_) {
Start();
}
ParseConfig();
}
void RADIUS_proxy_server::ResetConfig() {
PoolList_.pools.clear();
Pools_.clear();
defaultPoolIndex_=0;
AuthPoolsIndexV4_.clear();
AuthPoolsIndexV6_.clear();
AcctPoolsIndexV4_.clear();
AcctPoolsIndexV6_.clear();
AuthPoolsV4_.clear();
AuthPoolsV6_.clear();
AcctPoolsV4_.clear();
AcctPoolsV6_.clear();
}
void RADIUS_proxy_server::DeleteConfig() {
@@ -592,7 +348,6 @@ namespace OpenWifi {
}
ResetConfig();
Stop();
}
void RADIUS_proxy_server::GetConfig(GWObjects::RadiusProxyPoolList &C) {

View File

@@ -5,20 +5,11 @@
#pragma once
#include "framework/MicroService.h"
#include "RESTObjects/RESTAPI_GWobjects.h"
#include "Poco/Net/DatagramSocket.h"
#include "Poco/Net/SocketReactor.h"
#include "RADSECserver.h"
#include "RESTObjects/RESTAPI_GWobjects.h"
namespace OpenWifi {
enum class radius_type {
auth, acct, coa
};
class RADIUS_proxy_server : public SubSystemServer {
public:
inline static auto instance() {
@@ -28,23 +19,16 @@ namespace OpenWifi {
int Start() final;
void Stop() final;
inline bool Enabled() const { return enabled_; }
void OnAccountingSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
void OnAuthenticationSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
void OnCoASocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
void SendAccountingData(const std::string &serialNumber, const char *buffer, std::size_t size);
void SendAuthenticationData(const std::string &serialNumber, const char *buffer, std::size_t size);
void SendCoAData(const std::string &serialNumber, const char *buffer, std::size_t size);
void SendAccountingData(const std::string &serialNumber, const std::string &Destination,const char *buffer, std::size_t size);
void SendAuthenticationData(const std::string &serialNumber, const std::string &Destination,const char *buffer, std::size_t size);
void SetConfig(const GWObjects::RadiusProxyPoolList &C);
void DeleteConfig();
void GetConfig(GWObjects::RadiusProxyPoolList &C);
void StartRADSECServers();
void StartRADSECServer(const GWObjects::RadiusProxyServerEntry &E);
struct Destination {
Poco::Net::SocketAddress Addr;
uint64_t state = 0;
@@ -55,9 +39,6 @@ namespace OpenWifi {
bool monitor=false;
std::string monitorMethod;
std::vector<std::string> methodParameters;
bool useAsDefault=false;
bool useRADSEC=false;
std::vector<std::string> realms;
};
private:
@@ -65,44 +46,34 @@ namespace OpenWifi {
std::unique_ptr<Poco::Net::DatagramSocket> AccountingSocketV6_;
std::unique_ptr<Poco::Net::DatagramSocket> AuthenticationSocketV4_;
std::unique_ptr<Poco::Net::DatagramSocket> AuthenticationSocketV6_;
std::unique_ptr<Poco::Net::DatagramSocket> CoASocketV4_;
std::unique_ptr<Poco::Net::DatagramSocket> CoASocketV6_;
Poco::Net::SocketReactor RadiusReactor_;
Poco::Thread RadiusReactorThread_;
Poco::Net::SocketReactor AccountingReactor_;
Poco::Net::SocketReactor AuthenticationReactor_;
Poco::Thread AuthenticationReactorThread_;
Poco::Thread AccountingReactorThread_;
GWObjects::RadiusProxyPoolList PoolList_;
std::string ConfigFilename_;
std::map<Poco::Net::SocketAddress, std::unique_ptr<RADSECserver>> RADSECservers_;
typedef std::map<Poco::Net::SocketAddress,uint> PoolIndexMap_t;
PoolIndexMap_t AuthPoolsIndexV4_;
PoolIndexMap_t AcctPoolsIndexV4_;
PoolIndexMap_t AuthPoolsIndexV6_;
PoolIndexMap_t AcctPoolsIndexV6_;
struct RadiusPool {
std::vector<Destination> AuthV4;
std::vector<Destination> AuthV6;
std::vector<Destination> AcctV4;
std::vector<Destination> AcctV6;
std::vector<Destination> CoaV4;
std::vector<Destination> CoaV6;
};
std::vector<RadiusPool> Pools_;
uint defaultPoolIndex_=0;
bool enabled_=false;
bool defaultIsRADSEC_=false;
std::atomic_bool running_=false;
typedef std::vector<std::vector<Destination>> PoolIndexVec_t;
PoolIndexVec_t AuthPoolsV4_;
PoolIndexVec_t AuthPoolsV6_;
PoolIndexVec_t AcctPoolsV4_;
PoolIndexVec_t AcctPoolsV6_;
RADIUS_proxy_server() noexcept:
SubSystemServer("RADIUS-PROXY", "RADIUS-PROXY", "radius.proxy")
{
}
static bool SendData( Poco::Net::DatagramSocket & Sock, const unsigned char *buf , std::size_t size, const Poco::Net::SocketAddress &S);
void ParseConfig();
void ResetConfig();
Poco::Net::SocketAddress Route(radius_type rtype, const Poco::Net::SocketAddress &A, const RADIUS::RadiusPacket &P, bool &UseRADSEC);
void ParseServerList(const GWObjects::RadiusProxyServerConfig & Config, std::vector<Destination> &V4, std::vector<Destination> &V6, bool setAsDefault);
static Poco::Net::SocketAddress ChooseAddress(std::vector<Destination> &Pool, const Poco::Net::SocketAddress & OriginalAddress);
Poco::Net::SocketAddress DefaultRoute([[maybe_unused]] radius_type rtype, const Poco::Net::SocketAddress &RequestedAddress, const RADIUS::RadiusPacket &P, bool &UseRADSEC);
Poco::Net::SocketAddress Route(const Poco::Net::SocketAddress &A, PoolIndexVec_t & P, PoolIndexMap_t &M);
void ParseServerList(const GWObjects::RadiusProxyServerConfig & Config, PoolIndexMap_t &MapV4, PoolIndexMap_t &MapV6, PoolIndexVec_t &VecV4, PoolIndexVec_t &VecV6);
};
inline auto RADIUS_proxy_server() { return RADIUS_proxy_server::instance(); }

View File

@@ -1,251 +0,0 @@
//
// Created by stephane bourque on 2022-08-15.
//
#pragma once
#include <iostream>
#include <fstream>
#include "framework/MicroService.h"
#include "RESTObjects/RESTAPI_GWobjects.h"
#include "Poco/Net/SocketReactor.h"
#include "Poco/Net/SecureStreamSocket.h"
#include "Poco/Net/Context.h"
#include "Poco/Crypto/X509Certificate.h"
#include "Poco/Net/NetException.h"
#include "Poco/TemporaryFile.h"
#include "RADIUS_helpers.h"
#include "AP_WS_Server.h"
namespace OpenWifi {
class RADSECserver : public Poco::Runnable {
public:
RADSECserver(Poco::Net::SocketReactor & R, GWObjects::RadiusProxyServerEntry E) :
Reactor_(R),
Server_(std::move(E)),
Logger_(Poco::Logger::get(fmt::format("RADSEC: {}@{}:{}",
Server_.name ,
Server_.ip,
Server_.port)))
{
ReconnectorThr_.start(*this);
}
inline void run() final {
while(TryAgain_) {
if(!Connected_) {
std::unique_lock G(Mutex_);
Connect();
}
Poco::Thread::trySleep(1000);
}
}
inline bool SendData(const std::string &serial_number, const unsigned char *buffer, int length) {
try {
if (Connected_) {
RADIUS::RadiusPacket P(buffer, length);
// std::cout << serial_number << " Sending " << P.PacketType() << " " << length << " bytes" << std::endl;
int sent_bytes;
if (P.VerifyMessageAuthenticator(Server_.radsecSecret)) {
Logger_.debug(fmt::format("{}: {} Sending {} bytes", serial_number,
P.PacketType(), length));
sent_bytes = Socket_->sendBytes(buffer, length);
} else {
Logger_.debug(fmt::format("{}: {} Sending {} bytes", serial_number,
P.PacketType(), length));
P.ComputeMessageAuthenticator(Server_.radsecSecret);
sent_bytes = Socket_->sendBytes(P.Buffer(), length);
}
return (sent_bytes == length);
}
} catch (...) {
}
return false;
}
inline void onData([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf) {
unsigned char Buffer[4096];
try {
auto NumberOfReceivedBytes = Socket_->receiveBytes(Buffer,sizeof(Buffer));
if(NumberOfReceivedBytes>40) {
RADIUS::RadiusPacket P(Buffer,NumberOfReceivedBytes);
// P.Log(std::cout);
// std::cout << "RADSEC: " << P.PacketType() << " " << (int) P.PacketTypeInt() << " Received " << NumberOfReceivedBytes << " bytes" << std::endl;
if (P.IsAuthentication()) {
auto SerialNumber = P.ExtractSerialNumberFromProxyState();
Logger_.debug(fmt::format("{}: {} Received {} bytes.", SerialNumber, P.PacketType(), NumberOfReceivedBytes));
AP_WS_Server()->SendRadiusAuthenticationData(
SerialNumber, Buffer,
NumberOfReceivedBytes);
} else if (P.IsAccounting()) {
auto SerialNumber = P.ExtractSerialNumberFromProxyState();
Logger_.debug(fmt::format("{}: {} Received {} bytes.", SerialNumber, P.PacketType(), NumberOfReceivedBytes));
AP_WS_Server()->SendRadiusAccountingData(
SerialNumber, Buffer,
NumberOfReceivedBytes);
} else if (P.IsAuthority()) {
}
} else {
Disconnect();
}
} catch (const Poco::Exception &E) {
Logger_.log(E);
Disconnect();
}
}
inline void onError([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ErrorNotification>& pNf) {
std::cout << "onError" << std::endl;
Disconnect();
}
inline void onShutdown([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf) {
std::cout << "onShutdown" << std::endl;
Disconnect();
}
inline bool Connect() {
if(TryAgain_) {
Poco::TemporaryFile CertFile_(MicroService::instance().DataDir());
Poco::TemporaryFile KeyFile_(MicroService::instance().DataDir());
std::vector<Poco::TemporaryFile> CaCertFiles_;
DecodeFile(CertFile_.path(), Server_.radsecCert);
DecodeFile(KeyFile_.path(), Server_.radsecKey);
for(auto &cert:Server_.radsecCacerts) {
CaCertFiles_.emplace_back(Poco::TemporaryFile(MicroService::instance().DataDir()));
DecodeFile(CaCertFiles_[CaCertFiles_.size()-1].path(), cert);
}
Poco::Net::Context::Ptr SecureContext = Poco::AutoPtr<Poco::Net::Context>(
new Poco::Net::Context(Poco::Net::Context::TLS_CLIENT_USE,
KeyFile_.path(),
CertFile_.path(),""));
for(const auto &ca:CaCertFiles_) {
Poco::Crypto::X509Certificate cert(ca.path());
SecureContext->addCertificateAuthority(cert);
}
Socket_ = std::make_unique<Poco::Net::SecureStreamSocket>(SecureContext);
Poco::Net::SocketAddress Destination(Server_.ip, Server_.port);
try {
poco_information(Logger_, "Attempting to connect");
Socket_->connect(Destination, Poco::Timespan(100, 0));
Socket_->completeHandshake();
Socket_->verifyPeerCertificate();
if(Socket_->havePeerCertificate()) {
Peer_Cert_ = std::make_unique<Poco::Crypto::X509Certificate>(Socket_->peerCertificate());
}
Socket_->setBlocking(false);
Socket_->setNoDelay(true);
Socket_->setKeepAlive(true);
Reactor_.addEventHandler(
*Socket_,
Poco::NObserver<RADSECserver, Poco::Net::ReadableNotification>(
*this, &RADSECserver::onData));
Reactor_.addEventHandler(
*Socket_, Poco::NObserver<RADSECserver, Poco::Net::ErrorNotification>(
*this, &RADSECserver::onError));
Reactor_.addEventHandler(
*Socket_,
Poco::NObserver<RADSECserver, Poco::Net::ShutdownNotification>(
*this, &RADSECserver::onShutdown));
Socket_->setBlocking(false);
Socket_->setNoDelay(true);
Socket_->setKeepAlive(true);
Connected_ = true;
poco_information(Logger_,fmt::format("Connected. CN={}",CommonName()));
return true;
} catch (const Poco::Net::NetException &E) {
poco_information(Logger_,"Could not connect.");
Logger_.log(E);
} catch (const Poco::Exception &E) {
poco_information(Logger_,"Could not connect.");
Logger_.log(E);
} catch (...) {
poco_information(Logger_,"Could not connect.");
}
}
return false;
}
inline void Disconnect() {
if(Connected_) {
std::unique_lock G(Mutex_);
Reactor_.removeEventHandler(
*Socket_, Poco::NObserver<RADSECserver, Poco::Net::ReadableNotification>(
*this, &RADSECserver::onData));
Reactor_.removeEventHandler(
*Socket_, Poco::NObserver<RADSECserver, Poco::Net::ErrorNotification>(
*this, &RADSECserver::onError));
Reactor_.removeEventHandler(
*Socket_, Poco::NObserver<RADSECserver, Poco::Net::ShutdownNotification>(
*this, &RADSECserver::onShutdown));
Connected_ = false;
}
poco_information(Logger_,"Disconnecting.");
}
inline void Stop() {
TryAgain_ = false;
Disconnect();
ReconnectorThr_.wakeUp();
ReconnectorThr_.join();
}
static void DecodeFile(const std::string &filename, const std::string &s) {
std::ofstream sec_file(filename,std::ios_base::out|std::ios_base::trunc|std::ios_base::binary);
std::stringstream is(s);
Poco::Base64Decoder ds(is);
Poco::StreamCopier::copyStream(ds,sec_file);
sec_file.close();
}
[[nodiscard]] inline std::string CommonName() {
if(Peer_Cert_)
return Peer_Cert_->commonName();
return "";
}
[[nodiscard]] inline std::string IssuerName() {
if(Peer_Cert_)
return Peer_Cert_->issuerName();
return "";
}
[[nodiscard]] inline std::string SubjectName() {
if(Peer_Cert_)
return Peer_Cert_->subjectName();
return "";
}
private:
std::shared_mutex Mutex_;
Poco::Net::SocketReactor &Reactor_;
GWObjects::RadiusProxyServerEntry Server_;
Poco::Logger &Logger_;
std::atomic_bool Connected_=false;
std::atomic_bool TryAgain_=true;
std::unique_ptr<Poco::Net::SecureStreamSocket> Socket_;
Poco::Thread ReconnectorThr_;
std::unique_ptr<Poco::Crypto::X509Certificate> Peer_Cert_;
};
}

View File

@@ -8,7 +8,7 @@
#include "RESTAPI_RPC.h"
#include "CommandManager.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
#include "StorageService.h"
#include "framework/ow_constants.h"
#include "ParseWifiScan.h"
@@ -23,17 +23,12 @@ namespace OpenWifi::RESTAPI_RPC {
if (StorageService()->AddCommand(Cmd.SerialNumber, Cmd, Status)) {
Poco::JSON::Object RetObj;
Cmd.to_json(RetObj);
if(Handler!= nullptr)
return Handler->ReturnObject(RetObj);
return;
return Handler->ReturnObject(RetObj);
}
if(Handler!= nullptr)
return Handler->ReturnStatus(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
return Handler->ReturnStatus(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
}
void WaitForCommand(uint64_t RPCID,
bool RetryLater,
GWObjects::CommandDetails &Cmd,
void WaitForCommand(GWObjects::CommandDetails &Cmd,
Poco::JSON::Object & Params,
Poco::Net::HTTPServerRequest &Request,
Poco::Net::HTTPServerResponse &Response,
@@ -42,19 +37,12 @@ namespace OpenWifi::RESTAPI_RPC {
RESTAPIHandler * Handler,
Poco::Logger &Logger) {
Logger.information(fmt::format("{},{}: New {} command. User={} Serial={}. ", Cmd.UUID, RPCID, Cmd.Command, Cmd.SubmittedBy, Cmd.SerialNumber));
// if the command should be executed in the future, or if the device is not connected,
// then we should just add the command to
// the DB and let it figure out when to deliver the command.
auto SerialNumberInt = Utils::SerialNumberToInt(Cmd.SerialNumber);
if (Cmd.RunAt || (!AP_WS_Server()->Connected(SerialNumberInt) && RetryLater)) {
Logger.information(fmt::format("{},{}: Command will be run in the future or when device is connected again.", Cmd.UUID, RPCID));
SetCommandStatus(Cmd, Request, Response, Handler, Storage::CommandExecutionType::COMMAND_PENDING, Logger);
if (Cmd.RunAt || !DeviceRegistry()->Connected(Cmd.SerialNumber)) {
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_PENDING, Logger);
return;
} else if ((!AP_WS_Server()->Connected(SerialNumberInt) && !RetryLater)){
Logger.information(fmt::format("{},{}: Command canceled. Device is not connected. Command will not be retried.", Cmd.UUID, RPCID));
return SetCommandStatus(Cmd, Request, Response, Handler, Storage::CommandExecutionType::COMMAND_FAILED, Logger);
}
Cmd.Executed = OpenWifi::Now();
@@ -62,98 +50,100 @@ namespace OpenWifi::RESTAPI_RPC {
bool Sent;
std::chrono::time_point<std::chrono::high_resolution_clock> rpc_submitted = std::chrono::high_resolution_clock::now();
std::shared_ptr<CommandManager::promise_type_t> rpc_endpoint =
CommandManager()->PostCommand(RPCID, Cmd.SerialNumber, Cmd.Command, Params, Cmd.UUID, Sent);
CommandManager()->PostCommand(Cmd.SerialNumber, Cmd.Command, Params, Cmd.UUID, Sent);
if(RetryLater && (!Sent || rpc_endpoint== nullptr)) {
Logger.information(fmt::format("{},{}: Pending completion. Device is not connected.", Cmd.UUID, RPCID));
return SetCommandStatus(Cmd, Request, Response, Handler, Storage::CommandExecutionType::COMMAND_PENDING, Logger);
}
Logger.information(fmt::format("{}: user={} serial={}. Sent RPC request.", Cmd.Command, Cmd.SubmittedBy, Cmd.SerialNumber));
if(!RetryLater && !Sent) {
Logger.information(fmt::format("{},{}: Command canceled. Device is not connected. Command will not be retried.", Cmd.UUID, RPCID));
return SetCommandStatus(Cmd, Request, Response, Handler, Storage::CommandExecutionType::COMMAND_FAILED, Logger);
}
Poco::JSON::Object L;
Logger.information(fmt::format("{},{}: Command sent.", Cmd.UUID, RPCID));
std::future<CommandManager::objtype_t> rpc_future(rpc_endpoint->get_future());
auto rpc_result = rpc_future.wait_for(WaitTimeInMs);
if (rpc_result == std::future_status::ready) {
std::chrono::duration<double, std::milli> rpc_execution_time = std::chrono::high_resolution_clock::now() - rpc_submitted;
auto rpc_answer = rpc_future.get();
if (!rpc_answer.has(uCentralProtocol::RESULT) || !rpc_answer.isObject(uCentralProtocol::RESULT)) {
SetCommandStatus(Cmd, Request, Response, Handler, Storage::CommandExecutionType::COMMAND_FAILED, Logger);
Logger.information(fmt::format("{},{}: Invalid response. Missing result.", Cmd.UUID, RPCID));
return;
}
if (Sent && rpc_endpoint!= nullptr) {
std::future<CommandManager::objtype_t> rpc_future(rpc_endpoint->get_future());
auto rpc_result = rpc_future.wait_for(WaitTimeInMs);
if (rpc_result == std::future_status::ready) {
std::chrono::duration<double, std::milli> rpc_execution_time = std::chrono::high_resolution_clock::now() - rpc_submitted;
auto rpc_answer = rpc_future.get();
if (rpc_answer.has(uCentralProtocol::RESULT) && rpc_answer.isObject(uCentralProtocol::RESULT)) {
auto ResultFields =
rpc_answer.get(uCentralProtocol::RESULT).extract<Poco::JSON::Object::Ptr>();
if (ResultFields->has(uCentralProtocol::STATUS) && ResultFields->isObject(uCentralProtocol::STATUS)) {
auto StatusInnerObj =
ResultFields->get(uCentralProtocol::STATUS).extract<Poco::JSON::Object::Ptr>();
if (StatusInnerObj->has(uCentralProtocol::ERROR))
Cmd.ErrorCode = StatusInnerObj->get(uCentralProtocol::ERROR);
if (StatusInnerObj->has(uCentralProtocol::TEXT))
Cmd.ErrorText = StatusInnerObj->get(uCentralProtocol::TEXT).toString();
std::stringstream ResultText;
if(rpc_answer.has(uCentralProtocol::RESULT)) {
if(Cmd.Command==uCentralProtocol::WIFISCAN) {
auto ScanObj = rpc_answer.get(uCentralProtocol::RESULT).extract<Poco::JSON::Object::Ptr>();
ParseWifiScan(ScanObj, ResultText, Logger);
} else {
Poco::JSON::Stringifier::stringify(
rpc_answer.get(uCentralProtocol::RESULT), ResultText);
}
} if (rpc_answer.has(uCentralProtocol::RESULT_64)) {
uint64_t sz=0;
if(rpc_answer.has(uCentralProtocol::RESULT_SZ))
sz=rpc_answer.get(uCentralProtocol::RESULT_SZ);
std::string UnCompressedData;
Utils::ExtractBase64CompressedData(rpc_answer.get(uCentralProtocol::RESULT_64).toString(),
UnCompressedData,sz);
Poco::JSON::Stringifier::stringify(UnCompressedData, ResultText);
}
Cmd.Results = ResultText.str();
Cmd.Status = "completed";
Cmd.Completed = OpenWifi::Now();
Cmd.executionTime = rpc_execution_time.count();
auto ResultFields = rpc_answer.get(uCentralProtocol::RESULT).extract<Poco::JSON::Object::Ptr>();
if (!ResultFields->has(uCentralProtocol::STATUS) || !ResultFields->isObject(uCentralProtocol::STATUS)) {
Cmd.executionTime = rpc_execution_time.count();
if(Cmd.Command=="ping") {
SetCommandStatus(Cmd, Request, Response, Handler, Storage::CommandExecutionType::COMMAND_COMPLETED, Logger);
Logger.information(fmt::format("{},{}: Invalid response from device (ping: fix override). Missing status.", Cmd.UUID, RPCID));
if (Cmd.ErrorCode && Cmd.Command == uCentralProtocol::TRACE) {
Cmd.WaitingForFile = 0;
Cmd.AttachDate = Cmd.AttachSize = 0;
Cmd.AttachType = "";
}
// Add the completed command to the database...
StorageService()->AddCommand(Cmd.SerialNumber, Cmd, Storage::COMMAND_COMPLETED);
if (ObjectToReturn) {
Handler->ReturnObject(*ObjectToReturn);
} else {
Poco::JSON::Object O;
Cmd.to_json(O);
Handler->ReturnObject(O);
}
Logger.information( fmt::format("Command({}): completed in {:.3f}ms.", Cmd.UUID, Cmd.executionTime));
return;
} else {
SetCommandStatus(Cmd, Request, Response, Handler,
Storage::COMMAND_FAILED, Logger);
Logger.information(fmt::format(
"Invalid response for command '{}'. Missing status.", Cmd.UUID));
return;
}
} else {
SetCommandStatus(Cmd, Request, Response, Handler, Storage::CommandExecutionType::COMMAND_FAILED, Logger);
Logger.information(fmt::format("{},{}: Invalid response from device. Missing status.", Cmd.UUID,RPCID));
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_FAILED,
Logger);
Logger.information(fmt::format(
"Invalid response for command '{}'. Missing status.", Cmd.UUID));
return;
}
} else if (rpc_result == std::future_status::timeout) {
Logger.information(fmt::format(
"Timeout2 for command '{}'.", Cmd.UUID));
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_TIMEDOUT,
Logger);
return;
}
auto StatusInnerObj = ResultFields->get(uCentralProtocol::STATUS).extract<Poco::JSON::Object::Ptr>();
if (StatusInnerObj->has(uCentralProtocol::ERROR))
Cmd.ErrorCode = StatusInnerObj->get(uCentralProtocol::ERROR);
if (StatusInnerObj->has(uCentralProtocol::TEXT))
Cmd.ErrorText = StatusInnerObj->get(uCentralProtocol::TEXT).toString();
std::stringstream ResultText;
if(rpc_answer.has(uCentralProtocol::RESULT)) {
if(Cmd.Command==uCentralProtocol::WIFISCAN) {
auto ScanObj = rpc_answer.get(uCentralProtocol::RESULT).extract<Poco::JSON::Object::Ptr>();
ParseWifiScan(ScanObj, ResultText, Logger);
} else {
Poco::JSON::Stringifier::stringify(
rpc_answer.get(uCentralProtocol::RESULT), ResultText);
}
} if (rpc_answer.has(uCentralProtocol::RESULT_64)) {
uint64_t sz=0;
if(rpc_answer.has(uCentralProtocol::RESULT_SZ))
sz=rpc_answer.get(uCentralProtocol::RESULT_SZ);
std::string UnCompressedData;
Utils::ExtractBase64CompressedData(rpc_answer.get(uCentralProtocol::RESULT_64).toString(),
UnCompressedData,sz);
Poco::JSON::Stringifier::stringify(UnCompressedData, ResultText);
}
Cmd.Results = ResultText.str();
Cmd.Status = "completed";
Cmd.Completed = OpenWifi::Now();
Cmd.executionTime = rpc_execution_time.count();
if (Cmd.ErrorCode && Cmd.Command == uCentralProtocol::TRACE) {
Cmd.WaitingForFile = 0;
Cmd.AttachDate = Cmd.AttachSize = 0;
Cmd.AttachType = "";
}
// Add the completed command to the database...
StorageService()->AddCommand(Cmd.SerialNumber, Cmd, Storage::CommandExecutionType::COMMAND_COMPLETED);
if (ObjectToReturn && Handler) {
Handler->ReturnObject(*ObjectToReturn);
} else {
Poco::JSON::Object O;
Cmd.to_json(O);
if(Handler)
Handler->ReturnObject(O);
Logger.information(fmt::format(
"Pending completion for command '{}'.", Cmd.UUID));
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_PENDING, Logger);
return;
}
Logger.information( fmt::format("{},{}: Completed in {:.3f}ms.", Cmd.UUID, RPCID, Cmd.executionTime));
return;
}
CommandManager()->RemovePendingCommand(RPCID);
if(RetryLater) {
Logger.information(fmt::format("{},{}: Pending completion.", Cmd.UUID, RPCID));
SetCommandStatus(Cmd, Request, Response, Handler, Storage::CommandExecutionType::COMMAND_PENDING, Logger);
} else {
Logger.information(fmt::format("{},{}: Command canceled. Device is not connected. Command will not be retried.", Cmd.UUID, RPCID));
return SetCommandStatus(Cmd, Request, Response, Handler, Storage::CommandExecutionType::COMMAND_FAILED, Logger);
Logger.information(fmt::format(
"Pending completion for command '{}'.", Cmd.UUID));
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_PENDING, Logger);
return;
}
}
}

View File

@@ -20,17 +20,14 @@
namespace OpenWifi::RESTAPI_RPC {
void WaitForCommand(
uint64_t RPCID,
bool RetryLater,
GWObjects::CommandDetails &Cmd,
Poco::JSON::Object & Params,
Poco::Net::HTTPServerRequest &Request,
Poco::Net::HTTPServerResponse &Response,
std::chrono::milliseconds WaitTimeInMs,
Poco::JSON::Object * ObjectToReturn,
RESTAPIHandler * Handler,
Poco::Logger &Logger);
void WaitForCommand( GWObjects::CommandDetails &Cmd,
Poco::JSON::Object & Params,
Poco::Net::HTTPServerRequest &Request,
Poco::Net::HTTPServerResponse &Response,
std::chrono::milliseconds WaitTimeInMs,
Poco::JSON::Object * ObjectToReturn,
RESTAPIHandler * Handler,
Poco::Logger &Logger);
void SetCommandStatus( GWObjects::CommandDetails &Cmd,
Poco::Net::HTTPServerRequest &Request,

View File

@@ -18,7 +18,7 @@ namespace OpenWifi {
void RESTAPI_blacklist::DoDelete() {
auto SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
if(!Utils::NormalizeMac(SerialNumber)) {
if(SerialNumber.empty()) {
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
}
@@ -36,7 +36,7 @@ namespace OpenWifi {
void RESTAPI_blacklist::DoGet() {
auto SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
if(!Utils::NormalizeMac(SerialNumber)) {
if(SerialNumber.empty()) {
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
}
@@ -51,14 +51,13 @@ namespace OpenWifi {
}
void RESTAPI_blacklist::DoPost() {
const auto &Obj = ParsedBody_;
GWObjects::BlackListedDevice D;
if(!D.from_json(Obj)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if(D.serialNumber.empty() || !Utils::NormalizeMac(D.serialNumber)) {
if(D.serialNumber.empty()) {
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
}
@@ -84,7 +83,7 @@ namespace OpenWifi {
void RESTAPI_blacklist::DoPut() {
auto SerialNumber = Poco::toLower(GetBinding(RESTAPI::Protocol::SERIALNUMBER, ""));
if(!Utils::NormalizeMac(SerialNumber)) {
if(SerialNumber.empty()) {
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
}

View File

@@ -13,10 +13,6 @@
namespace OpenWifi {
void RESTAPI_commands::DoGet() {
auto SerialNumber = GetParameter(RESTAPI::Protocol::SERIALNUMBER, "");
if(!Utils::NormalizeMac(SerialNumber)) {
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
}
std::vector<GWObjects::CommandDetails> Commands;
if (QB_.Newest) {
StorageService()->GetNewestCommands(SerialNumber, QB_.Limit, Commands);
@@ -37,10 +33,10 @@ namespace OpenWifi {
void RESTAPI_commands::DoDelete() {
auto SerialNumber = GetParameter(RESTAPI::Protocol::SERIALNUMBER, "");
if(!Utils::NormalizeMac(SerialNumber)) {
if(SerialNumber.empty()) {
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
}
if (StorageService()->DeleteCommands(SerialNumber, QB_.StartDate, QB_.EndDate)) {
return OK();
}

View File

@@ -14,11 +14,10 @@
#include "StorageService.h"
#include "framework/ow_constants.h"
#include "framework/ConfigurationValidator.h"
#include "framework/orm.h"
namespace OpenWifi {
void RESTAPI_default_configuration::DoGet() {
std::string Name = ORM::Escape(GetBinding(RESTAPI::Protocol::NAME, ""));
std::string Name = GetBinding(RESTAPI::Protocol::NAME, "");
GWObjects::DefaultConfiguration DefConfig;
if (StorageService()->GetDefaultConfiguration(Name, DefConfig)) {
Poco::JSON::Object Obj;
@@ -29,7 +28,7 @@ namespace OpenWifi {
}
void RESTAPI_default_configuration::DoDelete() {
std::string Name = ORM::Escape(GetBinding(RESTAPI::Protocol::NAME, ""));
std::string Name = GetBinding(RESTAPI::Protocol::NAME, "");
if(Name.empty()) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,6 @@
#pragma once
#include "framework/MicroService.h"
#include "framework/ow_constants.h"
namespace OpenWifi {
class RESTAPI_device_commandHandler : public RESTAPIHandler {
@@ -31,22 +30,22 @@ namespace OpenWifi {
void GetStatistics();
void DeleteStatistics();
void GetStatus();
void ExecuteCommand();
void Configure();
void GetChecks();
void DeleteChecks();
void ExecuteCommand(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void Configure(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void Upgrade(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void Reboot(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void Factory(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void LEDs(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void Trace(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void MakeRequest(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void WifiScan(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void EventQueue(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void Rtty(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void Telemetry(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void Ping(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void Script(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout);
void Upgrade();
void Reboot();
void Factory();
void LEDs();
void Trace();
void MakeRequest();
void WifiScan();
void EventQueue();
void Rtty();
void Telemetry();
void Ping();
void Script();
static auto PathName() { return std::list<std::string>{"/api/v1/device/{serialNumber}/{command}"}; };
void DoGet() final;
@@ -54,9 +53,6 @@ namespace OpenWifi {
void DoPost() final;
void DoPut() final {};
void CallCanceled(const char * Cmd,const std::string &UUID, uint64_t RPC, const OpenWifi::RESTAPI::Errors::msg & Err);
void CallCanceled(const char * Cmd, const OpenWifi::RESTAPI::Errors::msg &Err, const std::string & Details="");
inline bool ValidateParameters() {
Command_ = GetBinding(RESTAPI::Protocol::COMMAND, "");
if (Command_.empty()) {
@@ -70,8 +66,6 @@ namespace OpenWifi {
}
private:
std::string SerialNumber_,
Command_;
std::uint64_t SerialNumberInt_=0;
std::string SerialNumber_, Command_;
};
}

View File

@@ -20,7 +20,7 @@ namespace OpenWifi {
void RESTAPI_device_handler::DoGet() {
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
if(!Utils::NormalizeMac(SerialNumber)) {
if(SerialNumber.empty()) {
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
}
@@ -42,7 +42,7 @@ namespace OpenWifi {
void RESTAPI_device_handler::DoDelete() {
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
if(!Utils::NormalizeMac(SerialNumber)) {
if(SerialNumber.empty()) {
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
}
@@ -86,7 +86,7 @@ namespace OpenWifi {
void RESTAPI_device_handler::DoPost() {
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
if(!Utils::NormalizeMac(SerialNumber)) {
if(SerialNumber.empty()) {
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
}
@@ -116,10 +116,6 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if(!Utils::NormalizeMac(Device.SerialNumber)) {
return BadRequest( RESTAPI::Errors::InvalidSerialNumber);
}
if(SerialNumber!=Device.SerialNumber) {
return BadRequest(RESTAPI::Errors::SerialNumberMismatch);
}
@@ -153,7 +149,7 @@ namespace OpenWifi {
void RESTAPI_device_handler::DoPut() {
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
if(!Utils::ValidSerialNumber(SerialNumber)) {
if(SerialNumber.empty()) {
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
}

View File

@@ -6,17 +6,17 @@
#include "RESTObjects/RESTAPI_GWobjects.h"
#include "StorageService.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
namespace OpenWifi {
inline void CompleteDeviceInfo(const GWObjects::Device & Device, Poco::JSON::Object & Answer) {
GWObjects::ConnectionState CS;
AP_WS_Server()->GetState(Device.SerialNumber,CS);
DeviceRegistry()->GetState(Device.SerialNumber,CS);
GWObjects::HealthCheck HC;
AP_WS_Server()->GetHealthcheck(Device.SerialNumber, HC);
DeviceRegistry()->GetHealthcheck(Device.SerialNumber, HC);
std::string Stats;
AP_WS_Server()->GetStatistics(Device.SerialNumber, Stats);
DeviceRegistry()->GetStatistics(Device.SerialNumber, Stats);
Poco::JSON::Object DeviceInfo;
Device.to_json(DeviceInfo);

View File

@@ -15,14 +15,11 @@
#include "framework/MicroService.h"
#include "RESTAPI/RESTAPI_device_helper.h"
#include "Poco/StringTokenizer.h"
#include "framework/orm.h"
#include "AP_WS_Server.h"
namespace OpenWifi {
bool PrepareOrderBy(const std::string &OrderByListRaw, std::string &OrderByString) {
auto OrderByList = ORM::Escape(OrderByListRaw);
bool PrepareOrderBy(const std::string &OrderByList, std::string &OrderByString) {
auto items = Poco::StringTokenizer(OrderByList,",");
std::string ItemList;
@@ -58,15 +55,6 @@ namespace OpenWifi {
void RESTAPI_devices_handler::DoGet() {
if(GetBoolParameter("connectionStatistics")) {
GWObjects::DeviceConnectionStatistics DCS;
Poco::JSON::Object Answer;
AP_WS_Server()->AverageDeviceStatistics(DCS.connectedDevices,DCS.averageConnectionTime, DCS.connectingDevices);
DCS.to_json(Answer);
return ReturnObject(Answer);
}
if(GetBoolParameter("orderSpec")) {
Types::StringVec Fields;
StorageService()->GetDeviceDbFieldList(Fields);
@@ -92,8 +80,6 @@ namespace OpenWifi {
Poco::JSON::Array Objects;
for (auto &i : SelectedRecords()) {
auto SerialNumber = i;
if(!Utils::ValidSerialNumber(i))
continue;
GWObjects::Device D;
if (StorageService()->GetDevice(SerialNumber, D)) {
if(completeInfo) {

View File

@@ -31,7 +31,7 @@ namespace OpenWifi {
}
GWObjects::RadiusProxyPoolList C;
if(!C.from_json(ParsedBody_) || C.pools.empty()) {
if(!C.from_json(ParsedBody_)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
@@ -40,7 +40,7 @@ namespace OpenWifi {
if(pool.name.empty()) {
return BadRequest(RESTAPI::Errors::PoolNameInvalid);
}
for(const auto &config:{pool.acctConfig,pool.authConfig,pool.coaConfig}) {
for(const auto &config:{pool.acctConfig,pool.authConfig}) {
if(config.strategy!="random" && config.strategy!="round_robin" && config.strategy!="weighted") {
return BadRequest(RESTAPI::Errors::InvalidRadiusProxyStrategy);
}

View File

@@ -26,6 +26,7 @@ namespace OpenWifi {
Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const std::string &Path, RESTAPIHandler::BindingMap &Bindings,
Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) {
Poco::Thread::current()->setName("ExtWebServerThread_" + std::to_string(TransactionId));
return RESTAPI_Router<
RESTAPI_devices_handler,
RESTAPI_device_handler,
@@ -49,6 +50,7 @@ namespace OpenWifi {
Poco::Net::HTTPRequestHandler * RESTAPI_IntRouter(const std::string &Path, RESTAPIHandler::BindingMap &Bindings,
Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) {
Poco::Thread::current()->setName("IntWebServerThread_" + std::to_string(TransactionId));
return RESTAPI_Router_I<
RESTAPI_devices_handler,
RESTAPI_device_handler,

View File

@@ -11,6 +11,7 @@ namespace OpenWifi {
void RESTAPI_telemetryWebSocket::DoGet() {
// try and upgrade this session to websocket...
Poco::Thread::current()->setName(fmt::format("TELEMETRY-WS({})",UserInfo_.userinfo.email));
if (Request->find("Upgrade") != Request->end() &&
Poco::icompare((*Request)["Upgrade"], "websocket") == 0) {
try {
@@ -25,10 +26,6 @@ void RESTAPI_telemetryWebSocket::DoGet() {
}
}
if(!Utils::NormalizeMac(SNum)) {
return BadRequest(RESTAPI::Errors::InvalidSerialNumber);
}
auto SerialNumber = Utils::SerialNumberToInt(SNum);
if(!TelemetryStream()->IsValidEndPoint(SerialNumber,UUID)) {

View File

@@ -11,7 +11,7 @@
#include "Daemon.h"
#ifdef TIP_GATEWAY_SERVICE
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
#include "CapabilitiesCache.h"
#endif
@@ -57,7 +57,7 @@ namespace OpenWifi::GWObjects {
#ifdef TIP_GATEWAY_SERVICE
ConnectionState ConState;
if (AP_WS_Server()->GetState(SerialNumber, ConState)) {
if (DeviceRegistry()->GetState(SerialNumber, ConState)) {
ConState.to_json(Obj);
} else {
field_to_json(Obj,"ipAddress", "");
@@ -203,10 +203,6 @@ namespace OpenWifi::GWObjects {
field_to_json(Obj,"kafkaClients", kafkaClients);
field_to_json(Obj,"kafkaPackets", kafkaPackets);
field_to_json(Obj,"locale", locale);
field_to_json(Obj,"started", started);
field_to_json(Obj,"sessionId", sessionId);
field_to_json(Obj,"connectionCompletionTime", connectionCompletionTime);
field_to_json(Obj,"totalConnectionTime", OpenWifi::Now() - started);
switch(VerifiedCertificate) {
case NO_CERTIFICATE:
@@ -222,23 +218,6 @@ namespace OpenWifi::GWObjects {
}
}
void DeviceConnectionStatistics::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj,"averageConnectionTime", averageConnectionTime);
field_to_json(Obj,"connectedDevices", connectedDevices );
field_to_json(Obj,"connectingDevices", connectingDevices );
}
bool DeviceConnectionStatistics::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj,"averageConnectionTime", averageConnectionTime);
field_from_json(Obj,"connectedDevices", connectedDevices );
field_from_json(Obj,"connectingDevices", connectingDevices );
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
void RttySessionDetails::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj,"serialNumber", SerialNumber);
field_to_json(Obj,"server", Server);
@@ -314,6 +293,7 @@ namespace OpenWifi::GWObjects {
} catch (const Poco::Exception &E) {
}
return false;
}
void RadiusProxyPoolList::to_json(Poco::JSON::Object &Obj) const {
@@ -334,8 +314,6 @@ namespace OpenWifi::GWObjects {
field_to_json(Obj,"description",description);
field_to_json(Obj,"authConfig",authConfig);
field_to_json(Obj,"acctConfig",acctConfig);
field_to_json(Obj,"coaConfig",coaConfig);
field_to_json(Obj,"useByDefault",useByDefault);
}
bool RadiusProxyPool::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -344,8 +322,6 @@ namespace OpenWifi::GWObjects {
field_from_json(Obj,"description",description);
field_from_json(Obj,"authConfig",authConfig);
field_from_json(Obj,"acctConfig",acctConfig);
field_from_json(Obj,"coaConfig",coaConfig);
field_from_json(Obj,"useByDefault",useByDefault);
return true;
} catch (const Poco::Exception &E) {
}
@@ -353,7 +329,7 @@ namespace OpenWifi::GWObjects {
}
void RadiusProxyServerConfig::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj,"strategy",strategy);
field_to_json(Obj,"policy",strategy);
field_to_json(Obj,"monitor",monitor);
field_to_json(Obj,"monitorMethod",monitorMethod);
field_to_json(Obj,"methodParameters",methodParameters);
@@ -362,7 +338,7 @@ namespace OpenWifi::GWObjects {
bool RadiusProxyServerConfig::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj,"strategy",strategy);
field_from_json(Obj,"policy",strategy);
field_from_json(Obj,"monitor",monitor);
field_from_json(Obj,"monitorMethod",monitorMethod);
field_from_json(Obj,"methodParameters",methodParameters);
@@ -378,16 +354,6 @@ namespace OpenWifi::GWObjects {
field_to_json(Obj,"ip",ip);
field_to_json(Obj,"port",port);
field_to_json(Obj,"weight",weight);
field_to_json(Obj,"secret",secret);
field_to_json(Obj,"certificate",certificate);
field_to_json(Obj,"radsec",radsec);
field_to_json(Obj,"radsecPort",radsecPort);
field_to_json(Obj,"radsecSecret",radsecSecret);
field_to_json(Obj,"radsecCacerts",radsecCacerts);
field_to_json(Obj,"radsecCert",radsecCert);
field_to_json(Obj,"radsecKey",radsecKey);
field_to_json(Obj,"radsecRealms",radsecRealms);
field_to_json(Obj,"ignore",ignore);
}
bool RadiusProxyServerEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -396,16 +362,6 @@ namespace OpenWifi::GWObjects {
field_from_json(Obj,"ip",ip);
field_from_json(Obj,"port",port);
field_from_json(Obj,"weight",weight);
field_from_json(Obj,"secret",secret);
field_from_json(Obj,"certificate",certificate);
field_from_json(Obj,"radsec",radsec);
field_from_json(Obj,"radsecSecret",radsecSecret);
field_from_json(Obj,"radsecPort",radsecPort);
field_from_json(Obj,"radsecCacerts",radsecCacerts);
field_from_json(Obj,"radsecCert",radsecCert);
field_from_json(Obj,"radsecKey",radsecKey);
field_from_json(Obj,"radsecRealms",radsecRealms);
field_from_json(Obj,"ignore",ignore);
return true;
} catch (const Poco::Exception &E) {
}

View File

@@ -38,10 +38,6 @@ namespace OpenWifi::GWObjects {
uint64_t kafkaPackets=0;
uint64_t websocketPackets=0;
std::string locale;
uint64_t started=0;
uint64_t sessionId=0;
double connectionCompletionTime=0.0;
void to_json(Poco::JSON::Object &Obj) const;
};
@@ -75,15 +71,6 @@ namespace OpenWifi::GWObjects {
void Print() const;
};
struct DeviceConnectionStatistics {
std::uint64_t connectedDevices = 0;
std::uint64_t averageConnectionTime = 0;
std::uint64_t connectingDevices = 0;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct Statistics {
std::string SerialNumber;
uint64_t UUID = 0 ;
@@ -229,16 +216,6 @@ namespace OpenWifi::GWObjects {
std::string ip;
uint16_t port=0;
uint64_t weight=0;
std::string secret;
std::string certificate;
bool radsec=false;
uint16_t radsecPort=2083;
std::string radsecSecret;
std::string radsecKey;
std::string radsecCert;
std::vector<std::string> radsecCacerts;
std::vector<std::string> radsecRealms;
bool ignore=false;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
@@ -260,8 +237,6 @@ namespace OpenWifi::GWObjects {
std::string description;
RadiusProxyServerConfig authConfig;
RadiusProxyServerConfig acctConfig;
RadiusProxyServerConfig coaConfig;
bool useByDefault=false;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);

View File

@@ -2,24 +2,20 @@
// Created by stephane bourque on 2021-08-11.
//
#include "SerialNumberCache.h"
#include <mutex>
#include "SerialNumberCache.h"
#include "StorageService.h"
namespace OpenWifi {
int SerialNumberCache::Start() {
poco_notice(Logger(),"Starting...");
StorageService()->UpdateSerialNumberCache();
return 0;
}
void SerialNumberCache::Stop() {
poco_notice(Logger(),"Stopping...");
SNs_.clear();
Reverse_SNs_.clear();
poco_notice(Logger(),"Stopped...");
}
void SerialNumberCache::AddSerialNumber(const std::string &S) {

View File

@@ -4,35 +4,33 @@
#include <fstream>
#include "framework/MicroService.h"
#include "StorageArchiver.h"
#include "StorageService.h"
#include "framework/MicroService.h"
namespace OpenWifi {
void Archiver::onTimer([[maybe_unused]] Poco::Timer &timer){
Utils::SetThreadName("strg-archiver");
auto now = OpenWifi::Now();
for(const auto &i:DBs_) {
if (!Poco::icompare(i.DBName, "healthchecks")) {
poco_information(Logger(),"Archiving HealthChecks...");
Logger().information("Archiving HealthChecks...");
StorageService()->RemoveHealthChecksRecordsOlderThan(
now - (i.HowManyDays * 24 * 60 * 60));
} else if (!Poco::icompare(i.DBName, "statistics")) {
poco_information(Logger(),"Archiving Statistics...");
Logger().information("Archiving Statistics...");
StorageService()->RemoveStatisticsRecordsOlderThan(
now - (i.HowManyDays * 24 * 60 * 60));
} else if (!Poco::icompare(i.DBName, "devicelogs")) {
poco_information(Logger(),"Archiving Device Logs...");
Logger().information("Archiving Device Logs...");
StorageService()->RemoveDeviceLogsRecordsOlderThan(
now - (i.HowManyDays * 24 * 60 * 60));
} else if (!Poco::icompare(i.DBName, "commandlist")) {
poco_information(Logger(),"Archiving Command History...");
Logger().information("Archiving Command History...");
StorageService()->RemoveCommandListRecordsOlderThan(
now - (i.HowManyDays * 24 * 60 * 60));
} else {
poco_information(Logger(),fmt::format("Cannot archive DB '{}'", i.DBName));
Logger().information(fmt::format("Cannot archive DB '{}'", i.DBName));
}
}
AppServiceRegistry().Set("lastStorageArchiverRun", (uint64_t) Now);
@@ -55,12 +53,11 @@ namespace OpenWifi {
Enabled_ = MicroService::instance().ConfigGetBool("archiver.enabled",false);
if(!Enabled_) {
poco_information(Logger(),"Archiver is disabled.");
Logger().information("Archiver is disabled.");
return 0;
}
Archiver_ = std::make_unique<Archiver>(Logger());
ArchiverCallback_ = std::make_unique<Poco::TimerCallback<Archiver>>(*Archiver_,&Archiver::onTimer);
ArchiverCallback_ = std::make_unique<Poco::TimerCallback<Archiver>>(Archiver_,&Archiver::onTimer);
auto Schedule = MicroService::instance().ConfigGetString("archiver.schedule","03:00");
auto S = Poco::StringTokenizer(Schedule,":");
@@ -82,7 +79,7 @@ namespace OpenWifi {
if(Poco::icompare(DBName,DB)==0) {
std::string Key = "archiver.db." + std::to_string(i) + ".keep";
auto Keep = MicroService::instance().ConfigGetInt(Key,7);
Archiver_->AddDb(Archiver::ArchiverDBEntry{
Archiver_.AddDb(Archiver::ArchiverDBEntry{
.DBName = DB,
.HowManyDays = Keep
});
@@ -93,21 +90,19 @@ namespace OpenWifi {
int NextRun = CalculateDelta(RunAtHour_,RunAtMin_);
poco_information(Logger(),fmt::format("Next run in {} seconds.",NextRun));
Logger().information(fmt::format("Next run in {} seconds.",NextRun));
Timer_.setStartInterval( NextRun * 1000);
Timer_.setPeriodicInterval(24 * 60 * 60 * 1000); // 1 hours
Timer_.start(*ArchiverCallback_, MicroService::instance().TimerPool());
Timer_.start(*ArchiverCallback_);
return 0;
}
void StorageArchiver::Stop() {
poco_information(Logger(),"Stopping...");
if(Enabled_) {
Timer_.stop();
}
poco_information(Logger(),"Stopped...");
}
};

View File

@@ -50,7 +50,7 @@ namespace OpenWifi {
private:
std::atomic_bool Enabled_ = false;
Poco::Timer Timer_;
std::unique_ptr<Archiver> Archiver_;
Archiver Archiver_{Logger()};
std::unique_ptr<Poco::TimerCallback<Archiver>> ArchiverCallback_;
StorageArchiver() noexcept:

View File

@@ -22,9 +22,8 @@ namespace OpenWifi {
void Storage::Stop() {
std::lock_guard Guard(Mutex_);
poco_notice(Logger(),"Stopping...");
Logger().notice("Stopping.");
StorageClass::Stop();
poco_notice(Logger(),"Stopped...");
}
}
// namespace

View File

@@ -19,30 +19,14 @@ namespace OpenWifi {
public:
enum class CommandExecutionType {
enum CommandExecutionType {
COMMAND_PENDING,
COMMAND_EXECUTED,
COMMAND_COMPLETED,
COMMAND_TIMEDOUT,
COMMAND_FAILED,
COMMAND_EXPIRED,
COMMAND_EXECUTING
COMMAND_FAILED
};
inline std::string to_string(const CommandExecutionType &C) {
switch(C) {
case CommandExecutionType::COMMAND_PENDING: return "pending";
case CommandExecutionType::COMMAND_EXECUTED: return "executed";
case CommandExecutionType::COMMAND_COMPLETED: return "completed";
case CommandExecutionType::COMMAND_TIMEDOUT: return "timedout";
case CommandExecutionType::COMMAND_FAILED: return "failed";
case CommandExecutionType::COMMAND_EXPIRED: return "expired";
case CommandExecutionType::COMMAND_EXECUTING:
default:
return "executing";
}
}
[[nodiscard]] inline std::string ComputeRange(uint64_t From, uint64_t HowMany) {
if(dbType_==sqlite) {
return " LIMIT " + std::to_string(From) + ", " + std::to_string(HowMany) + " ";
@@ -141,7 +125,7 @@ namespace OpenWifi {
bool DeleteCommands(std::string &SerialNumber, uint64_t FromDate, uint64_t ToDate);
bool GetNonExecutedCommands( uint64_t Offset, uint64_t HowMany, std::vector<GWObjects::CommandDetails> & Commands );
bool UpdateCommand( std::string &UUID, GWObjects::CommandDetails & Command );
bool GetCommand( const std::string &UUID, GWObjects::CommandDetails & Command );
bool GetCommand( std::string &UUID, GWObjects::CommandDetails & Command );
bool DeleteCommand( std::string &UUID );
bool GetReadyToExecuteCommands( uint64_t Offset, uint64_t HowMany, std::vector<GWObjects::CommandDetails> & Commands );
bool CommandExecuted(std::string & UUID);
@@ -155,10 +139,6 @@ namespace OpenWifi {
bool SetCommandResult(std::string & UUID, std::string & Result);
bool GetNewestCommands(std::string &SerialNumber, uint64_t HowMany, std::vector<GWObjects::CommandDetails> & Commands);
bool SetCommandExecuted(std::string & CommandUUID);
bool SetCommandTimedOut(std::string &CommandUUID);
void RemovedExpiredCommands();
void RemoveTimedOutCommands();
bool RemoveOldCommands(std::string & SerilNumber, std::string & Command);

View File

@@ -3,14 +3,14 @@
//
#include "framework/MicroService.h"
#include "AP_WS_Connection.h"
#include "AP_WS_Server.h"
#include "TelemetryClient.h"
#include "TelemetryStream.h"
#include "CommandManager.h"
#include "Poco/Net/SSLException.h"
#include "TelemetryClient.h"
#include "TelemetryStream.h"
#include "DeviceRegistry.h"
#include "WS_Connection.h"
namespace OpenWifi {
TelemetryClient::TelemetryClient(
@@ -34,8 +34,8 @@ namespace OpenWifi {
}
void TelemetryClient::CompleteStartup() {
std::lock_guard Guard(Mutex_);
try {
std::lock_guard Guard(Mutex_);
Socket_ = *WS_;
CId_ = Utils::FormatIPv6(Socket_.peerAddress().toString());
@@ -46,7 +46,6 @@ namespace OpenWifi {
WS_->setNoDelay(true);
WS_->setKeepAlive(true);
WS_->setMaxPayloadSize(2048);
WS_->setBlocking(false);
Reactor_.addEventHandler(
*WS_, Poco::NObserver<TelemetryClient, Poco::Net::ReadableNotification>(
*this, &TelemetryClient::OnSocketReadable));
@@ -57,7 +56,7 @@ namespace OpenWifi {
*WS_, Poco::NObserver<TelemetryClient, Poco::Net::ErrorNotification>(
*this, &TelemetryClient::OnSocketError));
Registered_ = true;
poco_information(Logger(),fmt::format("TELEMETRY-CONNECTION({}): Connection completed.", CId_));
Logger().information(fmt::format("CONNECTION({}): Connection completed.", CId_));
return;
}
} catch (const Poco::Net::SSLException &E) {
@@ -70,7 +69,7 @@ namespace OpenWifi {
}
TelemetryClient::~TelemetryClient() {
poco_information(Logger(),fmt::format("TELEMETRY-CONNECTION({}): Closing connection.", CId_));
Logger().information(fmt::format("CONNECTION({}): Closing connection.", CId_));
if(Registered_ && WS_)
{
Reactor_.removeEventHandler(*WS_,
@@ -93,26 +92,32 @@ namespace OpenWifi {
}
void TelemetryClient::SendTelemetryShutdown() {
poco_information(Logger(),fmt::format("TELEMETRY-SHUTDOWN({}): Closing.",CId_));
AP_WS_Server()->StopWebSocketTelemetry(CommandManager()->NextRPCId(), SerialNumber_);
Logger().information(fmt::format("TELEMETRY-SHUTDOWN({}): Closing.",CId_));
auto Device = DeviceRegistry()->GetDeviceConnection(SerialNumber_);
if(Device) {
if(Device->WSConn_)
Device->WSConn_->StopWebSocketTelemetry();
}
TelemetryStream()->DeRegisterClient(UUID_);
delete this;
}
void TelemetryClient::OnSocketShutdown([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf) {
poco_information(Logger(),fmt::format("TELEMETRY-SOCKET-SHUTDOWN({}): Orderly shutdown.", CId_));
std::lock_guard Guard(Mutex_);
Logger().information(fmt::format("SOCKET-SHUTDOWN({}): Orderly shutdown.", CId_));
SendTelemetryShutdown();
}
void TelemetryClient::OnSocketError([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ErrorNotification>& pNf) {
poco_information(Logger(),fmt::format("TELEMETRY-SOCKET-ERROR({}): Closing.",CId_));
std::lock_guard Guard(Mutex_);
Logger().information(fmt::format("SOCKET-ERROR({}): Closing.",CId_));
SendTelemetryShutdown();
}
void TelemetryClient::OnSocketReadable([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf) {
std::lock_guard Guard(Mutex_);
try
{
std::lock_guard Guard(Mutex_);
ProcessIncomingFrame();
}
catch (const Poco::Exception & E)
@@ -122,11 +127,11 @@ namespace OpenWifi {
}
catch (const std::exception & E) {
std::string W = E.what();
poco_information(Logger(),fmt::format("TELEMETRY-std::exception caught: {}. Connection terminated with {}",W,CId_));
Logger().information(fmt::format("std::exception caught: {}. Connection terminated with {}",W,CId_));
SendTelemetryShutdown();
}
catch ( ... ) {
poco_information(Logger(),fmt::format("TELEMETRY-Unknown exception for {}. Connection terminated.",CId_));
Logger().information(fmt::format("Unknown exception for {}. Connection terminated.",CId_));
SendTelemetryShutdown();
}
}
@@ -143,16 +148,16 @@ namespace OpenWifi {
Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
if (IncomingSize == 0 && flags == 0 && Op == 0) {
poco_information(Logger(),fmt::format("TELEMETRY-DISCONNECT({}): device has disconnected.", CId_));
Logger().information(fmt::format("DISCONNECT({}): device has disconnected.", CId_));
MustDisconnect = true;
} else {
if (Op == Poco::Net::WebSocket::FRAME_OP_PING) {
Logger().debug(fmt::format("TELEMETRY-WS-PING({}): received. PONG sent back.", CId_));
Logger().debug(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);
} else if (Op == Poco::Net::WebSocket::FRAME_OP_CLOSE) {
poco_information(Logger(),fmt::format("TELEMETRY-DISCONNECT({}): device wants to disconnect.", CId_));
Logger().information(fmt::format("DISCONNECT({}): device wants to disconnect.", CId_));
MustDisconnect = true ;
}
}

View File

@@ -3,34 +3,33 @@
//
#include <thread>
#include "framework/MicroService.h"
#include "Poco/JSON/Array.h"
#include "Poco/Net/HTTPHeaderStream.h"
#include "Poco/URI.h"
#include "RESTAPI/RESTAPI_telemetryWebSocket.h"
#include "TelemetryStream.h"
#include "framework/MicroService.h"
namespace OpenWifi {
int TelemetryStream::Start() {
Running_ = true;
Messages_->Readable_ += Poco::delegate(this,&TelemetryStream::onMessage);
// ReactorPool_.Start("TelemetryWebSocketPool_");
Thr_.start(Reactor_);
Utils::SetThreadName(Thr_,"telemetry-svr");
return 0;
}
void TelemetryStream::Stop() {
poco_information(Logger(),"Stopping...");
Logger().notice("Stopping reactors...");
// ReactorPool_.Stop();
Reactor_.stop();
Thr_.join();
if(Running_) {
Running_ = false;
Messages_->Readable_ -= Poco::delegate( this, &TelemetryStream::onMessage);
}
poco_information(Logger(),"Stopped...");
}
bool TelemetryStream::IsValidEndPoint(uint64_t SerialNumber, const std::string & UUID) {
@@ -47,11 +46,12 @@ namespace OpenWifi {
return (N->second.find(UUID) != N->second.end());
}
bool TelemetryStream::CreateEndpoint(uint64_t SerialNumber, std::string &EndPoint, const std::string &UUID) {
bool TelemetryStream::CreateEndpoint(uint64_t SerialNumber, std::string &EndPoint, std::string &UUID) {
std::lock_guard G(Mutex_);
Poco::URI Public(MicroService::instance().ConfigGetString("openwifi.system.uri.public"));
Poco::URI U;
UUID = MicroService::CreateUUID();
U.setScheme("wss");
U.setHost(Public.getHost());
U.setPort(Public.getPort());

View File

@@ -21,8 +21,8 @@
#include "Poco/URI.h"
#include "Poco/Net/HTTPServer.h"
#include "AP_WS_ReactorPool.h"
#include "TelemetryClient.h"
#include "WS_ReactorPool.h"
namespace OpenWifi {
@@ -43,18 +43,20 @@ namespace OpenWifi {
void Stop() override;
bool IsValidEndPoint(uint64_t SerialNumber, const std::string & UUID);
bool CreateEndpoint(uint64_t SerialNumber, std::string &EndPoint, const std::string &UUID);
bool CreateEndpoint(uint64_t SerialNumber, std::string &EndPoint, std::string &UUID);
void UpdateEndPoint(uint64_t SerialNumber, const std::string &PayLoad);
bool RegisterClient(const std::string &UUID, TelemetryClient *Client);
void DeRegisterClient(const std::string &UUID);
// Poco::Net::SocketReactor & NextReactor() { return ReactorPool_.NextReactor(); }
Poco::Net::SocketReactor & NextReactor() { return Reactor_; }
void onMessage(bool& b);
private:
volatile std::atomic_bool Running_=false;
std::atomic_bool Running_=false;
std::map<std::string, TelemetryClient *> Clients_; // uuid -> client
std::map<uint64_t, std::set<std::string>> SerialNumbers_; // serialNumber -> uuid
// ReactorPool ReactorPool_;
Poco::Net::SocketReactor Reactor_;
std::unique_ptr<FIFO<QueueUpdate>> Messages_=std::make_unique<FIFO<QueueUpdate>>(100);
Poco::Thread Thr_;

View File

@@ -1,144 +0,0 @@
//
// Created by stephane bourque on 2022-07-16.
//
#pragma once
#include "framework/MicroService.h"
#include "sdks/sdk_prov.h"
#include "AP_WS_Server.h"
namespace OpenWifi {
class VenueBroadcastNotification : public Poco::Notification {
public:
VenueBroadcastNotification(const std::string &SourceSerialNumber, const std::string &Data, uint64_t TimeStamp) :
SourceSerialNumber_(SourceSerialNumber),
Data_(Data),
TimeStamp_(TimeStamp) {
}
std::string SourceSerialNumber_;
std::string Data_;
uint64_t TimeStamp_=OpenWifi::Now();
};
class VenueBroadcaster : public SubSystemServer, Poco::Runnable {
public:
static auto instance() {
static auto instance_ = new VenueBroadcaster;
return instance_;
}
inline int Start() override {
Enabled_ = MicroService::instance().ConfigGetBool("venue_broadcast.enabled",true);
if(Enabled_) {
BroadcastManager_.start(*this);
}
return 0;
}
inline void Stop() override {
poco_information(Logger(),"Stopping...");
if(Enabled_ && Running_) {
BroadcastQueue_.wakeUpAll();
BroadcastManager_.wakeUp();
BroadcastManager_.join();
}
poco_information(Logger(),"Stopped...");
}
inline void reinitialize([[maybe_unused]] Poco::Util::Application &self) override {
poco_information(Logger(),"Reinitializing.");
}
struct VenueInfo {
uint64_t timestamp=OpenWifi::Now();
Types::StringVec serialNumbers;
};
inline bool FindSerialNumberList(const std::string &Source, OpenWifi::Types::StringVec & SerialNumbers) {
// Can we find our serial number in any of the lists so far...
for(const auto &venue:Venues_) {
auto entry = std::find(venue.second.serialNumbers.begin(),venue.second.serialNumbers.end(),Source);
if(entry!=venue.second.serialNumbers.end() && (OpenWifi::Now()-venue.second.timestamp)<600) {
SerialNumbers = venue.second.serialNumbers;
auto entry2 = std::find(SerialNumbers.begin(),SerialNumbers.end(),Source);
SerialNumbers.erase(entry2);
return true;
}
}
// get the venue from Prov and the serial numbers.
Types::UUID_t Venue;
Types::StringVec TmpSerialNumbers;
if(OpenWifi::SDK::Prov::GetSerialNumbersForVenueOfSerialNumber(Source,Venue,TmpSerialNumbers,Logger())) {
std::sort(TmpSerialNumbers.begin(),TmpSerialNumbers.end());
VenueInfo V{.timestamp=OpenWifi::Now(), .serialNumbers=TmpSerialNumbers};
Venues_[Venue] = V;
auto p = std::find(TmpSerialNumbers.begin(),TmpSerialNumbers.end(),Source);
if(p!=TmpSerialNumbers.end()) {
TmpSerialNumbers.erase(p);
SerialNumbers = TmpSerialNumbers;
return true;
}
}
return false;
}
inline void SendToDevice(const std::string &SerialNumber,const std::string &Payload) {
AP_WS_Server()->SendFrame(SerialNumber,Payload);
}
inline void run() final {
Running_ = true;
Utils::SetThreadName("venue-bcast");
Poco::AutoPtr<Poco::Notification> NextNotification(BroadcastQueue_.waitDequeueNotification());
while (NextNotification && Running_) {
auto Notification = dynamic_cast<VenueBroadcastNotification *>(NextNotification.get());
if (Notification != nullptr) {
Types::StringVec SerialNumbers;
if(FindSerialNumberList(Notification->SourceSerialNumber_,SerialNumbers)) {
Poco::JSON::Object Payload;
Payload.set("jsonrpc","2.0");
Payload.set("method","venue_broadcast");
Poco::JSON::Object ParamBlock;
ParamBlock.set("serial",Notification->SourceSerialNumber_);
ParamBlock.set("timestamp",Notification->TimeStamp_);
ParamBlock.set("data",Notification->Data_);
Payload.set("params", ParamBlock);
std::ostringstream o;
Payload.stringify(o);
for(const auto &Device:SerialNumbers) {
SendToDevice(Device,o.str());
}
}
}
NextNotification = BroadcastQueue_.waitDequeueNotification();
}
Running_=false;
}
inline void Broadcast(const std::string &SourceSerial, const std::string &Data, uint64_t TimeStamp) {
BroadcastQueue_.enqueueNotification(new VenueBroadcastNotification(SourceSerial,Data,TimeStamp));
}
private:
std::atomic_bool Running_=false;
bool Enabled_=false;
Poco::NotificationQueue BroadcastQueue_;
Poco::Thread BroadcastManager_;
std::map<OpenWifi::Types::UUID_t,VenueInfo> Venues_;
VenueBroadcaster() noexcept:
SubSystemServer("VenueBroadcaster", "VENUE-BCAST", "venue.broacast")
{
}
};
inline auto VenueBroadcaster() { return VenueBroadcaster::instance(); }
}

1132
src/WS_Connection.cpp Normal file

File diff suppressed because it is too large Load Diff

95
src/WS_Connection.h Normal file
View File

@@ -0,0 +1,95 @@
//
// Created by stephane bourque on 2022-02-03.
//
#pragma once
#include <string>
#include "Poco/Net/SocketReactor.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/JSON/Object.h"
#include "Poco/Net/SocketNotification.h"
#include "Poco/Logger.h"
#include "Poco/Net/WebSocket.h"
#include "DeviceRegistry.h"
#include "RESTObjects/RESTAPI_GWobjects.h"
namespace OpenWifi {
class WSConnection {
static constexpr int BufSize = 128000;
public:
WSConnection(Poco::Net::StreamSocket& Socket, Poco::Net::SocketReactor& Reactor);
~WSConnection();
void ProcessJSONRPCEvent(Poco::JSON::Object::Ptr & Doc);
void ProcessJSONRPCResult(Poco::JSON::Object::Ptr Doc);
void ProcessIncomingFrame();
void ProcessIncomingRadiusData(const Poco::JSON::Object::Ptr &Doc);
bool Send(const std::string &Payload);
bool SendRadiusAuthenticationData(const unsigned char * buffer, std::size_t size);
bool SendRadiusAccountingData(const unsigned char * buffer, std::size_t size);
void OnSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
void OnSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf);
void OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification>& pNf);
bool LookForUpgrade(const uint64_t UUID, uint64_t & UpgradedUUID);
static bool ExtractBase64CompressedData(const std::string & CompressedData, std::string & UnCompressedData, uint64_t compress_sz);
void LogException(const Poco::Exception &E);
inline Poco::Logger & Logger() { return Logger_; }
bool SetWebSocketTelemetryReporting(uint64_t interval, uint64_t TelemetryWebSocketTimer);
bool SetKafkaTelemetryReporting(uint64_t interval, uint64_t TelemetryKafkaTimer);
bool StopWebSocketTelemetry();
bool StopKafkaTelemetry();
inline bool GetTelemetryParameters(bool & Reporting, uint64_t & Interval,
uint64_t & WebSocketTimer, uint64_t & KafkaTimer,
uint64_t &WebSocketCount, uint64_t & KafkaCount,
uint64_t &WebSocketPackets,
uint64_t &KafkaPackets ) const {
Reporting = TelemetryReporting_;
WebSocketTimer = TelemetryWebSocketTimer_;
KafkaTimer = TelemetryKafkaTimer_;
WebSocketCount = TelemetryWebSocketRefCount_;
KafkaCount = TelemetryKafkaRefCount_;
Interval = TelemetryInterval_;
WebSocketPackets = TelemetryWebSocketPackets_;
KafkaPackets = TelemetryKafkaPackets_;
return true;
}
private:
std::recursive_mutex Mutex_;
Poco::Logger &Logger_;
Poco::Net::StreamSocket Socket_;
Poco::Net::SocketReactor & Reactor_;
std::unique_ptr<Poco::Net::WebSocket> WS_;
std::string SerialNumber_;
uint64_t SerialNumberInt_=0;
std::string Compatible_;
std::shared_ptr<DeviceRegistry::ConnectionEntry> Conn_;
bool Registered_ = false ;
std::string CId_;
std::string CN_;
GWObjects::CertificateValidation CertValidation_ = GWObjects::CertificateValidation::NO_CERTIFICATE;
uint64_t Errors_=0;
bool Connected_=false;
uint64_t ConnectionId_=0;
Poco::Net::IPAddress PeerAddress_;
mutable std::atomic_bool TelemetryReporting_ = false;
mutable uint64_t TelemetryWebSocketRefCount_ = 0;
mutable uint64_t TelemetryKafkaRefCount_ = 0;
mutable uint64_t TelemetryWebSocketTimer_ = 0;
mutable uint64_t TelemetryKafkaTimer_ = 0 ;
mutable uint64_t TelemetryInterval_ = 0;
mutable uint64_t TelemetryWebSocketPackets_=0;
mutable uint64_t TelemetryKafkaPackets_=0;
void CompleteStartup();
bool StartTelemetry();
bool StopTelemetry();
void UpdateCounts();
};
}

View File

@@ -5,58 +5,62 @@
#pragma once
#include <string>
#include <shared_mutex>
#include "Poco/Net/SocketAcceptor.h"
#include "Poco/Environment.h"
namespace OpenWifi {
class AP_WS_ReactorThreadPool {
class ReactorThreadPool {
public:
explicit AP_WS_ReactorThreadPool() {
NumberOfThreads_ = Poco::Environment::processorCount()*2;
if(NumberOfThreads_==0)
NumberOfThreads_=4;
explicit ReactorThreadPool() {
if(Poco::Environment::processorCount()>8)
NumberOfThreads_ = Poco::Environment::processorCount()/2;
else
NumberOfThreads_ = 2;
Start("ReactorThreadPool");
}
~ AP_WS_ReactorThreadPool() {
~ ReactorThreadPool() {
Stop();
}
void Start() {
void Start(const std::string & ThreadNamePrefix) {
for (uint64_t i = 0; i < NumberOfThreads_; ++i) {
auto NewReactor = std::make_unique<Poco::Net::SocketReactor>();
auto NewThread = std::make_unique<Poco::Thread>();
NewThread->setStackSize(2000000);
NewThread->start(*NewReactor);
std::string ThreadName{"ap:react:" + std::to_string(i)};
Utils::SetThreadName(*NewThread,ThreadName.c_str());
NewThread->setName(ThreadNamePrefix + "#" + std::to_string(i));
Reactors_.emplace_back(std::move(NewReactor));
Threads_.emplace_back(std::move(NewThread));
}
}
inline static auto instance() {
static auto instance_ = new ReactorThreadPool;
return instance_;
}
void Stop() {
for (auto &i : Reactors_)
i->stop();
for (auto &i : Threads_) {
i->join();
}
Reactors_.clear();
Threads_.clear();
}
Poco::Net::SocketReactor &NextReactor() {
std::shared_lock Lock(Mutex_);
std::lock_guard G(Mutex_);
NextReactor_++;
NextReactor_ %= NumberOfThreads_;
return *Reactors_[NextReactor_];
}
private:
std::shared_mutex Mutex_;
std::mutex Mutex_;
uint64_t NumberOfThreads_;
uint64_t NextReactor_ = 0;
std::vector<std::unique_ptr<Poco::Net::SocketReactor>> Reactors_;
std::vector<std::unique_ptr<Poco::Thread>> Threads_;
};
inline auto ReactorThreadPool() { return ReactorThreadPool::instance(); }
}

82
src/WS_Server.cpp Normal file
View File

@@ -0,0 +1,82 @@
//
// License type: BSD 3-Clause License
// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
//
// Created by Stephane Bourque on 2021-03-04.
// Arilia Wireless Inc.
//
#include "Poco/Net/HTTPHeaderStream.h"
#include "Poco/JSON/Array.h"
#include "ConfigurationCache.h"
#include "TelemetryStream.h"
#include "WS_Server.h"
namespace OpenWifi {
bool WebSocketServer::ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate) {
if(IsCertOk()) {
Logger().debug(fmt::format("CERTIFICATE({}): issuer='{}' cn='{}'", ConnectionId, Certificate.issuerName(),Certificate.commonName()));
if(!Certificate.issuedBy(*IssuerCert_)) {
Logger().debug(fmt::format("CERTIFICATE({}): issuer mismatch. Local='{}' Incoming='{}'", ConnectionId, IssuerCert_->issuerName(), Certificate.issuerName()));
return false;
}
return true;
}
return false;
}
int WebSocketServer::Start() {
// ReactorPool_.Start("DeviceReactorPool_");
for(const auto & Svr : ConfigServersList_ ) {
Logger().notice( fmt::format("Starting: {}:{} Keyfile:{} CertFile: {}",
Svr.Address(),
Svr.Port(),
Svr.KeyFile(),Svr.CertFile()));
Svr.LogCert(Logger());
if(!Svr.RootCA().empty())
Svr.LogCas(Logger());
auto Sock{Svr.CreateSecureSocket(Logger())};
if(!IsCertOk()) {
IssuerCert_ = std::make_unique<Poco::Crypto::X509Certificate>(Svr.IssuerCertFile());
Logger().information( fmt::format("Certificate Issuer Name:{}",IssuerCert_->issuerName()));
}
auto NewSocketAcceptor = std::make_unique<ws_server_reactor_type_t>(Sock, Reactor_); // , 2 /*Poco::Environment::processorCount()*2) */ );
Acceptors_.push_back(std::move(NewSocketAcceptor));
}
auto ProvString = MicroService::instance().ConfigGetString("autoprovisioning.process","default");
if(ProvString!="default") {
auto Tokens = Poco::StringTokenizer(ProvString, ",");
for (const auto &i : Tokens) {
if (i == "prov")
LookAtProvisioning_ = true;
else
UseDefaultConfig_ = true;
}
} else {
UseDefaultConfig_ = true;
}
SimulatorId_ = MicroService::instance().ConfigGetString("simulatorid","");
SimulatorEnabled_ = !SimulatorId_.empty();
ReactorThread_.setName("WS-DEVICE-REACTOR");
ReactorThread_.setStackSize(3000000);
ReactorThread_.start(Reactor_);
return 0;
}
void WebSocketServer::Stop() {
Logger().notice("Stopping reactors...");
// ReactorPool_.Stop();
Reactor_.stop();
ReactorThread_.join();
}
} //namespace

77
src/WS_Server.h Normal file
View File

@@ -0,0 +1,77 @@
//
// License type: BSD 3-Clause License
// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
//
// Created by Stephane Bourque on 2021-03-04.
// Arilia Wireless Inc.
//
#pragma once
#include <mutex>
#include <thread>
#include <array>
#include <ctime>
#include "framework/MicroService.h"
#include "Poco/AutoPtr.h"
#include "Poco/Net/SocketReactor.h"
#include "Poco/Net/ParallelSocketAcceptor.h"
#include "Poco/Net/SocketAcceptor.h"
#include "WS_Connection.h"
#include "WS_ReactorPool.h"
namespace OpenWifi {
class WebSocketServer : public SubSystemServer {
public:
static auto instance() {
static auto instance_ = new WebSocketServer;
return instance_;
}
int Start() override;
void Stop() override;
bool IsCertOk() { return IssuerCert_!= nullptr; }
bool ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate);
// Poco::Net::SocketReactor & GetNextReactor() { return ReactorPool_.NextReactor(); }
inline bool IsSimSerialNumber(const std::string & SerialNumber) const {
return IsSim(SerialNumber) && SerialNumber == SimulatorId_;
}
inline static bool IsSim(const std::string & SerialNumber) {
return SerialNumber.substr(0,6) == "53494d";
}
inline bool IsSimEnabled() const {
return SimulatorEnabled_;
}
inline bool UseProvisioning() const { return LookAtProvisioning_; }
inline bool UseDefaults() const { return UseDefaultConfig_; }
private:
std::unique_ptr<Poco::Crypto::X509Certificate> IssuerCert_;
// typedef std::unique_ptr<Poco::Net::ParallelSocketAcceptor<WSConnection, Poco::Net::SocketReactor>> ws_server_reactor_type_t;
typedef Poco::Net::SocketAcceptor<WSConnection> ws_server_reactor_type_t;
std::vector<std::unique_ptr<ws_server_reactor_type_t>> Acceptors_;
Poco::Net::SocketReactor Reactor_;
Poco::Thread ReactorThread_;
// ReactorPool ReactorPool_;
std::string SimulatorId_;
bool LookAtProvisioning_ = false;
bool UseDefaultConfig_ = true;
bool SimulatorEnabled_=false;
WebSocketServer() noexcept:
SubSystemServer("WebSocketServer", "WS-SVR", "ucentral.websocket") {
}
};
inline auto WebSocketServer() { return WebSocketServer::instance(); }
} //namespace

View File

@@ -1,206 +0,0 @@
{
"interfaces": [
{
"ethernet": [
{
"select-ports": [
"WAN*"
]
}
],
"ipv4": {
"addressing": "dynamic"
},
"ipv6": {
"addressing": "dynamic"
},
"name": "wan",
"role": "upstream",
"services": [
"ssh"
],
"ssids": []
},
{
"ethernet": [
{
"select-ports": [
"LAN*"
]
}
],
"ipv4": {
"addressing": "static",
"dhcp": {
"lease-count": 100,
"lease-first": 10,
"lease-time": "6h"
},
"gateway": "192.168.1.1",
"send-hostname": true,
"subnet": "192.168.1.1/24",
"use-dns": []
},
"ipv6": {
"addressing": "dynamic"
},
"name": "lan",
"role": "downstream",
"services": [
"wifi-steering",
"ssh"
],
"ssids": [
{
"bss-mode": "ap",
"encryption": {
"ieee80211w": "optional",
"proto": "wpa-mixed"
},
"hidden-ssid": false,
"isolate-clients": false,
"maximum-clients": 64,
"name": "arilia-rad",
"pass-point": {
"access-network-type": 0,
"anqp-3gpp-cell-net": [],
"anqp-domain": 8888,
"asra": false,
"auth-type": {
"type": "terms-and-conditions"
},
"connection-capability": [
"1:0:2",
"6:22:1",
"17:5060:0"
],
"disable-dgaf": true,
"domain-name": [
"main.arilia.com"
],
"esr": false,
"friendly-name": [
"eng:AriliaWifi",
"fra:AriliaWifi"
],
"hessid": "11:22:33:44:55:66",
"internet": true,
"ipaddr-type-available": 14,
"nai-realm": [],
"osen": false,
"roaming-consortium": [
"F4F5E8F5F4"
],
"uesa": false,
"venue-group": 2,
"venue-name": [
"eng:Bowen Development 1",
"fra:Bowen Development 1"
],
"venue-type": 8,
"venue-url": [
"http://www.example.com/info-fra",
"http://www.example.com/info-eng"
]
},
"radius": {
"accounting": {
"interval" : 600,
"host": "0.0.0.0",
"port": 1813,
"secret": "radsec"
},
"authentication": {
"host": "0.0.0.0",
"port": 1812,
"secret": "radsec",
},
"chargeable-user-id" : true,
"nas-identifier": "AriliaWifi",
"realm" : [
"c2k2q8e2pcs2udar1pa0.orion.area120.com"
]
},
"services": [
"radius-gw-proxy"
],
"wifi-bands": [
"2G",
"5G"
]
}
]
}
],
"metrics": {
"dhcp-snooping": {
"filters": [
"ack",
"discover",
"offer",
"request",
"solicit",
"reply",
"renew"
]
},
"health": {
"interval": 60
},
"statistics": {
"interval": 60,
"types": [
"ssids",
"lldp",
"clients"
]
},
"wifi-frames": {
"filters": [
"probe",
"auth",
"assoc",
"disassoc",
"deauth",
"local-deauth",
"inactive-deauth",
"key-mismatch",
"beacon-report",
"radar-detected"
]
}
},
"radios": [
{
"band": "2G",
"bandwidth": 10,
"beacon-interval": 100,
"channel": "auto",
"channel-mode": "HT",
"channel-width": 20,
"country": "CA",
"dtim-period": 2,
"maximum-clients": 64,
"tx-power": 23
},
{
"band": "5G",
"bandwidth": 20,
"beacon-interval": 100,
"channel": "auto",
"channel-mode": "VHT",
"channel-width": 80,
"country": "CA",
"dtim-period": 2,
"maximum-clients": 64,
"tx-power": 23
}
],
"services": {
"ssh": {
"password-authentication": true,
"port": 22
}
},
"uuid": 1661409802
}

View File

@@ -44,7 +44,7 @@ static json DefaultUCentralSchema = R"(
"switch": {
"$ref": "#/$defs/switch"
},
"radiosgrep": {
"radios": {
"type": "array",
"items": {
"$ref": "#/$defs/radio"

File diff suppressed because it is too large Load Diff

View File

@@ -1,169 +0,0 @@
//
// Created by stephane bourque on 2022-09-29.
//
#pragma once
#include "fmt/format.h"
#include "Poco/Util/Application.h"
#include "Poco/ErrorHandler.h"
#include "Poco/Net/NetException.h"
#include "Poco/Net/SSLException.h"
#include "Poco/JSON/Template.h"
#include "Poco/Thread.h"
namespace OpenWifi {
class MicroServiceErrorHandler : public Poco::ErrorHandler {
public:
explicit MicroServiceErrorHandler(Poco::Util::Application &App) : App_(App) {
}
inline void exception(const Poco::Exception & Base) override {
try {
if(Poco::Thread::current()!= nullptr) {
t_name = Poco::Thread::current()->getName();
t_id = Poco::Thread::current()->id();
} else {
t_name = "startup_code";
t_id = 0;
}
App_.logger().log(Base);
Base.rethrow();
} catch (const Poco::Net::InvalidCertificateException &E) {
poco_error(App_.logger(), fmt::format("Poco::Net::InvalidCertificateException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::Net::InvalidSocketException &E) {
poco_error(App_.logger(), fmt::format("Poco::Net::InvalidSocketException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::Net::WebSocketException &E) {
poco_error(App_.logger(), fmt::format("Poco::Net::WebSocketException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::Net::ConnectionResetException &E) {
poco_error(App_.logger(), fmt::format("Poco::Net::ConnectionResetException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::Net::CertificateValidationException &E) {
poco_error(App_.logger(), fmt::format("Poco::Net::CertificateValidationException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::Net::SSLConnectionUnexpectedlyClosedException &E) {
poco_error(App_.logger(), fmt::format("Poco::Net::SSLConnectionUnexpectedlyClosedException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::Net::SSLContextException &E) {
poco_error(App_.logger(), fmt::format("Poco::Net::SSLContextException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::Net::SSLException &E) {
poco_error(App_.logger(), fmt::format("Poco::Net::SSLException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::Net::InvalidAddressException &E) {
poco_error(App_.logger(), fmt::format("Poco::Net::InvalidAddressException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::Net::NetException &E) {
poco_error(App_.logger(), fmt::format("Poco::Net::NetException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::IOException &E) {
poco_error(App_.logger(), fmt::format("Poco::IOException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::RuntimeException &E) {
poco_error(App_.logger(), fmt::format("Poco::RuntimeException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::JSON::JSONTemplateException &E) {
poco_error(App_.logger(), fmt::format("Poco::JSON::JSONTemplateException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::JSON::JSONException &E) {
poco_error(App_.logger(), fmt::format("Poco::JSON::JSONException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::ApplicationException &E) {
poco_error(App_.logger(), fmt::format("Poco::ApplicationException thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (const Poco::Exception &E) {
poco_error(App_.logger(), fmt::format("Poco::Exception thr_name={} thr_id={} code={} text={} msg={} what={}",
t_name, t_id, E.code(),
E.displayText(),
E.message(),
E.what()));
} catch (...) {
poco_error(App_.logger(), fmt::format("Poco:Generic thr_name={}",t_name, t_id));
}
}
inline void exception(const std::exception & E) override {
if(Poco::Thread::current()!= nullptr) {
t_name = Poco::Thread::current()->getName();
t_id = Poco::Thread::current()->id();
} else {
t_name = "startup_code";
t_id = 0;
}
poco_warning(App_.logger(), fmt::format("std::exception in {}: {} thr_id={}",
t_name,E.what(),
t_id));
}
inline void exception() override {
if(Poco::Thread::current()!= nullptr) {
t_name = Poco::Thread::current()->getName();
t_id = Poco::Thread::current()->id();
} else {
t_name = "startup_code";
t_id = 0;
}
poco_warning(App_.logger(), fmt::format("generic exception in {} thr_id={}",
t_name, t_id));
}
private:
Poco::Util::Application &App_;
std::string t_name;
int t_id=0;
};
}

View File

@@ -33,6 +33,7 @@ namespace OpenWifi {
int Start() override {
std::lock_guard Guard(Mutex_);
Logger().setLevel(Poco::Message::PRIO_INFORMATION);
Logger().notice("Starting.");
std::string DBType = MicroService::instance().ConfigGetString("storage.type");

View File

@@ -69,41 +69,6 @@ namespace OpenWifi {
}
};
struct WebSocketClientNotificationNumberOfConnection {
std::uint64_t numberOfDevices=0;
std::uint64_t averageConnectedTime=0;
std::uint64_t numberOfConnectingDevices=0;
inline void to_json(Poco::JSON::Object &Obj) const {
RESTAPI_utils::field_to_json(Obj,"numberOfDevices", numberOfDevices);
RESTAPI_utils::field_to_json(Obj,"averageConnectedTime", averageConnectedTime);
RESTAPI_utils::field_to_json(Obj,"numberOfConnectingDevices", numberOfConnectingDevices);
}
inline bool from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
RESTAPI_utils::field_from_json(Obj,"numberOfDevices", numberOfDevices);
RESTAPI_utils::field_from_json(Obj,"averageConnectedTime", averageConnectedTime);
RESTAPI_utils::field_from_json(Obj,"numberOfConnectingDevices", numberOfConnectingDevices);
return true;
} catch (...) {
}
return false;
}
};
inline void WebSocketClientNotificationNumberOfConnections(std::uint64_t numberOfDevices,
std::uint64_t averageConnectedTime,
std::uint64_t numberOfConnectingDevices) {
WebSocketNotification<WebSocketClientNotificationNumberOfConnection> N;
N.content.numberOfDevices = numberOfDevices;
N.content.averageConnectedTime = averageConnectedTime;
N.content.numberOfConnectingDevices = numberOfConnectingDevices;
N.type = "device_connections_statistics";
WebSocketClientServer()->SendNotification(N);
}
inline void WebSocketClientNotificationDeviceConfigurationChange(const std::string &SerialNumber, uint64_t oldUUID, uint64_t newUUID) {
WebSocketNotification<WebNotificationSingleDeviceConfigurationChange> N;
N.content.serialNumber = SerialNumber;
@@ -181,10 +146,6 @@ namespace OpenWifi {
WebSocketClientServer()->SendUserNotification(User,N);
}
/////
/////
/////
struct WebSocketNotificationRebootList {
std::string title,
details,
@@ -228,58 +189,5 @@ namespace OpenWifi {
WebSocketClientServer()->SendUserNotification(User,N);
}
/////
/////
/////
struct WebSocketNotificationUpgradeList {
std::string title,
details,
jobId;
std::vector<std::string> success,
skipped,
no_firmware,
not_connected;
uint64_t timeStamp=OpenWifi::Now();
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
typedef WebSocketNotification<WebSocketNotificationUpgradeList> WebSocketClientNotificationVenueUpgradeList_t;
inline void WebSocketNotificationUpgradeList::to_json(Poco::JSON::Object &Obj) const {
RESTAPI_utils::field_to_json(Obj,"title",title);
RESTAPI_utils::field_to_json(Obj,"jobId",jobId);
RESTAPI_utils::field_to_json(Obj,"success",success);
RESTAPI_utils::field_to_json(Obj,"notConnected",not_connected);
RESTAPI_utils::field_to_json(Obj,"noFirmware",no_firmware);
RESTAPI_utils::field_to_json(Obj,"skipped",skipped);
RESTAPI_utils::field_to_json(Obj,"timeStamp",timeStamp);
RESTAPI_utils::field_to_json(Obj,"details",details);
}
inline bool WebSocketNotificationUpgradeList::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
RESTAPI_utils::field_from_json(Obj,"title",title);
RESTAPI_utils::field_from_json(Obj,"jobId",jobId);
RESTAPI_utils::field_from_json(Obj,"success",success);
RESTAPI_utils::field_from_json(Obj,"notConnected",not_connected);
RESTAPI_utils::field_from_json(Obj,"noFirmware",no_firmware);
RESTAPI_utils::field_from_json(Obj,"skipped",skipped);
RESTAPI_utils::field_from_json(Obj,"timeStamp",timeStamp);
RESTAPI_utils::field_from_json(Obj,"details",details);
return true;
} catch(...) {
}
return false;
}
inline void WebSocketClientNotificationVenueUpgradeCompletionToUser( const std::string & User, WebSocketClientNotificationVenueUpgradeList_t &N) {
N.type = "venue_upgrader";
WebSocketClientServer()->SendUserNotification(User,N);
}
} // namespace OpenWifi

View File

@@ -133,37 +133,6 @@ namespace ORM {
return R;
}
inline std::string WHERE_AND_(std::string Result) {
return Result;
}
template <typename T, typename... Args> std::string WHERE_AND_(std::string Result, const char *fieldName, const T &Value, Args... args) {
if constexpr(std::is_same_v<T,std::string>)
{
if(!Value.empty()) {
if(!Result.empty())
Result += " and ";
Result += fieldName;
Result += '=';
Result += "'";
Result += Escape(Value);
Result += "'";
}
} else {
if(!Result.empty())
Result += " and ";
Result += fieldName ;
Result += '=';
Result += std::to_string(Value);
}
return WHERE_AND_(Result,args...);
}
template <typename... Args> std::string WHERE_AND(Args... args) {
std::string Result;
return WHERE_AND_(Result, args...);
}
enum SqlComparison { EQ = 0, NEQ, LT, LTE, GT, GTE };
enum SqlBinaryOp { AND = 0 , OR };

View File

@@ -196,8 +196,6 @@ namespace OpenWifi::RESTAPI::Errors {
static const struct msg InvalidRadiusServerEntry{1142,"RADIUS Server IP address invalid or port missing."};
static const struct msg InvalidRadiusServerWeigth{1143,"RADIUS Server IP weight cannot be 0."};
static const struct msg MaximumRTTYSessionsReached{1144,"Too many RTTY sessions currently active"};
static const struct msg DeviceIsAlreadyBusy{1145,"Device is already executing a command. Please try later."};
}
@@ -430,7 +428,6 @@ namespace OpenWifi::uCentralProtocol {
static const char *RADIUSDATA = "data";
static const char *RADIUSACCT = "acct";
static const char *RADIUSAUTH = "auth";
static const char *RADIUSCOA = "coa";
static const char *RADIUSDST = "dst";
static const char *IES = "ies";
}
@@ -447,7 +444,6 @@ namespace OpenWifi::uCentralProtocol::Events {
static const char *RECOVERY = "recovery";
static const char *TELEMETRY = "telemetry";
static const char *DEVICEUPDATE = "deviceupdate";
static const char *VENUE_BROADCAST = "venue_broadcast";
enum EVENT_MSG {
ET_UNKNOWN,
@@ -460,8 +456,7 @@ namespace OpenWifi::uCentralProtocol::Events {
ET_CFGPENDING,
ET_RECOVERY,
ET_DEVICEUPDATE,
ET_TELEMETRY,
ET_VENUEBROADCAST
ET_TELEMETRY
};
inline EVENT_MSG EventFromString(const std::string & Method) {
@@ -485,8 +480,6 @@ namespace OpenWifi::uCentralProtocol::Events {
return ET_RECOVERY;
else if(strcmp(TELEMETRY,Method.c_str())==0)
return ET_TELEMETRY;
else if(strcmp(VENUE_BROADCAST,Method.c_str())==0)
return ET_VENUEBROADCAST;
return ET_UNKNOWN;
};
}

View File

@@ -9,163 +9,149 @@
namespace OpenWifi {
RTTYS_ClientConnection::RTTYS_ClientConnection(
Poco::Net::HTTPServerRequest &request,
Poco::Net::HTTPServerResponse &response,
Poco::Net::SocketReactor &reactor,
const std::string &Id)
:
Reactor_(reactor),
Id_(Id),
Logger_(Poco::Logger::get(fmt::format("RTTY-client({})",Id_)))
{
Valid_ = true;
WS_ = std::make_unique<Poco::Net::WebSocket>(request,response);
WS_->setBlocking(false);
WS_->setNoDelay(true);
WS_->setKeepAlive(true);
Registered_ = true;
Reactor_.addEventHandler(
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ReadableNotification>(
*this, &RTTYS_ClientConnection::onSocketReadable));
Reactor_.addEventHandler(
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ShutdownNotification>(
*this, &RTTYS_ClientConnection::onSocketShutdown));
Logger_.information("Starting connection");
}
Poco::Net::HTTPServerRequest & Request,
Poco::Net::HTTPServerResponse & Response,
std::string &Id,
Poco::Net::SocketReactor &Reactor, Poco::Logger &L)
: Id_(std::move(Id)),
SR_(Reactor),
Logger_(L) {
WS_ = new Poco::Net::WebSocket(Request, Response);
RTTYS_server()->Register(Id_, this);
Logger().information(fmt::format("{}: Client starting connection, session: {}.",
Id_, RTTYS_server()->DeviceSessionID(Id_)));
SR_.addEventHandler(
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ReadableNotification>(
*this, &RTTYS_ClientConnection::onSocketReadable));
SR_.addEventHandler(
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ShutdownNotification>(
*this, &RTTYS_ClientConnection::onSocketShutdown));
SR_.addEventHandler(
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ErrorNotification>(
*this, &RTTYS_ClientConnection::onSocketError));
auto DoLogin = [this]() -> void {
int tries = 0;
while (tries < 20) {
if (RTTYS_server()->Login(this->Id_)) {
Logger().information(
fmt::format("{}: Client connected to device, session: {}.", Id_,
RTTYS_server()->DeviceSessionID(Id_)));
this->Connected_ = true;
return;
}
std::this_thread::sleep_for(2000ms);
tries++;
Logger().information(fmt::format(
"{}: Waiting for device to connect to start session. (try={})", Id_,
tries));
}
Logger().information(
fmt::format("{}: Client could not connect to device, session: {}.", Id_,
RTTYS_server()->DeviceSessionID(Id_)));
delete this;
};
std::thread CompleteConnection(DoLogin);
CompleteConnection.detach();
}
RTTYS_ClientConnection::~RTTYS_ClientConnection() {
poco_information(Logger_,
fmt::format("Client {} session ending", Id_)
);
DeRegister();
}
void RTTYS_ClientConnection::DeRegister() {
Valid_ = false;
if(Registered_) {
Registered_ = false;
Reactor_.removeEventHandler(
Logger().information(fmt::format("{}: Client disconnecting.", Id_));
RTTYS_server()->DeRegister(Id_, this);
if(Connected_) {
SR_.removeEventHandler(
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ReadableNotification>(
*this, &RTTYS_ClientConnection::onSocketReadable));
Reactor_.removeEventHandler(
*this, &RTTYS_ClientConnection::onSocketReadable));
SR_.removeEventHandler(
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ShutdownNotification>(
*this, &RTTYS_ClientConnection::onSocketShutdown));
*this, &RTTYS_ClientConnection::onSocketShutdown));
SR_.removeEventHandler(
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ErrorNotification>(
*this, &RTTYS_ClientConnection::onSocketError));
}
delete WS_;
Logger().information(fmt::format("{}: Client disconnected.", Id_));
}
void RTTYS_ClientConnection::EndConnection() {
DeRegister();
RTTYS_server()->NotifyClientDisconnect(Id_, this);
void RTTYS_ClientConnection::Close() {
CloseConnection_ = true;
}
void RTTYS_ClientConnection::onSocketReadable([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf) {
bool MustDisconnect = false;
{
if(!Valid_ || !Registered_)
return;
std::lock_guard G(Mutex_);
try {
int flags;
Poco::Buffer<char> IncomingFrame(0);
auto n = WS_->receiveFrame(IncomingFrame, flags);
auto Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
switch (Op) {
case Poco::Net::WebSocket::FRAME_OP_PING: {
WS_->sendFrame("", 0,
(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 (n == 0) {
Logger_.information("Socket readable shutdown.");
MustDisconnect = true;
} else {
std::string s((char *)IncomingFrame.begin(), IncomingFrame.size());
try {
auto Doc = nlohmann::json::parse(s);
if (Doc.contains("type")) {
auto Type = Doc["type"];
if (Type == "winsize") {
auto cols = Doc["cols"];
auto rows = Doc["rows"];
if (!RTTYS_server()->WindowSize(Id_, cols, rows)) {
Logger_.information("Winsize shutdown.");
MustDisconnect = true;
}
int flags;
auto n = WS_->receiveFrame(Buffer_, sizeof(Buffer_), flags);
auto Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
switch(Op) {
case Poco::Net::WebSocket::FRAME_OP_PING: {
WS_->sendFrame("", 0,(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 (n == 0)
return delete this;
std::string s((char*)Buffer_, n);
try {
auto Doc = nlohmann::json::parse(s);
if (Doc.contains("type")) {
auto Type = Doc["type"];
if (Type == "winsize") {
auto cols = Doc["cols"];
auto rows = Doc["rows"];
if(!RTTYS_server()->WindowSize(Id_,cols, rows)) {
return delete this;
}
}
} catch (...) {
// just ignore parse errors
Logger_.information("Frame text exception shutdown.");
MustDisconnect = true;
}
} catch (...) {
// just ignore parse errors
}
} break;
case Poco::Net::WebSocket::FRAME_OP_BINARY: {
if (n == 0) {
Logger_.information("Frame binary size shutdown.");
MustDisconnect = true;
} else {
poco_trace(Logger_, fmt::format("Sending {} key strokes to device.", n));
if (!RTTYS_server()->SendKeyStrokes(
Id_, (const unsigned char *)IncomingFrame.begin(),
IncomingFrame.size())) {
Logger_.information("Sendkeystrokes shutdown.");
MustDisconnect = true;
}
}
break;
case Poco::Net::WebSocket::FRAME_OP_BINARY: {
if (n == 0)
return delete this;
if(!RTTYS_server()->SendKeyStrokes(Id_,Buffer_,n)) {
return delete this;
}
} break;
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
Logger_.information("Frame frame close shutdown.");
MustDisconnect = true;
} break;
}
break;
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
return delete this;
}
break;
default:
{
default: {
}
}
} catch (...) {
Logger_.information("Frame readable shutdown.");
MustDisconnect = true;
}
}
if(MustDisconnect) {
EndConnection();
}
}
void RTTYS_ClientConnection::SendData( const u_char *Buf, size_t len ) {
if(!Valid_ || !Registered_)
return;
try {
WS_->sendFrame(Buf, len,
Poco::Net::WebSocket::FRAME_FLAG_FIN |
Poco::Net::WebSocket::FRAME_OP_BINARY);
return;
} catch (...) {
Logger_.information("SendData shutdown.");
}
EndConnection();
WS_->sendFrame(Buf, len, Poco::Net::WebSocket::FRAME_FLAG_FIN | Poco::Net::WebSocket::FRAME_OP_BINARY);
}
void RTTYS_ClientConnection::SendData( const std::string &s) {
if(!Valid_ || !Registered_)
return;
try {
WS_->sendFrame(s.c_str(), s.length());
return;
} catch (...) {
Logger_.information("SendData shutdown.");
void RTTYS_ClientConnection::SendData( const std::string &s , bool login) {
if(login) {
RTTYS_server()->LoginDone(Id_);
}
EndConnection();
WS_->sendFrame( s.c_str(), s.length());
}
void RTTYS_ClientConnection::onSocketShutdown([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf) {
Logger_.information("Socket shutdown.");
EndConnection();
// RTTYS_server()->Close(Id_);
delete this;
}
void RTTYS_ClientConnection::onSocketError([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf) {
// RTTYS_server()->Close(Id_);
delete this;
}
}

View File

@@ -11,38 +11,32 @@
#include "Poco/Net/SocketNotification.h"
#include "Poco/FIFOBuffer.h"
#include <shared_mutex>
namespace OpenWifi {
class RTTYS_ClientConnection {
public:
RTTYS_ClientConnection(Poco::Net::HTTPServerRequest &request,
Poco::Net::HTTPServerResponse &response,
Poco::Net::SocketReactor & reactor,
const std::string &Id);
// RTTYS_ClientConnection(std::unique_ptr<Poco::Net::WebSocket> WS, std::string &Id,
RTTYS_ClientConnection(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response, std::string &Id,
Poco::Net::SocketReactor &Reactor, Poco::Logger &L);
~RTTYS_ClientConnection();
void onSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf);
void onSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf);
void onSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf);
void SendData( const u_char *Buf, size_t len );
void SendData( const std::string & S );
void DeRegister();
void SendData( const std::string & S, bool login=false);
[[nodiscard]] inline std::string ID() { return Id_; }
[[nodiscard]] inline bool Valid() { return Valid_; }
void Close();
private:
Poco::Net::SocketReactor &Reactor_;
std::string Id_;
std::unique_ptr<Poco::Net::WebSocket> WS_;
Poco::Logger &Logger_;
std::string Sid_;
std::recursive_mutex Mutex_;
volatile bool Valid_=false;
volatile bool Registered_=false;
void EndConnection();
Poco::Net::WebSocket *WS_= nullptr;
std::string Id_;
std::string Sid_;
Poco::Net::SocketReactor &SR_;
std::atomic_bool Connected_=false;
Poco::Logger & Logger_;
u_char Buffer_[16000]{0};
volatile bool CloseConnection_=false;
inline Poco::Logger & Logger() { return Logger_; }
};
}

View File

@@ -9,11 +9,11 @@
namespace OpenWifi {
RTTYS_Client_WebSocketRequestHandler::RTTYS_Client_WebSocketRequestHandler(Poco::Logger & L)
:Logger_(L) {
RTTY_Client_WebSocketRequestHandler::RTTY_Client_WebSocketRequestHandler(Poco::Net::SocketReactor &R, Poco::Logger & L)
:R_(R), Logger_(L) {
}
void RTTYS_Client_WebSocketRequestHandler::handleRequest(Poco::Net::HTTPServerRequest &request,
void RTTY_Client_WebSocketRequestHandler::handleRequest(Poco::Net::HTTPServerRequest &request,
Poco::Net::HTTPServerResponse &response) {
Poco::URI uri(request.getURI());
const auto & P = uri.getPath();
@@ -30,9 +30,11 @@ namespace OpenWifi {
}
try {
RTTYS_server()->CreateNewClient(request,response,T[2]);
Poco::Thread::current()->setName(fmt::format("WebRTTYRequest_WSHandler_{}", T[2]));
new RTTYS_ClientConnection(request, response, T[2], R_, Logger_);
Logger_.information("Websocket has finished");
} catch (...) {
poco_warning(Logger_,"Exception during WS creation");
Logger_.warning("Exception during WS creation");
}
};
@@ -103,10 +105,9 @@ namespace OpenWifi {
void PageRequestHandler::handleRequest(Poco::Net::HTTPServerRequest &request,
Poco::Net::HTTPServerResponse &response) {
Utils::SetThreadName("rt:webserver");
[[maybe_unused]] uint64_t id = rtty_ws_id++;
uint64_t id = rtty_ws_id++;
poco_debug(Logger(),fmt::format("{}: Starting request.",id));
Logger_.information(fmt::format("{}: Starting request.",id));
Poco::URI uri(request.getURI());
auto Path = uri.getPath();
@@ -128,7 +129,7 @@ namespace OpenWifi {
if (ParsedPath.count() > 1) {
if (ParsedPath[1] == "connect") {
response.redirect(Poco::replace(Path,"/connect/","/rtty/"));
poco_debug(Logger(),fmt::format("{}: Redirect: {}",id,Path));
RTTYS_server()->Logger().information(fmt::format("redirect: {}",Path));
return;
} else if (ParsedPath[1] == "authorized") {
SetCommonHeaders(request,response, false);
@@ -137,7 +138,7 @@ namespace OpenWifi {
response.setContentType("application/json");
std::ostream &answer = response.send();
answer << to_string(doc);
poco_debug(Logger(),fmt::format("{}: Finishing authorization request.",id));
Logger_.information(fmt::format("{}: Finishing authorization request.",id));
return;
} else if (ParsedPath[1] == "fontsize") {
SetCommonHeaders(request,response, false);
@@ -146,7 +147,7 @@ namespace OpenWifi {
response.setContentType("application/json");
std::ostream &answer = response.send();
answer << to_string(doc);
poco_debug(Logger(),fmt::format("{}: Finishing font size request.",id));
Logger_.information(fmt::format("{}: Finishing font size request.",id));
return;
}
}
@@ -154,12 +155,12 @@ namespace OpenWifi {
}
if(Path.find("../")!=std::string::npos) {
poco_debug(Logger(),fmt::format("{}: Finishing request.",id));
Logger_.information(fmt::format("{}: Finishing request.",id));
return;
}
if(Path.find("~/")!=std::string::npos) {
poco_debug(Logger(),fmt::format("{}: Finishing request.",id));
Logger_.information(fmt::format("{}: Finishing request.",id));
return;
}
@@ -169,7 +170,7 @@ namespace OpenWifi {
// std::cout << id << ": Path " << Path << " does not exist" << std::endl;
Path = RTTYS_server()->UIAssets() + "/index.html";
response.sendFile(Path,"text/html");
poco_debug(Logger(),fmt::format("{}: Finishing request.",id));
Logger_.information(fmt::format("{}: Finishing request.",id));
return;
}
Poco::Path P(Path);
@@ -186,7 +187,7 @@ namespace OpenWifi {
} else if (Ext == "css") {
Type = "text/css; charset=utf-8";
if(IsFileGZipped(Path)) {
poco_debug(Logger(),fmt::format("{}: Downloading UI Assets.",id));
Logger_.information(fmt::format("{}: Downloading UI Assets.",id));
response.set("Content-Encoding", "gzip");
}
} else if (Ext == "ico")
@@ -200,22 +201,21 @@ namespace OpenWifi {
response.setContentLength(F.getSize());
response.sendFile(Path, Type);
poco_debug(Logger(),fmt::format("{}: Finishing request.",id));
Logger_.information(fmt::format("{}: Finishing request.",id));
}
RTTYS_Client_RequestHandlerFactory::RTTYS_Client_RequestHandlerFactory(Poco::Logger & L)
: Logger_(L) {}
RTTY_Client_RequestHandlerFactory::RTTY_Client_RequestHandlerFactory(Poco::Net::SocketReactor &R, Poco::Logger & L)
: Reactor_(R), Logger_(L) {}
Poco::Net::HTTPRequestHandler *
RTTYS_Client_RequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest &request) {
RTTY_Client_RequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest &request) {
try {
if (request.find("Upgrade") != request.end() &&
Poco::icompare(request["Upgrade"], "websocket") == 0) {
Utils::SetThreadName("rtty-websvr-ws");
Poco::Thread::current()->setName("WebRTTYRequest_WSHandler");
return new RTTYS_Client_WebSocketRequestHandler(Logger_);
return new RTTY_Client_WebSocketRequestHandler(Reactor_, Logger_);
} else {
Utils::SetThreadName("rtty-websvr-pg");
Poco::Thread::current()->setName("WebRTTYRequest_PageHandler");
return new PageRequestHandler(Logger_);
}
} catch (...) {

View File

@@ -10,20 +10,21 @@
#include "Poco/Net/WebSocket.h"
namespace OpenWifi {
class RTTYS_Client_WebSocketRequestHandler : public Poco::Net::HTTPRequestHandler {
class RTTY_Client_WebSocketRequestHandler : public Poco::Net::HTTPRequestHandler {
public:
explicit RTTYS_Client_WebSocketRequestHandler(Poco::Logger &L);
explicit RTTY_Client_WebSocketRequestHandler(Poco::Net::SocketReactor &R, Poco::Logger &L );
void handleRequest(Poco::Net::HTTPServerRequest &request,
Poco::Net::HTTPServerResponse &response) override;
private:
Poco::Net::SocketReactor &R_;
Poco::Logger &Logger_;
};
class PageRequestHandler : public Poco::Net::HTTPRequestHandler {
public:
explicit PageRequestHandler(Poco::Logger &L)
PageRequestHandler(Poco::Logger &L)
: Logger_(L) {
}
@@ -32,17 +33,17 @@ namespace OpenWifi {
private:
Poco::Logger & Logger_;
inline Poco::Logger &Logger() { return Logger_; }
};
class RTTYS_Client_RequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory {
class RTTY_Client_RequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory {
public:
explicit RTTYS_Client_RequestHandlerFactory(Poco::Logger &L);
explicit RTTY_Client_RequestHandlerFactory(Poco::Net::SocketReactor &R, Poco::Logger &L);
Poco::Net::HTTPRequestHandler *
createRequestHandler(const Poco::Net::HTTPServerRequest &request) override;
private:
Poco::Net::SocketReactor &Reactor_;
Poco::Logger &Logger_;
};
}

View File

@@ -4,326 +4,249 @@
#include "RTTYS_device.h"
#include "rttys/RTTYS_server.h"
#include "rttys/RTTYS_ClientConnection.h"
#include "Poco/Net/SecureStreamSocketImpl.h"
#include "Poco/Net/StreamSocket.h"
void dump(const u_char *b, uint s) {
static const char hex[] = "0123456789abcdef";
int l=0;
std::cout << std::endl;
while(s) {
std::string SS;
SS += (hex[(*b & 0xf0) >> 4]);
SS += (hex[(*b & 0x0f)]);
std::cout << SS << " ";
l++;
if((l % 16) == 0)
std::cout << std::endl;
b++;
--s;
}
std::cout << std::endl;
}
#define SOCKET_DEBUG(X,Y,Z) { std::cout << __func__ << ":" << __LINE__ << std::endl; (Z)=socket_.sendBytes(X,Y); dump(X,Y); }
namespace OpenWifi {
RTTYS_Device_ConnectionHandler::RTTYS_Device_ConnectionHandler(Poco::Net::StreamSocket& socket, Poco::Net::SocketReactor & reactor):
socket_(socket),
reactor_(reactor),
Logger_(Poco::Logger::get(fmt::format("RTTY-device({})",socket_.peerAddress().toString())))
{
// std::thread T([=]() { CompleteConnection(); });
// T.detach();
CompleteConnection();
RTTY_Device_ConnectionHandler::RTTY_Device_ConnectionHandler(const Poco::Net::StreamSocket & socket) :
Poco::Net::TCPServerConnection(socket),
Logger_(RTTYS_server()->Logger()) {
device_address_ = socket.address().toString();
Logger().information(fmt::format("{}: Started.", device_address_));
conn_id_ = global_device_connection_id++;
}
void RTTYS_Device_ConnectionHandler::CompleteConnection() {
try {
valid_=true;
device_address_ = socket_.peerAddress();
RTTY_Device_ConnectionHandler::~RTTY_Device_ConnectionHandler() {
Logger().information(fmt::format("{}: Completing.", device_address_));
running_ = false;
RTTYS_server()->DeRegisterDevice(id_, this);
// socket().close();
Logger().information(fmt::format("{}: Completed.", device_address_));
}
auto SS = dynamic_cast<Poco::Net::SecureStreamSocketImpl *>(socket_.impl());
while (true) {
auto V = SS->completeHandshake();
if (V == 1)
break;
void RTTY_Device_ConnectionHandler::AddCommand(u_char C) {
std::lock_guard G(M_);
// std::cout << conn_id_ << ": Adding command " << (int)C << std::endl;
commands_.push_back(C);
}
bool RTTY_Device_ConnectionHandler::ProcessCommands() {
std::lock_guard G(M_);
if(!commands_.empty()) {
// std::cout << conn_id_ << ": Commands: " << commands_.size() << std::endl;
for(const auto &i:commands_) {
// std::cout << "Command: " << (int)i << std::endl;
if(i==msgTypeLogin) {
// std::cout << "Doing login..." << std::endl;
Login();
}
else if(i==msgTypeLogout) {
// std::cout << "Doing logout..." << std::endl;
Logout();
}
}
commands_.clear();
}
return true;
}
void RTTY_Device_ConnectionHandler::run() {
running_ = true ;
Poco::Timespan pollTimeOut(0,100);
Poco::Timespan pollError(0,1);
Poco::Timespan recvTimeOut(120,0);
socket().setKeepAlive(true);
socket().setNoDelay(true);
socket().setReceiveBufferSize(64000);
socket().setLinger(false,0);
socket().setSendBufferSize(64000);
socket().setReceiveTimeout(recvTimeOut);
int reason=0;
while(running_) {
if(!ProcessCommands()) {
reason=1;
running_=false;
break;
}
if ((SS->secure())) {
poco_information(Logger(), "Secure connection.");
// std::lock_guard G(M_);
if (socket().poll(pollError, Poco::Net::Socket::SELECT_ERROR) == true) {
reason=2;
running_=false;
continue;
}
socket_.setBlocking(false);
socket_.setKeepAlive(true);
socket_.setNoDelay(true);
registered_=true;
reactor_.addEventHandler(
socket_,
Poco::NObserver<RTTYS_Device_ConnectionHandler, Poco::Net::ReadableNotification>(
*this, &RTTYS_Device_ConnectionHandler::onSocketReadable));
reactor_.addEventHandler(
socket_,
Poco::NObserver<RTTYS_Device_ConnectionHandler, Poco::Net::ShutdownNotification>(
*this, &RTTYS_Device_ConnectionHandler::onSocketShutdown));
} catch (...) {
poco_warning(Logger(), "Device caused exception while completing connection.");
std::unique_lock G(M_);
EndConnection();
}
}
RTTYS_Device_ConnectionHandler::~RTTYS_Device_ConnectionHandler() {
poco_information(Logger_,
fmt::format("Device {} session ending", id_)
);
DeRegister();
}
void RTTYS_Device_ConnectionHandler::DeRegister() {
if(registered_) {
registered_ = false;
reactor_.removeEventHandler(
socket_,
Poco::NObserver<RTTYS_Device_ConnectionHandler, Poco::Net::ReadableNotification>(
*this, &RTTYS_Device_ConnectionHandler::onSocketReadable));
reactor_.removeEventHandler(
socket_,
Poco::NObserver<RTTYS_Device_ConnectionHandler, Poco::Net::ShutdownNotification>(
*this, &RTTYS_Device_ConnectionHandler::onSocketShutdown));
}
}
void RTTYS_Device_ConnectionHandler::EndConnection() {
if(valid_) {
valid_ = false;
DeRegister();
RTTYS_server()->NotifyDeviceDisconnect(id_, this);
}
}
[[maybe_unused]] static void dump(unsigned char *p,uint l) {
for(uint i=0;i<l;i++) {
std::cout << std::hex << (uint) p[i] << " ";
if(i % 16 == 0)
std::cout << std::endl;
}
std::cout << std::dec << std::endl ;
}
void RTTYS_Device_ConnectionHandler::onSocketReadable([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf) {
bool good = true;
if(!valid_ || !registered_)
return;
std::unique_lock G(M_);
try {
auto received_bytes = socket_.receiveBytes(inBuf_);
if (received_bytes == 0) {
poco_information(Logger(), fmt::format("{}: Device Closing connection - 0 bytes received.",id_));
return EndConnection();
if (socket().poll(pollTimeOut, Poco::Net::Socket::SELECT_READ) == false) {
continue;
}
while (inBuf_.isReadable() && good) {
uint32_t msg_len = 0;
if (waiting_for_bytes_ != 0) {
int received = socket().receiveBytes(inBuf_);
if(received<0) {
running_ = false;
reason=3;
continue;
}
if(received==0) {
continue;
}
while (!inBuf_.isEmpty() && running_) {
// std::cout << conn_id_ << ": processing buffer" << std::endl;
std::size_t msg_len;
if (waiting_for_bytes_ == 0) {
u_char header[3]{0};
inBuf_.read((char *)&header[0], 3);
last_command_ = header[0];
msg_len = header[1] * 256 + header[2];
} else {
if (inBuf_.used() >= RTTY_HDR_SIZE) {
auto *head = (unsigned char *)inBuf_.begin();
last_command_ = head[0];
msg_len = head[1] * 256 + head[2];
inBuf_.drain(RTTY_HDR_SIZE);
} else {
good = false;
continue;
}
msg_len = received;
}
switch (last_command_) {
case msgTypeRegister: {
good = do_msgTypeRegister(msg_len);
do_msgTypeRegister(msg_len);
} break;
case msgTypeLogin: {
good = do_msgTypeLogin(msg_len);
do_msgTypeLogin(msg_len);
} break;
case msgTypeLogout: {
good = do_msgTypeLogout(msg_len);
do_msgTypeLogout(msg_len);
} break;
case msgTypeTermData: {
good = do_msgTypeTermData(msg_len);
do_msgTypeTermData(msg_len);
} break;
case msgTypeWinsize: {
good = do_msgTypeWinsize(msg_len);
do_msgTypeWinsize(msg_len);
} break;
case msgTypeCmd: {
good = do_msgTypeCmd(msg_len);
do_msgTypeCmd(msg_len);
} break;
case msgTypeHeartbeat: {
good = do_msgTypeHeartbeat(msg_len);
do_msgTypeHeartbeat(msg_len);
} break;
case msgTypeFile: {
good = do_msgTypeFile(msg_len);
do_msgTypeFile(msg_len);
} break;
case msgTypeHttp: {
good = do_msgTypeHttp(msg_len);
do_msgTypeHttp(msg_len);
} break;
case msgTypeAck: {
good = do_msgTypeAck(msg_len);
do_msgTypeAck(msg_len);
} break;
case msgTypeMax: {
good = do_msgTypeMax(msg_len);
do_msgTypeMax(msg_len);
} break;
default: {
poco_warning(Logger(),
fmt::format("{}: Unknown command {} from device. GW closing connection.", id_,
(int)last_command_));
good = false;
default:
Logger().warning(fmt::format("{}: ID:{} Unknown command {}", conn_id_, id_, (int)last_command_));
running_ = false;
continue;
}
}
}
} catch (const Poco::Exception &E) {
good = false;
Logger().log(E,__FILE__,__LINE__);
poco_warning(Logger(),fmt::format("{}: Exception. GW closing connection.", id_));
} catch (const std::exception &E) {
poco_warning(Logger(),fmt::format("{}: Exception. GW closing connection.", id_));
good = false;
}
if(!good) {
return EndConnection();
}
}
void RTTYS_Device_ConnectionHandler::onSocketShutdown([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf) {
poco_information(Logger(),fmt::format("{}: Connection being closed - socket shutdown.",id_));
EndConnection();
}
bool RTTYS_Device_ConnectionHandler::SendToClient(const u_char *Buf, int Len) {
u_char bb[64000]{0};
if(old_rtty_) {
bb[0] = session_id_[0];
memcpy(&bb[1],Buf,Len);
} else {
bb[0] = 0;
memcpy(&bb[1],Buf,Len);
}
return RTTYS_server()->SendToClient(id_, Buf, Len );
}
bool RTTYS_Device_ConnectionHandler::SendToClient(const std::string &S) {
if(!valid_ || !registered_)
return false;
return RTTYS_server()->SendToClient(id_,S);
}
bool RTTYS_Device_ConnectionHandler::KeyStrokes(const u_char *buf, size_t len) {
if(!valid_ || !registered_)
return false;
if(len<=(sizeof(small_buf_)-RTTY_HDR_SIZE-session_length_)) {
small_buf_[0] = msgTypeTermData;
small_buf_[1] = ((len-1+session_length_) & 0xff00) >> 8;
small_buf_[2] = ((len-1+session_length_) & 0x00ff);
memcpy(&small_buf_[RTTY_HDR_SIZE],session_id_,session_length_);
memcpy(&small_buf_[RTTY_HDR_SIZE+session_length_], &buf[1], len-1);
try {
auto Sent = socket_.sendBytes(small_buf_, RTTY_HDR_SIZE + session_length_ + len - 1);
return (Sent==(int)(RTTY_HDR_SIZE + session_length_ + len - 1));
} catch (...) {
return false;
}
} else {
auto Msg = std::make_unique<unsigned char []>(len + RTTY_HDR_SIZE + session_length_);
Msg.get()[0] = msgTypeTermData;
Msg.get()[1] = ((len-1+session_length_) & 0xff00) >> 8;
Msg.get()[2] = ((len-1+session_length_) & 0x00ff);
memcpy((Msg.get()+RTTY_HDR_SIZE),session_id_,session_length_);
memcpy((Msg.get()+RTTY_HDR_SIZE+session_length_), &buf[1], len-1);
try {
auto Sent = socket_.sendBytes(Msg.get(), RTTY_HDR_SIZE + session_length_ + len - 1);
return (Sent==(int)( RTTY_HDR_SIZE + session_length_ + len - 1));
} catch (...) {
return false;
}
}
Logger().information(fmt::format("{}: ID:{} Exiting. Reason:{}", conn_id_, id_, reason));
// RTTYS_server()->DeRegister(id_, this);
// Logger().information(fmt::format("{}: ID:{} Exiting. Deregistered.", conn_id_, id_, reason));
loop_done_=true;
}
bool RTTYS_Device_ConnectionHandler::WindowSize(int cols, int rows) {
if(!valid_ || !registered_)
void RTTY_Device_ConnectionHandler::Stop() {
running_ = false;
}
void RTTY_Device_ConnectionHandler::SendToClient(const u_char *Buf, int Len) {
RTTYS_server()->SendToClient(id_, Buf, Len);
}
void RTTY_Device_ConnectionHandler::SendToClient(const std::string &S) {
RTTYS_server()->SendToClient(id_, S);
}
bool RTTY_Device_ConnectionHandler::KeyStrokes(const u_char *buf, size_t len) {
std::lock_guard G(M_);
u_char outBuf[16]{0};
if(len>(sizeof(outBuf)-5))
return false;
u_char outBuf[8+RTTY_SESSION_ID_LENGTH]{0};
auto total_len = 3 + 1 + len-1;
outBuf[0] = msgTypeTermData;
outBuf[1] = 0 ;
outBuf[2] = len +1-1;
outBuf[3] = sid_;
memcpy( &outBuf[4], &buf[1], len-1);
try {
socket().sendBytes(outBuf, total_len);
return true;
} catch (...) {
return false;
}
}
bool RTTY_Device_ConnectionHandler::WindowSize(int cols, int rows) {
std::lock_guard G(M_);
u_char outBuf[8]{0};
outBuf[0] = msgTypeWinsize;
outBuf[1] = 0 ;
outBuf[2] = 4 + session_length_ ;
memcpy(&outBuf[RTTY_HDR_SIZE],session_id_,session_length_);
outBuf[RTTY_HDR_SIZE+0+session_length_] = cols >> 8 ;
outBuf[RTTY_HDR_SIZE+1+session_length_] = cols & 0x00ff;
outBuf[RTTY_HDR_SIZE+2+session_length_] = rows >> 8;
outBuf[RTTY_HDR_SIZE+3+session_length_] = rows & 0x00ff;
outBuf[2] = 4 + 1 ;
outBuf[3] = sid_;
outBuf[4] = cols >> 8 ;
outBuf[5] = cols & 0x00ff;
outBuf[6] = rows >> 8;
outBuf[7] = rows & 0x00ff;
try {
auto Sent = socket_.sendBytes(outBuf, RTTY_HDR_SIZE + 4 + session_length_ );
return (Sent==(int)(RTTY_HDR_SIZE + 4 + session_length_));
socket().sendBytes(outBuf, 8);
return true;
} catch (...) {
}
return false;
}
bool RTTYS_Device_ConnectionHandler::Login() {
if(!valid_ || !registered_)
return false;
u_char outBuf[RTTY_HDR_SIZE+RTTY_SESSION_ID_LENGTH]{0};
bool RTTY_Device_ConnectionHandler::Login() {
std::lock_guard G(M_);
u_char outBuf[3]{0};
outBuf[0] = msgTypeLogin;
outBuf[1] = 0;
if(old_rtty_) {
outBuf[2] = 0;
} else {
outBuf[2] = RTTY_SESSION_ID_LENGTH;
std::strncpy(session_id_,Utils::ComputeHash(id_,token_).substr(0,RTTY_SESSION_ID_LENGTH/2).c_str(),RTTY_SESSION_ID_LENGTH);
memcpy(&outBuf[RTTY_HDR_SIZE],session_id_,RTTY_SESSION_ID_LENGTH);
}
outBuf[2] = 0;
try {
poco_information(Logger(),fmt::format("{}: Device login", id_));
auto Sent = socket_.sendBytes( outBuf, RTTY_HDR_SIZE + (old_rtty_ ? 0 : RTTY_SESSION_ID_LENGTH));
return Sent==(int)(RTTY_HDR_SIZE + (old_rtty_ ? 0 : RTTY_SESSION_ID_LENGTH));
socket().sendBytes(outBuf, 3);
} catch (const Poco::IOException &E) {
// std::cout << "1 " << E.what() << " " << E.name() << " "<< E.className() << " "<< E.message() << std::endl;
return false;
} catch (const Poco::Exception &E) {
// std::cout << "2 " << E.what() << " " << E.name() << std::endl;
return false;
}
Logger().debug(fmt::format("{}: Device {} login", conn_id_, id_));
return true;
}
bool RTTYS_Device_ConnectionHandler::Logout() {
if(!valid_ || !registered_)
return false;
u_char outBuf[4+RTTY_SESSION_ID_LENGTH]{0};
bool RTTY_Device_ConnectionHandler::Logout() {
std::lock_guard G(M_);
u_char outBuf[4]{0};
outBuf[0] = msgTypeLogout;
outBuf[1] = 0;
outBuf[2] = session_length_;
memcpy(&outBuf[3],session_id_,session_length_);
poco_information(Logger(),fmt::format("{}: Logout", id_));
outBuf[2] = 1;
outBuf[3] = sid_;
Logger().debug(fmt::format("{}: ID:{} Logout", conn_id_, id_));
try {
auto Sent = socket_.sendBytes(outBuf, RTTY_HDR_SIZE + session_length_);
return Sent==(int)(RTTY_HDR_SIZE+session_length_);
socket().sendBytes(outBuf, 4);
return true;
} catch (...) {
}
return false;
}
std::string RTTYS_Device_ConnectionHandler::ReadString() {
std::string RTTY_Device_ConnectionHandler::ReadString() {
std::string Res;
while(inBuf_.used()) {
@@ -338,145 +261,99 @@ namespace OpenWifi {
return Res;
}
bool RTTYS_Device_ConnectionHandler::do_msgTypeRegister([[maybe_unused]] std::size_t msg_len) {
bool good = true;
try {
// establish if this is an old rtty or a new one.
old_rtty_ = (inBuf_[0] != 0x03); // rtty_proto_ver for full session ID inclusion
if(old_rtty_) {
session_length_ = 1;
} else {
inBuf_.drain(1); // remove protocol if used.
session_length_ = RTTY_SESSION_ID_LENGTH;
}
void RTTY_Device_ConnectionHandler::do_msgTypeRegister([[maybe_unused]] std::size_t msg_len) {
socket().receiveBytes(inBuf_);
id_ = ReadString();
desc_ = ReadString();
token_ = ReadString();
serial_ = RTTYS_server()->SerialNumber(id_);
id_ = ReadString();
desc_ = ReadString();
token_ = ReadString();
poco_information(Logger(),
fmt::format("{}: Description:{} Device registration", id_, desc_));
RTTYS_server()->NotifyDeviceRegistration(id_,token_,this);
Poco::Thread::current()->setName(fmt::format("RTTY-device-thread-{}:{}:{}", conn_id_, id_, serial_));
Logger().debug(fmt::format("{}: ID:{} Serial:{} Description:{} Device registration", conn_id_, id_, serial_, desc_));
if (RTTYS_server()->Register(id_, token_, this)) {
u_char OutBuf[8];
OutBuf[0] = msgTypeRegister;
OutBuf[1] = 0; // Data length
OutBuf[2] = 4; //
OutBuf[3] = 0; // Error
OutBuf[1] = 0;
OutBuf[2] = 4;
OutBuf[3] = 0;
OutBuf[4] = 'O';
OutBuf[5] = 'K';
OutBuf[6] = 0;
if (socket_.sendBytes(OutBuf, 7) != 7) {
poco_information(Logger(),
fmt::format("{}: Description:{} Could not send data to complete registration",
id_, desc_));
good = false;
if(socket().sendBytes(OutBuf, 7) !=7) {
Logger().debug(fmt::format("{}: ID:{} Serial:{} Description:{} Could not complete registration", conn_id_, id_, serial_, desc_));
running_ = false;
}
} catch (...) {
good = false;
} else {
Logger().debug(fmt::format("{}: ID:{} Serial:{} Description:{} Could not complete registration", conn_id_, id_, serial_, desc_));
running_ = false;
}
return good;
}
bool RTTYS_Device_ConnectionHandler::do_msgTypeLogin([[maybe_unused]] std::size_t msg_len) {
poco_information(Logger(),fmt::format("{}: Asking for login", id_));
void RTTY_Device_ConnectionHandler::do_msgTypeLogin([[maybe_unused]] std::size_t msg_len) {
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for login", conn_id_, id_, serial_));
nlohmann::json doc;
char Error;
if(old_rtty_) {
inBuf_.read(&Error, 1);
inBuf_.read(&session_id_[0], session_length_);
} else {
char session[RTTY_SESSION_ID_LENGTH+1]{0};
inBuf_.read(&session[0], session_length_);
inBuf_.read(&Error, 1);
}
inBuf_.read(&Error, 1);
inBuf_.read(&sid_, 1);
doc["type"] = "login";
doc["err"] = Error;
const auto login_msg = to_string(doc);
return SendToClient(login_msg);
SendToClient(login_msg);
}
bool RTTYS_Device_ConnectionHandler::do_msgTypeLogout([[maybe_unused]] std::size_t msg_len) {
char session[RTTY_SESSION_ID_LENGTH];
if(old_rtty_) {
inBuf_.read(&session[0],1);
} else {
inBuf_.read(&session[0],RTTY_SESSION_ID_LENGTH);
}
poco_information(Logger(),fmt::format("{}: Logout", id_));
return false;
void RTTY_Device_ConnectionHandler::do_msgTypeLogout([[maybe_unused]] std::size_t msg_len) {
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for logout", conn_id_, id_, serial_));
}
bool RTTYS_Device_ConnectionHandler::do_msgTypeTermData(std::size_t msg_len) {
bool good;
if(waiting_for_bytes_>0) {
if(inBuf_.used()<waiting_for_bytes_) {
waiting_for_bytes_ = waiting_for_bytes_ - inBuf_.used();
good = SendToClient((unsigned char *)inBuf_.begin(), (int) inBuf_.used());
inBuf_.drain();
} else {
good = SendToClient((unsigned char *)inBuf_.begin(), waiting_for_bytes_);
inBuf_.drain(waiting_for_bytes_);
void RTTY_Device_ConnectionHandler::do_msgTypeTermData(std::size_t msg_len) {
if(waiting_for_bytes_!=0) {
auto to_read = std::min(inBuf_.used(),waiting_for_bytes_);
inBuf_.read(&scratch_[0], to_read);
SendToClient((u_char *)&scratch_[0], (int) to_read);
if(to_read<waiting_for_bytes_)
waiting_for_bytes_ -= to_read;
else
waiting_for_bytes_ = 0 ;
}
} else {
if(old_rtty_) {
inBuf_.drain(1);
msg_len -= 1;
} else {
inBuf_.drain(RTTY_SESSION_ID_LENGTH);
msg_len -= RTTY_SESSION_ID_LENGTH;
}
if(inBuf_.used()<msg_len) {
good = SendToClient((unsigned char *)inBuf_.begin(), inBuf_.used());
waiting_for_bytes_ = msg_len - inBuf_.used();
inBuf_.drain();
auto read_count = inBuf_.read(&scratch_[0], inBuf_.used());
SendToClient((u_char *)&scratch_[0], read_count);
waiting_for_bytes_ = msg_len - read_count;
} else {
waiting_for_bytes_ = 0 ;
good = SendToClient((unsigned char *)inBuf_.begin(), msg_len);
inBuf_.drain(msg_len);
inBuf_.read(&scratch_[0], msg_len);
SendToClient((u_char *)&scratch_[0], (int)msg_len);
waiting_for_bytes_=0;
}
}
return good;
}
bool RTTYS_Device_ConnectionHandler::do_msgTypeWinsize([[maybe_unused]] std::size_t msg_len) {
poco_information(Logger(),fmt::format("{}: Asking for msgTypeWinsize", id_));
return true;
void RTTY_Device_ConnectionHandler::do_msgTypeWinsize([[maybe_unused]] std::size_t msg_len) {
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for msgTypeWinsize", conn_id_, id_, serial_));
}
bool RTTYS_Device_ConnectionHandler::do_msgTypeCmd([[maybe_unused]] std::size_t msg_len) {
poco_information(Logger(),fmt::format("{}: Asking for msgTypeCmd", id_));
return true;
void RTTY_Device_ConnectionHandler::do_msgTypeCmd([[maybe_unused]] std::size_t msg_len) {
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for msgTypeCmd", conn_id_, id_, serial_));
}
bool RTTYS_Device_ConnectionHandler::do_msgTypeHeartbeat([[maybe_unused]] std::size_t msg_len) {
u_char MsgBuf[RTTY_HDR_SIZE + 16]{0};
if(msg_len)
inBuf_.drain(msg_len);
void RTTY_Device_ConnectionHandler::do_msgTypeHeartbeat([[maybe_unused]] std::size_t msg_len) {
u_char MsgBuf[3]{0};
MsgBuf[0] = msgTypeHeartbeat;
MsgBuf[1] = 0;
MsgBuf[2] = 0;
auto Sent = socket_.sendBytes(MsgBuf, RTTY_HDR_SIZE);
return Sent == RTTY_HDR_SIZE;
socket().sendBytes(MsgBuf, 3);
}
bool RTTYS_Device_ConnectionHandler::do_msgTypeFile([[maybe_unused]] std::size_t msg_len) {
poco_information(Logger(),fmt::format("{}: Asking for msgTypeFile", id_));
return true;
void RTTY_Device_ConnectionHandler::do_msgTypeFile([[maybe_unused]] std::size_t msg_len) {
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for msgTypeFile", conn_id_, id_, serial_));
}
bool RTTYS_Device_ConnectionHandler::do_msgTypeHttp([[maybe_unused]] std::size_t msg_len) {
poco_information(Logger(),fmt::format("{}: Asking for msgTypeHttp", id_));
return true;
void RTTY_Device_ConnectionHandler::do_msgTypeHttp([[maybe_unused]] std::size_t msg_len) {
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for msgTypeHttp", conn_id_, id_, serial_));
}
bool RTTYS_Device_ConnectionHandler::do_msgTypeAck([[maybe_unused]] std::size_t msg_len) {
poco_information(Logger(),fmt::format("{}: Asking for msgTypeAck", id_));
return true;
void RTTY_Device_ConnectionHandler::do_msgTypeAck([[maybe_unused]] std::size_t msg_len) {
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for msgTypeAck", conn_id_, id_, serial_));
}
bool RTTYS_Device_ConnectionHandler::do_msgTypeMax([[maybe_unused]] std::size_t msg_len) {
poco_information(Logger(),fmt::format("{}: Asking for msgTypeMax", id_));
return true;
void RTTY_Device_ConnectionHandler::do_msgTypeMax([[maybe_unused]] std::size_t msg_len) {
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for msgTypeMax", conn_id_, id_, serial_));
}
}

View File

@@ -5,85 +5,80 @@
#pragma once
#include <array>
#include <shared_mutex>
#include "framework/MicroService.h"
#include "Poco/FIFOBuffer.h"
#include "Poco/Net/TCPServerConnectionFactory.h"
namespace OpenWifi {
constexpr std::size_t RTTY_DEVICE_BUFSIZE=64000;
constexpr std::size_t RTTY_SESSION_ID_LENGTH=32;
constexpr std::size_t RTTY_HDR_SIZE=3;
inline static const std::size_t RTTY_DEVICE_BUFSIZE=64000;
class RTTYS_Device_ConnectionHandler{
public:
enum RTTY_MSG_TYPE {
msgTypeRegister = 0,
msgTypeLogin,
msgTypeLogout,
msgTypeTermData,
msgTypeWinsize,
msgTypeCmd,
msgTypeHeartbeat,
msgTypeFile,
msgTypeHttp,
msgTypeAck,
msgTypeMax };
inline static std::atomic_uint64_t global_device_connection_id = 1;
explicit RTTYS_Device_ConnectionHandler(Poco::Net::StreamSocket& socket, Poco::Net::SocketReactor& reactor);
~RTTYS_Device_ConnectionHandler();
class RTTY_Device_ConnectionHandler : public Poco::Net::TCPServerConnection {
public:
enum RTTY_MSG_TYPE {
msgTypeRegister = 0,
msgTypeLogin,
msgTypeLogout,
msgTypeTermData,
msgTypeWinsize,
msgTypeCmd,
msgTypeHeartbeat,
msgTypeFile,
msgTypeHttp,
msgTypeAck,
msgTypeMax };
bool Login();
bool Logout();
explicit RTTY_Device_ConnectionHandler(const Poco::Net::StreamSocket & socket) ;
~RTTY_Device_ConnectionHandler();
[[nodiscard]] bool SendToClient(const u_char *buf, int len);
[[nodiscard]] bool SendToClient(const std::string &S);
[[nodiscard]] bool WindowSize(int cols, int rows);
[[nodiscard]] bool KeyStrokes(const u_char *buf, size_t len);
std::string ReadString();
// inline auto SessionID() const { return conn_id_; }
void run() final;
bool Login();
bool Logout();
void Stop();
void onSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
void onSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf);
void SendToClient(const u_char *buf, int len);
void SendToClient(const std::string &S);
bool WindowSize(int cols, int rows);
bool KeyStrokes(const u_char *buf, size_t len);
std::string ReadString();
inline auto SessionID() const { return conn_id_; }
void AddCommand(u_char C);
inline Poco::Logger &Logger() { return Logger_; }
inline bool Valid() { return valid_; }
private:
std::atomic_bool running_=false;
volatile std::atomic_bool loop_done_=false;
std::string device_address_;
std::recursive_mutex M_;
Poco::Logger &Logger_;
std::string id_;
std::string token_;
std::string desc_;
std::string serial_;
char sid_=0;
Poco::FIFOBuffer inBuf_{64000};
std::array<char,32000> scratch_{0};
std::size_t waiting_for_bytes_{0};
u_char last_command_=0;
uint64_t conn_id_=0;
std::vector<u_char> commands_;
private:
Poco::Net::StreamSocket socket_;
Poco::Net::SocketReactor &reactor_;
Poco::FIFOBuffer inBuf_{RTTY_DEVICE_BUFSIZE};
Poco::Logger &Logger_;
inline Poco::Logger & Logger() { return Logger_; }
std::atomic_bool valid_=false;
bool old_rtty_=true;
Poco::Net::SocketAddress device_address_;
std::shared_mutex M_;
std::string id_;
std::string token_;
std::string desc_;
char session_id_[RTTY_SESSION_ID_LENGTH+1]{0};
std::uint64_t session_length_=1;
std::size_t waiting_for_bytes_{0};
u_char last_command_=0;
std::atomic_bool registered_=false;
unsigned char small_buf_[64+RTTY_SESSION_ID_LENGTH];
void do_msgTypeRegister(std::size_t msg_len);
void do_msgTypeLogin(std::size_t msg_len);
void do_msgTypeLogout(std::size_t msg_len);
void do_msgTypeTermData(std::size_t msg_len);
void do_msgTypeWinsize(std::size_t msg_len);
void do_msgTypeCmd(std::size_t msg_len);
void do_msgTypeHeartbeat(std::size_t msg_len);
void do_msgTypeFile(std::size_t msg_len);
void do_msgTypeHttp(std::size_t msg_len);
void do_msgTypeAck(std::size_t msg_len);
void do_msgTypeMax(std::size_t msg_len);
bool ProcessCommands();
};
void EndConnection() ;
void CompleteConnection();
void DeRegister();
[[nodiscard]] bool do_msgTypeRegister(std::size_t msg_len);
[[nodiscard]] bool do_msgTypeLogin(std::size_t msg_len);
[[nodiscard]] bool do_msgTypeLogout(std::size_t msg_len);
[[nodiscard]] bool do_msgTypeTermData(std::size_t msg_len);
[[nodiscard]] bool do_msgTypeWinsize(std::size_t msg_len);
[[nodiscard]] bool do_msgTypeCmd(std::size_t msg_len);
[[nodiscard]] bool do_msgTypeHeartbeat(std::size_t msg_len);
[[nodiscard]] bool do_msgTypeFile(std::size_t msg_len);
[[nodiscard]] bool do_msgTypeHttp(std::size_t msg_len);
[[nodiscard]] bool do_msgTypeAck(std::size_t msg_len);
[[nodiscard]] bool do_msgTypeMax(std::size_t msg_len);
};
}

View File

@@ -16,19 +16,23 @@ namespace OpenWifi {
int DSport = (int) MicroService::instance().ConfigGetInt("rtty.port", 5912);
int CSport = (int) MicroService::instance().ConfigGetInt("rtty.viewport", 5913);
RTTY_UIAssets_ = MicroService::instance().ConfigPath("rtty.assets", "$OWGW_ROOT/rtty_ui");
MaxConcurrentSessions_ = MicroService::instance().ConfigGetInt("rtty.maxsessions",0);
const auto & CertFileName = MicroService::instance().ConfigPath("openwifi.restapi.host.0.cert");
const auto & KeyFileName = MicroService::instance().ConfigPath("openwifi.restapi.host.0.key");
const auto & RootCa = MicroService::instance().ConfigPath("openwifi.restapi.host.0.rootca");
auto TcpServerParams = new Poco::Net::TCPServerParams();
TcpServerParams->setMaxThreads(50);
TcpServerParams->setMaxQueued(100);
if(MicroService::instance().NoAPISecurity()) {
Poco::Net::ServerSocket DeviceSocket(DSport, 64);
DeviceAcceptor_ = std::make_unique<Poco::Net::SocketAcceptor<RTTYS_Device_ConnectionHandler>>(DeviceSocket,DeviceReactor_);
DeviceSocket.setNoDelay(true);
DeviceAcceptor_ = std::make_unique<Poco::Net::TCPServer>(new Poco::Net::TCPServerConnectionFactoryImpl<RTTY_Device_ConnectionHandler>(), DeviceSocket, TcpServerParams);
} else {
auto DeviceSecureContext = Poco::AutoPtr<Poco::Net::Context>( new Poco::Net::Context(Poco::Net::Context::SERVER_USE,
auto DeviceSecureContext = new Poco::Net::Context(Poco::Net::Context::SERVER_USE,
KeyFileName, CertFileName, "",
Poco::Net::Context::VERIFY_RELAXED));
Poco::Net::Context::VERIFY_RELAXED);
Poco::Crypto::X509Certificate DeviceRoot(RootCa);
DeviceSecureContext->addCertificateAuthority(DeviceRoot);
DeviceSecureContext->disableStatelessSessionResumption();
@@ -40,21 +44,20 @@ namespace OpenWifi {
SSL_CTX_dane_enable(SSLCtxDevice);
Poco::Net::SecureServerSocket DeviceSocket(DSport, 64, DeviceSecureContext);
DeviceAcceptor_ = std::make_unique<Poco::Net::SocketAcceptor<RTTYS_Device_ConnectionHandler>>(DeviceSocket,DeviceReactor_);
DeviceSocket.setNoDelay(true);
DeviceAcceptor_ = std::make_unique<Poco::Net::TCPServer>(new Poco::Net::TCPServerConnectionFactoryImpl<RTTY_Device_ConnectionHandler>(), DeviceSocket, TcpServerParams);
}
DeviceReactorThread_.start(DeviceReactor_);
Utils::SetThreadName(DeviceReactorThread_,"rt:devreactor");
DeviceAcceptor_->start();
auto WebServerHttpParams = new Poco::Net::HTTPServerParams;
WebServerHttpParams->setMaxThreads(50);
WebServerHttpParams->setMaxQueued(200);
WebServerHttpParams->setKeepAlive(true);
WebServerHttpParams->setName("rt:dispatch");
if(MicroService::instance().NoAPISecurity()) {
Poco::Net::ServerSocket ClientSocket(CSport, 64);
ClientSocket.setNoDelay(true);
WebServer_ = std::make_unique<Poco::Net::HTTPServer>(new RTTYS_Client_RequestHandlerFactory(Logger()), ClientSocket, WebServerHttpParams);
WebServer_ = std::make_unique<Poco::Net::HTTPServer>(new RTTY_Client_RequestHandlerFactory(ClientReactor_, Logger()), ClientSocket, WebServerHttpParams);
} else {
auto WebClientSecureContext = new Poco::Net::Context(Poco::Net::Context::SERVER_USE, KeyFileName, CertFileName,
"", Poco::Net::Context::VERIFY_RELAXED);
@@ -70,213 +73,300 @@ namespace OpenWifi {
Poco::Net::SecureServerSocket ClientSocket(CSport, 64, WebClientSecureContext);
ClientSocket.setNoDelay(true);
WebServer_ = std::make_unique<Poco::Net::HTTPServer>(new RTTYS_Client_RequestHandlerFactory(Logger()), ClientSocket, WebServerHttpParams);
WebServer_ = std::make_unique<Poco::Net::HTTPServer>(new RTTY_Client_RequestHandlerFactory(ClientReactor_, Logger()), ClientSocket, WebServerHttpParams);
};
WebServer_->start();
ClientReactorThread_.setName("RTTYWebServerClientThread");
ClientReactorThread_.start(ClientReactor_);
Utils::SetThreadName(ClientReactorThread_,"rt:clntreactor");
}
GCCallBack_ = std::make_unique<Poco::TimerCallback<RTTYS_server>>(*this, &RTTYS_server::onTimer);
Timer_.setStartInterval(30 * 1000); // first run in 30 seconds
Timer_.setPeriodicInterval(5 * 1000);
Timer_.start(*GCCallBack_, MicroService::instance().TimerPool() );
NotificationManager_.start(*this);
Timer_.setStartInterval(10 * 1000); // first run in 30 seconds
Timer_.setPeriodicInterval(1 * 60 * 1000);
Timer_.start(*GCCallBack_);
return 0;
}
void RTTYS_server::Stop() {
Timer_.stop();
if(Internal_) {
ResponseQueue_.wakeUpAll();
NotificationManager_.wakeUp();
NotificationManager_.join();
WebServer_->stopAll(true);
WebServer_->stop();
Timer_.stop();
WebServer_->stopAll();
DeviceAcceptor_->stop();
ClientReactor_.stop();
ClientReactorThread_.join();
DeviceReactor_.stop();
DeviceAcceptor_->unregisterAcceptor();
DeviceReactorThread_.join();
NotificationManagerRunning_ = false;
}
}
void RTTYS_server::onTimer([[maybe_unused]] Poco::Timer & timer) {
poco_trace(Logger(),"Removing stale connections.");
Utils::SetThreadName("rt:janitor");
static auto LastStats = OpenWifi::Now();
std::lock_guard Lock(LocalMutex_);
for(auto element=EndPoints_.begin();element!=EndPoints_.end();) {
if(element->second->TooOld()) {
auto c = fmt::format("Removing {}. Serial: {} Device connection time: {}s. Client connection time: {}s",
element->first,
element->second->SerialNumber(),
element->second->TimeDeviceConnected(),
element->second->TimeClientConnected());
Logger().information(c);
TotalConnectedClientTime_ += element->second->TimeClientConnected();
TotalConnectedDeviceTime_ += element->second->TimeDeviceConnected();
Logger().debug("Removing stale RTTY connection information.");
std::lock_guard G(Mutex_);
auto now = OpenWifi::Now();
dump("GC ", std::cout);
for(auto element=EndPoints_.begin();element!=EndPoints_.end();) {
if( element->second.ShutdownComplete ||
(element->second.ShuttingDown && (now-element->second.TimeStamp>60))) {
element = EndPoints_.erase(element);
} else {
++element;
}
}
FailedDevices.clear();
FailedClients.clear();
if(Now()-LastStats>(60*5)) {
LastStats = Now();
Logger().information(fmt::format("Statistics: Total connections:{} Total Device Connection Time: {}s Total Client Connection Time: {}s Device failures: {} Client failures: {}",
TotalEndPoints_,
TotalConnectedDeviceTime_,
TotalConnectedClientTime_,
FailedNumDevices_,
FailedNumClients_));
}
dump("GC ", std::cout);
}
void RTTYS_server::CreateNewClient( Poco::Net::HTTPServerRequest &request,
Poco::Net::HTTPServerResponse &response,
const std::string &id) {
auto NewClient = new RTTYS_ClientConnection(request, response, ClientReactor_, id);
NotifyClientRegistration(id,NewClient);
void RTTYS_server::Register(const std::string &Id, RTTYS_ClientConnection *Client) {
std::lock_guard G(Mutex_);
dump("C REG--> ", std::cout);
auto It = EndPoints_.find(Id);
if(It!=EndPoints_.end()) {
It->second.Client = Client;
It->second.ClientConnected = OpenWifi::Now();
dump("C REG--> ", std::cout);
}
dump("C Already REG--> ", std::cout);
}
void RTTYS_server::run() {
Utils::SetThreadName("rt:manager");
NotificationManagerRunning_ = true;
Poco::AutoPtr<Poco::Notification> NextNotification(ResponseQueue_.waitDequeueNotification());
while (NextNotification && NotificationManagerRunning_) {
auto Notification = dynamic_cast<RTTYS_Notification *>(NextNotification.get());
if (Notification != nullptr) {
std::lock_guard Lock(LocalMutex_);
auto It = EndPoints_.find(Notification->id_);
if (It != EndPoints_.end()) {
switch (Notification->type_) {
case RTTYS_Notification_type::device_disconnection: {
It->second->DisconnectDevice();
} break;
case RTTYS_Notification_type::client_disconnection: {
It->second->DisconnectClient();
} break;
case RTTYS_Notification_type::device_registration: {
It->second->SetDevice(Notification->device_);
if(!It->second->Joined() && It->second->ValidClient()) {
It->second->Join();
It->second->Login();
}
} break;
case RTTYS_Notification_type::client_registration: {
It->second->SetClient(Notification->client_);
if(!It->second->Joined() && It->second->ValidDevice()) {
It->second->Join();
It->second->Login();
}
} break;
case RTTYS_Notification_type::unknown: {
} break;
};
} else {
if(Notification->type_==RTTYS_Notification_type::device_registration) {
FailedNumDevices_++;
auto ptr = std::unique_ptr<RTTYS_Device_ConnectionHandler>{Notification->device_};
FailedDevices.push_back(std::move(ptr));
} else if(Notification->type_==RTTYS_Notification_type::client_registration) {
FailedNumClients_++;
auto ptr = std::unique_ptr<RTTYS_ClientConnection>{Notification->client_};
FailedClients.push_back(std::move(ptr));
}
}
}
NextNotification = ResponseQueue_.waitDequeueNotification();
bool RTTYS_server::Register(const std::string &Id, const std::string &Token, RTTY_Device_ConnectionHandler *Device) {
std::lock_guard G(Mutex_);
dump("D REG--> ", std::cout);
auto It = EndPoints_.find(Id);
if(It!=EndPoints_.end()) {
It->second.Device = Device;
It->second.Token = Token;
It->second.DeviceConnected = OpenWifi::Now();
Logger().information(fmt::format("Creating session: {}, device:'{}'",Id,It->second.SerialNumber));
dump("D REG--> ", std::cout);
return true;
}
dump("D Already REG--> ", std::cout);
return false;
}
bool RTTYS_server::SendToClient(const std::string &Id, const u_char *Buf, std::size_t Len) {
std::lock_guard Lock(LocalMutex_);
try {
auto It = EndPoints_.find(Id);
if (It != EndPoints_.end() && It->second!=nullptr) {
return It->second->SendToClient(Buf,Len);
}
} catch(const Poco::Exception &E) {
Logger().log(E);
} catch (...) {
std::cout << "Exception in SendToClient 1" << std::endl;
std::lock_guard G(Mutex_);
auto It = EndPoints_.find(Id);
if(It!=EndPoints_.end() && It->second.Client!= nullptr) {
It->second.Client->SendData(Buf,Len);
return true;
}
return false;
}
bool RTTYS_server::SendToClient(const std::string &Id, const std::string &s) {
std::lock_guard Lock(LocalMutex_);
try {
auto It = EndPoints_.find(Id);
if (It != EndPoints_.end() && It->second!=nullptr) {
return It->second->SendToClient(s);
}
} catch(const Poco::Exception &E) {
Logger().log(E);
} catch (...) {
std::cout << "Exception in SendToClient 2" << std::endl;
std::lock_guard G(Mutex_);
auto It = EndPoints_.find(Id);
if(It!=EndPoints_.end() && It->second.Client!= nullptr) {
It->second.Client->SendData(s);
return true;
}
return false;
}
bool RTTYS_server::SendKeyStrokes(const std::string &Id, const u_char *buffer, std::size_t len) {
std::lock_guard Lock(LocalMutex_);
void RTTYS_server::DeRegister(const std::string &Id, RTTYS_ClientConnection *Client) {
std::lock_guard G(Mutex_);
dump("C DEREG--> ", std::cout);
auto It = EndPoints_.find(Id);
if(It!=EndPoints_.end() && It->second.Client==Client) {
if(It->second.Device!= nullptr) {
if(!It->second.ShuttingDown) {
It->second.ShuttingDown = true;
It->second.Device->Stop();
} else {
It->second.ShutdownComplete = true;
}
} else {
if(!It->second.ShuttingDown) {
It->second.ShuttingDown = true;
} else {
It->second.ShutdownComplete = true;
}
}
It->second.ClientConnected=0;
It->second.Client= nullptr;
}
dump("C DEREG--> ", std::cout);
}
void RTTYS_server::DeRegisterDevice(const std::string &Id, RTTY_Device_ConnectionHandler *Device) {
std::lock_guard G(Mutex_);
dump("D DEREG--> ", std::cout);
auto It = EndPoints_.find(Id);
if(It!=EndPoints_.end() && It->second.Device==Device) {
It->second.Device = nullptr;
It->second.DeviceConnected = 0 ;
if(It->second.Client!=nullptr) {
if(!It->second.ShuttingDown) {
It->second.ShuttingDown = true;
It->second.Client->Close();
} else {
It->second.ShutdownComplete = true;
}
} else {
if(!It->second.ShuttingDown) {
It->second.ShuttingDown = true;
} else {
It->second.ShutdownComplete = true;
}
}
}
dump("D DEREG--> ", std::cout);
if(Device!= nullptr) {
for (auto i = EndPoints_.begin(); i != EndPoints_.end(); i++) {
if (i->second.Device == Device) {
EndPoints_.erase(i);
break;
}
}
dump("D DEREG--> ", std::cout);
}
}
bool RTTYS_server::SendKeyStrokes(const std::string &Id, const u_char *buffer, std::size_t s) {
std::lock_guard G(Mutex_);
auto It=EndPoints_.find(Id);
if(It==EndPoints_.end() || It->second==nullptr) {
if(It==EndPoints_.end()) {
return false;
}
try {
auto res = It->second->KeyStrokes(buffer, len);
return res;
} catch(const Poco::Exception &E) {
Logger().log(E);
} catch (...) {
}
if(It->second.Device!= nullptr)
return It->second.Device->KeyStrokes(buffer,s);
return false;
}
bool RTTYS_server::WindowSize(const std::string &Id, int cols, int rows) {
std::lock_guard Lock(LocalMutex_);
std::lock_guard G(Mutex_);
auto It=EndPoints_.find(Id);
if(It==EndPoints_.end() || It->second==nullptr) {
if(It==EndPoints_.end()) {
return false;
}
try {
return It->second->WindowSize(cols,rows);
} catch(const Poco::Exception &E) {
Logger().log(E);
} catch (...) {
if(It->second.Device!= nullptr)
return It->second.Device->WindowSize(cols,rows);
return false;
}
bool RTTYS_server::CreateEndPoint(const std::string &Id, const std::string & Token, const std::string & UserName, const std::string & SerialNumber ) {
std::lock_guard G(Mutex_);
EndPoint E;
E.ShuttingDown = false;
E.Token = Token;
E.TimeStamp = OpenWifi::Now();
E.SerialNumber = SerialNumber;
E.UserName = UserName;
EndPoints_[Id] = E;
return true;
}
std::string RTTYS_server::SerialNumber(const std::string & Id) {
std::lock_guard G(Mutex_);
auto It = EndPoints_.find(Id);
if(It==EndPoints_.end())
return "";
return It->second.SerialNumber;
}
bool RTTYS_server::ValidId(const std::string &Token) {
std::lock_guard G(Mutex_);
return EndPoints_.find(Token) != EndPoints_.end();
}
void RTTYS_server::LoginDone(const std::string & Id) {
std::lock_guard G(Mutex_);
auto It = EndPoints_.find(Id);
if(It==EndPoints_.end())
return;
Logger().information(fmt::format("User: {}, Serial: {} logged in.",It->second.UserName, It->second.SerialNumber ));
}
bool RTTYS_server::ValidEndPoint(const std::string &Id, const std::string &Token) {
std::lock_guard G(Mutex_);
auto It = EndPoints_.find(Id);
if(It==EndPoints_.end()) {
return false;
}
uint64_t Now = OpenWifi::Now();
return ((It->second.Token == Token) && ((Now-It->second.TimeStamp)<30));
}
bool RTTYS_server::CanConnect( const std::string &Id, RTTYS_ClientConnection *Conn) {
std::lock_guard G(Mutex_);
auto It = EndPoints_.find(Id);
if(It!=EndPoints_.end() && It->second.Client==Conn) {
It->second.ClientConnected = OpenWifi::Now();
return true;
}
return false;
}
bool RTTYS_server::CreateEndPoint(const std::string &Id, const std::string & Token, const std::string & UserName, const std::string & SerialNumber ) {
std::unique_lock Lock(LocalMutex_);
bool RTTYS_server::IsDeviceRegistered( const std::string &Id, const std::string &Token, [[maybe_unused]] RTTY_Device_ConnectionHandler *Conn) {
std::lock_guard G(Mutex_);
if(MaxConcurrentSessions_!=0 && EndPoints_.size()==MaxConcurrentSessions_) {
auto It = EndPoints_.find(Id);
if(It == EndPoints_.end() || It->second.Token != Token )
return false;
}
EndPoints_[Id] = std::make_unique<RTTYS_EndPoint>(Token, SerialNumber, UserName );
++TotalEndPoints_;
return true;
}
bool RTTYS_server::ValidId(const std::string &Token) {
std::lock_guard Lock(LocalMutex_);
return EndPoints_.find(Token) != EndPoints_.end();
uint64_t RTTYS_server::DeviceSessionID(const std::string & Id) {
auto it = EndPoints_.find(Id);
if(it==EndPoints_.end()) {
return 0;
} else {
if(it->second.Device== nullptr) {
return 0;
} else {
return it->second.Device->SessionID();
}
}
}
bool RTTYS_server::Login(const std::string & Id) {
std::lock_guard G(Mutex_);
auto It = EndPoints_.find(Id);
if(It == EndPoints_.end()) {
return false;
}
if(It->second.Device!= nullptr) {
// std::cout << "login " << Id << " session " << It->second.Device->SessionID() << std::endl;
// It->second.Device->AddCommand(RTTY_Device_ConnectionHandler::msgTypeLogin);
// std::cout << "login done" << Id << std::endl;
return It->second.Device->Login();
}
return false;
}
bool RTTYS_server::Logout(const std::string & Id) {
std::lock_guard G(Mutex_);
auto It = EndPoints_.find(Id);
if(It == EndPoints_.end()) {
return false;
}
if(It->second.Device!= nullptr)
It->second.Device->Logout();
return true;
}
bool RTTYS_server::Close(const std::string & Id) {
std::lock_guard G(Mutex_);
auto It = EndPoints_.find(Id);
if(It == EndPoints_.end()) {
return false;
}
if(It->second.Device!= nullptr)
It->second.Device->Stop();
return true;
}
}

View File

@@ -8,206 +8,13 @@
#include "Poco/Net/SocketReactor.h"
#include "Poco/Net/SocketAcceptor.h"
#include "Poco/Timer.h"
#include "rttys/RTTYS_device.h"
#include "rttys/RTTYS_ClientConnection.h"
#include <shared_mutex>
namespace OpenWifi {
class RTTYS_Device_ConnectionHandler;
class RTTY_Device_ConnectionHandler;
class RTTYS_ClientConnection;
template <typename T> class MutexLockerDbg {
public:
MutexLockerDbg(const std::string &name, T &L) :
name_(name),
L_(L)
{
std::cout << name_ << ":L:0:" << Poco::Thread::current()->name() << ":" << Poco::Thread::currentTid() << std::endl;
L_.lock();
std::cout << name_ << ":L:1:" << Poco::Thread::current()->name() << ":" << Poco::Thread::currentTid() << std::endl;
}
~MutexLockerDbg() {
std::cout << name_ << ":U:0:" << Poco::Thread::current()->name() << ":" << Poco::Thread::currentTid() << std::endl;
L_.unlock();
std::cout << name_ << ":U:1:" << Poco::Thread::current()->name() << ":" << Poco::Thread::currentTid() << std::endl;
}
private:
std::string name_;
T & L_;
};
enum class RTTYS_Notification_type {
unknown,
device_disconnection,
client_disconnection,
client_registration,
device_registration
};
class RTTYS_Notification: public Poco::Notification {
public:
RTTYS_Notification(const RTTYS_Notification_type &type, const std::string &id,
RTTYS_Device_ConnectionHandler * device) :
type_(type),
id_(id),
device_(device) {
}
RTTYS_Notification(const RTTYS_Notification_type &type, const std::string &id,
RTTYS_ClientConnection * client) :
type_(type),
id_(id),
client_(client) {
}
RTTYS_Notification(const RTTYS_Notification_type &type,
const std::string &id,
const std::string &token,
RTTYS_Device_ConnectionHandler * device) :
type_(type),
id_(id),
token_(token),
device_(device) {
}
RTTYS_Notification_type type_=RTTYS_Notification_type::unknown;
std::string id_;
std::string token_;
RTTYS_Device_ConnectionHandler *device_= nullptr;
RTTYS_ClientConnection *client_ = nullptr;
};
class RTTYS_EndPoint {
public:
RTTYS_EndPoint(const std::string &Token, const std::string &SerialNumber, const std::string &UserName ):
Token_(Token),
SerialNumber_(SerialNumber),
UserName_(UserName)
{
Created_ = std::chrono::high_resolution_clock::now();
}
inline void SetClient(RTTYS_ClientConnection *Client) {
ClientConnected_ = std::chrono::high_resolution_clock::now();
Client_ = std::unique_ptr<RTTYS_ClientConnection>(Client);
}
inline void SetDevice(RTTYS_Device_ConnectionHandler* Device) {
DeviceConnected_ = std::chrono::high_resolution_clock::now();
Device_ = std::unique_ptr<RTTYS_Device_ConnectionHandler>(Device);
}
inline bool Login() {
if(Device_!= nullptr) {
return Device_->Login();
}
return false;
}
inline void DisconnectClient() {
ClientDisconnected_ = std::chrono::high_resolution_clock::now();
}
inline void DisconnectDevice() {
DeviceDisconnected_ = std::chrono::high_resolution_clock::now();
}
[[nodiscard]] inline bool TooOld() {
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
if(ClientDisconnected_!=std::chrono::time_point<std::chrono::high_resolution_clock>{0s} && (now-ClientDisconnected_)>5s) {
if(DeviceDisconnected_==std::chrono::time_point<std::chrono::high_resolution_clock>{0s}) {
DeviceDisconnected_ = std::chrono::high_resolution_clock::now();
}
return true;
}
if(DeviceDisconnected_!=std::chrono::time_point<std::chrono::high_resolution_clock>{0s} && (now-DeviceDisconnected_)>5s) {
if(ClientDisconnected_==std::chrono::time_point<std::chrono::high_resolution_clock>{0s}) {
ClientDisconnected_ = std::chrono::high_resolution_clock::now();
}
return true;
}
if(!Joined_ && (now-Created_)>30s) {
return true;
}
return false;
}
bool SendToClient(const u_char *Buf, std::size_t Len) {
if(Client_!= nullptr && Client_->Valid()) {
Client_->SendData(Buf,Len);
return true;
}
return false;
}
inline bool KeyStrokes(const u_char *buffer, std::size_t len) {
if( Device_!= nullptr && Device_->Valid() )
return Device_->KeyStrokes(buffer,len);
return false;
}
inline bool WindowSize( int cols, int rows) {
if(Device_!= nullptr && Device_->Valid())
return Device_->WindowSize(cols,rows);
return false;
}
[[nodiscard]] inline bool ValidClient() const {
return Client_!= nullptr && Client_->Valid();
}
[[nodiscard]] inline bool ValidDevice() const {
return Device_!= nullptr && Device_->Valid();
}
[[nodiscard]] inline bool Joined() volatile const { return Joined_; }
void Join() {
Joined_=true;
}
inline bool SendToClient(const std::string &S) {
if(Client_!= nullptr && Client_->Valid()) {
Client_->SendData(S);
return true;
}
return false;
}
[[nodiscard]] inline const std::string & UserName() const { return UserName_; }
[[nodiscard]] inline const std::string & SerialNumber() const { return SerialNumber_; }
[[nodiscard]] inline auto TimeDeviceConnected() {
if(DeviceDisconnected_==std::chrono::time_point<std::chrono::high_resolution_clock>{0s}) {
DeviceDisconnected_ = std::chrono::high_resolution_clock::now();
}
return std::chrono::duration<double>{DeviceDisconnected_ - DeviceConnected_}.count(); }
[[nodiscard]] inline auto TimeClientConnected() {
if(ClientDisconnected_==std::chrono::time_point<std::chrono::high_resolution_clock>{0s}) {
ClientDisconnected_ = std::chrono::high_resolution_clock::now();
}
return std::chrono::duration<double>{ClientDisconnected_ - ClientConnected_}.count();
}
private:
std::string Token_;
std::string SerialNumber_;
std::string UserName_;
std::unique_ptr<RTTYS_ClientConnection> Client_;
std::unique_ptr<RTTYS_Device_ConnectionHandler> Device_;
std::string Id_;
std::chrono::time_point<std::chrono::high_resolution_clock>
Created_{0s},DeviceDisconnected_{0s},
ClientDisconnected_{0s},DeviceConnected_{0s} ,ClientConnected_{0s};
volatile bool Joined_=false;
};
class RTTYS_server : public SubSystemServer, Poco::Runnable
class RTTYS_server : public SubSystemServer
{
public:
static auto instance() {
@@ -220,33 +27,38 @@ namespace OpenWifi {
inline auto UIAssets() { return RTTY_UIAssets_; }
void Register(const std::string &Id, RTTYS_ClientConnection *Client);
void DeRegister(const std::string &Id, RTTYS_ClientConnection *Client);
bool Register(const std::string &Id, const std::string &Token, RTTY_Device_ConnectionHandler *Device);
void DeRegisterDevice(const std::string &Id, RTTY_Device_ConnectionHandler *Device);
bool CreateEndPoint(const std::string &Id, const std::string & Token, const std::string & UserName, const std::string & SerialNumber );
std::string SerialNumber(const std::string & Id);
void LoginDone(const std::string & Id);
bool ValidEndPoint(const std::string &Id, const std::string &Token);
bool CanConnect( const std::string &Id, RTTYS_ClientConnection *Conn);
bool IsDeviceRegistered( const std::string &Id, const std::string &Token, [[maybe_unused]] RTTY_Device_ConnectionHandler *Conn);
bool Login(const std::string & Id_);
bool Logout(const std::string & Id_);
bool Close(const std::string & Id_);
uint64_t DeviceSessionID(const std::string & Id);
bool SendKeyStrokes(const std::string &Id, const u_char *buffer, std::size_t s);
bool WindowSize(const std::string &Id, int cols, int rows);
bool SendToClient(const std::string &id, const u_char *Buf, std::size_t Len);
bool SendToClient(const std::string &id, const std::string &s);
bool ValidId(const std::string &Id);
void run() final;
inline void NotifyDeviceDisconnect(const std::string &id, RTTYS_Device_ConnectionHandler *device) {
ResponseQueue_.enqueueNotification(new RTTYS_Notification(RTTYS_Notification_type::device_disconnection,id,device));
}
inline void NotifyClientDisconnect(const std::string &id, RTTYS_ClientConnection *client) {
ResponseQueue_.enqueueNotification(new RTTYS_Notification(RTTYS_Notification_type::client_disconnection,id,client));
}
inline void NotifyDeviceRegistration(const std::string &id, const std::string &token, RTTYS_Device_ConnectionHandler *device) {
ResponseQueue_.enqueueNotification(new RTTYS_Notification(RTTYS_Notification_type::device_registration,id,token,device));
}
inline void NotifyClientRegistration(const std::string &id, RTTYS_ClientConnection *client) {
ResponseQueue_.enqueueNotification(new RTTYS_Notification(RTTYS_Notification_type::client_registration,id,client));
}
void CreateNewClient(Poco::Net::HTTPServerRequest &request,
Poco::Net::HTTPServerResponse &response, const std::string &id);
struct EndPoint {
std::string Token;
RTTYS_ClientConnection * Client = nullptr;
RTTY_Device_ConnectionHandler * Device = nullptr;
uint64_t TimeStamp = OpenWifi::Now();
uint64_t DeviceConnected = 0;
uint64_t ClientConnected = 0;
std::string UserName;
std::string SerialNumber;
bool ShuttingDown = false;
bool ShutdownComplete = false;
};
void onTimer(Poco::Timer & timer);
@@ -254,38 +66,28 @@ namespace OpenWifi {
return Internal_;
}
inline Poco::Net::SocketReactor & ClientReactor() { return ClientReactor_; }
inline auto Uptime() const { return OpenWifi::Now() - Started_; }
inline void dump([[maybe_unused]] const char *ID, [[maybe_unused]] std::ostream &s) {
/* for(const auto &[id,point]:EndPoints_) {
s << ID << " ID: " << id << " C:" << (point.Client == nullptr) << " D:" << (point.Device== nullptr)
<< " Shutting down: " << point.ShuttingDown
<< " Shutdown: " << point.ShutdownComplete << std::endl;
}
*/
}
private:
Poco::Net::SocketReactor ClientReactor_;
Poco::Net::SocketReactor DeviceReactor_;
Poco::Thread ClientReactorThread_;
std::string RTTY_UIAssets_;
bool Internal_ = false;
// std::recursive_mutex M_;
Poco::Net::SocketReactor ClientReactor_;
Poco::Thread ClientReactorThread_;
std::string RTTY_UIAssets_;
std::atomic_bool Internal_ = false;
std::map<std::string,std::unique_ptr<RTTYS_EndPoint>> EndPoints_; // id, endpoint
std::map<std::string, EndPoint> EndPoints_; // id, endpoint
std::unique_ptr<Poco::Net::HTTPServer> WebServer_;
std::unique_ptr<Poco::Net::SocketAcceptor<RTTYS_Device_ConnectionHandler>> DeviceAcceptor_;
Poco::Thread DeviceReactorThread_;
Poco::NotificationQueue ResponseQueue_;
std::atomic_bool NotificationManagerRunning_=false;
Poco::Thread NotificationManager_;
std::unique_ptr<Poco::Net::TCPServer> DeviceAcceptor_;
Poco::Timer Timer_;
std::unique_ptr<Poco::TimerCallback<RTTYS_server>> GCCallBack_;
std::list<std::unique_ptr<RTTYS_Device_ConnectionHandler>> FailedDevices;
std::list<std::unique_ptr<RTTYS_ClientConnection>> FailedClients;
std::recursive_mutex LocalMutex_;
std::atomic_uint64_t TotalEndPoints_=0;
std::atomic_uint64_t FailedNumDevices_=0;
std::atomic_uint64_t FailedNumClients_=0;
double TotalConnectedDeviceTime_=0.0;
double TotalConnectedClientTime_=0.0;
std::atomic_uint64_t Started_=OpenWifi::Now();
std::atomic_uint64_t MaxConcurrentSessions_=0;
explicit RTTYS_server() noexcept:
SubSystemServer("RTTY_Server", "RTTY-SVR", "rtty.server")

View File

@@ -1,52 +0,0 @@
//
// Created by stephane bourque on 2022-07-16.
//
#pragma once
#include "framework/MicroService.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
namespace OpenWifi::SDK::Prov {
inline bool GetSerialNumbersForVenueOfSerialNumber( const std::string & SerialNumber, Types::UUID_t &Venue, Types::StringVec & AdjacentSerialNumbers , Poco::Logger &Logger ) {
OpenAPIRequestGet GetInventoryForSerialNumber( uSERVICE_PROVISIONING, "/api/v1/inventory/" + SerialNumber , {} , 30000);
auto CallResponse1 = Poco::makeShared<Poco::JSON::Object>();
if(!GetInventoryForSerialNumber.Do(CallResponse1,"")) {
Logger.error(fmt::format("{}: Cannot find serial number in inventory.", SerialNumber));
return false;
}
ProvObjects::InventoryTag Device;
if(!Device.from_json(CallResponse1)) {
Logger.error(fmt::format("{}: Invalid Inventory response.", SerialNumber));
return false;
}
Venue = Device.venue;
OpenAPIRequestGet GetInventoryForVenue( uSERVICE_PROVISIONING, "/api/v1/inventory" ,
{
{"serialOnly","true"},
{"venue", Venue}
}, 30000);
auto CallResponse2 = Poco::makeShared<Poco::JSON::Object>();
if(!GetInventoryForVenue.Do(CallResponse2,"")) {
Logger.error(fmt::format("{}: Cannot get inventory for venue.", SerialNumber));
return false;
}
try {
OpenWifi::RESTAPI_utils::field_from_json(CallResponse2, "serialNumbers",
AdjacentSerialNumbers);
} catch(...) {
Logger.error(fmt::format("{}: Cannot parse inventory list", SerialNumber));
return false;
}
return true;
}
}

Some files were not shown because too many files have changed in this diff Show More