mirror of
				https://github.com/Telecominfraproject/wlan-cloud-owprov.git
				synced 2025-10-31 18:48:09 +00:00 
			
		
		
		
	Compare commits
	
		
			26 Commits
		
	
	
		
			v3.0.0-RC2
			...
			release/v3
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | d8e343a27d | ||
|   | 0224d22317 | ||
|   | 4b07db924d | ||
|   | 10a39f2f50 | ||
|   | 8fc7ce7ca8 | ||
|   | da015b2ea0 | ||
|   | cd9fdc7a91 | ||
|   | a619c0dbe1 | ||
|   | 2575fa628a | ||
|   | 3529f86788 | ||
|   | 0a846e45c4 | ||
|   | 01b1107bac | ||
|   | 9412c0094b | ||
|   | d6e3701ca3 | ||
|   | 5ac7b92f1f | ||
|   | 74557c1600 | ||
|   | c6535500f2 | ||
|   | 2e8a2fe1c8 | ||
|   | 102e240c7e | ||
|   | fd85c70c2f | ||
|   | ec11708046 | ||
|   | eed9525845 | ||
|   | 4ded8997cd | ||
|   | 4ab9a1d6ac | ||
|   | bc116c1d82 | ||
|   | ce04f1c9b3 | 
							
								
								
									
										28
									
								
								BUILDING.md
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								BUILDING.md
									
									
									
									
									
								
							| @@ -1,5 +1,5 @@ | |||||||
| # Building from source | # Building from source | ||||||
| In order to build the OWPROV, you will need to install its dependencies, which includes the following: | In order to build OWPROV, you will need to install its dependencies, which includes the following: | ||||||
| - cmake | - cmake | ||||||
| - boost | - boost | ||||||
| - POCO 1.10.1 or later | - POCO 1.10.1 or later | ||||||
| @@ -12,7 +12,7 @@ In order to build the OWPROV, you will need to install its dependencies, which i | |||||||
|  |  | ||||||
| The build is done in 2 parts. The first part is to build a local copy of the framework tailored to your environment. This | The build is done in 2 parts. The first part is to build a local copy of the framework tailored to your environment. This | ||||||
| framework is called [Poco](https://github.com/pocoproject/poco). The version used in this project has a couple of fixes | framework is called [Poco](https://github.com/pocoproject/poco). The version used in this project has a couple of fixes | ||||||
| from the master copy needed for cmake. Please use the version of this [Poco fix](https://github.com/AriliaWireless/poco). Building | from the master copy needed for cmake. Please use the version of this [Poco fix](https://github.com/Telecominfraproject/wlan-cloud-lib-poco). Building | ||||||
| Poco may take several minutes depending on the platform you are building on. | Poco may take several minutes depending on the platform you are building on. | ||||||
|  |  | ||||||
| ## Ubuntu | ## Ubuntu | ||||||
| @@ -24,7 +24,7 @@ sudo apt install librdkafka-dev // default-libmysqlclient-dev | |||||||
| sudo apt install nlohmann-json-dev | sudo apt install nlohmann-json-dev | ||||||
|  |  | ||||||
| cd ~ | cd ~ | ||||||
| git clone https://github.com/AriliaWireless/poco --branch poco-tip-v1 | git clone https://github.com/Telecominfraproject/wlan-cloud-lib-poco --branch poco-tip-v1 poco | ||||||
| cd poco | cd poco | ||||||
| mkdir cmake-build | mkdir cmake-build | ||||||
| cd cmake-build | cd cmake-build | ||||||
| @@ -33,7 +33,7 @@ cmake --build . --config Release | |||||||
| sudo cmake --build . --target install | sudo cmake --build . --target install | ||||||
|  |  | ||||||
| cd ~ | cd ~ | ||||||
| git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1 | git clone https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka --branch tip-v1 cppkafka | ||||||
| cd cppkafka | cd cppkafka | ||||||
| mkdir cmake-build | mkdir cmake-build | ||||||
| cd cmake-build | cd cmake-build | ||||||
| @@ -42,7 +42,7 @@ cmake --build . --config Release | |||||||
| sudo cmake --build . --target install | sudo cmake --build . --target install | ||||||
|  |  | ||||||
| cd ~ | cd ~ | ||||||
| git clone https://github.com/AriliaWireless/valijson --branch tip-v1 | git clone https://github.com/Telecominfraproject/wlan-cloud-lib-valijson --branch tip-v1 valijson | ||||||
| cd valijson | cd valijson | ||||||
| mkdir cmake-build | mkdir cmake-build | ||||||
| cd cmake-build | cd cmake-build | ||||||
| @@ -50,7 +50,8 @@ cmake .. | |||||||
| cmake --build . --config Release | cmake --build . --config Release | ||||||
| sudo cmake --build . --target install | sudo cmake --build . --target install | ||||||
|  |  | ||||||
| git clone https://github.com/fmtlib/fmt --branch 9.0.0 /fmtlib | cd ~ | ||||||
|  | git clone https://github.com/fmtlib/fmt --branch 9.0.0 fmtlib | ||||||
| cd fmtlib | cd fmtlib | ||||||
| mkdir cmake-build | mkdir cmake-build | ||||||
| cd cmake-build | cd cmake-build | ||||||
| @@ -75,7 +76,7 @@ sudo yum install yaml-cpp-devel lua-devel | |||||||
| sudo dnf install postgresql.x86_64 librdkafka-devel | sudo dnf install postgresql.x86_64 librdkafka-devel | ||||||
| sudo dnf install postgresql-devel json-devel | sudo dnf install postgresql-devel json-devel | ||||||
|  |  | ||||||
| git clone https://github.com/AriliaWireless/poco --branch poco-tip-v1 | git clone https://github.com/Telecominfraproject/wlan-cloud-lib-poco --branch poco-tip-v1 poco | ||||||
| cd poco | cd poco | ||||||
| mkdir cmake-build | mkdir cmake-build | ||||||
| cd cmake-build | cd cmake-build | ||||||
| @@ -83,7 +84,8 @@ cmake .. | |||||||
| cmake --build . --config Release | cmake --build . --config Release | ||||||
| sudo cmake --build . --target install | sudo cmake --build . --target install | ||||||
|  |  | ||||||
| git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1 | cd ~ | ||||||
|  | git clone https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka --branch tip-v1 cppkafka | ||||||
| cd cppkafka | cd cppkafka | ||||||
| mkdir cmake-build | mkdir cmake-build | ||||||
| cd cmake-build | cd cmake-build | ||||||
| @@ -92,7 +94,7 @@ cmake --build . --config Release | |||||||
| sudo cmake --build . --target install | sudo cmake --build . --target install | ||||||
|  |  | ||||||
| cd ~ | cd ~ | ||||||
| git clone https://github.com/AriliaWireless/valijson --branch tip-v1 | git clone https://github.com/Telecominfraproject/wlan-cloud-lib-valijson --branch tip-v1 valijson | ||||||
| cd valijson | cd valijson | ||||||
| mkdir cmake-build | mkdir cmake-build | ||||||
| cd cmake-build | cd cmake-build | ||||||
| @@ -125,7 +127,7 @@ brew install openssl \ | |||||||
| 	nlohmann-json \ | 	nlohmann-json \ | ||||||
| 	fmt | 	fmt | ||||||
|  |  | ||||||
| git clone https://github.com/AriliaWireless/poco --branch poco-tip-v1 | git clone https://github.com/Telecominfraproject/wlan-cloud-lib-poco --branch poco-tip-v1 poco | ||||||
| pushd poco | pushd poco | ||||||
| mkdir cmake-build | mkdir cmake-build | ||||||
| push cmake-build | push cmake-build | ||||||
| @@ -135,7 +137,7 @@ sudo cmake --build . --target install | |||||||
| popd | popd | ||||||
| popd | popd | ||||||
|  |  | ||||||
| git clone https://github.com/AriliaWireless/cppkafka --branch tip-v1 | git clone https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka --branch tip-v1 cppkafka | ||||||
| pushd cppkafka | pushd cppkafka | ||||||
| mkdir cmake-build | mkdir cmake-build | ||||||
| pushd cmake-build | pushd cmake-build | ||||||
| @@ -145,7 +147,7 @@ sudo cmake --build . --target install | |||||||
| popd | popd | ||||||
| popd | popd | ||||||
|  |  | ||||||
| git clone https://github.com/AriliaWireless/valijson --branch tip-v1 | git clone https://github.com/Telecominfraproject/wlan-cloud-lib-valijson --branch tip-v1 valijson | ||||||
| cd valijson | cd valijson | ||||||
| mkdir cmake-build | mkdir cmake-build | ||||||
| cd cmake-build | cd cmake-build | ||||||
| @@ -172,6 +174,8 @@ adding -DSMALL_BUILD=1 on the cmake build line. | |||||||
|  |  | ||||||
| ```bash | ```bash | ||||||
| sudo apt install git cmake g++ libssl-dev libaprutil1-dev apache2-dev libboost-all-dev libyaml-cpp-dev | sudo apt install git cmake g++ libssl-dev libaprutil1-dev apache2-dev libboost-all-dev libyaml-cpp-dev | ||||||
|  |  | ||||||
|  | cd ~ | ||||||
| git clone https://github.com/stephb9959/poco | git clone https://github.com/stephb9959/poco | ||||||
| cd poco | cd poco | ||||||
| mkdir cmake-build | mkdir cmake-build | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| cmake_minimum_required(VERSION 3.13) | cmake_minimum_required(VERSION 3.13) | ||||||
| project(owprov VERSION 3.0.0) | project(owprov VERSION 3.0.2) | ||||||
|  |  | ||||||
| set(CMAKE_CXX_STANDARD 17) | set(CMAKE_CXX_STANDARD 17) | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								Dockerfile
									
									
									
									
									
								
							| @@ -15,8 +15,9 @@ FROM build-base AS poco-build | |||||||
|  |  | ||||||
| ARG POCO_VERSION | ARG POCO_VERSION | ||||||
|  |  | ||||||
| ADD https://api.github.com/repos/AriliaWireless/poco/git/refs/tags/${POCO_VERSION} version.json | ADD https://api.github.com/repos/Telecominfraproject/wlan-cloud-lib-poco/git/refs/tags/${POCO_VERSION} version.json | ||||||
| RUN git clone https://github.com/AriliaWireless/poco --branch ${POCO_VERSION} /poco | RUN git clone https://github.com/Telecominfraproject/wlan-cloud-lib-poco --branch ${POCO_VERSION} /poco | ||||||
|  |  | ||||||
|  |  | ||||||
| WORKDIR /poco | WORKDIR /poco | ||||||
| RUN mkdir cmake-build | RUN mkdir cmake-build | ||||||
| @@ -29,8 +30,8 @@ FROM build-base AS cppkafka-build | |||||||
|  |  | ||||||
| ARG CPPKAFKA_VERSION | ARG CPPKAFKA_VERSION | ||||||
|  |  | ||||||
| ADD https://api.github.com/repos/AriliaWireless/cppkafka/git/refs/tags/${CPPKAFKA_VERSION} version.json | ADD https://api.github.com/repos/Telecominfraproject/wlan-cloud-lib-cppkafka/git/refs/tags/${CPPKAFKA_VERSION} version.json | ||||||
| RUN git clone https://github.com/AriliaWireless/cppkafka --branch ${CPPKAFKA_VERSION} /cppkafka | RUN git clone https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka --branch ${CPPKAFKA_VERSION} /cppkafka | ||||||
|  |  | ||||||
| WORKDIR /cppkafka | WORKDIR /cppkafka | ||||||
| RUN mkdir cmake-build | RUN mkdir cmake-build | ||||||
| @@ -43,8 +44,8 @@ FROM build-base AS valijson-build | |||||||
|  |  | ||||||
| ARG VALIJASON_VERSION | ARG VALIJASON_VERSION | ||||||
|  |  | ||||||
| ADD https://api.github.com/repos/AriliaWireless/valijson/git/refs/tags/${VALIJASON_VERSION} version.json | ADD https://api.github.com/repos/Telecominfraproject/wlan-cloud-lib-valijson/git/refs/tags/${VALIJASON_VERSION} version.json | ||||||
| RUN git clone https://github.com/AriliaWireless/valijson --branch ${VALIJASON_VERSION} /valijson | RUN git clone https://github.com/Telecominfraproject/wlan-cloud-lib-valijson --branch ${VALIJASON_VERSION} /valijson | ||||||
|  |  | ||||||
| WORKDIR /valijson | WORKDIR /valijson | ||||||
| RUN mkdir cmake-build | RUN mkdir cmake-build | ||||||
|   | |||||||
| @@ -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: v3.0.0-RC2 |     tag: v3.0.2-RC1 | ||||||
|     pullPolicy: Always |     pullPolicy: Always | ||||||
| #    regcred: | #    regcred: | ||||||
| #      registry: tip-tip-wlan-cloud-ucentral.jfrog.io | #      registry: tip-tip-wlan-cloud-ucentral.jfrog.io | ||||||
|   | |||||||
| @@ -815,6 +815,17 @@ components: | |||||||
|           type: string |           type: string | ||||||
|           minLength: 2 |           minLength: 2 | ||||||
|           maxLength: 2 |           maxLength: 2 | ||||||
|  |         imported: | ||||||
|  |           type: integer | ||||||
|  |           format: int64 | ||||||
|  |         connected: | ||||||
|  |           type: integer | ||||||
|  |           format: int64 | ||||||
|  |         platform: | ||||||
|  |           type: string | ||||||
|  |           enum: | ||||||
|  |             - AP | ||||||
|  |             - SWITCH | ||||||
|  |  | ||||||
|     VenueDeviceList: |     VenueDeviceList: | ||||||
|       type: object |       type: object | ||||||
| @@ -3240,6 +3251,15 @@ paths: | |||||||
|           schema: |           schema: | ||||||
|             type: boolean |             type: boolean | ||||||
|           required: false |           required: false | ||||||
|  |         - in: query | ||||||
|  |           name: deviceType | ||||||
|  |           schema: | ||||||
|  |             type: string | ||||||
|  |             enum: | ||||||
|  |               - AP | ||||||
|  |               - SWITCH | ||||||
|  |           required: false | ||||||
|  |           default: AP | ||||||
|       requestBody: |       requestBody: | ||||||
|         description: Information used to create the new entity |         description: Information used to create the new entity | ||||||
|         content: |         content: | ||||||
| @@ -3268,6 +3288,15 @@ paths: | |||||||
|             format: uuid |             format: uuid | ||||||
|             example: When modifying the root entity, the uuid 0000-0000-0000 must be entered. |             example: When modifying the root entity, the uuid 0000-0000-0000 must be entered. | ||||||
|           required: true |           required: true | ||||||
|  |         - in: query | ||||||
|  |           name: deviceType | ||||||
|  |           schema: | ||||||
|  |             type: string | ||||||
|  |             enum: | ||||||
|  |               - AP | ||||||
|  |               - SWITCH | ||||||
|  |           required: false | ||||||
|  |           default: AP | ||||||
|       requestBody: |       requestBody: | ||||||
|         description: Information used to modify the new entity |         description: Information used to modify the new entity | ||||||
|         content: |         content: | ||||||
|   | |||||||
| @@ -79,15 +79,12 @@ namespace OpenWifi { | |||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     bool APConfig::ReplaceVariablesInObject(const Poco::JSON::Object &Original, | 	void APConfig::ReplaceNestedVariables(const std::string uuid, Poco::JSON::Object &Result) { | ||||||
| 											Poco::JSON::Object &Result) { | 		/* | ||||||
| 		// get all the names and expand | 		Helper method contains code previously in ReplaceVariablesinObject. | ||||||
| 		auto Names = Original.getNames(); | 		Once the top-level variable is resolved, this will be called to resolve any | ||||||
| 		for (const auto &i : Names) { | 		variables nested within the top-level variable. | ||||||
|             if (i == "__variableBlock") { | 		*/ | ||||||
|                 if (Original.isArray(i)) { |  | ||||||
|                     auto UUIDs = Original.getArray(i); |  | ||||||
|                     for (const auto &uuid: *UUIDs) { |  | ||||||
| 		ProvObjects::VariableBlock VB; | 		ProvObjects::VariableBlock VB; | ||||||
| 		if (StorageService()->VariablesDB().GetRecord("id", uuid, VB)) { | 		if (StorageService()->VariablesDB().GetRecord("id", uuid, VB)) { | ||||||
| 			for (const auto &var: VB.variables) { | 			for (const auto &var: VB.variables) { | ||||||
| @@ -96,20 +93,17 @@ namespace OpenWifi { | |||||||
| 					P.parse(var.value).extract<Poco::JSON::Object::Ptr>(); | 					P.parse(var.value).extract<Poco::JSON::Object::Ptr>(); | ||||||
| 				auto VarNames = VariableBlockInfo->getNames(); | 				auto VarNames = VariableBlockInfo->getNames(); | ||||||
| 				for (const auto &j: VarNames) { | 				for (const auto &j: VarNames) { | ||||||
| //                                    std::cout << "Name: " << j << std::endl; |  | ||||||
| 					if(VariableBlockInfo->isArray(j)) { | 					if(VariableBlockInfo->isArray(j)) { | ||||||
| 						auto Elements = VariableBlockInfo->getArray(j); | 						auto Elements = VariableBlockInfo->getArray(j); | ||||||
| 						if(Elements->size()>0) { | 						if(Elements->size()>0) { | ||||||
| 							Poco::JSON::Array InnerArray; | 							Poco::JSON::Array InnerArray; | ||||||
| 							ReplaceVariablesInArray(*Elements, InnerArray); | 							ReplaceVariablesInArray(*Elements, InnerArray); | ||||||
| 							Result.set(j, InnerArray); | 							Result.set(j, InnerArray); | ||||||
| //                                            std::cout << "Array!!!" << std::endl; |  | ||||||
| 						} else { | 						} else { | ||||||
| //                      	std::cout << "Empty Array!!!" << std::endl; | //                      	std::cout << "Empty Array!!!" << std::endl; | ||||||
| 						} | 						} | ||||||
| 					} else if(VariableBlockInfo->isObject(j)) { | 					} else if(VariableBlockInfo->isObject(j)) { | ||||||
| 						Poco::JSON::Object  InnerEval; | 						Poco::JSON::Object  InnerEval; | ||||||
| //                                        std::cout << "Visiting object " << j << std::endl; |  | ||||||
| 						auto O = VariableBlockInfo->getObject(j); | 						auto O = VariableBlockInfo->getObject(j); | ||||||
| 						ReplaceVariablesInObject(*O,InnerEval); | 						ReplaceVariablesInObject(*O,InnerEval); | ||||||
| 						Result.set(j, InnerEval); | 						Result.set(j, InnerEval); | ||||||
| @@ -120,6 +114,38 @@ namespace OpenWifi { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  |     bool APConfig::ReplaceVariablesInObject(const Poco::JSON::Object &Original, | ||||||
|  | 											Poco::JSON::Object &Result) { | ||||||
|  | 		// get all the names and expand | ||||||
|  | 		auto Names = Original.getNames(); | ||||||
|  | 		for (const auto &i : Names) { | ||||||
|  |             if (i == "__variableBlock") { | ||||||
|  |                 if (Original.isArray(i)) { | ||||||
|  | 					/* | ||||||
|  | 					E.g. of what the variable block would look like in an array: | ||||||
|  | 					"ssids": [ | ||||||
|  | 						{ | ||||||
|  | 							"__variableBlock": [ | ||||||
|  | 								"79c083d2-d496-4de0-8600-76a63556851b" | ||||||
|  | 							] | ||||||
|  | 						} | ||||||
|  | 					] | ||||||
|  | 					*/ | ||||||
|  |                     auto UUIDs = Original.getArray(i); | ||||||
|  |                     for (const std::string &uuid: *UUIDs) { | ||||||
|  |                         ReplaceNestedVariables(uuid, Result); | ||||||
|  | 					} | ||||||
|  |                 } | ||||||
|  | 				else { | ||||||
|  | 					/* | ||||||
|  | 					E.g. of what the variable block would look like replacing an entire json blob: | ||||||
|  | 					"services" : { | ||||||
|  | 						"__variableBlock": "ef8db4c0-f0ef-40d2-b676-c9c02ef39430" | ||||||
|  | 					} | ||||||
|  | 					*/ | ||||||
|  | 					const std::string uuid = Original.get(i); | ||||||
|  | 					ReplaceNestedVariables(uuid, Result); | ||||||
| 				} | 				} | ||||||
|             } else if (i == "__radiusEndpoint") { |             } else if (i == "__radiusEndpoint") { | ||||||
|                 auto EndPointId = Original.get(i).toString(); |                 auto EndPointId = Original.get(i).toString(); | ||||||
|   | |||||||
| @@ -47,6 +47,7 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 		bool ReplaceVariablesInArray(const Poco::JSON::Array &O, | 		bool ReplaceVariablesInArray(const Poco::JSON::Array &O, | ||||||
| 									 Poco::JSON::Array &Result); | 									 Poco::JSON::Array &Result); | ||||||
|  | 		void ReplaceNestedVariables(const std::string uuid, Poco::JSON::Object &Result); | ||||||
| 		bool ReplaceVariablesInObject(const Poco::JSON::Object &Original, | 		bool ReplaceVariablesInObject(const Poco::JSON::Object &Original, | ||||||
| 									  Poco::JSON::Object &Result); | 									  Poco::JSON::Object &Result); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -54,6 +54,8 @@ namespace OpenWifi { | |||||||
|             FW = P->get(uCentralProtocol::FIRMWARE).toString(); |             FW = P->get(uCentralProtocol::FIRMWARE).toString(); | ||||||
|         if (P->has(uCentralProtocol::SERIALNUMBER)) |         if (P->has(uCentralProtocol::SERIALNUMBER)) | ||||||
|             SN = P->get(uCentralProtocol::SERIALNUMBER).toString(); |             SN = P->get(uCentralProtocol::SERIALNUMBER).toString(); | ||||||
|  |         else if (P->has(uCentralProtocol::SERIAL)) | ||||||
|  |             SN = P->get(uCentralProtocol::SERIAL).toString(); | ||||||
|         if (P->has("locale")) { |         if (P->has("locale")) { | ||||||
|             locale = P->get("locale").toString(); |             locale = P->get("locale").toString(); | ||||||
|         } |         } | ||||||
| @@ -83,6 +85,7 @@ namespace OpenWifi { | |||||||
| 					Poco::JSON::Parser Parser; | 					Poco::JSON::Parser Parser; | ||||||
| 					auto Object = Parser.parse(Msg->Payload()).extract<Poco::JSON::Object::Ptr>(); | 					auto Object = Parser.parse(Msg->Payload()).extract<Poco::JSON::Object::Ptr>(); | ||||||
|                     bool    Connected=true; |                     bool    Connected=true; | ||||||
|  |                     bool isConnection=false; | ||||||
|  |  | ||||||
| 					if (Object->has(uCentralProtocol::PAYLOAD)) { | 					if (Object->has(uCentralProtocol::PAYLOAD)) { | ||||||
|                         auto PayloadObj = Object->getObject(uCentralProtocol::PAYLOAD); |                         auto PayloadObj = Object->getObject(uCentralProtocol::PAYLOAD); | ||||||
| @@ -91,6 +94,7 @@ namespace OpenWifi { | |||||||
|                             auto PingObj = PayloadObj->getObject("ping"); |                             auto PingObj = PayloadObj->getObject("ping"); | ||||||
|                             ProcessPing(PingObj, Firmware, SerialNumber, Compatible, ConnectedIP, Locale); |                             ProcessPing(PingObj, Firmware, SerialNumber, Compatible, ConnectedIP, Locale); | ||||||
|                         } else if(PayloadObj->has("capabilities")) { |                         } else if(PayloadObj->has("capabilities")) { | ||||||
|  |                             isConnection=true; | ||||||
|                             ProcessConnect(PayloadObj, Firmware, SerialNumber, Compatible, ConnectedIP, Locale); |                             ProcessConnect(PayloadObj, Firmware, SerialNumber, Compatible, ConnectedIP, Locale); | ||||||
|                         } else if(PayloadObj->has("disconnection")) { |                         } else if(PayloadObj->has("disconnection")) { | ||||||
|                             //  we ignore disconnection in provisioning |                             //  we ignore disconnection in provisioning | ||||||
| @@ -102,7 +106,7 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
|                         if (!SerialNumber.empty() && Connected) { |                         if (!SerialNumber.empty() && Connected) { | ||||||
|                             StorageService()->InventoryDB().CreateFromConnection( |                             StorageService()->InventoryDB().CreateFromConnection( | ||||||
|                                     SerialNumber, ConnectedIP, Compatible, Locale); |                                     SerialNumber, ConnectedIP, Compatible, Locale, isConnection); | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
| 				} catch (const Poco::Exception &E) { | 				} catch (const Poco::Exception &E) { | ||||||
|   | |||||||
| @@ -91,9 +91,10 @@ namespace OpenWifi { | |||||||
| 			} | 			} | ||||||
| 			auto Config = RawObject->get("configuration").toString(); | 			auto Config = RawObject->get("configuration").toString(); | ||||||
| 			Poco::JSON::Object Answer; | 			Poco::JSON::Object Answer; | ||||||
| 			std::vector<std::string> Error; |             auto deviceType = GetParameter("deviceType", "AP"); | ||||||
|  |             std::string Error; | ||||||
| 			auto Res = | 			auto Res = | ||||||
| 				ValidateUCentralConfiguration(Config, Error, GetBoolParameter("strict", true)); | 				ValidateUCentralConfiguration(ConfigurationValidator::GetType(deviceType),Config, Error, GetBoolParameter("strict", true)); | ||||||
| 			Answer.set("valid", Res); | 			Answer.set("valid", Res); | ||||||
| 			Answer.set("error", Error); | 			Answer.set("error", Error); | ||||||
| 			return ReturnObject(Answer); | 			return ReturnObject(Answer); | ||||||
| @@ -134,11 +135,27 @@ namespace OpenWifi { | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		std::vector<std::string> Errors; | 		std::vector<std::string> Errors; | ||||||
| 		if (!ValidateConfigBlock(NewObject, Errors)) { |         auto deviceType = GetParameter("deviceType", "AP"); | ||||||
|  |         if (!ValidateConfigBlock(ConfigurationValidator::GetType(deviceType), NewObject, Errors)) { | ||||||
|             return BadRequest(RESTAPI::Errors::ConfigBlockInvalid); |             return BadRequest(RESTAPI::Errors::ConfigBlockInvalid); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | 		Types::UUIDvec_t ToVariables; | ||||||
|  | 		if (RawObject->has("variables")) { | ||||||
|  | 			for (const auto &i : NewObject.variables) { | ||||||
|  | 				if (!i.empty() && !StorageService()->VariablesDB().Exists("id", i)) { | ||||||
|  | 					return BadRequest(RESTAPI::Errors::VariableMustExist); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			for (const auto &i : NewObject.variables) | ||||||
|  | 				ToVariables.emplace_back(i); | ||||||
|  | 			 | ||||||
|  | 			ToVariables = NewObject.variables; | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		if (DB_.CreateRecord(NewObject)) { | 		if (DB_.CreateRecord(NewObject)) { | ||||||
|  | 			AddMembership(StorageService()->VariablesDB(), | ||||||
|  | 							 &ProvObjects::VariableBlock::configurations, ToVariables, NewObject.info.id); | ||||||
| 			MoveUsage(StorageService()->PolicyDB(), DB_, "", NewObject.managementPolicy, | 			MoveUsage(StorageService()->PolicyDB(), DB_, "", NewObject.managementPolicy, | ||||||
| 					  NewObject.info.id); | 					  NewObject.info.id); | ||||||
| 			AddMembership(StorageService()->VenueDB(), &ProvObjects::Venue::configurations, | 			AddMembership(StorageService()->VenueDB(), &ProvObjects::Venue::configurations, | ||||||
| @@ -185,7 +202,8 @@ namespace OpenWifi { | |||||||
| 			Existing.deviceTypes = NewObject.deviceTypes; | 			Existing.deviceTypes = NewObject.deviceTypes; | ||||||
|  |  | ||||||
| 		std::vector<std::string> Errors; | 		std::vector<std::string> Errors; | ||||||
| 		if (!ValidateConfigBlock(NewObject, Errors)) { |         auto deviceType = GetParameter("deviceType", "AP"); | ||||||
|  |         if (!ValidateConfigBlock(ConfigurationValidator::GetType(deviceType), NewObject, Errors)) { | ||||||
|             return BadRequest(RESTAPI::Errors::ConfigBlockInvalid); |             return BadRequest(RESTAPI::Errors::ConfigBlockInvalid); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -389,6 +389,13 @@ namespace OpenWifi { | |||||||
| 			DB.ManipulateVectorMember(T, "id", Obj, Id, true); | 			DB.ManipulateVectorMember(T, "id", Obj, Id, true); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	template <typename db_type, typename Member> | ||||||
|  | 	void AddMembership(db_type &DB, Member T, const Types::UUIDvec_t &Obj, const std::string &Id) { | ||||||
|  | 		for (const auto &i : Obj) { | ||||||
|  | 			AddMembership(DB, T, i, Id); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	template <typename db_type, typename Member> | 	template <typename db_type, typename Member> | ||||||
| 	void ManageMembership(db_type &DB, Member T, const std::string &From, const std::string &To, | 	void ManageMembership(db_type &DB, Member T, const std::string &From, const std::string &To, | ||||||
| 						  const std::string &Id) { | 						  const std::string &Id) { | ||||||
| @@ -431,7 +438,7 @@ namespace OpenWifi { | |||||||
| 		return EntityDB::RootUUID(); | 		return EntityDB::RootUUID(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	inline bool ValidateConfigBlock(const ProvObjects::DeviceConfiguration &Config, |     inline bool ValidateConfigBlock(ConfigurationValidator::ConfigurationType Type, const ProvObjects::DeviceConfiguration &Config, | ||||||
|                                     std::vector<std::string> &Errors) { |                                     std::vector<std::string> &Errors) { | ||||||
|         static const std::vector<std::string> SectionNames{ |         static const std::vector<std::string> SectionNames{ | ||||||
|                 "globals",	   "interfaces", "metrics", "radios",	  "services",	"unit", |                 "globals",	   "interfaces", "metrics", "radios",	  "services",	"unit", | ||||||
| @@ -460,9 +467,11 @@ namespace OpenWifi { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             try { |             try { | ||||||
| 				if (ValidateUCentralConfiguration(i.configuration, Errors, true)) { |                 std::string Error; | ||||||
|  |                 if (ValidateUCentralConfiguration(Type,i.configuration, Error, true)) { | ||||||
|                     // std::cout << "Block: " << i.name << " is valid" << std::endl; |                     // std::cout << "Block: " << i.name << " is valid" << std::endl; | ||||||
|                 } else { |                 } else { | ||||||
|  |                     Errors.push_back(Error); | ||||||
|                     return false; |                     return false; | ||||||
|                 } |                 } | ||||||
|             } catch (...) { |             } catch (...) { | ||||||
| @@ -535,7 +544,7 @@ namespace OpenWifi { | |||||||
| 						ProvObjects::DeviceConfiguration DC; | 						ProvObjects::DeviceConfiguration DC; | ||||||
| 						if (DC.from_json(ConfigurationDetails)) { | 						if (DC.from_json(ConfigurationDetails)) { | ||||||
| 							if constexpr (std::is_same_v<Type, ProvObjects::InventoryTag>) { | 							if constexpr (std::is_same_v<Type, ProvObjects::InventoryTag>) { | ||||||
| 								if (!ValidateConfigBlock(DC, Errors)) { | 								if (!ValidateConfigBlock(ConfigurationValidator::ConfigurationType::AP,DC, Errors)) { | ||||||
| 									break; | 									break; | ||||||
| 								} | 								} | ||||||
| 								ProvObjects::CreateObjectInfo(R.UserInfo_.userinfo, DC.info); | 								ProvObjects::CreateObjectInfo(R.UserInfo_.userinfo, DC.info); | ||||||
|   | |||||||
| @@ -131,7 +131,9 @@ namespace OpenWifi { | |||||||
| 		} else { | 		} else { | ||||||
| 			ProvObjects::InventoryTagVec Tags; | 			ProvObjects::InventoryTagVec Tags; | ||||||
| 			DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, "", OrderBy); | 			DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, "", OrderBy); | ||||||
| 			return MakeJSONObjectArray("taglist", Tags, *this); |             return SendList(Tags, SerialOnly); | ||||||
|  |  | ||||||
|  | //			return MakeJSONObjectArray("taglist", Tags, *this); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } // namespace OpenWifi | } // namespace OpenWifi | ||||||
| @@ -187,7 +187,7 @@ namespace OpenWifi { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (!NewObject.sourceIP.empty() && CIDR::ValidateIpRanges(NewObject.sourceIP)) { | 		if (!NewObject.sourceIP.empty() && !CIDR::ValidateIpRanges(NewObject.sourceIP)) { | ||||||
| 			return BadRequest(RESTAPI::Errors::InvalidIPRanges); | 			return BadRequest(RESTAPI::Errors::InvalidIPRanges); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -587,6 +587,9 @@ namespace OpenWifi::ProvObjects { | |||||||
| 		field_to_json(Obj, "locale", locale); | 		field_to_json(Obj, "locale", locale); | ||||||
| 		field_to_json(Obj, "realMacAddress", realMacAddress); | 		field_to_json(Obj, "realMacAddress", realMacAddress); | ||||||
| 		field_to_json(Obj, "doNotAllowOverrides", doNotAllowOverrides); | 		field_to_json(Obj, "doNotAllowOverrides", doNotAllowOverrides); | ||||||
|  |         field_to_json(Obj, "imported", imported); | ||||||
|  |         field_to_json(Obj, "connected", connected); | ||||||
|  |         field_to_json(Obj, "platform", platform); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) { | 	bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||||
| @@ -609,6 +612,9 @@ namespace OpenWifi::ProvObjects { | |||||||
| 			field_from_json(Obj, "locale", locale); | 			field_from_json(Obj, "locale", locale); | ||||||
| 			field_from_json(Obj, "realMacAddress", realMacAddress); | 			field_from_json(Obj, "realMacAddress", realMacAddress); | ||||||
| 			field_from_json(Obj, "doNotAllowOverrides", doNotAllowOverrides); | 			field_from_json(Obj, "doNotAllowOverrides", doNotAllowOverrides); | ||||||
|  |             field_from_json(Obj, "imported", imported); | ||||||
|  |             field_from_json(Obj, "connected", connected); | ||||||
|  |             field_from_json(Obj, "platform", platform); | ||||||
| 			return true; | 			return true; | ||||||
| 		} catch (...) { | 		} catch (...) { | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -490,9 +490,11 @@ namespace OpenWifi::ProvObjects { | |||||||
|         std::string locale; |         std::string locale; | ||||||
|         std::string realMacAddress; |         std::string realMacAddress; | ||||||
|         bool doNotAllowOverrides = false; |         bool doNotAllowOverrides = false; | ||||||
|  |         std::uint64_t imported=0; | ||||||
|  |         std::uint64_t connected=0; | ||||||
|  |         std::string platform{"AP"}; | ||||||
|  |  | ||||||
|         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); | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -17,33 +17,42 @@ | |||||||
| namespace OpenWifi { | namespace OpenWifi { | ||||||
| 	class ConfigurationValidator : public SubSystemServer { | 	class ConfigurationValidator : public SubSystemServer { | ||||||
| 	  public: | 	  public: | ||||||
|  |  | ||||||
|  | 		enum class ConfigurationType { AP = 0 , SWITCH = 1}; | ||||||
|  |  | ||||||
| 		static auto instance() { | 		static auto instance() { | ||||||
| 			static auto instance_ = new ConfigurationValidator; | 			static auto instance_ = new ConfigurationValidator; | ||||||
| 			return instance_; | 			return instance_; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		bool Validate(const std::string &C, std::vector<std::string> &Errors, bool Strict); | 		bool Validate(ConfigurationType Type, const std::string &C, std::string &Errors, bool Strict); | ||||||
| 		int Start() override; | 		int Start() override; | ||||||
| 		void Stop() override; | 		void Stop() override; | ||||||
| 		void reinitialize(Poco::Util::Application &self) override; | 		void reinitialize(Poco::Util::Application &self) override; | ||||||
|  |  | ||||||
|  | 		inline static ConfigurationType GetType(const std::string &type) { | ||||||
|  | 			std::string Type = Poco::toUpper(type); | ||||||
|  | 			if (Type == "AP") | ||||||
|  | 				return ConfigurationType::AP; | ||||||
|  | 			if (Type == "SWITCH") | ||||||
|  | 				return ConfigurationType::SWITCH; | ||||||
|  | 			return ConfigurationType::AP; | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 	  private: | 	  private: | ||||||
| 		bool Initialized_ = false; | 		bool Initialized_ = false; | ||||||
| 		bool Working_ = false; | 		bool Working_ = false; | ||||||
| 		void Init(); | 		void Init(); | ||||||
| 		std::unique_ptr<valijson::Schema> RootSchema_; | 		std::array<valijson::Schema,2> 			RootSchema_; | ||||||
| 		std::unique_ptr<valijson::SchemaParser> SchemaParser_; | 		bool SetSchema(ConfigurationType Type, const std::string &SchemaStr); | ||||||
| 		std::unique_ptr<valijson::adapters::PocoJsonAdapter> PocoJsonAdapter_; |  | ||||||
| 		Poco::JSON::Object::Ptr SchemaDocPtr_; |  | ||||||
| 		bool SetSchema(const std::string &SchemaStr); |  | ||||||
|  |  | ||||||
| 		ConfigurationValidator() | 		ConfigurationValidator() | ||||||
| 			: SubSystemServer("ConfigValidator", "CFG-VALIDATOR", "config.validator") {} | 			: SubSystemServer("ConfigValidator", "CFG-VALIDATOR", "config.validator") {} | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	inline auto ConfigurationValidator() { return ConfigurationValidator::instance(); } | 	inline auto ConfigurationValidator() { return ConfigurationValidator::instance(); } | ||||||
| 	inline bool ValidateUCentralConfiguration(const std::string &C, std::vector<std::string> &Error, | 	inline bool ValidateUCentralConfiguration(ConfigurationValidator::ConfigurationType Type, const std::string &C, std::string &Errors, | ||||||
| 											  bool strict) { | 											  bool strict) { | ||||||
| 		return ConfigurationValidator::instance()->Validate(C, Error, strict); | 		return ConfigurationValidator::instance()->Validate(Type, C, Errors, strict); | ||||||
| 	} | 	} | ||||||
| } // namespace OpenWifi | } // namespace OpenWifi | ||||||
|   | |||||||
| @@ -16,9 +16,9 @@ namespace OpenWifi { | |||||||
| 		KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg, | 		KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg, | ||||||
| 									false); | 									false); | ||||||
| 		while (Running_) { | 		while (Running_) { | ||||||
| 			Poco::Thread::trySleep((unsigned long)MicroServiceDaemonBusTimer()); | 			if(!Poco::Thread::trySleep((unsigned long)MicroServiceDaemonBusTimer())) { | ||||||
| 			if (!Running_) |  | ||||||
|                 break; |                 break; | ||||||
|  |             } | ||||||
| 			Msg = (MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE)); | 			Msg = (MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE)); | ||||||
| 			KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), | 			KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), | ||||||
| 										Msg, false); | 										Msg, false); | ||||||
| @@ -29,7 +29,7 @@ namespace OpenWifi { | |||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	void EventBusManager::Start() { | 	void EventBusManager::Start() { | ||||||
| 		poco_information(Logger(), "Starting..."); | 		poco_information(Logger_, "Starting..."); | ||||||
| 		if (KafkaManager()->Enabled()) { | 		if (KafkaManager()->Enabled()) { | ||||||
| 			Thread_.start(*this); | 			Thread_.start(*this); | ||||||
| 		} | 		} | ||||||
| @@ -37,11 +37,11 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 	void EventBusManager::Stop() { | 	void EventBusManager::Stop() { | ||||||
| 		if (KafkaManager()->Enabled()) { | 		if (KafkaManager()->Enabled()) { | ||||||
| 			poco_information(Logger(), "Stopping..."); | 			poco_information(Logger_, "Stopping..."); | ||||||
| 			Running_ = false; | 			Running_ = false; | ||||||
| 			Thread_.wakeUp(); | 			Thread_.wakeUp(); | ||||||
| 			Thread_.join(); | 			Thread_.join(); | ||||||
| 			poco_information(Logger(), "Stopped..."); | 			poco_information(Logger_, "Stopped..."); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -22,7 +22,6 @@ namespace OpenWifi { | |||||||
| 			return instance_; | 			return instance_; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		explicit EventBusManager(Poco::Logger &L); |  | ||||||
| 		void run() final; | 		void run() final; | ||||||
| 		void Start(); | 		void Start(); | ||||||
| 		void Stop(); | 		void Stop(); | ||||||
|   | |||||||
| @@ -79,8 +79,10 @@ namespace OpenWifi { | |||||||
| 		Utils::SetThreadName("Kafka:Prod"); | 		Utils::SetThreadName("Kafka:Prod"); | ||||||
| 		cppkafka::Configuration Config( | 		cppkafka::Configuration Config( | ||||||
| 			{{"client.id", MicroServiceConfigGetString("openwifi.kafka.client.id", "")}, | 			{{"client.id", MicroServiceConfigGetString("openwifi.kafka.client.id", "")}, | ||||||
| 			 {"metadata.broker.list", | 			 {"metadata.broker.list",MicroServiceConfigGetString("openwifi.kafka.brokerlist", "")} // , | ||||||
| 			  MicroServiceConfigGetString("openwifi.kafka.brokerlist", "")}}); | 			 // {"send.buffer.bytes", KafkaManager()->KafkaManagerMaximumPayloadSize() } | ||||||
|  | 			} | ||||||
|  |  		); | ||||||
|  |  | ||||||
| 		AddKafkaSecurity(Config); | 		AddKafkaSecurity(Config); | ||||||
|  |  | ||||||
| @@ -275,6 +277,7 @@ namespace OpenWifi { | |||||||
| 	int KafkaManager::Start() { | 	int KafkaManager::Start() { | ||||||
| 		if (!KafkaEnabled_) | 		if (!KafkaEnabled_) | ||||||
| 			return 0; | 			return 0; | ||||||
|  | 		MaxPayloadSize_ = MicroServiceConfigGetInt("openwifi.kafka.max.payload", 250000); | ||||||
| 		ConsumerThr_.Start(); | 		ConsumerThr_.Start(); | ||||||
| 		ProducerThr_.Start(); | 		ProducerThr_.Start(); | ||||||
| 		return 0; | 		return 0; | ||||||
|   | |||||||
| @@ -94,11 +94,14 @@ namespace OpenWifi { | |||||||
| 			return ConsumerThr_.UnregisterTopicWatcher(Topic,Id); | 			return ConsumerThr_.UnregisterTopicWatcher(Topic,Id); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		std::uint64_t KafkaManagerMaximumPayloadSize() const { return MaxPayloadSize_; } | ||||||
|  |  | ||||||
| 	  private: | 	  private: | ||||||
| 		bool KafkaEnabled_ = false; | 		bool KafkaEnabled_ = false; | ||||||
| 		std::string SystemInfoWrapper_; | 		std::string SystemInfoWrapper_; | ||||||
| 		KafkaProducer ProducerThr_; | 		KafkaProducer ProducerThr_; | ||||||
| 		KafkaConsumer ConsumerThr_; | 		KafkaConsumer ConsumerThr_; | ||||||
|  | 		std::uint64_t MaxPayloadSize_ = 250000; | ||||||
|  |  | ||||||
| 		void PartitionAssignment(const cppkafka::TopicPartitionList &partitions); | 		void PartitionAssignment(const cppkafka::TopicPartitionList &partitions); | ||||||
| 		void PartitionRevocation(const cppkafka::TopicPartitionList &partitions); | 		void PartitionRevocation(const cppkafka::TopicPartitionList &partitions); | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| // | // | ||||||
|  | // | ||||||
| // Created by stephane bourque on 2022-10-26. | // Created by stephane bourque on 2022-10-26. | ||||||
| // | // | ||||||
|  |  | ||||||
| @@ -29,9 +30,11 @@ | |||||||
| #include "framework/WebSocketLogger.h" | #include "framework/WebSocketLogger.h" | ||||||
| #include "framework/utils.h" | #include "framework/utils.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | #ifdef  USE_MEDUSA_CLIENT | ||||||
|  | #include <medusa/MedusaClient.h> | ||||||
|  | #endif | ||||||
|  |  | ||||||
| 	void MicroService::Exit(int Reason) { std::exit(Reason); } | namespace OpenWifi { | ||||||
|  |  | ||||||
| 	static std::string MakeServiceListString(const Types::MicroServiceMetaMap &Services) { | 	static std::string MakeServiceListString(const Types::MicroServiceMetaMap &Services) { | ||||||
|         std::string SvcList; |         std::string SvcList; | ||||||
| @@ -204,9 +207,11 @@ namespace OpenWifi { | |||||||
| 			Res.push_back(ServiceRec); | 			Res.push_back(ServiceRec); | ||||||
| 		} | 		} | ||||||
| 		return Res; | 		return Res; | ||||||
|  |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	void MicroService::LoadConfigurationFile() { | 	void MicroService::LoadConfigurationFile() { | ||||||
|  |         if(ConfigContent_.empty()) { | ||||||
|             std::string Location = Poco::Environment::get(DAEMON_CONFIG_ENV_VAR, "."); |             std::string Location = Poco::Environment::get(DAEMON_CONFIG_ENV_VAR, "."); | ||||||
|             ConfigFileName_ = |             ConfigFileName_ = | ||||||
|                 ConfigFileName_.empty() ? Location + "/" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_; |                 ConfigFileName_.empty() ? Location + "/" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_; | ||||||
| @@ -220,9 +225,11 @@ namespace OpenWifi { | |||||||
|                           << std::endl; |                           << std::endl; | ||||||
|                 std::exit(Poco::Util::Application::EXIT_CONFIG); |                 std::exit(Poco::Util::Application::EXIT_CONFIG); | ||||||
|             } |             } | ||||||
|  |  | ||||||
| 		// 	    loadConfiguration(ConfigFile.toString()); |  | ||||||
|             PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration(ConfigFile.toString()); |             PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration(ConfigFile.toString()); | ||||||
|  |         } else { | ||||||
|  |             std::istringstream is(ConfigContent_); | ||||||
|  |             PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration(is); | ||||||
|  |         } | ||||||
| 		configPtr()->addWriteable(PropConfigurationFile_, PRIO_DEFAULT); | 		configPtr()->addWriteable(PropConfigurationFile_, PRIO_DEFAULT); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -425,11 +432,13 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 	void DaemonPostInitialization(Poco::Util::Application &self); | 	void DaemonPostInitialization(Poco::Util::Application &self); | ||||||
|  |  | ||||||
| 	void MicroService::initialize(Poco::Util::Application &self) { |     void MicroService::StartEverything(Poco::Util::Application &self) { | ||||||
| 		// add the default services |  | ||||||
|         LoadConfigurationFile(); |         LoadConfigurationFile(); | ||||||
|         InitializeLoggingSystem(); |         InitializeLoggingSystem(); | ||||||
|  |  | ||||||
|  |         static bool InitializedBaseService=false; | ||||||
|  |         if(!InitializedBaseService) { | ||||||
|  |             InitializedBaseService = true; | ||||||
|             SubSystems_.push_back(KafkaManager()); |             SubSystems_.push_back(KafkaManager()); | ||||||
|             SubSystems_.push_back(ALBHealthCheckServer()); |             SubSystems_.push_back(ALBHealthCheckServer()); | ||||||
|             SubSystems_.push_back(RESTAPI_ExtServer()); |             SubSystems_.push_back(RESTAPI_ExtServer()); | ||||||
| @@ -437,11 +446,13 @@ namespace OpenWifi { | |||||||
| #ifndef TIP_SECURITY_SERVICE | #ifndef TIP_SECURITY_SERVICE | ||||||
|             SubSystems_.push_back(AuthClient()); |             SubSystems_.push_back(AuthClient()); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|             Poco::Net::initializeSSL(); |             Poco::Net::initializeSSL(); | ||||||
|             Poco::Net::HTTPStreamFactory::registerFactory(); |             Poco::Net::HTTPStreamFactory::registerFactory(); | ||||||
|             Poco::Net::HTTPSStreamFactory::registerFactory(); |             Poco::Net::HTTPSStreamFactory::registerFactory(); | ||||||
|             Poco::Net::FTPStreamFactory::registerFactory(); |             Poco::Net::FTPStreamFactory::registerFactory(); | ||||||
|             Poco::Net::FTPSStreamFactory::registerFactory(); |             Poco::Net::FTPSStreamFactory::registerFactory(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         Poco::File DataDir(ConfigPath("openwifi.system.data")); |         Poco::File DataDir(ConfigPath("openwifi.system.data")); | ||||||
|         DataDir_ = DataDir.path(); |         DataDir_ = DataDir.path(); | ||||||
| @@ -470,6 +481,22 @@ namespace OpenWifi { | |||||||
|         KafkaManager()->RegisterTopicWatcher(KafkaTopics::SERVICE_EVENTS, F); |         KafkaManager()->RegisterTopicWatcher(KafkaTopics::SERVICE_EVENTS, F); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     void MicroService::StopEverything([[maybe_unused]] Poco::Util::Application &self) { | ||||||
|  |         LoadConfigurationFile(); | ||||||
|  |         InitializeLoggingSystem(); | ||||||
|  |  | ||||||
|  |         Types::TopicNotifyFunction F = [this](const std::string &Key, const std::string &Payload) { | ||||||
|  |             this->BusMessageReceived(Key, Payload); | ||||||
|  |         }; | ||||||
|  |         KafkaManager()->RegisterTopicWatcher(KafkaTopics::SERVICE_EVENTS, F); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void MicroService::initialize([[maybe_unused]] Poco::Util::Application &self) { | ||||||
|  | #ifndef USE_MEDUSA_CLIENT | ||||||
|  |         StartEverything(self); | ||||||
|  | #endif | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	void MicroService::uninitialize() { | 	void MicroService::uninitialize() { | ||||||
| 		// add your own uninitialization code here | 		// add your own uninitialization code here | ||||||
| 		ServerApplication::uninitialize(); | 		ServerApplication::uninitialize(); | ||||||
| @@ -753,6 +780,8 @@ namespace OpenWifi { | |||||||
| 		MicroServiceErrorHandler ErrorHandler(*this); | 		MicroServiceErrorHandler ErrorHandler(*this); | ||||||
| 		Poco::ErrorHandler::set(&ErrorHandler); | 		Poco::ErrorHandler::set(&ErrorHandler); | ||||||
|  |  | ||||||
|  |         Args_ = args; | ||||||
|  |  | ||||||
| 		if (!HelpRequested_) { | 		if (!HelpRequested_) { | ||||||
| 			SavePID(); | 			SavePID(); | ||||||
|  |  | ||||||
| @@ -768,11 +797,18 @@ namespace OpenWifi { | |||||||
| 				poco_information(logger, "Starting as a daemon."); | 				poco_information(logger, "Starting as a daemon."); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | #ifdef USE_MEDUSA_CLIENT | ||||||
|  |             MedusaClient::instance()->SetSubSystems(SubSystems_); | ||||||
|  |             MedusaClient::instance()->Start(); | ||||||
|  | 			waitForTerminationRequest(); | ||||||
|  |             MedusaClient::instance()->Stop(); | ||||||
|  | #else | ||||||
| 			poco_information(logger, fmt::format("System ID set to {}", ID_)); | 			poco_information(logger, fmt::format("System ID set to {}", ID_)); | ||||||
| 			StartSubSystemServers(); | 			StartSubSystemServers(); | ||||||
| 			waitForTerminationRequest(); | 			waitForTerminationRequest(); | ||||||
| 			StopSubSystemServers(); | 			StopSubSystemServers(); | ||||||
| 			logger.notice(fmt::format("Stopped {}...", DAEMON_APP_NAME)); | 			logger.notice(fmt::format("Stopped {}...", DAEMON_APP_NAME)); | ||||||
|  | #endif | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		return Application::EXIT_OK; | 		return Application::EXIT_OK; | ||||||
|   | |||||||
| @@ -55,9 +55,6 @@ namespace OpenWifi { | |||||||
| #include "nlohmann/json.hpp" | #include "nlohmann/json.hpp" | ||||||
| #include "ow_version.h" | #include "ow_version.h" | ||||||
|  |  | ||||||
| #define _OWDEBUG_ std::cout << __FILE__ << ":" << __LINE__ << std::endl; |  | ||||||
| // #define _OWDEBUG_ Logger().debug(Poco::format("%s: %lu",__FILE__,__LINE__)); |  | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace OpenWifi { | ||||||
|  |  | ||||||
| 	class MicroService : public Poco::Util::ServerApplication { | 	class MicroService : public Poco::Util::ServerApplication { | ||||||
| @@ -70,7 +67,6 @@ namespace OpenWifi { | |||||||
| 			  SubSystems_(std::move(Subsystems)), Logger_(Poco::Logger::get("FRAMEWORK")) { | 			  SubSystems_(std::move(Subsystems)), Logger_(Poco::Logger::get("FRAMEWORK")) { | ||||||
| 			instance_ = this; | 			instance_ = this; | ||||||
| 			RandomEngine_.seed(std::chrono::steady_clock::now().time_since_epoch().count()); | 			RandomEngine_.seed(std::chrono::steady_clock::now().time_since_epoch().count()); | ||||||
| 			// Logger_ = Poco::Logger::root().get("BASE-SVC"); |  | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		inline static const char *ExtraConfigurationFilename = "/configuration_override.json"; | 		inline static const char *ExtraConfigurationFilename = "/configuration_override.json"; | ||||||
| @@ -92,7 +88,7 @@ namespace OpenWifi { | |||||||
| 		inline uint64_t DaemonBusTimer() const { return DAEMON_BUS_TIMER; }; | 		inline uint64_t DaemonBusTimer() const { return DAEMON_BUS_TIMER; }; | ||||||
| 		[[nodiscard]] const std::string &AppName() { return DAEMON_APP_NAME; } | 		[[nodiscard]] const std::string &AppName() { return DAEMON_APP_NAME; } | ||||||
| 		static inline uint64_t GetPID() { return Poco::Process::id(); }; | 		static inline uint64_t GetPID() { return Poco::Process::id(); }; | ||||||
| 		[[nodiscard]] inline const std::string GetPublicAPIEndPoint() { | 		[[nodiscard]] inline std::string GetPublicAPIEndPoint() const { | ||||||
| 			return MyPublicEndPoint_ + "/api/v1"; | 			return MyPublicEndPoint_ + "/api/v1"; | ||||||
| 		}; | 		}; | ||||||
| 		[[nodiscard]] inline const std::string &GetUIURI() const { return UIURI_; }; | 		[[nodiscard]] inline const std::string &GetUIURI() const { return UIURI_; }; | ||||||
| @@ -107,7 +103,8 @@ namespace OpenWifi { | |||||||
| 		} | 		} | ||||||
| 		static MicroService &instance() { return *instance_; } | 		static MicroService &instance() { return *instance_; } | ||||||
|  |  | ||||||
| 		inline void Exit(int Reason); | 		inline void Exit(int Reason) { std::exit(Reason); } | ||||||
|  |  | ||||||
| 		void BusMessageReceived(const std::string &Key, const std::string &Payload); | 		void BusMessageReceived(const std::string &Key, const std::string &Payload); | ||||||
| 		Types::MicroServiceMetaVec GetServices(const std::string &Type); | 		Types::MicroServiceMetaVec GetServices(const std::string &Type); | ||||||
| 		Types::MicroServiceMetaVec GetServices(); | 		Types::MicroServiceMetaVec GetServices(); | ||||||
| @@ -115,6 +112,8 @@ namespace OpenWifi { | |||||||
| 		void Reload(); | 		void Reload(); | ||||||
| 		void LoadMyConfig(); | 		void LoadMyConfig(); | ||||||
| 		void initialize(Poco::Util::Application &self) override; | 		void initialize(Poco::Util::Application &self) override; | ||||||
|  |         void StartEverything(Poco::Util::Application &self); | ||||||
|  |         void StopEverything(Poco::Util::Application &self); | ||||||
|         void uninitialize() override; |         void uninitialize() override; | ||||||
| 		void reinitialize(Poco::Util::Application &self) override; | 		void reinitialize(Poco::Util::Application &self) override; | ||||||
| 		void defineOptions(Poco::Util::OptionSet &options) override; | 		void defineOptions(Poco::Util::OptionSet &options) override; | ||||||
| @@ -132,7 +131,7 @@ namespace OpenWifi { | |||||||
| 		void Reload(const std::string &Sub); | 		void Reload(const std::string &Sub); | ||||||
| 		Types::StringVec GetSubSystems() const; | 		Types::StringVec GetSubSystems() const; | ||||||
| 		Types::StringPairVec GetLogLevels(); | 		Types::StringPairVec GetLogLevels(); | ||||||
| 		const Types::StringVec &GetLogLevelNames(); | 		static const Types::StringVec &GetLogLevelNames(); | ||||||
| 		uint64_t ConfigGetInt(const std::string &Key, uint64_t Default); | 		uint64_t ConfigGetInt(const std::string &Key, uint64_t Default); | ||||||
| 		uint64_t ConfigGetInt(const std::string &Key); | 		uint64_t ConfigGetInt(const std::string &Key); | ||||||
| 		uint64_t ConfigGetBool(const std::string &Key, bool Default); | 		uint64_t ConfigGetBool(const std::string &Key, bool Default); | ||||||
| @@ -166,12 +165,25 @@ namespace OpenWifi { | |||||||
| 								const std::string &FormatterPattern, | 								const std::string &FormatterPattern, | ||||||
| 								const std::string &root_env_var); | 								const std::string &root_env_var); | ||||||
| 		inline bool AllowExternalMicroServices() const { return AllowExternalMicroServices_; } | 		inline bool AllowExternalMicroServices() const { return AllowExternalMicroServices_; } | ||||||
|  |         const ArgVec &Args() const { return Args_; } | ||||||
|  |  | ||||||
|  |         inline void SetConfigContent(const std::string &Content) { ConfigContent_ = Content; } | ||||||
|  |  | ||||||
|  |         inline std::optional<OpenWifi::Types::MicroServiceMeta> GetPrivateEndPointServiceKey( const std::string & ServicePrivateEndPoint ) { | ||||||
|  |             std::lock_guard   G(InfraMutex_); | ||||||
|  |             auto K = Services_.find(ServicePrivateEndPoint); | ||||||
|  |             if(K==end(Services_)) { | ||||||
|  |                 return std::nullopt; | ||||||
|  |             } | ||||||
|  |             return K->second; | ||||||
|  |         } | ||||||
|  |  | ||||||
| 	  private: | 	  private: | ||||||
| 		static MicroService *instance_; | 		static MicroService *instance_; | ||||||
| 		bool HelpRequested_ = false; | 		bool HelpRequested_ = false; | ||||||
| 		std::string LogDir_; | 		std::string LogDir_; | ||||||
| 		std::string ConfigFileName_; | 		std::string ConfigFileName_; | ||||||
|  |         std::string ConfigContent_; | ||||||
| 		uint64_t ID_ = 1; | 		uint64_t ID_ = 1; | ||||||
| 		Poco::SharedPtr<Poco::Crypto::RSAKey> AppKey_; | 		Poco::SharedPtr<Poco::Crypto::RSAKey> AppKey_; | ||||||
| 		bool DebugMode_ = false; | 		bool DebugMode_ = false; | ||||||
| @@ -201,6 +213,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}; | ||||||
|  |         ArgVec Args_; | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	inline MicroService *MicroService::instance_ = nullptr; | 	inline MicroService *MicroService::instance_ = nullptr; | ||||||
|   | |||||||
| @@ -133,4 +133,8 @@ namespace OpenWifi { | |||||||
| 		return MicroService::instance().Hash(); | 		return MicroService::instance().Hash(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  |     std::optional<OpenWifi::Types::MicroServiceMeta> MicroServicePrivateAccessKey(const std::string &servicePrivateEndPoint) { | ||||||
|  |         return MicroService::instance().GetPrivateEndPointServiceKey(servicePrivateEndPoint); | ||||||
|  |     } | ||||||
|  |  | ||||||
| } // namespace OpenWifi | } // namespace OpenWifi | ||||||
|   | |||||||
| @@ -23,6 +23,8 @@ namespace OpenWifi { | |||||||
| 	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(); | 	std::string MicroServiceAccessKey(); | ||||||
|  |     std::optional<OpenWifi::Types::MicroServiceMeta> MicroServicePrivateAccessKey(const std::string &servicePrivateEndPoint); | ||||||
|  |  | ||||||
|     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(); | ||||||
|   | |||||||
| @@ -58,11 +58,9 @@ namespace OpenWifi { | |||||||
| 	void UI_WebSocketClientServer::run() { | 	void UI_WebSocketClientServer::run() { | ||||||
| 		Running_ = true; | 		Running_ = true; | ||||||
| 		while (Running_) { | 		while (Running_) { | ||||||
| 			Poco::Thread::trySleep(2000); | 			if(!Poco::Thread::trySleep(2000)) { | ||||||
|  |  | ||||||
| 			if (!Running_) |  | ||||||
|                 break; |                 break; | ||||||
|  |             } | ||||||
| 			std::lock_guard G(LocalMutex_); | 			std::lock_guard G(LocalMutex_); | ||||||
| 			for (const auto i : ToBeRemoved_) { | 			for (const auto i : ToBeRemoved_) { | ||||||
| 				// std::cout << "Erasing old WS UI connection..." << std::endl; | 				// std::cout << "Erasing old WS UI connection..." << std::endl; | ||||||
|   | |||||||
| @@ -565,6 +565,7 @@ namespace OpenWifi::RESTAPI::Protocol { | |||||||
|  |  | ||||||
| 	static const char *TRANSFER = "transfer"; | 	static const char *TRANSFER = "transfer"; | ||||||
| 	static const char *CERTUPDATE = "certupdate"; | 	static const char *CERTUPDATE = "certupdate"; | ||||||
|  | 	static const char *POWERCYCLE = "powercycle"; | ||||||
| 	static const char *RRM = "rrm"; | 	static const char *RRM = "rrm"; | ||||||
|  |  | ||||||
| 	static const char *REQUIREMENTS = "requirements"; | 	static const char *REQUIREMENTS = "requirements"; | ||||||
| @@ -687,6 +688,7 @@ namespace OpenWifi::uCentralProtocol { | |||||||
|  |  | ||||||
| 	static const char *TRANSFER = "transfer"; | 	static const char *TRANSFER = "transfer"; | ||||||
| 	static const char *CERTUPDATE = "certupdate"; | 	static const char *CERTUPDATE = "certupdate"; | ||||||
|  | 	static const char *POWERCYCLE = "powercycle"; | ||||||
| 	static const char *RRM = "rrm"; | 	static const char *RRM = "rrm"; | ||||||
| 	static const char *ACTIONS = "actions"; | 	static const char *ACTIONS = "actions"; | ||||||
|  |  | ||||||
| @@ -785,6 +787,7 @@ namespace OpenWifi::APCommands { | |||||||
| 		rrm, | 		rrm, | ||||||
| 		certupdate, | 		certupdate, | ||||||
| 		transfer, | 		transfer, | ||||||
|  | 		powercycle, | ||||||
| 		unknown | 		unknown | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| @@ -799,7 +802,7 @@ namespace OpenWifi::APCommands { | |||||||
| 		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::RRM,		 	 RESTAPI::Protocol::CERTUPDATE, | ||||||
| 		RESTAPI::Protocol::TRANSFER | 		RESTAPI::Protocol::TRANSFER,	 RESTAPI::Protocol::POWERCYCLE | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	inline const char *to_string(Commands Cmd) { return uCentralAPCommands[(uint8_t)Cmd]; } | 	inline const char *to_string(Commands Cmd) { return uCentralAPCommands[(uint8_t)Cmd]; } | ||||||
|   | |||||||
| @@ -44,7 +44,10 @@ namespace OpenWifi { | |||||||
| 		ORM::Field{"devClass", ORM::FieldType::FT_TEXT}, | 		ORM::Field{"devClass", ORM::FieldType::FT_TEXT}, | ||||||
| 		ORM::Field{"locale", ORM::FieldType::FT_TEXT}, | 		ORM::Field{"locale", ORM::FieldType::FT_TEXT}, | ||||||
| 		ORM::Field{"realMacAddress", ORM::FieldType::FT_TEXT}, | 		ORM::Field{"realMacAddress", ORM::FieldType::FT_TEXT}, | ||||||
| 		ORM::Field{"doNotAllowOverrides", ORM::FieldType::FT_BOOLEAN}}; | 		ORM::Field{"doNotAllowOverrides", ORM::FieldType::FT_BOOLEAN}, | ||||||
|  |         ORM::Field{"imported", ORM::FieldType::FT_BIGINT}, | ||||||
|  |         ORM::Field{"connected", ORM::FieldType::FT_BIGINT}, | ||||||
|  |         ORM::Field{"platform", ORM::FieldType::FT_TEXT}}; | ||||||
|  |  | ||||||
| 	static ORM::IndexVec InventoryDB_Indexes{ | 	static ORM::IndexVec InventoryDB_Indexes{ | ||||||
| 		{std::string("inventory_name_index"), | 		{std::string("inventory_name_index"), | ||||||
| @@ -60,6 +63,9 @@ namespace OpenWifi { | |||||||
| 			"alter table " + TableName_ + " add column realMacAddress text", | 			"alter table " + TableName_ + " add column realMacAddress text", | ||||||
| 			"alter table " + TableName_ + " add column devClass text", | 			"alter table " + TableName_ + " add column devClass text", | ||||||
| 			"alter table " + TableName_ + " add column deviceRules text", | 			"alter table " + TableName_ + " add column deviceRules text", | ||||||
|  |             "alter table " + TableName_ + " add column platform text default 'AP'", | ||||||
|  |             "alter table " + TableName_ + " add column imported bigint", | ||||||
|  |             "alter table " + TableName_ + " add column connected bigint", | ||||||
| 			"alter table " + TableName_ + " add column doNotAllowOverrides boolean"}; | 			"alter table " + TableName_ + " add column doNotAllowOverrides boolean"}; | ||||||
|  |  | ||||||
| 		for (const auto &i : Script) { | 		for (const auto &i : Script) { | ||||||
| @@ -80,7 +86,8 @@ namespace OpenWifi { | |||||||
| 	bool InventoryDB::CreateFromConnection(const std::string &SerialNumberRaw, | 	bool InventoryDB::CreateFromConnection(const std::string &SerialNumberRaw, | ||||||
| 										   const std::string &ConnectionInfo, | 										   const std::string &ConnectionInfo, | ||||||
| 										   const std::string &DeviceType, | 										   const std::string &DeviceType, | ||||||
| 										   const std::string &Locale) { | 										   const std::string &Locale, | ||||||
|  | 										   const bool isConnection) { | ||||||
|  |  | ||||||
| 		ProvObjects::InventoryTag ExistingDevice; | 		ProvObjects::InventoryTag ExistingDevice; | ||||||
| 		auto SerialNumber = Poco::toLower(SerialNumberRaw); | 		auto SerialNumber = Poco::toLower(SerialNumberRaw); | ||||||
| @@ -106,6 +113,8 @@ namespace OpenWifi { | |||||||
| 			StateDoc["date"] = Utils::Now(); | 			StateDoc["date"] = Utils::Now(); | ||||||
| 			NewDevice.state = to_string(StateDoc); | 			NewDevice.state = to_string(StateDoc); | ||||||
| 			NewDevice.devClass = "any"; | 			NewDevice.devClass = "any"; | ||||||
|  |             NewDevice.connected = Now; | ||||||
|  |             NewDevice.imported = 0; | ||||||
| 			if (!IP.empty()) { | 			if (!IP.empty()) { | ||||||
| 				StorageService()->VenueDB().GetByIP(IP, NewDevice.venue); | 				StorageService()->VenueDB().GetByIP(IP, NewDevice.venue); | ||||||
| 				if (NewDevice.venue.empty()) { | 				if (NewDevice.venue.empty()) { | ||||||
| @@ -176,9 +185,32 @@ namespace OpenWifi { | |||||||
|  |  | ||||||
| 			if (modified) { | 			if (modified) { | ||||||
| 				ExistingDevice.info.modified = Utils::Now(); | 				ExistingDevice.info.modified = Utils::Now(); | ||||||
|  |                 ExistingDevice.connected = Utils::Now(); | ||||||
| 				StorageService()->InventoryDB().UpdateRecord("id", ExistingDevice.info.id, | 				StorageService()->InventoryDB().UpdateRecord("id", ExistingDevice.info.id, | ||||||
| 															 ExistingDevice); | 															 ExistingDevice); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | 			// Push entity and venue down to GW but only on connect (not ping) | ||||||
|  | 			if (isConnection && !ExistingDevice.venue.empty()) { | ||||||
|  | 				if (SDK::GW::Device::SetVenue(nullptr, ExistingDevice.serialNumber, ExistingDevice.venue)) { | ||||||
|  | 						Logger().information(Poco::format("%s: GW set venue property.", | ||||||
|  | 														  ExistingDevice.serialNumber)); | ||||||
|  | 				} else { | ||||||
|  | 					Logger().information(Poco::format( | ||||||
|  | 						"%s: could not set GW venue property.", ExistingDevice.serialNumber)); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if (isConnection && !ExistingDevice.entity.empty()) { | ||||||
|  | 				if (SDK::GW::Device::SetEntity(nullptr, ExistingDevice.serialNumber, ExistingDevice.entity)) { | ||||||
|  | 						Logger().information(Poco::format("%s: GW set entity property.", | ||||||
|  | 														  ExistingDevice.serialNumber)); | ||||||
|  | 				} else { | ||||||
|  | 					Logger().information(Poco::format( | ||||||
|  | 						"%s: could not set GW entity property.", ExistingDevice.serialNumber)); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  |  | ||||||
| 		} | 		} | ||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
| @@ -326,6 +358,9 @@ void ORM::DB<OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjects::InventoryTa | |||||||
| 	Out.locale = In.get<21>(); | 	Out.locale = In.get<21>(); | ||||||
| 	Out.realMacAddress = In.get<22>(); | 	Out.realMacAddress = In.get<22>(); | ||||||
| 	Out.doNotAllowOverrides = In.get<23>(); | 	Out.doNotAllowOverrides = In.get<23>(); | ||||||
|  |     Out.imported = In.get<24>(); | ||||||
|  |     Out.connected = In.get<25>(); | ||||||
|  |     Out.platform = In.get<26>(); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <> | template <> | ||||||
| @@ -355,4 +390,7 @@ void ORM::DB<OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjects::InventoryTa | |||||||
| 	Out.set<21>(In.locale); | 	Out.set<21>(In.locale); | ||||||
| 	Out.set<22>(In.realMacAddress); | 	Out.set<22>(In.realMacAddress); | ||||||
| 	Out.set<23>(In.doNotAllowOverrides); | 	Out.set<23>(In.doNotAllowOverrides); | ||||||
|  |     Out.set<24>(In.imported); | ||||||
|  |     Out.set<25>(In.connected); | ||||||
|  |     Out.set<26>(In.platform); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ namespace OpenWifi { | |||||||
| 						std::string, std::string, std::string, std::string, std::string, | 						std::string, std::string, std::string, std::string, std::string, | ||||||
| 						std::string, std::string, std::string, std::string, std::string, | 						std::string, std::string, std::string, std::string, std::string, | ||||||
| 						std::string, std::string, std::string, std::string, std::string, | 						std::string, std::string, std::string, std::string, std::string, | ||||||
| 						std::string, std::string, bool> | 						std::string, std::string, bool, uint64_t, uint64_t, std::string> | ||||||
| 		InventoryDBRecordType; | 		InventoryDBRecordType; | ||||||
|  |  | ||||||
| 	class InventoryDB : public ORM::DB<InventoryDBRecordType, ProvObjects::InventoryTag> { | 	class InventoryDB : public ORM::DB<InventoryDBRecordType, ProvObjects::InventoryTag> { | ||||||
| @@ -25,7 +25,8 @@ namespace OpenWifi { | |||||||
| 		virtual ~InventoryDB(){}; | 		virtual ~InventoryDB(){}; | ||||||
| 		bool CreateFromConnection(const std::string &SerialNumber, | 		bool CreateFromConnection(const std::string &SerialNumber, | ||||||
| 								  const std::string &ConnectionInfo, const std::string &DeviceType, | 								  const std::string &ConnectionInfo, const std::string &DeviceType, | ||||||
| 								  const std::string &Locale); | 								  const std::string &Locale, | ||||||
|  | 								  const bool isConnection); | ||||||
|  |  | ||||||
| 		void InitializeSerialCache(); | 		void InitializeSerialCache(); | ||||||
| 		bool GetRRMDeviceList(Types::UUIDvec_t &DeviceList); | 		bool GetRRMDeviceList(Types::UUIDvec_t &DeviceList); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user