mirror of
				https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
				synced 2025-10-31 02:37:56 +00:00 
			
		
		
		
	Compare commits
	
		
			4 Commits
		
	
	
		
			v3.0.0-RC2
			...
			release/v2
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 1f77b23024 | ||
|   | 511c53a9c0 | ||
|   | db33693157 | ||
|   | d966f53423 | 
| @@ -1,5 +1,5 @@ | |||||||
| cmake_minimum_required(VERSION 3.13) | cmake_minimum_required(VERSION 3.13) | ||||||
| project(owsec VERSION 3.0.0) | project(owsec VERSION 2.11.0) | ||||||
|  |  | ||||||
| set(CMAKE_CXX_STANDARD 17) | set(CMAKE_CXX_STANDARD 17) | ||||||
|  |  | ||||||
| @@ -185,7 +185,6 @@ if(NOT SMALL_BUILD) | |||||||
|             CppKafka::cppkafka |             CppKafka::cppkafka | ||||||
|             ${AWSSDK_LINK_LIBRARIES} |             ${AWSSDK_LINK_LIBRARIES} | ||||||
|             fmt::fmt |             fmt::fmt | ||||||
|             resolv |  | ||||||
|             ) |             ) | ||||||
|     if(UNIX AND NOT APPLE) |     if(UNIX AND NOT APPLE) | ||||||
|         target_link_libraries(owsec PUBLIC PocoJSON) |         target_link_libraries(owsec PUBLIC PocoJSON) | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ fullnameOverride: "" | |||||||
| images: | images: | ||||||
|   owsec: |   owsec: | ||||||
|     repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owsec |     repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owsec | ||||||
|     tag: v3.0.0-RC2 |     tag: v2.11.0 | ||||||
|     pullPolicy: Always |     pullPolicy: Always | ||||||
| #    regcred: | #    regcred: | ||||||
| #      registry: tip-tip-wlan-cloud-ucentral.jfrog.io | #      registry: tip-tip-wlan-cloud-ucentral.jfrog.io | ||||||
|   | |||||||
| @@ -218,7 +218,7 @@ namespace OpenWifi { | |||||||
| 				Expired = (WT.created_ + WT.expires_in_) < now; | 				Expired = (WT.created_ + WT.expires_in_) < now; | ||||||
| 				if (StorageService()->UserDB().GetUserById(UserId, UInfo.userinfo)) { | 				if (StorageService()->UserDB().GetUserById(UserId, UInfo.userinfo)) { | ||||||
| 					UInfo.webtoken = WT; | 					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))); | 													 TID, Utils::SanitizeToken(CallToken))); | ||||||
| 					return true; | 					return true; | ||||||
| 				} | 				} | ||||||
|   | |||||||
| @@ -171,31 +171,6 @@ namespace OpenWifi::GWObjects { | |||||||
| 		field_to_json(Obj, "lastModified", LastModified); | 		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 { | 	void CommandDetails::to_json(Poco::JSON::Object &Obj) const { | ||||||
| 		EmbedDocument("details", Obj, Details); | 		EmbedDocument("details", Obj, Details); | ||||||
| 		EmbedDocument("results", Obj, Results); | 		EmbedDocument("results", Obj, Results); | ||||||
| @@ -271,8 +246,6 @@ namespace OpenWifi::GWObjects { | |||||||
| 		field_to_json(Obj, "connectionCompletionTime", connectionCompletionTime); | 		field_to_json(Obj, "connectionCompletionTime", connectionCompletionTime); | ||||||
| 		field_to_json(Obj, "totalConnectionTime", Utils::Now() - started); | 		field_to_json(Obj, "totalConnectionTime", Utils::Now() - started); | ||||||
| 		field_to_json(Obj, "certificateExpiryDate", certificateExpiryDate); | 		field_to_json(Obj, "certificateExpiryDate", certificateExpiryDate); | ||||||
| 		field_to_json(Obj, "connectReason", connectReason); |  | ||||||
|  |  | ||||||
| #ifdef TIP_GATEWAY_SERVICE | #ifdef TIP_GATEWAY_SERVICE | ||||||
| 		hasRADIUSSessions = RADIUSSessionTracker()->HasSessions(SerialNumber); | 		hasRADIUSSessions = RADIUSSessionTracker()->HasSessions(SerialNumber); | ||||||
| 		AP_WS_Server()->ExtendedAttributes(SerialNumber, hasGPS, sanity, | 		AP_WS_Server()->ExtendedAttributes(SerialNumber, hasGPS, sanity, | ||||||
| @@ -430,10 +403,6 @@ namespace OpenWifi::GWObjects { | |||||||
| 		field_to_json(Obj, "acctConfig", acctConfig); | 		field_to_json(Obj, "acctConfig", acctConfig); | ||||||
| 		field_to_json(Obj, "coaConfig", coaConfig); | 		field_to_json(Obj, "coaConfig", coaConfig); | ||||||
| 		field_to_json(Obj, "useByDefault", useByDefault); | 		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) { | 	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, "acctConfig", acctConfig); | ||||||
| 			field_from_json(Obj, "coaConfig", coaConfig); | 			field_from_json(Obj, "coaConfig", coaConfig); | ||||||
| 			field_from_json(Obj, "useByDefault", useByDefault); | 			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; | 			return true; | ||||||
| 		} catch (const Poco::Exception &E) { | 		} catch (const Poco::Exception &E) { | ||||||
| 		} | 		} | ||||||
| @@ -665,50 +630,18 @@ namespace OpenWifi::GWObjects { | |||||||
| 		field_to_json(Obj, "chargeableUserIdentity", chargeableUserIdentity); | 		field_to_json(Obj, "chargeableUserIdentity", chargeableUserIdentity); | ||||||
| 		field_to_json(Obj, "interface", interface); | 		field_to_json(Obj, "interface", interface); | ||||||
| 		field_to_json(Obj, "secret", secret); | 		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 { | 	void RADIUSSessionList::to_json(Poco::JSON::Object &Obj) const { | ||||||
| 		field_to_json(Obj, "sessions", sessions); | 		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) { | 	bool RadiusCoADMParameters::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||||
| 		try { | 		try { | ||||||
| 			field_from_json(Obj, "accountingSessionId", accountingSessionId); | 			field_from_json(Obj, "accountingSessionId", accountingSessionId); | ||||||
| 			field_from_json(Obj, "accountingMultiSessionId", accountingMultiSessionId); | 			field_from_json(Obj, "accountingMultiSessionId", accountingMultiSessionId); | ||||||
| 			field_from_json(Obj, "callingStationId", callingStationId); | 			field_from_json(Obj, "callingStationId", callingStationId); | ||||||
| 			field_from_json(Obj, "chargeableUserIdentity", chargeableUserIdentity); | 			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; | 			return true; | ||||||
| 		} catch (const Poco::Exception &E) { | 		} catch (const Poco::Exception &E) { | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -42,13 +42,12 @@ namespace OpenWifi::GWObjects { | |||||||
| 		uint64_t sessionId = 0; | 		uint64_t sessionId = 0; | ||||||
| 		double connectionCompletionTime = 0.0; | 		double connectionCompletionTime = 0.0; | ||||||
| 		std::uint64_t certificateExpiryDate = 0; | 		std::uint64_t certificateExpiryDate = 0; | ||||||
| 		std::uint64_t hasRADIUSSessions = 0; | 		bool hasRADIUSSessions = false; | ||||||
| 		bool hasGPS = false; | 		bool hasGPS = false; | ||||||
| 		std::uint64_t sanity=0; | 		std::uint64_t sanity=0; | ||||||
| 		std::double_t memoryUsed=0.0; | 		std::double_t memoryUsed=0.0; | ||||||
| 		std::double_t load=0.0; | 		std::double_t load=0.0; | ||||||
| 		std::double_t temperature=0.0; | 		std::double_t temperature=0.0; | ||||||
| 		std::string 	connectReason; |  | ||||||
|  |  | ||||||
| 		void to_json(const std::string &SerialNumber, Poco::JSON::Object &Obj) ; | 		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); | 		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 { | 	struct CommandDetails { | ||||||
| 		std::string UUID; | 		std::string UUID; | ||||||
| 		std::string SerialNumber; | 		std::string SerialNumber; | ||||||
| @@ -360,10 +339,6 @@ namespace OpenWifi::GWObjects { | |||||||
| 		RadiusProxyServerConfig acctConfig; | 		RadiusProxyServerConfig acctConfig; | ||||||
| 		RadiusProxyServerConfig coaConfig; | 		RadiusProxyServerConfig coaConfig; | ||||||
| 		bool useByDefault = false; | 		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; | 		void to_json(Poco::JSON::Object &Obj) const; | ||||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||||
| @@ -418,8 +393,7 @@ namespace OpenWifi::GWObjects { | |||||||
| 					 			callingStationId, | 					 			callingStationId, | ||||||
| 								chargeableUserIdentity, | 								chargeableUserIdentity, | ||||||
| 								secret, | 								secret, | ||||||
| 								interface, | 								interface; | ||||||
| 								nasId; |  | ||||||
| 		std::uint64_t 			inputPackets = 0, | 		std::uint64_t 			inputPackets = 0, | ||||||
| 								outputPackets = 0, | 								outputPackets = 0, | ||||||
| 								inputOctets = 0, | 								inputOctets = 0, | ||||||
| @@ -427,7 +401,6 @@ namespace OpenWifi::GWObjects { | |||||||
| 								inputGigaWords = 0, | 								inputGigaWords = 0, | ||||||
| 								outputGigaWords = 0; | 								outputGigaWords = 0; | ||||||
| 		std::uint32_t 			sessionTime = 0; | 		std::uint32_t 			sessionTime = 0; | ||||||
| 		std::string 			calledStationId; |  | ||||||
|  |  | ||||||
| #ifdef TIP_GATEWAY_SERVICE | #ifdef TIP_GATEWAY_SERVICE | ||||||
| 		RADIUS::RadiusPacket	accountingPacket; | 		RADIUS::RadiusPacket	accountingPacket; | ||||||
| @@ -445,68 +418,7 @@ namespace OpenWifi::GWObjects { | |||||||
| 		std::string 			accountingSessionId, | 		std::string 			accountingSessionId, | ||||||
| 								accountingMultiSessionId, | 								accountingMultiSessionId, | ||||||
| 								callingStationId, | 								callingStationId, | ||||||
| 								chargeableUserIdentity, | 								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; |  | ||||||
|  |  | ||||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||||
| 	}; | 	}; | ||||||
|   | |||||||
| @@ -78,22 +78,21 @@ namespace OpenWifi::OWLSObjects { | |||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|     void SimulationStatus::to_json(Poco::JSON::Object &Obj) const { | 	void SimulationStatus::to_json(Poco::JSON::Object &Obj) const { | ||||||
|         field_to_json(Obj, "id", id); | 		field_to_json(Obj, "id", id); | ||||||
|         field_to_json(Obj, "simulationId", simulationId); | 		field_to_json(Obj, "simulationId", simulationId); | ||||||
|         field_to_json(Obj, "state", state); | 		field_to_json(Obj, "state", state); | ||||||
|         field_to_json(Obj, "tx", tx); | 		field_to_json(Obj, "tx", tx); | ||||||
|         field_to_json(Obj, "rx", rx); | 		field_to_json(Obj, "rx", rx); | ||||||
|         field_to_json(Obj, "msgsTx", msgsTx); | 		field_to_json(Obj, "msgsTx", msgsTx); | ||||||
|         field_to_json(Obj, "msgsRx", msgsRx); | 		field_to_json(Obj, "msgsRx", msgsRx); | ||||||
|         field_to_json(Obj, "liveDevices", liveDevices); | 		field_to_json(Obj, "liveDevices", liveDevices); | ||||||
|         field_to_json(Obj, "timeToFullDevices", timeToFullDevices); | 		field_to_json(Obj, "timeToFullDevices", timeToFullDevices); | ||||||
|         field_to_json(Obj, "startTime", startTime); | 		field_to_json(Obj, "startTime", startTime); | ||||||
|         field_to_json(Obj, "endTime", endTime); | 		field_to_json(Obj, "endTime", endTime); | ||||||
|         field_to_json(Obj, "errorDevices", errorDevices); | 		field_to_json(Obj, "errorDevices", errorDevices); | ||||||
|         field_to_json(Obj, "owner", owner); | 		field_to_json(Obj, "owner", owner); | ||||||
|         field_to_json(Obj, "expectedDevices", expectedDevices); | 	} | ||||||
|     } |  | ||||||
|  |  | ||||||
| 	void Dashboard::to_json([[maybe_unused]] Poco::JSON::Object &Obj) const {} | 	void Dashboard::to_json([[maybe_unused]] Poco::JSON::Object &Obj) const {} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -43,24 +43,23 @@ namespace OpenWifi::OWLSObjects { | |||||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|     struct SimulationStatus { | 	struct SimulationStatus { | ||||||
|         std::string id; | 		std::string id; | ||||||
|         std::string simulationId; | 		std::string simulationId; | ||||||
|         std::string state; | 		std::string state; | ||||||
|         uint64_t tx; | 		uint64_t tx; | ||||||
|         uint64_t rx; | 		uint64_t rx; | ||||||
|         uint64_t msgsTx; | 		uint64_t msgsTx; | ||||||
|         uint64_t msgsRx; | 		uint64_t msgsRx; | ||||||
|         uint64_t liveDevices; | 		uint64_t liveDevices; | ||||||
|         uint64_t timeToFullDevices; | 		uint64_t timeToFullDevices; | ||||||
|         uint64_t startTime; | 		uint64_t startTime; | ||||||
|         uint64_t endTime; | 		uint64_t endTime; | ||||||
|         uint64_t errorDevices; | 		uint64_t errorDevices; | ||||||
|         std::string owner; | 		std::string owner; | ||||||
|         uint64_t expectedDevices; |  | ||||||
|  |  | ||||||
|         void to_json(Poco::JSON::Object &Obj) const; | 		void to_json(Poco::JSON::Object &Obj) const; | ||||||
|     }; | 	}; | ||||||
|  |  | ||||||
| 	struct Dashboard { | 	struct Dashboard { | ||||||
| 		int O; | 		int O; | ||||||
|   | |||||||
| @@ -1194,243 +1194,4 @@ namespace OpenWifi::ProvObjects { | |||||||
| 		return false; | 		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 | } // namespace OpenWifi::ProvObjects | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -11,12 +11,10 @@ | |||||||
|  |  | ||||||
| #include "Poco/File.h" | #include "Poco/File.h" | ||||||
| #include "Poco/StreamCopier.h" | #include "Poco/StreamCopier.h" | ||||||
| #include "Poco/JSON/Object.h" |  | ||||||
| #include "Poco/JSON/Parser.h" |  | ||||||
|  |  | ||||||
| #include "framework/MicroServiceFuncs.h" | #include "framework/MicroServiceFuncs.h" | ||||||
|  |  | ||||||
| // #include "nlohmann/json.hpp" | #include "nlohmann/json.hpp" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace OpenWifi { | ||||||
|  |  | ||||||
| @@ -30,11 +28,11 @@ namespace OpenWifi { | |||||||
| 				if (F.exists()) { | 				if (F.exists()) { | ||||||
| 					std::ostringstream OS; | 					std::ostringstream OS; | ||||||
| 					std::ifstream IF(FileName); | 					std::ifstream IF(FileName); | ||||||
|                     Poco::JSON::Parser  P; | 					Poco::StreamCopier::copyStream(IF, OS); | ||||||
| 					Registry_ = P.parse(IF).extract<Poco::JSON::Object::Ptr>(); | 					Registry_ = nlohmann::json::parse(OS.str()); | ||||||
| 				} | 				} | ||||||
| 			} catch (...) { | 			} catch (...) { | ||||||
| 				Registry_ = Poco::makeShared<Poco::JSON::Object>(); | 				Registry_ = nlohmann::json::parse("{}"); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -46,47 +44,54 @@ namespace OpenWifi { | |||||||
| 		inline ~AppServiceRegistry() { Save(); } | 		inline ~AppServiceRegistry() { Save(); } | ||||||
|  |  | ||||||
| 		inline void Save() { | 		inline void Save() { | ||||||
|  | 			std::istringstream IS(to_string(Registry_)); | ||||||
| 			std::ofstream OF; | 			std::ofstream OF; | ||||||
| 			OF.open(FileName, std::ios::binary | std::ios::trunc); | 			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) { | 		inline void Set(const char *Key, uint64_t Value) { | ||||||
|             Poco::JSON::Array   Arr; | 			Registry_[Key] = Value; | ||||||
|             for(const auto &s:V) { |  | ||||||
|                 Arr.add(s); |  | ||||||
|             } |  | ||||||
|             Registry_->set(key,Arr); |  | ||||||
|             Save(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         template<class T> void Set(const char *key, const T &Value) { |  | ||||||
|             Registry_->set(key,Value); |  | ||||||
| 			Save(); | 			Save(); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|         bool Get(const char *key, std::vector<std::string> &Value) { | 		inline void Set(const char *Key, const std::string &Value) { | ||||||
|             if(Registry_->has(key) && !Registry_->isNull(key) && Registry_->isArray(key)) { | 			Registry_[Key] = Value; | ||||||
|                 auto Arr = Registry_->get(key); | 			Save(); | ||||||
|                 for(const auto &v:Arr) { | 		} | ||||||
|                     Value.emplace_back(v); |  | ||||||
|                 } |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         template<class T> bool Get(const char *key, T &Value) { | 		inline void Set(const char *Key, bool Value) { | ||||||
|             if(Registry_->has(key) && !Registry_->isNull(key)) { | 			Registry_[Key] = Value; | ||||||
|                 Value = Registry_->getValue<T>(key); | 			Save(); | ||||||
|                 return true; | 		} | ||||||
|             } |  | ||||||
|             return false; | 		inline bool Get(const char *Key, bool &Value) { | ||||||
|         } | 			if (Registry_[Key].is_boolean()) { | ||||||
|  | 				Value = Registry_[Key].get<bool>(); | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
|  | 			return false; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		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; | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 	  private: | 	  private: | ||||||
| 		std::string FileName; | 		std::string FileName; | ||||||
| 		Poco::JSON::Object::Ptr Registry_; | 		nlohmann::json Registry_; | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	inline auto AppServiceRegistry() { return AppServiceRegistry::instance(); } | 	inline auto AppServiceRegistry() { return AppServiceRegistry::instance(); } | ||||||
|   | |||||||
| @@ -9,6 +9,8 @@ | |||||||
|  |  | ||||||
| namespace OpenWifi { | namespace OpenWifi { | ||||||
|  |  | ||||||
|  | 	EventBusManager::EventBusManager(Poco::Logger &L) : Logger_(L) {} | ||||||
|  |  | ||||||
| 	void EventBusManager::run() { | 	void EventBusManager::run() { | ||||||
| 		Running_ = true; | 		Running_ = true; | ||||||
| 		Utils::SetThreadName("fmwk:EventMgr"); | 		Utils::SetThreadName("fmwk:EventMgr"); | ||||||
|   | |||||||
| @@ -12,16 +12,6 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 	class EventBusManager : public Poco::Runnable { | 	class EventBusManager : public Poco::Runnable { | ||||||
| 	  public: | 	  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); | 		explicit EventBusManager(Poco::Logger &L); | ||||||
| 		void run() final; | 		void run() final; | ||||||
| 		void Start(); | 		void Start(); | ||||||
| @@ -34,6 +24,4 @@ namespace OpenWifi { | |||||||
| 		Poco::Logger &Logger_; | 		Poco::Logger &Logger_; | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	inline auto EventBusManager() { return EventBusManager::instance(); } |  | ||||||
|  |  | ||||||
| } // namespace OpenWifi | } // namespace OpenWifi | ||||||
|   | |||||||
| @@ -307,8 +307,10 @@ namespace OpenWifi { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	[[nodiscard]] std::string KafkaManager::WrapSystemId(const std::string & PayLoad) { | 	[[nodiscard]] std::string KafkaManager::WrapSystemId(const std::string & PayLoad) { | ||||||
| 		return fmt::format(	R"lit({{ "system" : {{ "id" : {}, "host" : "{}" }}, "payload" : {} }})lit", | 		return fmt::format(	R"lit({{ "system" : {{ "id" : {}, | ||||||
| 						   MicroServiceID(), MicroServicePrivateEndPoint(), PayLoad ) ; | 									"host" : "{}" }}, | ||||||
|  | 									"payload" : {} }})lit", MicroServiceID(), | ||||||
|  | 						   				MicroServicePrivateEndPoint(), PayLoad ) ; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	void KafkaManager::PartitionAssignment(const cppkafka::TopicPartitionList &partitions) { | 	void KafkaManager::PartitionAssignment(const cppkafka::TopicPartitionList &partitions) { | ||||||
|   | |||||||
| @@ -20,7 +20,6 @@ namespace OpenWifi::KafkaTopics { | |||||||
| 	inline const char * DEVICE_EVENT_QUEUE = "device_event_queue"; | 	inline const char * DEVICE_EVENT_QUEUE = "device_event_queue"; | ||||||
| 	inline const char * DEVICE_TELEMETRY = "device_telemetry"; | 	inline const char * DEVICE_TELEMETRY = "device_telemetry"; | ||||||
| 	inline const char * PROVISIONING_CHANGE = "provisioning_change"; | 	inline const char * PROVISIONING_CHANGE = "provisioning_change"; | ||||||
| 	inline const char * RRM = "rrm"; |  | ||||||
|  |  | ||||||
| 	namespace ServiceEvents { | 	namespace ServiceEvents { | ||||||
| 		inline const char * EVENT_JOIN = "join"; | 		inline const char * EVENT_JOIN = "join"; | ||||||
|   | |||||||
| @@ -33,23 +33,9 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 	void MicroService::Exit(int Reason) { std::exit(Reason); } | 	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, | 	void MicroService::BusMessageReceived([[maybe_unused]] const std::string &Key, | ||||||
| 										  const std::string &Payload) { | 										  const std::string &Payload) { | ||||||
| 		std::lock_guard G(InfraMutex_); | 		std::lock_guard G(InfraMutex_); | ||||||
|  |  | ||||||
| 		Poco::Logger &BusLogger = EventBusManager()->Logger(); |  | ||||||
|  |  | ||||||
| 		try { | 		try { | ||||||
| 			Poco::JSON::Parser P; | 			Poco::JSON::Parser P; | ||||||
| 			auto Object = P.parse(Payload).extract<Poco::JSON::Object::Ptr>(); | 			auto Object = P.parse(Payload).extract<Poco::JSON::Object::Ptr>(); | ||||||
| @@ -69,10 +55,13 @@ namespace OpenWifi { | |||||||
| 							Object->has(KafkaTopics::ServiceEvents::Fields::KEY)) { | 							Object->has(KafkaTopics::ServiceEvents::Fields::KEY)) { | ||||||
| 							auto PrivateEndPoint = | 							auto PrivateEndPoint = | ||||||
| 								Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE).toString(); | 								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); | 								Services_.erase(PrivateEndPoint); | ||||||
| 								poco_information( | 								poco_debug( | ||||||
| 									BusLogger, | 									logger(), | ||||||
| 									fmt::format( | 									fmt::format( | ||||||
| 										"Service {} ID={} leaving system.", | 										"Service {} ID={} leaving system.", | ||||||
| 										Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE) | 										Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE) | ||||||
| @@ -80,7 +69,14 @@ namespace OpenWifi { | |||||||
| 										ID)); | 										ID)); | ||||||
| 							} else if (Event == KafkaTopics::ServiceEvents::EVENT_JOIN || | 							} else if (Event == KafkaTopics::ServiceEvents::EVENT_JOIN || | ||||||
| 									   Event == KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE) { | 									   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, | 									.Id = ID, | ||||||
| 									.Type = Poco::toLower( | 									.Type = Poco::toLower( | ||||||
| 										Object->get(KafkaTopics::ServiceEvents::Fields::TYPE) | 										Object->get(KafkaTopics::ServiceEvents::Fields::TYPE) | ||||||
| @@ -98,46 +94,20 @@ namespace OpenWifi { | |||||||
| 												   .toString(), | 												   .toString(), | ||||||
| 									.LastUpdate = Utils::Now()}; | 									.LastUpdate = Utils::Now()}; | ||||||
|  |  | ||||||
|                                 auto s1 = MakeServiceListString(Services_); | 								std::string SvcList; | ||||||
| 								auto PreviousSize = Services_.size(); | 								for (const auto &Svc : Services_) { | ||||||
| 								Services_[PrivateEndPoint] = ServiceInfo; | 									if (SvcList.empty()) | ||||||
| 								auto CurrentSize = Services_.size(); | 										SvcList = Svc.second.Type; | ||||||
| 								if(Event == KafkaTopics::ServiceEvents::EVENT_JOIN) { | 									else | ||||||
| 									if(!s1.empty()) { | 										SvcList += ", " + Svc.second.Type; | ||||||
| 										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()) |  | ||||||
| 											SvcList = Svc.second.Type; |  | ||||||
| 										else |  | ||||||
| 											SvcList += ", " + Svc.second.Type; |  | ||||||
| 									} |  | ||||||
| 									poco_information( |  | ||||||
| 										BusLogger, |  | ||||||
| 										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)); |  | ||||||
| 								} | 								} | ||||||
|  | 								poco_information( | ||||||
|  | 									logger(), | ||||||
|  | 									fmt::format("Current list of microservices: {}", SvcList)); | ||||||
| 							} | 							} | ||||||
| 						} else { | 						} else { | ||||||
| 							poco_information( | 							poco_error( | ||||||
| 								BusLogger, | 								logger(), | ||||||
| 								fmt::format("KAFKA-MSG: invalid event '{}', missing a field.", | 								fmt::format("KAFKA-MSG: invalid event '{}', missing a field.", | ||||||
| 											Event)); | 											Event)); | ||||||
| 						} | 						} | ||||||
| @@ -148,39 +118,32 @@ namespace OpenWifi { | |||||||
| 								Object->get(KafkaTopics::ServiceEvents::Fields::TOKEN).toString()); | 								Object->get(KafkaTopics::ServiceEvents::Fields::TOKEN).toString()); | ||||||
| #endif | #endif | ||||||
| 						} else { | 						} else { | ||||||
| 							poco_information( | 							poco_error( | ||||||
| 								BusLogger, | 								logger(), | ||||||
| 								fmt::format("KAFKA-MSG: invalid event '{}', missing token", Event)); | 								fmt::format("KAFKA-MSG: invalid event '{}', missing token", Event)); | ||||||
| 						} | 						} | ||||||
| 					} else { | 					} else { | ||||||
| 						poco_information(BusLogger, | 						poco_error(logger(), | ||||||
| 								   fmt::format("Unknown Event: {} Source: {}", Event, ID)); | 								   fmt::format("Unknown Event: {} Source: {}", Event, ID)); | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			} else { | 			} else { | ||||||
| 				std::ostringstream os; | 				poco_error(logger(), "Bad bus message."); | ||||||
| 				Object->stringify(std::cout); |                 std::ostringstream os; | ||||||
| 				poco_error(BusLogger, fmt::format("Bad bus message: {}", os.str())); |                 Object->stringify(std::cout); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			auto ServiceHint = Services_.begin(); | 			auto i = Services_.begin(); | ||||||
| 			auto now = Utils::Now(); | 			auto now = Utils::Now(); | ||||||
|             auto si1 = Services_.size(); | 			for (; i != Services_.end();) { | ||||||
|             auto ss1 = MakeServiceListString(Services_); | 				if ((now - i->second.LastUpdate) > 60) { | ||||||
| 			while(ServiceHint!=Services_.end()) { | 					i = Services_.erase(i); | ||||||
| 				if ((now - ServiceHint->second.LastUpdate) > 120) { |  | ||||||
| 					poco_information(BusLogger, fmt::format("ZombieService: Removing service {}, ", ServiceHint->second.PublicEndPoint)); |  | ||||||
| 					ServiceHint = Services_.erase(ServiceHint); |  | ||||||
| 				} else | 				} else | ||||||
| 					++ServiceHint; | 					++i; | ||||||
| 			} | 			} | ||||||
|             if(Services_.size() != si1) { |  | ||||||
|                 auto ss2 = MakeServiceListString(Services_); |  | ||||||
|                 poco_information(BusLogger, fmt::format("Current list of microservices: {} -> {}", ss1, ss2)); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
| 		} catch (const Poco::Exception &E) { | 		} catch (const Poco::Exception &E) { | ||||||
| 			BusLogger.log(E); | 			logger().log(E); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -449,7 +412,7 @@ namespace OpenWifi { | |||||||
| 			try { | 			try { | ||||||
| 				DataDir.createDirectory(); | 				DataDir.createDirectory(); | ||||||
| 			} catch (const Poco::Exception &E) { | 			} catch (const Poco::Exception &E) { | ||||||
| 				Logger_.log(E); | 				logger().log(E); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		WWWAssetsDir_ = ConfigPath("openwifi.restapi.wwwassets", ""); | 		WWWAssetsDir_ = ConfigPath("openwifi.restapi.wwwassets", ""); | ||||||
| @@ -567,12 +530,14 @@ namespace OpenWifi { | |||||||
| 		for (auto i : SubSystems_) { | 		for (auto i : SubSystems_) { | ||||||
| 			i->Start(); | 			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() { | 	void MicroService::StopSubSystemServers() { | ||||||
| 		AddActivity("Stopping"); | 		AddActivity("Stopping"); | ||||||
| 		EventBusManager()->Stop(); | 		EventBusManager_->Stop(); | ||||||
| 		for (auto i = SubSystems_.rbegin(); i != SubSystems_.rend(); ++i) { | 		for (auto i = SubSystems_.rbegin(); i != SubSystems_.rend(); ++i) { | ||||||
| 			(*i)->Stop(); | 			(*i)->Stop(); | ||||||
| 		} | 		} | ||||||
| @@ -732,7 +697,7 @@ namespace OpenWifi { | |||||||
| 			auto APIKEY = Request.get("X-API-KEY"); | 			auto APIKEY = Request.get("X-API-KEY"); | ||||||
| 			return APIKEY == MyHash_; | 			return APIKEY == MyHash_; | ||||||
| 		} catch (const Poco::Exception &E) { | 		} catch (const Poco::Exception &E) { | ||||||
| 			Logger_.log(E); | 			logger().log(E); | ||||||
| 		} | 		} | ||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -201,6 +201,7 @@ namespace OpenWifi { | |||||||
| 		Poco::JWT::Signer Signer_; | 		Poco::JWT::Signer Signer_; | ||||||
| 		Poco::Logger &Logger_; | 		Poco::Logger &Logger_; | ||||||
| 		Poco::ThreadPool TimerPool_{"timer:pool", 2, 32}; | 		Poco::ThreadPool TimerPool_{"timer:pool", 2, 32}; | ||||||
|  | 		std::unique_ptr<EventBusManager> EventBusManager_; | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	inline MicroService *MicroService::instance_ = nullptr; | 	inline MicroService *MicroService::instance_ = nullptr; | ||||||
|   | |||||||
| @@ -129,8 +129,4 @@ namespace OpenWifi { | |||||||
| 		return ALBHealthCheckServer()->RegisterExtendedHealthMessage(Callback); | 		return ALBHealthCheckServer()->RegisterExtendedHealthMessage(Callback); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	std::string MicroServiceAccessKey() { |  | ||||||
| 		return MicroService::instance().Hash(); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| } // namespace OpenWifi | } // namespace OpenWifi | ||||||
|   | |||||||
| @@ -22,7 +22,6 @@ namespace OpenWifi { | |||||||
| 	std::string MicroServicePublicEndPoint(); | 	std::string MicroServicePublicEndPoint(); | ||||||
| 	std::string MicroServiceConfigGetString(const std::string &Key, | 	std::string MicroServiceConfigGetString(const std::string &Key, | ||||||
| 											const std::string &DefaultValue); | 											const std::string &DefaultValue); | ||||||
| 	std::string MicroServiceAccessKey(); |  | ||||||
| 	bool MicroServiceConfigGetBool(const std::string &Key, bool DefaultValue); | 	bool MicroServiceConfigGetBool(const std::string &Key, bool DefaultValue); | ||||||
| 	std::uint64_t MicroServiceConfigGetInt(const std::string &Key, std::uint64_t DefaultValue); | 	std::uint64_t MicroServiceConfigGetInt(const std::string &Key, std::uint64_t DefaultValue); | ||||||
| 	std::string MicroServicePrivateEndPoint(); | 	std::string MicroServicePrivateEndPoint(); | ||||||
|   | |||||||
| @@ -47,8 +47,6 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
| 		Poco::Data::SessionPool &Pool() { return *Pool_; } |  | ||||||
|  |  | ||||||
| 	  private: | 	  private: | ||||||
| 		inline int Setup_SQLite(); | 		inline int Setup_SQLite(); | ||||||
| 		inline int Setup_MySQL(); | 		inline int Setup_MySQL(); | ||||||
|   | |||||||
| @@ -576,8 +576,8 @@ namespace ORM { | |||||||
| 		bool UpdateRecord(field_name_t FieldName, const T &Value, const RecordType &R) { | 		bool UpdateRecord(field_name_t FieldName, const T &Value, const RecordType &R) { | ||||||
| 			try { | 			try { | ||||||
| 				assert(ValidFieldName(FieldName)); | 				assert(ValidFieldName(FieldName)); | ||||||
|  |  | ||||||
| 				Poco::Data::Session Session = Pool_.get(); | 				Poco::Data::Session Session = Pool_.get(); | ||||||
|                 Session.begin(); |  | ||||||
| 				Poco::Data::Statement Update(Session); | 				Poco::Data::Statement Update(Session); | ||||||
|  |  | ||||||
| 				RecordTuple RT; | 				RecordTuple RT; | ||||||
| @@ -593,7 +593,6 @@ namespace ORM { | |||||||
| 				Update.execute(); | 				Update.execute(); | ||||||
| 				if (Cache_) | 				if (Cache_) | ||||||
| 					Cache_->UpdateCache(R); | 					Cache_->UpdateCache(R); | ||||||
|                 Session.commit(); |  | ||||||
| 				return true; | 				return true; | ||||||
| 			} catch (const Poco::Exception &E) { | 			} catch (const Poco::Exception &E) { | ||||||
| 				Logger_.log(E); | 				Logger_.log(E); | ||||||
| @@ -663,7 +662,6 @@ namespace ORM { | |||||||
| 				assert(ValidFieldName(FieldName)); | 				assert(ValidFieldName(FieldName)); | ||||||
|  |  | ||||||
| 				Poco::Data::Session Session = Pool_.get(); | 				Poco::Data::Session Session = Pool_.get(); | ||||||
|                 Session.begin(); |  | ||||||
| 				Poco::Data::Statement Delete(Session); | 				Poco::Data::Statement Delete(Session); | ||||||
|  |  | ||||||
| 				std::string St = "delete from " + TableName_ + " where " + FieldName + "=?"; | 				std::string St = "delete from " + TableName_ + " where " + FieldName + "=?"; | ||||||
| @@ -673,7 +671,6 @@ namespace ORM { | |||||||
| 				Delete.execute(); | 				Delete.execute(); | ||||||
| 				if (Cache_) | 				if (Cache_) | ||||||
| 					Cache_->Delete(FieldName, Value); | 					Cache_->Delete(FieldName, Value); | ||||||
|                 Session.commit(); |  | ||||||
| 				return true; | 				return true; | ||||||
| 			} catch (const Poco::Exception &E) { | 			} catch (const Poco::Exception &E) { | ||||||
| 				Logger_.log(E); | 				Logger_.log(E); | ||||||
| @@ -685,13 +682,11 @@ namespace ORM { | |||||||
| 			try { | 			try { | ||||||
| 				assert(!WhereClause.empty()); | 				assert(!WhereClause.empty()); | ||||||
| 				Poco::Data::Session Session = Pool_.get(); | 				Poco::Data::Session Session = Pool_.get(); | ||||||
|                 Session.begin(); |  | ||||||
| 				Poco::Data::Statement Delete(Session); | 				Poco::Data::Statement Delete(Session); | ||||||
|  |  | ||||||
| 				std::string St = "delete from " + TableName_ + " where " + WhereClause; | 				std::string St = "delete from " + TableName_ + " where " + WhereClause; | ||||||
| 				Delete << St; | 				Delete << St; | ||||||
| 				Delete.execute(); | 				Delete.execute(); | ||||||
|                 Session.commit(); |  | ||||||
| 				return true; | 				return true; | ||||||
| 			} catch (const Poco::Exception &E) { | 			} catch (const Poco::Exception &E) { | ||||||
| 				Logger_.log(E); | 				Logger_.log(E); | ||||||
|   | |||||||
| @@ -414,24 +414,10 @@ namespace OpenWifi::RESTAPI::Errors { | |||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     static const struct msg DefFirmwareNameExists { 1175, "Firmware name already exists." }; |     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 NotAValidECKey { 1176, "Not a valid Signing Key." }; | ||||||
|  |  | ||||||
|  | 	static const struct msg NotAValidRadiusPoolType { 1177, "Not a valid RADIUS pool type." }; | ||||||
|  |  | ||||||
|     static const struct msg SimulationDoesNotExist { |     static const struct msg SimulationDoesNotExist { | ||||||
|         7000, "Simulation Instance ID does not exist." |         7000, "Simulation Instance ID does not exist." | ||||||
| @@ -563,10 +549,6 @@ namespace OpenWifi::RESTAPI::Protocol { | |||||||
| 	static const char *CONTENTDISPOSITION = "Content-Disposition"; | 	static const char *CONTENTDISPOSITION = "Content-Disposition"; | ||||||
| 	static const char *CONTENTTYPE = "Content-Type"; | 	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 *REQUIREMENTS = "requirements"; | ||||||
| 	static const char *PASSWORDPATTERN = "passwordPattern"; | 	static const char *PASSWORDPATTERN = "passwordPattern"; | ||||||
| 	static const char *ACCESSPOLICY = "accessPolicy"; | 	static const char *ACCESSPOLICY = "accessPolicy"; | ||||||
| @@ -684,12 +666,6 @@ namespace OpenWifi::uCentralProtocol { | |||||||
| 	static const char *RADIUSCOA = "coa"; | 	static const char *RADIUSCOA = "coa"; | ||||||
| 	static const char *RADIUSDST = "dst"; | 	static const char *RADIUSDST = "dst"; | ||||||
| 	static const char *IES = "ies"; | 	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 | ||||||
|  |  | ||||||
| namespace OpenWifi::uCentralProtocol::Events { | namespace OpenWifi::uCentralProtocol::Events { | ||||||
| @@ -782,9 +758,6 @@ namespace OpenWifi::APCommands { | |||||||
| 		telemetry, | 		telemetry, | ||||||
| 		ping, | 		ping, | ||||||
| 		script, | 		script, | ||||||
| 		rrm, |  | ||||||
| 		certupdate, |  | ||||||
| 		transfer, |  | ||||||
| 		unknown | 		unknown | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| @@ -797,10 +770,7 @@ namespace OpenWifi::APCommands { | |||||||
| 		RESTAPI::Protocol::LEDS,		 RESTAPI::Protocol::TRACE, | 		RESTAPI::Protocol::LEDS,		 RESTAPI::Protocol::TRACE, | ||||||
| 		RESTAPI::Protocol::REQUEST,		 RESTAPI::Protocol::WIFISCAN, | 		RESTAPI::Protocol::REQUEST,		 RESTAPI::Protocol::WIFISCAN, | ||||||
| 		RESTAPI::Protocol::EVENTQUEUE,	 RESTAPI::Protocol::TELEMETRY, | 		RESTAPI::Protocol::EVENTQUEUE,	 RESTAPI::Protocol::TELEMETRY, | ||||||
| 		RESTAPI::Protocol::PING,		 RESTAPI::Protocol::SCRIPT, | 		RESTAPI::Protocol::PING,		 RESTAPI::Protocol::SCRIPT}; | ||||||
| 		RESTAPI::Protocol::RRM,		 	 RESTAPI::Protocol::CERTUPDATE, |  | ||||||
| 		RESTAPI::Protocol::TRANSFER |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| 	inline const char *to_string(Commands Cmd) { return uCentralAPCommands[(uint8_t)Cmd]; } | 	inline const char *to_string(Commands Cmd) { return uCentralAPCommands[(uint8_t)Cmd]; } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -14,8 +14,6 @@ | |||||||
| #include <string> | #include <string> | ||||||
| #include <algorithm> | #include <algorithm> | ||||||
|  |  | ||||||
| #include <resolv.h> |  | ||||||
|  |  | ||||||
| namespace OpenWifi::Utils { | namespace OpenWifi::Utils { | ||||||
|  |  | ||||||
| 	bool NormalizeMac(std::string &Mac) { | 	bool NormalizeMac(std::string &Mac) { | ||||||
| @@ -785,10 +783,6 @@ namespace OpenWifi::Utils { | |||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     bool VerifyPrivateKey(const std::string &key) { |  | ||||||
|         return VerifyECKey(key) || VerifyRSAKey(key); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     bool ValidX509Certificate([[ |     bool ValidX509Certificate([[ | ||||||
|                               maybe_unused]] const std::string &Cert) { |                               maybe_unused]] const std::string &Cert) { | ||||||
|         try { |         try { | ||||||
| @@ -868,78 +862,4 @@ namespace OpenWifi::Utils { | |||||||
|         return password; |         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 | } // namespace OpenWifi::Utils | ||||||
|   | |||||||
| @@ -247,24 +247,6 @@ namespace OpenWifi::Utils { | |||||||
| 		return count; | 		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 { |     struct CSRCreationParameters { | ||||||
|         std::string Country, Province, City, |         std::string Country, Province, City, | ||||||
|                     Organization, CommonName; |                     Organization, CommonName; | ||||||
| @@ -279,127 +261,7 @@ namespace OpenWifi::Utils { | |||||||
|     std::string generateStrongPassword(int minLength, int maxLength, int numDigits, int minLowercase, int minSpecial, int minUppercase); |     std::string generateStrongPassword(int minLength, int maxLength, int numDigits, int minLowercase, int minSpecial, int minUppercase); | ||||||
|     bool VerifyECKey(const std::string &key); |     bool VerifyECKey(const std::string &key); | ||||||
|     bool VerifyRSAKey(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::string &Cert); | ||||||
|     bool ValidX509Certificate(const std::vector<std::string> &Certs); |     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 | } // namespace OpenWifi::Utils | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user