mirror of
				https://github.com/Telecominfraproject/wlan-cloud-owprov.git
				synced 2025-10-30 02:02:36 +00:00 
			
		
		
		
	Framework update.
This commit is contained in:
		| @@ -83,7 +83,7 @@ using namespace std::chrono_literals; | ||||
| #include "Poco/Environment.h" | ||||
| #include "Poco/NObserver.h" | ||||
| #include "Poco/Net/SocketNotification.h" | ||||
|  | ||||
| #include "Poco/Base64Decoder.h" | ||||
| #include "cppkafka/cppkafka.h" | ||||
|  | ||||
| #include "framework/OpenWifiTypes.h" | ||||
| @@ -1121,6 +1121,39 @@ namespace OpenWifi::Utils { | ||||
|         return stream.str(); | ||||
|     } | ||||
|  | ||||
|     inline bool ExtractBase64CompressedData(const std::string &CompressedData, | ||||
|                                             std::string &UnCompressedData, uint64_t compress_sz ) { | ||||
|         std::istringstream ifs(CompressedData); | ||||
|         Poco::Base64Decoder b64in(ifs); | ||||
|         std::ostringstream ofs; | ||||
|         Poco::StreamCopier::copyStream(b64in, ofs); | ||||
|  | ||||
|         int factor = 20; | ||||
|         unsigned long MaxSize = compress_sz ? (unsigned long) (compress_sz + 5000) : (unsigned long) (ofs.str().size() * factor); | ||||
|         while(true) { | ||||
|             std::vector<uint8_t> UncompressedBuffer(MaxSize); | ||||
|             unsigned long FinalSize = MaxSize; | ||||
|             auto status = uncompress((uint8_t *)&UncompressedBuffer[0], &FinalSize, | ||||
|                                      (uint8_t *)ofs.str().c_str(), ofs.str().size()); | ||||
|             if(status==Z_OK) { | ||||
|                 UncompressedBuffer[FinalSize] = 0; | ||||
|                 UnCompressedData = (char *)&UncompressedBuffer[0]; | ||||
|                 return true; | ||||
|             } | ||||
|             if(status==Z_BUF_ERROR) { | ||||
|                 if(factor<300) { | ||||
|                     factor+=10; | ||||
|                     MaxSize = ofs.str().size() * factor; | ||||
|                     continue; | ||||
|                 } else { | ||||
|                     return false; | ||||
|                 } | ||||
|             } | ||||
|             return false; | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
| namespace OpenWifi { | ||||
| @@ -1813,31 +1846,21 @@ namespace OpenWifi { | ||||
| 	            Request = &RequestIn; | ||||
| 	            Response = &ResponseIn; | ||||
|  | ||||
|                 Logger_.information(fmt::format("Line: {}",__LINE__)); | ||||
|  | ||||
| 				Poco::Thread::current()->setName("WebServerThread_" + std::to_string(TransactionId_)); | ||||
|                 Logger_.information(fmt::format("Line: {}",__LINE__)); | ||||
|  | ||||
|                 if(Request->getContentLength()>0) { | ||||
|                     Logger_.information(fmt::format("Line: {}",__LINE__)); | ||||
|                     if(Request->getContentType().find("application/json")!=std::string::npos) { | ||||
|                         Logger_.information(fmt::format("Line: {}",__LINE__)); | ||||
|                         ParsedBody_ = IncomingParser_.parse(Request->stream()).extract<Poco::JSON::Object::Ptr>(); | ||||
|                         Logger_.information(fmt::format("Line: {}",__LINE__)); | ||||
|                     } | ||||
|                     Logger_.information(fmt::format("Line: {}",__LINE__)); | ||||
|                 } | ||||
|  | ||||
|                 Logger_.information(fmt::format("Line: {}",__LINE__)); | ||||
| 	            if(RateLimited_ && RESTAPI_RateLimiter()->IsRateLimited(RequestIn,MyRates_.Interval, MyRates_.MaxCalls)) { | ||||
| 	                return UnAuthorized(RESTAPI::Errors::RATE_LIMIT_EXCEEDED); | ||||
| 	            } | ||||
|  | ||||
|                 Logger_.information(fmt::format("Line: {}",__LINE__)); | ||||
| 	            if (!ContinueProcessing()) | ||||
| 	                return; | ||||
|  | ||||
|                 Logger_.information(fmt::format("Line: {}",__LINE__)); | ||||
| 	            bool Expired=false, Contacted=false; | ||||
| 	            if (AlwaysAuthorize_ && !IsAuthorized(Expired, Contacted, SubOnlyService_)) { | ||||
| 	                if(Expired) | ||||
| @@ -4366,7 +4389,7 @@ namespace OpenWifi { | ||||
|                                                Path, | ||||
|                                                Poco::Net::HTTPMessage::HTTP_1_1); | ||||
|  | ||||
|                 Poco::Logger::get("REST-CALLER").information(fmt::format("GET: {}", URI.toString())); | ||||
|                 Poco::Logger::get("REST-CALLER-GET").debug(fmt::format(" {}", URI.toString())); | ||||
|  | ||||
|                 if(BearerToken.empty()) { | ||||
|                     Request.add("X-API-KEY", Svc.AccessKey); | ||||
| @@ -4407,7 +4430,7 @@ namespace OpenWifi { | ||||
|         } | ||||
|         catch (const Poco::Exception &E) | ||||
|         { | ||||
|             std::cerr << E.displayText() << std::endl; | ||||
|             Poco::Logger::get("REST-CALLER-GET").log(E); | ||||
|         } | ||||
|         return Poco::Net::HTTPServerResponse::HTTP_GATEWAY_TIMEOUT; | ||||
|     } | ||||
| @@ -4418,14 +4441,13 @@ namespace OpenWifi { | ||||
|             for(auto const &Svc:Services) { | ||||
|                 Poco::URI	URI(Svc.PrivateEndPoint); | ||||
|  | ||||
|  | ||||
|                 auto Secure = (URI.getScheme() == "https"); | ||||
|  | ||||
|                 URI.setPath(EndPoint_); | ||||
|                 for (const auto &qp : QueryData_) | ||||
|                     URI.addQueryParameter(qp.first, qp.second); | ||||
|  | ||||
|                 Poco::Logger::get("REST-CALLER").information(fmt::format("PUT: {}", URI.toString())); | ||||
|                 Poco::Logger::get("REST-CALLER-PUT").debug(fmt::format("{}", URI.toString())); | ||||
|  | ||||
|                 std::string Path(URI.getPathAndQuery()); | ||||
|  | ||||
| @@ -4485,7 +4507,7 @@ namespace OpenWifi { | ||||
|         } | ||||
|         catch (const Poco::Exception &E) | ||||
|         { | ||||
|             std::cerr << E.displayText() << std::endl; | ||||
|             Poco::Logger::get("REST-CALLER-PUT").log(E); | ||||
|         } | ||||
|         return Poco::Net::HTTPServerResponse::HTTP_GATEWAY_TIMEOUT; | ||||
|     } | ||||
| @@ -4504,7 +4526,7 @@ namespace OpenWifi { | ||||
|                 for (const auto &qp : QueryData_) | ||||
|                     URI.addQueryParameter(qp.first, qp.second); | ||||
|  | ||||
|                 Poco::Logger::get("REST-CALLER").information(fmt::format("POST: {}", URI.toString())); | ||||
|                 Poco::Logger::get("REST-CALLER-POST").debug(fmt::format(" {}", URI.toString())); | ||||
|  | ||||
|                 std::string Path(URI.getPathAndQuery()); | ||||
|  | ||||
| @@ -4562,7 +4584,7 @@ namespace OpenWifi { | ||||
|         } | ||||
|         catch (const Poco::Exception &E) | ||||
|         { | ||||
|             std::cerr << E.displayText() << std::endl; | ||||
|             Poco::Logger::get("REST-CALLER-POST").log(E); | ||||
|         } | ||||
|         return Poco::Net::HTTPServerResponse::HTTP_GATEWAY_TIMEOUT; | ||||
|     } | ||||
| @@ -4580,7 +4602,7 @@ namespace OpenWifi { | ||||
|                 for (const auto &qp : QueryData_) | ||||
|                     URI.addQueryParameter(qp.first, qp.second); | ||||
|  | ||||
|                 Poco::Logger::get("REST-CALLER").information(fmt::format("DELETE: {}", URI.toString())); | ||||
|                 Poco::Logger::get("REST-CALLER-DELETE").debug(fmt::format(" {}", URI.toString())); | ||||
|  | ||||
|                 std::string Path(URI.getPathAndQuery()); | ||||
|  | ||||
| @@ -4614,7 +4636,7 @@ namespace OpenWifi { | ||||
|         } | ||||
|         catch (const Poco::Exception &E) | ||||
|         { | ||||
|             std::cerr << E.displayText() << std::endl; | ||||
|             Poco::Logger::get("REST-CALLER-DELETE").log(E); | ||||
|         } | ||||
|         return Poco::Net::HTTPServerResponse::HTTP_GATEWAY_TIMEOUT; | ||||
|     } | ||||
|   | ||||
							
								
								
									
										299
									
								
								src/framework/RESTAPI_GWobjects.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										299
									
								
								src/framework/RESTAPI_GWobjects.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,299 @@ | ||||
| // | ||||
| //	License type: BSD 3-Clause License | ||||
| //	License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE | ||||
| // | ||||
| //	Created by Stephane Bourque on 2021-03-04. | ||||
| //	Arilia Wireless Inc. | ||||
| // | ||||
|  | ||||
| #include "Poco/JSON/Parser.h" | ||||
| #include "Poco/JSON/Stringifier.h" | ||||
|  | ||||
| #include "Daemon.h" | ||||
| #ifdef	TIP_GATEWAY_SERVICE | ||||
| #include "DeviceRegistry.h" | ||||
| #include "CapabilitiesCache.h" | ||||
| #endif | ||||
|  | ||||
| #include "RESTAPI_GWobjects.h" | ||||
| #include "framework/MicroService.h" | ||||
|  | ||||
| using OpenWifi::RESTAPI_utils::field_to_json; | ||||
| using OpenWifi::RESTAPI_utils::field_from_json; | ||||
| using OpenWifi::RESTAPI_utils::EmbedDocument; | ||||
|  | ||||
| namespace OpenWifi::GWObjects { | ||||
|  | ||||
| 	void Device::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		field_to_json(Obj,"serialNumber", SerialNumber); | ||||
| #ifdef TIP_GATEWAY_SERVICE | ||||
| 		field_to_json(Obj,"deviceType", CapabilitiesCache::instance()->GetPlatform(Compatible)); | ||||
| #endif | ||||
| 		field_to_json(Obj,"macAddress", MACAddress); | ||||
| 		field_to_json(Obj,"manufacturer", Manufacturer); | ||||
| 		field_to_json(Obj,"UUID", UUID); | ||||
| 		EmbedDocument("configuration", Obj, Configuration); | ||||
| 		field_to_json(Obj,"notes", Notes); | ||||
| 		field_to_json(Obj,"createdTimestamp", CreationTimestamp); | ||||
| 		field_to_json(Obj,"lastConfigurationChange", LastConfigurationChange); | ||||
| 		field_to_json(Obj,"lastConfigurationDownload", LastConfigurationDownload); | ||||
| 		field_to_json(Obj,"lastFWUpdate", LastFWUpdate); | ||||
| 		field_to_json(Obj,"owner", Owner); | ||||
| 		field_to_json(Obj,"location", Location); | ||||
| 		field_to_json(Obj,"venue", Venue); | ||||
| 		field_to_json(Obj,"firmware", Firmware); | ||||
| 		field_to_json(Obj,"compatible", Compatible); | ||||
| 		field_to_json(Obj,"fwUpdatePolicy", FWUpdatePolicy); | ||||
| 		field_to_json(Obj,"devicePassword", DevicePassword); | ||||
| 		field_to_json(Obj,"subscriber", subscriber); | ||||
| 		field_to_json(Obj,"entity", entity); | ||||
| 		field_to_json(Obj,"modified", modified); | ||||
| 		field_to_json(Obj,"locale", locale); | ||||
| 	} | ||||
|  | ||||
| 	void Device::to_json_with_status(Poco::JSON::Object &Obj) const { | ||||
| 		to_json(Obj); | ||||
|  | ||||
| #ifdef TIP_GATEWAY_SERVICE | ||||
| 		ConnectionState ConState; | ||||
|  | ||||
| 		if (DeviceRegistry()->GetState(SerialNumber, ConState)) { | ||||
| 			ConState.to_json(Obj); | ||||
| 		} else { | ||||
| 			field_to_json(Obj,"ipAddress", ""); | ||||
| 			field_to_json(Obj,"txBytes", (uint64_t) 0); | ||||
| 			field_to_json(Obj,"rxBytes", (uint64_t )0); | ||||
| 			field_to_json(Obj,"messageCount", (uint64_t )0); | ||||
| 			field_to_json(Obj,"connected", false); | ||||
| 			field_to_json(Obj,"lastContact", ""); | ||||
| 			field_to_json(Obj,"verifiedCertificate", "NO_CERTIFICATE"); | ||||
| 			field_to_json(Obj,"associations_2G", (uint64_t) 0); | ||||
| 			field_to_json(Obj,"associations_5G", (uint64_t) 0); | ||||
| 		} | ||||
| #endif | ||||
| 	} | ||||
|  | ||||
| 	bool Device::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
| 		try { | ||||
| 			field_from_json(Obj,"serialNumber",SerialNumber); | ||||
| 			field_from_json(Obj,"deviceType",DeviceType); | ||||
| 			field_from_json(Obj,"macAddress",MACAddress); | ||||
| 			field_from_json(Obj,"configuration",Configuration); | ||||
| 			field_from_json(Obj,"notes",Notes); | ||||
| 			field_from_json(Obj,"manufacturer",Manufacturer); | ||||
| 			field_from_json(Obj,"owner",Owner); | ||||
| 			field_from_json(Obj,"location",Location); | ||||
| 			field_from_json(Obj,"venue",Venue); | ||||
| 			field_from_json(Obj,"compatible",Compatible); | ||||
| 			field_from_json(Obj,"subscriber", subscriber); | ||||
| 			field_from_json(Obj,"entity", entity); | ||||
| 			field_from_json(Obj,"locale", locale); | ||||
| 			return true; | ||||
| 		} catch (const Poco::Exception &E) { | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	void Device::Print() const { | ||||
| 		std::cout << "Device: " << SerialNumber << " DeviceType:" << DeviceType << " MACAddress:" << MACAddress << " Manufacturer:" | ||||
| 				  << Manufacturer << " " << Configuration << std::endl; | ||||
| 	} | ||||
|  | ||||
| 	void Statistics::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		EmbedDocument("data", Obj, Data); | ||||
| 		field_to_json(Obj,"UUID", UUID); | ||||
| 		field_to_json(Obj,"recorded", Recorded); | ||||
| 	} | ||||
|  | ||||
| 	void Capabilities::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		EmbedDocument("capabilities", Obj, Capabilities); | ||||
| 		field_to_json(Obj,"firstUpdate", FirstUpdate); | ||||
| 		field_to_json(Obj,"lastUpdate", LastUpdate); | ||||
| 	} | ||||
|  | ||||
| 	void DeviceLog::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		EmbedDocument("data", Obj, Data); | ||||
| 		field_to_json(Obj,"log", Log); | ||||
| 		field_to_json(Obj,"severity", Severity); | ||||
| 		field_to_json(Obj,"recorded", Recorded); | ||||
| 		field_to_json(Obj,"logType", LogType); | ||||
| 		field_to_json(Obj,"UUID", UUID); | ||||
| 	} | ||||
|  | ||||
| 	void HealthCheck::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		EmbedDocument("values", Obj, Data); | ||||
| 		field_to_json(Obj,"UUID", UUID); | ||||
| 		field_to_json(Obj,"sanity", Sanity); | ||||
| 		field_to_json(Obj,"recorded", Recorded); | ||||
| 	} | ||||
|  | ||||
| 	void DefaultConfiguration::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		EmbedDocument("configuration", Obj, Configuration); | ||||
| 		field_to_json(Obj,"name", Name); | ||||
| 		field_to_json(Obj,"modelIds", Models); | ||||
| 		field_to_json(Obj,"description", Description); | ||||
| 		field_to_json(Obj,"created", Created); | ||||
| 		field_to_json(Obj,"lastModified", LastModified); | ||||
| 	} | ||||
|  | ||||
| 	void CommandDetails::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		EmbedDocument("details", Obj, Details); | ||||
| 		EmbedDocument("results", Obj, Results); | ||||
| 		field_to_json(Obj,"UUID", UUID); | ||||
| 		field_to_json(Obj,"serialNumber", SerialNumber); | ||||
| 		field_to_json(Obj,"command", Command); | ||||
| 		field_to_json(Obj,"errorText", ErrorText); | ||||
| 		field_to_json(Obj,"submittedBy", SubmittedBy); | ||||
| 		field_to_json(Obj,"status", Status); | ||||
| 		field_to_json(Obj,"submitted", Submitted); | ||||
| 		field_to_json(Obj,"executed", Executed); | ||||
| 		field_to_json(Obj,"completed", Completed); | ||||
| 		field_to_json(Obj,"when", RunAt); | ||||
| 		field_to_json(Obj,"errorCode", ErrorCode); | ||||
| 		field_to_json(Obj,"custom", Custom); | ||||
| 		field_to_json(Obj,"waitingForFile", WaitingForFile); | ||||
| 		field_to_json(Obj,"attachFile", AttachDate); | ||||
| 		field_to_json(Obj,"executionTime", executionTime); | ||||
| 	} | ||||
|  | ||||
| 	bool DefaultConfiguration::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
| 		try { | ||||
| 			field_from_json(Obj,"name",Name); | ||||
| 			field_from_json(Obj,"configuration",Configuration); | ||||
| 			field_from_json(Obj,"modelIds",Models); | ||||
| 			field_from_json(Obj,"description",Description); | ||||
| 			return true; | ||||
| 		} catch (const Poco::Exception &E) { | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	void BlackListedDevice::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		field_to_json(Obj,"serialNumber", serialNumber); | ||||
| 		field_to_json(Obj,"author", author); | ||||
| 		field_to_json(Obj,"reason", reason); | ||||
| 		field_to_json(Obj,"created", created); | ||||
| 	} | ||||
|  | ||||
| 	bool BlackListedDevice::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
| 		try { | ||||
| 			field_from_json(Obj,"serialNumber",serialNumber); | ||||
| 			field_from_json(Obj,"author",author); | ||||
| 			field_from_json(Obj,"reason",reason); | ||||
| 			field_from_json(Obj,"created",created); | ||||
| 			return true; | ||||
| 		} catch (const Poco::Exception &E) { | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	void ConnectionState::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		field_to_json(Obj,"ipAddress", Address); | ||||
| 		field_to_json(Obj,"txBytes", TX); | ||||
| 		field_to_json(Obj,"rxBytes", RX); | ||||
| 		field_to_json(Obj,"messageCount", MessageCount); | ||||
| 		field_to_json(Obj,"UUID", UUID); | ||||
| 		field_to_json(Obj,"connected", Connected); | ||||
| 		field_to_json(Obj,"firmware", Firmware); | ||||
| 		field_to_json(Obj,"lastContact", LastContact); | ||||
| 		field_to_json(Obj,"associations_2G", Associations_2G); | ||||
| 		field_to_json(Obj,"associations_5G", Associations_5G); | ||||
| 		field_to_json(Obj,"webSocketClients", webSocketClients); | ||||
| 		field_to_json(Obj,"websocketPackets", websocketPackets); | ||||
| 		field_to_json(Obj,"kafkaClients", kafkaClients); | ||||
| 		field_to_json(Obj,"kafkaPackets", kafkaPackets); | ||||
| 		field_to_json(Obj,"locale", locale); | ||||
|  | ||||
| 		switch(VerifiedCertificate) { | ||||
| 			case NO_CERTIFICATE: | ||||
| 				field_to_json(Obj,"verifiedCertificate", "NO_CERTIFICATE"); break; | ||||
| 			case VALID_CERTIFICATE: | ||||
| 				field_to_json(Obj,"verifiedCertificate", "VALID_CERTIFICATE"); break; | ||||
| 			case MISMATCH_SERIAL: | ||||
| 				field_to_json(Obj,"verifiedCertificate", "MISMATCH_SERIAL"); break; | ||||
| 			case VERIFIED: | ||||
| 				field_to_json(Obj,"verifiedCertificate", "VERIFIED"); break; | ||||
| 			default: | ||||
| 				field_to_json(Obj,"verifiedCertificate", "NO_CERTIFICATE"); break; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	void RttySessionDetails::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		field_to_json(Obj,"serialNumber", SerialNumber); | ||||
| 		field_to_json(Obj,"server", Server); | ||||
| 		field_to_json(Obj,"port", Port); | ||||
| 		field_to_json(Obj,"token",Token); | ||||
| 		field_to_json(Obj,"timeout", TimeOut); | ||||
| 		field_to_json(Obj,"connectionId",ConnectionId); | ||||
| 		field_to_json(Obj,"commandUUID",CommandUUID); | ||||
| 		field_to_json(Obj,"started", Started); | ||||
| 		field_to_json(Obj,"viewport",ViewPort); | ||||
| 		field_to_json(Obj,"password",DevicePassword); | ||||
| 	} | ||||
|  | ||||
| 	void Dashboard::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		field_to_json(Obj,"commands",commands); | ||||
| 		field_to_json(Obj,"upTimes",upTimes); | ||||
| 		field_to_json(Obj,"memoryUsed",memoryUsed); | ||||
| 		field_to_json(Obj,"load1",load1); | ||||
| 		field_to_json(Obj,"load5",load5); | ||||
| 		field_to_json(Obj,"load15",load15); | ||||
| 		field_to_json(Obj,"vendors",vendors); | ||||
| 		field_to_json(Obj,"status",status); | ||||
| 		field_to_json(Obj,"deviceType",deviceType); | ||||
| 		field_to_json(Obj,"healths",healths); | ||||
| 		field_to_json(Obj,"certificates",certificates); | ||||
| 		field_to_json(Obj,"lastContact",lastContact); | ||||
| 		field_to_json(Obj,"associations",associations); | ||||
| 		field_to_json(Obj,"snapshot",snapshot); | ||||
| 		field_to_json(Obj,"numberOfDevices",numberOfDevices); | ||||
| 	} | ||||
|  | ||||
| 	void Dashboard::reset()  { | ||||
| 		commands.clear(); | ||||
| 		upTimes.clear(); | ||||
| 		memoryUsed.clear(); | ||||
| 		load1.clear(); | ||||
| 		load5.clear(); | ||||
| 		load15.clear(); | ||||
| 		vendors.clear(); | ||||
| 		status.clear(); | ||||
| 		deviceType.clear(); | ||||
| 		healths.clear(); | ||||
| 		certificates.clear(); | ||||
| 		lastContact.clear(); | ||||
| 		associations.clear(); | ||||
| 		numberOfDevices = 0 ; | ||||
| 		snapshot = OpenWifi::Now(); | ||||
| 	} | ||||
|  | ||||
| 	void CapabilitiesModel::to_json(Poco::JSON::Object &Obj) const{ | ||||
| 		field_to_json(Obj,"deviceType", deviceType); | ||||
| 		field_to_json(Obj,"capabilities", capabilities); | ||||
| 	}; | ||||
|  | ||||
| 	void ScriptRequest::to_json(Poco::JSON::Object &Obj) const { | ||||
| 		field_to_json(Obj,"serialNumber",serialNumber); | ||||
| 		field_to_json(Obj,"timeout",timeout); | ||||
| 		field_to_json(Obj,"type",type); | ||||
| 		field_to_json(Obj,"script",script); | ||||
| 		field_to_json(Obj,"scriptId",scriptId); | ||||
| 		field_to_json(Obj,"when",when); | ||||
| 	} | ||||
|  | ||||
| 	bool ScriptRequest::from_json(const Poco::JSON::Object::Ptr &Obj) { | ||||
| 		try { | ||||
| 			field_from_json(Obj,"serialNumber",serialNumber); | ||||
| 			field_from_json(Obj,"timeout",timeout); | ||||
| 			field_from_json(Obj,"type",type); | ||||
| 			field_from_json(Obj,"script",script); | ||||
| 			field_from_json(Obj,"scriptId",scriptId); | ||||
| 			field_from_json(Obj,"when",when); | ||||
| 			return true; | ||||
| 		} catch (const Poco::Exception &E) { | ||||
| 		} | ||||
| 		return false; | ||||
|  | ||||
| 	} | ||||
| } | ||||
|  | ||||
							
								
								
									
										213
									
								
								src/framework/RESTAPI_GWobjects.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										213
									
								
								src/framework/RESTAPI_GWobjects.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,213 @@ | ||||
| // | ||||
| //	License type: BSD 3-Clause License | ||||
| //	License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE | ||||
| // | ||||
| //	Created by Stephane Bourque on 2021-03-04. | ||||
| //	Arilia Wireless Inc. | ||||
| // | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "Poco/JSON/Object.h" | ||||
| #include "RESTAPI_SecurityObjects.h" | ||||
|  | ||||
| namespace OpenWifi::GWObjects { | ||||
|  | ||||
| 	enum CertificateValidation { | ||||
| 		NO_CERTIFICATE, | ||||
| 		VALID_CERTIFICATE, | ||||
| 		MISMATCH_SERIAL, | ||||
| 		VERIFIED | ||||
| 	}; | ||||
|  | ||||
| 	struct ConnectionState { | ||||
| 		uint64_t MessageCount = 0 ; | ||||
| 		std::string Address; | ||||
| 		uint64_t UUID = 0 ; | ||||
| 		uint64_t PendingUUID = 0 ; | ||||
| 		uint64_t TX = 0, RX = 0; | ||||
| 		uint64_t Associations_2G=0; | ||||
| 		uint64_t Associations_5G=0; | ||||
| 		bool Connected = false; | ||||
| 		uint64_t LastContact=0; | ||||
| 		std::string Firmware; | ||||
| 		CertificateValidation VerifiedCertificate = NO_CERTIFICATE; | ||||
| 		std::string Compatible; | ||||
| 		uint64_t 	kafkaClients=0; | ||||
| 		uint64_t 	webSocketClients=0; | ||||
| 		uint64_t 	kafkaPackets=0; | ||||
| 		uint64_t 	websocketPackets=0; | ||||
| 		std::string locale; | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 	}; | ||||
|  | ||||
| 	struct Device { | ||||
| 		std::string SerialNumber; | ||||
| 		std::string DeviceType; | ||||
| 		std::string MACAddress; | ||||
| 		std::string Manufacturer; | ||||
| 		std::string Configuration; | ||||
| 		SecurityObjects::NoteInfoVec 	Notes; | ||||
| 		std::string Owner; | ||||
| 		std::string Location; | ||||
| 		std::string Firmware; | ||||
| 		std::string Compatible; | ||||
| 		std::string FWUpdatePolicy; | ||||
| 		uint64_t UUID = 0 ; | ||||
| 		uint64_t CreationTimestamp = 0 ; | ||||
| 		uint64_t LastConfigurationChange = 0 ; | ||||
| 		uint64_t LastConfigurationDownload = 0 ; | ||||
| 		uint64_t LastFWUpdate = 0 ; | ||||
| 		std::string Venue; | ||||
| 		std::string DevicePassword; | ||||
| 		std::string subscriber; | ||||
| 		std::string entity; | ||||
| 		uint64_t 	modified=0; | ||||
| 		std::string locale; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 		void to_json_with_status(Poco::JSON::Object &Obj) const; | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 		void Print() const; | ||||
| 	}; | ||||
|  | ||||
| 	struct Statistics { | ||||
| 		std::string SerialNumber; | ||||
| 		uint64_t 	UUID = 0 ; | ||||
| 		std::string Data; | ||||
| 		uint64_t 	Recorded = 0; | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 	}; | ||||
|  | ||||
| 	struct HealthCheck { | ||||
| 		std::string SerialNumber; | ||||
| 		uint64_t 	UUID = 0 ; | ||||
| 		std::string Data; | ||||
| 		uint64_t 	Recorded = 0 ; | ||||
| 		uint64_t 	Sanity = 0 ; | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 	}; | ||||
|  | ||||
| 	struct Capabilities { | ||||
| 		std::string Capabilities; | ||||
| 		uint64_t 	FirstUpdate = 0 ; | ||||
| 		uint64_t 	LastUpdate = 0 ; | ||||
| 		void 		to_json(Poco::JSON::Object &Obj) const; | ||||
| 	}; | ||||
|  | ||||
| 	struct DeviceLog { | ||||
| 		enum Level { | ||||
| 			LOG_EMERG = 0,	 /* system is unusable */ | ||||
| 			LOG_ALERT = 1,	 /* action must be taken immediately */ | ||||
| 			LOG_CRIT = 2,	 /* critical conditions */ | ||||
| 			LOG_ERR = 3,	 /* error conditions */ | ||||
| 			LOG_WARNING = 4, /* warning conditions */ | ||||
| 			LOG_NOTICE = 5,	 /* normal but significant condition */ | ||||
| 			LOG_INFO = 6,	 /* informational */ | ||||
| 			LOG_DEBUG = 7	 /* debug-level messages */ | ||||
| 		}; | ||||
| 		std::string SerialNumber; | ||||
| 		std::string Log; | ||||
| 		std::string Data; | ||||
| 		uint64_t 	Severity = 0 ; | ||||
| 		uint64_t 	Recorded = 0 ; | ||||
| 		uint64_t 	LogType = 0 ; | ||||
| 		uint64_t 	UUID = 0 ; | ||||
| 		void 		to_json(Poco::JSON::Object &Obj) const; | ||||
| 	}; | ||||
|  | ||||
| 	struct DefaultConfiguration { | ||||
| 		std::string Name; | ||||
| 		std::string Configuration; | ||||
| 		Types::StringVec Models; | ||||
| 		std::string Description; | ||||
| 		uint64_t 	Created; | ||||
| 		uint64_t 	LastModified; | ||||
| 		void 		to_json(Poco::JSON::Object &Obj) const; | ||||
| 		bool 		from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	struct CommandDetails { | ||||
| 		std::string UUID; | ||||
| 		std::string SerialNumber; | ||||
| 		std::string Command; | ||||
| 		std::string Status; | ||||
| 		std::string SubmittedBy; | ||||
| 		std::string Results; | ||||
| 		std::string Details; | ||||
| 		std::string ErrorText; | ||||
| 		uint64_t Submitted = time(nullptr); | ||||
| 		uint64_t Executed = 0; | ||||
| 		uint64_t Completed = 0 ; | ||||
| 		uint64_t RunAt = 0 ; | ||||
| 		uint64_t ErrorCode = 0 ; | ||||
| 		uint64_t Custom = 0 ; | ||||
| 		uint64_t WaitingForFile = 0 ; | ||||
| 		uint64_t AttachDate = 0 ; | ||||
| 		uint64_t AttachSize = 0 ; | ||||
| 		std::string AttachType; | ||||
| 		double 		executionTime = 0.0; | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 	}; | ||||
|  | ||||
| 	struct BlackListedDevice { | ||||
| 		std::string serialNumber; | ||||
| 		std::string reason; | ||||
| 		std::string author; | ||||
| 		uint64_t created; | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
|  | ||||
| 	struct RttySessionDetails { | ||||
| 		std::string SerialNumber; | ||||
| 		std::string Server; | ||||
| 		uint64_t 	Port = 0 ; | ||||
| 		std::string Token; | ||||
| 		uint64_t 	TimeOut = 0 ; | ||||
| 		std::string ConnectionId; | ||||
| 		uint64_t 	Started = 0 ; | ||||
| 		std::string CommandUUID; | ||||
| 		uint64_t 	ViewPort = 0 ; | ||||
| 		std::string DevicePassword; | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 	}; | ||||
|  | ||||
| 	struct Dashboard { | ||||
| 		uint64_t 		  snapshot = 0 ; | ||||
| 		uint64_t 		  numberOfDevices = 0 ; | ||||
| 		Types::CountedMap commands; | ||||
| 		Types::CountedMap upTimes; | ||||
| 		Types::CountedMap memoryUsed; | ||||
| 		Types::CountedMap load1; | ||||
| 		Types::CountedMap load5; | ||||
| 		Types::CountedMap load15; | ||||
| 		Types::CountedMap vendors; | ||||
| 		Types::CountedMap status; | ||||
| 		Types::CountedMap deviceType; | ||||
| 		Types::CountedMap healths; | ||||
| 		Types::CountedMap certificates; | ||||
| 		Types::CountedMap lastContact; | ||||
| 		Types::CountedMap associations; | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 		void reset(); | ||||
| 	}; | ||||
|  | ||||
| 	struct CapabilitiesModel { | ||||
| 		std::string deviceType; | ||||
| 		std::string capabilities; | ||||
|  | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 	}; | ||||
|  | ||||
| 	struct ScriptRequest { | ||||
| 		uint64_t 	timeout=30; | ||||
| 		std::string serialNumber; | ||||
| 		std::string type; | ||||
| 		std::string script; | ||||
| 		std::string scriptId; | ||||
| 		uint64_t 	when=0; | ||||
| 		void to_json(Poco::JSON::Object &Obj) const; | ||||
| 		bool from_json(const Poco::JSON::Object::Ptr &Obj); | ||||
| 	}; | ||||
| } | ||||
| @@ -295,6 +295,9 @@ namespace OpenWifi::RESTAPI::Protocol { | ||||
| 	static const char * TIMES = "times"; | ||||
| 	static const char * UPTIME = "uptime"; | ||||
| 	static const char * START = "start"; | ||||
| 	static const char * DEBUG = "debug"; | ||||
| 	static const char * SCRIPT = "script"; | ||||
| 	static const char * TIMEOUT = "timeout"; | ||||
|  | ||||
| 	static const char * NEWPASSWORD = "newPassword"; | ||||
| 	static const char * USERS = "users"; | ||||
| @@ -360,6 +363,8 @@ namespace OpenWifi::uCentralProtocol { | ||||
|     static const char *CONFIG = "config"; | ||||
|     static const char *EMPTY_JSON_DOC = "{}"; | ||||
|     static const char *RESULT = "result"; | ||||
| 	static const char *RESULT_64 = "result_64"; | ||||
| 	static const char *RESULT_SZ = "result_sz"; | ||||
|     static const char *REQUEST = "request"; | ||||
|     static const char *PERFORM = "perform"; | ||||
|     static const char *CONFIGURE = "configure"; | ||||
| @@ -372,6 +377,7 @@ namespace OpenWifi::uCentralProtocol { | ||||
|     static const char *DURATION = "duration"; | ||||
|     static const char *PATTERN = "pattern"; | ||||
|     static const char *LEDS = "leds"; | ||||
| 	static const char *DEBUG = "debug"; | ||||
|     static const char *ON = "on"; | ||||
|     static const char *OFF = "off"; | ||||
|     static const char *BLINK = "blink"; | ||||
| @@ -406,6 +412,9 @@ namespace OpenWifi::uCentralProtocol { | ||||
|     static const char *CONNECTIONIP = "connectionIp"; | ||||
|     static const char *TELEMETRY = "telemetry"; | ||||
|     static const char *BANDWIDTH = "bandwidth"; | ||||
|  | ||||
| 	static const char *SCRIPT = "script"; | ||||
| 	static const char *TYPE = "type"; | ||||
| } | ||||
|  | ||||
| namespace OpenWifi::uCentralProtocol::Events { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 stephb9959
					stephb9959