mirror of
				https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
				synced 2025-10-31 02:37:56 +00:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			v2.1.0-RC1
			...
			v2.0.0
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 1de35630e9 | 
| @@ -1,5 +1,5 @@ | |||||||
| cmake_minimum_required(VERSION 3.13) | cmake_minimum_required(VERSION 3.13) | ||||||
| project(ucentralsec VERSION 2.1.0) | project(ucentralsec VERSION 2.0.0) | ||||||
|  |  | ||||||
| set(CMAKE_CXX_STANDARD 17) | set(CMAKE_CXX_STANDARD 17) | ||||||
|  |  | ||||||
| @@ -62,18 +62,14 @@ add_executable( ucentralsec | |||||||
|                 src/KafkaManager.h src/KafkaManager.cpp |                 src/KafkaManager.h src/KafkaManager.cpp | ||||||
|                 src/StorageService.cpp src/StorageService.h |                 src/StorageService.cpp src/StorageService.h | ||||||
|                 src/Utils.cpp src/Utils.h |                 src/Utils.cpp src/Utils.h | ||||||
|                 src/storage_setup.cpp |                 src/storage_sqlite.cpp src/storage_sqlite.cpp src/storage_pgql.cpp src/storage_mysql.cpp | ||||||
|                 src/storage_tables.cpp src/SMTPMailerService.cpp src/SMTPMailerService.h |                 src/storage_tables.cpp src/SMTPMailerService.cpp src/SMTPMailerService.h | ||||||
|                 src/RESTAPI_users_handler.cpp src/RESTAPI_users_handler.h |                 src/RESTAPI_users_handler.cpp src/RESTAPI_users_handler.h | ||||||
|                 src/RESTAPI_user_handler.cpp src/RESTAPI_user_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_action_links.cpp src/RESTAPI_action_links.h src/storage_users.cpp | ||||||
|                 src/RESTAPI_InternalServer.cpp src/RESTAPI_InternalServer.h |                 src/RESTAPI_InternalServer.cpp src/RESTAPI_InternalServer.h | ||||||
|                 src/RESTAPI_validateToken_handler.cpp src/RESTAPI_validateToken_handler.h |                 src/RESTAPI_validateToken_handler.cpp src/RESTAPI_validateToken_handler.h | ||||||
|                 src/RESTAPI_systemEndpoints_handler.cpp src/RESTAPI_systemEndpoints_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_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) | if(NOT SMALL_BUILD) | ||||||
|     target_link_libraries(ucentralsec PUBLIC |     target_link_libraries(ucentralsec PUBLIC | ||||||
|   | |||||||
| @@ -46,8 +46,7 @@ RUN addgroup -S "$UCENTRALSEC_USER" && \ | |||||||
|     adduser -S -G "$UCENTRALSEC_USER" "$UCENTRALSEC_USER" |     adduser -S -G "$UCENTRALSEC_USER" "$UCENTRALSEC_USER" | ||||||
|  |  | ||||||
| RUN mkdir /ucentral | 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 | RUN apk add --update --no-cache librdkafka mariadb-connector-c libpq unixodbc su-exec | ||||||
|  |  | ||||||
| COPY --from=builder /ucentralsec/cmake-build/ucentralsec /ucentral/ucentralsec | COPY --from=builder /ucentralsec/cmake-build/ucentralsec /ucentral/ucentralsec | ||||||
|   | |||||||
| @@ -1,18 +1,5 @@ | |||||||
| apiVersion: v2 | apiVersion: v1 | ||||||
| appVersion: "1.0" | appVersion: "1.0" | ||||||
| description: A Helm chart for Kubernetes | description: A Helm chart for Kubernetes | ||||||
| name: ucentralsec | name: ucentralsec | ||||||
| version: 0.1.0 | 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,11 +83,6 @@ spec: | |||||||
|             {{- toYaml . | nindent 12 }} |             {{- toYaml . | nindent 12 }} | ||||||
|           {{- end }} |           {{- end }} | ||||||
|  |  | ||||||
|       {{- with .Values.securityContext }} |  | ||||||
|       securityContext: |  | ||||||
|         {{- toYaml . | nindent 8 }} |  | ||||||
|       {{- end }} |  | ||||||
|  |  | ||||||
|       imagePullSecrets: |       imagePullSecrets: | ||||||
|       {{- range $image, $imageValue := .Values.images }} |       {{- range $image, $imageValue := .Values.images }} | ||||||
|         {{- if $imageValue.regcred }} |         {{- if $imageValue.regcred }} | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ fullnameOverride: "" | |||||||
| images: | images: | ||||||
|   ucentralsec: |   ucentralsec: | ||||||
|     repository: tip-tip-wlan-cloud-ucentral.jfrog.io/ucentralsec |     repository: tip-tip-wlan-cloud-ucentral.jfrog.io/ucentralsec | ||||||
|     tag: v2.1.0-RC1 |     tag: v2.0.0-RC1 | ||||||
|     pullPolicy: Always |     pullPolicy: Always | ||||||
| #    regcred: | #    regcred: | ||||||
| #      registry: tip-tip-wlan-cloud-ucentral.jfrog.io | #      registry: tip-tip-wlan-cloud-ucentral.jfrog.io | ||||||
| @@ -85,9 +85,6 @@ resources: {} | |||||||
|   #  cpu: 100m |   #  cpu: 100m | ||||||
|   #  memory: 128Mi |   #  memory: 128Mi | ||||||
|  |  | ||||||
| securityContext: |  | ||||||
|   fsGroup: 101 |  | ||||||
|  |  | ||||||
| nodeSelector: {} | nodeSelector: {} | ||||||
|  |  | ||||||
| tolerations: [] | tolerations: [] | ||||||
| @@ -176,7 +173,7 @@ configProperties: | |||||||
|   ucentral.system.commandchannel: /tmp/app_ucentralsec |   ucentral.system.commandchannel: /tmp/app_ucentralsec | ||||||
|   # Logging |   # Logging | ||||||
|   logging.formatters.f1.class: PatternFormatter |   logging.formatters.f1.class: PatternFormatter | ||||||
|   logging.formatters.f1.pattern: "%Y-%m-%d %H:%M:%S %s: [%p] %t" |   logging.formatters.f1.pattern: "%s: [%p] %t" | ||||||
|   logging.formatters.f1.times: UTC |   logging.formatters.f1.times: UTC | ||||||
|   logging.channels.c1.class: ConsoleChannel |   logging.channels.c1.class: ConsoleChannel | ||||||
|   logging.channels.c1.formatter: f1 |   logging.channels.c1.formatter: f1 | ||||||
| @@ -189,7 +186,7 @@ configProperties: | |||||||
|   logging.channels.c2.purgeCount: 20 |   logging.channels.c2.purgeCount: 20 | ||||||
|   logging.channels.c3.class: ConsoleChannel |   logging.channels.c3.class: ConsoleChannel | ||||||
|   logging.channels.c3.pattern: "%s: [%p] %t" |   logging.channels.c3.pattern: "%s: [%p] %t" | ||||||
|   logging.loggers.root.channel: c1 |   logging.loggers.root.channel: c2 | ||||||
|   logging.loggers.root.level: debug |   logging.loggers.root.level: debug | ||||||
|  |  | ||||||
|   # -> Secret part |   # -> Secret part | ||||||
| @@ -214,64 +211,3 @@ certs: | |||||||
|   # restapi-ca.pem: "" |   # restapi-ca.pem: "" | ||||||
|   # restapi-cert.pem: "" |   # restapi-cert.pem: "" | ||||||
|   # restapi-key.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 |               string | ||||||
|           required: true |           required: true | ||||||
|       responses: |       responses: | ||||||
|         204: |         200: | ||||||
|           description: successful operation |           description: successful operation | ||||||
|           content: |           content: | ||||||
|             application/json: |             application/json: | ||||||
| @@ -613,7 +613,7 @@ paths: | |||||||
|             format: int64 |             format: int64 | ||||||
|           required: true |           required: true | ||||||
|       responses: |       responses: | ||||||
|         204: |         200: | ||||||
|           $ref: '#/components/responses/Success' |           $ref: '#/components/responses/Success' | ||||||
|         403: |         403: | ||||||
|           $ref: '#/components/responses/Unauthorized' |           $ref: '#/components/responses/Unauthorized' | ||||||
| @@ -731,7 +731,7 @@ paths: | |||||||
|             format: uuid |             format: uuid | ||||||
|           required: true |           required: true | ||||||
|       responses: |       responses: | ||||||
|         204: |         200: | ||||||
|           $ref: '#/components/responses/Success' |           $ref: '#/components/responses/Success' | ||||||
|         403: |         403: | ||||||
|           $ref: '#/components/responses/Unauthorized' |           $ref: '#/components/responses/Unauthorized' | ||||||
|   | |||||||
| @@ -1,5 +1,9 @@ | |||||||
| // | // | ||||||
| // Created by stephane bourque on 2021-06-04. | //	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. | ||||||
| // | // | ||||||
|  |  | ||||||
| #ifndef UCENTRALGW_ALBHEALTHCHECKSERVER_H | #ifndef UCENTRALGW_ALBHEALTHCHECKSERVER_H | ||||||
| @@ -20,7 +24,7 @@ | |||||||
| #include "Daemon.h" | #include "Daemon.h" | ||||||
| #include "SubSystemServer.h" | #include "SubSystemServer.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
| 	class ALBRequestHandler: public Poco::Net::HTTPRequestHandler | 	class ALBRequestHandler: public Poco::Net::HTTPRequestHandler | ||||||
| 			/// Return a HTML document with the current date and time. | 			/// Return a HTML document with the current date and time. | ||||||
| @@ -85,7 +89,7 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
|             int Start() { |             int Start() { | ||||||
|                 if(Daemon()->ConfigGetBool("alb.enable",false)) { |                 if(Daemon()->ConfigGetBool("alb.enable",false)) { | ||||||
|                     Port_ = (int)Daemon()->ConfigGetInt("alb.port",15015); |                     Port_ = (int)Daemon()->ConfigGetInt("alb.port",15017); | ||||||
|                     Socket_ = std::make_unique<Poco::Net::ServerSocket>(Port_); |                     Socket_ = std::make_unique<Poco::Net::ServerSocket>(Port_); | ||||||
|                     auto Params = new Poco::Net::HTTPServerParams; |                     auto Params = new Poco::Net::HTTPServerParams; | ||||||
|                     Server_ = std::make_unique<Poco::Net::HTTPServer>(new ALBRequestHandlerFactory(Logger_), *Socket_, Params); |                     Server_ = std::make_unique<Poco::Net::HTTPServer>(new ALBRequestHandlerFactory(Logger_), *Socket_, Params); | ||||||
|   | |||||||
| @@ -1,88 +0,0 @@ | |||||||
| // |  | ||||||
| // 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; |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @@ -1,45 +0,0 @@ | |||||||
| // |  | ||||||
| // 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" | #include "SMTPMailerService.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     class AuthService *AuthService::instance_ = nullptr; |     class AuthService *AuthService::instance_ = nullptr; | ||||||
|  |  | ||||||
|     AuthService::ACCESS_TYPE AuthService::IntToAccessType(int C) { |     AuthService::ACCESS_TYPE AuthService::IntToAccessType(int C) { | ||||||
| @@ -277,7 +277,7 @@ namespace OpenWifi { | |||||||
|     std::string AuthService::ComputePasswordHash(const std::string &UserName, const std::string &Password) { |     std::string AuthService::ComputePasswordHash(const std::string &UserName, const std::string &Password) { | ||||||
|         std::string UName = Poco::trim(Poco::toLower(UserName)); |         std::string UName = Poco::trim(Poco::toLower(UserName)); | ||||||
|         SHA2_.update(Password + UName); |         SHA2_.update(Password + UName); | ||||||
|         return Utils::ToHex(SHA2_.digest()); |         return uCentral::Utils::ToHex(SHA2_.digest()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     bool AuthService::SendEmailToUser(std::string &Email, EMAIL_REASON Reason) { |     bool AuthService::SendEmailToUser(std::string &Email, EMAIL_REASON Reason) { | ||||||
|   | |||||||
| @@ -21,7 +21,7 @@ | |||||||
|  |  | ||||||
| #include "RESTAPI_SecurityObjects.h" | #include "RESTAPI_SecurityObjects.h" | ||||||
|  |  | ||||||
| namespace OpenWifi{ | namespace uCentral{ | ||||||
|  |  | ||||||
|     static const std::string AUTHENTICATION_SYSTEM{"SYSTEM"}; |     static const std::string AUTHENTICATION_SYSTEM{"SYSTEM"}; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -27,7 +27,7 @@ | |||||||
| #include "RESTAPI_InternalServer.h" | #include "RESTAPI_InternalServer.h" | ||||||
| #include "AuthService.h" | #include "AuthService.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     class Daemon *Daemon::instance_ = nullptr; |     class Daemon *Daemon::instance_ = nullptr; | ||||||
|  |  | ||||||
|     class Daemon *Daemon::instance() { |     class Daemon *Daemon::instance() { | ||||||
| @@ -55,7 +55,7 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| int main(int argc, char **argv) { | int main(int argc, char **argv) { | ||||||
|     try { |     try { | ||||||
|         auto App = OpenWifi::Daemon::instance(); |         auto App = uCentral::Daemon::instance(); | ||||||
|         auto ExitCode =  App->run(argc, argv); |         auto ExitCode =  App->run(argc, argv); | ||||||
|         delete App; |         delete App; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -21,15 +21,15 @@ | |||||||
| #include "Poco/Crypto/Cipher.h" | #include "Poco/Crypto/Cipher.h" | ||||||
|  |  | ||||||
|  |  | ||||||
| #include "OpenWifiTypes.h" | #include "uCentralTypes.h" | ||||||
| #include "MicroService.h" | #include "MicroService.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     static const char * vDAEMON_PROPERTIES_FILENAME = "ucentralsec.properties"; |     static const char * vDAEMON_PROPERTIES_FILENAME = "ucentralsec.properties"; | ||||||
|     static const char * vDAEMON_ROOT_ENV_VAR = "UCENTRALSEC_ROOT"; |     static const char * vDAEMON_ROOT_ENV_VAR = "UCENTRALSEC_ROOT"; | ||||||
|     static const char * vDAEMON_CONFIG_ENV_VAR = "UCENTRALSEC_CONFIG"; |     static const char * vDAEMON_CONFIG_ENV_VAR = "UCENTRALSEC_CONFIG"; | ||||||
|     static const char * vDAEMON_APP_NAME = uSERVICE_SECURITY.c_str(); |     static const char * vDAEMON_APP_NAME = "uCentralSec"; | ||||||
|     static const uint64_t vDAEMON_BUS_TIMER = 5000; |     static const uint64_t vDAEMON_BUS_TIMER = 5000; | ||||||
|  |  | ||||||
|     class Daemon : public MicroService { |     class Daemon : public MicroService { | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ | |||||||
| #include "Daemon.h" | #include "Daemon.h" | ||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
| 	class KafkaManager *KafkaManager::instance_ = nullptr; | 	class KafkaManager *KafkaManager::instance_ = nullptr; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,11 +13,11 @@ | |||||||
| #include <thread> | #include <thread> | ||||||
|  |  | ||||||
| #include "SubSystemServer.h" | #include "SubSystemServer.h" | ||||||
| #include "OpenWifiTypes.h" | #include "uCentralTypes.h" | ||||||
|  |  | ||||||
| #include "cppkafka/cppkafka.h" | #include "cppkafka/cppkafka.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
| 	class KafkaManager : public SubSystemServer { | 	class KafkaManager : public SubSystemServer { | ||||||
| 	  public: | 	  public: | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ | |||||||
| #ifndef UCENTRALGW_KAFKA_TOPICS_H | #ifndef UCENTRALGW_KAFKA_TOPICS_H | ||||||
| #define UCENTRALGW_KAFKA_TOPICS_H | #define UCENTRALGW_KAFKA_TOPICS_H | ||||||
|  |  | ||||||
| namespace OpenWifi::KafkaTopics { | namespace uCentral::KafkaTopics { | ||||||
| 	static const std::string HEALTHCHECK{"healthcheck"}; | 	static const std::string HEALTHCHECK{"healthcheck"}; | ||||||
| 	static const std::string STATE{"state"}; | 	static const std::string STATE{"state"}; | ||||||
| 	static const std::string CONNECTION{"connection"}; | 	static const std::string CONNECTION{"connection"}; | ||||||
| @@ -13,7 +13,6 @@ namespace OpenWifi::KafkaTopics { | |||||||
| 	static const std::string ALERTS{"alerts"}; | 	static const std::string ALERTS{"alerts"}; | ||||||
| 	static const std::string COMMAND{"command"}; | 	static const std::string COMMAND{"command"}; | ||||||
| 	static const std::string SERVICE_EVENTS{"service_events"}; | 	static const std::string SERVICE_EVENTS{"service_events"}; | ||||||
| 	static const std::string DEVICE_EVENT_QUEUE{"device_event_queue"}; |  | ||||||
|  |  | ||||||
| 	namespace ServiceEvents { | 	namespace ServiceEvents { | ||||||
| 		static const std::string EVENT_JOIN{"join"}; | 		static const std::string EVENT_JOIN{"join"}; | ||||||
|   | |||||||
| @@ -34,7 +34,7 @@ | |||||||
| #include "AuthClient.h" | #include "AuthClient.h" | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
| 	void MyErrorHandler::exception(const Poco::Exception & E) { | 	void MyErrorHandler::exception(const Poco::Exception & E) { | ||||||
| 		Poco::Thread * CurrentThread = Poco::Thread::current(); | 		Poco::Thread * CurrentThread = Poco::Thread::current(); | ||||||
| @@ -112,16 +112,6 @@ namespace OpenWifi { | |||||||
| 			} else { | 			} else { | ||||||
| 				logger().error("Bad bus message."); | 				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) { | 		} catch (const Poco::Exception &E) { | ||||||
| 			logger().log(E); | 			logger().log(E); | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -24,16 +24,16 @@ | |||||||
| #include "Poco/Net/HTTPServerRequest.h" | #include "Poco/Net/HTTPServerRequest.h" | ||||||
| #include "Poco/Process.h" | #include "Poco/Process.h" | ||||||
|  |  | ||||||
| #include "OpenWifiTypes.h" | #include "uCentralTypes.h" | ||||||
| #include "SubSystemServer.h" | #include "SubSystemServer.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
| 	static const std::string uSERVICE_SECURITY{"ucentralsec"}; | 	static const std::string uSERVICE_SECURITY{"ucentralsec"}; | ||||||
| 	static const std::string uSERVICE_GATEWAY{"ucentralgw"}; | 	static const std::string uSERVICE_GATEWAY{"ucentralgw"}; | ||||||
| 	static const std::string uSERVICE_FIRMWARE{ "ucentralfms"}; | 	static const std::string uSERVICE_FIRMWARE{ "ucentralfws"}; | ||||||
|     static const std::string uSERVICE_TOPOLOGY{ "owtopo"}; |     static const std::string uSERVICE_TOPOLOGY{ "ucentraltopo"}; | ||||||
|     static const std::string uSERVICE_PROVISIONING{ "owprov"}; |     static const std::string uSERVICE_PROVISIONING{ "ucentralprov"}; | ||||||
|  |  | ||||||
| 	class MyErrorHandler : public Poco::ErrorHandler { | 	class MyErrorHandler : public Poco::ErrorHandler { | ||||||
| 	  public: | 	  public: | ||||||
|   | |||||||
| @@ -1,68 +0,0 @@ | |||||||
| // |  | ||||||
| // 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; |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @@ -1,29 +0,0 @@ | |||||||
| // |  | ||||||
| // 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 |  | ||||||
| @@ -9,7 +9,7 @@ | |||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
| #include "RESTAPI_protocol.h" | #include "RESTAPI_protocol.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     void RESTAPI_AssetServer::handleRequest(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) { |     void RESTAPI_AssetServer::handleRequest(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) { | ||||||
|         if(Request.getMethod()==Poco::Net::HTTPRequest::HTTP_GET) |         if(Request.getMethod()==Poco::Net::HTTPRequest::HTTP_GET) | ||||||
|             DoGet(Request, Response); |             DoGet(Request, Response); | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ | |||||||
|  |  | ||||||
| #include "RESTAPI_handler.h" | #include "RESTAPI_handler.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     class RESTAPI_AssetServer : public RESTAPIHandler { |     class RESTAPI_AssetServer : public RESTAPIHandler { | ||||||
|     public: |     public: | ||||||
|         RESTAPI_AssetServer(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) |         RESTAPI_AssetServer(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ | |||||||
|  |  | ||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     class RESTAPI_InternalServer *RESTAPI_InternalServer::instance_ = nullptr; |     class RESTAPI_InternalServer *RESTAPI_InternalServer::instance_ = nullptr; | ||||||
|  |  | ||||||
| @@ -58,7 +58,7 @@ namespace OpenWifi { | |||||||
|     Poco::Net::HTTPRequestHandler *InternalRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest & Request) { |     Poco::Net::HTTPRequestHandler *InternalRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest & Request) { | ||||||
|  |  | ||||||
|         Logger_.debug(Poco::format("REQUEST(%s): %s %s", |         Logger_.debug(Poco::format("REQUEST(%s): %s %s", | ||||||
|                                    Utils::FormatIPv6(Request.clientAddress().toString()), |                                    uCentral::Utils::FormatIPv6(Request.clientAddress().toString()), | ||||||
|                                    Request.getMethod(), Request.getURI())); |                                    Request.getMethod(), Request.getURI())); | ||||||
|  |  | ||||||
|         Poco::URI uri(Request.getURI()); |         Poco::URI uri(Request.getURI()); | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ | |||||||
| #include "Poco/Net/HTTPServerRequest.h" | #include "Poco/Net/HTTPServerRequest.h" | ||||||
| #include "Poco/Net/NetException.h" | #include "Poco/Net/NetException.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     class RESTAPI_InternalServer : public SubSystemServer { |     class RESTAPI_InternalServer : public SubSystemServer { | ||||||
|         public: |         public: | ||||||
|   | |||||||
| @@ -12,10 +12,10 @@ | |||||||
| #include "RESTAPI_SecurityObjects.h" | #include "RESTAPI_SecurityObjects.h" | ||||||
| #include "RESTAPI_utils.h" | #include "RESTAPI_utils.h" | ||||||
|  |  | ||||||
| using OpenWifi::RESTAPI_utils::field_to_json; | using uCentral::RESTAPI_utils::field_to_json; | ||||||
| using OpenWifi::RESTAPI_utils::field_from_json; | using uCentral::RESTAPI_utils::field_from_json; | ||||||
|  |  | ||||||
| namespace OpenWifi::SecurityObjects { | namespace uCentral::SecurityObjects { | ||||||
|  |  | ||||||
| 	void AclTemplate::to_json(Poco::JSON::Object &Obj) const { | 	void AclTemplate::to_json(Poco::JSON::Object &Obj) const { | ||||||
| 		field_to_json(Obj,"Read",Read_); | 		field_to_json(Obj,"Read",Read_); | ||||||
| @@ -303,20 +303,6 @@ namespace OpenWifi::SecurityObjects { | |||||||
| 		return false; | 		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 { | 	void ProfileAction::to_json(Poco::JSON::Object &Obj) const { | ||||||
| 		field_to_json(Obj,"resource", resource); | 		field_to_json(Obj,"resource", resource); | ||||||
| 		field_to_json<ResourceAccessType>(Obj,"access", access, ResourceAccessTypeToString); | 		field_to_json<ResourceAccessType>(Obj,"access", access, ResourceAccessTypeToString); | ||||||
|   | |||||||
| @@ -10,9 +10,9 @@ | |||||||
| #define UCENTRAL_RESTAPI_SECURITYOBJECTS_H | #define UCENTRAL_RESTAPI_SECURITYOBJECTS_H | ||||||
|  |  | ||||||
| #include "Poco/JSON/Object.h" | #include "Poco/JSON/Object.h" | ||||||
| #include "OpenWifiTypes.h" | #include "uCentralTypes.h" | ||||||
|  |  | ||||||
| namespace OpenWifi::SecurityObjects { | namespace uCentral::SecurityObjects { | ||||||
|  |  | ||||||
| 	struct AclTemplate { | 	struct AclTemplate { | ||||||
| 		bool Read_ = true; | 		bool Read_ = true; | ||||||
| @@ -94,8 +94,6 @@ namespace OpenWifi::SecurityObjects { | |||||||
| 	}; | 	}; | ||||||
| 	typedef std::vector<UserInfo>   UserInfoVec; | 	typedef std::vector<UserInfo>   UserInfoVec; | ||||||
|  |  | ||||||
| 	bool append_from_json(Poco::JSON::Object::Ptr Obj, const UserInfo &UInfo, NoteInfoVec & Notes); |  | ||||||
|  |  | ||||||
| 	struct InternalServiceInfo { | 	struct InternalServiceInfo { | ||||||
| 		std::string privateURI; | 		std::string privateURI; | ||||||
| 		std::string publicURI; | 		std::string publicURI; | ||||||
| @@ -116,9 +114,9 @@ namespace OpenWifi::SecurityObjects { | |||||||
| 	struct SystemEndpoint { | 	struct SystemEndpoint { | ||||||
| 		std::string type; | 		std::string type; | ||||||
| 		uint64_t 	id = 0; | 		uint64_t 	id = 0; | ||||||
| 		std::string vendor{"OpenWiFi"}; | 		std::string vendor; | ||||||
| 		std::string uri; | 		std::string uri; | ||||||
| 		std::string authenticationType{"internal_v1"}; | 		std::string authenticationType; | ||||||
| 		void to_json(Poco::JSON::Object &Obj) const; | 		void to_json(Poco::JSON::Object &Obj) const; | ||||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||||
| 	}; | 	}; | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ | |||||||
| #include "RESTAPI_server.h" | #include "RESTAPI_server.h" | ||||||
| #include "Daemon.h" | #include "Daemon.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     void RESTAPI_action_links::handleRequest(Poco::Net::HTTPServerRequest &Request, |     void RESTAPI_action_links::handleRequest(Poco::Net::HTTPServerRequest &Request, | ||||||
|                        Poco::Net::HTTPServerResponse &Response) { |                        Poco::Net::HTTPServerResponse &Response) { | ||||||
|         //  there is no authentication here, this is just someone clicking on a link |         //  there is no authentication here, this is just someone clicking on a link | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ | |||||||
| #include "Poco/StreamCopier.h" | #include "Poco/StreamCopier.h" | ||||||
| #include "Poco/CountingStream.h" | #include "Poco/CountingStream.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     class RESTAPI_action_links : public RESTAPIHandler { |     class RESTAPI_action_links : public RESTAPIHandler { | ||||||
|     public: |     public: | ||||||
|         RESTAPI_action_links(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) |         RESTAPI_action_links(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ | |||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
| #include "RESTAPI_protocol.h" | #include "RESTAPI_protocol.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     void AvatarPartHandler::handlePart(const Poco::Net::MessageHeader &Header, std::istream &Stream) { |     void AvatarPartHandler::handlePart(const Poco::Net::MessageHeader &Header, std::istream &Stream) { | ||||||
|         FileType_ = Header.get(RESTAPI::Protocol::CONTENTTYPE, RESTAPI::Protocol::UNSPECIFIED); |         FileType_ = Header.get(RESTAPI::Protocol::CONTENTTYPE, RESTAPI::Protocol::UNSPECIFIED); | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ | |||||||
|  |  | ||||||
| #include "RESTAPI_handler.h" | #include "RESTAPI_handler.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     class AvatarPartHandler : public Poco::Net::PartHandler { |     class AvatarPartHandler : public Poco::Net::PartHandler { | ||||||
|     public: |     public: | ||||||
|   | |||||||
| @@ -27,16 +27,16 @@ | |||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
| #include "Daemon.h" | #include "Daemon.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
| 	bool RESTAPIHandler::ParseBindings(const std::string & Request, const std::list<const char *> & EndPoints, BindingMap &bindings) { | 	bool RESTAPIHandler::ParseBindings(const std::string & Request, const std::list<const char *> & EndPoints, BindingMap &bindings) { | ||||||
| 		std::string Param, Value; | 		std::string Param, Value; | ||||||
|  |  | ||||||
| 		bindings.clear(); | 		bindings.clear(); | ||||||
| 		std::vector<std::string> PathItems = Utils::Split(Request, '/'); | 		std::vector<std::string> PathItems = uCentral::Utils::Split(Request, '/'); | ||||||
|  |  | ||||||
| 		for(const auto &EndPoint:EndPoints) { | 		for(const auto &EndPoint:EndPoints) { | ||||||
| 			std::vector<std::string> ParamItems = Utils::Split(EndPoint, '/'); | 			std::vector<std::string> ParamItems = uCentral::Utils::Split(EndPoint, '/'); | ||||||
| 			if (PathItems.size() != ParamItems.size()) | 			if (PathItems.size() != ParamItems.size()) | ||||||
| 				continue; | 				continue; | ||||||
|  |  | ||||||
| @@ -364,21 +364,18 @@ namespace OpenWifi { | |||||||
| 		Poco::JSON::Stringifier::stringify(Object, Answer); | 		Poco::JSON::Stringifier::stringify(Object, Answer); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	bool RESTAPIHandler::InitQueryBlock() { | 	void RESTAPIHandler::InitQueryBlock() { | ||||||
| 		QB_.SerialNumber = GetParameter(RESTAPI::Protocol::SERIALNUMBER, ""); | 		QB_.SerialNumber = GetParameter(uCentral::RESTAPI::Protocol::SERIALNUMBER, ""); | ||||||
| 		QB_.StartDate = GetParameter(RESTAPI::Protocol::STARTDATE, 0); | 		QB_.StartDate = GetParameter(uCentral::RESTAPI::Protocol::STARTDATE, 0); | ||||||
| 		QB_.EndDate = GetParameter(RESTAPI::Protocol::ENDDATE, 0); | 		QB_.EndDate = GetParameter(uCentral::RESTAPI::Protocol::ENDDATE, 0); | ||||||
| 		QB_.Offset = GetParameter(RESTAPI::Protocol::OFFSET, 1); | 		QB_.Offset = GetParameter(uCentral::RESTAPI::Protocol::OFFSET, 0); | ||||||
| 		QB_.Limit = GetParameter(RESTAPI::Protocol::LIMIT, 100); | 		QB_.Limit = GetParameter(uCentral::RESTAPI::Protocol::LIMIT, 100); | ||||||
| 		QB_.Filter = GetParameter(RESTAPI::Protocol::FILTER, ""); | 		QB_.Filter = GetParameter(uCentral::RESTAPI::Protocol::FILTER, ""); | ||||||
| 		QB_.Select = GetParameter(RESTAPI::Protocol::SELECT, ""); | 		QB_.Select = GetParameter(uCentral::RESTAPI::Protocol::SELECT, ""); | ||||||
| 		QB_.Lifetime = GetBoolParameter(RESTAPI::Protocol::LIFETIME,false); | 		QB_.Lifetime = GetBoolParameter(uCentral::RESTAPI::Protocol::LIFETIME,false); | ||||||
| 		QB_.LogType = GetParameter(RESTAPI::Protocol::LOGTYPE,0); | 		QB_.LogType = GetParameter(uCentral::RESTAPI::Protocol::LOGTYPE,0); | ||||||
| 		QB_.LastOnly = GetBoolParameter(RESTAPI::Protocol::LASTONLY,false); | 		QB_.LastOnly = GetBoolParameter(uCentral::RESTAPI::Protocol::LASTONLY,false); | ||||||
| 		QB_.Newest = GetBoolParameter(RESTAPI::Protocol::NEWEST,false); | 		QB_.Newest = GetBoolParameter(uCentral::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){ | 	[[nodiscard]] uint64_t RESTAPIHandler::Get(const char *Parameter,const Poco::JSON::Object::Ptr &Obj, uint64_t Default){ | ||||||
| @@ -400,7 +397,7 @@ namespace OpenWifi { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	[[nodiscard]] uint64_t RESTAPIHandler::GetWhen(const Poco::JSON::Object::Ptr &Obj) { | 	[[nodiscard]] uint64_t RESTAPIHandler::GetWhen(const Poco::JSON::Object::Ptr &Obj) { | ||||||
| 		return RESTAPIHandler::Get(RESTAPI::Protocol::WHEN, Obj); | 		return RESTAPIHandler::Get(uCentral::RESTAPI::Protocol::WHEN, Obj); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -26,7 +26,7 @@ | |||||||
|  |  | ||||||
| #include "RESTAPI_SecurityObjects.h" | #include "RESTAPI_SecurityObjects.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     class RESTAPI_PartHandler: public Poco::Net::PartHandler |     class RESTAPI_PartHandler: public Poco::Net::PartHandler | ||||||
|     { |     { | ||||||
| @@ -140,7 +140,7 @@ namespace OpenWifi { | |||||||
|         void SendFile(Poco::File & File, Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response); |         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); |         const std::string &GetBinding(const std::string &Name, const std::string &Default); | ||||||
| 		bool InitQueryBlock(); | 		void InitQueryBlock(); | ||||||
|  |  | ||||||
| 		[[nodiscard]] static uint64_t Get(const char *Parameter,const Poco::JSON::Object::Ptr &Obj, uint64_t Default=0); | 		[[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=""); | 		[[nodiscard]] static std::string GetS(const char *Parameter,const Poco::JSON::Object::Ptr &Obj, const std::string & Default=""); | ||||||
| @@ -166,7 +166,7 @@ namespace OpenWifi { | |||||||
| 						   Poco::Net::HTTPServerResponse &Response) override { | 						   Poco::Net::HTTPServerResponse &Response) override { | ||||||
| 			if (!IsAuthorized(Request, Response)) | 			if (!IsAuthorized(Request, Response)) | ||||||
| 				return; | 				return; | ||||||
| 			BadRequest(Request, Response, "Unknown API endpoint"); | 			BadRequest(Request, Response); | ||||||
| 		} | 		} | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ | |||||||
|  |  | ||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
| 	void RESTAPI_oauth2Handler::handleRequest(Poco::Net::HTTPServerRequest &Request, | 	void RESTAPI_oauth2Handler::handleRequest(Poco::Net::HTTPServerRequest &Request, | ||||||
| 											  Poco::Net::HTTPServerResponse &Response) { | 											  Poco::Net::HTTPServerResponse &Response) { | ||||||
|  |  | ||||||
| @@ -29,9 +29,9 @@ namespace OpenWifi { | |||||||
| 				Poco::JSON::Parser parser; | 				Poco::JSON::Parser parser; | ||||||
| 				Poco::JSON::Object::Ptr Obj = parser.parse(Request.stream()).extract<Poco::JSON::Object::Ptr>(); | 				Poco::JSON::Object::Ptr Obj = parser.parse(Request.stream()).extract<Poco::JSON::Object::Ptr>(); | ||||||
|  |  | ||||||
| 				auto userId = GetS(RESTAPI::Protocol::USERID, Obj); | 				auto userId = GetS(uCentral::RESTAPI::Protocol::USERID, Obj); | ||||||
| 				auto password = GetS(RESTAPI::Protocol::PASSWORD, Obj); | 				auto password = GetS(uCentral::RESTAPI::Protocol::PASSWORD, Obj); | ||||||
| 				auto newPassword = GetS(RESTAPI::Protocol::NEWPASSWORD, Obj); | 				auto newPassword = GetS(uCentral::RESTAPI::Protocol::NEWPASSWORD, Obj); | ||||||
|  |  | ||||||
|                 if(GetBoolParameter(RESTAPI::Protocol::REQUIREMENTS, false)) { |                 if(GetBoolParameter(RESTAPI::Protocol::REQUIREMENTS, false)) { | ||||||
|                     Poco::JSON::Object  Answer; |                     Poco::JSON::Object  Answer; | ||||||
| @@ -79,7 +79,7 @@ namespace OpenWifi { | |||||||
|                     UnAuthorized(Request, Response, "Not authorized."); |                     UnAuthorized(Request, Response, "Not authorized."); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
| 				auto Token = GetBinding(RESTAPI::Protocol::TOKEN, "..."); | 				auto Token = GetBinding(uCentral::RESTAPI::Protocol::TOKEN, "..."); | ||||||
| 				if (Token == SessionToken_) { | 				if (Token == SessionToken_) { | ||||||
| 					AuthService()->Logout(Token); | 					AuthService()->Logout(Token); | ||||||
| 					ReturnStatus(Request, Response, Poco::Net::HTTPResponse::HTTP_NO_CONTENT, true); | 					ReturnStatus(Request, Response, Poco::Net::HTTPResponse::HTTP_NO_CONTENT, true); | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ | |||||||
|  |  | ||||||
| #include "RESTAPI_handler.h" | #include "RESTAPI_handler.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
| 	class RESTAPI_oauth2Handler : public RESTAPIHandler { | 	class RESTAPI_oauth2Handler : public RESTAPIHandler { | ||||||
| 	  public: | 	  public: | ||||||
| 		RESTAPI_oauth2Handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) | 		RESTAPI_oauth2Handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ | |||||||
| #ifndef UCENTRALGW_RESTAPI_PROTOCOL_H | #ifndef UCENTRALGW_RESTAPI_PROTOCOL_H | ||||||
| #define UCENTRALGW_RESTAPI_PROTOCOL_H | #define UCENTRALGW_RESTAPI_PROTOCOL_H | ||||||
|  |  | ||||||
| namespace OpenWifi::RESTAPI::Protocol { | namespace uCentral::RESTAPI::Protocol { | ||||||
| 	static const char * CAPABILITIES = "capabilities"; | 	static const char * CAPABILITIES = "capabilities"; | ||||||
| 	static const char * LOGS = "logs"; | 	static const char * LOGS = "logs"; | ||||||
| 	static const char * HEALTHCHECKS = "healthchecks"; | 	static const char * HEALTHCHECKS = "healthchecks"; | ||||||
|   | |||||||
| @@ -23,7 +23,7 @@ | |||||||
| #include "Daemon.h" | #include "Daemon.h" | ||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     class RESTAPI_Server *RESTAPI_Server::instance_ = nullptr; |     class RESTAPI_Server *RESTAPI_Server::instance_ = nullptr; | ||||||
|  |  | ||||||
| @@ -59,7 +59,7 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
|     Poco::Net::HTTPRequestHandler *RequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest & Request) { |     Poco::Net::HTTPRequestHandler *RequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest & Request) { | ||||||
|  |  | ||||||
|         Logger_.debug(Poco::format("REQUEST(%s): %s %s", Utils::FormatIPv6(Request.clientAddress().toString()), Request.getMethod(), Request.getURI())); |         Logger_.debug(Poco::format("REQUEST(%s): %s %s", uCentral::Utils::FormatIPv6(Request.clientAddress().toString()), Request.getMethod(), Request.getURI())); | ||||||
|  |  | ||||||
|         Poco::URI uri(Request.getURI()); |         Poco::URI uri(Request.getURI()); | ||||||
|         const auto & Path = uri.getPath(); |         const auto & Path = uri.getPath(); | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ | |||||||
| #include "Poco/Net/HTTPServerRequest.h" | #include "Poco/Net/HTTPServerRequest.h" | ||||||
| #include "Poco/Net/NetException.h" | #include "Poco/Net/NetException.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     class RESTAPI_Server : public SubSystemServer { |     class RESTAPI_Server : public SubSystemServer { | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ | |||||||
| #include "Daemon.h" | #include "Daemon.h" | ||||||
| #include "RESTAPI_SecurityObjects.h" | #include "RESTAPI_SecurityObjects.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     void RESTAPI_systemEndpoints_handler::handleRequest(Poco::Net::HTTPServerRequest &Request, |     void RESTAPI_systemEndpoints_handler::handleRequest(Poco::Net::HTTPServerRequest &Request, | ||||||
|                                                         Poco::Net::HTTPServerResponse &Response) { |                                                         Poco::Net::HTTPServerResponse &Response) { | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ | |||||||
| #define UCENTRALSEC_RESTAPI_SYSTEMENDPOINTS_HANDLER_H | #define UCENTRALSEC_RESTAPI_SYSTEMENDPOINTS_HANDLER_H | ||||||
|  |  | ||||||
| #include "RESTAPI_handler.h" | #include "RESTAPI_handler.h" | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     class RESTAPI_systemEndpoints_handler : public RESTAPIHandler { |     class RESTAPI_systemEndpoints_handler : public RESTAPIHandler { | ||||||
|     public: |     public: | ||||||
|         RESTAPI_systemEndpoints_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) |         RESTAPI_systemEndpoints_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ | |||||||
| #include "Daemon.h" | #include "Daemon.h" | ||||||
| #include "RESTAPI_protocol.h" | #include "RESTAPI_protocol.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
| 	void RESTAPI_system_command::handleRequest(Poco::Net::HTTPServerRequest &Request, | 	void RESTAPI_system_command::handleRequest(Poco::Net::HTTPServerRequest &Request, | ||||||
| 											   Poco::Net::HTTPServerResponse &Response) { | 											   Poco::Net::HTTPServerResponse &Response) { | ||||||
|  |  | ||||||
| @@ -27,8 +27,8 @@ namespace OpenWifi { | |||||||
| 			DoPost(Request, Response); | 			DoPost(Request, Response); | ||||||
| 		else if(Request.getMethod()==Poco::Net::HTTPRequest::HTTP_GET) | 		else if(Request.getMethod()==Poco::Net::HTTPRequest::HTTP_GET) | ||||||
| 			DoGet(Request, Response); | 			DoGet(Request, Response); | ||||||
| 		else |  | ||||||
|             BadRequest(Request, Response, "Unsupported method."); | 		BadRequest(Request, Response); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	void RESTAPI_system_command::DoPost(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) { | 	void RESTAPI_system_command::DoPost(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) { | ||||||
| @@ -36,19 +36,19 @@ namespace OpenWifi { | |||||||
| 			Poco::JSON::Parser parser; | 			Poco::JSON::Parser parser; | ||||||
| 			auto Obj = parser.parse(Request.stream()).extract<Poco::JSON::Object::Ptr>(); | 			auto Obj = parser.parse(Request.stream()).extract<Poco::JSON::Object::Ptr>(); | ||||||
|  |  | ||||||
| 			if (Obj->has(RESTAPI::Protocol::COMMAND)) { | 			if (Obj->has(uCentral::RESTAPI::Protocol::COMMAND)) { | ||||||
| 				auto Command = Poco::toLower(Obj->get(RESTAPI::Protocol::COMMAND).toString()); | 				auto Command = Poco::toLower(Obj->get(uCentral::RESTAPI::Protocol::COMMAND).toString()); | ||||||
| 				if (Command == RESTAPI::Protocol::SETLOGLEVEL) { | 				if (Command == uCentral::RESTAPI::Protocol::SETLOGLEVEL) { | ||||||
| 					if (Obj->has(RESTAPI::Protocol::PARAMETERS) && | 					if (Obj->has(uCentral::RESTAPI::Protocol::PARAMETERS) && | ||||||
| 						Obj->isArray(RESTAPI::Protocol::PARAMETERS)) { | 						Obj->isArray(uCentral::RESTAPI::Protocol::PARAMETERS)) { | ||||||
| 						auto ParametersBlock = Obj->getArray(RESTAPI::Protocol::PARAMETERS); | 						auto ParametersBlock = Obj->getArray(uCentral::RESTAPI::Protocol::PARAMETERS); | ||||||
| 						for (const auto &i:*ParametersBlock) { | 						for (const auto &i:*ParametersBlock) { | ||||||
| 							Poco::JSON::Parser pp; | 							Poco::JSON::Parser pp; | ||||||
| 							auto InnerObj = pp.parse(i).extract<Poco::JSON::Object::Ptr>(); | 							auto InnerObj = pp.parse(i).extract<Poco::JSON::Object::Ptr>(); | ||||||
| 							if (InnerObj->has(RESTAPI::Protocol::TAG) && | 							if (InnerObj->has(uCentral::RESTAPI::Protocol::TAG) && | ||||||
| 								InnerObj->has(RESTAPI::Protocol::VALUE)) { | 								InnerObj->has(uCentral::RESTAPI::Protocol::VALUE)) { | ||||||
| 								auto Name = GetS(RESTAPI::Protocol::TAG, InnerObj); | 								auto Name = GetS(uCentral::RESTAPI::Protocol::TAG, InnerObj); | ||||||
| 								auto Value = GetS(RESTAPI::Protocol::VALUE, InnerObj); | 								auto Value = GetS(uCentral::RESTAPI::Protocol::VALUE, InnerObj); | ||||||
| 								Daemon()->SetSubsystemLogLevel(Name, Value); | 								Daemon()->SetSubsystemLogLevel(Name, Value); | ||||||
| 								Logger_.information(Poco::format("Setting log level for %s at %s", Name, Value)); | 								Logger_.information(Poco::format("Setting log level for %s at %s", Name, Value)); | ||||||
| 							} | 							} | ||||||
| @@ -56,45 +56,45 @@ namespace OpenWifi { | |||||||
| 						OK(Request, Response); | 						OK(Request, Response); | ||||||
| 						return; | 						return; | ||||||
| 					} | 					} | ||||||
| 				} else if (Command == RESTAPI::Protocol::GETLOGLEVELS) { | 				} else if (Command == uCentral::RESTAPI::Protocol::GETLOGLEVELS) { | ||||||
| 					auto CurrentLogLevels = Daemon()->GetLogLevels(); | 					auto CurrentLogLevels = Daemon()->GetLogLevels(); | ||||||
| 					Poco::JSON::Object	Result; | 					Poco::JSON::Object	Result; | ||||||
| 					Poco::JSON::Array	Array; | 					Poco::JSON::Array	Array; | ||||||
| 					for(auto &[Name,Level]:CurrentLogLevels) { | 					for(auto &[Name,Level]:CurrentLogLevels) { | ||||||
| 						Poco::JSON::Object	Pair; | 						Poco::JSON::Object	Pair; | ||||||
| 						Pair.set( RESTAPI::Protocol::TAG,Name); | 						Pair.set( uCentral::RESTAPI::Protocol::TAG,Name); | ||||||
| 						Pair.set(RESTAPI::Protocol::VALUE,Level); | 						Pair.set(uCentral::RESTAPI::Protocol::VALUE,Level); | ||||||
| 						Array.add(Pair); | 						Array.add(Pair); | ||||||
| 					} | 					} | ||||||
| 					Result.set(RESTAPI::Protocol::TAGLIST,Array); | 					Result.set(uCentral::RESTAPI::Protocol::TAGLIST,Array); | ||||||
| 					ReturnObject(Request,Result,Response); | 					ReturnObject(Request,Result,Response); | ||||||
| 					return; | 					return; | ||||||
| 				} else if (Command == RESTAPI::Protocol::GETLOGLEVELNAMES) { | 				} else if (Command == uCentral::RESTAPI::Protocol::GETLOGLEVELNAMES) { | ||||||
| 					Poco::JSON::Object	Result; | 					Poco::JSON::Object	Result; | ||||||
| 					Poco::JSON::Array	LevelNamesArray; | 					Poco::JSON::Array	LevelNamesArray; | ||||||
| 					const Types::StringVec & LevelNames = Daemon()->GetLogLevelNames(); | 					const Types::StringVec & LevelNames = Daemon()->GetLogLevelNames(); | ||||||
| 					for(const auto &i:LevelNames) | 					for(const auto &i:LevelNames) | ||||||
| 						LevelNamesArray.add(i); | 						LevelNamesArray.add(i); | ||||||
| 					Result.set(RESTAPI::Protocol::LIST,LevelNamesArray); | 					Result.set(uCentral::RESTAPI::Protocol::LIST,LevelNamesArray); | ||||||
| 					ReturnObject(Request,Result,Response); | 					ReturnObject(Request,Result,Response); | ||||||
| 					return; | 					return; | ||||||
| 				} else if (Command == RESTAPI::Protocol::GETSUBSYSTEMNAMES) { | 				} else if (Command == uCentral::RESTAPI::Protocol::GETSUBSYSTEMNAMES) { | ||||||
| 					Poco::JSON::Object	Result; | 					Poco::JSON::Object	Result; | ||||||
| 					Poco::JSON::Array	LevelNamesArray; | 					Poco::JSON::Array	LevelNamesArray; | ||||||
| 					const Types::StringVec & SubSystemNames = Daemon()->GetSubSystems(); | 					const Types::StringVec & SubSystemNames = Daemon()->GetSubSystems(); | ||||||
| 					for(const auto &i:SubSystemNames) | 					for(const auto &i:SubSystemNames) | ||||||
| 						LevelNamesArray.add(i); | 						LevelNamesArray.add(i); | ||||||
| 					Result.set(RESTAPI::Protocol::LIST,LevelNamesArray); | 					Result.set(uCentral::RESTAPI::Protocol::LIST,LevelNamesArray); | ||||||
| 					ReturnObject(Request,Result,Response); | 					ReturnObject(Request,Result,Response); | ||||||
| 					return; | 					return; | ||||||
| 				} else if (Command == RESTAPI::Protocol::STATS) { | 				} else if (Command == uCentral::RESTAPI::Protocol::STATS) { | ||||||
|  |  | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} catch(const Poco::Exception &E) { | 		} catch(const Poco::Exception &E) { | ||||||
| 			Logger_.log(E); | 			Logger_.log(E); | ||||||
| 		} | 		} | ||||||
| 		BadRequest(Request, Response, "Unsupported or missing parameters."); | 		BadRequest(Request, Response); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	void RESTAPI_system_command::DoGet(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) { | 	void RESTAPI_system_command::DoGet(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) { | ||||||
| @@ -126,7 +126,7 @@ namespace OpenWifi { | |||||||
| 		} catch (const Poco::Exception &E) { | 		} catch (const Poco::Exception &E) { | ||||||
| 			Logger_.log(E); | 			Logger_.log(E); | ||||||
| 		} | 		} | ||||||
| 		BadRequest(Request, Response, "Unsupported or missing parameters."); | 		BadRequest(Request, Response); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| } | } | ||||||
| @@ -11,7 +11,7 @@ | |||||||
|  |  | ||||||
| #include "RESTAPI_handler.h" | #include "RESTAPI_handler.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
| class RESTAPI_system_command : public RESTAPIHandler { | class RESTAPI_system_command : public RESTAPIHandler { | ||||||
|   public: |   public: | ||||||
| 	RESTAPI_system_command(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) | 	RESTAPI_system_command(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ | |||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
| #include "RESTAPI_utils.h" | #include "RESTAPI_utils.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     void RESTAPI_user_handler::handleRequest(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) { |     void RESTAPI_user_handler::handleRequest(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) { | ||||||
|  |  | ||||||
|         if (!ContinueProcessing(Request, Response)) |         if (!ContinueProcessing(Request, Response)) | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ | |||||||
|  |  | ||||||
| #include "RESTAPI_handler.h" | #include "RESTAPI_handler.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     class RESTAPI_user_handler : public RESTAPIHandler { |     class RESTAPI_user_handler : public RESTAPIHandler { | ||||||
|     public: |     public: | ||||||
|         RESTAPI_user_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) |         RESTAPI_user_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ | |||||||
| #include "RESTAPI_protocol.h" | #include "RESTAPI_protocol.h" | ||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     void RESTAPI_users_handler::handleRequest(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) { |     void RESTAPI_users_handler::handleRequest(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) { | ||||||
|         if (!ContinueProcessing(Request, Response)) |         if (!ContinueProcessing(Request, Response)) | ||||||
|             return; |             return; | ||||||
| @@ -41,7 +41,7 @@ namespace OpenWifi { | |||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     Poco::JSON::Object RetObj; |                     Poco::JSON::Object RetObj; | ||||||
|                     RetObj.set(RESTAPI::Protocol::USERS, ArrayObj); |                     RetObj.set(uCentral::RESTAPI::Protocol::USERS, ArrayObj); | ||||||
|                     ReturnObject(Request, RetObj, Response); |                     ReturnObject(Request, RetObj, Response); | ||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
| @@ -61,7 +61,7 @@ namespace OpenWifi { | |||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 Poco::JSON::Object RetObj; |                 Poco::JSON::Object RetObj; | ||||||
|                 RetObj.set(RESTAPI::Protocol::USERS, ArrayObj); |                 RetObj.set(uCentral::RESTAPI::Protocol::USERS, ArrayObj); | ||||||
|                 ReturnObject(Request, RetObj, Response); |                 ReturnObject(Request, RetObj, Response); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ | |||||||
|  |  | ||||||
| #include "RESTAPI_handler.h" | #include "RESTAPI_handler.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     class RESTAPI_users_handler : public RESTAPIHandler { |     class RESTAPI_users_handler : public RESTAPIHandler { | ||||||
|     public: |     public: | ||||||
|         RESTAPI_users_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) |         RESTAPI_users_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
|  |  | ||||||
| #include "RESTAPI_utils.h" | #include "RESTAPI_utils.h" | ||||||
|  |  | ||||||
| namespace OpenWifi::RESTAPI_utils { | namespace uCentral::RESTAPI_utils { | ||||||
|  |  | ||||||
| 	void EmbedDocument(const std::string & ObjName, Poco::JSON::Object & Obj, const std::string &ObjStr) { | 	void EmbedDocument(const std::string & ObjName, Poco::JSON::Object & Obj, const std::string &ObjStr) { | ||||||
| 		std::string D = ObjStr.empty() ? "{}" : ObjStr; | 		std::string D = ObjStr.empty() ? "{}" : ObjStr; | ||||||
|   | |||||||
| @@ -9,10 +9,10 @@ | |||||||
| #include "Poco/JSON/Object.h" | #include "Poco/JSON/Object.h" | ||||||
| #include "Poco/JSON/Parser.h" | #include "Poco/JSON/Parser.h" | ||||||
| #include "Poco/Net/HTTPServerRequest.h" | #include "Poco/Net/HTTPServerRequest.h" | ||||||
| #include "OpenWifiTypes.h" | #include "uCentralTypes.h" | ||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
|  |  | ||||||
| namespace OpenWifi::RESTAPI_utils { | namespace uCentral::RESTAPI_utils { | ||||||
|  |  | ||||||
| 	void EmbedDocument(const std::string & ObjName, Poco::JSON::Object & Obj, const std::string &ObjStr); | 	void EmbedDocument(const std::string & ObjName, Poco::JSON::Object & Obj, const std::string &ObjStr); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ | |||||||
| #include "AuthService.h" | #include "AuthService.h" | ||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     void RESTAPI_validateToken_handler::handleRequest(Poco::Net::HTTPServerRequest &Request, |     void RESTAPI_validateToken_handler::handleRequest(Poco::Net::HTTPServerRequest &Request, | ||||||
|                                                       Poco::Net::HTTPServerResponse &Response) { |                                                       Poco::Net::HTTPServerResponse &Response) { | ||||||
|  |  | ||||||
| @@ -33,7 +33,6 @@ namespace OpenWifi { | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             NotFound(Request, Response); |             NotFound(Request, Response); | ||||||
|             return; |  | ||||||
|         } catch (const Poco::Exception &E) { |         } catch (const Poco::Exception &E) { | ||||||
|             Logger_.log(E); |             Logger_.log(E); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ | |||||||
|  |  | ||||||
| #include "RESTAPI_handler.h" | #include "RESTAPI_handler.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     class RESTAPI_validateToken_handler : public RESTAPIHandler { |     class RESTAPI_validateToken_handler : public RESTAPIHandler { | ||||||
|     public: |     public: | ||||||
|         RESTAPI_validateToken_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) |         RESTAPI_validateToken_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) | ||||||
|   | |||||||
| @@ -20,7 +20,7 @@ | |||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
| #include "Daemon.h" | #include "Daemon.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     class SMTPMailerService * SMTPMailerService::instance_ = nullptr; |     class SMTPMailerService * SMTPMailerService::instance_ = nullptr; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ | |||||||
|  |  | ||||||
| #include "Poco/File.h" | #include "Poco/File.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     enum MESSAGE_ATTRIBUTES { |     enum MESSAGE_ATTRIBUTES { | ||||||
|         RECIPIENT_EMAIL, |         RECIPIENT_EMAIL, | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ | |||||||
| #include "Poco/Util/Application.h" | #include "Poco/Util/Application.h" | ||||||
| #include "Utils.h" | #include "Utils.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     class Storage *Storage::instance_ = nullptr; |     class Storage *Storage::instance_ = nullptr; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ | |||||||
| #include "RESTAPI_SecurityObjects.h" | #include "RESTAPI_SecurityObjects.h" | ||||||
| #include "SubSystemServer.h" | #include "SubSystemServer.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     static const std::string AllActionLinksFieldsForSelect { |     static const std::string AllActionLinksFieldsForSelect { | ||||||
|             "Id, " |             "Id, " | ||||||
| @@ -179,16 +179,6 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
|         int 	Setup_SQLite(); |         int 	Setup_SQLite(); | ||||||
| 		[[nodiscard]] std::string ConvertParams(const std::string &S) const; | 		[[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 | #ifndef SMALL_BUILD | ||||||
|         int 	Setup_MySQL(); |         int 	Setup_MySQL(); | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ | |||||||
|  |  | ||||||
| #include "Daemon.h" | #include "Daemon.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
| SubSystemServer::SubSystemServer(std::string Name, const std::string &LoggingPrefix, | SubSystemServer::SubSystemServer(std::string Name, const std::string &LoggingPrefix, | ||||||
| 								 std::string SubSystemConfigPrefix) | 								 std::string SubSystemConfigPrefix) | ||||||
| 	: Name_(std::move(Name)), Logger_(Poco::Logger::get(LoggingPrefix)), | 	: Name_(std::move(Name)), Logger_(Poco::Logger::get(LoggingPrefix)), | ||||||
|   | |||||||
| @@ -23,7 +23,7 @@ | |||||||
| using SubMutex = std::recursive_mutex; | using SubMutex = std::recursive_mutex; | ||||||
| using SubMutexGuard = std::lock_guard<SubMutex>; | using SubMutexGuard = std::lock_guard<SubMutex>; | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
| class PropertiesFileServerEntry { | class PropertiesFileServerEntry { | ||||||
|   public: |   public: | ||||||
| 	PropertiesFileServerEntry(std::string Address, uint32_t port, std::string Key_file, | 	PropertiesFileServerEntry(std::string Address, uint32_t port, std::string Key_file, | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ | |||||||
| #include "uCentralProtocol.h" | #include "uCentralProtocol.h" | ||||||
| #include "Daemon.h" | #include "Daemon.h" | ||||||
|  |  | ||||||
| namespace OpenWifi::Utils { | namespace uCentral::Utils { | ||||||
|  |  | ||||||
| 	[[nodiscard]] bool ValidSerialNumber(const std::string &Serial) { | 	[[nodiscard]] bool ValidSerialNumber(const std::string &Serial) { | ||||||
| 		return ((Serial.size() < uCentralProtocol::SERIAL_NUMBER_LENGTH) && | 		return ((Serial.size() < uCentralProtocol::SERIAL_NUMBER_LENGTH) && | ||||||
|   | |||||||
							
								
								
									
										17
									
								
								src/Utils.h
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/Utils.h
									
									
									
									
									
								
							| @@ -11,18 +11,16 @@ | |||||||
|  |  | ||||||
| #include <vector> | #include <vector> | ||||||
| #include <string> | #include <string> | ||||||
| #include <iomanip> |  | ||||||
| #include <sstream> |  | ||||||
|  |  | ||||||
| #include "Poco/Net/NetworkInterface.h" | #include "Poco/Net/NetworkInterface.h" | ||||||
| #include "Poco/Net/IPAddress.h" | #include "Poco/Net/IPAddress.h" | ||||||
| #include "Poco/String.h" | #include "Poco/String.h" | ||||||
| #include "Poco/File.h" | #include "Poco/File.h" | ||||||
| #include "OpenWifiTypes.h" | #include "uCentralTypes.h" | ||||||
|  |  | ||||||
| #define DBGLINE { std::cout << __FILE__ << ":" << __func__ << ":" << __LINE__ << std::endl; }; | #define DBGLINE { std::cout << __FILE__ << ":" << __func__ << ":" << __LINE__ << std::endl; }; | ||||||
|  |  | ||||||
| namespace OpenWifi::Utils { | namespace uCentral::Utils { | ||||||
|  |  | ||||||
|     enum MediaTypeEncodings { |     enum MediaTypeEncodings { | ||||||
|         PLAIN, |         PLAIN, | ||||||
| @@ -75,16 +73,5 @@ namespace OpenWifi::Utils { | |||||||
|     [[nodiscard]] std::string SecondsToNiceText(uint64_t Seconds); |     [[nodiscard]] std::string SecondsToNiceText(uint64_t Seconds); | ||||||
|  |  | ||||||
| 	[[nodiscard]] bool IPinRange(const std::string &Range, const Poco::Net::IPAddress &IP); | 	[[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 | #endif // UCENTRALGW_UTILS_H | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ | |||||||
| #include "Poco/Data/LOBStream.h" | #include "Poco/Data/LOBStream.h" | ||||||
| #include "Daemon.h" | #include "Daemon.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     /* |     /* | ||||||
|                             "Id			    VARCHAR(36) PRIMARY KEY, " |                             "Id			    VARCHAR(36) PRIMARY KEY, " | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ | |||||||
| #ifndef WLAN_CLOUD_UCENTRALSEC_STORAGE_AVATAR_H | #ifndef WLAN_CLOUD_UCENTRALSEC_STORAGE_AVATAR_H | ||||||
| #define WLAN_CLOUD_UCENTRALSEC_STORAGE_AVATAR_H | #define WLAN_CLOUD_UCENTRALSEC_STORAGE_AVATAR_H | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										46
									
								
								src/storage_mysql.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/storage_mysql.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | |||||||
|  | // | ||||||
|  | //	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 | ||||||
|  | } | ||||||
							
								
								
									
										47
									
								
								src/storage_pgql.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								src/storage_pgql.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,47 @@ | |||||||
|  | // | ||||||
|  | //	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 | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -1,82 +0,0 @@ | |||||||
| // |  | ||||||
| // 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 |  | ||||||
|  |  | ||||||
| } |  | ||||||
|  |  | ||||||
							
								
								
									
										26
									
								
								src/storage_sqlite.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/storage_sqlite.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | // | ||||||
|  | //	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_users.h" | ||||||
| #include "storage_avatar.h" | #include "storage_avatar.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     int Storage::Create_Tables() { |     int Storage::Create_Tables() { | ||||||
|         Create_UserTable(); |         Create_UserTable(); | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ | |||||||
| #include "Poco/Tuple.h" | #include "Poco/Tuple.h" | ||||||
| #include "storage_users.h" | #include "storage_users.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|  |  | ||||||
|     bool Convert(const UserInfoRecord &T, SecurityObjects::UserInfo &U) { |     bool Convert(const UserInfoRecord &T, SecurityObjects::UserInfo &U) { | ||||||
|         U.Id = T.get<0>(); |         U.Id = T.get<0>(); | ||||||
| @@ -221,16 +221,17 @@ namespace OpenWifi { | |||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     bool Storage::GetUsers( uint64_t Offset, uint64_t HowMany, SecurityObjects::UserInfoVec & Users) { |     bool Storage::GetUsers( uint64_t Offset, uint64_t Limit, SecurityObjects::UserInfoVec & Users) { | ||||||
|         try { |         try { | ||||||
|             Poco::Data::Session Sess = Pool_->get(); |             Poco::Data::Session Sess = Pool_->get(); | ||||||
|             Poco::Data::Statement Select(Sess); |             Poco::Data::Statement Select(Sess); | ||||||
|             UserInfoRecordList Records; |             UserInfoRecordList Records; | ||||||
|  |  | ||||||
|             std::string St1{"select " + AllUsersFieldsForSelect + " from users order by id ASC "}; |             std::string St1{"select " + AllUsersFieldsForSelect + " from users"}; | ||||||
|  |  | ||||||
|             Select << ConvertParams(St1) + ComputeRange(Offset, HowMany), |             Select << ConvertParams(St1) , | ||||||
|                         Poco::Data::Keywords::into(Records); |                     Poco::Data::Keywords::into(Records), | ||||||
|  |                     Poco::Data::Keywords::range(Offset, Offset + Limit); | ||||||
|             Select.execute(); |             Select.execute(); | ||||||
|  |  | ||||||
|             for(const auto &R:Records) { |             for(const auto &R:Records) { | ||||||
|   | |||||||
| @@ -5,9 +5,9 @@ | |||||||
| #ifndef UCENTRALSEC_STORAGE_USERS_H | #ifndef UCENTRALSEC_STORAGE_USERS_H | ||||||
| #define UCENTRALSEC_STORAGE_USERS_H | #define UCENTRALSEC_STORAGE_USERS_H | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace uCentral { | ||||||
|     static const std::string AllUsersFieldsForCreation{ |     static const std::string AllUsersFieldsForCreation{ | ||||||
|         " Id             varchar(36) UNIQUE PRIMARY KEY," |             "Id             varchar(36)," | ||||||
|             "name           varchar," |             "name           varchar," | ||||||
|             "description    varchar," |             "description    varchar," | ||||||
|             "avatar         varchar," |             "avatar         varchar," | ||||||
| @@ -116,9 +116,6 @@ namespace OpenWifi { | |||||||
|             "canceled       bigint" |             "canceled       bigint" | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     typedef Poco::Tuple < |     typedef Poco::Tuple < | ||||||
|         std::string,    // Id = 0; |         std::string,    // Id = 0; | ||||||
|         std::string,    // name; |         std::string,    // name; | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ | |||||||
|  |  | ||||||
| #include "Poco/String.h" | #include "Poco/String.h" | ||||||
|  |  | ||||||
| namespace OpenWifi::uCentralProtocol { | namespace uCentral::uCentralProtocol { | ||||||
|  |  | ||||||
| 	const int SERIAL_NUMBER_LENGTH = 30; | 	const int SERIAL_NUMBER_LENGTH = 30; | ||||||
|  |  | ||||||
| @@ -79,15 +79,6 @@ namespace OpenWifi::uCentralProtocol { | |||||||
| 	static const char * VERBOSE = "verbose"; | 	static const char * VERBOSE = "verbose"; | ||||||
| 	static const char * BANDS = "bands"; | 	static const char * BANDS = "bands"; | ||||||
| 	static const char * CHANNELS = "channels"; | 	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 { | 	enum EVENT_MSG { | ||||||
| 			ET_UNKNOWN, | 			ET_UNKNOWN, | ||||||
| @@ -98,8 +89,7 @@ namespace OpenWifi::uCentralProtocol { | |||||||
| 			ET_CRASHLOG, | 			ET_CRASHLOG, | ||||||
| 			ET_PING, | 			ET_PING, | ||||||
| 			ET_CFGPENDING, | 			ET_CFGPENDING, | ||||||
| 			ET_RECOVERY, | 			ET_RECOVERY | ||||||
| 			ET_DEVICEUPDATE |  | ||||||
| 		}; | 		}; | ||||||
|  |  | ||||||
| 	static EVENT_MSG EventFromString(const std::string & Method) { | 	static EVENT_MSG EventFromString(const std::string & Method) { | ||||||
| @@ -119,8 +109,6 @@ namespace OpenWifi::uCentralProtocol { | |||||||
| 			return ET_CFGPENDING; | 			return ET_CFGPENDING; | ||||||
| 		} else if (!Poco::icompare(Method, RECOVERY)) { | 		} else if (!Poco::icompare(Method, RECOVERY)) { | ||||||
| 			return ET_RECOVERY; | 			return ET_RECOVERY; | ||||||
| 		} else if (!Poco::icompare(Method, DEVICEUPDATE)) { |  | ||||||
| 			return ET_DEVICEUPDATE; |  | ||||||
| 		} else | 		} else | ||||||
| 			return ET_UNKNOWN; | 			return ET_UNKNOWN; | ||||||
| 	}; | 	}; | ||||||
|   | |||||||
| @@ -15,9 +15,7 @@ | |||||||
| #include <utility> | #include <utility> | ||||||
| #include <queue> | #include <queue> | ||||||
| 
 | 
 | ||||||
| #include "Poco/StringTokenizer.h" | namespace uCentral::Types { | ||||||
| 
 |  | ||||||
| namespace OpenWifi::Types { |  | ||||||
|     typedef std::pair<std::string,std::string>              StringPair; |     typedef std::pair<std::string,std::string>              StringPair; | ||||||
| 	typedef std::vector<StringPair>	                        StringPairVec; | 	typedef std::vector<StringPair>	                        StringPairVec; | ||||||
|     typedef std::queue<StringPair>	                        StringPairQueue; |     typedef std::queue<StringPair>	                        StringPairQueue; | ||||||
| @@ -30,38 +28,12 @@ namespace OpenWifi::Types { | |||||||
| 	typedef std::map<std::string, TopicNotifyFunctionList>  NotifyTable; | 	typedef std::map<std::string, TopicNotifyFunctionList>  NotifyTable; | ||||||
|     typedef std::map<std::string,uint64_t>                  CountedMap; |     typedef std::map<std::string,uint64_t>                  CountedMap; | ||||||
| 
 | 
 | ||||||
|     typedef std::string         UUID_t; |     inline void UpdateCountedMap(CountedMap &M, const std::string &S ) { | ||||||
|     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); |         auto it = M.find(S); | ||||||
|         if(it==M.end()) |         if(it==M.end()) | ||||||
|             M[S] = Increment; |             M[S]=1; | ||||||
|         else |         else | ||||||
|             it->second += Increment; |             it->second += 1; | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     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); |  | ||||||
|     } |     } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| @@ -73,7 +73,7 @@ ucentral.kafka.queue.buffering.max.ms = 50 | |||||||
|  |  | ||||||
| ucentral.document.policy.access = /wwwassets/access_policy.html | ucentral.document.policy.access = /wwwassets/access_policy.html | ||||||
| ucentral.document.policy.password = /wwwassets/password_policy.html | ucentral.document.policy.password = /wwwassets/password_policy.html | ||||||
| ucentral.avatar.maxsize = 2000000 |  | ||||||
| # | # | ||||||
| # This section select which form of persistence you need | # 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 | # Only one selected at a time. If you select multiple, this service will die if a horrible | ||||||
|   | |||||||
| @@ -5,18 +5,41 @@ Wants=network-online.target | |||||||
|  |  | ||||||
| [Service] | [Service] | ||||||
| Type=simple | 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" | Environment="UCENTRALSEC_ROOT=/home/admin/dev/wlan-cloud-ucentralsec" | ||||||
| ExecStart=/home/admin/dev/wlan-cloud-ucentralsec/cmake-build/ucentralsec | ExecStart=/home/admin/dev/wlan-cloud-ucentralsec/cmake-build/ucentralsec | ||||||
| WorkingDirectory=/home/admin/dev/wlan-cloud-ucentralsec | WorkingDirectory=/home/admin/dev/wlan-cloud-ucentralsec | ||||||
| # ExecReload=/bin/kill -s HUP $MAINPID | ExecReload=/bin/kill -s HUP $MAINPID | ||||||
| User=admin | User=admin | ||||||
| # TimeoutSec=0 | TimeoutSec=0 | ||||||
| RestartSec=2 | RestartSec=2 | ||||||
| Restart=always | Restart=always | ||||||
| StartLimitBurst=3 |  | ||||||
| # KillMode=process |  | ||||||
| LimitNOFILE=500000 |  | ||||||
| LimitNPROC=500000 |  | ||||||
|  |  | ||||||
| [Install] | # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229. | ||||||
| WantedBy=multi-user.target | # 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 | ||||||
|  |  | ||||||
|  | # 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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user