mirror of
				https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
				synced 2025-11-03 20:27:45 +00:00 
			
		
		
		
	Compare commits
	
		
			20 Commits
		
	
	
		
			release/v2
			...
			release/v2
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					7439051e54 | ||
| 
						 | 
					0457294136 | ||
| 
						 | 
					82f683cfc3 | ||
| 
						 | 
					8cd59bcea7 | ||
| 
						 | 
					ca57334cca | ||
| 
						 | 
					371bee0baa | ||
| 
						 | 
					92ef201b2b | ||
| 
						 | 
					7211cd945b | ||
| 
						 | 
					7a3e1ca33a | ||
| 
						 | 
					2d5e7f3c00 | ||
| 
						 | 
					cda8c640fe | ||
| 
						 | 
					5ff6836c8c | ||
| 
						 | 
					1e05919e85 | ||
| 
						 | 
					4c9c693242 | ||
| 
						 | 
					7564da75b5 | ||
| 
						 | 
					197925d446 | ||
| 
						 | 
					eee368a918 | ||
| 
						 | 
					90b5bf526f | ||
| 
						 | 
					9e5f9c4f0f | ||
| 
						 | 
					208dda626f | 
@@ -1,5 +1,5 @@
 | 
			
		||||
cmake_minimum_required(VERSION 3.13)
 | 
			
		||||
project(ucentralsec VERSION 2.0.0)
 | 
			
		||||
project(ucentralsec VERSION 2.1.0)
 | 
			
		||||
 | 
			
		||||
set(CMAKE_CXX_STANDARD 17)
 | 
			
		||||
 | 
			
		||||
@@ -62,14 +62,18 @@ add_executable( ucentralsec
 | 
			
		||||
                src/KafkaManager.h src/KafkaManager.cpp
 | 
			
		||||
                src/StorageService.cpp src/StorageService.h
 | 
			
		||||
                src/Utils.cpp src/Utils.h
 | 
			
		||||
                src/storage_sqlite.cpp src/storage_sqlite.cpp src/storage_pgql.cpp src/storage_mysql.cpp
 | 
			
		||||
                src/storage_setup.cpp
 | 
			
		||||
                src/storage_tables.cpp src/SMTPMailerService.cpp src/SMTPMailerService.h
 | 
			
		||||
                src/RESTAPI_users_handler.cpp src/RESTAPI_users_handler.h
 | 
			
		||||
                src/RESTAPI_user_handler.cpp src/RESTAPI_user_handler.h
 | 
			
		||||
                src/RESTAPI_action_links.cpp src/RESTAPI_action_links.h src/storage_users.cpp
 | 
			
		||||
                src/RESTAPI_InternalServer.cpp src/RESTAPI_InternalServer.h
 | 
			
		||||
                src/RESTAPI_validateToken_handler.cpp src/RESTAPI_validateToken_handler.h
 | 
			
		||||
                src/RESTAPI_systemEndpoints_handler.cpp src/RESTAPI_systemEndpoints_handler.h src/RESTAPI_AssetServer.cpp src/RESTAPI_AssetServer.h src/RESTAPI_avatarHandler.cpp src/RESTAPI_avatarHandler.h src/storage_avatar.cpp src/storage_avatar.h src/storage_users.h)
 | 
			
		||||
                src/RESTAPI_systemEndpoints_handler.cpp src/RESTAPI_systemEndpoints_handler.h
 | 
			
		||||
                src/RESTAPI_AssetServer.cpp src/RESTAPI_AssetServer.h
 | 
			
		||||
                src/RESTAPI_avatarHandler.cpp src/RESTAPI_avatarHandler.h
 | 
			
		||||
                src/storage_avatar.cpp src/storage_avatar.h src/storage_users.h
 | 
			
		||||
                src/OpenWifiTypes.h )
 | 
			
		||||
 | 
			
		||||
if(NOT SMALL_BUILD)
 | 
			
		||||
    target_link_libraries(ucentralsec PUBLIC
 | 
			
		||||
 
 | 
			
		||||
@@ -46,7 +46,8 @@ RUN addgroup -S "$UCENTRALSEC_USER" && \
 | 
			
		||||
    adduser -S -G "$UCENTRALSEC_USER" "$UCENTRALSEC_USER"
 | 
			
		||||
 | 
			
		||||
RUN mkdir /ucentral
 | 
			
		||||
RUN mkdir -p "$UCENTRALSEC_ROOT" "$UCENTRALSEC_CONFIG"
 | 
			
		||||
RUN mkdir -p "$UCENTRALSEC_ROOT" "$UCENTRALSEC_CONFIG" && \
 | 
			
		||||
    chown "$UCENTRALSEC_USER": "$UCENTRALSEC_ROOT" "$UCENTRALSEC_CONFIG"
 | 
			
		||||
RUN apk add --update --no-cache librdkafka mariadb-connector-c libpq unixodbc su-exec
 | 
			
		||||
 | 
			
		||||
COPY --from=builder /ucentralsec/cmake-build/ucentralsec /ucentral/ucentralsec
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,18 @@
 | 
			
		||||
apiVersion: v1
 | 
			
		||||
apiVersion: v2
 | 
			
		||||
appVersion: "1.0"
 | 
			
		||||
description: A Helm chart for Kubernetes
 | 
			
		||||
name: ucentralsec
 | 
			
		||||
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
 | 
			
		||||
 
 | 
			
		||||
@@ -83,6 +83,11 @@ spec:
 | 
			
		||||
            {{- toYaml . | nindent 12 }}
 | 
			
		||||
          {{- end }}
 | 
			
		||||
 | 
			
		||||
      {{- with .Values.securityContext }}
 | 
			
		||||
      securityContext:
 | 
			
		||||
        {{- toYaml . | nindent 8 }}
 | 
			
		||||
      {{- end }}
 | 
			
		||||
 | 
			
		||||
      imagePullSecrets:
 | 
			
		||||
      {{- range $image, $imageValue := .Values.images }}
 | 
			
		||||
        {{- if $imageValue.regcred }}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ fullnameOverride: ""
 | 
			
		||||
images:
 | 
			
		||||
  ucentralsec:
 | 
			
		||||
    repository: tip-tip-wlan-cloud-ucentral.jfrog.io/ucentralsec
 | 
			
		||||
    tag: main
 | 
			
		||||
    tag: v2.1.0-RC1
 | 
			
		||||
    pullPolicy: Always
 | 
			
		||||
#    regcred:
 | 
			
		||||
#      registry: tip-tip-wlan-cloud-ucentral.jfrog.io
 | 
			
		||||
@@ -85,6 +85,9 @@ resources: {}
 | 
			
		||||
  #  cpu: 100m
 | 
			
		||||
  #  memory: 128Mi
 | 
			
		||||
 | 
			
		||||
securityContext:
 | 
			
		||||
  fsGroup: 101
 | 
			
		||||
 | 
			
		||||
nodeSelector: {}
 | 
			
		||||
 | 
			
		||||
tolerations: []
 | 
			
		||||
@@ -173,7 +176,7 @@ configProperties:
 | 
			
		||||
  ucentral.system.commandchannel: /tmp/app_ucentralsec
 | 
			
		||||
  # Logging
 | 
			
		||||
  logging.formatters.f1.class: PatternFormatter
 | 
			
		||||
  logging.formatters.f1.pattern: "%s: [%p] %t"
 | 
			
		||||
  logging.formatters.f1.pattern: "%Y-%m-%d %H:%M:%S %s: [%p] %t"
 | 
			
		||||
  logging.formatters.f1.times: UTC
 | 
			
		||||
  logging.channels.c1.class: ConsoleChannel
 | 
			
		||||
  logging.channels.c1.formatter: f1
 | 
			
		||||
@@ -186,7 +189,7 @@ configProperties:
 | 
			
		||||
  logging.channels.c2.purgeCount: 20
 | 
			
		||||
  logging.channels.c3.class: ConsoleChannel
 | 
			
		||||
  logging.channels.c3.pattern: "%s: [%p] %t"
 | 
			
		||||
  logging.loggers.root.channel: c2
 | 
			
		||||
  logging.loggers.root.channel: c1
 | 
			
		||||
  logging.loggers.root.level: debug
 | 
			
		||||
 | 
			
		||||
  # -> Secret part
 | 
			
		||||
@@ -211,3 +214,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
 | 
			
		||||
 
 | 
			
		||||
@@ -504,7 +504,7 @@ paths:
 | 
			
		||||
              string
 | 
			
		||||
          required: true
 | 
			
		||||
      responses:
 | 
			
		||||
        200:
 | 
			
		||||
        204:
 | 
			
		||||
          description: successful operation
 | 
			
		||||
          content:
 | 
			
		||||
            application/json:
 | 
			
		||||
@@ -613,7 +613,7 @@ paths:
 | 
			
		||||
            format: int64
 | 
			
		||||
          required: true
 | 
			
		||||
      responses:
 | 
			
		||||
        200:
 | 
			
		||||
        204:
 | 
			
		||||
          $ref: '#/components/responses/Success'
 | 
			
		||||
        403:
 | 
			
		||||
          $ref: '#/components/responses/Unauthorized'
 | 
			
		||||
@@ -731,7 +731,7 @@ paths:
 | 
			
		||||
            format: uuid
 | 
			
		||||
          required: true
 | 
			
		||||
      responses:
 | 
			
		||||
        200:
 | 
			
		||||
        204:
 | 
			
		||||
          $ref: '#/components/responses/Success'
 | 
			
		||||
        403:
 | 
			
		||||
          $ref: '#/components/responses/Unauthorized'
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,5 @@
 | 
			
		||||
//
 | 
			
		||||
//	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.
 | 
			
		||||
// Created by stephane bourque on 2021-06-04.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef UCENTRALGW_ALBHEALTHCHECKSERVER_H
 | 
			
		||||
@@ -24,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.
 | 
			
		||||
@@ -89,7 +85,7 @@ namespace uCentral {
 | 
			
		||||
 | 
			
		||||
            int Start() {
 | 
			
		||||
                if(Daemon()->ConfigGetBool("alb.enable",false)) {
 | 
			
		||||
                    Port_ = (int)Daemon()->ConfigGetInt("alb.port",15017);
 | 
			
		||||
                    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);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										88
									
								
								src/AuthClient.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								src/AuthClient.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,88 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by stephane bourque on 2021-06-30.
 | 
			
		||||
//
 | 
			
		||||
#include <utility>
 | 
			
		||||
 | 
			
		||||
#include "AuthClient.h"
 | 
			
		||||
#include "RESTAPI_SecurityObjects.h"
 | 
			
		||||
#include "Daemon.h"
 | 
			
		||||
#include "OpenAPIRequest.h"
 | 
			
		||||
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
	class AuthClient * AuthClient::instance_ = nullptr;
 | 
			
		||||
 | 
			
		||||
	int AuthClient::Start() {
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void AuthClient::Stop() {
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void AuthClient::RemovedCachedToken(const std::string &Token) {
 | 
			
		||||
		SubMutexGuard G(Mutex_);
 | 
			
		||||
		UserCache_.erase(Token);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	bool IsTokenExpired(const SecurityObjects::WebToken &T) {
 | 
			
		||||
		return ((T.expires_in_+T.created_)<std::time(nullptr));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	bool AuthClient::IsAuthorized(Poco::Net::HTTPServerRequest & Request, 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;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										45
									
								
								src/AuthClient.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								src/AuthClient.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by stephane bourque on 2021-06-30.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef UCENTRALGW_AUTHCLIENT_H
 | 
			
		||||
#define UCENTRALGW_AUTHCLIENT_H
 | 
			
		||||
 | 
			
		||||
#include "Poco/JSON/Object.h"
 | 
			
		||||
#include "Poco/Net/HTTPServerRequest.h"
 | 
			
		||||
#include "Poco/Net/HTTPServerResponse.h"
 | 
			
		||||
#include "Poco/JWT/Signer.h"
 | 
			
		||||
#include "Poco/SHA2Engine.h"
 | 
			
		||||
#include "RESTAPI_SecurityObjects.h"
 | 
			
		||||
#include "SubSystemServer.h"
 | 
			
		||||
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
class AuthClient : public SubSystemServer {
 | 
			
		||||
	  public:
 | 
			
		||||
		explicit AuthClient() noexcept:
 | 
			
		||||
			SubSystemServer("Authentication", "AUTH-CLNT", "authentication")
 | 
			
		||||
		{
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		static AuthClient *instance() {
 | 
			
		||||
			if (instance_ == nullptr) {
 | 
			
		||||
				instance_ = new AuthClient;
 | 
			
		||||
			}
 | 
			
		||||
			return instance_;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		int Start() override;
 | 
			
		||||
		void Stop() override;
 | 
			
		||||
		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_;
 | 
			
		||||
		OpenWifi::SecurityObjects::UserInfoCache 		UserCache_;
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	inline AuthClient * AuthClient() { return AuthClient::instance(); }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // UCENTRALGW_AUTHCLIENT_H
 | 
			
		||||
@@ -22,7 +22,7 @@
 | 
			
		||||
 | 
			
		||||
#include "SMTPMailerService.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    class AuthService *AuthService::instance_ = nullptr;
 | 
			
		||||
 | 
			
		||||
    AuthService::ACCESS_TYPE AuthService::IntToAccessType(int C) {
 | 
			
		||||
@@ -277,7 +277,7 @@ namespace uCentral {
 | 
			
		||||
    std::string AuthService::ComputePasswordHash(const std::string &UserName, const std::string &Password) {
 | 
			
		||||
        std::string UName = Poco::trim(Poco::toLower(UserName));
 | 
			
		||||
        SHA2_.update(Password + UName);
 | 
			
		||||
        return uCentral::Utils::ToHex(SHA2_.digest());
 | 
			
		||||
        return Utils::ToHex(SHA2_.digest());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool AuthService::SendEmailToUser(std::string &Email, EMAIL_REASON Reason) {
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@
 | 
			
		||||
 | 
			
		||||
#include "RESTAPI_SecurityObjects.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral{
 | 
			
		||||
namespace OpenWifi{
 | 
			
		||||
 | 
			
		||||
    static const std::string AUTHENTICATION_SYSTEM{"SYSTEM"};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@
 | 
			
		||||
#include "RESTAPI_InternalServer.h"
 | 
			
		||||
#include "AuthService.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    class Daemon *Daemon::instance_ = nullptr;
 | 
			
		||||
 | 
			
		||||
    class Daemon *Daemon::instance() {
 | 
			
		||||
@@ -55,7 +55,7 @@ namespace uCentral {
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv) {
 | 
			
		||||
    try {
 | 
			
		||||
        auto App = uCentral::Daemon::instance();
 | 
			
		||||
        auto App = OpenWifi::Daemon::instance();
 | 
			
		||||
        auto ExitCode =  App->run(argc, argv);
 | 
			
		||||
        delete App;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -21,15 +21,15 @@
 | 
			
		||||
#include "Poco/Crypto/Cipher.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "uCentralTypes.h"
 | 
			
		||||
#include "OpenWifiTypes.h"
 | 
			
		||||
#include "MicroService.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    static const char * vDAEMON_PROPERTIES_FILENAME = "ucentralsec.properties";
 | 
			
		||||
    static const char * vDAEMON_ROOT_ENV_VAR = "UCENTRALSEC_ROOT";
 | 
			
		||||
    static const char * vDAEMON_CONFIG_ENV_VAR = "UCENTRALSEC_CONFIG";
 | 
			
		||||
    static const char * vDAEMON_APP_NAME = "uCentralSec";
 | 
			
		||||
    static const char * vDAEMON_APP_NAME = uSERVICE_SECURITY.c_str();
 | 
			
		||||
    static const uint64_t vDAEMON_BUS_TIMER = 5000;
 | 
			
		||||
 | 
			
		||||
    class Daemon : public MicroService {
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@
 | 
			
		||||
#include "Daemon.h"
 | 
			
		||||
#include "Utils.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
	class KafkaManager *KafkaManager::instance_ = nullptr;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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:
 | 
			
		||||
 
 | 
			
		||||
@@ -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"};
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -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:
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										68
									
								
								src/OpenAPIRequest.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								src/OpenAPIRequest.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,68 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by stephane bourque on 2021-07-01.
 | 
			
		||||
//
 | 
			
		||||
#include <iostream>
 | 
			
		||||
 | 
			
		||||
#include "OpenAPIRequest.h"
 | 
			
		||||
 | 
			
		||||
#include "Poco/Net/HTTPSClientSession.h"
 | 
			
		||||
#include <Poco/Net/HTTPClientSession.h>
 | 
			
		||||
#include <Poco/Net/HTTPRequest.h>
 | 
			
		||||
#include <Poco/Net/HTTPResponse.h>
 | 
			
		||||
#include <Poco/StreamCopier.h>
 | 
			
		||||
#include <Poco/JSON/Parser.h>
 | 
			
		||||
#include <Poco/Path.h>
 | 
			
		||||
#include <Poco/URI.h>
 | 
			
		||||
#include <Poco/Exception.h>
 | 
			
		||||
#include "Utils.h"
 | 
			
		||||
#include "Daemon.h"
 | 
			
		||||
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
	OpenAPIRequestGet::OpenAPIRequestGet( 	const std::string & ServiceType,
 | 
			
		||||
											const std::string & EndPoint,
 | 
			
		||||
									 		Types::StringPairVec & QueryData,
 | 
			
		||||
											uint64_t msTimeout):
 | 
			
		||||
 		Type_(ServiceType),
 | 
			
		||||
 		EndPoint_(EndPoint),
 | 
			
		||||
		QueryData_(QueryData),
 | 
			
		||||
		msTimeout_(msTimeout) {
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	int OpenAPIRequestGet::Do(Poco::JSON::Object::Ptr &ResponseObject) {
 | 
			
		||||
		try {
 | 
			
		||||
		    auto Services = Daemon()->GetServices(Type_);
 | 
			
		||||
			for(auto const &Svc:Services) {
 | 
			
		||||
				Poco::URI	URI(Svc.PrivateEndPoint);
 | 
			
		||||
				Poco::Net::HTTPSClientSession Session(URI.getHost(), URI.getPort());
 | 
			
		||||
 | 
			
		||||
				URI.setPath(EndPoint_);
 | 
			
		||||
				for (const auto &qp : QueryData_)
 | 
			
		||||
					URI.addQueryParameter(qp.first, qp.second);
 | 
			
		||||
 | 
			
		||||
				std::string Path(URI.getPathAndQuery());
 | 
			
		||||
				Session.setTimeout(Poco::Timespan(msTimeout_/1000, msTimeout_ % 1000));
 | 
			
		||||
 | 
			
		||||
				Poco::Net::HTTPRequest Request(Poco::Net::HTTPRequest::HTTP_GET,
 | 
			
		||||
											   Path,
 | 
			
		||||
											   Poco::Net::HTTPMessage::HTTP_1_1);
 | 
			
		||||
				Request.add("X-API-KEY", Svc.AccessKey);
 | 
			
		||||
				Session.sendRequest(Request);
 | 
			
		||||
 | 
			
		||||
				Poco::Net::HTTPResponse Response;
 | 
			
		||||
				std::istream &is = Session.receiveResponse(Response);
 | 
			
		||||
				if(Response.getStatus()==Poco::Net::HTTPResponse::HTTP_OK) {
 | 
			
		||||
					Poco::JSON::Parser	P;
 | 
			
		||||
					ResponseObject = P.parse(is).extract<Poco::JSON::Object::Ptr>();
 | 
			
		||||
				}
 | 
			
		||||
				return Response.getStatus();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		catch (const Poco::Exception &E)
 | 
			
		||||
		{
 | 
			
		||||
			std::cerr << E.displayText() << std::endl;
 | 
			
		||||
		}
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										29
									
								
								src/OpenAPIRequest.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/OpenAPIRequest.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by stephane bourque on 2021-07-01.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef UCENTRALGW_OPENAPIREQUEST_H
 | 
			
		||||
#define UCENTRALGW_OPENAPIREQUEST_H
 | 
			
		||||
 | 
			
		||||
#include "Poco/JSON/Object.h"
 | 
			
		||||
 | 
			
		||||
#include "OpenWifiTypes.h"
 | 
			
		||||
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
	class OpenAPIRequestGet {
 | 
			
		||||
	  public:
 | 
			
		||||
		explicit OpenAPIRequestGet( const std::string & Type,
 | 
			
		||||
								   	const std::string & EndPoint,
 | 
			
		||||
									Types::StringPairVec & QueryData,
 | 
			
		||||
									uint64_t msTimeout);
 | 
			
		||||
		int Do(Poco::JSON::Object::Ptr &ResponseObject);
 | 
			
		||||
	  private:
 | 
			
		||||
		std::string 			Type_;
 | 
			
		||||
		std::string 			EndPoint_;
 | 
			
		||||
		Types::StringPairVec 	QueryData_;
 | 
			
		||||
		uint64_t 				msTimeout_;
 | 
			
		||||
	};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // UCENTRALGW_OPENAPIREQUEST_H
 | 
			
		||||
@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -9,7 +9,7 @@
 | 
			
		||||
#include "Utils.h"
 | 
			
		||||
#include "RESTAPI_protocol.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    void RESTAPI_AssetServer::handleRequest(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) {
 | 
			
		||||
        if(Request.getMethod()==Poco::Net::HTTPRequest::HTTP_GET)
 | 
			
		||||
            DoGet(Request, Response);
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
 | 
			
		||||
#include "RESTAPI_handler.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    class RESTAPI_AssetServer : public RESTAPIHandler {
 | 
			
		||||
    public:
 | 
			
		||||
        RESTAPI_AssetServer(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@
 | 
			
		||||
 | 
			
		||||
#include "Utils.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    class RESTAPI_InternalServer *RESTAPI_InternalServer::instance_ = nullptr;
 | 
			
		||||
 | 
			
		||||
@@ -58,7 +58,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()),
 | 
			
		||||
                                   Utils::FormatIPv6(Request.clientAddress().toString()),
 | 
			
		||||
                                   Request.getMethod(), Request.getURI()));
 | 
			
		||||
 | 
			
		||||
        Poco::URI uri(Request.getURI());
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@
 | 
			
		||||
#include "Poco/Net/HTTPServerRequest.h"
 | 
			
		||||
#include "Poco/Net/NetException.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    class RESTAPI_InternalServer : public SubSystemServer {
 | 
			
		||||
        public:
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
	};
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@
 | 
			
		||||
#include "RESTAPI_server.h"
 | 
			
		||||
#include "Daemon.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    void RESTAPI_action_links::handleRequest(Poco::Net::HTTPServerRequest &Request,
 | 
			
		||||
                       Poco::Net::HTTPServerResponse &Response) {
 | 
			
		||||
        //  there is no authentication here, this is just someone clicking on a link
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@
 | 
			
		||||
#include "Poco/StreamCopier.h"
 | 
			
		||||
#include "Poco/CountingStream.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    class RESTAPI_action_links : public RESTAPIHandler {
 | 
			
		||||
    public:
 | 
			
		||||
        RESTAPI_action_links(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@
 | 
			
		||||
#include "Utils.h"
 | 
			
		||||
#include "RESTAPI_protocol.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    void AvatarPartHandler::handlePart(const Poco::Net::MessageHeader &Header, std::istream &Stream) {
 | 
			
		||||
        FileType_ = Header.get(RESTAPI::Protocol::CONTENTTYPE, RESTAPI::Protocol::UNSPECIFIED);
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@
 | 
			
		||||
 | 
			
		||||
#include "RESTAPI_handler.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    class AvatarPartHandler : public Poco::Net::PartHandler {
 | 
			
		||||
    public:
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
@@ -364,18 +364,21 @@ namespace uCentral {
 | 
			
		||||
		Poco::JSON::Stringifier::stringify(Object, Answer);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void 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, 0);
 | 
			
		||||
		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);
 | 
			
		||||
	bool RESTAPIHandler::InitQueryBlock() {
 | 
			
		||||
		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;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] uint64_t RESTAPIHandler::Get(const char *Parameter,const Poco::JSON::Object::Ptr &Obj, uint64_t Default){
 | 
			
		||||
@@ -397,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);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@
 | 
			
		||||
 | 
			
		||||
#include "RESTAPI_SecurityObjects.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    class RESTAPI_PartHandler: public Poco::Net::PartHandler
 | 
			
		||||
    {
 | 
			
		||||
@@ -140,7 +140,7 @@ namespace uCentral {
 | 
			
		||||
        void SendFile(Poco::File & File, Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response);
 | 
			
		||||
 | 
			
		||||
        const std::string &GetBinding(const std::string &Name, const std::string &Default);
 | 
			
		||||
		void InitQueryBlock();
 | 
			
		||||
		bool InitQueryBlock();
 | 
			
		||||
 | 
			
		||||
		[[nodiscard]] static uint64_t Get(const char *Parameter,const Poco::JSON::Object::Ptr &Obj, uint64_t Default=0);
 | 
			
		||||
		[[nodiscard]] static std::string GetS(const char *Parameter,const Poco::JSON::Object::Ptr &Obj, const std::string & Default="");
 | 
			
		||||
@@ -166,7 +166,7 @@ namespace uCentral {
 | 
			
		||||
						   Poco::Net::HTTPServerResponse &Response) override {
 | 
			
		||||
			if (!IsAuthorized(Request, Response))
 | 
			
		||||
				return;
 | 
			
		||||
			BadRequest(Request, Response);
 | 
			
		||||
			BadRequest(Request, Response, "Unknown API endpoint");
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@
 | 
			
		||||
 | 
			
		||||
#include "Utils.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
	void RESTAPI_oauth2Handler::handleRequest(Poco::Net::HTTPServerRequest &Request,
 | 
			
		||||
											  Poco::Net::HTTPServerResponse &Response) {
 | 
			
		||||
 | 
			
		||||
@@ -29,9 +29,9 @@ namespace uCentral {
 | 
			
		||||
				Poco::JSON::Parser parser;
 | 
			
		||||
				Poco::JSON::Object::Ptr Obj = parser.parse(Request.stream()).extract<Poco::JSON::Object::Ptr>();
 | 
			
		||||
 | 
			
		||||
				auto userId = GetS(uCentral::RESTAPI::Protocol::USERID, Obj);
 | 
			
		||||
				auto password = GetS(uCentral::RESTAPI::Protocol::PASSWORD, Obj);
 | 
			
		||||
				auto newPassword = GetS(uCentral::RESTAPI::Protocol::NEWPASSWORD, Obj);
 | 
			
		||||
				auto userId = GetS(RESTAPI::Protocol::USERID, Obj);
 | 
			
		||||
				auto password = GetS(RESTAPI::Protocol::PASSWORD, Obj);
 | 
			
		||||
				auto newPassword = GetS(RESTAPI::Protocol::NEWPASSWORD, Obj);
 | 
			
		||||
 | 
			
		||||
                if(GetBoolParameter(RESTAPI::Protocol::REQUIREMENTS, false)) {
 | 
			
		||||
                    Poco::JSON::Object  Answer;
 | 
			
		||||
@@ -79,7 +79,7 @@ namespace uCentral {
 | 
			
		||||
                    UnAuthorized(Request, Response, "Not authorized.");
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				auto Token = GetBinding(uCentral::RESTAPI::Protocol::TOKEN, "...");
 | 
			
		||||
				auto Token = GetBinding(RESTAPI::Protocol::TOKEN, "...");
 | 
			
		||||
				if (Token == SessionToken_) {
 | 
			
		||||
					AuthService()->Logout(Token);
 | 
			
		||||
					ReturnStatus(Request, Response, Poco::Net::HTTPResponse::HTTP_NO_CONTENT, true);
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@
 | 
			
		||||
 | 
			
		||||
#include "RESTAPI_handler.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
	class RESTAPI_oauth2Handler : public RESTAPIHandler {
 | 
			
		||||
	  public:
 | 
			
		||||
		RESTAPI_oauth2Handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)
 | 
			
		||||
 
 | 
			
		||||
@@ -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";
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@
 | 
			
		||||
#include "Daemon.h"
 | 
			
		||||
#include "Utils.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    class RESTAPI_Server *RESTAPI_Server::instance_ = nullptr;
 | 
			
		||||
 | 
			
		||||
@@ -59,7 +59,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());
 | 
			
		||||
        const auto & Path = uri.getPath();
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@
 | 
			
		||||
#include "Poco/Net/HTTPServerRequest.h"
 | 
			
		||||
#include "Poco/Net/NetException.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    class RESTAPI_Server : public SubSystemServer {
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@
 | 
			
		||||
#include "Daemon.h"
 | 
			
		||||
#include "RESTAPI_SecurityObjects.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    void RESTAPI_systemEndpoints_handler::handleRequest(Poco::Net::HTTPServerRequest &Request,
 | 
			
		||||
                                                        Poco::Net::HTTPServerResponse &Response) {
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@
 | 
			
		||||
#define UCENTRALSEC_RESTAPI_SYSTEMENDPOINTS_HANDLER_H
 | 
			
		||||
 | 
			
		||||
#include "RESTAPI_handler.h"
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    class RESTAPI_systemEndpoints_handler : public RESTAPIHandler {
 | 
			
		||||
    public:
 | 
			
		||||
        RESTAPI_systemEndpoints_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 | 
			
		||||
@@ -27,8 +27,8 @@ namespace uCentral {
 | 
			
		||||
			DoPost(Request, Response);
 | 
			
		||||
		else if(Request.getMethod()==Poco::Net::HTTPRequest::HTTP_GET)
 | 
			
		||||
			DoGet(Request, Response);
 | 
			
		||||
 | 
			
		||||
		BadRequest(Request, Response);
 | 
			
		||||
		else
 | 
			
		||||
            BadRequest(Request, Response, "Unsupported method.");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void RESTAPI_system_command::DoPost(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,45 +56,45 @@ 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) {
 | 
			
		||||
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		} catch(const Poco::Exception &E) {
 | 
			
		||||
			Logger_.log(E);
 | 
			
		||||
		}
 | 
			
		||||
		BadRequest(Request, Response);
 | 
			
		||||
		BadRequest(Request, Response, "Unsupported or missing parameters.");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void RESTAPI_system_command::DoGet(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) {
 | 
			
		||||
@@ -126,7 +126,7 @@ namespace uCentral {
 | 
			
		||||
		} catch (const Poco::Exception &E) {
 | 
			
		||||
			Logger_.log(E);
 | 
			
		||||
		}
 | 
			
		||||
		BadRequest(Request, Response);
 | 
			
		||||
		BadRequest(Request, Response, "Unsupported or missing parameters.");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@
 | 
			
		||||
#include "Utils.h"
 | 
			
		||||
#include "RESTAPI_utils.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    void RESTAPI_user_handler::handleRequest(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) {
 | 
			
		||||
 | 
			
		||||
        if (!ContinueProcessing(Request, Response))
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
 | 
			
		||||
#include "RESTAPI_handler.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    class RESTAPI_user_handler : public RESTAPIHandler {
 | 
			
		||||
    public:
 | 
			
		||||
        RESTAPI_user_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
#include "RESTAPI_protocol.h"
 | 
			
		||||
#include "Utils.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    void RESTAPI_users_handler::handleRequest(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) {
 | 
			
		||||
        if (!ContinueProcessing(Request, Response))
 | 
			
		||||
            return;
 | 
			
		||||
@@ -41,7 +41,7 @@ namespace uCentral {
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    Poco::JSON::Object RetObj;
 | 
			
		||||
                    RetObj.set(uCentral::RESTAPI::Protocol::USERS, ArrayObj);
 | 
			
		||||
                    RetObj.set(RESTAPI::Protocol::USERS, ArrayObj);
 | 
			
		||||
                    ReturnObject(Request, RetObj, Response);
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
@@ -61,7 +61,7 @@ namespace uCentral {
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                Poco::JSON::Object RetObj;
 | 
			
		||||
                RetObj.set(uCentral::RESTAPI::Protocol::USERS, ArrayObj);
 | 
			
		||||
                RetObj.set(RESTAPI::Protocol::USERS, ArrayObj);
 | 
			
		||||
                ReturnObject(Request, RetObj, Response);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
 | 
			
		||||
#include "RESTAPI_handler.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    class RESTAPI_users_handler : public RESTAPIHandler {
 | 
			
		||||
    public:
 | 
			
		||||
        RESTAPI_users_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
#include "AuthService.h"
 | 
			
		||||
#include "Utils.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    void RESTAPI_validateToken_handler::handleRequest(Poco::Net::HTTPServerRequest &Request,
 | 
			
		||||
                                                      Poco::Net::HTTPServerResponse &Response) {
 | 
			
		||||
 | 
			
		||||
@@ -33,6 +33,7 @@ namespace uCentral {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            NotFound(Request, Response);
 | 
			
		||||
            return;
 | 
			
		||||
        } catch (const Poco::Exception &E) {
 | 
			
		||||
            Logger_.log(E);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
 | 
			
		||||
#include "RESTAPI_handler.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    class RESTAPI_validateToken_handler : public RESTAPIHandler {
 | 
			
		||||
    public:
 | 
			
		||||
        RESTAPI_validateToken_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal)
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@
 | 
			
		||||
#include "Utils.h"
 | 
			
		||||
#include "Daemon.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    class SMTPMailerService * SMTPMailerService::instance_ = nullptr;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@
 | 
			
		||||
 | 
			
		||||
#include "Poco/File.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    enum MESSAGE_ATTRIBUTES {
 | 
			
		||||
        RECIPIENT_EMAIL,
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@
 | 
			
		||||
#include "Poco/Util/Application.h"
 | 
			
		||||
#include "Utils.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    class Storage *Storage::instance_ = nullptr;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@
 | 
			
		||||
#include "RESTAPI_SecurityObjects.h"
 | 
			
		||||
#include "SubSystemServer.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    static const std::string AllActionLinksFieldsForSelect {
 | 
			
		||||
            "Id, "
 | 
			
		||||
@@ -179,6 +179,16 @@ namespace uCentral {
 | 
			
		||||
 | 
			
		||||
        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) {
 | 
			
		||||
		        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-1) + " ";
 | 
			
		||||
		    } else if(dbType_==mysql) {
 | 
			
		||||
		        return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From-1) + " ";
 | 
			
		||||
		    }
 | 
			
		||||
		    return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From-1) + " ";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
#ifndef SMALL_BUILD
 | 
			
		||||
        int 	Setup_MySQL();
 | 
			
		||||
 
 | 
			
		||||
@@ -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)),
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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) &&
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										17
									
								
								src/Utils.h
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/Utils.h
									
									
									
									
									
								
							@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@
 | 
			
		||||
#include "Poco/Data/LOBStream.h"
 | 
			
		||||
#include "Daemon.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
                            "Id			    VARCHAR(36) PRIMARY KEY, "
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@
 | 
			
		||||
#ifndef WLAN_CLOUD_UCENTRALSEC_STORAGE_AVATAR_H
 | 
			
		||||
#define WLAN_CLOUD_UCENTRALSEC_STORAGE_AVATAR_H
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
}
 | 
			
		||||
@@ -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
									
								
							
							
						
						
									
										82
									
								
								src/storage_setup.cpp
									
									
									
									
									
										Normal 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
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -1,26 +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 {
 | 
			
		||||
	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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
#include "storage_users.h"
 | 
			
		||||
#include "storage_avatar.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    int Storage::Create_Tables() {
 | 
			
		||||
        Create_UserTable();
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@
 | 
			
		||||
#include "Poco/Tuple.h"
 | 
			
		||||
#include "storage_users.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
 | 
			
		||||
    bool Convert(const UserInfoRecord &T, SecurityObjects::UserInfo &U) {
 | 
			
		||||
        U.Id = T.get<0>();
 | 
			
		||||
@@ -221,17 +221,16 @@ namespace uCentral {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool Storage::GetUsers( uint64_t Offset, uint64_t Limit, SecurityObjects::UserInfoVec & Users) {
 | 
			
		||||
    bool Storage::GetUsers( uint64_t Offset, uint64_t HowMany, SecurityObjects::UserInfoVec & Users) {
 | 
			
		||||
        try {
 | 
			
		||||
            Poco::Data::Session Sess = Pool_->get();
 | 
			
		||||
            Poco::Data::Statement Select(Sess);
 | 
			
		||||
            UserInfoRecordList Records;
 | 
			
		||||
 | 
			
		||||
            std::string St1{"select " + AllUsersFieldsForSelect + " from users"};
 | 
			
		||||
            std::string St1{"select " + AllUsersFieldsForSelect + " from users order by id ASC "};
 | 
			
		||||
 | 
			
		||||
            Select << ConvertParams(St1) ,
 | 
			
		||||
                    Poco::Data::Keywords::into(Records),
 | 
			
		||||
                    Poco::Data::Keywords::range(Offset, Offset + Limit);
 | 
			
		||||
            Select << ConvertParams(St1) + ComputeRange(Offset, HowMany),
 | 
			
		||||
                        Poco::Data::Keywords::into(Records);
 | 
			
		||||
            Select.execute();
 | 
			
		||||
 | 
			
		||||
            for(const auto &R:Records) {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,9 +5,9 @@
 | 
			
		||||
#ifndef UCENTRALSEC_STORAGE_USERS_H
 | 
			
		||||
#define UCENTRALSEC_STORAGE_USERS_H
 | 
			
		||||
 | 
			
		||||
namespace uCentral {
 | 
			
		||||
namespace OpenWifi {
 | 
			
		||||
    static const std::string AllUsersFieldsForCreation{
 | 
			
		||||
            "Id             varchar(36),"
 | 
			
		||||
        " Id             varchar(36) UNIQUE PRIMARY KEY,"
 | 
			
		||||
            "name           varchar,"
 | 
			
		||||
            "description    varchar,"
 | 
			
		||||
            "avatar         varchar,"
 | 
			
		||||
@@ -116,6 +116,9 @@ namespace uCentral {
 | 
			
		||||
            "canceled       bigint"
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    typedef Poco::Tuple <
 | 
			
		||||
        std::string,    // Id = 0;
 | 
			
		||||
        std::string,    // name;
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@
 | 
			
		||||
 | 
			
		||||
#include "Poco/String.h"
 | 
			
		||||
 | 
			
		||||
namespace uCentral::uCentralProtocol {
 | 
			
		||||
namespace OpenWifi::uCentralProtocol {
 | 
			
		||||
 | 
			
		||||
	const int SERIAL_NUMBER_LENGTH = 30;
 | 
			
		||||
 | 
			
		||||
@@ -79,6 +79,15 @@ namespace uCentral::uCentralProtocol {
 | 
			
		||||
	static const char * VERBOSE = "verbose";
 | 
			
		||||
	static const char * BANDS = "bands";
 | 
			
		||||
	static const char * CHANNELS = "channels";
 | 
			
		||||
	static const char * PASSWORD = "password";
 | 
			
		||||
	static const char * DEVICEUPDATE = "deviceupdate";
 | 
			
		||||
 | 
			
		||||
    static const char * SERIALNUMBER = "serialNumber";
 | 
			
		||||
    static const char * COMPATIBLE = "compatible";
 | 
			
		||||
    static const char * DISCONNECTION = "disconnection";
 | 
			
		||||
    static const char * TIMESTAMP = "timestamp";
 | 
			
		||||
    static const char * SYSTEM = "system";
 | 
			
		||||
    static const char * HOST = "host";
 | 
			
		||||
 | 
			
		||||
	enum EVENT_MSG {
 | 
			
		||||
			ET_UNKNOWN,
 | 
			
		||||
@@ -89,7 +98,8 @@ namespace uCentral::uCentralProtocol {
 | 
			
		||||
			ET_CRASHLOG,
 | 
			
		||||
			ET_PING,
 | 
			
		||||
			ET_CFGPENDING,
 | 
			
		||||
			ET_RECOVERY
 | 
			
		||||
			ET_RECOVERY,
 | 
			
		||||
			ET_DEVICEUPDATE
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
	static EVENT_MSG EventFromString(const std::string & Method) {
 | 
			
		||||
@@ -109,6 +119,8 @@ namespace uCentral::uCentralProtocol {
 | 
			
		||||
			return ET_CFGPENDING;
 | 
			
		||||
		} else if (!Poco::icompare(Method, RECOVERY)) {
 | 
			
		||||
			return ET_RECOVERY;
 | 
			
		||||
		} else if (!Poco::icompare(Method, DEVICEUPDATE)) {
 | 
			
		||||
			return ET_DEVICEUPDATE;
 | 
			
		||||
		} else
 | 
			
		||||
			return ET_UNKNOWN;
 | 
			
		||||
	};
 | 
			
		||||
 
 | 
			
		||||
@@ -73,7 +73,7 @@ ucentral.kafka.queue.buffering.max.ms = 50
 | 
			
		||||
 | 
			
		||||
ucentral.document.policy.access = /wwwassets/access_policy.html
 | 
			
		||||
ucentral.document.policy.password = /wwwassets/password_policy.html
 | 
			
		||||
 | 
			
		||||
ucentral.avatar.maxsize = 2000000
 | 
			
		||||
#
 | 
			
		||||
# This section select which form of persistence you need
 | 
			
		||||
# Only one selected at a time. If you select multiple, this service will die if a horrible
 | 
			
		||||
 
 | 
			
		||||
@@ -5,41 +5,18 @@ Wants=network-online.target
 | 
			
		||||
 | 
			
		||||
[Service]
 | 
			
		||||
Type=simple
 | 
			
		||||
# the default is not to use systemd for cgroups because the delegate issues still
 | 
			
		||||
# exists and systemd currently does not support the cgroup feature set required
 | 
			
		||||
# for containers run by docker
 | 
			
		||||
Environment="UCENTRALSEC_ROOT=/home/admin/dev/wlan-cloud-ucentralsec"
 | 
			
		||||
ExecStart=/home/admin/dev/wlan-cloud-ucentralsec/cmake-build/ucentralsec
 | 
			
		||||
WorkingDirectory=/home/admin/dev/wlan-cloud-ucentralsec
 | 
			
		||||
ExecReload=/bin/kill -s HUP $MAINPID
 | 
			
		||||
# ExecReload=/bin/kill -s HUP $MAINPID
 | 
			
		||||
User=admin
 | 
			
		||||
TimeoutSec=0
 | 
			
		||||
# TimeoutSec=0
 | 
			
		||||
RestartSec=2
 | 
			
		||||
Restart=always
 | 
			
		||||
 | 
			
		||||
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
 | 
			
		||||
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
 | 
			
		||||
# to make them work for either version of systemd.
 | 
			
		||||
StartLimitBurst=3
 | 
			
		||||
# KillMode=process
 | 
			
		||||
LimitNOFILE=500000
 | 
			
		||||
LimitNPROC=500000
 | 
			
		||||
 | 
			
		||||
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
 | 
			
		||||
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
 | 
			
		||||
# this option work for either version of systemd.
 | 
			
		||||
# StartLimitInterval=60s
 | 
			
		||||
 | 
			
		||||
# Having non-zero Limit*s causes performance problems due to accounting overhead
 | 
			
		||||
# in the kernel. We recommend using cgroups to do container-local accounting.
 | 
			
		||||
LimitNOFILE=infinity
 | 
			
		||||
LimitNPROC=infinity
 | 
			
		||||
LimitCORE=infinity
 | 
			
		||||
 | 
			
		||||
# Comment TasksMax if your systemd version does not support it.
 | 
			
		||||
# Only systemd 226 and above support this option.
 | 
			
		||||
TasksMax=infinity
 | 
			
		||||
 | 
			
		||||
# set delegate yes so that systemd does not reset the cgroups of docker containers
 | 
			
		||||
Delegate=yes
 | 
			
		||||
 | 
			
		||||
# kill only the docker process, not all processes in the cgroup
 | 
			
		||||
KillMode=process
 | 
			
		||||
OOMScoreAdjust=-500
 | 
			
		||||
[Install]
 | 
			
		||||
WantedBy=multi-user.target
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user