Compare commits

...

57 Commits

Author SHA1 Message Date
TIP Automation User
a63dec7f8b Chg: update image tag in helm values to v2.10.0 2023-06-30 15:30:50 +00:00
TIP Automation User
9c5ed40d57 Chg: update image tag in helm values to v2.10.0-RC2 2023-06-21 16:24:32 +00:00
Stephane Bourque
e1ec4d9491 Merge pull request #90 from Telecominfraproject/main
https://telecominfraproject.atlassian.net/browse/WIFI-12689
2023-06-20 09:02:22 -07:00
Stephane Bourque
0437031d78 Merge pull request #89 from pcosmo/patch-1
Update owprov.yaml
2023-06-20 09:00:19 -07:00
stephb9959
2242b02f0f https://telecominfraproject.atlassian.net/browse/WIFI-12689
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-06-20 08:42:15 -07:00
pcosmo
8287628583 Update owprov.yaml
Fixed typo in configuration commands, e.g.:

 getCponfiguration -> getConfiguration
2023-06-15 11:29:11 -04:00
TIP Automation User
f925ce12be Chg: update image tag in helm values to v2.10.0-RC1 2023-06-09 13:34:31 +00:00
stephb9959
7b3de5d5ef https://telecominfraproject.atlassian.net/browse/WIFI-12525
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-05-18 09:01:31 -07:00
stephb9959
6007c1f06f https://telecominfraproject.atlassian.net/browse/WIFI-12597
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-05-11 07:32:22 -07:00
stephb9959
74916abdbd https://telecominfraproject.atlassian.net/browse/WIFI-12525
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-05-03 07:50:37 -07:00
stephb9959
0899c6f2d9 https://telecominfraproject.atlassian.net/browse/WIFI-12525
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-04-19 14:09:37 -07:00
stephb9959
f51b2bd11e https://telecominfraproject.atlassian.net/browse/WIFI-12525
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-04-19 14:03:43 -07:00
stephb9959
8b21ef16a1 https://telecominfraproject.atlassian.net/browse/WIFI-12525
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-04-19 14:03:31 -07:00
stephb9959
7ad4de4960 https://telecominfraproject.atlassian.net/browse/WIFI-12361
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-03-08 09:32:14 -08:00
stephb9959
c5e63ce95b https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-03-02 11:12:46 -08:00
stephb9959
ba3607bd87 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-03-02 09:54:00 -08:00
stephb9959
ba526f85a8 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-03-02 09:16:14 -08:00
stephb9959
ecea2a1fb4 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-03-02 09:10:29 -08:00
stephb9959
e2e5687b47 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-03-01 10:11:06 -08:00
stephb9959
5c0150b81c https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-28 07:33:35 -08:00
stephb9959
ea4b1677f4 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-27 22:22:31 -08:00
stephb9959
38b9d6c231 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-27 22:17:02 -08:00
stephb9959
a7fa58b72a https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-27 22:09:37 -08:00
stephb9959
8e014eaeba https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-27 22:06:39 -08:00
stephb9959
3c6730ee44 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-27 22:03:55 -08:00
stephb9959
a8dec654eb https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-26 22:42:02 -08:00
stephb9959
f722389f74 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-24 23:24:55 -08:00
stephb9959
54518912a3 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-24 23:17:27 -08:00
stephb9959
5bf58812a1 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-24 22:48:35 -08:00
stephb9959
de364a1ffe https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-24 22:31:34 -08:00
stephb9959
593bee9a94 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-23 12:58:30 -08:00
stephb9959
d431e777a1 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-23 12:28:21 -08:00
stephb9959
d3639cf5a0 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-21 22:58:55 -08:00
stephb9959
8424910f0e https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-21 13:45:49 -08:00
stephb9959
ac6780d094 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-21 13:34:41 -08:00
stephb9959
bf6f5389d7 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-15 08:30:53 -08:00
stephb9959
3c8400ba97 https://telecominfraproject.atlassian.net/browse/WIFI-12225
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-09 09:35:06 -08:00
stephb9959
8957fde7bd https://telecominfraproject.atlassian.net/browse/WIFI-12225
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-08 21:02:05 -08:00
Stephane Bourque
a1dc0b38cc Merge pull request #87 from Telecominfraproject/WIFI-12225
https://telecominfraproject.atlassian.net/browse/WIFI-12225
2023-02-08 20:59:56 -08:00
stephb9959
a25b90ec82 https://telecominfraproject.atlassian.net/browse/WIFI-12225
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-08 20:59:13 -08:00
stephb9959
315cbaf3c1 https://telecominfraproject.atlassian.net/browse/WIFI-12225
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-08 20:56:28 -08:00
stephb9959
1ca3c0ade4 https://telecominfraproject.atlassian.net/browse/WIFI-12225
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-08 20:52:54 -08:00
Stephane Bourque
93224f609f Merge pull request #86 from Telecominfraproject/WIFI-12225
https://telecominfraproject.atlassian.net/browse/WIFI-12225
2023-02-08 20:40:31 -08:00
stephb9959
cb2f9a91b5 https://telecominfraproject.atlassian.net/browse/WIFI-12225
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-08 20:38:05 -08:00
stephb9959
865ad612e6 https://telecominfraproject.atlassian.net/browse/WIFI-12225
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-02-06 22:15:06 -08:00
Stephane Bourque
19b4f9edd1 Merge pull request #85 from Telecominfraproject/WIFI-12225
https://telecominfraproject.atlassian.net/browse/WIFI-12225
2023-01-26 21:44:51 -08:00
stephb9959
350553bd86 https://telecominfraproject.atlassian.net/browse/WIFI-12225
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-01-26 21:44:10 -08:00
Stephane Bourque
3b45abd604 Merge pull request #84 from Telecominfraproject/WIFI-12225
https://telecominfraproject.atlassian.net/browse/WIFI-12225
2023-01-26 21:39:38 -08:00
stephb9959
df2f5bb21b https://telecominfraproject.atlassian.net/browse/WIFI-12225
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-01-26 21:38:42 -08:00
Stephane Bourque
b1a489fa8f Merge pull request #83 from Telecominfraproject/WIFI-12225
https://telecominfraproject.atlassian.net/browse/WIFI-12225
2023-01-26 21:30:53 -08:00
stephb9959
9235bf7b73 https://telecominfraproject.atlassian.net/browse/WIFI-12225
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-01-26 21:29:05 -08:00
stephb9959
0b35942ef6 https://telecominfraproject.atlassian.net/browse/WIFI-12225
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-01-26 21:14:57 -08:00
stephb9959
d5e0687ade https://telecominfraproject.atlassian.net/browse/WIFI-10392
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-01-25 16:39:00 -08:00
stephb9959
b54a914c0d https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-01-24 21:37:10 -08:00
stephb9959
3e03b127fe https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-01-10 21:49:49 -08:00
stephb9959
15f91dc667 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	build
2023-01-08 10:57:53 -08:00
stephb9959
3e9663bcf4 https://telecominfraproject.atlassian.net/browse/WIFI-12068
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2023-01-08 10:57:42 -08:00
260 changed files with 24052 additions and 21553 deletions

178
.clang-format Normal file
View File

@@ -0,0 +1,178 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: true
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Always
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

190
BUILDING.md Normal file
View File

@@ -0,0 +1,190 @@
# Building from source
In order to build the OWPROV, you will need to install its dependencies, which includes the following:
- cmake
- boost
- POCO 1.10.1 or later
- a C++17 compiler
- openssl
- libpq-dev (PortgreSQL development libraries)
- mysql-client (MySQL client)
- librdkafka
- cppkafka
The build is done in 2 parts. The first part is to build a local copy of the framework tailored to your environment. This
framework is called [Poco](https://github.com/pocoproject/poco). The version used in this project has a couple of fixes
from the master copy needed for cmake. Please use the version of this [Poco fix](https://github.com/AriliaWireless/poco). Building
Poco may take several minutes depending on the platform you are building on.
## Ubuntu
These instructions have proven to work on Ubuntu 20.4.
```bash
sudo apt install git cmake g++ libssl-dev libmariadb-dev
sudo apt install libpq-dev libaprutil1-dev apache2-dev libboost-all-dev
sudo apt install librdkafka-dev // default-libmysqlclient-dev
sudo apt install nlohmann-json-dev
cd ~
git clone https://github.com/AriliaWireless/poco --branch poco-tip-v1
cd poco
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
cd ~
git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1
cd cppkafka
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
cd ~
git clone https://github.com/AriliaWireless/valijson --branch tip-v1
cd valijson
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
git clone https://github.com/fmtlib/fmt --branch 9.0.0 /fmtlib
cd fmtlib
mkdir cmake-build
cd cmake-build
cmake ..
make
make install
cd ~
git clone https://github.com/Telecominfraproject/wlan-cloud-owprov
cd wlan-cloud-owprov
mkdir cmake-build
cd cmake-build
cmake ..
make -j 8
```
## Fedora
The following instructions have proven to work on Fedora 33
```bash
sudo yum install cmake g++ openssl-devel mysql-devel mysql apr-util-devel boost boost-devel
sudo yum install yaml-cpp-devel lua-devel
sudo dnf install postgresql.x86_64 librdkafka-devel
sudo dnf install postgresql-devel json-devel
git clone https://github.com/AriliaWireless/poco --branch poco-tip-v1
cd poco
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1
cd cppkafka
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
cd ~
git clone https://github.com/AriliaWireless/valijson --branch tip-v1
cd valijson
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
cd ~
git clone https://github.com/Telecominfraproject/wlan-cloud-owprov
cd wlan-cloud-owprov
mkdir cmake-build
cd cmake-build
cmake ..
make
```
## macOS Build
The following instructions have proven to work on macOS Big Sur. You need to install [Homebrew](https://brew.sh/). You must also have installed [XCode for OS X](https://www.freecodecamp.org/news/how-to-download-and-install-xcode/).
```bash
brew install openssl \
cmake \
libpq \
mysql-client \
apr \
apr-util \
boost \
yaml-cpp \
postgresql \
librdkafka \
nlohmann-json \
fmt
git clone https://github.com/AriliaWireless/poco --branch poco-tip-v1
pushd poco
mkdir cmake-build
push cmake-build
cmake -DOPENSSL_ROOT_DIR=</path/to/openssl> -DENABLE_NETSSL=1 -DENABLE_JWT=1 -DENABLE_CRYPTO=1 ..
cmake --build . --config Release
sudo cmake --build . --target install
popd
popd
git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1
pushd cppkafka
mkdir cmake-build
pushd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
popd
popd
git clone https://github.com/AriliaWireless/valijson --branch tip-v1
cd valijson
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
popd
popd
git clone https://github.com/Telecominfraproject/wlan-cloud-owprov
pushd wlan-cloud-owprov
mkdir cmake-build
pushd cmake-build
cmake ..
make -j
popd
popd
```
## Raspberry
The build on a rPI takes a while. You can shorten that build time and requirements by disabling all the larger database
support. You can build with only SQLite support by not installing the packages for PostgreSQL, and MySQL by
adding -DSMALL_BUILD=1 on the cmake build line.
```bash
sudo apt install git cmake g++ libssl-dev libaprutil1-dev apache2-dev libboost-all-dev libyaml-cpp-dev
git clone https://github.com/stephb9959/poco
cd poco
mkdir cmake-build
cd cmake-build
cmake ..
cmake --build . --config Release
sudo cmake --build . --target install
cd ~
git clone https://github.com/Telecominfraproject/wlan-cloud-owprov
cd wlan-cloud-owprov
mkdir cmake-build
cd cmake-build
cmake -DSMALL_BUILD=1 ..
make
```

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
project(owprov VERSION 2.8.0) project(owprov VERSION 2.10.0)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
@@ -43,8 +43,8 @@ find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
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(fmt REQUIRED) find_package(fmt REQUIRED)
# find_package(valijson 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)
@@ -117,6 +117,7 @@ add_executable(owprov
src/framework/MicroServiceExtra.h src/framework/MicroServiceExtra.h
src/framework/ConfigurationValidator.cpp src/framework/ConfigurationValidator.cpp
src/framework/ConfigurationValidator.h src/framework/ConfigurationValidator.h
src/framework/default_device_types.h
src/UI_Prov_WebSocketNotifications.h src/UI_Prov_WebSocketNotifications.h
src/UI_Prov_WebSocketNotifications.cpp src/UI_Prov_WebSocketNotifications.cpp
src/RESTObjects/RESTAPI_SecurityObjects.h src/RESTObjects/RESTAPI_SecurityObjects.cpp src/RESTObjects/RESTAPI_SecurityObjects.h src/RESTObjects/RESTAPI_SecurityObjects.cpp
@@ -132,6 +133,7 @@ add_executable(owprov
src/Daemon.cpp src/Daemon.h src/Daemon.cpp src/Daemon.h
src/Dashboard.h src/Dashboard.cpp src/Dashboard.h src/Dashboard.cpp
src/StorageService.cpp src/StorageService.h src/StorageService.cpp src/StorageService.h
src/storage/storage_entity.cpp src/storage/storage_entity.h src/storage/storage_entity.cpp src/storage/storage_entity.h
src/storage/storage_policies.cpp src/storage/storage_policies.h src/storage/storage_policies.cpp src/storage/storage_policies.h
src/storage/storage_venue.cpp src/storage/storage_venue.h src/storage/storage_venue.cpp src/storage/storage_venue.h
@@ -141,6 +143,14 @@ add_executable(owprov
src/storage/storage_management_roles.cpp src/storage/storage_management_roles.h src/storage/storage_management_roles.cpp src/storage/storage_management_roles.h
src/storage/storage_configurations.cpp src/storage/storage_configurations.h src/storage/storage_configurations.cpp src/storage/storage_configurations.h
src/storage/storage_tags.cpp src/storage/storage_tags.h src/storage/storage_tags.cpp src/storage/storage_tags.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/storage/storage_maps.cpp src/storage/storage_maps.h
src/storage/storage_signup.cpp src/storage/storage_signup.h
src/storage/storage_variables.cpp src/storage/storage_variables.h
src/storage/storage_overrides.cpp src/storage/storage_overrides.h
src/RESTAPI/RESTAPI_entity_handler.cpp src/RESTAPI/RESTAPI_entity_handler.h src/RESTAPI/RESTAPI_entity_handler.cpp src/RESTAPI/RESTAPI_entity_handler.h
src/RESTAPI/RESTAPI_contact_handler.cpp src/RESTAPI/RESTAPI_contact_handler.h src/RESTAPI/RESTAPI_contact_handler.cpp src/RESTAPI/RESTAPI_contact_handler.h
src/RESTAPI/RESTAPI_location_handler.cpp src/RESTAPI/RESTAPI_location_handler.h src/RESTAPI/RESTAPI_location_handler.cpp src/RESTAPI/RESTAPI_location_handler.h
@@ -160,6 +170,13 @@ add_executable(owprov
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_signup_handler.h src/RESTAPI/RESTAPI_signup_handler.cpp
src/RESTAPI/RESTAPI_asset_server.cpp src/RESTAPI/RESTAPI_asset_server.h src/RESTAPI/RESTAPI_asset_server.cpp src/RESTAPI/RESTAPI_asset_server.h
src/RESTAPI/RESTAPI_db_helpers.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_variables_handler.cpp src/RESTAPI/RESTAPI_variables_handler.h
src/RESTAPI/RESTAPI_variables_list_handler.cpp src/RESTAPI/RESTAPI_variables_list_handler.h
src/RESTAPI/RESTAPI_overrides_handler.cpp src/RESTAPI/RESTAPI_overrides_handler.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
@@ -169,25 +186,14 @@ add_executable(owprov
src/AutoDiscovery.cpp src/AutoDiscovery.h src/AutoDiscovery.cpp src/AutoDiscovery.h
src/ConfigSanityChecker.cpp src/ConfigSanityChecker.h src/ConfigSanityChecker.cpp src/ConfigSanityChecker.h
src/TagServer.cpp src/TagServer.h src/TagServer.cpp src/TagServer.h
src/RESTAPI/RESTAPI_db_helpers.h
src/JobController.cpp src/JobController.h src/JobController.cpp src/JobController.h
src/JobRegistrations.cpp src/JobRegistrations.cpp
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_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/Signup.cpp src/Signup.h
src/DeviceTypeCache.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/FileDownloader.cpp src/FileDownloader.h
src/Tasks/VenueConfigUpdater.h src/Tasks/VenueConfigUpdater.h
src/libs/croncpp.h src/libs/croncpp.h
src/Kafka_ProvUpdater.cpp src/Kafka_ProvUpdater.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_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_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_list_handler.cpp src/RESTAPI/RESTAPI_service_class_list_handler.h
@@ -203,13 +209,12 @@ add_executable(owprov
src/ProvWebSocketClient.cpp src/ProvWebSocketClient.h src/ProvWebSocketClient.cpp src/ProvWebSocketClient.h
src/Tasks/VenueRebooter.h src/Tasks/VenueUpgrade.h src/Tasks/VenueRebooter.h src/Tasks/VenueUpgrade.h
src/sdks/SDK_fms.cpp src/sdks/SDK_fms.h src/sdks/SDK_fms.cpp src/sdks/SDK_fms.h
src/storage/storage_overrides.cpp src/storage/storage_overrides.h src/RESTAPI/RESTAPI_overrides_handler.cpp src/RESTAPI/RESTAPI_overrides_handler.h) src/RESTAPI/RESTAPI_overrides_handler.cpp src/RESTAPI/RESTAPI_overrides_handler.h)
target_link_libraries(owprov PUBLIC target_link_libraries(owprov PUBLIC
${Poco_LIBRARIES} ${Poco_LIBRARIES}
${MySQL_LIBRARIES} ${MySQL_LIBRARIES}
${ZLIB_LIBRARIES} ${ZLIB_LIBRARIES}
CppKafka::cppkafka CppKafka::cppkafka
fmt::fmt fmt::fmt)
nlohmann_json_schema_validator)

243
CONFIGURATION.md Normal file
View File

@@ -0,0 +1,243 @@
# OWPROV Configuration
Here is the list of parameters you can configure in the `owprov.properties` file.
## OWPROV Specific Parameters
### Default firmware management rules
FMS is already integrated with OpenWifi. In order to allow it to upgrade devices automatically, you should
set the following values.
```properties
firmware.updater.upgrade = <true/false>
firmware.updater.releaseonly = <true/false>
```
#### firmware.updater.upgrade
Should FMS attempt to upgrade devices by default.
#### firmware.updater.releaseonly
Should only RC software be used during upgrades.
### Google Map API Key
To support geocoding help, you need to configuration the following in the configuration file. Geocoding is used
when creating location and when reporting analytics.
```properties
geocodeapi = google
google.apikey = ********************************
```
### IP to Country Parameters
The controller has the ability to find the location of the IP of each Access Points. This uses an external IP location service. Currently,
the controller supports 3 services. Please note that these services will require to obtain an API key or token, and these may cause you to incur
additional fees. Here is the list of the services supported:
- ip2location: ip2location.com
- ipdata: ipdata.co
- ipinfo: ipinfo.io
```properties
iptocountry.default = US
iptocountry.provider = ipinfo
#iptocountry.provider = ipdata
#iptocountry.provider = ip2location
iptocountry.ipinfo.token =
iptocountry.ipdata.apikey =
iptocountry.ip2location.apikey =
```
#### iptocountry.default
This is the country code to be used if no information can be found at one of the providers or you have not configured any of the providers.
#### iptocountry.provider
You must select onf of the possible services and the fill the appropriate token or api key parameter.
## Generic OpenWiFi SDK parameters
### REST API External parameters
These are the parameters required for the configuration of the external facing REST API server
```properties
openwifi.restapi.host.0.backlog = 100
openwifi.restapi.host.0.security = relaxed
openwifi.restapi.host.0.rootca = $OWPROV_ROOT/certs/restapi-ca.pem
openwifi.restapi.host.0.address = *
openwifi.restapi.host.0.port = 16004
openwifi.restapi.host.0.cert = $OWPROV_ROOT/certs/restapi-cert.pem
openwifi.restapi.host.0.key = $OWPROV_ROOT/certs/restapi-key.pem
openwifi.restapi.host.0.key.password = mypassword
```
#### openwifi.restapi.host.0.backlog
This is the number of concurrent REST API calls that maybe be kept in the backlog for processing. That's a good rule of thumb. Never go above 500.
#### openwifi.restapi.host.0.rootca
This is the root file of your own certificate CA in `pem` format.
#### openwifi.restapi.host.0.cert
This is your own server certificate in `pem` format..
#### openwifi.restapi.host.0.key
This is the private key associated with your own certificate in `pem` format.
#### openwifi.restapi.host.0.address
Leve this a `*` in the case you want to bind to all interfaces on your gateway host or select the address of a single interface.
#### openwifi.restapi.host.0.port
The port on which the REST API server is listening. By default, this is 16002.
#### openwifi.restapi.host.0.security
Leave this as `relaxed` for now for devices.
#### openwifi.restapi.host.0.key.password
If you key file uses a password, please enter it here.
### REST API Intra microservice parameters
The following parameters describe the configuration for the inter-microservice HTTP server. You may use the same certificate/key
you are using for your extenral server or another certificate.
```properties
openwifi.internal.restapi.host.0.backlog = 100
openwifi.internal.restapi.host.0.security = relaxed
openwifi.internal.restapi.host.0.rootca = $OWPROV_ROOT/certs/restapi-ca.pem
openwifi.internal.restapi.host.0.address = *
openwifi.internal.restapi.host.0.port = 17004
openwifi.internal.restapi.host.0.cert = $OWPROV_ROOT/certs/restapi-cert.pem
openwifi.internal.restapi.host.0.key = $OWPROV_ROOT/certs/restapi-key.pem
openwifi.internal.restapi.host.0.key.password = mypassword
```
#### openwifi.internal.host.0.backlog
This is the number of concurrent REST API calls that maybe be kept in the backlog for processing. That's a good rule of thumb. Never go above 500.
#### openwifi.internal.host.0.rootca
This is the root file of your own certificate CA in `pem` format.
#### openwifi.internal.host.0.cert
This is your own server certificate in `pem` format..
#### openwifi.internal.host.0.key
This is the private key associated with your own certificate in `pem` format.
#### openwifi.internal.host.0.address
Leve this a `*` in the case you want to bind to all interfaces on your gateway host or select the address of a single interface.
#### openwifi.internal.host.0.port
The port on which the REST API server is listening. By default, this is 17002.
#### openwifi.internal.host.0.security
Leave this as `relaxed` for now for devices.
#### openwifi.internal.host.0.key.password
If you key file uses a password, please enter it here.
### Microservice information
These are different Microservie parameters. Following is a brief explanation.
```properties
openwifi.service.key = $OWPROV_ROOT/certs/restapi-key.pem
openwifi.service.key.password = mypassword
openwifi.system.data = $OWPROV_ROOT/data
openwifi.system.uri.private = https://localhost:17004
openwifi.system.uri.public = https://ucentral.example.com:16004
openwifi.system.uri.ui = https://provisionins-ui.example.com
openwifi.security.restapi.disable = false
openwifi.system.commandchannel = /tmp/app.ucentralprov
openwifi.autoprovisioning = true
```
#### openwifi.service.key
From time to time, the microservice must encrypt information. This is the key it should use. You may use the
same keey as you RESTAPI or your server.
#### openwifi.service.key.password
The password for the `openwifi.service.key`
#### openwifi.system.data
The location of system data. This path must exist.
#### openwifi.system.uri.private
The URI to reach the controller on the internal port.
#### openwifi.system.uri.public
The URI to reach the controller from the outside world.
#### openwifi.system.uri.ui
The URI of the UI to manage this service
#### openwifi.security.restapi.disable
This allows to disable security for internal and external API calls. This should only be used if the controller
sits behind an application load balancer that will actually do TLS. Setting this to `true` disables security.
#### openwifi.system.commandchannel
The UNIX socket command channel used by this service.
#### openwifi.autoprovisioning
Allow unknown devices to be provisioned by the system.
### ALB Support
In order to support an application load balancer health check verification, your need to provide the following parameters.
```properties
alb.enable = true
alb.port = 16104
```
### Kafka
The controller use Kafka, like all the other microservices. You must configure the kafka section in order for the
system to work.
```properties
openwifi.kafka.group.id = provisioning
openwifi.kafka.client.id = provisioning1
openwifi.kafka.enable = true
openwifi.kafka.brokerlist = my_Kafka.example.com:9092
openwifi.kafka.auto.commit = false
openwifi.kafka.queue.buffering.max.ms = 50
```
### openwifi.kafka.group.id
The group ID is a single word that should identify the type of service tuning. In the case `provisioning`
### openwifi.kafka.client.id
The client ID is a single service within that group ID. Each participant must have a unique client ID.
### openwifi.kafka.enable
Kafka should always be enabled.
### openwifi.kafka.brokerlist
The list of servers where your Kafka server is running. Comma separated.
### openwifi.kafka.auto.commit
Auto commit flag in Kafka. Leave as `false`.
### openwifi.kafka.queue.buffering.max.ms
Kafka buffering. Leave as `50`.
### Kafka security
If you intend to use SSL, you should look into Kafka Connect and specify the certificates below.
```properties
penwifi.kafka.ssl.ca.location =
openwifi.kafka.ssl.certificate.location =
openwifi.kafka.ssl.key.location =
openwifi.kafka.ssl.key.password =
```
### DB Type
The controller supports 3 types of Database. SQLite should only be used for sites with less than 100 APs or for testing in the lab.
In order to select which database to use, you must set the `storage.type` value to sqlite, postgresql, or mysql.
```properties
storage.type = sqlite
#storage.type = postgresql
#storage.type = mysql
```
### Storage SQLite parameters
Additional parameters to set for SQLite. The only important one is `storage.type.sqlite.db` which is the database name on disk.
```properties
storage.type.sqlite.db = provisioning.db
storage.type.sqlite.idletime = 120
storage.type.sqlite.maxsessions = 128
```
### Storage Postgres
Additional parameters to set if you select Postgres for your database. You must specify `host`, `username`, `password`,
`database`, and `port`.
```properties
storage.type.postgresql.maxsessions = 64
storage.type.postgresql.idletime = 60
storage.type.postgresql.host = localhost
storage.type.postgresql.username = provisioning
storage.type.postgresql.password = provisioning
storage.type.postgresql.database = provisioning
storage.type.postgresql.port = 5432
storage.type.postgresql.connectiontimeout = 60
```
### Storage MySQL/MariaDB
Additional parameters to set if you select mysql for your database. You must specify `host`, `username`, `password`,
`database`, and `port`.
```properties
storage.type.mysql.maxsessions = 64
storage.type.mysql.idletime = 60
storage.type.mysql.host = localhost
storage.type.postgresql.username = provisioning
storage.type.postgresql.password = provisioning
storage.type.postgresql.database = provisioning
storage.type.mysql.port = 3306
storage.type.mysql.connectiontimeout = 60
```
### Logging Parameters
The microservice provides extensive logging. If you would like to keep logging on disk, set the `logging.type = file`. If you only want
console logging, `set logging.type = console`. When selecting file, `logging.path` must exist. `logging.level` sets the
basic logging level for the entire controller. `logging.websocket` disables WebSocket logging.
```properties
logging.type = file
logging.path = $OWPROV_ROOT/logs
logging.level = information
logging.asynch = true
logging.websocket = false
```

38
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,38 @@
# How to Contribute
We'd love to accept your patches and contributions to this project. There are
just a few small guidelines you need to follow.
## Version of C++
This project is based on the C++17 standard and compiles as-is on most platforms
using either clang or g++. Do not use C++21 or C++23 features for now. Some core
libraries used in this project do not support C++21 or C++23 yet.
## Variable Naming
Naming of pretty much anything uses Pascal naming. Longer explicit names using casing.
Member variable naming adds a `_` at the end of the vars. Try to
keep this standard going. Sometimes you must override a base class function and then of course
you need to follow the base class.
## This is a cmake project
This is a cmake project, and you need to adhere to the cmake rules. If you need
to add a package to the CMakeList, you need to ensure that the package is available
on all required platforms and compiles. Remember that this project runs on Linux, OS X,
and the Raspberry PI.
## Licensed packages
When adding a package, you must also state the licensing for the package. MIT, BSD, Apache licenses
are acceptable. No commercial licenses are allowed.
## clang formatting
Please format your code using the included `.clang-format` file included in the project.
```bash
clang-format -i --style=<project root>/.clang-format myfile.cpp
```
## Pull Requests
All submissions, including submissions by project members, require review. We
accept GitHub pull requests. Please create a branch with the Jira name for addressing the issue you are fixing or the
feature you are implementing.
Create a pull-request from the branch into master.

View File

@@ -1,7 +1,7 @@
ARG DEBIAN_VERSION=11.5-slim ARG DEBIAN_VERSION=11.5-slim
ARG POCO_VERSION=poco-tip-v2 ARG POCO_VERSION=poco-tip-v2
ARG CPPKAFKA_VERSION=tip-v1 ARG CPPKAFKA_VERSION=tip-v1
ARG JSON_VALIDATOR_VERSION=2.1.0 ARG VALIJASON_VERSION=tip-v1
FROM debian:$DEBIAN_VERSION AS build-base FROM debian:$DEBIAN_VERSION AS build-base
@@ -39,19 +39,19 @@ RUN cmake ..
RUN cmake --build . --config Release -j8 RUN cmake --build . --config Release -j8
RUN cmake --build . --target install RUN cmake --build . --target install
FROM build-base AS json-schema-validator-build FROM build-base AS valijson-build
ARG JSON_VALIDATOR_VERSION ARG VALIJASON_VERSION
ADD https://api.github.com/repos/pboettch/json-schema-validator/git/refs/tags/${JSON_VALIDATOR_VERSION} version.json ADD https://api.github.com/repos/AriliaWireless/valijson/git/refs/tags/${VALIJASON_VERSION} version.json
RUN git clone https://github.com/pboettch/json-schema-validator --branch ${JSON_VALIDATOR_VERSION} /json-schema-validator RUN git clone https://github.com/AriliaWireless/valijson --branch ${VALIJASON_VERSION} /valijson
WORKDIR /json-schema-validator WORKDIR /valijson
RUN mkdir cmake-build RUN mkdir cmake-build
WORKDIR cmake-build WORKDIR cmake-build
RUN cmake .. RUN cmake ..
RUN make RUN cmake --build . --config Release -j8
RUN make install RUN cmake --build . --target install
FROM build-base AS owprov-build FROM build-base AS owprov-build
@@ -64,8 +64,7 @@ COPY --from=poco-build /usr/local/include /usr/local/include
COPY --from=poco-build /usr/local/lib /usr/local/lib COPY --from=poco-build /usr/local/lib /usr/local/lib
COPY --from=cppkafka-build /usr/local/include /usr/local/include 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=valijson-build /usr/local/include /usr/local/include
COPY --from=json-schema-validator-build /usr/local/lib /usr/local/lib
WORKDIR /owprov WORKDIR /owprov
RUN mkdir cmake-build RUN mkdir cmake-build

112
README.md
View File

@@ -1,16 +1,23 @@
# OpenWiFi Provisioning <p align="center">
<img src="images/project/logo.svg" width="200"/>
</p>
# OpenWiFi Provisioning Service (OWPROV)
## What is it?
The OWPROV is a service for the TIP OpenWiFi CloudSDK (OWSDK).
OWPROV manages groups of access points through the use of entities and vanues. OWPROV, like all other OWSDK microservices, is
defined using an OpenAPI definition and uses the ucentral communication protocol to interact with Access Points. To use
the OWPROV, you either need to [build it](#building) or use the [Docker version](#docker).
## OpenAPI ## OpenAPI
You may get static page with OpenAPI docs generated from the definition on [GitHub Page](https://telecominfraproject.github.io/wlan-cloud-owprov/). You may get static page with OpenAPI docs generated from the definition on [GitHub Page](https://telecominfraproject.github.io/wlan-cloud-owprov/).
Also, you may use [Swagger UI](https://petstore.swagger.io/#/) with OpenAPI definition file raw link (i.e. [latest version file](https://raw.githubusercontent.com/Telecominfraproject/wlan-cloud-owprov/main/openapi/owprov.yaml)) to get interactive docs page.
Also you may use [Swagger UI](https://petstore.swagger.io/#/) with OpenAPI definition file raw link (i.e. [latest version file](https://raw.githubusercontent.com/Telecominfraproject/wlan-cloud-owprov/main/openapi/owprov.yaml)) to get interactive docs page. ## Building
To build the microservice from source, please follow the instructions in [here](./BUILDING.md)
## Build from source. ## Docker
You need: To use the CLoudSDK deployment please follow [here](https://github.com/Telecominfraproject/wlan-cloud-ucentral-deploy)
- https://github.com/pboettch/json-schema-validator.git
- https://github.com/nlohmann/json.git
build and install them.
## Root entity ## Root entity
It's UUID value is 0000-0000-0000. Its parent entity must be empty. It's UUID value is 0000-0000-0000. Its parent entity must be empty.
@@ -51,24 +58,77 @@ You may modify the following fields in the POST
- You may include an array of devices UUIDs - You may include an array of devices UUIDs
- Topology and design cannot be set - Topology and design cannot be set
## Geocoding #### Expected directory layout
To support geocoding help, you need to configuration the following in the configuration file. Geocoding is used From the directory where your cloned source is, you will need to create the `certs`, `logs`, and `uploads` directories.
when creating location and when reporting analytics. ```bash
``` mkdir certs
geocodeapi = google mkdir certs/cas
google.apikey = ********************************** mkdir logs
mkdir uploads
``` ```
Currently, only google Geocoding is supported. Additional methods may be added in the future. You should now have the following:
```text
## Default firmware management rules --+-- certs
FMS is already integrated with OpenWifi. In order to allow it to upgrade devices automatically, you should | +--- cas
set the following values. +-- cmake
``` +-- cmake-build
firmware.updater.upgrade = <true/false> +-- logs
firmware.updater.releaseonly = <true/false> +-- src
+-- test_scripts
+-- openapi
+-- uploads
+-- owsec.properties
``` ```
### firmware.updater.upgrade
Should FMS attempt to upgrade devices by default.
### firmware.updater.releaseonly ### Certificate
Should only RC software be used during upgrades. The OWFMS uses a certificate to provide security for the REST API Certificate to secure the Northbound API.
#### The `certs` directory
For all deployments, you will need the following `certs` directory, populated with the proper files.
```text
certs ---+--- restapi-ca.pem
+--- restapi-cert.pem
+--- restapi-key.pem
```
## Firewall Considerations
| Port | Description | Configurable |
|:------|:-----------------------------------------------|:------------:|
| 16004 | Default port for REST API Access to the OWPROV | yes |
### Environment variables
The following environment variables should be set from the root directory of the service. They tell the OWGW process where to find
the configuration and the root directory.
```bash
export OWGW_ROOT=`pwd`
export OWGW_CONFIG=`pwd`
```
You can run the shell script `set_env.sh` from the microservice root.
### OWPROV Service Configuration
The configuration is kept in a file called `owprov.properties`. To understand the content of this file,
please look [here](https://github.com/Telecominfraproject/wlan-cloud-owprov/blob/main/CONFIGURATION.md)
## Kafka topics
Toe read more about Kafka, follow the [document](https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/main/KAFKA.md)
## Contributions
We need more contributors. Should you wish to contribute,
please follow the [contributions](https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/CONTRIBUTING.md) document.
## Pull Requests
Please create a branch with the Jira addressing the issue you are fixing or the feature you are implementing.
Create a pull-request from the branch into master.
## Additional OWSDK Microservices
Here is a list of additional OWSDK microservices
| Name | Description | Link | OpenAPI |
| :--- | :--- | :---: | :---: |
| OWSEC | Security Service | [here](https://github.com/Telecominfraproject/wlan-cloud-ucentralsec) | [here](https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml) |
| OWGW | Controller Service | [here](https://github.com/Telecominfraproject/wlan-cloud-ucentralgw) | [here](https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/openapi/owgw.yaml) |
| OWFMS | Firmware Management Service | [here](https://github.com/Telecominfraproject/wlan-cloud-ucentralfms) | [here](https://github.com/Telecominfraproject/wlan-cloud-ucentralfms/blob/main/openapi/owfms.yaml) |
| OWPROV | Provisioning Service | [here](https://github.com/Telecominfraproject/wlan-cloud-owprov) | [here](https://github.com/Telecominfraproject/wlan-cloud-owprov/blob/main/openapi/owprov.yaml) |
| OWANALYTICS | Analytics Service | [here](https://github.com/Telecominfraproject/wlan-cloud-analytics) | [here](https://github.com/Telecominfraproject/wlan-cloud-analytics/blob/main/openapi/owanalytics.yaml) |
| OWSUB | Subscriber Service | [here](https://github.com/Telecominfraproject/wlan-cloud-userportal) | [here](https://github.com/Telecominfraproject/wlan-cloud-userportal/blob/main/openapi/userportal.yaml) |

2
build
View File

@@ -1 +1 @@
34 32

View File

@@ -42,6 +42,7 @@ if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
STORAGE_TYPE_MYSQL_PASSWORD=${STORAGE_TYPE_MYSQL_PASSWORD:-"owprov"} \ STORAGE_TYPE_MYSQL_PASSWORD=${STORAGE_TYPE_MYSQL_PASSWORD:-"owprov"} \
STORAGE_TYPE_MYSQL_DATABASE=${STORAGE_TYPE_MYSQL_DATABASE:-"owprov"} \ STORAGE_TYPE_MYSQL_DATABASE=${STORAGE_TYPE_MYSQL_DATABASE:-"owprov"} \
STORAGE_TYPE_MYSQL_PORT=${STORAGE_TYPE_MYSQL_PORT:-"3306"} \ STORAGE_TYPE_MYSQL_PORT=${STORAGE_TYPE_MYSQL_PORT:-"3306"} \
RRM_PROVIDERS=${RRM_PROVIDERS:-"owrrm"} \
envsubst < /owprov.properties.tmpl > $OWPROV_CONFIG/owprov.properties envsubst < /owprov.properties.tmpl > $OWPROV_CONFIG/owprov.properties
fi fi

View File

@@ -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: main tag: v2.10.0
pullPolicy: Always pullPolicy: Always
# regcred: # regcred:
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io # registry: tip-tip-wlan-cloud-ucentral.jfrog.io

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
images/project/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

165
images/project/logo.svg Normal file
View File

@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.2.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 141.5 185.6" style="enable-background:new 0 0 141.5 185.6;" xml:space="preserve">
<style type="text/css">
.st0{fill:#414141;}
.st1{fill:#FFFFFF;}
.st2{fill:#FED206;}
.st3{fill:#EB6F53;}
.st4{fill:#3BA9B6;}
</style>
<g>
<g>
<path class="st0" d="M120.7,183.9H21.5c-10.8,0-19.5-8.7-19.5-19.5V20.5c0-10.8,8.7-19.5,19.5-19.5h99.2
c10.8,0,19.5,8.7,19.5,19.5v143.9C140.2,175.2,131.5,183.9,120.7,183.9z"/>
<g>
<g>
<g>
<path class="st1" d="M46.3,166.2v-3.4h-1.2v-0.6h3.1v0.6H47v3.4H46.3z"/>
</g>
<g>
<path class="st1" d="M49,166.2v-4h2.7v0.6h-2v1h2v0.6h-2v1.1h2v0.6H49z"/>
</g>
<g>
<path class="st1" d="M52.6,166.2v-4h0.7v3.4h1.8v0.6H52.6z"/>
</g>
<g>
<path class="st1" d="M55.7,166.2v-4h2.7v0.6h-2v1h2v0.6h-2v1.1h2v0.6H55.7z"/>
</g>
<g>
<path class="st1" d="M59.1,164.2c0-1.2,0.9-2.1,2.1-2.1c0.8,0,1.3,0.4,1.6,0.9l-0.6,0.3c-0.2-0.3-0.6-0.6-1-0.6
c-0.8,0-1.4,0.6-1.4,1.4c0,0.8,0.6,1.4,1.4,1.4c0.4,0,0.8-0.3,1-0.6l0.6,0.3c-0.3,0.5-0.8,0.9-1.6,0.9
C60,166.3,59.1,165.5,59.1,164.2z"/>
</g>
<g>
<path class="st1" d="M63.2,164.2c0-1.2,0.8-2.1,2-2.1c1.2,0,2,0.9,2,2.1c0,1.2-0.8,2.1-2,2.1C64,166.3,63.2,165.4,63.2,164.2z
M66.5,164.2c0-0.8-0.5-1.4-1.3-1.4c-0.8,0-1.3,0.6-1.3,1.4c0,0.8,0.5,1.4,1.3,1.4C66,165.7,66.5,165,66.5,164.2z"/>
</g>
<g>
<path class="st1" d="M71.3,166.2v-3.1l-1.2,3.1h-0.3l-1.2-3.1v3.1h-0.7v-4h1l1.1,2.7l1.1-2.7h1v4H71.3z"/>
</g>
<g>
<path class="st1" d="M75.7,166.2v-4h0.7v4H75.7z"/>
</g>
<g>
<path class="st1" d="M80.4,166.2l-2.1-2.8v2.8h-0.7v-4h0.7l2,2.8v-2.8h0.7v4H80.4z"/>
</g>
<g>
<path class="st1" d="M82.3,166.2v-4H85v0.6h-2v1h2v0.6h-2v1.7H82.3z"/>
</g>
<g>
<path class="st1" d="M87.9,166.2l-0.9-1.5h-0.7v1.5h-0.7v-4h1.7c0.8,0,1.3,0.5,1.3,1.2c0,0.7-0.5,1.1-0.9,1.2l1,1.6H87.9z
M88,163.5c0-0.4-0.3-0.6-0.7-0.6h-1v1.3h1C87.7,164.1,88,163.9,88,163.5z"/>
</g>
<g>
<path class="st1" d="M92.4,166.2l-0.3-0.8h-1.8l-0.3,0.8h-0.8l1.6-4h0.9l1.6,4H92.4z M91.2,162.9l-0.7,1.9h1.4L91.2,162.9z"/>
</g>
<g>
<path class="st1" d="M95.8,166.2v-4h1.5c0.8,0,1.2,0.5,1.2,1.2c0,0.6-0.4,1.2-1.2,1.2h-1.2v1.7H95.8z M98.2,163.4
c0-0.5-0.3-0.9-0.9-0.9h-1.1v1.7h1.1C97.8,164.3,98.2,163.9,98.2,163.4z"/>
</g>
<g>
<path class="st1" d="M101.5,166.2l-1.1-1.6h-0.9v1.6h-0.3v-4h1.5c0.7,0,1.2,0.4,1.2,1.2c0,0.7-0.5,1.1-1.1,1.1l1.2,1.7H101.5z
M101.6,163.4c0-0.5-0.4-0.9-0.9-0.9h-1.1v1.7h1.1C101.2,164.3,101.6,163.9,101.6,163.4z"/>
</g>
<g>
<path class="st1" d="M102.8,164.2c0-1.2,0.8-2.1,1.9-2.1c1.2,0,1.9,0.9,1.9,2.1c0,1.2-0.8,2.1-1.9,2.1
C103.6,166.3,102.8,165.4,102.8,164.2z M106.3,164.2c0-1-0.6-1.7-1.6-1.7c-1,0-1.6,0.7-1.6,1.7c0,1,0.6,1.7,1.6,1.7
C105.7,166,106.3,165.2,106.3,164.2z"/>
</g>
<g>
<path class="st1" d="M106.9,165.8l0.2-0.3c0.2,0.2,0.4,0.4,0.8,0.4c0.5,0,0.9-0.4,0.9-0.9v-2.8h0.3v2.8c0,0.8-0.5,1.2-1.2,1.2
C107.5,166.3,107.2,166.1,106.9,165.8z"/>
</g>
<g>
<path class="st1" d="M110.4,166.2v-4h2.5v0.3h-2.2v1.5h2.1v0.3h-2.1v1.6h2.2v0.3H110.4z"/>
</g>
<g>
<path class="st1" d="M113.5,164.2c0-1.2,0.9-2.1,2-2.1c0.6,0,1.1,0.3,1.5,0.7l-0.3,0.2c-0.3-0.3-0.7-0.6-1.2-0.6
c-0.9,0-1.7,0.7-1.7,1.7c0,1,0.7,1.7,1.7,1.7c0.5,0,0.9-0.2,1.2-0.6l0.3,0.2c-0.4,0.4-0.8,0.7-1.5,0.7
C114.4,166.3,113.5,165.5,113.5,164.2z"/>
</g>
<g>
<path class="st1" d="M118.7,166.2v-3.7h-1.3v-0.3h2.9v0.3H119v3.7H118.7z"/>
</g>
</g>
<g>
<polygon class="st1" points="26.3,163.8 31.6,158.5 36.9,163.8 37.7,163.8 31.6,157.6 25.5,163.8 "/>
<polygon class="st1" points="36.9,164.7 31.6,170 26.3,164.7 25.5,164.7 31.6,170.8 37.7,164.7 "/>
<polygon class="st1" points="31,163.8 36.3,158.5 41.6,163.8 42.5,163.8 36.3,157.6 30.2,163.8 "/>
<polygon class="st1" points="41.6,164.7 36.3,170 31,164.7 30.2,164.7 36.3,170.8 42.5,164.7 "/>
</g>
</g>
<g>
<path class="st1" d="M33.2,100.7c-4.6,0-8.3,3.7-8.3,8.3s3.7,8.3,8.3,8.3s8.3-3.7,8.3-8.3S37.8,100.7,33.2,100.7z"/>
</g>
<g>
<g>
<g>
<path class="st2" d="M33.2,35.2c40.7,0,73.8,33.1,73.8,73.8c0,0.7,0,1.4,0,2.1c0,1.7,0.6,3.3,1.7,4.6c1.2,1.2,2.8,1.9,4.5,2
l0.2,0c3.5,0,6.3-2.7,6.4-6.2c0-0.8,0-1.7,0-2.5c0-47.7-38.8-86.6-86.6-86.6c-0.8,0-1.7,0-2.5,0c-1.7,0-3.3,0.8-4.5,2
c-1.2,1.2-1.8,2.9-1.7,4.6c0.1,3.5,3,6.3,6.6,6.2C31.8,35.2,32.5,35.2,33.2,35.2z"/>
</g>
</g>
</g>
<g>
<g>
<g>
<path class="st3" d="M33.2,60.5c26.7,0,48.5,21.7,48.5,48.5c0,0.6,0,1.3,0,2c-0.1,1.7,0.5,3.3,1.7,4.6c1.2,1.3,2.7,2,4.4,2.1
c1.7,0.1,3.3-0.5,4.6-1.7c1.2-1.2,2-2.7,2-4.4c0-0.9,0.1-1.8,0.1-2.6c0-33.8-27.5-61.2-61.2-61.2c-0.8,0-1.6,0-2.6,0.1
c-1.7,0.1-3.3,0.8-4.4,2.1c-1.2,1.3-1.8,2.9-1.7,4.6s0.8,3.3,2.1,4.4c1.3,1.2,2.9,1.8,4.6,1.7C31.9,60.5,32.6,60.5,33.2,60.5z"
/>
</g>
</g>
</g>
<g>
<g>
<g>
<path class="st4" d="M33.2,86.7c12.3,0,22.3,10,22.3,22.3c0,0.5,0,1.1-0.1,1.8c-0.3,3.5,2.3,6.6,5.8,6.9
c3.5,0.3,6.6-2.3,6.9-5.8c0.1-1,0.1-1.9,0.1-2.8c0-19.3-15.7-35.1-35.1-35.1c-0.9,0-1.8,0-2.8,0.1c-1.7,0.1-3.2,0.9-4.3,2.2
c-1.1,1.3-1.6,2.9-1.5,4.6c0.1,1.7,0.9,3.2,2.2,4.3c1.3,1.1,2.9,1.6,4.6,1.5C32.1,86.7,32.7,86.7,33.2,86.7z"/>
</g>
</g>
</g>
</g>
<g>
<path class="st1" d="M35.8,130.4c1.1,0.6,2.1,1.5,2.7,2.6c0.7,1.1,1,2.3,1,3.7s-0.3,2.6-1,3.7c-0.7,1.1-1.6,2-2.7,2.6
c-1.1,0.6-2.4,1-3.8,1s-2.7-0.3-3.8-1c-1.1-0.6-2.1-1.5-2.7-2.6c-0.7-1.1-1-2.3-1-3.7c0-1.3,0.3-2.6,1-3.7c0.7-1.1,1.6-2,2.7-2.6
c1.1-0.6,2.4-0.9,3.8-0.9C33.4,129.5,34.7,129.8,35.8,130.4z M29.9,132.9c-0.7,0.4-1.2,0.9-1.6,1.6s-0.6,1.4-0.6,2.2
c0,0.8,0.2,1.6,0.6,2.3c0.4,0.7,0.9,1.2,1.6,1.6c0.7,0.4,1.4,0.6,2.1,0.6c0.8,0,1.5-0.2,2.1-0.6c0.6-0.4,1.2-0.9,1.5-1.6
c0.4-0.7,0.6-1.4,0.6-2.3c0-0.8-0.2-1.6-0.6-2.2s-0.9-1.2-1.5-1.6c-0.6-0.4-1.4-0.6-2.1-0.6C31.3,132.3,30.6,132.5,29.9,132.9z"/>
<path class="st1" d="M50.6,133.6c0.8,0.5,1.4,1.1,1.8,2c0.4,0.8,0.6,1.8,0.6,2.9c0,1.1-0.2,2-0.6,2.8c-0.4,0.8-1,1.5-1.8,1.9
c-0.8,0.5-1.6,0.7-2.6,0.7c-0.7,0-1.4-0.1-2-0.4s-1.1-0.7-1.5-1.2v5.4h-3.1V133h3.1v1.6c0.4-0.5,0.9-1,1.4-1.2s1.2-0.4,2-0.4
C48.9,132.9,49.8,133.1,50.6,133.6z M49.1,140.5c0.5-0.6,0.7-1.3,0.7-2.2c0-0.9-0.2-1.6-0.7-2.1c-0.5-0.6-1.1-0.8-1.9-0.8
s-1.4,0.3-1.9,0.8c-0.5,0.6-0.8,1.3-0.8,2.1c0,0.9,0.2,1.6,0.8,2.2s1.1,0.8,1.9,0.8S48.6,141,49.1,140.5z"/>
<path class="st1" d="M63.4,134.4c0.9,1,1.4,2.4,1.4,4.2c0,0.3,0,0.6,0,0.7H57c0.2,0.7,0.5,1.2,1,1.6c0.5,0.4,1.1,0.6,1.8,0.6
c0.5,0,1-0.1,1.5-0.3s0.9-0.5,1.3-0.9l1.6,1.6c-0.5,0.6-1.2,1.1-2,1.4c-0.8,0.3-1.6,0.5-2.6,0.5c-1.1,0-2.1-0.2-3-0.7
s-1.5-1.1-2-1.9c-0.5-0.8-0.7-1.8-0.7-2.9c0-1.1,0.2-2.1,0.7-2.9s1.1-1.5,2-1.9c0.8-0.5,1.8-0.7,2.9-0.7
C61.2,132.9,62.5,133.4,63.4,134.4z M61.8,137.5c0-0.7-0.3-1.3-0.7-1.7s-1-0.6-1.7-0.6c-0.7,0-1.2,0.2-1.7,0.6
c-0.4,0.4-0.7,1-0.9,1.7H61.8z"/>
<path class="st1" d="M76.2,134c0.7,0.7,1.1,1.7,1.1,3v6.8h-3.1v-5.9c0-0.7-0.2-1.2-0.6-1.6s-0.9-0.6-1.5-0.6
c-0.8,0-1.4,0.3-1.8,0.8c-0.4,0.5-0.7,1.2-0.7,2v5.3h-3.1V133h3.1v1.9c0.7-1.3,2-2,3.7-2C74.6,132.8,75.5,133.2,76.2,134z"/>
<path class="st1" d="M96,129.7h3.3l-4.7,14h-3.3l-2.9-10.1l-3,10.1h-3.2l-4.7-14h3.4l3,10.7l3-10.7H90l3.1,10.7L96,129.7z"/>
<path class="st1" d="M103.3,128.7c0.3,0.3,0.5,0.7,0.5,1.2s-0.2,0.9-0.5,1.2c-0.3,0.3-0.7,0.5-1.2,0.5c-0.5,0-0.9-0.2-1.2-0.5
c-0.3-0.3-0.5-0.7-0.5-1.2c0-0.5,0.2-0.9,0.5-1.2c0.3-0.3,0.7-0.5,1.2-0.5C102.6,128.2,103,128.3,103.3,128.7z M100.6,133h3.1
v10.8h-3.1V133z"/>
<path class="st1" d="M106.5,129.7h10.1l0,2.6h-6.9v3.4h6.3v2.6h-6.3v5.3h-3.2V129.7z"/>
<path class="st1" d="M120.9,128.7c0.3,0.3,0.5,0.7,0.5,1.2s-0.2,0.9-0.5,1.2c-0.3,0.3-0.7,0.5-1.2,0.5c-0.5,0-0.9-0.2-1.2-0.5
c-0.3-0.3-0.5-0.7-0.5-1.2c0-0.5,0.2-0.9,0.5-1.2c0.3-0.3,0.7-0.5,1.2-0.5C120.1,128.2,120.5,128.3,120.9,128.7z M118.1,133h3.1
v10.8h-3.1V133z"/>
</g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 8.0 KiB

View File

@@ -1253,12 +1253,21 @@ components:
items: items:
$ref: '#/components/schemas/ConfigurationOverride' $ref: '#/components/schemas/ConfigurationOverride'
######################################################################################### #########################################################################################
## ##
## These are endpoints that all services in the OPenWiFI stack must provide ## These are endpoints that all services in the OPenWiFI stack must provide
## ##
######################################################################################### #########################################################################################
ExtraSystemConfiguration:
type: array
items:
type: object
properties:
parameterName:
type: string
parameterValue:
type: string
AnyPayload: AnyPayload:
type: object type: object
properties: properties:
@@ -2057,19 +2066,12 @@ paths:
default: false default: false
required: false required: false
- in: query - in: query
description: return the list of devices under RRM description: return the list of devices for a subscriber
name: subscriber name: subscriber
schema: schema:
type: string type: string
format: uuid format: uuid
required: false required: false
- in: query
description: return RRM settings for a specific device
name: rrmSettings
schema:
type: boolean
default: false
required: false
- in: query - in: query
description: return the resolved configuration for a specific device description: return the resolved configuration for a specific device
name: resolveConfig name: resolveConfig
@@ -2135,6 +2137,13 @@ paths:
type: string type: string
format: uuid format: uuid
required: false required: false
- in: query
description: return RRM settings for a specific device
name: rrmSettings
schema:
type: boolean
default: false
required: false
responses: responses:
200: 200:
description: Succesful retrieve configuratiopn or part of the configuration description: Succesful retrieve configuratiopn or part of the configuration
@@ -2249,7 +2258,7 @@ paths:
get: get:
tags: tags:
- Configuration Overrides - Configuration Overrides
operationId: getCponfigurationOverrides operationId: getConfigurationOverrides
summary: retrieve a list of configuration overrides for a given device summary: retrieve a list of configuration overrides for a given device
parameters: parameters:
- in: path - in: path
@@ -2273,7 +2282,7 @@ paths:
delete: delete:
tags: tags:
- Configuration Overrides - Configuration Overrides
operationId: deleteCponfigurationOverrides operationId: deleteConfigurationOverrides
summary: delete all configuration overrides for a given device from a given source summary: delete all configuration overrides for a given device from a given source
parameters: parameters:
- in: path - in: path
@@ -2407,6 +2416,14 @@ paths:
type: boolean type: boolean
default: false default: false
required: false required: false
- in: query
description: list venues that use a specific RRM vendor
name: RRMvendor
schema:
type: string
example:
- this is the shortname of the RRM vendor
required: false
responses: responses:
200: 200:
description: Return a list of venues. description: Return a list of venues.
@@ -2525,6 +2542,17 @@ paths:
type: boolean type: boolean
default: false default: false
required: false required: false
- in: query
name: revisionsAvailable
schema:
type: boolean
default: false
required: false
- in: query
name: revision
schema:
type: string
required: false
requestBody: requestBody:
description: Information used to modify the new venue description: Information used to modify the new venue
content: content:
@@ -4408,3 +4436,66 @@ paths:
$ref: '#/components/responses/Unauthorized' $ref: '#/components/responses/Unauthorized'
404: 404:
$ref: '#/components/responses/NotFound' $ref: '#/components/responses/NotFound'
/systemConfiguration:
get:
tags:
- SystemConfiguration
summary: Retrieve system configuration items
operationId: getSystemConfiguration
parameters:
- in: query
description: Which parameters you want to retrieve
name: entries
schema:
type: string
example:
- element1
- element1,element2,element3
required: false
responses:
200:
description: List of configuration elements
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ExtraSystemConfiguration'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
put:
tags:
- SystemConfiguration
summary: Set some or all system configuration
operationId: setSystemConfiguration
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ExtraSystemConfiguration'
responses:
200:
$ref: '#/components/schemas/ExtraSystemConfiguration'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
delete:
tags:
- SystemConfiguration
summary: Delete all additional system configuration
operationId: deleteSystemConfiguration
responses:
200:
$ref: '#/components/responses/Success'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'

View File

@@ -37,10 +37,12 @@ openwifi.system.data = ${SYSTEM_DATA}
openwifi.system.debug = false openwifi.system.debug = false
openwifi.system.uri.private = ${SYSTEM_URI_PRIVATE} openwifi.system.uri.private = ${SYSTEM_URI_PRIVATE}
openwifi.system.uri.public = ${SYSTEM_URI_PUBLIC} openwifi.system.uri.public = ${SYSTEM_URI_PUBLIC}
openwifi.system.commandchannel = /tmp/app.ucentralfms openwifi.system.commandchannel = /tmp/app.owprov
openwifi.system.uri.ui = ${SYSTEM_URI_UI} openwifi.system.uri.ui = ${SYSTEM_URI_UI}
openwifi.security.restapi.disable = ${SECURITY_RESTAPI_DISABLE} openwifi.security.restapi.disable = ${SECURITY_RESTAPI_DISABLE}
rrm.providers = ${RRM_PROVIDERS}
############################# #############################
# Generic information for all micro services # Generic information for all micro services
############################# #############################

View File

@@ -11,359 +11,368 @@
namespace OpenWifi { namespace OpenWifi {
APConfig::APConfig(const std::string &SerialNumber, const std::string &DeviceType, Poco::Logger &L, bool Explain) APConfig::APConfig(const std::string &SerialNumber, const std::string &DeviceType,
: SerialNumber_(SerialNumber), Poco::Logger &L, bool Explain)
DeviceType_(DeviceType), : SerialNumber_(SerialNumber), DeviceType_(DeviceType), Logger_(L), Explain_(Explain) {}
Logger_(L),
Explain_(Explain)
{
}
APConfig::APConfig(const std::string & SerialNumber, Poco::Logger & L) APConfig::APConfig(const std::string &SerialNumber, Poco::Logger &L)
: SerialNumber_(SerialNumber), : SerialNumber_(SerialNumber), Logger_(L) {
Logger_(L) Explain_ = false;
{ Sub_ = true;
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,
for(const auto &i:*Arr) { Poco::JSON::Object::Ptr &Radio) {
auto R = i.extract<Poco::JSON::Object::Ptr>(); for (const auto &i : *Arr) {
if(R->has("band") && R->get("band").toString()==Band) { auto R = i.extract<Poco::JSON::Object::Ptr>();
Radio = R; if (R->has("band") && R->get("band").toString() == Band) {
return true; Radio = R;
} return true;
} }
return false; }
} return false;
}
bool APConfig::RemoveBand(const std::string &Band, const Poco::JSON::Array::Ptr &A_in,Poco::JSON::Array::Ptr &A_Out) { bool APConfig::RemoveBand(const std::string &Band, const Poco::JSON::Array::Ptr &A_in,
for(const auto &i:*A_in) { Poco::JSON::Array::Ptr &A_Out) {
auto R = i.extract<Poco::JSON::Object::Ptr>(); for (const auto &i : *A_in) {
if(R->has("band") && R->get("band").toString()==Band) { auto R = i.extract<Poco::JSON::Object::Ptr>();
} else { if (R->has("band") && R->get("band").toString() == Band) {
A_Out->add(i); } else {
} A_Out->add(i);
} }
return false; }
} return false;
}
[[maybe_unused]] static void ShowJSON([[maybe_unused]] const char *S,
[[maybe_unused]] const Poco::JSON::Object::Ptr &Obj) {
/*
std::stringstream O;
Poco::JSON::Stringifier::stringify(Obj,O);
std::cout << S << ":" << std::endl;
std::cout << ">>>" << std::endl << O.str() << std::endl << "<<<" << std::endl;
*/
}
[[maybe_unused ]] static void ShowJSON([[maybe_unused]] const char *S, [[maybe_unused]] const Poco::JSON::Object::Ptr &Obj) { bool APConfig::ReplaceVariablesInObject(const Poco::JSON::Object::Ptr &Original,
/* Poco::JSON::Object::Ptr &Result) {
std::stringstream O; // get all the names and expand
Poco::JSON::Stringifier::stringify(Obj,O); auto Names = Original->getNames();
std::cout << S << ":" << std::endl; for (const auto &i : Names) {
std::cout << ">>>" << std::endl << O.str() << std::endl << "<<<" << std::endl; if (i == "__variableBlock") {
*/ if (Original->isArray(i)) {
} auto UUIDs = Original->getArray(i);
for (const auto &uuid : *UUIDs) {
ProvObjects::VariableBlock VB;
if (StorageService()->VariablesDB().GetRecord("id", uuid, VB)) {
for (const auto &var : VB.variables) {
Poco::JSON::Parser P;
auto VariableBlockInfo =
P.parse(var.value).extract<Poco::JSON::Object::Ptr>();
auto VarNames = VariableBlockInfo->getNames();
for (const auto &j : VarNames) {
Result->set(j, VariableBlockInfo->get(j));
}
}
}
}
}
} 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));
}
}
return true;
}
bool APConfig::ReplaceVariablesInObject( const Poco::JSON::Object::Ptr & Original, Poco::JSON::Object::Ptr & Result) { bool APConfig::ReplaceVariablesInArray(const Poco::JSON::Array::Ptr &Original,
// get all the names and expand Poco::JSON::Array::Ptr &ResultArray) {
auto Names = Original->getNames();
for(const auto &i:Names) {
if(i=="__variableBlock") {
if(Original->isArray(i)) {
auto UUIDs = Original->getArray(i);
for(const auto &uuid:*UUIDs) {
ProvObjects::VariableBlock VB;
if(StorageService()->VariablesDB().GetRecord("id", uuid, VB)) {
for(const auto &var:VB.variables) {
Poco::JSON::Parser P;
auto VariableBlockInfo = P.parse(var.value).extract<Poco::JSON::Object::Ptr>();
auto VarNames = VariableBlockInfo->getNames();
for(const auto &j:VarNames) {
Result->set(j,VariableBlockInfo->get(j));
}
}
}
}
}
} 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));
}
}
return true;
}
bool APConfig::ReplaceVariablesInArray( const Poco::JSON::Array::Ptr & Original, Poco::JSON::Array::Ptr & ResultArray) { for (const auto &element : *Original) {
for(const auto &element:*Original) { if (element.isArray()) {
auto Expanded = Poco::makeShared<Poco::JSON::Array>();
const auto &Object = element.extract<Poco::JSON::Array::Ptr>();
ReplaceVariablesInArray(Object, Expanded);
ResultArray->add(Expanded);
} else if (element.isStruct()) {
auto Expanded = Poco::makeShared<Poco::JSON::Object>();
const auto &Object = element.extract<Poco::JSON::Object::Ptr>();
ReplaceVariablesInObject(Object, Expanded);
ResultArray->add(Expanded);
} else if (element.isString() || element.isNumeric() || element.isBoolean() ||
element.isInteger() || element.isSigned()) {
ResultArray->add(element);
} else {
auto Expanded = Poco::makeShared<Poco::JSON::Object>();
const auto &Object = element.extract<Poco::JSON::Object::Ptr>();
ReplaceVariablesInObject(Object, Expanded);
ResultArray->add(Expanded);
}
}
return true;
}
if(element.isArray()) { bool APConfig::Get(Poco::JSON::Object::Ptr &Configuration) {
auto Expanded = Poco::makeShared<Poco::JSON::Array>(); if (Config_.empty()) {
const auto & Object = element.extract<Poco::JSON::Array::Ptr>(); Explanation_.clear();
ReplaceVariablesInArray(Object,Expanded); try {
ResultArray->add(Expanded); if (!Sub_) {
} else if(element.isStruct()) { ProvObjects::InventoryTag D;
auto Expanded = Poco::makeShared<Poco::JSON::Object>(); if (StorageService()->InventoryDB().GetRecord("serialNumber", SerialNumber_,
const auto & Object = element.extract<Poco::JSON::Object::Ptr>(); D)) {
ReplaceVariablesInObject(Object,Expanded); if (!D.deviceConfiguration.empty()) {
ResultArray->add(Expanded); // std::cout << "Adding device specific configuration: " << D.deviceConfiguration.size() << std::endl;
} else if( element.isString() || AddConfiguration(D.deviceConfiguration);
element.isNumeric() || } else {
element.isBoolean() || // std::cout << "No device specific configuration." << std::endl;
element.isInteger() || }
element.isSigned() ) { if (!D.entity.empty()) {
ResultArray->add(element); AddEntityConfig(D.entity);
} else { } else if (!D.venue.empty()) {
auto Expanded = Poco::makeShared<Poco::JSON::Object>(); AddVenueConfig(D.venue);
const auto & Object = element.extract<Poco::JSON::Object::Ptr>(); }
ReplaceVariablesInObject(Object,Expanded); }
ResultArray->add(Expanded); } else {
} ProvObjects::SubscriberDevice D;
} if (StorageService()->SubscriberDeviceDB().GetRecord("serialNumber",
return true; SerialNumber_, D)) {
} if (!D.configuration.empty()) {
AddConfiguration(D.configuration);
}
}
}
// Now we have all the config we need.
} catch (const Poco::Exception &E) {
Logger_.log(E);
}
}
bool APConfig::Get(Poco::JSON::Object::Ptr & Configuration) { try {
if(Config_.empty()) { std::set<std::string> Sections;
Explanation_.clear(); for (const auto &i : Config_) {
try { Poco::JSON::Parser P;
if(!Sub_) { auto O = P.parse(i.element.configuration).extract<Poco::JSON::Object::Ptr>();
ProvObjects::InventoryTag D; auto Names = O->getNames();
if (StorageService()->InventoryDB().GetRecord("serialNumber", SerialNumber_, D)) { for (const auto &SectionName : Names) {
if (!D.deviceConfiguration.empty()) { auto InsertInfo = Sections.insert(SectionName);
std::cout << "Adding device specific configuration: " << D.deviceConfiguration.size() << std::endl; if (InsertInfo.second) {
AddConfiguration(D.deviceConfiguration); if (O->isArray(SectionName)) {
} else { auto OriginalArray = O->getArray(SectionName);
std::cout << "No device specific configuration." << std::endl; if (Explain_) {
} Poco::JSON::Object ExObj;
if (!D.entity.empty()) { ExObj.set("from-uuid", i.info.id);
AddEntityConfig(D.entity); ExObj.set("from-name", i.info.name);
} else if (!D.venue.empty()) { ExObj.set("action", "added");
AddVenueConfig(D.venue); ExObj.set("element", OriginalArray);
} Explanation_.add(ExObj);
} }
} else { auto ExpandedArray = Poco::makeShared<Poco::JSON::Array>();
ProvObjects::SubscriberDevice D; ReplaceVariablesInArray(OriginalArray, ExpandedArray);
if (StorageService()->SubscriberDeviceDB().GetRecord("serialNumber", SerialNumber_, D)) { Configuration->set(SectionName, ExpandedArray);
if (!D.configuration.empty()) { } else if (O->isObject(SectionName)) {
AddConfiguration(D.configuration); auto OriginalSection =
} O->get(SectionName).extract<Poco::JSON::Object::Ptr>();
} if (Explain_) {
} Poco::JSON::Object ExObj;
// Now we have all the config we need. ExObj.set("from-uuid", i.info.id);
} catch (const Poco::Exception &E ) { ExObj.set("from-name", i.info.name);
Logger_.log(E); 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 {
poco_warning(Logger(), fmt::format("Unknown config element type: {}",O->get(SectionName).toString()));
}
} 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);
}
}
}
}
try { // Apply overrides...
std::set<std::string> Sections; ProvObjects::ConfigurationOverrideList COL;
for (const auto &i: Config_) { if (StorageService()->OverridesDB().GetRecord("serialNumber", SerialNumber_, COL)) {
Poco::JSON::Parser P; for (const auto &col : COL.overrides) {
auto O = P.parse(i.element.configuration).extract<Poco::JSON::Object::Ptr>(); const auto Tokens = Poco::StringTokenizer(col.parameterName, ".");
auto Names = O->getNames(); if (Tokens[0] == "radios" && Tokens.count() == 3) {
for (const auto &SectionName: Names) { std::uint64_t RadioIndex = std::strtoull(Tokens[1].c_str(), nullptr, 10);
auto InsertInfo = Sections.insert(SectionName); if (RadioIndex < MaximumPossibleRadios) {
if (InsertInfo.second) { auto RadioArray = Configuration->getArray("radios");
if (O->isArray(SectionName)) { if (RadioIndex < RadioArray->size()) {
auto OriginalArray = O->getArray(SectionName); auto IndexedRadio =
if (Explain_) { RadioArray->get(RadioIndex).extract<Poco::JSON::Object::Ptr>();
Poco::JSON::Object ExObj; if (Tokens[2] == "tx-power") {
ExObj.set("from-uuid", i.info.id); IndexedRadio->set(
ExObj.set("from-name", i.info.name); "rx-power",
ExObj.set("action", "added"); std::strtoull(col.parameterValue.c_str(), nullptr, 10));
ExObj.set("element", OriginalArray); if (Explain_) {
Explanation_.add(ExObj); Poco::JSON::Object ExObj;
} ExObj.set("from-name", "overrides");
auto ExpandedArray = Poco::makeShared<Poco::JSON::Array>(); ExObj.set("override", col.parameterName);
ReplaceVariablesInArray(OriginalArray, ExpandedArray); ExObj.set("source", col.source);
Configuration->set(SectionName, ExpandedArray); ExObj.set("reason", col.reason);
} else if (O->isObject(SectionName)) { ExObj.set("value", col.parameterValue);
auto OriginalSection = O->get(SectionName).extract<Poco::JSON::Object::Ptr>(); Explanation_.add(ExObj);
if (Explain_) { }
Poco::JSON::Object ExObj; RadioArray->set(RadioIndex, IndexedRadio);
ExObj.set("from-uuid", i.info.id); Configuration->set("radios", RadioArray);
ExObj.set("from-name", i.info.name); } else if (Tokens[2] == "channel") {
ExObj.set("action", "added"); if (col.parameterValue == "auto") {
ExObj.set("element", OriginalSection); IndexedRadio->set("channel", "auto");
Explanation_.add(ExObj); } else {
} IndexedRadio->set(
auto ExpandedSection = Poco::makeShared<Poco::JSON::Object>(); "channel",
ReplaceVariablesInObject(OriginalSection, ExpandedSection); std::strtoull(col.parameterValue.c_str(), nullptr, 10));
Configuration->set(SectionName, ExpandedSection); }
} else { // std::cout << "Setting channel in radio " << RadioIndex << std::endl;
std::cout << " --- unknown element type --- " << O->get(SectionName).toString() if (Explain_) {
<< std::endl; Poco::JSON::Object ExObj;
} ExObj.set("from-name", "overrides");
} else { ExObj.set("override", col.parameterName);
if (Explain_) { ExObj.set("source", col.source);
Poco::JSON::Object ExObj; ExObj.set("reason", col.reason);
ExObj.set("from-uuid", i.info.id); ExObj.set("value", col.parameterValue);
ExObj.set("from-name", i.info.name); Explanation_.add(ExObj);
ExObj.set("action", "ignored"); }
ExObj.set("reason", "weight insufficient"); RadioArray->set(RadioIndex, IndexedRadio);
ExObj.set("element", O->get(SectionName)); Configuration->set("radios", RadioArray);
Explanation_.add(ExObj); } else {
} poco_error(
} Logger(),
} fmt::format("{}: Unsupported override variable name {}",
} col.parameterName));
}
}
} else {
poco_error(Logger(), fmt::format("{}: radio index out of range in {}",
col.parameterName));
}
} else {
poco_error(Logger(),
fmt::format("{}: Unsupported override variable name {}",
col.parameterName));
}
}
}
} catch (...) {
}
return !Config_.empty();
}
// Apply overrides... static bool DeviceTypeMatch(const std::string &DeviceType, const Types::StringVec &Types) {
ProvObjects::ConfigurationOverrideList COL; for (const auto &i : Types) {
if(StorageService()->OverridesDB().GetRecord("serialNumber", SerialNumber_, COL)) { if (i == "*" || Poco::icompare(DeviceType, i) == 0)
for (const auto &col: COL.overrides) { return true;
const auto Tokens = Poco::StringTokenizer(col.parameterName, "."); }
if (Tokens[0] == "radios" && Tokens.count() == 3) { return false;
std::uint64_t RadioIndex = std::strtoull(Tokens[1].c_str(), nullptr, 10); }
if (RadioIndex < MaximumPossibleRadios) {
auto RadioArray = Configuration->getArray("radios");
if (RadioIndex < RadioArray->size()) {
auto IndexedRadio = RadioArray->get(RadioIndex).extract<Poco::JSON::Object::Ptr>();
if (Tokens[2] == "tx-power") {
IndexedRadio->set("rx-power",
std::strtoull(col.parameterValue.c_str(), nullptr, 10));
if (Explain_) {
Poco::JSON::Object ExObj;
ExObj.set("from-name", "overrides");
ExObj.set("override", col.parameterName);
ExObj.set("source", col.source);
ExObj.set("reason", col.reason);
ExObj.set("value", col.parameterValue);
Explanation_.add(ExObj);
}
RadioArray->set(RadioIndex, IndexedRadio);
Configuration->set("radios", RadioArray);
} else if (Tokens[2] == "channel") {
if(col.parameterValue=="auto") {
IndexedRadio->set("channel", "auto");
} else {
IndexedRadio->set("channel",
std::strtoull(col.parameterValue.c_str(), nullptr, 10));
}
std::cout << "Setting channel in radio " << RadioIndex << std::endl;
if (Explain_) {
Poco::JSON::Object ExObj;
ExObj.set("from-name", "overrides");
ExObj.set("override", col.parameterName);
ExObj.set("source", col.source);
ExObj.set("reason", col.reason);
ExObj.set("value", col.parameterValue);
Explanation_.add(ExObj);
}
RadioArray->set(RadioIndex, IndexedRadio);
Configuration->set("radios", RadioArray);
} else {
poco_error(Logger(), fmt::format("{}: Unsupported override variable name {}",
col.parameterName));
}
}
} else {
poco_error(Logger(), fmt::format("{}: radio index out of range in {}", col.parameterName));
}
} else {
poco_error(Logger(),
fmt::format("{}: Unsupported override variable name {}", col.parameterName));
}
}
}
} catch (...) {
} void APConfig::AddConfiguration(const ProvObjects::DeviceConfigurationElementVec &Elements) {
return !Config_.empty(); 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);
}
}
}
static bool DeviceTypeMatch(const std::string &DeviceType, const Types::StringVec & Types) { void APConfig::AddConfiguration(const Types::UUIDvec_t &UUIDs) {
for(const auto &i:Types) { for (const auto &i : UUIDs)
if(i=="*" || Poco::icompare(DeviceType,i)==0) AddConfiguration(i);
return true; }
}
return false;
}
void APConfig::AddConfiguration(const ProvObjects::DeviceConfigurationElementVec &Elements) { void APConfig::AddConfiguration(const std::string &UUID) {
for(const auto &i:Elements) { if (UUID.empty())
if(i.weight==0) { return;
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) { ProvObjects::DeviceConfiguration Config;
for(const auto &i:UUIDs) if (StorageService()->ConfigurationDB().GetRecord("id", UUID, Config)) {
AddConfiguration(i); if (!Config.configuration.empty()) {
} if (DeviceTypeMatch(DeviceType_, Config.deviceTypes)) {
for (const auto &i : Config.configuration) {
if (i.weight == 0) {
VerboseElement VE{.element = i, .info = Config.info};
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 = Config.info};
Config_.insert(Hint, VE);
}
}
} else {
Poco::JSON::Object ExObj;
ExObj.set("from-uuid", Config.info.id);
ExObj.set("from-name", Config.info.name);
ExObj.set("action", "ignored");
ExObj.set("reason", "deviceType mismatch");
Explanation_.add(ExObj);
}
} else {
poco_error(Logger(),
fmt::format("Device configuration for {} is empty.", SerialNumber_));
}
} else {
poco_error(Logger(),
fmt::format("Invalid device configuration UUID for {}.", SerialNumber_));
}
}
void APConfig::AddConfiguration(const std::string &UUID) { void APConfig::AddEntityConfig(const std::string &UUID) {
if(UUID.empty()) ProvObjects::Entity E;
return; if (StorageService()->EntityDB().GetRecord("id", UUID, E)) {
AddConfiguration(E.configurations);
if (!E.parent.empty()) {
AddEntityConfig(E.parent);
}
} else {
}
}
ProvObjects::DeviceConfiguration Config; void APConfig::AddVenueConfig(const std::string &UUID) {
if(StorageService()->ConfigurationDB().GetRecord("id", UUID, Config)) { ProvObjects::Venue V;
if(!Config.configuration.empty()) { if (StorageService()->VenueDB().GetRecord("id", UUID, V)) {
if(DeviceTypeMatch(DeviceType_,Config.deviceTypes)) { AddConfiguration(V.configurations);
for(const auto &i:Config.configuration) { if (!V.entity.empty()) {
if(i.weight==0) { AddEntityConfig(V.entity);
VerboseElement VE{ .element = i, .info = Config.info}; } else if (!V.parent.empty()) {
Config_.push_back(VE); AddVenueConfig(V.parent);
} else { }
// we need to insert after everything bigger or equal } else {
auto Hint = std::lower_bound(Config_.cbegin(),Config_.cend(),i.weight, }
[](const VerboseElement &Elem, uint64_t Value) { }
return Elem.element.weight>=Value; }); } // namespace OpenWifi
VerboseElement VE{ .element = i, .info = Config.info};
Config_.insert(Hint,VE);
}
}
} else {
Poco::JSON::Object ExObj;
ExObj.set("from-uuid", Config.info.id);
ExObj.set("from-name",Config.info.name );
ExObj.set("action", "ignored");
ExObj.set("reason", "deviceType mismatch");
Explanation_.add(ExObj);
}
} else {
poco_error(Logger(),fmt::format("Device configuration for {} is empty.", SerialNumber_));
}
} else {
poco_error(Logger(),fmt::format("Invalid device configuration UUID for {}.", SerialNumber_));
}
}
void APConfig::AddEntityConfig(const std::string &UUID) {
ProvObjects::Entity E;
if(StorageService()->EntityDB().GetRecord("id",UUID,E)) {
AddConfiguration(E.configurations);
if(!E.parent.empty()) {
AddEntityConfig(E.parent);
}
} else {
}
}
void APConfig::AddVenueConfig(const std::string &UUID) {
ProvObjects::Venue V;
if(StorageService()->VenueDB().GetRecord("id",UUID,V)) {
AddConfiguration(V.configurations);
if(!V.entity.empty()) {
AddEntityConfig(V.entity);
} else if(!V.parent.empty()) {
AddVenueConfig(V.parent);
}
} else {
}
}
}

View File

@@ -4,52 +4,59 @@
#pragma once #pragma once
#include <string>
#include "Poco/Logger.h" #include "Poco/Logger.h"
#include "RESTObjects//RESTAPI_ProvObjects.h" #include "RESTObjects//RESTAPI_ProvObjects.h"
#include <string>
namespace OpenWifi { namespace OpenWifi {
constexpr std::uint64_t MaximumPossibleRadios=6; constexpr std::uint64_t MaximumPossibleRadios = 6;
struct VerboseElement { struct VerboseElement {
ProvObjects::DeviceConfigurationElement element; ProvObjects::DeviceConfigurationElement element;
ProvObjects::ObjectInfo info; ProvObjects::ObjectInfo info;
}; };
typedef std::vector<VerboseElement> ConfigVec; typedef std::vector<VerboseElement> ConfigVec;
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,
explicit APConfig(const std::string & SerialNumber, Poco::Logger & L); 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 Types::UUIDvec_t &UUID);
void AddConfiguration(const ProvObjects::DeviceConfigurationElementVec &Elements);
void AddVenueConfig(const std::string &UUID);
void AddEntityConfig(const std::string &UUID);
const Poco::JSON::Array &Explanation() { return Explanation_; };
void AddConfiguration(const std::string &UUID); private:
void AddConfiguration(const Types::UUIDvec_t &UUID); std::string SerialNumber_;
void AddConfiguration(const ProvObjects::DeviceConfigurationElementVec &Elements); std::string DeviceType_;
void AddVenueConfig(const std::string &UUID); Poco::Logger &Logger_;
void AddEntityConfig(const std::string &UUID); std::string CompleteConfig_;
const Poco::JSON::Array & Explanation() { return Explanation_; }; ConfigVec Config_;
private: Types::StringPairVec Errors;
std::string SerialNumber_; bool Explain_ = false;
std::string DeviceType_; Poco::JSON::Array Explanation_;
Poco::Logger & Logger_; bool Sub_ = false;
std::string CompleteConfig_; Poco::Logger &Logger() { return Logger_; }
ConfigVec Config_;
Types::StringPairVec Errors;
bool Explain_=false;
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 ReplaceVariablesInArray(const Poco::JSON::Array::Ptr &O,
bool ReplaceVariablesInObject( const Poco::JSON::Object::Ptr & Original, Poco::JSON::Object::Ptr & Result); 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,
bool mergeArray(const std::string &K, const Poco::JSON::Array::Ptr &A , const Poco::JSON::Array::Ptr &B, Poco::JSON::Array &Arr); Poco::JSON::Object::Ptr &Radio);
bool merge(const Poco::JSON::Object::Ptr & A, const Poco::JSON::Object::Ptr & B, Poco::JSON::Object::Ptr &C); bool mergeArray(const std::string &K, const Poco::JSON::Array::Ptr &A,
bool RemoveBand(const std::string &Band, const Poco::JSON::Array::Ptr &A_in,Poco::JSON::Array::Ptr &A_Out); const Poco::JSON::Array::Ptr &B, Poco::JSON::Array &Arr);
}; bool merge(const Poco::JSON::Object::Ptr &A, const Poco::JSON::Object::Ptr &B,
} Poco::JSON::Object::Ptr &C);
bool RemoveBand(const std::string &Band, const Poco::JSON::Array::Ptr &A_in,
Poco::JSON::Array::Ptr &A_Out);
};
} // namespace OpenWifi

View File

@@ -3,82 +3,87 @@
// //
#include "AutoDiscovery.h" #include "AutoDiscovery.h"
#include "framework/ow_constants.h"
#include "framework/KafkaTopics.h"
#include "framework/KafkaManager.h"
#include "StorageService.h"
#include "Poco/JSON/Parser.h" #include "Poco/JSON/Parser.h"
#include "StorageService.h"
#include "framework/KafkaManager.h"
#include "framework/KafkaTopics.h"
#include "framework/ow_constants.h"
namespace OpenWifi { namespace OpenWifi {
int AutoDiscovery::Start() { int AutoDiscovery::Start() {
poco_information(Logger(),"Starting..."); poco_information(Logger(), "Starting...");
Running_ = true; Running_ = true;
Types::TopicNotifyFunction F = [this](const std::string &Key, const std::string &Payload) { this->ConnectionReceived(Key,Payload); }; Types::TopicNotifyFunction F = [this](const std::string &Key, const std::string &Payload) {
ConnectionWatcherId_ = KafkaManager()->RegisterTopicWatcher(KafkaTopics::CONNECTION, F); this->ConnectionReceived(Key, Payload);
Worker_.start(*this); };
return 0; ConnectionWatcherId_ = KafkaManager()->RegisterTopicWatcher(KafkaTopics::CONNECTION, F);
}; Worker_.start(*this);
return 0;
};
void AutoDiscovery::Stop() { void AutoDiscovery::Stop() {
poco_information(Logger(),"Stopping..."); poco_information(Logger(), "Stopping...");
Running_ = false; Running_ = false;
KafkaManager()->UnregisterTopicWatcher(KafkaTopics::CONNECTION, ConnectionWatcherId_); KafkaManager()->UnregisterTopicWatcher(KafkaTopics::CONNECTION, ConnectionWatcherId_);
Queue_.wakeUpAll(); Queue_.wakeUpAll();
Worker_.join(); Worker_.join();
poco_information(Logger(),"Stopped..."); poco_information(Logger(), "Stopped...");
}; };
void AutoDiscovery::run() { void AutoDiscovery::run() {
Poco::AutoPtr<Poco::Notification> Note(Queue_.waitDequeueNotification()); Poco::AutoPtr<Poco::Notification> Note(Queue_.waitDequeueNotification());
Utils::SetThreadName("auto-discovery"); Utils::SetThreadName("auto-discovery");
while(Note && Running_) { while (Note && Running_) {
auto Msg = dynamic_cast<DiscoveryMessage *>(Note.get()); auto Msg = dynamic_cast<DiscoveryMessage *>(Note.get());
if(Msg!= nullptr) { if (Msg != nullptr) {
try { try {
Poco::JSON::Parser Parser; Poco::JSON::Parser Parser;
auto Object = Parser.parse(Msg->Payload()).extract<Poco::JSON::Object::Ptr>(); auto Object = Parser.parse(Msg->Payload()).extract<Poco::JSON::Object::Ptr>();
if (Object->has(uCentralProtocol::PAYLOAD)) { if (Object->has(uCentralProtocol::PAYLOAD)) {
auto PayloadObj = Object->getObject(uCentralProtocol::PAYLOAD); auto PayloadObj = Object->getObject(uCentralProtocol::PAYLOAD);
std::string ConnectedIP, SerialNumber, DeviceType; std::string ConnectedIP, SerialNumber, DeviceType;
if (PayloadObj->has(uCentralProtocol::CONNECTIONIP)) if (PayloadObj->has(uCentralProtocol::CONNECTIONIP))
ConnectedIP = PayloadObj->get(uCentralProtocol::CONNECTIONIP).toString(); ConnectedIP =
if (PayloadObj->has(uCentralProtocol::CAPABILITIES)) { PayloadObj->get(uCentralProtocol::CONNECTIONIP).toString();
auto CapObj = PayloadObj->getObject(uCentralProtocol::CAPABILITIES); if (PayloadObj->has(uCentralProtocol::CAPABILITIES)) {
if (CapObj->has(uCentralProtocol::COMPATIBLE)) { auto CapObj = PayloadObj->getObject(uCentralProtocol::CAPABILITIES);
DeviceType = CapObj->get(uCentralProtocol::COMPATIBLE).toString(); if (CapObj->has(uCentralProtocol::COMPATIBLE)) {
SerialNumber = PayloadObj->get(uCentralProtocol::SERIAL).toString(); DeviceType = CapObj->get(uCentralProtocol::COMPATIBLE).toString();
} SerialNumber = PayloadObj->get(uCentralProtocol::SERIAL).toString();
} else if (PayloadObj->has(uCentralProtocol::PING)) { }
auto PingMessage = PayloadObj->getObject(uCentralProtocol::PING); } else if (PayloadObj->has(uCentralProtocol::PING)) {
if (PingMessage->has(uCentralProtocol::FIRMWARE) && auto PingMessage = PayloadObj->getObject(uCentralProtocol::PING);
PingMessage->has(uCentralProtocol::SERIALNUMBER) && if (PingMessage->has(uCentralProtocol::FIRMWARE) &&
PingMessage->has(uCentralProtocol::COMPATIBLE)) { PingMessage->has(uCentralProtocol::SERIALNUMBER) &&
if (PingMessage->has(uCentralProtocol::CONNECTIONIP)) PingMessage->has(uCentralProtocol::COMPATIBLE)) {
ConnectedIP = PingMessage->get(uCentralProtocol::CONNECTIONIP).toString(); if (PingMessage->has(uCentralProtocol::CONNECTIONIP))
SerialNumber = PingMessage->get(uCentralProtocol::SERIALNUMBER).toString(); ConnectedIP =
DeviceType = PingMessage->get(uCentralProtocol::COMPATIBLE).toString(); PingMessage->get(uCentralProtocol::CONNECTIONIP).toString();
} SerialNumber =
} PingMessage->get(uCentralProtocol::SERIALNUMBER).toString();
std::string Locale; DeviceType =
if(PayloadObj->has("locale")) PingMessage->get(uCentralProtocol::COMPATIBLE).toString();
Locale = PayloadObj->get("locale").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, Locale);
} }
} catch (const Poco::Exception &E) { }
Logger().log(E); } catch (const Poco::Exception &E) {
} catch (...) { Logger().log(E);
} catch (...) {
}
} else {
}
Note = Queue_.waitDequeueNotification();
}
}
} } // namespace OpenWifi
} else {
}
Note = Queue_.waitDequeueNotification();
}
}
}

View File

@@ -7,53 +7,49 @@
#include "framework/OpenWifiTypes.h" #include "framework/OpenWifiTypes.h"
#include "framework/SubSystemServer.h" #include "framework/SubSystemServer.h"
#include "Poco/NotificationQueue.h"
#include "Poco/Notification.h" #include "Poco/Notification.h"
#include "Poco/NotificationQueue.h"
namespace OpenWifi { namespace OpenWifi {
class DiscoveryMessage : public Poco::Notification { class DiscoveryMessage : public Poco::Notification {
public: public:
explicit DiscoveryMessage(const std::string &Key, const std::string &Payload ) : explicit DiscoveryMessage(const std::string &Key, const std::string &Payload)
Key_(Key), : Key_(Key), Payload_(Payload) {}
Payload_(Payload) {} const std::string &Key() { return Key_; }
const std::string & Key() { return Key_; } const std::string &Payload() { return Payload_; }
const std::string & Payload() { return Payload_; }
private:
std::string Key_;
std::string Payload_;
};
class AutoDiscovery : public SubSystemServer, Poco::Runnable { private:
public: std::string Key_;
std::string Payload_;
};
static auto instance() { class AutoDiscovery : public SubSystemServer, Poco::Runnable {
static auto instance_ = new AutoDiscovery; public:
return instance_; static auto instance() {
} static auto instance_ = new AutoDiscovery;
return instance_;
}
int Start() override; int Start() override;
void Stop() override; void Stop() override;
void ConnectionReceived( const std::string & Key, const std::string & Payload) { void ConnectionReceived(const std::string &Key, const std::string &Payload) {
std::lock_guard G(Mutex_); std::lock_guard G(Mutex_);
poco_trace(Logger(),Poco::format("Device(%s): Connection/Ping message.", Key)); poco_trace(Logger(), Poco::format("Device(%s): Connection/Ping message.", Key));
Queue_.enqueueNotification( new DiscoveryMessage(Key,Payload)); Queue_.enqueueNotification(new DiscoveryMessage(Key, Payload));
} }
void run() override; void run() override;
private: private:
uint64_t ConnectionWatcherId_=0; uint64_t ConnectionWatcherId_ = 0;
Poco::NotificationQueue Queue_; Poco::NotificationQueue Queue_;
Poco::Thread Worker_; Poco::Thread Worker_;
std::atomic_bool Running_=false; std::atomic_bool Running_ = false;
AutoDiscovery() noexcept: AutoDiscovery() noexcept
SubSystemServer("AutoDiscovery", "AUTO-DISCOVERY", "discovery") : SubSystemServer("AutoDiscovery", "AUTO-DISCOVERY", "discovery") {}
{ };
}
};
inline auto AutoDiscovery() { return AutoDiscovery::instance(); } inline auto AutoDiscovery() { return AutoDiscovery::instance(); }
}
} // namespace OpenWifi

View File

@@ -4,50 +4,44 @@
#include "ConfigSanityChecker.h" #include "ConfigSanityChecker.h"
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
#include <iostream>
#include <iomanip> #include <iomanip>
#include <iostream>
namespace OpenWifi { namespace OpenWifi {
bool ConfigSanityChecker::Check() { bool ConfigSanityChecker::Check() {
try { try {
auto Doc = nlohmann::json::parse(Config_); auto Doc = nlohmann::json::parse(Config_);
for(const auto &[key,value]:Doc.items()) { for (const auto &[key, value] : Doc.items()) {
for(const auto &i:Funcs_) for (const auto &i : Funcs_)
if(i.first==key) if (i.first == key)
i.second(value); i.second(value);
} }
return true; return true;
} catch ( ... ) { } catch (...) {
}
return false;
}
} void ConfigSanityChecker::Check_radios([[maybe_unused]] nlohmann::json &d) {
return false; std::cout << "Validating radios" << std::endl;
} };
void ConfigSanityChecker::Check_radios([[maybe_unused]] nlohmann::json &d) { void ConfigSanityChecker::Check_interfaces([[maybe_unused]] nlohmann::json &d) {
std::cout << "Validating radios" << std::endl; std::cout << "Validating interfaces" << std::endl;
};
}; void ConfigSanityChecker::Check_metrics([[maybe_unused]] nlohmann::json &d) {
std::cout << "Validating metrics" << std::endl;
};
void ConfigSanityChecker::Check_interfaces([[maybe_unused]] nlohmann::json &d) { void ConfigSanityChecker::Check_services([[maybe_unused]] nlohmann::json &d) {
std::cout << "Validating interfaces" << std::endl; std::cout << "Validating services" << std::endl;
};
}; void ConfigSanityChecker::Check_uuid([[maybe_unused]] nlohmann::json &d) {
std::cout << "Validating uuid" << std::endl;
};
void ConfigSanityChecker::Check_metrics([[maybe_unused]] nlohmann::json &d) { } // namespace OpenWifi
std::cout << "Validating metrics" << std::endl;
};
void ConfigSanityChecker::Check_services([[maybe_unused]] nlohmann::json &d) {
std::cout << "Validating services" << std::endl;
};
void ConfigSanityChecker::Check_uuid([[maybe_unused]] nlohmann::json &d) {
std::cout << "Validating uuid" << std::endl;
};
}

View File

@@ -4,59 +4,57 @@
#pragma once #pragma once
#include <string>
#include <list>
#include <functional>
#include <map>
#include <vector>
#include <utility>
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
#include <functional>
#include <list>
#include <map>
#include <string>
#include <utility>
#include <vector>
namespace OpenWifi { namespace OpenWifi {
struct SanityError { struct SanityError {
std::string Cause; std::string Cause;
std::string Reason; std::string Reason;
std::string Severity; std::string Severity;
}; };
typedef std::list<SanityError> SanityErrorList; typedef std::list<SanityError> SanityErrorList;
class ConfigSanityChecker { class ConfigSanityChecker {
public: public:
explicit ConfigSanityChecker(std::string Config, std::string DeviceType) : explicit ConfigSanityChecker(std::string Config, std::string DeviceType)
Config_(std::move(Config)), : Config_(std::move(Config)), DeviceType_(std::move(DeviceType)) {}
DeviceType_(std::move(DeviceType)){}
bool Check(); bool Check();
const SanityErrorList & Errors() { return Errors_; } const SanityErrorList &Errors() { return Errors_; }
const SanityErrorList & Warnings() { return Warnings_; } const SanityErrorList &Warnings() { return Warnings_; }
typedef std::function<void(nlohmann::json &)> CheckFuncType; typedef std::function<void(nlohmann::json &)> CheckFuncType;
struct KeyToFunc { struct KeyToFunc {
std::string Key; std::string Key;
CheckFuncType Func; CheckFuncType Func;
}; };
typedef std::pair<std::string, CheckFuncType> FuncPair; typedef std::pair<std::string, CheckFuncType> FuncPair;
typedef std::vector<FuncPair> FuncList; typedef std::vector<FuncPair> FuncList;
void Check_radios(nlohmann::json &); void Check_radios(nlohmann::json &);
void Check_interfaces(nlohmann::json &); void Check_interfaces(nlohmann::json &);
void Check_metrics(nlohmann::json &); void Check_metrics(nlohmann::json &);
void Check_services(nlohmann::json &); void Check_services(nlohmann::json &);
void Check_uuid(nlohmann::json &); void Check_uuid(nlohmann::json &);
private: private:
std::string Config_; std::string Config_;
std::string DeviceType_; std::string DeviceType_;
SanityErrorList Errors_; SanityErrorList Errors_;
SanityErrorList Warnings_; SanityErrorList Warnings_;
FuncList Funcs_{ FuncList Funcs_{
std::make_pair("radios", [this](nlohmann::json &d){ this->Check_radios(d);} ) , std::make_pair("radios", [this](nlohmann::json &d) { this->Check_radios(d); }),
std::make_pair("interfaces", [this](nlohmann::json &d){ this->Check_interfaces(d);} ), std::make_pair("interfaces", [this](nlohmann::json &d) { this->Check_interfaces(d); }),
std::make_pair("metrics", [this](nlohmann::json &d){ this->Check_metrics(d);} ), std::make_pair("metrics", [this](nlohmann::json &d) { this->Check_metrics(d); }),
std::make_pair("services", [this](nlohmann::json &d){ this->Check_services(d);} ), std::make_pair("services", [this](nlohmann::json &d) { this->Check_services(d); }),
std::make_pair("uuid", [this](nlohmann::json &d){ this->Check_uuid(d);} ) std::make_pair("uuid", [this](nlohmann::json &d) { this->Check_uuid(d); })};
}; };
}; } // namespace OpenWifi
}

View File

@@ -6,101 +6,91 @@
// Arilia Wireless Inc. // Arilia Wireless Inc.
// //
#include "Poco/Util/Application.h"
#include "Poco/Util/Option.h"
#include "Poco/Environment.h" #include "Poco/Environment.h"
#include "Poco/Net/SSLManager.h" #include "Poco/Net/SSLManager.h"
#include "Poco/Util/Application.h"
#include "Poco/Util/Option.h"
#include "Daemon.h"
#include "StorageService.h"
#include "AutoDiscovery.h" #include "AutoDiscovery.h"
#include "framework/ConfigurationValidator.h" #include "Daemon.h"
#include "SerialNumberCache.h"
#include "JobController.h"
#include "FindCountry.h"
#include "Signup.h"
#include "DeviceTypeCache.h" #include "DeviceTypeCache.h"
#include "FileDownloader.h" #include "FileDownloader.h"
#include "framework/UI_WebSocketClientServer.h" #include "FindCountry.h"
#include "JobController.h"
#include "SerialNumberCache.h"
#include "Signup.h"
#include "StorageService.h"
#include "UI_Prov_WebSocketNotifications.h" #include "UI_Prov_WebSocketNotifications.h"
#include "framework/ConfigurationValidator.h"
#include "framework/UI_WebSocketClientServer.h"
namespace OpenWifi { namespace OpenWifi {
class Daemon *Daemon::instance_ = nullptr; class Daemon *Daemon::instance_ = nullptr;
class Daemon *Daemon::instance() { class Daemon *Daemon::instance() {
if (instance_ == nullptr) { if (instance_ == nullptr) {
instance_ = new Daemon(vDAEMON_PROPERTIES_FILENAME, instance_ = new Daemon(vDAEMON_PROPERTIES_FILENAME, vDAEMON_ROOT_ENV_VAR,
vDAEMON_ROOT_ENV_VAR, vDAEMON_CONFIG_ENV_VAR, vDAEMON_APP_NAME, vDAEMON_BUS_TIMER,
vDAEMON_CONFIG_ENV_VAR, SubSystemVec{OpenWifi::StorageService(), DeviceTypeCache(),
vDAEMON_APP_NAME, ConfigurationValidator(), SerialNumberCache(),
vDAEMON_BUS_TIMER, AutoDiscovery(), JobController(),
SubSystemVec{ UI_WebSocketClientServer(), FindCountryFromIP(),
OpenWifi::StorageService(), Signup(), FileDownloader()});
DeviceTypeCache(),
ConfigurationValidator(),
SerialNumberCache(),
AutoDiscovery(),
JobController(),
UI_WebSocketClientServer(),
FindCountryFromIP(),
Signup(),
FileDownloader()
});
} }
return instance_; return instance_;
} }
void Daemon::PostInitialization([[maybe_unused]] Poco::Util::Application &self) { void Daemon::PostInitialization([[maybe_unused]] Poco::Util::Application &self) {
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;
} else { } else {
FWRules_ = ProvObjects::upgrade_latest; FWRules_ = ProvObjects::upgrade_latest;
} }
} else { } else {
FWRules_ = ProvObjects::dont_upgrade; FWRules_ = ProvObjects::dont_upgrade;
} }
WebSocketProcessor_ = std::make_unique<ProvWebSocketClient>(logger()); WebSocketProcessor_ = std::make_unique<ProvWebSocketClient>(logger());
AssetDir_ = MicroService::instance().DataDir() + "/wwwassets"; AssetDir_ = MicroService::instance().DataDir() + "/wwwassets";
Poco::File DataDir(AssetDir_); Poco::File DataDir(AssetDir_);
if(!DataDir.exists()) { if (!DataDir.exists()) {
try { try {
DataDir.createDirectory(); DataDir.createDirectory();
} catch (const Poco::Exception &E) { } catch (const Poco::Exception &E) {
logger().log(E); logger().log(E);
} }
} }
} }
void DaemonPostInitialization(Poco::Util::Application &self) { void DaemonPostInitialization(Poco::Util::Application &self) {
Daemon()->PostInitialization(self); Daemon()->PostInitialization(self);
ProvWebSocketNotifications::Register(); ProvWebSocketNotifications::Register();
} }
} } // namespace OpenWifi
int main(int argc, char **argv) { int main(int argc, char **argv) {
int ExitCode; int ExitCode;
try { try {
Poco::Net::SSLManager::instance().initializeServer(nullptr, nullptr, nullptr); Poco::Net::SSLManager::instance().initializeServer(nullptr, nullptr, nullptr);
auto App = OpenWifi::Daemon::instance(); auto App = OpenWifi::Daemon::instance();
ExitCode = App->run(argc, argv); ExitCode = App->run(argc, argv);
Poco::Net::SSLManager::instance().shutdown(); Poco::Net::SSLManager::instance().shutdown();
} catch (Poco::Exception &exc) { } catch (Poco::Exception &exc) {
ExitCode = Poco::Util::Application::EXIT_SOFTWARE; ExitCode = Poco::Util::Application::EXIT_SOFTWARE;
std::cout << exc.displayText() << std::endl; std::cout << exc.displayText() << std::endl;
} catch (std::exception &exc) { } catch (std::exception &exc) {
ExitCode = Poco::Util::Application::EXIT_TEMPFAIL; ExitCode = Poco::Util::Application::EXIT_TEMPFAIL;
std::cout << exc.what() << std::endl; std::cout << exc.what() << std::endl;
} catch (...) { } catch (...) {
ExitCode = Poco::Util::Application::EXIT_TEMPFAIL; ExitCode = Poco::Util::Application::EXIT_TEMPFAIL;
std::cout << "Exception on closure" << std::endl; std::cout << "Exception on closure" << std::endl;
} }
std::cout << "Exitcode: " << ExitCode << std::endl; std::cout << "Exitcode: " << ExitCode << std::endl;
return ExitCode; return ExitCode;
} }
// end of namespace // end of namespace

View File

@@ -9,52 +9,48 @@
#pragma once #pragma once
#include <array> #include <array>
#include <iostream>
#include <cstdlib> #include <cstdlib>
#include <vector> #include <iostream>
#include <set> #include <set>
#include <vector>
#include "Dashboard.h" #include "Dashboard.h"
#include "ProvWebSocketClient.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
#include "framework/MicroService.h" #include "framework/MicroService.h"
#include "framework/MicroServiceNames.h" #include "framework/MicroServiceNames.h"
#include "framework/OpenWifiTypes.h" #include "framework/OpenWifiTypes.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
#include "ProvWebSocketClient.h"
namespace OpenWifi { namespace OpenWifi {
[[maybe_unused]] static const char * vDAEMON_PROPERTIES_FILENAME = "owprov.properties"; [[maybe_unused]] static const char *vDAEMON_PROPERTIES_FILENAME = "owprov.properties";
[[maybe_unused]] static const char * vDAEMON_ROOT_ENV_VAR = "OWPROV_ROOT"; [[maybe_unused]] static const char *vDAEMON_ROOT_ENV_VAR = "OWPROV_ROOT";
[[maybe_unused]] static const char * vDAEMON_CONFIG_ENV_VAR = "OWPROV_CONFIG"; [[maybe_unused]] static const char *vDAEMON_CONFIG_ENV_VAR = "OWPROV_CONFIG";
[[maybe_unused]] static const char * vDAEMON_APP_NAME = uSERVICE_PROVISIONING.c_str() ; [[maybe_unused]] static const char *vDAEMON_APP_NAME = uSERVICE_PROVISIONING.c_str();
[[maybe_unused]] static const uint64_t vDAEMON_BUS_TIMER = 10000; [[maybe_unused]] static const uint64_t vDAEMON_BUS_TIMER = 10000;
class Daemon : public MicroService { class Daemon : public MicroService {
public: public:
explicit Daemon(const std::string & PropFile, explicit Daemon(const std::string &PropFile, const std::string &RootEnv,
const std::string & RootEnv, const std::string &ConfigEnv, const std::string &AppName, uint64_t BusTimer,
const std::string & ConfigEnv, const SubSystemVec &SubSystems)
const std::string & AppName, : MicroService(PropFile, RootEnv, ConfigEnv, AppName, BusTimer, SubSystems){};
uint64_t BusTimer,
const SubSystemVec & SubSystems) :
MicroService( PropFile, RootEnv, ConfigEnv, AppName, BusTimer, SubSystems) {};
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_; } inline const std::string &AssetDir() { return AssetDir_; }
void PostInitialization(Poco::Util::Application &self); 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::string AssetDir_;
std::unique_ptr<ProvWebSocketClient> WebSocketProcessor_; std::unique_ptr<ProvWebSocketClient> WebSocketProcessor_;
}; };
inline Daemon * Daemon() { return Daemon::instance(); }
void DaemonPostInitialization(Poco::Util::Application &self);
}
inline Daemon *Daemon() { return Daemon::instance(); }
void DaemonPostInitialization(Poco::Util::Application &self);
} // namespace OpenWifi

View File

@@ -11,10 +11,10 @@
namespace OpenWifi { namespace OpenWifi {
void ProvisioningDashboard::Create() { void ProvisioningDashboard::Create() {
uint64_t Now = Utils::Now(); uint64_t Now = Utils::Now();
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.
LastRun_ = Now; LastRun_ = Now;
} }
} }
} } // namespace OpenWifi

View File

@@ -8,17 +8,21 @@
#pragma once #pragma once
#include "framework/OpenWifiTypes.h"
#include "RESTObjects/RESTAPI_ProvObjects.h" #include "RESTObjects/RESTAPI_ProvObjects.h"
#include "framework/OpenWifiTypes.h"
namespace OpenWifi { namespace OpenWifi {
class ProvisioningDashboard { class ProvisioningDashboard {
public: public:
void Create(); void Create();
[[nodiscard]] const ProvObjects::Report & Report() const { return DB_;} [[nodiscard]] const ProvObjects::Report &Report() const { return DB_; }
inline void Reset() { LastRun_=0; DB_.reset(); } inline void Reset() {
LastRun_ = 0;
DB_.reset();
}
private: private:
ProvObjects::Report DB_{}; ProvObjects::Report DB_{};
uint64_t LastRun_=0; uint64_t LastRun_ = 0;
}; };
} } // namespace OpenWifi

View File

@@ -6,125 +6,119 @@
#include <set> #include <set>
#include "framework/SubSystemServer.h"
#include "framework/AppServiceRegistry.h" #include "framework/AppServiceRegistry.h"
#include "framework/OpenAPIRequests.h"
#include "framework/MicroServiceNames.h" #include "framework/MicroServiceNames.h"
#include "framework/OpenAPIRequests.h"
#include "framework/SubSystemServer.h"
#include "Poco/Timer.h" #include "Poco/Timer.h"
namespace OpenWifi { namespace OpenWifi {
class DeviceTypeCache : public SubSystemServer { class DeviceTypeCache : public SubSystemServer {
public: public:
inline static auto instance() { inline static auto instance() {
static auto instance_ = new DeviceTypeCache; static auto instance_ = new DeviceTypeCache;
return instance_; return instance_;
} }
inline int Start() final { inline int Start() final {
InitializeCache(); InitializeCache();
TimerCallback_ = std::make_unique<Poco::TimerCallback<DeviceTypeCache>>(*this,&DeviceTypeCache::onTimer); TimerCallback_ = std::make_unique<Poco::TimerCallback<DeviceTypeCache>>(
Timer_.setStartInterval( 60 * 1000); // first run in 60 seconds *this, &DeviceTypeCache::onTimer);
Timer_.setPeriodicInterval(1 * 60 * 60 * 1000); // 1 hours Timer_.setStartInterval(60 * 1000); // first run in 60 seconds
Timer_.start(*TimerCallback_); Timer_.setPeriodicInterval(1 * 60 * 60 * 1000); // 1 hours
return 0; Timer_.start(*TimerCallback_);
} return 0;
}
inline void Stop() final { inline void Stop() final { Timer_.stop(); }
Timer_.stop();
}
inline void onTimer([[maybe_unused]] Poco::Timer & timer) { inline void onTimer([[maybe_unused]] Poco::Timer &timer) { UpdateDeviceTypes(); }
UpdateDeviceTypes();
}
inline bool IsAcceptableDeviceType(const std::string &D) const { return (DeviceTypes_.find(D)!=DeviceTypes_.end());}; inline bool IsAcceptableDeviceType(const std::string &D) const {
inline bool AreAcceptableDeviceTypes(const Types::StringVec &S, bool WildCardAllowed=true) const { return (DeviceTypes_.find(D) != DeviceTypes_.end());
for(const auto &i:S) { };
if(WildCardAllowed && i=="*") { inline bool AreAcceptableDeviceTypes(const Types::StringVec &S,
// We allow wildcards bool WildCardAllowed = true) const {
} else if(DeviceTypes_.find(i)==DeviceTypes_.end()) for (const auto &i : S) {
return false; if (WildCardAllowed && i == "*") {
} // We allow wildcards
return true; } else if (DeviceTypes_.find(i) == DeviceTypes_.end())
} return false;
}
return true;
}
private: private:
std::atomic_bool Initialized_=false; std::atomic_bool Initialized_ = false;
Poco::Timer Timer_; Poco::Timer Timer_;
std::set<std::string> DeviceTypes_; std::set<std::string> DeviceTypes_;
std::unique_ptr<Poco::TimerCallback<DeviceTypeCache>> TimerCallback_; std::unique_ptr<Poco::TimerCallback<DeviceTypeCache>> TimerCallback_;
inline DeviceTypeCache() noexcept: inline DeviceTypeCache() noexcept
SubSystemServer("DeviceTypes", "DEV-TYPES", "devicetypes") : SubSystemServer("DeviceTypes", "DEV-TYPES", "devicetypes") {}
{
}
inline void InitializeCache() { inline void InitializeCache() {
std::lock_guard G(Mutex_); std::lock_guard G(Mutex_);
Initialized_ = true; Initialized_ = true;
std::string DeviceTypes; std::string DeviceTypes;
if(AppServiceRegistry().Get("deviceTypes",DeviceTypes)) { if (AppServiceRegistry().Get("deviceTypes", DeviceTypes)) {
Poco::JSON::Parser P; Poco::JSON::Parser P;
try { try {
auto O = P.parse(DeviceTypes).extract<Poco::JSON::Array::Ptr>(); auto O = P.parse(DeviceTypes).extract<Poco::JSON::Array::Ptr>();
for(const auto &i:*O) { for (const auto &i : *O) {
DeviceTypes_.insert(i.toString()); DeviceTypes_.insert(i.toString());
} }
} catch (...) { } catch (...) {
}
}
}
} inline bool UpdateDeviceTypes() {
} try {
} Types::StringPairVec QueryData;
inline bool UpdateDeviceTypes() { QueryData.push_back(std::make_pair("deviceSet", "true"));
try { OpenAPIRequestGet Req(uSERVICE_FIRMWARE, "/api/v1/firmwares", QueryData, 10000);
Types::StringPairVec QueryData;
QueryData.push_back(std::make_pair("deviceSet","true")); auto Response = Poco::makeShared<Poco::JSON::Object>();
OpenAPIRequestGet Req( uSERVICE_FIRMWARE, auto StatusCode = Req.Do(Response);
"/api/v1/firmwares", if (StatusCode == Poco::Net::HTTPResponse::HTTP_OK) {
QueryData, if (Response->isArray("deviceTypes")) {
10000); 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;
}
auto Response = Poco::makeShared<Poco::JSON::Object>(); inline void SaveCache() {
auto StatusCode = Req.Do(Response); std::lock_guard G(Mutex_);
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() { Poco::JSON::Array Arr;
std::lock_guard G(Mutex_); for (auto const &i : DeviceTypes_)
Arr.add(i);
Poco::JSON::Array Arr; std::stringstream OS;
for(auto const &i:DeviceTypes_) Arr.stringify(OS);
Arr.add(i);
std::stringstream OS; AppServiceRegistry().Set("deviceTypes", OS.str());
Arr.stringify(OS); }
};
AppServiceRegistry().Set("deviceTypes", OS.str()); inline auto DeviceTypeCache() { return DeviceTypeCache::instance(); }
}
};
inline auto DeviceTypeCache() { return DeviceTypeCache::instance(); } } // namespace OpenWifi
}

View File

@@ -6,42 +6,42 @@
#include "Daemon.h" #include "Daemon.h"
namespace OpenWifi { namespace OpenWifi {
int FileDownloader::Start() { int FileDownloader::Start() {
poco_information(Logger(),"Starting..."); poco_information(Logger(), "Starting...");
TimerCallback_ = std::make_unique<Poco::TimerCallback<FileDownloader>>(*this,&FileDownloader::onTimer); TimerCallback_ =
Timer_.setStartInterval( 20 * 1000); // first run in 20 seconds std::make_unique<Poco::TimerCallback<FileDownloader>>(*this, &FileDownloader::onTimer);
Timer_.setPeriodicInterval(2 * 60 * 60 * 1000); // 1 hours Timer_.setStartInterval(20 * 1000); // first run in 20 seconds
Timer_.start(*TimerCallback_); Timer_.setPeriodicInterval(2 * 60 * 60 * 1000); // 1 hours
return 0; Timer_.start(*TimerCallback_);
} return 0;
}
void FileDownloader::Stop() { void FileDownloader::Stop() {
poco_information(Logger(),"Stopping..."); poco_information(Logger(), "Stopping...");
Timer_.stop(); Timer_.stop();
poco_information(Logger(),"Stopped..."); poco_information(Logger(), "Stopped...");
} }
void FileDownloader::onTimer([[maybe_unused]] Poco::Timer &timer) { void FileDownloader::onTimer([[maybe_unused]] Poco::Timer &timer) {
const static std::vector<std::pair<std::string,std::string>> Files const static std::vector<std::pair<std::string, std::string>> Files{
{ {"https://raw.githubusercontent.com/blogic/ucentral-schema/main/ucentral.schema.json",
{"https://raw.githubusercontent.com/blogic/ucentral-schema/main/ucentral.schema.json", "ucentral.schema.json" }, "ucentral.schema.json"},
{"https://ucentral.io/ucentral.schema.pretty.json", "ucentral.schema.pretty.json" } {"https://ucentral.io/ucentral.schema.pretty.json", "ucentral.schema.pretty.json"}};
};
Utils::SetThreadName("file-dmnldr"); Utils::SetThreadName("file-dmnldr");
for(const auto &[url,filename]:Files) { for (const auto &[url, filename] : Files) {
try { try {
std::string FileContent; std::string FileContent;
if (Utils::wgets(url, FileContent)) { if (Utils::wgets(url, FileContent)) {
std::ofstream OutputStream(Daemon()->AssetDir() + "/" + filename, std::ofstream OutputStream(Daemon()->AssetDir() + "/" + filename,
std::ios_base::out | std::ios_base::trunc); std::ios_base::out | std::ios_base::trunc);
OutputStream << FileContent; OutputStream << FileContent;
Logger().warning(Poco::format("File %s was downloaded",url)); Logger().warning(Poco::format("File %s was downloaded", url));
} }
} catch(...) { } catch (...) {
Logger().warning(Poco::format("File %s could not be downloaded",url)); Logger().warning(Poco::format("File %s could not be downloaded", url));
} }
} }
} }
} } // namespace OpenWifi

View File

@@ -3,32 +3,30 @@
// //
#pragma once #pragma once
#include "framework/SubSystemServer.h"
#include "Poco/Timer.h" #include "Poco/Timer.h"
#include "framework/SubSystemServer.h"
namespace OpenWifi { namespace OpenWifi {
class FileDownloader : public SubSystemServer { class FileDownloader : public SubSystemServer {
public: public:
static auto instance() {
static auto instance_ = new FileDownloader;
return instance_;
}
static auto instance() { int Start() override;
static auto instance_ = new FileDownloader; void Stop() override;
return instance_; void onTimer(Poco::Timer &timer);
}
int Start() override; private:
void Stop() override; Poco::Timer Timer_;
void onTimer(Poco::Timer & timer); std::unique_ptr<Poco::TimerCallback<FileDownloader>> TimerCallback_;
std::atomic_bool Running_ = false;
private: FileDownloader() noexcept
Poco::Timer Timer_; : SubSystemServer("FileDownloader", "FILE-DOWNLOADER", "downloader") {}
std::unique_ptr<Poco::TimerCallback<FileDownloader>> TimerCallback_; };
std::atomic_bool Running_ = false;
FileDownloader() noexcept: inline auto FileDownloader() { return FileDownloader::instance(); }
SubSystemServer("FileDownloader", "FILE-DOWNLOADER", "downloader") { } // namespace OpenWifi
}
};
inline auto FileDownloader() { return FileDownloader::instance(); }
}

View File

@@ -6,8 +6,8 @@
#include "Poco/Net/IPAddress.h" #include "Poco/Net/IPAddress.h"
#include "framework/SubSystemServer.h"
#include "framework/MicroServiceFuncs.h" #include "framework/MicroServiceFuncs.h"
#include "framework/SubSystemServer.h"
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
@@ -15,11 +15,10 @@ namespace OpenWifi {
class IPToCountryProvider { class IPToCountryProvider {
public: public:
virtual bool Init() = 0 ; virtual bool Init() = 0;
virtual Poco::URI URI(const std::string & IPAddress) = 0; virtual Poco::URI URI(const std::string &IPAddress) = 0;
virtual std::string Country( const std::string & Response ) = 0 ; virtual std::string Country(const std::string &Response) = 0;
virtual ~IPToCountryProvider() { virtual ~IPToCountryProvider(){};
};
}; };
class IPInfo : public IPToCountryProvider { class IPInfo : public IPToCountryProvider {
@@ -30,28 +29,26 @@ namespace OpenWifi {
return !Key_.empty(); return !Key_.empty();
} }
[[nodiscard]] inline Poco::URI URI(const std::string & IPAddress) override { [[nodiscard]] inline Poco::URI URI(const std::string &IPAddress) override {
Poco::URI U("https://ipinfo.io"); Poco::URI U("https://ipinfo.io");
U.setPath("/" + IPAddress); U.setPath("/" + IPAddress);
U.addQueryParameter("token",Key_); U.addQueryParameter("token", Key_);
return U; return U;
} }
inline std::string Country( const std::string & Response ) override { inline std::string Country(const std::string &Response) override {
try { try {
nlohmann::json IPInfo = nlohmann::json::parse(Response); nlohmann::json IPInfo = nlohmann::json::parse(Response);
if (IPInfo.contains("country") && IPInfo["country"].is_string()) { if (IPInfo.contains("country") && IPInfo["country"].is_string()) {
return IPInfo["country"]; return IPInfo["country"];
} }
} catch (...) { } catch (...) {
} }
return ""; return "";
} }
private: private:
std::string Key_; std::string Key_;
}; };
class IPData : public IPToCountryProvider { class IPData : public IPToCountryProvider {
@@ -62,24 +59,24 @@ namespace OpenWifi {
return !Key_.empty(); return !Key_.empty();
} }
[[nodiscard]] inline Poco::URI URI(const std::string & IPAddress) override { [[nodiscard]] inline Poco::URI URI(const std::string &IPAddress) override {
Poco::URI U("https://api.ipdata.co"); Poco::URI U("https://api.ipdata.co");
U.setPath("/" + IPAddress); U.setPath("/" + IPAddress);
U.addQueryParameter("api-key",Key_); U.addQueryParameter("api-key", Key_);
return U; return U;
} }
inline std::string Country( const std::string & Response ) override { inline std::string Country(const std::string &Response) override {
try { try {
nlohmann::json IPInfo = nlohmann::json::parse(Response); nlohmann::json IPInfo = nlohmann::json::parse(Response);
if (IPInfo.contains("country_code") && IPInfo["country_code"].is_string()) { if (IPInfo.contains("country_code") && IPInfo["country_code"].is_string()) {
return IPInfo["country_code"]; return IPInfo["country_code"];
} }
} catch (...) { } catch (...) {
} }
return ""; return "";
} }
private: private:
std::string Key_; std::string Key_;
}; };
@@ -92,33 +89,33 @@ namespace OpenWifi {
return !Key_.empty(); return !Key_.empty();
} }
[[nodiscard]] inline Poco::URI URI(const std::string & IPAddress) override { [[nodiscard]] inline Poco::URI URI(const std::string &IPAddress) override {
Poco::URI U("https://api.ip2location.com/v2"); Poco::URI U("https://api.ip2location.com/v2");
U.setPath("/"); U.setPath("/");
U.addQueryParameter("ip", IPAddress); U.addQueryParameter("ip", IPAddress);
U.addQueryParameter("package", "WS1"); U.addQueryParameter("package", "WS1");
U.addQueryParameter("key",Key_); U.addQueryParameter("key", Key_);
return U; return U;
} }
inline std::string Country( const std::string & Response ) override { inline std::string Country(const std::string &Response) override {
try { try {
nlohmann::json IPInfo = nlohmann::json::parse(Response); nlohmann::json IPInfo = nlohmann::json::parse(Response);
if (IPInfo.contains("country_code") && IPInfo["country_code"].is_string()) { if (IPInfo.contains("country_code") && IPInfo["country_code"].is_string()) {
return IPInfo["country_code"]; return IPInfo["country_code"];
} }
} catch (...) { } catch (...) {
} }
return ""; return "";
} }
private: private:
std::string Key_; std::string Key_;
}; };
template<typename BaseClass, typename T, typename... Args> template <typename BaseClass, typename T, typename... Args>
std::unique_ptr<BaseClass> IPLocationProvider(const std::string & RequestProvider ) { std::unique_ptr<BaseClass> IPLocationProvider(const std::string &RequestProvider) {
if(T::Name()==RequestProvider) { if (T::Name() == RequestProvider) {
return std::make_unique<T>(); return std::make_unique<T>();
} }
if constexpr (sizeof...(Args) == 0) { if constexpr (sizeof...(Args) == 0) {
@@ -136,11 +133,12 @@ namespace OpenWifi {
} }
inline int Start() final { inline int Start() final {
poco_notice(Logger(),"Starting..."); poco_notice(Logger(), "Starting...");
ProviderName_ = MicroServiceConfigGetString("iptocountry.provider",""); ProviderName_ = MicroServiceConfigGetString("iptocountry.provider", "");
if(!ProviderName_.empty()) { if (!ProviderName_.empty()) {
Provider_ = IPLocationProvider<IPToCountryProvider, IPInfo, IPData, IP2Location>(ProviderName_); Provider_ = IPLocationProvider<IPToCountryProvider, IPInfo, IPData, IP2Location>(
if(Provider_!= nullptr) { ProviderName_);
if (Provider_ != nullptr) {
Enabled_ = Provider_->Init(); Enabled_ = Provider_->Init();
} }
} }
@@ -149,28 +147,26 @@ namespace OpenWifi {
} }
inline void Stop() final { inline void Stop() final {
poco_notice(Logger(),"Stopping..."); poco_notice(Logger(), "Stopping...");
// Nothing to do - just to provide the same look at the others. // Nothing to do - just to provide the same look at the others.
poco_notice(Logger(),"Stopped..."); poco_notice(Logger(), "Stopped...");
} }
[[nodiscard]] static inline std::string ReformatAddress(const std::string & I ) [[nodiscard]] static inline std::string ReformatAddress(const std::string &I) {
{ if (I.substr(0, 7) == "::ffff:") {
if(I.substr(0,7) == "::ffff:") std::string ip = I.substr(7);
{
std::string ip = I.substr(7 );
return ip; return ip;
} }
return I; return I;
} }
inline std::string Get(const Poco::Net::IPAddress & IP) { inline std::string Get(const Poco::Net::IPAddress &IP) {
if (!Enabled_) if (!Enabled_)
return Default_; return Default_;
return Get(ReformatAddress(IP.toString())); return Get(ReformatAddress(IP.toString()));
} }
inline std::string Get(const std::string & IP) { inline std::string Get(const std::string &IP) {
if (!Enabled_) if (!Enabled_)
return Default_; return Default_;
try { try {
@@ -178,10 +174,10 @@ namespace OpenWifi {
std::string Response; std::string Response;
if (Utils::wgets(URL, Response)) { if (Utils::wgets(URL, Response)) {
auto Answer = Provider_->Country(Response); auto Answer = Provider_->Country(Response);
if(!Answer.empty()) if (!Answer.empty())
return Answer; return Answer;
} }
} catch(...) { } catch (...) {
} }
return Default_; return Default_;
} }
@@ -189,17 +185,14 @@ namespace OpenWifi {
inline auto Enabled() const { return Enabled_; } inline auto Enabled() const { return Enabled_; }
private: private:
bool Enabled_=false; bool Enabled_ = false;
std::string Default_; std::string Default_;
std::unique_ptr<IPToCountryProvider> Provider_; std::unique_ptr<IPToCountryProvider> Provider_;
std::string ProviderName_; std::string ProviderName_;
FindCountryFromIP() noexcept: FindCountryFromIP() noexcept : SubSystemServer("IpToCountry", "IPTOC-SVR", "iptocountry") {}
SubSystemServer("IpToCountry", "IPTOC-SVR", "iptocountry")
{
}
}; };
inline auto FindCountryFromIP() { return FindCountryFromIP::instance(); } inline auto FindCountryFromIP() { return FindCountryFromIP::instance(); }
} } // namespace OpenWifi

View File

@@ -3,59 +3,63 @@
// //
#include "JobController.h" #include "JobController.h"
#include "framework/utils.h"
#include "fmt/format.h" #include "fmt/format.h"
#include "framework/utils.h"
namespace OpenWifi { namespace OpenWifi {
void RegisterJobTypes(); void RegisterJobTypes();
int JobController::Start() { int JobController::Start() {
poco_information(Logger(),"Starting..."); poco_information(Logger(), "Starting...");
RegisterJobTypes(); RegisterJobTypes();
if(!Running_) if (!Running_)
Thr_.start(*this); Thr_.start(*this);
return 0; return 0;
} }
void JobController::Stop() { void JobController::Stop() {
if(Running_) { if (Running_) {
poco_information(Logger(),"Stopping..."); poco_information(Logger(), "Stopping...");
Running_ = false; Running_ = false;
Thr_.join(); Thr_.join();
poco_information(Logger(),"Stopped..."); poco_information(Logger(), "Stopped...");
} }
} }
void JobController::run() { void JobController::run() {
Running_ = true ; Running_ = true;
Utils::SetThreadName("job-controller"); Utils::SetThreadName("job-controller");
while(Running_) { while (Running_) {
Poco::Thread::trySleep(2000); Poco::Thread::trySleep(2000);
std::lock_guard G(Mutex_); std::lock_guard G(Mutex_);
for(auto &current_job:jobs_) { for (auto &current_job : jobs_) {
if(current_job!=nullptr) { if (current_job != nullptr) {
if(current_job->Started()==0 && Pool_.used()<Pool_.available()) { if (current_job->Started() == 0 && Pool_.used() < Pool_.available()) {
poco_information(current_job->Logger(),fmt::format("Starting {}: {}",current_job->JobId(),current_job->Name())); poco_information(current_job->Logger(),
current_job->Start(); fmt::format("Starting {}: {}", current_job->JobId(),
Pool_.start(*current_job); current_job->Name()));
} current_job->Start();
} Pool_.start(*current_job);
} }
}
}
for(auto it = jobs_.begin(); it!=jobs_.end();) {\ for (auto it = jobs_.begin(); it != jobs_.end();) {
auto current_job = *it; auto current_job = *it;
if(current_job!=nullptr && current_job->Completed()!=0) { if (current_job != nullptr && current_job->Completed() != 0) {
poco_information(current_job->Logger(),fmt::format("Completed {}: {}",current_job->JobId(),current_job->Name())); poco_information(
it = jobs_.erase(it); current_job->Logger(),
delete current_job; fmt::format("Completed {}: {}", current_job->JobId(), current_job->Name()));
} else { it = jobs_.erase(it);
++it; delete current_job;
} } else {
} ++it;
} }
} }
} }
}
} // namespace OpenWifi

View File

@@ -4,79 +4,72 @@
#pragma once #pragma once
#include <vector> #include "RESTObjects/RESTAPI_SecurityObjects.h"
#include <utility> #include "framework/SubSystemServer.h"
#include "framework/utils.h"
#include <functional> #include <functional>
#include <list> #include <list>
#include "framework/SubSystemServer.h" #include <utility>
#include "RESTObjects/RESTAPI_SecurityObjects.h" #include <vector>
#include "framework/utils.h"
namespace OpenWifi { namespace OpenWifi {
class Job : public Poco::Runnable { class Job : public Poco::Runnable {
public: public:
Job(const std::string &JobID, const std::string &name, const std::vector<std::string> & parameters, uint64_t when, const SecurityObjects::UserInfo &UI, Poco::Logger &L) : Job(const std::string &JobID, const std::string &name,
jobId_(JobID), const std::vector<std::string> &parameters, uint64_t when,
name_(name), const SecurityObjects::UserInfo &UI, Poco::Logger &L)
parameters_(parameters), : jobId_(JobID), name_(name), parameters_(parameters), when_(when), userinfo_(UI),
when_(when), Logger_(L){};
userinfo_(UI),
Logger_(L)
{};
virtual void run() = 0; virtual void run() = 0;
[[nodiscard]] std::string Name() const { return name_; } [[nodiscard]] std::string Name() const { return name_; }
const SecurityObjects::UserInfo & UserInfo() const { return userinfo_; } const SecurityObjects::UserInfo &UserInfo() const { return userinfo_; }
Poco::Logger & Logger() { return Logger_; } Poco::Logger &Logger() { return Logger_; }
const std::string & JobId() const { return jobId_; } const std::string &JobId() const { return jobId_; }
const std::string & Parameter(int x) const { return parameters_[x];} const std::string &Parameter(int x) const { return parameters_[x]; }
uint64_t When() const { return when_; } uint64_t When() const { return when_; }
void Start() { started_ = Utils::Now(); } void Start() { started_ = Utils::Now(); }
uint64_t Started() const { return started_; } uint64_t Started() const { return started_; }
uint64_t Completed() const { return completed_;} uint64_t Completed() const { return completed_; }
void Complete() { completed_ = Utils::Now(); } void Complete() { completed_ = Utils::Now(); }
private: private:
std::string jobId_; std::string jobId_;
std::string name_; std::string name_;
std::vector<std::string> parameters_; std::vector<std::string> parameters_;
uint64_t when_=0; uint64_t when_ = 0;
SecurityObjects::UserInfo userinfo_; SecurityObjects::UserInfo userinfo_;
Poco::Logger & Logger_; Poco::Logger &Logger_;
uint64_t started_=0; uint64_t started_ = 0;
uint64_t completed_=0; uint64_t completed_ = 0;
}; };
class JobController : public SubSystemServer, Poco::Runnable { class JobController : public SubSystemServer, Poco::Runnable {
public: public:
static auto instance() { static auto instance() {
static auto instance_ = new JobController; static auto instance_ = new JobController;
return instance_; return instance_;
} }
int Start() override; int Start() override;
void Stop() override; void Stop() override;
void run() override; void run() override;
inline void wakeup() { Thr_.wakeUp(); } inline void wakeup() { Thr_.wakeUp(); }
void AddJob( Job* newJob ) { void AddJob(Job *newJob) {
std::lock_guard G(Mutex_); std::lock_guard G(Mutex_);
jobs_.push_back(newJob); jobs_.push_back(newJob);
} }
private: private:
Poco::Thread Thr_; Poco::Thread Thr_;
std::atomic_bool Running_=false; std::atomic_bool Running_ = false;
std::list<Job *> jobs_; std::list<Job *> jobs_;
Poco::ThreadPool Pool_; Poco::ThreadPool Pool_;
JobController() noexcept: JobController() noexcept : SubSystemServer("JobController", "JOB-SVR", "job") {}
SubSystemServer("JobController", "JOB-SVR", "job") };
{ inline auto JobController() { return JobController::instance(); }
}
};
inline auto JobController() { return JobController::instance(); }
}
} // namespace OpenWifi

View File

@@ -4,8 +4,6 @@
namespace OpenWifi { namespace OpenWifi {
void RegisterJobTypes() { void RegisterJobTypes() {}
} } // namespace OpenWifi
}

View File

@@ -4,46 +4,45 @@
#pragma once #pragma once
#include "framework/KafkaTopics.h"
#include "framework/KafkaManager.h"
#include "RESTObjects/RESTAPI_ProvObjects.h" #include "RESTObjects/RESTAPI_ProvObjects.h"
#include "framework/KafkaManager.h"
#include "framework/KafkaTopics.h"
namespace OpenWifi { namespace OpenWifi {
enum ProvisioningOperation { enum ProvisioningOperation { creation = 0, modification, removal };
creation=0, modification, removal
};
template <typename ObjectType> inline bool UpdateKafkaProvisioningObject( ProvisioningOperation op, const ObjectType & obj) { template <typename ObjectType>
static std::vector<std::string> Ops{ "creation", "modification", "removal" }; inline bool UpdateKafkaProvisioningObject(ProvisioningOperation op, const ObjectType &obj) {
static std::vector<std::string> Ops{"creation", "modification", "removal"};
std::string OT{"object"}; std::string OT{"object"};
if constexpr(std::is_same_v<ObjectType,ProvObjects::Venue>) { if constexpr (std::is_same_v<ObjectType, ProvObjects::Venue>) {
OT = "Venue"; OT = "Venue";
} }
if constexpr(std::is_same_v<ObjectType,ProvObjects::Entity>) { if constexpr (std::is_same_v<ObjectType, ProvObjects::Entity>) {
OT = "Entity"; OT = "Entity";
} }
if constexpr(std::is_same_v<ObjectType,ProvObjects::InventoryTag>) { if constexpr (std::is_same_v<ObjectType, ProvObjects::InventoryTag>) {
OT = "InventoryTag"; OT = "InventoryTag";
} }
if constexpr(std::is_same_v<ObjectType,ProvObjects::Contact>) { if constexpr (std::is_same_v<ObjectType, ProvObjects::Contact>) {
OT = "Contact"; OT = "Contact";
} }
if constexpr(std::is_same_v<ObjectType,ProvObjects::Location>) { if constexpr (std::is_same_v<ObjectType, ProvObjects::Location>) {
OT = "Location"; OT = "Location";
} }
if constexpr(std::is_same_v<ObjectType,ProvObjects::DeviceConfiguration>) { if constexpr (std::is_same_v<ObjectType, ProvObjects::DeviceConfiguration>) {
OT = "DeviceConfiguration"; OT = "DeviceConfiguration";
} }
Poco::JSON::Object Payload; Poco::JSON::Object Payload;
obj.to_json(Payload); obj.to_json(Payload);
Payload.set("ObjectType",OT); Payload.set("ObjectType", OT);
std::ostringstream OS; std::ostringstream OS;
Payload.stringify(OS); Payload.stringify(OS);
KafkaManager()->PostMessage(KafkaTopics::PROVISIONING_CHANGE, Ops[op] , OS.str()); KafkaManager()->PostMessage(KafkaTopics::PROVISIONING_CHANGE, Ops[op], std::make_shared<std::string>(OS.str()));
return true; return true;
} }
} } // namespace OpenWifi

View File

@@ -4,165 +4,180 @@
#include "ProvWebSocketClient.h" #include "ProvWebSocketClient.h"
#include "StorageService.h"
#include "SerialNumberCache.h" #include "SerialNumberCache.h"
#include "sdks/SDK_sec.h" #include "StorageService.h"
#include "framework/UI_WebSocketClientServer.h" #include "framework/UI_WebSocketClientServer.h"
#include "sdks/SDK_sec.h"
namespace OpenWifi { namespace OpenWifi {
ProvWebSocketClient::ProvWebSocketClient(Poco::Logger &Logger) : ProvWebSocketClient::ProvWebSocketClient(Poco::Logger &Logger) : Logger_(Logger) {
Logger_(Logger){ UI_WebSocketClientServer()->SetProcessor(this);
UI_WebSocketClientServer()->SetProcessor(this); }
}
ProvWebSocketClient::~ProvWebSocketClient() { ProvWebSocketClient::~ProvWebSocketClient() {
UI_WebSocketClientServer()->SetProcessor(nullptr); UI_WebSocketClientServer()->SetProcessor(nullptr);
} }
void ProvWebSocketClient::ws_command_serial_number_search(const Poco::JSON::Object::Ptr &O, void ProvWebSocketClient::ws_command_serial_number_search(const Poco::JSON::Object::Ptr &O,
bool &Done, std::string &Answer) { bool &Done, std::string &Answer) {
Done = false; Done = false;
auto Prefix = O->get("serial_prefix").toString(); auto Prefix = ORM::Escape(O->get("serial_prefix").toString());
Poco::toLowerInPlace(Prefix); Poco::toLowerInPlace(Prefix);
Logger().information(Poco::format("serial_number_search: %s", Prefix)); Logger().information(Poco::format("serial_number_search: %s", Prefix));
if (!Prefix.empty() && Prefix.length() < 13) { if (!Prefix.empty() && Prefix.length() < 13) {
std::vector<uint64_t> Numbers; std::vector<uint64_t> Numbers;
SerialNumberCache()->FindNumbers(Prefix, 50, Numbers); SerialNumberCache()->FindNumbers(Prefix, 50, Numbers);
Poco::JSON::Array Arr; Poco::JSON::Array Arr;
for (const auto &i : Numbers) for (const auto &i : Numbers)
Arr.add(Utils::int_to_hex(i)); Arr.add(Utils::int_to_hex(i));
Poco::JSON::Object RetObj; Poco::JSON::Object RetObj;
RetObj.set("serialNumbers", Arr); RetObj.set("serialNumbers", Arr);
std::ostringstream SS; std::ostringstream SS;
Poco::JSON::Stringifier::stringify(RetObj, SS); Poco::JSON::Stringifier::stringify(RetObj, SS);
Answer = SS.str(); Answer = SS.str();
} }
} }
void ProvWebSocketClient::ws_command_address_completion(const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer) { void ProvWebSocketClient::ws_command_address_completion(const Poco::JSON::Object::Ptr &O,
Done = false; bool &Done, std::string &Answer) {
auto Address = O->get("address").toString(); Done = false;
Answer = GoogleGeoCodeCall(Address); 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) { void ProvWebSocketClient::ws_command_exit([[maybe_unused]] const Poco::JSON::Object::Ptr &O,
Done = true; bool &Done, std::string &Answer) {
Answer = R"lit({ "closing" : "Goodbye! Aurevoir! Hasta la vista!" })lit"; 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) { void ProvWebSocketClient::ws_command_invalid([[maybe_unused]] const Poco::JSON::Object::Ptr &O,
Done = false; bool &Done, std::string &Answer) {
Answer = std::string{R"lit({ "error" : "invalid command" })lit"}; 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) { void ProvWebSocketClient::ws_command_subuser_search(const Poco::JSON::Object::Ptr &O,
Done = false; bool &Done, std::string &Answer) {
auto operatorId = O->get("operatorId").toString(); Done = false;
std::string nameSearch, emailSearch; auto operatorId = ORM::Escape(O->get("operatorId").toString());
OpenWifi::RESTAPIHandler::AssignIfPresent(O,"nameSearch",nameSearch); std::string nameSearch, emailSearch;
OpenWifi::RESTAPIHandler::AssignIfPresent(O,"emailSearch",emailSearch); OpenWifi::RESTAPIHandler::AssignIfPresent(O, "nameSearch", nameSearch);
SecurityObjects::UserInfoList Users; OpenWifi::RESTAPIHandler::AssignIfPresent(O, "emailSearch", emailSearch);
SDK::Sec::Subscriber::Search(nullptr,operatorId,nameSearch,emailSearch,Users); SecurityObjects::UserInfoList Users;
SDK::Sec::Subscriber::Search(nullptr, operatorId, nameSearch, emailSearch, Users);
Poco::JSON::Array Arr; Poco::JSON::Array Arr;
for(const auto &i:Users.users) { for (const auto &i : Users.users) {
Poco::JSON::Object OO; Poco::JSON::Object OO;
OO.set("name", i.name); OO.set("name", i.name);
OO.set("email", i.email); OO.set("email", i.email);
OO.set("id", i.id); OO.set("id", i.id);
i.to_json(OO); i.to_json(OO);
Arr.add(OO); Arr.add(OO);
} }
Poco::JSON::Object ObjAnswer; Poco::JSON::Object ObjAnswer;
ObjAnswer.set("users", Arr); ObjAnswer.set("users", Arr);
std::ostringstream SS; std::ostringstream SS;
Poco::JSON::Stringifier::stringify(ObjAnswer, SS); Poco::JSON::Stringifier::stringify(ObjAnswer, SS);
Answer = SS.str(); Answer = SS.str();
} }
void ProvWebSocketClient::ws_command_subdevice_search( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer) { void ProvWebSocketClient::ws_command_subdevice_search(const Poco::JSON::Object::Ptr &O,
Done = false; bool &Done, std::string &Answer) {
auto operatorId = O->get("operatorId").toString(); Done = false;
auto Prefix = O->get("serial_prefix").toString(); auto operatorId = O->get("operatorId").toString();
Poco::toLowerInPlace(Prefix); auto Prefix = O->get("serial_prefix").toString();
std::string Query; Poco::toLowerInPlace(Prefix);
std::string Query;
if(Prefix[0]=='*') { if (Prefix[0] == '*') {
Query = fmt::format(" operatorId='{}' and (right(serialNumber,{})='{}' or right(realMacAddress,{})='{}' ) ", Query = fmt::format(" operatorId='{}' and (right(serialNumber,{})='{}' or "
operatorId, Prefix.size()-1, Prefix.substr(1), Prefix.size()-1, Prefix.substr(1)); "right(realMacAddress,{})='{}' ) ",
} else { operatorId, Prefix.size() - 1, Prefix.substr(1), Prefix.size() - 1,
Query = fmt::format(" operatorId='{}' and (left(serialNumber,{})='{}' or left(realMacAddress,{})='{}' ) ", Prefix.substr(1));
operatorId, Prefix.size(), Prefix, Prefix.size(), Prefix); } else {
} Query = fmt::format(" operatorId='{}' and (left(serialNumber,{})='{}' or "
"left(realMacAddress,{})='{}' ) ",
operatorId, Prefix.size(), Prefix, Prefix.size(), Prefix);
}
std::vector<ProvObjects::SubscriberDevice> SubDevices; std::vector<ProvObjects::SubscriberDevice> SubDevices;
StorageService()->SubscriberDeviceDB().GetRecords(0,200,SubDevices,Query); StorageService()->SubscriberDeviceDB().GetRecords(0, 200, SubDevices, Query);
Poco::JSON::Array Arr; Poco::JSON::Array Arr;
for(const auto &i:SubDevices) { for (const auto &i : SubDevices) {
Arr.add(i.serialNumber); Arr.add(i.serialNumber);
} }
Poco::JSON::Object RetObj; Poco::JSON::Object RetObj;
RetObj.set("serialNumbers", Arr); RetObj.set("serialNumbers", Arr);
std::ostringstream SS; std::ostringstream SS;
Poco::JSON::Stringifier::stringify(RetObj, SS); Poco::JSON::Stringifier::stringify(RetObj, SS);
Answer = SS.str(); Answer = SS.str();
} }
void ProvWebSocketClient::Processor(const Poco::JSON::Object::Ptr &O, std::string &Result, bool &Done ) { void
try { ProvWebSocketClient::Processor(const Poco::JSON::Object::Ptr &O, std::string &Result,
if (O->has("command") && O->has("id")) { bool &Done,
auto id = (uint64_t) O->get("id"); [[maybe_unused]] const SecurityObjects::UserInfo &UserInfo) {
std::string Answer; try {
auto Command = O->get("command").toString(); if (O->has("command") && O->has("id")) {
if (Command == "serial_number_search" && O->has("serial_prefix")) { auto id = (uint64_t)O->get("id");
ws_command_serial_number_search(O,Done,Answer); std::string Answer;
} else if (UI_WebSocketClientServer()->GeoCodeEnabled() && Command == "address_completion" && O->has("address")) { auto Command = O->get("command").toString();
ws_command_address_completion(O,Done,Answer); if (Command == "serial_number_search" && O->has("serial_prefix")) {
} else if (UI_WebSocketClientServer()->GeoCodeEnabled() && Command == "subuser_search" && O->has("operatorId")) { ws_command_serial_number_search(O, Done, Answer);
ws_command_subuser_search(O,Done,Answer); } else if (UI_WebSocketClientServer()->GeoCodeEnabled() &&
} else if (UI_WebSocketClientServer()->GeoCodeEnabled() && Command == "subdevice_search" && O->has("operatorId") && O->has("serial_prefix")) { Command == "address_completion" && O->has("address")) {
ws_command_subdevice_search(O,Done,Answer); ws_command_address_completion(O, Done, Answer);
} else if (Command=="exit") { } else if (UI_WebSocketClientServer()->GeoCodeEnabled() &&
ws_command_exit(O,Done,Answer); Command == "subuser_search" && O->has("operatorId")) {
} else { ws_command_subuser_search(O, Done, Answer);
ws_command_invalid(O,Done,Answer); } else if (UI_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); Result = fmt::format("{{ \"command_response_id\" : {} , \"response\" : {} }}", id,
} Answer);
} catch (const Poco::Exception &E) { }
Logger().log(E); } catch (const Poco::Exception &E) {
} Logger().log(E);
} }
}
std::string ProvWebSocketClient::GoogleGeoCodeCall(const std::string &A) { std::string ProvWebSocketClient::GoogleGeoCodeCall(const std::string &A) {
try { try {
std::string URI = { "https://maps.googleapis.com/maps/api/geocode/json"}; std::string URI = {"https://maps.googleapis.com/maps/api/geocode/json"};
Poco::URI uri(URI); Poco::URI uri(URI);
uri.addQueryParameter("address",A); uri.addQueryParameter("address", A);
uri.addQueryParameter("key", UI_WebSocketClientServer()->GoogleApiKey()); uri.addQueryParameter("key", UI_WebSocketClientServer()->GoogleApiKey());
Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort()); 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); Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, uri.getPathAndQuery(),
session.sendRequest(req); Poco::Net::HTTPMessage::HTTP_1_1);
Poco::Net::HTTPResponse res; session.sendRequest(req);
std::istream& rs = session.receiveResponse(res); Poco::Net::HTTPResponse res;
if(res.getStatus()==Poco::Net::HTTPResponse::HTTP_OK) { std::istream &rs = session.receiveResponse(res);
std::ostringstream os; if (res.getStatus() == Poco::Net::HTTPResponse::HTTP_OK) {
Poco::StreamCopier::copyStream(rs,os); std::ostringstream os;
return os.str(); Poco::StreamCopier::copyStream(rs, os);
} else { return os.str();
std::ostringstream os; } else {
Poco::StreamCopier::copyStream(rs,os); std::ostringstream os;
return R"lit({ "error: )lit" + os.str() + R"lit( })lit"; Poco::StreamCopier::copyStream(rs, os);
} return R"lit({ "error: )lit" + os.str() + R"lit( })lit";
} catch(...) { }
} catch (...) {
}
return "{ \"error\" : \"No call made\" }";
}
} } // namespace OpenWifi
return "{ \"error\" : \"No call made\" }";
}
}

View File

@@ -8,21 +8,27 @@
namespace OpenWifi { namespace OpenWifi {
class ProvWebSocketClient : public UI_WebSocketClientProcessor { class ProvWebSocketClient : public UI_WebSocketClientProcessor {
public: public:
explicit ProvWebSocketClient(Poco::Logger &Logger); explicit ProvWebSocketClient(Poco::Logger &Logger);
virtual ~ProvWebSocketClient(); virtual ~ProvWebSocketClient();
virtual void Processor(const Poco::JSON::Object::Ptr &O, std::string &Answer, bool &Done ); 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); const SecurityObjects::UserInfo &UserInfo);
void ws_command_address_completion( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer); void ws_command_serial_number_search(const Poco::JSON::Object::Ptr &O, bool &Done,
void ws_command_exit( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer); std::string &Answer);
void ws_command_invalid( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer); void ws_command_address_completion(const Poco::JSON::Object::Ptr &O, bool &Done,
void ws_command_subuser_search( const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer); std::string &Answer);
void ws_command_subdevice_search( 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);
std::string GoogleGeoCodeCall(const std::string &A); void ws_command_invalid(const Poco::JSON::Object::Ptr &O, bool &Done, std::string &Answer);
private: void ws_command_subuser_search(const Poco::JSON::Object::Ptr &O, bool &Done,
Poco::Logger & Logger_; std::string &Answer);
inline Poco::Logger & Logger() { return Logger_; } 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_; }
};
} // namespace OpenWifi

View File

@@ -3,19 +3,19 @@
// //
#include "RESTAPI_asset_server.h" #include "RESTAPI_asset_server.h"
#include "Daemon.h"
#include "Poco/File.h" #include "Poco/File.h"
#include "framework/ow_constants.h" #include "framework/ow_constants.h"
#include "Daemon.h"
namespace OpenWifi { namespace OpenWifi {
void RESTAPI_asset_server::DoGet() { void RESTAPI_asset_server::DoGet() {
Poco::File AssetFile; Poco::File AssetFile;
std::string AssetName = GetBinding(RESTAPI::Protocol::ID, ""); std::string AssetName = GetBinding(RESTAPI::Protocol::ID, "");
AssetFile = Daemon()->AssetDir() + "/" + AssetName; AssetFile = Daemon()->AssetDir() + "/" + AssetName;
if(!AssetFile.isFile()) { if (!AssetFile.isFile()) {
return NotFound(); return NotFound();
} }
SendFile(AssetFile); SendFile(AssetFile);
} }
} } // namespace OpenWifi

View File

@@ -3,29 +3,25 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_asset_server : public RESTAPIHandler { class RESTAPI_asset_server : public RESTAPIHandler {
public: public:
RESTAPI_asset_server(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting &Server, uint64_t TransactionId, bool Internal) RESTAPI_asset_server(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server, uint64_t TransactionId,
std::vector<std::string> bool Internal)
{ : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_GET, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server, TransactionId, Internal, false) {}
TransactionId, static auto PathName() { return std::list<std::string>{"/wwwassets/{id}"}; };
Internal, false) {} void DoGet() final;
static auto PathName() { return std::list<std::string>{"/wwwassets/{id}"}; }; void DoPost() final{};
void DoGet() final; void DoDelete() final{};
void DoPost() final {}; void DoPut() final{};
void DoDelete() final {};
void DoPut() final {};
private:
};
}
private:
};
} // namespace OpenWifi

View File

@@ -7,222 +7,243 @@
// //
#include "RESTAPI_configurations_handler.h" #include "RESTAPI_configurations_handler.h"
#include "DeviceTypeCache.h"
#include "RESTAPI/RESTAPI_db_helpers.h"
#include "RESTObjects/RESTAPI_ProvObjects.h" #include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/ConfigurationValidator.h" #include "framework/ConfigurationValidator.h"
#include "RESTAPI/RESTAPI_db_helpers.h"
#include "DeviceTypeCache.h"
namespace OpenWifi{ namespace OpenWifi {
void RESTAPI_configurations_handler::DoGet() { void RESTAPI_configurations_handler::DoGet() {
std::string UUID = GetBinding("uuid",""); std::string UUID = GetBinding("uuid", "");
ProvObjects::DeviceConfiguration Existing; ProvObjects::DeviceConfiguration Existing;
if(UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) { if (UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
return NotFound(); return NotFound();
} }
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
std::string Arg; std::string Arg;
if(HasParameter("expandInUse",Arg) && Arg=="true") { if (HasParameter("expandInUse", Arg) && Arg == "true") {
Storage::ExpandedListMap M; Storage::ExpandedListMap M;
std::vector<std::string> Errors; std::vector<std::string> Errors;
Poco::JSON::Object Inner; Poco::JSON::Object Inner;
if(StorageService()->ExpandInUse(Existing.inUse,M,Errors)) { if (StorageService()->ExpandInUse(Existing.inUse, M, Errors)) {
for(const auto &[type,list]:M) { for (const auto &[type, list] : M) {
Poco::JSON::Array ObjList; Poco::JSON::Array ObjList;
for(const auto &i:list.entries) { for (const auto &i : list.entries) {
Poco::JSON::Object O; Poco::JSON::Object O;
i.to_json(O); i.to_json(O);
ObjList.add(O); ObjList.add(O);
} }
Inner.set(type,ObjList); Inner.set(type, ObjList);
} }
} }
Answer.set("entries", Inner); Answer.set("entries", Inner);
return ReturnObject(Answer); return ReturnObject(Answer);
} else if(HasParameter("computedAffected",Arg) && Arg=="true") { } else if (HasParameter("computedAffected", Arg) && Arg == "true") {
Types::UUIDvec_t DeviceSerialNumbers; Types::UUIDvec_t DeviceSerialNumbers;
DB_.GetListOfAffectedDevices(UUID,DeviceSerialNumbers); DB_.GetListOfAffectedDevices(UUID, DeviceSerialNumbers);
return ReturnObject("affectedDevices", DeviceSerialNumbers); return ReturnObject("affectedDevices", DeviceSerialNumbers);
} else if(QB_.AdditionalInfo) { } else if (QB_.AdditionalInfo) {
AddExtendedInfo(Existing,Answer); AddExtendedInfo(Existing, Answer);
} }
Existing.to_json(Answer); Existing.to_json(Answer);
ReturnObject(Answer); ReturnObject(Answer);
} }
void RESTAPI_configurations_handler::DoDelete() { void RESTAPI_configurations_handler::DoDelete() {
std::string UUID = GetBinding("uuid",""); std::string UUID = GetBinding("uuid", "");
ProvObjects::DeviceConfiguration Existing; ProvObjects::DeviceConfiguration Existing;
if(UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) { if (UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
return NotFound(); return NotFound();
} }
if(!Existing.inUse.empty()) { if (!Existing.inUse.empty()) {
return BadRequest(RESTAPI::Errors::StillInUse); return BadRequest(RESTAPI::Errors::StillInUse);
} }
DB_.DeleteRecord("id", UUID); DB_.DeleteRecord("id", UUID);
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id); MoveUsage(StorageService()->PolicyDB(), DB_, Existing.managementPolicy, "",
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::configurations,Existing.venue,Existing.info.id); Existing.info.id);
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::configurations,Existing.entity,Existing.info.id); RemoveMembership(StorageService()->VenueDB(), &ProvObjects::Venue::configurations,
for(const auto &i:Existing.variables) Existing.venue, Existing.info.id);
RemoveMembership(StorageService()->VariablesDB(),&ProvObjects::VariableBlock::configurations,i,Existing.info.id); RemoveMembership(StorageService()->EntityDB(), &ProvObjects::Entity::configurations,
Existing.entity, Existing.info.id);
for (const auto &i : Existing.variables)
RemoveMembership(StorageService()->VariablesDB(),
&ProvObjects::VariableBlock::configurations, i, Existing.info.id);
return OK(); return OK();
} }
void RESTAPI_configurations_handler::DoPost() { void RESTAPI_configurations_handler::DoPost() {
auto UUID = GetBinding("uuid",""); auto UUID = GetBinding("uuid", "");
if(UUID.empty()) { if (UUID.empty()) {
return BadRequest(RESTAPI::Errors::MissingUUID); return BadRequest(RESTAPI::Errors::MissingUUID);
} }
const auto & RawObject = ParsedBody_; 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")) { if (!RawObject->has("configuration")) {
return BadRequest(RESTAPI::Errors::MustHaveConfigElement); return BadRequest(RESTAPI::Errors::MustHaveConfigElement);
} }
auto Config=RawObject->get("configuration").toString(); auto Config = RawObject->get("configuration").toString();
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
std::string Error; std::vector<std::string> Error;
auto Res = ValidateUCentralConfiguration(Config,Error); auto Res =
Answer.set("valid",Res); ValidateUCentralConfiguration(Config, Error, GetBoolParameter("strict", true));
Answer.set("error", Error); Answer.set("valid", Res);
return ReturnObject(Answer); Answer.set("error", Error);
} return ReturnObject(Answer);
}
ProvObjects::DeviceConfiguration NewObject; ProvObjects::DeviceConfiguration 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 ((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules, *this))) {
return; return;
} }
if(!ProvObjects::CreateObjectInfo(RawObject,UserInfo_.userinfo,NewObject.info)) { 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 (!NewObject.entity.empty() &&
return BadRequest(RESTAPI::Errors::EntityMustExist); !StorageService()->EntityDB().Exists("id", NewObject.entity)) {
} return BadRequest(RESTAPI::Errors::EntityMustExist);
}
if(!NewObject.venue.empty() && !StorageService()->VenueDB().Exists("id",NewObject.venue)) { if (!NewObject.venue.empty() &&
return BadRequest(RESTAPI::Errors::VenueMustExist); !StorageService()->VenueDB().Exists("id", NewObject.venue)) {
} return BadRequest(RESTAPI::Errors::VenueMustExist);
}
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) { if (!NewObject.managementPolicy.empty() &&
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID); !StorageService()->PolicyDB().Exists("id", NewObject.managementPolicy)) {
} return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
NewObject.inUse.clear(); NewObject.inUse.clear();
if(NewObject.deviceTypes.empty() || !DeviceTypeCache()->AreAcceptableDeviceTypes(NewObject.deviceTypes, true)) { if (NewObject.deviceTypes.empty() ||
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes); !DeviceTypeCache()->AreAcceptableDeviceTypes(NewObject.deviceTypes, true)) {
} return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
}
RESTAPI::Errors::msg Error; std::vector<std::string> Errors;
if(!ValidateConfigBlock(NewObject,Error)) { if (!ValidateConfigBlock(NewObject, Errors)) {
return BadRequest(Error); return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
} }
if(DB_.CreateRecord(NewObject)) { if (DB_.CreateRecord(NewObject)) {
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id); MoveUsage(StorageService()->PolicyDB(), DB_, "", NewObject.managementPolicy,
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::configurations,NewObject.venue, NewObject.info.id); NewObject.info.id);
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::configurations,NewObject.entity, NewObject.info.id); AddMembership(StorageService()->VenueDB(), &ProvObjects::Venue::configurations,
NewObject.venue, NewObject.info.id);
AddMembership(StorageService()->EntityDB(), &ProvObjects::Entity::configurations,
NewObject.entity, NewObject.info.id);
ConfigurationDB::RecordName AddedRecord; ConfigurationDB::RecordName AddedRecord;
DB_.GetRecord("id", NewObject.info.id, AddedRecord); DB_.GetRecord("id", NewObject.info.id, AddedRecord);
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
AddedRecord.to_json(Answer); AddedRecord.to_json(Answer);
return ReturnObject(Answer); return ReturnObject(Answer);
} }
InternalError(RESTAPI::Errors::RecordNotCreated); InternalError(RESTAPI::Errors::RecordNotCreated);
} }
void RESTAPI_configurations_handler::DoPut() { void RESTAPI_configurations_handler::DoPut() {
auto UUID = GetBinding("uuid",""); auto UUID = GetBinding("uuid", "");
ProvObjects::DeviceConfiguration Existing; ProvObjects::DeviceConfiguration Existing;
if(UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) { if (UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
return NotFound(); return NotFound();
} }
ProvObjects::DeviceConfiguration NewObject; ProvObjects::DeviceConfiguration NewObject;
const auto & RawObject = ParsedBody_; const auto &RawObject = ParsedBody_;
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 ((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules, *this))) {
return; 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(!NewObject.deviceTypes.empty() && !DeviceTypeCache()->AreAcceptableDeviceTypes(NewObject.deviceTypes, true)) { if (!NewObject.deviceTypes.empty() &&
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes); !DeviceTypeCache()->AreAcceptableDeviceTypes(NewObject.deviceTypes, true)) {
} return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
}
if(!NewObject.deviceTypes.empty()) if (!NewObject.deviceTypes.empty())
Existing.deviceTypes = NewObject.deviceTypes; Existing.deviceTypes = NewObject.deviceTypes;
RESTAPI::Errors::msg Error; std::vector<std::string> Errors;
if(!ValidateConfigBlock( NewObject,Error)) { if (!ValidateConfigBlock(NewObject, Errors)) {
return BadRequest(Error); return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
} }
if(RawObject->has("configuration")) { if (RawObject->has("configuration")) {
Existing.configuration = NewObject.configuration; Existing.configuration = NewObject.configuration;
} }
std::string FromPolicy, ToPolicy; std::string FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&ConfigurationDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB())) if (!CreateMove(RawObject, "managementPolicy",
return BadRequest(RESTAPI::Errors::EntityMustExist); &ConfigurationDB::RecordName::managementPolicy, Existing, FromPolicy,
ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromEntity, ToEntity; std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&ConfigurationDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB())) if (!CreateMove(RawObject, "entity", &ConfigurationDB::RecordName::entity, Existing,
return BadRequest(RESTAPI::Errors::EntityMustExist); FromEntity, ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromVenue, ToVenue; std::string FromVenue, ToVenue;
if(!CreateMove(RawObject,"venue",&ConfigurationDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB())) if (!CreateMove(RawObject, "venue", &ConfigurationDB::RecordName::venue, Existing,
return BadRequest(RESTAPI::Errors::VenueMustExist); FromVenue, ToVenue, StorageService()->VenueDB()))
return BadRequest(RESTAPI::Errors::VenueMustExist);
Types::UUIDvec_t FromVariables, ToVariables; Types::UUIDvec_t FromVariables, ToVariables;
if(RawObject->has("variables")) { if (RawObject->has("variables")) {
for(const auto &i:NewObject.variables) { for (const auto &i : NewObject.variables) {
if(!i.empty() && !StorageService()->VariablesDB().Exists("id",i)) { if (!i.empty() && !StorageService()->VariablesDB().Exists("id", i)) {
return BadRequest(RESTAPI::Errors::VariableMustExist); return BadRequest(RESTAPI::Errors::VariableMustExist);
} }
} }
for(const auto &i:Existing.variables) for (const auto &i : Existing.variables)
FromVariables.emplace_back(i); FromVariables.emplace_back(i);
for(const auto &i:NewObject.variables) for (const auto &i : NewObject.variables)
ToVariables.emplace_back(i); ToVariables.emplace_back(i);
FromVariables = Existing.variables; FromVariables = Existing.variables;
ToVariables = NewObject.variables; ToVariables = NewObject.variables;
Existing.variables = ToVariables; Existing.variables = ToVariables;
} }
if(RawObject->has("deviceRules")) if (RawObject->has("deviceRules"))
Existing.deviceRules = NewObject.deviceRules; Existing.deviceRules = NewObject.deviceRules;
if(DB_.UpdateRecord("id",UUID,Existing)) { if (DB_.UpdateRecord("id", UUID, Existing)) {
ManageMembership(StorageService()->VariablesDB(),&ProvObjects::VariableBlock::configurations, FromVariables, ToVariables, Existing.info.id); ManageMembership(StorageService()->VariablesDB(),
ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::configurations, FromVenue, ToVenue, Existing.info.id); &ProvObjects::VariableBlock::configurations, FromVariables,
ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::configurations, FromEntity, ToEntity, Existing.info.id); ToVariables, Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id); ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::configurations,
FromVenue, ToVenue, Existing.info.id);
ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::configurations,
FromEntity, ToEntity, Existing.info.id);
MoveUsage(StorageService()->PolicyDB(), DB_, FromPolicy, ToPolicy, Existing.info.id);
ProvObjects::DeviceConfiguration D; ProvObjects::DeviceConfiguration D;
DB_.GetRecord("id",UUID,D); DB_.GetRecord("id", UUID, D);
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
D.to_json(Answer); D.to_json(Answer);
return ReturnObject(Answer); return ReturnObject(Answer);
} }
InternalError(RESTAPI::Errors::RecordNotUpdated); InternalError(RESTAPI::Errors::RecordNotUpdated);
} }
} } // namespace OpenWifi

View File

@@ -7,27 +7,29 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_configurations_handler : public RESTAPIHandler { class RESTAPI_configurations_handler : public RESTAPIHandler {
public: public:
RESTAPI_configurations_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_configurations_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server,
std::vector<std::string>{ uint64_t TransactionId, bool Internal)
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_POST,
Server, Poco::Net::HTTPRequest::HTTP_PUT,
TransactionId, Poco::Net::HTTPRequest::HTTP_DELETE,
Internal){} Poco::Net::HTTPRequest::HTTP_OPTIONS},
static auto PathName() { return std::list<std::string>{"/api/v1/configuration/{uuid}"}; }; Server, TransactionId, Internal) {}
private: static auto PathName() { return std::list<std::string>{"/api/v1/configuration/{uuid}"}; };
ConfigurationDB &DB_=StorageService()->ConfigurationDB();
void DoGet(); private:
void DoPost(); ConfigurationDB &DB_ = StorageService()->ConfigurationDB();
void DoPut(); void DoGet();
void DoDelete(); void DoPost();
}; void DoPut();
} void DoDelete();
};
} // namespace OpenWifi

View File

@@ -4,12 +4,12 @@
#include "RESTAPI_configurations_list_handler.h" #include "RESTAPI_configurations_list_handler.h"
#include "RESTAPI_db_helpers.h"
#include "RESTObjects/RESTAPI_ProvObjects.h" #include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h" #include "StorageService.h"
#include "RESTAPI_db_helpers.h"
namespace OpenWifi{ namespace OpenWifi {
void RESTAPI_configurations_list_handler::DoGet() { void RESTAPI_configurations_list_handler::DoGet() {
return ListHandler<ConfigurationDB>("configurations", DB_, *this); return ListHandler<ConfigurationDB>("configurations", DB_, *this);
} }
} } // namespace OpenWifi

View File

@@ -3,27 +3,28 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_configurations_list_handler : public RESTAPIHandler { class RESTAPI_configurations_list_handler : public RESTAPIHandler {
public: public:
RESTAPI_configurations_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_configurations_list_handler(const RESTAPIHandler::BindingMap &bindings,
: RESTAPIHandler(bindings, L, Poco::Logger &L,
std::vector<std::string>{ RESTAPI_GenericServerAccounting &Server,
Poco::Net::HTTPRequest::HTTP_GET, uint64_t TransactionId, bool Internal)
Poco::Net::HTTPRequest::HTTP_OPTIONS}, : RESTAPIHandler(bindings, L,
Server, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
TransactionId, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Internal){} Server, TransactionId, Internal) {}
static auto PathName() { return std::list<std::string>{"/api/v1/configuration"}; }; static auto PathName() { return std::list<std::string>{"/api/v1/configuration"}; };
private:
ConfigurationDB & DB_=StorageService()->ConfigurationDB(); private:
void DoGet() final; ConfigurationDB &DB_ = StorageService()->ConfigurationDB();
void DoPost() final {}; void DoGet() final;
void DoPut() final {}; void DoPost() final{};
void DoDelete() final {}; void DoPut() final{};
}; void DoDelete() final{};
} };
} // namespace OpenWifi

View File

@@ -8,163 +8,171 @@
#include "RESTAPI_contact_handler.h" #include "RESTAPI_contact_handler.h"
#include "framework/ow_constants.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
#include "RESTAPI_db_helpers.h" #include "RESTAPI_db_helpers.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
#include "framework/ow_constants.h"
namespace OpenWifi{ namespace OpenWifi {
void RESTAPI_contact_handler::DoGet() { void RESTAPI_contact_handler::DoGet() {
std::string UUID = GetBinding("uuid",""); std::string UUID = GetBinding("uuid", "");
ProvObjects::Contact Existing; ProvObjects::Contact Existing;
if(UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) { if (UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
return NotFound(); return NotFound();
} }
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
std::string Arg; std::string Arg;
if(HasParameter("expandInUse",Arg) && Arg=="true") { if (HasParameter("expandInUse", Arg) && Arg == "true") {
Storage::ExpandedListMap M; Storage::ExpandedListMap M;
std::vector<std::string> Errors; std::vector<std::string> Errors;
Poco::JSON::Object Inner; Poco::JSON::Object Inner;
if(StorageService()->ExpandInUse(Existing.inUse,M,Errors)) { if (StorageService()->ExpandInUse(Existing.inUse, M, Errors)) {
for(const auto &[type,list]:M) { for (const auto &[type, list] : M) {
Poco::JSON::Array ObjList; Poco::JSON::Array ObjList;
for(const auto &i:list.entries) { for (const auto &i : list.entries) {
Poco::JSON::Object O; Poco::JSON::Object O;
i.to_json(O); i.to_json(O);
ObjList.add(O); ObjList.add(O);
} }
Inner.set(type,ObjList); Inner.set(type, ObjList);
} }
} }
Answer.set("entries", Inner); Answer.set("entries", Inner);
return ReturnObject(Answer); return ReturnObject(Answer);
} else if(QB_.AdditionalInfo) { } else if (QB_.AdditionalInfo) {
AddExtendedInfo(Existing, Answer); AddExtendedInfo(Existing, Answer);
} }
Existing.to_json(Answer); Existing.to_json(Answer);
ReturnObject(Answer); ReturnObject(Answer);
} }
void RESTAPI_contact_handler::DoDelete() { void RESTAPI_contact_handler::DoDelete() {
std::string UUID = GetBinding("uuid",""); std::string UUID = GetBinding("uuid", "");
ProvObjects::Contact Existing; ProvObjects::Contact Existing;
if(UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) { if (UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
return NotFound(); return NotFound();
} }
bool Force=false; bool Force = false;
std::string Arg; std::string Arg;
if(HasParameter("force",Arg) && Arg=="true") if (HasParameter("force", Arg) && Arg == "true")
Force=true; Force = true;
if(!Force && !Existing.inUse.empty()) { if (!Force && !Existing.inUse.empty()) {
return BadRequest(RESTAPI::Errors::StillInUse); return BadRequest(RESTAPI::Errors::StillInUse);
} }
DB_.DeleteRecord("id",UUID); DB_.DeleteRecord("id", UUID);
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::contacts,Existing.entity,Existing.info.id); RemoveMembership(StorageService()->EntityDB(), &ProvObjects::Entity::contacts,
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.info.id,"",Existing.info.id); Existing.entity, Existing.info.id);
return OK(); MoveUsage(StorageService()->PolicyDB(), DB_, Existing.info.id, "", Existing.info.id);
} return OK();
}
void RESTAPI_contact_handler::DoPost() { void RESTAPI_contact_handler::DoPost() {
std::string UUID = GetBinding(RESTAPI::Protocol::UUID,""); std::string UUID = GetBinding(RESTAPI::Protocol::UUID, "");
if(UUID.empty()) { if (UUID.empty()) {
return BadRequest(RESTAPI::Errors::MissingUUID); return BadRequest(RESTAPI::Errors::MissingUUID);
} }
const auto & Obj = ParsedBody_; const auto &Obj = ParsedBody_;
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);
} }
if(!ProvObjects::CreateObjectInfo(Obj,UserInfo_.userinfo,NewObject.info)) { if (!ProvObjects::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)) { if (NewObject.entity.empty() &&
return BadRequest(RESTAPI::Errors::EntityMustExist); !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() &&
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID); !StorageService()->PolicyDB().Exists("id", NewObject.managementPolicy)) {
} return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
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); AddMembership(StorageService()->EntityDB(), &ProvObjects::Entity::contacts,
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id); NewObject.entity, NewObject.info.id);
MoveUsage(StorageService()->PolicyDB(), DB_, "", NewObject.managementPolicy,
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);
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
NewContact.to_json(Answer); NewContact.to_json(Answer);
ReturnObject(Answer); ReturnObject(Answer);
return; return;
} }
InternalError(RESTAPI::Errors::RecordNotCreated); InternalError(RESTAPI::Errors::RecordNotCreated);
} }
void RESTAPI_contact_handler::DoPut() { void RESTAPI_contact_handler::DoPut() {
std::string UUID = GetBinding(RESTAPI::Protocol::UUID,""); std::string UUID = GetBinding(RESTAPI::Protocol::UUID, "");
ProvObjects::Contact Existing; ProvObjects::Contact 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_; const auto &RawObject = ParsedBody_;
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);
} }
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 FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&ContactDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB())) if (!CreateMove(RawObject, "managementPolicy", &ContactDB::RecordName::managementPolicy,
return BadRequest(RESTAPI::Errors::EntityMustExist); Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromEntity, ToEntity; std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&ContactDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB())) if (!CreateMove(RawObject, "entity", &ContactDB::RecordName::entity, Existing, FromEntity,
return BadRequest(RESTAPI::Errors::EntityMustExist); ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
AssignIfPresent(RawObject, "title", Existing.title); AssignIfPresent(RawObject, "title", Existing.title);
AssignIfPresent(RawObject, "salutation", Existing.salutation); AssignIfPresent(RawObject, "salutation", Existing.salutation);
AssignIfPresent(RawObject, "firstname", Existing.firstname); AssignIfPresent(RawObject, "firstname", Existing.firstname);
AssignIfPresent(RawObject, "lastname", Existing.lastname); AssignIfPresent(RawObject, "lastname", Existing.lastname);
AssignIfPresent(RawObject, "initials", Existing.initials); AssignIfPresent(RawObject, "initials", Existing.initials);
AssignIfPresent(RawObject, "visual", Existing.visual); AssignIfPresent(RawObject, "visual", Existing.visual);
AssignIfPresent(RawObject, "primaryEmail", Existing.primaryEmail); AssignIfPresent(RawObject, "primaryEmail", Existing.primaryEmail);
AssignIfPresent(RawObject, "secondaryEmail", Existing.secondaryEmail); AssignIfPresent(RawObject, "secondaryEmail", Existing.secondaryEmail);
AssignIfPresent(RawObject, "accessPIN", Existing.accessPIN); AssignIfPresent(RawObject, "accessPIN", Existing.accessPIN);
if(RawObject->has("type")) if (RawObject->has("type"))
Existing.type = NewObject.type; Existing.type = NewObject.type;
if(RawObject->has("mobiles")) if (RawObject->has("mobiles"))
Existing.mobiles = NewObject.mobiles; Existing.mobiles = NewObject.mobiles;
if(RawObject->has("phones")) if (RawObject->has("phones"))
Existing.phones = NewObject.phones; Existing.phones = NewObject.phones;
if(DB_.UpdateRecord("id", UUID, Existing)) { if (DB_.UpdateRecord("id", UUID, Existing)) {
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id); MoveUsage(StorageService()->PolicyDB(), DB_, FromPolicy, ToPolicy, Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::contacts,FromEntity,ToEntity,Existing.info.id); ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::contacts,
FromEntity, ToEntity, Existing.info.id);
ProvObjects::Contact NewObjectAdded; ProvObjects::Contact 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);
} }
InternalError(RESTAPI::Errors::RecordNotUpdated); InternalError(RESTAPI::Errors::RecordNotUpdated);
} }
} } // namespace OpenWifi

View File

@@ -7,28 +7,29 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_contact_handler : public RESTAPIHandler { class RESTAPI_contact_handler : public RESTAPIHandler {
public: public:
RESTAPI_contact_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_contact_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server, uint64_t TransactionId,
std::vector<std::string>{ bool Internal)
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_POST,
Server, Poco::Net::HTTPRequest::HTTP_PUT,
TransactionId, Poco::Net::HTTPRequest::HTTP_DELETE,
Internal){} Poco::Net::HTTPRequest::HTTP_OPTIONS},
static auto PathName() { return std::list<std::string>{"/api/v1/contact/{uuid}"}; }; Server, TransactionId, Internal) {}
static auto PathName() { return std::list<std::string>{"/api/v1/contact/{uuid}"}; };
private: private:
ContactDB &DB_=StorageService()->ContactDB(); 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;
}; };
} } // namespace OpenWifi

View File

@@ -4,12 +4,12 @@
#include "RESTAPI_contact_list_handler.h" #include "RESTAPI_contact_list_handler.h"
#include "RESTAPI_db_helpers.h"
#include "RESTObjects/RESTAPI_ProvObjects.h" #include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h" #include "StorageService.h"
#include "RESTAPI_db_helpers.h"
namespace OpenWifi{ namespace OpenWifi {
void RESTAPI_contact_list_handler::DoGet() { void RESTAPI_contact_list_handler::DoGet() {
return ListHandler<ContactDB>("contacts", DB_, *this); return ListHandler<ContactDB>("contacts", DB_, *this);
} }
} } // namespace OpenWifi

View File

@@ -3,27 +3,27 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_contact_list_handler : public RESTAPIHandler { class RESTAPI_contact_list_handler : public RESTAPIHandler {
public: public:
RESTAPI_contact_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_contact_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server,
std::vector<std::string>{ uint64_t TransactionId, bool Internal)
Poco::Net::HTTPRequest::HTTP_GET, : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Server, Poco::Net::HTTPRequest::HTTP_OPTIONS},
TransactionId, Server, TransactionId, Internal) {}
Internal){} static auto PathName() { return std::list<std::string>{"/api/v1/contact"}; };
static auto PathName() { return std::list<std::string>{"/api/v1/contact"}; };
private: private:
ContactDB & DB_=StorageService()->ContactDB(); 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{};
}; };
} } // namespace OpenWifi

File diff suppressed because it is too large Load Diff

View File

@@ -6,172 +6,176 @@
// Arilia Wireless Inc. // Arilia Wireless Inc.
// //
#include "RESTAPI_entity_handler.h" #include "RESTAPI_entity_handler.h"
#include "RESTAPI_db_helpers.h"
#include "RESTObjects/RESTAPI_ProvObjects.h" #include "RESTObjects/RESTAPI_ProvObjects.h"
#include "RESTObjects/RESTAPI_SecurityObjects.h" #include "RESTObjects/RESTAPI_SecurityObjects.h"
#include "StorageService.h" #include "StorageService.h"
#include "RESTAPI_db_helpers.h"
#include "framework/CIDR.h" #include "framework/CIDR.h"
namespace OpenWifi{ namespace OpenWifi {
void RESTAPI_entity_handler::DoGet() { void RESTAPI_entity_handler::DoGet() {
std::string UUID = GetBinding("uuid", ""); std::string UUID = GetBinding("uuid", "");
ProvObjects::Entity Existing; ProvObjects::Entity Existing;
if(UUID.empty() || !DB_.GetRecord("id",UUID,Existing)) { if (UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
return NotFound(); return NotFound();
} }
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
Existing.to_json(Answer); Existing.to_json(Answer);
if(NeedAdditionalInfo()) if (NeedAdditionalInfo())
AddExtendedInfo( Existing, Answer); AddExtendedInfo(Existing, Answer);
ReturnObject(Answer); ReturnObject(Answer);
} }
void RESTAPI_entity_handler::DoDelete() { void RESTAPI_entity_handler::DoDelete() {
std::string UUID = GetBinding("uuid", ""); std::string UUID = GetBinding("uuid", "");
ProvObjects::Entity Existing; ProvObjects::Entity Existing;
if(UUID.empty() || !DB_.GetRecord("id",UUID,Existing)) { if (UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
return NotFound(); return NotFound();
} }
if(UUID == EntityDB::RootUUID()) { if (UUID == EntityDB::RootUUID()) {
return BadRequest(RESTAPI::Errors::CannotDeleteRoot); return BadRequest(RESTAPI::Errors::CannotDeleteRoot);
} }
if( !Existing.children.empty() || !Existing.devices.empty() || !Existing.venues.empty() || !Existing.locations.empty() if (!Existing.children.empty() || !Existing.devices.empty() || !Existing.venues.empty() ||
|| !Existing.contacts.empty() || !Existing.configurations.empty()) { !Existing.locations.empty() || !Existing.contacts.empty() ||
return BadRequest(RESTAPI::Errors::StillInUse); !Existing.configurations.empty()) {
} return BadRequest(RESTAPI::Errors::StillInUse);
}
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id); MoveUsage(StorageService()->PolicyDB(), DB_, Existing.managementPolicy, "",
DB_.DeleteRecord("id",UUID); Existing.info.id);
DB_.DeleteChild("id",Existing.parent,UUID); DB_.DeleteRecord("id", UUID);
return OK(); DB_.DeleteChild("id", Existing.parent, UUID);
} return OK();
}
void RESTAPI_entity_handler::DoPost() { void RESTAPI_entity_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);
} }
if(UUID==EntityDB::RootUUID()) { if (UUID == EntityDB::RootUUID()) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
} }
const auto & RawObject = ParsedBody_; const auto &RawObject = ParsedBody_;
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))) { if ((RawObject->has("deviceRules") && !ValidDeviceRules(NewEntity.deviceRules, *this))) {
return; return;
} }
if(!ProvObjects::CreateObjectInfo(RawObject,UserInfo_.userinfo,NewEntity.info)) { if (!ProvObjects::CreateObjectInfo(RawObject, UserInfo_.userinfo, NewEntity.info)) {
return BadRequest(RESTAPI::Errors::NameMustBeSet); return BadRequest(RESTAPI::Errors::NameMustBeSet);
} }
// When creating an entity, it cannot have any relations other that parent, notes, name, description. Everything else // When creating an entity, it cannot have any relations other that parent, notes, name,
// must be conveyed through PUT. // description. Everything else must be conveyed through PUT.
NewEntity.info.id = (UUID==EntityDB::RootUUID()) ? UUID : MicroServiceCreateUUID(); NewEntity.info.id = (UUID == EntityDB::RootUUID()) ? UUID : MicroServiceCreateUUID();
if(UUID==EntityDB::RootUUID()) { if (UUID == EntityDB::RootUUID()) {
NewEntity.parent=""; NewEntity.parent = "";
} else if(NewEntity.parent.empty() || !DB_.Exists("id",NewEntity.parent)) { } else if (NewEntity.parent.empty() || !DB_.Exists("id", NewEntity.parent)) {
return BadRequest(RESTAPI::Errors::ParentUUIDMustExist); return BadRequest(RESTAPI::Errors::ParentUUIDMustExist);
} }
if(!NewEntity.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id", NewEntity.managementPolicy)){ if (!NewEntity.managementPolicy.empty() &&
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID); !StorageService()->PolicyDB().Exists("id", NewEntity.managementPolicy)) {
} return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
if(!NewEntity.sourceIP.empty() && !CIDR::ValidateIpRanges(NewEntity.sourceIP)) { if (!NewEntity.sourceIP.empty() && !CIDR::ValidateIpRanges(NewEntity.sourceIP)) {
return BadRequest(RESTAPI::Errors::InvalidIPRanges); return BadRequest(RESTAPI::Errors::InvalidIPRanges);
} }
NewEntity.venues.clear(); NewEntity.venues.clear();
NewEntity.children.clear(); NewEntity.children.clear();
NewEntity.contacts.clear(); NewEntity.contacts.clear();
NewEntity.locations.clear(); NewEntity.locations.clear();
NewEntity.deviceConfiguration.clear(); NewEntity.deviceConfiguration.clear();
NewEntity.managementRoles.clear(); NewEntity.managementRoles.clear();
if(DB_.CreateRecord(NewEntity)) { if (DB_.CreateRecord(NewEntity)) {
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewEntity.managementPolicy,NewEntity.info.id); MoveUsage(StorageService()->PolicyDB(), DB_, "", NewEntity.managementPolicy,
DB_.AddChild("id",NewEntity.parent,NewEntity.info.id); NewEntity.info.id);
DB_.AddChild("id", NewEntity.parent, NewEntity.info.id);
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
NewEntity.to_json(Answer); NewEntity.to_json(Answer);
return ReturnObject(Answer); return ReturnObject(Answer);
} }
InternalError(RESTAPI::Errors::RecordNotCreated); InternalError(RESTAPI::Errors::RecordNotCreated);
} }
/* /*
* Put is a complex operation, it contains commands only. * Put is a complex operation, it contains commands only.
* addContact=UUID, delContact=UUID, * addContact=UUID, delContact=UUID,
* addLocation=UUID, delLocation=UUID, * addLocation=UUID, delLocation=UUID,
* addVenue=UUID, delVenue=UUID, * addVenue=UUID, delVenue=UUID,
* addEntity=UUID, delEntity=UUID * addEntity=UUID, delEntity=UUID
* addDevice=UUID, delDevice=UUID * addDevice=UUID, delDevice=UUID
*/ */
void RESTAPI_entity_handler::DoPut() { void RESTAPI_entity_handler::DoPut() {
std::string UUID = GetBinding("uuid", ""); std::string UUID = GetBinding("uuid", "");
ProvObjects::Entity Existing; ProvObjects::Entity 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_; const auto &RawObject = ParsedBody_;
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))) { if ((RawObject->has("deviceRules") && !ValidDeviceRules(NewEntity.deviceRules, *this))) {
return; 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 FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&EntityDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB())) if (!CreateMove(RawObject, "managementPolicy", &EntityDB::RecordName::managementPolicy,
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID); Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
if(RawObject->has("sourceIP")) { if (RawObject->has("sourceIP")) {
if(!NewEntity.sourceIP.empty() && !CIDR::ValidateIpRanges(NewEntity.sourceIP)) { if (!NewEntity.sourceIP.empty() && !CIDR::ValidateIpRanges(NewEntity.sourceIP)) {
return BadRequest(RESTAPI::Errors::InvalidIPRanges); return BadRequest(RESTAPI::Errors::InvalidIPRanges);
} }
Existing.sourceIP = NewEntity.sourceIP; Existing.sourceIP = NewEntity.sourceIP;
} }
RESTAPI::Errors::msg Error; RESTAPI::Errors::msg Error;
if(!StorageService()->Validate(Parameters_,Error)) { if (!StorageService()->Validate(Parameters_, Error)) {
return BadRequest(Error); return BadRequest(Error);
} }
if(RawObject->has("deviceRules")) if (RawObject->has("deviceRules"))
Existing.deviceRules = NewEntity.deviceRules; 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); MoveUsage(StorageService()->PolicyDB(), DB_, FromPolicy, ToPolicy, Existing.info.id);
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
ProvObjects::Entity NewRecord; ProvObjects::Entity NewRecord;
StorageService()->EntityDB().GetRecord("id",UUID, NewRecord); StorageService()->EntityDB().GetRecord("id", UUID, NewRecord);
NewRecord.to_json(Answer); NewRecord.to_json(Answer);
return ReturnObject(Answer); return ReturnObject(Answer);
} }
InternalError(RESTAPI::Errors::RecordNotUpdated); InternalError(RESTAPI::Errors::RecordNotUpdated);
} }
} } // namespace OpenWifi

View File

@@ -7,30 +7,29 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_entity_handler : public RESTAPIHandler { class RESTAPI_entity_handler : public RESTAPIHandler {
public: public:
RESTAPI_entity_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_entity_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server, uint64_t TransactionId,
std::vector<std::string>{ bool Internal)
Poco::Net::HTTPRequest::HTTP_GET, : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_POST, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_POST,
Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_PUT,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_DELETE,
Server, Poco::Net::HTTPRequest::HTTP_OPTIONS},
TransactionId, Server, TransactionId, Internal) {}
Internal){} static auto PathName() { return std::list<std::string>{"/api/v1/entity/{uuid}"}; };
static auto PathName() { return std::list<std::string>{"/api/v1/entity/{uuid}"}; };
private: private:
EntityDB & DB_=StorageService()->EntityDB(); EntityDB &DB_ = StorageService()->EntityDB();
void DoGet() final; void DoGet() final;
void DoPost() final ; void DoPost() final;
void DoPut() final; void DoPut() final;
void DoDelete() final; void DoDelete() final;
}; };
} } // namespace OpenWifi

View File

@@ -7,35 +7,34 @@
// //
#include "RESTAPI_entity_list_handler.h" #include "RESTAPI_entity_list_handler.h"
#include "StorageService.h"
#include "RESTAPI_db_helpers.h" #include "RESTAPI_db_helpers.h"
#include "StorageService.h"
namespace OpenWifi{ 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(DB_), ProvObjects::Entity>("entities", DB_, *this);
ProvObjects::Entity>("entities",DB_,*this ); } else if (QB_.CountOnly) {
} else if(QB_.CountOnly) { auto C = DB_.Count();
auto C = DB_.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);
DB_.BuildTree(FullTree); return ReturnObject(FullTree);
return ReturnObject(FullTree); } else {
} else { EntityDB::RecordVec Entities;
EntityDB::RecordVec Entities; DB_.GetRecords(QB_.Offset, QB_.Limit, Entities);
DB_.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_; const auto &FullTree = ParsedBody_;
DB_.ImportTree(FullTree); DB_.ImportTree(FullTree);
return OK(); return OK();
} }
BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
} }
} } // namespace OpenWifi

View File

@@ -6,29 +6,28 @@
// Arilia Wireless Inc. // Arilia Wireless Inc.
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_entity_list_handler : public RESTAPIHandler { class RESTAPI_entity_list_handler : public RESTAPIHandler {
public: public:
RESTAPI_entity_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_entity_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server, uint64_t TransactionId,
std::vector<std::string>{ bool Internal)
Poco::Net::HTTPRequest::HTTP_GET, : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_POST, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_POST,
Server, Poco::Net::HTTPRequest::HTTP_OPTIONS},
TransactionId, Server, TransactionId, Internal) {}
Internal){} static auto PathName() { return std::list<std::string>{"/api/v1/entity"}; };
static auto PathName() { return std::list<std::string>{"/api/v1/entity"}; };
private: private:
EntityDB &DB_=StorageService()->EntityDB(); EntityDB &DB_ = StorageService()->EntityDB();
void DoGet() final; void DoGet() final;
void DoPost() final ; void DoPost() final;
void DoPut() final {}; void DoPut() final{};
void DoDelete() final {}; void DoDelete() final{};
}; };
} } // namespace OpenWifi

View File

@@ -8,425 +8,475 @@
#include "RESTAPI_inventory_handler.h" #include "RESTAPI_inventory_handler.h"
#include "StorageService.h"
#include "APConfig.h" #include "APConfig.h"
#include "AutoDiscovery.h" #include "AutoDiscovery.h"
#include "sdks/SDK_gw.h" #include "DeviceTypeCache.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" #include "StorageService.h"
#include "framework/utils.h" #include "framework/utils.h"
#include "sdks/SDK_gw.h"
#include "sdks/SDK_sec.h"
namespace OpenWifi{ namespace OpenWifi {
void GetRejectedLines(const Poco::JSON::Object::Ptr &Response, Types::StringVec & Warnings) { void GetRejectedLines(const Poco::JSON::Object::Ptr &Response, Types::StringVec &Warnings) {
try { try {
if(Response->has("results")) { if (Response->has("results")) {
auto Results = Response->get("results").extract<Poco::JSON::Object::Ptr>(); auto Results = Response->get("results").extract<Poco::JSON::Object::Ptr>();
auto Status = Results->get("status").extract<Poco::JSON::Object::Ptr>(); auto Status = Results->get("status").extract<Poco::JSON::Object::Ptr>();
auto Rejected = Status->getArray("rejected"); auto Rejected = Status->getArray("rejected");
std::transform(Rejected->begin(),Rejected->end(),std::back_inserter(Warnings), [](auto i) -> auto { return i.toString(); }); std::transform(
// for(const auto &i:*Rejected) Rejected->begin(), Rejected->end(), std::back_inserter(Warnings),
// Warnings.push_back(i.toString()); [](auto i) -> auto { return i.toString(); });
} // for(const auto &i:*Rejected)
} catch (...) { // Warnings.push_back(i.toString());
} }
} } catch (...) {
}
}
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, "");
poco_debug(Logger(),fmt::format("{}: Retrieving inventory information.", SerialNumber)); poco_debug(Logger(), fmt::format("{}: Retrieving inventory information.", SerialNumber));
if (SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER, SerialNumber, Existing)) { if (SerialNumber.empty() ||
return NotFound(); !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER, SerialNumber, Existing)) {
} return NotFound();
poco_debug(Logger(), fmt::format("{},{}: Retrieving inventory information.", Existing.serialNumber, Existing.info.id)); }
poco_debug(Logger(), fmt::format("{},{}: Retrieving inventory information.",
Existing.serialNumber, Existing.info.id));
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
std::string Arg; std::string Arg;
if (GetBoolParameter("config", false)) { if (GetBoolParameter("config", false)) {
bool Explain = GetBoolParameter("explain", false); bool Explain = GetBoolParameter("explain", false);
APConfig Device(SerialNumber, Existing.deviceType, Logger(), Explain); APConfig Device(SerialNumber, Existing.deviceType, Logger(), Explain);
auto Configuration = Poco::makeShared<Poco::JSON::Object>(); auto Configuration = Poco::makeShared<Poco::JSON::Object>();
if (Device.Get(Configuration)) { if (Device.Get(Configuration)) {
Answer.set("config", Configuration); Answer.set("config", Configuration);
if (Explain) if (Explain)
Answer.set("explanation", Device.Explanation()); Answer.set("explanation", Device.Explanation());
} else { } else {
Answer.set("config", "none"); Answer.set("config", "none");
} }
return ReturnObject(Answer); return ReturnObject(Answer);
} else if (GetBoolParameter("firmwareOptions", false)) { } else if (GetBoolParameter("firmwareOptions", false)) {
ProvObjects::DeviceRules Rules; ProvObjects::DeviceRules Rules;
StorageService()->InventoryDB().EvaluateDeviceSerialNumberRules(SerialNumber, Rules); StorageService()->InventoryDB().EvaluateDeviceSerialNumberRules(SerialNumber, Rules);
Answer.set("firmwareUpgrade", Rules.firmwareUpgrade); Answer.set("firmwareUpgrade", Rules.firmwareUpgrade);
Answer.set("firmwareRCOnly", Rules.rcOnly == "yes"); Answer.set("firmwareRCOnly", Rules.rcOnly == "yes");
return ReturnObject(Answer); return ReturnObject(Answer);
} else if(GetBoolParameter("rrmSettings",false)) { } else if (GetBoolParameter("rrmSettings", false)) {
ProvObjects::DeviceRules Rules; ProvObjects::DeviceRules Rules;
StorageService()->InventoryDB().EvaluateDeviceSerialNumberRules(SerialNumber, Rules); StorageService()->InventoryDB().EvaluateDeviceSerialNumberRules(SerialNumber, Rules);
if(Rules.rrm=="no" || Rules.rrm=="inherit") { if (Rules.rrm == "no" || Rules.rrm == "inherit") {
Answer.set("rrm", Rules.rrm); Answer.set("rrm", Rules.rrm);
} else { } else {
ProvObjects::RRMDetails D; ProvObjects::RRMDetails D;
Poco::JSON::Parser P; Poco::JSON::Parser P;
try { try {
auto Obj = P.parse(Rules.rrm).extract<Poco::JSON::Object::Ptr>(); auto Obj = P.parse(Rules.rrm).extract<Poco::JSON::Object::Ptr>();
Answer.set("rrm", Obj); Answer.set("rrm", Obj);
} catch (...) { } catch (...) {
Answer.set("rrm", "invalid"); Answer.set("rrm", "invalid");
} }
} }
return ReturnObject(Answer); return ReturnObject(Answer);
} else if(GetBoolParameter("applyConfiguration", false)) { } else if (GetBoolParameter("applyConfiguration", false)) {
poco_debug(Logger(), fmt::format("{}: Retrieving configuration.",Existing.serialNumber)); poco_debug(Logger(),
auto Device = std::make_shared<APConfig>(SerialNumber, Existing.deviceType, Logger(), false); fmt::format("{}: Retrieving configuration.", Existing.serialNumber));
auto Configuration = Poco::makeShared<Poco::JSON::Object>(); auto Device =
Poco::JSON::Object ErrorsObj, WarningsObj; std::make_shared<APConfig>(SerialNumber, Existing.deviceType, Logger(), false);
ProvObjects::InventoryConfigApplyResult Results; auto Configuration = Poco::makeShared<Poco::JSON::Object>();
poco_debug(Logger(), fmt::format("{}: Computing configuration.",Existing.serialNumber)); Poco::JSON::Object ErrorsObj, WarningsObj;
if (Device->Get(Configuration)) { ProvObjects::InventoryConfigApplyResult Results;
std::ostringstream OS; poco_debug(Logger(),
Configuration->stringify(OS); fmt::format("{}: Computing configuration.", Existing.serialNumber));
Results.appliedConfiguration = OS.str(); if (Device->Get(Configuration)) {
auto Response=Poco::makeShared<Poco::JSON::Object>(); std::ostringstream OS;
poco_debug(Logger(), fmt::format("{}: Sending configuration push.",Existing.serialNumber)); Configuration->stringify(OS);
if (SDK::GW::Device::Configure(this, SerialNumber, Configuration, Response)) { Results.appliedConfiguration = OS.str();
poco_debug(Logger(), fmt::format("{}: Sending configuration pushed.",Existing.serialNumber)); auto Response = Poco::makeShared<Poco::JSON::Object>();
GetRejectedLines(Response, Results.warnings); poco_debug(Logger(),
Results.errorCode = 0; fmt::format("{}: Sending configuration push.", Existing.serialNumber));
} else { if (SDK::GW::Device::Configure(this, SerialNumber, Configuration, Response)) {
poco_debug(Logger(), fmt::format("{}: Sending configuration failed.",Existing.serialNumber)); poco_debug(Logger(), fmt::format("{}: Sending configuration pushed.",
Results.errorCode = 1; Existing.serialNumber));
} GetRejectedLines(Response, Results.warnings);
} else { Results.errorCode = 0;
poco_debug(Logger(), fmt::format("{}: Configuration is bad.",Existing.serialNumber)); } else {
Results.errorCode = 1; poco_debug(Logger(), fmt::format("{}: Sending configuration failed.",
} Existing.serialNumber));
Results.to_json(Answer); Results.errorCode = 1;
return ReturnObject(Answer); }
} else if(GetBoolParameter("resolveConfig", false)) { } else {
poco_debug(Logger(),fmt::format("{}: Retrieving configuration.",Existing.serialNumber)); poco_debug(Logger(),
auto Device = std::make_shared<APConfig>(SerialNumber, Existing.deviceType, Logger(), false); fmt::format("{}: Configuration is bad.", Existing.serialNumber));
auto Configuration = Poco::makeShared<Poco::JSON::Object>(); Results.errorCode = 1;
Poco::JSON::Object ErrorsObj, WarningsObj; }
ProvObjects::InventoryConfigApplyResult Results; Results.to_json(Answer);
poco_debug(Logger(),Poco::format("{}: Computing configuration.",Existing.serialNumber)); return ReturnObject(Answer);
if (Device->Get(Configuration)) { } else if (GetBoolParameter("resolveConfig", false)) {
Answer.set("configuration", Configuration); poco_debug(Logger(),
} else { fmt::format("{}: Retrieving configuration.", Existing.serialNumber));
Answer.set("error", 1); auto Device =
} std::make_shared<APConfig>(SerialNumber, Existing.deviceType, Logger(), false);
return ReturnObject(Answer); auto Configuration = Poco::makeShared<Poco::JSON::Object>();
} else if(QB_.AdditionalInfo) { Poco::JSON::Object ErrorsObj, WarningsObj;
AddExtendedInfo(Existing,Answer); ProvObjects::InventoryConfigApplyResult Results;
} poco_debug(Logger(),
Existing.to_json(Answer); Poco::format("{}: Computing configuration.", Existing.serialNumber));
ReturnObject(Answer); if (Device->Get(Configuration)) {
} Answer.set("configuration", Configuration);
} else {
Answer.set("error", 1);
}
return ReturnObject(Answer);
} else if (QB_.AdditionalInfo) {
AddExtendedInfo(Existing, Answer);
}
Existing.to_json(Answer);
ReturnObject(Answer);
}
void RESTAPI_inventory_handler::DoDelete() { void RESTAPI_inventory_handler::DoDelete() {
ProvObjects::InventoryTag Existing; ProvObjects::InventoryTag Existing;
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,""); std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
if(SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER,SerialNumber,Existing)) { if (SerialNumber.empty() ||
return NotFound(); !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER, SerialNumber, Existing)) {
} return NotFound();
}
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id); MoveUsage(StorageService()->PolicyDB(), DB_, Existing.managementPolicy, "",
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::configurations,Existing.venue,Existing.info.id); Existing.info.id);
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::configurations,Existing.entity,Existing.info.id); RemoveMembership(StorageService()->VenueDB(), &ProvObjects::Venue::configurations,
MoveUsage(StorageService()->LocationDB(),DB_,Existing.location,"",Existing.info.id); Existing.venue, Existing.info.id);
MoveUsage(StorageService()->ContactDB(),DB_,Existing.contact,"",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.deviceConfiguration.empty()) {
ProvObjects::DeviceConfiguration DC; ProvObjects::DeviceConfiguration DC;
if(StorageService()->ConfigurationDB().GetRecord("id", Existing.deviceConfiguration, DC)) { if (StorageService()->ConfigurationDB().GetRecord("id", Existing.deviceConfiguration,
if(DC.subscriberOnly) DC)) {
StorageService()->ConfigurationDB().DeleteRecord("id", Existing.deviceConfiguration); if (DC.subscriberOnly)
else StorageService()->ConfigurationDB().DeleteRecord("id",
StorageService()->ConfigurationDB().DeleteInUse("id", Existing.deviceConfiguration, DB_.Prefix(), Existing.deviceConfiguration);
Existing.info.id); else
} StorageService()->ConfigurationDB().DeleteInUse(
} "id", Existing.deviceConfiguration, DB_.Prefix(), Existing.info.id);
}
}
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id); MoveUsage(StorageService()->PolicyDB(), DB_, Existing.managementPolicy, "",
MoveUsage(StorageService()->LocationDB(),DB_,Existing.location,"",Existing.info.id); Existing.info.id);
MoveUsage(StorageService()->ContactDB(),DB_,Existing.contact,"",Existing.info.id); MoveUsage(StorageService()->LocationDB(), DB_, Existing.location, "", Existing.info.id);
MoveUsage(StorageService()->ConfigurationDB(),DB_,Existing.deviceConfiguration,"",Existing.info.id); MoveUsage(StorageService()->ContactDB(), DB_, Existing.contact, "", Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::devices,Existing.entity,"",Existing.info.id); MoveUsage(StorageService()->ConfigurationDB(), DB_, Existing.deviceConfiguration, "",
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::devices,Existing.venue,"",Existing.info.id); Existing.info.id);
DB_.DeleteRecord("id", Existing.info.id); ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::devices,
SerialNumberCache()->DeleteSerialNumber(SerialNumber); Existing.entity, "", Existing.info.id);
return OK(); ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::devices, Existing.venue,
} "", Existing.info.id);
DB_.DeleteRecord("id", Existing.info.id);
SerialNumberCache()->DeleteSerialNumber(SerialNumber);
return OK();
}
void RESTAPI_inventory_handler::DoPost() {
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
Poco::toLowerInPlace(SerialNumber);
if (SerialNumber.empty()) {
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
}
void RESTAPI_inventory_handler::DoPost() { if (!NormalizeMac(SerialNumber)) {
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,""); return BadRequest(RESTAPI::Errors::InvalidSerialNumber);
Poco::toLowerInPlace(SerialNumber); }
if(SerialNumber.empty()) {
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
}
if(!NormalizeMac(SerialNumber)) { if (DB_.Exists(RESTAPI::Protocol::SERIALNUMBER, SerialNumber)) {
return BadRequest(RESTAPI::Errors::InvalidSerialNumber); return BadRequest(RESTAPI::Errors::SerialNumberExists);
} }
if(DB_.Exists(RESTAPI::Protocol::SERIALNUMBER,SerialNumber)) { const auto &RawObject = ParsedBody_;
return BadRequest(RESTAPI::Errors::SerialNumberExists); ProvObjects::InventoryTag NewObject;
} if (!NewObject.from_json(RawObject)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
const auto & RawObject = ParsedBody_; NormalizeMac(NewObject.serialNumber);
ProvObjects::InventoryTag NewObject; if (SerialNumber != NewObject.serialNumber) {
if (!NewObject.from_json(RawObject)) { return BadRequest(RESTAPI::Errors::SerialNumberMismatch);
return BadRequest(RESTAPI::Errors::InvalidJSONDocument); }
}
NormalizeMac(NewObject.serialNumber); if ((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules, *this))) {
if(SerialNumber!=NewObject.serialNumber) { return;
return BadRequest(RESTAPI::Errors::SerialNumberMismatch); }
}
if((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules,*this))) { if (!Provisioning::DeviceClass::Validate(NewObject.devClass.c_str())) {
return; return BadRequest(RESTAPI::Errors::InvalidDeviceClass);
} }
if(!Provisioning::DeviceClass::Validate(NewObject.devClass.c_str())) { if (NewObject.devClass.empty()) {
return BadRequest(RESTAPI::Errors::InvalidDeviceClass); NewObject.devClass = Provisioning::DeviceClass::ANY;
} }
if(NewObject.devClass.empty()) { if (!ProvObjects::CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info)) {
NewObject.devClass = Provisioning::DeviceClass::ANY; return BadRequest(RESTAPI::Errors::NameMustBeSet);
} }
if(!ProvObjects::CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info)) { if (NewObject.deviceType.empty() ||
return BadRequest( RESTAPI::Errors::NameMustBeSet); !DeviceTypeCache()->IsAcceptableDeviceType(NewObject.deviceType)) {
} return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
}
if(NewObject.deviceType.empty() || !DeviceTypeCache()->IsAcceptableDeviceType(NewObject.deviceType)) { if (OpenWifi::EntityDB::IsRoot(NewObject.entity) ||
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes); (!NewObject.entity.empty() &&
} !StorageService()->EntityDB().Exists("id", NewObject.entity))) {
return BadRequest(RESTAPI::Errors::ValidNonRootUUID);
}
if(OpenWifi::EntityDB::IsRoot(NewObject.entity) || (!NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObject.entity))) { if (!NewObject.venue.empty() &&
return BadRequest(RESTAPI::Errors::ValidNonRootUUID); !StorageService()->VenueDB().Exists("id", NewObject.venue)) {
} return BadRequest(RESTAPI::Errors::VenueMustExist);
}
if(!NewObject.venue.empty() && !StorageService()->VenueDB().Exists("id",NewObject.venue)) { if (!NewObject.venue.empty() && !NewObject.entity.empty()) {
return BadRequest(RESTAPI::Errors::VenueMustExist); return BadRequest(RESTAPI::Errors::NotBoth);
} }
if(!NewObject.venue.empty() && !NewObject.entity.empty()) { if (!NewObject.location.empty() &&
return BadRequest(RESTAPI::Errors::NotBoth); !StorageService()->LocationDB().Exists("id", NewObject.location)) {
} return BadRequest(RESTAPI::Errors::LocationMustExist);
}
if(!NewObject.location.empty() && !StorageService()->LocationDB().Exists("id",NewObject.location)) { if (!NewObject.contact.empty() &&
return BadRequest(RESTAPI::Errors::LocationMustExist); !StorageService()->ContactDB().Exists("id", NewObject.contact)) {
} return BadRequest(RESTAPI::Errors::ContactMustExist);
}
if(!NewObject.contact.empty() && !StorageService()->ContactDB().Exists("id",NewObject.contact)) { if (!NewObject.deviceConfiguration.empty() &&
return BadRequest(RESTAPI::Errors::ContactMustExist); !StorageService()->ConfigurationDB().Exists("id", NewObject.deviceConfiguration)) {
} return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
}
if(!NewObject.deviceConfiguration.empty() && !StorageService()->ConfigurationDB().Exists("id",NewObject.deviceConfiguration)) { if (!NewObject.managementPolicy.empty() &&
return BadRequest(RESTAPI::Errors::ConfigurationMustExist); !StorageService()->PolicyDB().Exists("id", NewObject.managementPolicy)) {
} return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) { std::vector<std::string> Errors;
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID); auto ObjectsCreated = CreateObjects(NewObject, *this, Errors);
} if (!Errors.empty()) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
}
RESTAPI::Errors::msg Error=RESTAPI::Errors::SUCCESS; if (DB_.CreateRecord(NewObject)) {
auto ObjectsCreated = CreateObjects(NewObject,*this,Error); SDK::GW::Device::SetOwnerShip(this, SerialNumber, NewObject.entity, NewObject.venue,
if(Error.err_num != 0) { NewObject.subscriber);
return BadRequest(Error); SerialNumberCache()->AddSerialNumber(SerialNumber, NewObject.deviceType);
} MoveUsage(StorageService()->PolicyDB(), DB_, "", NewObject.managementPolicy,
NewObject.info.id);
MoveUsage(StorageService()->LocationDB(), DB_, "", NewObject.location,
NewObject.info.id);
MoveUsage(StorageService()->ContactDB(), DB_, "", NewObject.contact, NewObject.info.id);
MoveUsage(StorageService()->ConfigurationDB(), DB_, "", NewObject.deviceConfiguration,
NewObject.info.id);
ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::devices, "",
NewObject.entity, NewObject.info.id);
ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::devices, "",
NewObject.venue, NewObject.info.id);
if(DB_.CreateRecord(NewObject)) { ProvObjects::InventoryTag NewTag;
SDK::GW::Device::SetOwnerShip(this, SerialNumber, NewObject.entity, NewObject.venue, NewObject.subscriber); DB_.GetRecord("id", NewObject.info.id, NewTag);
SerialNumberCache()->AddSerialNumber(SerialNumber,NewObject.deviceType); Poco::JSON::Object Answer;
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id); NewTag.to_json(Answer);
MoveUsage(StorageService()->LocationDB(),DB_,"",NewObject.location,NewObject.info.id); return ReturnObject(Answer);
MoveUsage(StorageService()->ContactDB(),DB_,"",NewObject.contact,NewObject.info.id); }
MoveUsage(StorageService()->ConfigurationDB(),DB_,"",NewObject.deviceConfiguration,NewObject.info.id); InternalError(RESTAPI::Errors::RecordNotCreated);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::devices,"",NewObject.entity,NewObject.info.id); }
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::devices,"",NewObject.venue,NewObject.info.id);
ProvObjects::InventoryTag NewTag; void RESTAPI_inventory_handler::DoPut() {
DB_.GetRecord("id",NewObject.info.id,NewTag);
Poco::JSON::Object Answer;
NewTag.to_json(Answer);
return ReturnObject(Answer);
}
InternalError(RESTAPI::Errors::RecordNotCreated);
}
void RESTAPI_inventory_handler::DoPut() { std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
if (SerialNumber.empty() || !Utils::ValidSerialNumber(SerialNumber)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,""); ProvObjects::InventoryTag Existing;
if(SerialNumber.empty() || !Utils::ValidSerialNumber(SerialNumber)) { if (SerialNumber.empty() ||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER, SerialNumber, Existing)) {
} return NotFound();
}
ProvObjects::InventoryTag Existing; auto RemoveSubscriber = GetParameter("removeSubscriber");
if(SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER,SerialNumber,Existing)) { if (!RemoveSubscriber.empty()) {
return NotFound(); if (Existing.subscriber == RemoveSubscriber) {
} poco_information(Logger(), fmt::format("{}: removing subscriber ({})", SerialNumber,
RemoveSubscriber));
ProvObjects::DeviceConfiguration DC;
if (StorageService()->ConfigurationDB().GetRecord(
"id", Existing.deviceConfiguration, DC)) {
poco_information(Logger(),
fmt::format("{}: removing configuration for subscriber ({})",
SerialNumber, RemoveSubscriber));
if (DC.subscriberOnly) {
if (!StorageService()->ConfigurationDB().DeleteRecord(
"id", Existing.deviceConfiguration)) {
poco_debug(Logger(), "Could not delete the subscriber configuration");
}
} else {
poco_debug(Logger(), "Configurations is not for a subscriber.");
}
Existing.deviceConfiguration = "";
}
Existing.subscriber = "";
Poco::JSON::Object state;
state.set("date", Utils::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 {
poco_information(Logger(), fmt::format("{}: wrong subscriber ({})", SerialNumber,
RemoveSubscriber));
}
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
auto RemoveSubscriber = GetParameter("removeSubscriber"); const auto &RawObject = ParsedBody_;
if(!RemoveSubscriber.empty()) { ProvObjects::InventoryTag NewObject;
if(Existing.subscriber == RemoveSubscriber) { if (!NewObject.from_json(RawObject)) {
poco_information(Logger(),fmt::format("{}: removing subscriber ({})", SerialNumber, RemoveSubscriber)); return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
ProvObjects::DeviceConfiguration DC; }
if(StorageService()->ConfigurationDB().GetRecord("id",Existing.deviceConfiguration,DC)) {
poco_information(Logger(),fmt::format("{}: removing configuration for subscriber ({})", SerialNumber, RemoveSubscriber));
if(DC.subscriberOnly) {
if(!StorageService()->ConfigurationDB().DeleteRecord("id", Existing.deviceConfiguration)) {
poco_debug(Logger(),"Could not delete the subscriber configuration");
}
}
else {
poco_debug(Logger(),"Configurations is not for a subscriber.");
}
Existing.deviceConfiguration = "";
}
Existing.subscriber = "";
Poco::JSON::Object state;
state.set("date",Utils::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 {
poco_information(Logger(),fmt::format("{}: wrong subscriber ({})", SerialNumber, RemoveSubscriber));
}
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
const auto & RawObject = ParsedBody_; if ((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules, *this))) {
ProvObjects::InventoryTag NewObject; return;
if(!NewObject.from_json(RawObject)) { }
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if((RawObject->has("deviceRules") && !ValidDeviceRules(NewObject.deviceRules,*this))) { if (!Provisioning::DeviceClass::Validate(NewObject.devClass.c_str())) {
return; return BadRequest(RESTAPI::Errors::InvalidDeviceClass);
} }
if(!Provisioning::DeviceClass::Validate(NewObject.devClass.c_str())) { if (!NewObject.deviceType.empty()) {
return BadRequest(RESTAPI::Errors::InvalidDeviceClass); if (!DeviceTypeCache()->IsAcceptableDeviceType(NewObject.deviceType)) {
} return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
}
}
if(!NewObject.deviceType.empty()) { if (!UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info)) {
if(!DeviceTypeCache()->IsAcceptableDeviceType(NewObject.deviceType)) { return BadRequest(RESTAPI::Errors::NameMustBeSet);
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes); }
}
}
if(!UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info)) { if (RawObject->has("deviceRules"))
return BadRequest(RESTAPI::Errors::NameMustBeSet); Existing.deviceRules = NewObject.deviceRules;
}
if(RawObject->has("deviceRules")) std::string FromPolicy, ToPolicy;
Existing.deviceRules = NewObject.deviceRules; if (!CreateMove(RawObject, "managementPolicy", &InventoryDB::RecordName::managementPolicy,
Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromPolicy, ToPolicy; std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"managementPolicy",&InventoryDB::RecordName::managementPolicy, Existing, FromPolicy, if (!CreateMove(RawObject, "entity", &InventoryDB::RecordName::entity, Existing, FromEntity,
ToPolicy, StorageService()->PolicyDB())) ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist); return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromEntity, ToEntity; std::string FromVenue, ToVenue;
if(!CreateMove(RawObject,"entity",&InventoryDB::RecordName::entity, Existing, FromEntity, ToEntity, if (!CreateMove(RawObject, "venue", &InventoryDB::RecordName::venue, Existing, FromVenue,
StorageService()->EntityDB())) ToVenue, StorageService()->VenueDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist); return BadRequest(RESTAPI::Errors::VenueMustExist);
std::string FromVenue, ToVenue; std::string FromLocation, ToLocation;
if(!CreateMove(RawObject,"venue",&InventoryDB::RecordName::venue, Existing, FromVenue, ToVenue, if (!CreateMove(RawObject, "location", &InventoryDB::RecordName::location, Existing,
StorageService()->VenueDB())) FromLocation, ToLocation, StorageService()->LocationDB()))
return BadRequest(RESTAPI::Errors::VenueMustExist); return BadRequest(RESTAPI::Errors::VenueMustExist);
std::string FromLocation, ToLocation; std::string FromContact, ToContact;
if(!CreateMove(RawObject,"location",&InventoryDB::RecordName::location, Existing, FromLocation, ToLocation, if (!CreateMove(RawObject, "contact", &InventoryDB::RecordName::contact, Existing,
StorageService()->LocationDB())) FromContact, ToContact, StorageService()->ContactDB()))
return BadRequest(RESTAPI::Errors::VenueMustExist); return BadRequest(RESTAPI::Errors::VenueMustExist);
std::string FromContact, ToContact; std::string FromConfiguration, ToConfiguration;
if(!CreateMove(RawObject,"contact",&InventoryDB::RecordName::contact, Existing, FromContact, ToContact, if (!CreateMove(RawObject, "deviceConfiguration",
StorageService()->ContactDB())) &InventoryDB::RecordName::deviceConfiguration, Existing, FromConfiguration,
return BadRequest(RESTAPI::Errors::VenueMustExist); ToConfiguration, StorageService()->ConfigurationDB()))
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
std::string FromConfiguration, ToConfiguration; std::string NewSubScriber;
if(!CreateMove(RawObject,"deviceConfiguration",&InventoryDB::RecordName::deviceConfiguration, Existing, if (AssignIfPresent(RawObject, "subscriber", NewSubScriber)) {
FromConfiguration, ToConfiguration, StorageService()->ConfigurationDB())) if (!NewSubScriber.empty()) {
return BadRequest(RESTAPI::Errors::ConfigurationMustExist); if (NewSubScriber != Existing.subscriber) {
SecurityObjects::UserInfo U;
if (SDK::Sec::Subscriber::Get(this, NewSubScriber, U)) {
Existing.subscriber = NewSubScriber;
} else {
return BadRequest(RESTAPI::Errors::SubscriberMustExist);
}
}
} else {
Existing.subscriber = "";
}
}
std::string NewSubScriber; AssignIfPresent(RawObject, "doNotAllowOverrides", Existing.doNotAllowOverrides);
if(AssignIfPresent(RawObject, "subscriber", NewSubScriber)) {
if(!NewSubScriber.empty()) {
if(NewSubScriber!=Existing.subscriber) {
SecurityObjects::UserInfo U;
if(SDK::Sec::Subscriber::Get(this, NewSubScriber, U)) {
Existing.subscriber = NewSubScriber;
} else {
return BadRequest(RESTAPI::Errors::SubscriberMustExist);
}
}
} else {
Existing.subscriber = "";
}
}
AssignIfPresent(RawObject, "doNotAllowOverrides", Existing.doNotAllowOverrides); if (RawObject->has("devClass") && NewObject.devClass != Existing.devClass) {
Existing.devClass = NewObject.devClass;
}
if( RawObject->has("devClass") && NewObject.devClass!= Existing.devClass) { if (RawObject->has("state") && NewObject.state != Existing.state) {
Existing.devClass = NewObject.devClass; Existing.state = NewObject.state;
} }
if( RawObject->has("state") && NewObject.state!= Existing.state) { std::vector<std::string> Errors;
Existing.state = NewObject.state; auto ObjectsCreated = CreateObjects(NewObject, *this, Errors);
} if (!Errors.empty()) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
}
RESTAPI::Errors::msg Error=RESTAPI::Errors::SUCCESS; if (!ObjectsCreated.empty()) {
auto ObjectsCreated = CreateObjects(NewObject,*this,Error); auto it = ObjectsCreated.find("configuration");
if(Error.err_num != 0) { if (it != ObjectsCreated.end()) {
return BadRequest(Error); FromConfiguration = "";
} ToConfiguration = it->second;
Existing.deviceConfiguration = ToConfiguration;
}
}
if(!ObjectsCreated.empty()) { if (StorageService()->InventoryDB().UpdateRecord("id", Existing.info.id, Existing)) {
auto it = ObjectsCreated.find("configuration"); MoveUsage(StorageService()->PolicyDB(), DB_, FromPolicy, ToPolicy, Existing.info.id);
if(it!=ObjectsCreated.end()) { MoveUsage(StorageService()->LocationDB(), DB_, FromLocation, ToLocation,
FromConfiguration=""; Existing.info.id);
ToConfiguration=it->second; MoveUsage(StorageService()->ContactDB(), DB_, FromContact, ToContact, Existing.info.id);
Existing.deviceConfiguration=ToConfiguration; MoveUsage(StorageService()->ConfigurationDB(), DB_, FromConfiguration, ToConfiguration,
} Existing.info.id);
} ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::devices,
FromEntity, ToEntity, Existing.info.id);
ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::devices, FromVenue,
ToVenue, Existing.info.id);
if(StorageService()->InventoryDB().UpdateRecord("id", Existing.info.id, Existing)) { SDK::GW::Device::SetOwnerShip(this, SerialNumber, Existing.entity, Existing.venue,
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id); Existing.subscriber);
MoveUsage(StorageService()->LocationDB(),DB_,FromLocation,ToLocation,Existing.info.id);
MoveUsage(StorageService()->ContactDB(),DB_,FromContact,ToContact,Existing.info.id);
MoveUsage(StorageService()->ConfigurationDB(),DB_,FromConfiguration,ToConfiguration,Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::devices,FromEntity,ToEntity,Existing.info.id);
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::devices,FromVenue,ToVenue,Existing.info.id);
SDK::GW::Device::SetOwnerShip(this, SerialNumber, Existing.entity, Existing.venue, Existing.subscriber); ProvObjects::InventoryTag NewObjectCreated;
DB_.GetRecord("id", Existing.info.id, NewObjectCreated);
ProvObjects::InventoryTag NewObjectCreated; Poco::JSON::Object Answer;
DB_.GetRecord("id", Existing.info.id, NewObjectCreated); NewObject.to_json(Answer);
Poco::JSON::Object Answer; return ReturnObject(Answer);
NewObject.to_json(Answer); }
return ReturnObject(Answer); InternalError(RESTAPI::Errors::RecordNotUpdated);
} }
InternalError(RESTAPI::Errors::RecordNotUpdated); } // namespace OpenWifi
}
}

View File

@@ -7,30 +7,33 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_inventory_handler : public RESTAPIHandler { class RESTAPI_inventory_handler : public RESTAPIHandler {
public: public:
RESTAPI_inventory_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_inventory_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server, uint64_t TransactionId,
std::vector<std::string>{ bool Internal)
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_POST,
Server, Poco::Net::HTTPRequest::HTTP_PUT,
TransactionId, Poco::Net::HTTPRequest::HTTP_DELETE,
Internal){} Poco::Net::HTTPRequest::HTTP_OPTIONS},
static auto PathName() { return std::list<std::string>{"/api/v1/inventory/{serialNumber}"}; }; Server, TransactionId, Internal) {}
static auto PathName() {
return std::list<std::string>{"/api/v1/inventory/{serialNumber}"};
};
private: private:
InventoryDB &DB_=StorageService()->InventoryDB(); 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);
}; };
} } // namespace OpenWifi

View File

@@ -6,127 +6,132 @@
// Arilia Wireless Inc. // Arilia Wireless Inc.
// //
#include "RESTAPI_inventory_list_handler.h" #include "RESTAPI_inventory_list_handler.h"
#include "StorageService.h"
#include "RESTAPI/RESTAPI_db_helpers.h" #include "RESTAPI/RESTAPI_db_helpers.h"
#include "StorageService.h"
namespace OpenWifi{ namespace OpenWifi {
void RESTAPI_inventory_list_handler::SendList( const ProvObjects::InventoryTagVec & Tags, bool SerialOnly) { void RESTAPI_inventory_list_handler::SendList(const ProvObjects::InventoryTagVec &Tags,
Poco::JSON::Array Array; bool SerialOnly) {
for(const auto &i:Tags) { Poco::JSON::Array Array;
if(SerialOnly) { for (const auto &i : Tags) {
Array.add(i.serialNumber); if (SerialOnly) {
} else { Array.add(i.serialNumber);
Poco::JSON::Object O; } else {
i.to_json(O); Poco::JSON::Object O;
if(QB_.AdditionalInfo) i.to_json(O);
AddExtendedInfo(i,O); if (QB_.AdditionalInfo)
Array.add(O); AddExtendedInfo(i, O);
} Array.add(O);
} }
Poco::JSON::Object Answer; }
if(SerialOnly) Poco::JSON::Object Answer;
Answer.set("serialNumbers", Array); if (SerialOnly)
else Answer.set("serialNumbers", Array);
Answer.set("taglist", Array); else
ReturnObject(Answer); Answer.set("taglist", Array);
} ReturnObject(Answer);
}
void RESTAPI_inventory_list_handler::DoGet() { void RESTAPI_inventory_list_handler::DoGet() {
if(GetBoolParameter("orderSpec")) { if (GetBoolParameter("orderSpec")) {
return ReturnFieldList(DB_,*this); return ReturnFieldList(DB_, *this);
} }
bool SerialOnly=GetBoolParameter("serialOnly"); bool SerialOnly = GetBoolParameter("serialOnly");
std::string UUID; std::string UUID;
std::string Arg,Arg2; std::string Arg, Arg2;
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 (!DB_.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(DB_)>("taglist", DB_, *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 = DB_.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); DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, DB_.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 = DB_.Count(DB_.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); DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, DB_.OP("venue", ORM::EQ, UUID), OrderBy);
return SendList( Tags, SerialOnly); return SendList(Tags, SerialOnly);
} else if(GetBoolParameter("subscribersOnly") && GetBoolParameter("unassigned")) { } else if (GetBoolParameter("subscribersOnly") && GetBoolParameter("unassigned")) {
if(QB_.CountOnly) { if (QB_.CountOnly) {
auto C = DB_.Count(" devClass='subscriber' and subscriber='' "); auto C = DB_.Count(" devClass='subscriber' and subscriber='' ");
return ReturnCountOnly( C); return ReturnCountOnly(C);
} }
ProvObjects::InventoryTagVec Tags; ProvObjects::InventoryTagVec Tags;
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, " devClass='subscriber' and subscriber='' ", OrderBy); DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, " devClass='subscriber' and subscriber='' ",
if(QB_.CountOnly) { OrderBy);
auto C = DB_.Count(DB_.OP("venue",ORM::EQ,UUID)); if (QB_.CountOnly) {
return ReturnCountOnly( C); auto C = DB_.Count(DB_.OP("venue", ORM::EQ, UUID));
} return ReturnCountOnly(C);
return SendList(Tags, SerialOnly); }
} else if(GetBoolParameter("subscribersOnly")) { return SendList(Tags, SerialOnly);
if(QB_.CountOnly) { } else if (GetBoolParameter("subscribersOnly")) {
auto C = DB_.Count(" devClass='subscriber' and subscriber!='' "); if (QB_.CountOnly) {
return ReturnCountOnly( C); 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); ProvObjects::InventoryTagVec Tags;
return SendList(Tags, SerialOnly); DB_.GetRecords(QB_.Offset, QB_.Limit, Tags,
} else if(GetBoolParameter("unassigned")) { " devClass='subscriber' and subscriber!='' ", OrderBy);
if(QB_.CountOnly) { return SendList(Tags, SerialOnly);
std::string Empty; } else if (GetBoolParameter("unassigned")) {
auto C = DB_.Count( InventoryDB::OP( DB_.OP("venue",ORM::EQ,Empty), if (QB_.CountOnly) {
ORM::AND, DB_.OP("entity",ORM::EQ,Empty) )); std::string Empty;
return ReturnCountOnly(C); auto C = DB_.Count(InventoryDB::OP(DB_.OP("venue", ORM::EQ, Empty), ORM::AND,
} DB_.OP("entity", ORM::EQ, Empty)));
ProvObjects::InventoryTagVec Tags; return ReturnCountOnly(C);
std::string Empty; }
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, InventoryDB::OP( DB_.OP("venue",ORM::EQ,Empty), ProvObjects::InventoryTagVec Tags;
ORM::AND, DB_.OP("entity",ORM::EQ,Empty) ) , OrderBy ); std::string Empty;
return SendList(Tags, SerialOnly); DB_.GetRecords(QB_.Offset, QB_.Limit, Tags,
} else if (HasParameter("subscriber",Arg) && !Arg.empty()) { InventoryDB::OP(DB_.OP("venue", ORM::EQ, Empty), ORM::AND,
// looking for device(s) for a specific subscriber... DB_.OP("entity", ORM::EQ, Empty)),
ProvObjects::InventoryTagVec Tags; OrderBy);
DB_.GetRecords(0,100,Tags," subscriber='" + Arg + "'"); return SendList(Tags, SerialOnly);
if(SerialOnly) { } else if (HasParameter("subscriber", Arg) && !Arg.empty()) {
std::vector<std::string> SerialNumbers; // looking for device(s) for a specific subscriber...
std::transform(cbegin(Tags), cend(Tags), std::back_inserter(SerialNumbers), [](const auto &T) { return T.serialNumber; }); ProvObjects::InventoryTagVec Tags;
return ReturnObject("serialNumbers",SerialNumbers); DB_.GetRecords(0, 100, Tags, " subscriber='" + ORM::Escape(Arg) + "'");
} else { if (SerialOnly) {
return MakeJSONObjectArray("taglist", Tags, *this); std::vector<std::string> SerialNumbers;
} std::transform(cbegin(Tags), cend(Tags), std::back_inserter(SerialNumbers),
} else if (QB_.CountOnly) { [](const auto &T) { return T.serialNumber; });
auto C = DB_.Count(); return ReturnObject("serialNumbers", SerialNumbers);
return ReturnCountOnly(C); } else {
} else if (GetBoolParameter("rrmOnly")) { return MakeJSONObjectArray("taglist", Tags, *this);
Types::UUIDvec_t DeviceList; }
DB_.GetRRMDeviceList(DeviceList); } else if (QB_.CountOnly) {
if(QB_.CountOnly) auto C = DB_.Count();
return ReturnCountOnly(DeviceList.size()); return ReturnCountOnly(C);
else { } else if (GetBoolParameter("rrmOnly")) {
return ReturnObject("serialNumbers",DeviceList); Types::UUIDvec_t DeviceList;
} DB_.GetRRMDeviceList(DeviceList);
} else { if (QB_.CountOnly)
ProvObjects::InventoryTagVec Tags; return ReturnCountOnly(DeviceList.size());
DB_.GetRecords(QB_.Offset,QB_.Limit,Tags,"",OrderBy); else {
return MakeJSONObjectArray("taglist", Tags, *this); return ReturnObject("serialNumbers", DeviceList);
} }
} } else {
} ProvObjects::InventoryTagVec Tags;
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, "", OrderBy);
return MakeJSONObjectArray("taglist", Tags, *this);
}
}
} // namespace OpenWifi

View File

@@ -7,29 +7,29 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_inventory_list_handler : public RESTAPIHandler { class RESTAPI_inventory_list_handler : public RESTAPIHandler {
public: public:
RESTAPI_inventory_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_inventory_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server,
std::vector<std::string>{ uint64_t TransactionId, bool Internal)
Poco::Net::HTTPRequest::HTTP_GET, : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Server, Poco::Net::HTTPRequest::HTTP_OPTIONS},
TransactionId, Server, TransactionId, Internal) {}
Internal){} static auto PathName() { return std::list<std::string>{"/api/v1/inventory"}; };
static auto PathName() { return std::list<std::string>{"/api/v1/inventory"}; };
private:
InventoryDB &DB_=StorageService()->InventoryDB();
void DoGet() final;
void DoPost() final {};
void DoPut() final {};
void DoDelete() final {};
void SendList(const ProvObjects::InventoryTagVec & Tags, bool SerialOnly); private:
}; InventoryDB &DB_ = StorageService()->InventoryDB();
} void DoGet() final;
void DoPost() final{};
void DoPut() final{};
void DoDelete() final{};
void SendList(const ProvObjects::InventoryTagVec &Tags, bool SerialOnly);
};
} // namespace OpenWifi

View File

@@ -8,19 +8,19 @@
namespace OpenWifi { namespace OpenWifi {
void RESTAPI_iptocountry_handler::DoGet() { void RESTAPI_iptocountry_handler::DoGet() {
auto IPList = GetParameter("iplist",""); auto IPList = GetParameter("iplist", "");
if(IPList.empty()) { if (IPList.empty()) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
} }
auto IPAddresses = Poco::StringTokenizer(IPList,","); auto IPAddresses = Poco::StringTokenizer(IPList, ",");
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
Answer.set("enabled", FindCountryFromIP()->Enabled()); Answer.set("enabled", FindCountryFromIP()->Enabled());
Poco::JSON::Array Countries; Poco::JSON::Array Countries;
for(const auto &i:IPAddresses) { for (const auto &i : IPAddresses) {
Countries.add(FindCountryFromIP()->Get(i)); Countries.add(FindCountryFromIP()->Get(i));
} }
Answer.set("countryCodes", Countries); Answer.set("countryCodes", Countries);
@@ -28,4 +28,4 @@ namespace OpenWifi {
return ReturnObject(Answer); return ReturnObject(Answer);
} }
} } // namespace OpenWifi

View File

@@ -3,23 +3,23 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_iptocountry_handler : public RESTAPIHandler { class RESTAPI_iptocountry_handler : public RESTAPIHandler {
public: public:
RESTAPI_iptocountry_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_iptocountry_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server, uint64_t TransactionId,
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET, bool Internal)
Poco::Net::HTTPRequest::HTTP_OPTIONS}, : RESTAPIHandler(bindings, L,
Server, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
TransactionId, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Internal){}; Server, TransactionId, Internal){};
static auto PathName() { return std::list<std::string>{"/api/v1/iptocountry"}; }; static auto PathName() { return std::list<std::string>{"/api/v1/iptocountry"}; };
void DoGet() final; void DoGet() final;
void DoDelete() final {}; void DoDelete() final{};
void DoPost() final {}; void DoPost() final{};
void DoPut() final {}; void DoPut() final{};
}; };
} } // namespace OpenWifi

View File

@@ -6,162 +6,169 @@
// Arilia Wireless Inc. // Arilia Wireless Inc.
// //
#include "RESTAPI_location_handler.h" #include "RESTAPI_location_handler.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h"
#include "Daemon.h" #include "Daemon.h"
#include "RESTAPI/RESTAPI_db_helpers.h" #include "RESTAPI/RESTAPI_db_helpers.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h"
#include "framework/utils.h" #include "framework/utils.h"
namespace OpenWifi{ namespace OpenWifi {
void RESTAPI_location_handler::DoGet() { void RESTAPI_location_handler::DoGet() {
std::string UUID = GetBinding("uuid",""); std::string UUID = GetBinding("uuid", "");
ProvObjects::Location Existing; ProvObjects::Location Existing;
if(UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) { if (UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
return BadRequest(RESTAPI::Errors::MissingUUID); return BadRequest(RESTAPI::Errors::MissingUUID);
} }
std::string Arg; std::string Arg;
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
if(HasParameter("expandInUse",Arg) && Arg=="true") { if (HasParameter("expandInUse", Arg) && Arg == "true") {
Storage::ExpandedListMap M; Storage::ExpandedListMap M;
std::vector<std::string> Errors; std::vector<std::string> Errors;
Poco::JSON::Object Inner; Poco::JSON::Object Inner;
if(StorageService()->ExpandInUse(Existing.inUse,M,Errors)) { if (StorageService()->ExpandInUse(Existing.inUse, M, Errors)) {
for(const auto &[type,list]:M) { for (const auto &[type, list] : M) {
Poco::JSON::Array ObjList; Poco::JSON::Array ObjList;
for(const auto &i:list.entries) { for (const auto &i : list.entries) {
Poco::JSON::Object O; Poco::JSON::Object O;
i.to_json(O); i.to_json(O);
ObjList.add(O); ObjList.add(O);
} }
Inner.set(type,ObjList); Inner.set(type, ObjList);
} }
} }
Answer.set("entries", Inner); Answer.set("entries", Inner);
return ReturnObject(Answer); return ReturnObject(Answer);
} else if(QB_.AdditionalInfo) { } else if (QB_.AdditionalInfo) {
AddExtendedInfo(Existing, Answer); AddExtendedInfo(Existing, Answer);
} }
Existing.to_json(Answer); Existing.to_json(Answer);
ReturnObject(Answer); ReturnObject(Answer);
} }
void RESTAPI_location_handler::DoDelete() { void RESTAPI_location_handler::DoDelete() {
std::string UUID = GetBinding("uuid",""); std::string UUID = GetBinding("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();
} }
bool Force=false; bool Force = false;
std::string Arg; std::string Arg;
if(HasParameter("force",Arg) && Arg=="true") if (HasParameter("force", Arg) && Arg == "true")
Force=true; Force = true;
if(!Force && !Existing.inUse.empty()) { if (!Force && !Existing.inUse.empty()) {
return BadRequest(RESTAPI::Errors::StillInUse); return BadRequest(RESTAPI::Errors::StillInUse);
} }
DB_.DeleteRecord("id",UUID); DB_.DeleteRecord("id", UUID);
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::locations,Existing.entity,Existing.info.id); RemoveMembership(StorageService()->EntityDB(), &ProvObjects::Entity::locations,
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.info.id,"",Existing.info.id); Existing.entity, Existing.info.id);
return OK(); MoveUsage(StorageService()->PolicyDB(), DB_, Existing.info.id, "", Existing.info.id);
} return OK();
}
void RESTAPI_location_handler::DoPost() { void RESTAPI_location_handler::DoPost() {
std::string UUID = GetBinding(RESTAPI::Protocol::UUID,""); std::string UUID = GetBinding(RESTAPI::Protocol::UUID, "");
if(UUID.empty()) { if (UUID.empty()) {
return BadRequest(RESTAPI::Errors::MissingUUID); return BadRequest(RESTAPI::Errors::MissingUUID);
} }
const auto & Obj = ParsedBody_; const auto &Obj = ParsedBody_;
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);
} }
if(!ProvObjects::CreateObjectInfo(Obj, UserInfo_.userinfo, NewObject.info)) { if (!ProvObjects::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)) { if (NewObject.entity.empty() ||
return BadRequest(RESTAPI::Errors::EntityMustExist); !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() &&
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID); !StorageService()->PolicyDB().Exists("id", NewObject.managementPolicy)) {
} return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
NewObject.inUse.clear(); NewObject.inUse.clear();
if(DB_.CreateRecord(NewObject)) { if (DB_.CreateRecord(NewObject)) {
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id); MoveUsage(StorageService()->PolicyDB(), DB_, "", NewObject.managementPolicy,
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::locations,NewObject.entity,NewObject.info.id); NewObject.info.id);
AddMembership(StorageService()->EntityDB(), &ProvObjects::Entity::locations,
NewObject.entity, NewObject.info.id);
LocationDB::RecordName AddedRecord; LocationDB::RecordName AddedRecord;
DB_.GetRecord("id", NewObject.info.id,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);
} }
BadRequest(RESTAPI::Errors::RecordNotCreated); BadRequest(RESTAPI::Errors::RecordNotCreated);
} }
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_; const auto &RawObject = ParsedBody_;
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);
} }
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 FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&LocationDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB())) if (!CreateMove(RawObject, "managementPolicy", &LocationDB::RecordName::managementPolicy,
return BadRequest(RESTAPI::Errors::EntityMustExist); Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromEntity, ToEntity; std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&LocationDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB())) if (!CreateMove(RawObject, "entity", &LocationDB::RecordName::entity, Existing, FromEntity,
return BadRequest(RESTAPI::Errors::EntityMustExist); ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
AssignIfPresent(RawObject, "buildingName", Existing.buildingName); AssignIfPresent(RawObject, "buildingName", Existing.buildingName);
AssignIfPresent(RawObject, "city", Existing.city); AssignIfPresent(RawObject, "city", Existing.city);
AssignIfPresent(RawObject, "state", Existing.state); AssignIfPresent(RawObject, "state", Existing.state);
AssignIfPresent(RawObject, "postal", Existing.postal); AssignIfPresent(RawObject, "postal", Existing.postal);
AssignIfPresent(RawObject, "country", Existing.country); AssignIfPresent(RawObject, "country", Existing.country);
AssignIfPresent(RawObject, "geoCode", Existing.geoCode); AssignIfPresent(RawObject, "geoCode", Existing.geoCode);
if(RawObject->has("addressLines")) if (RawObject->has("addressLines"))
Existing.addressLines = NewObject.addressLines; Existing.addressLines = NewObject.addressLines;
if(RawObject->has("phones")) if (RawObject->has("phones"))
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 = Utils::Now(); Existing.info.modified = Utils::Now();
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); MoveUsage(StorageService()->PolicyDB(), DB_, FromPolicy, ToPolicy, Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::locations,FromEntity, ToEntity, Existing.info.id); ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::locations,
FromEntity, ToEntity, 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);
} }
InternalError(RESTAPI::Errors::RecordNotUpdated); InternalError(RESTAPI::Errors::RecordNotUpdated);
} }
} } // namespace OpenWifi

View File

@@ -7,28 +7,29 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_location_handler : public RESTAPIHandler { class RESTAPI_location_handler : public RESTAPIHandler {
public: public:
RESTAPI_location_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_location_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server, uint64_t TransactionId,
std::vector<std::string>{ bool Internal)
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_POST,
Server, Poco::Net::HTTPRequest::HTTP_PUT,
TransactionId, Poco::Net::HTTPRequest::HTTP_DELETE,
Internal){} Poco::Net::HTTPRequest::HTTP_OPTIONS},
static auto PathName() { return std::list<std::string>{"/api/v1/location/{uuid}"}; }; Server, TransactionId, Internal) {}
static auto PathName() { return std::list<std::string>{"/api/v1/location/{uuid}"}; };
private: private:
LocationDB & DB_ = StorageService()->LocationDB(); 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;
}; };
} } // namespace OpenWifi

View File

@@ -4,13 +4,13 @@
#include "RESTAPI_location_list_handler.h" #include "RESTAPI_location_list_handler.h"
#include "RESTAPI/RESTAPI_db_helpers.h"
#include "RESTObjects/RESTAPI_ProvObjects.h" #include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h" #include "StorageService.h"
#include "RESTAPI/RESTAPI_db_helpers.h"
namespace OpenWifi{ namespace OpenWifi {
void RESTAPI_location_list_handler::DoGet() { void RESTAPI_location_list_handler::DoGet() {
return ListHandler<LocationDB>("locations", DB_, *this); return ListHandler<LocationDB>("locations", DB_, *this);
} }
} } // namespace OpenWifi

View File

@@ -3,27 +3,27 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_location_list_handler : public RESTAPIHandler { class RESTAPI_location_list_handler : public RESTAPIHandler {
public: public:
RESTAPI_location_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_location_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server,
std::vector<std::string>{ uint64_t TransactionId, bool Internal)
Poco::Net::HTTPRequest::HTTP_GET, : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Server, Poco::Net::HTTPRequest::HTTP_OPTIONS},
TransactionId, Server, TransactionId, Internal) {}
Internal){} static auto PathName() { return std::list<std::string>{"/api/v1/location"}; };
static auto PathName() { return std::list<std::string>{"/api/v1/location"}; };
private: private:
LocationDB & DB_=StorageService()->LocationDB(); 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{};
}; };
} } // namespace OpenWifi

View File

@@ -6,144 +6,152 @@
// Arilia Wireless Inc. // Arilia Wireless Inc.
// //
#include "RESTAPI_managementPolicy_handler.h" #include "RESTAPI_managementPolicy_handler.h"
#include "Daemon.h"
#include "Poco/JSON/Parser.h"
#include "RESTAPI/RESTAPI_db_helpers.h"
#include "RESTObjects/RESTAPI_ProvObjects.h" #include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h" #include "StorageService.h"
#include "Poco/JSON/Parser.h"
#include "Daemon.h"
#include "RESTAPI/RESTAPI_db_helpers.h"
namespace OpenWifi{ namespace OpenWifi {
void RESTAPI_managementPolicy_handler::DoGet() { void RESTAPI_managementPolicy_handler::DoGet() {
std::string UUID = GetBinding("uuid",""); std::string UUID = GetBinding("uuid", "");
ProvObjects::ManagementPolicy Existing; ProvObjects::ManagementPolicy Existing;
if(UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) { if (UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
return NotFound(); return NotFound();
} }
std::string Arg; std::string Arg;
if(HasParameter("expandInUse",Arg) && Arg=="true") { if (HasParameter("expandInUse", Arg) && Arg == "true") {
Storage::ExpandedListMap M; Storage::ExpandedListMap M;
std::vector<std::string> Errors; std::vector<std::string> Errors;
Poco::JSON::Object Inner; Poco::JSON::Object Inner;
if(StorageService()->ExpandInUse(Existing.inUse,M,Errors)) { if (StorageService()->ExpandInUse(Existing.inUse, M, Errors)) {
for(const auto &[type,list]:M) { for (const auto &[type, list] : M) {
Poco::JSON::Array ObjList; Poco::JSON::Array ObjList;
for(const auto &i:list.entries) { for (const auto &i : list.entries) {
Poco::JSON::Object O; Poco::JSON::Object O;
i.to_json(O); i.to_json(O);
ObjList.add(O); ObjList.add(O);
} }
Inner.set(type,ObjList); Inner.set(type, ObjList);
} }
} }
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
Answer.set("entries", Inner); Answer.set("entries", Inner);
return ReturnObject(Answer); return ReturnObject(Answer);
} }
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
if(QB_.AdditionalInfo) if (QB_.AdditionalInfo)
AddExtendedInfo(Existing,Answer); AddExtendedInfo(Existing, Answer);
Existing.to_json(Answer); Existing.to_json(Answer);
ReturnObject(Answer); ReturnObject(Answer);
} }
void RESTAPI_managementPolicy_handler::DoDelete() { void RESTAPI_managementPolicy_handler::DoDelete() {
std::string UUID = GetBinding("uuid",""); std::string UUID = GetBinding("uuid", "");
ProvObjects::ManagementPolicy Existing; ProvObjects::ManagementPolicy Existing;
if(UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) { if (UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
return NotFound(); return NotFound();
} }
if(!Existing.inUse.empty()) { if (!Existing.inUse.empty()) {
return BadRequest(RESTAPI::Errors::StillInUse); return BadRequest(RESTAPI::Errors::StillInUse);
} }
StorageService()->PolicyDB().DeleteRecord("id", UUID); StorageService()->PolicyDB().DeleteRecord("id", UUID);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementPolicies,Existing.entity,"",Existing.info.id); ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::managementPolicies,
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementPolicies,Existing.venue,"",Existing.info.id); Existing.entity, "", Existing.info.id);
return OK(); ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::managementPolicies,
} Existing.venue, "", Existing.info.id);
return OK();
}
void RESTAPI_managementPolicy_handler::DoPost() { void RESTAPI_managementPolicy_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);
} }
ProvObjects::ManagementPolicy NewObject; ProvObjects::ManagementPolicy NewObject;
const auto & RawObject = ParsedBody_; const auto &RawObject = ParsedBody_;
if(!NewObject.from_json(RawObject)) { if (!NewObject.from_json(RawObject)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument); return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
} }
if(!CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info)) { if (!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 (NewObject.entity.empty() ||
return BadRequest(RESTAPI::Errors::EntityMustExist); !StorageService()->EntityDB().Exists("id", NewObject.entity)) {
} return BadRequest(RESTAPI::Errors::EntityMustExist);
}
if(NewObject.venue.empty() || !StorageService()->VenueDB().Exists("id", NewObject.venue)) { if (NewObject.venue.empty() || !StorageService()->VenueDB().Exists("id", NewObject.venue)) {
return BadRequest(RESTAPI::Errors::VenueMustExist); return BadRequest(RESTAPI::Errors::VenueMustExist);
} }
NewObject.inUse.clear(); NewObject.inUse.clear();
if(DB_.CreateRecord(NewObject)) { if (DB_.CreateRecord(NewObject)) {
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementPolicies,NewObject.entity,NewObject.info.id); AddMembership(StorageService()->EntityDB(), &ProvObjects::Entity::managementPolicies,
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementPolicies,NewObject.venue,NewObject.info.id); NewObject.entity, NewObject.info.id);
PolicyDB::RecordName AddedObject; AddMembership(StorageService()->VenueDB(), &ProvObjects::Venue::managementPolicies,
DB_.GetRecord("id",NewObject.info.id,AddedObject); NewObject.venue, NewObject.info.id);
Poco::JSON::Object Answer; PolicyDB::RecordName AddedObject;
AddedObject.to_json(Answer); DB_.GetRecord("id", NewObject.info.id, AddedObject);
return ReturnObject(Answer); Poco::JSON::Object Answer;
} AddedObject.to_json(Answer);
InternalError(RESTAPI::Errors::RecordNotCreated); return ReturnObject(Answer);
} }
InternalError(RESTAPI::Errors::RecordNotCreated);
}
void RESTAPI_managementPolicy_handler::DoPut() { void RESTAPI_managementPolicy_handler::DoPut() {
std::string UUID = GetBinding("uuid",""); std::string UUID = GetBinding("uuid", "");
ProvObjects::ManagementPolicy Existing; ProvObjects::ManagementPolicy Existing;
if(UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) { if (UUID.empty() || !DB_.GetRecord("id", UUID, Existing)) {
return NotFound(); return NotFound();
} }
ProvObjects::ManagementPolicy NewPolicy; ProvObjects::ManagementPolicy NewPolicy;
const auto & RawObject = ParsedBody_; const auto &RawObject = ParsedBody_;
if(!NewPolicy.from_json(RawObject)) { if (!NewPolicy.from_json(RawObject)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument); return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
} }
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 FromEntity, ToEntity; std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&PolicyDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB())) if (!CreateMove(RawObject, "entity", &PolicyDB::RecordName::entity, Existing, FromEntity,
return BadRequest(RESTAPI::Errors::EntityMustExist); ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromVenue, ToVenue; std::string FromVenue, ToVenue;
if(!CreateMove(RawObject,"venue",&PolicyDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB())) if (!CreateMove(RawObject, "venue", &PolicyDB::RecordName::venue, Existing, FromVenue,
return BadRequest(RESTAPI::Errors::EntityMustExist); 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); ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::managementPolicies,
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementPolicies, FromVenue,ToVenue,Existing.info.id); FromEntity, ToEntity, Existing.info.id);
ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::managementPolicies,
FromVenue, ToVenue, Existing.info.id);
ProvObjects::ManagementPolicy P; 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);
return ReturnObject(Answer); return ReturnObject(Answer);
} }
InternalError(RESTAPI::Errors::RecordNotUpdated); InternalError(RESTAPI::Errors::RecordNotUpdated);
} }
} } // namespace OpenWifi

View File

@@ -6,30 +6,32 @@
// Arilia Wireless Inc. // Arilia Wireless Inc.
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_managementPolicy_handler : public RESTAPIHandler { class RESTAPI_managementPolicy_handler : public RESTAPIHandler {
public: public:
RESTAPI_managementPolicy_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_managementPolicy_handler(const RESTAPIHandler::BindingMap &bindings,
: RESTAPIHandler(bindings, L, Poco::Logger &L, RESTAPI_GenericServerAccounting &Server,
std::vector<std::string>{ uint64_t TransactionId, bool Internal)
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_POST,
Server, Poco::Net::HTTPRequest::HTTP_PUT,
TransactionId, Poco::Net::HTTPRequest::HTTP_DELETE,
Internal){} Poco::Net::HTTPRequest::HTTP_OPTIONS},
static auto PathName() { return std::list<std::string>{"/api/v1/managementPolicy/{uuid}"}; }; Server, TransactionId, Internal) {}
static auto PathName() {
return std::list<std::string>{"/api/v1/managementPolicy/{uuid}"};
};
private: private:
PolicyDB &DB_=StorageService()->PolicyDB(); PolicyDB &DB_ = StorageService()->PolicyDB();
void DoGet() final; void DoGet() final;
void DoPost() final ; void DoPost() final;
void DoPut() final ; void DoPut() final;
void DoDelete() final ; void DoDelete() final;
}; };
} } // namespace OpenWifi

View File

@@ -4,12 +4,12 @@
#include "RESTAPI_managementPolicy_list_handler.h" #include "RESTAPI_managementPolicy_list_handler.h"
#include "RESTAPI/RESTAPI_db_helpers.h"
#include "RESTObjects/RESTAPI_ProvObjects.h" #include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h" #include "StorageService.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); return ListHandler<PolicyDB>("managementPolicies", DB_, *this);
} }
} } // namespace OpenWifi

View File

@@ -3,27 +3,28 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_managementPolicy_list_handler : public RESTAPIHandler { class RESTAPI_managementPolicy_list_handler : public RESTAPIHandler {
public: public:
RESTAPI_managementPolicy_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_managementPolicy_list_handler(const RESTAPIHandler::BindingMap &bindings,
: RESTAPIHandler(bindings, L, Poco::Logger &L,
std::vector<std::string>{ RESTAPI_GenericServerAccounting &Server,
Poco::Net::HTTPRequest::HTTP_GET, uint64_t TransactionId, bool Internal)
Poco::Net::HTTPRequest::HTTP_OPTIONS}, : RESTAPIHandler(bindings, L,
Server, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
TransactionId, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Internal){} Server, TransactionId, Internal) {}
static auto PathName() { return std::list<std::string>{"/api/v1/managementPolicy"}; }; static auto PathName() { return std::list<std::string>{"/api/v1/managementPolicy"}; };
private:
PolicyDB &DB_=StorageService()->PolicyDB(); private:
void DoGet() final ; PolicyDB &DB_ = StorageService()->PolicyDB();
void DoPost() final {}; void DoGet() final;
void DoPut() final {}; void DoPost() final{};
void DoDelete() final {}; void DoPut() final{};
}; void DoDelete() final{};
} };
} // namespace OpenWifi

View File

@@ -4,150 +4,164 @@
#include "RESTAPI_managementRole_handler.h" #include "RESTAPI_managementRole_handler.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h"
#include "Poco/JSON/Parser.h" #include "Poco/JSON/Parser.h"
#include "Poco/StringTokenizer.h" #include "Poco/StringTokenizer.h"
#include "RESTAPI/RESTAPI_db_helpers.h" #include "RESTAPI/RESTAPI_db_helpers.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h"
namespace OpenWifi{ namespace OpenWifi {
void RESTAPI_managementRole_handler::DoGet() { void RESTAPI_managementRole_handler::DoGet() {
ProvObjects::ManagementRole Existing; ProvObjects::ManagementRole Existing;
std::string UUID = GetBinding(RESTAPI::Protocol::ID,""); std::string UUID = GetBinding(RESTAPI::Protocol::ID, "");
if(UUID.empty() || !DB_.GetRecord(RESTAPI::Protocol::ID,UUID,Existing)) { if (UUID.empty() || !DB_.GetRecord(RESTAPI::Protocol::ID, UUID, Existing)) {
return NotFound(); return NotFound();
} }
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
std::string Arg; std::string Arg;
if(HasParameter("expandInUse",Arg) && Arg=="true") { if (HasParameter("expandInUse", Arg) && Arg == "true") {
Storage::ExpandedListMap M; Storage::ExpandedListMap M;
std::vector<std::string> Errors; std::vector<std::string> Errors;
Poco::JSON::Object Inner; Poco::JSON::Object Inner;
if(StorageService()->ExpandInUse(Existing.inUse,M,Errors)) { if (StorageService()->ExpandInUse(Existing.inUse, M, Errors)) {
for(const auto &[type,list]:M) { for (const auto &[type, list] : M) {
Poco::JSON::Array ObjList; Poco::JSON::Array ObjList;
for(const auto &i:list.entries) { for (const auto &i : list.entries) {
Poco::JSON::Object O; Poco::JSON::Object O;
i.to_json(O); i.to_json(O);
ObjList.add(O); ObjList.add(O);
} }
Inner.set(type,ObjList); Inner.set(type, ObjList);
} }
} }
Answer.set("entries", Inner); Answer.set("entries", Inner);
return ReturnObject(Answer); return ReturnObject(Answer);
} }
if(QB_.AdditionalInfo) if (QB_.AdditionalInfo)
AddExtendedInfo(Existing,Answer); AddExtendedInfo(Existing, Answer);
Existing.to_json(Answer); Existing.to_json(Answer);
ReturnObject(Answer); ReturnObject(Answer);
} }
void RESTAPI_managementRole_handler::DoDelete() { void RESTAPI_managementRole_handler::DoDelete() {
ProvObjects::ManagementRole Existing; ProvObjects::ManagementRole Existing;
std::string UUID = GetBinding(RESTAPI::Protocol::ID,""); std::string UUID = GetBinding(RESTAPI::Protocol::ID, "");
if(UUID.empty() || !DB_.GetRecord(RESTAPI::Protocol::ID,UUID,Existing)) { if (UUID.empty() || !DB_.GetRecord(RESTAPI::Protocol::ID, UUID, Existing)) {
return NotFound(); return NotFound();
} }
bool Force=false; bool Force = false;
std::string Arg; std::string Arg;
if(HasParameter("force",Arg) && Arg=="true") if (HasParameter("force", Arg) && Arg == "true")
Force=true; Force = true;
if(!Force && !Existing.inUse.empty()) { if (!Force && !Existing.inUse.empty()) {
return BadRequest(RESTAPI::Errors::StillInUse); return BadRequest(RESTAPI::Errors::StillInUse);
} }
DB_.DeleteRecord("id", Existing.info.id); DB_.DeleteRecord("id", Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id); MoveUsage(StorageService()->PolicyDB(), DB_, Existing.managementPolicy, "",
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementRoles,Existing.entity,Existing.info.id); Existing.info.id);
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementRoles,Existing.venue,Existing.info.id); RemoveMembership(StorageService()->EntityDB(), &ProvObjects::Entity::managementRoles,
return OK(); Existing.entity, Existing.info.id);
} RemoveMembership(StorageService()->VenueDB(), &ProvObjects::Venue::managementRoles,
Existing.venue, Existing.info.id);
return OK();
}
void RESTAPI_managementRole_handler::DoPost() { void RESTAPI_managementRole_handler::DoPost() {
std::string UUID = GetBinding(RESTAPI::Protocol::ID,""); std::string UUID = GetBinding(RESTAPI::Protocol::ID, "");
if(UUID.empty()) { if (UUID.empty()) {
return BadRequest(RESTAPI::Errors::MissingUUID); return BadRequest(RESTAPI::Errors::MissingUUID);
} }
const auto & RawObj = ParsedBody_; const auto &RawObj = ParsedBody_;
ProvObjects::ManagementRole NewObject; ProvObjects::ManagementRole NewObject;
if (!NewObject.from_json(RawObj)) { if (!NewObject.from_json(RawObj)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument); return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
} }
if(!CreateObjectInfo(RawObj, UserInfo_.userinfo, NewObject.info)) { if (!CreateObjectInfo(RawObj, 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 (NewObject.entity.empty() ||
return BadRequest(RESTAPI::Errors::EntityMustExist); !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() &&
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID); !StorageService()->PolicyDB().Exists("id", NewObject.managementPolicy)) {
} return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
if(DB_.CreateRecord(NewObject)) { if (DB_.CreateRecord(NewObject)) {
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementRoles,NewObject.entity,NewObject.info.id); AddMembership(StorageService()->EntityDB(), &ProvObjects::Entity::managementRoles,
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementRoles,NewObject.venue,NewObject.info.id); NewObject.entity, NewObject.info.id);
MoveUsage(StorageService()->PolicyDB(), DB_, "", NewObject.managementPolicy, NewObject.info.id); AddMembership(StorageService()->VenueDB(), &ProvObjects::Venue::managementRoles,
NewObject.venue, 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);
Role.to_json(Answer); Role.to_json(Answer);
return ReturnObject(Answer); return ReturnObject(Answer);
} }
InternalError(RESTAPI::Errors::RecordNotCreated); InternalError(RESTAPI::Errors::RecordNotCreated);
} }
void RESTAPI_managementRole_handler::DoPut() { void RESTAPI_managementRole_handler::DoPut() {
ProvObjects::ManagementRole Existing; ProvObjects::ManagementRole Existing;
std::string UUID = GetBinding(RESTAPI::Protocol::ID,""); std::string UUID = GetBinding(RESTAPI::Protocol::ID, "");
if(UUID.empty() || !DB_.GetRecord(RESTAPI::Protocol::ID,UUID,Existing)) { if (UUID.empty() || !DB_.GetRecord(RESTAPI::Protocol::ID, UUID, Existing)) {
return NotFound(); return NotFound();
} }
const auto & RawObject = ParsedBody_; const auto &RawObject = ParsedBody_;
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);
} }
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 FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&ManagementRoleDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB())) if (!CreateMove(RawObject, "managementPolicy",
return BadRequest(RESTAPI::Errors::EntityMustExist); &ManagementRoleDB::RecordName::managementPolicy, Existing, FromPolicy,
ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromEntity, ToEntity; std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&ManagementRoleDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB())) if (!CreateMove(RawObject, "entity", &ManagementRoleDB::RecordName::entity, Existing,
return BadRequest(RESTAPI::Errors::EntityMustExist); FromEntity, ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromVenue, ToVenue; std::string FromVenue, ToVenue;
if(!CreateMove(RawObject,"venue",&ManagementRoleDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB())) if (!CreateMove(RawObject, "venue", &ManagementRoleDB::RecordName::venue, Existing,
return BadRequest(RESTAPI::Errors::EntityMustExist); 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); MoveUsage(StorageService()->PolicyDB(), DB_, FromPolicy, ToPolicy, Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementRoles, FromEntity, ToEntity, Existing.info.id); ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::managementRoles,
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementRoles, FromVenue, ToVenue, Existing.info.id); FromEntity, ToEntity, Existing.info.id);
ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::managementRoles,
FromVenue, ToVenue, Existing.info.id);
ProvObjects::ManagementRole NewRecord; ProvObjects::ManagementRole 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);
return ReturnObject(Answer); return ReturnObject(Answer);
} }
InternalError(RESTAPI::Errors::RecordNotUpdated); InternalError(RESTAPI::Errors::RecordNotUpdated);
} }
} } // namespace OpenWifi

View File

@@ -3,27 +3,29 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_managementRole_handler : public RESTAPIHandler { class RESTAPI_managementRole_handler : public RESTAPIHandler {
public: public:
RESTAPI_managementRole_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_managementRole_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server,
std::vector<std::string>{ uint64_t TransactionId, bool Internal)
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_POST,
Server, Poco::Net::HTTPRequest::HTTP_PUT,
TransactionId, Poco::Net::HTTPRequest::HTTP_DELETE,
Internal){} Poco::Net::HTTPRequest::HTTP_OPTIONS},
static auto PathName() { return std::list<std::string>{"/api/v1/managementRole/{uuid}"}; }; Server, TransactionId, Internal) {}
private: static auto PathName() { return std::list<std::string>{"/api/v1/managementRole/{uuid}"}; };
ManagementRoleDB &DB_=StorageService()->RolesDB();
void DoGet() final ; private:
void DoPost() final ; ManagementRoleDB &DB_ = StorageService()->RolesDB();
void DoPut() final ; void DoGet() final;
void DoDelete() final ; void DoPost() final;
}; void DoPut() final;
} void DoDelete() final;
};
} // namespace OpenWifi

View File

@@ -3,11 +3,11 @@
// //
#include "RESTAPI_managementRole_list_handler.h" #include "RESTAPI_managementRole_list_handler.h"
#include "StorageService.h"
#include "RESTAPI/RESTAPI_db_helpers.h" #include "RESTAPI/RESTAPI_db_helpers.h"
#include "StorageService.h"
namespace OpenWifi{ namespace OpenWifi {
void RESTAPI_managementRole_list_handler::DoGet() { void RESTAPI_managementRole_list_handler::DoGet() {
return ListHandler<ManagementRoleDB>("roles", DB_, *this); return ListHandler<ManagementRoleDB>("roles", DB_, *this);
} }
} } // namespace OpenWifi

View File

@@ -3,28 +3,28 @@
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_managementRole_list_handler : public RESTAPIHandler { class RESTAPI_managementRole_list_handler : public RESTAPIHandler {
public: public:
RESTAPI_managementRole_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_managementRole_list_handler(const RESTAPIHandler::BindingMap &bindings,
: RESTAPIHandler(bindings, L, Poco::Logger &L,
std::vector<std::string>{ RESTAPI_GenericServerAccounting &Server,
Poco::Net::HTTPRequest::HTTP_GET, uint64_t TransactionId, bool Internal)
Poco::Net::HTTPRequest::HTTP_OPTIONS}, : RESTAPIHandler(bindings, L,
Server, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
TransactionId, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Internal) { Server, TransactionId, Internal) {}
} static auto PathName() { return std::list<std::string>{"/api/v1/managementRole"}; };
static auto PathName() { return std::list<std::string>{"/api/v1/managementRole"}; };
private: private:
ManagementRoleDB &DB_=StorageService()->RolesDB(); ManagementRoleDB &DB_ = StorageService()->RolesDB();
void DoGet() final; void DoGet() final;
void DoPost() final {}; void DoPost() final{};
void DoPut() final {}; void DoPut() final{};
void DoDelete() final {}; void DoDelete() final{};
}; };
} } // namespace OpenWifi

View File

@@ -4,170 +4,183 @@
#include "RESTAPI_map_handler.h" #include "RESTAPI_map_handler.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h"
#include "Poco/JSON/Parser.h" #include "Poco/JSON/Parser.h"
#include "Poco/StringTokenizer.h" #include "Poco/StringTokenizer.h"
#include "RESTAPI/RESTAPI_db_helpers.h" #include "RESTAPI/RESTAPI_db_helpers.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h"
namespace OpenWifi{ namespace OpenWifi {
void RESTAPI_map_handler::DoGet() { void RESTAPI_map_handler::DoGet() {
ProvObjects::Map Existing; ProvObjects::Map Existing;
std::string UUID = GetBinding(RESTAPI::Protocol::UUID,""); std::string UUID = GetBinding(RESTAPI::Protocol::UUID, "");
if(UUID.empty() || !DB_.GetRecord(RESTAPI::Protocol::ID,UUID,Existing)) { if (UUID.empty() || !DB_.GetRecord(RESTAPI::Protocol::ID, UUID, Existing)) {
return NotFound(); return NotFound();
} }
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
if(QB_.AdditionalInfo) if (QB_.AdditionalInfo)
AddExtendedInfo(Existing,Answer); AddExtendedInfo(Existing, Answer);
Existing.to_json(Answer); Existing.to_json(Answer);
ReturnObject(Answer); ReturnObject(Answer);
} }
void RESTAPI_map_handler::DoDelete() { void RESTAPI_map_handler::DoDelete() {
ProvObjects::Map Existing; ProvObjects::Map Existing;
std::string UUID = GetBinding(RESTAPI::Protocol::UUID,""); std::string UUID = GetBinding(RESTAPI::Protocol::UUID, "");
if(UUID.empty() || !DB_.GetRecord(RESTAPI::Protocol::ID,UUID,Existing)) { if (UUID.empty() || !DB_.GetRecord(RESTAPI::Protocol::ID, UUID, Existing)) {
return NotFound(); return NotFound();
} }
if( UserInfo_.userinfo.userRole!=SecurityObjects::ROOT && if (UserInfo_.userinfo.userRole != SecurityObjects::ROOT &&
UserInfo_.userinfo.userRole!=SecurityObjects::ADMIN && UserInfo_.userinfo.userRole != SecurityObjects::ADMIN &&
UserInfo_.userinfo.id!=Existing.creator) { UserInfo_.userinfo.id != Existing.creator) {
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED); return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
} }
DB_.DeleteRecord("id", Existing.info.id); DB_.DeleteRecord("id", Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id); MoveUsage(StorageService()->PolicyDB(), DB_, Existing.managementPolicy, "",
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::maps,Existing.entity,Existing.info.id); Existing.info.id);
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::maps,Existing.venue,Existing.info.id); RemoveMembership(StorageService()->EntityDB(), &ProvObjects::Entity::maps, Existing.entity,
return OK(); Existing.info.id);
} RemoveMembership(StorageService()->VenueDB(), &ProvObjects::Venue::maps, Existing.venue,
Existing.info.id);
return OK();
}
static bool ValidateVisibility(const std::string &V) { static bool ValidateVisibility(const std::string &V) {
return (V=="private" || V=="public" || V=="select"); return (V == "private" || V == "public" || V == "select");
} }
void RESTAPI_map_handler::DoPost() { void RESTAPI_map_handler::DoPost() {
std::string UUID = GetBinding(RESTAPI::Protocol::UUID,""); std::string UUID = GetBinding(RESTAPI::Protocol::UUID, "");
if(UUID.empty()) { if (UUID.empty()) {
return BadRequest(RESTAPI::Errors::MissingUUID); return BadRequest(RESTAPI::Errors::MissingUUID);
} }
const auto & RawObject = ParsedBody_; const auto &RawObject = ParsedBody_;
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);
} }
if(!CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info)) { if (!CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info)) {
return BadRequest( RESTAPI::Errors::NameMustBeSet); return BadRequest(RESTAPI::Errors::NameMustBeSet);
} }
if(!ValidateVisibility(NewObject.visibility)) { if (!ValidateVisibility(NewObject.visibility)) {
return BadRequest(RESTAPI::Errors::InvalidVisibilityAttribute); return BadRequest(RESTAPI::Errors::InvalidVisibilityAttribute);
} }
if(RawObject->has("entity")) { if (RawObject->has("entity")) {
if(!NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObject.entity)) if (!NewObject.entity.empty() &&
return BadRequest(RESTAPI::Errors::EntityMustExist); !StorageService()->EntityDB().Exists("id", NewObject.entity))
} return BadRequest(RESTAPI::Errors::EntityMustExist);
}
if(RawObject->has("managementPolicy")) { if (RawObject->has("managementPolicy")) {
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) if (!NewObject.managementPolicy.empty() &&
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID); !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()->EntityDB(), &ProvObjects::Entity::maps,
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::maps,NewObject.venue,NewObject.info.id); NewObject.entity, NewObject.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id); AddMembership(StorageService()->VenueDB(), &ProvObjects::Venue::maps, NewObject.venue,
Poco::JSON::Object Answer; NewObject.info.id);
ProvObjects::Map M; MoveUsage(StorageService()->PolicyDB(), DB_, "", NewObject.managementPolicy,
DB_.GetRecord("id", NewObject.info.id,M); NewObject.info.id);
M.to_json(Answer); Poco::JSON::Object Answer;
return ReturnObject(Answer); ProvObjects::Map M;
} DB_.GetRecord("id", NewObject.info.id, M);
InternalError(RESTAPI::Errors::RecordNotCreated); M.to_json(Answer);
} return ReturnObject(Answer);
}
InternalError(RESTAPI::Errors::RecordNotCreated);
}
void RESTAPI_map_handler::DoPut() { void RESTAPI_map_handler::DoPut() {
ProvObjects::Map Existing; ProvObjects::Map Existing;
std::string UUID = GetBinding(RESTAPI::Protocol::UUID,""); std::string UUID = GetBinding(RESTAPI::Protocol::UUID, "");
if(UUID.empty() || !DB_.GetRecord(RESTAPI::Protocol::ID,UUID,Existing)) { if (UUID.empty() || !DB_.GetRecord(RESTAPI::Protocol::ID, UUID, Existing)) {
return NotFound(); return NotFound();
} }
const auto & RawObject = ParsedBody_; const auto &RawObject = ParsedBody_;
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);
} }
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( UserInfo_.userinfo.userRole!=SecurityObjects::ROOT && if (UserInfo_.userinfo.userRole != SecurityObjects::ROOT &&
UserInfo_.userinfo.userRole!=SecurityObjects::ADMIN && UserInfo_.userinfo.userRole != SecurityObjects::ADMIN &&
UserInfo_.userinfo.id!=Existing.creator) { UserInfo_.userinfo.id != Existing.creator) {
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED); return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
} }
if( UserInfo_.userinfo.userRole==SecurityObjects::ROOT || if (UserInfo_.userinfo.userRole == SecurityObjects::ROOT ||
UserInfo_.userinfo.userRole==SecurityObjects::ADMIN) { UserInfo_.userinfo.userRole == SecurityObjects::ADMIN) {
} else if(Existing.creator != UserInfo_.userinfo.id) { } else if (Existing.creator != UserInfo_.userinfo.id) {
if(Existing.visibility == "private") { if (Existing.visibility == "private") {
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED); return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
} }
if(Existing.visibility == "select") { if (Existing.visibility == "select") {
bool allowed=false; 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; allowed = true;
} }
} }
} }
if(!allowed) { if (!allowed) {
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED); return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
} }
} }
} }
std::string FromPolicy, ToPolicy; std::string FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&MapDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB())) if (!CreateMove(RawObject, "managementPolicy", &MapDB::RecordName::managementPolicy,
return BadRequest(RESTAPI::Errors::EntityMustExist); Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromEntity, ToEntity; std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&MapDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB())) if (!CreateMove(RawObject, "entity", &MapDB::RecordName::entity, Existing, FromEntity,
return BadRequest(RESTAPI::Errors::EntityMustExist); ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromVenue, ToVenue; std::string FromVenue, ToVenue;
if(!CreateMove(RawObject,"venue",&MapDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB())) if (!CreateMove(RawObject, "venue", &MapDB::RecordName::venue, Existing, FromVenue, ToVenue,
return BadRequest(RESTAPI::Errors::VenueMustExist); 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); MoveUsage(StorageService()->PolicyDB(), DB_, FromPolicy, ToPolicy, Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::maps,FromEntity,ToEntity,Existing.info.id); ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::maps, FromEntity,
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::maps,FromVenue,ToVenue,Existing.info.id); 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);
return ReturnObject(Answer); return ReturnObject(Answer);
} }
InternalError(RESTAPI::Errors::RecordNotUpdated); InternalError(RESTAPI::Errors::RecordNotUpdated);
} }
} } // namespace OpenWifi

View File

@@ -2,27 +2,29 @@
// Created by stephane bourque on 2021-11-09. // Created by stephane bourque on 2021-11-09.
// //
#pragma once #pragma once
#include "framework/RESTAPI_Handler.h"
#include "StorageService.h" #include "StorageService.h"
#include "framework/RESTAPI_Handler.h"
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_map_handler : public RESTAPIHandler { class RESTAPI_map_handler : public RESTAPIHandler {
public: public:
RESTAPI_map_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServerAccounting & Server, uint64_t TransactionId, bool Internal) RESTAPI_map_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
: RESTAPIHandler(bindings, L, RESTAPI_GenericServerAccounting &Server, uint64_t TransactionId,
std::vector<std::string>{ bool Internal)
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, : RESTAPIHandler(bindings, L,
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_POST,
Server, Poco::Net::HTTPRequest::HTTP_PUT,
TransactionId, Poco::Net::HTTPRequest::HTTP_DELETE,
Internal){} Poco::Net::HTTPRequest::HTTP_OPTIONS},
static auto PathName() { return std::list<std::string>{"/api/v1/map/{uuid}"}; }; Server, TransactionId, Internal) {}
private: static auto PathName() { return std::list<std::string>{"/api/v1/map/{uuid}"}; };
MapDB &DB_=StorageService()->MapDB();
void DoGet() final ; private:
void DoPost() final ; MapDB &DB_ = StorageService()->MapDB();
void DoPut() final ; void DoGet() final;
void DoDelete() final ; void DoPost() final;
}; void DoPut() final;
} void DoDelete() final;
};
} // namespace OpenWifi

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