mirror of
				https://github.com/Telecominfraproject/wlan-cloud-owprov.git
				synced 2025-10-31 02:27:52 +00:00 
			
		
		
		
	Compare commits
	
		
			7 Commits
		
	
	
		
			v2.10.0-RC
			...
			v2.11.0-RC
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | e3d63cc90d | ||
|   | 3ce14e5efe | ||
|   | 7f860eb633 | ||
|   | 2628fe1b6a | ||
|   | 29a48f6753 | ||
|   | f8220e3a5e | ||
|   | 8dde169148 | 
| @@ -1,5 +1,5 @@ | |||||||
| cmake_minimum_required(VERSION 3.13) | cmake_minimum_required(VERSION 3.13) | ||||||
| project(owprov VERSION 2.10.0) | project(owprov VERSION 2.11.0) | ||||||
|  |  | ||||||
| set(CMAKE_CXX_STANDARD 17) | set(CMAKE_CXX_STANDARD 17) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ fullnameOverride: "" | |||||||
| images: | images: | ||||||
|   owprov: |   owprov: | ||||||
|     repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owprov |     repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owprov | ||||||
|     tag: main |     tag: v2.11.0-RC1 | ||||||
|     pullPolicy: Always |     pullPolicy: Always | ||||||
| #    regcred: | #    regcred: | ||||||
| #      registry: tip-tip-wlan-cloud-ucentral.jfrog.io | #      registry: tip-tip-wlan-cloud-ucentral.jfrog.io | ||||||
|   | |||||||
| @@ -1331,12 +1331,6 @@ components: | |||||||
|             - $ref: '#/components/schemas/StringList' |             - $ref: '#/components/schemas/StringList' | ||||||
|             - $ref: '#/components/schemas/TagValuePairList' |             - $ref: '#/components/schemas/TagValuePairList' | ||||||
|  |  | ||||||
|     SystemCommandResults: |  | ||||||
|       type: object |  | ||||||
|       oneOf: |  | ||||||
|         - $ref: '#/components/schemas/StringList' |  | ||||||
|         - $ref: '#/components/schemas/TagValuePairList' |  | ||||||
|  |  | ||||||
|     NoteInfo: |     NoteInfo: | ||||||
|       type: object |       type: object | ||||||
|       properties: |       properties: | ||||||
| @@ -1376,6 +1370,33 @@ components: | |||||||
|                 type: integer |                 type: integer | ||||||
|                 format: int64 |                 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' | ||||||
|  |  | ||||||
|     Dashboard: |     Dashboard: | ||||||
|       type: object |       type: object | ||||||
|       properties: |       properties: | ||||||
| @@ -4423,15 +4444,12 @@ paths: | |||||||
|             type: string |             type: string | ||||||
|             enum: |             enum: | ||||||
|               - info |               - info | ||||||
|  |               - extraConfiguration | ||||||
|  |               - resources | ||||||
|           required: true |           required: true | ||||||
|       responses: |       responses: | ||||||
|         200: |         200: | ||||||
|           description: Successful command execution |           $ref: '#/components/schemas/SystemCommandResults' | ||||||
|           content: |  | ||||||
|             application/json: |  | ||||||
|               schema: |  | ||||||
|                 oneOf: |  | ||||||
|                   - $ref: '#/components/schemas/SystemInfoResults' |  | ||||||
|         403: |         403: | ||||||
|           $ref: '#/components/responses/Unauthorized' |           $ref: '#/components/responses/Unauthorized' | ||||||
|         404: |         404: | ||||||
|   | |||||||
| @@ -90,9 +90,9 @@ namespace OpenWifi { | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (!Existing.contacts.empty()) { | 		if (!Existing.contacts.empty()) { | ||||||
| 			for (const auto &i : Existing.contacts) | 			for (const auto &contact_uuid : Existing.contacts) | ||||||
| 				StorageService()->ContactDB().DeleteInUse( | 				StorageService()->ContactDB().DeleteInUse( | ||||||
| 					"id", i, StorageService()->VenueDB().Prefix(), UUID); | 					"id", contact_uuid, StorageService()->VenueDB().Prefix(), UUID); | ||||||
| 		} | 		} | ||||||
| 		if (!Existing.location.empty()) | 		if (!Existing.location.empty()) | ||||||
| 			StorageService()->LocationDB().DeleteInUse("id", Existing.location, | 			StorageService()->LocationDB().DeleteInUse("id", Existing.location, | ||||||
| @@ -101,9 +101,9 @@ namespace OpenWifi { | |||||||
| 			StorageService()->PolicyDB().DeleteInUse("id", Existing.managementPolicy, | 			StorageService()->PolicyDB().DeleteInUse("id", Existing.managementPolicy, | ||||||
| 													 StorageService()->VenueDB().Prefix(), UUID); | 													 StorageService()->VenueDB().Prefix(), UUID); | ||||||
| 		if (!Existing.deviceConfiguration.empty()) { | 		if (!Existing.deviceConfiguration.empty()) { | ||||||
| 			for (auto &i : Existing.deviceConfiguration) | 			for (auto &configuration_uuid : Existing.deviceConfiguration) | ||||||
| 				StorageService()->ConfigurationDB().DeleteInUse( | 				StorageService()->ConfigurationDB().DeleteInUse( | ||||||
| 					"id", i, StorageService()->VenueDB().Prefix(), UUID); | 					"id", configuration_uuid, StorageService()->VenueDB().Prefix(), UUID); | ||||||
| 		} | 		} | ||||||
| 		if (!Existing.parent.empty()) | 		if (!Existing.parent.empty()) | ||||||
| 			StorageService()->VenueDB().DeleteChild("id", Existing.parent, UUID); | 			StorageService()->VenueDB().DeleteChild("id", Existing.parent, UUID); | ||||||
| @@ -157,6 +157,10 @@ namespace OpenWifi { | |||||||
| 			return BadRequest(RESTAPI::Errors::EntityMustExist); | 			return BadRequest(RESTAPI::Errors::EntityMustExist); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  |         if(StorageService()->VenueDB().DoesVenueNameAlreadyExist(NewObject.info.name,NewObject.entity, NewObject.parent)) { | ||||||
|  |             return BadRequest(RESTAPI::Errors::VenuesNameAlreadyExists); | ||||||
|  |         } | ||||||
|  |  | ||||||
| 		if (!NewObject.contacts.empty()) { | 		if (!NewObject.contacts.empty()) { | ||||||
| 			for (const auto &i : NewObject.contacts) { | 			for (const auto &i : NewObject.contacts) { | ||||||
| 				if (!StorageService()->ContactDB().Exists("id", i)) { | 				if (!StorageService()->ContactDB().Exists("id", i)) { | ||||||
| @@ -432,7 +436,7 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 		std::string MoveFromEntity, MoveToEntity; | 		std::string MoveFromEntity, MoveToEntity; | ||||||
| 		if (AssignIfPresent(RawObject, "entity", MoveToEntity)) { | 		if (AssignIfPresent(RawObject, "entity", MoveToEntity)) { | ||||||
| 			if (!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id", MoveToEntity)) { | 			if (MoveToEntity.empty() || !StorageService()->EntityDB().Exists("id", MoveToEntity)) { | ||||||
| 				return BadRequest(RESTAPI::Errors::EntityMustExist); | 				return BadRequest(RESTAPI::Errors::EntityMustExist); | ||||||
| 			} | 			} | ||||||
| 			MoveFromEntity = Existing.entity; | 			MoveFromEntity = Existing.entity; | ||||||
| @@ -441,7 +445,7 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 		std::string MoveToVenue, MoveFromVenue; | 		std::string MoveToVenue, MoveFromVenue; | ||||||
| 		if (AssignIfPresent(RawObject, "venue", MoveToVenue)) { | 		if (AssignIfPresent(RawObject, "venue", MoveToVenue)) { | ||||||
| 			if (!MoveToVenue.empty() && !StorageService()->VenueDB().Exists("id", MoveToVenue)) { | 			if (MoveToVenue.empty() || !StorageService()->VenueDB().Exists("id", MoveToVenue)) { | ||||||
| 				return BadRequest(RESTAPI::Errors::VenueMustExist); | 				return BadRequest(RESTAPI::Errors::VenueMustExist); | ||||||
| 			} | 			} | ||||||
| 			MoveFromVenue = Existing.parent; | 			MoveFromVenue = Existing.parent; | ||||||
| @@ -450,7 +454,7 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 		std::string MoveFromLocation, MoveToLocation; | 		std::string MoveFromLocation, MoveToLocation; | ||||||
| 		if (AssignIfPresent(RawObject, "location", MoveToLocation)) { | 		if (AssignIfPresent(RawObject, "location", MoveToLocation)) { | ||||||
| 			if (!MoveToLocation.empty() && | 			if (MoveToLocation.empty() || | ||||||
| 				!StorageService()->LocationDB().Exists("id", MoveToLocation)) { | 				!StorageService()->LocationDB().Exists("id", MoveToLocation)) { | ||||||
| 				return BadRequest(RESTAPI::Errors::LocationMustExist); | 				return BadRequest(RESTAPI::Errors::LocationMustExist); | ||||||
| 			} | 			} | ||||||
| @@ -460,8 +464,8 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 		Types::UUIDvec_t MoveFromContacts, MoveToContacts; | 		Types::UUIDvec_t MoveFromContacts, MoveToContacts; | ||||||
| 		if (AssignIfPresent(RawObject, "contacts", MoveToContacts)) { | 		if (AssignIfPresent(RawObject, "contacts", MoveToContacts)) { | ||||||
| 			for (const auto &i : NewObject.contacts) { | 			for (const auto &contact : NewObject.contacts) { | ||||||
| 				if (!StorageService()->ContactDB().Exists("id", i)) { | 				if (!StorageService()->ContactDB().Exists("id", contact)) { | ||||||
| 					return BadRequest(RESTAPI::Errors::ContactMustExist); | 					return BadRequest(RESTAPI::Errors::ContactMustExist); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| @@ -471,7 +475,7 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 		std::string MoveFromPolicy, MoveToPolicy; | 		std::string MoveFromPolicy, MoveToPolicy; | ||||||
| 		if (AssignIfPresent(RawObject, "managementPolicy", MoveToPolicy)) { | 		if (AssignIfPresent(RawObject, "managementPolicy", MoveToPolicy)) { | ||||||
| 			if (!MoveToPolicy.empty() && !StorageService()->PolicyDB().Exists("id", MoveToPolicy)) { | 			if (MoveToPolicy.empty() || !StorageService()->PolicyDB().Exists("id", MoveToPolicy)) { | ||||||
| 				return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID); | 				return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID); | ||||||
| 			} | 			} | ||||||
| 			MoveFromPolicy = Existing.managementPolicy; | 			MoveFromPolicy = Existing.managementPolicy; | ||||||
| @@ -481,8 +485,8 @@ namespace OpenWifi { | |||||||
| 		Types::UUIDvec_t MoveToConfigurations, MoveFromConfigurations; | 		Types::UUIDvec_t MoveToConfigurations, MoveFromConfigurations; | ||||||
| 		if (RawObject->has("deviceConfiguration")) { | 		if (RawObject->has("deviceConfiguration")) { | ||||||
| 			MoveToConfigurations = NewObject.deviceConfiguration; | 			MoveToConfigurations = NewObject.deviceConfiguration; | ||||||
| 			for (auto &i : MoveToConfigurations) { | 			for (auto &configuration : MoveToConfigurations) { | ||||||
| 				if (!StorageService()->ConfigurationDB().Exists("id", i)) { | 				if (!StorageService()->ConfigurationDB().Exists("id", configuration)) { | ||||||
| 					return BadRequest(RESTAPI::Errors::ConfigurationMustExist); | 					return BadRequest(RESTAPI::Errors::ConfigurationMustExist); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|   | |||||||
| @@ -26,7 +26,7 @@ namespace OpenWifi { | |||||||
| 			Response.set("Connection", "keep-alive"); | 			Response.set("Connection", "keep-alive"); | ||||||
| 			Response.setVersion(Poco::Net::HTTPMessage::HTTP_1_1); | 			Response.setVersion(Poco::Net::HTTPMessage::HTTP_1_1); | ||||||
| 			std::ostream &Answer = Response.send(); | 			std::ostream &Answer = Response.send(); | ||||||
| 			Answer << "process Alive and kicking!"; | 			Answer << ALBHealthCheckServer()->CallbackText(); | ||||||
| 		} catch (...) { | 		} catch (...) { | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -37,6 +37,8 @@ namespace OpenWifi { | |||||||
| 		inline static std::atomic_uint64_t req_id_ = 1; | 		inline static std::atomic_uint64_t req_id_ = 1; | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|  | 	typedef std::string ALBHealthMessageCallback(); | ||||||
|  |  | ||||||
| 	class ALBHealthCheckServer : public SubSystemServer { | 	class ALBHealthCheckServer : public SubSystemServer { | ||||||
| 	  public: | 	  public: | ||||||
| 		ALBHealthCheckServer(); | 		ALBHealthCheckServer(); | ||||||
| @@ -48,10 +50,22 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 		int Start() override; | 		int Start() override; | ||||||
| 		void Stop() 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: | 	  private: | ||||||
| 		std::unique_ptr<Poco::Net::HTTPServer> Server_; | 		std::unique_ptr<Poco::Net::HTTPServer> Server_; | ||||||
| 		std::unique_ptr<Poco::Net::ServerSocket> Socket_; | 		std::unique_ptr<Poco::Net::ServerSocket> Socket_; | ||||||
|  | 		ALBHealthMessageCallback	*Callback_= nullptr; | ||||||
| 		int Port_ = 0; | 		int Port_ = 0; | ||||||
| 		mutable std::atomic_bool Running_ = false; | 		mutable std::atomic_bool Running_ = false; | ||||||
| 	}; | 	}; | ||||||
|   | |||||||
| @@ -2235,6 +2235,17 @@ static std::string DefaultUCentralSchema = R"foo( | |||||||
|                         ] |                         ] | ||||||
|                     } |                     } | ||||||
|                 }, |                 }, | ||||||
|  |                 "vlan-awareness": { | ||||||
|  |                     "type": "object", | ||||||
|  |                     "properties": { | ||||||
|  |                         "first": { | ||||||
|  |                             "type": "integer" | ||||||
|  |                         }, | ||||||
|  |                         "last": { | ||||||
|  |                             "type": "integer" | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 }, | ||||||
|                 "vlan": { |                 "vlan": { | ||||||
|                     "$ref": "#/$defs/interface.vlan" |                     "$ref": "#/$defs/interface.vlan" | ||||||
|                 }, |                 }, | ||||||
|   | |||||||
| @@ -213,7 +213,7 @@ namespace OpenWifi { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	void KafkaProducer::Produce(const char *Topic, const std::string &Key, | 	void KafkaProducer::Produce(const char *Topic, const std::string &Key, | ||||||
| 								const std::shared_ptr<std::string> Payload) { | 								std::shared_ptr<std::string> Payload) { | ||||||
| 		std::lock_guard G(Mutex_); | 		std::lock_guard G(Mutex_); | ||||||
| 		Queue_.enqueueNotification(new KafkaMessage(Topic, Key, Payload)); | 		Queue_.enqueueNotification(new KafkaMessage(Topic, Key, Payload)); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -18,8 +18,8 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 	class KafkaMessage : public Poco::Notification { | 	class KafkaMessage : public Poco::Notification { | ||||||
| 	  public: | 	  public: | ||||||
| 		KafkaMessage(const char * Topic, const std::string &Key, const std::shared_ptr<std::string> Payload) | 		KafkaMessage(const char * Topic, const std::string &Key, std::shared_ptr<std::string> Payload) | ||||||
| 			: Topic_(Topic), Key_(Key), Payload_(std::move(Payload)) {} | 			: Topic_(Topic), Key_(Key), Payload_(Payload) {} | ||||||
|  |  | ||||||
| 		inline const char * Topic() { return Topic_; } | 		inline const char * Topic() { return Topic_; } | ||||||
| 		inline const std::string &Key() { return Key_; } | 		inline const std::string &Key() { return Key_; } | ||||||
| @@ -36,7 +36,7 @@ namespace OpenWifi { | |||||||
| 		void run() override; | 		void run() override; | ||||||
| 		void Start(); | 		void Start(); | ||||||
| 		void Stop(); | 		void Stop(); | ||||||
| 		void Produce(const char *Topic, const std::string &Key, const std::shared_ptr<std::string> Payload); | 		void Produce(const char *Topic, const std::string &Key, std::shared_ptr<std::string> Payload); | ||||||
|  |  | ||||||
| 	  private: | 	  private: | ||||||
| 		std::recursive_mutex Mutex_; | 		std::recursive_mutex Mutex_; | ||||||
| @@ -92,9 +92,9 @@ namespace OpenWifi { | |||||||
| 		void Stop() override; | 		void Stop() override; | ||||||
|  |  | ||||||
| 		void PostMessage(const char *topic, const std::string &key, | 		void PostMessage(const char *topic, const std::string &key, | ||||||
| 						 const std::shared_ptr<std::string> PayLoad, bool WrapMessage = true); | 						 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); | 		void Dispatch(const char *Topic, const std::string &Key, std::shared_ptr<std::string> Payload); | ||||||
| 		[[nodiscard]] const std::shared_ptr<std::string> WrapSystemId(const std::shared_ptr<std::string> PayLoad); | 		[[nodiscard]] const std::shared_ptr<std::string> WrapSystemId(std::shared_ptr<std::string> PayLoad); | ||||||
| 		[[nodiscard]] inline bool Enabled() const { return KafkaEnabled_; } | 		[[nodiscard]] inline bool Enabled() const { return KafkaEnabled_; } | ||||||
| 		uint64_t RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F); | 		uint64_t RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F); | ||||||
| 		void UnregisterTopicWatcher(const std::string &Topic, uint64_t Id); | 		void UnregisterTopicWatcher(const std::string &Topic, uint64_t Id); | ||||||
|   | |||||||
| @@ -129,6 +129,8 @@ namespace OpenWifi { | |||||||
| 				} | 				} | ||||||
| 			} else { | 			} else { | ||||||
| 				poco_error(logger(), "Bad bus message."); | 				poco_error(logger(), "Bad bus message."); | ||||||
|  |                 std::ostringstream os; | ||||||
|  |                 Object->stringify(std::cout); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			auto i = Services_.begin(); | 			auto i = Services_.begin(); | ||||||
|   | |||||||
| @@ -5,6 +5,8 @@ | |||||||
| #include "framework/MicroServiceFuncs.h" | #include "framework/MicroServiceFuncs.h" | ||||||
| #include "framework/MicroService.h" | #include "framework/MicroService.h" | ||||||
|  |  | ||||||
|  | #include "framework/ALBserver.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace OpenWifi { | ||||||
| 	const std::string &MicroServiceDataDirectory() { return MicroService::instance().DataDir(); } | 	const std::string &MicroServiceDataDirectory() { return MicroService::instance().DataDir(); } | ||||||
|  |  | ||||||
| @@ -123,4 +125,8 @@ namespace OpenWifi { | |||||||
| 		return MicroService::instance().AllowExternalMicroServices(); | 		return MicroService::instance().AllowExternalMicroServices(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	void MicroServiceALBCallback( std::string Callback()) { | ||||||
|  | 		return ALBHealthCheckServer()->RegisterExtendedHealthMessage(Callback); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| } // namespace OpenWifi | } // namespace OpenWifi | ||||||
|   | |||||||
| @@ -53,4 +53,5 @@ namespace OpenWifi { | |||||||
| 	std::string MicroServiceGetPublicAPIEndPoint(); | 	std::string MicroServiceGetPublicAPIEndPoint(); | ||||||
| 	void MicroServiceDeleteOverrideConfiguration(); | 	void MicroServiceDeleteOverrideConfiguration(); | ||||||
| 	bool AllowExternalMicroServices(); | 	bool AllowExternalMicroServices(); | ||||||
|  | 	void MicroServiceALBCallback( std::string Callback()); | ||||||
| } // namespace OpenWifi | } // namespace OpenWifi | ||||||
|   | |||||||
| @@ -28,6 +28,9 @@ namespace OpenWifi::Types { | |||||||
| 	typedef std::string UUID_t; | 	typedef std::string UUID_t; | ||||||
| 	typedef std::vector<UUID_t> UUIDvec_t; | 	typedef std::vector<UUID_t> UUIDvec_t; | ||||||
| 	typedef std::map<std::string, std::map<uint32_t, uint64_t>> Counted3DMapSII; | 	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 { | 	struct MicroServiceMeta { | ||||||
| 		uint64_t Id = 0; | 		uint64_t Id = 0; | ||||||
|   | |||||||
| @@ -24,9 +24,10 @@ namespace OpenWifi { | |||||||
| 							 Server, TransactionId, Internal) {} | 							 Server, TransactionId, Internal) {} | ||||||
| 		static auto PathName() { return std::list<std::string>{"/api/v1/system"}; } | 		static auto PathName() { return std::list<std::string>{"/api/v1/system"}; } | ||||||
|  |  | ||||||
| 		inline void DoGet() { | 		inline void DoGet() final { | ||||||
| 			std::string Arg; | 			std::string Arg; | ||||||
| 			if (HasParameter("command", Arg) && Arg == "info") { | 			if (HasParameter("command", Arg)) { | ||||||
|  | 				if (Arg == "info") { | ||||||
| 					Poco::JSON::Object Answer; | 					Poco::JSON::Object Answer; | ||||||
| 					Answer.set(RESTAPI::Protocol::VERSION, MicroServiceVersion()); | 					Answer.set(RESTAPI::Protocol::VERSION, MicroServiceVersion()); | ||||||
| 					Answer.set(RESTAPI::Protocol::UPTIME, MicroServiceUptimeTotalSeconds()); | 					Answer.set(RESTAPI::Protocol::UPTIME, MicroServiceUptimeTotalSeconds()); | ||||||
| @@ -64,11 +65,23 @@ namespace OpenWifi { | |||||||
| 					Answer.set("certificates", Certificates); | 					Answer.set("certificates", Certificates); | ||||||
| 					return ReturnObject(Answer); | 					return ReturnObject(Answer); | ||||||
| 				} | 				} | ||||||
| 			if (GetBoolParameter("extraConfiguration")) { | 				if (Arg == "extraConfiguration") { | ||||||
| 					Poco::JSON::Object Answer; | 					Poco::JSON::Object Answer; | ||||||
| 					MicroServiceGetExtraConfiguration(Answer); | 					MicroServiceGetExtraConfiguration(Answer); | ||||||
| 					return ReturnObject(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); | 			BadRequest(RESTAPI::Errors::InvalidCommand); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -102,6 +102,20 @@ namespace OpenWifi::RESTAPI_utils { | |||||||
| 		Obj.set(Field, A); | 		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) { | 	inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::TagList &V) { | ||||||
| 		Poco::JSON::Array A; | 		Poco::JSON::Array A; | ||||||
| 		for (const auto &i : V) | 		for (const auto &i : V) | ||||||
| @@ -284,6 +298,28 @@ 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> | 	template <class T> | ||||||
| 	void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, | 	void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, | ||||||
| 						 std::vector<T> &Value) { | 						 std::vector<T> &Value) { | ||||||
|   | |||||||
| @@ -22,9 +22,8 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 	class StorageClass : public SubSystemServer { | 	class StorageClass : public SubSystemServer { | ||||||
| 	  public: | 	  public: | ||||||
| 		StorageClass() noexcept : SubSystemServer("StorageClass", "STORAGE-SVR", "storage") {} |  | ||||||
|  |  | ||||||
| 		int Start() override { |         inline int Start() override { | ||||||
| 			std::lock_guard Guard(Mutex_); | 			std::lock_guard Guard(Mutex_); | ||||||
|  |  | ||||||
| 			Logger().notice("Starting."); | 			Logger().notice("Starting."); | ||||||
| @@ -40,17 +39,22 @@ namespace OpenWifi { | |||||||
| 			return 0; | 			return 0; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		void Stop() override { Pool_->shutdown(); } | 		inline void Stop() override { Pool_->shutdown(); } | ||||||
|  |  | ||||||
| 		DBType Type() const { return dbType_; }; | 		DBType Type() const { return dbType_; }; | ||||||
|  |  | ||||||
|  |         StorageClass() noexcept : SubSystemServer("StorageClass", "STORAGE-SVR", "storage") { | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |  | ||||||
| 	  private: | 	  private: | ||||||
| 		inline int Setup_SQLite(); | 		inline int Setup_SQLite(); | ||||||
| 		inline int Setup_MySQL(); | 		inline int Setup_MySQL(); | ||||||
| 		inline int Setup_PostgreSQL(); | 		inline int Setup_PostgreSQL(); | ||||||
|  |  | ||||||
|  |  | ||||||
|     protected: |     protected: | ||||||
| 		std::unique_ptr<Poco::Data::SessionPool> Pool_; | 		std::shared_ptr<Poco::Data::SessionPool> Pool_; | ||||||
| 		Poco::Data::SQLite::Connector SQLiteConn_; | 		Poco::Data::SQLite::Connector SQLiteConn_; | ||||||
| 		Poco::Data::PostgreSQL::Connector PostgresConn_; | 		Poco::Data::PostgreSQL::Connector PostgresConn_; | ||||||
| 		Poco::Data::MySQL::Connector MySQLConn_; | 		Poco::Data::MySQL::Connector MySQLConn_; | ||||||
| @@ -81,7 +85,7 @@ namespace OpenWifi { | |||||||
| 		//        Poco::Data::SessionPool(SQLiteConn_.name(), DBName, 8, | 		//        Poco::Data::SessionPool(SQLiteConn_.name(), DBName, 8, | ||||||
| 		//                                                                                     (int)NumSessions, | 		//                                                                                     (int)NumSessions, | ||||||
| 		//                                                                                     (int)IdleTime)); | 		//                                                                                     (int)IdleTime)); | ||||||
| 		Pool_ = std::make_unique<Poco::Data::SessionPool>(SQLiteConn_.name(), DBName, 8, | 		Pool_ = std::make_shared<Poco::Data::SessionPool>(SQLiteConn_.name(), DBName, 8, | ||||||
| 														  (int)NumSessions, (int)IdleTime); | 														  (int)NumSessions, (int)IdleTime); | ||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
| @@ -102,7 +106,7 @@ namespace OpenWifi { | |||||||
| 									";compress=true;auto-reconnect=true"; | 									";compress=true;auto-reconnect=true"; | ||||||
|  |  | ||||||
| 		Poco::Data::MySQL::Connector::registerConnector(); | 		Poco::Data::MySQL::Connector::registerConnector(); | ||||||
| 		Pool_ = std::make_unique<Poco::Data::SessionPool>(MySQLConn_.name(), ConnectionStr, 8, | 		Pool_ = std::make_shared<Poco::Data::SessionPool>(MySQLConn_.name(), ConnectionStr, 8, | ||||||
| 														  NumSessions, IdleTime); | 														  NumSessions, IdleTime); | ||||||
|  |  | ||||||
| 		return 0; | 		return 0; | ||||||
| @@ -126,7 +130,7 @@ namespace OpenWifi { | |||||||
| 									" connect_timeout=" + ConnectionTimeout; | 									" connect_timeout=" + ConnectionTimeout; | ||||||
|  |  | ||||||
| 		Poco::Data::PostgreSQL::Connector::registerConnector(); | 		Poco::Data::PostgreSQL::Connector::registerConnector(); | ||||||
| 		Pool_ = std::make_unique<Poco::Data::SessionPool>(PostgresConn_.name(), ConnectionStr, 8, | 		Pool_ = std::make_shared<Poco::Data::SessionPool>(PostgresConn_.name(), ConnectionStr, 8, | ||||||
| 														  NumSessions, IdleTime); | 														  NumSessions, IdleTime); | ||||||
|  |  | ||||||
| 		return 0; | 		return 0; | ||||||
|   | |||||||
| @@ -401,6 +401,12 @@ namespace OpenWifi::RESTAPI::Errors { | |||||||
| 		1171, "Command not supported on simulated device." | 		1171, "Command not supported on simulated device." | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|  |     static const struct msg VenuesNameAlreadyExists { | ||||||
|  |             1172, "The venue name already exists." | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     static const struct msg DefFirmwareNameExists { 1172, "Firmware name already exists." }; | ||||||
|  |  | ||||||
|     static const struct msg SimulationDoesNotExist { |     static const struct msg SimulationDoesNotExist { | ||||||
|         7000, "Simulation Instance ID does not exist." |         7000, "Simulation Instance ID does not exist." | ||||||
|     }; |     }; | ||||||
|   | |||||||
| @@ -132,6 +132,15 @@ namespace OpenWifi::Utils { | |||||||
| 		return std::regex_match(Hostname, HostNameRegex); | 		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) { | 	[[nodiscard]] std::string ToHex(const std::vector<unsigned char> &B) { | ||||||
| 		std::string R; | 		std::string R; | ||||||
| 		R.reserve(B.size() * 2); | 		R.reserve(B.size() * 2); | ||||||
|   | |||||||
| @@ -13,6 +13,8 @@ | |||||||
| #include <string> | #include <string> | ||||||
| #include <thread> | #include <thread> | ||||||
|  |  | ||||||
|  | #include <dirent.h> | ||||||
|  |  | ||||||
| #include "Poco/Base64Decoder.h" | #include "Poco/Base64Decoder.h" | ||||||
| #include "Poco/Base64Encoder.h" | #include "Poco/Base64Encoder.h" | ||||||
| #include "Poco/File.h" | #include "Poco/File.h" | ||||||
| @@ -71,6 +73,7 @@ namespace OpenWifi::Utils { | |||||||
| 	[[nodiscard]] bool ValidSerialNumbers(const std::vector<std::string> &Serial); | 	[[nodiscard]] bool ValidSerialNumbers(const std::vector<std::string> &Serial); | ||||||
| 	[[nodiscard]] bool ValidUUID(const std::string &UUID); | 	[[nodiscard]] bool ValidUUID(const std::string &UUID); | ||||||
| 	[[nodiscard]] bool ValidHostname(const std::string &hostname); | 	[[nodiscard]] bool ValidHostname(const std::string &hostname); | ||||||
|  | 	[[nodiscard]] bool ValidNumber(const std::string &number, bool isSigned); | ||||||
|  |  | ||||||
| 	template <typename... Args> std::string ComputeHash(Args &&...args) { | 	template <typename... Args> std::string ComputeHash(Args &&...args) { | ||||||
| 		Poco::SHA2Engine E; | 		Poco::SHA2Engine E; | ||||||
| @@ -181,4 +184,67 @@ namespace OpenWifi::Utils { | |||||||
| 		return false; | 		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; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| } // namespace OpenWifi::Utils | } // namespace OpenWifi::Utils | ||||||
|   | |||||||
| @@ -112,6 +112,31 @@ namespace OpenWifi { | |||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  |     bool VenueDB::DoesVenueNameAlreadyExist(const std::string &name, const std::string &entity_uuid, const std::string &parent_uuid) { | ||||||
|  |  | ||||||
|  |         std::string Statement; | ||||||
|  |         if(!entity_uuid.empty()) { | ||||||
|  |             Statement = fmt::format("select count(*) from venues where entity='{}' and upper(name)='{}'", | ||||||
|  |                                     entity_uuid, Poco::toUpper(name)); | ||||||
|  |         } else { | ||||||
|  |             Statement = fmt::format("select count(*) from venues where parent='{}' and upper(name)='{}'", | ||||||
|  |                                     parent_uuid, Poco::toUpper(name)); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         std::uint64_t RecordCount = 0; | ||||||
|  |         try { | ||||||
|  |             Poco::Data::Session Session = Pool_.get(); | ||||||
|  |             Poco::Data::Statement Command(Session); | ||||||
|  |  | ||||||
|  |             Command << Statement, | ||||||
|  |                     Poco::Data::Keywords::into(RecordCount); | ||||||
|  |             Command.execute(); | ||||||
|  |         } catch (...) { | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |         return RecordCount!=0; | ||||||
|  |     } | ||||||
|  |  | ||||||
| } // namespace OpenWifi | } // namespace OpenWifi | ||||||
|  |  | ||||||
| template <> | template <> | ||||||
|   | |||||||
| @@ -26,6 +26,7 @@ namespace OpenWifi { | |||||||
| 		bool GetByIP(const std::string &IP, std::string &uuid); | 		bool GetByIP(const std::string &IP, std::string &uuid); | ||||||
| 		bool Upgrade(uint32_t from, uint32_t &to) override; | 		bool Upgrade(uint32_t from, uint32_t &to) override; | ||||||
| 		bool EvaluateDeviceRules(const std::string &id, ProvObjects::DeviceRules &Rules); | 		bool EvaluateDeviceRules(const std::string &id, ProvObjects::DeviceRules &Rules); | ||||||
|  |         bool DoesVenueNameAlreadyExist(const std::string &name, const std::string &entity_uuid, const std::string &parent_uuid); | ||||||
|  |  | ||||||
| 	  private: | 	  private: | ||||||
| 	}; | 	}; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user