mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralgw.git
synced 2025-11-02 11:47:47 +00:00
Compare commits
1 Commits
v2.4.0-RC2
...
release/v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
079b9f77a1 |
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
project(owgw VERSION 2.4.0)
|
||||
project(owgw VERSION 2.3.0)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
@@ -102,7 +102,7 @@ add_executable( owgw
|
||||
src/Dashboard.cpp src/Dashboard.h
|
||||
src/SerialNumberCache.cpp src/SerialNumberCache.h
|
||||
src/TelemetryStream.cpp src/TelemetryStream.h
|
||||
src/framework/ConfigurationValidator.cpp src/framework/ConfigurationValidator.h
|
||||
src/ConfigurationValidator.cpp src/ConfigurationValidator.h
|
||||
src/ConfigurationCache.cpp src/ConfigurationCache.h
|
||||
)
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@ Poco may take several minutes depending on the platform you are building on.
|
||||
### Ubuntu
|
||||
These instructions have proven to work on Ubuntu 20.4.
|
||||
```
|
||||
sudo apt install git cmake g++ libssl-dev libmariadb-dev
|
||||
sudo apt install git cmake g++ libssl-dev libmariadb-dev unixodbc-dev
|
||||
sudo apt install libpq-dev libaprutil1-dev apache2-dev libboost-all-dev
|
||||
sudo apt install librdkafka-dev libmysqlclient-dev default-libmysqlclient-dev
|
||||
sudo apt install librdkafka-dev liblua5.3-dev libmysqlclient-dev
|
||||
|
||||
git clone https://github.com/stephb9959/poco
|
||||
cd poco
|
||||
|
||||
@@ -24,12 +24,6 @@ spec:
|
||||
metadata:
|
||||
annotations:
|
||||
checksum/config: {{ include "owgw.config" . | sha256sum }}
|
||||
{{- if .Values.podSecurityPolicy.enabled }}
|
||||
kubernetes.io/psp: {{ include "owgw.fullname" . }}-{{ .Release.Namespace }}-owgw-unsafe-sysctl
|
||||
{{- end }}
|
||||
{{- with .Values.podAnnotations }}
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
labels:
|
||||
app.kubernetes.io/name: {{ include "owgw.name" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
{{- if .Values.podSecurityPolicy.enabled }}
|
||||
---
|
||||
apiVersion: policy/v1beta1
|
||||
kind: PodSecurityPolicy
|
||||
metadata:
|
||||
name: {{ include "owgw.fullname" . }}-{{ .Release.Namespace }}-owgw-unsafe-sysctl
|
||||
labels:
|
||||
app.kubernetes.io/name: {{ include "owgw.name" . }}
|
||||
helm.sh/chart: {{ include "owgw.chart" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||
spec:
|
||||
allowedUnsafeSysctls:
|
||||
{{- range $unsafeSysctl := .Values.securityContext.sysctls }}
|
||||
- {{ $unsafeSysctl.name }}
|
||||
{{- end }}
|
||||
privileged: false
|
||||
seLinux:
|
||||
rule: RunAsAny
|
||||
supplementalGroups:
|
||||
rule: RunAsAny
|
||||
runAsUser:
|
||||
rule: RunAsAny
|
||||
fsGroup:
|
||||
rule: RunAsAny
|
||||
volumes:
|
||||
- '*'
|
||||
{{- end }}
|
||||
@@ -1,16 +0,0 @@
|
||||
{{- if .Values.podSecurityPolicy.enabled }}
|
||||
---
|
||||
kind: Role
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
metadata:
|
||||
name: {{ include "owgw.fullname" . }}-owgw-use-unsafe-sysctl
|
||||
rules:
|
||||
- apiGroups:
|
||||
- policy
|
||||
resources:
|
||||
- podsecuritypolicies
|
||||
verbs:
|
||||
- use
|
||||
resourceNames:
|
||||
- {{ include "owgw.fullname" . }}-{{ .Release.Namespace }}-owgw-unsafe-sysctl
|
||||
{{- end }}
|
||||
@@ -1,15 +0,0 @@
|
||||
{{- if .Values.podSecurityPolicy.enabled }}
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: {{ include "owgw.fullname" . }}-owgw-use-unsafe-sysctl-to-default
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
name: {{ include "owgw.fullname" . }}-owgw-use-unsafe-sysctl
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: default
|
||||
namespace: {{ .Release.Namespace }}
|
||||
{{- end }}
|
||||
@@ -8,7 +8,7 @@ fullnameOverride: ""
|
||||
images:
|
||||
owgw:
|
||||
repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owgw
|
||||
tag: v2.4.0-RC2
|
||||
tag: v2.3.0-RC1
|
||||
pullPolicy: Always
|
||||
# regcred:
|
||||
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io
|
||||
@@ -112,17 +112,6 @@ resources: {}
|
||||
|
||||
securityContext:
|
||||
fsGroup: 101
|
||||
# Usage of unsafe sysctls requires multiple things:
|
||||
# - allow these unsafe sysctls on kubelet level (by adding --allowed-unsafe-sysctls flag)
|
||||
# - enabling addition of PodSecurityContext setting podSecurityPolicy.enabled to "true" below
|
||||
# - uncommenting parameters below
|
||||
#sysctls:
|
||||
#- name: net.ipv4.tcp_keepalive_intvl
|
||||
# value: "5"
|
||||
#- name: net.ipv4.tcp_keepalive_probes
|
||||
# value: "2"
|
||||
#- name: net.ipv4.tcp_keepalive_time
|
||||
# value: "45"
|
||||
|
||||
nodeSelector: {}
|
||||
|
||||
@@ -130,11 +119,6 @@ tolerations: []
|
||||
|
||||
affinity: {}
|
||||
|
||||
podAnnotations: {}
|
||||
|
||||
podSecurityPolicy:
|
||||
enabled: false
|
||||
|
||||
persistence:
|
||||
enabled: true
|
||||
# storageClassName: "-"
|
||||
|
||||
@@ -51,16 +51,6 @@ components:
|
||||
properties:
|
||||
ErrorCode:
|
||||
type: integer
|
||||
enum:
|
||||
- 0 # Success
|
||||
- 1 # PASSWORD_CHANGE_REQUIRED,
|
||||
- 2 # INVALID_CREDENTIALS,
|
||||
- 3 # PASSWORD_ALREADY_USED,
|
||||
- 4 # USERNAME_PENDING_VERIFICATION,
|
||||
- 5 # PASSWORD_INVALID,
|
||||
- 6 # INTERNAL_ERROR,
|
||||
- 7 # ACCESS_DENIED,
|
||||
- 8 # INVALID_TOKEN
|
||||
ErrorDetails:
|
||||
type: string
|
||||
ErrorDescription:
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class CommandManager * CommandManager::instance_ = nullptr;
|
||||
|
||||
void CommandManager::run() {
|
||||
Running_ = true;
|
||||
while(Running_)
|
||||
|
||||
@@ -68,12 +68,15 @@ namespace OpenWifi {
|
||||
bool GetCommand(uint64_t Id, const std::string & SerialNumber, CommandTag &T);
|
||||
|
||||
static CommandManager *instance() {
|
||||
static CommandManager *instance_ = new CommandManager;
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new CommandManager;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
inline bool Running() const { return Running_; }
|
||||
|
||||
private:
|
||||
static CommandManager * instance_;
|
||||
std::atomic_bool Running_ = false;
|
||||
Poco::Thread ManagerThread;
|
||||
uint64_t Id_=2; // do not start @1. We ignore ID=1 & 0 is illegal..
|
||||
|
||||
@@ -5,4 +5,5 @@
|
||||
#include "ConfigurationCache.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class ConfigurationCache * ConfigurationCache::instance_ = nullptr;
|
||||
}
|
||||
@@ -13,9 +13,10 @@ namespace OpenWifi {
|
||||
class ConfigurationCache {
|
||||
public:
|
||||
|
||||
static ConfigurationCache & instance() {
|
||||
static ConfigurationCache instance;
|
||||
return instance;
|
||||
static ConfigurationCache &instance() {
|
||||
if(instance_== nullptr)
|
||||
instance_ = new ConfigurationCache;
|
||||
return *instance_;
|
||||
}
|
||||
|
||||
inline uint64_t CurrentConfig(const std::string &SerialNumber) {
|
||||
@@ -26,12 +27,13 @@ namespace OpenWifi {
|
||||
return Hint->second;
|
||||
}
|
||||
|
||||
inline void Add(const std::string &SerialNumber, uint64_t Id) {
|
||||
void Add(const std::string &SerialNumber, uint64_t Id) {
|
||||
std::lock_guard G(Mutex_);
|
||||
Cache_[SerialNumber]=Id;
|
||||
}
|
||||
|
||||
private:
|
||||
static ConfigurationCache *instance_;
|
||||
std::mutex Mutex_;
|
||||
std::map<std::string,uint64_t> Cache_;
|
||||
};
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
// Created by stephane bourque on 2021-09-14.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "Poco/Logger.h"
|
||||
#include <fstream>
|
||||
#include <regex>
|
||||
#include <iostream>
|
||||
|
||||
#include "framework/MicroService.h"
|
||||
#include "ConfigurationValidator.h"
|
||||
#include "framework/CountryCodes.h"
|
||||
#include "Poco/StringTokenizer.h"
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
@@ -96,69 +94,6 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
},
|
||||
"globals.wireless-multimedia.class-selector": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"CS1",
|
||||
"CS2",
|
||||
"CS3",
|
||||
"CS4",
|
||||
"CS5",
|
||||
"CS6",
|
||||
"AF11",
|
||||
"AF12",
|
||||
"AF13",
|
||||
"AF21",
|
||||
"AF22",
|
||||
"AF23",
|
||||
"AF31",
|
||||
"AF32",
|
||||
"AF33",
|
||||
"AF41",
|
||||
"AF42",
|
||||
"AF43",
|
||||
"DF",
|
||||
"EF"
|
||||
]
|
||||
}
|
||||
},
|
||||
"globals.wireless-multimedia": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"UP0": {
|
||||
"$ref": "#/$defs/globals.wireless-multimedia.class-selector"
|
||||
},
|
||||
"UP1": {
|
||||
"$ref": "#/$defs/globals.wireless-multimedia.class-selector"
|
||||
},
|
||||
"UP2": {
|
||||
"$ref": "#/$defs/globals.wireless-multimedia.class-selector"
|
||||
},
|
||||
"UP3": {
|
||||
"$ref": "#/$defs/globals.wireless-multimedia.class-selector"
|
||||
},
|
||||
"UP4": {
|
||||
"$ref": "#/$defs/globals.wireless-multimedia.class-selector"
|
||||
},
|
||||
"UP5": {
|
||||
"$ref": "#/$defs/globals.wireless-multimedia.class-selector"
|
||||
},
|
||||
"UP6": {
|
||||
"$ref": "#/$defs/globals.wireless-multimedia.class-selector"
|
||||
},
|
||||
"UP7": {
|
||||
"$ref": "#/$defs/globals.wireless-multimedia.class-selector"
|
||||
}
|
||||
}
|
||||
},
|
||||
"globals.wireless-multimedia-profile": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"enterprise"
|
||||
]
|
||||
},
|
||||
"globals": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -175,16 +110,6 @@ namespace OpenWifi {
|
||||
"examples": [
|
||||
"fdca:1234:4567::/48"
|
||||
]
|
||||
},
|
||||
"wireless-multimedia": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/$defs/globals.wireless-multimedia"
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/globals.wireless-multimedia-profile"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -880,7 +805,6 @@ namespace OpenWifi {
|
||||
"sae",
|
||||
"sae-mixed",
|
||||
"wpa3",
|
||||
"wpa3-192",
|
||||
"wpa3-mixed"
|
||||
],
|
||||
"examples": [
|
||||
@@ -1217,11 +1141,8 @@ namespace OpenWifi {
|
||||
"maxLength": 2
|
||||
},
|
||||
"domain-name": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"format": "hostname"
|
||||
}
|
||||
"type": "string",
|
||||
"format": "hostname"
|
||||
},
|
||||
"nai-realm": {
|
||||
"type": "array",
|
||||
@@ -1342,25 +1263,6 @@ namespace OpenWifi {
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"wan-metrics": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"info": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"up",
|
||||
"down",
|
||||
"testing"
|
||||
]
|
||||
},
|
||||
"downlink": {
|
||||
"type": "integer"
|
||||
},
|
||||
"uplink": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1577,6 +1479,10 @@ namespace OpenWifi {
|
||||
"type": "string",
|
||||
"format": "ipv4",
|
||||
"example": "192.168.100.1"
|
||||
},
|
||||
"vlan-id": {
|
||||
"type": "integer",
|
||||
"maximum": 4096
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1934,13 +1840,9 @@ namespace OpenWifi {
|
||||
"properties": {
|
||||
"controller": {
|
||||
"type": "string",
|
||||
"format": "ip",
|
||||
"uc-format": "cidr",
|
||||
"example": "192.168.10.1"
|
||||
},
|
||||
"datapath-description": {
|
||||
"type": "string",
|
||||
"example": "Building 2, Floor 6, AP 2"
|
||||
},
|
||||
"mode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
@@ -1948,8 +1850,7 @@ namespace OpenWifi {
|
||||
"ptcp",
|
||||
"ssl",
|
||||
"tcp"
|
||||
],
|
||||
"default": "ssl"
|
||||
]
|
||||
},
|
||||
"ca-certificate": {
|
||||
"type": "string"
|
||||
@@ -2024,76 +1925,13 @@ namespace OpenWifi {
|
||||
"service.quality-of-service": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"select-ports": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"default": "WAN"
|
||||
}
|
||||
},
|
||||
"bandwidth-up": {
|
||||
"upload-rate": {
|
||||
"type": "integer",
|
||||
"default": 0
|
||||
},
|
||||
"bandwidth-down": {
|
||||
"download-rate": {
|
||||
"type": "integer",
|
||||
"default": 0
|
||||
},
|
||||
"classifier": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"dscp": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"CS0",
|
||||
"CS1",
|
||||
"CS2",
|
||||
"CS3",
|
||||
"CS4",
|
||||
"CS5",
|
||||
"CS6",
|
||||
"CS7"
|
||||
],
|
||||
"default": "CS1"
|
||||
},
|
||||
"ports": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"protocol": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"any",
|
||||
"tcp",
|
||||
"udp"
|
||||
],
|
||||
"default": "any"
|
||||
},
|
||||
"port": {
|
||||
"type": "integer"
|
||||
},
|
||||
"range-end": {
|
||||
"type": "integer"
|
||||
},
|
||||
"reclassify": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"dns": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"format": "fqdn"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -2315,6 +2153,7 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
)"_json;
|
||||
|
||||
class ConfigurationValidator *ConfigurationValidator::instance_ = nullptr;
|
||||
@@ -2323,13 +2162,13 @@ namespace OpenWifi {
|
||||
if(Initialized_)
|
||||
return;
|
||||
std::string GitSchema;
|
||||
try {
|
||||
if(Utils::wgets(GitUCentralJSONSchemaFile, GitSchema)) {
|
||||
auto schema = json::parse(GitSchema);
|
||||
Validator_->set_root_schema(schema);
|
||||
Logger_.information("Using uCentral validation schema from GIT.");
|
||||
} else {
|
||||
std::string FileName{ MicroService::instance().DataDir() + "/ucentral.schema.json" };
|
||||
if(Utils::wgets(GitUCentralJSONSchemaFile, GitSchema)) {
|
||||
auto schema = json::parse(GitSchema);
|
||||
Validator_->set_root_schema(schema);
|
||||
Logger_.information("Using uCentral validation schema from GIT.");
|
||||
} else {
|
||||
std::string FileName{ MicroService::instance().DataDir() + "/ucentral.schema.json" };
|
||||
try {
|
||||
std::ifstream input(FileName);
|
||||
std::stringstream schema_file;
|
||||
schema_file << input.rdbuf();
|
||||
@@ -2337,10 +2176,10 @@ namespace OpenWifi {
|
||||
auto schema = json::parse(schema_file.str());
|
||||
Validator_->set_root_schema(schema);
|
||||
Logger_.information("Using uCentral validation schema from local file.");
|
||||
} catch (const Poco::Exception &E) {
|
||||
Validator_->set_root_schema(DefaultUCentralSchema);
|
||||
Logger_.information("Using uCentral validation from built-in default.");
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Validator_->set_root_schema(DefaultUCentralSchema);
|
||||
Logger_.information("Using uCentral validation from built-in default.");
|
||||
}
|
||||
Initialized_ = Working_ = true;
|
||||
}
|
||||
@@ -2354,116 +2193,13 @@ namespace OpenWifi {
|
||||
|
||||
}
|
||||
|
||||
static inline bool IsIPv4(const std::string &value) {
|
||||
Poco::Net::IPAddress A;
|
||||
return ((Poco::Net::IPAddress::tryParse(value,A) && A.family()==Poco::Net::IPAddress::IPv4));
|
||||
}
|
||||
|
||||
static inline bool IsIPv6(const std::string &value) {
|
||||
Poco::Net::IPAddress A;
|
||||
return ((Poco::Net::IPAddress::tryParse(value,A) && A.family()==Poco::Net::IPAddress::IPv6));
|
||||
}
|
||||
|
||||
static inline bool IsIP(const std::string &value) {
|
||||
return IsIPv4(value) || IsIPv6(value);
|
||||
}
|
||||
|
||||
static inline bool IsCIDRv6(const std::string &value) {
|
||||
auto Tokens = Poco::StringTokenizer(value,"/");
|
||||
if(Tokens.count()==2 && IsIPv6(Tokens[0])) {
|
||||
auto Mask = std::atoi(Tokens[1].c_str());
|
||||
if(Mask>=48 && Mask<=128)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool IsCIDRv4(const std::string &value) {
|
||||
auto Tokens = Poco::StringTokenizer(value,"/");
|
||||
if(Tokens.count()==2 && IsIPv4(Tokens[0])) {
|
||||
auto Mask = std::atoi(Tokens[1].c_str());
|
||||
if(Mask>=0 && Mask<=32)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool IsCIDR(const std::string &value) {
|
||||
return IsCIDRv4(value) || IsCIDRv6(value);
|
||||
}
|
||||
|
||||
void ConfigurationValidator::my_format_checker(const std::string &format, const std::string &value)
|
||||
{
|
||||
static const std::regex host_regex{"^(?=.{1,254}$)((?=[a-z0-9-]{1,63}\\.)(xn--+)?[a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,63}$"};
|
||||
static const std::regex mac_regex{"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"};
|
||||
static const std::regex uc_timeout_regex{"^[0-9]+[dmshw]$"};
|
||||
static const std::regex b64_regex("^[a-zA-Z0-9\\+/]*={0,3}$");
|
||||
|
||||
if(format == "uc-cidr4") {
|
||||
if(IsCIDRv4(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid CIDR IPv4: should be something like 192.168.0.0/16.");
|
||||
} else if(format == "uc-cidr6") {
|
||||
if(IsCIDRv6(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid CIDR IPv6: should be something like 2e60:3500::/64.");
|
||||
} else if(format=="uc-cidr") {
|
||||
if(IsCIDR(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid CIDR IPv6/IPv4: should be something like 2e60:3500::/64.");
|
||||
} else if(format == "uc-mac") {
|
||||
if(std::regex_match(value,mac_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid MAC: should be something like 2e60:3500::/64.");
|
||||
} else if(format == "uc-timeout") {
|
||||
if(std::regex_match(value,uc_timeout_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a proper timeout value: 6d, 300m, 24h, 84000s, infinite");
|
||||
} else if(format == "uc-host") {
|
||||
if(IsIP(value))
|
||||
return;
|
||||
if(std::regex_match(value,host_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a proper FQDN.");
|
||||
} else if(format == "fqdn") {
|
||||
if(std::regex_match(value,host_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a proper FQDN.");
|
||||
} else if(format == "uc-base64") {
|
||||
std::string s{value};
|
||||
Poco::trimInPlace(s);
|
||||
if( (s.size() %4 ==0) && std::regex_match(s,b64_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a base64 encoded value.");
|
||||
} else if(format == "uri") {
|
||||
try {
|
||||
Poco::URI uri(value);
|
||||
return;
|
||||
} catch (...) {
|
||||
}
|
||||
throw std::invalid_argument(value + " is not a valid URI: should be something like https://hello.world.com.");
|
||||
} else if(format == "ip") {
|
||||
if (IsIP(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid IP address.");
|
||||
} else {
|
||||
try {
|
||||
nlohmann::json_schema::default_string_format_check(format,value);
|
||||
} catch (const std::logic_error &E) {
|
||||
std::string Error{"JSON Schema validation: "};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ConfigurationValidator::Validate(const std::string &C, std::string &Error) {
|
||||
bool ConfigurationValidator::Validate(const std::string &C) {
|
||||
if(Working_) {
|
||||
try {
|
||||
auto Doc = json::parse(C);
|
||||
Validator_->validate(Doc);
|
||||
return true;
|
||||
} catch(const std::exception &E) {
|
||||
Error = E.what();
|
||||
std::cout << "Validation failed, here is why: " << E.what() << "\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,9 @@
|
||||
#ifndef OWPROV_CONFIGURATIONVALIDATOR_H
|
||||
#define OWPROV_CONFIGURATIONVALIDATOR_H
|
||||
|
||||
#include <nlohmann/json-schema.hpp>
|
||||
#include "Poco/Logger.h"
|
||||
#include "framework/MicroService.h"
|
||||
#include <nlohmann/json-schema.hpp>
|
||||
|
||||
using nlohmann::json;
|
||||
using nlohmann::json_schema::json_validator;
|
||||
@@ -21,8 +22,31 @@ namespace OpenWifi {
|
||||
return instance_;
|
||||
}
|
||||
|
||||
bool Validate(const std::string &C, std::string &Error);
|
||||
static void my_format_checker(const std::string &format, const std::string &value);
|
||||
bool Validate(const std::string &C);
|
||||
static void my_format_checker(const std::string &format, const std::string &value)
|
||||
{
|
||||
/*
|
||||
"format": "uc-mac"
|
||||
"format": "uc-timeout",
|
||||
"format": "uc-cidr4",
|
||||
"format": "uc-cidr6",
|
||||
"uc-format": "cidr",
|
||||
"format": "fqdn",
|
||||
"format": "uc-host",
|
||||
"format": "uri"
|
||||
"format": "hostname"
|
||||
"format": "uc-base64"
|
||||
|
||||
|
||||
if (format == "something") {
|
||||
return;
|
||||
if (!check_value_for_something(value))
|
||||
throw std::invalid_argument("value is not a good something");
|
||||
} else
|
||||
throw std::logic_error("Don't know how to validate " + format);
|
||||
*/
|
||||
}
|
||||
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
void reinitialize(Poco::Util::Application &self) override;
|
||||
@@ -40,7 +64,7 @@ namespace OpenWifi {
|
||||
};
|
||||
|
||||
inline ConfigurationValidator * ConfigurationValidator() { return ConfigurationValidator::instance(); }
|
||||
inline bool ValidateUCentralConfiguration(const std::string &C, std::string &Error) { return ConfigurationValidator::instance()->Validate(C, Error); }
|
||||
inline bool ValidateUCentralConfiguration(const std::string &C) { return ConfigurationValidator::instance()->Validate(C); }
|
||||
}
|
||||
|
||||
#endif //OWPROV_CONFIGURATIONVALIDATOR_H
|
||||
@@ -11,9 +11,10 @@
|
||||
#include "Poco/Util/Option.h"
|
||||
#include "Poco/Environment.h"
|
||||
|
||||
#include "Daemon.h"
|
||||
#include "CentralConfig.h"
|
||||
#include "CommandManager.h"
|
||||
#include "Daemon.h"
|
||||
#include "ConfigurationValidator.h"
|
||||
#include "DeviceRegistry.h"
|
||||
#include "FileUploader.h"
|
||||
#include "OUIServer.h"
|
||||
@@ -22,12 +23,14 @@
|
||||
#include "StorageService.h"
|
||||
#include "TelemetryStream.h"
|
||||
#include "WebSocketServer.h"
|
||||
#include "framework/ConfigurationValidator.h"
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class Daemon *Daemon::instance_ = nullptr;
|
||||
|
||||
class Daemon *Daemon::instance() {
|
||||
static Daemon instance(vDAEMON_PROPERTIES_FILENAME,
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new Daemon(vDAEMON_PROPERTIES_FILENAME,
|
||||
vDAEMON_ROOT_ENV_VAR,
|
||||
vDAEMON_CONFIG_ENV_VAR,
|
||||
vDAEMON_APP_NAME,
|
||||
@@ -44,7 +47,8 @@ namespace OpenWifi {
|
||||
StorageArchiver(),
|
||||
TelemetryStream()
|
||||
});
|
||||
return &instance;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
void Daemon::initialize() {
|
||||
@@ -91,9 +95,10 @@ namespace OpenWifi {
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
|
||||
auto App = OpenWifi::Daemon::instance();
|
||||
auto ExitCode = App->run(argc, argv);
|
||||
delete App;
|
||||
|
||||
return ExitCode;
|
||||
|
||||
} catch (Poco::Exception &exc) {
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace OpenWifi {
|
||||
inline DeviceDashboard & GetDashboard() { return DB_; }
|
||||
Poco::Logger & Log() { return Poco::Logger::get(AppName()); }
|
||||
private:
|
||||
static Daemon *instance_;
|
||||
bool AutoProvisioning_ = false;
|
||||
Types::StringMapStringSet DeviceTypeIdentifications_;
|
||||
DeviceDashboard DB_;
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
#include "OUIServer.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class DeviceRegistry *DeviceRegistry::instance_ = nullptr;
|
||||
|
||||
DeviceRegistry::DeviceRegistry() noexcept:
|
||||
SubSystemServer("DeviceRegistry", "DevStatus", "devicestatus") {
|
||||
}
|
||||
|
||||
int DeviceRegistry::Start() {
|
||||
std::lock_guard Guard(Mutex_);
|
||||
@@ -92,13 +97,13 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<DeviceRegistry::ConnectionEntry> DeviceRegistry::Register(const std::string & SerialNumber, WSConnection *Ptr)
|
||||
GWObjects::ConnectionState * DeviceRegistry::Register(const std::string & SerialNumber, WSConnection *Ptr)
|
||||
{
|
||||
std::lock_guard Guard(Mutex_);
|
||||
|
||||
auto Device = Devices_.find(SerialNumber);
|
||||
if( Device == Devices_.end()) {
|
||||
auto E = Devices_[SerialNumber] = std::make_shared<ConnectionEntry>();
|
||||
auto E = std::make_unique<ConnectionEntry>();
|
||||
|
||||
E->WSConn_ = Ptr;
|
||||
E->Conn_.SerialNumber = SerialNumber;
|
||||
@@ -110,7 +115,9 @@ namespace OpenWifi {
|
||||
E->Conn_.TX = 0 ;
|
||||
E->Conn_.RX = 0;
|
||||
E->Conn_.VerifiedCertificate = GWObjects::CertificateValidation::NO_CERTIFICATE;
|
||||
return E;
|
||||
auto R=&E->Conn_;
|
||||
Devices_[SerialNumber] = std::move(E);
|
||||
return R;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -118,7 +125,7 @@ namespace OpenWifi {
|
||||
Device->second->Conn_.Connected = true;
|
||||
Device->second->Conn_.LastContact = std::time(nullptr);
|
||||
Device->second->Conn_.VerifiedCertificate = GWObjects::CertificateValidation::NO_CERTIFICATE;
|
||||
return Device->second;
|
||||
return &Device->second->Conn_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +142,15 @@ namespace OpenWifi {
|
||||
|
||||
void DeviceRegistry::UnRegister(const std::string & SerialNumber, WSConnection *Ptr) {
|
||||
std::lock_guard Guard(Mutex_);
|
||||
Devices_.erase(SerialNumber);
|
||||
|
||||
auto Device = Devices_.find(SerialNumber);
|
||||
|
||||
if( Device != Devices_.end() && Device->second->WSConn_==Ptr) {
|
||||
Device->second->Conn_.Address = "";
|
||||
Device->second->WSConn_ = nullptr;
|
||||
Device->second->Conn_.Connected = false;
|
||||
Device->second->Conn_.VerifiedCertificate = GWObjects::NO_CERTIFICATE;
|
||||
}
|
||||
}
|
||||
|
||||
bool DeviceRegistry::SendFrame(const std::string & SerialNumber, const std::string & Payload) {
|
||||
|
||||
@@ -29,7 +29,9 @@ namespace OpenWifi {
|
||||
};
|
||||
|
||||
static DeviceRegistry *instance() {
|
||||
static DeviceRegistry *instance_ = new DeviceRegistry;
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new DeviceRegistry;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
@@ -41,7 +43,7 @@ namespace OpenWifi {
|
||||
void SetState(const std::string & SerialNumber, GWObjects::ConnectionState & State);
|
||||
bool GetHealthcheck(const std::string &SerialNumber, GWObjects::HealthCheck & CheckData);
|
||||
void SetHealthcheck(const std::string &SerialNumber, const GWObjects::HealthCheck &H);
|
||||
std::shared_ptr<ConnectionEntry> Register(const std::string & SerialNumber, WSConnection *);
|
||||
GWObjects::ConnectionState * Register(const std::string & SerialNumber, WSConnection *);
|
||||
void UnRegister(const std::string & SerialNumber, WSConnection *);
|
||||
bool SendCommand(GWObjects::CommandDetails & Command);
|
||||
bool Connected(const std::string & SerialNumber);
|
||||
@@ -51,11 +53,10 @@ namespace OpenWifi {
|
||||
bool AnalyzeRegistry(GWObjects::Dashboard &D);
|
||||
|
||||
private:
|
||||
std::map<std::string,std::shared_ptr<ConnectionEntry>> Devices_;
|
||||
static DeviceRegistry *instance_;
|
||||
std::map<std::string,std::unique_ptr<ConnectionEntry>> Devices_;
|
||||
|
||||
DeviceRegistry() noexcept:
|
||||
SubSystemServer("DeviceRegistry", "DevStatus", "devicestatus") {
|
||||
}
|
||||
DeviceRegistry() noexcept;
|
||||
};
|
||||
|
||||
inline DeviceRegistry * DeviceRegistry() { return DeviceRegistry::instance(); }
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class FileUploader *FileUploader::instance_ = nullptr;
|
||||
|
||||
static const std::string URI_BASE{"/v1/upload/"};
|
||||
|
||||
|
||||
@@ -30,13 +30,16 @@ namespace OpenWifi {
|
||||
const std::string & Path() { return Path_; };
|
||||
|
||||
static FileUploader *instance() {
|
||||
static FileUploader * instance_ = new FileUploader;
|
||||
return instance_;
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new FileUploader;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline uint64_t MaxSize() const { return MaxSize_; }
|
||||
|
||||
private:
|
||||
static FileUploader *instance_;
|
||||
std::vector<std::unique_ptr<Poco::Net::HTTPServer>> Servers_;
|
||||
Poco::ThreadPool Pool_;
|
||||
std::string FullName_;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class OUIServer * OUIServer::instance_;
|
||||
|
||||
int OUIServer::Start() {
|
||||
Running_=true;
|
||||
|
||||
@@ -15,7 +15,9 @@ namespace OpenWifi {
|
||||
typedef std::map<uint64_t,std::string> OUIMap;
|
||||
|
||||
static OUIServer *instance() {
|
||||
static OUIServer *instance_ = new OUIServer;
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new OUIServer;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
@@ -31,6 +33,7 @@ namespace OpenWifi {
|
||||
[[nodiscard]] bool ProcessFile(const std::string &FileName, OUIMap &Map);
|
||||
|
||||
private:
|
||||
static OUIServer * instance_;
|
||||
uint64_t LastUpdate_ = 0 ;
|
||||
bool ValidFile_=false;
|
||||
OUIMap OUIs_;
|
||||
|
||||
@@ -204,7 +204,7 @@ void RESTAPI_device_commandHandler::Configure() {
|
||||
GWObjects::CommandDetails Cmd;
|
||||
|
||||
Cmd.SerialNumber = SerialNumber_;
|
||||
Cmd.UUID = MicroService::CreateUUID();
|
||||
Cmd.UUID = MicroService::instance().CreateUUID();
|
||||
Cmd.SubmittedBy = UserInfo_.webtoken.username_;
|
||||
Cmd.Command = uCentralProtocol::CONFIGURE;
|
||||
Cmd.RunAt = When;
|
||||
@@ -246,7 +246,7 @@ void RESTAPI_device_commandHandler::Upgrade() {
|
||||
GWObjects::CommandDetails Cmd;
|
||||
|
||||
Cmd.SerialNumber = SerialNumber_;
|
||||
Cmd.UUID = MicroService::CreateUUID();
|
||||
Cmd.UUID = MicroService::instance().CreateUUID();
|
||||
Cmd.SubmittedBy = UserInfo_.webtoken.username_;
|
||||
Cmd.Command = uCentralProtocol::UPGRADE;
|
||||
Cmd.RunAt = When;
|
||||
@@ -357,7 +357,7 @@ void RESTAPI_device_commandHandler::ExecuteCommand() {
|
||||
GWObjects::CommandDetails Cmd;
|
||||
|
||||
Cmd.SerialNumber = SerialNumber_;
|
||||
Cmd.UUID = MicroService::CreateUUID();
|
||||
Cmd.UUID = MicroService::instance().CreateUUID();
|
||||
Cmd.SubmittedBy = UserInfo_.webtoken.username_;
|
||||
Cmd.Command = Command;
|
||||
Cmd.Custom = 1;
|
||||
@@ -397,7 +397,7 @@ void RESTAPI_device_commandHandler::Reboot() {
|
||||
uint64_t When = GetWhen(Obj);
|
||||
GWObjects::CommandDetails Cmd;
|
||||
Cmd.SerialNumber = SerialNumber_;
|
||||
Cmd.UUID = MicroService::CreateUUID();
|
||||
Cmd.UUID = MicroService::instance().CreateUUID();
|
||||
Cmd.SubmittedBy = UserInfo_.webtoken.username_;
|
||||
Cmd.Command = uCentralProtocol::REBOOT;
|
||||
Cmd.RunAt = When;
|
||||
@@ -434,7 +434,7 @@ void RESTAPI_device_commandHandler::Factory() {
|
||||
GWObjects::CommandDetails Cmd;
|
||||
|
||||
Cmd.SerialNumber = SerialNumber_;
|
||||
Cmd.UUID = MicroService::CreateUUID();
|
||||
Cmd.UUID = MicroService::instance().CreateUUID();
|
||||
Cmd.SubmittedBy = UserInfo_.webtoken.username_;
|
||||
Cmd.Command = uCentralProtocol::FACTORY;
|
||||
Cmd.RunAt = When;
|
||||
@@ -480,7 +480,7 @@ void RESTAPI_device_commandHandler::LEDs() {
|
||||
GWObjects::CommandDetails Cmd;
|
||||
|
||||
Cmd.SerialNumber = SerialNumber_;
|
||||
Cmd.UUID = MicroService::CreateUUID();
|
||||
Cmd.UUID = MicroService::instance().CreateUUID();
|
||||
Cmd.SubmittedBy = UserInfo_.webtoken.username_;
|
||||
Cmd.Command = uCentralProtocol::LEDS;
|
||||
Cmd.RunAt = When;
|
||||
@@ -519,7 +519,7 @@ void RESTAPI_device_commandHandler::Trace() {
|
||||
|
||||
auto Network = GetS(RESTAPI::Protocol::NETWORK, Obj);
|
||||
auto Interface = GetS(RESTAPI::Protocol::INTERFACE, Obj);
|
||||
auto UUID = MicroService::CreateUUID();
|
||||
auto UUID = MicroService::instance().CreateUUID();
|
||||
auto URI = FileUploader()->FullName() + UUID;
|
||||
|
||||
GWObjects::CommandDetails Cmd;
|
||||
@@ -567,7 +567,7 @@ void RESTAPI_device_commandHandler::WifiScan() {
|
||||
(!Obj->has(RESTAPI::Protocol::BANDS) &&
|
||||
!Obj->has(RESTAPI::Protocol::CHANNELS)))) {
|
||||
bool Verbose = GetB(RESTAPI::Protocol::VERBOSE, Obj);
|
||||
auto UUID = MicroService::CreateUUID();
|
||||
auto UUID = MicroService::instance().CreateUUID();
|
||||
GWObjects::CommandDetails Cmd;
|
||||
|
||||
Cmd.SerialNumber = SerialNumber_;
|
||||
@@ -618,7 +618,7 @@ void RESTAPI_device_commandHandler::EventQueue() {
|
||||
|
||||
auto Types = Obj->getArray(RESTAPI::Protocol::TYPES);
|
||||
|
||||
auto UUID = MicroService::CreateUUID();
|
||||
auto UUID = MicroService::instance().CreateUUID();
|
||||
GWObjects::CommandDetails Cmd;
|
||||
|
||||
Cmd.SerialNumber = SerialNumber_;
|
||||
@@ -664,7 +664,7 @@ void RESTAPI_device_commandHandler::MakeRequest() {
|
||||
|
||||
Cmd.SerialNumber = SerialNumber_;
|
||||
Cmd.SubmittedBy = UserInfo_.webtoken.username_;
|
||||
Cmd.UUID = MicroService::CreateUUID();
|
||||
Cmd.UUID = MicroService::instance().CreateUUID();
|
||||
Cmd.Command = uCentralProtocol::REQUEST;
|
||||
Cmd.RunAt = When;
|
||||
|
||||
@@ -689,7 +689,7 @@ void RESTAPI_device_commandHandler::MakeRequest() {
|
||||
if (MicroService::instance().ConfigGetString("rtty.enabled", "false") == "true") {
|
||||
GWObjects::Device Device;
|
||||
if (StorageService()->GetDevice(SerialNumber_, Device)) {
|
||||
auto CommandUUID = MicroService::CreateUUID();
|
||||
auto CommandUUID = MicroService::instance().CreateUUID();
|
||||
|
||||
GWObjects::RttySessionDetails Rtty{
|
||||
.SerialNumber = SerialNumber_,
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
#include "RESTAPI_device_handler.h"
|
||||
#include "CentralConfig.h"
|
||||
#include "ConfigurationCache.h"
|
||||
#include "ConfigurationValidator.h"
|
||||
#include "Poco/JSON/Parser.h"
|
||||
#include "StorageService.h"
|
||||
#include "framework/ConfigurationValidator.h"
|
||||
#include "framework/MicroService.h"
|
||||
#include "framework/RESTAPI_errors.h"
|
||||
#include "framework/RESTAPI_protocol.h"
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
void RESTAPI_device_handler::DoGet() {
|
||||
@@ -41,40 +41,9 @@ namespace OpenWifi {
|
||||
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
|
||||
}
|
||||
|
||||
std::string Arg;
|
||||
if(HasParameter("oui",Arg) && Arg=="true" && SerialNumber.size()==6) {
|
||||
|
||||
std::set<std::string> Set;
|
||||
std::vector<GWObjects::Device> Devices;
|
||||
|
||||
bool Done = false;
|
||||
uint64_t Offset=1;
|
||||
while(!Done) {
|
||||
|
||||
StorageService()->GetDevices(Offset,500,Devices);
|
||||
for(const auto &i:Devices) {
|
||||
if(i.SerialNumber.substr(0,6) == SerialNumber) {
|
||||
Set.insert(i.SerialNumber);
|
||||
}
|
||||
}
|
||||
|
||||
if(Devices.size()<500)
|
||||
Done=true;
|
||||
|
||||
Offset += Devices.size();
|
||||
}
|
||||
|
||||
for(auto &i:Set) {
|
||||
std::string SNum{i};
|
||||
StorageService()->DeleteDevice(SNum);
|
||||
}
|
||||
|
||||
return OK();
|
||||
|
||||
} else if (StorageService()->DeleteDevice(SerialNumber)) {
|
||||
if (StorageService()->DeleteDevice(SerialNumber)) {
|
||||
return OK();
|
||||
}
|
||||
|
||||
NotFound();
|
||||
}
|
||||
|
||||
@@ -93,11 +62,8 @@ namespace OpenWifi {
|
||||
}
|
||||
auto Config=Body->get("configuration").toString();
|
||||
Poco::JSON::Object Answer;
|
||||
std::string Error;
|
||||
auto Res = ValidateUCentralConfiguration(Config, Error);
|
||||
auto Res = ValidateUCentralConfiguration(Config);
|
||||
Answer.set("valid",Res);
|
||||
if(!Error.empty())
|
||||
Answer.set("error",Error);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
|
||||
@@ -116,8 +82,7 @@ namespace OpenWifi {
|
||||
return BadRequest(RESTAPI::Errors::SerialNumberMismatch);
|
||||
}
|
||||
|
||||
std::string Error;
|
||||
if(Device.Configuration.empty() || (!Device.Configuration.empty() && !ValidateUCentralConfiguration(Device.Configuration,Error))) {
|
||||
if(Device.Configuration.empty() || (!Device.Configuration.empty() && !ValidateUCentralConfiguration(Device.Configuration))) {
|
||||
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
|
||||
}
|
||||
|
||||
@@ -159,8 +124,7 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
if(!NewDevice.Configuration.empty()) {
|
||||
std::string Error;
|
||||
if (!ValidateUCentralConfiguration(NewDevice.Configuration, Error)) {
|
||||
if (!ValidateUCentralConfiguration(NewDevice.Configuration)) {
|
||||
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
|
||||
}
|
||||
Config::Config NewConfig(NewDevice.Configuration);
|
||||
|
||||
@@ -46,8 +46,7 @@ namespace OpenWifi {
|
||||
if(!Authenticated) {
|
||||
std::string Frame{IncomingFrame.begin()};
|
||||
auto Tokens = Utils::Split(Frame,':');
|
||||
bool Expired=false;
|
||||
if(Tokens.size()==2 && AuthClient()->IsAuthorized(Tokens[1], UserInfo_, Expired)) {
|
||||
if(Tokens.size()==2 && AuthClient()->IsTokenAuthorized(Tokens[1], UserInfo_)) {
|
||||
Authenticated=true;
|
||||
std::string S{"Welcome! Bienvenue! Bienvenidos!"};
|
||||
WS.sendFrame(S.c_str(),S.size());
|
||||
@@ -75,12 +74,6 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
|
||||
Logger_.warning(Poco::format("CLOSE(%s): Client is closing its WS connection.", UserInfo_.userinfo.email));
|
||||
Done=true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace OpenWifi::GWObjects {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Device::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
bool Device::from_json(Poco::JSON::Object::Ptr Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"serialNumber",SerialNumber);
|
||||
field_from_json(Obj,"deviceType",DeviceType);
|
||||
@@ -147,7 +147,7 @@ namespace OpenWifi::GWObjects {
|
||||
field_to_json(Obj,"attachFile", AttachDate);
|
||||
}
|
||||
|
||||
bool DefaultConfiguration::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
bool DefaultConfiguration::from_json(Poco::JSON::Object::Ptr Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"name",Name);
|
||||
field_from_json(Obj,"configuration",Configuration);
|
||||
@@ -166,7 +166,7 @@ namespace OpenWifi::GWObjects {
|
||||
field_to_json(Obj,"created", created);
|
||||
}
|
||||
|
||||
bool BlackListedDevice::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
bool BlackListedDevice::from_json(Poco::JSON::Object::Ptr Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"serialNumber",serialNumber);
|
||||
field_from_json(Obj,"author",author);
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace OpenWifi::GWObjects {
|
||||
std::string DevicePassword;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
void to_json_with_status(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
bool from_json(Poco::JSON::Object::Ptr Obj);
|
||||
void Print() const;
|
||||
};
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace OpenWifi::GWObjects {
|
||||
uint64_t Created;
|
||||
uint64_t LastModified;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
bool from_json(Poco::JSON::Object::Ptr Obj);
|
||||
};
|
||||
|
||||
struct CommandDetails {
|
||||
@@ -147,7 +147,7 @@ namespace OpenWifi::GWObjects {
|
||||
std::string author;
|
||||
uint64_t created;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
bool from_json(Poco::JSON::Object::Ptr Obj);
|
||||
};
|
||||
|
||||
struct RttySessionDetails {
|
||||
|
||||
@@ -10,30 +10,27 @@
|
||||
#include "RESTAPI_ProvObjects.h"
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
using OpenWifi::RESTAPI_utils::field_to_json;
|
||||
using OpenWifi::RESTAPI_utils::field_from_json;
|
||||
|
||||
namespace OpenWifi::ProvObjects {
|
||||
|
||||
void ObjectInfo::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"id",id);
|
||||
field_to_json(Obj,"name",name);
|
||||
field_to_json(Obj,"description",description);
|
||||
field_to_json(Obj,"created",created);
|
||||
field_to_json(Obj,"modified",modified);
|
||||
field_to_json(Obj,"notes",notes);
|
||||
field_to_json(Obj,"tags",tags);
|
||||
RESTAPI_utils::field_to_json(Obj,"id",id);
|
||||
RESTAPI_utils::field_to_json(Obj,"name",name);
|
||||
RESTAPI_utils::field_to_json(Obj,"description",description);
|
||||
RESTAPI_utils::field_to_json(Obj,"created",created);
|
||||
RESTAPI_utils::field_to_json(Obj,"modified",modified);
|
||||
RESTAPI_utils::field_to_json(Obj,"notes",notes);
|
||||
RESTAPI_utils::field_to_json(Obj,"tags",tags);
|
||||
}
|
||||
|
||||
bool ObjectInfo::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"id",id);
|
||||
field_from_json(Obj,"name",name);
|
||||
field_from_json(Obj,"description",description);
|
||||
field_from_json(Obj,"created",created);
|
||||
field_from_json(Obj,"modified",modified);
|
||||
field_from_json(Obj,"notes",notes);
|
||||
field_from_json(Obj,"tags",tags);
|
||||
RESTAPI_utils::field_from_json(Obj,"id",id);
|
||||
RESTAPI_utils::field_from_json(Obj,"name",name);
|
||||
RESTAPI_utils::field_from_json(Obj,"description",description);
|
||||
RESTAPI_utils::field_from_json(Obj,"created",created);
|
||||
RESTAPI_utils::field_from_json(Obj,"modified",modified);
|
||||
RESTAPI_utils::field_from_json(Obj,"notes",notes);
|
||||
RESTAPI_utils::field_from_json(Obj,"tags",tags);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
@@ -42,18 +39,18 @@ namespace OpenWifi::ProvObjects {
|
||||
}
|
||||
|
||||
void ManagementPolicyEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json( Obj,"users",users);
|
||||
field_to_json( Obj,"resources",resources);
|
||||
field_to_json( Obj,"access",access);
|
||||
field_to_json( Obj,"policy",policy);
|
||||
RESTAPI_utils::field_to_json( Obj,"users",users);
|
||||
RESTAPI_utils::field_to_json( Obj,"resources",resources);
|
||||
RESTAPI_utils::field_to_json( Obj,"access",access);
|
||||
RESTAPI_utils::field_to_json( Obj,"policy",policy);
|
||||
}
|
||||
|
||||
bool ManagementPolicyEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json( Obj,"users",users);
|
||||
field_from_json( Obj,"resources",resources);
|
||||
field_from_json( Obj,"access",access);
|
||||
field_from_json( Obj,"policy",policy);
|
||||
RESTAPI_utils::field_from_json( Obj,"users",users);
|
||||
RESTAPI_utils::field_from_json( Obj,"resources",resources);
|
||||
RESTAPI_utils::field_from_json( Obj,"access",access);
|
||||
RESTAPI_utils::field_from_json( Obj,"policy",policy);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
@@ -63,17 +60,17 @@ namespace OpenWifi::ProvObjects {
|
||||
|
||||
void ManagementPolicy::to_json(Poco::JSON::Object &Obj) const {
|
||||
info.to_json(Obj);
|
||||
field_to_json(Obj, "entries", entries);
|
||||
field_to_json(Obj, "inUse", inUse);
|
||||
field_to_json(Obj, "entity", entity);
|
||||
RESTAPI_utils::field_to_json(Obj, "entries", entries);
|
||||
RESTAPI_utils::field_to_json(Obj, "inUse", inUse);
|
||||
RESTAPI_utils::field_to_json(Obj, "entity", entity);
|
||||
}
|
||||
|
||||
bool ManagementPolicy::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
info.from_json(Obj);
|
||||
field_from_json(Obj, "entries", entries);
|
||||
field_from_json(Obj, "inUse", inUse);
|
||||
field_from_json(Obj, "entity", entity);
|
||||
RESTAPI_utils::field_from_json(Obj, "entries", entries);
|
||||
RESTAPI_utils::field_from_json(Obj, "inUse", inUse);
|
||||
RESTAPI_utils::field_from_json(Obj, "entity", entity);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
@@ -83,31 +80,31 @@ namespace OpenWifi::ProvObjects {
|
||||
|
||||
void Entity::to_json(Poco::JSON::Object &Obj) const {
|
||||
info.to_json(Obj);
|
||||
field_to_json( Obj,"parent",parent);
|
||||
field_to_json( Obj,"venues",venues);
|
||||
field_to_json( Obj,"children",children);
|
||||
field_to_json( Obj,"contacts",contacts);
|
||||
field_to_json( Obj,"locations",locations);
|
||||
field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
field_to_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
field_to_json( Obj,"devices",devices);
|
||||
field_to_json( Obj,"rrm",rrm);
|
||||
field_to_json( Obj,"sourceIP",sourceIP);
|
||||
RESTAPI_utils::field_to_json( Obj,"parent",parent);
|
||||
RESTAPI_utils::field_to_json( Obj,"venues",venues);
|
||||
RESTAPI_utils::field_to_json( Obj,"children",children);
|
||||
RESTAPI_utils::field_to_json( Obj,"contacts",contacts);
|
||||
RESTAPI_utils::field_to_json( Obj,"locations",locations);
|
||||
RESTAPI_utils::field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_to_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
RESTAPI_utils::field_to_json( Obj,"devices",devices);
|
||||
RESTAPI_utils::field_to_json( Obj,"rrm",rrm);
|
||||
RESTAPI_utils::field_to_json( Obj,"sourceIP",sourceIP);
|
||||
}
|
||||
|
||||
bool Entity::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
info.from_json(Obj);
|
||||
field_from_json( Obj,"parent",parent);
|
||||
field_from_json( Obj,"venues",venues);
|
||||
field_from_json( Obj,"children",children);
|
||||
field_from_json( Obj,"contacts",contacts);
|
||||
field_from_json( Obj,"locations",locations);
|
||||
field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
field_from_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
field_from_json( Obj,"devices",devices);
|
||||
field_from_json( Obj,"rrm",rrm);
|
||||
field_from_json( Obj,"sourceIP",sourceIP);
|
||||
RESTAPI_utils::field_from_json( Obj,"parent",parent);
|
||||
RESTAPI_utils::field_from_json( Obj,"venues",venues);
|
||||
RESTAPI_utils::field_from_json( Obj,"children",children);
|
||||
RESTAPI_utils::field_from_json( Obj,"contacts",contacts);
|
||||
RESTAPI_utils::field_from_json( Obj,"locations",locations);
|
||||
RESTAPI_utils::field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_from_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
RESTAPI_utils::field_from_json( Obj,"devices",devices);
|
||||
RESTAPI_utils::field_from_json( Obj,"rrm",rrm);
|
||||
RESTAPI_utils::field_from_json( Obj,"sourceIP",sourceIP);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
@@ -116,14 +113,14 @@ namespace OpenWifi::ProvObjects {
|
||||
}
|
||||
|
||||
void DiGraphEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json( Obj,"parent",parent);
|
||||
field_to_json( Obj,"child",child);
|
||||
RESTAPI_utils::field_to_json( Obj,"parent",parent);
|
||||
RESTAPI_utils::field_to_json( Obj,"child",child);
|
||||
}
|
||||
|
||||
bool DiGraphEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json( Obj,"parent",parent);
|
||||
field_from_json( Obj,"child",child);
|
||||
RESTAPI_utils::field_from_json( Obj,"parent",parent);
|
||||
RESTAPI_utils::field_from_json( Obj,"child",child);
|
||||
return true;
|
||||
} catch (...) {
|
||||
|
||||
@@ -133,37 +130,37 @@ namespace OpenWifi::ProvObjects {
|
||||
|
||||
void Venue::to_json(Poco::JSON::Object &Obj) const {
|
||||
info.to_json(Obj);
|
||||
field_to_json( Obj,"parent",parent);
|
||||
field_to_json( Obj,"entity",entity);
|
||||
field_to_json( Obj,"children",children);
|
||||
field_to_json( Obj,"devices",devices);
|
||||
field_to_json( Obj,"topology",topology);
|
||||
field_to_json( Obj,"parent",parent);
|
||||
field_to_json( Obj,"design",design);
|
||||
field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
field_to_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
field_to_json( Obj,"contact",contact);
|
||||
field_to_json( Obj,"location",location);
|
||||
field_to_json( Obj,"rrm",rrm);
|
||||
field_to_json( Obj,"sourceIP",sourceIP);
|
||||
RESTAPI_utils::field_to_json( Obj,"parent",parent);
|
||||
RESTAPI_utils::field_to_json( Obj,"entity",entity);
|
||||
RESTAPI_utils::field_to_json( Obj,"children",children);
|
||||
RESTAPI_utils::field_to_json( Obj,"devices",devices);
|
||||
RESTAPI_utils::field_to_json( Obj,"topology",topology);
|
||||
RESTAPI_utils::field_to_json( Obj,"parent",parent);
|
||||
RESTAPI_utils::field_to_json( Obj,"design",design);
|
||||
RESTAPI_utils::field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_to_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
RESTAPI_utils::field_to_json( Obj,"contact",contact);
|
||||
RESTAPI_utils::field_to_json( Obj,"location",location);
|
||||
RESTAPI_utils::field_to_json( Obj,"rrm",rrm);
|
||||
RESTAPI_utils::field_to_json( Obj,"sourceIP",sourceIP);
|
||||
}
|
||||
|
||||
bool Venue::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
info.from_json(Obj);
|
||||
field_from_json( Obj,"parent",parent);
|
||||
field_from_json( Obj,"entity",entity);
|
||||
field_from_json( Obj,"children",children);
|
||||
field_from_json( Obj,"devices",devices);
|
||||
field_from_json( Obj,"topology",topology);
|
||||
field_from_json( Obj,"parent",parent);
|
||||
field_from_json( Obj,"design",design);
|
||||
field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
field_from_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
field_from_json( Obj,"contact",contact);
|
||||
field_from_json( Obj,"location",location);
|
||||
field_from_json( Obj,"rrm",rrm);
|
||||
field_from_json( Obj,"sourceIP",sourceIP);
|
||||
RESTAPI_utils::field_from_json( Obj,"parent",parent);
|
||||
RESTAPI_utils::field_from_json( Obj,"entity",entity);
|
||||
RESTAPI_utils::field_from_json( Obj,"children",children);
|
||||
RESTAPI_utils::field_from_json( Obj,"devices",devices);
|
||||
RESTAPI_utils::field_from_json( Obj,"topology",topology);
|
||||
RESTAPI_utils::field_from_json( Obj,"parent",parent);
|
||||
RESTAPI_utils::field_from_json( Obj,"design",design);
|
||||
RESTAPI_utils::field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_from_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
RESTAPI_utils::field_from_json( Obj,"contact",contact);
|
||||
RESTAPI_utils::field_from_json( Obj,"location",location);
|
||||
RESTAPI_utils::field_from_json( Obj,"rrm",rrm);
|
||||
RESTAPI_utils::field_from_json( Obj,"sourceIP",sourceIP);
|
||||
return true;
|
||||
} catch (...) {
|
||||
|
||||
@@ -172,16 +169,16 @@ namespace OpenWifi::ProvObjects {
|
||||
}
|
||||
|
||||
void UserInfoDigest::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json( Obj,"id",id);
|
||||
field_to_json( Obj,"entity",loginId);
|
||||
field_to_json( Obj,"children",userType);
|
||||
RESTAPI_utils::field_to_json( Obj,"id",id);
|
||||
RESTAPI_utils::field_to_json( Obj,"entity",loginId);
|
||||
RESTAPI_utils::field_to_json( Obj,"children",userType);
|
||||
}
|
||||
|
||||
bool UserInfoDigest::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json( Obj,"id",id);
|
||||
field_from_json( Obj,"entity",loginId);
|
||||
field_from_json( Obj,"children",userType);
|
||||
RESTAPI_utils::field_from_json( Obj,"id",id);
|
||||
RESTAPI_utils::field_from_json( Obj,"entity",loginId);
|
||||
RESTAPI_utils::field_from_json( Obj,"children",userType);
|
||||
return true;
|
||||
} catch(...) {
|
||||
}
|
||||
@@ -190,17 +187,17 @@ namespace OpenWifi::ProvObjects {
|
||||
|
||||
void ManagementRole::to_json(Poco::JSON::Object &Obj) const {
|
||||
info.to_json(Obj);
|
||||
field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
field_to_json( Obj,"users",users);
|
||||
field_to_json( Obj,"entity",entity);
|
||||
RESTAPI_utils::field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_to_json( Obj,"users",users);
|
||||
RESTAPI_utils::field_to_json( Obj,"entity",entity);
|
||||
}
|
||||
|
||||
bool ManagementRole::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
info.from_json(Obj);
|
||||
field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
field_from_json( Obj,"users",users);
|
||||
field_from_json( Obj,"entity",entity);
|
||||
RESTAPI_utils::field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_from_json( Obj,"users",users);
|
||||
RESTAPI_utils::field_from_json( Obj,"entity",entity);
|
||||
return true;
|
||||
} catch(...) {
|
||||
}
|
||||
@@ -209,39 +206,39 @@ namespace OpenWifi::ProvObjects {
|
||||
|
||||
void Location::to_json(Poco::JSON::Object &Obj) const {
|
||||
info.to_json(Obj);
|
||||
field_to_json( Obj,"type",OpenWifi::ProvObjects::to_string(type));
|
||||
field_to_json( Obj,"buildingName",buildingName);
|
||||
field_to_json( Obj,"addressLines",addressLines);
|
||||
field_to_json( Obj,"city",city);
|
||||
field_to_json( Obj,"state",state);
|
||||
field_to_json( Obj,"postal",postal);
|
||||
field_to_json( Obj,"country",country);
|
||||
field_to_json( Obj,"phones",phones);
|
||||
field_to_json( Obj,"mobiles",mobiles);
|
||||
field_to_json( Obj,"geoCode",geoCode);
|
||||
field_to_json( Obj,"inUse",inUse);
|
||||
field_to_json( Obj,"entity",entity);
|
||||
field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_to_json( Obj,"type",OpenWifi::ProvObjects::to_string(type));
|
||||
RESTAPI_utils::field_to_json( Obj,"buildingName",buildingName);
|
||||
RESTAPI_utils::field_to_json( Obj,"addressLines",addressLines);
|
||||
RESTAPI_utils::field_to_json( Obj,"city",city);
|
||||
RESTAPI_utils::field_to_json( Obj,"state",state);
|
||||
RESTAPI_utils::field_to_json( Obj,"postal",postal);
|
||||
RESTAPI_utils::field_to_json( Obj,"country",country);
|
||||
RESTAPI_utils::field_to_json( Obj,"phones",phones);
|
||||
RESTAPI_utils::field_to_json( Obj,"mobiles",mobiles);
|
||||
RESTAPI_utils::field_to_json( Obj,"geoCode",geoCode);
|
||||
RESTAPI_utils::field_to_json( Obj,"inUse",inUse);
|
||||
RESTAPI_utils::field_to_json( Obj,"entity",entity);
|
||||
RESTAPI_utils::field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
}
|
||||
|
||||
bool Location::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
info.from_json(Obj);
|
||||
std::string tmp_type;
|
||||
field_from_json( Obj,"type", tmp_type);
|
||||
RESTAPI_utils::field_from_json( Obj,"type", tmp_type);
|
||||
type = location_from_string(tmp_type);
|
||||
field_from_json( Obj,"buildingName",buildingName);
|
||||
field_from_json( Obj,"addressLines",addressLines);
|
||||
field_from_json( Obj,"city",city);
|
||||
field_from_json( Obj,"state",state);
|
||||
field_from_json( Obj,"postal",postal);
|
||||
field_from_json( Obj,"country",country);
|
||||
field_from_json( Obj,"phones",phones);
|
||||
field_from_json( Obj,"mobiles",mobiles);
|
||||
field_from_json( Obj,"geoCode",geoCode);
|
||||
field_from_json( Obj,"inUse",inUse);
|
||||
field_from_json( Obj,"entity",entity);
|
||||
field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_from_json( Obj,"buildingName",buildingName);
|
||||
RESTAPI_utils::field_from_json( Obj,"addressLines",addressLines);
|
||||
RESTAPI_utils::field_from_json( Obj,"city",city);
|
||||
RESTAPI_utils::field_from_json( Obj,"state",state);
|
||||
RESTAPI_utils::field_from_json( Obj,"postal",postal);
|
||||
RESTAPI_utils::field_from_json( Obj,"country",country);
|
||||
RESTAPI_utils::field_from_json( Obj,"phones",phones);
|
||||
RESTAPI_utils::field_from_json( Obj,"mobiles",mobiles);
|
||||
RESTAPI_utils::field_from_json( Obj,"geoCode",geoCode);
|
||||
RESTAPI_utils::field_from_json( Obj,"inUse",inUse);
|
||||
RESTAPI_utils::field_from_json( Obj,"entity",entity);
|
||||
RESTAPI_utils::field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
return true;
|
||||
} catch (...) {
|
||||
|
||||
@@ -251,43 +248,43 @@ namespace OpenWifi::ProvObjects {
|
||||
|
||||
void Contact::to_json(Poco::JSON::Object &Obj) const {
|
||||
info.to_json(Obj);
|
||||
field_to_json( Obj,"type", to_string(type));
|
||||
field_to_json( Obj,"title",title);
|
||||
field_to_json( Obj,"salutation",salutation);
|
||||
field_to_json( Obj,"firstname",firstname);
|
||||
field_to_json( Obj,"lastname",lastname);
|
||||
field_to_json( Obj,"initials",initials);
|
||||
field_to_json( Obj,"visual",visual);
|
||||
field_to_json( Obj,"mobiles",mobiles);
|
||||
field_to_json( Obj,"phones",phones);
|
||||
field_to_json( Obj,"primaryEmail",primaryEmail);
|
||||
field_to_json( Obj,"secondaryEmail",secondaryEmail);
|
||||
field_to_json( Obj,"accessPIN",accessPIN);
|
||||
field_to_json( Obj,"inUse",inUse);
|
||||
field_to_json( Obj,"entity",entity);
|
||||
field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_to_json( Obj,"type", to_string(type));
|
||||
RESTAPI_utils::field_to_json( Obj,"title",title);
|
||||
RESTAPI_utils::field_to_json( Obj,"salutation",salutation);
|
||||
RESTAPI_utils::field_to_json( Obj,"firstname",firstname);
|
||||
RESTAPI_utils::field_to_json( Obj,"lastname",lastname);
|
||||
RESTAPI_utils::field_to_json( Obj,"initials",initials);
|
||||
RESTAPI_utils::field_to_json( Obj,"visual",visual);
|
||||
RESTAPI_utils::field_to_json( Obj,"mobiles",mobiles);
|
||||
RESTAPI_utils::field_to_json( Obj,"phones",phones);
|
||||
RESTAPI_utils::field_to_json( Obj,"primaryEmail",primaryEmail);
|
||||
RESTAPI_utils::field_to_json( Obj,"secondaryEmail",secondaryEmail);
|
||||
RESTAPI_utils::field_to_json( Obj,"accessPIN",accessPIN);
|
||||
RESTAPI_utils::field_to_json( Obj,"inUse",inUse);
|
||||
RESTAPI_utils::field_to_json( Obj,"entity",entity);
|
||||
RESTAPI_utils::field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
}
|
||||
|
||||
bool Contact::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
info.from_json(Obj);
|
||||
std::string tmp_type;
|
||||
field_from_json( Obj,"type", tmp_type);
|
||||
RESTAPI_utils::field_from_json( Obj,"type", tmp_type);
|
||||
type = contact_from_string(tmp_type);
|
||||
field_from_json( Obj,"title",title);
|
||||
field_from_json( Obj,"salutation",salutation);
|
||||
field_from_json( Obj,"firstname",firstname);
|
||||
field_from_json( Obj,"lastname",lastname);
|
||||
field_from_json( Obj,"initials",initials);
|
||||
field_from_json( Obj,"visual",visual);
|
||||
field_from_json( Obj,"mobiles",mobiles);
|
||||
field_from_json( Obj,"phones",phones);
|
||||
field_from_json( Obj,"primaryEmail",primaryEmail);
|
||||
field_from_json( Obj,"secondaryEmail",secondaryEmail);
|
||||
field_from_json( Obj,"accessPIN",accessPIN);
|
||||
field_from_json( Obj,"inUse",inUse);
|
||||
field_from_json( Obj,"entity",entity);
|
||||
field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_from_json( Obj,"title",title);
|
||||
RESTAPI_utils::field_from_json( Obj,"salutation",salutation);
|
||||
RESTAPI_utils::field_from_json( Obj,"firstname",firstname);
|
||||
RESTAPI_utils::field_from_json( Obj,"lastname",lastname);
|
||||
RESTAPI_utils::field_from_json( Obj,"initials",initials);
|
||||
RESTAPI_utils::field_from_json( Obj,"visual",visual);
|
||||
RESTAPI_utils::field_from_json( Obj,"mobiles",mobiles);
|
||||
RESTAPI_utils::field_from_json( Obj,"phones",phones);
|
||||
RESTAPI_utils::field_from_json( Obj,"primaryEmail",primaryEmail);
|
||||
RESTAPI_utils::field_from_json( Obj,"secondaryEmail",secondaryEmail);
|
||||
RESTAPI_utils::field_from_json( Obj,"accessPIN",accessPIN);
|
||||
RESTAPI_utils::field_from_json( Obj,"inUse",inUse);
|
||||
RESTAPI_utils::field_from_json( Obj,"entity",entity);
|
||||
RESTAPI_utils::field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
return true;
|
||||
} catch (...) {
|
||||
|
||||
@@ -297,35 +294,35 @@ namespace OpenWifi::ProvObjects {
|
||||
|
||||
void InventoryTag::to_json(Poco::JSON::Object &Obj) const {
|
||||
info.to_json(Obj);
|
||||
field_to_json(Obj, "serialNumber", serialNumber);
|
||||
field_to_json(Obj, "venue", venue);
|
||||
field_to_json(Obj, "entity", entity);
|
||||
field_to_json(Obj, "subscriber", subscriber);
|
||||
field_to_json(Obj, "deviceType", deviceType);
|
||||
field_to_json(Obj, "qrCode", qrCode);
|
||||
field_to_json(Obj, "geoCode", geoCode);
|
||||
field_to_json(Obj, "location", location);
|
||||
field_to_json(Obj, "contact", contact);
|
||||
field_to_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
field_to_json( Obj,"rrm",rrm);
|
||||
field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_to_json(Obj, "serialNumber", serialNumber);
|
||||
RESTAPI_utils::field_to_json(Obj, "venue", venue);
|
||||
RESTAPI_utils::field_to_json(Obj, "entity", entity);
|
||||
RESTAPI_utils::field_to_json(Obj, "subscriber", subscriber);
|
||||
RESTAPI_utils::field_to_json(Obj, "deviceType", deviceType);
|
||||
RESTAPI_utils::field_to_json(Obj, "qrCode", qrCode);
|
||||
RESTAPI_utils::field_to_json(Obj, "geoCode", geoCode);
|
||||
RESTAPI_utils::field_to_json(Obj, "location", location);
|
||||
RESTAPI_utils::field_to_json(Obj, "contact", contact);
|
||||
RESTAPI_utils::field_to_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
RESTAPI_utils::field_to_json( Obj,"rrm",rrm);
|
||||
RESTAPI_utils::field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
}
|
||||
|
||||
bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
info.from_json(Obj);
|
||||
field_from_json( Obj,"serialNumber",serialNumber);
|
||||
field_from_json( Obj,"venue",venue);
|
||||
field_from_json( Obj,"entity",entity);
|
||||
field_from_json( Obj,"subscriber",subscriber);
|
||||
field_from_json( Obj,"deviceType",deviceType);
|
||||
field_from_json(Obj, "qrCode", qrCode);
|
||||
field_from_json( Obj,"geoCode",geoCode);
|
||||
field_from_json( Obj,"location",location);
|
||||
field_from_json( Obj,"contact",contact);
|
||||
field_from_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
field_from_json( Obj,"rrm",rrm);
|
||||
field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_from_json( Obj,"serialNumber",serialNumber);
|
||||
RESTAPI_utils::field_from_json( Obj,"venue",venue);
|
||||
RESTAPI_utils::field_from_json( Obj,"entity",entity);
|
||||
RESTAPI_utils::field_from_json( Obj,"subscriber",subscriber);
|
||||
RESTAPI_utils::field_from_json( Obj,"deviceType",deviceType);
|
||||
RESTAPI_utils::field_from_json(Obj, "qrCode", qrCode);
|
||||
RESTAPI_utils::field_from_json( Obj,"geoCode",geoCode);
|
||||
RESTAPI_utils::field_from_json( Obj,"location",location);
|
||||
RESTAPI_utils::field_from_json( Obj,"contact",contact);
|
||||
RESTAPI_utils::field_from_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
RESTAPI_utils::field_from_json( Obj,"rrm",rrm);
|
||||
RESTAPI_utils::field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
@@ -334,18 +331,18 @@ namespace OpenWifi::ProvObjects {
|
||||
}
|
||||
|
||||
void DeviceConfigurationElement::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json( Obj,"name", name);
|
||||
field_to_json( Obj,"description", description);
|
||||
field_to_json( Obj,"weight", weight);
|
||||
field_to_json( Obj,"configuration", configuration);
|
||||
RESTAPI_utils::field_to_json( Obj,"name", name);
|
||||
RESTAPI_utils::field_to_json( Obj,"description", description);
|
||||
RESTAPI_utils::field_to_json( Obj,"weight", weight);
|
||||
RESTAPI_utils::field_to_json( Obj,"configuration", configuration);
|
||||
}
|
||||
|
||||
bool DeviceConfigurationElement::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json( Obj,"name",name);
|
||||
field_from_json( Obj,"description",description);
|
||||
field_from_json( Obj,"weight",weight);
|
||||
field_from_json( Obj,"configuration",configuration);
|
||||
RESTAPI_utils::field_from_json( Obj,"name",name);
|
||||
RESTAPI_utils::field_from_json( Obj,"description",description);
|
||||
RESTAPI_utils::field_from_json( Obj,"weight",weight);
|
||||
RESTAPI_utils::field_from_json( Obj,"configuration",configuration);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
@@ -355,27 +352,27 @@ namespace OpenWifi::ProvObjects {
|
||||
|
||||
void DeviceConfiguration::to_json(Poco::JSON::Object &Obj) const {
|
||||
info.to_json(Obj);
|
||||
field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
field_to_json( Obj,"deviceTypes",deviceTypes);
|
||||
field_to_json( Obj,"configuration",configuration);
|
||||
field_to_json( Obj,"inUse",inUse);
|
||||
field_to_json( Obj,"variables",variables);
|
||||
field_to_json( Obj,"rrm",rrm);
|
||||
field_to_json( Obj,"firmwareUpgrade",firmwareUpgrade);
|
||||
field_to_json( Obj,"firmwareRCOnly",firmwareRCOnly);
|
||||
RESTAPI_utils::field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_to_json( Obj,"deviceTypes",deviceTypes);
|
||||
RESTAPI_utils::field_to_json( Obj,"configuration",configuration);
|
||||
RESTAPI_utils::field_to_json( Obj,"inUse",inUse);
|
||||
RESTAPI_utils::field_to_json( Obj,"variables",variables);
|
||||
RESTAPI_utils::field_to_json( Obj,"rrm",rrm);
|
||||
RESTAPI_utils::field_to_json( Obj,"firmwareUpgrade",firmwareUpgrade);
|
||||
RESTAPI_utils::field_to_json( Obj,"firmwareRCOnly",firmwareRCOnly);
|
||||
}
|
||||
|
||||
bool DeviceConfiguration::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
info.from_json(Obj);
|
||||
field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
field_from_json( Obj,"deviceTypes",deviceTypes);
|
||||
field_from_json( Obj,"configuration",configuration);
|
||||
field_from_json( Obj,"inUse",inUse);
|
||||
field_from_json( Obj,"variables",variables);
|
||||
field_from_json( Obj,"rrm",rrm);
|
||||
field_from_json( Obj,"firmwareUpgrade",firmwareUpgrade);
|
||||
field_from_json( Obj,"firmwareRCOnly",firmwareRCOnly);
|
||||
RESTAPI_utils::field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
RESTAPI_utils::field_from_json( Obj,"deviceTypes",deviceTypes);
|
||||
RESTAPI_utils::field_from_json( Obj,"configuration",configuration);
|
||||
RESTAPI_utils::field_from_json( Obj,"inUse",inUse);
|
||||
RESTAPI_utils::field_from_json( Obj,"variables",variables);
|
||||
RESTAPI_utils::field_from_json( Obj,"rrm",rrm);
|
||||
RESTAPI_utils::field_from_json( Obj,"firmwareUpgrade",firmwareUpgrade);
|
||||
RESTAPI_utils::field_from_json( Obj,"firmwareRCOnly",firmwareRCOnly);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
@@ -384,8 +381,8 @@ namespace OpenWifi::ProvObjects {
|
||||
}
|
||||
|
||||
void Report::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "snapshot", snapShot);
|
||||
field_to_json(Obj, "devices", tenants);
|
||||
RESTAPI_utils::field_to_json(Obj, "snapshot", snapShot);
|
||||
RESTAPI_utils::field_to_json(Obj, "devices", tenants);
|
||||
};
|
||||
|
||||
void Report::reset() {
|
||||
@@ -393,16 +390,16 @@ namespace OpenWifi::ProvObjects {
|
||||
}
|
||||
|
||||
void ExpandedUseEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "uuid", uuid);
|
||||
field_to_json(Obj, "name", name);
|
||||
field_to_json(Obj, "description", description);
|
||||
RESTAPI_utils::field_to_json(Obj, "uuid", uuid);
|
||||
RESTAPI_utils::field_to_json(Obj, "name", name);
|
||||
RESTAPI_utils::field_to_json(Obj, "description", description);
|
||||
}
|
||||
|
||||
bool ExpandedUseEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json( Obj,"uuid",uuid);
|
||||
field_from_json( Obj,"name",name);
|
||||
field_from_json( Obj,"description",description);
|
||||
RESTAPI_utils::field_from_json( Obj,"uuid",uuid);
|
||||
RESTAPI_utils::field_from_json( Obj,"name",name);
|
||||
RESTAPI_utils::field_from_json( Obj,"description",description);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
@@ -411,14 +408,14 @@ namespace OpenWifi::ProvObjects {
|
||||
}
|
||||
|
||||
void ExpandedUseEntryList::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "type", type);
|
||||
field_to_json(Obj, "entries", entries);
|
||||
RESTAPI_utils::field_to_json(Obj, "type", type);
|
||||
RESTAPI_utils::field_to_json(Obj, "entries", entries);
|
||||
}
|
||||
|
||||
bool ExpandedUseEntryList::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json( Obj,"type",type);
|
||||
field_from_json( Obj,"entries",entries);
|
||||
RESTAPI_utils::field_from_json( Obj,"type",type);
|
||||
RESTAPI_utils::field_from_json( Obj,"entries",entries);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
@@ -427,94 +424,12 @@ namespace OpenWifi::ProvObjects {
|
||||
}
|
||||
|
||||
void ExpandedUseEntryMapList::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "entries", entries);
|
||||
RESTAPI_utils::field_to_json(Obj, "entries", entries);
|
||||
}
|
||||
|
||||
bool ExpandedUseEntryMapList::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json( Obj,"entries",entries);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void UserList::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "list", list);
|
||||
}
|
||||
|
||||
bool UserList::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj, "list", list);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ObjectACL::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "users", users);
|
||||
field_to_json(Obj, "access", access);
|
||||
}
|
||||
|
||||
bool ObjectACL::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj, "users", users);
|
||||
field_from_json(Obj, "access", access);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ObjectACLList::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "list", list);
|
||||
}
|
||||
|
||||
bool ObjectACLList::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj, "list", list);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Map::to_json(Poco::JSON::Object &Obj) const {
|
||||
info.to_json(Obj);
|
||||
field_to_json( Obj,"data",data);
|
||||
field_to_json( Obj,"entity",entity);
|
||||
field_to_json( Obj,"creator",creator);
|
||||
field_to_json( Obj,"visibility",visibility);
|
||||
field_to_json( Obj,"access",access);
|
||||
}
|
||||
|
||||
bool Map::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
info.from_json(Obj);
|
||||
field_from_json( Obj,"data",data);
|
||||
field_from_json( Obj,"entity",entity);
|
||||
field_from_json( Obj,"creator",creator);
|
||||
field_from_json( Obj,"visibility",visibility);
|
||||
field_from_json( Obj,"access",access);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MapList::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json( Obj,"list",list);
|
||||
}
|
||||
|
||||
bool MapList::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json( Obj,"list",list);
|
||||
RESTAPI_utils::field_from_json( Obj,"entries",entries);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
@@ -523,47 +438,13 @@ namespace OpenWifi::ProvObjects {
|
||||
}
|
||||
|
||||
bool UpdateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I) {
|
||||
uint64_t Now = std::time(nullptr);
|
||||
if(O->has("name"))
|
||||
I.name = O->get("name").toString();
|
||||
|
||||
if(I.name.empty())
|
||||
return false;
|
||||
|
||||
if(O->has("description"))
|
||||
I.description = O->get("description").toString();
|
||||
SecurityObjects::MergeNotes(O,U,I.notes);
|
||||
SecurityObjects::NoteInfoVec N;
|
||||
for(auto &i:I.notes) {
|
||||
if(i.note.empty())
|
||||
continue;
|
||||
N.push_back(SecurityObjects::NoteInfo{.created=Now,.createdBy=U.email,.note=i.note});
|
||||
}
|
||||
I.modified = Now;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I) {
|
||||
uint64_t Now = std::time(nullptr);
|
||||
if(O->has("name"))
|
||||
I.name = O->get("name").toString();
|
||||
|
||||
if(I.name.empty())
|
||||
return false;
|
||||
|
||||
if(O->has("description"))
|
||||
I.description = O->get("description").toString();
|
||||
|
||||
SecurityObjects::NoteInfoVec N;
|
||||
for(auto &i:I.notes) {
|
||||
if(i.note.empty())
|
||||
continue;
|
||||
N.push_back(SecurityObjects::NoteInfo{.created=Now,.createdBy=U.email,.note=i.note});
|
||||
}
|
||||
I.notes = N;
|
||||
I.modified = I.created = Now;
|
||||
I.id = MicroService::instance().CreateUUID();
|
||||
|
||||
SecurityObjects::MergeNotes(O,U,I.notes);
|
||||
I.modified = std::time(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -15,13 +15,6 @@
|
||||
|
||||
namespace OpenWifi::ProvObjects {
|
||||
|
||||
enum FIRMWARE_UPGRADE_RULES {
|
||||
dont_upgrade,
|
||||
upgrade_inherit,
|
||||
upgrade_release_only,
|
||||
upgrade_latest
|
||||
};
|
||||
|
||||
struct ObjectInfo {
|
||||
Types::UUID_t id;
|
||||
std::string name;
|
||||
@@ -324,50 +317,7 @@ namespace OpenWifi::ProvObjects {
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
struct UserList {
|
||||
std::vector<std::string> list;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
struct ObjectACL {
|
||||
UserList users;
|
||||
std::string access;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
struct ObjectACLList {
|
||||
std::vector<ObjectACL> list;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
struct Map {
|
||||
ObjectInfo info;
|
||||
std::string data;
|
||||
std::string entity;
|
||||
std::string creator;
|
||||
std::string visibility;
|
||||
ObjectACLList access;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
struct MapList {
|
||||
std::vector<Map> list;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
bool UpdateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I);
|
||||
bool CreateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace OpenWifi::SecurityObjects {
|
||||
field_to_json(Obj,"primary", primary);
|
||||
}
|
||||
|
||||
bool MobilePhoneNumber::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
bool MobilePhoneNumber::from_json(Poco::JSON::Object::Ptr Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"number",number);
|
||||
field_from_json(Obj,"verified",verified);
|
||||
@@ -155,7 +155,7 @@ namespace OpenWifi::SecurityObjects {
|
||||
field_to_json(Obj,"method", method);
|
||||
}
|
||||
|
||||
bool MfaAuthInfo::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
bool MfaAuthInfo::from_json(Poco::JSON::Object::Ptr Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"enabled",enabled);
|
||||
field_from_json(Obj,"method",method);
|
||||
@@ -171,7 +171,7 @@ namespace OpenWifi::SecurityObjects {
|
||||
field_to_json(Obj, "mfa", mfa);
|
||||
}
|
||||
|
||||
bool UserLoginLoginExtensions::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
bool UserLoginLoginExtensions::from_json(Poco::JSON::Object::Ptr Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"mobiles",mobiles);
|
||||
field_from_json(Obj,"mfa",mfa);
|
||||
@@ -189,7 +189,7 @@ namespace OpenWifi::SecurityObjects {
|
||||
field_to_json(Obj, "method", method);
|
||||
}
|
||||
|
||||
bool MFAChallengeRequest::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
bool MFAChallengeRequest::from_json(Poco::JSON::Object::Ptr Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"uuid",uuid);
|
||||
field_from_json(Obj,"question",question);
|
||||
@@ -208,7 +208,7 @@ namespace OpenWifi::SecurityObjects {
|
||||
|
||||
}
|
||||
|
||||
bool MFAChallengeResponse::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
bool MFAChallengeResponse::from_json(Poco::JSON::Object::Ptr Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"uuid",uuid);
|
||||
field_from_json(Obj,"answer",answer);
|
||||
@@ -387,12 +387,11 @@ namespace OpenWifi::SecurityObjects {
|
||||
field_to_json(Obj,"note", note);
|
||||
}
|
||||
|
||||
bool NoteInfo::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
bool NoteInfo::from_json(Poco::JSON::Object::Ptr Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"created",created);
|
||||
field_from_json(Obj,"createdBy",createdBy);
|
||||
field_from_json(Obj,"note",note);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
@@ -429,11 +428,10 @@ namespace OpenWifi::SecurityObjects {
|
||||
field_to_json<ResourceAccessType>(Obj,"access", access, ResourceAccessTypeToString);
|
||||
}
|
||||
|
||||
bool ProfileAction::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
bool ProfileAction::from_json(Poco::JSON::Object::Ptr Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"resource",resource);
|
||||
field_from_json<ResourceAccessType>(Obj,"access",access,ResourceAccessTypeFromString );
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
@@ -449,7 +447,7 @@ namespace OpenWifi::SecurityObjects {
|
||||
field_to_json(Obj,"notes", notes);
|
||||
}
|
||||
|
||||
bool SecurityProfile::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
bool SecurityProfile::from_json(Poco::JSON::Object::Ptr Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"id",id);
|
||||
field_from_json(Obj,"name",name);
|
||||
@@ -457,7 +455,6 @@ namespace OpenWifi::SecurityObjects {
|
||||
field_from_json(Obj,"policy",policy);
|
||||
field_from_json(Obj,"role",role);
|
||||
field_from_json(Obj,"notes",notes);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
@@ -468,51 +465,13 @@ namespace OpenWifi::SecurityObjects {
|
||||
field_to_json(Obj, "profiles", profiles);
|
||||
}
|
||||
|
||||
bool SecurityProfileList::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
bool SecurityProfileList::from_json(Poco::JSON::Object::Ptr Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"profiles",profiles);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ActionLink::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"id",id);
|
||||
field_to_json(Obj,"action",action);
|
||||
field_to_json(Obj,"userId",userId);
|
||||
field_to_json(Obj,"actionTemplate",actionTemplate);
|
||||
field_to_json(Obj,"variables",variables);
|
||||
field_to_json(Obj,"locale",locale);
|
||||
field_to_json(Obj,"message",message);
|
||||
field_to_json(Obj,"sent",sent);
|
||||
field_to_json(Obj,"created",created);
|
||||
field_to_json(Obj,"expires",expires);
|
||||
field_to_json(Obj,"completed",completed);
|
||||
field_to_json(Obj,"canceled",canceled);
|
||||
|
||||
}
|
||||
|
||||
bool ActionLink::from_json(Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"id",id);
|
||||
field_from_json(Obj,"action",action);
|
||||
field_from_json(Obj,"userId",userId);
|
||||
field_from_json(Obj,"actionTemplate",actionTemplate);
|
||||
field_from_json(Obj,"variables",variables);
|
||||
field_from_json(Obj,"locale",locale);
|
||||
field_from_json(Obj,"message",message);
|
||||
field_from_json(Obj,"sent",sent);
|
||||
field_from_json(Obj,"created",created);
|
||||
field_from_json(Obj,"expires",expires);
|
||||
field_from_json(Obj,"completed",completed);
|
||||
field_from_json(Obj,"canceled",canceled);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#define UCENTRAL_RESTAPI_SECURITYOBJECTS_H
|
||||
|
||||
#include "Poco/JSON/Object.h"
|
||||
#include "framework/OpenWifiTypes.h"
|
||||
#include "../framework/OpenWifiTypes.h"
|
||||
|
||||
namespace OpenWifi::SecurityObjects {
|
||||
|
||||
@@ -53,25 +53,25 @@ namespace OpenWifi::SecurityObjects {
|
||||
std::string createdBy;
|
||||
std::string note;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
bool from_json(Poco::JSON::Object::Ptr Obj);
|
||||
};
|
||||
typedef std::vector<NoteInfo> NoteInfoVec;
|
||||
|
||||
struct MobilePhoneNumber {
|
||||
std::string number;
|
||||
bool verified = false;
|
||||
bool primary = false;
|
||||
bool verified;
|
||||
bool primary;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
bool from_json(Poco::JSON::Object::Ptr Obj);
|
||||
};
|
||||
|
||||
struct MfaAuthInfo {
|
||||
bool enabled = false;
|
||||
bool enabled;
|
||||
std::string method;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
bool from_json(Poco::JSON::Object::Ptr Obj);
|
||||
};
|
||||
|
||||
struct UserLoginLoginExtensions {
|
||||
@@ -79,17 +79,17 @@ namespace OpenWifi::SecurityObjects {
|
||||
struct MfaAuthInfo mfa;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
bool from_json(Poco::JSON::Object::Ptr Obj);
|
||||
};
|
||||
|
||||
struct MFAChallengeRequest {
|
||||
std::string uuid;
|
||||
std::string question;
|
||||
std::string method;
|
||||
uint64_t created = std::time(nullptr);
|
||||
uint64_t created;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
bool from_json(Poco::JSON::Object::Ptr Obj);
|
||||
};
|
||||
|
||||
struct MFAChallengeResponse {
|
||||
@@ -97,7 +97,7 @@ namespace OpenWifi::SecurityObjects {
|
||||
std::string answer;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
bool from_json(Poco::JSON::Object::Ptr Obj);
|
||||
};
|
||||
|
||||
struct UserInfo {
|
||||
@@ -200,7 +200,7 @@ namespace OpenWifi::SecurityObjects {
|
||||
std::string resource;
|
||||
ResourceAccessType access;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
bool from_json(Poco::JSON::Object::Ptr Obj);
|
||||
};
|
||||
typedef std::vector<ProfileAction> ProfileActionVec;
|
||||
|
||||
@@ -212,37 +212,14 @@ namespace OpenWifi::SecurityObjects {
|
||||
std::string role;
|
||||
NoteInfoVec notes;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
bool from_json(Poco::JSON::Object::Ptr Obj);
|
||||
};
|
||||
typedef std::vector<SecurityProfile> SecurityProfileVec;
|
||||
|
||||
struct SecurityProfileList {
|
||||
SecurityProfileVec profiles;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
enum LinkActions {
|
||||
FORGOT_PASSWORD=1,
|
||||
VERIFY_EMAIL
|
||||
};
|
||||
|
||||
struct ActionLink {
|
||||
std::string id;
|
||||
uint64_t action;
|
||||
std::string userId;
|
||||
std::string actionTemplate;
|
||||
Types::StringPairVec variables;
|
||||
std::string locale;
|
||||
std::string message;
|
||||
uint64_t sent=0;
|
||||
uint64_t created=std::time(nullptr);
|
||||
uint64_t expires=0;
|
||||
uint64_t completed=0;
|
||||
uint64_t canceled=0;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(Poco::JSON::Object::Ptr &Obj);
|
||||
bool from_json(Poco::JSON::Object::Ptr Obj);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class SerialNumberCache * SerialNumberCache::instance_ = nullptr;
|
||||
|
||||
int SerialNumberCache::Start() {
|
||||
StorageService()->UpdateSerialNumberCache();
|
||||
return 0;
|
||||
|
||||
@@ -11,8 +11,10 @@ namespace OpenWifi {
|
||||
class SerialNumberCache : public SubSystemServer {
|
||||
public:
|
||||
|
||||
static SerialNumberCache * instance() {
|
||||
static SerialNumberCache * instance_ = new SerialNumberCache;
|
||||
static SerialNumberCache *instance() {
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new SerialNumberCache;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
@@ -23,6 +25,7 @@ namespace OpenWifi {
|
||||
void FindNumbers(const std::string &S, uint HowMany, std::vector<uint64_t> &A);
|
||||
|
||||
private:
|
||||
static SerialNumberCache * instance_;
|
||||
uint64_t LastUpdate_ = 0 ;
|
||||
std::vector<uint64_t> SNs_;
|
||||
std::mutex M_;
|
||||
|
||||
@@ -13,43 +13,49 @@ namespace OpenWifi {
|
||||
try {
|
||||
UpdatesSinceLastWrite_++;
|
||||
// get the interfaces section
|
||||
if(O->has("interfaces") && O->isArray("interfaces")) {
|
||||
auto IFaces = O->getArray("interfaces");
|
||||
for (auto const &i : *IFaces) {
|
||||
auto Interface = i.extract<Poco::JSON::Object::Ptr>();
|
||||
if (Interface->has("name") && Interface->has("counters")) {
|
||||
auto InterfaceName = Interface->get("name").toString();
|
||||
auto InterfaceMapEntry = Stats_.find(InterfaceName);
|
||||
if(InterfaceMapEntry == Stats_.end()) {
|
||||
std::map<std::string,uint64_t> NewStatEntry;
|
||||
Stats_[InterfaceName] = NewStatEntry;
|
||||
InterfaceMapEntry = Stats_.find(InterfaceName);
|
||||
}
|
||||
auto CountersObj = Interface->getObject("counters");
|
||||
for (const auto &j : *CountersObj) {
|
||||
auto Entry = InterfaceMapEntry->second.find(j.first);
|
||||
if(Entry==InterfaceMapEntry->second.end()) {
|
||||
InterfaceMapEntry->second[j.first] = j.second;
|
||||
} else {
|
||||
InterfaceMapEntry->second[j.first] += j.second;
|
||||
if(O->has("interfaces")) {
|
||||
auto IFaces = O->get("interfaces");
|
||||
if(IFaces.isArray()) {
|
||||
auto IFaceObjs = IFaces.extract<Poco::JSON::Array::Ptr>();
|
||||
for (auto const &i : *IFaceObjs) {
|
||||
auto Interface = i.extract<Poco::JSON::Object::Ptr>();
|
||||
if (Interface->has("name") && Interface->has("counters")) {
|
||||
auto InterfaceName = Interface->get("name").toString();
|
||||
auto InterfaceMapEntry = Stats_.find(InterfaceName);
|
||||
if(InterfaceMapEntry == Stats_.end()) {
|
||||
std::map<std::string,uint64_t> NewStatEntry;
|
||||
Stats_[InterfaceName] = NewStatEntry;
|
||||
InterfaceMapEntry = Stats_.find(InterfaceName);
|
||||
}
|
||||
|
||||
auto CountersObj = Interface->get("counters").extract<Poco::JSON::Object::Ptr>();
|
||||
Poco::DynamicStruct CounterVars = *CountersObj;
|
||||
|
||||
for (const auto &j : CounterVars) {
|
||||
auto Entry = InterfaceMapEntry->second.find(j.first);
|
||||
if(Entry==InterfaceMapEntry->second.end()) {
|
||||
InterfaceMapEntry->second[j.first] = j.second;
|
||||
} else {
|
||||
InterfaceMapEntry->second[j.first] += j.second;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Conn_)
|
||||
GetAssociations(O,Conn_->Associations_2G,Conn_->Associations_5G);
|
||||
|
||||
if(UpdatesSinceLastWrite_>10)
|
||||
Save();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(Conn_)
|
||||
GetAssociations(O,Conn_->Conn_.Associations_2G,Conn_->Conn_.Associations_5G);
|
||||
|
||||
if(UpdatesSinceLastWrite_>10)
|
||||
Save();
|
||||
return true;
|
||||
} else {
|
||||
Logger_.information(Poco::format("DEVICE(%s): State is missing interfaces",SerialNumber_));
|
||||
std::cout << "No interfaces section" << std::endl;
|
||||
}
|
||||
} catch (const Poco::Exception &E ) {
|
||||
Logger_.log(E);
|
||||
std::cout << "Exception0.. " << E.displayText() << " " << E.what() << std::endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -61,7 +67,7 @@ namespace OpenWifi {
|
||||
const auto & Result = ParsedMessage.extract<Poco::JSON::Object::Ptr>();
|
||||
return Add(Result);
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
std::cout << "Exception1.." << std::endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -76,6 +82,12 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
void StateProcessor::to_json(Poco::JSON::Object & Obj) const {
|
||||
/* interfaces: [
|
||||
name:
|
||||
counters: {
|
||||
|
||||
}
|
||||
*/
|
||||
Poco::JSON::Array Interfaces;
|
||||
for(const auto & Interface: Stats_) {
|
||||
Poco::JSON::Object InnerObj;
|
||||
@@ -139,16 +151,7 @@ namespace OpenWifi {
|
||||
Poco::JSON::Parser p2;
|
||||
auto RadioObj = i.extract<Poco::JSON::Object::Ptr>();
|
||||
if(RadioObj->has("phy") && RadioObj->has("channel")) {
|
||||
if(RadioObj->isArray("channel")) {
|
||||
auto ChannelArray = RadioObj->getArray("channel");
|
||||
if(ChannelArray->size()) {
|
||||
RadioPHYs[RadioObj->get("phy").toString()] =
|
||||
ChannelToBand( ChannelArray->getElement<uint64_t>(0) );
|
||||
}
|
||||
} else {
|
||||
RadioPHYs[RadioObj->get("phy").toString()] =
|
||||
ChannelToBand(RadioObj->get("channel"));
|
||||
}
|
||||
RadioPHYs[RadioObj->get("phy").toString()]= ChannelToBand(RadioObj->get("channel"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,18 +4,16 @@
|
||||
|
||||
#ifndef UCENTRALGW_STATEPROCESSOR_H
|
||||
#define UCENTRALGW_STATEPROCESSOR_H
|
||||
#include <map>
|
||||
|
||||
#include "Poco/JSON/Object.h"
|
||||
#include "Poco/Logger.h"
|
||||
#include "RESTObjects//RESTAPI_GWobjects.h"
|
||||
#include "DeviceRegistry.h"
|
||||
#include <map>
|
||||
|
||||
namespace OpenWifi {
|
||||
class StateProcessor {
|
||||
public:
|
||||
explicit StateProcessor(std::shared_ptr<DeviceRegistry::ConnectionEntry> Conn, Poco::Logger & L):
|
||||
Conn_(Conn), Logger_(L) {}
|
||||
explicit StateProcessor(GWObjects::ConnectionState * Conn):
|
||||
Conn_(Conn) {}
|
||||
|
||||
~StateProcessor() {
|
||||
Save();
|
||||
@@ -33,12 +31,11 @@ namespace OpenWifi {
|
||||
|
||||
private:
|
||||
std::string SerialNumber_;
|
||||
Poco::JSON::Object State_;
|
||||
Poco::Logger & Logger_;
|
||||
Poco::JSON::Object State_;
|
||||
// interface name is the key, each entry is a map with the stats name as key and then the value
|
||||
std::map<std::string,std::map<std::string,uint64_t>> Stats_;
|
||||
uint64_t UpdatesSinceLastWrite_ = 0 ;
|
||||
std::shared_ptr<DeviceRegistry::ConnectionEntry> Conn_;
|
||||
GWObjects::ConnectionState * Conn_ = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -10,66 +10,92 @@
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
void Archiver::onTimer(Poco::Timer &timer){
|
||||
auto Now = std::time(nullptr);
|
||||
for(const auto &i:DBs_) {
|
||||
if (!Poco::icompare(i.DBName, "healthchecks")) {
|
||||
Logger_.information("Archiving HealthChecks...");
|
||||
StorageService()->RemoveHealthChecksRecordsOlderThan(
|
||||
Now - (i.HowManyDays * 24 * 60 * 60));
|
||||
} else if (!Poco::icompare(i.DBName, "statistics")) {
|
||||
Logger_.information("Archiving Statistics...");
|
||||
StorageService()->RemoveStatisticsRecordsOlderThan(
|
||||
Now - (i.HowManyDays * 24 * 60 * 60));
|
||||
} else if (!Poco::icompare(i.DBName, "devicelogs")) {
|
||||
Logger_.information("Archiving Device Logs...");
|
||||
StorageService()->RemoveDeviceLogsRecordsOlderThan(
|
||||
Now - (i.HowManyDays * 24 * 60 * 60));
|
||||
} else if (!Poco::icompare(i.DBName, "commandlist")) {
|
||||
Logger_.information("Archiving Command History...");
|
||||
StorageService()->RemoveCommandListRecordsOlderThan(
|
||||
Now - (i.HowManyDays * 24 * 60 * 60));
|
||||
} else {
|
||||
Logger_.information(Poco::format("Cannot archive DB '%s'", i.DBName));
|
||||
class StorageArchiver *StorageArchiver::instance_ = nullptr;
|
||||
|
||||
void StorageArchiver::run() {
|
||||
Running_ = true ;
|
||||
GetLastRun();
|
||||
while(Running_) {
|
||||
Poco::Thread::trySleep(2000);
|
||||
Poco::DateTime Now;
|
||||
|
||||
if(!Running_)
|
||||
break;
|
||||
|
||||
if(LastRun_!=Now.day()) {
|
||||
if(Now.hour()>=RunAtHour_ && Now.minute()>=RunAtMin_) {
|
||||
std::lock_guard G(Mutex_);
|
||||
for(const auto &i:DBs_) {
|
||||
if (!Poco::icompare(i.DBName, "healthchecks")) {
|
||||
Logger_.information("Archiving HealthChecks...");
|
||||
StorageService()->RemoveHealthChecksRecordsOlderThan(
|
||||
std::time(nullptr) - (i.HowManyDays * 24 * 60 * 60));
|
||||
} else if (!Poco::icompare(i.DBName, "statistics")) {
|
||||
Logger_.information("Archiving Statistics...");
|
||||
StorageService()->RemoveStatisticsRecordsOlderThan(
|
||||
std::time(nullptr) - (i.HowManyDays * 24 * 60 * 60));
|
||||
} else if (!Poco::icompare(i.DBName, "devicelogs")) {
|
||||
Logger_.information("Archiving Device Logs...");
|
||||
StorageService()->RemoveDeviceLogsRecordsOlderThan(
|
||||
std::time(nullptr) - (i.HowManyDays * 24 * 60 * 60));
|
||||
} else if (!Poco::icompare(i.DBName, "commandlist")) {
|
||||
Logger_.information("Archiving Command History...");
|
||||
StorageService()->RemoveCommandListRecordsOlderThan(
|
||||
std::time(nullptr) - (i.HowManyDays * 24 * 60 * 60));
|
||||
} else {
|
||||
}
|
||||
}
|
||||
LastRun_ = Now.day();
|
||||
SetLastRun();
|
||||
}
|
||||
}
|
||||
}
|
||||
AppServiceRegistry().Set("lastStorageArchiverRun", (uint64_t) Now);
|
||||
}
|
||||
|
||||
static auto CalculateDelta(int H, int M) {
|
||||
Poco::LocalDateTime dt;
|
||||
Poco::LocalDateTime scheduled(dt.year(), dt.month(), dt.day(), H, M, 0);
|
||||
|
||||
size_t delta = 0;
|
||||
if ((dt.hour() < H) || (dt.hour()==H && dt.minute()<M)) {
|
||||
delta = scheduled.timestamp().epochTime() - dt.timestamp().epochTime();
|
||||
} else {
|
||||
delta = (24*60*60) - (dt.timestamp().epochTime() - scheduled.timestamp().epochTime());
|
||||
void StorageArchiver::GetLastRun() {
|
||||
try {
|
||||
Poco::File LR(LastRunFileName_);
|
||||
try {
|
||||
if (LR.exists()) {
|
||||
std::ifstream I;
|
||||
I.open(LR.path());
|
||||
I >> LastRun_;
|
||||
I.close();
|
||||
} else {
|
||||
LastRun_ = 0;
|
||||
}
|
||||
} catch(...) {
|
||||
LastRun_=0;
|
||||
}
|
||||
} catch(...) {
|
||||
LastRun_=0;
|
||||
}
|
||||
}
|
||||
|
||||
void StorageArchiver::SetLastRun() {
|
||||
try {
|
||||
std::ofstream O;
|
||||
O.open(LastRunFileName_,std::ios::binary | std::ios::trunc);
|
||||
O << LastRun_;
|
||||
O.close();
|
||||
} catch(const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
}
|
||||
return delta;
|
||||
}
|
||||
|
||||
int StorageArchiver::Start() {
|
||||
|
||||
Enabled_ = MicroService::instance().ConfigGetBool("archiver.enabled",false);
|
||||
|
||||
if(!Enabled_) {
|
||||
Logger_.information("Archiver is disabled.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ArchiverCallback_ = std::make_unique<Poco::TimerCallback<Archiver>>(Archiver_,&Archiver::onTimer);
|
||||
|
||||
auto Schedule = MicroService::instance().ConfigGetString("archiver.schedule","03:00");
|
||||
auto S = Poco::StringTokenizer(Schedule,":");
|
||||
|
||||
int RunAtHour_, RunAtMin_;
|
||||
if(S.count()!=2) {
|
||||
RunAtHour_ = 3 ;
|
||||
RunAtMin_ = 0;
|
||||
} else {
|
||||
RunAtHour_ = std::atoi(S[0].c_str());
|
||||
RunAtMin_ = std::atoi(S[1].c_str());
|
||||
}
|
||||
Types::StringVec S = Utils::Split(Schedule,':');
|
||||
RunAtHour_ = std::atoi(S[0].c_str());
|
||||
RunAtMin_ = std::atoi(S[1].c_str());
|
||||
|
||||
for(int i=0;i<20;i++) {
|
||||
std::string key = "archiver.db." + std::to_string(i) + ".name";
|
||||
@@ -79,7 +105,7 @@ namespace OpenWifi {
|
||||
if(Poco::icompare(DBName,DB)==0) {
|
||||
std::string Key = "archiver.db." + std::to_string(i) + ".keep";
|
||||
auto Keep = MicroService::instance().ConfigGetInt(Key,7);
|
||||
Archiver_.AddDb(Archiver::ArchiverDBEntry{
|
||||
DBs_.push_back(ArchiverDBEntry{
|
||||
.DBName = DB,
|
||||
.HowManyDays = Keep
|
||||
});
|
||||
@@ -87,21 +113,17 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int NextRun = CalculateDelta(RunAtHour_,RunAtMin_);
|
||||
|
||||
Logger_.information(Poco::format("Next run in %d seconds.",NextRun));
|
||||
|
||||
Timer_.setStartInterval( NextRun * 1000);
|
||||
Timer_.setPeriodicInterval(24 * 60 * 60 * 1000); // 1 hours
|
||||
Timer_.start(*ArchiverCallback_);
|
||||
|
||||
LastRunFileName_ = MicroService::instance().DataDir() + "/archiver_lastrun.txt";
|
||||
Janitor_.start(*this);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void StorageArchiver::Stop() {
|
||||
if(Enabled_) {
|
||||
Timer_.stop();
|
||||
|
||||
if(Running_) {
|
||||
Running_=false;
|
||||
Janitor_.wakeUp();
|
||||
Janitor_.join();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,58 +8,54 @@
|
||||
#include <functional>
|
||||
|
||||
#include "framework/MicroService.h"
|
||||
#include "Poco/Timer.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
static const std::list<std::string> AllInternalDBNames{"healthchecks", "statistics", "devicelogs" , "commandlist" };
|
||||
struct ArchiverDBEntry {
|
||||
std::string DBName;
|
||||
uint64_t HowManyDays=7;
|
||||
};
|
||||
typedef std::vector<ArchiverDBEntry> ArchiverDBEntryVec;
|
||||
|
||||
class Archiver {
|
||||
public:
|
||||
struct ArchiverDBEntry {
|
||||
std::string DBName;
|
||||
uint64_t HowManyDays=7;
|
||||
};
|
||||
typedef std::vector<ArchiverDBEntry> ArchiverDBEntryVec;
|
||||
static const std::list<std::string> AllInternalDBNames{"healthchecks", "statistics", "devicelogs" , "commandlist" };
|
||||
|
||||
explicit Archiver(Poco::Logger &Logger):
|
||||
Logger_(Logger) {
|
||||
class StorageArchiver : public SubSystemServer, Poco::Runnable {
|
||||
|
||||
public:
|
||||
static StorageArchiver *instance() {
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new StorageArchiver;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
void onTimer(Poco::Timer & timer);
|
||||
inline void AddDb(const ArchiverDBEntry &E ) {
|
||||
DBs_.push_back(E);
|
||||
void run() override;
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
void GetLastRun();
|
||||
void SetLastRun();
|
||||
|
||||
inline bool Enabled() const { return Enabled_; }
|
||||
|
||||
private:
|
||||
static StorageArchiver *instance_;
|
||||
std::atomic_bool Running_ = false;
|
||||
std::atomic_bool Enabled_ = false;
|
||||
Poco::Thread Janitor_;
|
||||
ArchiverDBEntryVec DBs_;
|
||||
uint64_t RunAtHour_=0;
|
||||
uint64_t RunAtMin_=0;
|
||||
uint64_t LastRun_=0;
|
||||
std::string LastRunFileName_;
|
||||
|
||||
StorageArchiver() noexcept:
|
||||
SubSystemServer("StorageArchiver", "STORAGE-ARCHIVE", "archiver")
|
||||
{
|
||||
}
|
||||
private:
|
||||
Poco::Logger &Logger_;
|
||||
ArchiverDBEntryVec DBs_;
|
||||
};
|
||||
|
||||
class StorageArchiver : public SubSystemServer {
|
||||
};
|
||||
|
||||
public:
|
||||
static StorageArchiver *instance() {
|
||||
static StorageArchiver * instance_ = new StorageArchiver;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
inline bool Enabled() const { return Enabled_; }
|
||||
|
||||
private:
|
||||
std::atomic_bool Enabled_ = false;
|
||||
Poco::Timer Timer_;
|
||||
Archiver Archiver_{Logger_};
|
||||
std::unique_ptr<Poco::TimerCallback<Archiver>> ArchiverCallback_;
|
||||
|
||||
StorageArchiver() noexcept:
|
||||
SubSystemServer("StorageArchiver", "STORAGE-ARCHIVE", "archiver")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
inline StorageArchiver * StorageArchiver() { return StorageArchiver::instance(); }
|
||||
inline StorageArchiver * StorageArchiver() { return StorageArchiver::instance(); }
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class Storage *Storage::instance_ = nullptr;
|
||||
|
||||
int Storage::Start() {
|
||||
std::lock_guard Guard(Mutex_);
|
||||
StorageClass::Start();
|
||||
|
||||
@@ -28,8 +28,10 @@ namespace OpenWifi {
|
||||
};
|
||||
|
||||
static Storage *instance() {
|
||||
static Storage * instance_ = new Storage;
|
||||
return instance_;
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new Storage;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
typedef std::map<std::string,std::string> DeviceCapabilitiesCache;
|
||||
@@ -145,6 +147,7 @@ namespace OpenWifi {
|
||||
inline bool GetDeviceCapabilitiesCache(DeviceCapabilitiesCache & Caps) { std::lock_guard G(Mutex_); Caps = CapsCache_; return true; };
|
||||
|
||||
private:
|
||||
static Storage *instance_;
|
||||
DeviceCapabilitiesCache CapsCache_;
|
||||
|
||||
};
|
||||
|
||||
@@ -25,20 +25,16 @@
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class TelemetryStream *TelemetryStream::instance_ = nullptr;
|
||||
|
||||
int TelemetryStream::Start() {
|
||||
ReactorPool_.Start();
|
||||
Runner_.start(*this);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TelemetryStream::Stop() {
|
||||
Logger_.notice("Stopping reactors...");
|
||||
ReactorPool_.Stop();
|
||||
|
||||
if(Running_) {
|
||||
Running_ = false;
|
||||
Runner_.join();
|
||||
}
|
||||
Logger_.notice("Stopping reactors...");
|
||||
ReactorPool_.Stop();
|
||||
}
|
||||
|
||||
bool TelemetryStream::CreateEndpoint(const std::string &SerialNumber, std::string &EndPoint, std::string &UUID) {
|
||||
@@ -46,7 +42,7 @@ namespace OpenWifi {
|
||||
|
||||
Poco::URI Public(MicroService::instance().ConfigGetString("openwifi.system.uri.public"));
|
||||
Poco::URI U;
|
||||
UUID = MicroService::CreateUUID();
|
||||
UUID = MicroService::instance().CreateUUID();
|
||||
U.setScheme("wss");
|
||||
U.setHost(Public.getHost());
|
||||
U.setPort(Public.getPort());
|
||||
@@ -55,70 +51,38 @@ namespace OpenWifi {
|
||||
U.addQueryParameter("uuid", UUID);
|
||||
U.addQueryParameter("serialNumber", SerialNumber);
|
||||
EndPoint = U.toString();
|
||||
auto H = SerialNumbers_.find(SerialNumber);
|
||||
if(H == SerialNumbers_.end()) {
|
||||
std::set<std::string> UUIDs{UUID};
|
||||
SerialNumbers_[SerialNumber] = UUIDs;
|
||||
} else {
|
||||
H->second.insert(UUID);
|
||||
}
|
||||
SerialNumbers_[SerialNumber] = UUID;
|
||||
Clients_[UUID] = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TelemetryStream::UpdateEndPoint(const std::string &SerialNumber, const std::string &PayLoad) {
|
||||
std::lock_guard G(QueueMutex_);
|
||||
Queue_.push(QueueUpdate{.SerialNumber=SerialNumber,.Payload=PayLoad});
|
||||
Runner_.wakeUp();
|
||||
}
|
||||
void TelemetryStream::DeleteEndPoint(const std::string &SerialNumber) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
void TelemetryStream::run() {
|
||||
Running_ = true;
|
||||
std::vector<QueueUpdate> Entries;
|
||||
auto H1 = SerialNumbers_.find(SerialNumber);
|
||||
if(H1!=SerialNumbers_.end()) {
|
||||
auto H2 = Clients_.find(H1->second);
|
||||
if(H2!=Clients_.end()) {
|
||||
try {
|
||||
delete H2->second;
|
||||
} catch (const Poco::Exception &E ) {
|
||||
|
||||
while(Running_) {
|
||||
bool QueueEmpty = true;
|
||||
{
|
||||
std::lock_guard G(QueueMutex_);
|
||||
QueueEmpty = Queue_.empty();
|
||||
}
|
||||
|
||||
if(QueueEmpty) {
|
||||
Poco::Thread::trySleep(2000);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!Running_)
|
||||
break;
|
||||
|
||||
{
|
||||
std::lock_guard G(QueueMutex_);
|
||||
Entries.clear();
|
||||
while(!Queue_.empty()) {
|
||||
Entries.push_back(Queue_.front());
|
||||
Queue_.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TelemetryStream::UpdateEndPoint(const std::string &SerialNumber, const std::string &PayLoad) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
auto H1 = SerialNumbers_.find(SerialNumber);
|
||||
if(H1!=SerialNumbers_.end()) {
|
||||
auto H2 = Clients_.find(H1->second);
|
||||
if(H2!=Clients_.end() && H2->second!=nullptr) {
|
||||
try {
|
||||
H2->second->Send(PayLoad);
|
||||
} catch (...) {
|
||||
|
||||
{
|
||||
std::lock_guard G(Mutex_);
|
||||
for(auto &E:Entries) {
|
||||
auto H1 = SerialNumbers_.find(E.SerialNumber);
|
||||
if (H1 != SerialNumbers_.end()) {
|
||||
for (auto &i : H1->second) {
|
||||
auto H2 = Clients_.find(i);
|
||||
if (H2 != Clients_.end() && H2->second != nullptr) {
|
||||
try {
|
||||
H2->second->Send(E.Payload);
|
||||
} catch (...) {
|
||||
}
|
||||
}
|
||||
if(!Running_)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!Running_)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,8 +90,13 @@ namespace OpenWifi {
|
||||
|
||||
bool TelemetryStream::RegisterClient(const std::string &UUID, TelemetryClient *Client) {
|
||||
std::lock_guard G(Mutex_);
|
||||
Clients_[UUID] = Client;
|
||||
return true;
|
||||
|
||||
auto Hint = Clients_.find(UUID);
|
||||
if(Hint!=Clients_.end()) {
|
||||
Hint->second = Client;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TelemetryStream::DeRegisterClient(const std::string &UUID) {
|
||||
@@ -137,16 +106,9 @@ namespace OpenWifi {
|
||||
if(Hint!=Clients_.end()) {
|
||||
Clients_.erase(Hint);
|
||||
for(const auto &i:SerialNumbers_) {
|
||||
auto S = i.second;
|
||||
S.erase(UUID);
|
||||
}
|
||||
|
||||
// remove empty slots
|
||||
for( auto i = SerialNumbers_.begin(); i!= SerialNumbers_.end();) {
|
||||
if(i->second.empty()) {
|
||||
i = SerialNumbers_.erase(i);
|
||||
} else {
|
||||
++i;
|
||||
if(i.second==UUID) {
|
||||
SerialNumbers_.erase(i.first);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,15 +93,12 @@ namespace OpenWifi {
|
||||
void CompleteStartup();
|
||||
};
|
||||
|
||||
class TelemetryStream : public SubSystemServer, Poco::Runnable {
|
||||
class TelemetryStream : public SubSystemServer {
|
||||
public:
|
||||
struct QueueUpdate {
|
||||
std::string SerialNumber;
|
||||
std::string Payload;
|
||||
};
|
||||
|
||||
static TelemetryStream *instance() {
|
||||
static TelemetryStream * instance_ = new TelemetryStream;
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new TelemetryStream;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
@@ -109,19 +106,17 @@ namespace OpenWifi {
|
||||
void Stop() override;
|
||||
|
||||
bool CreateEndpoint(const std::string &SerialNumber, std::string &EndPoint, std::string &UUID);
|
||||
void DeleteEndPoint(const std::string &SerialNumber);
|
||||
void UpdateEndPoint(const std::string &SerialNumber, const std::string &PayLoad);
|
||||
bool RegisterClient(const std::string &UUID, TelemetryClient *Client);
|
||||
void DeRegisterClient(const std::string &UUID);
|
||||
Poco::Net::SocketReactor & NextReactor() { return ReactorPool_.NextReactor(); }
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
std::atomic_bool Running_=false;
|
||||
std::map<std::string, TelemetryClient *> Clients_; // uuid -> client
|
||||
std::map<std::string, std::set<std::string>> SerialNumbers_; // serialNumber -> uuid
|
||||
TelemetryReactorPool ReactorPool_;
|
||||
std::mutex QueueMutex_;
|
||||
Poco::Thread Runner_;
|
||||
std::queue<QueueUpdate> Queue_;
|
||||
static TelemetryStream * instance_;
|
||||
std::map<std::string, TelemetryClient *> Clients_; // uuid -> client
|
||||
std::map<std::string, std::string> SerialNumbers_; // serialNumber -> uuid
|
||||
TelemetryReactorPool ReactorPool_;
|
||||
TelemetryStream() noexcept:
|
||||
SubSystemServer("TelemetryServer", "TELEMETRY-SVR", "openwifi.telemetry")
|
||||
{
|
||||
|
||||
@@ -28,6 +28,14 @@
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class WebSocketServer *WebSocketServer::instance_ = nullptr;
|
||||
|
||||
WebSocketServer::WebSocketServer() noexcept:
|
||||
SubSystemServer("WebSocketServer", "WS-SVR", "ucentral.websocket")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool WebSocketServer::ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate) {
|
||||
if(IsCertOk()) {
|
||||
Logger_.debug(Poco::format("CERTIFICATE(%s): issuer='%s' cn='%s'", ConnectionId, Certificate.issuerName(),Certificate.commonName()));
|
||||
@@ -147,8 +155,6 @@ namespace OpenWifi {
|
||||
} catch (const Poco::Exception &E ) {
|
||||
Logger_.error("Exception caught during device connection. Device will have to retry.");
|
||||
Logger_.log(E);
|
||||
} catch (...) {
|
||||
Logger_.error("Exception caught during device connection. Device will have to retry. Unsecure connect denied.");
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
@@ -162,22 +168,6 @@ namespace OpenWifi {
|
||||
T.detach();
|
||||
}
|
||||
|
||||
static void NotifyKafkaDisconnect(std::string SerialNumber) {
|
||||
try {
|
||||
Poco::JSON::Object Disconnect;
|
||||
Poco::JSON::Object Details;
|
||||
Details.set(uCentralProtocol::SERIALNUMBER, SerialNumber);
|
||||
Details.set(uCentralProtocol::TIMESTAMP, std::time(nullptr));
|
||||
Disconnect.set(uCentralProtocol::DISCONNECTION, Details);
|
||||
Poco::JSON::Stringifier Stringify;
|
||||
std::ostringstream OS;
|
||||
Stringify.condense(Disconnect, OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber, OS.str());
|
||||
} catch (...) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
WSConnection::~WSConnection() {
|
||||
DeviceRegistry()->UnRegister(SerialNumber_,this);
|
||||
if(Registered_ && WS_)
|
||||
@@ -199,9 +189,15 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
if(KafkaManager()->Enabled() && !SerialNumber_.empty()) {
|
||||
std::string s(SerialNumber_);
|
||||
std::thread t([s](){ NotifyKafkaDisconnect(s);});
|
||||
t.detach();
|
||||
Poco::JSON::Object Disconnect;
|
||||
Poco::JSON::Object Details;
|
||||
Details.set(uCentralProtocol::SERIALNUMBER, SerialNumber_);
|
||||
Details.set(uCentralProtocol::TIMESTAMP,std::time(nullptr));
|
||||
Disconnect.set(uCentralProtocol::DISCONNECTION,Details);
|
||||
Poco::JSON::Stringifier Stringify;
|
||||
std::ostringstream OS;
|
||||
Stringify.condense(Disconnect,OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber_, OS.str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +208,7 @@ namespace OpenWifi {
|
||||
return false;
|
||||
|
||||
uint64_t GoodConfig=ConfigurationCache().CurrentConfig(SerialNumber_);
|
||||
if(GoodConfig && (GoodConfig==UUID || GoodConfig==Conn_->Conn_.PendingUUID))
|
||||
if(GoodConfig && (GoodConfig==UUID || GoodConfig==Conn_->PendingUUID))
|
||||
return false;
|
||||
|
||||
GWObjects::Device D;
|
||||
@@ -225,10 +221,10 @@ namespace OpenWifi {
|
||||
return false;
|
||||
}
|
||||
|
||||
Conn_->Conn_.PendingUUID = D.UUID;
|
||||
Conn_->PendingUUID = D.UUID;
|
||||
GWObjects::CommandDetails Cmd;
|
||||
Cmd.SerialNumber = SerialNumber_;
|
||||
Cmd.UUID = MicroService::CreateUUID();
|
||||
Cmd.UUID = MicroService::instance().CreateUUID();
|
||||
Cmd.SubmittedBy = uCentralProtocol::SUBMITTED_BY_SYSTEM;
|
||||
Cmd.Status = uCentralProtocol::PENDING;
|
||||
Cmd.Command = uCentralProtocol::CONFIGURE;
|
||||
@@ -273,10 +269,6 @@ namespace OpenWifi {
|
||||
CommandManager()->PostCommandResult(SerialNumber_, Doc);
|
||||
}
|
||||
|
||||
static bool IsSimSerialNumber(const std::string & SerialNumber) {
|
||||
return SerialNumber.substr(0,6) == "53494d";
|
||||
}
|
||||
|
||||
void WSConnection::ProcessJSONRPCEvent(Poco::JSON::Object::Ptr & Doc) {
|
||||
|
||||
auto Method = Doc->get(uCentralProtocol::METHOD).toString();
|
||||
@@ -328,7 +320,7 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
if(Conn_!= nullptr)
|
||||
Conn_->Conn_.LastContact = std::time(nullptr);
|
||||
Conn_->LastContact = std::time(nullptr);
|
||||
|
||||
switch(EventType) {
|
||||
case uCentralProtocol::ET_CONNECT: {
|
||||
@@ -341,16 +333,16 @@ namespace OpenWifi {
|
||||
|
||||
Conn_ = DeviceRegistry()->Register(Serial, this);
|
||||
SerialNumber_ = Serial;
|
||||
Conn_->Conn_.SerialNumber = Serial;
|
||||
Conn_->Conn_.UUID = UUID;
|
||||
Conn_->Conn_.Firmware = Firmware;
|
||||
Conn_->Conn_.PendingUUID = 0;
|
||||
Conn_->Conn_.LastContact = std::time(nullptr);
|
||||
Conn_->Conn_.Address = Utils::FormatIPv6(WS_->peerAddress().toString());
|
||||
Conn_->SerialNumber = Serial;
|
||||
Conn_->UUID = UUID;
|
||||
Conn_->Firmware = Firmware;
|
||||
Conn_->PendingUUID = 0;
|
||||
Conn_->LastContact = std::time(nullptr);
|
||||
Conn_->Address = Utils::FormatIPv6(WS_->peerAddress().toString());
|
||||
CId_ = SerialNumber_ + "@" + CId_ ;
|
||||
|
||||
// We need to verify the certificate if we have one
|
||||
if(!CN_.empty() && (Utils::SerialNumberMatch(CN_,SerialNumber_) || IsSimSerialNumber(CN_))) {
|
||||
if(!CN_.empty() && Utils::SerialNumberMatch(CN_,SerialNumber_)) {
|
||||
CertValidation_ = GWObjects::VERIFIED;
|
||||
Logger_.information(Poco::format("CONNECT(%s): Fully validated and authenticated device..", CId_));
|
||||
} else {
|
||||
@@ -359,7 +351,7 @@ namespace OpenWifi {
|
||||
else
|
||||
Logger_.information(Poco::format("CONNECT(%s): Authenticated but not validated. Serial='%s' CN='%s'", CId_, Serial, CN_));
|
||||
}
|
||||
Conn_->Conn_.VerifiedCertificate = CertValidation_;
|
||||
Conn_->VerifiedCertificate = CertValidation_;
|
||||
|
||||
if (Daemon()->AutoProvisioning() && !StorageService()->DeviceExists(SerialNumber_)) {
|
||||
StorageService()->CreateDefaultDevice(SerialNumber_, Capabilities, Firmware, Compatible_);
|
||||
@@ -369,9 +361,9 @@ namespace OpenWifi {
|
||||
StorageService()->SetConnectInfo(SerialNumber_, Firmware );
|
||||
}
|
||||
}
|
||||
Conn_->Conn_.Compatible = Compatible_;
|
||||
Conn_->Compatible = Compatible_;
|
||||
|
||||
StatsProcessor_ = std::make_unique<StateProcessor>(Conn_, Logger_);
|
||||
StatsProcessor_ = std::make_unique<StateProcessor>(Conn_);
|
||||
StatsProcessor_->Initialize(Serial);
|
||||
LookForUpgrade(UUID);
|
||||
|
||||
@@ -410,7 +402,7 @@ namespace OpenWifi {
|
||||
else
|
||||
Logger_.debug(Poco::format("STATE(%s): UUID=%Lu Updating for CMD=%s.", CId_,
|
||||
UUID, request_uuid));
|
||||
Conn_->Conn_.UUID = UUID;
|
||||
Conn_->UUID = UUID;
|
||||
LookForUpgrade(UUID);
|
||||
GWObjects::Statistics Stats{ .SerialNumber = SerialNumber_, .UUID = UUID, .Data = State};
|
||||
Stats.Recorded = std::time(nullptr);
|
||||
@@ -419,7 +411,8 @@ namespace OpenWifi {
|
||||
StorageService()->SetCommandResult(request_uuid, State);
|
||||
}
|
||||
|
||||
StatsProcessor_->Add(State);
|
||||
if (StatsProcessor_)
|
||||
StatsProcessor_->Add(State);
|
||||
|
||||
if(KafkaManager()->Enabled()) {
|
||||
Poco::JSON::Stringifier Stringify;
|
||||
@@ -458,7 +451,7 @@ namespace OpenWifi {
|
||||
Logger_.debug(Poco::format("HEALTHCHECK(%s): UUID=%Lu Updating for CMD=%s.",
|
||||
CId_, UUID, request_uuid));
|
||||
|
||||
Conn_->Conn_.UUID = UUID;
|
||||
Conn_->UUID = UUID;
|
||||
LookForUpgrade(UUID);
|
||||
|
||||
GWObjects::HealthCheck Check;
|
||||
@@ -513,7 +506,7 @@ namespace OpenWifi {
|
||||
.Severity = Severity,
|
||||
.Recorded = (uint64_t)time(nullptr),
|
||||
.LogType = 0,
|
||||
.UUID = Conn_->Conn_.UUID};
|
||||
.UUID = Conn_->UUID};
|
||||
StorageService()->AddLog(DeviceLog);
|
||||
} else {
|
||||
Logger_.warning(Poco::format("LOG(%s): Missing parameters.", CId_));
|
||||
@@ -609,7 +602,7 @@ namespace OpenWifi {
|
||||
if(ParamsObj->get(uCentralProtocol::REBOOT).toString()=="true") {
|
||||
GWObjects::CommandDetails Cmd;
|
||||
Cmd.SerialNumber = SerialNumber_;
|
||||
Cmd.UUID = MicroService::CreateUUID();
|
||||
Cmd.UUID = MicroService::instance().CreateUUID();
|
||||
Cmd.SubmittedBy = uCentralProtocol::SUBMITTED_BY_SYSTEM;
|
||||
Cmd.Status = uCentralProtocol::PENDING;
|
||||
Cmd.Command = uCentralProtocol::REBOOT;
|
||||
@@ -716,7 +709,7 @@ namespace OpenWifi {
|
||||
|
||||
void WSConnection::ProcessIncomingFrame() {
|
||||
|
||||
// bool MustDisconnect=false;
|
||||
bool MustDisconnect=false;
|
||||
Poco::Buffer<char> IncomingFrame(0);
|
||||
|
||||
try {
|
||||
@@ -727,28 +720,18 @@ namespace OpenWifi {
|
||||
|
||||
if (IncomingSize == 0 && flags == 0 && Op == 0) {
|
||||
Logger_.information(Poco::format("DISCONNECT(%s): device has disconnected.", CId_));
|
||||
return delete this;
|
||||
MustDisconnect = true;
|
||||
} else {
|
||||
|
||||
if (Conn_ != nullptr) {
|
||||
Conn_->Conn_.RX += IncomingSize;
|
||||
Conn_->Conn_.MessageCount++;
|
||||
}
|
||||
|
||||
switch (Op) {
|
||||
case Poco::Net::WebSocket::FRAME_OP_PING: {
|
||||
Logger_.debug(Poco::format("WS-PING(%s): received. PONG sent back.", CId_));
|
||||
WS_->sendFrame("", 0,
|
||||
(int)Poco::Net::WebSocket::FRAME_OP_PONG |
|
||||
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
|
||||
if (Conn_ != nullptr) {
|
||||
Conn_->Conn_.MessageCount++;
|
||||
}
|
||||
|
||||
if (KafkaManager()->Enabled() && Conn_) {
|
||||
Poco::JSON::Object PingObject;
|
||||
Poco::JSON::Object PingDetails;
|
||||
PingDetails.set(uCentralProtocol::FIRMWARE, Conn_->Conn_.Firmware);
|
||||
PingDetails.set(uCentralProtocol::FIRMWARE, Conn_->Firmware);
|
||||
PingDetails.set(uCentralProtocol::SERIALNUMBER, SerialNumber_);
|
||||
PingDetails.set(uCentralProtocol::COMPATIBLE, Compatible_);
|
||||
PingDetails.set(uCentralProtocol::CONNECTIONIP, CId_);
|
||||
@@ -759,49 +742,46 @@ namespace OpenWifi {
|
||||
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber_,
|
||||
OS.str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case Poco::Net::WebSocket::FRAME_OP_PONG: {
|
||||
Logger_.debug(Poco::format("PONG(%s): received and ignored.",CId_));
|
||||
return;
|
||||
Logger_.debug(Poco::format("PONG(%s): received and ignored.",CId_));
|
||||
}
|
||||
break;
|
||||
|
||||
case Poco::Net::WebSocket::FRAME_OP_TEXT: {
|
||||
std::string IncomingMessageStr = asString(IncomingFrame);
|
||||
Logger_.debug(Poco::format("FRAME(%s): Frame received (length=%d, flags=0x%x). Msg=%s",
|
||||
CId_, IncomingSize, unsigned(flags),IncomingMessageStr));
|
||||
std::string IncomingMessageStr = asString(IncomingFrame);
|
||||
Logger_.debug(Poco::format("FRAME(%s): Frame received (length=%d, flags=0x%x). Msg=%s",
|
||||
CId_, IncomingSize, unsigned(flags),IncomingMessageStr));
|
||||
|
||||
Poco::JSON::Parser parser;
|
||||
auto ParsedMessage = parser.parse(IncomingMessageStr);
|
||||
auto IncomingJSON = ParsedMessage.extract<Poco::JSON::Object::Ptr>();
|
||||
Poco::JSON::Parser parser;
|
||||
auto ParsedMessage = parser.parse(IncomingMessageStr);
|
||||
auto IncomingJSON = ParsedMessage.extract<Poco::JSON::Object::Ptr>();
|
||||
|
||||
if (IncomingJSON->has(uCentralProtocol::JSONRPC)) {
|
||||
if(IncomingJSON->has(uCentralProtocol::METHOD) &&
|
||||
IncomingJSON->has(uCentralProtocol::PARAMS)) {
|
||||
ProcessJSONRPCEvent(IncomingJSON);
|
||||
} else if (IncomingJSON->has(uCentralProtocol::RESULT) &&
|
||||
IncomingJSON->has(uCentralProtocol::ID)) {
|
||||
Logger_.debug(Poco::format("RPC-RESULT(%s): payload: %s",CId_,IncomingMessageStr));
|
||||
ProcessJSONRPCResult(IncomingJSON);
|
||||
} else {
|
||||
Logger_.warning(Poco::format(
|
||||
"INVALID-PAYLOAD(%s): Payload is not JSON-RPC 2.0: %s", CId_,
|
||||
IncomingMessageStr));
|
||||
}
|
||||
} else {
|
||||
Logger_.error(Poco::format("FRAME(%s): illegal transaction header, missing 'jsonrpc'",CId_));
|
||||
Errors_++;
|
||||
if (IncomingJSON->has(uCentralProtocol::JSONRPC)) {
|
||||
if(IncomingJSON->has(uCentralProtocol::METHOD) &&
|
||||
IncomingJSON->has(uCentralProtocol::PARAMS)) {
|
||||
ProcessJSONRPCEvent(IncomingJSON);
|
||||
} else if (IncomingJSON->has(uCentralProtocol::RESULT) &&
|
||||
IncomingJSON->has(uCentralProtocol::ID)) {
|
||||
Logger_.debug(Poco::format("RPC-RESULT(%s): payload: %s",CId_,IncomingMessageStr));
|
||||
ProcessJSONRPCResult(IncomingJSON);
|
||||
} else {
|
||||
Logger_.warning(Poco::format(
|
||||
"INVALID-PAYLOAD(%s): Payload is not JSON-RPC 2.0: %s", CId_,
|
||||
IncomingMessageStr));
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
Logger_.error(Poco::format("FRAME(%s): illegal transaction header, missing 'jsonrpc'",CId_));
|
||||
Errors_++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
|
||||
Logger_.warning(Poco::format("CLOSE(%s): Device is closing its connection.",CId_));
|
||||
return delete this;
|
||||
MustDisconnect = true;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -810,6 +790,11 @@ namespace OpenWifi {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (Conn_ != nullptr) {
|
||||
Conn_->RX += IncomingSize;
|
||||
Conn_->MessageCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const Poco::Net::ConnectionResetException & E)
|
||||
@@ -817,7 +802,7 @@ namespace OpenWifi {
|
||||
std::string IncomingMessageStr = asString(IncomingFrame);
|
||||
Logger_.warning(Poco::format("%s(%s): Caught a ConnectionResetException: %s, Message: %s",
|
||||
std::string(__func__), CId_, E.displayText(),IncomingMessageStr));
|
||||
return delete this;
|
||||
MustDisconnect= true;
|
||||
}
|
||||
catch (const Poco::JSON::JSONException & E)
|
||||
{
|
||||
@@ -830,54 +815,57 @@ namespace OpenWifi {
|
||||
std::string IncomingMessageStr = asString(IncomingFrame);
|
||||
Logger_.warning(Poco::format("%s(%s): Caught a websocket exception: %s. Message: %s",
|
||||
std::string(__func__), CId_, E.displayText(), IncomingMessageStr ));
|
||||
return delete this;
|
||||
MustDisconnect = true ;
|
||||
}
|
||||
catch (const Poco::Net::SSLConnectionUnexpectedlyClosedException & E)
|
||||
{
|
||||
std::string IncomingMessageStr = asString(IncomingFrame);
|
||||
Logger_.warning(Poco::format("%s(%s): Caught a SSLConnectionUnexpectedlyClosedException: %s. Message: %s",
|
||||
std::string(__func__), CId_, E.displayText(), IncomingMessageStr ));
|
||||
return delete this;
|
||||
MustDisconnect = true ;
|
||||
}
|
||||
catch (const Poco::Net::SSLException & E)
|
||||
{
|
||||
std::string IncomingMessageStr = asString(IncomingFrame);
|
||||
Logger_.warning(Poco::format("%s(%s): Caught a SSL exception: %s. Message: %s",
|
||||
std::string(__func__), CId_, E.displayText(), IncomingMessageStr ));
|
||||
return delete this;
|
||||
MustDisconnect = true ;
|
||||
}
|
||||
catch (const Poco::Net::NetException & E) {
|
||||
std::string IncomingMessageStr = asString(IncomingFrame);
|
||||
Logger_.warning( Poco::format("%s(%s): Caught a NetException: %s. Message: %s",
|
||||
std::string(__func__), CId_, E.displayText(), IncomingMessageStr ));
|
||||
return delete this;
|
||||
MustDisconnect = true ;
|
||||
}
|
||||
catch (const Poco::IOException & E) {
|
||||
std::string IncomingMessageStr = asString(IncomingFrame);
|
||||
Logger_.warning( Poco::format("%s(%s): Caught a IOException: %s. Message: %s",
|
||||
std::string(__func__), CId_, E.displayText(), IncomingMessageStr ));
|
||||
return delete this;
|
||||
MustDisconnect = true ;
|
||||
}
|
||||
catch (const Poco::Exception &E) {
|
||||
std::string IncomingMessageStr = asString(IncomingFrame);
|
||||
Logger_.warning( Poco::format("%s(%s): Caught a more generic Poco exception: %s. Message: %s",
|
||||
std::string(__func__), CId_, E.displayText(), IncomingMessageStr ));
|
||||
return delete this;
|
||||
MustDisconnect = true ;
|
||||
}
|
||||
catch (const std::exception & E) {
|
||||
std::string IncomingMessageStr = asString(IncomingFrame);
|
||||
Logger_.warning( Poco::format("%s(%s): Caught a std::exception: %s. Message: %s",
|
||||
std::string{__func__}, CId_, std::string{E.what()}, IncomingMessageStr) );
|
||||
return delete this;
|
||||
MustDisconnect = true ;
|
||||
}
|
||||
catch (...) {
|
||||
return delete this;
|
||||
MustDisconnect = true;
|
||||
}
|
||||
|
||||
if(Errors_<10)
|
||||
return;
|
||||
if(!MustDisconnect && Errors_<10)
|
||||
return;
|
||||
|
||||
if(Errors_>10) {
|
||||
Logger_.information(Poco::format("DISCONNECTING(%s): Too many errors",CId_));
|
||||
}
|
||||
|
||||
Logger_.information(Poco::format("DISCONNECTING(%s): Too many errors",CId_));
|
||||
delete this;
|
||||
}
|
||||
|
||||
@@ -886,7 +874,7 @@ namespace OpenWifi {
|
||||
|
||||
auto BytesSent = WS_->sendFrame(Payload.c_str(),(int)Payload.size());
|
||||
if(Conn_)
|
||||
Conn_->Conn_.TX += BytesSent;
|
||||
Conn_->TX += BytesSent;
|
||||
return BytesSent == Payload.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace OpenWifi {
|
||||
std::unique_ptr<Poco::Net::WebSocket> WS_;
|
||||
std::string SerialNumber_;
|
||||
std::string Compatible_;
|
||||
std::shared_ptr<DeviceRegistry::ConnectionEntry> Conn_;
|
||||
GWObjects::ConnectionState * Conn_ = nullptr;
|
||||
bool Registered_ = false ;
|
||||
std::string CId_;
|
||||
std::string CN_;
|
||||
@@ -117,7 +117,9 @@ namespace OpenWifi {
|
||||
class WebSocketServer : public SubSystemServer {
|
||||
public:
|
||||
static WebSocketServer *instance() {
|
||||
static WebSocketServer *instance_ = new WebSocketServer;
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new WebSocketServer;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
@@ -129,16 +131,13 @@ namespace OpenWifi {
|
||||
Poco::Net::SocketReactor & GetNextReactor() { return ReactorPool_.NextReactor(); }
|
||||
|
||||
private:
|
||||
static WebSocketServer *instance_;
|
||||
std::unique_ptr<Poco::Crypto::X509Certificate> IssuerCert_;
|
||||
std::vector<std::unique_ptr<Poco::Net::ParallelSocketAcceptor<WSConnection, Poco::Net::SocketReactor>>> Acceptors_;
|
||||
Poco::Net::SocketReactor Reactor_;
|
||||
Poco::Thread ReactorThread_;
|
||||
ReactorPool ReactorPool_;
|
||||
|
||||
WebSocketServer() noexcept:
|
||||
SubSystemServer("WebSocketServer", "WS-SVR", "ucentral.websocket") {
|
||||
|
||||
}
|
||||
WebSocketServer() noexcept;
|
||||
};
|
||||
|
||||
inline WebSocketServer * WebSocketServer() { return WebSocketServer::instance(); }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -47,19 +47,13 @@ namespace OpenWifi::RESTAPI::Errors {
|
||||
static const std::string IdMustBe0{"To create a user, you must set the ID to 0"};
|
||||
static const std::string InvalidUserRole{"Invalid userRole."};
|
||||
static const std::string InvalidEmailAddress{"Invalid email address."};
|
||||
static const std::string InvalidPassword{"Invalid password."};
|
||||
static const std::string PasswordRejected{"Password was rejected. This maybe an old password."};
|
||||
static const std::string InvalidIPRanges{"Invalid IP range specifications."};
|
||||
static const std::string InvalidLOrderBy{"Invalid orderBy specification."};
|
||||
static const std::string NeedMobileNumber{"You must provide at least one validated phone number."};
|
||||
static const std::string BadMFAMethod{"MFA only supports sms or email."};
|
||||
static const std::string InvalidCredentials{"Invalid credentials (username/password)."};
|
||||
static const std::string InvalidPassword{"Password does not conform to basic password rules."};
|
||||
static const std::string UserPendingVerification{"User access denied pending email verification."};
|
||||
static const std::string PasswordMustBeChanged{"Password must be changed."};
|
||||
static const std::string UnrecognizedRequest{"Ill-formed request. Please consult documentation."};
|
||||
static const std::string MissingAuthenticationInformation{"Missing authentication information."};
|
||||
static const std::string InsufficientAccessRights{"Insufficient access rights to complete the operation."};
|
||||
static const std::string ExpiredToken{"Token has expired, user must login."};
|
||||
|
||||
}
|
||||
|
||||
#endif //OWPROV_RESTAPI_ERRORS_H
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// Created by stephane bourque on 2021-10-06.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#ifndef OPENWIFI_STORAGE_H
|
||||
#define OPENWIFI_STORAGE_H
|
||||
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/SessionPool.h"
|
||||
@@ -25,6 +26,13 @@ namespace OpenWifi {
|
||||
|
||||
class StorageClass : public SubSystemServer {
|
||||
public:
|
||||
/* static StorageClass *instance() {
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new StorageClass;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
*/
|
||||
StorageClass() noexcept:
|
||||
SubSystemServer("StorageClass", "STORAGE-SVR", "storage")
|
||||
{
|
||||
@@ -48,18 +56,18 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
void Stop() override {
|
||||
Pool_->shutdown();
|
||||
|
||||
}
|
||||
|
||||
[[nodiscard]] inline std::string ComputeRange(uint64_t From, uint64_t HowMany) {
|
||||
if(dbType_==sqlite) {
|
||||
return " LIMIT " + std::to_string(From) + ", " + std::to_string(HowMany) + " ";
|
||||
return " LIMIT " + std::to_string(From-1) + ", " + std::to_string(HowMany) + " ";
|
||||
} else if(dbType_==pgsql) {
|
||||
return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From) + " ";
|
||||
return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From-1) + " ";
|
||||
} else if(dbType_==mysql) {
|
||||
return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From) + " ";
|
||||
return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From-1) + " ";
|
||||
}
|
||||
return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From) + " ";
|
||||
return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From-1) + " ";
|
||||
}
|
||||
|
||||
inline std::string ConvertParams(const std::string & S) const {
|
||||
@@ -88,13 +96,15 @@ namespace OpenWifi {
|
||||
inline int Setup_PostgreSQL();
|
||||
|
||||
protected:
|
||||
Poco::SharedPtr<Poco::Data::SessionPool> Pool_;
|
||||
Poco::Data::SQLite::Connector SQLiteConn_;
|
||||
Poco::Data::PostgreSQL::Connector PostgresConn_;
|
||||
Poco::Data::MySQL::Connector MySQLConn_;
|
||||
DBType dbType_ = sqlite;
|
||||
std::unique_ptr<Poco::Data::SessionPool> Pool_;
|
||||
std::unique_ptr<Poco::Data::SQLite::Connector> SQLiteConn_;
|
||||
std::unique_ptr<Poco::Data::PostgreSQL::Connector> PostgresConn_;
|
||||
std::unique_ptr<Poco::Data::MySQL::Connector> MySQLConn_;
|
||||
DBType dbType_ = sqlite;
|
||||
};
|
||||
|
||||
// inline StorageClass * Storage() { return StorageClass::instance(); }
|
||||
|
||||
#ifdef SMALL_BUILD
|
||||
int Service::Setup_MySQL() { Daemon()->exit(Poco::Util::Application::EXIT_CONFIG); return 0; }
|
||||
int Service::Setup_PostgreSQL() { Daemon()->exit(Poco::Util::Application::EXIT_CONFIG); return 0; }
|
||||
@@ -106,8 +116,9 @@ namespace OpenWifi {
|
||||
auto DBName = MicroService::instance().DataDir() + "/" + MicroService::instance().ConfigGetString("storage.type.sqlite.db");
|
||||
auto NumSessions = MicroService::instance().ConfigGetInt("storage.type.sqlite.maxsessions", 64);
|
||||
auto IdleTime = MicroService::instance().ConfigGetInt("storage.type.sqlite.idletime", 60);
|
||||
SQLiteConn_.registerConnector();
|
||||
Pool_ = Poco::SharedPtr<Poco::Data::SessionPool>(new Poco::Data::SessionPool(SQLiteConn_.name(), DBName, 4, NumSessions, IdleTime));
|
||||
SQLiteConn_ = std::make_unique<Poco::Data::SQLite::Connector>();
|
||||
SQLiteConn_->registerConnector();
|
||||
Pool_ = std::make_unique<Poco::Data::SessionPool>(SQLiteConn_->name(), DBName, 4, NumSessions, IdleTime);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -130,8 +141,9 @@ namespace OpenWifi {
|
||||
";port=" + Port +
|
||||
";compress=true;auto-reconnect=true";
|
||||
|
||||
MySQLConn_.registerConnector();
|
||||
Pool_ = Poco::SharedPtr<Poco::Data::SessionPool>(new Poco::Data::SessionPool(MySQLConn_.name(), ConnectionStr, 4, NumSessions, IdleTime));
|
||||
MySQLConn_ = std::make_unique<Poco::Data::MySQL::Connector>();
|
||||
MySQLConn_->registerConnector();
|
||||
Pool_ = std::make_unique<Poco::Data::SessionPool>(MySQLConn_->name(), ConnectionStr, 4, NumSessions, IdleTime);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -156,11 +168,14 @@ namespace OpenWifi {
|
||||
" port=" + Port +
|
||||
" connect_timeout=" + ConnectionTimeout;
|
||||
|
||||
PostgresConn_.registerConnector();
|
||||
Pool_ = Poco::SharedPtr<Poco::Data::SessionPool>(new Poco::Data::SessionPool(PostgresConn_.name(), ConnectionStr, 4, NumSessions, IdleTime));
|
||||
PostgresConn_ = std::make_unique<Poco::Data::PostgreSQL::Connector>();
|
||||
PostgresConn_->registerConnector();
|
||||
Pool_ = std::make_unique<Poco::Data::SessionPool>(PostgresConn_->name(), ConnectionStr, 4, NumSessions, IdleTime);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif //OPENWIFI_STORAGE_H
|
||||
|
||||
@@ -157,8 +157,9 @@ typedef Poco::Tuple<
|
||||
bool DatesIncluded = (FromDate != 0 || ToDate != 0);
|
||||
|
||||
std::string Fields{
|
||||
"SELECT " + DB_Command_SelectFields + " FROM CommandList " };
|
||||
|
||||
"SELECT " +
|
||||
DB_Command_SelectFields +
|
||||
" FROM CommandList ORDER BY UUID ASC "};
|
||||
std::string IntroStatement = SerialNumber.empty()
|
||||
? Fields + std::string(DatesIncluded ? "WHERE " : "")
|
||||
: Fields + "WHERE SerialNumber='" + SerialNumber + "'" +
|
||||
@@ -176,12 +177,7 @@ typedef Poco::Tuple<
|
||||
|
||||
Poco::Data::Statement Select(Sess);
|
||||
|
||||
std::string FullQuery = IntroStatement + DateSelector +
|
||||
" ORDER BY Submitted ASC " + ComputeRange(Offset, HowMany);
|
||||
|
||||
// std::cout << "Offset: " << Offset << " >> " << FullQuery << std::endl;
|
||||
|
||||
Select << FullQuery,
|
||||
Select << IntroStatement + DateSelector + ComputeRange(Offset, HowMany),
|
||||
Poco::Data::Keywords::into(Records);
|
||||
Select.execute();
|
||||
for (const auto &i : Records) {
|
||||
@@ -359,10 +355,12 @@ typedef Poco::Tuple<
|
||||
|
||||
std::string st{"SELECT " +
|
||||
DB_Command_SelectFields +
|
||||
" FROM CommandList WHERE SerialNumber=? ORDER BY Submitted DESC " + ComputeRange(0, HowMany)};
|
||||
" FROM CommandList WHERE SerialNumber=? ORDER BY Submitted DESC"};
|
||||
|
||||
Select << ConvertParams(st),
|
||||
Poco::Data::Keywords::into(Records),
|
||||
Poco::Data::Keywords::use(SerialNumber);
|
||||
Poco::Data::Keywords::use(SerialNumber),
|
||||
Poco::Data::Keywords::limit(HowMany);
|
||||
Select.execute();
|
||||
|
||||
for (auto i : Records) {
|
||||
@@ -679,7 +677,7 @@ typedef Poco::Tuple<
|
||||
while(More) {
|
||||
auto Command = RSet[0].convert<std::string>();
|
||||
if(!Command.empty())
|
||||
OpenWifi::Types::UpdateCountedMap(R,Command);
|
||||
Types::UpdateCountedMap(R,Command);
|
||||
More = RSet.moveNext();
|
||||
}
|
||||
return true;
|
||||
@@ -689,4 +687,4 @@ typedef Poco::Tuple<
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -414,23 +414,14 @@ namespace OpenWifi {
|
||||
// std::lock_guard<std::mutex> guard(Mutex_);
|
||||
|
||||
try {
|
||||
std::vector<std::string> DBList{"Devices", "Statistics", "CommandList", "HealthChecks", "LifetimeStats", "Capabilities", "DeviceLogs"};
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Delete(Sess);
|
||||
|
||||
for(const auto &i:DBList) {
|
||||
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Delete(Sess);
|
||||
|
||||
std::string St{"DELETE FROM " + i + " WHERE SerialNumber=?"};
|
||||
try {
|
||||
Delete << ConvertParams(St),
|
||||
Poco::Data::Keywords::use(SerialNumber);
|
||||
Delete.execute();
|
||||
} catch (...) {
|
||||
|
||||
}
|
||||
}
|
||||
std::string St{"DELETE FROM Devices WHERE SerialNumber=?"};
|
||||
|
||||
Delete << ConvertParams(St),
|
||||
Poco::Data::Keywords::use(SerialNumber);
|
||||
Delete.execute();
|
||||
SerialNumberCache()->DeleteSerialNumber(SerialNumber);
|
||||
return true;
|
||||
}
|
||||
@@ -733,8 +724,6 @@ namespace OpenWifi {
|
||||
GWObjects::HealthCheck HC;
|
||||
if(DeviceRegistry()->GetHealthcheck(SerialNumber,HC))
|
||||
Types::UpdateCountedMap(Dashboard.healths, ComputeSanityTag(HC.Sanity));
|
||||
else
|
||||
Types::UpdateCountedMap(Dashboard.healths, ComputeSanityTag(100));
|
||||
std::string LastStats;
|
||||
if(DeviceRegistry()->GetStatistics(SerialNumber, LastStats) && !LastStats.empty()) {
|
||||
Poco::JSON::Parser P;
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace OpenWifi {
|
||||
|
||||
std::string st{"SELECT " + DB_HealthCheckSelectFields + " FROM HealthChecks WHERE SerialNumber=? ORDER BY Recorded DESC "};
|
||||
|
||||
Select << ConvertParams(st) + ComputeRange(0,HowMany),
|
||||
Select << ConvertParams(st) + ComputeRange(1,HowMany),
|
||||
Poco::Data::Keywords::into(Records),
|
||||
Poco::Data::Keywords::use(SerialNumber);
|
||||
Select.execute();
|
||||
|
||||
@@ -161,7 +161,7 @@ namespace OpenWifi {
|
||||
Poco::Data::Statement Select(Sess);
|
||||
|
||||
|
||||
std::string st{"SELECT " + DB_LogsSelectFields + " FROM DeviceLogs WHERE SerialNumber=? AND LogType=? ORDER BY Recorded DESC " + ComputeRange(0, HowMany)};
|
||||
std::string st{"SELECT " + DB_LogsSelectFields + " FROM DeviceLogs WHERE SerialNumber=? AND LogType=? ORDER BY Recorded DESC " + ComputeRange(1, HowMany)};
|
||||
Select << ConvertParams(st),
|
||||
Poco::Data::Keywords::into(Records),
|
||||
Poco::Data::Keywords::use(SerialNumber),
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace OpenWifi {
|
||||
std::string St{"SELECT " +
|
||||
DB_StatsSelectFields +
|
||||
" FROM Statistics WHERE SerialNumber=? ORDER BY Recorded DESC "};
|
||||
Select << ConvertParams(St) + ComputeRange(0, HowMany),
|
||||
Select << ConvertParams(St) + ComputeRange(1, HowMany),
|
||||
Poco::Data::Keywords::into(Records),
|
||||
Poco::Data::Keywords::use(SerialNumber);
|
||||
Select.execute();
|
||||
|
||||
@@ -35,7 +35,7 @@ fi
|
||||
token=""
|
||||
result_file=result.json
|
||||
username="tip@ucentral.com"
|
||||
password="Snoopy99!!!"
|
||||
password="openwifi"
|
||||
browser_list=(firefox sensible-browser xdg-open w3m links links2 lynx youtube-dl)
|
||||
browser=""
|
||||
|
||||
@@ -106,7 +106,7 @@ setgateway() {
|
||||
fi
|
||||
fi
|
||||
done
|
||||
# echo "Using ${OWGW}..."
|
||||
echo "Using ${OWGW}..."
|
||||
}
|
||||
|
||||
logout() {
|
||||
@@ -137,7 +137,7 @@ deletecommand() {
|
||||
}
|
||||
|
||||
listcommands() {
|
||||
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/commands?serialNumber=$1&limit=300" \
|
||||
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/commands?serialNumber=$1&limit=3000" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
jq < ${result_file}
|
||||
@@ -157,7 +157,7 @@ deletecommands() {
|
||||
}
|
||||
|
||||
getcapabilities() {
|
||||
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/capabilities" \
|
||||
curl -${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/capabilities" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
jq < ${result_file}
|
||||
@@ -189,13 +189,6 @@ deletedevice() {
|
||||
-H "Authorization: Bearer ${token}"
|
||||
}
|
||||
|
||||
deleteoui() {
|
||||
curl ${FLAGS} -X DELETE "https://${OWGW}/api/v1/device/$1?oui=true" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}"
|
||||
}
|
||||
|
||||
|
||||
createdevice() {
|
||||
payload="{ \"serialNumber\": \"$1\", \"UUID\": 1234456, \"configuration\" : $(cat "$2") , \"deviceType\": \"AP\",\"location\": \"\", \"macAddress\": \"$3\", \"manufacturer\": \"Linksys EA8300 (Dallas)\", \"owner\": \"\" }"
|
||||
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1" \
|
||||
@@ -687,7 +680,6 @@ case "$1" in
|
||||
"deletecapabilities") login; deletecapabilities "$2" ; logout ;;
|
||||
"listdevices") login; listdevices ; logout ;;
|
||||
"deletedevice") login; deletedevice "$2" ; logout ;;
|
||||
"deleteoui") login; deleteoui "$2" ; logout ;;
|
||||
"createdevice") login; createdevice "$2" "$3" "$4" ; logout ;;
|
||||
"reboot") login; reboot "$2" ; logout ;;
|
||||
"getdevicestatus") login; getdevicestatus "$2" ; logout ;;
|
||||
|
||||
Reference in New Issue
Block a user