Compare commits

..

18 Commits

Author SHA1 Message Date
oblom0v
fde3917fad Change image tag to rc version 2021-08-31 13:44:07 +02:00
Johann Hoffmann
d1ccf3fd0b Change ownership of uCentralFMS root directory inside Dockerfile (#8)
* Change ownership of uCentralFMS root directory inside Dockerfile

* Add missing colon in chown command

* No idea what the change is
2021-08-31 13:43:02 +02:00
oblom0v
6bee5277ea Add branching release model in CI 2021-08-26 20:15:17 +02:00
Dmitry Dunaev
f3966a5228 Merge pull request #7 from Telecominfraproject/feature/wifi-3150--external-db
[WIFI-3150] Add: external databases as optional dependencies for Helm chart
2021-08-24 14:21:59 +03:00
Dmitry Dunaev
7bf3ea5b1f [WIFI-3150] Add: external databases as optional dependencies for Helm chart 2021-08-23 16:32:47 +03:00
stephb9959
ed628caace Removing credentials from config file 2021-08-22 20:10:18 -07:00
stephb9959
7afc77249a Improving DB setup 2021-08-22 08:27:19 -07:00
stephb9959
f84700a397 Fixing Daemon startup code. 2021-08-21 15:15:47 -07:00
stephb9959
e43e6e892e Fixing Daemon startup code. 2021-08-21 14:36:20 -07:00
stephb9959
e89ae33f58 Move to 2.1 2021-08-21 11:40:04 -07:00
stephb9959
b9a0cc8281 Fixing error in firmware age calculation. 2021-08-17 14:47:01 -07:00
stephb9959
c91ca76717 Microservice bus cleanup. 2021-08-17 14:22:11 -07:00
stephb9959
6160958685 Microservice bus cleanup. 2021-08-17 14:20:12 -07:00
stephb9959
736fccddfe Removed some debug staements 2021-08-12 08:39:01 -07:00
stephb9959
21310ebee4 Fixing dashboard + adding firmware age average. 2021-08-12 08:37:41 -07:00
stephb9959
9f34cfe5e6 Fixing OPenAPI return values 2021-08-11 07:50:38 -07:00
stephb9959
fa4e0118e6 Fixing timing issues for some RESTAPIs. 2021-08-06 19:31:59 -07:00
Stephane Bourque
68e634f4bc Merge pull request #6 from Telecominfraproject/feature/restapi-tests
Fix: restapi requsts through NLB
2021-08-06 07:16:23 -07:00
85 changed files with 525 additions and 520 deletions

View File

@@ -7,6 +7,9 @@ on:
- '**.md'
branches:
- main
- 'release/*'
tags:
- 'v*'
pull_request:
branches:
- main
@@ -27,28 +30,36 @@ jobs:
- name: Build Docker image
run: docker build -t wlan-cloud-ucentralfms:${{ github.sha }} .
- name: Tag Docker image
run: |
TAGS="${{ github.sha }}"
if [[ ${GITHUB_REF} == "refs/heads/"* ]]
then
CURRENT_TAG=$(echo ${GITHUB_REF#refs/heads/} | tr '/' '-')
TAGS="$TAGS $CURRENT_TAG"
else
if [[ ${GITHUB_REF} == "refs/tags/"* ]]
then
CURRENT_TAG=$(echo ${GITHUB_REF#refs/tags/} | tr '/' '-')
TAGS="$TAGS $CURRENT_TAG"
else # PR build
CURRENT_TAG=$(echo ${GITHUB_HEAD_REF#refs/heads/} | tr '/' '-')
TAGS="$TAGS $CURRENT_TAG"
fi
fi
echo "Result tags: $TAGS"
for tag in $TAGS; do
docker tag wlan-cloud-ucentralfms:${{ github.sha }} ${{ env.DOCKER_REGISTRY_URL }}/ucentralfms:$tag
done
- name: Log into Docker registry
if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/pull/') || github.ref == 'refs/heads/main'
uses: docker/login-action@v1
with:
registry: ${{ env.DOCKER_REGISTRY_URL }}
username: ${{ env.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
- name: Push Docker image
- name: Push Docker images
if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/pull/') || github.ref == 'refs/heads/main'
run: |
TAGS="${{ github.sha }}"
if [ ${GITHUB_REF} == "refs/heads/main" ]
then
TAGS="$TAGS ${GITHUB_REF#refs/heads/}"
else # PR build
CURRENT_TAG=$(echo ${GITHUB_HEAD_REF#refs/heads/} | tr '/' '-')
TAGS="$TAGS $CURRENT_TAG"
fi
echo "Pushing tags $TAGS"
for tag in $TAGS; do
docker tag wlan-cloud-ucentralfms:${{ github.sha }} ${{ env.DOCKER_REGISTRY_URL }}/ucentralfms:$tag
docker push ${{ env.DOCKER_REGISTRY_URL }}/ucentralfms:$tag
done
docker images | grep ${{ env.DOCKER_REGISTRY_URL }}/ucentralfms | awk -F ' ' '{print $1":"$2}' | xargs -I {} docker push {}

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13)
project(ucentralfms VERSION 2.0.0)
project(ucentralfms VERSION 2.1.0)
set(CMAKE_CXX_STANDARD 17)
@@ -53,11 +53,11 @@ add_executable( ucentralfms
src/Dashboard.cpp src/Dashboard.h
src/Daemon.cpp src/Daemon.h
src/StorageService.cpp src/StorageService.h
src/storage_tables.cpp src/storage_sqlite.cpp
src/storage_tables.cpp
src/storage_setup.cpp
src/SubSystemServer.cpp src/SubSystemServer.h
src/RESTAPI_handler.cpp src/RESTAPI_handler.h
src/storage_firmwares.cpp
src/storage_mysql.cpp src/storage_pgql.cpp
src/Utils.cpp src/Utils.h
src/RESTAPI_server.cpp src/RESTAPI_server.h
src/RESTAPI_firmwaresHandler.cpp src/RESTAPI_firmwaresHandler.h
@@ -76,14 +76,17 @@ add_executable( ucentralfms
src/RESTAPI_FMSObjects.cpp src/RESTAPI_FMSObjects.h
src/storage_firmwares.h src/storage_history.cpp
src/storage_history.h src/storage_deviceTypes.cpp
src/storage_deviceTypes.h src/RESTAPI_historyHandler.cpp src/RESTAPI_historyHandler.h src/NewConnectionHandler.cpp src/NewConnectionHandler.h
src/RESTAPI_historyHandler.cpp src/RESTAPI_historyHandler.h
src/NewConnectionHandler.cpp src/NewConnectionHandler.h
src/LatestFirmwareCache.cpp src/LatestFirmwareCache.h
src/DeviceCache.cpp src/DeviceCache.h
src/RESTAPI_firmwareAgeHandler.cpp src/RESTAPI_firmwareAgeHandler.h
src/storage_deviceInfo.cpp src/storage_deviceInfo.h
src/RESTAPI_connectedDevicesHandler.cpp src/RESTAPI_connectedDevicesHandler.h
src/FirmwareCache.cpp src/FirmwareCache.h
src/RESTAPI_connectedDeviceHandler.cpp src/RESTAPI_connectedDeviceHandler.h src/RESTAPI_deviceReportHandler.cpp src/RESTAPI_deviceReportHandler.h)
src/RESTAPI_connectedDeviceHandler.cpp src/RESTAPI_connectedDeviceHandler.h
src/RESTAPI_deviceReportHandler.cpp src/RESTAPI_deviceReportHandler.h
src/OpenWifiTypes.h )
target_link_libraries(ucentralfms PUBLIC
${Poco_LIBRARIES} ${MySQL_LIBRARIES}

View File

@@ -57,7 +57,8 @@ RUN addgroup -S "$UCENTRALFMS_USER" && \
adduser -S -G "$UCENTRALFMS_USER" "$UCENTRALFMS_USER"
RUN mkdir /ucentral
RUN mkdir -p "$UCENTRALFMS_ROOT" "$UCENTRALFMS_CONFIG"
RUN mkdir -p "$UCENTRALFMS_ROOT" "$UCENTRALFMS_CONFIG" && \
chown "$UCENTRALFMS_USER": "$UCENTRALFMS_ROOT" "$UCENTRALFMS_CONFIG"
RUN apk add --update --no-cache librdkafka curl-dev mariadb-connector-c libpq unixodbc su-exec
COPY --from=builder /ucentralfms/cmake-build/ucentralfms /ucentral/ucentralfms

2
build
View File

@@ -1 +1 @@
7
14

View File

@@ -1,5 +1,18 @@
apiVersion: v1
apiVersion: v2
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: ucentralfms
version: 0.1.0
dependencies:
- name: postgresql
repository: https://charts.bitnami.com/bitnami
version: 10.9.2
condition: postgresql.enabled
- name: mysql
repository: https://charts.bitnami.com/bitnami
version: 8.8.3
condition: mysql.enabled
- name: mariadb
repository: https://charts.bitnami.com/bitnami
version: 9.4.2
condition: mariadb.enabled

View File

@@ -8,7 +8,7 @@ fullnameOverride: ""
images:
ucentralfms:
repository: tip-tip-wlan-cloud-ucentral.jfrog.io/ucentralfms
tag: main
tag: v2.1.0-RC1
pullPolicy: Always
# regcred:
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io
@@ -204,3 +204,64 @@ certs:
# restapi-ca.pem: ""
# restapi-cert.pem: ""
# restapi-key.pem: ""
# PostgreSQL (https://github.com/bitnami/charts/tree/master/bitnami/postgresql)
postgresql:
enabled: false
image:
registry: docker.io
repository: bitnami/postgresql
tag: 11.13.0-debian-10-r0
postgresqlPostgresPassword: ""
postgresqlUsername: postgres
postgresqlPassword: ""
postgresqlDatabase: ""
persistence:
enabled: true
storageClass: ""
size: 8Gi
# MySQL (https://github.com/bitnami/charts/tree/master/bitnami/mysql)
mysql:
enabled: false
image:
registry: docker.io
repository: bitnami/mysql
tag: 8.0.26-debian-10-r10
auth:
rootPassword: ""
database: my_database
username: ""
password: ""
primary:
persistence:
enabled: true
storageClass: ""
size: 8Gi
# MariaDB (https://github.com/bitnami/charts/tree/master/bitnami/mariadb)
mariadb:
enabled: false
image:
registry: docker.io
repository: bitnami/mariadb
tag: 10.5.12-debian-10-r0
auth:
rootPassword: ""
database: my_database
username: ""
password: ""
primary:
persistence:
enabled: true
storageClass: ""
size: 8Gi

View File

@@ -239,6 +239,8 @@ components:
$ref: '#/components/schemas/TagIntPairList'
usingLatest:
$ref: '#/components/schemas/TagIntPairList'
totalSecondsOld:
$ref: '#/components/schemas/TagIntPairList'
#########################################################################################
##
@@ -491,7 +493,7 @@ paths:
format: uuid
required: true
responses:
200:
204:
description: Successfully deleted Firmware for the device.
content:
application/json:
@@ -563,7 +565,7 @@ paths:
format: uuid
required: true
responses:
200:
204:
description: Success.
content:
application/json:

View File

@@ -20,7 +20,7 @@
#include "Daemon.h"
#include "SubSystemServer.h"
namespace uCentral {
namespace OpenWifi {
class ALBRequestHandler: public Poco::Net::HTTPRequestHandler
/// Return a HTML document with the current date and time.
@@ -85,7 +85,7 @@ namespace uCentral {
int Start() {
if(Daemon()->ConfigGetBool("alb.enable",false)) {
Port_ = (int)Daemon()->ConfigGetInt("alb.port",15016);
Port_ = (int)Daemon()->ConfigGetInt("alb.port",15015);
Socket_ = std::make_unique<Poco::Net::ServerSocket>(Port_);
auto Params = new Poco::Net::HTTPServerParams;
Server_ = std::make_unique<Poco::Net::HTTPServer>(new ALBRequestHandlerFactory(Logger_), *Socket_, Params);

View File

@@ -8,7 +8,7 @@
#include "Daemon.h"
#include "OpenAPIRequest.h"
namespace uCentral {
namespace OpenWifi {
class AuthClient * AuthClient::instance_ = nullptr;
int AuthClient::Start() {
@@ -38,7 +38,7 @@ namespace uCentral {
} else {
Types::StringPairVec QueryData;
QueryData.push_back(std::make_pair("token",SessionToken));
OpenAPIRequestGet Req(uSERVICE_SECURITY,
OpenAPIRequestGet Req( uSERVICE_SECURITY,
"/api/v1/validateToken",
QueryData,
5000);
@@ -56,4 +56,33 @@ namespace uCentral {
}
return false;
}
bool AuthClient::IsTokenAuthorized(const std::string &SessionToken, SecurityObjects::UserInfoAndPolicy & UInfo) {
SubMutexGuard G(Mutex_);
auto User = UserCache_.find(SessionToken);
if(User != UserCache_.end() && !IsTokenExpired(User->second.webtoken)) {
UInfo = User->second;
return true;
} else {
Types::StringPairVec QueryData;
QueryData.push_back(std::make_pair("token",SessionToken));
OpenAPIRequestGet Req(uSERVICE_SECURITY,
"/api/v1/validateToken",
QueryData,
5000);
Poco::JSON::Object::Ptr Response;
if(Req.Do(Response)==Poco::Net::HTTPResponse::HTTP_OK) {
if(Response->has("tokenInfo") && Response->has("userInfo")) {
SecurityObjects::UserInfoAndPolicy P;
P.from_json(Response);
UserCache_[SessionToken] = P;
UInfo = P;
}
return true;
}
}
return false;
}
}

View File

@@ -13,9 +13,9 @@
#include "RESTAPI_SecurityObjects.h"
#include "SubSystemServer.h"
namespace uCentral {
namespace OpenWifi {
class AuthClient : public SubSystemServer {
class AuthClient : public SubSystemServer {
public:
explicit AuthClient() noexcept:
SubSystemServer("Authentication", "AUTH-CLNT", "authentication")
@@ -31,12 +31,12 @@ namespace uCentral {
int Start() override;
void Stop() override;
bool IsAuthorized(Poco::Net::HTTPServerRequest & Request, std::string &SessionToken, SecurityObjects::UserInfoAndPolicy & UInfo );
bool IsAuthorized(Poco::Net::HTTPServerRequest & Request, std::string &SessionToken, OpenWifi::SecurityObjects::UserInfoAndPolicy & UInfo );
void RemovedCachedToken(const std::string &Token);
bool IsTokenAuthorized(const std::string &Token, SecurityObjects::UserInfoAndPolicy & UInfo);
private:
static AuthClient *instance_;
SecurityObjects::UserInfoCache UserCache_;
OpenWifi::SecurityObjects::UserInfoCache UserCache_;
};
inline AuthClient * AuthClient() { return AuthClient::instance(); }

View File

@@ -26,7 +26,7 @@
#include "DeviceCache.h"
#include "FirmwareCache.h"
namespace uCentral {
namespace OpenWifi {
class Daemon *Daemon::instance_ = nullptr;
class Daemon *Daemon::instance() {
@@ -66,7 +66,7 @@ int main(int argc, char **argv) {
int ExitCode=0;
{
auto App = uCentral::Daemon::instance();
auto App = OpenWifi::Daemon::instance();
ExitCode = App->run(argc, argv);
}

View File

@@ -16,16 +16,16 @@
#include "Poco/Crypto/Cipher.h"
#include "MicroService.h"
#include "uCentralTypes.h"
#include "OpenWifiTypes.h"
#include "RESTAPI_FMSObjects.h"
#include "Dashboard.h"
namespace uCentral {
namespace OpenWifi {
static const char * vDAEMON_PROPERTIES_FILENAME = "ucentralfms.properties";
static const char * vDAEMON_ROOT_ENV_VAR = "UCENTRALFMS_ROOT";
static const char * vDAEMON_CONFIG_ENV_VAR = "UCENTRALFMS_CONFIG";
static const char * vDAEMON_APP_NAME = "uCentralFMS";
static const char * vDAEMON_APP_NAME = uSERVICE_FIRMWARE.c_str();
static const uint64_t vDAEMON_BUS_TIMER = 10000;
class Daemon : public MicroService {

View File

@@ -5,7 +5,7 @@
#include "Dashboard.h"
#include "StorageService.h"
namespace uCentral {
namespace OpenWifi {
void DeviceDashboard::Create() {
uint64_t Now = std::time(nullptr);

View File

@@ -5,10 +5,10 @@
#ifndef UCENTRALGW_DASHBOARD_H
#define UCENTRALGW_DASHBOARD_H
#include "uCentralTypes.h"
#include "OpenWifiTypes.h"
#include "RESTAPI_FMSObjects.h"
namespace uCentral {
namespace OpenWifi {
class DeviceDashboard {
public:
void Create();

View File

@@ -4,7 +4,7 @@
#include "DeviceCache.h"
namespace uCentral {
namespace OpenWifi {
class DeviceCache *DeviceCache::instance_ = nullptr;
int DeviceCache::Start() {

View File

@@ -7,9 +7,9 @@
#include <string>
#include "SubSystemServer.h"
#include "uCentralTypes.h"
#include "OpenWifiTypes.h"
namespace uCentral {
namespace OpenWifi {
struct DeviceCacheEntry {
std::string deviceType;

View File

@@ -4,7 +4,7 @@
#include "FirmwareCache.h"
namespace uCentral {
namespace OpenWifi {
class FirmwareCache *FirmwareCache::instance_ = nullptr;
int FirmwareCache::Start() {

View File

@@ -11,7 +11,7 @@
#include "RESTAPI_FMSObjects.h"
#include "SubSystemServer.h"
namespace uCentral {
namespace OpenWifi {
typedef std::map<std::string,std::shared_ptr<FMSObjects::Firmware>> FirmwareCacheMap;

View File

@@ -12,7 +12,7 @@
#include "Daemon.h"
#include "Utils.h"
namespace uCentral {
namespace OpenWifi {
class KafkaManager *KafkaManager::instance_ = nullptr;

View File

@@ -13,11 +13,11 @@
#include <thread>
#include "SubSystemServer.h"
#include "uCentralTypes.h"
#include "OpenWifiTypes.h"
#include "cppkafka/cppkafka.h"
namespace uCentral {
namespace OpenWifi {
class KafkaManager : public SubSystemServer {
public:

View File

@@ -5,7 +5,7 @@
#ifndef UCENTRALGW_KAFKA_TOPICS_H
#define UCENTRALGW_KAFKA_TOPICS_H
namespace uCentral::KafkaTopics {
namespace OpenWifi::KafkaTopics {
static const std::string HEALTHCHECK{"healthcheck"};
static const std::string STATE{"state"};
static const std::string CONNECTION{"connection"};
@@ -13,6 +13,7 @@ namespace uCentral::KafkaTopics {
static const std::string ALERTS{"alerts"};
static const std::string COMMAND{"command"};
static const std::string SERVICE_EVENTS{"service_events"};
static const std::string DEVICE_EVENT_QUEUE{"device_event_queue"};
namespace ServiceEvents {
static const std::string EVENT_JOIN{"join"};

View File

@@ -5,7 +5,7 @@
#include "LatestFirmwareCache.h"
#include "StorageService.h"
namespace uCentral {
namespace OpenWifi {
class LatestFirmwareCache *LatestFirmwareCache::instance_ = nullptr;
int LatestFirmwareCache::Start() {

View File

@@ -13,7 +13,7 @@
#include "RESTAPI_SecurityObjects.h"
#include "SubSystemServer.h"
namespace uCentral {
namespace OpenWifi {
struct LatestFirmwareCacheEntry {
std::string Id;

View File

@@ -17,7 +17,7 @@
#include "StorageService.h"
#include "LatestFirmwareCache.h"
namespace uCentral {
namespace OpenWifi {
class ManifestCreator *ManifestCreator::instance_ = nullptr;
void ManifestCreator::run() {

View File

@@ -11,7 +11,7 @@
#include "SubSystemServer.h"
namespace uCentral {
namespace OpenWifi {
struct S3BucketEntry {
bool Valid = false;

View File

@@ -34,7 +34,7 @@
#include "AuthClient.h"
#endif
namespace uCentral {
namespace OpenWifi {
void MyErrorHandler::exception(const Poco::Exception & E) {
Poco::Thread * CurrentThread = Poco::Thread::current();
@@ -112,6 +112,16 @@ namespace uCentral {
} else {
logger().error("Bad bus message.");
}
auto i=Services_.begin();
auto Now = (uint64_t )std::time(nullptr);
for(;i!=Services_.end();) {
if((Now - i->second.LastUpdate)>60) {
i = Services_.erase(i);
} else
++i;
}
} catch (const Poco::Exception &E) {
logger().log(E);
}

View File

@@ -24,16 +24,16 @@
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Process.h"
#include "uCentralTypes.h"
#include "OpenWifiTypes.h"
#include "SubSystemServer.h"
namespace uCentral {
namespace OpenWifi {
static const std::string uSERVICE_SECURITY{"ucentralsec"};
static const std::string uSERVICE_GATEWAY{"ucentralgw"};
static const std::string uSERVICE_FIRMWARE{ "ucentralfws"};
static const std::string uSERVICE_TOPOLOGY{ "ucentraltopo"};
static const std::string uSERVICE_PROVISIONING{ "ucentralprov"};
static const std::string uSERVICE_FIRMWARE{ "ucentralfms"};
static const std::string uSERVICE_TOPOLOGY{ "owtopo"};
static const std::string uSERVICE_PROVISIONING{ "owprov"};
class MyErrorHandler : public Poco::ErrorHandler {
public:

View File

@@ -5,7 +5,7 @@
#include "NewConnectionHandler.h"
#include "Kafka_topics.h"
#include "KafkaManager.h"
#include "uCentralTypes.h"
#include "OpenWifiTypes.h"
#include "Poco/JSON/Object.h"
#include "Poco/JSON/Parser.h"
#include "StorageService.h"
@@ -19,7 +19,7 @@
"payload" : "{"capabilities":{"compatible":"linksys_ea8300","model":"Linksys EA8300 (Dallas)","network":{"lan":["eth0"],"wan":["eth1"]},"platform":"ap","switch":{"switch0":{"enable":true,"ports":[{"device":"eth0","need_tag":false,"num":0,"want_untag":true},{"num":1,"role":"lan"},{"num":2,"role":"lan"},{"num":3,"role":"lan"},{"num":4,"role":"lan"}],"reset":true,"roles":[{"device":"eth0","ports":"1 2 3 4 0","role":"lan"}]}},"wifi":{"platform/soc/a000000.wifi":{"band":["2G"],"channels":[1,2,3,4,5,6,7,8,9,10,11],"frequencies":[2412,2417,2422,2427,2432,2437,2442,2447,2452,2457,2462],"ht_capa":6639,"htmode":["HT20","HT40","VHT20","VHT40","VHT80"],"rx_ant":3,"tx_ant":3,"vht_capa":865687986},"platform/soc/a800000.wifi":{"band":["5G"],"channels":[36,40,44,48,52,56,60,64],"frequencies":[5180,5200,5220,5240,5260,5280,5300,5320],"ht_capa":6639,"htmode":["HT20","HT40","VHT20","VHT40","VHT80"],"rx_ant":3,"tx_ant":3,"vht_capa":865687986},"soc/40000000.pci/pci0000:00/0000:00:00.0/0000:01:00.0":{"band":["5G"],"channels":[100,104,108,112,116,120,124,128,132,136,140,144,149,153,157,161,165],"frequencies":[5500,5520,5540,5560,5580,5600,5620,5640,5660,5680,5700,5720,5745,5765,5785,5805,5825],"ht_capa":6639,"htmode":["HT20","HT40","VHT20","VHT40","VHT80"],"rx_ant":3,"tx_ant":3,"vht_capa":865696178}}},"firmware":"OpenWrt 21.02-SNAPSHOT r16011+53-6fd65c6573 / TIP-devel-0825cb93","serial":"24f5a207a130","uuid":1623866223}}
*/
namespace uCentral {
namespace OpenWifi {
class NewConnectionHandler *NewConnectionHandler::instance_ = nullptr;
void NewConnectionHandler::run() {
@@ -55,13 +55,13 @@ namespace uCentral {
if(Object->has(uCentralProtocol::PAYLOAD)) {
auto PayloadObj = Object->getObject(uCentralProtocol::PAYLOAD);
if(PayloadObj->has(uCentralProtocol::CAPABILITIES)) {
std::cout << "CAPABILITIES:" << SerialNumber << std::endl;
// std::cout << "CAPABILITIES:" << SerialNumber << std::endl;
auto CapObj = PayloadObj->getObject(uCentralProtocol::CAPABILITIES);
if(CapObj->has(uCentralProtocol::COMPATIBLE)) {
auto DeviceType = CapObj->get(uCentralProtocol::COMPATIBLE).toString();
auto Serial = PayloadObj->get(uCentralProtocol::SERIAL).toString();
auto Revision = Storage::TrimRevision(PayloadObj->get(uCentralProtocol::FIRMWARE).toString());
std::cout << "ConnectionEvent: SerialNumber: " << SerialNumber << " DeviceType: " << DeviceType << " Revision:" << Revision << std::endl;
// std::cout << "ConnectionEvent: SerialNumber: " << SerialNumber << " DeviceType: " << DeviceType << " Revision:" << Revision << std::endl;
FMSObjects::FirmwareAgeDetails FA;
if(Storage()->ComputeFirmwareAge(DeviceType, Revision, FA)) {
Storage()->SetDeviceRevision(SerialNumber, Revision, DeviceType, EndPoint);
@@ -78,7 +78,7 @@ namespace uCentral {
auto SNum = DisconnectMessage->get(uCentralProtocol::SERIALNUMBER).toString();
auto Timestamp = DisconnectMessage->get(uCentralProtocol::TIMESTAMP);
Storage()->SetDeviceDisconnected(SNum,EndPoint);
std::cout << "DISCONNECTION:" << SerialNumber << std::endl;
// std::cout << "DISCONNECTION:" << SerialNumber << std::endl;
}
} else if(PayloadObj->has(uCentralProtocol::PING)) {
// std::cout << "PING:" << SerialNumber << std::endl;

View File

@@ -7,9 +7,9 @@
#include "SubSystemServer.h"
#include "uCentralTypes.h"
#include "OpenWifiTypes.h"
namespace uCentral {
namespace OpenWifi {
class NewConnectionHandler : public SubSystemServer, Poco::Runnable {
public:

View File

@@ -17,7 +17,7 @@
#include "Utils.h"
#include "Daemon.h"
namespace uCentral {
namespace OpenWifi {
OpenAPIRequestGet::OpenAPIRequestGet( const std::string & ServiceType,
const std::string & EndPoint,
@@ -32,7 +32,7 @@ namespace uCentral {
int OpenAPIRequestGet::Do(Poco::JSON::Object::Ptr &ResponseObject) {
try {
auto Services = Daemon()->GetServices(Type_);
auto Services = Daemon()->GetServices(Type_);
for(auto const &Svc:Services) {
Poco::URI URI(Svc.PrivateEndPoint);
Poco::Net::HTTPSClientSession Session(URI.getHost(), URI.getPort());
@@ -42,7 +42,7 @@ namespace uCentral {
URI.addQueryParameter(qp.first, qp.second);
std::string Path(URI.getPathAndQuery());
Session.setTimeout(Poco::Timespan(5, 0));
Session.setTimeout(Poco::Timespan(msTimeout_/1000, msTimeout_ % 1000));
Poco::Net::HTTPRequest Request(Poco::Net::HTTPRequest::HTTP_GET,
Path,

View File

@@ -7,9 +7,9 @@
#include "Poco/JSON/Object.h"
#include "uCentralTypes.h"
#include "OpenWifiTypes.h"
namespace uCentral {
namespace OpenWifi {
class OpenAPIRequestGet {
public:

View File

@@ -15,7 +15,9 @@
#include <utility>
#include <queue>
namespace uCentral::Types {
#include "Poco/StringTokenizer.h"
namespace OpenWifi::Types {
typedef std::pair<std::string,std::string> StringPair;
typedef std::vector<StringPair> StringPairVec;
typedef std::queue<StringPair> StringPairQueue;
@@ -28,12 +30,38 @@ namespace uCentral::Types {
typedef std::map<std::string, TopicNotifyFunctionList> NotifyTable;
typedef std::map<std::string,uint64_t> CountedMap;
inline void UpdateCountedMap(CountedMap &M, const std::string &S ) {
typedef std::string UUID_t;
typedef std::vector<UUID_t> UUIDvec_t;
inline void UpdateCountedMap(CountedMap &M, const std::string &S, uint64_t Increment=1) {
auto it = M.find(S);
if(it==M.end())
M[S]=1;
M[S] = Increment;
else
it->second += 1;
it->second += Increment;
}
inline std::string to_string( const StringVec &V) {
std::string Result;
bool first=true;
for(const auto &i:V) {
if(first) {
Result += i;
first = false;
} else {
Result += ",";
Result += i;
}
}
return Result;
}
inline void from_string(const std::string &S, StringVec &V) {
Poco::StringTokenizer Tokens(S,",",Poco::StringTokenizer::TOK_TRIM | Poco::StringTokenizer::TOK_IGNORE_EMPTY);
for(auto const &i:Tokens)
V.emplace_back(i);
}
};

View File

@@ -5,10 +5,10 @@
#include "RESTAPI_FMSObjects.h"
#include "RESTAPI_utils.h"
using uCentral::RESTAPI_utils::field_to_json;
using uCentral::RESTAPI_utils::field_from_json;
using OpenWifi::RESTAPI_utils::field_to_json;
using OpenWifi::RESTAPI_utils::field_from_json;
namespace uCentral::FMSObjects {
namespace OpenWifi::FMSObjects {
void Firmware::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj, "id", id);
@@ -220,6 +220,7 @@ namespace uCentral::FMSObjects {
field_to_json(Obj, "unknownFirmwares", UnknownFirmwares_);
field_to_json(Obj,"snapshot",snapshot);
field_to_json(Obj,"numberOfDevices",numberOfDevices);
field_to_json(Obj, "totalSecondsOld", totalSecondsOld_);
}
void DeviceReport::reset() {
@@ -230,6 +231,7 @@ namespace uCentral::FMSObjects {
EndPoints_.clear();
UsingLatest_.clear();
UnknownFirmwares_.clear();
totalSecondsOld_.clear();
numberOfDevices = 0 ;
snapshot = std::time(nullptr);
}

View File

@@ -9,9 +9,9 @@
#include "RESTAPI_SecurityObjects.h"
#include "uCentralTypes.h"
#include "OpenWifiTypes.h"
namespace uCentral::FMSObjects {
namespace OpenWifi::FMSObjects {
struct Firmware {
std::string id;
@@ -122,6 +122,7 @@ namespace uCentral::FMSObjects {
Types::CountedMap EndPoints_;
Types::CountedMap UsingLatest_;
Types::CountedMap UnknownFirmwares_;
Types::CountedMap totalSecondsOld_;
void to_json(Poco::JSON::Object &Obj) const;
void reset();
bool from_json(const Poco::JSON::Object::Ptr &Obj);

View File

@@ -19,11 +19,11 @@
#include "RESTAPI_utils.h"
#include "Utils.h"
using uCentral::RESTAPI_utils::field_to_json;
using uCentral::RESTAPI_utils::field_from_json;
using uCentral::RESTAPI_utils::EmbedDocument;
using OpenWifi::RESTAPI_utils::field_to_json;
using OpenWifi::RESTAPI_utils::field_from_json;
using OpenWifi::RESTAPI_utils::EmbedDocument;
namespace uCentral::GWObjects {
namespace OpenWifi::GWObjects {
void Device::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj,"serialNumber", SerialNumber);
@@ -57,13 +57,15 @@ namespace uCentral::GWObjects {
if (DeviceRegistry()->GetState(SerialNumber, ConState)) {
ConState.to_json(Obj);
} else {
field_to_json(Obj,"ipAddress", "N/A");
field_to_json(Obj,"ipAddress", "");
field_to_json(Obj,"txBytes", (uint64_t) 0);
field_to_json(Obj,"rxBytes", (uint64_t )0);
field_to_json(Obj,"messageCount", (uint64_t )0);
field_to_json(Obj,"connected", false);
field_to_json(Obj,"lastContact", "N/A");
field_to_json(Obj,"lastContact", "");
field_to_json(Obj,"verifiedCertificate", "NO_CERTIFICATE");
field_to_json(Obj,"associations_2G", (uint64_t) 0);
field_to_json(Obj,"associations_5G", (uint64_t) 0);
}
#endif
}
@@ -176,6 +178,9 @@ namespace uCentral::GWObjects {
field_to_json(Obj,"connected", Connected);
field_to_json(Obj,"firmware", Firmware);
field_to_json(Obj,"lastContact", LastContact);
field_to_json(Obj,"associations_2G", Associations_2G);
field_to_json(Obj,"associations_5G", Associations_5G);
switch(VerifiedCertificate) {
case NO_CERTIFICATE:
field_to_json(Obj,"verifiedCertificate", "NO_CERTIFICATE"); break;
@@ -203,5 +208,40 @@ namespace uCentral::GWObjects {
field_to_json(Obj,"password",DevicePassword);
}
void Dashboard::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj,"commands",commands);
field_to_json(Obj,"upTimes",upTimes);
field_to_json(Obj,"memoryUsed",memoryUsed);
field_to_json(Obj,"load1",load1);
field_to_json(Obj,"load5",load5);
field_to_json(Obj,"load15",load15);
field_to_json(Obj,"vendors",vendors);
field_to_json(Obj,"status",status);
field_to_json(Obj,"deviceType",deviceType);
field_to_json(Obj,"healths",healths);
field_to_json(Obj,"certificates",certificates);
field_to_json(Obj,"lastContact",lastContact);
field_to_json(Obj,"associations",associations);
field_to_json(Obj,"snapshot",snapshot);
field_to_json(Obj,"numberOfDevices",numberOfDevices);
}
void Dashboard::reset() {
commands.clear();
upTimes.clear();
memoryUsed.clear();
load1.clear();
load5.clear();
load15.clear();
vendors.clear();
status.clear();
deviceType.clear();
healths.clear();
certificates.clear();
lastContact.clear();
associations.clear();
numberOfDevices = 0 ;
snapshot = std::time(nullptr);
}
}

View File

@@ -12,7 +12,7 @@
#include "Poco/JSON/Object.h"
#include "RESTAPI_SecurityObjects.h"
namespace uCentral::GWObjects {
namespace OpenWifi::GWObjects {
enum CertificateValidation {
NO_CERTIFICATE,
@@ -24,14 +24,17 @@ namespace uCentral::GWObjects {
struct ConnectionState {
uint64_t MessageCount = 0 ;
std::string SerialNumber;
std::string Address = "N/A";
std::string Address;
uint64_t UUID = 0 ;
uint64_t PendingUUID = 0 ;
uint64_t TX = 0, RX = 0;
uint64_t Associations_2G=0;
uint64_t Associations_5G=0;
bool Connected = false;
uint64_t LastContact=0;
std::string Firmware;
CertificateValidation VerifiedCertificate = NO_CERTIFICATE;
std::string Compatible;
void to_json(Poco::JSON::Object &Obj) const;
};
@@ -156,6 +159,26 @@ namespace uCentral::GWObjects {
std::string DevicePassword;
void to_json(Poco::JSON::Object &Obj) const;
};
struct Dashboard {
uint64_t snapshot;
uint64_t numberOfDevices;
Types::CountedMap commands;
Types::CountedMap upTimes;
Types::CountedMap memoryUsed;
Types::CountedMap load1;
Types::CountedMap load5;
Types::CountedMap load15;
Types::CountedMap vendors;
Types::CountedMap status;
Types::CountedMap deviceType;
Types::CountedMap healths;
Types::CountedMap certificates;
Types::CountedMap lastContact;
Types::CountedMap associations;
void to_json(Poco::JSON::Object &Obj) const;
void reset();
};
}
#endif //UCENTRAL_RESTAPI_OBJECTS_H

View File

@@ -14,7 +14,7 @@
#include "Utils.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_InternalServer *RESTAPI_InternalServer::instance_ = nullptr;
@@ -56,7 +56,7 @@ namespace uCentral {
Poco::Net::HTTPRequestHandler *InternalRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest & Request) {
Logger_.debug(
Poco::format("REQUEST(%s): %s %s", uCentral::Utils::FormatIPv6(Request.clientAddress().toString()),
Poco::format("REQUEST(%s): %s %s", Utils::FormatIPv6(Request.clientAddress().toString()),
Request.getMethod(), Request.getURI()));
Poco::URI uri(Request.getURI());

View File

@@ -12,7 +12,7 @@
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/NetException.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_InternalServer : public SubSystemServer {

View File

@@ -12,10 +12,10 @@
#include "RESTAPI_SecurityObjects.h"
#include "RESTAPI_utils.h"
using uCentral::RESTAPI_utils::field_to_json;
using uCentral::RESTAPI_utils::field_from_json;
using OpenWifi::RESTAPI_utils::field_to_json;
using OpenWifi::RESTAPI_utils::field_from_json;
namespace uCentral::SecurityObjects {
namespace OpenWifi::SecurityObjects {
void AclTemplate::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj,"Read",Read_);
@@ -303,6 +303,20 @@ namespace uCentral::SecurityObjects {
return false;
}
bool append_from_json(Poco::JSON::Object::Ptr Obj, const UserInfo &UInfo, NoteInfoVec & Notes) {
try {
SecurityObjects::NoteInfoVec NIV;
NIV = RESTAPI_utils::to_object_array<SecurityObjects::NoteInfo>(Obj->get("notes").toString());
for(auto const &i:NIV) {
SecurityObjects::NoteInfo ii{.created=(uint64_t)std::time(nullptr), .createdBy=UInfo.email, .note=i.note};
Notes.push_back(ii);
}
} catch(...) {
}
return false;
}
void ProfileAction::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj,"resource", resource);
field_to_json<ResourceAccessType>(Obj,"access", access, ResourceAccessTypeToString);

View File

@@ -10,9 +10,9 @@
#define UCENTRAL_RESTAPI_SECURITYOBJECTS_H
#include "Poco/JSON/Object.h"
#include "uCentralTypes.h"
#include "OpenWifiTypes.h"
namespace uCentral::SecurityObjects {
namespace OpenWifi::SecurityObjects {
struct AclTemplate {
bool Read_ = true;
@@ -94,6 +94,8 @@ namespace uCentral::SecurityObjects {
};
typedef std::vector<UserInfo> UserInfoVec;
bool append_from_json(Poco::JSON::Object::Ptr Obj, const UserInfo &UInfo, NoteInfoVec & Notes);
struct InternalServiceInfo {
std::string privateURI;
std::string publicURI;
@@ -114,9 +116,9 @@ namespace uCentral::SecurityObjects {
struct SystemEndpoint {
std::string type;
uint64_t id = 0;
std::string vendor;
std::string vendor{"OpenWiFi"};
std::string uri;
std::string authenticationType;
std::string authenticationType{"internal_v1"};
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};

View File

@@ -7,7 +7,7 @@
#include "StorageService.h"
#include "RESTAPI_protocol.h"
namespace uCentral {
namespace OpenWifi {
void RESTAPI_connectedDeviceHandler::handleRequest(Poco::Net::HTTPServerRequest &Request,
Poco::Net::HTTPServerResponse &Response) {
if (!ContinueProcessing(Request, Response))

View File

@@ -7,7 +7,7 @@
#include "RESTAPI_handler.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_connectedDeviceHandler : public RESTAPIHandler {
public:
RESTAPI_connectedDeviceHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)

View File

@@ -9,7 +9,7 @@
#include "StorageService.h"
#include "RESTAPI_protocol.h"
namespace uCentral {
namespace OpenWifi {
void RESTAPI_connectedDevicesHandler::handleRequest(Poco::Net::HTTPServerRequest &Request,
Poco::Net::HTTPServerResponse &Response) {
if (!ContinueProcessing(Request, Response))

View File

@@ -8,7 +8,7 @@
#include "RESTAPI_handler.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_connectedDevicesHandler : public RESTAPIHandler {
public:
RESTAPI_connectedDevicesHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)

View File

@@ -8,7 +8,7 @@
#include "Poco/JSON/Object.h"
#include "Daemon.h"
namespace uCentral {
namespace OpenWifi {
void RESTAPI_deviceReportHandler::handleRequest(Poco::Net::HTTPServerRequest &Request,
Poco::Net::HTTPServerResponse &Response) {
if (!ContinueProcessing(Request, Response))

View File

@@ -7,7 +7,7 @@
#include "RESTAPI_handler.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_deviceReportHandler : public RESTAPIHandler {
public:
RESTAPI_deviceReportHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)

View File

@@ -12,7 +12,7 @@
#include "uCentralProtocol.h"
#include "RESTAPI_protocol.h"
namespace uCentral {
namespace OpenWifi {
void RESTAPI_firmwareAgeHandler::handleRequest(Poco::Net::HTTPServerRequest &Request,
Poco::Net::HTTPServerResponse &Response) {
if (!ContinueProcessing(Request, Response))
@@ -31,7 +31,7 @@ namespace uCentral {
InitQueryBlock();
if (!QB_.Select.empty()) {
Poco::JSON::Array Objects;
std::vector<std::string> Numbers = uCentral::Utils::Split(QB_.Select);
std::vector<std::string> Numbers = Utils::Split(QB_.Select);
for (auto &i : Numbers) {
DeviceCacheEntry E;
if (DeviceCache()->GetDevice(i, E)) {

View File

@@ -7,7 +7,7 @@
#include "RESTAPI_handler.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_firmwareAgeHandler : public RESTAPIHandler {
public:
RESTAPI_firmwareAgeHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)

View File

@@ -11,7 +11,7 @@
#include "RESTAPI_protocol.h"
#include "RESTAPI_utils.h"
namespace uCentral {
namespace OpenWifi {
void RESTAPI_firmwareHandler::handleRequest(Poco::Net::HTTPServerRequest &Request,
Poco::Net::HTTPServerResponse &Response) {
if (!ContinueProcessing(Request, Response))

View File

@@ -7,7 +7,7 @@
#include "RESTAPI_handler.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_firmwareHandler : public RESTAPIHandler {
public:
RESTAPI_firmwareHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)

View File

@@ -7,7 +7,7 @@
#include "LatestFirmwareCache.h"
#include "RESTAPI_protocol.h"
namespace uCentral {
namespace OpenWifi {
void RESTAPI_firmwaresHandler::handleRequest(Poco::Net::HTTPServerRequest &Request,
Poco::Net::HTTPServerResponse &Response) {
if (!ContinueProcessing(Request, Response))

View File

@@ -7,7 +7,7 @@
#include "RESTAPI_handler.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_firmwaresHandler : public RESTAPIHandler {
public:
RESTAPI_firmwaresHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)

View File

@@ -27,16 +27,16 @@
#include "Utils.h"
#include "Daemon.h"
namespace uCentral {
namespace OpenWifi {
bool RESTAPIHandler::ParseBindings(const std::string & Request, const std::list<const char *> & EndPoints, BindingMap &bindings) {
std::string Param, Value;
bindings.clear();
std::vector<std::string> PathItems = uCentral::Utils::Split(Request, '/');
std::vector<std::string> PathItems = Utils::Split(Request, '/');
for(const auto &EndPoint:EndPoints) {
std::vector<std::string> ParamItems = uCentral::Utils::Split(EndPoint, '/');
std::vector<std::string> ParamItems = Utils::Split(EndPoint, '/');
if (PathItems.size() != ParamItems.size())
continue;
@@ -365,17 +365,17 @@ namespace uCentral {
}
bool RESTAPIHandler::InitQueryBlock() {
QB_.SerialNumber = GetParameter(uCentral::RESTAPI::Protocol::SERIALNUMBER, "");
QB_.StartDate = GetParameter(uCentral::RESTAPI::Protocol::STARTDATE, 0);
QB_.EndDate = GetParameter(uCentral::RESTAPI::Protocol::ENDDATE, 0);
QB_.Offset = GetParameter(uCentral::RESTAPI::Protocol::OFFSET, 1);
QB_.Limit = GetParameter(uCentral::RESTAPI::Protocol::LIMIT, 100);
QB_.Filter = GetParameter(uCentral::RESTAPI::Protocol::FILTER, "");
QB_.Select = GetParameter(uCentral::RESTAPI::Protocol::SELECT, "");
QB_.Lifetime = GetBoolParameter(uCentral::RESTAPI::Protocol::LIFETIME,false);
QB_.LogType = GetParameter(uCentral::RESTAPI::Protocol::LOGTYPE,0);
QB_.LastOnly = GetBoolParameter(uCentral::RESTAPI::Protocol::LASTONLY,false);
QB_.Newest = GetBoolParameter(uCentral::RESTAPI::Protocol::NEWEST,false);
QB_.SerialNumber = GetParameter(RESTAPI::Protocol::SERIALNUMBER, "");
QB_.StartDate = GetParameter(RESTAPI::Protocol::STARTDATE, 0);
QB_.EndDate = GetParameter(RESTAPI::Protocol::ENDDATE, 0);
QB_.Offset = GetParameter(RESTAPI::Protocol::OFFSET, 1);
QB_.Limit = GetParameter(RESTAPI::Protocol::LIMIT, 100);
QB_.Filter = GetParameter(RESTAPI::Protocol::FILTER, "");
QB_.Select = GetParameter(RESTAPI::Protocol::SELECT, "");
QB_.Lifetime = GetBoolParameter(RESTAPI::Protocol::LIFETIME,false);
QB_.LogType = GetParameter(RESTAPI::Protocol::LOGTYPE,0);
QB_.LastOnly = GetBoolParameter(RESTAPI::Protocol::LASTONLY,false);
QB_.Newest = GetBoolParameter(RESTAPI::Protocol::NEWEST,false);
if(QB_.Offset<1) return false;
return true;
@@ -400,7 +400,7 @@ namespace uCentral {
}
[[nodiscard]] uint64_t RESTAPIHandler::GetWhen(const Poco::JSON::Object::Ptr &Obj) {
return RESTAPIHandler::Get(uCentral::RESTAPI::Protocol::WHEN, Obj);
return RESTAPIHandler::Get(RESTAPI::Protocol::WHEN, Obj);
}

View File

@@ -26,7 +26,7 @@
#include "RESTAPI_SecurityObjects.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_PartHandler: public Poco::Net::PartHandler
{

View File

@@ -12,7 +12,7 @@
#include "StorageService.h"
#include "RESTAPI_protocol.h"
namespace uCentral {
namespace OpenWifi {
void RESTAPI_historyHandler::handleRequest(Poco::Net::HTTPServerRequest &Request,
Poco::Net::HTTPServerResponse &Response) {
if (!ContinueProcessing(Request, Response))

View File

@@ -8,7 +8,7 @@
#include "RESTAPI_handler.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_historyHandler : public RESTAPIHandler {
public:
RESTAPI_historyHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)

View File

@@ -9,7 +9,7 @@
#ifndef UCENTRALGW_RESTAPI_PROTOCOL_H
#define UCENTRALGW_RESTAPI_PROTOCOL_H
namespace uCentral::RESTAPI::Protocol {
namespace OpenWifi::RESTAPI::Protocol {
static const char * CAPABILITIES = "capabilities";
static const char * LOGS = "logs";
static const char * HEALTHCHECKS = "healthchecks";

View File

@@ -17,7 +17,7 @@
#include "RESTAPI_historyHandler.h"
#include "RESTAPI_deviceReportHandler.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_server *RESTAPI_server::instance_ = nullptr;
@@ -43,12 +43,6 @@ namespace uCentral {
Params->setMaxThreads(50);
Params->setMaxQueued(200);
Params->setKeepAlive(true);
/*
uint64_t T = 45000;
Params->setKeepAliveTimeout(T);
Params->setMaxKeepAliveRequests(200);
Params->setTimeout(T + 10000);
*/
auto NewServer = std::make_unique<Poco::Net::HTTPServer>(new RequestHandlerFactory, Pool_, Sock, Params);
NewServer->start();
@@ -60,7 +54,7 @@ namespace uCentral {
Poco::Net::HTTPRequestHandler *RequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest & Request) {
Logger_.debug(Poco::format("REQUEST(%s): %s %s", uCentral::Utils::FormatIPv6(Request.clientAddress().toString()), Request.getMethod(), Request.getURI()));
Logger_.debug(Poco::format("REQUEST(%s): %s %s", Utils::FormatIPv6(Request.clientAddress().toString()), Request.getMethod(), Request.getURI()));
Poco::URI uri(Request.getURI());
auto *Path = uri.getPath().c_str();

View File

@@ -13,7 +13,7 @@
#include "SubSystemServer.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_server : public SubSystemServer {

View File

@@ -13,7 +13,7 @@
#include "Daemon.h"
#include "RESTAPI_protocol.h"
namespace uCentral {
namespace OpenWifi {
void RESTAPI_system_command::handleRequest(Poco::Net::HTTPServerRequest &Request,
Poco::Net::HTTPServerResponse &Response) {
@@ -36,19 +36,19 @@ namespace uCentral {
Poco::JSON::Parser parser;
auto Obj = parser.parse(Request.stream()).extract<Poco::JSON::Object::Ptr>();
if (Obj->has(uCentral::RESTAPI::Protocol::COMMAND)) {
auto Command = Poco::toLower(Obj->get(uCentral::RESTAPI::Protocol::COMMAND).toString());
if (Command == uCentral::RESTAPI::Protocol::SETLOGLEVEL) {
if (Obj->has(uCentral::RESTAPI::Protocol::PARAMETERS) &&
Obj->isArray(uCentral::RESTAPI::Protocol::PARAMETERS)) {
auto ParametersBlock = Obj->getArray(uCentral::RESTAPI::Protocol::PARAMETERS);
if (Obj->has(RESTAPI::Protocol::COMMAND)) {
auto Command = Poco::toLower(Obj->get(RESTAPI::Protocol::COMMAND).toString());
if (Command == RESTAPI::Protocol::SETLOGLEVEL) {
if (Obj->has(RESTAPI::Protocol::PARAMETERS) &&
Obj->isArray(RESTAPI::Protocol::PARAMETERS)) {
auto ParametersBlock = Obj->getArray(RESTAPI::Protocol::PARAMETERS);
for (const auto &i:*ParametersBlock) {
Poco::JSON::Parser pp;
auto InnerObj = pp.parse(i).extract<Poco::JSON::Object::Ptr>();
if (InnerObj->has(uCentral::RESTAPI::Protocol::TAG) &&
InnerObj->has(uCentral::RESTAPI::Protocol::VALUE)) {
auto Name = GetS(uCentral::RESTAPI::Protocol::TAG, InnerObj);
auto Value = GetS(uCentral::RESTAPI::Protocol::VALUE, InnerObj);
if (InnerObj->has(RESTAPI::Protocol::TAG) &&
InnerObj->has(RESTAPI::Protocol::VALUE)) {
auto Name = GetS(RESTAPI::Protocol::TAG, InnerObj);
auto Value = GetS(RESTAPI::Protocol::VALUE, InnerObj);
Daemon()->SetSubsystemLogLevel(Name, Value);
Logger_.information(Poco::format("Setting log level for %s at %s", Name, Value));
}
@@ -56,38 +56,38 @@ namespace uCentral {
OK(Request, Response);
return;
}
} else if (Command == uCentral::RESTAPI::Protocol::GETLOGLEVELS) {
} else if (Command == RESTAPI::Protocol::GETLOGLEVELS) {
auto CurrentLogLevels = Daemon()->GetLogLevels();
Poco::JSON::Object Result;
Poco::JSON::Array Array;
for(auto &[Name,Level]:CurrentLogLevels) {
Poco::JSON::Object Pair;
Pair.set( uCentral::RESTAPI::Protocol::TAG,Name);
Pair.set(uCentral::RESTAPI::Protocol::VALUE,Level);
Pair.set( RESTAPI::Protocol::TAG,Name);
Pair.set(RESTAPI::Protocol::VALUE,Level);
Array.add(Pair);
}
Result.set(uCentral::RESTAPI::Protocol::TAGLIST,Array);
Result.set(RESTAPI::Protocol::TAGLIST,Array);
ReturnObject(Request,Result,Response);
return;
} else if (Command == uCentral::RESTAPI::Protocol::GETLOGLEVELNAMES) {
} else if (Command == RESTAPI::Protocol::GETLOGLEVELNAMES) {
Poco::JSON::Object Result;
Poco::JSON::Array LevelNamesArray;
const Types::StringVec & LevelNames = Daemon()->GetLogLevelNames();
for(const auto &i:LevelNames)
LevelNamesArray.add(i);
Result.set(uCentral::RESTAPI::Protocol::LIST,LevelNamesArray);
Result.set(RESTAPI::Protocol::LIST,LevelNamesArray);
ReturnObject(Request,Result,Response);
return;
} else if (Command == uCentral::RESTAPI::Protocol::GETSUBSYSTEMNAMES) {
} else if (Command == RESTAPI::Protocol::GETSUBSYSTEMNAMES) {
Poco::JSON::Object Result;
Poco::JSON::Array LevelNamesArray;
const Types::StringVec & SubSystemNames = Daemon()->GetSubSystems();
for(const auto &i:SubSystemNames)
LevelNamesArray.add(i);
Result.set(uCentral::RESTAPI::Protocol::LIST,LevelNamesArray);
Result.set(RESTAPI::Protocol::LIST,LevelNamesArray);
ReturnObject(Request,Result,Response);
return;
} else if (Command == uCentral::RESTAPI::Protocol::STATS) {
} else if (Command == RESTAPI::Protocol::STATS) {
}
}

View File

@@ -11,7 +11,7 @@
#include "RESTAPI_handler.h"
namespace uCentral {
namespace OpenWifi {
class RESTAPI_system_command : public RESTAPIHandler {
public:
RESTAPI_system_command(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)

View File

@@ -4,7 +4,7 @@
#include "RESTAPI_utils.h"
namespace uCentral::RESTAPI_utils {
namespace OpenWifi::RESTAPI_utils {
void EmbedDocument(const std::string & ObjName, Poco::JSON::Object & Obj, const std::string &ObjStr) {
std::string D = ObjStr.empty() ? "{}" : ObjStr;

View File

@@ -9,10 +9,10 @@
#include "Poco/JSON/Object.h"
#include "Poco/JSON/Parser.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "uCentralTypes.h"
#include "OpenWifiTypes.h"
#include "Utils.h"
namespace uCentral::RESTAPI_utils {
namespace OpenWifi::RESTAPI_utils {
void EmbedDocument(const std::string & ObjName, Poco::JSON::Object & Obj, const std::string &ObjStr);

View File

@@ -14,7 +14,7 @@
#include "Utils.h"
namespace uCentral {
namespace OpenWifi {
class Storage *Storage::instance_ = nullptr;

View File

@@ -27,7 +27,7 @@
#include "Poco/Data/MySQL/Connector.h"
#endif
namespace uCentral {
namespace OpenWifi {
class Storage : public SubSystemServer {
public:
@@ -61,7 +61,7 @@ namespace uCentral {
int Start() override;
void Stop() override;
int Setup_SQLite();
[[nodiscard]] std::string ConvertParams(const std::string &S) const;
[[nodiscard]] inline std::string ComputeRange(uint64_t From, uint64_t HowMany) {
if(dbType_==sqlite) {
@@ -92,11 +92,6 @@ namespace uCentral {
return instance_;
}
#ifndef SMALL_BUILD
int Setup_MySQL();
int Setup_PostgreSQL();
#endif
private:
static Storage *instance_;
std::unique_ptr<Poco::Data::SessionPool> Pool_= nullptr;
@@ -111,6 +106,11 @@ namespace uCentral {
SubSystemServer("Storage", "STORAGE-SVR", "storage")
{
}
int Setup_SQLite();
int Setup_MySQL();
int Setup_PostgreSQL();
};
inline Storage * Storage() { return Storage::instance(); };

View File

@@ -19,7 +19,7 @@
#include "Daemon.h"
namespace uCentral {
namespace OpenWifi {
SubSystemServer::SubSystemServer(std::string Name, const std::string &LoggingPrefix,
std::string SubSystemConfigPrefix)
: Name_(std::move(Name)), Logger_(Poco::Logger::get(LoggingPrefix)),

View File

@@ -23,7 +23,7 @@
using SubMutex = std::recursive_mutex;
using SubMutexGuard = std::lock_guard<SubMutex>;
namespace uCentral {
namespace OpenWifi {
class PropertiesFileServerEntry {
public:
PropertiesFileServerEntry(std::string Address, uint32_t port, std::string Key_file,

View File

@@ -28,7 +28,7 @@
#include "uCentralProtocol.h"
#include "Daemon.h"
namespace uCentral::Utils {
namespace OpenWifi::Utils {
[[nodiscard]] bool ValidSerialNumber(const std::string &Serial) {
return ((Serial.size() < uCentralProtocol::SERIAL_NUMBER_LENGTH) &&

View File

@@ -11,16 +11,18 @@
#include <vector>
#include <string>
#include <iomanip>
#include <sstream>
#include "Poco/Net/NetworkInterface.h"
#include "Poco/Net/IPAddress.h"
#include "Poco/String.h"
#include "Poco/File.h"
#include "uCentralTypes.h"
#include "OpenWifiTypes.h"
#define DBGLINE { std::cout << __FILE__ << ":" << __func__ << ":" << __LINE__ << std::endl; };
namespace uCentral::Utils {
namespace OpenWifi::Utils {
enum MediaTypeEncodings {
PLAIN,
@@ -73,5 +75,16 @@ namespace uCentral::Utils {
[[nodiscard]] std::string SecondsToNiceText(uint64_t Seconds);
[[nodiscard]] bool IPinRange(const std::string &Range, const Poco::Net::IPAddress &IP);
template< typename T >
std::string int_to_hex( T i )
{
std::stringstream stream;
stream << std::setfill ('0') << std::setw(12)
<< std::hex << i;
return stream.str();
}
}
#endif // UCENTRALGW_UTILS_H

View File

@@ -1,154 +0,0 @@
//
// Created by stephane bourque on 2021-06-02.
//
#include "s3bucketreader.h"
#include "Daemon.h"
#include <aws/s3/model/ListObjectsRequest.h>
#include <aws/s3/model/GetObjectRequest.h>
#include "Poco/JSON/Object.h"
#include "Poco/JSON/Parser.h"
#include "Poco/File.h"
#include "Utils.h"
namespace uCentral {
bool S3BucketReader::Initialize() {
S3BucketName_ = Daemon()->ConfigGetString("s3.bucketname");
S3Region_ = Daemon()->ConfigGetString("s3.region");
S3Secret_ = Daemon()->ConfigGetString("s3.secret");
S3Key_ = Daemon()->ConfigGetString("s3.key");
S3Retry_ = Daemon()->ConfigGetInt("s3.retry",60);
AwsConfig_.enableTcpKeepAlive = true;
AwsConfig_.enableEndpointDiscovery = true;
AwsConfig_.useDualStack = true;
if(!S3Region_.empty())
AwsConfig_.region = S3Region_;
AwsCreds_.SetAWSAccessKeyId(S3Key_);
AwsCreds_.SetAWSSecretKey(S3Secret_);
return true;
}
void S3BucketReader::Close() {
}
bool S3BucketReader::GetObjectContent(Aws::S3::S3Client &S3Client, const std::string &ObjectName, std::string & ObjectContent) {
Aws::S3::Model::GetObjectRequest Request;
Request.SetBucket(S3BucketName_.c_str());
Request.SetKey(ObjectName.c_str());
Aws::S3::Model::GetObjectOutcome get_object_outcome = S3Client.GetObject(Request);
if (get_object_outcome.IsSuccess())
{
auto & FileData = get_object_outcome.GetResultWithOwnership().GetBody();
std::string O;
std::ostringstream OS(O);
OS << FileData.rdbuf();
ObjectContent = OS.str();
return true;
}
return false;
}
bool S3BucketReader::ReadBucket() {
static const std::string JSON(".json");
static const std::string UPGRADE("-upgrade.bin");
std::string URIBase = "https://";
URIBase += Daemon()->ConfigGetString("s3.bucket.uri");
BucketContent_.clear();
Aws::S3::Model::ListObjectsRequest Request;
Request.WithBucket(S3BucketName_.c_str());
Aws::S3::S3Client S3Client(AwsCreds_,AwsConfig_);
auto Outcome = S3Client.ListObjects(Request);
if(Outcome.IsSuccess()) {
std::cout << "Success..." << std::endl;
Aws::Vector<Aws::S3::Model::Object> objects = Outcome.GetResult().GetContents();
for (const auto &Object : objects) {
Poco::Path FileName(Object.GetKey().c_str());
std::cout << "Object: " << Object.GetKey() << std::endl;
if (FileName.getExtension() == "json") {
std::string Release = FileName.getBaseName();
std::string Content;
if (GetObjectContent(S3Client, FileName.getFileName(), Content)) {
Poco::JSON::Parser P;
auto ParsedContent = P.parse(Content).extract<Poco::JSON::Object::Ptr>();
if (ParsedContent->has("image") &&
ParsedContent->has("compatible") &&
ParsedContent->has("revision") &&
ParsedContent->has("timestamp")) {
auto It = BucketContent_.find(Release);
if (It != BucketContent_.end()) {
It->second.Timestamp = ParsedContent->get("timestamp");
It->second.Compatible = ParsedContent->get("compatible").toString();
It->second.Revision = ParsedContent->get("revision").toString();
It->second.Image = ParsedContent->get("image").toString();
It->second.S3ContentManifest = Content;
} else {
BucketContent_.emplace(Release, BucketEntry{
.S3ContentManifest = Content,
.Revision = ParsedContent->get("revision").toString(),
.Image = ParsedContent->get("image").toString(),
.Compatible = ParsedContent->get("compatible").toString(),
.Timestamp = ParsedContent->get("timestamp")});
}
}
}
} else if (FileName.getExtension() > "bin") {
std::string Release = FileName.substr(0, FileName.size() - UPGRADE.size());
auto It = BucketContent_.find(Release);
if(It != BucketContent_.end()) {
It->second.S3TimeStamp = (uint64_t ) (Object.GetLastModified().Millis()/1000);
It->second.S3Size = Object.GetSize();
It->second.S3Name = FileName;
It->second.URI = URIBase + FileName;
} else {
BucketContent_.emplace(Release, BucketEntry{
.S3Name = FileName,
.S3TimeStamp = (uint64_t ) (Object.GetLastModified().Millis()/1000),
.S3Size = (uint64_t ) Object.GetSize(),
.URI = URIBase + FileName });
}
} else {
}
}
} else {
std::cout << "No success in connecting..." << Outcome.GetError() << std::endl;
}
return true;
}
const BucketContent & S3BucketReader::Bucket() const {
return BucketContent_;
};
void BucketEntry::Print() const {
std::cout << " Name: " << S3Name << std::endl;
std::cout << " Size: " << S3Size << std::endl;
std::cout << " Date: " << S3TimeStamp << std::endl;
std::cout << " Latest: " << S3ContentManifest << std::endl;
std::cout << " Image: " << Image << std::endl;
std::cout << " Revision: " << Revision << std::endl;
std::cout << " Compatible: " << Compatible << std::endl;
std::cout << " Timestamp: " << Timestamp << std::endl;
std::cout << " URI: " << URI << std::endl;
}
void Print(const uCentral::BucketContent &B) {
for(const auto &[Name,Entry]:B) {
std::cout << "Release:" << Name << std::endl;
Entry.Print();
}
}
}

View File

@@ -1,54 +0,0 @@
//
// Created by stephane bourque on 2021-06-02.
//
#include <list>
#ifndef UCENTRALFWS_S3BUCKETREADER_H
#define UCENTRALFWS_S3BUCKETREADER_H
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/core/auth/AWSCredentials.h>
namespace uCentral {
// pair: filename_root, content of root.latest
struct BucketEntry {
bool Valid = false;
std::string S3Name;
std::string S3ContentManifest;
uint64_t S3TimeStamp = 0;
uint64_t S3Size = 0;
std::string Revision;
std::string Image;
std::string Compatible;
uint64_t Timestamp = 0;
std::string URI;
void Print() const;
};
typedef std::map<std::string, BucketEntry> BucketContent;
void Print(const BucketContent &B);
class S3BucketReader {
public:
bool Initialize();
bool ReadBucket();
const BucketContent & Bucket() const;
bool GetObjectContent(Aws::S3::S3Client &S3Client, const std::string &ObjectName, std::string & ObjectContent);
void Close();
private:
Aws::String S3BucketName_;
Aws::String S3Region_;
Aws::String S3Key_;
Aws::String S3Secret_;
uint64_t S3Retry_;
Aws::Client::ClientConfiguration AwsConfig_{"ARILIA"};
Aws::Auth::AWSCredentials AwsCreds_;
BucketContent BucketContent_;
};
}
#endif //UCENTRALFWS_S3BUCKETREADER_H

View File

@@ -16,7 +16,7 @@
"lastUpdate=?, "
"status=?
*/
namespace uCentral {
namespace OpenWifi {
bool Convert(const DevicesRecord &T, FMSObjects::DeviceConnectionInformation & F) {
F.serialNumber = T.get<0>();
@@ -221,7 +221,7 @@ namespace uCentral {
} else if (Age.age == 0) {
Types::UpdateCountedMap(Report.UnknownFirmwares_, Revision);
} else {
Types::UpdateCountedMap(Report.totalSecondsOld_,"total_seconds", Age.age);
}
}
More = RSet.moveNext();

View File

@@ -7,7 +7,7 @@
#include "StorageService.h"
namespace uCentral {
namespace OpenWifi {
static const std::string DBNAME_DEVICES{"devices"};
static const std::string DBFIELDS_DEVICES_CREATION {

View File

@@ -7,7 +7,7 @@
#include <string>
namespace uCentral {
namespace OpenWifi {
static const std::string DBNAME_DEVICETYPES{"deviceTypes"};
static const std::string DBFIELDS_DEVICETYPES_CREATION {
" id varchar(36) UNIQUE PRIMARY KEY, "

View File

@@ -10,7 +10,7 @@
#include "Daemon.h"
#include <limits>
namespace uCentral {
namespace OpenWifi {
bool Convert(const FirmwaresRecord &T, FMSObjects::Firmware & F) {
F.id = T.get<0>();

View File

@@ -7,7 +7,7 @@
#include "Poco/Tuple.h"
namespace uCentral {
namespace OpenWifi {
static const std::string DBNAME_FIRMWARES{"firmwares"};
static const std::string DBFIELDS_FIRMWARES_CREATION {
"Id varchar(36) UNIQUE PRIMARY KEY, "

View File

@@ -7,7 +7,7 @@
#include "RESTAPI_FMSObjects.h"
#include "Daemon.h"
namespace uCentral {
namespace OpenWifi {
/*
* " id, "
"serialNumber, "

View File

@@ -8,7 +8,7 @@
#include <string>
#include "Poco/Tuple.h"
namespace uCentral {
namespace OpenWifi {
static const std::string DBNAME_HISTORY{"history"};
static const std::string DBFIELDS_HISTORY_CREATION {
" id varchar(36) UNIQUE PRIMARY KEY, "

View File

@@ -1,46 +0,0 @@
//
// License type: BSD 3-Clause License
// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
//
// Created by Stephane Bourque on 2021-03-04.
// Arilia Wireless Inc.
//
#include "Daemon.h"
#include "StorageService.h"
namespace uCentral {
#ifdef SMALL_BUILD
int Service::Setup_MySQL() { uCentral::instance()->exit(Poco::Util::Application::EXIT_CONFIG);}
#else
int Storage::Setup_MySQL() {
dbType_ = mysql ;
Logger_.notice("MySQL Storage enabled.");
auto NumSessions = Daemon()->ConfigGetInt("storage.type.mysql.maxsessions", 64);
auto IdleTime = Daemon()->ConfigGetInt("storage.type.mysql.idletime", 60);
auto Host = Daemon()->ConfigGetString("storage.type.mysql.host");
auto Username = Daemon()->ConfigGetString("storage.type.mysql.username");
auto Password = Daemon()->ConfigGetString("storage.type.mysql.password");
auto Database = Daemon()->ConfigGetString("storage.type.mysql.database");
auto Port = Daemon()->ConfigGetString("storage.type.mysql.port");
std::string ConnectionStr =
"host=" + Host +
";user=" + Username +
";password=" + Password +
";db=" + Database +
";port=" + Port +
";compress=true;auto-reconnect=true";
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;
}
#endif
}

View File

@@ -1,47 +0,0 @@
//
// License type: BSD 3-Clause License
// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
//
// Created by Stephane Bourque on 2021-03-04.
// Arilia Wireless Inc.
//
#include "Daemon.h"
#include "StorageService.h"
namespace uCentral {
#ifdef SMALL_BUILD
int Service::Setup_PostgreSQL() { uCentral::instance()->exit(Poco::Util::Application::EXIT_CONFIG);}
#else
int Storage::Setup_PostgreSQL() {
Logger_.notice("PostgreSQL Storage enabled.");
dbType_ = pgsql ;
auto NumSessions = Daemon()->ConfigGetInt("storage.type.postgresql.maxsessions", 64);
auto IdleTime = Daemon()->ConfigGetInt("storage.type.postgresql.idletime", 60);
auto Host = Daemon()->ConfigGetString("storage.type.postgresql.host");
auto Username = Daemon()->ConfigGetString("storage.type.postgresql.username");
auto Password = Daemon()->ConfigGetString("storage.type.postgresql.password");
auto Database = Daemon()->ConfigGetString("storage.type.postgresql.database");
auto Port = Daemon()->ConfigGetString("storage.type.postgresql.port");
auto ConnectionTimeout = Daemon()->ConfigGetString("storage.type.postgresql.connectiontimeout");
std::string ConnectionStr =
"host=" + Host +
" user=" + Username +
" password=" + Password +
" dbname=" + Database +
" port=" + Port +
" connect_timeout=" + ConnectionTimeout;
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
}

82
src/storage_setup.cpp Normal file
View File

@@ -0,0 +1,82 @@
//
// Created by stephane bourque on 2021-08-22.
//
#include "StorageService.h"
#include "Daemon.h"
namespace OpenWifi {
#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; }
#else
int Storage::Setup_SQLite() {
Logger_.notice("SQLite Storage enabled.");
auto DBName = Daemon()->DataDir() + "/" + Daemon()->ConfigGetString("storage.type.sqlite.db");
auto NumSessions = Daemon()->ConfigGetInt("storage.type.sqlite.maxsessions", 64);
auto IdleTime = Daemon()->ConfigGetInt("storage.type.sqlite.idletime", 60);
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;
}
int Storage::Setup_MySQL() {
Logger_.notice("MySQL Storage enabled.");
auto NumSessions = Daemon()->ConfigGetInt("storage.type.mysql.maxsessions", 64);
auto IdleTime = Daemon()->ConfigGetInt("storage.type.mysql.idletime", 60);
auto Host = Daemon()->ConfigGetString("storage.type.mysql.host");
auto Username = Daemon()->ConfigGetString("storage.type.mysql.username");
auto Password = Daemon()->ConfigGetString("storage.type.mysql.password");
auto Database = Daemon()->ConfigGetString("storage.type.mysql.database");
auto Port = Daemon()->ConfigGetString("storage.type.mysql.port");
std::string ConnectionStr =
"host=" + Host +
";user=" + Username +
";password=" + Password +
";db=" + Database +
";port=" + Port +
";compress=true;auto-reconnect=true";
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;
}
int Storage::Setup_PostgreSQL() {
Logger_.notice("PostgreSQL Storage enabled.");
auto NumSessions = Daemon()->ConfigGetInt("storage.type.postgresql.maxsessions", 64);
auto IdleTime = Daemon()->ConfigGetInt("storage.type.postgresql.idletime", 60);
auto Host = Daemon()->ConfigGetString("storage.type.postgresql.host");
auto Username = Daemon()->ConfigGetString("storage.type.postgresql.username");
auto Password = Daemon()->ConfigGetString("storage.type.postgresql.password");
auto Database = Daemon()->ConfigGetString("storage.type.postgresql.database");
auto Port = Daemon()->ConfigGetString("storage.type.postgresql.port");
auto ConnectionTimeout = Daemon()->ConfigGetString("storage.type.postgresql.connectiontimeout");
std::string ConnectionStr =
"host=" + Host +
" user=" + Username +
" password=" + Password +
" dbname=" + Database +
" port=" + Port +
" connect_timeout=" + ConnectionTimeout;
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
}

View File

@@ -1,25 +0,0 @@
//
// License type: BSD 3-Clause License
// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
//
// Created by Stephane Bourque on 2021-03-04.
// Arilia Wireless Inc.
//
#include "StorageService.h"
#include "Daemon.h"
namespace uCentral {
int Storage::Setup_SQLite() {
Logger_.notice("SQLite Storage enabled.");
auto DBName = Daemon()->DataDir() + "/" + Daemon()->ConfigGetString("storage.type.sqlite.db");
auto NumSessions = Daemon()->ConfigGetInt("storage.type.sqlite.maxsessions", 64);
auto IdleTime = Daemon()->ConfigGetInt("storage.type.sqlite.idletime", 60);
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;
}
}

View File

@@ -8,7 +8,7 @@
#include "StorageService.h"
namespace uCentral {
namespace OpenWifi {
int Storage::Create_Tables() {
Create_Firmwares();

View File

@@ -11,7 +11,7 @@
#include "Poco/String.h"
namespace uCentral::uCentralProtocol {
namespace OpenWifi::uCentralProtocol {
const int SERIAL_NUMBER_LENGTH = 30;

View File

@@ -41,8 +41,8 @@ ucentral.system.uri.ui = ucentral-ui.arilia.com
#
s3.bucketname = ucentral-ap-firmware
s3.region = us-east-1
s3.secret = ****************************
s3.key = **************************
s3.secret = *******************************************
s3.key = *******************************************
s3.retry = 60
s3.bucket.uri = ucentral-ap-firmware.s3.amazonaws.com
@@ -62,7 +62,8 @@ alb.port = 16104
ucentral.kafka.group.id = firmware
ucentral.kafka.client.id = firmware1
ucentral.kafka.enable = true
ucentral.kafka.brokerlist = a1.arilia.com:9092
# ucentral.kafka.brokerlist = a1.arilia.com:9092
ucentral.kafka.brokerlist = debfarm1-node-c.arilia.com:9092
ucentral.kafka.auto.commit = false
ucentral.kafka.queue.buffering.max.ms = 50