mirror of
				https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
				synced 2025-10-31 02:37:56 +00:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			v3.0.0
			...
			v2.10.0-RC
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 5a6baeca7d | 
| @@ -1,5 +1,5 @@ | ||||
| cmake_minimum_required(VERSION 3.13) | ||||
| project(owsec VERSION 3.0.0) | ||||
| project(owsec VERSION 2.10.0) | ||||
|  | ||||
| set(CMAKE_CXX_STANDARD 17) | ||||
|  | ||||
| @@ -42,7 +42,7 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") | ||||
|     string(REGEX REPLACE "\n$" "" GIT_HASH "${GIT_HASH}") | ||||
| endif() | ||||
|  | ||||
| add_definitions(-DAWS_CUSTOM_MEMORY_MANAGEMENT -DBOOST_NO_CXX98_FUNCTION_BASE=1) | ||||
| add_definitions(-DAWS_CUSTOM_MEMORY_MANAGEMENT) | ||||
|  | ||||
| set(BUILD_SHARED_LIBS 1) | ||||
|  | ||||
| @@ -185,7 +185,6 @@ if(NOT SMALL_BUILD) | ||||
|             CppKafka::cppkafka | ||||
|             ${AWSSDK_LINK_LIBRARIES} | ||||
|             fmt::fmt | ||||
|             resolv | ||||
|             ) | ||||
|     if(UNIX AND NOT APPLE) | ||||
|         target_link_libraries(owsec PUBLIC PocoJSON) | ||||
|   | ||||
| @@ -9,7 +9,7 @@ fullnameOverride: "" | ||||
| images: | ||||
|   owsec: | ||||
|     repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owsec | ||||
|     tag: v3.0.0 | ||||
|     tag: v2.10.0-RC1 | ||||
|     pullPolicy: Always | ||||
| #    regcred: | ||||
| #      registry: tip-tip-wlan-cloud-ucentral.jfrog.io | ||||
|   | ||||
| @@ -565,6 +565,12 @@ components: | ||||
|             - $ref: '#/components/schemas/StringList' | ||||
|             - $ref: '#/components/schemas/TagValuePairList' | ||||
|  | ||||
|     SystemCommandResults: | ||||
|       type: object | ||||
|       oneOf: | ||||
|         - $ref: '#/components/schemas/StringList' | ||||
|         - $ref: '#/components/schemas/TagValuePairList' | ||||
|  | ||||
|     SystemInfoResults: | ||||
|       type: object | ||||
|       properties: | ||||
| @@ -593,33 +599,6 @@ components: | ||||
|                 type: integer | ||||
|                 format: int64 | ||||
|  | ||||
|     SystemResources: | ||||
|       type: object | ||||
|       properties: | ||||
|         numberOfFileDescriptors: | ||||
|           type: integer | ||||
|           format: int64 | ||||
|         currRealMem: | ||||
|           type: integer | ||||
|           format: int64 | ||||
|         peakRealMem: | ||||
|           type: integer | ||||
|           format: int64 | ||||
|         currVirtMem: | ||||
|           type: integer | ||||
|           format: int64 | ||||
|         peakVirtMem: | ||||
|           type: integer | ||||
|           format: int64 | ||||
|  | ||||
|     SystemCommandResults: | ||||
|       type: object | ||||
|       oneOf: | ||||
|         - $ref: '#/components/schemas/SystemResources' | ||||
|         - $ref: '#/components/schemas/SystemInfoResults' | ||||
|         - $ref: '#/components/schemas/StringList' | ||||
|         - $ref: '#/components/schemas/TagValuePairList' | ||||
|  | ||||
|     ProfileAction: | ||||
|       type: object | ||||
|       properties: | ||||
| @@ -1988,12 +1967,16 @@ paths: | ||||
|             type: string | ||||
|             enum: | ||||
|               - info | ||||
|               - extraConfiguration | ||||
|               - resources | ||||
|           required: true | ||||
|  | ||||
|       responses: | ||||
|         200: | ||||
|           $ref: '#/components/schemas/SystemCommandResults' | ||||
|           description: Successful command execution | ||||
|           content: | ||||
|             application/json: | ||||
|               schema: | ||||
|                 oneOf: | ||||
|                   - $ref: '#/components/schemas/SystemInfoResults' | ||||
|         403: | ||||
|           $ref: '#/components/responses/Unauthorized' | ||||
|         404: | ||||
|   | ||||
| @@ -28,13 +28,10 @@ namespace OpenWifi { | ||||
| 		poco_information(Logger(), "Stopped..."); | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	void ActionLinkManager::run() { | ||||
| 		Running_ = true; | ||||
| 		Utils::SetThreadName("action-mgr"); | ||||
|  | ||||
|         Poco::Thread::trySleep(10000); | ||||
|  | ||||
| 		while (Running_) { | ||||
| 			Poco::Thread::trySleep(2000); | ||||
| 			if (!Running_) | ||||
| @@ -101,8 +98,10 @@ namespace OpenWifi { | ||||
| 				} break; | ||||
|  | ||||
| 				case OpenWifi::SecurityObjects::LinkActions::SUB_FORGOT_PASSWORD: { | ||||
| 					auto Signup = Poco::StringTokenizer(UInfo.signingUp, ":"); | ||||
| 					if (AuthService()->SendEmailToSubUser(i.id, UInfo.email, | ||||
| 														  MessagingTemplates::SUB_FORGOT_PASSWORD,"")) { | ||||
| 														  MessagingTemplates::SUB_FORGOT_PASSWORD, | ||||
| 														  Signup.count() == 1 ? "" : Signup[0])) { | ||||
| 						poco_information( | ||||
| 							Logger(), | ||||
| 							fmt::format("Send subscriber password reset link to {}", UInfo.email)); | ||||
| @@ -111,8 +110,10 @@ namespace OpenWifi { | ||||
| 				} break; | ||||
|  | ||||
| 				case OpenWifi::SecurityObjects::LinkActions::SUB_VERIFY_EMAIL: { | ||||
| 					auto Signup = Poco::StringTokenizer(UInfo.signingUp, ":"); | ||||
| 					if (AuthService()->SendEmailToSubUser( | ||||
| 							i.id, UInfo.email, MessagingTemplates::SUB_EMAIL_VERIFICATION,"")) { | ||||
| 							i.id, UInfo.email, MessagingTemplates::SUB_EMAIL_VERIFICATION, | ||||
| 							Signup.count() == 1 ? "" : Signup[0])) { | ||||
| 						poco_information( | ||||
| 							Logger(), fmt::format("Send subscriber email verification link to {}", | ||||
| 												  UInfo.email)); | ||||
|   | ||||
| @@ -218,7 +218,7 @@ namespace OpenWifi { | ||||
| 				Expired = (WT.created_ + WT.expires_in_) < now; | ||||
| 				if (StorageService()->UserDB().GetUserById(UserId, UInfo.userinfo)) { | ||||
| 					UInfo.webtoken = WT; | ||||
| 					poco_trace(Logger(), fmt::format("TokenValidation success for TID={} Token={}", | ||||
| 					poco_debug(Logger(), fmt::format("TokenValidation success for TID={} Token={}", | ||||
| 													 TID, Utils::SanitizeToken(CallToken))); | ||||
| 					return true; | ||||
| 				} | ||||
| @@ -342,8 +342,10 @@ namespace OpenWifi { | ||||
| 				Obj.set("event", "remove-token"); | ||||
| 				Obj.set("id", MicroServiceID()); | ||||
| 				Obj.set("token", token); | ||||
| 				std::stringstream ResultText; | ||||
| 				Poco::JSON::Stringifier::stringify(Obj, ResultText); | ||||
| 				KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, | ||||
| 											MicroServicePrivateEndPoint(), Obj, false); | ||||
| 											MicroServicePrivateEndPoint(), std::make_shared<std::string>(ResultText.str()), false); | ||||
| 			} | ||||
| 		} catch (const Poco::Exception &E) { | ||||
| 			Logger().log(E); | ||||
| @@ -798,6 +800,7 @@ namespace OpenWifi { | ||||
|  | ||||
| 		if (StorageService()->SubDB().GetUserByEmail(Email, UInfo)) { | ||||
| 			switch (Reason) { | ||||
|  | ||||
| 			case MessagingTemplates::SUB_FORGOT_PASSWORD: { | ||||
| 				MessageAttributes Attrs; | ||||
| 				Attrs[RECIPIENT_EMAIL] = UInfo.email; | ||||
|   | ||||
| @@ -37,9 +37,9 @@ namespace OpenWifi { | ||||
| 			instance_ = | ||||
| 				new Daemon(vDAEMON_PROPERTIES_FILENAME, vDAEMON_ROOT_ENV_VAR, | ||||
| 						   vDAEMON_CONFIG_ENV_VAR, vDAEMON_APP_NAME, vDAEMON_BUS_TIMER, | ||||
| 						   SubSystemVec{StorageService(), SMSSender(), AuthService(), ActionLinkManager(), | ||||
| 						   SubSystemVec{StorageService(), SMSSender(), ActionLinkManager(), | ||||
| 										SMTPMailerService(), RESTAPI_RateLimiter(), TotpCache(), | ||||
| 										UI_WebSocketClientServer(), SecretStore()}); | ||||
| 										AuthService(), UI_WebSocketClientServer(), SecretStore()}); | ||||
| 		} | ||||
| 		return instance_; | ||||
| 	} | ||||
|   | ||||
| @@ -37,11 +37,11 @@ namespace OpenWifi { | ||||
| 		if (Action == "password_reset") | ||||
| 			return RequestResetPassword(Link); | ||||
| 		else if (Action == "sub_password_reset") | ||||
| 			return RequestResetPassword(Link); | ||||
| 			return RequestSubResetPassword(Link); | ||||
| 		else if (Action == "email_verification") | ||||
| 			return DoEmailVerification(Link); | ||||
| 		else if (Action == "sub_email_verification") | ||||
| 			return DoEmailVerification(Link); | ||||
| 			return DoSubEmailVerification(Link); | ||||
| 		else if (Action == "signup_verification") | ||||
| 			return DoNewSubVerification(Link); | ||||
| 		else | ||||
| @@ -101,6 +101,7 @@ namespace OpenWifi { | ||||
| 	} | ||||
|  | ||||
| 	void RESTAPI_action_links::CompleteResetPassword() { | ||||
| 		//  form has been posted... | ||||
| 		RESTAPI_PartHandler PartHandler; | ||||
| 		Poco::Net::HTMLForm Form(*Request, Request->stream(), PartHandler); | ||||
| 		if (!Form.empty()) { | ||||
|   | ||||
| @@ -34,9 +34,7 @@ namespace OpenWifi { | ||||
| 			return BadRequest(RESTAPI::Errors::SMSCouldNotValidate); | ||||
| 		} | ||||
|  | ||||
|         if(Internal_) { | ||||
|             poco_information(Logger(),fmt::format("Internal SMS request: TID={}", TransactionId_)); | ||||
|         } else if (UserInfo_.userinfo.userRole != SecurityObjects::ROOT && | ||||
| 		if (UserInfo_.userinfo.userRole != SecurityObjects::ROOT && | ||||
| 			UserInfo_.userinfo.userRole != SecurityObjects::PARTNER && | ||||
| 			UserInfo_.userinfo.userRole != SecurityObjects::ADMIN) { | ||||
| 			return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED); | ||||
|   | ||||
| @@ -185,7 +185,7 @@ namespace OpenWifi { | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if (GetBoolParameter("forgotPassword") || GetBoolParameter("resetPassword")) { | ||||
| 		if (GetBoolParameter("forgotPassword")) { | ||||
| 			Existing.changePassword = true; | ||||
| 			Logger_.information(fmt::format("FORGOTTEN-PASSWORD({}): Request for {}", | ||||
| 											Request->clientAddress().toString(), Existing.email)); | ||||
|   | ||||
| @@ -33,7 +33,7 @@ namespace OpenWifi { | ||||
| 			return NotFound(); | ||||
| 		} | ||||
|  | ||||
| 		if (!Internal_ && !ACLProcessor::Can(UserInfo_.userinfo, UInfo, ACLProcessor::READ)) { | ||||
| 		if (!ACLProcessor::Can(UserInfo_.userinfo, UInfo, ACLProcessor::READ)) { | ||||
| 			return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED); | ||||
| 		} | ||||
|  | ||||
|   | ||||
| @@ -171,31 +171,6 @@ namespace OpenWifi::GWObjects { | ||||
| 		field_to_json(Obj, "lastModified", LastModified); | ||||
| 	} | ||||
|  | ||||
| 	void DefaultFirmware::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		field_to_json(Obj, "deviceType", deviceType); | ||||
| 		field_to_json(Obj, "description", Description); | ||||
| 		field_to_json(Obj, "uri", uri); | ||||
| 		field_to_json(Obj, "revision", revision); | ||||
| 		field_to_json(Obj, "imageCreationDate", imageCreationDate); | ||||
| 		field_to_json(Obj, "created", Created); | ||||
| 		field_to_json(Obj, "lastModified", LastModified); | ||||
| 	} | ||||
|  | ||||
| 	bool DefaultFirmware::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
| 		try { | ||||
| 			field_from_json(Obj, "deviceType", deviceType); | ||||
| 			field_from_json(Obj, "description", Description); | ||||
| 			field_from_json(Obj, "uri", uri); | ||||
| 			field_from_json(Obj, "revision", revision); | ||||
| 			field_from_json(Obj, "imageCreationDate", imageCreationDate); | ||||
| 			field_from_json(Obj, "created", Created); | ||||
| 			field_from_json(Obj, "lastModified", LastModified); | ||||
| 			return true; | ||||
| 		} catch (const Poco::Exception &E) { | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	void CommandDetails::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		EmbedDocument("details", Obj, Details); | ||||
| 		EmbedDocument("results", Obj, Results); | ||||
| @@ -271,8 +246,6 @@ namespace OpenWifi::GWObjects { | ||||
| 		field_to_json(Obj, "connectionCompletionTime", connectionCompletionTime); | ||||
| 		field_to_json(Obj, "totalConnectionTime", Utils::Now() - started); | ||||
| 		field_to_json(Obj, "certificateExpiryDate", certificateExpiryDate); | ||||
| 		field_to_json(Obj, "connectReason", connectReason); | ||||
|  | ||||
| #ifdef TIP_GATEWAY_SERVICE | ||||
| 		hasRADIUSSessions = RADIUSSessionTracker()->HasSessions(SerialNumber); | ||||
| 		AP_WS_Server()->ExtendedAttributes(SerialNumber, hasGPS, sanity, | ||||
| @@ -430,10 +403,6 @@ namespace OpenWifi::GWObjects { | ||||
| 		field_to_json(Obj, "acctConfig", acctConfig); | ||||
| 		field_to_json(Obj, "coaConfig", coaConfig); | ||||
| 		field_to_json(Obj, "useByDefault", useByDefault); | ||||
| 		field_to_json(Obj, "radsecKeepAlive", radsecKeepAlive); | ||||
| 		field_to_json(Obj, "poolProxyIp", poolProxyIp); | ||||
| 		field_to_json(Obj, "radsecPoolType", radsecPoolType); | ||||
| 		field_to_json(Obj, "enabled", enabled); | ||||
| 	} | ||||
|  | ||||
| 	bool RadiusProxyPool::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
| @@ -444,10 +413,6 @@ namespace OpenWifi::GWObjects { | ||||
| 			field_from_json(Obj, "acctConfig", acctConfig); | ||||
| 			field_from_json(Obj, "coaConfig", coaConfig); | ||||
| 			field_from_json(Obj, "useByDefault", useByDefault); | ||||
| 			field_from_json(Obj, "radsecKeepAlive", radsecKeepAlive); | ||||
| 			field_from_json(Obj, "poolProxyIp", poolProxyIp); | ||||
| 			field_from_json(Obj, "radsecPoolType", radsecPoolType); | ||||
| 			field_from_json(Obj, "enabled", enabled); | ||||
| 			return true; | ||||
| 		} catch (const Poco::Exception &E) { | ||||
| 		} | ||||
| @@ -665,50 +630,18 @@ namespace OpenWifi::GWObjects { | ||||
| 		field_to_json(Obj, "chargeableUserIdentity", chargeableUserIdentity); | ||||
| 		field_to_json(Obj, "interface", interface); | ||||
| 		field_to_json(Obj, "secret", secret); | ||||
| 		field_to_json(Obj, "nasId", nasId); | ||||
| 		field_to_json(Obj, "calledStationId", calledStationId); | ||||
| 	} | ||||
|  | ||||
| 	void RADIUSSessionList::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		field_to_json(Obj, "sessions", sessions); | ||||
| 	} | ||||
|  | ||||
| 	void RadiusCoADMParameters::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		field_to_json(Obj, "accountingSessionId", accountingSessionId); | ||||
| 		field_to_json(Obj, "accountingMultiSessionId", accountingMultiSessionId); | ||||
| 		field_to_json(Obj, "callingStationId", callingStationId); | ||||
| 		field_to_json(Obj, "chargeableUserIdentity", chargeableUserIdentity); | ||||
| 		field_to_json(Obj, "userName", userName); | ||||
| 	} | ||||
|  | ||||
| 	bool RadiusCoADMParameters::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
| 		try { | ||||
| 			field_from_json(Obj, "accountingSessionId", accountingSessionId); | ||||
| 			field_from_json(Obj, "accountingMultiSessionId", accountingMultiSessionId); | ||||
| 			field_from_json(Obj, "callingStationId", callingStationId); | ||||
| 			field_from_json(Obj, "chargeableUserIdentity", chargeableUserIdentity); | ||||
| 			field_from_json(Obj, "userName", userName); | ||||
| 			return true; | ||||
| 		} catch (const Poco::Exception &E) { | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	bool DeviceTransferRequest::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
| 		try { | ||||
| 			field_from_json(Obj, "serialNumber", serialNumber); | ||||
| 			field_from_json(Obj, "server", server); | ||||
| 			field_from_json(Obj, "port", port); | ||||
| 			return true; | ||||
| 		} catch (const Poco::Exception &E) { | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	bool DeviceCertificateUpdateRequest::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
| 		try { | ||||
| 			field_from_json(Obj, "serialNumber", serialNumber); | ||||
| 			field_from_json(Obj, "encodedCertificate", encodedCertificate); | ||||
| 			return true; | ||||
| 		} catch (const Poco::Exception &E) { | ||||
| 		} | ||||
|   | ||||
| @@ -42,13 +42,12 @@ namespace OpenWifi::GWObjects { | ||||
| 		uint64_t sessionId = 0; | ||||
| 		double connectionCompletionTime = 0.0; | ||||
| 		std::uint64_t certificateExpiryDate = 0; | ||||
| 		std::uint64_t hasRADIUSSessions = 0; | ||||
| 		bool hasRADIUSSessions = false; | ||||
| 		bool hasGPS = false; | ||||
| 		std::uint64_t sanity=0; | ||||
| 		std::double_t memoryUsed=0.0; | ||||
| 		std::double_t load=0.0; | ||||
| 		std::double_t temperature=0.0; | ||||
| 		std::string 	connectReason; | ||||
|  | ||||
| 		void to_json(const std::string &SerialNumber, Poco::JSON::Object &Obj) ; | ||||
| 	}; | ||||
| @@ -182,26 +181,6 @@ namespace OpenWifi::GWObjects { | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	struct DefaultFirmware { | ||||
| 		std::string deviceType; | ||||
| 		std::string Description; | ||||
| 		std::string uri; | ||||
| 		std::string revision; | ||||
| 		uint64_t imageCreationDate; | ||||
| 		uint64_t Created; | ||||
| 		uint64_t LastModified; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	struct DefaultFirmwareList { | ||||
| 		std::vector<DefaultFirmware>	firmwares; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	struct CommandDetails { | ||||
| 		std::string UUID; | ||||
| 		std::string SerialNumber; | ||||
| @@ -360,10 +339,6 @@ namespace OpenWifi::GWObjects { | ||||
| 		RadiusProxyServerConfig acctConfig; | ||||
| 		RadiusProxyServerConfig coaConfig; | ||||
| 		bool useByDefault = false; | ||||
| 		std::string 	radsecPoolType; | ||||
| 		std::string 	poolProxyIp; | ||||
| 		std::uint64_t 	radsecKeepAlive=25; | ||||
| 		bool			enabled=true; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| @@ -418,8 +393,7 @@ namespace OpenWifi::GWObjects { | ||||
| 					 			callingStationId, | ||||
| 								chargeableUserIdentity, | ||||
| 								secret, | ||||
| 								interface, | ||||
| 								nasId; | ||||
| 								interface; | ||||
| 		std::uint64_t 			inputPackets = 0, | ||||
| 								outputPackets = 0, | ||||
| 								inputOctets = 0, | ||||
| @@ -427,7 +401,6 @@ namespace OpenWifi::GWObjects { | ||||
| 								inputGigaWords = 0, | ||||
| 								outputGigaWords = 0; | ||||
| 		std::uint32_t 			sessionTime = 0; | ||||
| 		std::string 			calledStationId; | ||||
|  | ||||
| #ifdef TIP_GATEWAY_SERVICE | ||||
| 		RADIUS::RadiusPacket	accountingPacket; | ||||
| @@ -445,68 +418,7 @@ namespace OpenWifi::GWObjects { | ||||
| 		std::string 			accountingSessionId, | ||||
| 								accountingMultiSessionId, | ||||
| 								callingStationId, | ||||
| 								chargeableUserIdentity, | ||||
| 								userName; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 	}; | ||||
|  | ||||
| 	enum class RadiusPoolStrategy { | ||||
| 		round_robin, random, weighted, unknown | ||||
| 	}; | ||||
|  | ||||
| 	enum class RadiusEndpointType { | ||||
| 		generic, radsec, globalreach, orion, unknown | ||||
| 	}; | ||||
|  | ||||
| 	static inline RadiusEndpointType RadiusEndpointType(const std::string &T) { | ||||
| 		if(T=="generic") return RadiusEndpointType::generic; | ||||
| 		if(T=="radsec") return RadiusEndpointType::radsec; | ||||
| 		if(T=="globalreach") return RadiusEndpointType::globalreach; | ||||
| 		if(T=="orion") return RadiusEndpointType::orion; | ||||
| 		return RadiusEndpointType::unknown; | ||||
| 	} | ||||
|  | ||||
| 	static inline RadiusPoolStrategy RadiusPoolStrategy(const std::string &T) { | ||||
| 		if(T=="round_robin") return RadiusPoolStrategy::round_robin; | ||||
| 		if(T=="random") return RadiusPoolStrategy::random; | ||||
| 		if(T=="weighted") return RadiusPoolStrategy::weighted; | ||||
| 		return RadiusPoolStrategy::unknown; | ||||
| 	} | ||||
|  | ||||
| 	static inline std::string to_string(enum RadiusEndpointType T) { | ||||
| 		switch(T) { | ||||
| 		case RadiusEndpointType::generic: return "generic"; | ||||
| 		case RadiusEndpointType::radsec: return "radsec"; | ||||
| 		case RadiusEndpointType::globalreach: return "globalreach"; | ||||
| 		case RadiusEndpointType::orion: return "orion"; | ||||
| 		default: | ||||
| 			return "unknown"; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	static inline std::string to_string(enum RadiusPoolStrategy T) { | ||||
| 		switch(T) { | ||||
| 		case RadiusPoolStrategy::round_robin: return "round_robin"; | ||||
| 		case RadiusPoolStrategy::random: return "random"; | ||||
| 		case RadiusPoolStrategy::weighted: return "weighted"; | ||||
| 		default: | ||||
| 			return "unknown"; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	struct DeviceTransferRequest { | ||||
| 		std::string 	serialNumber; | ||||
| 		std::string 	server; | ||||
| 		std::uint64_t 	port; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	struct DeviceCertificateUpdateRequest { | ||||
| 		std::string 	serialNumber; | ||||
| 		std::string 	encodedCertificate; | ||||
| 								chargeableUserIdentity; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|   | ||||
| @@ -92,7 +92,6 @@ namespace OpenWifi::OWLSObjects { | ||||
| 		field_to_json(Obj, "endTime", endTime); | ||||
| 		field_to_json(Obj, "errorDevices", errorDevices); | ||||
| 		field_to_json(Obj, "owner", owner); | ||||
|         field_to_json(Obj, "expectedDevices", expectedDevices); | ||||
| 	} | ||||
|  | ||||
| 	void Dashboard::to_json([[maybe_unused]] Poco::JSON::Object &Obj) const {} | ||||
|   | ||||
| @@ -57,7 +57,6 @@ namespace OpenWifi::OWLSObjects { | ||||
| 		uint64_t endTime; | ||||
| 		uint64_t errorDevices; | ||||
| 		std::string owner; | ||||
|         uint64_t expectedDevices; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 	}; | ||||
|   | ||||
| @@ -1194,243 +1194,4 @@ namespace OpenWifi::ProvObjects { | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
|     void GLBLRAccountInfo::to_json(Poco::JSON::Object &Obj) const { | ||||
|         info.to_json(Obj); | ||||
|         field_to_json(Obj, "privateKey", privateKey); | ||||
|         field_to_json(Obj, "country", country); | ||||
|         field_to_json(Obj, "province", province); | ||||
|         field_to_json(Obj, "city", city); | ||||
|         field_to_json(Obj, "organization", organization); | ||||
|         field_to_json(Obj, "commonName", commonName); | ||||
|         field_to_json(Obj, "CSR", CSR); | ||||
|         field_to_json(Obj, "CSRPrivateKey", CSRPrivateKey); | ||||
|         field_to_json(Obj, "CSRPublicKey", CSRPublicKey); | ||||
|         field_to_json(Obj, "GlobalReachAcctId", GlobalReachAcctId); | ||||
|     } | ||||
|  | ||||
|     bool GLBLRAccountInfo::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
|         try { | ||||
|             info.from_json(Obj); | ||||
|             field_from_json(Obj, "privateKey", privateKey); | ||||
|             field_from_json(Obj, "country", country); | ||||
|             field_from_json(Obj, "province", province); | ||||
|             field_from_json(Obj, "city", city); | ||||
|             field_from_json(Obj, "organization", organization); | ||||
|             field_from_json(Obj, "commonName", commonName); | ||||
|             field_from_json(Obj, "CSR", CSR); | ||||
|             field_from_json(Obj, "CSRPrivateKey", CSRPrivateKey); | ||||
|             field_from_json(Obj, "CSRPublicKey", CSRPublicKey); | ||||
|             field_from_json(Obj, "GlobalReachAcctId", GlobalReachAcctId); | ||||
|             return true; | ||||
|         } catch (const Poco::Exception &E) { | ||||
|  | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     void GLBLRCertificateInfo::to_json(Poco::JSON::Object &Obj) const { | ||||
|         field_to_json(Obj, "id", id); | ||||
|         field_to_json(Obj, "name", name); | ||||
|         field_to_json(Obj, "accountId", accountId); | ||||
|         field_to_json(Obj, "csr", csr); | ||||
|         field_to_json(Obj, "certificate", certificate); | ||||
|         field_to_json(Obj, "certificateChain", certificateChain); | ||||
|         field_to_json(Obj, "certificateId", certificateId); | ||||
|         field_to_json(Obj, "expiresAt", expiresAt); | ||||
|         field_to_json(Obj, "created", created); | ||||
|     } | ||||
|  | ||||
|     bool GLBLRCertificateInfo::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
|         try { | ||||
|             field_from_json(Obj, "id", id); | ||||
|             field_from_json(Obj, "name", name); | ||||
|             field_from_json(Obj, "accountId", accountId); | ||||
|             field_from_json(Obj, "csr", csr); | ||||
|             field_from_json(Obj, "certificate", certificate); | ||||
|             field_from_json(Obj, "certificateChain", certificateChain); | ||||
|             field_from_json(Obj, "certificateId", certificateId); | ||||
|             field_from_json(Obj, "expiresAt", expiresAt); | ||||
|             field_from_json(Obj, "created", created); | ||||
|             return true; | ||||
|         } catch (const Poco::Exception &E) { | ||||
|  | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     void GooglOrionAccountInfo::to_json(Poco::JSON::Object &Obj) const { | ||||
|         info.to_json(Obj); | ||||
|         field_to_json(Obj, "privateKey", privateKey); | ||||
|         field_to_json(Obj, "certificate", certificate); | ||||
|         field_to_json(Obj, "cacerts", cacerts); | ||||
|     } | ||||
|  | ||||
|     bool GooglOrionAccountInfo::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
|         try { | ||||
|             info.from_json(Obj); | ||||
|             field_from_json(Obj, "privateKey", privateKey); | ||||
|             field_from_json(Obj, "certificate", certificate); | ||||
|             field_from_json(Obj, "cacerts", cacerts); | ||||
|             return true; | ||||
|         } catch (const Poco::Exception &E) { | ||||
|  | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     void RADIUSServer::to_json(Poco::JSON::Object &Obj) const { | ||||
|         field_to_json(Obj, "Hostname", Hostname); | ||||
|         field_to_json(Obj, "IP", IP); | ||||
|         field_to_json(Obj, "Port", Port); | ||||
|         field_to_json(Obj, "Secret", Secret); | ||||
|     } | ||||
|  | ||||
|     bool RADIUSServer::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
|         try { | ||||
|             field_from_json(Obj, "Hostname", Hostname); | ||||
|             field_from_json(Obj, "IP", IP); | ||||
|             field_from_json(Obj, "Port", Port); | ||||
|             field_from_json(Obj, "Secret", Secret); | ||||
|             return true; | ||||
|         } catch (const Poco::Exception &E) { | ||||
|  | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     void RADIUSEndPointRadiusType::to_json(Poco::JSON::Object &Obj) const { | ||||
|         field_to_json(Obj, "Authentication", Authentication); | ||||
|         field_to_json(Obj, "Accounting", Accounting); | ||||
|         field_to_json(Obj, "CoA", CoA); | ||||
|         field_to_json(Obj, "AccountingInterval", AccountingInterval); | ||||
|     } | ||||
|  | ||||
|     bool RADIUSEndPointRadiusType::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
|         try { | ||||
|             field_from_json(Obj, "Authentication", Authentication); | ||||
|             field_from_json(Obj, "Accounting", Accounting); | ||||
|             field_from_json(Obj, "CoA", CoA); | ||||
|             field_from_json(Obj, "AccountingInterval", AccountingInterval); | ||||
|             return true; | ||||
|         } catch (const Poco::Exception &E) { | ||||
|  | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     void RADIUSEndPointRadsecType::to_json(Poco::JSON::Object &Obj) const { | ||||
|         field_to_json(Obj, "Hostname", Hostname); | ||||
|         field_to_json(Obj, "IP", IP); | ||||
|         field_to_json(Obj, "Port", Port); | ||||
|         field_to_json(Obj, "Secret", Secret); | ||||
|         field_to_json(Obj, "OpenRoamingType", OpenRoamingType); | ||||
|         field_to_json(Obj, "UseOpenRoamingAccount", UseOpenRoamingAccount); | ||||
|         field_to_json(Obj, "Weight", Weight); | ||||
|         field_to_json(Obj, "Certificate", Certificate); | ||||
|         field_to_json(Obj, "PrivateKey", PrivateKey); | ||||
|         field_to_json(Obj, "CaCerts", CaCerts); | ||||
|         field_to_json(Obj, "AllowSelfSigned", AllowSelfSigned); | ||||
|     } | ||||
|  | ||||
|     bool RADIUSEndPointRadsecType::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
|         try { | ||||
|             field_from_json(Obj, "Hostname", Hostname); | ||||
|             field_from_json(Obj, "IP", IP); | ||||
|             field_from_json(Obj, "Port", Port); | ||||
|             field_from_json(Obj, "Secret", Secret); | ||||
|             field_from_json(Obj, "OpenRoamingType", OpenRoamingType); | ||||
|             field_from_json(Obj, "UseOpenRoamingAccount", UseOpenRoamingAccount); | ||||
|             field_from_json(Obj, "Weight", Weight); | ||||
|             field_from_json(Obj, "Certificate", Certificate); | ||||
|             field_from_json(Obj, "PrivateKey", PrivateKey); | ||||
|             field_from_json(Obj, "CaCerts", CaCerts); | ||||
|             field_from_json(Obj, "AllowSelfSigned", AllowSelfSigned); | ||||
|             return true; | ||||
|         } catch (const Poco::Exception &E) { | ||||
|  | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     void RADIUSEndPoint::to_json(Poco::JSON::Object &Obj) const { | ||||
|         info.to_json(Obj); | ||||
|         field_to_json(Obj, "Type", Type); | ||||
|         field_to_json(Obj, "RadsecServers", RadsecServers); | ||||
|         field_to_json(Obj, "RadiusServers", RadiusServers); | ||||
|         field_to_json(Obj, "PoolStrategy", PoolStrategy); | ||||
|         field_to_json(Obj, "Index", Index); | ||||
|         field_to_json(Obj, "UsedBy", UsedBy); | ||||
|         field_to_json(Obj, "UseGWProxy", UseGWProxy); | ||||
|         field_to_json(Obj, "NasIdentifier", NasIdentifier); | ||||
|         field_to_json(Obj, "AccountingInterval", AccountingInterval); | ||||
|     } | ||||
|  | ||||
|     bool RADIUSEndPoint::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
|         try { | ||||
|             info.from_json(Obj); | ||||
|             field_from_json(Obj, "Type", Type); | ||||
|             field_from_json(Obj, "RadsecServers", RadsecServers); | ||||
|             field_from_json(Obj, "RadiusServers", RadiusServers); | ||||
|             field_from_json(Obj, "PoolStrategy", PoolStrategy); | ||||
|             field_from_json(Obj, "Index", Index); | ||||
|             field_from_json(Obj, "UsedBy", UsedBy); | ||||
|             field_from_json(Obj, "UseGWProxy", UseGWProxy); | ||||
|             field_from_json(Obj, "NasIdentifier", NasIdentifier); | ||||
|             field_from_json(Obj, "AccountingInterval", AccountingInterval); | ||||
|             return true; | ||||
|         } catch (const Poco::Exception &E) { | ||||
|  | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     void RADIUSEndpointUpdateStatus::to_json(Poco::JSON::Object &Obj) const { | ||||
|         field_to_json(Obj, "lastUpdate", lastUpdate); | ||||
|         field_to_json(Obj, "lastConfigurationChange", lastConfigurationChange); | ||||
|     } | ||||
|  | ||||
|     bool RADIUSEndpointUpdateStatus::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
|         try { | ||||
|             field_from_json(Obj, "lastUpdate", lastUpdate); | ||||
|             field_from_json(Obj, "lastConfigurationChange", lastConfigurationChange); | ||||
|             return true; | ||||
|         } catch (const Poco::Exception &E) { | ||||
|  | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     bool RADIUSEndpointUpdateStatus::Read() { | ||||
|         Poco::File  F(OpenWifi::MicroServiceDataDirectory()+"/RADIUSEndpointUpdateStatus.json"); | ||||
|         try { | ||||
|             if (F.exists()) { | ||||
|                 Poco::JSON::Parser P; | ||||
|                 std::ifstream ifs(F.path(), std::ios_base::in | std::ios_base::binary); | ||||
|                 auto Obj = P.parse(ifs); | ||||
|                 return from_json(Obj.extract<Poco::JSON::Object::Ptr>()); | ||||
|             } | ||||
|         } catch (...) { | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     bool RADIUSEndpointUpdateStatus::Save() { | ||||
|         Poco::File  F(OpenWifi::MicroServiceDataDirectory()+"/RADIUSEndpointUpdateStatus.json"); | ||||
|         try { | ||||
|             Poco::JSON::Object Obj; | ||||
|             to_json(Obj); | ||||
|             std::ofstream O(F.path(), std::ios_base::out | std::ios_base::trunc | std::ios_base::binary); | ||||
|             Poco::JSON::Stringifier::stringify(Obj, O); | ||||
|             return true; | ||||
|         } catch (...) { | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     bool RADIUSEndpointUpdateStatus::ChangeConfiguration() { | ||||
|         Read(); | ||||
|         lastConfigurationChange = Utils::Now(); | ||||
|         return Save(); | ||||
|     } | ||||
|  | ||||
| } // namespace OpenWifi::ProvObjects | ||||
|   | ||||
| @@ -29,7 +29,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::TagList tags; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -37,7 +36,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUIDvec_t serialNumbers; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -48,7 +46,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string policy; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -60,18 +57,14 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUID_t venue; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	typedef std::vector<ManagementPolicy> ManagementPolicyVec; | ||||
|  | ||||
| 	struct RRMAlgorithmDetails { | ||||
| 		std::string name; | ||||
| 		std::string parameters; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -79,9 +72,7 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string vendor; | ||||
| 		std::string schedule; | ||||
| 		std::vector<RRMAlgorithmDetails> algorithms; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -91,7 +82,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string firmwareUpgrade{"inherit"}; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -114,10 +104,8 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUIDvec_t configurations; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	typedef std::vector<Entity> EntityVec; | ||||
|  | ||||
| 	struct DiGraphEntry { | ||||
| @@ -125,7 +113,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUID_t child; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -153,10 +140,8 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUIDvec_t boards; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	typedef std::vector<Venue> VenueVec; | ||||
|  | ||||
| 	struct UserInfoDigest { | ||||
| @@ -165,7 +150,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string userType; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -178,10 +162,8 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUID_t venue; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	typedef std::vector<ManagementRole> ManagementRoleVec; | ||||
|  | ||||
| 	enum LocationType { | ||||
| @@ -250,10 +232,8 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUID_t managementPolicy; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	typedef std::vector<Location> LocationVec; | ||||
|  | ||||
| 	struct OperatorLocation { | ||||
| @@ -273,10 +253,8 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUID_t managementPolicy; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	typedef std::vector<Location> LocationVec; | ||||
|  | ||||
| 	struct SubLocation { | ||||
| @@ -292,7 +270,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string geoCode; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -300,7 +277,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::vector<OperatorLocation> locations; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -380,10 +356,8 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUID_t managementPolicy; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	typedef std::vector<Contact> ContactVec; | ||||
|  | ||||
| 	struct OperatorContact { | ||||
| @@ -405,7 +379,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUID_t managementPolicy; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -424,7 +397,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string accessPIN; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -432,7 +404,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::vector<OperatorContact> contacts; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -445,10 +416,8 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string configuration; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	typedef std::vector<DeviceConfigurationElement> DeviceConfigurationElementVec; | ||||
|  | ||||
| 	struct DeviceConfiguration { | ||||
| @@ -465,10 +434,8 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string subscriber; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	typedef std::vector<DeviceConfiguration> DeviceConfigurationVec; | ||||
|  | ||||
| 	struct InventoryTag { | ||||
| @@ -492,7 +459,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		bool doNotAllowOverrides = false; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -502,7 +468,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		InventoryTagVec taglist; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -513,7 +478,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		uint64_t errorCode; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -522,7 +486,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::CountedMap tenants; | ||||
|  | ||||
| 		void reset(); | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 	}; | ||||
|  | ||||
| @@ -532,7 +495,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string description; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -541,7 +503,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::vector<ExpandedUseEntry> entries; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -549,7 +510,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::vector<ExpandedUseEntryList> entries; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -557,13 +517,10 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUIDvec_t list; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
|     enum ACLACCESS { | ||||
|         NONE = 0, READ = 1, MODIFY = 2, CREATE = 3, DELETE = 4 | ||||
|     }; | ||||
| 	enum ACLACCESS { NONE = 0, READ = 1, MODIFY = 2, CREATE = 3, DELETE = 4 }; | ||||
|  | ||||
| 	struct ObjectACL { | ||||
| 		UuidList users; | ||||
| @@ -571,7 +528,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		uint64_t access = (uint64_t)NONE; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -579,7 +535,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::vector<ObjectACL> list; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -594,7 +549,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string venue; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -602,7 +556,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::vector<Map> list; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -632,7 +585,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string operatorId; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -643,7 +595,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string value; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -651,7 +602,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::vector<Variable> variables; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -666,7 +616,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUID_t managementPolicy; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -674,7 +623,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::vector<VariableBlock> variableBlocks; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -689,7 +637,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string registrationId; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -697,7 +644,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::vector<Operator> operators; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -708,7 +654,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		Types::UUIDvec_t devices; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -724,7 +669,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		bool defaultService = false; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -732,7 +676,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::vector<ServiceClass> serviceClasses; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -743,7 +686,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string firmwareRCOnly{"inherit"}; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -768,7 +710,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::string realMacAddress; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -776,7 +717,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::vector<SubscriberDevice> subscriberDevices; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -789,7 +729,6 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::uint64_t modified; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| @@ -799,119 +738,12 @@ namespace OpenWifi::ProvObjects { | ||||
| 		std::vector<ConfigurationOverride> overrides; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	bool UpdateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, | ||||
| 						  ObjectInfo &I); | ||||
|  | ||||
| 	bool CreateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, | ||||
| 						  ObjectInfo &I); | ||||
|  | ||||
| 	bool CreateObjectInfo(const SecurityObjects::UserInfo &U, ObjectInfo &I); | ||||
|  | ||||
|     struct GLBLRAccountInfo { | ||||
|         ObjectInfo info; | ||||
|         std::string privateKey; | ||||
|         std::string country, province, city, organization, commonName; | ||||
|         std::string CSR, CSRPrivateKey, CSRPublicKey; | ||||
|         std::string GlobalReachAcctId; | ||||
|  | ||||
|         void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
|         bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
|     }; | ||||
|  | ||||
|     struct GLBLRCertificateInfo { | ||||
|         std::string id; | ||||
|         std::string name; | ||||
|         std::string accountId; | ||||
|         std::string csr; | ||||
|         std::string certificate; | ||||
|         std::string certificateChain; | ||||
|         std::string certificateId; | ||||
|         std::uint64_t expiresAt = 0; | ||||
|         std::uint64_t created = 0; | ||||
|  | ||||
|         void to_json(Poco::JSON::Object &Obj) const; | ||||
|  | ||||
|         bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
|     }; | ||||
|  | ||||
|     struct GooglOrionAccountInfo { | ||||
|         ObjectInfo info; | ||||
|         std::string privateKey; | ||||
|         std::string certificate; | ||||
|         std::vector<std::string> cacerts; | ||||
|  | ||||
|         void to_json(Poco::JSON::Object &Obj) const; | ||||
|         bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
|     }; | ||||
|  | ||||
|     struct RADIUSServer { | ||||
|         std::string     Hostname; | ||||
|         std::string     IP; | ||||
|         std::uint64_t   Port=0; | ||||
|         std::string     Secret; | ||||
|  | ||||
|         void to_json(Poco::JSON::Object &Obj) const; | ||||
|         bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
|     }; | ||||
|  | ||||
|     struct RADIUSEndPointRadiusType { | ||||
|         std::vector<RADIUSServer>    Authentication; | ||||
|         std::vector<RADIUSServer>    Accounting; | ||||
|         std::vector<RADIUSServer>    CoA; | ||||
|         std::uint64_t AccountingInterval = 60; | ||||
|  | ||||
|         void to_json(Poco::JSON::Object &Obj) const; | ||||
|         bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
|     }; | ||||
|  | ||||
|     struct RADIUSEndPointRadsecType { | ||||
|         std::string     Hostname; | ||||
|         std::string     IP; | ||||
|         std::uint64_t   Port=2083; | ||||
|         std::string     Secret{"radsec"}; | ||||
|         std::string     OpenRoamingType; | ||||
|         std::string     UseOpenRoamingAccount; | ||||
|         std::uint64_t   Weight=0; | ||||
|         std::string     Certificate; | ||||
|         std::string     PrivateKey; | ||||
|         std::vector<std::string>    CaCerts; | ||||
|         bool AllowSelfSigned=false; | ||||
|  | ||||
|         void to_json(Poco::JSON::Object &Obj) const; | ||||
|         bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
|     }; | ||||
|  | ||||
|     struct RADIUSEndPoint { | ||||
|         ObjectInfo                  info; | ||||
|         std::string                 Type{"radius"}; | ||||
|         std::string                 PoolStrategy{"none"}; | ||||
|         bool                        UseGWProxy=true; | ||||
|         std::string                 Index; | ||||
|         std::vector<std::string>    UsedBy; | ||||
|         std::vector<RADIUSEndPointRadiusType>   RadiusServers; | ||||
|         std::vector<RADIUSEndPointRadsecType>   RadsecServers; | ||||
|         std::string                 NasIdentifier; | ||||
|         std::uint64_t               AccountingInterval=600; | ||||
|  | ||||
|         void to_json(Poco::JSON::Object &Obj) const; | ||||
|         bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
|     }; | ||||
|  | ||||
|     struct RADIUSEndpointUpdateStatus { | ||||
|         std::uint64_t   lastUpdate=0; | ||||
|         std::uint64_t   lastConfigurationChange=0; | ||||
|  | ||||
|         void to_json(Poco::JSON::Object &Obj) const; | ||||
|         bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
|         bool Read(); | ||||
|         bool Save(); | ||||
|         bool ChangeConfiguration(); | ||||
|     }; | ||||
|  | ||||
|  | ||||
| }; // namespace OpenWifi::ProvObjects | ||||
|   | ||||
| @@ -26,7 +26,7 @@ namespace OpenWifi { | ||||
| 			Response.set("Connection", "keep-alive"); | ||||
| 			Response.setVersion(Poco::Net::HTTPMessage::HTTP_1_1); | ||||
| 			std::ostream &Answer = Response.send(); | ||||
| 			Answer << ALBHealthCheckServer()->CallbackText(); | ||||
| 			Answer << "process Alive and kicking!"; | ||||
| 		} catch (...) { | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -37,8 +37,6 @@ namespace OpenWifi { | ||||
| 		inline static std::atomic_uint64_t req_id_ = 1; | ||||
| 	}; | ||||
|  | ||||
| 	typedef std::string ALBHealthMessageCallback(); | ||||
|  | ||||
| 	class ALBHealthCheckServer : public SubSystemServer { | ||||
| 	  public: | ||||
| 		ALBHealthCheckServer(); | ||||
| @@ -50,22 +48,10 @@ namespace OpenWifi { | ||||
|  | ||||
| 		int Start() override; | ||||
| 		void Stop() override; | ||||
| 		inline void RegisterExtendedHealthMessage(ALBHealthMessageCallback *F) { | ||||
| 			Callback_=F; | ||||
| 		}; | ||||
|  | ||||
| 		inline std::string CallbackText() { | ||||
| 			if(Callback_== nullptr) { | ||||
| 				return "process Alive and kicking!"; | ||||
| 			} else { | ||||
| 				return Callback_(); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 	  private: | ||||
| 		std::unique_ptr<Poco::Net::HTTPServer> Server_; | ||||
| 		std::unique_ptr<Poco::Net::ServerSocket> Socket_; | ||||
| 		ALBHealthMessageCallback	*Callback_= nullptr; | ||||
| 		int Port_ = 0; | ||||
| 		mutable std::atomic_bool Running_ = false; | ||||
| 	}; | ||||
|   | ||||
| @@ -11,12 +11,10 @@ | ||||
|  | ||||
| #include "Poco/File.h" | ||||
| #include "Poco/StreamCopier.h" | ||||
| #include "Poco/JSON/Object.h" | ||||
| #include "Poco/JSON/Parser.h" | ||||
|  | ||||
| #include "framework/MicroServiceFuncs.h" | ||||
|  | ||||
| // #include "nlohmann/json.hpp" | ||||
| #include "nlohmann/json.hpp" | ||||
|  | ||||
| namespace OpenWifi { | ||||
|  | ||||
| @@ -30,11 +28,11 @@ namespace OpenWifi { | ||||
| 				if (F.exists()) { | ||||
| 					std::ostringstream OS; | ||||
| 					std::ifstream IF(FileName); | ||||
|                     Poco::JSON::Parser  P; | ||||
| 					Registry_ = P.parse(IF).extract<Poco::JSON::Object::Ptr>(); | ||||
| 					Poco::StreamCopier::copyStream(IF, OS); | ||||
| 					Registry_ = nlohmann::json::parse(OS.str()); | ||||
| 				} | ||||
| 			} catch (...) { | ||||
| 				Registry_ = Poco::makeShared<Poco::JSON::Object>(); | ||||
| 				Registry_ = nlohmann::json::parse("{}"); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| @@ -46,39 +44,46 @@ namespace OpenWifi { | ||||
| 		inline ~AppServiceRegistry() { Save(); } | ||||
|  | ||||
| 		inline void Save() { | ||||
| 			std::istringstream IS(to_string(Registry_)); | ||||
| 			std::ofstream OF; | ||||
| 			OF.open(FileName, std::ios::binary | std::ios::trunc); | ||||
|             Registry_->stringify(OF); | ||||
| 			Poco::StreamCopier::copyStream(IS, OF); | ||||
| 		} | ||||
|  | ||||
|         void Set(const char *key, const std::vector<std::string> &V) { | ||||
|             Poco::JSON::Array   Arr; | ||||
|             for(const auto &s:V) { | ||||
|                 Arr.add(s); | ||||
|             } | ||||
|             Registry_->set(key,Arr); | ||||
| 		inline void Set(const char *Key, uint64_t Value) { | ||||
| 			Registry_[Key] = Value; | ||||
| 			Save(); | ||||
| 		} | ||||
|  | ||||
|         template<class T> void Set(const char *key, const T &Value) { | ||||
|             Registry_->set(key,Value); | ||||
| 		inline void Set(const char *Key, const std::string &Value) { | ||||
| 			Registry_[Key] = Value; | ||||
| 			Save(); | ||||
| 		} | ||||
|  | ||||
|         bool Get(const char *key, std::vector<std::string> &Value) { | ||||
|             if(Registry_->has(key) && !Registry_->isNull(key) && Registry_->isArray(key)) { | ||||
|                 auto Arr = Registry_->get(key); | ||||
|                 for(const auto &v:Arr) { | ||||
|                     Value.emplace_back(v); | ||||
| 		inline void Set(const char *Key, bool Value) { | ||||
| 			Registry_[Key] = Value; | ||||
| 			Save(); | ||||
| 		} | ||||
|  | ||||
| 		inline bool Get(const char *Key, bool &Value) { | ||||
| 			if (Registry_[Key].is_boolean()) { | ||||
| 				Value = Registry_[Key].get<bool>(); | ||||
| 				return true; | ||||
| 			} | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
|         template<class T> bool Get(const char *key, T &Value) { | ||||
|             if(Registry_->has(key) && !Registry_->isNull(key)) { | ||||
|                 Value = Registry_->getValue<T>(key); | ||||
| 		inline bool Get(const char *Key, uint64_t &Value) { | ||||
| 			if (Registry_[Key].is_number_unsigned()) { | ||||
| 				Value = Registry_[Key].get<uint64_t>(); | ||||
| 				return true; | ||||
| 			} | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		inline bool Get(const char *Key, std::string &Value) { | ||||
| 			if (Registry_[Key].is_string()) { | ||||
| 				Value = Registry_[Key].get<std::string>(); | ||||
| 				return true; | ||||
| 			} | ||||
| 			return false; | ||||
| @@ -86,7 +91,7 @@ namespace OpenWifi { | ||||
|  | ||||
| 	  private: | ||||
| 		std::string FileName; | ||||
| 		Poco::JSON::Object::Ptr Registry_; | ||||
| 		nlohmann::json Registry_; | ||||
| 	}; | ||||
|  | ||||
| 	inline auto AppServiceRegistry() { return AppServiceRegistry::instance(); } | ||||
|   | ||||
| @@ -34,17 +34,9 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|     "$schema": "http://json-schema.org/draft-07/schema#", | ||||
|     "type": "object", | ||||
|     "properties": { | ||||
|         "strict": { | ||||
|             "type": "boolean", | ||||
|             "default": false | ||||
|         }, | ||||
|         "uuid": { | ||||
|             "type": "integer" | ||||
|         }, | ||||
|         "public_ip_lookup": { | ||||
|             "type": "string", | ||||
|             "format": "uc-fqdn" | ||||
|         }, | ||||
|         "unit": { | ||||
|             "$ref": "#/$defs/unit" | ||||
|         }, | ||||
| @@ -118,20 +110,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                 "random-password": { | ||||
|                     "type": "boolean", | ||||
|                     "default": false | ||||
|                 }, | ||||
|                 "beacon-advertisement": { | ||||
|                     "type": "object", | ||||
|                     "properties": { | ||||
|                         "device-name": { | ||||
|                             "type": "boolean" | ||||
|                         }, | ||||
|                         "device-serial": { | ||||
|                             "type": "boolean" | ||||
|                         }, | ||||
|                         "network-id": { | ||||
|                             "type": "integer" | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
| @@ -240,52 +218,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "interface.ssid.encryption": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
|                 "proto": { | ||||
|                     "type": "string", | ||||
|                     "enum": [ | ||||
|                         "none", | ||||
|                         "owe", | ||||
|                         "owe-transition", | ||||
|                         "psk", | ||||
|                         "psk2", | ||||
|                         "psk-mixed", | ||||
|                         "psk2-radius", | ||||
|                         "wpa", | ||||
|                         "wpa2", | ||||
|                         "wpa-mixed", | ||||
|                         "sae", | ||||
|                         "sae-mixed", | ||||
|                         "wpa3", | ||||
|                         "wpa3-192", | ||||
|                         "wpa3-mixed" | ||||
|                     ], | ||||
|                     "examples": [ | ||||
|                         "psk2" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "key": { | ||||
|                     "type": "string", | ||||
|                     "maxLength": 63, | ||||
|                     "minLength": 8 | ||||
|                 }, | ||||
|                 "ieee80211w": { | ||||
|                     "type": "string", | ||||
|                     "enum": [ | ||||
|                         "disabled", | ||||
|                         "optional", | ||||
|                         "required" | ||||
|                     ], | ||||
|                     "default": "disabled" | ||||
|                 }, | ||||
|                 "key-caching": { | ||||
|                     "type": "boolean", | ||||
|                     "default": true | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "definitions": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
| @@ -702,6 +634,26 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                     "type": "string", | ||||
|                     "format": "uc-timeout", | ||||
|                     "default": "6h" | ||||
|                 }, | ||||
|                 "relay-server": { | ||||
|                     "type": "string", | ||||
|                     "format": "ipv4", | ||||
|                     "example": "192.168.2.1" | ||||
|                 }, | ||||
|                 "circuit-id-format": { | ||||
|                     "type": "string", | ||||
|                     "example": [ | ||||
|                         "\\{Interface\\}:\\{VLAN-Id\\}:\\{SSID\\}:\\{Model\\}:\\{Name\\}:\\{AP-MAC\\}:\\{Location\\}", | ||||
|                         "\\{AP-MAC\\};\\{SSID\\};\\{Crypto\\}", | ||||
|                         "\\{Name\\} \\{ESSID\\}" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "remote-id-format": { | ||||
|                     "type": "string", | ||||
|                     "example": [ | ||||
|                         "\\{Client-MAC-hex\\} \\{SSID\\}", | ||||
|                         "\\{AP-MAC-hex\\} \\{SSID\\}" | ||||
|                     ] | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
| @@ -780,8 +732,7 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                     "type": "string", | ||||
|                     "enum": [ | ||||
|                         "dynamic", | ||||
|                         "static", | ||||
|                         "none" | ||||
|                         "static" | ||||
|                     ], | ||||
|                     "examples": [ | ||||
|                         "static" | ||||
| @@ -1071,6 +1022,52 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                 } | ||||
|             ] | ||||
|         }, | ||||
|         "interface.ssid.encryption": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
|                 "proto": { | ||||
|                     "type": "string", | ||||
|                     "enum": [ | ||||
|                         "none", | ||||
|                         "owe", | ||||
|                         "owe-transition", | ||||
|                         "psk", | ||||
|                         "psk2", | ||||
|                         "psk-mixed", | ||||
|                         "psk2-radius", | ||||
|                         "wpa", | ||||
|                         "wpa2", | ||||
|                         "wpa-mixed", | ||||
|                         "sae", | ||||
|                         "sae-mixed", | ||||
|                         "wpa3", | ||||
|                         "wpa3-192", | ||||
|                         "wpa3-mixed" | ||||
|                     ], | ||||
|                     "examples": [ | ||||
|                         "psk2" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "key": { | ||||
|                     "type": "string", | ||||
|                     "maxLength": 63, | ||||
|                     "minLength": 8 | ||||
|                 }, | ||||
|                 "ieee80211w": { | ||||
|                     "type": "string", | ||||
|                     "enum": [ | ||||
|                         "disabled", | ||||
|                         "optional", | ||||
|                         "required" | ||||
|                     ], | ||||
|                     "default": "disabled" | ||||
|                 }, | ||||
|                 "key-caching": { | ||||
|                     "type": "boolean", | ||||
|                     "default": true | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "interface.ssid.multi-psk": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
| @@ -1235,32 +1232,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                         "secret" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "secondary": { | ||||
|                     "type": "object", | ||||
|                     "properties": { | ||||
|                         "host": { | ||||
|                             "type": "string", | ||||
|                             "format": "uc-host", | ||||
|                             "examples": [ | ||||
|                                 "192.168.1.10" | ||||
|                             ] | ||||
|                         }, | ||||
|                         "port": { | ||||
|                             "type": "integer", | ||||
|                             "maximum": 65535, | ||||
|                             "minimum": 1024, | ||||
|                             "examples": [ | ||||
|                                 1812 | ||||
|                             ] | ||||
|                         }, | ||||
|                         "secret": { | ||||
|                             "type": "string", | ||||
|                             "examples": [ | ||||
|                                 "secret" | ||||
|                             ] | ||||
|                         } | ||||
|                     } | ||||
|                 }, | ||||
|                 "request-attribute": { | ||||
|                     "type": "array", | ||||
|                     "items": { | ||||
| @@ -1338,25 +1309,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                                         "value": "Example Operator" | ||||
|                                     } | ||||
|                                 ] | ||||
|                             }, | ||||
|                             { | ||||
|                                 "type": "object", | ||||
|                                 "properties": { | ||||
|                                     "id": { | ||||
|                                         "type": "integer", | ||||
|                                         "maximum": 255, | ||||
|                                         "minimum": 1 | ||||
|                                     }, | ||||
|                                     "hex-value": { | ||||
|                                         "type": "string" | ||||
|                                     } | ||||
|                                 }, | ||||
|                                 "examples": [ | ||||
|                                     { | ||||
|                                         "id": 32, | ||||
|                                         "value": "0a0b0c0d" | ||||
|                                     } | ||||
|                                 ] | ||||
|                             } | ||||
|                         ] | ||||
|                     } | ||||
| @@ -1706,236 +1658,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "service.captive.click": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
|                 "auth-mode": { | ||||
|                     "type": "string", | ||||
|                     "const": "click-to-continue" | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "service.captive.radius": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
|                 "auth-mode": { | ||||
|                     "type": "string", | ||||
|                     "const": "radius" | ||||
|                 }, | ||||
|                 "auth-server": { | ||||
|                     "type": "string", | ||||
|                     "format": "uc-host", | ||||
|                     "examples": [ | ||||
|                         "192.168.1.10" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "auth-port": { | ||||
|                     "type": "integer", | ||||
|                     "maximum": 65535, | ||||
|                     "minimum": 1024, | ||||
|                     "default": 1812 | ||||
|                 }, | ||||
|                 "auth-secret": { | ||||
|                     "type": "string", | ||||
|                     "examples": [ | ||||
|                         "secret" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "acct-server": { | ||||
|                     "type": "string", | ||||
|                     "format": "uc-host", | ||||
|                     "examples": [ | ||||
|                         "192.168.1.10" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "acct-port": { | ||||
|                     "type": "integer", | ||||
|                     "maximum": 65535, | ||||
|                     "minimum": 1024, | ||||
|                     "default": 1812 | ||||
|                 }, | ||||
|                 "acct-secret": { | ||||
|                     "type": "string", | ||||
|                     "examples": [ | ||||
|                         "secret" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "acct-interval": { | ||||
|                     "type": "integer", | ||||
|                     "default": 600 | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "service.captive.credentials": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
|                 "auth-mode": { | ||||
|                     "type": "string", | ||||
|                     "const": "credentials" | ||||
|                 }, | ||||
|                 "credentials": { | ||||
|                     "type": "array", | ||||
|                     "items": { | ||||
|                         "type": "object", | ||||
|                         "properties": { | ||||
|                             "username": { | ||||
|                                 "type": "string" | ||||
|                             }, | ||||
|                             "password": { | ||||
|                                 "type": "string" | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "service.captive.uam": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
|                 "auth-mode": { | ||||
|                     "type": "string", | ||||
|                     "const": "uam" | ||||
|                 }, | ||||
|                 "uam-port": { | ||||
|                     "type": "integer", | ||||
|                     "maximum": 65535, | ||||
|                     "minimum": 1024, | ||||
|                     "default": 3990 | ||||
|                 }, | ||||
|                 "uam-secret": { | ||||
|                     "type": "string" | ||||
|                 }, | ||||
|                 "uam-server": { | ||||
|                     "type": "string" | ||||
|                 }, | ||||
|                 "nasid": { | ||||
|                     "type": "string" | ||||
|                 }, | ||||
|                 "nasmac": { | ||||
|                     "type": "string" | ||||
|                 }, | ||||
|                 "auth-server": { | ||||
|                     "type": "string", | ||||
|                     "format": "uc-host", | ||||
|                     "examples": [ | ||||
|                         "192.168.1.10" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "auth-port": { | ||||
|                     "type": "integer", | ||||
|                     "maximum": 65535, | ||||
|                     "minimum": 1024, | ||||
|                     "default": 1812 | ||||
|                 }, | ||||
|                 "auth-secret": { | ||||
|                     "type": "string", | ||||
|                     "examples": [ | ||||
|                         "secret" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "acct-server": { | ||||
|                     "type": "string", | ||||
|                     "format": "uc-host", | ||||
|                     "examples": [ | ||||
|                         "192.168.1.10" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "acct-port": { | ||||
|                     "type": "integer", | ||||
|                     "maximum": 65535, | ||||
|                     "minimum": 1024, | ||||
|                     "default": 1812 | ||||
|                 }, | ||||
|                 "acct-secret": { | ||||
|                     "type": "string", | ||||
|                     "examples": [ | ||||
|                         "secret" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "acct-interval": { | ||||
|                     "type": "integer", | ||||
|                     "default": 600 | ||||
|                 }, | ||||
|                 "ssid": { | ||||
|                     "type": "string" | ||||
|                 }, | ||||
|                 "mac-format": { | ||||
|                     "type": "string", | ||||
|                     "enum": [ | ||||
|                         "aabbccddeeff", | ||||
|                         "aa-bb-cc-dd-ee-ff", | ||||
|                         "aa:bb:cc:dd:ee:ff", | ||||
|                         "AABBCCDDEEFF", | ||||
|                         "AA:BB:CC:DD:EE:FF", | ||||
|                         "AA-BB-CC-DD-EE-FF" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "final-redirect-url": { | ||||
|                     "type": "string", | ||||
|                     "enum": [ | ||||
|                         "default", | ||||
|                         "uam" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "mac-auth": { | ||||
|                     "type": "boolean", | ||||
|                     "default": "default" | ||||
|                 }, | ||||
|                 "radius-gw-proxy": { | ||||
|                     "type": "boolean", | ||||
|                     "default": false | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "service.captive": { | ||||
|             "allOf": [ | ||||
|                 { | ||||
|                     "oneOf": [ | ||||
|                         { | ||||
|                             "$ref": "#/$defs/service.captive.click" | ||||
|                         }, | ||||
|                         { | ||||
|                             "$ref": "#/$defs/service.captive.radius" | ||||
|                         }, | ||||
|                         { | ||||
|                             "$ref": "#/$defs/service.captive.credentials" | ||||
|                         }, | ||||
|                         { | ||||
|                             "$ref": "#/$defs/service.captive.uam" | ||||
|                         } | ||||
|                     ] | ||||
|                 }, | ||||
|                 { | ||||
|                     "type": "object", | ||||
|                     "properties": { | ||||
|                         "walled-garden-fqdn": { | ||||
|                             "type": "array", | ||||
|                             "items": { | ||||
|                                 "type": "string" | ||||
|                             } | ||||
|                         }, | ||||
|                         "walled-garden-ipaddr": { | ||||
|                             "type": "array", | ||||
|                             "items": { | ||||
|                                 "type": "string", | ||||
|                                 "format": "uc-ip" | ||||
|                             } | ||||
|                         }, | ||||
|                         "web-root": { | ||||
|                             "type": "string", | ||||
|                             "format": "uc-base64" | ||||
|                         }, | ||||
|                         "idle-timeout": { | ||||
|                             "type": "integer", | ||||
|                             "default": 600 | ||||
|                         }, | ||||
|                         "session-timeout": { | ||||
|                             "type": "integer" | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             ] | ||||
|         }, | ||||
|         "interface.ssid": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
| @@ -1988,10 +1710,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                 "isolate-clients": { | ||||
|                     "type": "boolean" | ||||
|                 }, | ||||
|                 "strict-forwarding": { | ||||
|                     "type": "boolean", | ||||
|                     "default": false | ||||
|                 }, | ||||
|                 "power-save": { | ||||
|                     "type": "boolean" | ||||
|                 }, | ||||
| @@ -2039,11 +1757,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                     "decription": "This option allows embedding custom vendor specific IEs inside the beacons of a BSS in AP mode.", | ||||
|                     "type": "string" | ||||
|                 }, | ||||
|                 "tip-information-element": { | ||||
|                     "decription": "The device will broadcast the TIP vendor IE inside its beacons if this option is enabled.", | ||||
|                     "type": "boolean", | ||||
|                     "default": true | ||||
|                 }, | ||||
|                 "fils-discovery-interval": { | ||||
|                     "type": "integer", | ||||
|                     "default": 20, | ||||
| @@ -2065,15 +1778,8 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                     "$ref": "#/$defs/interface.ssid.rate-limit" | ||||
|                 }, | ||||
|                 "roaming": { | ||||
|                     "anyOf": [ | ||||
|                         { | ||||
|                     "$ref": "#/$defs/interface.ssid.roaming" | ||||
|                 }, | ||||
|                         { | ||||
|                             "type": "boolean" | ||||
|                         } | ||||
|                     ] | ||||
|                 }, | ||||
|                 "radius": { | ||||
|                     "$ref": "#/$defs/interface.ssid.radius" | ||||
|                 }, | ||||
| @@ -2089,9 +1795,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                 "access-control-list": { | ||||
|                     "$ref": "#/$defs/interface.ssid.acl" | ||||
|                 }, | ||||
|                 "captive": { | ||||
|                     "$ref": "#/$defs/service.captive" | ||||
|                 }, | ||||
|                 "hostapd-bss-raw": { | ||||
|                     "type": "array", | ||||
|                     "items": { | ||||
| @@ -2259,17 +1962,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                         ] | ||||
|                     } | ||||
|                 }, | ||||
|                 "vlan-awareness": { | ||||
|                     "type": "object", | ||||
|                     "properties": { | ||||
|                         "first": { | ||||
|                             "type": "integer" | ||||
|                         }, | ||||
|                         "last": { | ||||
|                             "type": "integer" | ||||
|                         } | ||||
|                     } | ||||
|                 }, | ||||
|                 "vlan": { | ||||
|                     "$ref": "#/$defs/interface.vlan" | ||||
|                 }, | ||||
| @@ -2392,10 +2084,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                     "examples": [ | ||||
|                         "01234567890123456789012345678901" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "mutual-tls": { | ||||
|                     "type": "boolean", | ||||
|                     "default": true | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
| @@ -2467,24 +2155,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                     "type": "boolean", | ||||
|                     "default": false | ||||
|                 }, | ||||
|                 "mode": { | ||||
|                     "type": "string", | ||||
|                     "enum": [ | ||||
|                         "radius", | ||||
|                         "user" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "port-filter": { | ||||
|                     "type": "array", | ||||
|                     "items": { | ||||
|                         "type": "string", | ||||
|                         "examples": [ | ||||
|                             { | ||||
|                                 "LAN1": null | ||||
|                             } | ||||
|                         ] | ||||
|                     } | ||||
|                 }, | ||||
|                 "server-certificate": { | ||||
|                     "type": "string" | ||||
|                 }, | ||||
| @@ -2496,77 +2166,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                     "items": { | ||||
|                         "$ref": "#/$defs/interface.ssid.radius.local-user" | ||||
|                     } | ||||
|                 }, | ||||
|                 "radius": { | ||||
|                     "type": "object", | ||||
|                     "properties": { | ||||
|                         "nas-identifier": { | ||||
|                             "type": "string" | ||||
|                         }, | ||||
|                         "auth-server-addr": { | ||||
|                             "type": "string", | ||||
|                             "format": "uc-host", | ||||
|                             "examples": [ | ||||
|                                 "192.168.1.10" | ||||
|                             ] | ||||
|                         }, | ||||
|                         "auth-server-port": { | ||||
|                             "type": "integer", | ||||
|                             "maximum": 65535, | ||||
|                             "minimum": 1024, | ||||
|                             "examples": [ | ||||
|                                 1812 | ||||
|                             ] | ||||
|                         }, | ||||
|                         "auth-server-secret": { | ||||
|                             "type": "string", | ||||
|                             "examples": [ | ||||
|                                 "secret" | ||||
|                             ] | ||||
|                         }, | ||||
|                         "acct-server-addr": { | ||||
|                             "type": "string", | ||||
|                             "format": "uc-host", | ||||
|                             "examples": [ | ||||
|                                 "192.168.1.10" | ||||
|                             ] | ||||
|                         }, | ||||
|                         "acct-server-port": { | ||||
|                             "type": "integer", | ||||
|                             "maximum": 65535, | ||||
|                             "minimum": 1024, | ||||
|                             "examples": [ | ||||
|                                 1813 | ||||
|                             ] | ||||
|                         }, | ||||
|                         "acct-server-secret": { | ||||
|                             "type": "string", | ||||
|                             "examples": [ | ||||
|                                 "secret" | ||||
|                             ] | ||||
|                         }, | ||||
|                         "coa-server-addr": { | ||||
|                             "type": "string", | ||||
|                             "format": "uc-host", | ||||
|                             "examples": [ | ||||
|                                 "192.168.1.10" | ||||
|                             ] | ||||
|                         }, | ||||
|                         "coa-server-port": { | ||||
|                             "type": "integer", | ||||
|                             "maximum": 65535, | ||||
|                             "minimum": 1024, | ||||
|                             "examples": [ | ||||
|                                 1814 | ||||
|                             ] | ||||
|                         }, | ||||
|                         "coa-server-secret": { | ||||
|                             "type": "string", | ||||
|                             "examples": [ | ||||
|                                 "secret" | ||||
|                             ] | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
| @@ -2890,12 +2489,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                         } | ||||
|                     } | ||||
|                 }, | ||||
|                 "services": { | ||||
|                     "type": "array", | ||||
|                     "items": { | ||||
|                         "type": "string" | ||||
|                     } | ||||
|                 }, | ||||
|                 "classifier": { | ||||
|                     "type": "array", | ||||
|                     "items": { | ||||
| @@ -3100,6 +2693,236 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "service.captive.click": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
|                 "auth-mode": { | ||||
|                     "type": "string", | ||||
|                     "const": "click-to-continue" | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "service.captive.radius": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
|                 "auth-mode": { | ||||
|                     "type": "string", | ||||
|                     "const": "radius" | ||||
|                 }, | ||||
|                 "auth-server": { | ||||
|                     "type": "string", | ||||
|                     "format": "uc-host", | ||||
|                     "examples": [ | ||||
|                         "192.168.1.10" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "auth-port": { | ||||
|                     "type": "integer", | ||||
|                     "maximum": 65535, | ||||
|                     "minimum": 1024, | ||||
|                     "default": 1812 | ||||
|                 }, | ||||
|                 "auth-secret": { | ||||
|                     "type": "string", | ||||
|                     "examples": [ | ||||
|                         "secret" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "acct-server": { | ||||
|                     "type": "string", | ||||
|                     "format": "uc-host", | ||||
|                     "examples": [ | ||||
|                         "192.168.1.10" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "acct-port": { | ||||
|                     "type": "integer", | ||||
|                     "maximum": 65535, | ||||
|                     "minimum": 1024, | ||||
|                     "default": 1812 | ||||
|                 }, | ||||
|                 "acct-secret": { | ||||
|                     "type": "string", | ||||
|                     "examples": [ | ||||
|                         "secret" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "acct-interval": { | ||||
|                     "type": "integer", | ||||
|                     "default": 600 | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "service.captive.credentials": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
|                 "auth-mode": { | ||||
|                     "type": "string", | ||||
|                     "const": "credentials" | ||||
|                 }, | ||||
|                 "credentials": { | ||||
|                     "type": "array", | ||||
|                     "items": { | ||||
|                         "type": "object", | ||||
|                         "properties": { | ||||
|                             "username": { | ||||
|                                 "type": "string" | ||||
|                             }, | ||||
|                             "password": { | ||||
|                                 "type": "string" | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "service.captive.uam": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
|                 "auth-mode": { | ||||
|                     "type": "string", | ||||
|                     "const": "uam" | ||||
|                 }, | ||||
|                 "uam-port": { | ||||
|                     "type": "integer", | ||||
|                     "maximum": 65535, | ||||
|                     "minimum": 1024, | ||||
|                     "default": 3990 | ||||
|                 }, | ||||
|                 "uam-secret": { | ||||
|                     "type": "string" | ||||
|                 }, | ||||
|                 "uam-server": { | ||||
|                     "type": "string" | ||||
|                 }, | ||||
|                 "nasid": { | ||||
|                     "type": "string" | ||||
|                 }, | ||||
|                 "nasmac": { | ||||
|                     "type": "string" | ||||
|                 }, | ||||
|                 "auth-server": { | ||||
|                     "type": "string", | ||||
|                     "format": "uc-host", | ||||
|                     "examples": [ | ||||
|                         "192.168.1.10" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "auth-port": { | ||||
|                     "type": "integer", | ||||
|                     "maximum": 65535, | ||||
|                     "minimum": 1024, | ||||
|                     "default": 1812 | ||||
|                 }, | ||||
|                 "auth-secret": { | ||||
|                     "type": "string", | ||||
|                     "examples": [ | ||||
|                         "secret" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "acct-server": { | ||||
|                     "type": "string", | ||||
|                     "format": "uc-host", | ||||
|                     "examples": [ | ||||
|                         "192.168.1.10" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "acct-port": { | ||||
|                     "type": "integer", | ||||
|                     "maximum": 65535, | ||||
|                     "minimum": 1024, | ||||
|                     "default": 1812 | ||||
|                 }, | ||||
|                 "acct-secret": { | ||||
|                     "type": "string", | ||||
|                     "examples": [ | ||||
|                         "secret" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "acct-interval": { | ||||
|                     "type": "integer", | ||||
|                     "default": 600 | ||||
|                 }, | ||||
|                 "ssid": { | ||||
|                     "type": "string" | ||||
|                 }, | ||||
|                 "mac-format": { | ||||
|                     "type": "string", | ||||
|                     "enum": [ | ||||
|                         "aabbccddeeff", | ||||
|                         "aa-bb-cc-dd-ee-ff", | ||||
|                         "aa:bb:cc:dd:ee:ff", | ||||
|                         "AABBCCDDEEFF", | ||||
|                         "AA:BB:CC:DD:EE:FF", | ||||
|                         "AA-BB-CC-DD-EE-FF" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "final-redirect-url": { | ||||
|                     "type": "string", | ||||
|                     "enum": [ | ||||
|                         "default", | ||||
|                         "uam" | ||||
|                     ] | ||||
|                 }, | ||||
|                 "mac-auth": { | ||||
|                     "type": "boolean", | ||||
|                     "default": "default" | ||||
|                 }, | ||||
|                 "radius-gw-proxy": { | ||||
|                     "type": "boolean", | ||||
|                     "default": false | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "service.captive": { | ||||
|             "allOf": [ | ||||
|                 { | ||||
|                     "oneOf": [ | ||||
|                         { | ||||
|                             "$ref": "#/$defs/service.captive.click" | ||||
|                         }, | ||||
|                         { | ||||
|                             "$ref": "#/$defs/service.captive.radius" | ||||
|                         }, | ||||
|                         { | ||||
|                             "$ref": "#/$defs/service.captive.credentials" | ||||
|                         }, | ||||
|                         { | ||||
|                             "$ref": "#/$defs/service.captive.uam" | ||||
|                         } | ||||
|                     ] | ||||
|                 }, | ||||
|                 { | ||||
|                     "type": "object", | ||||
|                     "properties": { | ||||
|                         "walled-garden-fqdn": { | ||||
|                             "type": "array", | ||||
|                             "items": { | ||||
|                                 "type": "string" | ||||
|                             } | ||||
|                         }, | ||||
|                         "walled-garden-ipaddr": { | ||||
|                             "type": "array", | ||||
|                             "items": { | ||||
|                                 "type": "string", | ||||
|                                 "format": "uc-ip" | ||||
|                             } | ||||
|                         }, | ||||
|                         "web-root": { | ||||
|                             "type": "string", | ||||
|                             "format": "uc-base64" | ||||
|                         }, | ||||
|                         "idle-timeout": { | ||||
|                             "type": "integer", | ||||
|                             "default": 600 | ||||
|                         }, | ||||
|                         "session-timeout": { | ||||
|                             "type": "integer" | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             ] | ||||
|         }, | ||||
|         "service.gps": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
| @@ -3118,50 +2941,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "service.dhcp-relay": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
|                 "select-ports": { | ||||
|                     "type": "array", | ||||
|                     "items": { | ||||
|                         "type": "string" | ||||
|                     } | ||||
|                 }, | ||||
|                 "vlans": { | ||||
|                     "type": "array", | ||||
|                     "items": { | ||||
|                         "type": "object", | ||||
|                         "properties": { | ||||
|                             "vlan": { | ||||
|                                 "type": "number" | ||||
|                             }, | ||||
|                             "relay-server": { | ||||
|                                 "type": "string", | ||||
|                                 "format": "uc-ip" | ||||
|                             }, | ||||
|                             "circuit-id-format": { | ||||
|                                 "type": "string", | ||||
|                                 "enum": [ | ||||
|                                     "vlan-id", | ||||
|                                     "ap-mac", | ||||
|                                     "ssid" | ||||
|                                 ], | ||||
|                                 "default": "vlan-id" | ||||
|                             }, | ||||
|                             "remote-id-format": { | ||||
|                                 "type": "string", | ||||
|                                 "enum": [ | ||||
|                                     "vlan-id", | ||||
|                                     "ap-mac", | ||||
|                                     "ssid" | ||||
|                                 ], | ||||
|                                 "default": "ap-mac" | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "service": { | ||||
|             "type": "object", | ||||
|             "properties": { | ||||
| @@ -3221,9 +3000,6 @@ static std::string DefaultUCentralSchema = R"foo( | ||||
|                 }, | ||||
|                 "gps": { | ||||
|                     "$ref": "#/$defs/service.gps" | ||||
|                 }, | ||||
|                 "dhcp-relay": { | ||||
|                     "$ref": "#/$defs/service.dhcp-relay" | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|   | ||||
| @@ -9,21 +9,23 @@ | ||||
|  | ||||
| namespace OpenWifi { | ||||
|  | ||||
| 	EventBusManager::EventBusManager(Poco::Logger &L) : Logger_(L) {} | ||||
|  | ||||
| 	void EventBusManager::run() { | ||||
| 		Running_ = true; | ||||
| 		Utils::SetThreadName("fmwk:EventMgr"); | ||||
| 		auto Msg = (MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN)); | ||||
| 		auto Msg = std::make_shared<std::string>(MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN)); | ||||
| 		KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg, | ||||
| 									false); | ||||
| 		while (Running_) { | ||||
| 			Poco::Thread::trySleep((unsigned long)MicroServiceDaemonBusTimer()); | ||||
| 			if (!Running_) | ||||
| 				break; | ||||
| 			Msg = (MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE)); | ||||
| 			Msg = std::make_shared<std::string>(MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE)); | ||||
| 			KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), | ||||
| 										Msg, false); | ||||
| 		} | ||||
| 		Msg = (MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_LEAVE)); | ||||
| 		Msg = std::make_shared<std::string>(MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_LEAVE)); | ||||
| 		KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg, | ||||
| 									false); | ||||
| 	}; | ||||
|   | ||||
| @@ -12,16 +12,6 @@ namespace OpenWifi { | ||||
|  | ||||
| 	class EventBusManager : public Poco::Runnable { | ||||
| 	  public: | ||||
| 		EventBusManager() : | ||||
| 			Logger_(Poco::Logger::create( | ||||
| 				"EventBusManager", Poco::Logger::root().getChannel(), Poco::Logger::root().getLevel())) { | ||||
| 		} | ||||
|  | ||||
| 		static auto instance() { | ||||
| 			static auto instance_ = new EventBusManager; | ||||
| 			return instance_; | ||||
| 		} | ||||
|  | ||||
| 		explicit EventBusManager(Poco::Logger &L); | ||||
| 		void run() final; | ||||
| 		void Start(); | ||||
| @@ -34,6 +24,4 @@ namespace OpenWifi { | ||||
| 		Poco::Logger &Logger_; | ||||
| 	}; | ||||
|  | ||||
| 	inline auto EventBusManager() { return EventBusManager::instance(); } | ||||
|  | ||||
| } // namespace OpenWifi | ||||
|   | ||||
| @@ -6,7 +6,6 @@ | ||||
|  | ||||
| #include "fmt/format.h" | ||||
| #include "framework/MicroServiceFuncs.h" | ||||
| #include "cppkafka/utils/consumer_dispatcher.h" | ||||
|  | ||||
| namespace OpenWifi { | ||||
|  | ||||
| @@ -100,12 +99,9 @@ namespace OpenWifi { | ||||
| 			try { | ||||
| 				auto Msg = dynamic_cast<KafkaMessage *>(Note.get()); | ||||
| 				if (Msg != nullptr) { | ||||
| 					auto NewMessage = cppkafka::MessageBuilder(Msg->Topic()); | ||||
| 					NewMessage.key(Msg->Key()); | ||||
| 					NewMessage.partition(0); | ||||
| 					NewMessage.payload(Msg->Payload()); | ||||
| 					Producer.produce(NewMessage); | ||||
| 					Producer.flush(); | ||||
| 					Producer.produce(cppkafka::MessageBuilder(Msg->Topic()) | ||||
| 										 .key(Msg->Key()) | ||||
| 										 .payload(Msg->Payload())); | ||||
| 				} | ||||
| 			} catch (const cppkafka::HandleException &E) { | ||||
| 				poco_warning(Logger_, | ||||
| @@ -160,49 +156,43 @@ namespace OpenWifi { | ||||
| 			} | ||||
| 		}); | ||||
|  | ||||
| 		// bool AutoCommit = MicroServiceConfigGetBool("openwifi.kafka.auto.commit", false); | ||||
| 		// auto BatchSize = MicroServiceConfigGetInt("openwifi.kafka.consumer.batchsize", 100); | ||||
| 		bool AutoCommit = MicroServiceConfigGetBool("openwifi.kafka.auto.commit", false); | ||||
| 		auto BatchSize = MicroServiceConfigGetInt("openwifi.kafka.consumer.batchsize", 20); | ||||
|  | ||||
| 		Types::StringVec Topics; | ||||
| 		std::for_each(Topics_.begin(),Topics_.end(), | ||||
| 					  [&](const std::string & T) { Topics.emplace_back(T); }); | ||||
| 		KafkaManager()->Topics(Topics); | ||||
| 		Consumer.subscribe(Topics); | ||||
|  | ||||
| 		Running_ = true; | ||||
| 		std::vector<cppkafka::Message> MsgVec; | ||||
|  | ||||
| 		Dispatcher_ = std::make_unique<cppkafka::ConsumerDispatcher>(Consumer); | ||||
|  | ||||
| 		Dispatcher_->run( | ||||
| 			// Callback executed whenever a new message is consumed | ||||
| 			[&](cppkafka::Message msg) { | ||||
| 				// Print the key (if any) | ||||
| 				std::lock_guard G(ConsumerMutex_); | ||||
| 				auto It = Notifiers_.find(msg.get_topic()); | ||||
| 				if (It != Notifiers_.end()) { | ||||
| 					const auto &FL = It->second; | ||||
| 					for (const auto &[CallbackFunc, _] : FL) { | ||||
| 		while (Running_) { | ||||
| 			try { | ||||
| 							CallbackFunc(msg.get_key(), msg.get_payload()); | ||||
| 				std::vector<cppkafka::Message> MsgVec = | ||||
| 					Consumer.poll_batch(BatchSize, std::chrono::milliseconds(100)); | ||||
| 				for (auto const &Msg : MsgVec) { | ||||
| 					if (!Msg) | ||||
| 						continue; | ||||
| 					if (Msg.get_error()) { | ||||
| 						if (!Msg.is_eof()) { | ||||
| 							poco_error(Logger_, | ||||
| 									   fmt::format("Error: {}", Msg.get_error().to_string())); | ||||
| 						} | ||||
| 						if (!AutoCommit) | ||||
| 							Consumer.async_commit(Msg); | ||||
| 						continue; | ||||
| 					} | ||||
| 					KafkaManager()->Dispatch(Msg.get_topic().c_str(), Msg.get_key(), std::make_shared<std::string>(Msg.get_payload())); | ||||
| 					if (!AutoCommit) | ||||
| 						Consumer.async_commit(Msg); | ||||
| 				} | ||||
| 			} catch (const cppkafka::HandleException &E) { | ||||
| 				poco_warning(Logger_, | ||||
| 							 fmt::format("Caught a Kafka exception (consumer): {}", E.what())); | ||||
| 			} catch (const Poco::Exception &E) { | ||||
|  | ||||
| 				Logger_.log(E); | ||||
| 			} catch (...) { | ||||
|  | ||||
| 				poco_error(Logger_, "std::exception"); | ||||
| 			} | ||||
| 		} | ||||
| 				} | ||||
| 				Consumer.commit(msg); | ||||
| 			}, | ||||
| 			// Whenever there's an error (other than the EOF soft error) | ||||
| 			[&Logger_](cppkafka::Error error) { | ||||
| 				poco_warning(Logger_,fmt::format("Error: {}", error.to_string())); | ||||
| 			}, | ||||
| 			// Whenever EOF is reached on a partition, print this | ||||
| 			[&Logger_](cppkafka::ConsumerDispatcher::EndOfFile, const cppkafka::TopicPartition& topic_partition) { | ||||
| 				poco_debug(Logger_,fmt::format("Partition {} EOF", topic_partition.get_partition())); | ||||
| 			} | ||||
| 		); | ||||
|  | ||||
| 		Consumer.unsubscribe(); | ||||
| 		poco_information(Logger_, "Stopped..."); | ||||
| 	} | ||||
| @@ -223,13 +213,14 @@ namespace OpenWifi { | ||||
| 	} | ||||
|  | ||||
| 	void KafkaProducer::Produce(const char *Topic, const std::string &Key, | ||||
| 								const std::string &Payload) { | ||||
| 								const std::shared_ptr<std::string> Payload) { | ||||
| 		std::lock_guard G(Mutex_); | ||||
| 		Queue_.enqueueNotification(new KafkaMessage(Topic, Key, Payload)); | ||||
| 	} | ||||
|  | ||||
| 	void KafkaConsumer::Start() { | ||||
| 		if (!Running_) { | ||||
| 			Running_ = true; | ||||
| 			Worker_.start(*this); | ||||
| 		} | ||||
| 	} | ||||
| @@ -237,16 +228,29 @@ namespace OpenWifi { | ||||
| 	void KafkaConsumer::Stop() { | ||||
| 		if (Running_) { | ||||
| 			Running_ = false; | ||||
| 			if(Dispatcher_) { | ||||
| 				Dispatcher_->stop(); | ||||
| 			} | ||||
| 			Worker_.wakeUp(); | ||||
| 			Worker_.join(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	std::uint64_t KafkaConsumer::RegisterTopicWatcher(const std::string &Topic, | ||||
| 	void KafkaDispatcher::Start() { | ||||
| 		if (!Running_) { | ||||
| 			Running_ = true; | ||||
| 			Worker_.start(*this); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	void KafkaDispatcher::Stop() { | ||||
| 		if (Running_) { | ||||
| 			Running_ = false; | ||||
| 			Queue_.wakeUpAll(); | ||||
| 			Worker_.join(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	auto KafkaDispatcher::RegisterTopicWatcher(const std::string &Topic, | ||||
| 											   Types::TopicNotifyFunction &F) { | ||||
| 		std::lock_guard G(ConsumerMutex_); | ||||
| 		std::lock_guard G(Mutex_); | ||||
| 		auto It = Notifiers_.find(Topic); | ||||
| 		if (It == Notifiers_.end()) { | ||||
| 			Types::TopicNotifyFunctionList L; | ||||
| @@ -255,12 +259,11 @@ namespace OpenWifi { | ||||
| 		} else { | ||||
| 			It->second.emplace(It->second.end(), std::make_pair(F, FunctionId_)); | ||||
| 		} | ||||
| 		Topics_.insert(Topic); | ||||
| 		return FunctionId_++; | ||||
| 	} | ||||
|  | ||||
| 	void KafkaConsumer::UnregisterTopicWatcher(const std::string &Topic, int Id) { | ||||
| 		std::lock_guard G(ConsumerMutex_); | ||||
| 	void KafkaDispatcher::UnregisterTopicWatcher(const std::string &Topic, int Id) { | ||||
| 		std::lock_guard G(Mutex_); | ||||
| 		auto It = Notifiers_.find(Topic); | ||||
| 		if (It != Notifiers_.end()) { | ||||
| 			Types::TopicNotifyFunctionList &L = It->second; | ||||
| @@ -272,17 +275,56 @@ namespace OpenWifi { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	void KafkaDispatcher::Dispatch(const char *Topic, const std::string &Key, | ||||
| 								   const std::shared_ptr<std::string> Payload) { | ||||
| 		std::lock_guard G(Mutex_); | ||||
| 		auto It = Notifiers_.find(Topic); | ||||
| 		if (It != Notifiers_.end()) { | ||||
| 			Queue_.enqueueNotification(new KafkaMessage(Topic, Key, Payload)); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	void KafkaDispatcher::run() { | ||||
| 		Poco::Logger &Logger_ = | ||||
| 			Poco::Logger::create("KAFKA-DISPATCHER", KafkaManager()->Logger().getChannel()); | ||||
| 		poco_information(Logger_, "Starting..."); | ||||
| 		Poco::AutoPtr<Poco::Notification> Note(Queue_.waitDequeueNotification()); | ||||
| 		Utils::SetThreadName("kafka:dispatch"); | ||||
| 		while (Note && Running_) { | ||||
| 			auto Msg = dynamic_cast<KafkaMessage *>(Note.get()); | ||||
| 			if (Msg != nullptr) { | ||||
| 				auto It = Notifiers_.find(Msg->Topic()); | ||||
| 				if (It != Notifiers_.end()) { | ||||
| 					const auto &FL = It->second; | ||||
| 					for (const auto &[CallbackFunc, _] : FL) { | ||||
| 						CallbackFunc(Msg->Key(), Msg->Payload()); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 			Note = Queue_.waitDequeueNotification(); | ||||
| 		} | ||||
| 		poco_information(Logger_, "Stopped..."); | ||||
| 	} | ||||
|  | ||||
| 	void KafkaDispatcher::Topics(std::vector<std::string> &T) { | ||||
| 		T.clear(); | ||||
| 		for (const auto &[TopicName, _] : Notifiers_) | ||||
| 			T.push_back(TopicName); | ||||
| 	} | ||||
|  | ||||
| 	int KafkaManager::Start() { | ||||
| 		if (!KafkaEnabled_) | ||||
| 			return 0; | ||||
| 		ConsumerThr_.Start(); | ||||
| 		ProducerThr_.Start(); | ||||
| 		Dispatcher_.Start(); | ||||
| 		return 0; | ||||
| 	} | ||||
|  | ||||
| 	void KafkaManager::Stop() { | ||||
| 		if (KafkaEnabled_) { | ||||
| 			poco_information(Logger(), "Stopping..."); | ||||
| 			Dispatcher_.Stop(); | ||||
| 			ProducerThr_.Stop(); | ||||
| 			ConsumerThr_.Stop(); | ||||
| 			poco_information(Logger(), "Stopped..."); | ||||
| @@ -291,25 +333,38 @@ namespace OpenWifi { | ||||
| 	} | ||||
|  | ||||
| 	void KafkaManager::PostMessage(const char *topic, const std::string &key, | ||||
| 								   const std::string & PayLoad, bool WrapMessage) { | ||||
| 								   const std::shared_ptr<std::string> PayLoad, bool WrapMessage) { | ||||
| 		if (KafkaEnabled_) { | ||||
| 			ProducerThr_.Produce(topic, key, WrapMessage ? WrapSystemId(PayLoad) : PayLoad); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	void KafkaManager::PostMessage(const char *topic, const std::string &key, | ||||
| 					 const Poco::JSON::Object &Object, bool WrapMessage) { | ||||
| 	void KafkaManager::Dispatch(const char *Topic, const std::string &Key, | ||||
| 								const std::shared_ptr<std::string> Payload) { | ||||
| 		Dispatcher_.Dispatch(Topic, Key, Payload); | ||||
| 	} | ||||
|  | ||||
| 	[[nodiscard]] const std::shared_ptr<std::string> KafkaManager::WrapSystemId(const std::shared_ptr<std::string> PayLoad) { | ||||
| 		*PayLoad = SystemInfoWrapper_ + *PayLoad + "}"; | ||||
| 		return PayLoad; | ||||
| 	} | ||||
|  | ||||
| 	uint64_t KafkaManager::RegisterTopicWatcher(const std::string &Topic, | ||||
| 												Types::TopicNotifyFunction &F) { | ||||
| 		if (KafkaEnabled_) { | ||||
| 			std::ostringstream ObjectStr; | ||||
| 			Object.stringify(ObjectStr); | ||||
| 			ProducerThr_.Produce(topic, key, WrapMessage ? WrapSystemId(ObjectStr.str()) : ObjectStr.str()); | ||||
| 			return Dispatcher_.RegisterTopicWatcher(Topic, F); | ||||
| 		} else { | ||||
| 			return 0; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	[[nodiscard]] std::string KafkaManager::WrapSystemId(const std::string & PayLoad) { | ||||
| 		return fmt::format(	R"lit({{ "system" : {{ "id" : {}, "host" : "{}" }}, "payload" : {} }})lit", | ||||
| 						   MicroServiceID(), MicroServicePrivateEndPoint(), PayLoad ) ; | ||||
| 	void KafkaManager::UnregisterTopicWatcher(const std::string &Topic, uint64_t Id) { | ||||
| 		if (KafkaEnabled_) { | ||||
| 			Dispatcher_.UnregisterTopicWatcher(Topic, Id); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	void KafkaManager::Topics(std::vector<std::string> &T) { Dispatcher_.Topics(T); } | ||||
|  | ||||
| 	void KafkaManager::PartitionAssignment(const cppkafka::TopicPartitionList &partitions) { | ||||
| 		poco_information( | ||||
|   | ||||
| @@ -6,7 +6,7 @@ | ||||
|  | ||||
| #include "Poco/Notification.h" | ||||
| #include "Poco/NotificationQueue.h" | ||||
| #include "Poco/JSON/Object.h" | ||||
|  | ||||
| #include "framework/KafkaTopics.h" | ||||
| #include "framework/OpenWifiTypes.h" | ||||
| #include "framework/SubSystemServer.h" | ||||
| @@ -18,17 +18,17 @@ namespace OpenWifi { | ||||
|  | ||||
| 	class KafkaMessage : public Poco::Notification { | ||||
| 	  public: | ||||
| 		KafkaMessage(const char * Topic, const std::string &Key, const std::string &Payload) | ||||
| 			: Topic_(Topic), Key_(Key), Payload_(Payload) {} | ||||
| 		KafkaMessage(const char * Topic, const std::string &Key, const std::shared_ptr<std::string> Payload) | ||||
| 			: Topic_(Topic), Key_(Key), Payload_(std::move(Payload)) {} | ||||
|  | ||||
| 		inline const char * Topic() { return Topic_; } | ||||
| 		inline const std::string &Key() { return Key_; } | ||||
| 		inline const std::string &Payload() { return Payload_; } | ||||
| 		inline const std::string &Payload() { return *Payload_; } | ||||
|  | ||||
| 	  private: | ||||
| 		const char *Topic_; | ||||
| 		std::string Key_; | ||||
| 		std::string Payload_; | ||||
| 		std::shared_ptr<std::string> Payload_; | ||||
| 	}; | ||||
|  | ||||
| 	class KafkaProducer : public Poco::Runnable { | ||||
| @@ -36,10 +36,10 @@ namespace OpenWifi { | ||||
| 		void run() override; | ||||
| 		void Start(); | ||||
| 		void Stop(); | ||||
| 		void Produce(const char *Topic, const std::string &Key, const std::string & Payload); | ||||
| 		void Produce(const char *Topic, const std::string &Key, const std::shared_ptr<std::string> Payload); | ||||
|  | ||||
| 	  private: | ||||
| 		std::mutex Mutex_; | ||||
| 		std::recursive_mutex Mutex_; | ||||
| 		Poco::Thread Worker_; | ||||
| 		mutable std::atomic_bool Running_ = false; | ||||
| 		Poco::NotificationQueue Queue_; | ||||
| @@ -47,22 +47,33 @@ namespace OpenWifi { | ||||
|  | ||||
| 	class KafkaConsumer : public Poco::Runnable { | ||||
| 	  public: | ||||
| 		void run() override; | ||||
| 		void Start(); | ||||
| 		void Stop(); | ||||
|  | ||||
| 	  private: | ||||
| 		std::mutex 				ConsumerMutex_; | ||||
| 		std::recursive_mutex Mutex_; | ||||
| 		Poco::Thread Worker_; | ||||
| 		mutable std::atomic_bool Running_ = false; | ||||
| 	}; | ||||
|  | ||||
| 	class KafkaDispatcher : public Poco::Runnable { | ||||
| 	  public: | ||||
| 		void Start(); | ||||
| 		void Stop(); | ||||
| 		auto RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F); | ||||
| 		void UnregisterTopicWatcher(const std::string &Topic, int Id); | ||||
| 		void Dispatch(const char *Topic, const std::string &Key, const std::shared_ptr<std::string> Payload); | ||||
| 		void run() override; | ||||
| 		void Topics(std::vector<std::string> &T); | ||||
|  | ||||
| 	  private: | ||||
| 		std::recursive_mutex Mutex_; | ||||
| 		Types::NotifyTable Notifiers_; | ||||
| 		Poco::Thread Worker_; | ||||
| 		mutable std::atomic_bool Running_ = false; | ||||
| 		uint64_t FunctionId_ = 1; | ||||
| 		std::unique_ptr<cppkafka::ConsumerDispatcher> 	Dispatcher_; | ||||
| 		std::set<std::string>	Topics_; | ||||
|  | ||||
| 		void run() override; | ||||
| 		friend class KafkaManager; | ||||
| 		std::uint64_t RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F); | ||||
| 		void UnregisterTopicWatcher(const std::string &Topic, int Id); | ||||
| 		Poco::NotificationQueue Queue_; | ||||
| 	}; | ||||
|  | ||||
| 	class KafkaManager : public SubSystemServer { | ||||
| @@ -81,24 +92,20 @@ namespace OpenWifi { | ||||
| 		void Stop() override; | ||||
|  | ||||
| 		void PostMessage(const char *topic, const std::string &key, | ||||
| 						 const std::string &PayLoad, bool WrapMessage = true); | ||||
| 		void PostMessage(const char *topic, const std::string &key, | ||||
| 						 const Poco::JSON::Object &Object, bool WrapMessage = true); | ||||
|  | ||||
| 		[[nodiscard]] std::string WrapSystemId(const std::string & PayLoad); | ||||
| 						 const std::shared_ptr<std::string> PayLoad, bool WrapMessage = true); | ||||
| 		void Dispatch(const char *Topic, const std::string &Key, const std::shared_ptr<std::string> Payload); | ||||
| 		[[nodiscard]] const std::shared_ptr<std::string> WrapSystemId(const std::shared_ptr<std::string> PayLoad); | ||||
| 		[[nodiscard]] inline bool Enabled() const { return KafkaEnabled_; } | ||||
| 		inline std::uint64_t RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F) { | ||||
| 			return ConsumerThr_.RegisterTopicWatcher(Topic,F); | ||||
| 		} | ||||
| 		inline void UnregisterTopicWatcher(const std::string &Topic, uint64_t Id) { | ||||
| 			return ConsumerThr_.UnregisterTopicWatcher(Topic,Id); | ||||
| 		} | ||||
| 		uint64_t RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F); | ||||
| 		void UnregisterTopicWatcher(const std::string &Topic, uint64_t Id); | ||||
| 		void Topics(std::vector<std::string> &T); | ||||
|  | ||||
| 	  private: | ||||
| 		bool KafkaEnabled_ = false; | ||||
| 		std::string SystemInfoWrapper_; | ||||
| 		KafkaProducer ProducerThr_; | ||||
| 		KafkaConsumer ConsumerThr_; | ||||
| 		KafkaDispatcher Dispatcher_; | ||||
|  | ||||
| 		void PartitionAssignment(const cppkafka::TopicPartitionList &partitions); | ||||
| 		void PartitionRevocation(const cppkafka::TopicPartitionList &partitions); | ||||
|   | ||||
| @@ -20,7 +20,6 @@ namespace OpenWifi::KafkaTopics { | ||||
| 	inline const char * DEVICE_EVENT_QUEUE = "device_event_queue"; | ||||
| 	inline const char * DEVICE_TELEMETRY = "device_telemetry"; | ||||
| 	inline const char * PROVISIONING_CHANGE = "provisioning_change"; | ||||
| 	inline const char * RRM = "rrm"; | ||||
|  | ||||
| 	namespace ServiceEvents { | ||||
| 		inline const char * EVENT_JOIN = "join"; | ||||
|   | ||||
| @@ -33,23 +33,9 @@ namespace OpenWifi { | ||||
|  | ||||
| 	void MicroService::Exit(int Reason) { std::exit(Reason); } | ||||
|  | ||||
|     static std::string MakeServiceListString(const Types::MicroServiceMetaMap &Services) { | ||||
|         std::string SvcList; | ||||
|         for (const auto &Svc : Services) { | ||||
|             if (SvcList.empty()) | ||||
|                 SvcList = Svc.second.Type; | ||||
|             else | ||||
|                 SvcList += ", " + Svc.second.Type; | ||||
|         } | ||||
|         return SvcList; | ||||
|     } | ||||
|  | ||||
| 	void MicroService::BusMessageReceived([[maybe_unused]] const std::string &Key, | ||||
| 										  const std::string &Payload) { | ||||
| 		std::lock_guard G(InfraMutex_); | ||||
|  | ||||
| 		Poco::Logger &BusLogger = EventBusManager()->Logger(); | ||||
|  | ||||
| 		try { | ||||
| 			Poco::JSON::Parser P; | ||||
| 			auto Object = P.parse(Payload).extract<Poco::JSON::Object::Ptr>(); | ||||
| @@ -69,10 +55,13 @@ namespace OpenWifi { | ||||
| 							Object->has(KafkaTopics::ServiceEvents::Fields::KEY)) { | ||||
| 							auto PrivateEndPoint = | ||||
| 								Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE).toString(); | ||||
| 							if (Event == KafkaTopics::ServiceEvents::EVENT_LEAVE) { | ||||
| 							if (Event == KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE && | ||||
| 								Services_.find(PrivateEndPoint) != Services_.end()) { | ||||
| 								Services_[PrivateEndPoint].LastUpdate = Utils::Now(); | ||||
| 							} else if (Event == KafkaTopics::ServiceEvents::EVENT_LEAVE) { | ||||
| 								Services_.erase(PrivateEndPoint); | ||||
| 								poco_information( | ||||
| 									BusLogger, | ||||
| 								poco_debug( | ||||
| 									logger(), | ||||
| 									fmt::format( | ||||
| 										"Service {} ID={} leaving system.", | ||||
| 										Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE) | ||||
| @@ -80,7 +69,14 @@ namespace OpenWifi { | ||||
| 										ID)); | ||||
| 							} else if (Event == KafkaTopics::ServiceEvents::EVENT_JOIN || | ||||
| 									   Event == KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE) { | ||||
| 								auto ServiceInfo = Types::MicroServiceMeta{ | ||||
| 								poco_debug( | ||||
| 									logger(), | ||||
| 									fmt::format( | ||||
| 										"Service {} ID={} joining system.", | ||||
| 										Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE) | ||||
| 											.toString(), | ||||
| 										ID)); | ||||
| 								Services_[PrivateEndPoint] = Types::MicroServiceMeta{ | ||||
| 									.Id = ID, | ||||
| 									.Type = Poco::toLower( | ||||
| 										Object->get(KafkaTopics::ServiceEvents::Fields::TYPE) | ||||
| @@ -98,22 +94,6 @@ namespace OpenWifi { | ||||
| 												   .toString(), | ||||
| 									.LastUpdate = Utils::Now()}; | ||||
|  | ||||
|                                 auto s1 = MakeServiceListString(Services_); | ||||
| 								auto PreviousSize = Services_.size(); | ||||
| 								Services_[PrivateEndPoint] = ServiceInfo; | ||||
| 								auto CurrentSize = Services_.size(); | ||||
| 								if(Event == KafkaTopics::ServiceEvents::EVENT_JOIN) { | ||||
| 									if(!s1.empty()) { | ||||
| 										poco_information( | ||||
| 											BusLogger, | ||||
| 											fmt::format( | ||||
| 												"Service {} ID={} is joining the system.", | ||||
| 												Object | ||||
| 													->get( | ||||
| 														KafkaTopics::ServiceEvents::Fields::PRIVATE) | ||||
| 													.toString(), | ||||
| 												ID)); | ||||
| 									} | ||||
| 								std::string SvcList; | ||||
| 								for (const auto &Svc : Services_) { | ||||
| 									if (SvcList.empty()) | ||||
| @@ -122,22 +102,12 @@ namespace OpenWifi { | ||||
| 										SvcList += ", " + Svc.second.Type; | ||||
| 								} | ||||
| 								poco_information( | ||||
| 										BusLogger, | ||||
| 									logger(), | ||||
| 									fmt::format("Current list of microservices: {}", SvcList)); | ||||
| 								} else if(CurrentSize!=PreviousSize) { | ||||
| 									poco_information( | ||||
| 										BusLogger, | ||||
| 										fmt::format( | ||||
| 											"Service {} ID={} is being added back in.", | ||||
| 											Object | ||||
| 												->get(KafkaTopics::ServiceEvents::Fields::PRIVATE) | ||||
| 												.toString(), | ||||
| 											ID)); | ||||
| 								} | ||||
| 							} | ||||
| 						} else { | ||||
| 							poco_information( | ||||
| 								BusLogger, | ||||
| 							poco_error( | ||||
| 								logger(), | ||||
| 								fmt::format("KAFKA-MSG: invalid event '{}', missing a field.", | ||||
| 											Event)); | ||||
| 						} | ||||
| @@ -148,39 +118,30 @@ namespace OpenWifi { | ||||
| 								Object->get(KafkaTopics::ServiceEvents::Fields::TOKEN).toString()); | ||||
| #endif | ||||
| 						} else { | ||||
| 							poco_information( | ||||
| 								BusLogger, | ||||
| 							poco_error( | ||||
| 								logger(), | ||||
| 								fmt::format("KAFKA-MSG: invalid event '{}', missing token", Event)); | ||||
| 						} | ||||
| 					} else { | ||||
| 						poco_information(BusLogger, | ||||
| 						poco_error(logger(), | ||||
| 								   fmt::format("Unknown Event: {} Source: {}", Event, ID)); | ||||
| 					} | ||||
| 				} | ||||
| 			} else { | ||||
| 				std::ostringstream os; | ||||
| 				Object->stringify(std::cout); | ||||
| 				poco_error(BusLogger, fmt::format("Bad bus message: {}", os.str())); | ||||
| 				poco_error(logger(), "Bad bus message."); | ||||
| 			} | ||||
|  | ||||
| 			auto ServiceHint = Services_.begin(); | ||||
| 			auto i = Services_.begin(); | ||||
| 			auto now = Utils::Now(); | ||||
|             auto si1 = Services_.size(); | ||||
|             auto ss1 = MakeServiceListString(Services_); | ||||
| 			while(ServiceHint!=Services_.end()) { | ||||
| 				if ((now - ServiceHint->second.LastUpdate) > 120) { | ||||
| 					poco_information(BusLogger, fmt::format("ZombieService: Removing service {}, ", ServiceHint->second.PublicEndPoint)); | ||||
| 					ServiceHint = Services_.erase(ServiceHint); | ||||
| 			for (; i != Services_.end();) { | ||||
| 				if ((now - i->second.LastUpdate) > 60) { | ||||
| 					i = Services_.erase(i); | ||||
| 				} else | ||||
| 					++ServiceHint; | ||||
| 			} | ||||
|             if(Services_.size() != si1) { | ||||
|                 auto ss2 = MakeServiceListString(Services_); | ||||
|                 poco_information(BusLogger, fmt::format("Current list of microservices: {} -> {}", ss1, ss2)); | ||||
| 					++i; | ||||
| 			} | ||||
|  | ||||
| 		} catch (const Poco::Exception &E) { | ||||
| 			BusLogger.log(E); | ||||
| 			logger().log(E); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -449,7 +410,7 @@ namespace OpenWifi { | ||||
| 			try { | ||||
| 				DataDir.createDirectory(); | ||||
| 			} catch (const Poco::Exception &E) { | ||||
| 				Logger_.log(E); | ||||
| 				logger().log(E); | ||||
| 			} | ||||
| 		} | ||||
| 		WWWAssetsDir_ = ConfigPath("openwifi.restapi.wwwassets", ""); | ||||
| @@ -567,12 +528,14 @@ namespace OpenWifi { | ||||
| 		for (auto i : SubSystems_) { | ||||
| 			i->Start(); | ||||
| 		} | ||||
| 		EventBusManager()->Start(); | ||||
| 		EventBusManager_ = std::make_unique<EventBusManager>(Poco::Logger::create( | ||||
| 			"EventBusManager", Poco::Logger::root().getChannel(), Poco::Logger::root().getLevel())); | ||||
| 		EventBusManager_->Start(); | ||||
| 	} | ||||
|  | ||||
| 	void MicroService::StopSubSystemServers() { | ||||
| 		AddActivity("Stopping"); | ||||
| 		EventBusManager()->Stop(); | ||||
| 		EventBusManager_->Stop(); | ||||
| 		for (auto i = SubSystems_.rbegin(); i != SubSystems_.rend(); ++i) { | ||||
| 			(*i)->Stop(); | ||||
| 		} | ||||
| @@ -732,7 +695,7 @@ namespace OpenWifi { | ||||
| 			auto APIKEY = Request.get("X-API-KEY"); | ||||
| 			return APIKEY == MyHash_; | ||||
| 		} catch (const Poco::Exception &E) { | ||||
| 			Logger_.log(E); | ||||
| 			logger().log(E); | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
|   | ||||
| @@ -201,6 +201,7 @@ namespace OpenWifi { | ||||
| 		Poco::JWT::Signer Signer_; | ||||
| 		Poco::Logger &Logger_; | ||||
| 		Poco::ThreadPool TimerPool_{"timer:pool", 2, 32}; | ||||
| 		std::unique_ptr<EventBusManager> EventBusManager_; | ||||
| 	}; | ||||
|  | ||||
| 	inline MicroService *MicroService::instance_ = nullptr; | ||||
|   | ||||
| @@ -5,8 +5,6 @@ | ||||
| #include "framework/MicroServiceFuncs.h" | ||||
| #include "framework/MicroService.h" | ||||
|  | ||||
| #include "framework/ALBserver.h" | ||||
|  | ||||
| namespace OpenWifi { | ||||
| 	const std::string &MicroServiceDataDirectory() { return MicroService::instance().DataDir(); } | ||||
|  | ||||
| @@ -125,12 +123,4 @@ namespace OpenWifi { | ||||
| 		return MicroService::instance().AllowExternalMicroServices(); | ||||
| 	} | ||||
|  | ||||
| 	void MicroServiceALBCallback( std::string Callback()) { | ||||
| 		return ALBHealthCheckServer()->RegisterExtendedHealthMessage(Callback); | ||||
| 	} | ||||
|  | ||||
| 	std::string MicroServiceAccessKey() { | ||||
| 		return MicroService::instance().Hash(); | ||||
| 	} | ||||
|  | ||||
| } // namespace OpenWifi | ||||
|   | ||||
| @@ -22,7 +22,6 @@ namespace OpenWifi { | ||||
| 	std::string MicroServicePublicEndPoint(); | ||||
| 	std::string MicroServiceConfigGetString(const std::string &Key, | ||||
| 											const std::string &DefaultValue); | ||||
| 	std::string MicroServiceAccessKey(); | ||||
| 	bool MicroServiceConfigGetBool(const std::string &Key, bool DefaultValue); | ||||
| 	std::uint64_t MicroServiceConfigGetInt(const std::string &Key, std::uint64_t DefaultValue); | ||||
| 	std::string MicroServicePrivateEndPoint(); | ||||
| @@ -54,5 +53,4 @@ namespace OpenWifi { | ||||
| 	std::string MicroServiceGetPublicAPIEndPoint(); | ||||
| 	void MicroServiceDeleteOverrideConfiguration(); | ||||
| 	bool AllowExternalMicroServices(); | ||||
| 	void MicroServiceALBCallback( std::string Callback()); | ||||
| } // namespace OpenWifi | ||||
|   | ||||
| @@ -28,9 +28,6 @@ namespace OpenWifi::Types { | ||||
| 	typedef std::string UUID_t; | ||||
| 	typedef std::vector<UUID_t> UUIDvec_t; | ||||
| 	typedef std::map<std::string, std::map<uint32_t, uint64_t>> Counted3DMapSII; | ||||
| 	typedef std::vector<int64_t> IntList; | ||||
| 	typedef std::vector<uint64_t> UIntList; | ||||
| 	typedef std::vector<double> DoubleList; | ||||
|  | ||||
| 	struct MicroServiceMeta { | ||||
| 		uint64_t Id = 0; | ||||
|   | ||||
| @@ -574,36 +574,6 @@ namespace OpenWifi { | ||||
| 			Poco::JSON::Stringifier::stringify(Object, Answer); | ||||
| 		} | ||||
|  | ||||
|         inline void ReturnObject(const std::vector<std::string> &Strings) { | ||||
|             Poco::JSON::Array   Arr; | ||||
|             for(const auto &String:Strings) { | ||||
|                 Arr.add(String); | ||||
|             } | ||||
|             std::ostringstream os; | ||||
|             Arr.stringify(os); | ||||
|             return ReturnRawJSON(os.str()); | ||||
|         } | ||||
|  | ||||
|         template<class T> void ReturnObject(const std::vector<T> &Objects) { | ||||
|             Poco::JSON::Array   Arr; | ||||
|             for(const auto &Object:Objects) { | ||||
|                 Poco::JSON::Object O; | ||||
|                 Object.to_json(O); | ||||
|                 Arr.add(O); | ||||
|             } | ||||
|             std::ostringstream os; | ||||
|             Arr.stringify(os); | ||||
|             return ReturnRawJSON(os.str()); | ||||
|         } | ||||
|  | ||||
|         template<class T> void ReturnObject(const T &Object) { | ||||
|             Poco::JSON::Object  O; | ||||
|             Object.to_json(O); | ||||
|             std::ostringstream os; | ||||
|             O.stringify(os); | ||||
|             return ReturnRawJSON(os.str()); | ||||
|         } | ||||
|  | ||||
| 		inline void ReturnRawJSON(const std::string &json_doc) { | ||||
| 			PrepareResponse(); | ||||
| 			if (Request != nullptr) { | ||||
|   | ||||
| @@ -24,10 +24,9 @@ namespace OpenWifi { | ||||
| 							 Server, TransactionId, Internal) {} | ||||
| 		static auto PathName() { return std::list<std::string>{"/api/v1/system"}; } | ||||
|  | ||||
| 		inline void DoGet() final { | ||||
| 		inline void DoGet() { | ||||
| 			std::string Arg; | ||||
| 			if (HasParameter("command", Arg)) { | ||||
| 				if (Arg == "info") { | ||||
| 			if (HasParameter("command", Arg) && Arg == "info") { | ||||
| 				Poco::JSON::Object Answer; | ||||
| 				Answer.set(RESTAPI::Protocol::VERSION, MicroServiceVersion()); | ||||
| 				Answer.set(RESTAPI::Protocol::UPTIME, MicroServiceUptimeTotalSeconds()); | ||||
| @@ -65,23 +64,11 @@ namespace OpenWifi { | ||||
| 				Answer.set("certificates", Certificates); | ||||
| 				return ReturnObject(Answer); | ||||
| 			} | ||||
| 				if (Arg == "extraConfiguration") { | ||||
| 			if (GetBoolParameter("extraConfiguration")) { | ||||
| 				Poco::JSON::Object Answer; | ||||
| 				MicroServiceGetExtraConfiguration(Answer); | ||||
| 				return ReturnObject(Answer); | ||||
| 			} | ||||
| 				if (Arg == "resources") { | ||||
| 					Poco::JSON::Object Answer; | ||||
| 					Answer.set("numberOfFileDescriptors", Utils::get_open_fds()); | ||||
| 					std::uint64_t currRealMem, peakRealMem, currVirtMem, peakVirtMem; | ||||
| 					Utils::getMemory(currRealMem, peakRealMem, currVirtMem, peakVirtMem); | ||||
| 					Answer.set("currRealMem", currRealMem); | ||||
| 					Answer.set("peakRealMem", peakRealMem); | ||||
| 					Answer.set("currVirtMem", currVirtMem); | ||||
| 					Answer.set("peakVirtMem", peakVirtMem); | ||||
| 					return ReturnObject(Answer); | ||||
| 				} | ||||
| 			} | ||||
| 			BadRequest(RESTAPI::Errors::InvalidCommand); | ||||
| 		} | ||||
|  | ||||
|   | ||||
| @@ -102,20 +102,6 @@ namespace OpenWifi::RESTAPI_utils { | ||||
| 		Obj.set(Field, A); | ||||
| 	} | ||||
|  | ||||
| 	inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::DoubleList &V) { | ||||
| 		Poco::JSON::Array A; | ||||
| 		for (const auto &i : V) | ||||
| 			A.add(i); | ||||
| 		Obj.set(Field, A); | ||||
| 	} | ||||
|  | ||||
| 	inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::IntList &V) { | ||||
| 		Poco::JSON::Array A; | ||||
| 		for (const auto &i : V) | ||||
| 			A.add(i); | ||||
| 		Obj.set(Field, A); | ||||
| 	} | ||||
|  | ||||
| 	inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::TagList &V) { | ||||
| 		Poco::JSON::Array A; | ||||
| 		for (const auto &i : V) | ||||
| @@ -298,28 +284,6 @@ namespace OpenWifi::RESTAPI_utils { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, | ||||
| 								Types::DoubleList &Value) { | ||||
| 		if (Obj->isArray(Field) && !Obj->isNull(Field)) { | ||||
| 			Value.clear(); | ||||
| 			Poco::JSON::Array::Ptr A = Obj->getArray(Field); | ||||
| 			for (const auto &i : *A) { | ||||
| 				Value.push_back(i); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, | ||||
| 								Types::IntList &Value) { | ||||
| 		if (Obj->isArray(Field) && !Obj->isNull(Field)) { | ||||
| 			Value.clear(); | ||||
| 			Poco::JSON::Array::Ptr A = Obj->getArray(Field); | ||||
| 			for (const auto &i : *A) { | ||||
| 				Value.push_back(i); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	template <class T> | ||||
| 	void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, | ||||
| 						 std::vector<T> &Value) { | ||||
|   | ||||
| @@ -22,8 +22,9 @@ namespace OpenWifi { | ||||
|  | ||||
| 	class StorageClass : public SubSystemServer { | ||||
| 	  public: | ||||
| 		StorageClass() noexcept : SubSystemServer("StorageClass", "STORAGE-SVR", "storage") {} | ||||
|  | ||||
|         inline int Start() override { | ||||
| 		int Start() override { | ||||
| 			std::lock_guard Guard(Mutex_); | ||||
|  | ||||
| 			Logger().notice("Starting."); | ||||
| @@ -39,24 +40,17 @@ namespace OpenWifi { | ||||
| 			return 0; | ||||
| 		} | ||||
|  | ||||
| 		inline void Stop() override { Pool_->shutdown(); } | ||||
| 		void Stop() override { Pool_->shutdown(); } | ||||
|  | ||||
| 		DBType Type() const { return dbType_; }; | ||||
|  | ||||
|         StorageClass() noexcept : SubSystemServer("StorageClass", "STORAGE-SVR", "storage") { | ||||
|  | ||||
|         } | ||||
|  | ||||
| 		Poco::Data::SessionPool &Pool() { return *Pool_; } | ||||
|  | ||||
| 	  private: | ||||
| 		inline int Setup_SQLite(); | ||||
| 		inline int Setup_MySQL(); | ||||
| 		inline int Setup_PostgreSQL(); | ||||
|  | ||||
|  | ||||
| 	  protected: | ||||
| 		std::shared_ptr<Poco::Data::SessionPool> Pool_; | ||||
| 		std::unique_ptr<Poco::Data::SessionPool> Pool_; | ||||
| 		Poco::Data::SQLite::Connector SQLiteConn_; | ||||
| 		Poco::Data::PostgreSQL::Connector PostgresConn_; | ||||
| 		Poco::Data::MySQL::Connector MySQLConn_; | ||||
| @@ -87,7 +81,7 @@ namespace OpenWifi { | ||||
| 		//        Poco::Data::SessionPool(SQLiteConn_.name(), DBName, 8, | ||||
| 		//                                                                                     (int)NumSessions, | ||||
| 		//                                                                                     (int)IdleTime)); | ||||
| 		Pool_ = std::make_shared<Poco::Data::SessionPool>(SQLiteConn_.name(), DBName, 8, | ||||
| 		Pool_ = std::make_unique<Poco::Data::SessionPool>(SQLiteConn_.name(), DBName, 8, | ||||
| 														  (int)NumSessions, (int)IdleTime); | ||||
| 		return 0; | ||||
| 	} | ||||
| @@ -108,7 +102,7 @@ namespace OpenWifi { | ||||
| 									";compress=true;auto-reconnect=true"; | ||||
|  | ||||
| 		Poco::Data::MySQL::Connector::registerConnector(); | ||||
| 		Pool_ = std::make_shared<Poco::Data::SessionPool>(MySQLConn_.name(), ConnectionStr, 8, | ||||
| 		Pool_ = std::make_unique<Poco::Data::SessionPool>(MySQLConn_.name(), ConnectionStr, 8, | ||||
| 														  NumSessions, IdleTime); | ||||
|  | ||||
| 		return 0; | ||||
| @@ -132,7 +126,7 @@ namespace OpenWifi { | ||||
| 									" connect_timeout=" + ConnectionTimeout; | ||||
|  | ||||
| 		Poco::Data::PostgreSQL::Connector::registerConnector(); | ||||
| 		Pool_ = std::make_shared<Poco::Data::SessionPool>(PostgresConn_.name(), ConnectionStr, 8, | ||||
| 		Pool_ = std::make_unique<Poco::Data::SessionPool>(PostgresConn_.name(), ConnectionStr, 8, | ||||
| 														  NumSessions, IdleTime); | ||||
|  | ||||
| 		return 0; | ||||
|   | ||||
| @@ -37,7 +37,6 @@ namespace OpenWifi { | ||||
| 		P.cipherList = "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"; | ||||
| 		P.dhUse2048Bits = true; | ||||
| 		P.caLocation = cas_; | ||||
|         // P.securityLevel = | ||||
|  | ||||
| 		auto Context = Poco::AutoPtr<Poco::Net::Context>( | ||||
| 			new Poco::Net::Context(Poco::Net::Context::TLS_SERVER_USE, P)); | ||||
| @@ -54,6 +53,7 @@ namespace OpenWifi { | ||||
|  | ||||
| 			Context->useCertificate(Cert); | ||||
| 			Context->addChainCertificate(Root); | ||||
|  | ||||
| 			Context->addCertificateAuthority(Root); | ||||
|  | ||||
| 			if (level_ == Poco::Net::Context::VERIFY_STRICT) { | ||||
| @@ -76,18 +76,18 @@ namespace OpenWifi { | ||||
| 				L.fatal(fmt::format("Wrong Certificate({}) for Key({})", cert_file_, key_file_)); | ||||
| 			} | ||||
|  | ||||
|             SSL_CTX_set_verify(SSLCtx, level_==Poco::Net::Context::VERIFY_NONE ? SSL_VERIFY_NONE : SSL_VERIFY_PEER, nullptr); | ||||
| 			SSL_CTX_set_verify(SSLCtx, SSL_VERIFY_PEER, nullptr); | ||||
|  | ||||
| 			if (level_ == Poco::Net::Context::VERIFY_STRICT) { | ||||
| 				SSL_CTX_set_client_CA_list(SSLCtx, SSL_load_client_CA_file(client_cas_.c_str())); | ||||
|                 SSL_CTX_enable_ct(SSLCtx, SSL_CT_VALIDATION_STRICT); | ||||
| 			} | ||||
| 			SSL_CTX_enable_ct(SSLCtx, SSL_CT_VALIDATION_STRICT); | ||||
| 			SSL_CTX_dane_enable(SSLCtx); | ||||
|  | ||||
| 			Context->enableSessionCache(); | ||||
| 			Context->setSessionCacheSize(0); | ||||
| 			Context->setSessionTimeout(60); | ||||
| 			Context->enableExtendedCertificateVerification( level_!= Poco::Net::Context::VERIFY_NONE ); | ||||
| 			Context->enableExtendedCertificateVerification(true); | ||||
| 			Context->disableStatelessSessionResumption(); | ||||
| 		} | ||||
|  | ||||
|   | ||||
| @@ -576,8 +576,8 @@ namespace ORM { | ||||
| 		bool UpdateRecord(field_name_t FieldName, const T &Value, const RecordType &R) { | ||||
| 			try { | ||||
| 				assert(ValidFieldName(FieldName)); | ||||
|  | ||||
| 				Poco::Data::Session Session = Pool_.get(); | ||||
|                 Session.begin(); | ||||
| 				Poco::Data::Statement Update(Session); | ||||
|  | ||||
| 				RecordTuple RT; | ||||
| @@ -593,7 +593,6 @@ namespace ORM { | ||||
| 				Update.execute(); | ||||
| 				if (Cache_) | ||||
| 					Cache_->UpdateCache(R); | ||||
|                 Session.commit(); | ||||
| 				return true; | ||||
| 			} catch (const Poco::Exception &E) { | ||||
| 				Logger_.log(E); | ||||
| @@ -663,7 +662,6 @@ namespace ORM { | ||||
| 				assert(ValidFieldName(FieldName)); | ||||
|  | ||||
| 				Poco::Data::Session Session = Pool_.get(); | ||||
|                 Session.begin(); | ||||
| 				Poco::Data::Statement Delete(Session); | ||||
|  | ||||
| 				std::string St = "delete from " + TableName_ + " where " + FieldName + "=?"; | ||||
| @@ -673,7 +671,6 @@ namespace ORM { | ||||
| 				Delete.execute(); | ||||
| 				if (Cache_) | ||||
| 					Cache_->Delete(FieldName, Value); | ||||
|                 Session.commit(); | ||||
| 				return true; | ||||
| 			} catch (const Poco::Exception &E) { | ||||
| 				Logger_.log(E); | ||||
| @@ -685,13 +682,11 @@ namespace ORM { | ||||
| 			try { | ||||
| 				assert(!WhereClause.empty()); | ||||
| 				Poco::Data::Session Session = Pool_.get(); | ||||
|                 Session.begin(); | ||||
| 				Poco::Data::Statement Delete(Session); | ||||
|  | ||||
| 				std::string St = "delete from " + TableName_ + " where " + WhereClause; | ||||
| 				Delete << St; | ||||
| 				Delete.execute(); | ||||
|                 Session.commit(); | ||||
| 				return true; | ||||
| 			} catch (const Poco::Exception &E) { | ||||
| 				Logger_.log(E); | ||||
|   | ||||
| @@ -40,7 +40,6 @@ namespace OpenWifi { | ||||
| 	}; | ||||
| } | ||||
|  | ||||
| #define DBGLINE     std::cout << __LINE__ << ":" << __FILE__ << ", " << __func__ << std::endl; | ||||
| namespace OpenWifi::RESTAPI::Errors { | ||||
| 	struct msg { | ||||
| 		uint64_t err_num; | ||||
| @@ -402,37 +401,6 @@ namespace OpenWifi::RESTAPI::Errors { | ||||
| 		1171, "Command not supported on simulated device." | ||||
| 	}; | ||||
|  | ||||
|     static const struct msg VenuesNameAlreadyExists { | ||||
|             1172, "The venue name already exists." | ||||
|     }; | ||||
|  | ||||
|     static const struct msg InvalidGlobalReachAccount { | ||||
|             1173, "Invalid Global Reach account information." | ||||
|     }; | ||||
|     static const struct msg CannotCreateCSR { | ||||
|             1174, "Cannot create a CSR certificate." | ||||
|     }; | ||||
|  | ||||
|     static const struct msg DefFirmwareNameExists { 1175, "Firmware name already exists." }; | ||||
|     static const struct msg NotAValidECKey { 1176, "Not a valid Signing Key." }; | ||||
| 	static const struct msg NotAValidRadiusPoolType { 1177, "Not a valid RADIUS pool type." }; | ||||
|     static const struct msg InvalidRadiusTypeEndpoint { 1178, "Invalid RADIUS Server Endpoint type." }; | ||||
|     static const struct msg InvalidRadiusEndpointPoolStrategy { 1179, "Invalid RADIUS Server Endpoint Pool strategy." }; | ||||
|     static const struct msg EndpointMustHaveOneTypeOfServers { 1180, "All servers must be either RADIUS or RADSEC." }; | ||||
|     static const struct msg RadiusEndpointIndexInvalid { 1181, "Index must be an address between 0.0.1.1 and 0.0.2.254" }; | ||||
|     static const struct msg RadiusEndpointIndexMustBeUnique { 1182, "Index must be unique." }; | ||||
|     static const struct msg OrionAccountMustExist { 1183, "Orion account must exist." }; | ||||
|     static const struct msg GlobalReachCertMustExist { 1184, "Global Reach certificate must exist." }; | ||||
|     static const struct msg InvalidRadsecMainCertificate { 1185, "Invalid Radsec main certificate." }; | ||||
|     static const struct msg InvalidRadsecCaCertificate { 1186, "Invalid Radsec CA certificates." }; | ||||
|     static const struct msg InvalidRadsecPrivteKey { 1187, "Invalid Radsec Private key." }; | ||||
|     static const struct msg InvalidRadsecIPAddress { 1188, "Invalid Radsec IP Address." }; | ||||
|     static const struct msg InvalidRadsecPort { 1189, "Invalid Radsec Port." }; | ||||
|     static const struct msg InvalidRadsecSecret { 1190, "Invalid Radsec Secret." }; | ||||
|     static const struct msg InvalidRadiusServer { 1191, "Invalid Radius Server." }; | ||||
|  | ||||
| 	static const struct msg InvalidRRMAction { 1192, "Invalid RRM Action." }; | ||||
|  | ||||
|     static const struct msg SimulationDoesNotExist { | ||||
|         7000, "Simulation Instance ID does not exist." | ||||
|     }; | ||||
| @@ -563,10 +531,6 @@ namespace OpenWifi::RESTAPI::Protocol { | ||||
| 	static const char *CONTENTDISPOSITION = "Content-Disposition"; | ||||
| 	static const char *CONTENTTYPE = "Content-Type"; | ||||
|  | ||||
| 	static const char *TRANSFER = "transfer"; | ||||
| 	static const char *CERTUPDATE = "certupdate"; | ||||
| 	static const char *RRM = "rrm"; | ||||
|  | ||||
| 	static const char *REQUIREMENTS = "requirements"; | ||||
| 	static const char *PASSWORDPATTERN = "passwordPattern"; | ||||
| 	static const char *ACCESSPOLICY = "accessPolicy"; | ||||
| @@ -684,12 +648,6 @@ namespace OpenWifi::uCentralProtocol { | ||||
| 	static const char *RADIUSCOA = "coa"; | ||||
| 	static const char *RADIUSDST = "dst"; | ||||
| 	static const char *IES = "ies"; | ||||
|  | ||||
| 	static const char *TRANSFER = "transfer"; | ||||
| 	static const char *CERTUPDATE = "certupdate"; | ||||
| 	static const char *RRM = "rrm"; | ||||
| 	static const char *ACTIONS = "actions"; | ||||
|  | ||||
| } // namespace OpenWifi::uCentralProtocol | ||||
|  | ||||
| namespace OpenWifi::uCentralProtocol::Events { | ||||
| @@ -782,9 +740,6 @@ namespace OpenWifi::APCommands { | ||||
| 		telemetry, | ||||
| 		ping, | ||||
| 		script, | ||||
| 		rrm, | ||||
| 		certupdate, | ||||
| 		transfer, | ||||
| 		unknown | ||||
| 	}; | ||||
|  | ||||
| @@ -797,10 +752,7 @@ namespace OpenWifi::APCommands { | ||||
| 		RESTAPI::Protocol::LEDS,		 RESTAPI::Protocol::TRACE, | ||||
| 		RESTAPI::Protocol::REQUEST,		 RESTAPI::Protocol::WIFISCAN, | ||||
| 		RESTAPI::Protocol::EVENTQUEUE,	 RESTAPI::Protocol::TELEMETRY, | ||||
| 		RESTAPI::Protocol::PING,		 RESTAPI::Protocol::SCRIPT, | ||||
| 		RESTAPI::Protocol::RRM,		 	 RESTAPI::Protocol::CERTUPDATE, | ||||
| 		RESTAPI::Protocol::TRANSFER | ||||
| 	}; | ||||
| 		RESTAPI::Protocol::PING,		 RESTAPI::Protocol::SCRIPT}; | ||||
|  | ||||
| 	inline const char *to_string(Commands Cmd) { return uCentralAPCommands[(uint8_t)Cmd]; } | ||||
|  | ||||
|   | ||||
| @@ -3,19 +3,10 @@ | ||||
| // | ||||
|  | ||||
| #include "Poco/Path.h" | ||||
| #include "Poco/TemporaryFile.h" | ||||
| #include "Poco/Crypto/ECKey.h" | ||||
|  | ||||
| #include "framework/AppServiceRegistry.h" | ||||
| #include "framework/utils.h" | ||||
|  | ||||
| #include <iostream> | ||||
| #include <cstdlib> | ||||
| #include <ctime> | ||||
| #include <string> | ||||
| #include <algorithm> | ||||
|  | ||||
| #include <resolv.h> | ||||
|  | ||||
| namespace OpenWifi::Utils { | ||||
|  | ||||
| 	bool NormalizeMac(std::string &Mac) { | ||||
| @@ -141,15 +132,6 @@ namespace OpenWifi::Utils { | ||||
| 		return std::regex_match(Hostname, HostNameRegex); | ||||
| 	} | ||||
|  | ||||
| 	[[nodiscard]] bool ValidNumber(const std::string &number, bool isSigned) | ||||
| 	{ | ||||
| 		static std::regex IntRegex("^-?[0-9]\\d*(\\.\\d+)?$"); | ||||
| 		if(!isSigned) { | ||||
| 			IntRegex = "^[0-9]\\d*(\\.\\d+)?$"; | ||||
| 		} | ||||
| 		return std::regex_match(number, IntRegex); | ||||
| 	} | ||||
|  | ||||
| 	[[nodiscard]] std::string ToHex(const std::vector<unsigned char> &B) { | ||||
| 		std::string R; | ||||
| 		R.reserve(B.size() * 2); | ||||
| @@ -617,329 +599,4 @@ namespace OpenWifi::Utils { | ||||
| 		return DT.timestamp().epochTime(); | ||||
| 	} | ||||
|  | ||||
|     static std::string FileToString(const std::string &Filename) { | ||||
|         std::ifstream   ifs(Filename.c_str(),std::ios_base::in|std::ios_base::binary); | ||||
|         std::ostringstream os; | ||||
|         Poco::StreamCopier::copyStream(ifs,os); | ||||
|         return os.str(); | ||||
|     } | ||||
|  | ||||
|     bool CreateX509CSR(const CSRCreationParameters & Parameters, CSRCreationResults & Results) { | ||||
|         int             ret = 0; | ||||
|         RSA             *r = nullptr; | ||||
|         BIGNUM          *bne = nullptr; | ||||
|  | ||||
|         int             nVersion = 0; | ||||
|         unsigned long   e = RSA_F4; | ||||
|  | ||||
|         X509_REQ        *x509_req = nullptr; | ||||
|         X509_NAME       *x509_name = nullptr; | ||||
|         EVP_PKEY        *pKey = nullptr; | ||||
| //        RSA             *tem = nullptr; | ||||
| //        BIO             *bio_err = nullptr; | ||||
|  | ||||
|         const char      *szCountry = Parameters.Country.c_str(); | ||||
|         const char      *szProvince = Parameters.Province.c_str(); | ||||
|         const char      *szCity = Parameters.City.c_str(); | ||||
|         const char      *szOrganization = Parameters.Organization.c_str(); | ||||
|         const char      *szCommon = Parameters.CommonName.c_str(); | ||||
|  | ||||
|         Poco::TemporaryFile     CsrPath, PubKey, PrivateKey; | ||||
|         std::string             Result; | ||||
|         std::ifstream           ifs; | ||||
|         std::ostringstream      ss; | ||||
|         BIO                     *bp_public = nullptr, | ||||
|                 *bp_private = nullptr, | ||||
|                 *bp_csr = nullptr; | ||||
|  | ||||
|         // 1. generate rsa key | ||||
|         bne = BN_new(); | ||||
|         ret = BN_set_word(bne,e); | ||||
|         if(ret != 1){ | ||||
|             goto free_all; | ||||
|         } | ||||
|  | ||||
|         r = RSA_new(); | ||||
|         ret = RSA_generate_key_ex(r, Parameters.bits, bne, nullptr); | ||||
|         if(ret != 1){ | ||||
|             goto free_all; | ||||
|         } | ||||
|  | ||||
|         bp_public = BIO_new_file(PubKey.path().c_str(), "w+"); | ||||
|         ret = PEM_write_bio_RSAPublicKey(bp_public, r); | ||||
|         if(ret != 1) { | ||||
|             goto free_all; | ||||
|         } | ||||
|  | ||||
|         bp_private = BIO_new_file(PrivateKey.path().c_str(), "w+"); | ||||
|         ret = PEM_write_bio_RSAPrivateKey(bp_private, r, NULL, NULL, 0, NULL, NULL); | ||||
|         if(ret != 1) { | ||||
|             goto free_all; | ||||
|         } | ||||
|  | ||||
| // 2. set version of x509 req | ||||
|         x509_req = X509_REQ_new(); | ||||
|         ret = X509_REQ_set_version(x509_req, nVersion); | ||||
|         if (ret != 1){ | ||||
|             goto free_all; | ||||
|         } | ||||
|  | ||||
| // 3. set subject of x509 req | ||||
|         x509_name = X509_REQ_get_subject_name(x509_req); | ||||
|  | ||||
|         ret = X509_NAME_add_entry_by_txt(x509_name,"C", MBSTRING_ASC, (const unsigned char*)szCountry, -1, -1, 0); | ||||
|         if (ret != 1){ | ||||
|             goto free_all; | ||||
|         } | ||||
|  | ||||
|         ret = X509_NAME_add_entry_by_txt(x509_name,"ST", MBSTRING_ASC, (const unsigned char*)szProvince, -1, -1, 0); | ||||
|         if (ret != 1){ | ||||
|             goto free_all; | ||||
|         } | ||||
|  | ||||
|         ret = X509_NAME_add_entry_by_txt(x509_name,"L", MBSTRING_ASC, (const unsigned char*)szCity, -1, -1, 0); | ||||
|         if (ret != 1){ | ||||
|             goto free_all; | ||||
|         } | ||||
|  | ||||
|         ret = X509_NAME_add_entry_by_txt(x509_name,"O", MBSTRING_ASC, (const unsigned char*)szOrganization, -1, -1, 0); | ||||
|         if (ret != 1){ | ||||
|             goto free_all; | ||||
|         } | ||||
|  | ||||
|         ret = X509_NAME_add_entry_by_txt(x509_name,"CN", MBSTRING_ASC, (const unsigned char*)szCommon, -1, -1, 0); | ||||
|         if (ret != 1){ | ||||
|             goto free_all; | ||||
|         } | ||||
|  | ||||
| // 4. set public key of x509 req | ||||
|         pKey = EVP_PKEY_new(); | ||||
|         EVP_PKEY_assign_RSA(pKey, r); | ||||
|         r = nullptr;   // will be free rsa when EVP_PKEY_free(pKey) | ||||
|  | ||||
|         ret = X509_REQ_set_pubkey(x509_req, pKey); | ||||
|         if (ret != 1){ | ||||
|             goto free_all; | ||||
|         } | ||||
|  | ||||
| // 5. set sign key of x509 req | ||||
|         ret = X509_REQ_sign(x509_req, pKey, EVP_sha1());    // return x509_req->signature->length | ||||
|         if (ret <= 0){ | ||||
|             goto free_all; | ||||
|         } | ||||
|  | ||||
|         bp_csr = BIO_new_file(CsrPath.path().c_str(),"w"); | ||||
|         ret = PEM_write_bio_X509_REQ(bp_csr, x509_req); | ||||
|  | ||||
| // 6. free | ||||
|         free_all: | ||||
|         X509_REQ_free(x509_req); | ||||
|         BIO_free_all(bp_csr); | ||||
|         BIO_free_all(bp_public); | ||||
|         BIO_free_all(bp_private); | ||||
|  | ||||
|         EVP_PKEY_free(pKey); | ||||
|         BN_free(bne); | ||||
|         if(ret==1) { | ||||
|             Results.CSR = FileToString(CsrPath.path()); | ||||
|             Results.PrivateKey = FileToString(PrivateKey.path()); | ||||
|             Results.PublicKey = FileToString(PubKey.path()); | ||||
|         } | ||||
|  | ||||
|         return ret; | ||||
|     } | ||||
|  | ||||
|     bool VerifyECKey(const std::string &key) { | ||||
|         try { | ||||
|             Poco::TemporaryFile F; | ||||
|  | ||||
|             std::ofstream of(F.path().c_str(), std::ios_base::trunc | std::ios_base::out | std::ios_base::binary); | ||||
|             of << key; | ||||
|             of.close(); | ||||
|  | ||||
|             auto Key = Poco::SharedPtr<Poco::Crypto::ECKey>( | ||||
|                     new Poco::Crypto::ECKey("", F.path(),"")); | ||||
|  | ||||
|             return true; | ||||
|         } catch (const Poco::Exception &E) { | ||||
|  | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     bool VerifyRSAKey([[ | ||||
|     maybe_unused]] const std::string &key) { | ||||
|         try { | ||||
|             Poco::TemporaryFile F; | ||||
|  | ||||
|             std::ofstream of(F.path().c_str(), std::ios_base::trunc | std::ios_base::out | std::ios_base::binary); | ||||
|             of << key; | ||||
|             of.close(); | ||||
|  | ||||
|             auto Key = Poco::SharedPtr<Poco::Crypto::RSAKey>( | ||||
|                     new Poco::Crypto::RSAKey("", F.path(),"")); | ||||
|             return true; | ||||
|         } catch (const Poco::Exception &E) { | ||||
|  | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     bool VerifyPrivateKey(const std::string &key) { | ||||
|         return VerifyECKey(key) || VerifyRSAKey(key); | ||||
|     } | ||||
|  | ||||
|     bool ValidX509Certificate([[ | ||||
|                               maybe_unused]] const std::string &Cert) { | ||||
|         try { | ||||
|             Poco::TemporaryFile F; | ||||
|             std::ofstream of(F.path().c_str(), std::ios_base::trunc | std::ios_base::out | std::ios_base::binary); | ||||
|             of << Cert; | ||||
|             of.close(); | ||||
|  | ||||
|             auto Key = Poco::SharedPtr<Poco::Crypto::X509Certificate>( | ||||
|                     new Poco::Crypto::X509Certificate(F.path())); | ||||
|             return true; | ||||
|         } catch (const Poco::Exception &E) { | ||||
|  | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     bool ValidX509Certificate([[ | ||||
|                               maybe_unused]] const std::vector<std::string> &Certs) { | ||||
|         auto F = [](const std::string &C) -> bool { return ValidX509Certificate(C); }; | ||||
|         return std::all_of(Certs.begin(),Certs.end(), F); | ||||
|     } | ||||
|  | ||||
|     std::string generateStrongPassword(int minLength, int maxLength, int numDigits, int minLowercase, int minSpecial, int minUppercase) { | ||||
|         // Define character sets for each category | ||||
|         const std::string lowercaseChars = "abcdefghijklmnopqrstuvwxyz"; | ||||
|         const std::string uppercaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||||
|         const std::string digitChars = "0123456789"; | ||||
|         const std::string specialChars = "!@#$%^&*()_+[]{}|;:,.<>?"; | ||||
|  | ||||
|         // Check if parameters are valid | ||||
|         if (minLength < 1 || minLength > maxLength || minLowercase + minUppercase + numDigits + minSpecial > maxLength) { | ||||
|             return "Invalid parameters"; | ||||
|         } | ||||
|  | ||||
|         // Initialize random seed | ||||
|         std::random_device rd; | ||||
|         std::mt19937 g(rd()); | ||||
|  | ||||
|         // Initialize the password string | ||||
|         std::string password; | ||||
|  | ||||
|         // Generate the required number of each character type | ||||
|         for (int i = 0; i < minLowercase; ++i) { | ||||
|             password += lowercaseChars[g() % lowercaseChars.length()]; | ||||
|         } | ||||
|         for (int i = 0; i < minUppercase; ++i) { | ||||
|             password += uppercaseChars[g() % uppercaseChars.length()]; | ||||
|         } | ||||
|         for (int i = 0; i < numDigits; ++i) { | ||||
|             password += digitChars[g() % digitChars.length()]; | ||||
|         } | ||||
|         for (int i = 0; i < minSpecial; ++i) { | ||||
|             password += specialChars[g() % specialChars.length()]; | ||||
|         } | ||||
|  | ||||
|         // Calculate how many more characters are needed | ||||
|         int remainingLength = maxLength - (int)password.length(); | ||||
|  | ||||
|         // Generate random characters to fill the remaining length | ||||
|         for (int i = 0; i < remainingLength; ++i) { | ||||
|             int category = g() % 4; // Randomly select a category | ||||
|             if (category == 0) { | ||||
|                 password += lowercaseChars[g() % lowercaseChars.length()]; | ||||
|             } else if (category == 1) { | ||||
|                 password += uppercaseChars[g() % uppercaseChars.length()]; | ||||
|             } else if (category == 2) { | ||||
|                 password += digitChars[g() % digitChars.length()]; | ||||
|             } else { | ||||
|                 password += specialChars[g() % specialChars.length()]; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // Shuffle the password to randomize the character order | ||||
|         std::shuffle(password.begin(), password.end(),g); | ||||
|  | ||||
|         return password; | ||||
|     } | ||||
|  | ||||
| // Function to query NAPTR records for a domain and return them in a vector | ||||
|     std::vector<NAPTRRecord> getNAPTRRecords(const std::string& domain) { | ||||
|         std::vector<NAPTRRecord> naptrRecords; | ||||
|  | ||||
|         unsigned char buf[4096]; | ||||
|         ns_msg handle; | ||||
|         ns_initparse(buf, NS_PACKETSZ, &handle); | ||||
|  | ||||
|         // Query NAPTR records for the given domain | ||||
|         int response = res_query(domain.c_str(), ns_c_in, ns_t_naptr, buf, sizeof(buf)); | ||||
|         if (response < 0) { | ||||
|             return naptrRecords; | ||||
|         } | ||||
|  | ||||
|         if(ns_initparse(buf, response, &handle) < 0) { | ||||
|             return naptrRecords; | ||||
|         } | ||||
|  | ||||
|         // Iterate through the DNS response and extract NAPTR records | ||||
|         int count = ns_msg_count(handle, ns_s_an); | ||||
|         for (int i = 0; i < count; ++i) { | ||||
|             ns_rr rr; | ||||
|             if (ns_parserr(&handle, ns_s_an, i, &rr) == 0) { | ||||
|                 char rdata[256]; | ||||
|                 ns_sprintrr(&handle, &rr, nullptr, nullptr, rdata, sizeof(rdata)); | ||||
|                 NAPTRRecord record; | ||||
|                 std::istringstream os(rdata); | ||||
|                 os  >> record.name >> record.ttl >> record.rclass >> record.rtype >> record.order >> record.preference >> record.flags | ||||
|                     >> record.service >> record.regexp >>  record.replacement; | ||||
|                 naptrRecords.push_back(record); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return naptrRecords; | ||||
|     } | ||||
|  | ||||
|     std::vector<SrvRecord> getSRVRecords(const std::string& domain) { | ||||
|         std::vector<SrvRecord> srvRecords; | ||||
|  | ||||
|         // Buffer to hold the DNS response | ||||
|         unsigned char buf[4096]; | ||||
|         ns_msg handle; | ||||
|         ns_initparse(buf, NS_PACKETSZ, &handle); | ||||
|  | ||||
|         // Query NAPTR records for the given domain | ||||
|         int response = res_query(domain.c_str(), ns_c_in, ns_t_srv, buf, sizeof(buf)); | ||||
|         if (response < 0) { | ||||
|             std::cerr << "DNS query failed for " << domain << ": " << hstrerror(h_errno) << std::endl; | ||||
|             return srvRecords; | ||||
|         } | ||||
|  | ||||
|         if(ns_initparse(buf, response, &handle) < 0) { | ||||
|             return srvRecords; | ||||
|         } | ||||
|  | ||||
|         // Iterate through the DNS response and extract NAPTR records | ||||
|         int count = ns_msg_count(handle, ns_s_an); | ||||
|         for (int i = 0; i < count; ++i) { | ||||
|             ns_rr rr; | ||||
|             if (ns_parserr(&handle, ns_s_an, i, &rr) == 0) { | ||||
|                 char rdata[256]; | ||||
|                 ns_sprintrr(&handle, &rr, nullptr, nullptr, rdata, sizeof(rdata)); | ||||
|                 SrvRecord record; | ||||
|                 std::istringstream os(rdata); | ||||
|                 os  >>  record.name >> record.ttl >> record.rclass >> record.rtype >> record.pref >> record.weight >> | ||||
|                     record.port >> record.srvname ; | ||||
|                 srvRecords.push_back(record); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return srvRecords; | ||||
|     } | ||||
|  | ||||
|  | ||||
| } // namespace OpenWifi::Utils | ||||
|   | ||||
| @@ -13,8 +13,6 @@ | ||||
| #include <string> | ||||
| #include <thread> | ||||
|  | ||||
| #include <dirent.h> | ||||
|  | ||||
| #include "Poco/Base64Decoder.h" | ||||
| #include "Poco/Base64Encoder.h" | ||||
| #include "Poco/File.h" | ||||
| @@ -73,7 +71,6 @@ namespace OpenWifi::Utils { | ||||
| 	[[nodiscard]] bool ValidSerialNumbers(const std::vector<std::string> &Serial); | ||||
| 	[[nodiscard]] bool ValidUUID(const std::string &UUID); | ||||
| 	[[nodiscard]] bool ValidHostname(const std::string &hostname); | ||||
| 	[[nodiscard]] bool ValidNumber(const std::string &number, bool isSigned); | ||||
|  | ||||
| 	template <typename... Args> std::string ComputeHash(Args &&...args) { | ||||
| 		Poco::SHA2Engine E; | ||||
| @@ -184,222 +181,4 @@ namespace OpenWifi::Utils { | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	static inline std::uint64_t GetValue(FILE *file) { | ||||
| 		unsigned long v=0; | ||||
| 		char factor[32]; | ||||
| 		if(fscanf(file, " %lu %31s", &v, factor)==2) { | ||||
| 			switch (factor[0]) { | ||||
| 			case 'k': | ||||
| 				return v * 1000; | ||||
| 			case 'M': | ||||
| 				return v * 1000000; | ||||
| 			case 'G': | ||||
| 				return v * 1000000000; | ||||
| 			} | ||||
| 		} | ||||
| 		return v; | ||||
| 	} | ||||
|  | ||||
| 	inline bool getMemory( | ||||
| 		std::uint64_t &currRealMem, std::uint64_t &peakRealMem, | ||||
| 		std::uint64_t &currVirtMem, std::uint64_t &peakVirtMem) { | ||||
|  | ||||
| 		// stores each word in status file | ||||
| 		char buffer[1024] = ""; | ||||
|  | ||||
| 		currRealMem = peakRealMem = currVirtMem = peakVirtMem = 0; | ||||
|  | ||||
| 		// linux file contains this-process info | ||||
| 		FILE * file = std::fopen("/proc/self/status", "r"); | ||||
| 		if (file == nullptr) { | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		// read the entire file, recording mems in kB | ||||
| 		while (fscanf(file, " %1023s", buffer) == 1) { | ||||
|  | ||||
| 			if (strcmp(buffer, "VmRSS:") == 0) { | ||||
| 				currRealMem= GetValue(file); | ||||
| 			} else if (strcmp(buffer, "VmHWM:") == 0) { | ||||
| 				peakRealMem= GetValue(file); | ||||
| 			} else if (strcmp(buffer, "VmSize:") == 0) { | ||||
| 				currVirtMem= GetValue(file); | ||||
| 			} else if (strcmp(buffer, "VmPeak:") == 0) { | ||||
| 				peakVirtMem= GetValue(file); | ||||
| 			} | ||||
| 		} | ||||
| 		fclose(file); | ||||
|  | ||||
| 		return true; | ||||
| 	} | ||||
|  | ||||
| 	inline int get_open_fds() { | ||||
| 		DIR *dp = opendir("/proc/self/fd"); | ||||
| 		struct dirent *de; | ||||
| 		int count = -3; // '.', '..', dp | ||||
|  | ||||
| 		if (dp == nullptr) | ||||
| 			return -1; | ||||
| 		while ((de = readdir(dp)) != nullptr) | ||||
| 			count++; | ||||
| 		(void)closedir(dp); | ||||
|  | ||||
| 		return count; | ||||
| 	} | ||||
|  | ||||
|     inline std::uint32_t IPtoInt(const std::string &A) { | ||||
|         Poco::Net::IPAddress    IP; | ||||
|         std::uint32_t Result=0; | ||||
|  | ||||
|         if(Poco::Net::IPAddress::tryParse(A,IP)) { | ||||
|             for(const auto i:IP.toBytes()) { | ||||
|                 Result <<= 8; | ||||
|                 Result += i; | ||||
|             } | ||||
|         } | ||||
|         return Result; | ||||
|     } | ||||
|  | ||||
|     inline bool ValidIP(const std::string &IPstr) { | ||||
|         Poco::Net::IPAddress    IP; | ||||
|         return Poco::Net::IPAddress::tryParse(IPstr,IP); | ||||
|     } | ||||
|  | ||||
|     struct CSRCreationParameters { | ||||
|         std::string Country, Province, City, | ||||
|                     Organization, CommonName; | ||||
|         int         bits=2048; | ||||
|     }; | ||||
|  | ||||
|     struct CSRCreationResults { | ||||
|         std::string     CSR, PublicKey, PrivateKey; | ||||
|     }; | ||||
|  | ||||
|     bool CreateX509CSR(const CSRCreationParameters & Parameters, CSRCreationResults & Results); | ||||
|     std::string generateStrongPassword(int minLength, int maxLength, int numDigits, int minLowercase, int minSpecial, int minUppercase); | ||||
|     bool VerifyECKey(const std::string &key); | ||||
|     bool VerifyRSAKey(const std::string &key); | ||||
|     bool VerifyPrivateKey(const std::string &key); | ||||
|     bool ValidX509Certificate(const std::string &Cert); | ||||
|     bool ValidX509Certificate(const std::vector<std::string> &Certs); | ||||
|  | ||||
|     struct NAPTRRecord { | ||||
|         std::string     name; | ||||
|         std::string     ttl; | ||||
|         std::string     rclass; | ||||
|         std::string     rtype; | ||||
|         uint32_t        order=0; | ||||
|         uint32_t        preference=0; | ||||
|         std::string     flags; | ||||
|         std::string     service; | ||||
|         std::string     regexp; | ||||
|         std::string     replacement; | ||||
|     }; | ||||
|  | ||||
| // Function to query NAPTR records for a domain and return them in a vector | ||||
|     std::vector<NAPTRRecord> getNAPTRRecords(const std::string& domain); | ||||
|     struct SrvRecord { | ||||
|         std::string     name; | ||||
|         std::string     ttl; | ||||
|         std::string     rclass; | ||||
|         std::string     rtype; | ||||
|         uint32_t        pref = 0; | ||||
|         uint32_t        weight = 0; | ||||
|         uint32_t        port = 0; | ||||
|         std::string     srvname; | ||||
|     }; | ||||
|  | ||||
|     std::vector<SrvRecord> getSRVRecords(const std::string& domain); | ||||
|  | ||||
|     struct HostNameServerResult{ | ||||
|         std::string     Hostname; | ||||
|         uint32_t        Port; | ||||
|     }; | ||||
|  | ||||
| 	class CompressedString { | ||||
| 	  public: | ||||
| 		CompressedString() { | ||||
| 			DecompressedSize_ = 0; | ||||
| 		}; | ||||
|  | ||||
| 		explicit CompressedString(const std::string &Data) : DecompressedSize_(Data.size()) { | ||||
| 			CompressIt(Data); | ||||
| 		} | ||||
|  | ||||
| 		CompressedString(const CompressedString &Data) { | ||||
| 			this->DecompressedSize_ = Data.DecompressedSize_; | ||||
| 			this->CompressedData_ = Data.CompressedData_; | ||||
| 		} | ||||
|  | ||||
| 		CompressedString& operator=(const CompressedString& rhs) { | ||||
| 			if (this != &rhs) { | ||||
| 				this->DecompressedSize_ = rhs.DecompressedSize_; | ||||
| 				this->CompressedData_ = rhs.CompressedData_; | ||||
| 			} | ||||
| 			return *this; | ||||
| 		} | ||||
|  | ||||
| 		CompressedString& operator=(CompressedString&& rhs) { | ||||
| 			if (this != &rhs) { | ||||
| 				this->DecompressedSize_ = rhs.DecompressedSize_; | ||||
| 				this->CompressedData_ = rhs.CompressedData_; | ||||
| 			} | ||||
| 			return *this; | ||||
| 		} | ||||
|  | ||||
| 		~CompressedString() = default; | ||||
|  | ||||
| 		operator std::string() const { | ||||
| 			return DecompressIt(); | ||||
| 		} | ||||
|  | ||||
| 		CompressedString &operator=(const std::string &Data) { | ||||
| 			DecompressedSize_ = Data.size(); | ||||
| 			CompressIt(Data); | ||||
| 			return *this; | ||||
| 		} | ||||
|  | ||||
| 		auto CompressedSize() const { return CompressedData_.size(); } | ||||
| 		auto DecompressedSize() const { return DecompressedSize_; } | ||||
|  | ||||
| 	  private: | ||||
| 		std::string     CompressedData_; | ||||
| 		std::size_t     DecompressedSize_; | ||||
|  | ||||
| 		inline void CompressIt(const std::string &Data) { | ||||
| 			z_stream strm; // = {0}; | ||||
| 			CompressedData_.resize(Data.size()); | ||||
| 			strm.next_in = (Bytef *)Data.data(); | ||||
| 			strm.avail_in = Data.size(); | ||||
| 			strm.next_out = (Bytef *)CompressedData_.data(); | ||||
| 			strm.avail_out = Data.size(); | ||||
| 			strm.zalloc = Z_NULL; | ||||
| 			strm.zfree = Z_NULL; | ||||
| 			strm.opaque = Z_NULL; | ||||
| 			deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY); | ||||
| 			deflate(&strm, Z_FINISH); | ||||
| 			deflateEnd(&strm); | ||||
| 			CompressedData_.resize(strm.total_out); | ||||
| 		} | ||||
|  | ||||
| 		[[nodiscard]] std::string DecompressIt() const { | ||||
| 			std::string Result; | ||||
| 			if(DecompressedSize_!=0) { | ||||
| 				Result.resize(DecompressedSize_); | ||||
| 				z_stream strm ; //= {0}; | ||||
| 				strm.next_in = (Bytef *)CompressedData_.data(); | ||||
| 				strm.avail_in = CompressedData_.size(); | ||||
| 				strm.next_out = (Bytef *)Result.data(); | ||||
| 				strm.avail_out = Result.size(); | ||||
| 				strm.zalloc = Z_NULL; | ||||
| 				strm.zfree = Z_NULL; | ||||
| 				strm.opaque = Z_NULL; | ||||
| 				inflateInit2(&strm, 15 + 32); | ||||
| 				inflate(&strm, Z_FINISH); | ||||
| 				inflateEnd(&strm); | ||||
| 			} | ||||
| 			return Result; | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
| } // namespace OpenWifi::Utils | ||||
|   | ||||
		Reference in New Issue
	
	Block a user