mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-30 18:18:03 +00:00
Compare commits
7 Commits
v2.6.0-RC1
...
release/v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a941f5cad7 | ||
|
|
6aea5f560a | ||
|
|
58e40bf06a | ||
|
|
510a018cec | ||
|
|
b742288f60 | ||
|
|
b581598e69 | ||
|
|
19023d0c10 |
35
.github/workflows/ci.yml
vendored
35
.github/workflows/ci.yml
vendored
@@ -13,7 +13,6 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- 'release/*'
|
|
||||||
|
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
@@ -40,16 +39,6 @@ jobs:
|
|||||||
registry_user: ucentral
|
registry_user: ucentral
|
||||||
registry_password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
|
registry_password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
- name: Notify on failure via Slack
|
|
||||||
if: failure() && github.ref == 'refs/heads/main'
|
|
||||||
uses: rtCamp/action-slack-notify@v2
|
|
||||||
env:
|
|
||||||
SLACK_USERNAME: GitHub Actions failure notifier
|
|
||||||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
|
||||||
SLACK_COLOR: "${{ job.status }}"
|
|
||||||
SLACK_ICON: https://raw.githubusercontent.com/quintessence/slack-icons/master/images/github-logo-slack-icon.png
|
|
||||||
SLACK_TITLE: Docker build failed for OWProv service
|
|
||||||
|
|
||||||
trigger-testing:
|
trigger-testing:
|
||||||
if: startsWith(github.ref, 'refs/pull/')
|
if: startsWith(github.ref, 'refs/pull/')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -78,26 +67,4 @@ jobs:
|
|||||||
workflow: ow_docker-compose.yml
|
workflow: ow_docker-compose.yml
|
||||||
token: ${{ secrets.WLAN_TESTING_PAT }}
|
token: ${{ secrets.WLAN_TESTING_PAT }}
|
||||||
ref: master
|
ref: master
|
||||||
inputs: '{"deployment_version": "${{ env.BASE_BRANCH }}", "owgw_version": "${{ env.OWGW_BASE_BRANCH }}", "owsec_version": "${{ env.BASE_BRANCH }}", "owfms_version": "${{ env.BASE_BRANCH }}", "owprov_version": "${{ github.sha }}", "owanalytics_version": "${{ env.BASE_BRANCH }}", "owsub_version": "${{ env.BASE_BRANCH }}", "microservice": "all"}'
|
inputs: '{"owgw_version": "${{ env.OWGW_BASE_BRANCH }}", "owgwui_version": "${{ env.BASE_BRANCH }}", "owsec_version": "${{ env.BASE_BRANCH }}", "owfms_version": "${{ env.BASE_BRANCH }}", "owprov_version": "${{ github.sha }}", "owprovui_version": "${{ env.BASE_BRANCH }}"}'
|
||||||
|
|
||||||
trigger-deploy-to-dev:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: github.ref == 'refs/heads/main'
|
|
||||||
needs:
|
|
||||||
- docker
|
|
||||||
steps:
|
|
||||||
- name: Checkout actions repo
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
repository: Telecominfraproject/.github
|
|
||||||
path: github
|
|
||||||
|
|
||||||
- name: Trigger deployment of the latest version to dev instance and wait for result
|
|
||||||
uses: ./github/composite-actions/trigger-workflow-and-wait
|
|
||||||
with:
|
|
||||||
owner: Telecominfraproject
|
|
||||||
repo: wlan-testing
|
|
||||||
workflow: ucentralgw-dev-deployment.yaml
|
|
||||||
token: ${{ secrets.WLAN_TESTING_PAT }}
|
|
||||||
ref: master
|
|
||||||
inputs: '{"force_latest": "true"}'
|
|
||||||
|
|||||||
1
.github/workflows/cleanup.yml
vendored
1
.github/workflows/cleanup.yml
vendored
@@ -4,7 +4,6 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- 'release/*'
|
|
||||||
types: [ closed ]
|
types: [ closed ]
|
||||||
|
|
||||||
defaults:
|
defaults:
|
||||||
|
|||||||
46
.github/workflows/release.yml
vendored
46
.github/workflows/release.yml
vendored
@@ -1,46 +0,0 @@
|
|||||||
name: Release chart package
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
helm-package:
|
|
||||||
runs-on: ubuntu-20.04
|
|
||||||
env:
|
|
||||||
HELM_REPO_URL: https://tip.jfrog.io/artifactory/tip-wlan-cloud-ucentral-helm/
|
|
||||||
HELM_REPO_USERNAME: ucentral
|
|
||||||
steps:
|
|
||||||
- name: Checkout uCentral assembly chart repo
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
path: wlan-cloud-owprov
|
|
||||||
|
|
||||||
- name: Build package
|
|
||||||
working-directory: wlan-cloud-owprov/helm
|
|
||||||
run: |
|
|
||||||
helm plugin install https://github.com/aslafy-z/helm-git --version 0.10.0
|
|
||||||
helm repo add bitnami https://charts.bitnami.com/bitnami
|
|
||||||
helm repo update
|
|
||||||
helm dependency update
|
|
||||||
mkdir dist
|
|
||||||
helm package . -d dist
|
|
||||||
|
|
||||||
- name: Generate GitHub release body
|
|
||||||
working-directory: wlan-cloud-owprov/helm
|
|
||||||
run: |
|
|
||||||
pip3 install yq -q
|
|
||||||
echo "Docker image - tip-tip-wlan-cloud-ucentral.jfrog.io/owprov:$GITHUB_REF_NAME" > release.txt
|
|
||||||
echo "Helm charted may be attached to this release" >> release.txt
|
|
||||||
echo "Deployment artifacts may be found in https://github.com/Telecominfraproject/wlan-cloud-ucentral-deploy/tree/$GITHUB_REF_NAME" >> release.txt
|
|
||||||
|
|
||||||
- name: Create GitHub release
|
|
||||||
uses: softprops/action-gh-release@v1
|
|
||||||
with:
|
|
||||||
body_path: wlan-cloud-owprov/helm/release.txt
|
|
||||||
files: wlan-cloud-owprov/helm/dist/*
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
project(owprov VERSION 2.6.0)
|
project(owprov VERSION 2.5.0)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
@@ -39,11 +39,17 @@ endif()
|
|||||||
|
|
||||||
add_definitions(-DAWS_CUSTOM_MEMORY_MANAGEMENT)
|
add_definitions(-DAWS_CUSTOM_MEMORY_MANAGEMENT)
|
||||||
|
|
||||||
|
set(BUILD_SHARED_LIBS 1)
|
||||||
|
set(Boost_USE_STATIC_LIBS OFF)
|
||||||
|
set(Boost_USE_MULTITHREADED ON)
|
||||||
|
set(Boost_USE_STATIC_RUNTIME OFF)
|
||||||
|
|
||||||
|
find_package(Boost REQUIRED system)
|
||||||
find_package(OpenSSL REQUIRED)
|
find_package(OpenSSL REQUIRED)
|
||||||
|
find_package(AWSSDK REQUIRED COMPONENTS s3)
|
||||||
find_package(Poco REQUIRED COMPONENTS Crypto JWT Net Util NetSSL Data DataSQLite)
|
find_package(Poco REQUIRED COMPONENTS Crypto JWT Net Util NetSSL Data DataSQLite)
|
||||||
find_package(nlohmann_json REQUIRED)
|
find_package(nlohmann_json REQUIRED)
|
||||||
find_package(nlohmann_json_schema_validator REQUIRED)
|
find_package(nlohmann_json_schema_validator REQUIRED)
|
||||||
find_package(fmt REQUIRED)
|
|
||||||
|
|
||||||
if(SMALL_BUILD)
|
if(SMALL_BUILD)
|
||||||
find_package(Poco REQUIRED COMPONENTS Crypto JWT Net Util NetSSL Data DataSQLite)
|
find_package(Poco REQUIRED COMPONENTS Crypto JWT Net Util NetSSL Data DataSQLite)
|
||||||
@@ -58,12 +64,6 @@ 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)
|
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(owprov
|
add_executable(owprov
|
||||||
build
|
build
|
||||||
src/ow_version.h.in
|
src/ow_version.h.in
|
||||||
@@ -72,11 +72,12 @@ add_executable(owprov
|
|||||||
src/framework/MicroService.h
|
src/framework/MicroService.h
|
||||||
src/framework/OpenWifiTypes.h
|
src/framework/OpenWifiTypes.h
|
||||||
src/framework/orm.h
|
src/framework/orm.h
|
||||||
|
src/framework/RESTAPI_errors.h
|
||||||
|
src/framework/RESTAPI_protocol.h
|
||||||
src/framework/StorageClass.h
|
src/framework/StorageClass.h
|
||||||
|
src/framework/uCentral_Protocol.h
|
||||||
src/framework/ConfigurationValidator.cpp
|
src/framework/ConfigurationValidator.cpp
|
||||||
src/framework/ConfigurationValidator.h
|
src/framework/ConfigurationValidator.h
|
||||||
src/framework/ow_constants.h
|
|
||||||
src/framework/WebSocketClientNotifications.h
|
|
||||||
src/RESTObjects/RESTAPI_SecurityObjects.h src/RESTObjects/RESTAPI_SecurityObjects.cpp
|
src/RESTObjects/RESTAPI_SecurityObjects.h src/RESTObjects/RESTAPI_SecurityObjects.cpp
|
||||||
src/RESTObjects/RESTAPI_ProvObjects.cpp src/RESTObjects/RESTAPI_ProvObjects.h
|
src/RESTObjects/RESTAPI_ProvObjects.cpp src/RESTObjects/RESTAPI_ProvObjects.h
|
||||||
src/RESTObjects/RESTAPI_GWobjects.h src/RESTObjects/RESTAPI_GWobjects.cpp
|
src/RESTObjects/RESTAPI_GWobjects.h src/RESTObjects/RESTAPI_GWobjects.cpp
|
||||||
@@ -103,6 +104,7 @@ add_executable(owprov
|
|||||||
src/RESTAPI/RESTAPI_inventory_list_handler.cpp src/RESTAPI/RESTAPI_inventory_list_handler.h
|
src/RESTAPI/RESTAPI_inventory_list_handler.cpp src/RESTAPI/RESTAPI_inventory_list_handler.h
|
||||||
src/RESTAPI/RESTAPI_entity_list_handler.cpp src/RESTAPI/RESTAPI_entity_list_handler.h
|
src/RESTAPI/RESTAPI_entity_list_handler.cpp src/RESTAPI/RESTAPI_entity_list_handler.h
|
||||||
src/RESTAPI/RESTAPI_configurations_handler.cpp src/RESTAPI/RESTAPI_configurations_handler.h
|
src/RESTAPI/RESTAPI_configurations_handler.cpp src/RESTAPI/RESTAPI_configurations_handler.h
|
||||||
|
src/RESTAPI/RESTAPI_webSocketServer.h src/RESTAPI/RESTAPI_webSocketServer.cpp
|
||||||
src/RESTAPI/RESTAPI_contact_list_handler.cpp src/RESTAPI/RESTAPI_contact_list_handler.h
|
src/RESTAPI/RESTAPI_contact_list_handler.cpp src/RESTAPI/RESTAPI_contact_list_handler.h
|
||||||
src/RESTAPI/RESTAPI_location_list_handler.cpp src/RESTAPI/RESTAPI_location_list_handler.h
|
src/RESTAPI/RESTAPI_location_list_handler.cpp src/RESTAPI/RESTAPI_location_list_handler.h
|
||||||
src/RESTAPI/RESTAPI_venue_list_handler.cpp src/RESTAPI/RESTAPI_venue_list_handler.h
|
src/RESTAPI/RESTAPI_venue_list_handler.cpp src/RESTAPI/RESTAPI_venue_list_handler.h
|
||||||
@@ -111,8 +113,6 @@ add_executable(owprov
|
|||||||
src/RESTAPI/RESTAPI_managementRole_list_handler.cpp src/RESTAPI/RESTAPI_managementRole_list_handler.h
|
src/RESTAPI/RESTAPI_managementRole_list_handler.cpp src/RESTAPI/RESTAPI_managementRole_list_handler.h
|
||||||
src/RESTAPI/RESTAPI_configurations_list_handler.cpp src/RESTAPI/RESTAPI_configurations_list_handler.h
|
src/RESTAPI/RESTAPI_configurations_list_handler.cpp src/RESTAPI/RESTAPI_configurations_list_handler.h
|
||||||
src/RESTAPI/RESTAPI_iptocountry_handler.cpp src/RESTAPI/RESTAPI_iptocountry_handler.h
|
src/RESTAPI/RESTAPI_iptocountry_handler.cpp src/RESTAPI/RESTAPI_iptocountry_handler.h
|
||||||
src/RESTAPI/RESTAPI_signup_handler.h src/RESTAPI/RESTAPI_signup_handler.cpp
|
|
||||||
src/RESTAPI/RESTAPI_asset_server.cpp src/RESTAPI/RESTAPI_asset_server.h
|
|
||||||
src/FindCountry.h
|
src/FindCountry.h
|
||||||
src/sdks/SDK_gw.cpp src/sdks/SDK_gw.h
|
src/sdks/SDK_gw.cpp src/sdks/SDK_gw.h
|
||||||
src/sdks/SDK_prov.cpp src/sdks/SDK_prov.h
|
src/sdks/SDK_prov.cpp src/sdks/SDK_prov.h
|
||||||
@@ -126,22 +126,14 @@ add_executable(owprov
|
|||||||
src/JobController.cpp src/JobController.h
|
src/JobController.cpp src/JobController.h
|
||||||
src/JobRegistrations.cpp
|
src/JobRegistrations.cpp
|
||||||
src/storage/storage_jobs.cpp src/storage/storage_jobs.h
|
src/storage/storage_jobs.cpp src/storage/storage_jobs.h
|
||||||
|
src/WebSocketClientServer.cpp src/WebSocketClientServer.h
|
||||||
src/storage/storage_maps.cpp src/storage/storage_maps.h
|
src/storage/storage_maps.cpp src/storage/storage_maps.h
|
||||||
src/RESTAPI/RESTAPI_map_handler.cpp src/RESTAPI/RESTAPI_map_handler.h
|
src/RESTAPI/RESTAPI_map_handler.cpp src/RESTAPI/RESTAPI_map_handler.h
|
||||||
src/RESTAPI/RESTAPI_map_list_handler.cpp src/RESTAPI/RESTAPI_map_list_handler.h
|
src/RESTAPI/RESTAPI_map_list_handler.cpp src/RESTAPI/RESTAPI_map_list_handler.h)
|
||||||
src/storage/storage_signup.cpp src/storage/storage_signup.h
|
|
||||||
src/Signup.cpp src/Signup.h
|
|
||||||
src/DeviceTypeCache.h
|
|
||||||
src/storage/storage_variables.cpp src/storage/storage_variables.h
|
|
||||||
src/RESTAPI/RESTAPI_variables_handler.cpp src/RESTAPI/RESTAPI_variables_handler.h
|
|
||||||
src/RESTAPI/RESTAPI_variables_list_handler.cpp src/RESTAPI/RESTAPI_variables_list_handler.h
|
|
||||||
src/FileDownloader.cpp src/FileDownloader.h src/Tasks/VenueConfigUpdater.h src/Kafka_ProvUpdater.cpp src/Kafka_ProvUpdater.h src/storage/storage_operataor.cpp src/storage/storage_operataor.h src/storage/storage_sub_devices.cpp src/storage/storage_sub_devices.h src/storage/storage_service_class.cpp src/storage/storage_service_class.h src/RESTAPI/RESTAPI_sub_devices_list_handler.cpp src/RESTAPI/RESTAPI_sub_devices_list_handler.h src/RESTAPI/RESTAPI_sub_devices_handler.cpp src/RESTAPI/RESTAPI_sub_devices_handler.h src/RESTAPI/RESTAPI_service_class_list_handler.cpp src/RESTAPI/RESTAPI_service_class_list_handler.h src/RESTAPI/RESTAPI_service_class_handler.cpp src/RESTAPI/RESTAPI_service_class_handler.h src/RESTAPI/RESTAPI_operators_list_handler.cpp src/RESTAPI/RESTAPI_operators_list_handler.h src/RESTAPI/RESTAPI_operators_handler.cpp src/RESTAPI/RESTAPI_operators_handler.h src/storage/storage_op_contacts.cpp src/storage/storage_op_contacts.h src/storage/storage_op_locations.cpp src/storage/storage_op_locations.h src/RESTAPI/RESTAPI_op_contact_list_handler.cpp src/RESTAPI/RESTAPI_op_contact_list_handler.h src/RESTAPI/RESTAPI_op_contact_handler.cpp src/RESTAPI/RESTAPI_op_contact_handler.h src/RESTAPI/RESTAPI_op_location_list_handler.cpp src/RESTAPI/RESTAPI_op_location_list_handler.h src/RESTAPI/RESTAPI_op_location_handler.cpp src/RESTAPI/RESTAPI_op_location_handler.h src/ProvWebSocketClient.cpp src/ProvWebSocketClient.h src/Tasks/VenueRebooter.h src/Tasks/VenueUpgrade.h src/sdks/SDK_fms.cpp src/sdks/SDK_fms.h)
|
|
||||||
|
|
||||||
target_link_libraries(owprov PUBLIC
|
target_link_libraries(owprov PUBLIC
|
||||||
${Poco_LIBRARIES}
|
${Poco_LIBRARIES} ${MySQL_LIBRARIES}
|
||||||
${MySQL_LIBRARIES}
|
${Boost_LIBRARIES}
|
||||||
${ZLIB_LIBRARIES}
|
${ZLIB_LIBRARIES} ${AWSSDK_LINK_LIBRARIES}
|
||||||
CppKafka::cppkafka
|
CppKafka::cppkafka nlohmann_json_schema_validator)
|
||||||
fmt::fmt
|
|
||||||
nlohmann_json_schema_validator)
|
|
||||||
|
|
||||||
|
|||||||
28
Dockerfile
28
Dockerfile
@@ -43,17 +43,20 @@ RUN cmake ..
|
|||||||
RUN make
|
RUN make
|
||||||
RUN make install
|
RUN make install
|
||||||
|
|
||||||
FROM build-base AS fmtlib-build
|
FROM build-base AS aws-sdk-cpp-build
|
||||||
|
|
||||||
ADD https://api.github.com/repos/fmtlib/fmt/git/refs/heads/master version.json
|
ADD https://api.github.com/repos/aws/aws-sdk-cpp/git/refs/heads/main version.json
|
||||||
RUN git clone https://github.com/fmtlib/fmt /fmtlib
|
RUN git clone --recurse-submodules https://github.com/aws/aws-sdk-cpp /aws-sdk-cpp
|
||||||
|
|
||||||
WORKDIR /fmtlib
|
WORKDIR /aws-sdk-cpp
|
||||||
RUN mkdir cmake-build
|
RUN mkdir cmake-build
|
||||||
WORKDIR cmake-build
|
WORKDIR cmake-build
|
||||||
RUN cmake ..
|
RUN cmake .. -DBUILD_ONLY="sns;s3" \
|
||||||
RUN make
|
-DCMAKE_BUILD_TYPE=Release \
|
||||||
RUN make install
|
-DCMAKE_CXX_FLAGS="-Wno-error=stringop-overflow -Wno-error=uninitialized" \
|
||||||
|
-DAUTORUN_UNIT_TESTS=OFF
|
||||||
|
RUN cmake --build . --config Release -j8
|
||||||
|
RUN cmake --build . --target install
|
||||||
|
|
||||||
FROM build-base AS owprov-build
|
FROM build-base AS owprov-build
|
||||||
|
|
||||||
@@ -68,13 +71,15 @@ COPY --from=cppkafka-build /usr/local/include /usr/local/include
|
|||||||
COPY --from=cppkafka-build /usr/local/lib /usr/local/lib
|
COPY --from=cppkafka-build /usr/local/lib /usr/local/lib
|
||||||
COPY --from=json-schema-validator-build /usr/local/include /usr/local/include
|
COPY --from=json-schema-validator-build /usr/local/include /usr/local/include
|
||||||
COPY --from=json-schema-validator-build /usr/local/lib /usr/local/lib
|
COPY --from=json-schema-validator-build /usr/local/lib /usr/local/lib
|
||||||
COPY --from=fmtlib-build /usr/local/include /usr/local/include
|
COPY --from=aws-sdk-cpp-build /usr/local/include /usr/local/include
|
||||||
COPY --from=fmtlib-build /usr/local/lib /usr/local/lib
|
COPY --from=aws-sdk-cpp-build /usr/local/lib /usr/local/lib
|
||||||
|
|
||||||
WORKDIR /owprov
|
WORKDIR /owprov
|
||||||
RUN mkdir cmake-build
|
RUN mkdir cmake-build
|
||||||
WORKDIR /owprov/cmake-build
|
WORKDIR /owprov/cmake-build
|
||||||
RUN cmake ..
|
RUN cmake .. \
|
||||||
|
-Dcrypto_LIBRARY=/usr/lib/libcrypto.so \
|
||||||
|
-DBUILD_SHARED_LIBS=ON
|
||||||
RUN cmake --build . --config Release -j8
|
RUN cmake --build . --config Release -j8
|
||||||
|
|
||||||
FROM alpine:3.15
|
FROM alpine:3.15
|
||||||
@@ -105,6 +110,9 @@ RUN wget https://raw.githubusercontent.com/Telecominfraproject/wlan-cloud-ucentr
|
|||||||
COPY --from=owprov-build /owprov/cmake-build/owprov /openwifi/owprov
|
COPY --from=owprov-build /owprov/cmake-build/owprov /openwifi/owprov
|
||||||
COPY --from=cppkafka-build /cppkafka/cmake-build/src/lib/* /usr/local/lib
|
COPY --from=cppkafka-build /cppkafka/cmake-build/src/lib/* /usr/local/lib
|
||||||
COPY --from=poco-build /poco/cmake-build/lib/* /usr/local/lib
|
COPY --from=poco-build /poco/cmake-build/lib/* /usr/local/lib
|
||||||
|
COPY --from=aws-sdk-cpp-build /aws-sdk-cpp/cmake-build/aws-cpp-sdk-core/libaws-cpp-sdk-core.so /usr/local/lib
|
||||||
|
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
|
||||||
|
|
||||||
EXPOSE 16005 17005 16105
|
EXPOSE 16005 17005 16105
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
# Subscribers Architecture
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
The goal is to provide multiple WISPs with access to a set of subscribers. All subscribers will fall in the default WISP and can be moved to any other WISP later. You can use the source IP to detect which WISP to select.
|
|
||||||
Entities can be generic entities when created OR WISP entities.
|
|
||||||
|
|
||||||
@@ -26,10 +26,6 @@ if [[ "$TEMPLATE_CONFIG" = 'true' && ! -f "$OWPROV_CONFIG"/owprov.properties ]];
|
|||||||
SYSTEM_URI_UI=${SYSTEM_URI_UI:-"http://localhost"} \
|
SYSTEM_URI_UI=${SYSTEM_URI_UI:-"http://localhost"} \
|
||||||
KAFKA_ENABLE=${KAFKA_ENABLE:-"true"} \
|
KAFKA_ENABLE=${KAFKA_ENABLE:-"true"} \
|
||||||
KAFKA_BROKERLIST=${KAFKA_BROKERLIST:-"localhost:9092"} \
|
KAFKA_BROKERLIST=${KAFKA_BROKERLIST:-"localhost:9092"} \
|
||||||
KAFKA_SSL_CA_LOCATION=${KAFKA_SSL_CA_LOCATION:-""} \
|
|
||||||
KAFKA_SSL_CERTIFICATE_LOCATION=${KAFKA_SSL_CERTIFICATE_LOCATION:-""} \
|
|
||||||
KAFKA_SSL_KEY_LOCATION=${KAFKA_SSL_KEY_LOCATION:-""} \
|
|
||||||
KAFKA_SSL_KEY_PASSWORD=${KAFKA_SSL_KEY_PASSWORD:-""} \
|
|
||||||
STORAGE_TYPE=${STORAGE_TYPE:-"sqlite"} \
|
STORAGE_TYPE=${STORAGE_TYPE:-"sqlite"} \
|
||||||
STORAGE_TYPE_POSTGRESQL_HOST=${STORAGE_TYPE_POSTGRESQL_HOST:-"localhost"} \
|
STORAGE_TYPE_POSTGRESQL_HOST=${STORAGE_TYPE_POSTGRESQL_HOST:-"localhost"} \
|
||||||
STORAGE_TYPE_POSTGRESQL_USERNAME=${STORAGE_TYPE_POSTGRESQL_USERNAME:-"owprov"} \
|
STORAGE_TYPE_POSTGRESQL_USERNAME=${STORAGE_TYPE_POSTGRESQL_USERNAME:-"owprov"} \
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ fullnameOverride: ""
|
|||||||
images:
|
images:
|
||||||
owprov:
|
owprov:
|
||||||
repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owprov
|
repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owprov
|
||||||
tag: v2.6.0-RC1
|
tag: v2.5.2
|
||||||
pullPolicy: Always
|
pullPolicy: Always
|
||||||
# regcred:
|
# regcred:
|
||||||
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io
|
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io
|
||||||
@@ -149,10 +149,6 @@ configProperties:
|
|||||||
openwifi.kafka.brokerlist: localhost:9092
|
openwifi.kafka.brokerlist: localhost:9092
|
||||||
openwifi.kafka.auto.commit: false
|
openwifi.kafka.auto.commit: false
|
||||||
openwifi.kafka.queue.buffering.max.ms: 50
|
openwifi.kafka.queue.buffering.max.ms: 50
|
||||||
openwifi.kafka.ssl.ca.location: ""
|
|
||||||
openwifi.kafka.ssl.certificate.location: ""
|
|
||||||
openwifi.kafka.ssl.key.location: ""
|
|
||||||
openwifi.kafka.ssl.key.password: ""
|
|
||||||
# Storage
|
# Storage
|
||||||
storage.type: sqlite # (sqlite|postgresql|mysql|odbc)
|
storage.type: sqlite # (sqlite|postgresql|mysql|odbc)
|
||||||
## SQLite
|
## SQLite
|
||||||
@@ -181,7 +177,6 @@ configProperties:
|
|||||||
openwifi.system.uri.public: https://localhost:16005
|
openwifi.system.uri.public: https://localhost:16005
|
||||||
openwifi.system.uri.ui: https://localhost
|
openwifi.system.uri.ui: https://localhost
|
||||||
openwifi.system.commandchannel: /tmp/app_owprov
|
openwifi.system.commandchannel: /tmp/app_owprov
|
||||||
iptocountry.provider: ipinfo
|
|
||||||
# Logging
|
# Logging
|
||||||
logging.type: console
|
logging.type: console
|
||||||
logging.path: $OWPROV_ROOT/logs
|
logging.path: $OWPROV_ROOT/logs
|
||||||
|
|||||||
1934
openapi/owprov.yaml
1934
openapi/owprov.yaml
File diff suppressed because it is too large
Load Diff
@@ -37,7 +37,6 @@ openwifi.system.uri.ui = owprov-ui.arilia.com
|
|||||||
|
|
||||||
firmware.updater.upgrade = false
|
firmware.updater.upgrade = false
|
||||||
firmware.updater.releaseonly = false
|
firmware.updater.releaseonly = false
|
||||||
rrm.default = false;
|
|
||||||
|
|
||||||
geocodeapi = google
|
geocodeapi = google
|
||||||
google.apikey = **********************************
|
google.apikey = **********************************
|
||||||
@@ -66,13 +65,6 @@ openwifi.kafka.enable = true
|
|||||||
openwifi.kafka.brokerlist = a1.arilia.com:9092
|
openwifi.kafka.brokerlist = a1.arilia.com:9092
|
||||||
openwifi.kafka.auto.commit = false
|
openwifi.kafka.auto.commit = false
|
||||||
openwifi.kafka.queue.buffering.max.ms = 50
|
openwifi.kafka.queue.buffering.max.ms = 50
|
||||||
openwifi.kafka.ssl.ca.location =
|
|
||||||
openwifi.kafka.ssl.certificate.location =
|
|
||||||
openwifi.kafka.ssl.key.location =
|
|
||||||
openwifi.kafka.ssl.key.password =
|
|
||||||
|
|
||||||
signup.graceperiod = 3600
|
|
||||||
signup.lingerperiod = 84400
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# This section select which form of persistence you need
|
# This section select which form of persistence you need
|
||||||
|
|||||||
@@ -58,10 +58,6 @@ openwifi.kafka.enable = ${KAFKA_ENABLE}
|
|||||||
openwifi.kafka.brokerlist = ${KAFKA_BROKERLIST}
|
openwifi.kafka.brokerlist = ${KAFKA_BROKERLIST}
|
||||||
openwifi.kafka.auto.commit = false
|
openwifi.kafka.auto.commit = false
|
||||||
openwifi.kafka.queue.buffering.max.ms = 50
|
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}
|
|
||||||
openwifi.kafka.ssl.key.password = ${KAFKA_SSL_KEY_PASSWORD}
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# This section select which form of persistence you need
|
# This section select which form of persistence you need
|
||||||
|
|||||||
268
src/APConfig.cpp
268
src/APConfig.cpp
@@ -12,16 +12,7 @@ namespace OpenWifi {
|
|||||||
DeviceType_(DeviceType),
|
DeviceType_(DeviceType),
|
||||||
Logger_(L),
|
Logger_(L),
|
||||||
Explain_(Explain)
|
Explain_(Explain)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
APConfig::APConfig(const std::string & SerialNumber, Poco::Logger & L)
|
|
||||||
: SerialNumber_(SerialNumber),
|
|
||||||
Logger_(L)
|
|
||||||
{
|
|
||||||
Explain_ = false;
|
|
||||||
Sub_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool APConfig::FindRadio(const std::string &Band, const Poco::JSON::Array::Ptr &Arr, Poco::JSON::Object::Ptr & Radio) {
|
bool APConfig::FindRadio(const std::string &Band, const Poco::JSON::Array::Ptr &Arr, Poco::JSON::Object::Ptr & Radio) {
|
||||||
for(const auto &i:*Arr) {
|
for(const auto &i:*Arr) {
|
||||||
@@ -45,8 +36,7 @@ namespace OpenWifi {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ShowJSON(const char *S, const Poco::JSON::Object::Ptr &Obj) {
|
||||||
[[maybe_unused ]] static void ShowJSON([[maybe_unused]] const char *S, [[maybe_unused]] const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
/*
|
/*
|
||||||
std::stringstream O;
|
std::stringstream O;
|
||||||
Poco::JSON::Stringifier::stringify(Obj,O);
|
Poco::JSON::Stringifier::stringify(Obj,O);
|
||||||
@@ -55,96 +45,98 @@ namespace OpenWifi {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
bool APConfig::ReplaceVariablesInObject( const Poco::JSON::Object::Ptr & Original, Poco::JSON::Object::Ptr & Result) {
|
bool APConfig::mergeArray(const std::string &K, const Poco::JSON::Array::Ptr &A , const Poco::JSON::Array::Ptr &B, Poco::JSON::Array &Arr) {
|
||||||
// get all the names and expand
|
if(K=="radios") {
|
||||||
auto Names = Original->getNames();
|
auto BB=Poco::makeShared<Poco::JSON::Array>();
|
||||||
for(const auto &i:Names) {
|
BB = B;
|
||||||
if(i=="__variableBlock") {
|
for(const auto &i:*A) {
|
||||||
if(Original->isArray(i)) {
|
auto A_Radio = i.extract<Poco::JSON::Object::Ptr>();
|
||||||
auto UUIDs = Original->getArray(i);
|
// std::cout << "Radio A:" << std::endl;
|
||||||
for(const auto &uuid:*UUIDs) {
|
// ShowJSON(A_Radio);
|
||||||
ProvObjects::VariableBlock VB;
|
if(A_Radio->has("band")) {
|
||||||
if(StorageService()->VariablesDB().GetRecord("id", uuid, VB)) {
|
std::string Band = A_Radio->get("band").toString();
|
||||||
for(const auto &var:VB.variables) {
|
// std::cout << "Looking for band: " << Band << std::endl;
|
||||||
Poco::JSON::Parser P;
|
auto B_Radio=Poco::makeShared<Poco::JSON::Object>();
|
||||||
auto VariableBlockInfo = P.parse(var.value).extract<Poco::JSON::Object::Ptr>();
|
if(FindRadio(Band,B,B_Radio)) {
|
||||||
auto VarNames = VariableBlockInfo->getNames();
|
ShowJSON("Data to be merged", B_Radio);
|
||||||
for(const auto &j:VarNames) {
|
auto RR = Poco::makeShared<Poco::JSON::Object>();
|
||||||
Result->set(j,VariableBlockInfo->get(j));
|
merge(A_Radio, B_Radio,RR);
|
||||||
}
|
ShowJSON("Merged data", RR);
|
||||||
}
|
auto CC = Poco::makeShared<Poco::JSON::Array>();
|
||||||
}
|
RemoveBand(Band, BB, CC );
|
||||||
|
BB = CC;
|
||||||
|
Arr.add(RR);
|
||||||
|
} else {
|
||||||
|
Arr.add(A_Radio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(Original->isArray(i)) {
|
|
||||||
auto Arr = Poco::makeShared<Poco::JSON::Array>();
|
|
||||||
auto Obj = Original->getArray(i);
|
|
||||||
ReplaceVariablesInArray(Obj,Arr);
|
|
||||||
Result->set(i,Arr);
|
|
||||||
} else if (Original->isObject(i)) {
|
|
||||||
auto Expanded = Poco::makeShared<Poco::JSON::Object>();
|
|
||||||
auto Obj = Original->getObject(i);
|
|
||||||
ReplaceVariablesInObject(Obj,Expanded);
|
|
||||||
Result->set(i,Expanded);
|
|
||||||
} else {
|
|
||||||
Result->set(i,Original->get(i));
|
|
||||||
}
|
}
|
||||||
|
for(const auto &i:*BB)
|
||||||
|
Arr.add(i);
|
||||||
|
} else {
|
||||||
|
Arr = *A;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool APConfig::ReplaceVariablesInArray( const Poco::JSON::Array::Ptr & Original, Poco::JSON::Array::Ptr & ResultArray) {
|
bool APConfig::merge(const Poco::JSON::Object::Ptr & A, const Poco::JSON::Object::Ptr & B, Poco::JSON::Object::Ptr &C) {
|
||||||
|
for(const auto &i:*A) {
|
||||||
for(const auto &element:*Original) {
|
const std::string & K = i.first;
|
||||||
|
// std::cout << "KEY: " << K << std::endl;
|
||||||
if(element.isArray()) {
|
if(B->has(K)) {
|
||||||
auto Expanded = Poco::makeShared<Poco::JSON::Array>();
|
if(A->isArray(K)) {
|
||||||
const auto & Object = element.extract<Poco::JSON::Array::Ptr>();
|
// std::cout << "ISARRAY" << std::endl;
|
||||||
ReplaceVariablesInArray(Object,Expanded);
|
if(B->isArray(K)) {
|
||||||
ResultArray->add(Expanded);
|
Poco::JSON::Array Arr;
|
||||||
} else if(element.isStruct()) {
|
auto AR1=A->getArray(K);
|
||||||
auto Expanded = Poco::makeShared<Poco::JSON::Object>();
|
auto AR2=B->getArray(K);
|
||||||
const auto & Object = element.extract<Poco::JSON::Object::Ptr>();
|
mergeArray(K,AR1,AR2,Arr);
|
||||||
ReplaceVariablesInObject(Object,Expanded);
|
C->set(K,Arr);
|
||||||
ResultArray->add(Expanded);
|
} else {
|
||||||
} else if( element.isString() ||
|
C->set(K,A->getArray(K));
|
||||||
element.isNumeric() ||
|
}
|
||||||
element.isBoolean() ||
|
}
|
||||||
element.isInteger() ||
|
else if(A->isObject(K) && B->isObject(K)) {
|
||||||
element.isSigned() ) {
|
// std::cout << "ISOBJECT" << std::endl;
|
||||||
ResultArray->add(element);
|
auto R=Poco::makeShared<Poco::JSON::Object>();
|
||||||
|
merge(A->getObject(K),B->getObject(K),R);
|
||||||
|
C->set(K,R);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
C->set(K,i.second);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
auto Expanded = Poco::makeShared<Poco::JSON::Object>();
|
C->set(K,i.second);
|
||||||
const auto & Object = element.extract<Poco::JSON::Object::Ptr>();
|
|
||||||
ReplaceVariablesInObject(Object,Expanded);
|
|
||||||
ResultArray->add(Expanded);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(const auto &i:*B) {
|
||||||
|
const std::string & K = i.first;
|
||||||
|
if(!A->has(K)) {
|
||||||
|
// std::cout << "Before leave" << std::endl;
|
||||||
|
// ShowJSON(C);
|
||||||
|
C->set(K, i.second);
|
||||||
|
// std::cout << "After leave" << std::endl;
|
||||||
|
// ShowJSON(C);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool APConfig::Get(Poco::JSON::Object::Ptr & Configuration) {
|
bool APConfig::Get(Poco::JSON::Object::Ptr &Configuration) {
|
||||||
if(Config_.empty()) {
|
if(Config_.empty()) {
|
||||||
Explanation_.clear();
|
Explanation_.clear();
|
||||||
try {
|
try {
|
||||||
if(!Sub_) {
|
ProvObjects::InventoryTag D;
|
||||||
ProvObjects::InventoryTag D;
|
if(StorageService()->InventoryDB().GetRecord("serialNumber", SerialNumber_, D)) {
|
||||||
if (StorageService()->InventoryDB().GetRecord("serialNumber", SerialNumber_, D)) {
|
if(!D.deviceConfiguration.empty()) {
|
||||||
if (!D.deviceConfiguration.empty()) {
|
AddConfiguration(D.deviceConfiguration);
|
||||||
AddConfiguration(D.deviceConfiguration);
|
|
||||||
}
|
|
||||||
if (!D.entity.empty()) {
|
|
||||||
AddEntityConfig(D.entity);
|
|
||||||
} else if (!D.venue.empty()) {
|
|
||||||
AddVenueConfig(D.venue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
if(!D.entity.empty()) {
|
||||||
ProvObjects::SubscriberDevice D;
|
AddEntityConfig(D.entity);
|
||||||
if (StorageService()->SubscriberDeviceDB().GetRecord("serialNumber", SerialNumber_, D)) {
|
} else if(!D.venue.empty()) {
|
||||||
if (!D.configuration.empty()) {
|
AddVenueConfig(D.venue);
|
||||||
AddConfiguration(D.configuration);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Now we have all the config we need.
|
// Now we have all the config we need.
|
||||||
@@ -153,56 +145,45 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// So we have sections...
|
||||||
|
// interfaces
|
||||||
|
// metrics
|
||||||
|
// radios
|
||||||
|
// services
|
||||||
|
// globals
|
||||||
|
// unit
|
||||||
|
auto Tmp=Poco::makeShared<Poco::JSON::Object>();
|
||||||
std::set<std::string> Sections;
|
std::set<std::string> Sections;
|
||||||
for(const auto &i:Config_) {
|
for(const auto &i:Config_) {
|
||||||
|
ShowJSON("Iteration Start:", Tmp);
|
||||||
Poco::JSON::Parser P;
|
Poco::JSON::Parser P;
|
||||||
auto O = P.parse(i.element.configuration).extract<Poco::JSON::Object::Ptr>();
|
auto O = P.parse(i.element.configuration).extract<Poco::JSON::Object::Ptr>();
|
||||||
auto Names = O->getNames();
|
auto Names = O->getNames();
|
||||||
for(const auto &SectionName:Names) {
|
auto SectionInfo = O->get(Names[0]);
|
||||||
auto InsertInfo = Sections.insert(SectionName);
|
auto InsertInfo = Sections.insert(Names[0]);
|
||||||
if (InsertInfo.second) {
|
if(InsertInfo.second) {
|
||||||
if (O->isArray(SectionName)) {
|
if(Explain_) {
|
||||||
auto OriginalArray = O->getArray(SectionName);
|
Poco::JSON::Object ExObj;
|
||||||
if (Explain_) {
|
ExObj.set("from-uuid", i.info.id);
|
||||||
Poco::JSON::Object ExObj;
|
ExObj.set("from-name", i.info.name);
|
||||||
ExObj.set("from-uuid", i.info.id);
|
ExObj.set("action", "added");
|
||||||
ExObj.set("from-name", i.info.name);
|
ExObj.set("element",SectionInfo);
|
||||||
ExObj.set("action", "added");
|
Explanation_.add(ExObj);
|
||||||
ExObj.set("element", OriginalArray);
|
}
|
||||||
Explanation_.add(ExObj);
|
Tmp->set(Names[0],O->get(Names[0]));
|
||||||
}
|
} else {
|
||||||
auto ExpandedArray = Poco::makeShared<Poco::JSON::Array>();
|
if(Explain_) {
|
||||||
ReplaceVariablesInArray(OriginalArray, ExpandedArray);
|
Poco::JSON::Object ExObj;
|
||||||
Configuration->set(SectionName, ExpandedArray);
|
ExObj.set("from-uuid", i.info.id);
|
||||||
} else if (O->isObject(SectionName)) {
|
ExObj.set("from-name", i.info.name);
|
||||||
auto OriginalSection = O->get(SectionName).extract<Poco::JSON::Object::Ptr>();
|
ExObj.set("action", "ignored");
|
||||||
if (Explain_) {
|
ExObj.set("reason","weight insufficient");
|
||||||
Poco::JSON::Object ExObj;
|
ExObj.set("element",SectionInfo);
|
||||||
ExObj.set("from-uuid", i.info.id);
|
Explanation_.add(ExObj);
|
||||||
ExObj.set("from-name", i.info.name);
|
|
||||||
ExObj.set("action", "added");
|
|
||||||
ExObj.set("element", OriginalSection);
|
|
||||||
Explanation_.add(ExObj);
|
|
||||||
}
|
|
||||||
auto ExpandedSection = Poco::makeShared<Poco::JSON::Object>();
|
|
||||||
ReplaceVariablesInObject(OriginalSection, ExpandedSection);
|
|
||||||
Configuration->set(SectionName, ExpandedSection);
|
|
||||||
} else {
|
|
||||||
std::cout << " --- unknown element type --- " << O->get(SectionName).toString() << std::endl;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (Explain_) {
|
|
||||||
Poco::JSON::Object ExObj;
|
|
||||||
ExObj.set("from-uuid", i.info.id);
|
|
||||||
ExObj.set("from-name", i.info.name);
|
|
||||||
ExObj.set("action", "ignored");
|
|
||||||
ExObj.set("reason", "weight insufficient");
|
|
||||||
ExObj.set("element", O->get(SectionName));
|
|
||||||
Explanation_.add(ExObj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Configuration = Tmp;
|
||||||
if(Config_.empty())
|
if(Config_.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -217,33 +198,19 @@ namespace OpenWifi {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void APConfig::AddConfiguration(const ProvObjects::DeviceConfigurationElementVec &Elements) {
|
|
||||||
for(const auto &i:Elements) {
|
|
||||||
if(i.weight==0) {
|
|
||||||
VerboseElement VE{ .element = i, .info = ProvObjects::ObjectInfo{} };
|
|
||||||
Config_.push_back(VE);
|
|
||||||
} else {
|
|
||||||
// we need to insert after everything bigger or equal
|
|
||||||
auto Hint = std::lower_bound(Config_.cbegin(),Config_.cend(),i.weight,
|
|
||||||
[](const VerboseElement &Elem, uint64_t Value) {
|
|
||||||
return Elem.element.weight>=Value; });
|
|
||||||
VerboseElement VE{ .element = i, .info = ProvObjects::ObjectInfo{}};
|
|
||||||
Config_.insert(Hint,VE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void APConfig::AddConfiguration(const Types::UUIDvec_t &UUIDs) {
|
void APConfig::AddConfiguration(const Types::UUIDvec_t &UUIDs) {
|
||||||
for(const auto &i:UUIDs)
|
for(const auto &i:UUIDs)
|
||||||
AddConfiguration(i);
|
AddConfiguration(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void APConfig::AddConfiguration(const std::string &UUID) {
|
void APConfig::AddConfiguration(const std::string &UUID) {
|
||||||
|
|
||||||
|
ProvObjects::DeviceConfiguration Config;
|
||||||
if(UUID.empty())
|
if(UUID.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ProvObjects::DeviceConfiguration Config;
|
if(StorageService()->ConfigurationDB().GetRecord("id", UUID,Config)) {
|
||||||
if(StorageService()->ConfigurationDB().GetRecord("id", UUID, Config)) {
|
// find where to insert into this list using the weight.
|
||||||
if(!Config.configuration.empty()) {
|
if(!Config.configuration.empty()) {
|
||||||
if(DeviceTypeMatch(DeviceType_,Config.deviceTypes)) {
|
if(DeviceTypeMatch(DeviceType_,Config.deviceTypes)) {
|
||||||
for(const auto &i:Config.configuration) {
|
for(const auto &i:Config.configuration) {
|
||||||
@@ -253,7 +220,7 @@ namespace OpenWifi {
|
|||||||
} else {
|
} else {
|
||||||
// we need to insert after everything bigger or equal
|
// we need to insert after everything bigger or equal
|
||||||
auto Hint = std::lower_bound(Config_.cbegin(),Config_.cend(),i.weight,
|
auto Hint = std::lower_bound(Config_.cbegin(),Config_.cend(),i.weight,
|
||||||
[](const VerboseElement &Elem, uint64_t Value) {
|
[](const VerboseElement &Elem, int Value) {
|
||||||
return Elem.element.weight>=Value; });
|
return Elem.element.weight>=Value; });
|
||||||
VerboseElement VE{ .element = i, .info = Config.info};
|
VerboseElement VE{ .element = i, .info = Config.info};
|
||||||
Config_.insert(Hint,VE);
|
Config_.insert(Hint,VE);
|
||||||
@@ -274,24 +241,21 @@ namespace OpenWifi {
|
|||||||
void APConfig::AddEntityConfig(const std::string &UUID) {
|
void APConfig::AddEntityConfig(const std::string &UUID) {
|
||||||
ProvObjects::Entity E;
|
ProvObjects::Entity E;
|
||||||
if(StorageService()->EntityDB().GetRecord("id",UUID,E)) {
|
if(StorageService()->EntityDB().GetRecord("id",UUID,E)) {
|
||||||
AddConfiguration(E.configurations);
|
AddConfiguration(E.deviceConfiguration);
|
||||||
if(!E.parent.empty()) {
|
if(!E.parent.empty())
|
||||||
AddEntityConfig(E.parent);
|
AddEntityConfig(E.parent);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void APConfig::AddVenueConfig(const std::string &UUID) {
|
void APConfig::AddVenueConfig(const std::string &UUID) {
|
||||||
ProvObjects::Venue V;
|
ProvObjects::Venue V;
|
||||||
if(StorageService()->VenueDB().GetRecord("id",UUID,V)) {
|
if(StorageService()->VenueDB().GetRecord("id",UUID,V)) {
|
||||||
AddConfiguration(V.configurations);
|
AddConfiguration(V.deviceConfiguration);
|
||||||
if(!V.entity.empty()) {
|
if(!V.entity.empty()) {
|
||||||
AddEntityConfig(V.entity);
|
AddEntityConfig(V.entity);
|
||||||
} else if(!V.parent.empty()) {
|
} else if(!V.parent.empty()) {
|
||||||
AddVenueConfig(V.parent);
|
AddVenueConfig(V.parent);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,14 +19,12 @@ namespace OpenWifi {
|
|||||||
class APConfig {
|
class APConfig {
|
||||||
public:
|
public:
|
||||||
explicit APConfig(const std::string & SerialNumber, const std::string & DeviceType, Poco::Logger & L, bool Explain=false);
|
explicit APConfig(const std::string & SerialNumber, const std::string & DeviceType, Poco::Logger & L, bool Explain=false);
|
||||||
explicit APConfig(const std::string & SerialNumber, Poco::Logger & L);
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] bool Get(Poco::JSON::Object::Ptr &Configuration);
|
[[nodiscard]] bool Get(Poco::JSON::Object::Ptr &Configuration);
|
||||||
|
|
||||||
void AddConfiguration(const std::string &UUID);
|
void AddConfiguration(const std::string &UUID);
|
||||||
void AddConfiguration(const Types::UUIDvec_t &UUID);
|
void AddConfiguration(const Types::UUIDvec_t &UUID);
|
||||||
void AddConfiguration(const ProvObjects::DeviceConfigurationElementVec &Elements);
|
|
||||||
void AddVenueConfig(const std::string &UUID);
|
void AddVenueConfig(const std::string &UUID);
|
||||||
void AddEntityConfig(const std::string &UUID);
|
void AddEntityConfig(const std::string &UUID);
|
||||||
const Poco::JSON::Array & Explanation() { return Explanation_; };
|
const Poco::JSON::Array & Explanation() { return Explanation_; };
|
||||||
@@ -39,11 +37,6 @@ namespace OpenWifi {
|
|||||||
Types::StringPairVec Errors;
|
Types::StringPairVec Errors;
|
||||||
bool Explain_=false;
|
bool Explain_=false;
|
||||||
Poco::JSON::Array Explanation_;
|
Poco::JSON::Array Explanation_;
|
||||||
bool Sub_=false;
|
|
||||||
Poco::Logger & Logger() { return Logger_;}
|
|
||||||
|
|
||||||
bool ReplaceVariablesInArray( const Poco::JSON::Array::Ptr & O, Poco::JSON::Array::Ptr & Result);
|
|
||||||
bool ReplaceVariablesInObject( const Poco::JSON::Object::Ptr & Original, Poco::JSON::Object::Ptr & Result);
|
|
||||||
|
|
||||||
bool FindRadio(const std::string &Band, const Poco::JSON::Array::Ptr &Arr, Poco::JSON::Object::Ptr & Radio);
|
bool FindRadio(const std::string &Band, const Poco::JSON::Array::Ptr &Arr, Poco::JSON::Object::Ptr & Radio);
|
||||||
bool mergeArray(const std::string &K, const Poco::JSON::Array::Ptr &A , const Poco::JSON::Array::Ptr &B, Poco::JSON::Array &Arr);
|
bool mergeArray(const std::string &K, const Poco::JSON::Array::Ptr &A , const Poco::JSON::Array::Ptr &B, Poco::JSON::Array &Arr);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "AutoDiscovery.h"
|
#include "AutoDiscovery.h"
|
||||||
#include "framework/ow_constants.h"
|
#include "framework/uCentral_Protocol.h"
|
||||||
#include "framework/KafkaTopics.h"
|
#include "framework/KafkaTopics.h"
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
|
|
||||||
@@ -55,12 +55,8 @@ namespace OpenWifi {
|
|||||||
DeviceType = PingMessage->get(uCentralProtocol::COMPATIBLE).toString();
|
DeviceType = PingMessage->get(uCentralProtocol::COMPATIBLE).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string Locale;
|
|
||||||
if(PayloadObj->has("locale"))
|
|
||||||
Locale = PayloadObj->get("locale").toString();
|
|
||||||
|
|
||||||
if (!SerialNumber.empty()) {
|
if (!SerialNumber.empty()) {
|
||||||
StorageService()->InventoryDB().CreateFromConnection(SerialNumber, ConnectedIP, DeviceType, Locale);
|
StorageService()->InventoryDB().CreateFromConnection(SerialNumber, ConnectedIP, DeviceType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const Poco::Exception &E) {
|
} catch (const Poco::Exception &E) {
|
||||||
|
|||||||
@@ -25,27 +25,27 @@ namespace OpenWifi {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigSanityChecker::Check_radios([[maybe_unused]] nlohmann::json &d) {
|
void ConfigSanityChecker::Check_radios(nlohmann::json &d) {
|
||||||
std::cout << "Validating radios" << std::endl;
|
std::cout << "Validating radios" << std::endl;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void ConfigSanityChecker::Check_interfaces([[maybe_unused]] nlohmann::json &d) {
|
void ConfigSanityChecker::Check_interfaces(nlohmann::json &d) {
|
||||||
std::cout << "Validating interfaces" << std::endl;
|
std::cout << "Validating interfaces" << std::endl;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void ConfigSanityChecker::Check_metrics([[maybe_unused]] nlohmann::json &d) {
|
void ConfigSanityChecker::Check_metrics(nlohmann::json &d) {
|
||||||
std::cout << "Validating metrics" << std::endl;
|
std::cout << "Validating metrics" << std::endl;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void ConfigSanityChecker::Check_services([[maybe_unused]] nlohmann::json &d) {
|
void ConfigSanityChecker::Check_services(nlohmann::json &d) {
|
||||||
std::cout << "Validating services" << std::endl;
|
std::cout << "Validating services" << std::endl;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void ConfigSanityChecker::Check_uuid([[maybe_unused]] nlohmann::json &d) {
|
void ConfigSanityChecker::Check_uuid(nlohmann::json &d) {
|
||||||
std::cout << "Validating uuid" << std::endl;
|
std::cout << "Validating uuid" << std::endl;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,10 +16,8 @@
|
|||||||
#include "framework/ConfigurationValidator.h"
|
#include "framework/ConfigurationValidator.h"
|
||||||
#include "SerialNumberCache.h"
|
#include "SerialNumberCache.h"
|
||||||
#include "JobController.h"
|
#include "JobController.h"
|
||||||
|
#include "WebSocketClientServer.h"
|
||||||
#include "FindCountry.h"
|
#include "FindCountry.h"
|
||||||
#include "Signup.h"
|
|
||||||
#include "DeviceTypeCache.h"
|
|
||||||
#include "FileDownloader.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
class Daemon *Daemon::instance_ = nullptr;
|
class Daemon *Daemon::instance_ = nullptr;
|
||||||
@@ -33,21 +31,18 @@ namespace OpenWifi {
|
|||||||
vDAEMON_BUS_TIMER,
|
vDAEMON_BUS_TIMER,
|
||||||
SubSystemVec{
|
SubSystemVec{
|
||||||
OpenWifi::StorageService(),
|
OpenWifi::StorageService(),
|
||||||
DeviceTypeCache(),
|
|
||||||
ConfigurationValidator(),
|
ConfigurationValidator(),
|
||||||
SerialNumberCache(),
|
SerialNumberCache(),
|
||||||
AutoDiscovery(),
|
AutoDiscovery(),
|
||||||
JobController(),
|
JobController(),
|
||||||
WebSocketClientServer(),
|
WebSocketClientServer(),
|
||||||
FindCountryFromIP(),
|
FindCountryFromIP()
|
||||||
Signup(),
|
|
||||||
FileDownloader()
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return instance_;
|
return instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Daemon::PostInitialization([[maybe_unused]] Poco::Util::Application &self) {
|
void Daemon::initialize() {
|
||||||
if(MicroService::instance().ConfigGetBool("firmware.updater.upgrade",false)) {
|
if(MicroService::instance().ConfigGetBool("firmware.updater.upgrade",false)) {
|
||||||
if(MicroService::instance().ConfigGetBool("firmware.updater.releaseonly",false)) {
|
if(MicroService::instance().ConfigGetBool("firmware.updater.releaseonly",false)) {
|
||||||
FWRules_ = ProvObjects::upgrade_release_only;
|
FWRules_ = ProvObjects::upgrade_release_only;
|
||||||
@@ -57,19 +52,11 @@ namespace OpenWifi {
|
|||||||
} else {
|
} else {
|
||||||
FWRules_ = ProvObjects::dont_upgrade;
|
FWRules_ = ProvObjects::dont_upgrade;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketProcessor_ = std::make_unique<ProvWebSocketClient>(logger());
|
|
||||||
|
|
||||||
AssetDir_ = MicroService::instance().DataDir() + "/wwwassets";
|
|
||||||
Poco::File DataDir(AssetDir_);
|
|
||||||
if(!DataDir.exists()) {
|
|
||||||
try {
|
|
||||||
DataDir.createDirectory();
|
|
||||||
} catch (const Poco::Exception &E) {
|
|
||||||
logger().log(E);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MicroServicePostInitialization() {
|
||||||
|
Daemon()->initialize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|||||||
27
src/Daemon.h
27
src/Daemon.h
@@ -18,15 +18,14 @@
|
|||||||
#include "framework/MicroService.h"
|
#include "framework/MicroService.h"
|
||||||
#include "framework/OpenWifiTypes.h"
|
#include "framework/OpenWifiTypes.h"
|
||||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||||
#include "ProvWebSocketClient.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
[[maybe_unused]] static const char * vDAEMON_PROPERTIES_FILENAME = "owprov.properties";
|
static const char * vDAEMON_PROPERTIES_FILENAME = "owprov.properties";
|
||||||
[[maybe_unused]] static const char * vDAEMON_ROOT_ENV_VAR = "OWPROV_ROOT";
|
static const char * vDAEMON_ROOT_ENV_VAR = "OWPROV_ROOT";
|
||||||
[[maybe_unused]] static const char * vDAEMON_CONFIG_ENV_VAR = "OWPROV_CONFIG";
|
static const char * vDAEMON_CONFIG_ENV_VAR = "OWPROV_CONFIG";
|
||||||
[[maybe_unused]] static const char * vDAEMON_APP_NAME = uSERVICE_PROVISIONING.c_str() ;
|
static const char * vDAEMON_APP_NAME = uSERVICE_PROVISIONING.c_str() ;
|
||||||
[[maybe_unused]] static const uint64_t vDAEMON_BUS_TIMER = 10000;
|
static const uint64_t vDAEMON_BUS_TIMER = 10000;
|
||||||
|
|
||||||
class Daemon : public MicroService {
|
class Daemon : public MicroService {
|
||||||
public:
|
public:
|
||||||
@@ -38,24 +37,18 @@ namespace OpenWifi {
|
|||||||
const SubSystemVec & SubSystems) :
|
const SubSystemVec & SubSystems) :
|
||||||
MicroService( PropFile, RootEnv, ConfigEnv, AppName, BusTimer, SubSystems) {};
|
MicroService( PropFile, RootEnv, ConfigEnv, AppName, BusTimer, SubSystems) {};
|
||||||
|
|
||||||
|
void initialize();
|
||||||
static Daemon *instance();
|
static Daemon *instance();
|
||||||
inline OpenWifi::ProvisioningDashboard & GetDashboard() { return DB_; }
|
inline OpenWifi::ProvisioningDashboard & GetDashboard() { return DB_; }
|
||||||
Poco::Logger & Log() { return Poco::Logger::get(AppName()); }
|
Poco::Logger & Log() { return Poco::Logger::get(AppName()); }
|
||||||
ProvObjects::FIRMWARE_UPGRADE_RULES FirmwareRules() const { return FWRules_; }
|
ProvObjects::FIRMWARE_UPGRADE_RULES FirmwareRules() const { return FWRules_; }
|
||||||
inline const std::string & AssetDir() { return AssetDir_; }
|
|
||||||
void PostInitialization(Poco::Util::Application &self);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Daemon *instance_;
|
static Daemon *instance_;
|
||||||
OpenWifi::ProvisioningDashboard DB_{};
|
OpenWifi::ProvisioningDashboard DB_{};
|
||||||
ProvObjects::FIRMWARE_UPGRADE_RULES FWRules_{ProvObjects::dont_upgrade};
|
ProvObjects::FIRMWARE_UPGRADE_RULES FWRules_{ProvObjects::dont_upgrade};
|
||||||
std::string AssetDir_;
|
|
||||||
std::unique_ptr<ProvWebSocketClient> WebSocketProcessor_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Daemon * Daemon() { return Daemon::instance(); }
|
inline Daemon * Daemon() { return Daemon::instance(); }
|
||||||
inline void DaemonPostInitialization(Poco::Util::Application &self) {
|
|
||||||
Daemon()->PostInitialization(self);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
void ProvisioningDashboard::Create() {
|
void ProvisioningDashboard::Create() {
|
||||||
uint64_t Now = OpenWifi::Now();
|
uint64_t Now = std::time(nullptr);
|
||||||
if(LastRun_==0 || (Now-LastRun_)>120) {
|
if(LastRun_==0 || (Now-LastRun_)>120) {
|
||||||
DB_.reset();
|
DB_.reset();
|
||||||
// Todo: call dashboard creation code.
|
// Todo: call dashboard creation code.
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-02-23.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "Poco/Timer.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
class DeviceTypeCache : public SubSystemServer {
|
|
||||||
public:
|
|
||||||
inline static auto instance() {
|
|
||||||
static auto instance_ = new DeviceTypeCache;
|
|
||||||
return instance_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int Start() final {
|
|
||||||
InitializeCache();
|
|
||||||
TimerCallback_ = std::make_unique<Poco::TimerCallback<DeviceTypeCache>>(*this,&DeviceTypeCache::onTimer);
|
|
||||||
Timer_.setStartInterval( 60 * 1000); // first run in 60 seconds
|
|
||||||
Timer_.setPeriodicInterval(1 * 60 * 60 * 1000); // 1 hours
|
|
||||||
Timer_.start(*TimerCallback_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Stop() final {
|
|
||||||
Timer_.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void onTimer([[maybe_unused]] Poco::Timer & timer) {
|
|
||||||
UpdateDeviceTypes();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool IsAcceptableDeviceType(const std::string &D) const { return (DeviceTypes_.find(D)!=DeviceTypes_.end());};
|
|
||||||
inline bool AreAcceptableDeviceTypes(const Types::StringVec &S, bool WildCardAllowed=true) const {
|
|
||||||
for(const auto &i:S) {
|
|
||||||
if(WildCardAllowed && i=="*") {
|
|
||||||
// We allow wildcards
|
|
||||||
} else if(DeviceTypes_.find(i)==DeviceTypes_.end())
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::atomic_bool Initialized_=false;
|
|
||||||
Poco::Timer Timer_;
|
|
||||||
std::set<std::string> DeviceTypes_;
|
|
||||||
std::unique_ptr<Poco::TimerCallback<DeviceTypeCache>> TimerCallback_;
|
|
||||||
|
|
||||||
inline DeviceTypeCache() noexcept:
|
|
||||||
SubSystemServer("DeviceTypes", "DEV-TYPES", "devicetypes")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void InitializeCache() {
|
|
||||||
std::lock_guard G(Mutex_);
|
|
||||||
|
|
||||||
Initialized_ = true;
|
|
||||||
std::string DeviceTypes;
|
|
||||||
if(AppServiceRegistry().Get("deviceTypes",DeviceTypes)) {
|
|
||||||
Poco::JSON::Parser P;
|
|
||||||
try {
|
|
||||||
auto O = P.parse(DeviceTypes).extract<Poco::JSON::Array::Ptr>();
|
|
||||||
for(const auto &i:*O) {
|
|
||||||
DeviceTypes_.insert(i.toString());
|
|
||||||
}
|
|
||||||
} catch (...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool UpdateDeviceTypes() {
|
|
||||||
try {
|
|
||||||
Types::StringPairVec QueryData;
|
|
||||||
|
|
||||||
QueryData.push_back(std::make_pair("deviceSet","true"));
|
|
||||||
OpenAPIRequestGet Req( uSERVICE_FIRMWARE,
|
|
||||||
"/api/v1/firmwares",
|
|
||||||
QueryData,
|
|
||||||
10000);
|
|
||||||
|
|
||||||
auto Response = Poco::makeShared<Poco::JSON::Object>();
|
|
||||||
auto StatusCode = Req.Do(Response);
|
|
||||||
if( StatusCode == Poco::Net::HTTPResponse::HTTP_OK) {
|
|
||||||
if(Response->isArray("deviceTypes")) {
|
|
||||||
std::lock_guard G(Mutex_);
|
|
||||||
DeviceTypes_.clear();
|
|
||||||
auto Array = Response->getArray("deviceTypes");
|
|
||||||
for(const auto &i:*Array) {
|
|
||||||
// std::cout << "Adding deviceType:" << i.toString() << std::endl;
|
|
||||||
DeviceTypes_.insert(i.toString());
|
|
||||||
}
|
|
||||||
SaveCache();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
} catch (const Poco::Exception &E) {
|
|
||||||
Logger().log(E);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void SaveCache() {
|
|
||||||
std::lock_guard G(Mutex_);
|
|
||||||
|
|
||||||
Poco::JSON::Array Arr;
|
|
||||||
for(auto const &i:DeviceTypes_)
|
|
||||||
Arr.add(i);
|
|
||||||
|
|
||||||
std::stringstream OS;
|
|
||||||
Arr.stringify(OS);
|
|
||||||
|
|
||||||
AppServiceRegistry().Set("deviceTypes", OS.str());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
inline auto DeviceTypeCache() { return DeviceTypeCache::instance(); }
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-03-11.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "FileDownloader.h"
|
|
||||||
#include "Daemon.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
int FileDownloader::Start() {
|
|
||||||
TimerCallback_ = std::make_unique<Poco::TimerCallback<FileDownloader>>(*this,&FileDownloader::onTimer);
|
|
||||||
Timer_.setStartInterval( 20 * 1000); // first run in 20 seconds
|
|
||||||
Timer_.setPeriodicInterval(2 * 60 * 60 * 1000); // 1 hours
|
|
||||||
Timer_.start(*TimerCallback_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileDownloader::Stop() {
|
|
||||||
Timer_.stop();
|
|
||||||
Logger().notice("Stopping.");
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileDownloader::onTimer([[maybe_unused]] Poco::Timer &timer) {
|
|
||||||
const static std::vector<std::pair<std::string,std::string>> Files
|
|
||||||
{
|
|
||||||
{"https://raw.githubusercontent.com/blogic/ucentral-schema/main/ucentral.schema.json", "ucentral.schema.json" },
|
|
||||||
{"https://ucentral.io/ucentral.schema.pretty.json", "ucentral.schema.pretty.json" }
|
|
||||||
};
|
|
||||||
|
|
||||||
for(const auto &[url,filename]:Files) {
|
|
||||||
try {
|
|
||||||
std::string FileContent;
|
|
||||||
if (Utils::wgets(url, FileContent)) {
|
|
||||||
std::ofstream OutputStream(Daemon()->AssetDir() + "/" + filename,
|
|
||||||
std::ios_base::out | std::ios_base::trunc);
|
|
||||||
OutputStream << FileContent;
|
|
||||||
Logger().warning(Poco::format("File %s was downloaded",url));
|
|
||||||
}
|
|
||||||
} catch(...) {
|
|
||||||
Logger().warning(Poco::format("File %s could not be downloaded",url));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-03-11.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "Poco/Timer.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
class FileDownloader : public SubSystemServer {
|
|
||||||
public:
|
|
||||||
|
|
||||||
static auto instance() {
|
|
||||||
static auto instance_ = new FileDownloader;
|
|
||||||
return instance_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Start() override;
|
|
||||||
void Stop() override;
|
|
||||||
void onTimer(Poco::Timer & timer);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Poco::Timer Timer_;
|
|
||||||
std::unique_ptr<Poco::TimerCallback<FileDownloader>> TimerCallback_;
|
|
||||||
std::atomic_bool Running_ = false;
|
|
||||||
|
|
||||||
FileDownloader() noexcept:
|
|
||||||
SubSystemServer("FileDownloader", "FILE-DOWNLOADER", "downloader") {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
inline auto FileDownloader() { return FileDownloader::instance(); }
|
|
||||||
}
|
|
||||||
@@ -55,11 +55,12 @@ namespace OpenWifi {
|
|||||||
std::string Description,
|
std::string Description,
|
||||||
std::string RegisteredName,
|
std::string RegisteredName,
|
||||||
ParametersVec Parameters,
|
ParametersVec Parameters,
|
||||||
[[maybe_unused]] bool Parallel=true) :
|
bool Parallel=true) :
|
||||||
Title_(std::move(Title)),
|
Title_(std::move(Title)),
|
||||||
Description_(std::move(Description)),
|
Description_(std::move(Description)),
|
||||||
RegisteredName_(std::move(RegisteredName)),
|
RegisteredName_(std::move(RegisteredName)),
|
||||||
Parameters_(std::move(Parameters))
|
Parameters_(std::move(Parameters)),
|
||||||
|
Parallel_(Parallel)
|
||||||
{
|
{
|
||||||
UUID_ = MicroService::instance().CreateUUID();
|
UUID_ = MicroService::instance().CreateUUID();
|
||||||
}
|
}
|
||||||
@@ -72,6 +73,7 @@ namespace OpenWifi {
|
|||||||
std::string Description_;
|
std::string Description_;
|
||||||
std::string RegisteredName_;
|
std::string RegisteredName_;
|
||||||
ParametersVec Parameters_;
|
ParametersVec Parameters_;
|
||||||
|
bool Parallel_=true;
|
||||||
};
|
};
|
||||||
|
|
||||||
class JobRegistry {
|
class JobRegistry {
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-01.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "Kafka_ProvUpdater.h"
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-01.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
enum ProvisioningOperation {
|
|
||||||
creation=0, modification, removal
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename ObjectType> inline bool UpdateKafkaProvisioningObject( ProvisioningOperation op, const ObjectType & obj) {
|
|
||||||
static std::vector<std::string> Ops{ "creation", "modification", "removal" };
|
|
||||||
|
|
||||||
std::string OT{"object"};
|
|
||||||
if constexpr(std::is_same_v<ObjectType,ProvObjects::Venue>) {
|
|
||||||
OT = "Venue";
|
|
||||||
}
|
|
||||||
if constexpr(std::is_same_v<ObjectType,ProvObjects::Entity>) {
|
|
||||||
OT = "Entity";
|
|
||||||
}
|
|
||||||
if constexpr(std::is_same_v<ObjectType,ProvObjects::InventoryTag>) {
|
|
||||||
OT = "InventoryTag";
|
|
||||||
}
|
|
||||||
if constexpr(std::is_same_v<ObjectType,ProvObjects::Contact>) {
|
|
||||||
OT = "Contact";
|
|
||||||
}
|
|
||||||
if constexpr(std::is_same_v<ObjectType,ProvObjects::Location>) {
|
|
||||||
OT = "Location";
|
|
||||||
}
|
|
||||||
if constexpr(std::is_same_v<ObjectType,ProvObjects::DeviceConfiguration>) {
|
|
||||||
OT = "DeviceConfiguration";
|
|
||||||
}
|
|
||||||
|
|
||||||
Poco::JSON::Object Payload;
|
|
||||||
obj.to_json(Payload);
|
|
||||||
Payload.set("ObjectType",OT);
|
|
||||||
std::ostringstream OS;
|
|
||||||
Payload.stringify(OS);
|
|
||||||
KafkaManager()->PostMessage(KafkaTopics::PROVISIONING_CHANGE, Ops[op] , OS.str());
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-28.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "ProvWebSocketClient.h"
|
|
||||||
|
|
||||||
#include "StorageService.h"
|
|
||||||
#include "SerialNumberCache.h"
|
|
||||||
#include "sdks/SDK_sec.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
ProvWebSocketClient::ProvWebSocketClient(Poco::Logger &Logger) :
|
|
||||||
Logger_(Logger){
|
|
||||||
WebSocketClientServer()->SetProcessor(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvWebSocketClient::~ProvWebSocketClient() {
|
|
||||||
WebSocketClientServer()->SetProcessor(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProvWebSocketClient::ws_command_serial_number_search(const Poco::JSON::Object::Ptr &O,
|
|
||||||
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);
|
|
||||||
Poco::JSON::Array Arr;
|
|
||||||
for (const auto &i : Numbers)
|
|
||||||
Arr.add(Utils::int_to_hex(i));
|
|
||||||
Poco::JSON::Object RetObj;
|
|
||||||
RetObj.set("serialNumbers", Arr);
|
|
||||||
std::ostringstream SS;
|
|
||||||
Poco::JSON::Stringifier::stringify(RetObj, SS);
|
|
||||||
Answer = SS.str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProvWebSocketClient::ws_command_address_completion(const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer) {
|
|
||||||
Done = false;
|
|
||||||
auto Address = O->get("address").toString();
|
|
||||||
Answer = GoogleGeoCodeCall(Address);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProvWebSocketClient::ws_command_exit([[maybe_unused]] const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer) {
|
|
||||||
Done = true;
|
|
||||||
Answer = R"lit({ "closing" : "Goodbye! Aurevoir! Hasta la vista!" })lit";
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProvWebSocketClient::ws_command_invalid([[maybe_unused]] const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer) {
|
|
||||||
Done = false;
|
|
||||||
Answer = std::string{R"lit({ "error" : "invalid command" })lit"};
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProvWebSocketClient::ws_command_subuser_search( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer) {
|
|
||||||
Done = false;
|
|
||||||
auto operatorId = O->get("operatorId").toString();
|
|
||||||
std::string nameSearch, emailSearch;
|
|
||||||
OpenWifi::RESTAPIHandler::AssignIfPresent(O,"nameSearch",nameSearch);
|
|
||||||
OpenWifi::RESTAPIHandler::AssignIfPresent(O,"emailSearch",emailSearch);
|
|
||||||
SecurityObjects::UserInfoList Users;
|
|
||||||
SDK::Sec::Subscriber::Search(nullptr,operatorId,nameSearch,emailSearch,Users);
|
|
||||||
|
|
||||||
Poco::JSON::Array Arr;
|
|
||||||
for(const auto &i:Users.users) {
|
|
||||||
Poco::JSON::Object OO;
|
|
||||||
OO.set("name", i.name);
|
|
||||||
OO.set("email", i.email);
|
|
||||||
OO.set("id", i.id);
|
|
||||||
i.to_json(OO);
|
|
||||||
Arr.add(OO);
|
|
||||||
}
|
|
||||||
Poco::JSON::Object ObjAnswer;
|
|
||||||
ObjAnswer.set("users", Arr);
|
|
||||||
std::ostringstream SS;
|
|
||||||
Poco::JSON::Stringifier::stringify(ObjAnswer, SS);
|
|
||||||
Answer = SS.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProvWebSocketClient::ws_command_subdevice_search( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer) {
|
|
||||||
Done = false;
|
|
||||||
auto operatorId = O->get("operatorId").toString();
|
|
||||||
auto Prefix = O->get("serial_prefix").toString();
|
|
||||||
std::string Query;
|
|
||||||
|
|
||||||
if(Prefix[0]=='*') {
|
|
||||||
Query = fmt::format(" operatorId='{}' and (right(serialNumber,{})='{}' or right(realMacAddress,{})='{}' ) ",
|
|
||||||
operatorId, Prefix.size()-1, Prefix.substr(1), Prefix.size()-1, Prefix.substr(1));
|
|
||||||
} else {
|
|
||||||
Query = fmt::format(" operatorId='{}' and (left(serialNumber,{})='{}' or left(realMacAddress,{})='{}' ) ",
|
|
||||||
operatorId, Prefix.size(), Prefix, Prefix.size(), Prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ProvObjects::SubscriberDevice> SubDevices;
|
|
||||||
|
|
||||||
StorageService()->SubscriberDeviceDB().GetRecords(0,200,SubDevices,Query);
|
|
||||||
Poco::JSON::Array Arr;
|
|
||||||
for(const auto &i:SubDevices) {
|
|
||||||
Arr.add(i.serialNumber);
|
|
||||||
}
|
|
||||||
Poco::JSON::Object RetObj;
|
|
||||||
RetObj.set("serialNumbers", Arr);
|
|
||||||
std::ostringstream SS;
|
|
||||||
Poco::JSON::Stringifier::stringify(RetObj, SS);
|
|
||||||
Answer = SS.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProvWebSocketClient::Processor(const Poco::JSON::Object::Ptr &O, std::string &Result, bool &Done ) {
|
|
||||||
try {
|
|
||||||
if (O->has("command") && O->has("id")) {
|
|
||||||
auto id = (uint64_t) O->get("id");
|
|
||||||
std::string Answer;
|
|
||||||
auto Command = O->get("command").toString();
|
|
||||||
if (Command == "serial_number_search" && O->has("serial_prefix")) {
|
|
||||||
ws_command_serial_number_search(O,Done,Answer);
|
|
||||||
} else if (WebSocketClientServer()->GeoCodeEnabled() && Command == "address_completion" && O->has("address")) {
|
|
||||||
ws_command_address_completion(O,Done,Answer);
|
|
||||||
} else if (WebSocketClientServer()->GeoCodeEnabled() && Command == "subuser_search" && O->has("operatorId")) {
|
|
||||||
ws_command_subuser_search(O,Done,Answer);
|
|
||||||
} else if (WebSocketClientServer()->GeoCodeEnabled() && Command == "subdevice_search" && O->has("operatorId") && O->has("serial_prefix")) {
|
|
||||||
ws_command_subdevice_search(O,Done,Answer);
|
|
||||||
} else if (Command=="exit") {
|
|
||||||
ws_command_exit(O,Done,Answer);
|
|
||||||
} else {
|
|
||||||
ws_command_invalid(O,Done,Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result = fmt::format("{{ \"command_response_id\" : {} , \"response\" : {} }}" , id, Answer);
|
|
||||||
}
|
|
||||||
} catch (const Poco::Exception &E) {
|
|
||||||
Logger().log(E);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ProvWebSocketClient::GoogleGeoCodeCall(const std::string &A) {
|
|
||||||
try {
|
|
||||||
std::string URI = { "https://maps.googleapis.com/maps/api/geocode/json"};
|
|
||||||
Poco::URI uri(URI);
|
|
||||||
|
|
||||||
uri.addQueryParameter("address",A);
|
|
||||||
uri.addQueryParameter("key", WebSocketClientServer()->GoogleApiKey());
|
|
||||||
|
|
||||||
Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort());
|
|
||||||
Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, uri.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1);
|
|
||||||
session.sendRequest(req);
|
|
||||||
Poco::Net::HTTPResponse res;
|
|
||||||
std::istream& rs = session.receiveResponse(res);
|
|
||||||
if(res.getStatus()==Poco::Net::HTTPResponse::HTTP_OK) {
|
|
||||||
std::ostringstream os;
|
|
||||||
Poco::StreamCopier::copyStream(rs,os);
|
|
||||||
return os.str();
|
|
||||||
} else {
|
|
||||||
std::ostringstream os;
|
|
||||||
Poco::StreamCopier::copyStream(rs,os);
|
|
||||||
return R"lit({ "error: )lit" + os.str() + R"lit( })lit";
|
|
||||||
}
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return "{ \"error\" : \"No call made\" }";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-28.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
class ProvWebSocketClient : public WebSocketClientProcessor {
|
|
||||||
public:
|
|
||||||
explicit ProvWebSocketClient(Poco::Logger &Logger);
|
|
||||||
virtual ~ProvWebSocketClient();
|
|
||||||
virtual void Processor(const Poco::JSON::Object::Ptr &O, std::string &Answer, bool &Done );
|
|
||||||
void ws_command_serial_number_search( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer);
|
|
||||||
void ws_command_address_completion( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer);
|
|
||||||
void ws_command_exit( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer);
|
|
||||||
void ws_command_invalid( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer);
|
|
||||||
void ws_command_subuser_search( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer);
|
|
||||||
void ws_command_subdevice_search( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer);
|
|
||||||
std::string GoogleGeoCodeCall(const std::string &A);
|
|
||||||
private:
|
|
||||||
Poco::Logger & Logger_;
|
|
||||||
inline Poco::Logger & Logger() { return Logger_; }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2021-07-10.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_asset_server.h"
|
|
||||||
#include "Poco/File.h"
|
|
||||||
#include "framework/ow_constants.h"
|
|
||||||
#include "Daemon.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
void RESTAPI_asset_server::DoGet() {
|
|
||||||
Poco::File AssetFile;
|
|
||||||
|
|
||||||
std::string AssetName = GetBinding(RESTAPI::Protocol::ID, "");
|
|
||||||
AssetFile = Daemon()->AssetDir() + "/" + AssetName;
|
|
||||||
if(!AssetFile.isFile()) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
SendFile(AssetFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2021-07-10.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "../framework/MicroService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
class RESTAPI_asset_server : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_asset_server(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>
|
|
||||||
{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal, false) {}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/wwwassets/{id}"}; };
|
|
||||||
void DoGet() final;
|
|
||||||
void DoPost() final {};
|
|
||||||
void DoDelete() final {};
|
|
||||||
void DoPut() final {};
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -11,9 +11,9 @@
|
|||||||
#include "RESTAPI_configurations_handler.h"
|
#include "RESTAPI_configurations_handler.h"
|
||||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
|
#include "framework/RESTAPI_errors.h"
|
||||||
#include "framework/ConfigurationValidator.h"
|
#include "framework/ConfigurationValidator.h"
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||||
#include "DeviceTypeCache.h"
|
|
||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
|
|
||||||
@@ -65,14 +65,39 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
DB_.DeleteRecord("id", UUID);
|
if(DB_.DeleteRecord("id", UUID)) {
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
|
return OK();
|
||||||
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::configurations,Existing.venue,Existing.info.id);
|
}
|
||||||
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::configurations,Existing.entity,Existing.info.id);
|
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||||
for(const auto &i:Existing.variables)
|
}
|
||||||
RemoveMembership(StorageService()->VariablesDB(),&ProvObjects::VariableBlock::configurations,i,Existing.info.id);
|
|
||||||
|
|
||||||
return OK();
|
bool RESTAPI_configurations_handler::ValidateConfigBlock(const ProvObjects::DeviceConfiguration &Config, std::string & Error) {
|
||||||
|
static const std::vector<std::string> SectionNames{ "globals", "interfaces", "metrics", "radios", "services", "unit" };
|
||||||
|
|
||||||
|
for(const auto &i:Config.configuration) {
|
||||||
|
Poco::JSON::Parser P;
|
||||||
|
if(i.name.empty()) {
|
||||||
|
BadRequest(RESTAPI::Errors::NameMustBeSet);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto Blocks = P.parse(i.configuration).extract<Poco::JSON::Object::Ptr>();
|
||||||
|
auto N = Blocks->getNames();
|
||||||
|
for(const auto &j:N) {
|
||||||
|
if(std::find(SectionNames.cbegin(),SectionNames.cend(),j)==SectionNames.cend()) {
|
||||||
|
BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ValidateUCentralConfiguration(i.configuration, Error)) {
|
||||||
|
/* nothing to do */ ;
|
||||||
|
} else {
|
||||||
|
// std::cout << "Block: " << std::endl << ">>>" << std::endl << i.configuration << std::endl << ">>> REJECTED" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_configurations_handler::DoPost() {
|
void RESTAPI_configurations_handler::DoPost() {
|
||||||
@@ -81,13 +106,13 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
std::string Arg;
|
std::string Arg;
|
||||||
if(HasParameter("validateOnly",Arg) && Arg=="true") {
|
if(HasParameter("validateOnly",Arg) && Arg=="true") {
|
||||||
if(!RawObject->has("configuration")) {
|
auto Body = ParseStream();
|
||||||
return BadRequest(RESTAPI::Errors::MustHaveConfigElement);
|
if(!Body->has("configuration")) {
|
||||||
|
return BadRequest("Must have 'configuration' element.");
|
||||||
}
|
}
|
||||||
auto Config=RawObject->get("configuration").toString();
|
auto Config=Body->get("configuration").toString();
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
std::string Error;
|
std::string Error;
|
||||||
auto Res = ValidateUCentralConfiguration(Config,Error);
|
auto Res = ValidateUCentralConfiguration(Config,Error);
|
||||||
@@ -96,50 +121,37 @@ namespace OpenWifi{
|
|||||||
return ReturnObject(Answer);
|
return ReturnObject(Answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProvObjects::DeviceConfiguration NewObject;
|
ProvObjects::DeviceConfiguration C;
|
||||||
if (!NewObject.from_json(RawObject)) {
|
Poco::JSON::Object::Ptr Obj = ParseStream();
|
||||||
|
if (!C.from_json(Obj)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules,*this))) {
|
if(!ProvObjects::CreateObjectInfo(Obj,UserInfo_.userinfo,C.info)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!ProvObjects::CreateObjectInfo(RawObject,UserInfo_.userinfo,NewObject.info)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
|
if(!C.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",C.managementPolicy)) {
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
return BadRequest(RESTAPI::Errors::UnknownId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!NewObject.venue.empty() && !StorageService()->VenueDB().Exists("id",NewObject.venue)) {
|
C.inUse.clear();
|
||||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
if(C.deviceTypes.empty() || !StorageService()->AreAcceptableDeviceTypes(C.deviceTypes, true)) {
|
||||||
}
|
|
||||||
|
|
||||||
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
NewObject.inUse.clear();
|
|
||||||
if(NewObject.deviceTypes.empty() || !DeviceTypeCache()->AreAcceptableDeviceTypes(NewObject.deviceTypes, true)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
|
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
RESTAPI::Errors::msg Error;
|
std::string Error;
|
||||||
if(!ValidateConfigBlock(NewObject,Error)) {
|
if(!ValidateConfigBlock(C,Error)) {
|
||||||
return BadRequest(Error);
|
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid + ", error: " + Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(DB_.CreateRecord(NewObject)) {
|
if(DB_.CreateRecord(C)) {
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
|
DB_.GetRecord("id", C.info.id, C);
|
||||||
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::configurations,NewObject.venue, NewObject.info.id);
|
if(!C.managementPolicy.empty())
|
||||||
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::configurations,NewObject.entity, NewObject.info.id);
|
StorageService()->PolicyDB().AddInUse("id",C.managementPolicy,DB_.Prefix(), C.info.id);
|
||||||
|
|
||||||
ConfigurationDB::RecordName AddedRecord;
|
|
||||||
DB_.GetRecord("id", NewObject.info.id, AddedRecord);
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
AddedRecord.to_json(Answer);
|
C.to_json(Answer);
|
||||||
return ReturnObject(Answer);
|
return ReturnObject(Answer);
|
||||||
}
|
}
|
||||||
InternalError(RESTAPI::Errors::RecordNotCreated);
|
InternalError(RESTAPI::Errors::RecordNotCreated);
|
||||||
@@ -152,72 +164,57 @@ namespace OpenWifi{
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
ProvObjects::DeviceConfiguration NewObject;
|
ProvObjects::DeviceConfiguration NewConfig;
|
||||||
const auto & RawObject = ParsedBody_;
|
auto ParsedObj = ParseStream();
|
||||||
if (!NewObject.from_json(RawObject)) {
|
if (!NewConfig.from_json(ParsedObj)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules,*this))) {
|
if(!UpdateObjectInfo(ParsedObj, UserInfo_.userinfo, Existing.info)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!NewObject.deviceTypes.empty() && !DeviceTypeCache()->AreAcceptableDeviceTypes(NewObject.deviceTypes, true)) {
|
if(!NewConfig.deviceTypes.empty() && !StorageService()->AreAcceptableDeviceTypes(NewConfig.deviceTypes, true)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
|
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!NewObject.deviceTypes.empty())
|
std::string Error;
|
||||||
Existing.deviceTypes = NewObject.deviceTypes;
|
if(!ValidateConfigBlock( NewConfig,Error)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid + ", error: " + Error);
|
||||||
RESTAPI::Errors::msg Error;
|
|
||||||
if(!ValidateConfigBlock( NewObject,Error)) {
|
|
||||||
return BadRequest(Error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(RawObject->has("configuration")) {
|
if(ParsedObj->has("configuration")) {
|
||||||
Existing.configuration = NewObject.configuration;
|
Existing.configuration = NewConfig.configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FromPolicy, ToPolicy;
|
std::string MovePolicy;
|
||||||
if(!CreateMove(RawObject,"managementPolicy",&ConfigurationDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
|
bool MovingPolicy=false;
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
if(AssignIfPresent(ParsedObj,"managementPolicy",MovePolicy)) {
|
||||||
|
if(!MovePolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewConfig.managementPolicy)) {
|
||||||
std::string FromEntity, ToEntity;
|
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
if(!CreateMove(RawObject,"entity",&ConfigurationDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
|
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
|
|
||||||
std::string FromVenue, ToVenue;
|
|
||||||
if(!CreateMove(RawObject,"venue",&ConfigurationDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB()))
|
|
||||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
|
||||||
|
|
||||||
Types::UUIDvec_t FromVariables, ToVariables;
|
|
||||||
if(RawObject->has("variables")) {
|
|
||||||
for(const auto &i:NewObject.variables) {
|
|
||||||
if(!i.empty() && !StorageService()->VariablesDB().Exists("id",i)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::VariableMustExist);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for(const auto &i:Existing.variables)
|
MovingPolicy = NewConfig.managementPolicy != Existing.managementPolicy;
|
||||||
FromVariables.emplace_back(i);
|
|
||||||
for(const auto &i:NewObject.variables)
|
|
||||||
ToVariables.emplace_back(i);
|
|
||||||
FromVariables = Existing.variables;
|
|
||||||
ToVariables = NewObject.variables;
|
|
||||||
Existing.variables = ToVariables;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(RawObject->has("deviceRules"))
|
if(!NewConfig.deviceTypes.empty())
|
||||||
Existing.deviceRules = NewObject.deviceRules;
|
Existing.deviceTypes = NewConfig.deviceTypes;
|
||||||
|
|
||||||
|
AssignIfPresent(ParsedObj, "rrm", Existing.rrm);
|
||||||
|
AssignIfPresent(ParsedObj,"firmwareUpgrade",Existing.firmwareUpgrade);
|
||||||
|
AssignIfPresent(ParsedObj,"firmwareRCOnly", Existing.firmwareRCOnly);
|
||||||
|
|
||||||
|
if(!NewConfig.variables.empty())
|
||||||
|
Existing.variables = NewConfig.variables;
|
||||||
|
|
||||||
if(DB_.UpdateRecord("id",UUID,Existing)) {
|
if(DB_.UpdateRecord("id",UUID,Existing)) {
|
||||||
ManageMembership(StorageService()->VariablesDB(),&ProvObjects::VariableBlock::configurations, FromVariables, ToVariables, Existing.info.id);
|
if(MovingPolicy) {
|
||||||
ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::configurations, FromVenue, ToVenue, Existing.info.id);
|
if(!Existing.managementPolicy.empty())
|
||||||
ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::configurations, FromEntity, ToEntity, Existing.info.id);
|
StorageService()->PolicyDB().DeleteInUse("id",Existing.managementPolicy,DB_.Prefix(),Existing.info.id);
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id);
|
if(!MovePolicy.empty())
|
||||||
|
StorageService()->PolicyDB().AddInUse("id",MovePolicy,DB_.Prefix(),Existing.info.id);
|
||||||
|
Existing.managementPolicy = MovePolicy;
|
||||||
|
}
|
||||||
|
DB_.UpdateRecord("id", UUID, Existing);
|
||||||
|
|
||||||
ProvObjects::DeviceConfiguration D;
|
ProvObjects::DeviceConfiguration D;
|
||||||
DB_.GetRecord("id",UUID,D);
|
DB_.GetRecord("id",UUID,D);
|
||||||
|
|||||||
@@ -22,13 +22,17 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal),
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/configuration/{uuid}"}; };
|
DB_(StorageService()->ConfigurationDB()){}
|
||||||
private:
|
|
||||||
ConfigurationDB &DB_=StorageService()->ConfigurationDB();
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/configurations/{uuid}"}; };
|
||||||
|
|
||||||
void DoGet();
|
void DoGet();
|
||||||
void DoPost();
|
void DoPost();
|
||||||
void DoPut();
|
void DoPut();
|
||||||
void DoDelete();
|
void DoDelete();
|
||||||
|
private:
|
||||||
|
bool ValidateConfigBlock(const ProvObjects::DeviceConfiguration &Config, std::string & Error);
|
||||||
|
ConfigurationDB &DB_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,17 @@
|
|||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
void RESTAPI_configurations_list_handler::DoGet() {
|
void RESTAPI_configurations_list_handler::DoGet() {
|
||||||
return ListHandler<ConfigurationDB>("configurations", DB_, *this);
|
if(!QB_.Select.empty()) {
|
||||||
|
return ReturnRecordList<decltype(StorageService()->ConfigurationDB()),
|
||||||
|
ProvObjects::DeviceConfiguration>("configurations",StorageService()->ConfigurationDB(),*this );
|
||||||
|
} else if(QB_.CountOnly) {
|
||||||
|
Poco::JSON::Object Answer;
|
||||||
|
auto C = StorageService()->ConfigurationDB().Count();
|
||||||
|
return ReturnCountOnly(C);
|
||||||
|
} else {
|
||||||
|
ProvObjects::DeviceConfigurationVec Configs;
|
||||||
|
StorageService()->ConfigurationDB().GetRecords(QB_.Offset,QB_.Limit,Configs);
|
||||||
|
return MakeJSONObjectArray("configurations", Configs, *this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
#include "framework/MicroService.h"
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
@@ -18,10 +17,10 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal) {}
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/configuration"}; };
|
|
||||||
private:
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/configurations"}; };
|
||||||
ConfigurationDB & DB_=StorageService()->ConfigurationDB();
|
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final {};
|
void DoPost() final {};
|
||||||
void DoPut() final {};
|
void DoPut() final {};
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
|
|
||||||
#include "RESTAPI_contact_handler.h"
|
#include "RESTAPI_contact_handler.h"
|
||||||
|
|
||||||
#include "framework/ow_constants.h"
|
#include "framework/RESTAPI_protocol.h"
|
||||||
|
#include "framework/RESTAPI_errors.h"
|
||||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||||
#include "RESTAPI_db_helpers.h"
|
#include "RESTAPI_db_helpers.h"
|
||||||
|
|
||||||
@@ -66,10 +67,12 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
DB_.DeleteRecord("id",UUID);
|
if(DB_.DeleteRecord("id",UUID)) {
|
||||||
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::contacts,Existing.entity,Existing.info.id);
|
if(!Existing.entity.empty())
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.info.id,"",Existing.info.id);
|
StorageService()->EntityDB().DeleteLocation("id",Existing.entity,UUID);
|
||||||
return OK();
|
return OK();
|
||||||
|
}
|
||||||
|
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_contact_handler::DoPost() {
|
void RESTAPI_contact_handler::DoPost() {
|
||||||
@@ -79,7 +82,7 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & Obj = ParsedBody_;
|
auto Obj = ParseStream();
|
||||||
ProvObjects::Contact NewObject;
|
ProvObjects::Contact NewObject;
|
||||||
if (!NewObject.from_json(Obj)) {
|
if (!NewObject.from_json(Obj)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
@@ -89,7 +92,7 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
|
if(NewObject.entity.empty() || !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,8 +103,10 @@ namespace OpenWifi{
|
|||||||
NewObject.inUse.clear();
|
NewObject.inUse.clear();
|
||||||
|
|
||||||
if(DB_.CreateRecord(NewObject)) {
|
if(DB_.CreateRecord(NewObject)) {
|
||||||
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::contacts,NewObject.entity,NewObject.info.id);
|
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
|
StorageService()->EntityDB().AddContact("id",NewObject.entity,NewObject.info.id);
|
||||||
|
if(!NewObject.managementPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().AddInUse("id",NewObject.managementPolicy,DB_.Prefix(),NewObject.info.id);
|
||||||
|
|
||||||
ProvObjects::Contact NewContact;
|
ProvObjects::Contact NewContact;
|
||||||
StorageService()->ContactDB().GetRecord("id", NewObject.info.id, NewContact);
|
StorageService()->ContactDB().GetRecord("id", NewObject.info.id, NewContact);
|
||||||
@@ -121,7 +126,7 @@ namespace OpenWifi{
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
auto RawObject = ParseStream();
|
||||||
ProvObjects::Contact NewObject;
|
ProvObjects::Contact NewObject;
|
||||||
if (!NewObject.from_json(RawObject)) {
|
if (!NewObject.from_json(RawObject)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
@@ -131,13 +136,25 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FromPolicy, ToPolicy;
|
std::string MoveToPolicy, MoveFromPolicy;
|
||||||
if(!CreateMove(RawObject,"managementPolicy",&ContactDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
|
bool MovingPolicy=false;
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
if(AssignIfPresent(RawObject,"managementPolicy",MoveToPolicy)) {
|
||||||
|
if(!MoveToPolicy.empty() && !StorageService()->PolicyDB().Exists("id",MoveToPolicy)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
|
}
|
||||||
|
MoveFromPolicy = Existing.managementPolicy;
|
||||||
|
MovingPolicy = MoveToPolicy != Existing.managementPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
std::string FromEntity, ToEntity;
|
std::string MoveToEntity,MoveFromEntity;
|
||||||
if(!CreateMove(RawObject,"entity",&ContactDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
|
bool MovingEntity=false;
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
if(AssignIfPresent(RawObject,"entity",MoveToEntity)) {
|
||||||
|
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||||
|
}
|
||||||
|
MoveFromEntity = Existing.entity;
|
||||||
|
MovingEntity = MoveToEntity != Existing.entity ;
|
||||||
|
}
|
||||||
|
|
||||||
AssignIfPresent(RawObject, "title", Existing.title);
|
AssignIfPresent(RawObject, "title", Existing.title);
|
||||||
AssignIfPresent(RawObject, "salutation", Existing.salutation);
|
AssignIfPresent(RawObject, "salutation", Existing.salutation);
|
||||||
@@ -155,9 +172,26 @@ namespace OpenWifi{
|
|||||||
if(RawObject->has("phones"))
|
if(RawObject->has("phones"))
|
||||||
Existing.phones = NewObject.phones;
|
Existing.phones = NewObject.phones;
|
||||||
|
|
||||||
|
Existing.entity = MoveToEntity;
|
||||||
|
Existing.managementPolicy = MoveToPolicy;
|
||||||
|
|
||||||
if(DB_.UpdateRecord("id", UUID, Existing)) {
|
if(DB_.UpdateRecord("id", UUID, Existing)) {
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id);
|
|
||||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::contacts,FromEntity,ToEntity,Existing.info.id);
|
if(MovingPolicy) {
|
||||||
|
if(!MoveFromPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().DeleteInUse("id",MoveFromPolicy,DB_.Prefix(),Existing.info.id);
|
||||||
|
if(!MoveToPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().AddInUse("id", MoveToPolicy, DB_.Prefix(), Existing.info.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(MovingEntity) {
|
||||||
|
if(!MoveFromEntity.empty()) {
|
||||||
|
StorageService()->EntityDB().DeleteContact("id", MoveFromEntity, Existing.info.id);
|
||||||
|
}
|
||||||
|
if(!MoveToEntity.empty()) {
|
||||||
|
StorageService()->EntityDB().AddContact("id", MoveToEntity, Existing.info.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ProvObjects::Contact NewObjectAdded;
|
ProvObjects::Contact NewObjectAdded;
|
||||||
DB_.GetRecord("id", UUID, NewObjectAdded);
|
DB_.GetRecord("id", UUID, NewObjectAdded);
|
||||||
|
|||||||
@@ -22,14 +22,15 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal),
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/contact/{uuid}"}; };
|
DB_(StorageService()->ContactDB()){}
|
||||||
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/contact/{uuid}"}; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ContactDB &DB_=StorageService()->ContactDB();
|
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final;
|
void DoPost() final;
|
||||||
void DoPut() final;
|
void DoPut() final;
|
||||||
void DoDelete() final;
|
void DoDelete() final;
|
||||||
|
ContactDB &DB_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,17 @@
|
|||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
void RESTAPI_contact_list_handler::DoGet() {
|
void RESTAPI_contact_list_handler::DoGet() {
|
||||||
return ListHandler<ContactDB>("contacts", DB_, *this);
|
if(!QB_.Select.empty()) {
|
||||||
|
return ReturnRecordList<decltype(StorageService()->ContactDB()),
|
||||||
|
ProvObjects::Contact>("contacts",StorageService()->ContactDB(),*this );
|
||||||
|
} else if(QB_.CountOnly) {
|
||||||
|
Poco::JSON::Object Answer;
|
||||||
|
auto C = StorageService()->ContactDB().Count();
|
||||||
|
return ReturnCountOnly(C);
|
||||||
|
} else {
|
||||||
|
ProvObjects::ContactVec Contacts;
|
||||||
|
StorageService()->ContactDB().GetRecords(QB_.Offset,QB_.Limit,Contacts);
|
||||||
|
return MakeJSONObjectArray("contacts", Contacts, *this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include "framework/MicroService.h"
|
#include "framework/MicroService.h"
|
||||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
@@ -19,10 +18,9 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal) {}
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/contact"}; };
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/contact"}; };
|
||||||
private:
|
|
||||||
ContactDB & DB_=StorageService()->ContactDB();
|
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final {};
|
void DoPost() final {};
|
||||||
void DoPut() final {};
|
void DoPut() final {};
|
||||||
|
|||||||
@@ -7,12 +7,11 @@
|
|||||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
#include "framework/MicroService.h"
|
#include "framework/MicroService.h"
|
||||||
#include "framework/ConfigurationValidator.h"
|
#include "framework/RESTAPI_errors.h"
|
||||||
#include "sdks/SDK_sec.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
inline static void AddInfoBlock(const ProvObjects::ObjectInfo & O, Poco::JSON::Object &J) {
|
static void AddInfoBlock(const ProvObjects::ObjectInfo & O, Poco::JSON::Object &J) {
|
||||||
J.set("name", O.name);
|
J.set("name", O.name);
|
||||||
J.set("description", O.description);
|
J.set("description", O.description);
|
||||||
J.set("id", O.id);
|
J.set("id", O.id);
|
||||||
@@ -155,6 +154,9 @@ namespace OpenWifi {
|
|||||||
return R.ReturnObject(Answer);
|
return R.ReturnObject(Answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReturnRecordList<decltype(StorageService()->InventoryDB()),
|
||||||
|
// ProvObjects::InventoryTag>("taglist",StorageService()->InventoryDB(),*this );
|
||||||
|
|
||||||
inline static bool is_uuid(const std::string &u) {
|
inline static bool is_uuid(const std::string &u) {
|
||||||
return u.find('-') != std::string::npos;
|
return u.find('-') != std::string::npos;
|
||||||
}
|
}
|
||||||
@@ -170,7 +172,7 @@ namespace OpenWifi {
|
|||||||
AddExtendedInfo(E,Obj);
|
AddExtendedInfo(E,Obj);
|
||||||
ObjArr.add(Obj);
|
ObjArr.add(Obj);
|
||||||
} else {
|
} else {
|
||||||
return R.BadRequest(RESTAPI::Errors::UnknownId);
|
return R.BadRequest(RESTAPI::Errors::UnknownId + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
@@ -189,7 +191,7 @@ namespace OpenWifi {
|
|||||||
AddExtendedInfo(E,Obj);
|
AddExtendedInfo(E,Obj);
|
||||||
ObjArr.add(Obj);
|
ObjArr.add(Obj);
|
||||||
} else {
|
} else {
|
||||||
return R.BadRequest(RESTAPI::Errors::UnknownId);
|
return R.BadRequest(RESTAPI::Errors::UnknownId + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
@@ -210,463 +212,4 @@ namespace OpenWifi {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef std::tuple<std::string,std::string,std::string> triplet_t;
|
|
||||||
|
|
||||||
inline void AddLocationTriplet(const std::string &id, std::vector<triplet_t> & IDs) {
|
|
||||||
ProvObjects::Location L;
|
|
||||||
if(StorageService()->LocationDB().GetRecord("id",id,L)) {
|
|
||||||
IDs.emplace_back(std::make_tuple(L.info.name,L.info.description,L.info.id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void AddLocationTriplet(const std::vector<std::string> &id, std::vector<triplet_t> & IDs) {
|
|
||||||
for(const auto &i:id)
|
|
||||||
AddLocationTriplet(i,IDs);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void GetLocationsForEntity(const std::string &ID, std::vector<triplet_t> & IDs) {
|
|
||||||
ProvObjects::Entity Existing;
|
|
||||||
if(StorageService()->EntityDB().template GetRecord("id",ID,Existing)) {
|
|
||||||
if(!Existing.locations.empty()) {
|
|
||||||
AddLocationTriplet(Existing.locations,IDs);
|
|
||||||
}
|
|
||||||
if(!Existing.parent.empty()) {
|
|
||||||
GetLocationsForEntity(Existing.parent,IDs);
|
|
||||||
}
|
|
||||||
if(ID==EntityDB::RootUUID())
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void GetLocationsForVenue(const std::string &ID, std::vector<triplet_t> & IDs) {
|
|
||||||
ProvObjects::Venue Existing;
|
|
||||||
if(StorageService()->VenueDB().template GetRecord("id",ID,Existing)) {
|
|
||||||
if(!Existing.parent.empty()) {
|
|
||||||
GetLocationsForVenue(Existing.parent,IDs);
|
|
||||||
}
|
|
||||||
ProvObjects::Entity E;
|
|
||||||
if(StorageService()->EntityDB().GetRecord("id", Existing.entity, E)) {
|
|
||||||
AddLocationTriplet(E.locations,IDs);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename DB> void ListHandler(const char *BlockName,DB & DBInstance, RESTAPIHandler & R) {
|
|
||||||
auto Entity = R.GetParameter("entity", "");
|
|
||||||
auto Venue = R.GetParameter("venue", "");
|
|
||||||
|
|
||||||
typedef typename DB::RecordVec RecVec;
|
|
||||||
typedef typename DB::RecordName RecType;
|
|
||||||
|
|
||||||
if constexpr(std::is_same_v<RecType,ProvObjects::Venue>) {
|
|
||||||
auto LocationsForVenue = R.GetParameter("locationsForVenue","");
|
|
||||||
if(!LocationsForVenue.empty()) {
|
|
||||||
std::vector<triplet_t> IDs;
|
|
||||||
GetLocationsForVenue(LocationsForVenue,IDs);
|
|
||||||
Poco::JSON::Array A;
|
|
||||||
for(const auto &[name,description,uuid]:IDs) {
|
|
||||||
Poco::JSON::Object O;
|
|
||||||
O.set("name", name);
|
|
||||||
O.set("description",description);
|
|
||||||
O.set("uuid",uuid);
|
|
||||||
A.add(O);
|
|
||||||
}
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
Answer.set("locations",A);
|
|
||||||
return R.ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!R.QB_.Select.empty()) {
|
|
||||||
return ReturnRecordList<decltype(DBInstance),
|
|
||||||
RecType>(BlockName, DBInstance, R);
|
|
||||||
} if(!Entity.empty()) {
|
|
||||||
RecVec Entries;
|
|
||||||
DBInstance.GetRecords(R.QB_.Offset,R.QB_.Limit,Entries," entity=' " + Entity +"'");
|
|
||||||
if(R.QB_.CountOnly)
|
|
||||||
return R.ReturnCountOnly(Entries.size());
|
|
||||||
return MakeJSONObjectArray(BlockName, Entries, R);
|
|
||||||
} if(!Venue.empty()) {
|
|
||||||
RecVec Entries;
|
|
||||||
DBInstance.GetRecords(R.QB_.Offset,R.QB_.Limit,Entries," venue=' " + Venue +"'");
|
|
||||||
if(R.QB_.CountOnly)
|
|
||||||
return R.ReturnCountOnly(Entries.size());
|
|
||||||
return MakeJSONObjectArray(BlockName, Entries, R);
|
|
||||||
} else if(R.QB_.CountOnly) {
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
auto C = DBInstance.Count();
|
|
||||||
return R.ReturnCountOnly(C);
|
|
||||||
} else {
|
|
||||||
RecVec Entries;
|
|
||||||
DBInstance.GetRecords(R.QB_.Offset,R.QB_.Limit,Entries);
|
|
||||||
return MakeJSONObjectArray(BlockName, Entries, R);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename db_type> void ListHandlerForOperator(const char *BlockName,db_type & DB, RESTAPIHandler & R, const Types::UUID_t & OperatorId, const Types::UUID_t & subscriberId="") {
|
|
||||||
typedef typename db_type::RecordVec RecVec;
|
|
||||||
typedef typename db_type::RecordName RecType;
|
|
||||||
|
|
||||||
auto whereClause = subscriberId.empty() ?
|
|
||||||
fmt::format(" operatorId='{}'", OperatorId) :
|
|
||||||
fmt::format(" operatorId='{}' and subscriberId='{}' ", OperatorId, subscriberId);
|
|
||||||
|
|
||||||
if(R.QB_.CountOnly) {
|
|
||||||
auto Count = DB.Count( whereClause );
|
|
||||||
return R.ReturnCountOnly(Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!R.QB_.Select.empty()) {
|
|
||||||
return ReturnRecordList<decltype(DB),
|
|
||||||
RecType>(BlockName, DB, R);
|
|
||||||
}
|
|
||||||
|
|
||||||
RecVec Entries;
|
|
||||||
DB.GetRecords(R.QB_.Offset,R.QB_.Limit,Entries,whereClause);
|
|
||||||
return MakeJSONObjectArray(BlockName, Entries, R);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename db_type, typename ObjectDB> void MoveUsage(db_type &DB_InUse, ObjectDB & DB, const std::string & From, const std::string & To, const std::string &Id) {
|
|
||||||
if(From!=To) {
|
|
||||||
if(!From.empty())
|
|
||||||
DB_InUse.DeleteInUse("id",From,DB.Prefix(),Id);
|
|
||||||
if(!To.empty())
|
|
||||||
DB_InUse.AddInUse("id",To,DB.Prefix(),Id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename db_type, typename ObjectDB> void MoveUsage(db_type &DB_InUse, ObjectDB & DB, const Types::UUIDvec_t & From, const Types::UUIDvec_t & To, const std::string &Id) {
|
|
||||||
if(From!=To) {
|
|
||||||
if(!From.empty()) {
|
|
||||||
for(const auto &i:From)
|
|
||||||
DB_InUse.DeleteInUse("id", i, DB.Prefix(), Id);
|
|
||||||
}
|
|
||||||
if(!To.empty()) {
|
|
||||||
for(const auto &i:To)
|
|
||||||
DB_InUse.AddInUse("id", i, DB.Prefix(), Id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename db_type> void MoveChild(db_type &DB, const std::string & Parent, const std::string & Child, const std::string &Id) {
|
|
||||||
if(Parent!=Child) {
|
|
||||||
if(!Parent.empty())
|
|
||||||
DB.InUse.DeleteInUse("id",Parent,Id);
|
|
||||||
if(!Child.empty())
|
|
||||||
DB.AddInUse("id",Child,Id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename db_type, typename Member> void RemoveMembership( db_type & DB, Member T, const std::string & Obj, const std::string &Id) {
|
|
||||||
if(!Obj.empty())
|
|
||||||
DB.ManipulateVectorMember(T, "id", Obj, Id, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename db_type, typename Member> void AddMembership( db_type & DB, Member T, const std::string & Obj, const std::string &Id) {
|
|
||||||
if(!Obj.empty())
|
|
||||||
DB.ManipulateVectorMember(T, "id", Obj, Id, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename db_type, typename Member> void ManageMembership( db_type & DB, Member T, const std::string & From, const std::string & To, const std::string &Id) {
|
|
||||||
RemoveMembership(DB,T,From,Id);
|
|
||||||
AddMembership(DB,T,To,Id);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename db_type, typename Member> void ManageMembership( db_type & DB, Member T, const Types::UUIDvec_t & From, const Types::UUIDvec_t & To, const std::string &Id) {
|
|
||||||
if(From!=To) {
|
|
||||||
for (const auto &i: From) {
|
|
||||||
RemoveMembership(DB, T, i, Id);
|
|
||||||
}
|
|
||||||
for (const auto &i: To) {
|
|
||||||
AddMembership(DB, T, i, Id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Member, typename Rec, typename db_type > bool CreateMove(const Poco::JSON::Object::Ptr & RawObj, const char *fieldname, Member T, Rec & Existing, std::string &From, std::string &To, db_type & TheDB) {
|
|
||||||
if(RawObj->has(fieldname)) {
|
|
||||||
From = Existing.*T;
|
|
||||||
To = RawObj->get(fieldname).toString();
|
|
||||||
if(!To.empty() && !TheDB.Exists("id",To))
|
|
||||||
return false;
|
|
||||||
Existing.*T=To;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string FindParentEntity(const ProvObjects::Venue &V) {
|
|
||||||
if(V.parent.empty())
|
|
||||||
return V.entity;
|
|
||||||
ProvObjects::Venue P;
|
|
||||||
if(StorageService()->VenueDB().GetRecord("id",V.parent,P))
|
|
||||||
return FindParentEntity(P);
|
|
||||||
return EntityDB::RootUUID();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool ValidateConfigBlock(const ProvObjects::DeviceConfiguration &Config, RESTAPI::Errors::msg & Error) {
|
|
||||||
static const std::vector<std::string> SectionNames{ "globals", "interfaces", "metrics", "radios", "services", "unit" };
|
|
||||||
|
|
||||||
for(const auto &i:Config.configuration) {
|
|
||||||
Poco::JSON::Parser P;
|
|
||||||
if(i.name.empty()) {
|
|
||||||
std::cout << "Name is empty" << std::endl;
|
|
||||||
Error = RESTAPI::Errors::NameMustBeSet;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
auto Blocks = P.parse(i.configuration).extract<Poco::JSON::Object::Ptr>();
|
|
||||||
auto N = Blocks->getNames();
|
|
||||||
for (const auto &j: N) {
|
|
||||||
if (std::find(SectionNames.cbegin(), SectionNames.cend(), j) == SectionNames.cend()) {
|
|
||||||
Error = RESTAPI::Errors::UnknownConfigurationSection;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (const Poco::JSON::JSONException &E ) {
|
|
||||||
Error = RESTAPI::Errors::InvalidJSONDocument;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
std::string ErrorText;
|
|
||||||
if (ValidateUCentralConfiguration(i.configuration, ErrorText)) {
|
|
||||||
// std::cout << "Block: " << i.name << " is valid" << std::endl;
|
|
||||||
} else {
|
|
||||||
Error = RESTAPI::Errors::ConfigBlockInvalid ;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch(...) {
|
|
||||||
std::cout << "Exception in validation" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Type> std::map<std::string,std::string> CreateObjects(Type & NewObject, RESTAPIHandler & R, RESTAPI::Errors::msg & Error) {
|
|
||||||
std::map<std::string,std::string> Result;
|
|
||||||
|
|
||||||
auto createObjects = R.GetParameter("createObjects","");
|
|
||||||
if(!createObjects.empty()) {
|
|
||||||
std::cout << "createObjects: " << createObjects << std::endl;
|
|
||||||
Poco::JSON::Parser P;
|
|
||||||
auto Objects = P.parse(createObjects).extract<Poco::JSON::Object::Ptr>();
|
|
||||||
if(Objects->isArray("objects")) {
|
|
||||||
auto ObjectsArray = Objects->getArray("objects");
|
|
||||||
for(const auto &i:*ObjectsArray) {
|
|
||||||
auto Object = i.extract<Poco::JSON::Object::Ptr>();
|
|
||||||
if (Object->has("location")) {
|
|
||||||
auto LocationDetails = Object->get("location").extract<Poco::JSON::Object::Ptr>();
|
|
||||||
ProvObjects::Location LC;
|
|
||||||
if (LC.from_json(LocationDetails)) {
|
|
||||||
if constexpr(std::is_same_v<Type,ProvObjects::Venue>) {
|
|
||||||
std::cout << "Location decoded: " << LC.info.name << std::endl;
|
|
||||||
std::string ParentEntity = FindParentEntity(NewObject);
|
|
||||||
ProvObjects::CreateObjectInfo(R.UserInfo_.userinfo, LC.info);
|
|
||||||
LC.entity = ParentEntity;
|
|
||||||
if (StorageService()->LocationDB().CreateRecord(LC)) {
|
|
||||||
NewObject.location = LC.info.id;
|
|
||||||
AddMembership(StorageService()->EntityDB(), &ProvObjects::Entity::locations,
|
|
||||||
ParentEntity, LC.info.id);
|
|
||||||
Result["location"] = LC.info.id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if constexpr(std::is_same_v<Type,ProvObjects::Operator>) {
|
|
||||||
std::cout << "Location decoded: " << LC.info.name << std::endl;
|
|
||||||
std::string ParentEntity = FindParentEntity(NewObject);
|
|
||||||
ProvObjects::CreateObjectInfo(R.UserInfo_.userinfo, LC.info);
|
|
||||||
LC.entity = ParentEntity;
|
|
||||||
if (StorageService()->LocationDB().CreateRecord(LC)) {
|
|
||||||
NewObject.location = LC.info.id;
|
|
||||||
AddMembership(StorageService()->EntityDB(), &ProvObjects::Entity::locations,
|
|
||||||
ParentEntity, LC.info.id);
|
|
||||||
Result["location"] = LC.info.id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Error = RESTAPI::Errors::InvalidJSONDocument;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (Object->has("contact")) {
|
|
||||||
auto ContactDetails = Object->get("contact").extract<Poco::JSON::Object::Ptr>();
|
|
||||||
ProvObjects::Contact CC;
|
|
||||||
if (CC.from_json(ContactDetails)) {
|
|
||||||
std::cout << "contact decoded: " << CC.info.name << std::endl;
|
|
||||||
} else {
|
|
||||||
std::cout << "contact not decoded." << std::endl;
|
|
||||||
}
|
|
||||||
} else if (Object->has("configuration")) {
|
|
||||||
auto ConfigurationDetails = Object->get("configuration").template extract<Poco::JSON::Object::Ptr>();
|
|
||||||
ProvObjects::DeviceConfiguration DC;
|
|
||||||
if(DC.from_json(ConfigurationDetails)) {
|
|
||||||
if constexpr(std::is_same_v<Type, ProvObjects::InventoryTag>) {
|
|
||||||
if(!ValidateConfigBlock(DC,Error)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::cout << "Configuration decoded: " << DC.info.name << std::endl;
|
|
||||||
ProvObjects::CreateObjectInfo(R.UserInfo_.userinfo, DC.info);
|
|
||||||
if (StorageService()->ConfigurationDB().CreateRecord(DC)) {
|
|
||||||
NewObject.deviceConfiguration = DC.info.id;
|
|
||||||
Result["configuration"] = DC.info.id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Error = RESTAPI::Errors::InvalidJSONDocument;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool ValidDeviceRules(const ProvObjects::DeviceRules & DR) {
|
|
||||||
return (DR.rrm=="yes" || DR.rrm=="no" || DR.rrm=="inherit") &&
|
|
||||||
(DR.firmwareUpgrade=="yes" || DR.firmwareUpgrade=="no" || DR.firmwareUpgrade=="inherit") &&
|
|
||||||
(DR.rcOnly=="yes" || DR.rcOnly=="no" || DR.rcOnly=="inherit");
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool ValidDeviceRules(const ProvObjects::DeviceRules & DR, RESTAPIHandler &H) {
|
|
||||||
if(ValidDeviceRules(DR))
|
|
||||||
return true;
|
|
||||||
H.BadRequest(RESTAPI::Errors::InvalidRRM);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool ValidSourceIP([[maybe_unused]] const std::vector<std::string> & IPs) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool ValidPeriod(const std::string &P) {
|
|
||||||
return (P=="hourly" || P=="daily" || P=="monthly" || P=="yearly" ||
|
|
||||||
P=="quarterly" || P=="lifetime" || P=="custom1" ||
|
|
||||||
P=="custom2"|| P=="custom3"|| P=="custom4");
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool ValidContactType(const std::string &contact) {
|
|
||||||
auto C = Poco::toLower(contact);
|
|
||||||
return (C=="subscriber" || C=="user" || C=="installer" || C=="csr" ||
|
|
||||||
C=="manager" || C=="businessowner" || C=="technician" ||
|
|
||||||
C=="corporate");
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool ValidContactType(const std::string &contact, RESTAPIHandler &H) {
|
|
||||||
auto C = Poco::toLower(contact);
|
|
||||||
if (C=="subscriber" || C=="user" || C=="installer" || C=="csr" ||
|
|
||||||
C=="manager" || C=="businessowner" || C=="technician" ||
|
|
||||||
C=="corporate")
|
|
||||||
return true;
|
|
||||||
H.BadRequest(RESTAPI::Errors::InvalidContactType);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool ValidLocationType(const std::string &location) {
|
|
||||||
auto C = Poco::toLower(location);
|
|
||||||
return (C=="service" || C=="equipment" || C=="auto" || C=="manual" ||
|
|
||||||
C=="special" || C=="unknown" || C=="corporate");
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool ValidLocationType(const std::string &location, RESTAPIHandler &H) {
|
|
||||||
auto C = Poco::toLower(location);
|
|
||||||
if((C=="service" || C=="equipment" || C=="auto" || C=="manual" ||
|
|
||||||
C=="special" || C=="unknown" || C=="corporate"))
|
|
||||||
return true;
|
|
||||||
H.BadRequest(RESTAPI::Errors::InvalidLocationType);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename DBType> bool ValidDbId(const Types::UUID_t &uuid, DBType & DB, bool AllowEmpty , const RESTAPI::Errors::msg &Error , RESTAPIHandler & H) {
|
|
||||||
if(!AllowEmpty && uuid.empty()) {
|
|
||||||
H.BadRequest(Error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(uuid.empty())
|
|
||||||
return true;
|
|
||||||
if(!DB.Exists("id",uuid)) {
|
|
||||||
H.BadRequest(Error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool ValidSubscriberId( const Types::UUID_t & uuid, bool AllowEmpty, RESTAPIHandler &H ) {
|
|
||||||
if(!AllowEmpty && uuid.empty()) {
|
|
||||||
H.BadRequest(RESTAPI::Errors::InvalidSubscriberId);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(uuid.empty())
|
|
||||||
return true;
|
|
||||||
SecurityObjects::UserInfo NewSubInfo;
|
|
||||||
if(!SDK::Sec::Subscriber::Get(&H, uuid, NewSubInfo)) {
|
|
||||||
H.BadRequest(RESTAPI::Errors::InvalidSubscriberId);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool ValidSubscriberId( const Types::UUID_t & uuid, bool AllowEmpty, std::string & email, RESTAPIHandler &H ) {
|
|
||||||
if(!AllowEmpty && uuid.empty()) {
|
|
||||||
H.BadRequest(RESTAPI::Errors::InvalidSubscriberId);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(uuid.empty())
|
|
||||||
return true;
|
|
||||||
SecurityObjects::UserInfo NewSubInfo;
|
|
||||||
if(!SDK::Sec::Subscriber::Get(&H, uuid, NewSubInfo)) {
|
|
||||||
H.BadRequest(RESTAPI::Errors::InvalidSubscriberId);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
email = NewSubInfo.email;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool ValidSerialNumber(const std::string &serialNumber, bool AllowEmpty, RESTAPIHandler &H) {
|
|
||||||
if(!AllowEmpty && serialNumber.empty()) {
|
|
||||||
H.BadRequest(RESTAPI::Errors::InvalidSerialNumber);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!Utils::ValidSerialNumber(serialNumber)) {
|
|
||||||
H.BadRequest(RESTAPI::Errors::InvalidSerialNumber);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename DBType, typename DBRecordType> void ReturnUpdatedObject( DBType & DB, const DBRecordType & R, RESTAPIHandler &H) {
|
|
||||||
if(DB.UpdateRecord("id",R.info.id,R)) {
|
|
||||||
DBRecordType Updated;
|
|
||||||
DB.GetRecord("id",R.info.id,Updated);
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
Updated.to_json(Answer);
|
|
||||||
return H.ReturnObject(Answer);
|
|
||||||
} else {
|
|
||||||
H.InternalError(RESTAPI::Errors::RecordNotUpdated);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename DBType, typename DBRecordType> void ReturnCreatedObject( DBType & DB, const DBRecordType & R, RESTAPIHandler &H) {
|
|
||||||
if(DB.CreateRecord(R)) {
|
|
||||||
DBRecordType Updated;
|
|
||||||
DB.GetRecord("id",R.info.id,Updated);
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
Updated.to_json(Answer);
|
|
||||||
return H.ReturnObject(Answer);
|
|
||||||
} else {
|
|
||||||
H.InternalError(RESTAPI::Errors::RecordNotCreated);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename DBType> void ReturnFieldList(DBType & DB, RESTAPIHandler &H) {
|
|
||||||
Types::StringVec Fields;
|
|
||||||
DB.GetFieldNames(Fields);
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
RESTAPI_utils::field_to_json(Answer,"list",Fields);
|
|
||||||
return H.ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,14 +42,20 @@ namespace OpenWifi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( !Existing.children.empty() || !Existing.devices.empty() || !Existing.venues.empty() || !Existing.locations.empty()
|
if( !Existing.children.empty() || !Existing.devices.empty() || !Existing.venues.empty() || !Existing.locations.empty()
|
||||||
|| !Existing.contacts.empty() || !Existing.configurations.empty()) {
|
|| !Existing.contacts.empty()) {
|
||||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
|
if(!Existing.deviceConfiguration.empty()) {
|
||||||
DB_.DeleteRecord("id",UUID);
|
for(auto &i:Existing.deviceConfiguration)
|
||||||
DB_.DeleteChild("id",Existing.parent,UUID);
|
StorageService()->ConfigurationDB().DeleteInUse("id", i, DB_.Prefix(), Existing.info.id);
|
||||||
return OK();
|
}
|
||||||
|
|
||||||
|
if(DB_.DeleteRecord("id",UUID)) {
|
||||||
|
DB_.DeleteChild("id",Existing.parent,UUID);
|
||||||
|
return OK();
|
||||||
|
}
|
||||||
|
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_entity_handler::DoPost() {
|
void RESTAPI_entity_handler::DoPost() {
|
||||||
@@ -58,21 +64,17 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(UUID==EntityDB::RootUUID()) {
|
if(!DB_.RootExists() && UUID != EntityDB::RootUUID()) {
|
||||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
return BadRequest(RESTAPI::Errors::MustCreateRootFirst);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
auto Obj = ParseStream();
|
||||||
ProvObjects::Entity NewEntity;
|
ProvObjects::Entity NewEntity;
|
||||||
if (!NewEntity.from_json(RawObject)) {
|
if (!NewEntity.from_json(Obj)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((RawObject->has("deviceRules") && !ValidDeviceRules(NewEntity.deviceRules,*this))) {
|
if(!ProvObjects::CreateObjectInfo(Obj,UserInfo_.userinfo,NewEntity.info)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!ProvObjects::CreateObjectInfo(RawObject,UserInfo_.userinfo,NewEntity.info)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +88,13 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::ParentUUIDMustExist);
|
return BadRequest(RESTAPI::Errors::ParentUUIDMustExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!NewEntity.deviceConfiguration.empty()) {
|
||||||
|
for(auto &i:NewEntity.deviceConfiguration)
|
||||||
|
if(!StorageService()->ConfigurationDB().Exists("id",i)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!NewEntity.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id", NewEntity.managementPolicy)){
|
if(!NewEntity.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id", NewEntity.managementPolicy)){
|
||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
}
|
}
|
||||||
@@ -98,12 +107,13 @@ namespace OpenWifi{
|
|||||||
NewEntity.children.clear();
|
NewEntity.children.clear();
|
||||||
NewEntity.contacts.clear();
|
NewEntity.contacts.clear();
|
||||||
NewEntity.locations.clear();
|
NewEntity.locations.clear();
|
||||||
NewEntity.deviceConfiguration.clear();
|
|
||||||
NewEntity.managementRoles.clear();
|
|
||||||
|
|
||||||
if(DB_.CreateRecord(NewEntity)) {
|
if(DB_.CreateShortCut(NewEntity)) {
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewEntity.managementPolicy,NewEntity.info.id);
|
if(UUID==EntityDB::RootUUID()) {
|
||||||
DB_.AddChild("id",NewEntity.parent,NewEntity.info.id);
|
DB_.CheckForRoot();
|
||||||
|
} else {
|
||||||
|
DB_.AddChild("id",NewEntity.parent,NewEntity.info.id);
|
||||||
|
}
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
NewEntity.to_json(Answer);
|
NewEntity.to_json(Answer);
|
||||||
@@ -128,23 +138,37 @@ namespace OpenWifi{
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
auto RawObject = ParseStream();
|
||||||
ProvObjects::Entity NewEntity;
|
ProvObjects::Entity NewEntity;
|
||||||
if(!NewEntity.from_json(RawObject)) {
|
if(!NewEntity.from_json(RawObject)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((RawObject->has("deviceRules") && !ValidDeviceRules(NewEntity.deviceRules,*this))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info)) {
|
if(!UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info)) {
|
||||||
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FromPolicy, ToPolicy;
|
std::string NewManagementPolicy;
|
||||||
if(!CreateMove(RawObject,"managementPolicy",&EntityDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
|
Types::UUIDvec_t NewConfiguration;
|
||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
bool MovingConfiguration=false,
|
||||||
|
MovingManagementPolicy=false;
|
||||||
|
if(RawObject->has("deviceConfiguration")) {
|
||||||
|
if(!NewEntity.deviceConfiguration.empty()) {
|
||||||
|
for(auto &i:NewEntity.deviceConfiguration) {
|
||||||
|
if(!StorageService()->ConfigurationDB().Exists("id",i)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NewConfiguration = NewEntity.deviceConfiguration;
|
||||||
|
}
|
||||||
|
MovingConfiguration = Existing.deviceConfiguration != NewConfiguration;
|
||||||
|
}
|
||||||
|
if(AssignIfPresent(RawObject,"managementPolicy",NewManagementPolicy)) {
|
||||||
|
if(!NewManagementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewManagementPolicy)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
|
}
|
||||||
|
MovingManagementPolicy = Existing.managementPolicy != NewManagementPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
if(RawObject->has("sourceIP")) {
|
if(RawObject->has("sourceIP")) {
|
||||||
if(!NewEntity.sourceIP.empty() && !CIDR::ValidateIpRanges(NewEntity.sourceIP)) {
|
if(!NewEntity.sourceIP.empty() && !CIDR::ValidateIpRanges(NewEntity.sourceIP)) {
|
||||||
@@ -153,16 +177,51 @@ namespace OpenWifi{
|
|||||||
Existing.sourceIP = NewEntity.sourceIP;
|
Existing.sourceIP = NewEntity.sourceIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
RESTAPI::Errors::msg Error;
|
std::string Error;
|
||||||
if(!StorageService()->Validate(Parameters_,Error)) {
|
if(!StorageService()->Validate(Parameters_,Error)) {
|
||||||
return BadRequest(Error);
|
return BadRequest(Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(RawObject->has("deviceRules"))
|
AssignIfPresent(RawObject, "rrm", Existing.rrm);
|
||||||
Existing.deviceRules = NewEntity.deviceRules;
|
|
||||||
|
|
||||||
if(DB_.UpdateRecord("id",UUID,Existing)) {
|
if(DB_.UpdateRecord("id",UUID,Existing)) {
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id);
|
for(const auto &i:*Request) {
|
||||||
|
std::string Child{i.second};
|
||||||
|
auto UUID_parts = Utils::Split(Child,':');
|
||||||
|
if(i.first=="add" && UUID_parts[0] == "con") {
|
||||||
|
DB_.AddContact("id", UUID, UUID_parts[1]);
|
||||||
|
StorageService()->ContactDB().AddInUse("id",UUID_parts[1],DB_.Prefix(), UUID);
|
||||||
|
} else if (i.first == "del" && UUID_parts[0] == "con") {
|
||||||
|
DB_.DeleteContact("id", UUID, UUID_parts[1]);
|
||||||
|
StorageService()->ContactDB().DeleteInUse("id",UUID_parts[1],DB_.Prefix(),UUID);
|
||||||
|
} else if (i.first == "add" && UUID_parts[0] == "loc") {
|
||||||
|
DB_.AddLocation("id", UUID, UUID_parts[1]);
|
||||||
|
StorageService()->LocationDB().AddInUse("id",UUID_parts[1],DB_.Prefix(),UUID);
|
||||||
|
} else if (i.first == "del" && UUID_parts[0] == "loc") {
|
||||||
|
DB_.DeleteLocation("id", UUID, UUID_parts[1]);
|
||||||
|
StorageService()->LocationDB().DeleteInUse("id",UUID_parts[1],DB_.Prefix(),UUID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(MovingConfiguration) {
|
||||||
|
if(!Existing.deviceConfiguration.empty())
|
||||||
|
for(auto &i:Existing.deviceConfiguration)
|
||||||
|
StorageService()->ConfigurationDB().DeleteInUse("id",i,DB_.Prefix(),Existing.info.id);
|
||||||
|
if(!NewConfiguration.empty())
|
||||||
|
for(auto &i:NewConfiguration)
|
||||||
|
StorageService()->ConfigurationDB().AddInUse("id",i,DB_.Prefix(),Existing.info.id);
|
||||||
|
Existing.deviceConfiguration = NewConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(MovingManagementPolicy) {
|
||||||
|
if(!Existing.managementPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().DeleteInUse("id",Existing.managementPolicy, DB_.Prefix(), Existing.info.id);
|
||||||
|
if(!NewManagementPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().AddInUse("id", NewManagementPolicy, DB_.Prefix(), Existing.info.id);
|
||||||
|
Existing.managementPolicy = NewManagementPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
DB_.UpdateRecord("id", Existing.info.id, Existing);
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
ProvObjects::Entity NewRecord;
|
ProvObjects::Entity NewRecord;
|
||||||
|
|||||||
@@ -24,11 +24,12 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal),
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/entity/{uuid}"}; };
|
DB_(StorageService()->EntityDB()){}
|
||||||
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/entity/{uuid}"}; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EntityDB & DB_=StorageService()->EntityDB();
|
EntityDB & DB_;
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final ;
|
void DoPost() final ;
|
||||||
void DoPut() final;
|
void DoPut() final;
|
||||||
|
|||||||
@@ -15,26 +15,26 @@ namespace OpenWifi{
|
|||||||
|
|
||||||
void RESTAPI_entity_list_handler::DoGet() {
|
void RESTAPI_entity_list_handler::DoGet() {
|
||||||
if(!QB_.Select.empty()) {
|
if(!QB_.Select.empty()) {
|
||||||
return ReturnRecordList<decltype(DB_),
|
return ReturnRecordList<decltype(StorageService()->EntityDB()),
|
||||||
ProvObjects::Entity>("entities",DB_,*this );
|
ProvObjects::Entity>("entities",StorageService()->EntityDB(),*this );
|
||||||
} else if(QB_.CountOnly) {
|
} else if(QB_.CountOnly) {
|
||||||
auto C = DB_.Count();
|
auto C = StorageService()->EntityDB().Count();
|
||||||
return ReturnCountOnly(C);
|
return ReturnCountOnly(C);
|
||||||
} else if (GetBoolParameter("getTree",false)) {
|
} else if (GetBoolParameter("getTree",false)) {
|
||||||
Poco::JSON::Object FullTree;
|
Poco::JSON::Object FullTree;
|
||||||
DB_.BuildTree(FullTree);
|
StorageService()->EntityDB().BuildTree(FullTree);
|
||||||
return ReturnObject(FullTree);
|
return ReturnObject(FullTree);
|
||||||
} else {
|
} else {
|
||||||
EntityDB::RecordVec Entities;
|
ProvObjects::EntityVec Entities;
|
||||||
DB_.GetRecords(QB_.Offset, QB_.Limit,Entities);
|
StorageService()->EntityDB().GetRecords(QB_.Offset, QB_.Limit,Entities);
|
||||||
return MakeJSONObjectArray("entities", Entities, *this);
|
return MakeJSONObjectArray("entities", Entities, *this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_entity_list_handler::DoPost() {
|
void RESTAPI_entity_list_handler::DoPost() {
|
||||||
if (GetBoolParameter("setTree",false)) {
|
if (GetBoolParameter("setTree",false)) {
|
||||||
const auto & FullTree = ParsedBody_;
|
auto FullTree = ParseStream();
|
||||||
DB_.ImportTree(FullTree);
|
StorageService()->EntityDB().ImportTree(FullTree);
|
||||||
return OK();
|
return OK();
|
||||||
}
|
}
|
||||||
BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
#include "framework/MicroService.h"
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
class RESTAPI_entity_list_handler : public RESTAPIHandler {
|
class RESTAPI_entity_list_handler : public RESTAPIHandler {
|
||||||
@@ -23,10 +22,9 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal) {}
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/entity"}; };
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/entity"}; };
|
||||||
private:
|
|
||||||
EntityDB &DB_=StorageService()->EntityDB();
|
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final ;
|
void DoPost() final ;
|
||||||
void DoPut() final {};
|
void DoPut() final {};
|
||||||
|
|||||||
@@ -8,14 +8,15 @@
|
|||||||
|
|
||||||
#include "RESTAPI_inventory_handler.h"
|
#include "RESTAPI_inventory_handler.h"
|
||||||
|
|
||||||
|
#include "framework/RESTAPI_protocol.h"
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
#include "APConfig.h"
|
#include "APConfig.h"
|
||||||
|
#include "framework/RESTAPI_errors.h"
|
||||||
#include "AutoDiscovery.h"
|
#include "AutoDiscovery.h"
|
||||||
#include "sdks/SDK_gw.h"
|
#include "sdks/SDK_gw.h"
|
||||||
#include "sdks/SDK_sec.h"
|
#include "sdks/SDK_sec.h"
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||||
#include "SerialNumberCache.h"
|
#include "SerialNumberCache.h"
|
||||||
#include "DeviceTypeCache.h"
|
|
||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
|
|
||||||
@@ -34,14 +35,11 @@ namespace OpenWifi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_inventory_handler::DoGet() {
|
void RESTAPI_inventory_handler::DoGet() {
|
||||||
|
|
||||||
ProvObjects::InventoryTag Existing;
|
ProvObjects::InventoryTag Existing;
|
||||||
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,"");
|
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,"");
|
||||||
Logger().debug(Poco::format("%s: Retrieving inventory information.",SerialNumber));
|
|
||||||
if(SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER,SerialNumber,Existing)) {
|
if(SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER,SerialNumber,Existing)) {
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
Logger().debug(Poco::format("%s,%s: Retrieving inventory information.", Existing.serialNumber, Existing.info.id ));
|
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
std::string Arg;
|
std::string Arg;
|
||||||
@@ -49,7 +47,7 @@ namespace OpenWifi{
|
|||||||
bool Explain = (HasParameter("explain",Arg) && Arg == "true");
|
bool Explain = (HasParameter("explain",Arg) && Arg == "true");
|
||||||
APConfig Device(SerialNumber,Existing.deviceType,Logger(), Explain);
|
APConfig Device(SerialNumber,Existing.deviceType,Logger(), Explain);
|
||||||
|
|
||||||
auto Configuration = Poco::makeShared<Poco::JSON::Object>();
|
Poco::JSON::Object::Ptr Configuration;
|
||||||
if(Device.Get(Configuration)) {
|
if(Device.Get(Configuration)) {
|
||||||
Answer.set("config", Configuration);
|
Answer.set("config", Configuration);
|
||||||
if(Explain)
|
if(Explain)
|
||||||
@@ -59,37 +57,48 @@ namespace OpenWifi{
|
|||||||
}
|
}
|
||||||
return ReturnObject(Answer);
|
return ReturnObject(Answer);
|
||||||
} else if(HasParameter("firmwareOptions", Arg) && Arg=="true") {
|
} else if(HasParameter("firmwareOptions", Arg) && Arg=="true") {
|
||||||
ProvObjects::DeviceRules Rules;
|
ProvObjects::FIRMWARE_UPGRADE_RULES Rules;
|
||||||
StorageService()->InventoryDB().EvaluateDeviceSerialNumberRules(SerialNumber,Rules);
|
|
||||||
Answer.set("firmwareUpgrade",Rules.firmwareUpgrade);
|
StorageService()->InventoryDB().FindFirmwareOptions(SerialNumber,Rules);
|
||||||
Answer.set("firmwareRCOnly", Rules.rcOnly == "yes" );
|
|
||||||
|
if(Rules == ProvObjects::dont_upgrade) {
|
||||||
|
Answer.set("firmwareUpgrade","no");
|
||||||
|
} else {
|
||||||
|
Answer.set("firmwareUpgrade","yes");
|
||||||
|
if(Rules == ProvObjects::upgrade_release_only)
|
||||||
|
Answer.set("firmwareRCOnly", Rules == ProvObjects::upgrade_release_only );
|
||||||
|
}
|
||||||
return ReturnObject(Answer);
|
return ReturnObject(Answer);
|
||||||
} else if(HasParameter("applyConfiguration",Arg) && Arg=="true") {
|
} else if(HasParameter("applyConfiguration",Arg) && Arg=="true") {
|
||||||
Logger().debug(Poco::format("%s: Retrieving configuration.",Existing.serialNumber));
|
APConfig Device(SerialNumber, Existing.deviceType, Logger(), false);
|
||||||
auto Device = std::make_shared<APConfig>(SerialNumber, Existing.deviceType, Logger(), false);
|
Poco::JSON::Object::Ptr Configuration;
|
||||||
auto Configuration = Poco::makeShared<Poco::JSON::Object>();
|
|
||||||
|
Types::StringVec Errors, Warnings;
|
||||||
Poco::JSON::Object ErrorsObj, WarningsObj;
|
Poco::JSON::Object ErrorsObj, WarningsObj;
|
||||||
ProvObjects::InventoryConfigApplyResult Results;
|
int ErrorCode;
|
||||||
Logger().debug(Poco::format("%s: Computing configuration.",Existing.serialNumber));
|
if (Device.Get(Configuration)) {
|
||||||
if (Device->Get(Configuration)) {
|
Poco::JSON::Object::Ptr Response;
|
||||||
std::ostringstream OS;
|
|
||||||
Configuration->stringify(OS);
|
|
||||||
Results.appliedConfiguration = OS.str();
|
|
||||||
auto Response=Poco::makeShared<Poco::JSON::Object>();
|
|
||||||
Logger().debug(Poco::format("%s: Sending configuration push.",Existing.serialNumber));
|
|
||||||
if (SDK::GW::Device::Configure(this, SerialNumber, Configuration, Response)) {
|
if (SDK::GW::Device::Configure(this, SerialNumber, Configuration, Response)) {
|
||||||
Logger().debug(Poco::format("%s: Sending configuration pushed.",Existing.serialNumber));
|
std::ostringstream os;
|
||||||
GetRejectedLines(Response, Results.warnings);
|
Response->stringify(os);
|
||||||
Results.errorCode = 0;
|
// std::cout << "Success: " << os.str() << std::endl;
|
||||||
|
GetRejectedLines(Response, Warnings);
|
||||||
|
ErrorCode = 0;
|
||||||
} else {
|
} else {
|
||||||
Logger().debug(Poco::format("%s: Sending configuration failed.",Existing.serialNumber));
|
std::ostringstream os;
|
||||||
Results.errorCode = 1;
|
Response->stringify(os);
|
||||||
|
ErrorCode = 1;
|
||||||
|
// std::cout << "Failure: " << os.str() << std::endl;
|
||||||
}
|
}
|
||||||
|
Answer.set("appliedConfiguration", Configuration);
|
||||||
|
Answer.set("response", Response);
|
||||||
} else {
|
} else {
|
||||||
Logger().debug(Poco::format("%s: Configuration is bad.",Existing.serialNumber));
|
Answer.set("appliedConfiguration", "");
|
||||||
Results.errorCode = 1;
|
ErrorCode = 1;
|
||||||
}
|
}
|
||||||
Results.to_json(Answer);
|
Answer.set("errorCode", ErrorCode);
|
||||||
|
RESTAPI_utils::field_to_json(Answer, "errors", Errors);
|
||||||
|
RESTAPI_utils::field_to_json(Answer, "warnings", Warnings);
|
||||||
return ReturnObject(Answer);
|
return ReturnObject(Answer);
|
||||||
} else if(QB_.AdditionalInfo) {
|
} else if(QB_.AdditionalInfo) {
|
||||||
AddExtendedInfo(Existing,Answer);
|
AddExtendedInfo(Existing,Answer);
|
||||||
@@ -105,34 +114,33 @@ namespace OpenWifi{
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
|
if(!Existing.venue.empty())
|
||||||
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::configurations,Existing.venue,Existing.info.id);
|
StorageService()->VenueDB().DeleteDevice("id",Existing.venue,Existing.info.id);
|
||||||
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::configurations,Existing.entity,Existing.info.id);
|
|
||||||
MoveUsage(StorageService()->LocationDB(),DB_,Existing.location,"",Existing.info.id);
|
|
||||||
MoveUsage(StorageService()->ContactDB(),DB_,Existing.contact,"",Existing.info.id);
|
|
||||||
|
|
||||||
if(!Existing.deviceConfiguration.empty()) {
|
if(!Existing.entity.empty())
|
||||||
ProvObjects::DeviceConfiguration DC;
|
StorageService()->EntityDB().DeleteDevice("id",Existing.entity,Existing.info.id);
|
||||||
if(StorageService()->ConfigurationDB().GetRecord("id", Existing.deviceConfiguration, DC)) {
|
|
||||||
if(DC.subscriberOnly)
|
if(!Existing.location.empty())
|
||||||
StorageService()->ConfigurationDB().DeleteRecord("id", Existing.deviceConfiguration);
|
StorageService()->LocationDB().DeleteInUse("id",Existing.location,DB_.Prefix(),Existing.info.id);
|
||||||
else
|
|
||||||
StorageService()->ConfigurationDB().DeleteInUse("id", Existing.deviceConfiguration, DB_.Prefix(),
|
if(!Existing.contact.empty())
|
||||||
Existing.info.id);
|
StorageService()->ContactDB().DeleteInUse("id",Existing.contact,DB_.Prefix(),Existing.info.id);
|
||||||
}
|
|
||||||
|
if(!Existing.deviceConfiguration.empty())
|
||||||
|
StorageService()->ConfigurationDB().DeleteInUse("id", Existing.deviceConfiguration, DB_.Prefix(), Existing.info.id);
|
||||||
|
|
||||||
|
if(DB_.DeleteRecord("id", Existing.info.id)) {
|
||||||
|
DB_.DeleteRecord(RESTAPI::Protocol::ID, Existing.info.id);
|
||||||
|
SerialNumberCache()->DeleteSerialNumber(SerialNumber);
|
||||||
|
return OK();
|
||||||
}
|
}
|
||||||
|
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
|
|
||||||
MoveUsage(StorageService()->LocationDB(),DB_,Existing.location,"",Existing.info.id);
|
|
||||||
MoveUsage(StorageService()->ContactDB(),DB_,Existing.contact,"",Existing.info.id);
|
|
||||||
MoveUsage(StorageService()->ConfigurationDB(),DB_,Existing.deviceConfiguration,"",Existing.info.id);
|
|
||||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::devices,Existing.entity,"",Existing.info.id);
|
|
||||||
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::devices,Existing.venue,"",Existing.info.id);
|
|
||||||
DB_.DeleteRecord("id", Existing.info.id);
|
|
||||||
SerialNumberCache()->DeleteSerialNumber(SerialNumber);
|
|
||||||
return OK();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ValidDevClass(const std::string &D) {
|
||||||
|
const static std::vector<std::string> Classes{ "any", "entity", "subscriber" , "venue" };
|
||||||
|
return std::find(cbegin(Classes), cend(Classes), D)!=cend(Classes);
|
||||||
|
}
|
||||||
|
|
||||||
void RESTAPI_inventory_handler::DoPost() {
|
void RESTAPI_inventory_handler::DoPost() {
|
||||||
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,"");
|
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,"");
|
||||||
@@ -145,32 +153,24 @@ namespace OpenWifi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(DB_.Exists(RESTAPI::Protocol::SERIALNUMBER,SerialNumber)) {
|
if(DB_.Exists(RESTAPI::Protocol::SERIALNUMBER,SerialNumber)) {
|
||||||
return BadRequest(RESTAPI::Errors::SerialNumberExists);
|
return BadRequest(RESTAPI::Errors::SerialNumberExists + " (" + SerialNumber + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
auto Obj = ParseStream();
|
||||||
ProvObjects::InventoryTag NewObject;
|
ProvObjects::InventoryTag NewObject;
|
||||||
if (!NewObject.from_json(RawObject)) {
|
if (!NewObject.from_json(Obj)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules,*this))) {
|
if(!ValidDevClass(NewObject.devClass)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!Provisioning::DeviceClass::Validate(NewObject.devClass.c_str())) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidDeviceClass);
|
return BadRequest(RESTAPI::Errors::InvalidDeviceClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NewObject.devClass.empty()) {
|
if(!ProvObjects::CreateObjectInfo(Obj, UserInfo_.userinfo, NewObject.info)) {
|
||||||
NewObject.devClass = Provisioning::DeviceClass::ANY;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!ProvObjects::CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info)) {
|
|
||||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NewObject.deviceType.empty() || !DeviceTypeCache()->IsAcceptableDeviceType(NewObject.deviceType)) {
|
if(NewObject.deviceType.empty() || !StorageService()->IsAcceptableDeviceType(NewObject.deviceType)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
|
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,21 +202,39 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
RESTAPI::Errors::msg Error=RESTAPI::Errors::SUCCESS;
|
if(!NewObject.venue.empty()) {
|
||||||
auto ObjectsCreated = CreateObjects(NewObject,*this,Error);
|
nlohmann::json state;
|
||||||
if(Error.err_num != 0) {
|
state["method"] = "assignedTo";
|
||||||
return BadRequest(Error);
|
state["venue"] = NewObject.venue;
|
||||||
|
state["date"] = std::time(nullptr);
|
||||||
|
NewObject.state = to_string(state);
|
||||||
|
} else if (!NewObject.entity.empty()) {
|
||||||
|
nlohmann::json state;
|
||||||
|
state["method"] = "assignedTo";
|
||||||
|
state["entity"] = NewObject.entity;
|
||||||
|
state["date"] = std::time(nullptr);
|
||||||
|
NewObject.state = to_string(state);
|
||||||
|
} else {
|
||||||
|
nlohmann::json state;
|
||||||
|
state["method"] = "created";
|
||||||
|
state["date"] = std::time(nullptr);
|
||||||
|
NewObject.state = to_string(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(DB_.CreateRecord(NewObject)) {
|
if(DB_.CreateRecord(NewObject)) {
|
||||||
SDK::GW::Device::SetOwnerShip(this, SerialNumber, NewObject.entity, NewObject.venue, NewObject.subscriber);
|
|
||||||
SerialNumberCache()->AddSerialNumber(SerialNumber,NewObject.deviceType);
|
SerialNumberCache()->AddSerialNumber(SerialNumber,NewObject.deviceType);
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
|
if (!NewObject.venue.empty())
|
||||||
MoveUsage(StorageService()->LocationDB(),DB_,"",NewObject.location,NewObject.info.id);
|
StorageService()->VenueDB().AddDevice("id",NewObject.venue,NewObject.info.id);
|
||||||
MoveUsage(StorageService()->ContactDB(),DB_,"",NewObject.contact,NewObject.info.id);
|
if (!NewObject.entity.empty())
|
||||||
MoveUsage(StorageService()->ConfigurationDB(),DB_,"",NewObject.deviceConfiguration,NewObject.info.id);
|
StorageService()->EntityDB().AddDevice("id",NewObject.entity,NewObject.info.id);
|
||||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::devices,"",NewObject.entity,NewObject.info.id);
|
if (!NewObject.location.empty())
|
||||||
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::devices,"",NewObject.venue,NewObject.info.id);
|
StorageService()->LocationDB().AddInUse("id",NewObject.location,DB_.Prefix(),NewObject.info.id);
|
||||||
|
if (!NewObject.contact.empty())
|
||||||
|
StorageService()->ContactDB().AddInUse("id",NewObject.contact,DB_.Prefix(),NewObject.info.id);
|
||||||
|
if (!NewObject.deviceConfiguration.empty())
|
||||||
|
StorageService()->ConfigurationDB().AddInUse("id",NewObject.deviceConfiguration,DB_.Prefix(),NewObject.info.id);
|
||||||
|
if (!NewObject.managementPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().AddInUse("id",NewObject.managementPolicy,DB_.Prefix(),NewObject.info.id);
|
||||||
|
|
||||||
ProvObjects::InventoryTag NewTag;
|
ProvObjects::InventoryTag NewTag;
|
||||||
DB_.GetRecord("id",NewObject.info.id,NewTag);
|
DB_.GetRecord("id",NewObject.info.id,NewTag);
|
||||||
@@ -227,71 +245,163 @@ namespace OpenWifi{
|
|||||||
InternalError(RESTAPI::Errors::RecordNotCreated);
|
InternalError(RESTAPI::Errors::RecordNotCreated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RESTAPI_inventory_handler::PerformClaim(const std::string &SerialNumber, const std::string &Claimer, std::string & ClaimId, uint64_t &ErrorCode, Poco::JSON::Object &Answer ) {
|
||||||
|
|
||||||
|
if(UserInfo_.userinfo.userRole==SecurityObjects::SUBSCRIBER && Claimer!=UserInfo_.userinfo.id) {
|
||||||
|
return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights, ACCESS_DENIED);
|
||||||
|
} else if(UserInfo_.userinfo.userRole==SecurityObjects::ROOT && !SDK::Sec::Subscriber::Exists(this, Claimer)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||||
|
} else if(UserInfo_.userinfo.userRole!=SecurityObjects::ROOT && UserInfo_.userinfo.userRole!=SecurityObjects::SUBSCRIBER) {
|
||||||
|
return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights,ACCESS_DENIED);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t Now = std::time(nullptr);
|
||||||
|
|
||||||
|
// if the device exists, check the status to see if we would follow this claim.
|
||||||
|
ProvObjects::InventoryTag ExistingDevice;
|
||||||
|
if(DB_.GetRecord("serialNumber",SerialNumber,ExistingDevice)) {
|
||||||
|
// Device is already in there... so we could have claimed that device before, or someone else uses it
|
||||||
|
// or, it is free and clear: it connected but nobody has ever used it...
|
||||||
|
if(!ExistingDevice.state.empty()) {
|
||||||
|
try {
|
||||||
|
Poco::JSON::Parser P;
|
||||||
|
auto StateDoc = P.parse(ExistingDevice.state).extract<Poco::JSON::Object::Ptr>();
|
||||||
|
if (StateDoc->has("method")) {
|
||||||
|
auto Method = StateDoc->get("method").toString();
|
||||||
|
if(Method=="claiming") {
|
||||||
|
auto RecordedClaimer = StateDoc->get("claimer").toString();
|
||||||
|
auto RecordedClaimId = StateDoc->get("claimId").toString();
|
||||||
|
if(Claimer==RecordedClaimer) {
|
||||||
|
ErrorCode = 3;
|
||||||
|
ClaimId = RecordedClaimId;
|
||||||
|
Answer.set("claimer", Claimer);
|
||||||
|
Answer.set("claimId", RecordedClaimId);
|
||||||
|
Answer.set("errorCode",ErrorCode);
|
||||||
|
Answer.set("date", Now);
|
||||||
|
Answer.set("reason", "Claim already in progress");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ErrorCode = 1;
|
||||||
|
ClaimId = RecordedClaimId;
|
||||||
|
Answer.set("claimer", Claimer);
|
||||||
|
Answer.set("claimId", RecordedClaimId);
|
||||||
|
Answer.set("errorCode",ErrorCode);
|
||||||
|
Answer.set("date", Now);
|
||||||
|
Answer.set("reason", "Claimed by another user: "+ RecordedClaimer);
|
||||||
|
return;
|
||||||
|
} else if(Method=="claimed") {
|
||||||
|
// We already own this one...
|
||||||
|
if(Claimer==ExistingDevice.subscriber) {
|
||||||
|
auto RecordedClaimer = StateDoc->get("claimer").toString();
|
||||||
|
auto RecordedClaimId = StateDoc->get("claimId").toString();
|
||||||
|
ErrorCode = 0;
|
||||||
|
ClaimId = RecordedClaimId;
|
||||||
|
Answer.set("claimer", Claimer);
|
||||||
|
Answer.set("claimId", RecordedClaimId);
|
||||||
|
Answer.set("errorCode",ErrorCode);
|
||||||
|
Answer.set("date", Now);
|
||||||
|
Answer.set("reason", "Success");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// Someone else has claimed this device.
|
||||||
|
ErrorCode = 1;
|
||||||
|
ClaimId = "";
|
||||||
|
Answer.set("claimer", Claimer);
|
||||||
|
Answer.set("claimId", "");
|
||||||
|
Answer.set("errorCode",ErrorCode);
|
||||||
|
Answer.set("date", Now);
|
||||||
|
Answer.set("reason", "Claimed by another user: "+ ExistingDevice.subscriber);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if(Method=="auto-discovery") {
|
||||||
|
if(StateDoc->has("assignedTo")) {
|
||||||
|
auto AssignedTo = StateDoc->get("assignedTo").toString();
|
||||||
|
ErrorCode = 1;
|
||||||
|
ClaimId = "";
|
||||||
|
Answer.set("claimer", Claimer);
|
||||||
|
Answer.set("claimId", "");
|
||||||
|
Answer.set("errorCode",ErrorCode);
|
||||||
|
Answer.set("date", Now);
|
||||||
|
Answer.set("reason", "Claimed by venue: '" + ExistingDevice.venue + "' or entity: '" + ExistingDevice.entity + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Device does not exist, so claim it for now.
|
||||||
|
ProvObjects::InventoryTag NewDevice;
|
||||||
|
NewDevice.info.created = NewDevice.info.modified = Now;
|
||||||
|
NewDevice.info.id = MicroService::instance().CreateUUID();
|
||||||
|
NewDevice.info.name = SerialNumber;
|
||||||
|
NewDevice.info.notes.push_back(SecurityObjects::NoteInfo{ .created=Now,
|
||||||
|
.createdBy=UserInfo_.userinfo.email,
|
||||||
|
.note="Claim started for device"});
|
||||||
|
NewDevice.info.description = "Subscriber device";
|
||||||
|
NewDevice.subscriber = UserInfo_.userinfo.id;
|
||||||
|
NewDevice.deviceType = "unknown";
|
||||||
|
nlohmann::json StateDoc;
|
||||||
|
|
||||||
|
ClaimId = MicroService::instance().CreateUUID();
|
||||||
|
|
||||||
|
StateDoc["method"] = "claiming";
|
||||||
|
StateDoc["date"] = Now;
|
||||||
|
StateDoc["claimer"] = Claimer;
|
||||||
|
StateDoc["claimId"] = ClaimId;
|
||||||
|
NewDevice.state = StateDoc;
|
||||||
|
ErrorCode = 0 ;
|
||||||
|
DB_.CreateRecord(NewDevice);
|
||||||
|
|
||||||
|
Answer.set("claimer", Claimer);
|
||||||
|
Answer.set("claimId", ClaimId);
|
||||||
|
Answer.set("errorCode",0);
|
||||||
|
Answer.set("date", Now);
|
||||||
|
Answer.set("reason", "Success");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void RESTAPI_inventory_handler::DoPut() {
|
void RESTAPI_inventory_handler::DoPut() {
|
||||||
|
|
||||||
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,"");
|
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,"");
|
||||||
|
|
||||||
if(SerialNumber.empty() || !Utils::ValidSerialNumber(SerialNumber)) {
|
if(SerialNumber.empty() || !Utils::ValidSerialNumber(SerialNumber)) {
|
||||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Claimer;
|
||||||
|
if(HasParameter("claimer",Claimer) && !Claimer.empty()) {
|
||||||
|
uint64_t ErrorCode;
|
||||||
|
Poco::JSON::Object Answer;
|
||||||
|
std::string ClaimId;
|
||||||
|
PerformClaim(SerialNumber, Claimer, ClaimId, ErrorCode, Answer);
|
||||||
|
return ReturnObject(Answer);
|
||||||
|
}
|
||||||
|
|
||||||
ProvObjects::InventoryTag Existing;
|
ProvObjects::InventoryTag Existing;
|
||||||
if(SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER,SerialNumber,Existing)) {
|
if(SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER,SerialNumber,Existing)) {
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto RemoveSubscriber = GetParameter("removeSubscriber");
|
auto RawObject = ParseStream();
|
||||||
if(!RemoveSubscriber.empty()) {
|
|
||||||
if(Existing.subscriber == RemoveSubscriber) {
|
|
||||||
Logger().information(Poco::format("%s: removing subscriber (%s)", SerialNumber, RemoveSubscriber));
|
|
||||||
ProvObjects::DeviceConfiguration DC;
|
|
||||||
if(StorageService()->ConfigurationDB().GetRecord("id",Existing.deviceConfiguration,DC)) {
|
|
||||||
Logger().information(Poco::format("%s: removing configuration for subscriber (%s)", SerialNumber, RemoveSubscriber));
|
|
||||||
if(DC.subscriberOnly) {
|
|
||||||
if(!StorageService()->ConfigurationDB().DeleteRecord("id", Existing.deviceConfiguration)) {
|
|
||||||
Logger().debug("Could not delete the subscriber configuration");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Logger().debug("Configurations is not for a subscriber.");
|
|
||||||
}
|
|
||||||
Existing.deviceConfiguration = "";
|
|
||||||
}
|
|
||||||
Existing.subscriber = "";
|
|
||||||
Poco::JSON::Object state;
|
|
||||||
state.set("date",OpenWifi::Now());
|
|
||||||
state.set("method","auto-discovery");
|
|
||||||
state.set("last-operation", "returned to inventory");
|
|
||||||
std::ostringstream OO;
|
|
||||||
state.stringify(OO);
|
|
||||||
Existing.state = OO.str();
|
|
||||||
StorageService()->InventoryDB().UpdateRecord("id",Existing.info.id,Existing);
|
|
||||||
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::devices,"id",Existing.info.id);
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
Existing.to_json(Answer);
|
|
||||||
SDK::GW::Device::SetSubscriber(nullptr, SerialNumber, "");
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
} else {
|
|
||||||
Logger().information(Poco::format("%s: wrong subscriber (%s)", SerialNumber, RemoveSubscriber));
|
|
||||||
}
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
ProvObjects::InventoryTag NewObject;
|
ProvObjects::InventoryTag NewObject;
|
||||||
if(!NewObject.from_json(RawObject)) {
|
if(!NewObject.from_json(RawObject)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules,*this))) {
|
if(!ValidDevClass(NewObject.devClass)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!Provisioning::DeviceClass::Validate(NewObject.devClass.c_str())) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidDeviceClass);
|
return BadRequest(RESTAPI::Errors::InvalidDeviceClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!NewObject.deviceType.empty()) {
|
if(!NewObject.deviceType.empty()) {
|
||||||
if(!DeviceTypeCache()->IsAcceptableDeviceType(NewObject.deviceType)) {
|
if(!StorageService()->IsAcceptableDeviceType(NewObject.deviceType)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
|
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -300,38 +410,61 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(RawObject->has("deviceRules"))
|
std::string NewVenue, NewEntity, NewLocation, NewContact, NewConfiguration, NewPolicy;
|
||||||
Existing.deviceRules = NewObject.deviceRules;
|
bool MovingVenue=false,
|
||||||
|
MovingEntity=false,
|
||||||
|
MovingLocation=false,
|
||||||
|
MovingContact=false,
|
||||||
|
MovingConfiguration=false,
|
||||||
|
MovingPolicy=false;
|
||||||
|
|
||||||
std::string FromPolicy, ToPolicy;
|
AssignIfPresent(RawObject, "rrm",Existing.rrm);
|
||||||
if(!CreateMove(RawObject,"managementPolicy",&InventoryDB::RecordName::managementPolicy, Existing, FromPolicy,
|
|
||||||
ToPolicy, StorageService()->PolicyDB()))
|
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
|
|
||||||
std::string FromEntity, ToEntity;
|
if(AssignIfPresent(RawObject, "venue",NewVenue)) {
|
||||||
if(!CreateMove(RawObject,"entity",&InventoryDB::RecordName::entity, Existing, FromEntity, ToEntity,
|
if(!NewVenue.empty() && !StorageService()->VenueDB().Exists("id",NewVenue)) {
|
||||||
StorageService()->EntityDB()))
|
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
}
|
||||||
|
MovingVenue = Existing.venue != NewVenue;
|
||||||
|
}
|
||||||
|
|
||||||
std::string FromVenue, ToVenue;
|
if(AssignIfPresent(RawObject, "entity",NewEntity)) {
|
||||||
if(!CreateMove(RawObject,"venue",&InventoryDB::RecordName::venue, Existing, FromVenue, ToVenue,
|
if(!NewEntity.empty() && !StorageService()->EntityDB().Exists("id",NewEntity)) {
|
||||||
StorageService()->VenueDB()))
|
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
}
|
||||||
|
MovingEntity = Existing.entity != NewEntity;
|
||||||
|
}
|
||||||
|
|
||||||
std::string FromLocation, ToLocation;
|
if(!NewEntity.empty() && !NewVenue.empty()) {
|
||||||
if(!CreateMove(RawObject,"location",&InventoryDB::RecordName::location, Existing, FromLocation, ToLocation,
|
return BadRequest(RESTAPI::Errors::NotBoth);
|
||||||
StorageService()->LocationDB()))
|
}
|
||||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
|
||||||
|
|
||||||
std::string FromContact, ToContact;
|
if(AssignIfPresent(RawObject, "location",NewLocation)) {
|
||||||
if(!CreateMove(RawObject,"contact",&InventoryDB::RecordName::contact, Existing, FromContact, ToContact,
|
if(!NewLocation.empty() && !StorageService()->LocationDB().Exists("id",NewLocation)) {
|
||||||
StorageService()->ContactDB()))
|
return BadRequest(RESTAPI::Errors::LocationMustExist);
|
||||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
}
|
||||||
|
MovingLocation = Existing.location != NewLocation;
|
||||||
|
}
|
||||||
|
|
||||||
std::string FromConfiguration, ToConfiguration;
|
if(AssignIfPresent(RawObject, "contact",NewContact)) {
|
||||||
if(!CreateMove(RawObject,"deviceConfiguration",&InventoryDB::RecordName::deviceConfiguration, Existing,
|
if(!NewContact.empty() && !StorageService()->ContactDB().Exists("id",NewContact)) {
|
||||||
FromConfiguration, ToConfiguration, StorageService()->ConfigurationDB()))
|
return BadRequest(RESTAPI::Errors::ContactMustExist);
|
||||||
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
|
}
|
||||||
|
MovingContact = Existing.contact != NewContact;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(AssignIfPresent(RawObject, "deviceConfiguration",NewConfiguration)) {
|
||||||
|
if(!NewConfiguration.empty() && !StorageService()->ConfigurationDB().Exists("id",NewConfiguration)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
|
||||||
|
}
|
||||||
|
MovingConfiguration = Existing.deviceConfiguration != NewConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(AssignIfPresent(RawObject, "managementPolicy",NewPolicy)) {
|
||||||
|
if(!NewPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewPolicy)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
|
}
|
||||||
|
MovingPolicy = Existing.managementPolicy != NewPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
std::string NewSubScriber;
|
std::string NewSubScriber;
|
||||||
if(AssignIfPresent(RawObject, "subscriber", NewSubScriber)) {
|
if(AssignIfPresent(RawObject, "subscriber", NewSubScriber)) {
|
||||||
@@ -357,30 +490,77 @@ namespace OpenWifi{
|
|||||||
Existing.state = NewObject.state;
|
Existing.state = NewObject.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
RESTAPI::Errors::msg Error=RESTAPI::Errors::SUCCESS;
|
std::string Arg;
|
||||||
auto ObjectsCreated = CreateObjects(NewObject,*this,Error);
|
bool UnAssign=false;
|
||||||
if(Error.err_num != 0) {
|
if(HasParameter("unassign", Arg) && Arg=="true") {
|
||||||
return BadRequest(Error);
|
UnAssign=true;
|
||||||
}
|
if(!Existing.venue.empty()) {
|
||||||
|
StorageService()->VenueDB().DeleteDevice("id",Existing.venue,Existing.info.id);
|
||||||
if(!ObjectsCreated.empty()) {
|
} else if(!Existing.entity.empty()) {
|
||||||
auto it = ObjectsCreated.find("configuration");
|
StorageService()->EntityDB().DeleteDevice("id",Existing.entity,Existing.info.id);
|
||||||
if(it!=ObjectsCreated.end()) {
|
|
||||||
FromConfiguration="";
|
|
||||||
ToConfiguration=it->second;
|
|
||||||
Existing.deviceConfiguration=ToConfiguration;
|
|
||||||
}
|
}
|
||||||
|
if(!Existing.location.empty())
|
||||||
|
StorageService()->LocationDB().DeleteInUse("id",Existing.location,DB_.Prefix(),Existing.info.id);
|
||||||
|
if(!Existing.contact.empty())
|
||||||
|
StorageService()->ContactDB().DeleteInUse("id",Existing.contact,DB_.Prefix(),Existing.info.id);
|
||||||
|
if(!Existing.deviceConfiguration.empty())
|
||||||
|
StorageService()->ConfigurationDB().DeleteInUse("id",Existing.deviceConfiguration,DB_.Prefix(),Existing.info.id);
|
||||||
|
if(!Existing.managementPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().DeleteInUse("id",Existing.managementPolicy,DB_.Prefix(),Existing.info.id);
|
||||||
|
Existing.venue.clear();
|
||||||
|
Existing.entity.clear();
|
||||||
|
Existing.deviceConfiguration.clear();
|
||||||
|
Existing.contact.clear();
|
||||||
|
Existing.location.clear();
|
||||||
|
Existing.managementPolicy.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StorageService()->InventoryDB().UpdateRecord("id", Existing.info.id, Existing)) {
|
if(StorageService()->InventoryDB().UpdateRecord("id", Existing.info.id, Existing)) {
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id);
|
if(!UnAssign) {
|
||||||
MoveUsage(StorageService()->LocationDB(),DB_,FromLocation,ToLocation,Existing.info.id);
|
if(MovingEntity) {
|
||||||
MoveUsage(StorageService()->ContactDB(),DB_,FromContact,ToContact,Existing.info.id);
|
if(!Existing.entity.empty())
|
||||||
MoveUsage(StorageService()->ConfigurationDB(),DB_,FromConfiguration,ToConfiguration,Existing.info.id);
|
StorageService()->EntityDB().DeleteDevice("id",Existing.entity,Existing.info.id);
|
||||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::devices,FromEntity,ToEntity,Existing.info.id);
|
if(!NewEntity.empty())
|
||||||
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::devices,FromVenue,ToVenue,Existing.info.id);
|
StorageService()->EntityDB().AddDevice("id", NewEntity, Existing.info.id);
|
||||||
|
Existing.entity = NewEntity;
|
||||||
SDK::GW::Device::SetOwnerShip(this, SerialNumber, Existing.entity, Existing.venue, Existing.subscriber);
|
}
|
||||||
|
if(MovingVenue) {
|
||||||
|
if(!Existing.venue.empty())
|
||||||
|
StorageService()->VenueDB().DeleteDevice("id",Existing.venue,Existing.info.id);
|
||||||
|
if(!NewVenue.empty())
|
||||||
|
StorageService()->VenueDB().AddDevice("id", NewVenue, Existing.info.id);
|
||||||
|
Existing.venue = NewVenue;
|
||||||
|
}
|
||||||
|
if(MovingConfiguration) {
|
||||||
|
if(!Existing.deviceConfiguration.empty())
|
||||||
|
StorageService()->ConfigurationDB().DeleteInUse("id",Existing.deviceConfiguration,DB_.Prefix(),Existing.info.id);
|
||||||
|
if(!NewConfiguration.empty())
|
||||||
|
StorageService()->ConfigurationDB().AddInUse("id",NewConfiguration,DB_.Prefix(),Existing.info.id);
|
||||||
|
Existing.deviceConfiguration = NewConfiguration;
|
||||||
|
}
|
||||||
|
if(MovingContact) {
|
||||||
|
if(!Existing.contact.empty())
|
||||||
|
StorageService()->ContactDB().DeleteInUse("id",Existing.contact,DB_.Prefix(),Existing.info.id);
|
||||||
|
if(!NewContact.empty())
|
||||||
|
StorageService()->ContactDB().AddInUse("id",NewContact,DB_.Prefix(),Existing.info.id);
|
||||||
|
Existing.contact = NewContact;
|
||||||
|
}
|
||||||
|
if(MovingLocation) {
|
||||||
|
if(!Existing.location.empty())
|
||||||
|
StorageService()->LocationDB().DeleteInUse("id",Existing.location,DB_.Prefix(),Existing.info.id);
|
||||||
|
if(!NewLocation.empty())
|
||||||
|
StorageService()->LocationDB().AddInUse("id",NewLocation,DB_.Prefix(),Existing.info.id);
|
||||||
|
Existing.location = NewLocation;
|
||||||
|
}
|
||||||
|
if(MovingPolicy) {
|
||||||
|
if(!Existing.managementPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().DeleteInUse("id",Existing.managementPolicy,DB_.Prefix(),Existing.info.id);
|
||||||
|
if(!NewPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().AddInUse("id",NewPolicy,DB_.Prefix(),Existing.info.id);
|
||||||
|
Existing.managementPolicy = NewPolicy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DB_.UpdateRecord("id", Existing.info.id, Existing);
|
||||||
|
|
||||||
ProvObjects::InventoryTag NewObjectCreated;
|
ProvObjects::InventoryTag NewObjectCreated;
|
||||||
DB_.GetRecord("id", Existing.info.id, NewObjectCreated);
|
DB_.GetRecord("id", Existing.info.id, NewObjectCreated);
|
||||||
|
|||||||
@@ -22,16 +22,17 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal),
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/inventory/{serialNumber}"}; };
|
DB_(StorageService()->InventoryDB()){}
|
||||||
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/inventory/{serialNumber}"}; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
InventoryDB &DB_=StorageService()->InventoryDB();
|
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final;
|
void DoPost() final;
|
||||||
void DoPut() final;
|
void DoPut() final;
|
||||||
void DoDelete() final;
|
void DoDelete() final;
|
||||||
void PerformClaim(const std::string &SerialNumber, const std::string & Claimer ,
|
void PerformClaim(const std::string &SerialNumber, const std::string & Claimer ,
|
||||||
std::string & ClaimId, uint64_t &ErrorCode, Poco::JSON::Object &Answer);
|
std::string & ClaimId, uint64_t &ErrorCode, Poco::JSON::Object &Answer);
|
||||||
|
InventoryDB &DB_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "RESTAPI_inventory_list_handler.h"
|
#include "RESTAPI_inventory_list_handler.h"
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
|
#include "framework/RESTAPI_errors.h"
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
@@ -34,77 +35,54 @@ namespace OpenWifi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_inventory_list_handler::DoGet() {
|
void RESTAPI_inventory_list_handler::DoGet() {
|
||||||
|
|
||||||
if(GetBoolParameter("orderSpec")) {
|
|
||||||
return ReturnFieldList(DB_,*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SerialOnly=GetBoolParameter("serialOnly");
|
|
||||||
|
|
||||||
std::string UUID;
|
std::string UUID;
|
||||||
std::string Arg,Arg2;
|
std::string Arg;
|
||||||
|
|
||||||
|
bool SerialOnly=false;
|
||||||
|
if(HasParameter("serialOnly",Arg) && Arg=="true")
|
||||||
|
SerialOnly=true;
|
||||||
|
|
||||||
std::string OrderBy{" ORDER BY serialNumber ASC "};
|
std::string OrderBy{" ORDER BY serialNumber ASC "};
|
||||||
if(HasParameter("orderBy",Arg)) {
|
if(HasParameter("orderBy",Arg)) {
|
||||||
if(!DB_.PrepareOrderBy(Arg,OrderBy)) {
|
if(!StorageService()->InventoryDB().PrepareOrderBy(Arg,OrderBy)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidLOrderBy);
|
return BadRequest(RESTAPI::Errors::InvalidLOrderBy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!QB_.Select.empty()) {
|
if(!QB_.Select.empty()) {
|
||||||
return ReturnRecordList<decltype(DB_)>("taglist",DB_,*this );
|
return ReturnRecordList<decltype(StorageService()->InventoryDB())>("taglist",StorageService()->InventoryDB(),*this );
|
||||||
} else if(HasParameter("entity",UUID)) {
|
} else if(HasParameter("entity",UUID)) {
|
||||||
if(QB_.CountOnly) {
|
if(QB_.CountOnly) {
|
||||||
auto C = DB_.Count( StorageService()->InventoryDB().OP("entity",ORM::EQ,UUID));
|
auto C = StorageService()->InventoryDB().Count( StorageService()->InventoryDB().OP("entity",ORM::EQ,UUID));
|
||||||
return ReturnCountOnly( C);
|
return ReturnCountOnly( C);
|
||||||
}
|
}
|
||||||
ProvObjects::InventoryTagVec Tags;
|
ProvObjects::InventoryTagVec Tags;
|
||||||
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, DB_.OP("entity",ORM::EQ,UUID), OrderBy);
|
StorageService()->InventoryDB().GetRecords(QB_.Offset, QB_.Limit, Tags, StorageService()->InventoryDB().OP("entity",ORM::EQ,UUID), OrderBy);
|
||||||
return SendList(Tags, SerialOnly);
|
return SendList(Tags, SerialOnly);
|
||||||
} else if(HasParameter("venue",UUID)) {
|
} else if(HasParameter("venue",UUID)) {
|
||||||
if(QB_.CountOnly) {
|
if(QB_.CountOnly) {
|
||||||
auto C = DB_.Count(DB_.OP("venue",ORM::EQ,UUID));
|
auto C = StorageService()->InventoryDB().Count(StorageService()->InventoryDB().OP("venue",ORM::EQ,UUID));
|
||||||
return ReturnCountOnly( C);
|
return ReturnCountOnly( C);
|
||||||
}
|
}
|
||||||
ProvObjects::InventoryTagVec Tags;
|
ProvObjects::InventoryTagVec Tags;
|
||||||
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, DB_.OP("venue",ORM::EQ,UUID), OrderBy);
|
StorageService()->InventoryDB().GetRecords(QB_.Offset, QB_.Limit, Tags, StorageService()->InventoryDB().OP("venue",ORM::EQ,UUID), OrderBy);
|
||||||
return SendList( Tags, SerialOnly);
|
return SendList( Tags, SerialOnly);
|
||||||
} else if(GetBoolParameter("subscribersOnly") && GetBoolParameter("unassigned")) {
|
} else if(HasParameter("unassigned",Arg) && Arg=="true") {
|
||||||
if(QB_.CountOnly) {
|
|
||||||
auto C = DB_.Count(" devClass='subscriber' and subscriber='' ");
|
|
||||||
return ReturnCountOnly( C);
|
|
||||||
}
|
|
||||||
ProvObjects::InventoryTagVec Tags;
|
|
||||||
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, " devClass='subscriber' and subscriber='' ", OrderBy);
|
|
||||||
if(QB_.CountOnly) {
|
|
||||||
auto C = DB_.Count(DB_.OP("venue",ORM::EQ,UUID));
|
|
||||||
return ReturnCountOnly( C);
|
|
||||||
}
|
|
||||||
return SendList(Tags, SerialOnly);
|
|
||||||
} else if(GetBoolParameter("subscribersOnly")) {
|
|
||||||
if(QB_.CountOnly) {
|
|
||||||
auto C = DB_.Count(" devClass='subscriber' and subscriber!='' ");
|
|
||||||
return ReturnCountOnly( C);
|
|
||||||
}
|
|
||||||
ProvObjects::InventoryTagVec Tags;
|
|
||||||
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags," devClass='subscriber' and subscriber!='' ", OrderBy);
|
|
||||||
return SendList(Tags, SerialOnly);
|
|
||||||
} else if(GetBoolParameter("unassigned")) {
|
|
||||||
if(QB_.CountOnly) {
|
if(QB_.CountOnly) {
|
||||||
std::string Empty;
|
std::string Empty;
|
||||||
auto C = DB_.Count( InventoryDB::OP( DB_.OP("venue",ORM::EQ,Empty),
|
auto C = StorageService()->InventoryDB().Count( InventoryDB::OP( StorageService()->InventoryDB().OP("venue",ORM::EQ,Empty),
|
||||||
ORM::AND, DB_.OP("entity",ORM::EQ,Empty) ));
|
ORM::AND, StorageService()->InventoryDB().OP("entity",ORM::EQ,Empty) ));
|
||||||
return ReturnCountOnly(C);
|
return ReturnCountOnly(C);
|
||||||
}
|
}
|
||||||
ProvObjects::InventoryTagVec Tags;
|
ProvObjects::InventoryTagVec Tags;
|
||||||
std::string Empty;
|
std::string Empty;
|
||||||
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, InventoryDB::OP( DB_.OP("venue",ORM::EQ,Empty),
|
StorageService()->InventoryDB().GetRecords(QB_.Offset, QB_.Limit, Tags, InventoryDB::OP( StorageService()->InventoryDB().OP("venue",ORM::EQ,Empty),
|
||||||
ORM::AND, DB_.OP("entity",ORM::EQ,Empty) ) , OrderBy );
|
ORM::AND, StorageService()->InventoryDB().OP("entity",ORM::EQ,Empty) ) , OrderBy );
|
||||||
return SendList(Tags, SerialOnly);
|
return SendList(Tags, SerialOnly);
|
||||||
} else if (HasParameter("subscriber",Arg) && !Arg.empty()) {
|
} else if (HasParameter("subscriber",Arg) && !Arg.empty()) {
|
||||||
// looking for device(s) for a specific subscriber...
|
// looking for device(s) for a specific subscriber...
|
||||||
ProvObjects::InventoryTagVec Tags;
|
ProvObjects::InventoryTagVec Tags;
|
||||||
DB_.GetRecords(0,100,Tags," subscriber='" + Arg + "'");
|
StorageService()->InventoryDB().GetRecords(0,100,Tags," subscriber='" + Arg + "'");
|
||||||
if(SerialOnly) {
|
if(SerialOnly) {
|
||||||
std::vector<std::string> SerialNumbers;
|
std::vector<std::string> SerialNumbers;
|
||||||
std::transform(cbegin(Tags), cend(Tags), std::back_inserter(SerialNumbers), [](const auto &T) { return T.serialNumber; });
|
std::transform(cbegin(Tags), cend(Tags), std::back_inserter(SerialNumbers), [](const auto &T) { return T.serialNumber; });
|
||||||
@@ -113,11 +91,11 @@ namespace OpenWifi{
|
|||||||
return MakeJSONObjectArray("taglist", Tags, *this);
|
return MakeJSONObjectArray("taglist", Tags, *this);
|
||||||
}
|
}
|
||||||
} else if (QB_.CountOnly) {
|
} else if (QB_.CountOnly) {
|
||||||
auto C = DB_.Count();
|
auto C = StorageService()->InventoryDB().Count();
|
||||||
return ReturnCountOnly(C);
|
return ReturnCountOnly(C);
|
||||||
} else if (GetBoolParameter("rrmOnly")) {
|
} else if (GetBoolParameter("rrmOnly",false)) {
|
||||||
Types::UUIDvec_t DeviceList;
|
Types::UUIDvec_t DeviceList;
|
||||||
DB_.GetRRMDeviceList(DeviceList);
|
StorageService()->InventoryDB().GetRRMDeviceList(DeviceList);
|
||||||
if(QB_.CountOnly)
|
if(QB_.CountOnly)
|
||||||
return ReturnCountOnly(DeviceList.size());
|
return ReturnCountOnly(DeviceList.size());
|
||||||
else {
|
else {
|
||||||
@@ -125,7 +103,7 @@ namespace OpenWifi{
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ProvObjects::InventoryTagVec Tags;
|
ProvObjects::InventoryTagVec Tags;
|
||||||
DB_.GetRecords(QB_.Offset,QB_.Limit,Tags,"",OrderBy);
|
StorageService()->InventoryDB().GetRecords(QB_.Offset,QB_.Limit,Tags,"",OrderBy);
|
||||||
return MakeJSONObjectArray("taglist", Tags, *this);
|
return MakeJSONObjectArray("taglist", Tags, *this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "StorageService.h"
|
|
||||||
#include "framework/MicroService.h"
|
#include "framework/MicroService.h"
|
||||||
|
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
@@ -22,10 +22,9 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal) {}
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/inventory"}; };
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/inventory"}; };
|
||||||
private:
|
|
||||||
InventoryDB &DB_=StorageService()->InventoryDB();
|
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final {};
|
void DoPost() final {};
|
||||||
void DoPut() final {};
|
void DoPut() final {};
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class RESTAPI_iptocountry_handler : public RESTAPIHandler {
|
|||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){};
|
Internal){};
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/iptocountry"}; };
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/iptocountry"}; };
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoDelete() final {};
|
void DoDelete() final {};
|
||||||
void DoPost() final {};
|
void DoPost() final {};
|
||||||
|
|||||||
@@ -8,8 +8,11 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "RESTAPI_location_handler.h"
|
#include "RESTAPI_location_handler.h"
|
||||||
|
#include "framework/RESTAPI_errors.h"
|
||||||
|
|
||||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
|
#include "framework/RESTAPI_protocol.h"
|
||||||
#include "Daemon.h"
|
#include "Daemon.h"
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||||
|
|
||||||
@@ -64,10 +67,13 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
DB_.DeleteRecord("id",UUID);
|
if(DB_.DeleteRecord("id",UUID)) {
|
||||||
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::locations,Existing.entity,Existing.info.id);
|
if(!Existing.entity.empty())
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.info.id,"",Existing.info.id);
|
StorageService()->EntityDB().DeleteLocation("id",Existing.entity,UUID);
|
||||||
return OK();
|
|
||||||
|
return OK();
|
||||||
|
}
|
||||||
|
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_location_handler::DoPost() {
|
void RESTAPI_location_handler::DoPost() {
|
||||||
@@ -76,7 +82,7 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & Obj = ParsedBody_;
|
auto Obj = ParseStream();
|
||||||
ProvObjects::Location NewObject;
|
ProvObjects::Location NewObject;
|
||||||
if (!NewObject.from_json(Obj)) {
|
if (!NewObject.from_json(Obj)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
@@ -97,11 +103,11 @@ namespace OpenWifi{
|
|||||||
NewObject.inUse.clear();
|
NewObject.inUse.clear();
|
||||||
|
|
||||||
if(DB_.CreateRecord(NewObject)) {
|
if(DB_.CreateRecord(NewObject)) {
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
|
if(!NewObject.managementPolicy.empty())
|
||||||
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::locations,NewObject.entity,NewObject.info.id);
|
StorageService()->PolicyDB().AddInUse("id",NewObject.managementPolicy,DB_.Prefix(),NewObject.info.id);
|
||||||
|
|
||||||
|
StorageService()->EntityDB().AddLocation("id",NewObject.entity,NewObject.info.id);
|
||||||
|
|
||||||
LocationDB::RecordName AddedRecord;
|
|
||||||
DB_.GetRecord("id", NewObject.info.id,AddedRecord);
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
NewObject.to_json(Answer);
|
NewObject.to_json(Answer);
|
||||||
return ReturnObject(Answer);
|
return ReturnObject(Answer);
|
||||||
@@ -110,14 +116,13 @@ namespace OpenWifi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_location_handler::DoPut() {
|
void RESTAPI_location_handler::DoPut() {
|
||||||
|
std::string UUID = GetBinding(RESTAPI::Protocol::UUID,"");
|
||||||
std::string UUID = GetBinding(RESTAPI::Protocol::UUID);
|
|
||||||
ProvObjects::Location Existing;
|
ProvObjects::Location Existing;
|
||||||
if(UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
|
if(UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
auto RawObject = ParseStream();
|
||||||
ProvObjects::Location NewObject;
|
ProvObjects::Location NewObject;
|
||||||
if (!NewObject.from_json(RawObject)) {
|
if (!NewObject.from_json(RawObject)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
@@ -127,13 +132,27 @@ namespace OpenWifi{
|
|||||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FromPolicy, ToPolicy;
|
std::string MoveFromPolicy,MoveToPolicy;
|
||||||
if(!CreateMove(RawObject,"managementPolicy",&LocationDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
|
bool MovingPolicy=false;
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
if(AssignIfPresent(RawObject,"managementPolicy",MoveToPolicy)) {
|
||||||
|
if(!MoveToPolicy.empty() && !StorageService()->PolicyDB().Exists("id",MoveToPolicy)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
|
}
|
||||||
|
MoveFromPolicy = Existing.managementPolicy;
|
||||||
|
MovingPolicy = MoveToPolicy != MoveFromPolicy;
|
||||||
|
Existing.managementPolicy = MoveToPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
std::string FromEntity, ToEntity;
|
std::string MoveFromEntity,MoveToEntity;
|
||||||
if(!CreateMove(RawObject,"entity",&LocationDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
|
bool MovingEntity=false;
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
if(AssignIfPresent(RawObject,"entity",MoveToEntity)) {
|
||||||
|
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||||
|
}
|
||||||
|
MoveFromEntity = Existing.entity;
|
||||||
|
MovingEntity = MoveToEntity != Existing.entity;
|
||||||
|
Existing.entity = MoveToEntity;
|
||||||
|
}
|
||||||
|
|
||||||
AssignIfPresent(RawObject, "buildingName", Existing.buildingName);
|
AssignIfPresent(RawObject, "buildingName", Existing.buildingName);
|
||||||
AssignIfPresent(RawObject, "city", Existing.city);
|
AssignIfPresent(RawObject, "city", Existing.city);
|
||||||
@@ -147,16 +166,27 @@ namespace OpenWifi{
|
|||||||
Existing.phones = NewObject.phones;
|
Existing.phones = NewObject.phones;
|
||||||
if(RawObject->has("mobiles"))
|
if(RawObject->has("mobiles"))
|
||||||
Existing.mobiles = NewObject.mobiles;
|
Existing.mobiles = NewObject.mobiles;
|
||||||
Existing.info.modified = OpenWifi::Now();
|
Existing.info.modified = std::time(nullptr);
|
||||||
if(RawObject->has("type"))
|
if(RawObject->has("type"))
|
||||||
Existing.type = NewObject.type;
|
Existing.type = NewObject.type;
|
||||||
|
|
||||||
if(DB_.UpdateRecord("id", UUID, Existing)) {
|
if(DB_.UpdateRecord("id", UUID, Existing)) {
|
||||||
MoveUsage(StorageService()->PolicyDB(), DB_, FromPolicy, ToPolicy, Existing.info.id);
|
if(MovingPolicy) {
|
||||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::locations,FromEntity, ToEntity, Existing.info.id);
|
if(!MoveFromPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().DeleteInUse("id",MoveFromPolicy,DB_.Prefix(),Existing.info.id);
|
||||||
|
if(!MoveToPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().AddInUse("id", MoveToPolicy, DB_.Prefix(), Existing.info.id);
|
||||||
|
}
|
||||||
|
if(MovingEntity) {
|
||||||
|
if(!MoveFromEntity.empty())
|
||||||
|
StorageService()->EntityDB().DeleteLocation("id",MoveFromEntity,Existing.info.id);
|
||||||
|
if(!MoveToEntity.empty())
|
||||||
|
StorageService()->EntityDB().AddLocation("id", MoveToEntity, Existing.info.id);
|
||||||
|
}
|
||||||
|
|
||||||
ProvObjects::Location NewObjectAdded;
|
ProvObjects::Location NewObjectAdded;
|
||||||
DB_.GetRecord("id", UUID, NewObjectAdded);
|
DB_.GetRecord("id", UUID, NewObjectAdded);
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
NewObjectAdded.to_json(Answer);
|
NewObjectAdded.to_json(Answer);
|
||||||
return ReturnObject(Answer);
|
return ReturnObject(Answer);
|
||||||
|
|||||||
@@ -22,14 +22,15 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal),
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/location/{uuid}"}; };
|
DB_(StorageService()->LocationDB()){}
|
||||||
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/location/{uuid}"}; };
|
||||||
|
|
||||||
private:
|
|
||||||
LocationDB & DB_ = StorageService()->LocationDB();
|
|
||||||
void DoGet() final ;
|
void DoGet() final ;
|
||||||
void DoPost() final ;
|
void DoPost() final ;
|
||||||
void DoPut() final ;
|
void DoPut() final ;
|
||||||
void DoDelete() final ;
|
void DoDelete() final ;
|
||||||
|
private:
|
||||||
|
LocationDB &DB_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,17 @@
|
|||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
|
|
||||||
void RESTAPI_location_list_handler::DoGet() {
|
void RESTAPI_location_list_handler::DoGet() {
|
||||||
return ListHandler<LocationDB>("locations", DB_, *this);
|
if(!QB_.Select.empty()) {
|
||||||
|
return ReturnRecordList<decltype(StorageService()->LocationDB()),
|
||||||
|
ProvObjects::Location>("locations",StorageService()->LocationDB(),*this );
|
||||||
|
} else if(QB_.CountOnly) {
|
||||||
|
Poco::JSON::Object Answer;
|
||||||
|
auto C = StorageService()->LocationDB().Count();
|
||||||
|
return ReturnCountOnly(C);
|
||||||
|
} else {
|
||||||
|
ProvObjects::LocationVec Locations;
|
||||||
|
StorageService()->LocationDB().GetRecords(QB_.Offset,QB_.Limit,Locations);
|
||||||
|
return MakeJSONObjectArray("locations", Locations, *this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
#include "framework/MicroService.h"
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
@@ -18,10 +17,9 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal) {}
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/location"}; };
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/location"}; };
|
||||||
private:
|
|
||||||
LocationDB & DB_=StorageService()->LocationDB();
|
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final {};
|
void DoPost() final {};
|
||||||
void DoPut() final {};
|
void DoPut() final {};
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
#include "Poco/JSON/Parser.h"
|
#include "Poco/JSON/Parser.h"
|
||||||
#include "Daemon.h"
|
#include "Daemon.h"
|
||||||
|
#include "framework/RESTAPI_errors.h"
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
@@ -63,10 +64,11 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageService()->PolicyDB().DeleteRecord("id", UUID);
|
if(StorageService()->PolicyDB().DeleteRecord("id", UUID)) {
|
||||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementPolicies,Existing.entity,"",Existing.info.id);
|
return OK();
|
||||||
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementPolicies,Existing.venue,"",Existing.info.id);
|
}
|
||||||
return OK();
|
|
||||||
|
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_managementPolicy_handler::DoPost() {
|
void RESTAPI_managementPolicy_handler::DoPost() {
|
||||||
@@ -75,32 +77,23 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProvObjects::ManagementPolicy NewObject;
|
ProvObjects::ManagementPolicy NewPolicy;
|
||||||
const auto & RawObject = ParsedBody_;
|
auto NewObject = ParseStream();
|
||||||
if(!NewObject.from_json(RawObject)) {
|
if(!NewPolicy.from_json(NewObject)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info)) {
|
if(!CreateObjectInfo(NewObject, UserInfo_.userinfo, NewPolicy.info)) {
|
||||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NewObject.entity.empty() || !StorageService()->EntityDB().Exists("id", NewObject.entity)) {
|
NewPolicy.inUse.clear();
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NewObject.venue.empty() || !StorageService()->VenueDB().Exists("id", NewObject.venue)) {
|
if(DB_.CreateRecord(NewPolicy)) {
|
||||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
ProvObjects::ManagementPolicy Policy;
|
||||||
}
|
DB_.GetRecord("id",NewPolicy.info.id,Policy);
|
||||||
|
|
||||||
NewObject.inUse.clear();
|
|
||||||
if(DB_.CreateRecord(NewObject)) {
|
|
||||||
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementPolicies,NewObject.entity,NewObject.info.id);
|
|
||||||
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementPolicies,NewObject.venue,NewObject.info.id);
|
|
||||||
PolicyDB::RecordName AddedObject;
|
|
||||||
DB_.GetRecord("id",NewObject.info.id,AddedObject);
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
AddedObject.to_json(Answer);
|
Policy.to_json(Answer);
|
||||||
return ReturnObject(Answer);
|
return ReturnObject(Answer);
|
||||||
}
|
}
|
||||||
InternalError(RESTAPI::Errors::RecordNotCreated);
|
InternalError(RESTAPI::Errors::RecordNotCreated);
|
||||||
@@ -114,31 +107,20 @@ namespace OpenWifi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProvObjects::ManagementPolicy NewPolicy;
|
ProvObjects::ManagementPolicy NewPolicy;
|
||||||
const auto & RawObject = ParsedBody_;
|
auto NewObject = ParseStream();
|
||||||
if(!NewPolicy.from_json(RawObject)) {
|
if(!NewPolicy.from_json(NewObject)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info)) {
|
if(!UpdateObjectInfo(NewObject, UserInfo_.userinfo, Existing.info)) {
|
||||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FromEntity, ToEntity;
|
|
||||||
if(!CreateMove(RawObject,"entity",&PolicyDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
|
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
|
|
||||||
std::string FromVenue, ToVenue;
|
|
||||||
if(!CreateMove(RawObject,"venue",&PolicyDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB()))
|
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
|
|
||||||
if(!NewPolicy.entries.empty())
|
if(!NewPolicy.entries.empty())
|
||||||
Existing.entries = NewPolicy.entries;
|
Existing.entries = NewPolicy.entries;
|
||||||
|
|
||||||
if(DB_.UpdateRecord("id", Existing.info.id, Existing)) {
|
if(DB_.UpdateRecord("id", Existing.info.id, Existing)) {
|
||||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementPolicies, FromEntity,ToEntity,Existing.info.id);
|
ProvObjects::ManagementPolicy P;
|
||||||
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementPolicies, FromVenue,ToVenue,Existing.info.id);
|
|
||||||
|
|
||||||
ProvObjects::ManagementPolicy P;
|
|
||||||
DB_.GetRecord("id",Existing.info.id,P);
|
DB_.GetRecord("id",Existing.info.id,P);
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
P.to_json(Answer);
|
P.to_json(Answer);
|
||||||
|
|||||||
@@ -21,11 +21,12 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal),
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/managementPolicy/{uuid}"}; };
|
DB_(StorageService()->PolicyDB()){}
|
||||||
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/managementPolicy/{uuid}"}; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PolicyDB &DB_=StorageService()->PolicyDB();
|
PolicyDB &DB_;
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final ;
|
void DoPost() final ;
|
||||||
void DoPut() final ;
|
void DoPut() final ;
|
||||||
|
|||||||
@@ -6,10 +6,22 @@
|
|||||||
|
|
||||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
|
#include "framework/RESTAPI_errors.h"
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
void RESTAPI_managementPolicy_list_handler::DoGet() {
|
void RESTAPI_managementPolicy_list_handler::DoGet() {
|
||||||
return ListHandler<PolicyDB>("managementPolicies", DB_, *this);
|
if(!QB_.Select.empty()) {
|
||||||
|
return ReturnRecordList<decltype(StorageService()->PolicyDB()),
|
||||||
|
ProvObjects::ManagementPolicy>("managementPolicies",StorageService()->PolicyDB(),*this );
|
||||||
|
} else if(QB_.CountOnly) {
|
||||||
|
Poco::JSON::Object Answer;
|
||||||
|
auto C = StorageService()->ContactDB().Count();
|
||||||
|
return ReturnCountOnly(C);
|
||||||
|
} else {
|
||||||
|
ProvObjects::ManagementPolicyVec Policies;
|
||||||
|
StorageService()->PolicyDB().GetRecords(QB_.Offset,QB_.Limit,Policies);
|
||||||
|
return MakeJSONObjectArray("managementPolicies", Policies, *this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
#include "framework/MicroService.h"
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
@@ -16,10 +15,9 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal) {}
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/managementPolicy"}; };
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/managementPolicy"}; };
|
||||||
private:
|
|
||||||
PolicyDB &DB_=StorageService()->PolicyDB();
|
|
||||||
void DoGet() final ;
|
void DoGet() final ;
|
||||||
void DoPost() final {};
|
void DoPost() final {};
|
||||||
void DoPut() final {};
|
void DoPut() final {};
|
||||||
|
|||||||
@@ -4,10 +4,12 @@
|
|||||||
|
|
||||||
#include "RESTAPI_managementRole_handler.h"
|
#include "RESTAPI_managementRole_handler.h"
|
||||||
|
|
||||||
|
#include "framework/RESTAPI_protocol.h"
|
||||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
#include "Poco/JSON/Parser.h"
|
#include "Poco/JSON/Parser.h"
|
||||||
#include "Poco/StringTokenizer.h"
|
#include "Poco/StringTokenizer.h"
|
||||||
|
#include "framework/RESTAPI_errors.h"
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
@@ -62,11 +64,13 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
DB_.DeleteRecord("id", Existing.info.id);
|
if(!Existing.managementPolicy.empty())
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
|
StorageService()->PolicyDB().DeleteInUse("id",Existing.managementPolicy,DB_.Prefix(),Existing.info.id);
|
||||||
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementRoles,Existing.entity,Existing.info.id);
|
|
||||||
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementRoles,Existing.venue,Existing.info.id);
|
if(StorageService()->RolesDB().DeleteRecord("id", Existing.info.id)) {
|
||||||
return OK();
|
return OK();
|
||||||
|
}
|
||||||
|
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_managementRole_handler::DoPost() {
|
void RESTAPI_managementRole_handler::DoPost() {
|
||||||
@@ -75,29 +79,23 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & RawObj = ParsedBody_;
|
auto Obj = ParseStream();
|
||||||
ProvObjects::ManagementRole NewObject;
|
ProvObjects::ManagementRole NewObject;
|
||||||
if (!NewObject.from_json(RawObj)) {
|
if (!NewObject.from_json(Obj)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!CreateObjectInfo(RawObj, UserInfo_.userinfo, NewObject.info)) {
|
if(!CreateObjectInfo(Obj, UserInfo_.userinfo, NewObject.info)) {
|
||||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NewObject.entity.empty() || !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
|
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
|
||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(DB_.CreateRecord(NewObject)) {
|
if(DB_.CreateRecord(NewObject)) {
|
||||||
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementRoles,NewObject.entity,NewObject.info.id);
|
if(!NewObject.managementPolicy.empty())
|
||||||
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementRoles,NewObject.venue,NewObject.info.id);
|
StorageService()->PolicyDB().AddInUse("id", NewObject.managementPolicy, DB_.Prefix(), NewObject.info.id);
|
||||||
MoveUsage(StorageService()->PolicyDB(), DB_, "", NewObject.managementPolicy, NewObject.info.id);
|
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
ProvObjects::ManagementRole Role;
|
ProvObjects::ManagementRole Role;
|
||||||
DB_.GetRecord("id", NewObject.info.id,Role);
|
DB_.GetRecord("id", NewObject.info.id,Role);
|
||||||
@@ -114,7 +112,7 @@ namespace OpenWifi{
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
auto RawObject = ParseStream();
|
||||||
ProvObjects::ManagementRole NewObject;
|
ProvObjects::ManagementRole NewObject;
|
||||||
if(!NewObject.from_json(RawObject)) {
|
if(!NewObject.from_json(RawObject)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
@@ -124,22 +122,20 @@ namespace OpenWifi{
|
|||||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FromPolicy, ToPolicy;
|
std::string NewPolicy,OldPolicy = Existing.managementPolicy;
|
||||||
if(!CreateMove(RawObject,"managementPolicy",&ManagementRoleDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
|
AssignIfPresent(RawObject, "managementPolicy", NewPolicy);
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
if(!NewPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewPolicy)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
|
}
|
||||||
|
|
||||||
std::string FromEntity, ToEntity;
|
if(!NewPolicy.empty())
|
||||||
if(!CreateMove(RawObject,"entity",&ManagementRoleDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
|
Existing.managementPolicy = NewPolicy;
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
|
|
||||||
std::string FromVenue, ToVenue;
|
|
||||||
if(!CreateMove(RawObject,"venue",&ManagementRoleDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB()))
|
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
|
|
||||||
if(DB_.UpdateRecord("id",UUID,Existing)) {
|
if(DB_.UpdateRecord("id",UUID,Existing)) {
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_, FromPolicy, ToPolicy, Existing.info.id);
|
if(!OldPolicy.empty())
|
||||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementRoles, FromEntity, ToEntity, Existing.info.id);
|
StorageService()->PolicyDB().DeleteInUse("id",OldPolicy,DB_.Prefix(),UUID);
|
||||||
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementRoles, FromVenue, ToVenue, Existing.info.id);
|
if(!NewPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().AddInUse("id",NewPolicy,DB_.Prefix(),UUID);
|
||||||
|
|
||||||
ProvObjects::ManagementRole NewRecord;
|
ProvObjects::ManagementRole NewRecord;
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,11 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal),
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/managementRole/{uuid}"}; };
|
DB_(StorageService()->RolesDB()){}
|
||||||
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/managementRole/{uuid}"}; };
|
||||||
private:
|
private:
|
||||||
ManagementRoleDB &DB_=StorageService()->RolesDB();
|
ManagementRoleDB &DB_;
|
||||||
void DoGet() final ;
|
void DoGet() final ;
|
||||||
void DoPost() final ;
|
void DoPost() final ;
|
||||||
void DoPut() final ;
|
void DoPut() final ;
|
||||||
|
|||||||
@@ -7,10 +7,22 @@
|
|||||||
#include "RESTAPI_managementRole_list_handler.h"
|
#include "RESTAPI_managementRole_list_handler.h"
|
||||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
|
#include "framework/RESTAPI_errors.h"
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
void RESTAPI_managementRole_list_handler::DoGet() {
|
void RESTAPI_managementRole_list_handler::DoGet() {
|
||||||
return ListHandler<ManagementRoleDB>("roles", DB_, *this);
|
if(!QB_.Select.empty()) {
|
||||||
|
return ReturnRecordList<decltype(StorageService()->RolesDB()),
|
||||||
|
ProvObjects::ManagementRole>("roles",StorageService()->RolesDB(),*this );
|
||||||
|
} else if(QB_.CountOnly) {
|
||||||
|
Poco::JSON::Object Answer;
|
||||||
|
auto C = StorageService()->RolesDB().Count();
|
||||||
|
return ReturnCountOnly(C);
|
||||||
|
} else {
|
||||||
|
ProvObjects::ManagementRoleVec Roles;
|
||||||
|
StorageService()->RolesDB().GetRecords(QB_.Offset,QB_.Limit,Roles);
|
||||||
|
return MakeJSONObjectArray("roles", Roles, *this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
#include "framework/MicroService.h"
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
@@ -17,11 +16,9 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal) {
|
Internal) {}
|
||||||
}
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/managementRole"}; };
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/managementRole"}; };
|
|
||||||
private:
|
|
||||||
ManagementRoleDB &DB_=StorageService()->RolesDB();
|
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final {};
|
void DoPost() final {};
|
||||||
void DoPut() final {};
|
void DoPut() final {};
|
||||||
|
|||||||
@@ -4,10 +4,12 @@
|
|||||||
|
|
||||||
#include "RESTAPI_map_handler.h"
|
#include "RESTAPI_map_handler.h"
|
||||||
|
|
||||||
|
#include "framework/RESTAPI_protocol.h"
|
||||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
#include "Poco/JSON/Parser.h"
|
#include "Poco/JSON/Parser.h"
|
||||||
#include "Poco/StringTokenizer.h"
|
#include "Poco/StringTokenizer.h"
|
||||||
|
#include "framework/RESTAPI_errors.h"
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
@@ -34,20 +36,17 @@ namespace OpenWifi{
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( UserInfo_.userinfo.userRole!=SecurityObjects::ROOT &&
|
if(UserInfo_.userinfo.id!=Existing.creator) {
|
||||||
UserInfo_.userinfo.userRole!=SecurityObjects::ADMIN &&
|
return UnAuthorized("You must be the creator of the map to delete it");
|
||||||
UserInfo_.userinfo.id!=Existing.creator) {
|
|
||||||
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DB_.DeleteRecord("id", Existing.info.id);
|
if(DB_.DeleteRecord("id", Existing.info.id)) {
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
|
return OK();
|
||||||
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::maps,Existing.entity,Existing.info.id);
|
}
|
||||||
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::maps,Existing.venue,Existing.info.id);
|
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||||
return OK();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ValidateVisibility(const std::string &V) {
|
static auto ValidateVisibility(const std::string &V) {
|
||||||
return (V=="private" || V=="public" || V=="select");
|
return (V=="private" || V=="public" || V=="select");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,36 +56,20 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
auto Obj = ParseStream();
|
||||||
ProvObjects::Map NewObject;
|
ProvObjects::Map NewObject;
|
||||||
if (!NewObject.from_json(RawObject)) {
|
if (!NewObject.from_json(Obj)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info)) {
|
if(!CreateObjectInfo(Obj, UserInfo_.userinfo, NewObject.info)) {
|
||||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ValidateVisibility(NewObject.visibility)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidVisibilityAttribute);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RawObject->has("entity")) {
|
|
||||||
if(!NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObject.entity))
|
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RawObject->has("managementPolicy")) {
|
|
||||||
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy))
|
|
||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
NewObject.creator = UserInfo_.userinfo.id;
|
NewObject.creator = UserInfo_.userinfo.id;
|
||||||
|
|
||||||
if(DB_.CreateRecord(NewObject)) {
|
if(DB_.CreateRecord(NewObject)) {
|
||||||
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::maps,NewObject.entity,NewObject.info.id);
|
|
||||||
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::maps,NewObject.venue,NewObject.info.id);
|
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
ProvObjects::Map M;
|
ProvObjects::Map M;
|
||||||
DB_.GetRecord("id", NewObject.info.id,M);
|
DB_.GetRecord("id", NewObject.info.id,M);
|
||||||
@@ -103,7 +86,7 @@ namespace OpenWifi{
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
auto RawObject = ParseStream();
|
||||||
ProvObjects::Map NewObject;
|
ProvObjects::Map NewObject;
|
||||||
if(!NewObject.from_json(RawObject)) {
|
if(!NewObject.from_json(RawObject)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
@@ -113,56 +96,33 @@ namespace OpenWifi{
|
|||||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( UserInfo_.userinfo.userRole!=SecurityObjects::ROOT &&
|
if(Existing.creator != UserInfo_.userinfo.id) {
|
||||||
UserInfo_.userinfo.userRole!=SecurityObjects::ADMIN &&
|
if(Existing.visibility == ProvObjects::PRIVATE) {
|
||||||
UserInfo_.userinfo.id!=Existing.creator) {
|
return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights, ACCESS_DENIED);
|
||||||
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( UserInfo_.userinfo.userRole==SecurityObjects::ROOT ||
|
|
||||||
UserInfo_.userinfo.userRole==SecurityObjects::ADMIN) {
|
|
||||||
|
|
||||||
} else if(Existing.creator != UserInfo_.userinfo.id) {
|
|
||||||
if(Existing.visibility == "private") {
|
|
||||||
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
|
|
||||||
}
|
}
|
||||||
if(Existing.visibility == "select") {
|
if(Existing.visibility == ProvObjects::SELECT) {
|
||||||
bool allowed=false;
|
|
||||||
for(const auto &i:Existing.access.list) {
|
for(const auto &i:Existing.access.list) {
|
||||||
for(const auto &j:i.users.list) {
|
for(const auto &j:i.users.list) {
|
||||||
if(j==UserInfo_.userinfo.id) {
|
if(j==UserInfo_.userinfo.id) {
|
||||||
allowed=true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!allowed) {
|
|
||||||
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FromPolicy, ToPolicy;
|
if(RawObject->has("entity") && !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
|
||||||
if(!CreateMove(RawObject,"managementPolicy",&MapDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
|
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||||
|
}
|
||||||
|
|
||||||
std::string FromEntity, ToEntity;
|
AssignIfPresent(RawObject,"entity",Existing.entity);
|
||||||
if(!CreateMove(RawObject,"entity",&MapDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
|
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
|
|
||||||
std::string FromVenue, ToVenue;
|
|
||||||
if(!CreateMove(RawObject,"venue",&MapDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB()))
|
|
||||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
|
||||||
|
|
||||||
AssignIfPresent(RawObject,"data", Existing.data);
|
AssignIfPresent(RawObject,"data", Existing.data);
|
||||||
if(RawObject->has("visibility"))
|
if(RawObject->has("visibility"))
|
||||||
Existing.visibility = NewObject.visibility;
|
Existing.visibility = NewObject.visibility;
|
||||||
|
|
||||||
if(DB_.UpdateRecord("id",UUID,Existing)) {
|
if(DB_.UpdateRecord("id",UUID,Existing)) {
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id);
|
|
||||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::maps,FromEntity,ToEntity,Existing.info.id);
|
|
||||||
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::maps,FromVenue,ToVenue,Existing.info.id);
|
|
||||||
|
|
||||||
ProvObjects::Map NewRecord;
|
ProvObjects::Map NewRecord;
|
||||||
|
|
||||||
DB_.GetRecord("id", UUID, NewRecord);
|
DB_.GetRecord("id", UUID, NewRecord);
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
NewRecord.to_json(Answer);
|
NewRecord.to_json(Answer);
|
||||||
|
|||||||
@@ -17,10 +17,11 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal),
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/map/{uuid}"}; };
|
DB_(StorageService()->MapDB()){}
|
||||||
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/map/{uuid}"}; };
|
||||||
private:
|
private:
|
||||||
MapDB &DB_=StorageService()->MapDB();
|
MapDB &DB_;
|
||||||
void DoGet() final ;
|
void DoGet() final ;
|
||||||
void DoPost() final ;
|
void DoPost() final ;
|
||||||
void DoPut() final ;
|
void DoPut() final ;
|
||||||
|
|||||||
@@ -9,16 +9,23 @@
|
|||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
void RESTAPI_map_list_handler::DoGet() {
|
void RESTAPI_map_list_handler::DoGet() {
|
||||||
const char *BlockName{"list"};
|
|
||||||
if(GetBoolParameter("myMaps",false)) {
|
if(GetBoolParameter("myMaps",false)) {
|
||||||
auto where = DB_.OP("creator",ORM::EQ,UserInfo_.userinfo.id);
|
auto where = StorageService()->MapDB().OP("creator",ORM::EQ,UserInfo_.userinfo.id);
|
||||||
MapDB::RecordVec Maps;
|
std::vector<ProvObjects::Map> Maps;
|
||||||
DB_.GetRecords(QB_.Offset,QB_.Limit,Maps,where);
|
StorageService()->MapDB().GetRecords(QB_.Offset,QB_.Limit,Maps,where);
|
||||||
return MakeJSONObjectArray(BlockName, Maps, *this);
|
return MakeJSONObjectArray("list", Maps, *this);
|
||||||
} else if(GetBoolParameter("sharedWithMe",false)) {
|
} else if(GetBoolParameter("sharedWithMe",false)) {
|
||||||
|
|
||||||
|
} else if(!QB_.Select.empty()) {
|
||||||
|
return ReturnRecordList<decltype(StorageService()->MapDB()),ProvObjects::Map>("list",StorageService()->MapDB(),*this );
|
||||||
|
} else if(QB_.CountOnly) {
|
||||||
|
Poco::JSON::Object Answer;
|
||||||
|
auto C = StorageService()->MapDB().Count();
|
||||||
|
return ReturnCountOnly(C);
|
||||||
} else {
|
} else {
|
||||||
return ListHandler<MapDB>(BlockName, DB_, *this);
|
std::vector<ProvObjects::Map> Maps;
|
||||||
|
StorageService()->MapDB().GetRecords(QB_.Offset,QB_.Limit,Maps);
|
||||||
|
return MakeJSONObjectArray("list", Maps, *this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
#include "framework/MicroService.h"
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
@@ -17,11 +16,9 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal) {
|
Internal) {}
|
||||||
}
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/map"}; };
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/map"}; };
|
|
||||||
private:
|
|
||||||
MapDB &DB_=StorageService()->MapDB();
|
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final {};
|
void DoPost() final {};
|
||||||
void DoPut() final {};
|
void DoPut() final {};
|
||||||
|
|||||||
@@ -1,102 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-07.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_op_contact_handler.h"
|
|
||||||
#include "RESTAPI_db_helpers.h"
|
|
||||||
#include "sdks/SDK_sec.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
void RESTAPI_op_contact_handler::DoGet() {
|
|
||||||
auto uuid = GetBinding("uuid","");
|
|
||||||
if(uuid.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
OpContactDB::RecordName Existing;
|
|
||||||
if(!DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
Existing.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_op_contact_handler::DoDelete() {
|
|
||||||
auto uuid = GetBinding("uuid","");
|
|
||||||
if(uuid.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
OpContactDB::RecordName Existing;
|
|
||||||
if(!DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
// see if anyone is still using this thing
|
|
||||||
if(!Existing.subscriberDeviceId.empty()){
|
|
||||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
|
||||||
}
|
|
||||||
|
|
||||||
DB_.DeleteRecord("id", uuid);
|
|
||||||
return OK();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_op_contact_handler::DoPost() {
|
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
OpContactDB::RecordName NewObject;
|
|
||||||
if(!NewObject.from_json(RawObject)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !ValidDbId(NewObject.operatorId,StorageService()->OperatorDB(), false, RESTAPI::Errors::InvalidOperatorId, *this ) ||
|
|
||||||
!ValidDbId(NewObject.managementPolicy,StorageService()->PolicyDB(), true, RESTAPI::Errors::UnknownManagementPolicyUUID, *this ) ||
|
|
||||||
!ValidDbId(NewObject.subscriberDeviceId,StorageService()->SubscriberDeviceDB(), true, RESTAPI::Errors::InvalidSubscriberDeviceId, *this ) ||
|
|
||||||
!ValidContactType(NewObject.type,*this) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info);
|
|
||||||
return ReturnCreatedObject(DB_,NewObject,*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_op_contact_handler::DoPut() {
|
|
||||||
auto uuid = GetBinding("uuid");
|
|
||||||
OpContactDB::RecordName Existing;
|
|
||||||
if(uuid.empty() || !DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
OpContactDB::RecordName UpdateObj;
|
|
||||||
if(!UpdateObj.from_json(RawObject)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !ValidContactType(UpdateObj.type,*this) ||
|
|
||||||
!ValidDbId(UpdateObj.managementPolicy,StorageService()->PolicyDB(), true, RESTAPI::Errors::UnknownManagementPolicyUUID, *this ) ||
|
|
||||||
!ValidDbId(UpdateObj.subscriberDeviceId,StorageService()->SubscriberDeviceDB(), true, RESTAPI::Errors::InvalidSubscriberDeviceId, *this )
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info);
|
|
||||||
AssignIfPresent(RawObject,"type",Existing.type);
|
|
||||||
AssignIfPresent(RawObject,"title",Existing.title);
|
|
||||||
AssignIfPresent(RawObject,"salutation",Existing.salutation);
|
|
||||||
AssignIfPresent(RawObject,"firstname",Existing.firstname);
|
|
||||||
AssignIfPresent(RawObject,"lastname",Existing.lastname);
|
|
||||||
AssignIfPresent(RawObject,"initials",Existing.initials);
|
|
||||||
AssignIfPresent(RawObject,"visual",Existing.visual);
|
|
||||||
AssignIfPresent(RawObject,"mobiles",Existing.mobiles);
|
|
||||||
AssignIfPresent(RawObject,"phones",Existing.phones);
|
|
||||||
AssignIfPresent(RawObject,"accessPIN",Existing.accessPIN);
|
|
||||||
AssignIfPresent(RawObject,"secondaryEmail",Existing.secondaryEmail);
|
|
||||||
AssignIfPresent(RawObject,"primaryEmail",Existing.primaryEmail);
|
|
||||||
AssignIfPresent(RawObject,"subscriberDeviceId",Existing.subscriberDeviceId);
|
|
||||||
AssignIfPresent(RawObject,"managementPolicy",Existing.managementPolicy);
|
|
||||||
|
|
||||||
return ReturnUpdatedObject(DB_,Existing,*this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-07.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
class RESTAPI_op_contact_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_op_contact_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal){}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/operatorContact/{uuid}"}; };
|
|
||||||
private:
|
|
||||||
OpContactDB &DB_=StorageService()->OpContactDB();
|
|
||||||
void DoGet() final ;
|
|
||||||
void DoPost() final ;
|
|
||||||
void DoPut() final ;
|
|
||||||
void DoDelete() final ;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-07.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_op_contact_list_handler.h"
|
|
||||||
#include "RESTAPI_db_helpers.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
void RESTAPI_op_contact_list_handler::DoGet() {
|
|
||||||
auto operatorId= GetParameter("operatorId");
|
|
||||||
|
|
||||||
if(operatorId.empty() || !StorageService()->OperatorDB().Exists("id",operatorId)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::OperatorIdMustExist);
|
|
||||||
}
|
|
||||||
return ListHandlerForOperator<OpContactDB>("contacts", DB_, *this,operatorId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-07.
|
|
||||||
//
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
class RESTAPI_op_contact_list_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_op_contact_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal) {
|
|
||||||
}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/operatorContact"}; };
|
|
||||||
private:
|
|
||||||
OpContactDB &DB_=StorageService()->OpContactDB();
|
|
||||||
void DoGet() final;
|
|
||||||
void DoPost() final {};
|
|
||||||
void DoPut() final {};
|
|
||||||
void DoDelete() final {};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-07.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_op_location_handler.h"
|
|
||||||
#include "sdks/SDK_sec.h"
|
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
void RESTAPI_op_location_handler::DoGet() {
|
|
||||||
auto uuid = GetBinding("uuid","");
|
|
||||||
if(uuid.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
OpLocationDB::RecordName Existing;
|
|
||||||
if(!DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
Existing.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_op_location_handler::DoDelete() {
|
|
||||||
auto uuid = GetBinding("uuid","");
|
|
||||||
if(uuid.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
OpLocationDB::RecordName Existing;
|
|
||||||
if(!DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
// see if anyone is still using this thing
|
|
||||||
if(!Existing.subscriberDeviceId.empty()){
|
|
||||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
|
||||||
}
|
|
||||||
DB_.DeleteRecord("id", uuid);
|
|
||||||
return OK();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_op_location_handler::DoPost() {
|
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
OpLocationDB::RecordName NewObject;
|
|
||||||
if(!NewObject.from_json(RawObject)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !ValidDbId(NewObject.operatorId,StorageService()->OperatorDB(), false, RESTAPI::Errors::InvalidOperatorId, *this ) ||
|
|
||||||
!ValidDbId(NewObject.managementPolicy,StorageService()->PolicyDB(), true, RESTAPI::Errors::UnknownManagementPolicyUUID, *this ) ||
|
|
||||||
!ValidDbId(NewObject.subscriberDeviceId,StorageService()->SubscriberDeviceDB(), true, RESTAPI::Errors::InvalidSubscriberDeviceId, *this ) ||
|
|
||||||
!ValidLocationType(NewObject.type,*this)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info);
|
|
||||||
return ReturnCreatedObject(DB_, NewObject, *this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_op_location_handler::DoPut() {
|
|
||||||
auto uuid = GetBinding("uuid");
|
|
||||||
OpLocationDB::RecordName Existing;
|
|
||||||
if(uuid.empty() || !DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto RawObject = ParsedBody_;
|
|
||||||
OpLocationDB::RecordName UpdateObj;
|
|
||||||
if(!UpdateObj.from_json(RawObject)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !ValidLocationType(UpdateObj.type,*this) ||
|
|
||||||
!ValidDbId(UpdateObj.managementPolicy,StorageService()->PolicyDB(), true, RESTAPI::Errors::UnknownManagementPolicyUUID, *this ) ||
|
|
||||||
!ValidDbId(UpdateObj.subscriberDeviceId,StorageService()->SubscriberDeviceDB(), true, RESTAPI::Errors::InvalidSubscriberDeviceId, *this )
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info);
|
|
||||||
AssignIfPresent(RawObject,"type",Existing.type);
|
|
||||||
AssignIfPresent(RawObject,"subscriberDeviceId", Existing.subscriberDeviceId);
|
|
||||||
AssignIfPresent(RawObject,"managementPolicy", Existing.managementPolicy);
|
|
||||||
AssignIfPresent(RawObject,"buildingName",Existing.buildingName);
|
|
||||||
AssignIfPresent(RawObject,"addressLines",Existing.addressLines);
|
|
||||||
AssignIfPresent(RawObject,"city",Existing.city);
|
|
||||||
AssignIfPresent(RawObject,"state",Existing.state);
|
|
||||||
AssignIfPresent(RawObject,"postal",Existing.postal);
|
|
||||||
AssignIfPresent(RawObject,"country",Existing.country);
|
|
||||||
AssignIfPresent(RawObject,"mobiles",Existing.mobiles);
|
|
||||||
AssignIfPresent(RawObject,"phones",Existing.phones);
|
|
||||||
AssignIfPresent(RawObject,"geoCode",Existing.geoCode);
|
|
||||||
|
|
||||||
return ReturnUpdatedObject(DB_,Existing,*this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-07.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
class RESTAPI_op_location_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_op_location_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal){}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/operatorLocation/{uuid}"}; };
|
|
||||||
private:
|
|
||||||
OpLocationDB &DB_=StorageService()->OpLocationDB();
|
|
||||||
void DoGet() final ;
|
|
||||||
void DoPost() final ;
|
|
||||||
void DoPut() final ;
|
|
||||||
void DoDelete() final ;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-07.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_op_location_list_handler.h"
|
|
||||||
#include "RESTAPI_db_helpers.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
void RESTAPI_op_location_list_handler::DoGet() {
|
|
||||||
auto operatorId= GetParameter("operatorId");
|
|
||||||
|
|
||||||
if(operatorId.empty() || !StorageService()->OperatorDB().Exists("id",operatorId)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::OperatorIdMustExist);
|
|
||||||
}
|
|
||||||
return ListHandlerForOperator<OpLocationDB>("locations", DB_, *this,operatorId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-07.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
class RESTAPI_op_location_list_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_op_location_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal) {
|
|
||||||
}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/operatorLocation"}; };
|
|
||||||
private:
|
|
||||||
OpLocationDB &DB_=StorageService()->OpLocationDB();
|
|
||||||
void DoGet() final;
|
|
||||||
void DoPost() final {};
|
|
||||||
void DoPut() final {};
|
|
||||||
void DoDelete() final {};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-06.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_operators_handler.h"
|
|
||||||
#include "RESTAPI_db_helpers.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
void RESTAPI_operators_handler::DoGet() {
|
|
||||||
auto uuid = GetBinding("uuid","");
|
|
||||||
if(uuid.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
OperatorDB::RecordName Existing;
|
|
||||||
if(!DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
Existing.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_operators_handler::DoDelete() {
|
|
||||||
auto uuid = GetBinding("uuid","");
|
|
||||||
if(uuid.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
OperatorDB::RecordName Existing;
|
|
||||||
if(!DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Existing.defaultOperator) {
|
|
||||||
return BadRequest(RESTAPI::Errors::CannotDeleteDefaultOperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let's see if there are any subscribers in this operator
|
|
||||||
auto Count = StorageService()->SubscriberDeviceDB().Count(fmt::format(" operatorId='{}'", uuid));
|
|
||||||
if(Count>0) {
|
|
||||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
|
||||||
}
|
|
||||||
|
|
||||||
DB_.DeleteRecord("id",uuid);
|
|
||||||
StorageService()->ServiceClassDB().DeleteRecords(fmt::format(" operatorId='{}'", uuid));
|
|
||||||
return OK();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_operators_handler::DoPost() {
|
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
ProvObjects::Operator NewObject;
|
|
||||||
if(!NewObject.from_json(RawObject)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NewObject.defaultOperator) {
|
|
||||||
return BadRequest(RESTAPI::Errors::CannotCreateDefaultOperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
if((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules,*this))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RawObject->has("managementPolicy") && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!ValidSourceIP(NewObject.sourceIP)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidIPAddresses);
|
|
||||||
}
|
|
||||||
|
|
||||||
Poco::toLowerInPlace(NewObject.registrationId);
|
|
||||||
if(NewObject.registrationId.empty() || DB_.Exists("registrationId",NewObject.registrationId)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidRegistrationOperatorName);
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info);
|
|
||||||
if(DB_.CreateRecord(NewObject)) {
|
|
||||||
|
|
||||||
// Create the default service...
|
|
||||||
ProvObjects::ServiceClass DefSer;
|
|
||||||
DefSer.info.id = MicroService::CreateUUID();
|
|
||||||
DefSer.info.name = "Default Service Class";
|
|
||||||
DefSer.defaultService = true;
|
|
||||||
DefSer.info.created = DefSer.info.modified = OpenWifi::Now();
|
|
||||||
DefSer.operatorId = NewObject.info.id;
|
|
||||||
DefSer.period = "monthly";
|
|
||||||
DefSer.billingCode = "basic";
|
|
||||||
DefSer.currency = "USD";
|
|
||||||
StorageService()->ServiceClassDB().CreateRecord(DefSer);
|
|
||||||
|
|
||||||
ProvObjects::Operator New;
|
|
||||||
DB_.GetRecord("id",NewObject.info.id,New);
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
New.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
return InternalError(RESTAPI::Errors::RecordNotCreated);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_operators_handler::DoPut() {
|
|
||||||
auto uuid = GetBinding("uuid","");
|
|
||||||
if(uuid.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::Operator Existing;
|
|
||||||
if(!DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
ProvObjects::Operator UpdatedObj;
|
|
||||||
if(!UpdatedObj.from_json(RawObject)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
if((RawObject->has("deviceRules") && !ValidDeviceRules(UpdatedObj.deviceRules,*this))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RawObject->has("managementPolicy")) {
|
|
||||||
if(!StorageService()->PolicyDB().Exists("id",UpdatedObj.managementPolicy)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
|
||||||
}
|
|
||||||
Existing.managementPolicy = UpdatedObj.managementPolicy;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info);
|
|
||||||
|
|
||||||
if(RawObject->has("variables")) {
|
|
||||||
Existing.variables = UpdatedObj.variables;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RawObject->has("sourceIP")) {
|
|
||||||
if(!UpdatedObj.sourceIP.empty() && !ValidSourceIP(UpdatedObj.sourceIP)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidIPAddresses);
|
|
||||||
}
|
|
||||||
Existing.sourceIP = UpdatedObj.sourceIP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RawObject->has("deviceRules"))
|
|
||||||
Existing.deviceRules = UpdatedObj.deviceRules;
|
|
||||||
|
|
||||||
return ReturnUpdatedObject(DB_, Existing, *this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-06.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
class RESTAPI_operators_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_operators_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal){}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/operator/{uuid}"}; };
|
|
||||||
private:
|
|
||||||
OperatorDB &DB_=StorageService()->OperatorDB();
|
|
||||||
void DoGet() final ;
|
|
||||||
void DoPost() final ;
|
|
||||||
void DoPut() final ;
|
|
||||||
void DoDelete() final ;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-06.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_operators_list_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
void RESTAPI_operators_list_handler::DoGet() {
|
|
||||||
|
|
||||||
if(QB_.CountOnly) {
|
|
||||||
auto Count = DB_.Count();
|
|
||||||
return ReturnCountOnly(Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!QB_.Select.empty()) {
|
|
||||||
return ReturnRecordList<decltype(DB_), ProvObjects::Operator>("operators", DB_, *this);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ProvObjects::Operator> Entries;
|
|
||||||
DB_.GetRecords(QB_.Offset,QB_.Limit,Entries);
|
|
||||||
return MakeJSONObjectArray("operators", Entries, *this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-06.
|
|
||||||
//
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
class RESTAPI_operators_list_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_operators_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal) {
|
|
||||||
}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/operator"}; };
|
|
||||||
private:
|
|
||||||
OperatorDB &DB_=StorageService()->OperatorDB();
|
|
||||||
void DoGet() final;
|
|
||||||
void DoPost() final {};
|
|
||||||
void DoPut() final {};
|
|
||||||
void DoDelete() final {};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -15,32 +15,18 @@
|
|||||||
#include "RESTAPI/RESTAPI_entity_list_handler.h"
|
#include "RESTAPI/RESTAPI_entity_list_handler.h"
|
||||||
#include "RESTAPI/RESTAPI_configurations_handler.h"
|
#include "RESTAPI/RESTAPI_configurations_handler.h"
|
||||||
#include "RESTAPI/RESTAPI_configurations_list_handler.h"
|
#include "RESTAPI/RESTAPI_configurations_list_handler.h"
|
||||||
|
#include "RESTAPI/RESTAPI_webSocketServer.h"
|
||||||
#include "RESTAPI/RESTAPI_contact_list_handler.h"
|
#include "RESTAPI/RESTAPI_contact_list_handler.h"
|
||||||
#include "RESTAPI/RESTAPI_location_list_handler.h"
|
#include "RESTAPI/RESTAPI_location_list_handler.h"
|
||||||
#include "RESTAPI/RESTAPI_venue_list_handler.h"
|
#include "RESTAPI/RESTAPI_venue_list_handler.h"
|
||||||
#include "RESTAPI/RESTAPI_managementRole_list_handler.h"
|
#include "RESTAPI/RESTAPI_managementRole_list_handler.h"
|
||||||
#include "RESTAPI/RESTAPI_map_handler.h"
|
#include "RESTAPI/RESTAPI_map_handler.h"
|
||||||
#include "RESTAPI/RESTAPI_map_list_handler.h"
|
#include "RESTAPI/RESTAPI_map_list_handler.h"
|
||||||
#include "RESTAPI/RESTAPI_iptocountry_handler.h"
|
#include "RESTAPI_iptocountry_handler.h"
|
||||||
#include "RESTAPI/RESTAPI_signup_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_variables_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_variables_list_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_asset_server.h"
|
|
||||||
#include "RESTAPI/RESTAPI_service_class_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_service_class_list_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_operators_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_operators_list_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_sub_devices_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_sub_devices_list_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_op_contact_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_op_contact_list_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_op_location_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_op_location_list_handler.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const std::string &Path, RESTAPIHandler::BindingMap &Bindings,
|
Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings,
|
||||||
Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) {
|
Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) {
|
||||||
return RESTAPI_Router<
|
return RESTAPI_Router<
|
||||||
RESTAPI_system_command,
|
RESTAPI_system_command,
|
||||||
@@ -62,60 +48,18 @@ namespace OpenWifi {
|
|||||||
RESTAPI_map_handler,
|
RESTAPI_map_handler,
|
||||||
RESTAPI_map_list_handler,
|
RESTAPI_map_list_handler,
|
||||||
RESTAPI_webSocketServer,
|
RESTAPI_webSocketServer,
|
||||||
RESTAPI_iptocountry_handler,
|
RESTAPI_iptocountry_handler
|
||||||
RESTAPI_signup_handler,
|
|
||||||
RESTAPI_variables_handler,
|
|
||||||
RESTAPI_variables_list_handler,
|
|
||||||
RESTAPI_sub_devices_handler,
|
|
||||||
RESTAPI_sub_devices_list_handler,
|
|
||||||
RESTAPI_operators_handler,
|
|
||||||
RESTAPI_operators_list_handler,
|
|
||||||
RESTAPI_service_class_handler,
|
|
||||||
RESTAPI_service_class_list_handler,
|
|
||||||
RESTAPI_op_contact_handler,
|
|
||||||
RESTAPI_op_contact_list_handler,
|
|
||||||
RESTAPI_op_location_handler,
|
|
||||||
RESTAPI_op_location_list_handler,
|
|
||||||
RESTAPI_asset_server
|
|
||||||
>(Path,Bindings,L, S, TransactionId);
|
>(Path,Bindings,L, S, TransactionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Poco::Net::HTTPRequestHandler * RESTAPI_IntRouter(const std::string &Path, RESTAPIHandler::BindingMap &Bindings,
|
Poco::Net::HTTPRequestHandler * RESTAPI_IntRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings,
|
||||||
Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) {
|
Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) {
|
||||||
return RESTAPI_Router_I<
|
return RESTAPI_Router_I<
|
||||||
RESTAPI_system_command,
|
RESTAPI_system_command ,
|
||||||
RESTAPI_entity_handler,
|
|
||||||
RESTAPI_entity_list_handler,
|
|
||||||
RESTAPI_contact_handler,
|
|
||||||
RESTAPI_contact_list_handler,
|
|
||||||
RESTAPI_location_handler,
|
|
||||||
RESTAPI_location_list_handler,
|
|
||||||
RESTAPI_venue_handler,
|
|
||||||
RESTAPI_venue_list_handler,
|
|
||||||
RESTAPI_inventory_handler,
|
RESTAPI_inventory_handler,
|
||||||
RESTAPI_inventory_list_handler,
|
|
||||||
RESTAPI_managementPolicy_handler,
|
|
||||||
RESTAPI_managementPolicy_list_handler,
|
|
||||||
RESTAPI_managementRole_list_handler,
|
|
||||||
RESTAPI_configurations_handler,
|
RESTAPI_configurations_handler,
|
||||||
RESTAPI_configurations_list_handler,
|
RESTAPI_configurations_list_handler,
|
||||||
RESTAPI_map_handler,
|
RESTAPI_iptocountry_handler
|
||||||
RESTAPI_map_list_handler,
|
>(Path, Bindings, L, S, TransactionId);
|
||||||
RESTAPI_webSocketServer,
|
|
||||||
RESTAPI_iptocountry_handler,
|
|
||||||
RESTAPI_signup_handler,
|
|
||||||
RESTAPI_variables_handler,
|
|
||||||
RESTAPI_variables_list_handler,
|
|
||||||
RESTAPI_sub_devices_handler,
|
|
||||||
RESTAPI_sub_devices_list_handler,
|
|
||||||
RESTAPI_operators_handler,
|
|
||||||
RESTAPI_operators_list_handler,
|
|
||||||
RESTAPI_service_class_handler,
|
|
||||||
RESTAPI_service_class_list_handler,
|
|
||||||
RESTAPI_op_contact_handler,
|
|
||||||
RESTAPI_op_contact_list_handler,
|
|
||||||
RESTAPI_op_location_handler,
|
|
||||||
RESTAPI_op_location_list_handler
|
|
||||||
>(Path, Bindings, L, S, TransactionId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-06.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_service_class_handler.h"
|
|
||||||
#include "RESTAPI_db_helpers.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
void RESTAPI_service_class_handler::DoGet() {
|
|
||||||
auto uuid = GetBinding("uuid","");
|
|
||||||
if(uuid.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
ServiceClassDB::RecordName Existing;
|
|
||||||
if(!DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
Existing.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_service_class_handler::DoDelete() {
|
|
||||||
auto uuid = GetBinding("uuid","");
|
|
||||||
if(uuid.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
ServiceClassDB::RecordName Existing;
|
|
||||||
if(!DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
// see if anyone is still using this thing
|
|
||||||
auto Count = StorageService()->SubscriberDeviceDB().Count( fmt::format(" serviceClass='{}' ", uuid));
|
|
||||||
if(Count>0) {
|
|
||||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
|
||||||
}
|
|
||||||
DB_.DeleteRecord("id", uuid);
|
|
||||||
return OK();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_service_class_handler::DoPost() {
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
ProvObjects::ServiceClass NewObject;
|
|
||||||
if(!NewObject.from_json(RawObject)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NewObject.operatorId.empty() || !StorageService()->OperatorDB().Exists("id",NewObject.operatorId)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info);
|
|
||||||
|
|
||||||
if(RawObject->has("managementPolicy") && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NewObject.billingCode.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidBillingCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DefaultCount = DB_.Count( fmt::format(" defaultService=true and operatorId='{}' ", NewObject.operatorId));
|
|
||||||
if(DefaultCount==0)
|
|
||||||
NewObject.defaultService=true;
|
|
||||||
else
|
|
||||||
NewObject.defaultService=false;
|
|
||||||
|
|
||||||
if(NewObject.period.empty())
|
|
||||||
NewObject.period = "monthly";
|
|
||||||
|
|
||||||
if(!ValidPeriod(NewObject.period)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidBillingPeriod);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ReturnCreatedObject(DB_, NewObject, *this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_service_class_handler::DoPut() {
|
|
||||||
auto uuid = GetBinding("uuid","");
|
|
||||||
|
|
||||||
ProvObjects::ServiceClass Existing;
|
|
||||||
if(uuid.empty() || !DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
ProvObjects::ServiceClass UpdateObj;
|
|
||||||
if(!UpdateObj.from_json(RawObject)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RawObject->has("managementPolicy") && !StorageService()->PolicyDB().Exists("id",UpdateObj.managementPolicy)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info);
|
|
||||||
AssignIfPresent(RawObject,"cost",Existing.cost);
|
|
||||||
AssignIfPresent(RawObject,"currency",Existing.currency);
|
|
||||||
if(RawObject->has("billingCode") && UpdateObj.billingCode.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidBillingCode);
|
|
||||||
}
|
|
||||||
AssignIfPresent(RawObject,"billingCode",Existing.billingCode);
|
|
||||||
|
|
||||||
if(RawObject->has("variables")) {
|
|
||||||
Existing.variables = UpdateObj.variables;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ReturnUpdatedObject(DB_, Existing, *this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-06.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
class RESTAPI_service_class_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_service_class_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal){}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/serviceClass/{uuid}"}; };
|
|
||||||
private:
|
|
||||||
ServiceClassDB &DB_=StorageService()->ServiceClassDB();
|
|
||||||
void DoGet() final ;
|
|
||||||
void DoPost() final ;
|
|
||||||
void DoPut() final ;
|
|
||||||
void DoDelete() final ;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-06.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_service_class_list_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
void RESTAPI_service_class_list_handler::DoGet() {
|
|
||||||
auto operatorId= GetParameter("operatorId");
|
|
||||||
|
|
||||||
if(operatorId.empty() || !StorageService()->OperatorDB().Exists("id",operatorId)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::OperatorIdMustExist);
|
|
||||||
}
|
|
||||||
return ListHandlerForOperator<ServiceClassDB>("serviceClasses", DB_, *this,operatorId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-06.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
class RESTAPI_service_class_list_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_service_class_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal) {
|
|
||||||
}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/serviceClass"}; };
|
|
||||||
private:
|
|
||||||
ServiceClassDB &DB_=StorageService()->ServiceClassDB();
|
|
||||||
void DoGet() final;
|
|
||||||
void DoPost() final {};
|
|
||||||
void DoPut() final {};
|
|
||||||
void DoDelete() final {};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,257 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-02-20.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_signup_handler.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
#include "Signup.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
void RESTAPI_signup_handler::DoPost() {
|
|
||||||
auto UserName = GetParameter("email");
|
|
||||||
Poco::toLowerInPlace(UserName);
|
|
||||||
Poco::trimInPlace(UserName);
|
|
||||||
|
|
||||||
auto macAddress = GetParameter("macAddress");
|
|
||||||
Poco::toLowerInPlace(macAddress);
|
|
||||||
Poco::trimInPlace(macAddress);
|
|
||||||
|
|
||||||
auto deviceID = GetParameter("deviceID");
|
|
||||||
Poco::toLowerInPlace(deviceID);
|
|
||||||
Poco::trimInPlace(deviceID);
|
|
||||||
|
|
||||||
auto registrationId = GetParameter("registrationId");
|
|
||||||
Poco::toLowerInPlace(registrationId);
|
|
||||||
Poco::trimInPlace(registrationId);
|
|
||||||
|
|
||||||
if(UserName.empty() || macAddress.empty() || registrationId.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!Utils::ValidEMailAddress(UserName)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidEmailAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!Utils::ValidSerialNumber(macAddress)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidSerialNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(registrationId.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidRegistrationOperatorName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// find the operator id
|
|
||||||
ProvObjects::Operator SignupOperator;
|
|
||||||
if(!StorageService()->OperatorDB().GetRecord("registrationId", registrationId, SignupOperator)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidRegistrationOperatorName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if a signup already exists for this user, we should just return its value completion
|
|
||||||
SignupDB::RecordVec SEs;
|
|
||||||
if(StorageService()->SignupDB().GetRecords(0,100, SEs, " email='" + UserName + "' and serialNumber='"+macAddress+"' ")) {
|
|
||||||
for(const auto &i:SEs) {
|
|
||||||
|
|
||||||
if(!i.deviceID.empty() && i.deviceID!=deviceID) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidDeviceID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i.statusCode == ProvObjects::SignupStatusCodes::SignupWaitingForEmail ||
|
|
||||||
i.statusCode == ProvObjects::SignupStatusCodes::SignupWaitingForDevice ||
|
|
||||||
i.statusCode == ProvObjects::SignupStatusCodes::SignupSuccess ) {
|
|
||||||
Logger().information(fmt::format("SIGNUP: Returning existing signup record for '{}'",i.email));
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
i.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// So we do not have an outstanding signup...
|
|
||||||
// Can we actually claim this serial number??? if not, we need to return an error
|
|
||||||
ProvObjects::InventoryTag IT;
|
|
||||||
std::string SerialNumber;
|
|
||||||
bool FoundIT=false;
|
|
||||||
for(int Index=0;Index<4;Index++) {
|
|
||||||
auto TrySerialNumber = Utils::SerialNumberToInt(macAddress);
|
|
||||||
for (uint i = 0; i < 4; ++i) {
|
|
||||||
SerialNumber = Utils::IntToSerialNumber(TrySerialNumber + i);
|
|
||||||
if (StorageService()->InventoryDB().GetRecord("serialNumber", SerialNumber, IT)) {
|
|
||||||
if (!IT.subscriber.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::SerialNumberAlreadyProvisioned);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(IT.devClass.empty() || IT.devClass == "subscriber" || IT.devClass == "any")) {
|
|
||||||
return BadRequest(RESTAPI::Errors::SerialNumberNotTheProperClass);
|
|
||||||
}
|
|
||||||
FoundIT = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// OK, we can claim this device, can we create a userid?
|
|
||||||
// Let's create one
|
|
||||||
// If sec.signup("email",uuid);
|
|
||||||
auto SignupUUID = MicroService::instance().CreateUUID();
|
|
||||||
Logger().information(fmt::format("SIGNUP: Creating signup entry for '{}', uuid='{}'",UserName, SignupUUID));
|
|
||||||
|
|
||||||
Poco::JSON::Object Body;
|
|
||||||
OpenAPIRequestPost CreateUser( uSERVICE_SECURITY, "/api/v1/signup", {
|
|
||||||
{ "email", UserName },
|
|
||||||
{ "signupUUID" , SignupUUID },
|
|
||||||
{ "owner" , SignupOperator.info.id },
|
|
||||||
|
|
||||||
}, Body, 30000);
|
|
||||||
|
|
||||||
Poco::JSON::Object::Ptr Answer;
|
|
||||||
if(CreateUser.Do(Answer) == Poco::Net::HTTPServerResponse::HTTP_OK) {
|
|
||||||
SecurityObjects::UserInfo UI;
|
|
||||||
|
|
||||||
UI.from_json(Answer);
|
|
||||||
std::ostringstream os;
|
|
||||||
Answer->stringify(os);
|
|
||||||
Logger().information(fmt::format("SIGNUP: email: '{}' signupID: '{}' userId: '{}'", UserName, SignupUUID, UI.id));
|
|
||||||
|
|
||||||
// so create the Signup entry and modify the inventory
|
|
||||||
ProvObjects::SignupEntry SE;
|
|
||||||
SE.info.id = SignupUUID;
|
|
||||||
SE.info.created = SE.info.modified = SE.submitted = OpenWifi::Now();
|
|
||||||
SE.completed = 0 ;
|
|
||||||
SE.macAddress = macAddress;
|
|
||||||
SE.error = 0 ;
|
|
||||||
SE.userId = UI.id;
|
|
||||||
SE.email = UserName;
|
|
||||||
SE.deviceID = deviceID;
|
|
||||||
SE.registrationId = registrationId;
|
|
||||||
SE.status = "waiting-for-email-verification";
|
|
||||||
SE.operatorId = SignupOperator.info.id;
|
|
||||||
SE.statusCode = ProvObjects::SignupStatusCodes::SignupWaitingForEmail;
|
|
||||||
StorageService()->SignupDB().CreateRecord(SE);
|
|
||||||
Signup()->AddOutstandingSignup(SE);
|
|
||||||
|
|
||||||
if(FoundIT) {
|
|
||||||
Poco::JSON::Object StateDoc;
|
|
||||||
StateDoc.set("method", "signup");
|
|
||||||
StateDoc.set("claimer", UserName);
|
|
||||||
StateDoc.set("claimerId", UI.id);
|
|
||||||
StateDoc.set("signupUUID", SignupUUID);
|
|
||||||
StateDoc.set("errorCode",0);
|
|
||||||
StateDoc.set("date", OpenWifi::Now());
|
|
||||||
StateDoc.set("status", "waiting for email-verification");
|
|
||||||
std::ostringstream os2;
|
|
||||||
StateDoc.stringify(os2);
|
|
||||||
IT.realMacAddress = macAddress;
|
|
||||||
IT.state = os2.str();
|
|
||||||
IT.info.modified = OpenWifi::Now();
|
|
||||||
std::cout << "Updating inventory entry: " << SE.macAddress << std::endl;
|
|
||||||
StorageService()->InventoryDB().UpdateRecord("id",IT.info.id,IT);
|
|
||||||
}
|
|
||||||
|
|
||||||
Poco::JSON::Object SEAnswer;
|
|
||||||
SE.to_json(SEAnswer);
|
|
||||||
return ReturnObject(SEAnswer);
|
|
||||||
}
|
|
||||||
return BadRequest(RESTAPI::Errors::UserAlreadyExists);
|
|
||||||
}
|
|
||||||
|
|
||||||
// this will be called by the SEC backend once the password has been verified.
|
|
||||||
void RESTAPI_signup_handler::DoPut() {
|
|
||||||
auto SignupUUID = GetParameter("signupUUID");
|
|
||||||
auto Operation = GetParameter("operation");
|
|
||||||
|
|
||||||
Logger().information(fmt::format("signup-progress: {} - {} ", SignupUUID, Operation));
|
|
||||||
if(SignupUUID.empty() || Operation.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::SignupEntry SE;
|
|
||||||
Logger().information(fmt::format("signup-progress: {} - {} fetching entry", SignupUUID, Operation));
|
|
||||||
if(!StorageService()->SignupDB().GetRecord("id",SignupUUID,SE)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger().information(fmt::format("signup-progress: {} - {} fetching entry", SignupUUID, Operation));
|
|
||||||
if(Operation == "emailVerified" && SE.statusCode==ProvObjects::SignupStatusCodes::SignupWaitingForEmail) {
|
|
||||||
Logger().information(fmt::format("{}: email {} verified.",SE.info.id, SE.email));
|
|
||||||
std::cout << "Verified email for : " << SE.email << std::endl;
|
|
||||||
SE.info.modified = OpenWifi::Now();
|
|
||||||
SE.status = "emailVerified";
|
|
||||||
SE.statusCode = ProvObjects::SignupStatusCodes::SignupWaitingForDevice;
|
|
||||||
StorageService()->SignupDB().UpdateRecord("id", SE.info.id, SE);
|
|
||||||
Signup()->AddOutstandingSignup(SE);
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
SE.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
Logger().information(fmt::format("signup-progress: {} - {} something is bad", SignupUUID, Operation));
|
|
||||||
|
|
||||||
return BadRequest(RESTAPI::Errors::UnknownId);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_signup_handler::DoGet() {
|
|
||||||
auto EMail = GetParameter("email");
|
|
||||||
auto SignupUUID = GetParameter("signupUUID");
|
|
||||||
auto macAddress = GetParameter("macAddress");
|
|
||||||
auto List = GetBoolParameter("listOnly",false);
|
|
||||||
|
|
||||||
Logger().information(fmt::format("Looking for signup for {}",EMail));
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
ProvObjects::SignupEntry SE;
|
|
||||||
if(!SignupUUID.empty()) {
|
|
||||||
Logger().information(fmt::format("Looking for signup for {}: Signup {}",EMail, SignupUUID));
|
|
||||||
if(StorageService()->SignupDB().GetRecord("id", SignupUUID, SE)) {
|
|
||||||
SE.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
return NotFound();
|
|
||||||
} else if(!EMail.empty()) {
|
|
||||||
SignupDB::RecordVec SEs;
|
|
||||||
Logger().information(fmt::format("Looking for signup for {}: Signup {}",EMail, SignupUUID));
|
|
||||||
if(StorageService()->SignupDB().GetRecords(0,100,SEs, " email='"+EMail+"' ")) {
|
|
||||||
return ReturnObject("signups",SEs);
|
|
||||||
}
|
|
||||||
return NotFound();
|
|
||||||
} else if(!macAddress.empty()) {
|
|
||||||
SignupDB::RecordVec SEs;
|
|
||||||
Logger().information(fmt::format("Looking for signup for {}: Mac {}",EMail, macAddress));
|
|
||||||
if(StorageService()->SignupDB().GetRecords(0,100,SEs, " serialNumber='"+macAddress+"' ")) {
|
|
||||||
return ReturnObject("signups",SEs);
|
|
||||||
}
|
|
||||||
return NotFound();
|
|
||||||
} else if(List) {
|
|
||||||
Logger().information(fmt::format("Returning list of signups...",EMail, macAddress));
|
|
||||||
SignupDB::RecordVec SEs;
|
|
||||||
StorageService()->SignupDB().GetRecords(0,100,SEs);
|
|
||||||
return ReturnObject("signups",SEs);
|
|
||||||
}
|
|
||||||
Logger().information(fmt::format("Bad signup get",EMail, macAddress));
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_signup_handler::DoDelete() {
|
|
||||||
auto EMail = GetParameter("email", "");
|
|
||||||
auto SignupUUID = GetParameter("signupUUID", "");
|
|
||||||
auto macAddress = GetParameter("macAddress", "");
|
|
||||||
auto deviceID = GetParameter("deviceID","");
|
|
||||||
|
|
||||||
if(!SignupUUID.empty()) {
|
|
||||||
if(StorageService()->SignupDB().DeleteRecord("id", SignupUUID)) {
|
|
||||||
return OK();
|
|
||||||
}
|
|
||||||
return NotFound();
|
|
||||||
} else if(!EMail.empty()) {
|
|
||||||
if(StorageService()->SignupDB().DeleteRecord("email",EMail)) {
|
|
||||||
return OK();
|
|
||||||
}
|
|
||||||
return NotFound();
|
|
||||||
} else if(!macAddress.empty()) {
|
|
||||||
if(StorageService()->SignupDB().DeleteRecord("serialNumber", macAddress)) {
|
|
||||||
return OK();
|
|
||||||
}
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-02-20.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
class RESTAPI_signup_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_signup_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_POST,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_PUT,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_DELETE},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal, false, true ){}
|
|
||||||
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/signup"}; };
|
|
||||||
|
|
||||||
/* inline bool RoleIsAuthorized(std::string & Reason) {
|
|
||||||
if(UserInfo_.userinfo.userRole != SecurityObjects::USER_ROLE::SUBSCRIBER) {
|
|
||||||
Reason = "User must be a subscriber";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
void DoGet() final;
|
|
||||||
void DoPost() final;
|
|
||||||
void DoPut() final ;
|
|
||||||
void DoDelete() final;
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,144 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-06.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_sub_devices_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
|
||||||
#include "sdks/SDK_sec.h"
|
|
||||||
#include "sdks/SDK_gw.h"
|
|
||||||
#include "APConfig.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
void RESTAPI_sub_devices_handler::DoGet() {
|
|
||||||
auto uuid = GetBinding("uuid");
|
|
||||||
if(uuid.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::SubscriberDevice SD;
|
|
||||||
if(Utils::ValidUUID(uuid)) {
|
|
||||||
if (!DB_.GetRecord("id", uuid, SD)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
} else if(Utils::ValidSerialNumber(uuid)) {
|
|
||||||
if (!DB_.GetRecord("serialNumber", uuid, SD)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
SD.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_sub_devices_handler::DoDelete() {
|
|
||||||
auto uuid = GetBinding("uuid");
|
|
||||||
if(uuid.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!DB_.Exists("id",uuid)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
DB_.DeleteRecord("id",uuid);
|
|
||||||
return OK();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_sub_devices_handler::DoPost() {
|
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
SubscriberDeviceDB::RecordName NewObject;
|
|
||||||
if(!NewObject.from_json(RawObject)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !ValidDbId(NewObject.managementPolicy, StorageService()->PolicyDB(), true , RESTAPI::Errors::UnknownManagementPolicyUUID, *this) ||
|
|
||||||
!ValidDbId(NewObject.operatorId, StorageService()->OperatorDB(), true, RESTAPI::Errors::InvalidOperatorId, *this) ||
|
|
||||||
!ValidDbId(NewObject.serviceClass, StorageService()->ServiceClassDB(), true, RESTAPI::Errors::InvalidServiceClassId, *this) ||
|
|
||||||
!ValidSubscriberId(NewObject.subscriberId, true, *this) ||
|
|
||||||
(RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules,*this)) ||
|
|
||||||
!ValidSerialNumber(NewObject.serialNumber,false,*this)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::CreateObjectInfo(RawObject,UserInfo_.userinfo,NewObject.info);
|
|
||||||
return ReturnCreatedObject(DB_,NewObject,*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_sub_devices_handler::DoPut() {
|
|
||||||
auto uuid = GetBinding("uuid");
|
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
SubscriberDeviceDB::RecordName UpdateObj;
|
|
||||||
if(!UpdateObj.from_json(RawObject)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
SubscriberDeviceDB::RecordName Existing;
|
|
||||||
if(!DB_.GetRecord("id",uuid,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !ValidDbId(UpdateObj.managementPolicy, StorageService()->PolicyDB(), true , RESTAPI::Errors::UnknownManagementPolicyUUID, *this) ||
|
|
||||||
!ValidDbId(UpdateObj.operatorId, StorageService()->OperatorDB(), true, RESTAPI::Errors::InvalidOperatorId, *this) ||
|
|
||||||
!ValidDbId(UpdateObj.serviceClass, StorageService()->ServiceClassDB(), true, RESTAPI::Errors::InvalidServiceClassId, *this) ||
|
|
||||||
!ValidSubscriberId(UpdateObj.subscriberId, true, *this) ||
|
|
||||||
(RawObject->has("deviceRules") && !ValidDeviceRules(UpdateObj.deviceRules,*this)) ||
|
|
||||||
!ValidSerialNumber(UpdateObj.serialNumber,false,*this)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProvObjects::UpdateObjectInfo(RawObject,UserInfo_.userinfo,Existing.info);
|
|
||||||
AssignIfPresent(RawObject, "deviceType", Existing.deviceType);
|
|
||||||
AssignIfPresent(RawObject, "subscriberId", Existing.subscriberId);
|
|
||||||
AssignIfPresent(RawObject, "managementPolicy", Existing.managementPolicy);
|
|
||||||
AssignIfPresent(RawObject, "serviceClass", Existing.serviceClass);
|
|
||||||
AssignIfPresent(RawObject, "qrCode", Existing.qrCode);
|
|
||||||
AssignIfPresent(RawObject, "geoCode", Existing.geoCode);
|
|
||||||
if(RawObject->has("deviceRules"))
|
|
||||||
Existing.deviceRules = UpdateObj.deviceRules;
|
|
||||||
AssignIfPresent(RawObject, "state", Existing.state);
|
|
||||||
AssignIfPresent(RawObject, "locale", Existing.locale);
|
|
||||||
AssignIfPresent(RawObject, "billingCode", Existing.billingCode);
|
|
||||||
AssignIfPresent(RawObject, "realMacAddress", Existing.realMacAddress);
|
|
||||||
AssignIfPresent(RawObject, "contact", UpdateObj.contact, Existing.contact);
|
|
||||||
AssignIfPresent(RawObject, "location", UpdateObj.location, Existing.location);
|
|
||||||
|
|
||||||
if(RawObject->has("configuration")) {
|
|
||||||
Existing.configuration = UpdateObj.configuration;
|
|
||||||
}
|
|
||||||
StorageService()->SubscriberDeviceDB().UpdateRecord("id",uuid,Existing);
|
|
||||||
ApplyConfiguration(Existing.serialNumber);
|
|
||||||
return ReturnUpdatedObject(DB_,Existing,*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RESTAPI_sub_devices_handler::ApplyConfiguration(const std::string &SerialNumber) {
|
|
||||||
auto Device = std::make_shared<APConfig>(SerialNumber, Logger());
|
|
||||||
auto Configuration = Poco::makeShared<Poco::JSON::Object>();
|
|
||||||
Poco::JSON::Object ErrorsObj, WarningsObj;
|
|
||||||
Logger().debug(Poco::format("%s: Computing configuration.",SerialNumber));
|
|
||||||
if (Device->Get(Configuration)) {
|
|
||||||
std::ostringstream OS;
|
|
||||||
Configuration->stringify(OS);
|
|
||||||
auto Response=Poco::makeShared<Poco::JSON::Object>();
|
|
||||||
Logger().debug(Poco::format("%s: Sending configuration push.",SerialNumber));
|
|
||||||
if (SDK::GW::Device::Configure(this, SerialNumber, Configuration, Response)) {
|
|
||||||
Logger().debug(Poco::format("%s: Sending configuration pushed.",SerialNumber));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
Logger().debug(Poco::format("%s: Sending configuration failed.",SerialNumber));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Logger().debug(Poco::format("%s: Configuration is bad.",SerialNumber));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-06.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
class RESTAPI_sub_devices_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_sub_devices_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal){}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/subscriberDevice/{uuid}"}; };
|
|
||||||
bool ApplyConfiguration(const std::string &SerialNumber);
|
|
||||||
|
|
||||||
private:
|
|
||||||
SubscriberDeviceDB &DB_=StorageService()->SubscriberDeviceDB();
|
|
||||||
void DoGet() final ;
|
|
||||||
void DoPost() final ;
|
|
||||||
void DoPut() final ;
|
|
||||||
void DoDelete() final ;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-06.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_sub_devices_list_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
void RESTAPI_sub_devices_list_handler::DoGet() {
|
|
||||||
auto operatorId=GetParameter("operatorId");
|
|
||||||
auto subscriberId=GetParameter("subscriberId");
|
|
||||||
|
|
||||||
if(!operatorId.empty() && !StorageService()->OperatorDB().Exists("id",operatorId)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::OperatorIdMustExist);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ListHandlerForOperator<SubscriberDeviceDB>("subscriberDevices", DB_, *this, operatorId, subscriberId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-04-06.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
class RESTAPI_sub_devices_list_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_sub_devices_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal) {
|
|
||||||
}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/subscriberDevice"}; };
|
|
||||||
private:
|
|
||||||
SubscriberDeviceDB &DB_=StorageService()->SubscriberDeviceDB();
|
|
||||||
void DoGet() final;
|
|
||||||
void DoPost() final {};
|
|
||||||
void DoPut() final {};
|
|
||||||
void DoDelete() final {};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-02-23.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_variables_handler.h"
|
|
||||||
#include "RESTAPI_db_helpers.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
void RESTAPI_variables_handler::DoGet() {
|
|
||||||
auto UUID = GetBinding("uuid","");
|
|
||||||
if(UUID.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
VariablesDB::RecordName Existing;
|
|
||||||
if(!DB_.GetRecord("id",UUID,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
if(QB_.AdditionalInfo)
|
|
||||||
AddExtendedInfo(Existing, Answer);
|
|
||||||
Existing.to_json(Answer);
|
|
||||||
ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_variables_handler::DoDelete() {
|
|
||||||
auto UUID = GetBinding("uuid","");
|
|
||||||
if(UUID.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
VariablesDB::RecordName Existing;
|
|
||||||
if(!DB_.GetRecord("id",UUID,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!Existing.configurations.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
|
||||||
}
|
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
|
|
||||||
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::variables,Existing.venue,Existing.info.id);
|
|
||||||
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::variables,Existing.entity,Existing.info.id);
|
|
||||||
DB_.DeleteRecord("id", UUID);
|
|
||||||
|
|
||||||
return OK();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_variables_handler::DoPost() {
|
|
||||||
auto UUID = GetBinding("uuid","");
|
|
||||||
if(UUID.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto & RawObj = ParsedBody_;
|
|
||||||
VariablesDB::RecordName NewObject;
|
|
||||||
if(!NewObject.from_json(RawObj)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!NewObject.venue.empty() && !StorageService()->VenueDB().Exists("id",NewObject.venue)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!ProvObjects::CreateObjectInfo(RawObj,UserInfo_.userinfo,NewObject.info)) {
|
|
||||||
return BadRequest((RESTAPI::Errors::MissingOrInvalidParameters));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(DB_.CreateRecord(NewObject)) {
|
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
|
|
||||||
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::variables,NewObject.venue, NewObject.info.id);
|
|
||||||
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::variables,NewObject.entity, NewObject.info.id);
|
|
||||||
|
|
||||||
VariablesDB::RecordName Added;
|
|
||||||
DB_.GetRecord("id",NewObject.info.id,Added);
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
Added.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
return BadRequest(RESTAPI::Errors::RecordNotCreated);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_variables_handler::DoPut() {
|
|
||||||
auto UUID = GetBinding("uuid","");
|
|
||||||
if(UUID.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
VariablesDB::RecordName Existing;
|
|
||||||
if(!StorageService()->VariablesDB().GetRecord("id",UUID,Existing)) {
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
VariablesDB::RecordName NewObj;
|
|
||||||
if(!NewObj.from_json(RawObject)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!ProvObjects::UpdateObjectInfo(RawObject,UserInfo_.userinfo,Existing.info)) {
|
|
||||||
return BadRequest((RESTAPI::Errors::MissingOrInvalidParameters));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RawObject->has("variables"))
|
|
||||||
Existing.variables = NewObj.variables;
|
|
||||||
|
|
||||||
std::string FromPolicy, ToPolicy;
|
|
||||||
if(!CreateMove(RawObject,"managementPolicy",&VariablesDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
|
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
|
|
||||||
std::string FromEntity, ToEntity;
|
|
||||||
if(!CreateMove(RawObject,"entity",&VariablesDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
|
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
|
||||||
|
|
||||||
std::string FromVenue, ToVenue;
|
|
||||||
if(!CreateMove(RawObject,"venue",&VariablesDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB()))
|
|
||||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
|
||||||
|
|
||||||
if(DB_.UpdateRecord("id", UUID, Existing)) {
|
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id);
|
|
||||||
ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::variables, FromVenue, ToVenue, Existing.info.id);
|
|
||||||
ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::variables, FromEntity, ToEntity, Existing.info.id);
|
|
||||||
|
|
||||||
VariablesDB::RecordName Added;
|
|
||||||
DB_.GetRecord("id",NewObj.info.id,Added);
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
Added.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
return BadRequest(RESTAPI::Errors::RecordNotCreated);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-02-23.
|
|
||||||
//
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
class RESTAPI_variables_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_variables_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal){}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/variable/{uuid}"}; };
|
|
||||||
private:
|
|
||||||
VariablesDB & DB_=StorageService()->VariablesDB();
|
|
||||||
void DoGet() final ;
|
|
||||||
void DoPost() final ;
|
|
||||||
void DoPut() final ;
|
|
||||||
void DoDelete() final ;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-02-23.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_variables_list_handler.h"
|
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
void RESTAPI_variables_list_handler::DoGet() {
|
|
||||||
return ListHandler<VariablesDB>("variableBlocks", DB_, *this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-02-23.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
class RESTAPI_variables_list_handler : public RESTAPIHandler {
|
|
||||||
public:
|
|
||||||
RESTAPI_variables_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
|
|
||||||
: RESTAPIHandler(bindings, L,
|
|
||||||
std::vector<std::string>{
|
|
||||||
Poco::Net::HTTPRequest::HTTP_GET,
|
|
||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
|
||||||
Server,
|
|
||||||
TransactionId,
|
|
||||||
Internal) {
|
|
||||||
}
|
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/variable"}; };
|
|
||||||
private:
|
|
||||||
VariablesDB & DB_=StorageService()->VariablesDB();
|
|
||||||
void DoGet() final;
|
|
||||||
void DoPost() final {};
|
|
||||||
void DoPut() final {};
|
|
||||||
void DoDelete() final {};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -11,44 +11,11 @@
|
|||||||
|
|
||||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
|
#include "framework/RESTAPI_errors.h"
|
||||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||||
#include "Tasks/VenueConfigUpdater.h"
|
|
||||||
#include "Tasks/VenueRebooter.h"
|
|
||||||
#include "Tasks/VenueUpgrade.h"
|
|
||||||
|
|
||||||
#include "Kafka_ProvUpdater.h"
|
|
||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
|
|
||||||
static Types::UUIDvec_t GetDevices(const ProvObjects::Venue &V, bool GetChildren) {
|
|
||||||
Types::UUIDvec_t R;
|
|
||||||
std::copy(V.devices.begin(),V.devices.end(),std::back_inserter(R));
|
|
||||||
if(GetChildren) {
|
|
||||||
for (const auto &i: V.children) {
|
|
||||||
ProvObjects::Venue V2;
|
|
||||||
if (StorageService()->VenueDB().GetRecord("id", i, V2)) {
|
|
||||||
auto LowerDevs = GetDevices(V2, GetChildren);
|
|
||||||
std::copy(LowerDevs.begin(), LowerDevs.end(), std::back_inserter(R));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::sort(R.begin(),R.end());
|
|
||||||
auto Last = std::unique(R.begin(),R.end());
|
|
||||||
R.erase(Last,R.end());
|
|
||||||
|
|
||||||
std::vector<std::string> SerialNumbers;
|
|
||||||
|
|
||||||
for(const auto &device:R) {
|
|
||||||
ProvObjects::InventoryTag IT;
|
|
||||||
if(StorageService()->InventoryDB().GetRecord("id",device,IT)) {
|
|
||||||
SerialNumbers.push_back(IT.serialNumber);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return SerialNumbers;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RESTAPI_venue_handler::DoGet() {
|
void RESTAPI_venue_handler::DoGet() {
|
||||||
std::string UUID = GetBinding("uuid", "");
|
std::string UUID = GetBinding("uuid", "");
|
||||||
ProvObjects::Venue Existing;
|
ProvObjects::Venue Existing;
|
||||||
@@ -56,18 +23,6 @@ namespace OpenWifi{
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(GetBoolParameter("getDevices")) {
|
|
||||||
ProvObjects::VenueDeviceList VDL;
|
|
||||||
VDL.id = Existing.info.id;
|
|
||||||
VDL.name = Existing.info.name;
|
|
||||||
VDL.description = Existing.info.description;
|
|
||||||
auto GetChildren = GetBoolParameter("getChildren");
|
|
||||||
VDL.devices = GetDevices(Existing,GetChildren);
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
VDL.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
if(QB_.AdditionalInfo)
|
if(QB_.AdditionalInfo)
|
||||||
AddExtendedInfo(Existing, Answer);
|
AddExtendedInfo(Existing, Answer);
|
||||||
@@ -87,11 +42,8 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Existing.contacts.empty()) {
|
if(!Existing.contact.empty())
|
||||||
for(const auto &i:Existing.contacts)
|
StorageService()->ContactDB().DeleteInUse("id",Existing.contact,StorageService()->VenueDB().Prefix(),UUID);
|
||||||
StorageService()->ContactDB().DeleteInUse("id", i, StorageService()->VenueDB().Prefix(),
|
|
||||||
UUID);
|
|
||||||
}
|
|
||||||
if(!Existing.location.empty())
|
if(!Existing.location.empty())
|
||||||
StorageService()->LocationDB().DeleteInUse("id",Existing.location,StorageService()->VenueDB().Prefix(),UUID);
|
StorageService()->LocationDB().DeleteInUse("id",Existing.location,StorageService()->VenueDB().Prefix(),UUID);
|
||||||
if(!Existing.managementPolicy.empty())
|
if(!Existing.managementPolicy.empty())
|
||||||
@@ -105,58 +57,47 @@ namespace OpenWifi{
|
|||||||
if(!Existing.entity.empty())
|
if(!Existing.entity.empty())
|
||||||
StorageService()->EntityDB().DeleteVenue("id",Existing.entity,UUID);
|
StorageService()->EntityDB().DeleteVenue("id",Existing.entity,UUID);
|
||||||
DB_.DeleteRecord("id",UUID);
|
DB_.DeleteRecord("id",UUID);
|
||||||
|
|
||||||
UpdateKafkaProvisioningObject(ProvisioningOperation::removal,Existing);
|
|
||||||
|
|
||||||
return OK();
|
return OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_venue_handler::DoPost() {
|
void RESTAPI_venue_handler::DoPost() {
|
||||||
std::string UUID = GetBinding("uuid", "");
|
std::string UUID = GetBinding("uuid", "");
|
||||||
if (UUID.empty()) {
|
if(UUID.empty()) {
|
||||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
auto Obj = ParseStream();
|
||||||
ProvObjects::Venue NewObject;
|
ProvObjects::Venue NewObject;
|
||||||
if (!NewObject.from_json(RawObject)) {
|
if (!NewObject.from_json(Obj)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules,*this))) {
|
if(!CreateObjectInfo(Obj, UserInfo_.userinfo, NewObject.info)) {
|
||||||
return;
|
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info)) {
|
if(NewObject.parent.empty() && NewObject.entity.empty()) {
|
||||||
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NewObject.parent.empty() && NewObject.entity.empty()) {
|
|
||||||
return BadRequest(RESTAPI::Errors::ParentOrEntityMustBeSet);
|
return BadRequest(RESTAPI::Errors::ParentOrEntityMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NewObject.parent.empty() && !NewObject.entity.empty()) {
|
if(!NewObject.parent.empty() && !NewObject.entity.empty()) {
|
||||||
return BadRequest(RESTAPI::Errors::NotBoth);
|
return BadRequest(RESTAPI::Errors::NotBoth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NewObject.parent.empty() && !DB_.Exists("id", NewObject.parent)) {
|
if(!NewObject.parent.empty() && !DB_.Exists("id",NewObject.parent)) {
|
||||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NewObject.entity == EntityDB::RootUUID()) {
|
if(NewObject.entity == EntityDB::RootUUID()) {
|
||||||
return BadRequest(RESTAPI::Errors::ValidNonRootUUID);
|
return BadRequest(RESTAPI::Errors::ValidNonRootUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id", NewObject.entity)) {
|
if(!NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NewObject.contacts.empty()) {
|
if(!NewObject.contact.empty() && !StorageService()->ContactDB().Exists("id",NewObject.contact)) {
|
||||||
for(const auto &i:NewObject.contacts) {
|
return BadRequest(RESTAPI::Errors::ContactMustExist);
|
||||||
if(!StorageService()->ContactDB().Exists("id", i)) {
|
|
||||||
return BadRequest(RESTAPI::Errors::ContactMustExist);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!NewObject.location.empty() && !StorageService()->LocationDB().Exists("id",NewObject.location)) {
|
if(!NewObject.location.empty() && !StorageService()->LocationDB().Exists("id",NewObject.location)) {
|
||||||
@@ -181,20 +122,7 @@ namespace OpenWifi{
|
|||||||
|
|
||||||
NewObject.children.clear();
|
NewObject.children.clear();
|
||||||
|
|
||||||
RESTAPI::Errors::msg Error=RESTAPI::Errors::SUCCESS;
|
if(DB_.CreateShortCut(NewObject)) {
|
||||||
auto ObjectsCreated = CreateObjects(NewObject,*this,Error);
|
|
||||||
if(Error.err_num != 0) {
|
|
||||||
return BadRequest(Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(DB_.CreateRecord(NewObject)) {
|
|
||||||
MoveUsage(StorageService()->ContactDB(),DB_,{}, NewObject.contacts, NewObject.info.id);
|
|
||||||
MoveUsage(StorageService()->LocationDB(),DB_,"", NewObject.location, NewObject.info.id);
|
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
|
|
||||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::venues,"",NewObject.entity,NewObject.info.id);
|
|
||||||
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::children,"",NewObject.parent,NewObject.info.id);
|
|
||||||
MoveUsage(StorageService()->ConfigurationDB(),DB_,{},NewObject.deviceConfiguration,NewObject.info.id);
|
|
||||||
|
|
||||||
ProvObjects::Venue NewRecord;
|
ProvObjects::Venue NewRecord;
|
||||||
DB_.GetRecord("id",NewObject.info.id,NewRecord);
|
DB_.GetRecord("id",NewObject.info.id,NewRecord);
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
@@ -206,80 +134,22 @@ namespace OpenWifi{
|
|||||||
|
|
||||||
void RESTAPI_venue_handler::DoPut() {
|
void RESTAPI_venue_handler::DoPut() {
|
||||||
std::string UUID = GetBinding("uuid", "");
|
std::string UUID = GetBinding("uuid", "");
|
||||||
|
|
||||||
ProvObjects::Venue Existing;
|
ProvObjects::Venue Existing;
|
||||||
if(UUID.empty() || !DB_.GetRecord("id",UUID,Existing)) {
|
if(UUID.empty() || !DB_.GetRecord("id",UUID,Existing)) {
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto testUpdateOnly = GetBoolParameter("testUpdateOnly");
|
auto RawObject = ParseStream();
|
||||||
if(testUpdateOnly) {
|
|
||||||
ProvObjects::SerialNumberList SNL;
|
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
SNL.serialNumbers = Existing.devices;
|
|
||||||
SNL.to_json(Answer);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(GetBoolParameter("updateAllDevices")) {
|
|
||||||
ProvObjects::SerialNumberList SNL;
|
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
SNL.serialNumbers = Existing.devices;
|
|
||||||
|
|
||||||
auto Task = new VenueConfigUpdater(UUID,UserInfo_.userinfo,0,Logger());
|
|
||||||
auto JobId = Task->Start();
|
|
||||||
|
|
||||||
SNL.to_json(Answer);
|
|
||||||
Answer.set("jobId",JobId);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(GetBoolParameter("upgradeAllDevices")) {
|
|
||||||
ProvObjects::SerialNumberList SNL;
|
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
SNL.serialNumbers = Existing.devices;
|
|
||||||
|
|
||||||
auto Task = new VenueUpgrade(UUID,UserInfo_.userinfo,0,Logger());
|
|
||||||
auto JobId = Task->Start();
|
|
||||||
|
|
||||||
SNL.to_json(Answer);
|
|
||||||
Answer.set("jobId",JobId);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(GetBoolParameter("rebootAllDevices")) {
|
|
||||||
ProvObjects::SerialNumberList SNL;
|
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
|
||||||
SNL.serialNumbers = Existing.devices;
|
|
||||||
|
|
||||||
auto Task = new VenueRebooter(UUID,UserInfo_.userinfo,0,Logger());
|
|
||||||
auto JobId = Task->Start();
|
|
||||||
|
|
||||||
SNL.to_json(Answer);
|
|
||||||
Answer.set("jobId",JobId);
|
|
||||||
return ReturnObject(Answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto & RawObject = ParsedBody_;
|
|
||||||
ProvObjects::Venue NewObject;
|
ProvObjects::Venue NewObject;
|
||||||
if (!NewObject.from_json(RawObject)) {
|
if (!NewObject.from_json(RawObject)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules,*this))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info)) {
|
if(!UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info)) {
|
||||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(RawObject->has("deviceRules"))
|
AssignIfPresent(RawObject, "rrm",Existing.rrm);
|
||||||
Existing.deviceRules = NewObject.deviceRules;
|
|
||||||
|
|
||||||
if(RawObject->has("sourceIP")) {
|
if(RawObject->has("sourceIP")) {
|
||||||
if(!NewObject.sourceIP.empty() && !CIDR::ValidateIpRanges(NewObject.sourceIP)) {
|
if(!NewObject.sourceIP.empty() && !CIDR::ValidateIpRanges(NewObject.sourceIP)) {
|
||||||
@@ -288,100 +158,114 @@ namespace OpenWifi{
|
|||||||
Existing.sourceIP = NewObject.sourceIP;
|
Existing.sourceIP = NewObject.sourceIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MoveFromEntity,MoveToEntity;
|
std::string MoveEntity;
|
||||||
if(AssignIfPresent(RawObject, "entity", MoveToEntity)) {
|
bool MovingEntity=false;
|
||||||
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
|
if(AssignIfPresent(RawObject, "entity", MoveEntity)) {
|
||||||
|
if(!MoveEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveEntity)) {
|
||||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||||
}
|
}
|
||||||
MoveFromEntity = Existing.entity;
|
MovingEntity = MoveEntity != Existing.entity;
|
||||||
Existing.entity = MoveToEntity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MoveToVenue,MoveFromVenue;
|
std::string MoveVenue;
|
||||||
if(AssignIfPresent(RawObject, "venue", MoveToVenue)) {
|
bool MovingVenue=false;
|
||||||
if(!MoveToVenue.empty() && !StorageService()->VenueDB().Exists("id",MoveToVenue)) {
|
if(AssignIfPresent(RawObject, "venue", MoveVenue)) {
|
||||||
|
if(!MoveVenue.empty() && !StorageService()->VenueDB().Exists("id",MoveVenue)) {
|
||||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
||||||
}
|
}
|
||||||
MoveFromVenue = Existing.parent;
|
MovingVenue = MoveVenue != Existing.parent;
|
||||||
Existing.parent = MoveToVenue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MoveFromLocation, MoveToLocation;
|
std::string MoveLocation;
|
||||||
if(AssignIfPresent(RawObject,"location",MoveToLocation)) {
|
bool MovingLocation=false;
|
||||||
if(!MoveToLocation.empty() && !StorageService()->LocationDB().Exists("id",MoveToLocation)) {
|
if(AssignIfPresent(RawObject,"location",MoveLocation)) {
|
||||||
|
if(!MoveLocation.empty() && !StorageService()->LocationDB().Exists("id",MoveLocation)) {
|
||||||
return BadRequest(RESTAPI::Errors::LocationMustExist);
|
return BadRequest(RESTAPI::Errors::LocationMustExist);
|
||||||
}
|
}
|
||||||
MoveFromLocation = Existing.location;
|
MovingLocation = MoveLocation!=Existing.location;
|
||||||
Existing.location = MoveToLocation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Types::UUIDvec_t MoveFromContacts, MoveToContacts;
|
std::string MoveContact;
|
||||||
if(AssignIfPresent(RawObject,"contacts",MoveToContacts)) {
|
bool MovingContact=false;
|
||||||
for(const auto &i:NewObject.contacts) {
|
if(AssignIfPresent(RawObject,"contact",MoveContact)) {
|
||||||
if(!StorageService()->ContactDB().Exists("id", i)) {
|
if(!MoveContact.empty() && !StorageService()->ContactDB().Exists("id",MoveContact)) {
|
||||||
return BadRequest(RESTAPI::Errors::ContactMustExist);
|
return BadRequest(RESTAPI::Errors::ContactMustExist);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
MoveFromContacts = Existing.contacts;
|
MovingContact = MoveContact!=Existing.contact;
|
||||||
Existing.contacts = MoveToContacts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MoveFromPolicy, MoveToPolicy;
|
std::string MovePolicy;
|
||||||
if(AssignIfPresent(RawObject,"managementPolicy",MoveToPolicy)) {
|
bool MovingPolicy=false;
|
||||||
if(!MoveToPolicy.empty() && !StorageService()->PolicyDB().Exists("id",MoveToPolicy)) {
|
if(AssignIfPresent(RawObject,"managementPolicy",MovePolicy)) {
|
||||||
|
if(!MovePolicy.empty() && !StorageService()->PolicyDB().Exists("id",MovePolicy)) {
|
||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
}
|
}
|
||||||
MoveFromPolicy = Existing.managementPolicy;
|
MovingPolicy = MovePolicy != Existing.managementPolicy;
|
||||||
Existing.managementPolicy = MoveToPolicy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Types::UUIDvec_t MoveToConfigurations, MoveFromConfigurations;
|
Types::UUIDvec_t MoveConfiguration;
|
||||||
|
bool MovingConfiguration=false;
|
||||||
if(RawObject->has("deviceConfiguration")){
|
if(RawObject->has("deviceConfiguration")){
|
||||||
MoveToConfigurations = NewObject.deviceConfiguration;
|
if(!NewObject.deviceConfiguration.empty()){
|
||||||
for(auto &i:MoveToConfigurations) {
|
for(auto &i:NewObject.deviceConfiguration) {
|
||||||
if(!StorageService()->ConfigurationDB().Exists("id",i)) {
|
if(!StorageService()->ConfigurationDB().Exists("id",i)) {
|
||||||
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
|
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
MoveConfiguration = NewObject.deviceConfiguration;
|
||||||
MoveToConfigurations = NewObject.deviceConfiguration;
|
}
|
||||||
MoveFromConfigurations = Existing.deviceConfiguration;
|
MovingConfiguration = MoveConfiguration != Existing.deviceConfiguration;
|
||||||
Existing.deviceConfiguration = MoveToConfigurations;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ErrorText;
|
|
||||||
NewObject.parent = Existing.parent;
|
|
||||||
NewObject.entity = Existing.entity;
|
|
||||||
|
|
||||||
RESTAPI::Errors::msg Error=RESTAPI::Errors::SUCCESS;
|
|
||||||
auto ObjectsCreated = CreateObjects(NewObject,*this,Error);
|
|
||||||
if(Error.err_num != 0) {
|
|
||||||
return BadRequest(Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!ObjectsCreated.empty()) {
|
|
||||||
if(!ObjectsCreated.empty()) {
|
|
||||||
auto it = ObjectsCreated.find("location");
|
|
||||||
if(it!=ObjectsCreated.end()) {
|
|
||||||
MoveFromLocation="";
|
|
||||||
MoveToLocation=it->second;
|
|
||||||
Existing.location=MoveToLocation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RawObject->has("boards")) {
|
|
||||||
Existing.boards = NewObject.boards;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StorageService()->VenueDB().UpdateRecord("id", UUID, Existing)) {
|
if(StorageService()->VenueDB().UpdateRecord("id", UUID, Existing)) {
|
||||||
UpdateKafkaProvisioningObject(ProvisioningOperation::modification,Existing);
|
if(MovingContact) {
|
||||||
MoveUsage(StorageService()->ContactDB(),DB_,MoveFromContacts, MoveToContacts, Existing.info.id);
|
if(!Existing.contact.empty())
|
||||||
MoveUsage(StorageService()->LocationDB(),DB_,MoveFromLocation, MoveToLocation, Existing.info.id);
|
StorageService()->ContactDB().DeleteInUse("id",Existing.contact,DB_.Prefix(),Existing.info.id);
|
||||||
MoveUsage(StorageService()->PolicyDB(),DB_,MoveFromPolicy,MoveToPolicy,Existing.info.id);
|
if(!MoveContact.empty())
|
||||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::venues,MoveFromEntity,MoveToEntity,Existing.info.id);
|
StorageService()->ContactDB().AddInUse("id", MoveContact, DB_.Prefix(), Existing.info.id);
|
||||||
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::children,MoveFromVenue,MoveToVenue,Existing.info.id);
|
Existing.contact = MoveContact;
|
||||||
MoveUsage(StorageService()->ConfigurationDB(),DB_,MoveFromConfigurations,MoveToConfigurations,Existing.info.id);
|
}
|
||||||
|
if(MovingEntity) {
|
||||||
|
if(!Existing.entity.empty())
|
||||||
|
StorageService()->EntityDB().DeleteVenue("id", Existing.entity, Existing.info.id);
|
||||||
|
if(!MoveEntity.empty())
|
||||||
|
StorageService()->EntityDB().AddVenue("id",MoveEntity,Existing.info.id);
|
||||||
|
Existing.entity = MoveEntity;
|
||||||
|
}
|
||||||
|
if(MovingVenue) {
|
||||||
|
if(!Existing.parent.empty())
|
||||||
|
DB_.DeleteChild("id",Existing.parent,Existing.info.id);
|
||||||
|
if(!MoveVenue.empty())
|
||||||
|
DB_.AddChild("id", MoveVenue, Existing.info.id);
|
||||||
|
Existing.parent = MoveVenue;
|
||||||
|
}
|
||||||
|
if(MovingLocation) {
|
||||||
|
if(!Existing.location.empty())
|
||||||
|
StorageService()->LocationDB().DeleteInUse("id", Existing.location, DB_.Prefix(), Existing.info.id);
|
||||||
|
if(!MoveLocation.empty())
|
||||||
|
StorageService()->LocationDB().AddInUse("id", MoveLocation, DB_.Prefix(), Existing.info.id);
|
||||||
|
Existing.location = MoveLocation;
|
||||||
|
}
|
||||||
|
if(MovingPolicy) {
|
||||||
|
if(!Existing.managementPolicy.empty())
|
||||||
|
StorageService()->PolicyDB().DeleteInUse("id", Existing.managementPolicy, DB_.Prefix(), Existing.info.id);
|
||||||
|
if(!MovePolicy.empty())
|
||||||
|
StorageService()->PolicyDB().AddInUse("id", MovePolicy, DB_.Prefix(), Existing.info.id);
|
||||||
|
Existing.managementPolicy = MovePolicy;
|
||||||
|
}
|
||||||
|
if(MovingConfiguration) {
|
||||||
|
if(!Existing.deviceConfiguration.empty()) {
|
||||||
|
for(auto &i:Existing.deviceConfiguration)
|
||||||
|
StorageService()->ConfigurationDB().DeleteInUse("id", i, DB_.Prefix(), Existing.info.id);
|
||||||
|
}
|
||||||
|
if(!MoveConfiguration.empty()) {
|
||||||
|
for(auto &i:MoveConfiguration)
|
||||||
|
StorageService()->ConfigurationDB().AddInUse("id", i, DB_.Prefix(), Existing.info.id);
|
||||||
|
}
|
||||||
|
Existing.deviceConfiguration = MoveConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
DB_.UpdateRecord("id",Existing.info.id, Existing);
|
||||||
ProvObjects::Venue AddedRecord;
|
ProvObjects::Venue AddedRecord;
|
||||||
DB_.GetRecord("id",UUID,AddedRecord);
|
DB_.GetRecord("id",UUID,AddedRecord);
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
|
|||||||
@@ -22,16 +22,16 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal){}
|
Internal), DB_(StorageService()->VenueDB()) {}
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/venue/{uuid}"}; };
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/venue/{uuid}"}; };
|
||||||
private:
|
private:
|
||||||
VenueDB &DB_=StorageService()->VenueDB();
|
VenueDB &DB_;
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final;
|
void DoPost() final;
|
||||||
void DoPut() final;
|
void DoPut() final;
|
||||||
void DoDelete() final;
|
void DoDelete() final;
|
||||||
|
|
||||||
template <typename T> bool IdExists(T &DB, const std::string &Field, const RESTAPI::Errors::msg &Error) {
|
template <typename T> bool IdExists(T &DB, const std::string &Field, const std::string &Error) {
|
||||||
if(!Field.empty() && !DB.Exists("id",Field)) {
|
if(!Field.empty() && !DB.Exists("id",Field)) {
|
||||||
BadRequest(Error);
|
BadRequest(Error);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -8,6 +8,37 @@
|
|||||||
|
|
||||||
namespace OpenWifi{
|
namespace OpenWifi{
|
||||||
void RESTAPI_venue_list_handler::DoGet() {
|
void RESTAPI_venue_list_handler::DoGet() {
|
||||||
return ListHandler<VenueDB>("venues", DB_, *this);
|
try {
|
||||||
|
std::string Arg;
|
||||||
|
if(!QB_.Select.empty()) {
|
||||||
|
return ReturnRecordList<decltype(StorageService()->VenueDB()),
|
||||||
|
ProvObjects::Venue>("venues",StorageService()->VenueDB(),*this );
|
||||||
|
} else if(HasParameter("entity",Arg)) {
|
||||||
|
ProvObjects::VenueVec Venues;
|
||||||
|
StorageService()->VenueDB().GetRecords(QB_.Offset,QB_.Limit,Venues, StorageService()->VenueDB().OP("entity",ORM::EQ,Arg));
|
||||||
|
if(QB_.CountOnly) {
|
||||||
|
return ReturnCountOnly(Venues.size());
|
||||||
|
}
|
||||||
|
return MakeJSONObjectArray("venues", Venues, *this);
|
||||||
|
} else if(HasParameter("venue",Arg)) {
|
||||||
|
ProvObjects::VenueVec Venues;
|
||||||
|
StorageService()->VenueDB().GetRecords(QB_.Offset,QB_.Limit,Venues,StorageService()->VenueDB().OP("venue",ORM::EQ,Arg));
|
||||||
|
if(QB_.CountOnly) {
|
||||||
|
return ReturnCountOnly(Venues.size());
|
||||||
|
}
|
||||||
|
return MakeJSONObjectArray("venues", Venues, *this);
|
||||||
|
} else if(QB_.CountOnly) {
|
||||||
|
Poco::JSON::Object Answer;
|
||||||
|
auto C = StorageService()->VenueDB().Count();
|
||||||
|
return ReturnCountOnly(C);
|
||||||
|
} else {
|
||||||
|
ProvObjects::VenueVec Venues;
|
||||||
|
StorageService()->VenueDB().GetRecords(QB_.Offset, QB_.Limit,Venues);
|
||||||
|
return MakeJSONObjectArray("venues", Venues, *this);
|
||||||
|
}
|
||||||
|
} catch(const Poco::Exception &E) {
|
||||||
|
Logger().log(E);
|
||||||
|
}
|
||||||
|
InternalError("Internal error.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "framework/MicroService.h"
|
#include "framework/MicroService.h"
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
@@ -18,12 +17,9 @@ namespace OpenWifi {
|
|||||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
Server,
|
Server,
|
||||||
TransactionId,
|
TransactionId,
|
||||||
Internal) {
|
Internal) {}
|
||||||
}
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/venue"}; };
|
||||||
static auto PathName() { return std::list<std::string>{"/api/v1/venue"}; };
|
|
||||||
|
|
||||||
private:
|
|
||||||
VenueDB &DB_=StorageService()->VenueDB();
|
|
||||||
void DoGet() final;
|
void DoGet() final;
|
||||||
void DoPost() final {};
|
void DoPost() final {};
|
||||||
void DoPut() final {};
|
void DoPut() final {};
|
||||||
|
|||||||
204
src/RESTAPI/RESTAPI_webSocketServer.cpp
Normal file
204
src/RESTAPI/RESTAPI_webSocketServer.cpp
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
//
|
||||||
|
// Created by stephane bourque on 2021-08-12.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "RESTAPI_webSocketServer.h"
|
||||||
|
|
||||||
|
#include "framework/MicroService.h"
|
||||||
|
|
||||||
|
#include "Poco/Net/WebSocket.h"
|
||||||
|
#include "Poco/Net/NetException.h"
|
||||||
|
#include "Poco/Net/HTTPResponse.h"
|
||||||
|
#include "Poco/JSON/Object.h"
|
||||||
|
#include "Poco/JSON/Parser.h"
|
||||||
|
#include "Poco/JSON/Stringifier.h"
|
||||||
|
#include "Poco/Net/HTTPSClientSession.h"
|
||||||
|
|
||||||
|
#include "SerialNumberCache.h"
|
||||||
|
#include "WebSocketClientServer.h"
|
||||||
|
|
||||||
|
namespace OpenWifi {
|
||||||
|
|
||||||
|
void RESTAPI_webSocketServer::DoGet() {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(Request->find("Upgrade") != Request->end() && Poco::icompare((*Request)["Upgrade"], "websocket") == 0) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Poco::Net::WebSocket WS(*Request, *Response);
|
||||||
|
Logger().information("WebSocket connection established.");
|
||||||
|
auto Id = MicroService::CreateUUID();
|
||||||
|
new WebSocketClient(WS,Id,Logger());
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
std::cout << "Cannot create websocket client..." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(...) {
|
||||||
|
std::cout << "Cannot upgrade connection..." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
void RESTAPI_webSocketServer::DoGet() {
|
||||||
|
|
||||||
|
// try and upgrade this session to websocket...
|
||||||
|
if(Request->find("Upgrade") != Request->end() && Poco::icompare((*Request)["Upgrade"], "websocket") == 0) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Poco::Net::WebSocket WS(*Request, *Response);
|
||||||
|
Logger().information("WebSocket connection established.");
|
||||||
|
int flags;
|
||||||
|
int n;
|
||||||
|
bool Authenticated=false;
|
||||||
|
bool Done=false;
|
||||||
|
GoogleApiKey_ = MicroService::instance().ConfigGetString("google.apikey","");
|
||||||
|
GeoCodeEnabled_ = !GoogleApiKey_.empty();
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Poco::Buffer<char> IncomingFrame(0);
|
||||||
|
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: {
|
||||||
|
IncomingFrame.append(0);
|
||||||
|
if(!Authenticated) {
|
||||||
|
std::string Frame{IncomingFrame.begin()};
|
||||||
|
auto Tokens = Utils::Split(Frame,':');
|
||||||
|
if(Tokens.size()==2 && AuthClient()->IsTokenAuthorized(Tokens[1], UserInfo_)) {
|
||||||
|
Authenticated=true;
|
||||||
|
std::string S{"Welcome! Bienvenue! Bienvenidos!"};
|
||||||
|
WS.sendFrame(S.c_str(),S.size());
|
||||||
|
} else {
|
||||||
|
std::string S{"Invalid token. Closing connection."};
|
||||||
|
WS.sendFrame(S.c_str(),S.size());
|
||||||
|
Done=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
Poco::JSON::Parser P;
|
||||||
|
auto Obj = P.parse(IncomingFrame.begin())
|
||||||
|
.extract<Poco::JSON::Object::Ptr>();
|
||||||
|
std::string Answer;
|
||||||
|
Process(Obj, Answer, Done );
|
||||||
|
if (!Answer.empty())
|
||||||
|
WS.sendFrame(Answer.c_str(), Answer.size());
|
||||||
|
else {
|
||||||
|
WS.sendFrame("{}", 2);
|
||||||
|
}
|
||||||
|
} catch (const Poco::JSON::JSONException & E) {
|
||||||
|
Logger().log(E);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (!Done && (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE));
|
||||||
|
Logger().information("WebSocket connection closed.");
|
||||||
|
}
|
||||||
|
catch (const Poco::Net::WebSocketException & E)
|
||||||
|
{
|
||||||
|
Logger().log(E);
|
||||||
|
switch (E.code())
|
||||||
|
{
|
||||||
|
case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION:
|
||||||
|
Response->set("Sec-WebSocket-Version", Poco::Net::WebSocket::WEBSOCKET_VERSION);
|
||||||
|
// fallthrough
|
||||||
|
case Poco::Net::WebSocket::WS_ERR_NO_HANDSHAKE:
|
||||||
|
case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_VERSION:
|
||||||
|
case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_KEY:
|
||||||
|
Response->setStatusAndReason(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST);
|
||||||
|
Response->setContentLength(0);
|
||||||
|
Response->send();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const Poco::Exception &E) {
|
||||||
|
Logger().log(E);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
void RESTAPI_webSocketServer::Process(const Poco::JSON::Object::Ptr &O, std::string &Answer, bool &Done ) {
|
||||||
|
try {
|
||||||
|
if (O->has("command")) {
|
||||||
|
auto Command = O->get("command").toString();
|
||||||
|
if (Command == "serial_number_search" && O->has("serial_prefix")) {
|
||||||
|
auto Prefix = O->get("serial_prefix").toString();
|
||||||
|
uint64_t HowMany = 32;
|
||||||
|
if (O->has("howMany"))
|
||||||
|
HowMany = O->get("howMany");
|
||||||
|
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);
|
||||||
|
Poco::JSON::Array A;
|
||||||
|
for (const auto &i : Numbers)
|
||||||
|
A.add(Utils::int_to_hex(i));
|
||||||
|
Poco::JSON::Object AO;
|
||||||
|
AO.set("serialNumbers", A);
|
||||||
|
AO.set("command","serial_number_search");
|
||||||
|
std::ostringstream SS;
|
||||||
|
Poco::JSON::Stringifier::stringify(AO, SS);
|
||||||
|
Answer = SS.str();
|
||||||
|
}
|
||||||
|
} else if (GeoCodeEnabled_ && Command == "address_completion" && O->has("address")) {
|
||||||
|
auto Address = O->get("address").toString();
|
||||||
|
Answer = GoogleGeoCodeCall(Address);
|
||||||
|
} else if (Command=="exit") {
|
||||||
|
Answer = R"lit({ "closing" : "Goodbye! Aurevoir! Hasta la vista!" })lit";
|
||||||
|
Done = true;
|
||||||
|
} else {
|
||||||
|
Answer = std::string{R"lit({ "error" : "invalid command" })lit"};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (const Poco::Exception &E) {
|
||||||
|
Logger().log(E);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string RESTAPI_webSocketServer::GoogleGeoCodeCall(const std::string &A) {
|
||||||
|
try {
|
||||||
|
std::string URI = { "https://maps.googleapis.com/maps/api/geocode/json"};
|
||||||
|
Poco::URI uri(URI);
|
||||||
|
|
||||||
|
uri.addQueryParameter("address",A);
|
||||||
|
uri.addQueryParameter("key", GoogleApiKey_);
|
||||||
|
|
||||||
|
Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort());
|
||||||
|
Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, uri.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1);
|
||||||
|
session.sendRequest(req);
|
||||||
|
Poco::Net::HTTPResponse res;
|
||||||
|
std::istream& rs = session.receiveResponse(res);
|
||||||
|
|
||||||
|
if(res.getStatus()==Poco::Net::HTTPResponse::HTTP_OK) {
|
||||||
|
std::ostringstream os;
|
||||||
|
Poco::StreamCopier::copyStream(rs,os);
|
||||||
|
return os.str();
|
||||||
|
} else {
|
||||||
|
std::ostringstream os;
|
||||||
|
Poco::StreamCopier::copyStream(rs,os);
|
||||||
|
return R"lit({ "error: )lit" + os.str() + R"lit( })lit";
|
||||||
|
}
|
||||||
|
} catch(...) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return "{ \"error\" : \"No call made\" }";
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/RESTAPI/RESTAPI_webSocketServer.h
Normal file
29
src/RESTAPI/RESTAPI_webSocketServer.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// Created by stephane bourque on 2021-08-12.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "framework/MicroService.h"
|
||||||
|
|
||||||
|
namespace OpenWifi {
|
||||||
|
class RESTAPI_webSocketServer : public RESTAPIHandler {
|
||||||
|
public:
|
||||||
|
RESTAPI_webSocketServer(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
|
||||||
|
: RESTAPIHandler(bindings, L,
|
||||||
|
std::vector<std::string>{ Poco::Net::HTTPRequest::HTTP_GET,
|
||||||
|
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||||
|
Server, TransactionId, Internal,false) {}
|
||||||
|
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/ws"};}
|
||||||
|
void DoGet() final;
|
||||||
|
void DoDelete() final {};
|
||||||
|
void DoPost() final {};
|
||||||
|
void DoPut() final {};
|
||||||
|
private:
|
||||||
|
void Process(const Poco::JSON::Object::Ptr &O, std::string &Answer, bool &Done);
|
||||||
|
std::string GoogleGeoCodeCall(const std::string &A);
|
||||||
|
bool GeoCodeEnabled_=false;
|
||||||
|
std::string GoogleApiKey_;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,622 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-01-10.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RESTAPI_AnalyticsObjects.h"
|
|
||||||
#include "RESTAPI_ProvObjects.h"
|
|
||||||
#include "framework/MicroService.h"
|
|
||||||
|
|
||||||
using OpenWifi::RESTAPI_utils::field_to_json;
|
|
||||||
using OpenWifi::RESTAPI_utils::field_from_json;
|
|
||||||
|
|
||||||
namespace OpenWifi::AnalyticsObjects {
|
|
||||||
|
|
||||||
void Report::reset() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Report::to_json([[maybe_unused]] Poco::JSON::Object &Obj) const {
|
|
||||||
}
|
|
||||||
|
|
||||||
void VenueInfo::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"id",id);
|
|
||||||
field_to_json(Obj,"name",name);
|
|
||||||
field_to_json(Obj,"description",description);
|
|
||||||
field_to_json(Obj,"retention",retention);
|
|
||||||
field_to_json(Obj,"interval",interval);
|
|
||||||
field_to_json(Obj,"monitorSubVenues",monitorSubVenues);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VenueInfo::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"id",id);
|
|
||||||
field_from_json(Obj,"name",name);
|
|
||||||
field_from_json(Obj,"description",description);
|
|
||||||
field_from_json(Obj,"retention",retention);
|
|
||||||
field_from_json(Obj,"interval",interval);
|
|
||||||
field_from_json(Obj,"monitorSubVenues",monitorSubVenues);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BoardInfo::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
info.to_json(Obj);
|
|
||||||
field_to_json(Obj,"venueList",venueList);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BoardInfo::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
info.from_json(Obj);
|
|
||||||
field_from_json(Obj,"venueList",venueList);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceInfo::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"boardId",boardId);
|
|
||||||
field_to_json(Obj,"type",type);
|
|
||||||
field_to_json(Obj,"serialNumber",serialNumber);
|
|
||||||
field_to_json(Obj,"deviceType",deviceType);
|
|
||||||
field_to_json(Obj,"lastContact",lastContact);
|
|
||||||
field_to_json(Obj,"lastPing",lastPing);
|
|
||||||
field_to_json(Obj,"lastState",lastState);
|
|
||||||
field_to_json(Obj,"lastFirmware",lastFirmware);
|
|
||||||
field_to_json(Obj,"lastFirmwareUpdate",lastFirmwareUpdate);
|
|
||||||
field_to_json(Obj,"lastConnection",lastConnection);
|
|
||||||
field_to_json(Obj,"lastDisconnection",lastDisconnection);
|
|
||||||
field_to_json(Obj,"pings",pings);
|
|
||||||
field_to_json(Obj,"states",states);
|
|
||||||
field_to_json(Obj,"connected",connected);
|
|
||||||
field_to_json(Obj,"connectionIp",connectionIp);
|
|
||||||
field_to_json(Obj,"associations_2g",associations_2g);
|
|
||||||
field_to_json(Obj,"associations_5g",associations_5g);
|
|
||||||
field_to_json(Obj,"associations_6g",associations_6g);
|
|
||||||
field_to_json(Obj,"health",health);
|
|
||||||
field_to_json(Obj,"lastHealth",lastHealth);
|
|
||||||
field_to_json(Obj,"locale",locale);
|
|
||||||
field_to_json(Obj,"uptime",uptime);
|
|
||||||
field_to_json(Obj,"memory",memory);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeviceInfo::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"boardId",boardId);
|
|
||||||
field_from_json(Obj,"type",type);
|
|
||||||
field_from_json(Obj,"serialNumber",serialNumber);
|
|
||||||
field_from_json(Obj,"deviceType",deviceType);
|
|
||||||
field_from_json(Obj,"lastContact",lastContact);
|
|
||||||
field_from_json(Obj,"lastPing",lastPing);
|
|
||||||
field_from_json(Obj,"lastState",lastState);
|
|
||||||
field_from_json(Obj,"lastFirmware",lastFirmware);
|
|
||||||
field_from_json(Obj,"lastFirmwareUpdate",lastFirmwareUpdate);
|
|
||||||
field_from_json(Obj,"lastConnection",lastConnection);
|
|
||||||
field_from_json(Obj,"lastDisconnection",lastDisconnection);
|
|
||||||
field_from_json(Obj,"pings",pings);
|
|
||||||
field_from_json(Obj,"states",states);
|
|
||||||
field_from_json(Obj,"connected",connected);
|
|
||||||
field_from_json(Obj,"connectionIp",connectionIp);
|
|
||||||
field_from_json(Obj,"associations_2g",associations_2g);
|
|
||||||
field_from_json(Obj,"associations_5g",associations_5g);
|
|
||||||
field_from_json(Obj,"associations_6g",associations_6g);
|
|
||||||
field_from_json(Obj,"health",health);
|
|
||||||
field_from_json(Obj,"lastHealth",lastHealth);
|
|
||||||
field_from_json(Obj,"locale",locale);
|
|
||||||
field_from_json(Obj,"uptime",uptime);
|
|
||||||
field_from_json(Obj,"memory",memory);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceInfoList::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"devices",devices);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeviceInfoList::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"devices",devices);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UE_rate::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"bitrate",bitrate);
|
|
||||||
field_to_json(Obj,"mcs",mcs);
|
|
||||||
field_to_json(Obj,"nss",nss);
|
|
||||||
field_to_json(Obj,"ht",ht);
|
|
||||||
field_to_json(Obj,"sgi",sgi);
|
|
||||||
field_to_json(Obj,"chwidth",chwidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UE_rate::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"bitrate",bitrate);
|
|
||||||
field_from_json(Obj,"mcs",mcs);
|
|
||||||
field_from_json(Obj,"nss",nss);
|
|
||||||
field_from_json(Obj,"ht",ht);
|
|
||||||
field_from_json(Obj,"sgi",sgi);
|
|
||||||
field_from_json(Obj,"chwidth",chwidth);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UETimePoint::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"station",station);
|
|
||||||
field_to_json(Obj,"rssi",rssi);
|
|
||||||
field_to_json(Obj,"tx_bytes",tx_bytes);
|
|
||||||
field_to_json(Obj,"rx_bytes",rx_bytes);
|
|
||||||
field_to_json(Obj,"tx_duration",tx_duration);
|
|
||||||
field_to_json(Obj,"rx_packets",rx_packets);
|
|
||||||
field_to_json(Obj,"tx_packets",tx_packets);
|
|
||||||
field_to_json(Obj,"tx_retries",tx_retries);
|
|
||||||
field_to_json(Obj,"tx_failed",tx_failed);
|
|
||||||
field_to_json(Obj,"connected",connected);
|
|
||||||
field_to_json(Obj,"inactive",inactive);
|
|
||||||
field_to_json(Obj,"tx_rate",tx_rate);
|
|
||||||
field_to_json(Obj,"rx_rate",rx_rate);
|
|
||||||
// field_to_json(Obj, "tidstats", tidstats);
|
|
||||||
|
|
||||||
field_to_json(Obj,"tx_bytes_bw",tx_bytes_bw);
|
|
||||||
field_to_json(Obj,"rx_bytes_bw",rx_bytes_bw);
|
|
||||||
field_to_json(Obj,"tx_packets_bw",tx_packets_bw);
|
|
||||||
field_to_json(Obj,"rx_packets_bw",rx_packets_bw);
|
|
||||||
field_to_json(Obj,"tx_failed_pct",tx_failed_pct);
|
|
||||||
field_to_json(Obj,"tx_retries_pct",tx_retries_pct);
|
|
||||||
field_to_json(Obj,"tx_duration_pct",tx_duration_pct);
|
|
||||||
|
|
||||||
field_to_json(Obj,"tx_bytes_delta",tx_bytes_delta);
|
|
||||||
field_to_json(Obj,"rx_bytes_delta",rx_bytes_delta);
|
|
||||||
field_to_json(Obj,"tx_packets_delta",tx_packets_delta);
|
|
||||||
field_to_json(Obj,"rx_packets_delta",rx_packets_delta);
|
|
||||||
field_to_json(Obj,"tx_failed_delta",tx_failed_delta);
|
|
||||||
field_to_json(Obj,"tx_retries_delta",tx_retries_delta);
|
|
||||||
field_to_json(Obj,"tx_duration_delta",tx_duration_delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UETimePoint::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"station",station);
|
|
||||||
field_from_json(Obj,"rssi",rssi);
|
|
||||||
field_from_json(Obj,"tx_bytes",tx_bytes);
|
|
||||||
field_from_json(Obj,"rx_bytes",rx_bytes);
|
|
||||||
field_from_json(Obj,"tx_duration",tx_duration);
|
|
||||||
field_from_json(Obj,"rx_packets",rx_packets);
|
|
||||||
field_from_json(Obj,"tx_packets",tx_packets);
|
|
||||||
field_from_json(Obj,"tx_retries",tx_retries);
|
|
||||||
field_from_json(Obj,"tx_failed",tx_failed);
|
|
||||||
field_from_json(Obj,"connected",connected);
|
|
||||||
field_from_json(Obj,"inactive",inactive);
|
|
||||||
field_from_json(Obj,"tx_rate",tx_rate);
|
|
||||||
field_from_json(Obj,"rx_rate",rx_rate);
|
|
||||||
// field_from_json(Obj,"tidstats",tidstats);
|
|
||||||
field_from_json(Obj,"tx_bytes_bw",tx_bytes_bw);
|
|
||||||
field_from_json(Obj,"rx_bytes_bw",rx_bytes_bw);
|
|
||||||
field_from_json(Obj,"tx_packets_bw",tx_packets_bw);
|
|
||||||
field_from_json(Obj,"rx_packets_bw",rx_packets_bw);
|
|
||||||
field_from_json(Obj,"tx_failed_pct",tx_failed_pct);
|
|
||||||
field_from_json(Obj,"tx_retries_pct",tx_retries_pct);
|
|
||||||
field_from_json(Obj,"tx_duration_pct",tx_duration_pct);
|
|
||||||
field_from_json(Obj,"tx_bytes_delta",tx_bytes_delta);
|
|
||||||
field_from_json(Obj,"rx_bytes_delta",rx_bytes_delta);
|
|
||||||
field_from_json(Obj,"tx_packets_delta",tx_packets_delta);
|
|
||||||
field_from_json(Obj,"rx_packets_delta",rx_packets_delta);
|
|
||||||
field_from_json(Obj,"tx_failed_delta",tx_failed_delta);
|
|
||||||
field_from_json(Obj,"tx_retries_delta",tx_retries_delta);
|
|
||||||
field_from_json(Obj,"tx_duration_delta",tx_duration_delta);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void APTimePoint::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"collisions",collisions);
|
|
||||||
field_to_json(Obj,"multicast",multicast);
|
|
||||||
field_to_json(Obj,"rx_bytes",rx_bytes);
|
|
||||||
field_to_json(Obj,"rx_dropped",rx_dropped);
|
|
||||||
field_to_json(Obj,"rx_errors",rx_errors);
|
|
||||||
field_to_json(Obj,"rx_packets",rx_packets);
|
|
||||||
field_to_json(Obj,"tx_bytes",tx_bytes);
|
|
||||||
field_to_json(Obj,"tx_packets",tx_packets);
|
|
||||||
field_to_json(Obj,"tx_dropped",tx_dropped);
|
|
||||||
field_to_json(Obj,"tx_errors",tx_errors);
|
|
||||||
field_to_json(Obj,"tx_packets",tx_packets);
|
|
||||||
|
|
||||||
field_to_json(Obj,"tx_bytes_bw",tx_bytes_bw);
|
|
||||||
field_to_json(Obj,"rx_bytes_bw",rx_bytes_bw);
|
|
||||||
field_to_json(Obj,"rx_dropped_pct",rx_dropped_pct);
|
|
||||||
field_to_json(Obj,"tx_dropped_pct",tx_dropped_pct);
|
|
||||||
field_to_json(Obj,"rx_packets_bw",rx_packets_bw);
|
|
||||||
field_to_json(Obj,"tx_packets_bw",tx_packets_bw);
|
|
||||||
field_to_json(Obj,"rx_errors_pct",rx_errors_pct);
|
|
||||||
field_to_json(Obj,"tx_errors_pct",tx_errors_pct);
|
|
||||||
|
|
||||||
field_to_json(Obj,"tx_bytes_delta",tx_bytes_delta);
|
|
||||||
field_to_json(Obj,"rx_bytes_delta",rx_bytes_delta);
|
|
||||||
field_to_json(Obj,"rx_dropped_delta",rx_dropped_delta);
|
|
||||||
field_to_json(Obj,"tx_dropped_delta",tx_dropped_delta);
|
|
||||||
field_to_json(Obj,"rx_packets_delta",rx_packets_delta);
|
|
||||||
field_to_json(Obj,"tx_packets_delta",tx_packets_delta);
|
|
||||||
field_to_json(Obj,"rx_errors_delta",rx_errors_delta);
|
|
||||||
field_to_json(Obj,"tx_errors_delta",tx_errors_delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool APTimePoint::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"collisions",collisions);
|
|
||||||
field_from_json(Obj,"multicast",multicast);
|
|
||||||
field_from_json(Obj,"rx_bytes",rx_bytes);
|
|
||||||
field_from_json(Obj,"rx_dropped",rx_dropped);
|
|
||||||
field_from_json(Obj,"rx_errors",rx_errors);
|
|
||||||
field_from_json(Obj,"rx_packets",rx_packets);
|
|
||||||
field_from_json(Obj,"tx_bytes",tx_bytes);
|
|
||||||
field_from_json(Obj,"tx_packets",tx_packets);
|
|
||||||
field_from_json(Obj,"tx_dropped",tx_dropped);
|
|
||||||
field_from_json(Obj,"tx_errors",tx_errors);
|
|
||||||
field_from_json(Obj,"tx_packets",tx_packets);
|
|
||||||
|
|
||||||
field_from_json(Obj,"tx_bytes_bw",tx_bytes_bw);
|
|
||||||
field_from_json(Obj,"rx_bytes_bw",rx_bytes_bw);
|
|
||||||
field_from_json(Obj,"rx_dropped_pct",rx_dropped_pct);
|
|
||||||
field_from_json(Obj,"tx_dropped_pct",tx_dropped_pct);
|
|
||||||
field_from_json(Obj,"rx_packets_bw",rx_packets_bw);
|
|
||||||
field_from_json(Obj,"tx_packets_bw",tx_packets_bw);
|
|
||||||
field_from_json(Obj,"rx_errors_pct",rx_errors_pct);
|
|
||||||
field_from_json(Obj,"tx_errors_pct",tx_errors_pct);
|
|
||||||
|
|
||||||
field_from_json(Obj,"tx_bytes_delta",tx_bytes_delta);
|
|
||||||
field_from_json(Obj,"rx_bytes_delta",rx_bytes_delta);
|
|
||||||
field_from_json(Obj,"rx_dropped_delta",rx_dropped_delta);
|
|
||||||
field_from_json(Obj,"tx_dropped_delta",tx_dropped_delta);
|
|
||||||
field_from_json(Obj,"rx_packets_delta",rx_packets_delta);
|
|
||||||
field_from_json(Obj,"tx_packets_delta",tx_packets_delta);
|
|
||||||
field_from_json(Obj,"rx_errors_delta",rx_errors_delta);
|
|
||||||
field_from_json(Obj,"tx_errors_delta",tx_errors_delta);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TIDstat_entry::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"rx_msdu",rx_msdu);
|
|
||||||
field_to_json(Obj,"tx_msdu",tx_msdu);
|
|
||||||
field_to_json(Obj,"tx_msdu_failed",tx_msdu_failed);
|
|
||||||
field_to_json(Obj,"tx_msdu_retries",tx_msdu_retries);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TIDstat_entry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"rx_msdu",rx_msdu);
|
|
||||||
field_from_json(Obj,"tx_msdu",tx_msdu);
|
|
||||||
field_from_json(Obj,"tx_msdu_failed",tx_msdu_failed);
|
|
||||||
field_from_json(Obj,"tx_msdu_retries",tx_msdu_retries);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RadioTimePoint::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"band",band);
|
|
||||||
field_to_json(Obj,"channel_width",channel_width);
|
|
||||||
field_to_json(Obj,"active_ms",active_ms);
|
|
||||||
field_to_json(Obj,"busy_ms",busy_ms);
|
|
||||||
field_to_json(Obj,"receive_ms",receive_ms);
|
|
||||||
field_to_json(Obj,"transmit_ms",transmit_ms);
|
|
||||||
field_to_json(Obj,"tx_power",tx_power);
|
|
||||||
field_to_json(Obj,"channel",channel);
|
|
||||||
field_to_json(Obj,"temperature",temperature);
|
|
||||||
field_to_json(Obj,"noise",noise);
|
|
||||||
field_to_json(Obj,"active_pct",active_pct);
|
|
||||||
field_to_json(Obj,"busy_pct",busy_pct);
|
|
||||||
field_to_json(Obj,"receive_pct",receive_pct);
|
|
||||||
field_to_json(Obj,"transmit_pct",transmit_pct);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RadioTimePoint::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"band",band);
|
|
||||||
field_from_json(Obj,"channel_width",channel_width);
|
|
||||||
field_from_json(Obj,"active_ms",active_ms);
|
|
||||||
field_from_json(Obj,"busy_ms",busy_ms);
|
|
||||||
field_from_json(Obj,"receive_ms",receive_ms);
|
|
||||||
field_from_json(Obj,"transmit_ms",transmit_ms);
|
|
||||||
field_from_json(Obj,"tx_power",tx_power);
|
|
||||||
field_from_json(Obj,"channel",channel);
|
|
||||||
field_from_json(Obj,"temperature",temperature);
|
|
||||||
field_from_json(Obj,"noise",noise);
|
|
||||||
field_from_json(Obj,"active_pct",active_pct);
|
|
||||||
field_from_json(Obj,"busy_pct",busy_pct);
|
|
||||||
field_from_json(Obj,"receive_pct",receive_pct);
|
|
||||||
field_from_json(Obj,"transmit_pct",transmit_pct);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AveragePoint::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"min",min);
|
|
||||||
field_to_json(Obj,"max",max);
|
|
||||||
field_to_json(Obj,"avg",avg);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AveragePoint::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"min",min);
|
|
||||||
field_from_json(Obj,"max",max);
|
|
||||||
field_from_json(Obj,"avg",avg);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SSIDTimePoint::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"bssid",bssid);
|
|
||||||
field_to_json(Obj,"mode",mode);
|
|
||||||
field_to_json(Obj,"ssid",ssid);
|
|
||||||
field_to_json(Obj,"band",band);
|
|
||||||
field_to_json(Obj,"channel",channel);
|
|
||||||
field_to_json(Obj,"associations",associations);
|
|
||||||
field_to_json(Obj,"tx_bytes_bw",tx_bytes_bw);
|
|
||||||
field_to_json(Obj,"rx_bytes_bw",rx_bytes_bw);
|
|
||||||
field_to_json(Obj,"tx_packets_bw",tx_packets_bw);
|
|
||||||
field_to_json(Obj,"rx_packets_bw",rx_packets_bw);
|
|
||||||
field_to_json(Obj,"tx_failed_pct",tx_failed_pct);
|
|
||||||
field_to_json(Obj,"tx_retries_pct",tx_retries_pct);
|
|
||||||
field_to_json(Obj,"tx_duration_pct",tx_duration_pct);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SSIDTimePoint::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"bssid",bssid);
|
|
||||||
field_from_json(Obj,"mode",mode);
|
|
||||||
field_from_json(Obj,"ssid",ssid);
|
|
||||||
field_from_json(Obj,"band",band);
|
|
||||||
field_from_json(Obj,"channel",channel);
|
|
||||||
field_from_json(Obj,"associations",associations);
|
|
||||||
field_from_json(Obj,"tx_bytes_bw",tx_bytes_bw);
|
|
||||||
field_from_json(Obj,"rx_bytes_bw",rx_bytes_bw);
|
|
||||||
field_from_json(Obj,"tx_packets_bw",tx_packets_bw);
|
|
||||||
field_from_json(Obj,"rx_packets_bw",rx_packets_bw);
|
|
||||||
field_from_json(Obj,"tx_failed_pct",tx_failed_pct);
|
|
||||||
field_from_json(Obj,"tx_retries_pct",tx_retries_pct);
|
|
||||||
field_from_json(Obj,"tx_duration_pct",tx_duration_pct);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceTimePoint::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"id",id);
|
|
||||||
field_to_json(Obj,"boardId",boardId);
|
|
||||||
field_to_json(Obj,"timestamp",timestamp);
|
|
||||||
field_to_json(Obj,"ap_data",ap_data);
|
|
||||||
field_to_json(Obj,"ssid_data",ssid_data);
|
|
||||||
field_to_json(Obj,"radio_data",radio_data);
|
|
||||||
field_to_json(Obj,"device_info",device_info);
|
|
||||||
field_to_json(Obj,"serialNumber",serialNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeviceTimePoint::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"id",id);
|
|
||||||
field_from_json(Obj,"boardId",boardId);
|
|
||||||
field_from_json(Obj,"timestamp",timestamp);
|
|
||||||
field_from_json(Obj,"ap_data",ap_data);
|
|
||||||
field_from_json(Obj,"ssid_data",ssid_data);
|
|
||||||
field_from_json(Obj,"radio_data",radio_data);
|
|
||||||
field_from_json(Obj,"device_info",device_info);
|
|
||||||
field_from_json(Obj,"serialNumber",serialNumber);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceTimePointAnalysis::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"noise",noise);
|
|
||||||
field_to_json(Obj,"temperature",temperature);
|
|
||||||
field_to_json(Obj,"active_pct",active_pct);
|
|
||||||
field_to_json(Obj,"busy_pct",busy_pct);
|
|
||||||
field_to_json(Obj,"receive_pct",receive_pct);
|
|
||||||
field_to_json(Obj,"transmit_pct",transmit_pct);
|
|
||||||
field_to_json(Obj,"tx_power",tx_power);
|
|
||||||
field_to_json(Obj,"tx_bytes_bw",tx_bytes_bw);
|
|
||||||
field_to_json(Obj,"rx_bytes_bw",rx_bytes_bw);
|
|
||||||
field_to_json(Obj,"rx_dropped_pct",rx_dropped_pct);
|
|
||||||
field_to_json(Obj,"tx_dropped_pct",tx_dropped_pct);
|
|
||||||
field_to_json(Obj,"rx_packets_bw",rx_packets_bw);
|
|
||||||
field_to_json(Obj,"tx_packets_bw",tx_packets_bw);
|
|
||||||
field_to_json(Obj,"rx_errors_pct",rx_errors_pct);
|
|
||||||
field_to_json(Obj,"tx_errors_pct",tx_errors_pct);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeviceTimePointAnalysis::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"noise",noise);
|
|
||||||
field_from_json(Obj,"temperature",temperature);
|
|
||||||
field_from_json(Obj,"active_pct",active_pct);
|
|
||||||
field_from_json(Obj,"busy_pct",busy_pct);
|
|
||||||
field_from_json(Obj,"receive_pct",receive_pct);
|
|
||||||
field_from_json(Obj,"transmit_pct",transmit_pct);
|
|
||||||
field_from_json(Obj,"tx_power",tx_power);
|
|
||||||
field_from_json(Obj,"tx_bytes_bw",tx_bytes_bw);
|
|
||||||
field_from_json(Obj,"rx_bytes_bw",rx_bytes_bw);
|
|
||||||
field_from_json(Obj,"rx_dropped_pct",rx_dropped_pct);
|
|
||||||
field_from_json(Obj,"tx_dropped_pct",tx_dropped_pct);
|
|
||||||
field_from_json(Obj,"rx_packets_bw",rx_packets_bw);
|
|
||||||
field_from_json(Obj,"tx_packets_bw",tx_packets_bw);
|
|
||||||
field_from_json(Obj,"rx_errors_pct",rx_errors_pct);
|
|
||||||
field_from_json(Obj,"tx_errors_pct",tx_errors_pct);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceTimePointList::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"points",points);
|
|
||||||
field_to_json(Obj,"stats",stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeviceTimePointList::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"points",points);
|
|
||||||
field_from_json(Obj,"stats",stats);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceTimePointStats::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"firstPoint",firstPoint);
|
|
||||||
field_to_json(Obj,"lastPoint",lastPoint);
|
|
||||||
field_to_json(Obj,"count",count);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeviceTimePointStats::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"firstPoint",firstPoint);
|
|
||||||
field_from_json(Obj,"lastPoint",lastPoint);
|
|
||||||
field_from_json(Obj,"count",count);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WifiClientRate::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"bitrate",bitrate);
|
|
||||||
field_to_json(Obj,"chwidth",chwidth);
|
|
||||||
field_to_json(Obj,"mcs",mcs);
|
|
||||||
field_to_json(Obj,"nss",nss);
|
|
||||||
field_to_json(Obj,"vht",vht);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WifiClientRate::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"bitrate",bitrate);
|
|
||||||
field_from_json(Obj,"chwidth",chwidth);
|
|
||||||
field_from_json(Obj,"mcs",mcs);
|
|
||||||
field_from_json(Obj,"nss",nss);
|
|
||||||
field_from_json(Obj,"vht",vht);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WifiClientHistory::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj,"timestamp",timestamp);
|
|
||||||
field_to_json(Obj,"stationId",stationId);
|
|
||||||
field_to_json(Obj,"bssId",bssId);
|
|
||||||
field_to_json(Obj,"ssid",ssid);
|
|
||||||
field_to_json(Obj,"rssi",rssi);
|
|
||||||
field_to_json(Obj,"rx_bitrate",rx_bitrate);
|
|
||||||
field_to_json(Obj,"rx_chwidth",rx_chwidth);
|
|
||||||
field_to_json(Obj,"rx_mcs",rx_mcs);
|
|
||||||
field_to_json(Obj,"rx_nss",rx_nss);
|
|
||||||
field_to_json(Obj,"rx_vht",rx_vht);
|
|
||||||
field_to_json(Obj,"tx_bitrate",tx_bitrate);
|
|
||||||
field_to_json(Obj,"tx_chwidth",tx_chwidth);
|
|
||||||
field_to_json(Obj,"tx_mcs",tx_mcs);
|
|
||||||
field_to_json(Obj,"tx_nss",tx_nss);
|
|
||||||
field_to_json(Obj,"tx_vht",tx_vht);
|
|
||||||
field_to_json(Obj,"rx_bytes",rx_bytes);
|
|
||||||
field_to_json(Obj,"tx_bytes",tx_bytes);
|
|
||||||
field_to_json(Obj,"rx_duration",rx_duration);
|
|
||||||
field_to_json(Obj,"tx_duration",tx_duration);
|
|
||||||
field_to_json(Obj,"rx_packets",rx_packets);
|
|
||||||
field_to_json(Obj,"tx_packets",tx_packets);
|
|
||||||
field_to_json(Obj,"ipv4",ipv4);
|
|
||||||
field_to_json(Obj,"ipv6",ipv6);
|
|
||||||
field_to_json(Obj,"channel_width",channel_width);
|
|
||||||
field_to_json(Obj,"noise",noise);
|
|
||||||
field_to_json(Obj,"tx_power",tx_power);
|
|
||||||
field_to_json(Obj,"channel",channel);
|
|
||||||
field_to_json(Obj,"active_ms",active_ms);
|
|
||||||
field_to_json(Obj,"busy_ms",busy_ms);
|
|
||||||
field_to_json(Obj,"receive_ms",receive_ms);
|
|
||||||
field_to_json(Obj,"mode",mode);
|
|
||||||
field_to_json(Obj,"ack_signal",ack_signal);
|
|
||||||
field_to_json(Obj,"ack_signal_avg",ack_signal_avg);
|
|
||||||
field_to_json(Obj,"connected",connected);
|
|
||||||
field_to_json(Obj,"inactive",inactive);
|
|
||||||
field_to_json(Obj,"tx_retries",tx_retries);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WifiClientHistory::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj,"timestamp",timestamp);
|
|
||||||
field_from_json(Obj,"stationId",stationId);
|
|
||||||
field_from_json(Obj,"bssId",bssId);
|
|
||||||
field_from_json(Obj,"ssid",ssid);
|
|
||||||
field_from_json(Obj,"rssi",rssi);
|
|
||||||
field_from_json(Obj,"rx_bitrate",rx_bitrate);
|
|
||||||
field_from_json(Obj,"rx_chwidth",rx_chwidth);
|
|
||||||
field_from_json(Obj,"rx_mcs",rx_mcs);
|
|
||||||
field_from_json(Obj,"rx_nss",rx_nss);
|
|
||||||
field_from_json(Obj,"rx_vht",rx_vht);
|
|
||||||
field_from_json(Obj,"tx_bitrate",tx_bitrate);
|
|
||||||
field_from_json(Obj,"tx_chwidth",tx_chwidth);
|
|
||||||
field_from_json(Obj,"tx_mcs",tx_mcs);
|
|
||||||
field_from_json(Obj,"tx_nss",tx_nss);
|
|
||||||
field_from_json(Obj,"tx_vht",tx_vht);
|
|
||||||
field_from_json(Obj,"rx_bytes",rx_bytes);
|
|
||||||
field_from_json(Obj,"tx_bytes",tx_bytes);
|
|
||||||
field_from_json(Obj,"rx_duration",rx_duration);
|
|
||||||
field_from_json(Obj,"tx_duration",tx_duration);
|
|
||||||
field_from_json(Obj,"rx_packets",rx_packets);
|
|
||||||
field_from_json(Obj,"tx_packets",tx_packets);
|
|
||||||
field_from_json(Obj,"ipv4",ipv4);
|
|
||||||
field_from_json(Obj,"ipv6",ipv6);
|
|
||||||
field_from_json(Obj,"channel_width",channel_width);
|
|
||||||
field_from_json(Obj,"noise",noise);
|
|
||||||
field_from_json(Obj,"tx_power",tx_power);
|
|
||||||
field_from_json(Obj,"channel",channel);
|
|
||||||
field_from_json(Obj,"active_ms",active_ms);
|
|
||||||
field_from_json(Obj,"busy_ms",busy_ms);
|
|
||||||
field_from_json(Obj,"receive_ms",receive_ms);
|
|
||||||
field_from_json(Obj,"mode",mode);
|
|
||||||
field_from_json(Obj,"ack_signal",ack_signal);
|
|
||||||
field_from_json(Obj,"ack_signal_avg",ack_signal_avg);
|
|
||||||
field_from_json(Obj,"connected",connected);
|
|
||||||
field_from_json(Obj,"inactive",inactive);
|
|
||||||
field_from_json(Obj,"tx_retries",tx_retries);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,421 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by stephane bourque on 2022-01-10.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "RESTAPI_ProvObjects.h"
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
namespace AnalyticsObjects {
|
|
||||||
|
|
||||||
struct Report {
|
|
||||||
uint64_t snapShot = 0;
|
|
||||||
|
|
||||||
void reset();
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VenueInfo {
|
|
||||||
OpenWifi::Types::UUID_t id;
|
|
||||||
std::string name;
|
|
||||||
std::string description;
|
|
||||||
uint64_t retention = 0;
|
|
||||||
uint64_t interval = 0;
|
|
||||||
bool monitorSubVenues = false;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BoardInfo {
|
|
||||||
ProvObjects::ObjectInfo info;
|
|
||||||
std::vector<VenueInfo> venueList;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
|
|
||||||
inline bool operator<(const BoardInfo &bb) const {
|
|
||||||
return info.id < bb.info.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator==(const BoardInfo &bb) const {
|
|
||||||
return info.id == bb.info.id;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DeviceInfo {
|
|
||||||
std::string boardId;
|
|
||||||
std::string type;
|
|
||||||
std::string serialNumber;
|
|
||||||
std::string deviceType;
|
|
||||||
uint64_t lastContact = 0 ;
|
|
||||||
uint64_t lastPing = 0;
|
|
||||||
uint64_t lastState = 0;
|
|
||||||
std::string lastFirmware;
|
|
||||||
uint64_t lastFirmwareUpdate = 0;
|
|
||||||
uint64_t lastConnection = 0;
|
|
||||||
uint64_t lastDisconnection = 0;
|
|
||||||
uint64_t pings = 0;
|
|
||||||
uint64_t states = 0;
|
|
||||||
bool connected = false;
|
|
||||||
std::string connectionIp;
|
|
||||||
uint64_t associations_2g = 0;
|
|
||||||
uint64_t associations_5g = 0;
|
|
||||||
uint64_t associations_6g = 0;
|
|
||||||
uint64_t health = 0;
|
|
||||||
uint64_t lastHealth = 0;
|
|
||||||
std::string locale;
|
|
||||||
uint64_t uptime = 0;
|
|
||||||
double memory = 0.0;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DeviceInfoList {
|
|
||||||
std::vector<DeviceInfo> devices;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
enum wifi_band {
|
|
||||||
band_2g = 0, band_5g = 1, band_6g = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TIDstat_entry {
|
|
||||||
uint64_t rx_msdu = 0,
|
|
||||||
tx_msdu = 0,
|
|
||||||
tx_msdu_failed = 0,
|
|
||||||
tx_msdu_retries = 0;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct UE_rate {
|
|
||||||
uint64_t bitrate=0;
|
|
||||||
uint64_t mcs=0;
|
|
||||||
uint64_t nss=0;
|
|
||||||
bool ht=false;
|
|
||||||
bool sgi=false;
|
|
||||||
uint64_t chwidth=0;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AveragePoint {
|
|
||||||
double min = 0.0,
|
|
||||||
max = 0.0,
|
|
||||||
avg = 0.0;
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct UETimePoint {
|
|
||||||
std::string station;
|
|
||||||
int64_t rssi = 0;
|
|
||||||
uint64_t tx_bytes = 0,
|
|
||||||
rx_bytes = 0,
|
|
||||||
tx_duration = 0,
|
|
||||||
rx_packets = 0,
|
|
||||||
tx_packets = 0,
|
|
||||||
tx_retries = 0,
|
|
||||||
tx_failed = 0,
|
|
||||||
connected = 0,
|
|
||||||
inactive = 0;
|
|
||||||
|
|
||||||
double tx_bytes_bw = 0.0 ,
|
|
||||||
rx_bytes_bw = 0.0 ,
|
|
||||||
tx_packets_bw = 0.0 ,
|
|
||||||
rx_packets_bw = 0.0 ,
|
|
||||||
tx_failed_pct = 0.0 ,
|
|
||||||
tx_retries_pct = 0.0 ,
|
|
||||||
tx_duration_pct = 0.0;
|
|
||||||
|
|
||||||
uint64_t tx_bytes_delta = 0,
|
|
||||||
rx_bytes_delta = 0,
|
|
||||||
tx_duration_delta = 0,
|
|
||||||
rx_packets_delta = 0,
|
|
||||||
tx_packets_delta = 0,
|
|
||||||
tx_retries_delta = 0,
|
|
||||||
tx_failed_delta = 0;
|
|
||||||
|
|
||||||
UE_rate tx_rate,
|
|
||||||
rx_rate;
|
|
||||||
std::vector<TIDstat_entry> tidstats;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
enum SSID_MODES {
|
|
||||||
unknown = 0,
|
|
||||||
ap,
|
|
||||||
mesh,
|
|
||||||
sta,
|
|
||||||
wds_ap,
|
|
||||||
wds_sta,
|
|
||||||
wds_repeater
|
|
||||||
};
|
|
||||||
|
|
||||||
inline SSID_MODES SSID_Mode(const std::string &m) {
|
|
||||||
if (m == "ap")
|
|
||||||
return ap;
|
|
||||||
if (m == "sta")
|
|
||||||
return sta;
|
|
||||||
if (m == "mesh")
|
|
||||||
return mesh;
|
|
||||||
if (m == "wds-ap")
|
|
||||||
return wds_ap;
|
|
||||||
if (m == "wds-sta")
|
|
||||||
return wds_sta;
|
|
||||||
if (m == "wds-repeater")
|
|
||||||
return wds_repeater;
|
|
||||||
return unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SSIDTimePoint {
|
|
||||||
std::string bssid,
|
|
||||||
mode,
|
|
||||||
ssid;
|
|
||||||
uint64_t band=0,
|
|
||||||
channel=0;
|
|
||||||
std::vector<UETimePoint> associations;
|
|
||||||
|
|
||||||
AveragePoint tx_bytes_bw,
|
|
||||||
rx_bytes_bw,
|
|
||||||
tx_packets_bw,
|
|
||||||
rx_packets_bw,
|
|
||||||
tx_failed_pct,
|
|
||||||
tx_retries_pct,
|
|
||||||
tx_duration_pct;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct APTimePoint {
|
|
||||||
uint64_t collisions = 0,
|
|
||||||
multicast = 0,
|
|
||||||
rx_bytes = 0,
|
|
||||||
rx_dropped = 0,
|
|
||||||
rx_errors = 0,
|
|
||||||
rx_packets = 0,
|
|
||||||
tx_bytes = 0,
|
|
||||||
tx_dropped = 0,
|
|
||||||
tx_errors = 0,
|
|
||||||
tx_packets = 0;
|
|
||||||
|
|
||||||
double tx_bytes_bw = 0.0 ,
|
|
||||||
rx_bytes_bw = 0.0 ,
|
|
||||||
rx_dropped_pct = 0.0,
|
|
||||||
tx_dropped_pct = 0.0,
|
|
||||||
rx_packets_bw = 0.0,
|
|
||||||
tx_packets_bw = 0.0,
|
|
||||||
rx_errors_pct = 0.0 ,
|
|
||||||
tx_errors_pct = 0.0;
|
|
||||||
|
|
||||||
uint64_t tx_bytes_delta = 0,
|
|
||||||
rx_bytes_delta = 0 ,
|
|
||||||
rx_dropped_delta = 0,
|
|
||||||
tx_dropped_delta = 0,
|
|
||||||
rx_packets_delta = 0,
|
|
||||||
tx_packets_delta = 0,
|
|
||||||
rx_errors_delta = 0,
|
|
||||||
tx_errors_delta = 0;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct RadioTimePoint {
|
|
||||||
uint64_t band = 0,
|
|
||||||
channel_width = 0;
|
|
||||||
uint64_t active_ms = 0,
|
|
||||||
busy_ms = 0,
|
|
||||||
receive_ms = 0,
|
|
||||||
transmit_ms = 0,
|
|
||||||
tx_power = 0,
|
|
||||||
channel = 0;
|
|
||||||
int64_t temperature = 0,
|
|
||||||
noise = 0;
|
|
||||||
|
|
||||||
double active_pct = 0.0 ,
|
|
||||||
busy_pct = 0.0,
|
|
||||||
receive_pct = 0.0,
|
|
||||||
transmit_pct = 0.0;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct DeviceTimePoint {
|
|
||||||
std::string id;
|
|
||||||
std::string boardId;
|
|
||||||
uint64_t timestamp = 0;
|
|
||||||
APTimePoint ap_data;
|
|
||||||
std::vector<SSIDTimePoint> ssid_data;
|
|
||||||
std::vector<RadioTimePoint> radio_data;
|
|
||||||
AnalyticsObjects::DeviceInfo device_info;
|
|
||||||
std::string serialNumber;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
|
|
||||||
inline bool operator<(const DeviceTimePoint &rhs) const {
|
|
||||||
if(timestamp < rhs.timestamp)
|
|
||||||
return true;
|
|
||||||
if(timestamp > rhs.timestamp)
|
|
||||||
return false;
|
|
||||||
if(device_info.serialNumber < rhs.device_info.serialNumber)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator==(const DeviceTimePoint &rhs) const {
|
|
||||||
return timestamp==rhs.timestamp && device_info.serialNumber==rhs.device_info.serialNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator>(const DeviceTimePoint &rhs) const {
|
|
||||||
if(timestamp > rhs.timestamp)
|
|
||||||
return true;
|
|
||||||
if(timestamp < rhs.timestamp)
|
|
||||||
return false;
|
|
||||||
if(device_info.serialNumber > rhs.device_info.serialNumber)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DeviceTimePointAnalysis {
|
|
||||||
uint64_t timestamp;
|
|
||||||
|
|
||||||
AveragePoint noise;
|
|
||||||
AveragePoint temperature;
|
|
||||||
AveragePoint active_pct;
|
|
||||||
AveragePoint busy_pct;
|
|
||||||
AveragePoint receive_pct;
|
|
||||||
AveragePoint transmit_pct;
|
|
||||||
AveragePoint tx_power;
|
|
||||||
|
|
||||||
AveragePoint tx_bytes_bw;
|
|
||||||
AveragePoint rx_bytes_bw;
|
|
||||||
AveragePoint rx_dropped_pct;
|
|
||||||
AveragePoint tx_dropped_pct;
|
|
||||||
AveragePoint rx_packets_bw;
|
|
||||||
AveragePoint tx_packets_bw;
|
|
||||||
AveragePoint rx_errors_pct;
|
|
||||||
AveragePoint tx_errors_pct;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DeviceTimePointList {
|
|
||||||
std::vector<DeviceTimePoint> points;
|
|
||||||
std::vector<DeviceTimePointAnalysis> stats;
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BandwidthAnalysisEntry {
|
|
||||||
uint64_t timestamp = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BandwidthAnalysis {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AverageValueSigned {
|
|
||||||
int64_t peak=0, avg=0, low=0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AverageValueUnsigned {
|
|
||||||
uint64_t peak=0, avg=0, low=0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct RadioAnalysis {
|
|
||||||
uint64_t timestamp=0;
|
|
||||||
AverageValueSigned noise, temperature;
|
|
||||||
AverageValueUnsigned active_ms,
|
|
||||||
busy_ms,
|
|
||||||
transmit_ms,
|
|
||||||
receive_ms;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DeviceTimePointStats {
|
|
||||||
uint64_t firstPoint=0;
|
|
||||||
uint64_t lastPoint=0;
|
|
||||||
uint64_t count=0;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct WifiClientRate {
|
|
||||||
uint32_t bitrate=0;
|
|
||||||
uint32_t chwidth=0;
|
|
||||||
uint16_t mcs=0;
|
|
||||||
uint16_t nss=0;
|
|
||||||
bool vht=false;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct WifiClientHistory {
|
|
||||||
uint64_t timestamp=OpenWifi::Now();
|
|
||||||
std::string stationId;
|
|
||||||
std::string bssId;
|
|
||||||
std::string ssid;
|
|
||||||
int64_t rssi=0;
|
|
||||||
uint32_t rx_bitrate=0;
|
|
||||||
uint32_t rx_chwidth=0;
|
|
||||||
uint16_t rx_mcs=0;
|
|
||||||
uint16_t rx_nss=0;
|
|
||||||
bool rx_vht=false;
|
|
||||||
uint32_t tx_bitrate=0;
|
|
||||||
uint32_t tx_chwidth=0;
|
|
||||||
uint16_t tx_mcs=0;
|
|
||||||
uint16_t tx_nss=0;
|
|
||||||
bool tx_vht=false;
|
|
||||||
uint64_t rx_bytes=0;
|
|
||||||
uint64_t tx_bytes=0;
|
|
||||||
uint64_t rx_duration=0;
|
|
||||||
uint64_t tx_duration=0;
|
|
||||||
uint64_t rx_packets=0;
|
|
||||||
uint64_t tx_packets=0;
|
|
||||||
std::string ipv4;
|
|
||||||
std::string ipv6;
|
|
||||||
uint64_t channel_width=0;
|
|
||||||
int64_t noise=0;
|
|
||||||
uint64_t tx_power=0;
|
|
||||||
uint64_t channel=0;
|
|
||||||
uint64_t active_ms=0;
|
|
||||||
uint64_t busy_ms=0;
|
|
||||||
uint64_t receive_ms=0;
|
|
||||||
std::string mode;
|
|
||||||
int64_t ack_signal=0;
|
|
||||||
int64_t ack_signal_avg=0;
|
|
||||||
uint64_t connected=0;
|
|
||||||
uint64_t inactive=0;
|
|
||||||
uint64_t tx_retries=0;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -236,7 +236,7 @@ namespace OpenWifi::FMSObjects {
|
|||||||
snapshot = std::time(nullptr);
|
snapshot = std::time(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceReport::from_json([[maybe_unused]] const Poco::JSON::Object::Ptr &Obj) {
|
bool DeviceReport::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -245,32 +245,4 @@ namespace OpenWifi::FMSObjects {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceInformation::to_json(Poco::JSON::Object &Obj) const {
|
|
||||||
field_to_json(Obj, "serialNumber",serialNumber);
|
|
||||||
field_to_json(Obj, "history", history);
|
|
||||||
field_to_json(Obj, "currentFirmware", currentFirmware);
|
|
||||||
field_to_json(Obj, "currentFirmwareDate", currentFirmwareDate);
|
|
||||||
field_to_json(Obj, "latestFirmware", latestFirmware);
|
|
||||||
field_to_json(Obj, "latestFirmwareDate", latestFirmwareDate);
|
|
||||||
field_to_json(Obj, "latestFirmwareAvailable",latestFirmwareAvailable);
|
|
||||||
field_to_json(Obj, "latestFirmwareURI",latestFirmwareURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeviceInformation::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
|
||||||
try {
|
|
||||||
field_from_json(Obj, "serialNumber",serialNumber);
|
|
||||||
field_from_json(Obj, "history", history);
|
|
||||||
field_from_json(Obj, "currentFirmware", currentFirmware);
|
|
||||||
field_from_json(Obj, "currentFirmwareDate", currentFirmwareDate);
|
|
||||||
field_from_json(Obj, "latestFirmware", latestFirmware);
|
|
||||||
field_from_json(Obj, "latestFirmwareDate", latestFirmwareDate);
|
|
||||||
field_from_json(Obj, "latestFirmwareAvailable",latestFirmwareAvailable);
|
|
||||||
field_from_json(Obj, "latestFirmwareURI",latestFirmwareURI);
|
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,20 +127,6 @@ namespace OpenWifi::FMSObjects {
|
|||||||
void reset();
|
void reset();
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DeviceInformation {
|
|
||||||
std::string serialNumber;
|
|
||||||
RevisionHistoryEntryList history;
|
|
||||||
std::string currentFirmware;
|
|
||||||
uint64_t currentFirmwareDate=0;
|
|
||||||
std::string latestFirmware;
|
|
||||||
uint64_t latestFirmwareDate=0;
|
|
||||||
bool latestFirmwareAvailable;
|
|
||||||
std::string latestFirmwareURI;
|
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
|
||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user