Compare commits

...

44 Commits

Author SHA1 Message Date
TIP Automation User
7fc16581c7 Chg: update image tag in helm values to v2.7.0 2022-10-05 11:32:52 +00:00
TIP Automation User
2244e20be2 Chg: update image tag in helm values to v2.7.0-RC5 2022-10-05 02:45:53 +00:00
jaspreetsachdev
129458f7b6 Merge pull request #68 from Telecominfraproject/main
Fix for WIFI-10942
2022-10-04 22:43:00 -04:00
stephb9959
c187710ddf Merge remote-tracking branch 'origin/main' 2022-10-04 08:17:26 -07:00
stephb9959
c04a0c47ba https://telecominfraproject.atlassian.net/browse/WIFI-10942
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-10-04 08:17:14 -07:00
Dmitry Dunaev
8e16986e2d Merge pull request #67 from Telecominfraproject/main
[WIFI-10581] Fix: securityContext fsGroup in helm
2022-10-03 15:52:04 +03:00
Dmitry Dunaev
7492e68a73 [WIFI-10581] Fix: securityContext fsGroup in helm
Signed-off-by: Dmitry Dunaev <dmitry@opsfleet.com>
2022-10-03 15:51:35 +03:00
TIP Automation User
3df36a2e9d Chg: update image tag in helm values to v2.7.0-RC4 2022-10-03 11:14:20 +00:00
Dmitry Dunaev
c74507948d Merge pull request #66 from Telecominfraproject/main
[WIFI-10581] Add: postgresql-client in Dockerfile
2022-10-03 14:05:18 +03:00
Dmitry Dunaev
912903cc49 [WIFI-10581] Fix: Helm image to main
Signed-off-by: Dmitry Dunaev <dmitry@opsfleet.com>
2022-10-03 12:10:40 +03:00
Dmitry Dunaev
2a1cc8dc2a Merge pull request #65 from Telecominfraproject/fix/wifi-10581--postgres-client
[WIFI-10581] Add: postgresql-client in Dockerfile
2022-10-03 11:23:42 +03:00
Dmitry Dunaev
4e344eac03 [WIFI-10581] Add: postgresql-client in Dockerfile
Signed-off-by: Dmitry Dunaev <dmitry@opsfleet.com>
2022-10-03 11:23:28 +03:00
Stephane Bourque
838b6d016c Merge pull request #63 from Telecominfraproject/main
https://telecominfraproject.atlassian.net/browse/WIFI-10942
2022-10-02 23:07:17 -07:00
Stephane Bourque
9be24a146d Merge pull request #64 from Telecominfraproject/WIFI-10942
https://telecominfraproject.atlassian.net/browse/WIFI-10942
2022-10-02 23:05:55 -07:00
Stephane Bourque
2b9e934ac1 https://telecominfraproject.atlassian.net/browse/WIFI-10942 2022-10-02 23:05:15 -07:00
Stephane Bourque
db5dffe2b8 Merge branch 'release/v2.7.0' into main 2022-10-02 11:16:51 -07:00
Stephane Bourque
e527983fa6 Merge pull request #62 from Telecominfraproject/WIFI-10942
https://telecominfraproject.atlassian.net/browse/WIFI-10942
2022-10-02 11:14:56 -07:00
Stephane Bourque
e0ef8d1dbf Merge branch 'main' into WIFI-10942 2022-10-02 11:14:49 -07:00
Stephane Bourque
bc1a2b2ab8 https://telecominfraproject.atlassian.net/browse/WIFI-10942 2022-10-02 11:13:20 -07:00
Stephane Bourque
06da583a6d Merge pull request #61 from Telecominfraproject/WIFI-10942
https://telecominfraproject.atlassian.net/browse/WIFI-10942
2022-10-02 11:12:41 -07:00
Stephane Bourque
39e8fbc863 https://telecominfraproject.atlassian.net/browse/WIFI-10942 2022-10-02 11:11:34 -07:00
Stephane Bourque
88adcf6e78 Merge pull request #51 from Telecominfraproject/WIFI-10581-switch-images-to-debian-slim
[WIFI-10581] Switch microservice Docker images from Alpine to Debian-slim
2022-10-02 11:06:57 -07:00
TIP Automation User
dc6455813a Chg: update image tag in helm values to v2.7.0-RC3 2022-09-30 16:31:31 +00:00
Stephane Bourque
fed5739afc Merge pull request #60 from Telecominfraproject/WIFI-10942
https://telecominfraproject.atlassian.net/browse/WIFI-10942
2022-09-30 08:54:24 -07:00
stephb9959
f2fd761558 https://telecominfraproject.atlassian.net/browse/WIFI-10942 2022-09-30 08:52:34 -07:00
TIP Automation User
139c3ba217 Chg: update image tag in helm values to v2.7.0-RC2 2022-09-29 23:27:35 +00:00
jaspreetsachdev
ec8d304ae7 Merge pull request #59 from Telecominfraproject/main
Fixes for WIFI-10245
2022-09-29 19:18:39 -04:00
Dmitry Dunaev
578580ad95 Merge pull request #58 from Telecominfraproject/feature/wifi-10932--docker-support-http
[WIFI-10932] Add: restapi disable property in docker entrypoint
2022-09-28 17:33:39 +03:00
Dmitry Dunaev
5e719c9b90 [WIFI-10932] Add: restapi disable property in docker entrypoint
Signed-off-by: Dmitry Dunaev <dmitry@opsfleet.com>
2022-09-28 17:33:15 +03:00
Dmitry Dunaev
96b59c700a Merge pull request #57 from Telecominfraproject/feature/wifi-10582--helm-global-cert-secret
[WIFI-10582] Add: functionality to use external existing certificates secret
2022-09-28 17:06:18 +03:00
Dmitry Dunaev
bbaa5da556 [WIFI-10582] Add: functionality to use external existing certificates secret
Signed-off-by: Dmitry Dunaev <dmitry@opsfleet.com>
2022-09-28 13:32:28 +03:00
Stephane Bourque
5df2701c21 Merge pull request #56 from Telecominfraproject/WIFI-10900
https://telecominfraproject.atlassian.net/browse/WIFI-10900
2022-09-22 21:32:15 -07:00
stephb9959
ebd890dc79 https://telecominfraproject.atlassian.net/browse/WIFI-10900
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-09-22 21:31:08 -07:00
Stephane Bourque
23729bdde0 Merge pull request #55 from Telecominfraproject/WIFI-10900
https://telecominfraproject.atlassian.net/browse/WIFI-10900
2022-09-22 20:37:26 -07:00
stephb9959
f02d932059 https://telecominfraproject.atlassian.net/browse/WIFI-10900
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-09-22 20:36:59 -07:00
Stephane Bourque
c450328e05 Merge pull request #54 from Telecominfraproject/WIFI-10900
https://telecominfraproject.atlassian.net/browse/WIFI-10900
2022-09-22 07:47:42 -07:00
stephb9959
cf461eadb0 https://telecominfraproject.atlassian.net/browse/WIFI-10900
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-09-22 07:40:01 -07:00
stephb9959
73ee40acde https://telecominfraproject.atlassian.net/browse/WIFI-10900
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-09-22 07:23:07 -07:00
Dmitry Dunaev
acd5800206 Revert: "https://telecominfraproject.atlassian.net/browse/WIFI-10245"
This reverts commit 892a756aae.
2022-09-22 14:27:15 +03:00
Stephane Bourque
c5b613ecff Merge pull request #53 from Telecominfraproject/WIFI-10245
https://telecominfraproject.atlassian.net/browse/WIFI-10245
2022-09-21 19:45:55 -07:00
stephb9959
892a756aae https://telecominfraproject.atlassian.net/browse/WIFI-10245
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-09-21 19:45:15 -07:00
Johann Hoffmann
8b37fe2c8c Fix self-signed cert file extension for Debian
Signed-off-by: Johann Hoffmann <johann.hoffmann@mailbox.org>
2022-08-19 17:19:58 +02:00
Johann Hoffmann
66433efb61 Create necessary library links in Docker image
Signed-off-by: Johann Hoffmann <johann.hoffmann@mailbox.org>
2022-08-19 16:13:43 +02:00
Johann Hoffmann
085aa109c3 Switch to Debian-slim base images
Signed-off-by: Johann Hoffmann <johann.hoffmann@mailbox.org>
2022-08-18 18:07:06 +02:00
27 changed files with 577 additions and 221 deletions

View File

@@ -59,6 +59,8 @@ 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)
add_definitions(-DPOCO_LOG_DEBUG="1")
if(ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
@@ -74,7 +76,9 @@ add_executable( owfms
src/framework/orm.h
src/framework/StorageClass.h
src/framework/ow_constants.h
src/framework/MicroServiceErrorHandler.h
src/framework/WebSocketClientNotifications.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

View File

@@ -1,18 +1,17 @@
ARG ALPINE_VERSION=3.16.2
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
ARG AWS_SDK_VERSION=1.9.315
FROM alpine:$ALPINE_VERSION AS build-base
FROM debian:$DEBIAN_VERSION AS build-base
RUN apk add --update --no-cache \
RUN apt-get update && apt-get install --no-install-recommends -y \
make cmake g++ git \
unixodbc-dev postgresql-dev mariadb-dev \
librdkafka-dev boost-dev openssl-dev \
zlib-dev nlohmann-json \
curl-dev
libpq-dev libmariadb-dev libmariadbclient-dev-compat \
librdkafka-dev libboost-all-dev libssl-dev \
zlib1g-dev nlohmann-json3-dev ca-certificates libcurl4-openssl-dev
FROM build-base AS poco-build
@@ -82,6 +81,9 @@ RUN mkdir cmake-build
WORKDIR cmake-build
RUN cmake .. -DBUILD_ONLY="sns;s3" \
-DCMAKE_BUILD_TYPE=Release \
-DUSE_OPENSSL=ON \
-DCPP_STANDARD=17 \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_CXX_FLAGS="-Wno-error=stringop-overflow -Wno-error=uninitialized" \
-DAUTORUN_UNIT_TESTS=OFF
RUN cmake --build . --config Release -j8
@@ -108,26 +110,24 @@ COPY --from=fmtlib-build /usr/local/lib /usr/local/lib
WORKDIR /owfms
RUN mkdir cmake-build
WORKDIR /owfms/cmake-build
RUN cmake .. \
-Dcrypto_LIBRARY=/usr/lib/libcrypto.so \
-DBUILD_SHARED_LIBS=ON
RUN cmake ..
RUN cmake --build . --config Release -j8
FROM alpine:$ALPINE_VERSION
FROM debian:$DEBIAN_VERSION
ENV OWFMS_USER=owfms \
OWFMS_ROOT=/owfms-data \
OWFMS_CONFIG=/owfms-data
RUN addgroup -S "$OWFMS_USER" && \
adduser -S -G "$OWFMS_USER" "$OWFMS_USER"
RUN useradd "$OWFMS_USER"
RUN mkdir /openwifi
RUN mkdir -p "$OWFMS_ROOT" "$OWFMS_CONFIG" && \
chown "$OWFMS_USER": "$OWFMS_ROOT" "$OWFMS_CONFIG"
RUN apk add --update --no-cache librdkafka su-exec gettext ca-certificates bash jq curl \
mariadb-connector-c libpq unixodbc postgresql-client
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
COPY readiness_check /readiness_check
COPY test_scripts/curl/cli /cli
@@ -136,7 +136,7 @@ COPY owfms.properties.tmpl /
COPY docker-entrypoint.sh /
COPY wait-for-postgres.sh /
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.pem
-O /usr/local/share/ca-certificates/restapi-ca-selfsigned.crt
COPY --from=owfms-build /owfms/cmake-build/owfms /openwifi/owfms
COPY --from=cppkafka-build /cppkafka/cmake-build/src/lib/* /usr/local/lib
@@ -145,6 +145,8 @@ COPY --from=aws-sdk-cpp-build /aws-sdk-cpp/cmake-build/aws-cpp-sdk-core/libaws-c
COPY --from=aws-sdk-cpp-build /aws-sdk-cpp/cmake-build/aws-cpp-sdk-s3/libaws-cpp-sdk-s3.so /usr/local/lib
COPY --from=aws-sdk-cpp-build /aws-sdk-cpp/cmake-build/aws-cpp-sdk-sns/libaws-cpp-sdk-sns.so /usr/local/lib
RUN ldconfig
EXPOSE 16004 17004 16104
ENTRYPOINT ["/docker-entrypoint.sh"]

2
build
View File

@@ -1 +1 @@
6
18

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -e
if [ "$SELFSIGNED_CERTS" = 'true' ]; then
@@ -22,6 +22,7 @@ if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
SYSTEM_URI_PRIVATE=${SYSTEM_URI_PRIVATE:-"https://localhost:17004"} \
SYSTEM_URI_PUBLIC=${SYSTEM_URI_PUBLIC:-"https://localhost:16004"} \
SYSTEM_URI_UI=${SYSTEM_URI_UI:-"http://localhost"} \
SECURITY_RESTAPI_DISABLE=${SECURITY_RESTAPI_DISABLE:-"false"} \
S3_BUCKETNAME=${S3_BUCKETNAME:-"ucentral-ap-firmware"} \
S3_REGION=${S3_REGION:-"us-east-1"} \
S3_SECRET=${S3_SECRET:-"*******************************************"} \
@@ -51,7 +52,7 @@ if [ "$1" = '/openwifi/owfms' -a "$(id -u)" = '0' ]; then
if [ "$RUN_CHOWN" = 'true' ]; then
chown -R "$OWFMS_USER": "$OWFMS_ROOT" "$OWFMS_CONFIG"
fi
exec su-exec "$OWFMS_USER" "$@"
exec gosu "$OWFMS_USER" "$@"
fi
exec "$@"

View File

@@ -70,7 +70,8 @@ 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 Firmware | |
| configProperties | hash | Configuration properties that should be passed to the application in `owfms.properties`. May be passed by key in set (i.e. `configProperties."rtty\.token"`) | |
| certs | hash | Defines files (keys and certificates) that should be passed to the Firmware (PEM format is adviced to be used) (see `volumes.owfms` on where it is mounted) | |
| 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.owfms` on where it is mounted). If `existingCertsSecret` is set, certificates passed this way will not be used. | |
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,

View File

@@ -131,8 +131,10 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.securityContext }}
securityContext:
fsGroup: 101
{{- toYaml . | nindent 8 }}
{{- end }}
imagePullSecrets:
{{- range $image, $imageValue := .Values.images }}

View File

@@ -9,7 +9,7 @@ fullnameOverride: ""
images:
owfms:
repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owfms
tag: v2.7.0-RC1
tag: v2.7.0
pullPolicy: Always
# regcred:
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io
@@ -71,7 +71,7 @@ volumes:
mountPath: /owfms-data/certs
volumeDefinition: |
secret:
secretName: {{ include "owfms.fullname" . }}-certs
secretName: {{ if .Values.existingCertsSecret }}{{ .Values.existingCertsSecret }}{{ else }}{{ include "owfms.fullname" . }}-certs{{ end }}
# Change this if you want to use another volume type
- name: persist
mountPath: /owfms-data/persist
@@ -91,6 +91,9 @@ resources: {}
# cpu: 100m
# memory: 128Mi
securityContext:
fsGroup: 1000
nodeSelector: {}
tolerations: []
@@ -207,6 +210,9 @@ 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:
# restapi-ca.pem: ""
# restapi-cert.pem: ""

View File

@@ -35,6 +35,7 @@ openwifi.system.uri.private = https://localhost:17004
openwifi.system.uri.public = https://ucentral.dpaas.arilia.com:16004
openwifi.system.commandchannel = /tmp/app.owfms
openwifi.system.uri.ui = ucentral-ui.arilia.com
openwifi.security.restapi.disable = false
firmwaredb.refresh = 1800
firmwaredb.maxage = 90

View File

@@ -36,6 +36,8 @@ openwifi.system.uri.private = ${SYSTEM_URI_PRIVATE}
openwifi.system.uri.public = ${SYSTEM_URI_PUBLIC}
openwifi.system.commandchannel = /tmp/app.ucentralfms
openwifi.system.uri.ui = ${SYSTEM_URI_UI}
openwifi.security.restapi.disable = ${SECURITY_RESTAPI_DISABLE}
firmwaredb.refresh = 1800
firmwaredb.maxage = 90

View File

@@ -11,6 +11,7 @@
namespace OpenWifi {
int AutoUpdater::Start() {
poco_information(Logger(),"Starting...");
AutoUpdaterEnabled_ = MicroService::instance().ConfigGetBool("autoupdater.enabled", false);
if(AutoUpdaterEnabled_) {
Running_ = false;
@@ -24,10 +25,12 @@ namespace OpenWifi {
}
void AutoUpdater::Stop() {
poco_information(Logger(),"Stopping...");
Running_ = false;
if(AutoUpdaterEnabled_) {
Timer_.stop();
}
poco_information(Logger(),"Stopped...");
}
void AutoUpdater::ToBeUpgraded(std::string serialNumber, std::string DeviceType) {
@@ -45,7 +48,7 @@ namespace OpenWifi {
auto Entry = Queue_.front();
Queue_.pop_front();
try {
Logger().debug(fmt::format("Preparing to upgrade {}",Entry.first));
poco_debug(Logger(),fmt::format("Preparing to upgrade {}",Entry.first));
auto CacheEntry = Cache_.find(Entry.first);
uint64_t now = OpenWifi::Now();
std::string firmwareUpgrade;
@@ -55,11 +58,11 @@ namespace OpenWifi {
C.LastCheck = now;
bool firmwareRCOnly;
if(OpenWifi::SDK::Prov::GetFirmwareOptions(Entry.first, firmwareUpgrade, firmwareRCOnly)) {
Logger().debug(fmt::format("Found firmware options for {}",Entry.first));
poco_debug(Logger(),fmt::format("Found firmware options for {}",Entry.first));
C.firmwareRCOnly = firmwareRCOnly;
C.firmwareUpgrade = firmwareUpgrade;
} else {
Logger().debug(fmt::format("Found no firmware options for {}",Entry.first));
poco_debug(Logger(),fmt::format("Found no firmware options for {}",Entry.first));
C.firmwareRCOnly = firmwareRCOnly;
C.firmwareUpgrade = firmwareUpgrade;
}
@@ -69,7 +72,7 @@ namespace OpenWifi {
}
if(firmwareUpgrade=="no") {
Logger().information(fmt::format("Device {} not upgradable. Provisioning service settings.",Entry.first));
poco_information(Logger(),fmt::format("Device {} not upgradable. Provisioning service settings.",Entry.first));
continue;
}
@@ -79,26 +82,26 @@ namespace OpenWifi {
if(LF) {
if(StorageService()->FirmwaresDB().GetFirmware(fwEntry.Id,fwDetails)) {
// send the command to upgrade this device...
Logger().information(fmt::format("Upgrading {} to version {}", Entry.first, fwEntry.Revision));
poco_information(Logger(),fmt::format("Upgrading {} to version {}", Entry.first, fwEntry.Revision));
if(OpenWifi::SDK::GW::SendFirmwareUpgradeCommand(Entry.first,fwDetails.uri)) {
Logger().information(fmt::format("Upgrade command sent for {}",Entry.first));
poco_information(Logger(),fmt::format("Upgrade command sent for {}",Entry.first));
} else {
Logger().information(fmt::format("Upgrade command not sent for {}",Entry.first));
poco_information(Logger(),fmt::format("Upgrade command not sent for {}",Entry.first));
}
} else {
Logger().information(fmt::format("Firmware for device {} ({}) cannot be found.", Entry.first, Entry.second ));
poco_information(Logger(),fmt::format("Firmware for device {} ({}) cannot be found.", Entry.first, Entry.second ));
}
} else {
Logger().information(fmt::format("Firmware for device {} ({}) cannot be found.", Entry.first, Entry.second ));
poco_information(Logger(),fmt::format("Firmware for device {} ({}) cannot be found.", Entry.first, Entry.second ));
}
} catch (...) {
Logger().information(fmt::format("Exception during auto update for device {}.", Entry.first ));
poco_information(Logger(),fmt::format("Exception during auto update for device {}.", Entry.first ));
}
}
}
void AutoUpdater::reinitialize([[maybe_unused]] Poco::Util::Application &self) {
Logger().information("Reinitializing.");
poco_information(Logger(),"Reinitializing.");
Reset();
}
}

View File

@@ -7,10 +7,13 @@
namespace OpenWifi {
int DeviceCache::Start() {
poco_information(Logger(),"Starting...");
return 0;
}
void DeviceCache::Stop() {
poco_information(Logger(),"Stopping...");
poco_information(Logger(),"Stopped...");
}
void DeviceCache::AddToCache(

View File

@@ -7,11 +7,13 @@
namespace OpenWifi {
int FirmwareCache::Start() {
poco_information(Logger(),"Starting...");
return 0;
}
void FirmwareCache::Stop() {
poco_information(Logger(),"Stopping...");
poco_information(Logger(),"Stopped...");
}
std::shared_ptr<FMSObjects::Firmware> GetFirmware([[maybe_unused]] const std::string & DeviceType, [[maybe_unused]] const std::string & Revision) {

View File

@@ -8,11 +8,14 @@
namespace OpenWifi {
int LatestFirmwareCache::Start() {
poco_information(Logger(),"Starting...");
StorageService()->FirmwaresDB().PopulateLatestFirmwareCache();
return 0;
}
void LatestFirmwareCache::Stop() {
poco_information(Logger(),"Stopping...");
poco_information(Logger(),"Stopped...");
}
bool LatestFirmwareCache::AddToCache(const std::string & DeviceType, const std::string &Revision, const std::string &Id, uint64_t TimeStamp) {

View File

@@ -57,7 +57,7 @@ namespace OpenWifi {
Types::StringSet RevisionSet_;
Types::StringSet DeviceSet_;
explicit LatestFirmwareCache() noexcept:
SubSystemServer("FirmwareCache", "FIRMWARE-CACHE", "FirmwareCache")
SubSystemServer("LatestFirmwareCache", "LATEST-FIRMWARE-CACHE", "LatestFirmwareCache")
{
}
};

View File

@@ -18,11 +18,11 @@ namespace OpenWifi {
void ManifestCreator::onTimer([[maybe_unused]] Poco::Timer &timer) {
Utils::SetThreadName("manifest");
Logger().information("Performing DB refresh");
poco_information(Logger(),"Performing DB refresh");
S3BucketContent BucketList;
StorageService()->FirmwaresDB().RemoveOldFirmware();
ReadBucket(BucketList);
Logger().information(fmt::format("Found {} firmware entries in S3 repository.", BucketList.size()));
poco_information(Logger(),fmt::format("Found {} firmware entries in S3 repository.", BucketList.size()));
ComputeManifest(BucketList);
AddManifestToDB(BucketList);
}
@@ -49,7 +49,7 @@ namespace OpenWifi {
Entry.Image = ParsedContent->get("image").toString();
auto FullNme = Name + "-upgrade.bin";
if(FullNme!=Entry.Image) {
Logger().error(fmt::format("MANIFEST({}): Image name does not match manifest name ({}).",Name,Entry.Image));
poco_error(Logger(),fmt::format("MANIFEST({}): Image name does not match manifest name ({}).",Name,Entry.Image));
Entry.Valid = false;
BadFormat++;
continue;
@@ -61,7 +61,7 @@ namespace OpenWifi {
Entry.Valid = false;
}
} else {
Logger().error(fmt::format("MANIFEST({}): Entry does not have a valid JSON manifest.",Name));
poco_error(Logger(),fmt::format("MANIFEST({}): Entry does not have a valid JSON manifest.",Name));
MissingJson++;
Entry.Valid = false;
}
@@ -70,10 +70,10 @@ namespace OpenWifi {
}
}
Logger().information(fmt::format("Accepted {} firmwares.", Accepted));
Logger().information(fmt::format("Rejected {} too old firmwares.", Rejected));
Logger().information(fmt::format("Rejected {} bad JSON.", BadFormat));
Logger().information(fmt::format("Rejected {} missing JSON.", MissingJson));
poco_information(Logger(),fmt::format("Accepted {} firmwares.", Accepted));
poco_information(Logger(),fmt::format("Rejected {} too old firmwares.", Rejected));
poco_information(Logger(),fmt::format("Rejected {} bad JSON.", BadFormat));
poco_information(Logger(),fmt::format("Rejected {} missing JSON.", MissingJson));
return true;
}
@@ -99,7 +99,7 @@ namespace OpenWifi {
F.revision = BucketEntry.Revision;
F.deviceType = BucketEntry.Compatible;
if(StorageService()->FirmwaresDB().AddFirmware(F)) {
Logger().information(fmt::format("Adding firmware '{}', size={}",Release,F.size));
poco_information(Logger(),fmt::format("Adding firmware '{}', size={}",Release,F.size));
} else {
}
}
@@ -185,7 +185,7 @@ namespace OpenWifi {
while(!isDone) {
Outcome = S3Client.ListObjectsV2(Request);
if(!Outcome.IsSuccess()) {
Logger().error(fmt::format("Error while doing ListObjectsV2: {}, {}",
poco_error(Logger(),fmt::format("Error while doing ListObjectsV2: {}, {}",
std::string{Outcome.GetError().GetExceptionName()},
std::string{Outcome.GetError().GetMessage()}));
return false;
@@ -281,7 +281,7 @@ namespace OpenWifi {
// std::cout << "Count:" << Count << " Runs:" << Runs << std::endl;
if(!Outcome.IsSuccess()) {
Logger().error(fmt::format("Error while doing ListObjectsV2: {}, {}",
poco_error(Logger(),fmt::format("Error while doing ListObjectsV2: {}, {}",
std::string{Outcome.GetError().GetExceptionName()},
std::string{Outcome.GetError().GetMessage()}));
return false;

View File

@@ -46,9 +46,9 @@ namespace OpenWifi {
if(Command=="delete_device") {
auto pSerialNumber = PayloadSection["payload"]["serialNumber"];
if(pSerialNumber==SerialNumber) {
Logger().debug(fmt::format("Removing device '{}' from upgrade history.",SerialNumber));
poco_debug(Logger(),fmt::format("Removing device '{}' from upgrade history.",SerialNumber));
StorageService()->HistoryDB().DeleteHistory(SerialNumber);
Logger().debug(fmt::format("Removing device '{}' from device table.",SerialNumber));
poco_debug(Logger(),fmt::format("Removing device '{}' from device table.",SerialNumber));
StorageService()->DevicesDB().DeleteDevice(SerialNumber);
}
}

View File

@@ -68,12 +68,12 @@ namespace OpenWifi {
if(StorageService()->FirmwaresDB().ComputeFirmwareAge(DeviceType, Revision, FA)) {
StorageService()->DevicesDB().SetDeviceRevision(SerialNumber, Revision, DeviceType, EndPoint);
if(FA.age)
Logger().information(fmt::format("Device {} connection. Firmware is {} older than latest.",SerialNumber, Utils::SecondsToNiceText(FA.age)));
poco_information(Logger(),fmt::format("Device {} connection. Firmware is {} older than latest.",SerialNumber, Utils::SecondsToNiceText(FA.age)));
else
Logger().information(fmt::format("Device {} connection. Device firmware is up to date.",SerialNumber));
poco_information(Logger(),fmt::format("Device {} connection. Device firmware is up to date.",SerialNumber));
}
else {
Logger().information(fmt::format("Device {} connection. Firmware age cannot be determined.",SerialNumber));
poco_information(Logger(),fmt::format("Device {} connection. Firmware age cannot be determined.",SerialNumber));
}
if(!LatestFirmwareCache()->IsLatest(DeviceType, Revision)) {
@@ -116,6 +116,7 @@ namespace OpenWifi {
};
int NewConnectionHandler::Start() {
poco_information(Logger(),"Starting...");
Types::TopicNotifyFunction F = [this](std::string s1,std::string s2) { this->ConnectionReceived(s1,s2); };
ConnectionWatcherId_ = KafkaManager()->RegisterTopicWatcher(KafkaTopics::CONNECTION, F);
Worker_.start(*this);
@@ -123,10 +124,12 @@ namespace OpenWifi {
};
void NewConnectionHandler::Stop() {
poco_information(Logger(),"Stopping...");
KafkaManager()->UnregisterTopicWatcher(KafkaTopics::CONNECTION, ConnectionWatcherId_);
Running_ = false;
Worker_.wakeUp();
Worker_.join();
poco_information(Logger(),"Stopped...");
};
bool NewConnectionHandler::Update() {

View File

@@ -203,6 +203,10 @@ 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:
@@ -218,6 +222,21 @@ namespace OpenWifi::GWObjects {
}
}
void DeviceConnectionStatistics::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj,"averageConnectionTime", averageConnectionTime);
field_to_json(Obj,"connectedDevices", connectedDevices );
}
bool DeviceConnectionStatistics::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj,"averageConnectionTime", averageConnectionTime);
field_from_json(Obj,"connectedDevices", connectedDevices );
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);
@@ -293,7 +312,6 @@ namespace OpenWifi::GWObjects {
} catch (const Poco::Exception &E) {
}
return false;
}
void RadiusProxyPoolList::to_json(Poco::JSON::Object &Obj) const {
@@ -314,6 +332,8 @@ 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) {
@@ -322,6 +342,8 @@ 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) {
}
@@ -329,7 +351,7 @@ namespace OpenWifi::GWObjects {
}
void RadiusProxyServerConfig::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj,"policy",strategy);
field_to_json(Obj,"strategy",strategy);
field_to_json(Obj,"monitor",monitor);
field_to_json(Obj,"monitorMethod",monitorMethod);
field_to_json(Obj,"methodParameters",methodParameters);
@@ -338,7 +360,7 @@ namespace OpenWifi::GWObjects {
bool RadiusProxyServerConfig::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj,"policy",strategy);
field_from_json(Obj,"strategy",strategy);
field_from_json(Obj,"monitor",monitor);
field_from_json(Obj,"monitorMethod",monitorMethod);
field_from_json(Obj,"methodParameters",methodParameters);
@@ -354,6 +376,16 @@ 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) {
@@ -362,6 +394,16 @@ 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,6 +38,10 @@ 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;
};
@@ -71,6 +75,13 @@ namespace OpenWifi::GWObjects {
void Print() const;
};
struct DeviceConnectionStatistics {
std::uint64_t connectedDevices = 0;
std::uint64_t averageConnectionTime = 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 ;
@@ -216,6 +227,16 @@ 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);
@@ -237,6 +258,8 @@ 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

@@ -11,6 +11,7 @@
namespace OpenWifi {
int Storage::Start() {
poco_information(Logger(),"Starting...");
std::lock_guard Guard(Mutex_);
StorageClass::Start();
@@ -27,9 +28,10 @@ namespace OpenWifi {
}
void Storage::Stop() {
poco_information(Logger(),"Stopping...");
std::lock_guard Guard(Mutex_);
Logger().notice("Stopping.");
StorageClass::Stop();
poco_information(Logger(),"Stopped...");
}
std::string Storage::TrimRevision(const std::string &R) {

View File

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

View File

@@ -23,6 +23,13 @@
#include <queue>
#include <variant>
// This must be defined for poco_debug and poco_trace macros to function.
#ifndef POCO_LOG_DEBUG
#define POCO_LOG_DEBUG true
#endif
namespace OpenWifi {
inline uint64_t Now() { return std::time(nullptr); };
}
@@ -89,8 +96,10 @@ using namespace std::chrono_literals;
#include "Poco/NObserver.h"
#include "Poco/Net/SocketNotification.h"
#include "Poco/Base64Decoder.h"
#include "Poco/ThreadLocal.h"
#include "cppkafka/cppkafka.h"
#include "framework/MicroServiceErrorHandler.h"
#include "framework/OpenWifiTypes.h"
#include "framework/KafkaTopics.h"
#include "framework/ow_constants.h"
@@ -660,6 +669,19 @@ namespace OpenWifi::RESTAPI_utils {
namespace OpenWifi::Utils {
inline bool NormalizeMac(std::string & Mac) {
Poco::replaceInPlace(Mac,":","");
Poco::replaceInPlace(Mac,"-","");
if(Mac.size()!=12)
return false;
for(const auto &i:Mac) {
if(!std::isxdigit(i))
return false;
}
Poco::toLowerInPlace(Mac);
return true;
}
inline void SetThreadName(const char *name) {
#ifdef __linux__
Poco::Thread::current()->setName(name);
@@ -1339,36 +1361,19 @@ namespace OpenWifi {
Poco::ExpireLRUCache<KeyType,Record> Cache_{Size,Expiry};
};
class MyErrorHandler : public Poco::ErrorHandler {
public:
explicit MyErrorHandler(Poco::Util::Application &App) : App_(App) {}
inline void exception(const Poco::Exception & E) {
Poco::Thread * CurrentThread = Poco::Thread::current();
App_.logger().log(E);
App_.logger().error(fmt::format("Exception occurred in {}",CurrentThread->getName()));
}
inline void exception(const std::exception & E) {
Poco::Thread * CurrentThread = Poco::Thread::current();
App_.logger().warning(fmt::format("std::exception in {}: {}",CurrentThread->getName(),E.what()));
}
inline void exception() {
Poco::Thread * CurrentThread = Poco::Thread::current();
App_.logger().warning(fmt::format("exception in {}",CurrentThread->getName()));
}
private:
Poco::Util::Application &App_;
};
class BusEventManager : public Poco::Runnable {
public:
explicit BusEventManager(Poco::Logger &L) : Logger_(L) {
}
inline void run() final;
inline void Start();
inline void Stop();
inline Poco::Logger & Logger() { return Logger_; }
private:
mutable std::atomic_bool Running_ = false;
Poco::Thread Thread_;
Poco::Logger &Logger_;
};
class MyPrivateKeyPassphraseHandler : public Poco::Net::PrivateKeyPassphraseHandler {
@@ -1382,6 +1387,7 @@ namespace OpenWifi {
Logger_.information("Returning key passphrase.");
privateKey = Password_;
};
inline Poco::Logger & Logger() { return Logger_; }
private:
std::string Password_;
Poco::Logger & Logger_;
@@ -1650,14 +1656,14 @@ namespace OpenWifi {
class SubSystemServer : public Poco::Util::Application::Subsystem {
public:
SubSystemServer(std::string Name, const std::string &LoggingPrefix,
std::string SubSystemConfigPrefix);
SubSystemServer(const std::string & Name, const std::string &LoggingPrefix,
const std::string & SubSystemConfigPrefix);
inline void initialize(Poco::Util::Application &self) override;
inline void uninitialize() override {
}
inline void reinitialize([[maybe_unused]] Poco::Util::Application &self) override {
Logger().information("Reloading of this subsystem is not supported.");
Logger_->L_.information("Reloading of this subsystem is not supported.");
}
inline void defineOptions([[maybe_unused]] Poco::Util::OptionSet &options) override {
}
@@ -1666,30 +1672,30 @@ namespace OpenWifi {
inline const PropertiesFileServerEntry & Host(uint64_t index) { return ConfigServersList_[index]; };
inline uint64_t HostSize() const { return ConfigServersList_.size(); }
inline Poco::Logger &Logger() { if(Log_)
return Log_->L;
return Poco::Logger::get("tmp");
};
inline void SetLoggingLevel(Poco::Message::Priority NewPriority) { Logger().setLevel(NewPriority); }
inline int GetLoggingLevel() { return Logger().getLevel(); }
inline Poco::Logger & Logger() const { return Logger_->L_; }
inline void SetLoggingLevel(const std::string & levelName) {
Logger_->L_.setLevel(Poco::Logger::parseLevel(levelName));
}
inline int GetLoggingLevel() { return Logger_->L_.getLevel(); }
virtual int Start() = 0;
virtual void Stop() = 0;
struct LoggerWrapper {
Poco::Logger &L;
explicit inline LoggerWrapper(Poco::Logger &Logger) : L(Logger) {}
};
struct LoggerWrapper {
Poco::Logger & L_;
LoggerWrapper(Poco::Logger &L) :
L_(L) {}
};
protected:
std::recursive_mutex Mutex_;
std::vector<PropertiesFileServerEntry> ConfigServersList_;
private:
std::unique_ptr<LoggerWrapper> Log_;
// Poco::Logger &Logger_;
std::string Name_;
std::string LoggerPrefix_;
std::string SubSystemConfigPrefix_;
std::unique_ptr<LoggerWrapper> Logger_;
std::string Name_;
std::string LoggerPrefix_;
std::string SubSystemConfigPrefix_;
};
class RESTAPI_GenericServer {
@@ -1823,7 +1829,7 @@ namespace OpenWifi {
E->Count++;
Cache_.update(H,E);
if(E->Count > MaxCalls) {
Logger().warning(fmt::format("RATE-LIMIT-EXCEEDED: from '{}'", R.clientAddress().toString()));
poco_warning(Logger(),fmt::format("RATE-LIMIT-EXCEEDED: from '{}'", R.clientAddress().toString()));
return true;
}
return false;
@@ -2165,12 +2171,16 @@ namespace OpenWifi {
SetCommonHeaders(CloseConnection);
}
inline void BadRequest(const OpenWifi::RESTAPI::Errors::msg &E) {
inline void BadRequest(const OpenWifi::RESTAPI::Errors::msg &E, const std::string & Extra="") {
PrepareResponse(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST);
Poco::JSON::Object ErrorObject;
ErrorObject.set("ErrorCode",400);
ErrorObject.set("ErrorDetails",Request->getMethod());
ErrorObject.set("ErrorDescription",fmt::format("{}: {}",E.err_num,E.err_txt)) ;
if(Extra.empty())
ErrorObject.set("ErrorDescription",fmt::format("{}: {}",E.err_num,E.err_txt)) ;
else
ErrorObject.set("ErrorDescription",fmt::format("{}: {} ({})",E.err_num,E.err_txt, Extra)) ;
std::ostream &Answer = Response->send();
Poco::JSON::Stringifier::stringify(ErrorObject, Answer);
}
@@ -2214,7 +2224,7 @@ namespace OpenWifi {
ErrorObject.set("ErrorDescription",fmt::format("{}: {}",E.err_num,E.err_txt)) ;
std::ostream &Answer = Response->send();
Poco::JSON::Stringifier::stringify(ErrorObject, Answer);
Logger_.debug(fmt::format("RES-NOTFOUND: User='{}@{}' Method='{}' Path='{}",
poco_debug(Logger_,fmt::format("RES-NOTFOUND: User='{}@{}' Method='{}' Path='{}",
UserInfo_.userinfo.email,
Utils::FormatIPv6(Request->clientAddress().toString()),
Request->getMethod(),
@@ -2446,6 +2456,7 @@ namespace OpenWifi {
Poco::Net::HTTPServerResponse *Response= nullptr;
SecurityObjects::UserInfoAndPolicy UserInfo_;
QueryBlock QB_;
const std::string & Requester() const { return REST_Requester_; }
protected:
BindingMap Bindings_;
Poco::URI::QueryParameters Parameters_;
@@ -2462,6 +2473,7 @@ namespace OpenWifi {
RateLimit MyRates_;
uint64_t TransactionId_;
Poco::JSON::Object::Ptr ParsedBody_;
std::string REST_Requester_;
};
class RESTAPI_UnknownRequestHandler : public RESTAPIHandler {
@@ -2781,9 +2793,11 @@ namespace OpenWifi {
inline void Stop() override {
if(KafkaEnabled_) {
poco_information(Logger(),"Stopping...");
Dispatcher_.Stop();
ProducerThr_.Stop();
ConsumerThr_.Stop();
poco_information(Logger(),"Stopped...");
return;
}
}
@@ -2861,12 +2875,13 @@ namespace OpenWifi {
}
inline void Stop() override {
poco_information(Logger(),"Stopping...");
std::lock_guard G(Mutex_);
Cache_.clear();
poco_information(Logger(),"Stopped...");
}
inline void RemovedCachedToken(const std::string &Token) {
std::lock_guard G(Mutex_);
Cache_.remove(Token);
}
@@ -2876,6 +2891,7 @@ namespace OpenWifi {
inline bool RetrieveTokenInformation(const std::string & SessionToken,
SecurityObjects::UserInfoAndPolicy & UInfo,
std::uint64_t TID,
bool & Expired, bool & Contacted, bool Sub=false) {
try {
Types::StringPairVec QueryData;
@@ -2901,7 +2917,6 @@ namespace OpenWifi {
return false;
}
Expired = false;
std::lock_guard G(Mutex_);
Cache_.update(SessionToken, UInfo);
return true;
} else {
@@ -2909,14 +2924,15 @@ namespace OpenWifi {
}
}
} catch (...) {
poco_error(Logger(),fmt::format("Failed to retrieve token={} for TID={}", SessionToken, TID));
}
Expired = false;
return false;
}
inline bool IsAuthorized(const std::string &SessionToken, SecurityObjects::UserInfoAndPolicy & UInfo,
std::uint64_t TID,
bool & Expired, bool & Contacted, bool Sub = false) {
std::lock_guard G(Mutex_);
auto User = Cache_.get(SessionToken);
if(!User.isNull()) {
if(IsTokenExpired(User->webtoken)) {
@@ -2927,7 +2943,7 @@ namespace OpenWifi {
UInfo = *User;
return true;
}
return RetrieveTokenInformation(SessionToken, UInfo, Expired, Contacted, Sub);
return RetrieveTokenInformation(SessionToken, UInfo, TID, Expired, Contacted, Sub);
}
private:
@@ -2945,12 +2961,12 @@ namespace OpenWifi {
{
}
void handleRequest(Poco::Net::HTTPServerRequest& Request, Poco::Net::HTTPServerResponse& Response) override
void handleRequest([[maybe_unused]] Poco::Net::HTTPServerRequest& Request, Poco::Net::HTTPServerResponse& Response) override
{
Utils::SetThreadName("alb-request");
try {
if((id_ % 100) == 0) {
Logger_.debug(fmt::format("ALB-REQUEST({}): ALB Request {}.",
poco_debug(Logger_,fmt::format("ALB-REQUEST({}): ALB Request {}.",
Request.clientAddress().toString(), id_));
}
Response.setChunkedTransferEncoding(true);
@@ -3008,8 +3024,10 @@ namespace OpenWifi {
inline int Start() override;
inline void Stop() override {
poco_information(Logger(),"Stopping...");
if(Running_)
Server_->stop();
Server_->stopAll(true);
poco_information(Logger(),"Stopped...");
}
private:
@@ -3038,12 +3056,14 @@ namespace OpenWifi {
inline void Stop() override {
Logger().information("Stopping...");
for( const auto & svr : RESTServers_ )
svr->stop();
svr->stopAll(true);
Pool_.stopAll();
Pool_.joinAll();
RESTServers_.clear();
Logger().information("Stopped...");
}
inline void reinitialize(Poco::Util::Application &self) override;
inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) {
@@ -3051,10 +3071,11 @@ namespace OpenWifi {
Utils::SetThreadName(fmt::format("x-rest:{}",Id).c_str());
return RESTAPI_ExtRouter(Path, Bindings, Logger(), Server_, Id);
}
const Poco::ThreadPool & Pool() { return Pool_; }
private:
std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_;
Poco::ThreadPool Pool_{"x-rest",2,32};
Poco::ThreadPool Pool_{"x-rest",8,128};
RESTAPI_GenericServer Server_;
RESTAPI_ExtServer() noexcept:
@@ -3071,15 +3092,16 @@ namespace OpenWifi {
inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override {
try {
Poco::URI uri(Request.getURI());
Utils::SetThreadName(fmt::format("x-rest:{}",TransactionId_).c_str());
return RESTAPI_ExtServer()->CallServer(uri.getPath(), TransactionId_++);
auto TID = NextTransactionId_++;
Utils::SetThreadName(fmt::format("x-rest:{}",TID).c_str());
return RESTAPI_ExtServer()->CallServer(uri.getPath(), TID);
} catch (...) {
}
return nullptr;
}
private:
static inline std::atomic_uint64_t TransactionId_ = 1;
static inline std::atomic_uint64_t NextTransactionId_ = 1;
};
class LogMuxer : public Poco::Channel {
@@ -3171,9 +3193,10 @@ namespace OpenWifi {
inline void Stop() override {
Logger().information("Stopping...");
for( const auto & svr : RESTServers_ )
svr->stop();
svr->stopAll(true);
Pool_.stopAll();
Pool_.joinAll();
Logger().information("Stopped...");
}
inline void reinitialize(Poco::Util::Application &self) override;
@@ -3183,9 +3206,10 @@ namespace OpenWifi {
Utils::SetThreadName(fmt::format("i-rest:{}",Id).c_str());
return RESTAPI_IntRouter(Path, Bindings, Logger(), Server_, Id);
}
const Poco::ThreadPool & Pool() { return Pool_; }
private:
std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_;
Poco::ThreadPool Pool_{"i-rest",2,16};
Poco::ThreadPool Pool_{"i-rest",4,64};
RESTAPI_GenericServer Server_;
RESTAPI_IntServer() noexcept:
@@ -3200,12 +3224,13 @@ namespace OpenWifi {
public:
inline IntRequestHandlerFactory() = default;
inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override {
Utils::SetThreadName(fmt::format("i-rest:{}",TransactionId_).c_str());
auto TID=NextTransactionId_++;
Utils::SetThreadName(fmt::format("i-rest:{}",TID).c_str());
Poco::URI uri(Request.getURI());
return RESTAPI_IntServer()->CallServer(uri.getPath(), TransactionId_);
return RESTAPI_IntServer()->CallServer(uri.getPath(), TID);
}
private:
static inline std::atomic_uint64_t TransactionId_ = 1;
static inline std::atomic_uint64_t NextTransactionId_ = 1;
};
struct MicroServiceMeta {
@@ -3266,7 +3291,7 @@ namespace OpenWifi {
return ((RandomEngine_() % (max-min)) + min);
}
inline Poco::Logger & GetLogger(const std::string &Name) {
/* inline Poco::Logger & GetLogger(const std::string &Name) {
static auto initialized = false;
if(!initialized) {
@@ -3275,7 +3300,7 @@ namespace OpenWifi {
}
return Poco::Logger::get(Name);
}
*/
virtual void GetExtraConfiguration(Poco::JSON::Object & Cfg) {
Cfg.set("additionalConfiguration",false);
}
@@ -3368,7 +3393,6 @@ namespace OpenWifi {
std::string MyPublicEndPoint_;
std::string UIURI_;
std::string Version_{ OW_VERSION::VERSION + "("+ OW_VERSION::BUILD + ")" + " - " + OW_VERSION::HASH };
BusEventManager BusEventManager_;
std::recursive_mutex InfraMutex_;
std::default_random_engine RandomEngine_;
Poco::Util::PropertyFileConfiguration * PropConfigurationFile_ = nullptr;
@@ -3382,7 +3406,8 @@ namespace OpenWifi {
bool NoBuiltInCrypto_=false;
Poco::JWT::Signer Signer_;
Poco::Logger &Logger_;
Poco::ThreadPool TimerPool_{"timer:pool",2,16};
Poco::ThreadPool TimerPool_{"timer:pool",2,32};
std::unique_ptr<BusEventManager> BusEventManager_;
};
inline void MicroService::Exit(int Reason) {
@@ -3463,7 +3488,7 @@ namespace OpenWifi {
}
} catch (const Poco::Exception &E) {
Logger_.log(E);
logger().log(E);
}
}
@@ -3546,7 +3571,7 @@ namespace OpenWifi {
auto LoggingDestination = MicroService::instance().ConfigGetString("logging.type", "file");
auto LoggingFormat = MicroService::instance().ConfigGetString("logging.format",
"%Y-%m-%d %H:%M:%S %s: [%p] %t");
"%Y-%m-%d %H:%M:%S.%i %s: [%p][thr:%I] %t");
if (LoggingDestination == "console") {
Poco::AutoPtr<Poco::ConsoleChannel> Console(new Poco::ConsoleChannel);
Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(Console));
@@ -3577,14 +3602,14 @@ namespace OpenWifi {
FileChannel->setProperty("archive", "timestamp");
FileChannel->setProperty("path", LoggingLocation);
Poco::AutoPtr<Poco::AsyncChannel> Async_File(new Poco::AsyncChannel(FileChannel));
Poco::AutoPtr<Poco::AsyncChannel> Async_Muxer(new Poco::AsyncChannel(LogMuxer()));
Poco::AutoPtr<Poco::SplitterChannel> Splitter(new Poco::SplitterChannel);
Splitter->addChannel(Async_File);
Splitter->addChannel(Async_Muxer);
// Poco::AutoPtr<Poco::AsyncChannel> Async_Muxer(new Poco::AsyncChannel(LogMuxer()));
// Poco::AutoPtr<Poco::SplitterChannel> Splitter(new Poco::SplitterChannel);
// Splitter->addChannel(Async_File);
// Splitter->addChannel(Async_Muxer);
Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter);
Formatter->setProperty("pattern", LoggingFormat);
Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(
new Poco::FormattingChannel(Formatter, Splitter));
new Poco::FormattingChannel(Formatter, Async_File));
Poco::Logger::root().setChannel(FormattingChannel);
}
auto Level = Poco::Logger::parseLevel(MicroService::instance().ConfigGetString("logging.level", "debug"));
@@ -3603,7 +3628,9 @@ namespace OpenWifi {
SubSystems_.push_back(ALBHealthCheckServer());
SubSystems_.push_back(RESTAPI_ExtServer());
SubSystems_.push_back(RESTAPI_IntServer());
#ifndef TIP_SECURITY_SERVICE
SubSystems_.push_back(AuthClient());
#endif
Poco::Net::initializeSSL();
Poco::Net::HTTPStreamFactory::registerFactory();
Poco::Net::HTTPSStreamFactory::registerFactory();
@@ -3714,8 +3741,9 @@ namespace OpenWifi {
}
inline void MicroService::InitializeSubSystemServers() {
for(auto i:SubSystems_)
addSubsystem(i);
for(auto i:SubSystems_) {
addSubsystem(i);
}
}
inline void MicroService::StartSubSystemServers() {
@@ -3723,12 +3751,13 @@ namespace OpenWifi {
for(auto i:SubSystems_) {
i->Start();
}
BusEventManager_.Start();
BusEventManager_ = std::make_unique<BusEventManager>(Poco::Logger::create("BusEventManager",Poco::Logger::root().getChannel(),Poco::Logger::root().getLevel()));
BusEventManager_->Start();
}
inline void MicroService::StopSubSystemServers() {
AddActivity("Stopping");
BusEventManager_.Stop();
BusEventManager_->Stop();
for(auto i=SubSystems_.rbegin(); i!=SubSystems_.rend(); ++i) {
(*i)->Stop();
}
@@ -3905,14 +3934,15 @@ namespace OpenWifi {
}
}
inline SubSystemServer::SubSystemServer(std::string Name, const std::string &LoggingPrefix,
std::string SubSystemConfigPrefix):
Name_(std::move(Name)),
LoggerPrefix_(LoggingPrefix),
SubSystemConfigPrefix_(std::move(SubSystemConfigPrefix)) {
inline SubSystemServer::SubSystemServer(const std::string &Name, const std::string &LoggingPrefix,
const std::string &SubSystemConfigPrefix):
Name_(Name),
LoggerPrefix_(LoggingPrefix),
SubSystemConfigPrefix_(SubSystemConfigPrefix) {
}
inline int RESTAPI_ExtServer::Start() {
Logger().information("Starting.");
Server_.InitLogging();
for(const auto & Svr: ConfigServersList_) {
@@ -3928,8 +3958,6 @@ namespace OpenWifi {
}
Poco::Net::HTTPServerParams::Ptr Params = new Poco::Net::HTTPServerParams;
Params->setMaxThreads(50);
Params->setMaxQueued(200);
Params->setKeepAlive(true);
Params->setName("ws:xrest");
@@ -3944,7 +3972,6 @@ namespace OpenWifi {
NewServer->start();
RESTServers_.push_back(std::move(NewServer));
}
return 0;
}
@@ -3965,8 +3992,6 @@ namespace OpenWifi {
}
auto Params = new Poco::Net::HTTPServerParams;
Params->setMaxThreads(50);
Params->setMaxQueued(200);
Params->setKeepAlive(true);
Params->setName("ws:irest");
@@ -3986,7 +4011,7 @@ namespace OpenWifi {
}
inline int MicroService::main([[maybe_unused]] const ArgVec &args) {
MyErrorHandler ErrorHandler(*this);
MicroServiceErrorHandler ErrorHandler(*this);
Poco::ErrorHandler::set(&ErrorHandler);
if (!HelpRequested_) {
@@ -4034,7 +4059,11 @@ namespace OpenWifi {
auto i = 0;
bool good = true;
Log_ = std::make_unique<LoggerWrapper>(Poco::Logger::get(LoggerPrefix_));
auto NewLevel = MicroService::instance().ConfigGetString("logging.level." + Name_, "");
if(NewLevel.empty())
Logger_ = std::make_unique<LoggerWrapper>(Poco::Logger::create(LoggerPrefix_, Poco::Logger::root().getChannel(), Poco::Logger::root().getLevel()));
else
Logger_ = std::make_unique<LoggerWrapper>(Poco::Logger::create(LoggerPrefix_, Poco::Logger::root().getChannel(), Poco::Logger::parseLevel(NewLevel)));
ConfigServersList_.clear();
while (good) {
@@ -4124,9 +4153,11 @@ namespace OpenWifi {
inline void BusEventManager::Stop() {
if(KafkaManager()->Enabled()) {
poco_information(Logger(),"Stopping...");
Running_ = false;
Thread_.wakeUp();
Thread_.join();
poco_information(Logger(),"Stopped...");
}
}
@@ -4138,37 +4169,37 @@ namespace OpenWifi {
inline void KafkaLoggerFun([[maybe_unused]] cppkafka::KafkaHandleBase & handle, int level, const std::string & facility, const std::string &message) {
switch ((cppkafka::LogLevel) level) {
case cppkafka::LogLevel::LogNotice: {
KafkaManager()->Logger().notice(fmt::format("kafka-log: facility: {} message: {}",facility, message));
poco_notice(KafkaManager()->Logger(),fmt::format("kafka-log: facility: {} message: {}",facility, message));
}
break;
case cppkafka::LogLevel::LogDebug: {
KafkaManager()->Logger().debug(fmt::format("kafka-log: facility: {} message: {}",facility, message));
poco_debug(KafkaManager()->Logger(),fmt::format("kafka-log: facility: {} message: {}",facility, message));
}
break;
case cppkafka::LogLevel::LogInfo: {
KafkaManager()->Logger().information(fmt::format("kafka-log: facility: {} message: {}",facility, message));
poco_information(KafkaManager()->Logger(),fmt::format("kafka-log: facility: {} message: {}",facility, message));
}
break;
case cppkafka::LogLevel::LogWarning: {
KafkaManager()->Logger().warning(fmt::format("kafka-log: facility: {} message: {}",facility, message));
case cppkafka::LogLevel::LogWarning: {
poco_warning(KafkaManager()->Logger(), fmt::format("kafka-log: facility: {} message: {}",facility, message));
}
break;
case cppkafka::LogLevel::LogAlert:
case cppkafka::LogLevel::LogCrit: {
KafkaManager()->Logger().critical(fmt::format("kafka-log: facility: {} message: {}",facility, message));
poco_critical(KafkaManager()->Logger(),fmt::format("kafka-log: facility: {} message: {}",facility, message));
}
break;
case cppkafka::LogLevel::LogErr:
case cppkafka::LogLevel::LogEmerg:
default: {
KafkaManager()->Logger().error(fmt::format("kafka-log: facility: {} message: {}",facility, message));
poco_error(KafkaManager()->Logger(),fmt::format("kafka-log: facility: {} message: {}",facility, message));
}
break;
}
}
inline void KafkaErrorFun([[maybe_unused]] cppkafka::KafkaHandleBase & handle, int error, const std::string &reason) {
KafkaManager()->Logger().error(fmt::format("kafka-error: {}, reason: {}", error, reason));
poco_error(KafkaManager()->Logger(),fmt::format("kafka-error: {}, reason: {}", error, reason));
}
inline void AddKafkaSecurity(cppkafka::Configuration & Config) {
@@ -4217,11 +4248,11 @@ namespace OpenWifi {
cppkafka::MessageBuilder(Msg->Topic()).key(Msg->Key()).payload(Msg->Payload()));
}
} catch (const cppkafka::HandleException &E) {
KafkaManager()->Logger().warning(fmt::format("Caught a Kafka exception (producer): {}", E.what()));
poco_warning(KafkaManager()->Logger(),fmt::format("Caught a Kafka exception (producer): {}", E.what()));
} catch( const Poco::Exception &E) {
KafkaManager()->Logger().log(E);
} catch (...) {
KafkaManager()->Logger().error("std::exception");
poco_error(KafkaManager()->Logger(),"std::exception");
}
Note = Queue_.waitDequeueNotification();
}
@@ -4281,7 +4312,7 @@ namespace OpenWifi {
continue;
if (Msg.get_error()) {
if (!Msg.is_eof()) {
KafkaManager()->Logger().error(fmt::format("Error: {}", Msg.get_error().to_string()));
poco_error(KafkaManager()->Logger(),fmt::format("Error: {}", Msg.get_error().to_string()));
}
if(!AutoCommit)
Consumer.async_commit(Msg);
@@ -4292,11 +4323,11 @@ namespace OpenWifi {
Consumer.async_commit(Msg);
}
} catch (const cppkafka::HandleException &E) {
KafkaManager()->Logger().warning(fmt::format("Caught a Kafka exception (consumer): {}", E.what()));
poco_warning(KafkaManager()->Logger(),fmt::format("Caught a Kafka exception (consumer): {}", E.what()));
} catch (const Poco::Exception &E) {
KafkaManager()->Logger().log(E);
} catch (...) {
KafkaManager()->Logger().error("std::exception");
poco_error(KafkaManager()->Logger(),"std::exception");
}
}
Consumer.unsubscribe();
@@ -4740,7 +4771,7 @@ namespace OpenWifi {
}
#ifdef TIP_SECURITY_SERVICE
[[nodiscard]] bool AuthServiceIsAuthorized(Poco::Net::HTTPServerRequest & Request,std::string &SessionToken, SecurityObjects::UserInfoAndPolicy & UInfo, bool & Expired , bool Sub );
[[nodiscard]] bool AuthServiceIsAuthorized(Poco::Net::HTTPServerRequest & Request,std::string &SessionToken, SecurityObjects::UserInfoAndPolicy & UInfo, std::uint64_t TID, bool & Expired , bool Sub );
#endif
inline bool RESTAPIHandler::IsAuthorized( bool & Expired , [[maybe_unused]] bool & Contacted , bool Sub ) {
if(Internal_ && Request->has("X-INTERNAL-NAME")) {
@@ -4748,16 +4779,20 @@ namespace OpenWifi {
Contacted = true;
if(!Allowed) {
if(Server_.LogBadTokens(false)) {
Logger_.debug(fmt::format("I-REQ-DENIED({}): Method={} Path={}",
Utils::FormatIPv6(Request->clientAddress().toString()),
Request->getMethod(), Request->getURI()));
poco_debug(Logger_,fmt::format("I-REQ-DENIED({}): TID={} Method={} Path={}",
Utils::FormatIPv6(Request->clientAddress().toString()),
TransactionId_,
Request->getMethod(), Request->getURI()));
}
} else {
auto Id = Request->get("X-INTERNAL-NAME", "unknown");
REST_Requester_ = Id;
if(Server_.LogIt(Request->getMethod(),true)) {
Logger_.debug(fmt::format("I-REQ-ALLOWED({}): User='{}' Method={} Path={}",
Utils::FormatIPv6(Request->clientAddress().toString()), Id,
Request->getMethod(), Request->getURI()));
poco_debug(Logger_,fmt::format("I-REQ-ALLOWED({}): TID={} User='{}' Method={} Path={}",
Utils::FormatIPv6(Request->clientAddress().toString()),
TransactionId_,
Id,
Request->getMethod(), Request->getURI()));
}
}
return Allowed;
@@ -4773,24 +4808,28 @@ namespace OpenWifi {
}
}
#ifdef TIP_SECURITY_SERVICE
if (AuthServiceIsAuthorized(*Request, SessionToken_, UserInfo_, Expired, Sub)) {
if (AuthServiceIsAuthorized(*Request, SessionToken_, UserInfo_, TransactionId_, Expired, Sub)) {
#else
if (AuthClient()->IsAuthorized( SessionToken_, UserInfo_, Expired, Contacted, Sub)) {
if (AuthClient()->IsAuthorized( SessionToken_, UserInfo_, TransactionId_, Expired, Contacted, Sub)) {
#endif
REST_Requester_ = UserInfo_.userinfo.email;
if(Server_.LogIt(Request->getMethod(),true)) {
Logger_.debug(fmt::format("X-REQ-ALLOWED({}): User='{}@{}' Method={} Path={}",
UserInfo_.userinfo.email,
Utils::FormatIPv6(Request->clientAddress().toString()),
Request->clientAddress().toString(),
Request->getMethod(),
Request->getURI()));
poco_debug(Logger_,fmt::format("X-REQ-ALLOWED({}): TID={} User='{}@{}' Method={} Path={}",
UserInfo_.userinfo.email,
TransactionId_,
Utils::FormatIPv6(Request->clientAddress().toString()),
Request->clientAddress().toString(),
Request->getMethod(),
Request->getURI()));
}
return true;
} else {
if(Server_.LogBadTokens(true)) {
Logger_.debug(fmt::format("X-REQ-DENIED({}): Method={} Path={}",
Utils::FormatIPv6(Request->clientAddress().toString()),
Request->getMethod(), Request->getURI()));
poco_debug(Logger_,fmt::format("X-REQ-DENIED({}): TID={} Method={} Path={}",
Utils::FormatIPv6(Request->clientAddress().toString()),
TransactionId_,
Request->getMethod(),
Request->getURI()));
}
}
return false;
@@ -4859,7 +4898,7 @@ namespace OpenWifi {
void run() override;
// MyParallelSocketReactor &ReactorPool();
Poco::Net::SocketReactor & Reactor() { return Reactor_; }
void NewClient(Poco::Net::WebSocket &WS, const std::string &Id);
void NewClient(Poco::Net::WebSocket &WS, const std::string &Id, const std::string &UserName);
bool Register(WebSocketClient *Client, const std::string &Id);
void SetProcessor(WebSocketClientProcessor *F);
void UnRegister(const std::string &Id);
@@ -4910,18 +4949,22 @@ namespace OpenWifi {
class WebSocketClient {
public:
explicit WebSocketClient(Poco::Net::WebSocket &WS, const std::string &Id, Poco::Logger &L,
WebSocketClientProcessor *Processor);
explicit WebSocketClient(Poco::Net::WebSocket &WS,
const std::string &Id,
const std::string &UserName,
Poco::Logger &L,
WebSocketClientProcessor *Processor);
virtual ~WebSocketClient();
[[nodiscard]] inline const std::string &Id();
[[nodiscard]] Poco::Logger &Logger();
inline bool Send(const std::string &Payload);
private:
std::unique_ptr<Poco::Net::WebSocket> WS_;
Poco::Net::SocketReactor &Reactor_;
std::string Id_;
Poco::Logger &Logger_;
bool Authenticated_ = false;
Poco::Net::SocketReactor &Reactor_;
std::string Id_;
std::string UserName_;
Poco::Logger &Logger_;
std::atomic_bool Authenticated_ = false;
SecurityObjects::UserInfoAndPolicy UserInfo_;
WebSocketClientProcessor *Processor_ = nullptr;
void OnSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf);
@@ -4929,33 +4972,9 @@ namespace OpenWifi {
void OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf);
};
/* inline MyParallelSocketReactor::MyParallelSocketReactor(uint32_t NumReactors) :
NumReactors_(NumReactors)
{
Reactors_ = new Poco::Net::SocketReactor[NumReactors_];
for(uint32_t i=0;i<NumReactors_;i++) {
ReactorPool_.start(Reactors_[i]);
}
}
inline MyParallelSocketReactor::~MyParallelSocketReactor() {
for(uint32_t i=0;i<NumReactors_;i++) {
Reactors_[i].stop();
}
ReactorPool_.stopAll();
ReactorPool_.joinAll();
delete [] Reactors_;
}
inline Poco::Net::SocketReactor & MyParallelSocketReactor::Reactor() {
return Reactors_[ rand() % NumReactors_ ];
}
// inline MyParallelSocketReactor & WebSocketClientServer::ReactorPool() { return *ReactorPool_; }
*/
inline void WebSocketClientServer::NewClient(Poco::Net::WebSocket & WS, const std::string &Id) {
inline void WebSocketClientServer::NewClient(Poco::Net::WebSocket & WS, const std::string &Id, const std::string &UserName ) {
std::lock_guard G(Mutex_);
auto Client = new WebSocketClient(WS,Id,Logger(), Processor_);
auto Client = new WebSocketClient(WS,Id,UserName,Logger(), Processor_);
Clients_[Id] = std::make_pair(Client,"");
}
@@ -5072,6 +5091,7 @@ namespace OpenWifi {
auto Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
if (n == 0) {
poco_debug(Logger(),fmt::format("CLOSE({}): {} UI Client is closing WS connection.", Id_, UserName_));
return delete this;
}
@@ -5084,7 +5104,7 @@ namespace OpenWifi {
case Poco::Net::WebSocket::FRAME_OP_PONG: {
} break;
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
Logger().warning(Poco::format("CLOSE(%s): UI Client is closing its connection.", Id_));
poco_debug(Logger(),fmt::format("CLOSE({}): {} UI Client is closing WS connection.", Id_, UserName_));
Done = true;
} break;
case Poco::Net::WebSocket::FRAME_OP_TEXT: {
@@ -5094,8 +5114,10 @@ namespace OpenWifi {
auto Tokens = Utils::Split(Frame, ':');
bool Expired = false, Contacted = false;
if (Tokens.size() == 2 &&
AuthClient()->IsAuthorized(Tokens[1], UserInfo_, Expired, Contacted)) {
AuthClient()->IsAuthorized(Tokens[1], UserInfo_, 0, Expired, Contacted)) {
Authenticated_ = true;
UserName_ = UserInfo_.userinfo.email;
poco_debug(Logger(),fmt::format("START({}): {} UI Client is starting WS connection.", Id_, UserName_));
std::string S{"Welcome! Bienvenue! Bienvenidos!"};
WS_->sendFrame(S.c_str(), S.size());
WebSocketClientServer()->SetUser(Id_, UserInfo_.userinfo.email);
@@ -5141,9 +5163,10 @@ namespace OpenWifi {
}
inline WebSocketClient::WebSocketClient( Poco::Net::WebSocket & WS , const std::string &Id, Poco::Logger & L, WebSocketClientProcessor * Processor) :
inline WebSocketClient::WebSocketClient( Poco::Net::WebSocket & WS , const std::string &Id, const std::string &UserName, Poco::Logger & L, WebSocketClientProcessor * Processor) :
Reactor_(WebSocketClientServer()->Reactor()),
Id_(Id),
UserName_(UserName),
Logger_(L),
Processor_(Processor) {
try {
@@ -5157,7 +5180,10 @@ namespace OpenWifi {
Reactor_.addEventHandler(*WS_,
Poco::NObserver<WebSocketClient, Poco::Net::ErrorNotification>(
*this, &WebSocketClient::OnSocketError));
// WebSocketClientServer()->Register(this, Id_);
WS_->setNoDelay(true);
WS_->setKeepAlive(true);
WS_->setBlocking(false);
} catch (...) {
delete this;
}
@@ -5177,7 +5203,6 @@ namespace OpenWifi {
Poco::Net::ErrorNotification>(*this,&WebSocketClient::OnSocketError));
(*WS_).shutdown();
(*WS_).close();
WebSocketClientServer()->UnRegister(Id_);
} catch(...) {
}
@@ -5223,9 +5248,8 @@ namespace OpenWifi {
try
{
Poco::Net::WebSocket WS(*Request, *Response);
Logger().information("UI-WebSocket connection established.");
auto Id = MicroService::CreateUUID();
WebSocketClientServer()->NewClient(WS,Id);
WebSocketClientServer()->NewClient(WS,Id,UserInfo_.userinfo.email);
}
catch (...) {
std::cout << "Cannot create websocket client..." << std::endl;

View File

@@ -0,0 +1,169 @@
//
// 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,7 +33,6 @@ 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

@@ -146,6 +146,10 @@ namespace OpenWifi {
WebSocketClientServer()->SendUserNotification(User,N);
}
/////
/////
/////
struct WebSocketNotificationRebootList {
std::string title,
details,
@@ -189,5 +193,58 @@ 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

@@ -196,6 +196,8 @@ 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."};
}
@@ -428,6 +430,7 @@ 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";
}
@@ -444,6 +447,7 @@ 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,
@@ -456,7 +460,8 @@ namespace OpenWifi::uCentralProtocol::Events {
ET_CFGPENDING,
ET_RECOVERY,
ET_DEVICEUPDATE,
ET_TELEMETRY
ET_TELEMETRY,
ET_VENUEBROADCAST
};
inline EVENT_MSG EventFromString(const std::string & Method) {
@@ -480,6 +485,8 @@ 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

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# wait-for-postgres.sh
set -e
@@ -20,7 +20,7 @@ if [ "$1" = '/openwifi/owfms' -a "$(id -u)" = '0' ]; then
if [ "$RUN_CHOWN" = 'true' ]; then
chown -R "$OWFMS_USER": "$OWFMS_ROOT" "$OWFMS_CONFIG"
fi
exec su-exec "$OWFMS_USER" "$@"
exec gosu "$OWFMS_USER" "$@"
fi
exec "$@"