#include #include "httppost.h" #include "cwmp.nsmap" #include "soapcwmpService.h" #include "plugin/threads.h" #include #include #include #include #include #include "json.hpp" #include #include #define HOST "localhost" #define USER "acs" #define PASSWORD "159753" #define DATABASE "ACS" #define PORT 3306 bool DEBUG = false; using json = nlohmann::json; //int port = 7547; int port = 7548; //int port = 8001; int POST_handler(struct soap *soap); struct http_post_handlers http_post_handlers[] = { {"POST", POST_handler}, {NULL} }; std::string currentISO8601TimeUTC() { std::time_t t = std::time(nullptr); std::ostringstream ss; ss << std::put_time(std::localtime(&t), "%FT%T %Z"); return ss.str(); } void handler(int s) { printf("Sassan Caught SIGPIPE ...\n"); } void *process_request(void *arg) { cwmpService *service = (cwmpService *) arg; THREAD_DETACH(THREAD_ID); if (service) { service->serve(); service->destroy(); /* clean up */ delete service; } return NULL; } // //TODO: Read keys from config file and remap them to zbx_keys std::string zbx_keys[] = {"InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.Uptime", "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.UL_MCS", "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.TX_Power", "InternetGatewayDevice.DeviceInfo.SoftwareVersion", "InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.SINR2", "InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.SINR1", "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.RSRP2", "InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.RSRQ", "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.RSRQ", "InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.DHCPServerEnable", "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Setting.Status", "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus", "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.RSRP1", "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress", "InternetGatewayDevice.WEB_GUI.Overview.DeviceInfo.IMSI", "InternetGatewayDevice.WEB_GUI.Overview.DeviceInfo.IMEI", "InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.EnodeBId", "InternetGatewayDevice.DeviceInfo.MemoryStatus.Free", "InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.EnodeBId", "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.DL_MCS", "InternetGatewayDevice.Time.CurrentLocalTime", "InternetGatewayDevice.DeviceInfo.ProcessStatus.CPUUsage", "InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.CellId", "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.BytesSent", "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.BytesReceived", "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.PacketsReceived", "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.PacketsSent", "InternetGatewayDevice.DeviceInfo.UpTime", "InternetGatewayDevice.DeviceInfo.X_TGT_IMSI", "InternetGatewayDevice.WEB_GUI.Network.Network_Mode.WANIPAddress", "InternetGatewayDevice.WEB_GUI.Network.ScanMode.Settings.PCILock", "InternetGatewayDevice.WEB_GUI.Overview.LTEStatus.DnsServer", "InternetGatewayDevice.DeviceInfo.HardwareVersion", "InternetGatewayDevice.DeviceInfo.Manufacturer", "InternetGatewayDevice.DeviceInfo.ManufacturerOUI", "InternetGatewayDevice.DeviceInfo.ModelName", "InternetGatewayDevice.DeviceInfo.ModelNumber", "InternetGatewayDevice.DeviceInfo.Description", "InternetGatewayDevice.DeviceInfo.ProductClass", "InternetGatewayDevice.DeviceInfo.SerialNumber", "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.1.Enable", "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.2.Enable", "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Enable", "InternetGatewayDevice.WEB_GUI.Overview.LTEStatus.DL_DataRate_Current", "InternetGatewayDevice.WEB_GUI.Overview.LTEStatus.UL_DataRate_Current", "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.PCI", "InternetGatewayDevice.WEB_GUI.Overview.LANStatus.MacAddress", "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.DL_Frequency", "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.UL_Frequency", "InternetGatewayDevice.ManagementServer.ConnectionRequestURL", "InternetGatewayDevice.ManagementServer.PeriodicInformInterval", "InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.IPInterface.1.IPInterfaceIPAddress", //ESM "InternetGatewayDevice.DeviceInfo.SpecVersion", "InternetGatewayDevice.DeviceInfo.ProvisioningCode", // "InternetGatewayDevice.DeviceInfo.Manufacturer", "InternetGatewayDevice.DeviceInfo.ManufacturerOUI", "InternetGatewayDevice.DeviceInfo.ProductClass", "InternetGatewayDevice.DeviceInfo.SerialNumber", "InternetGatewayDevice.DeviceInfo.ModelName", "InternetGatewayDevice.DeviceInfo.RSRP1", "InternetGatewayDevice.DeviceInfo.RSRP2", "InternetGatewayDevice.DeviceInfo.CINR1", "InternetGatewayDevice.DeviceInfo.CINR2", "InternetGatewayDevice.DeviceInfo.RSRQ", "InternetGatewayDevice.DeviceInfo.TAC", "InternetGatewayDevice.DeviceInfo.PCID", "InternetGatewayDevice.DeviceInfo.EARFCN", "InternetGatewayDevice.DeviceInfo.PWR", "InternetGatewayDevice.DeviceInfo.IMEI", "InternetGatewayDevice.DeviceInfo.IMSI", "InternetGatewayDevice.DeviceInfo.IPV4", "InternetGatewayDevice.DeviceInfo.RSSI", "InternetGatewayDevice.DeviceInfo.ENODBID", "InternetGatewayDevice.DeviceInfo.CELLID", "InternetGatewayDevice.DeviceInfo.DLBAND", "InternetGatewayDevice.DeviceInfo.ULBAND", "InternetGatewayDevice.DeviceInfo.TXMODE", "InternetGatewayDevice.DeviceInfo.FREQUANCE", "InternetGatewayDevice.DeviceInfo.SINR1", "InternetGatewayDevice.DeviceInfo.SINR2", "InternetGatewayDevice.DeviceInfo.NOISE1", "InternetGatewayDevice.DeviceInfo.NOISE2", "InternetGatewayDevice.DeviceInfo.MODAL", "InternetGatewayDevice.DeviceInfo.CAR", "InternetGatewayDevice.DeviceInfo.BAND", "InternetGatewayDevice.DeviceInfo.PLMN", "InternetGatewayDevice.DeviceInfo.WANUPTIME", "InternetGatewayDevice.DeviceInfo.SYSUPTIME", "InternetGatewayDevice.DeviceInfo.BITRECIEVED", "InternetGatewayDevice.DeviceInfo.BITSENT", "InternetGatewayDevice.DeviceInfo.CPUUSAGE", "InternetGatewayDevice.DeviceInfo.MEMORYFREE", "InternetGatewayDevice.DeviceInfo.TXPOWER", "InternetGatewayDevice.DeviceInfo.PCILOCK", "InternetGatewayDevice.DeviceInfo.ULMCS", "InternetGatewayDevice.DeviceInfo.DLMCS", "InternetGatewayDevice.DeviceInfo.CURRENTTIME", "InternetGatewayDevice.DeviceInfo.HardwareVersion", "InternetGatewayDevice.DeviceInfo.SoftwareVersion", "InternetGatewayDevice.ManagementServer.ConnectionRequestURL", "InternetGatewayDevice.ManagementServer.ParameterKey", "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress" }; // std::string validateInt(std::string y) { int x{0}; try { x = stoi(y); } catch (std::invalid_argument &e) { return "-100000"; // if no conversion could be performed } catch (std::out_of_range &e) { // if the converted value would fall out of the range of the result type // or if the underlying function (std::strtol or std::strtoull) sets errno // to ERANGE. return "-100000"; } catch (...) { // everything else return "-100000"; } return std::to_string(x); } std::string url_encode(const std::string &value) { std::ostringstream escaped; escaped.fill('0'); escaped << std::hex; for (std::string::const_iterator i = value.begin(), n = value.end(); i != n; ++i) { std::string::value_type c = (*i); // Keep alphanumeric and other accepted characters intact if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { escaped << c; continue; } // Any other characters are percent-encoded escaped << std::uppercase; escaped << '%' << std::setw(2) << int((unsigned char) c); escaped << std::nouppercase; } return escaped.str(); } int main(int argc, char *argv[]) { signal(SIGPIPE, handler); for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { printf("Usage: App \nOptions are:\n"); printf("\t -v,--version: version information\n"); printf("\t -d,--debug: run in debug mode\n"); printf("\t -p,--port: override port\n"); printf("\t -h,--help: print this help\n"); exit(0); } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) { std::cout << "TR069 Server Build (1.4) Powered by gSoap 2.8.83 and CMake " << std::endl; return 0; } else if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { DEBUG = true; } else { if (i == argc - 1) { break; } } } if (DEBUG == true) { std::cout << "TR069 Server Started on DEBUG mode Port " << port << "(1.4)...\n" << std::endl; } else { std::cout << "TR069 Server Started on Port " << port << "(1.4)...\n" << std::endl; } cwmpService service(SOAP_XML_INDENT); service.soap->send_timeout = service.soap->recv_timeout = 5; service.soap->transfer_timeout = 60; service.soap->keep_alive = 20; service.soap->tcp_keep_alive = 1; service.soap->bind_flags |= SO_REUSEADDR; service.soap->bind_flags |= SO_REUSEPORT; service.soap->bind_flags |= MSG_NOSIGNAL; soap_init2(service.soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE); SOAP_SOCKET m = service.bind(NULL, port, 100); /* master socket */ if (soap_valid_socket(m)) { while (soap_valid_socket(service.accept())) { THREAD_TYPE tid; void *arg = (void *) service.copy(); if (arg) while (THREAD_CREATE(&tid, (void *(*)(void *)) process_request, arg)) sleep(1); } } service.soap_stream_fault(std::cerr); service.destroy(); /* clean up */ return 0; } int POST_handler(struct soap *soap) { const char *buf; size_t len; buf = soap_http_get_body(soap, &len); if (len == 0) { std::cerr << "Sassan 204...: " << buf << std::endl; return 204; // HTTP 400 Bad Request } } int cwmpService::GetParameterNames(struct _cwmp__GetParameterNames *cwmp__GetParameterNames, struct _cwmp__GetParameterNamesResponse *cwmp__GetParameterNamesResponse) { return SOAP_OK; } int cwmpService::GetParameterValues(struct _cwmp__GetParameterValues *cwmp__GetParameterValues, struct _cwmp__GetParameterValuesResponse *cwmp__GetParameterValuesResponse) { return SOAP_OK; } int cwmpService::SetParameterValues(struct _cwmp__SetParameterValues *cwmp__SetParameterValues, struct _cwmp__SetParameterValuesResponse *cwmp__SetParameterValuesResponse) { return SOAP_OK; } int cwmpService::SetParameterAttributes( struct _cwmp__SetParameterAttributes *cwmp__SetParameterAttributes, struct _cwmp__SetParameterAttributesResponse *cwmp__SetParameterAttributesResponse) { return SOAP_OK; } int cwmpService::GetParameterAttributes(struct _cwmp__GetParameterAttributes *cwmp__GetParameterAttributes, struct _cwmp__GetParameterAttributesResponse *cwmp__GetParameterAttributesResponse) { return SOAP_OK; } int cwmpService::Download(struct _cwmp__Download *cwmp__Download, struct _cwmp__DownloadResponse *cwmp__DownloadResponse) { return SOAP_OK; } int cwmpService::Upload( struct _cwmp__Upload *cwmp__Upload, struct _cwmp__UploadResponse *cwmp__UploadResponse) { return SOAP_OK; } int cwmpService::AddObject( struct _cwmp__AddObject *cwmp__AddObject, struct _cwmp__AddObjectResponse *cwmp__AddObjectResponse) { return SOAP_OK; } int cwmpService::DeleteObject( struct _cwmp__DeleteObject *cwmp__DeleteObject, struct _cwmp__DeleteObjectResponse *cwmp__DeleteObjectResponse) { return SOAP_OK; } int cwmpService::GetRPCMethods( struct _cwmp__GetRPCMethods *cwmp__GetRPCMethods, struct _cwmp__GetRPCMethodsResponse *cwmp__GetRPCMethodsResponse) { return SOAP_OK; } int cwmpService::GetParameterValuesResponse( struct _cwmp__GetParameterValuesResponse *cwmp__GetParameterValuesResponse) { return SOAP_OK; } int cwmpService::Inform(struct _cwmp__Inform *cwmp__Inform, struct _cwmp__InformResponse *cwmp__InformResponse, struct soap *soap) { std::string _id = std::string(cwmp__Inform->DeviceId->OUI) + "-" + std::string(cwmp__Inform->DeviceId->ProductClass) + "-" + std::string(cwmp__Inform->DeviceId->SerialNumber); std::cerr << "Inform Recieved from: " << url_encode(_id) << " at " << time(NULL) << std::endl; char *imsi; char *ip; auto timestamp = std::chrono::high_resolution_clock::now(); std::vector th; std::vector th_acs; // int indexes[24]; std::vector ind; std::ofstream outfile; outfile.open("/var/tmp/tr069/" + url_encode(_id), std::ios::out | std::ios::trunc); std::ofstream mongoData; time_t second; std::string _time; std::map tr069{}; second = time(NULL); std::stringstream strstream; strstream << second; strstream >> _time; ip = soap->host; for (int i = 0; i < cwmp__Inform->ParameterList->__size; ++i) { char *_Name = cwmp__Inform->ParameterList->__ptrParameterValueStruct[i]->Name; char *_Value = cwmp__Inform->ParameterList->__ptrParameterValueStruct[i]->Value; if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.X_TGT_IMSI") == 0 or std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.IMSI") == 0) { imsi = _Value; break; } } for (int i = 0; i < cwmp__Inform->ParameterList->__size; ++i) { char *_Name = cwmp__Inform->ParameterList->__ptrParameterValueStruct[i]->Name; char *_Value = cwmp__Inform->ParameterList->__ptrParameterValueStruct[i]->Value; outfile << _Name << ": " << _Value << std::endl; // if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.X_TGT_IMSI") == 0) { // imsi = _Value; // } // if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.Network_Mode.WANIPAddress") == 0) { // ip = _Value; // } std::string cpe = cwmp__Inform->DeviceId->SerialNumber; auto j = std::find(std::begin(zbx_keys), std::end(zbx_keys), _Name); if (j != std::end(zbx_keys)) { if ( !strcmp(_Name, "InternetGatewayDevice.DeviceInfo.MODAL") == 0 or !strcmp(_Name, "InternetGatewayDevice.DeviceInfo.ULMCS") == 0 or !strcmp(_Name, "InternetGatewayDevice.DeviceInfo.DLMCS") == 0 or !strcmp(_Name, "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.DL_MCS") == 0 or !strcmp(_Name, "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.UL_MCS") == 0) { if (!strcmp(_Value, "QPSK")) { _Value = "4"; } else if (!strcmp(_Value, "QAM8")) { _Value = "8"; } else if (!strcmp(_Value, "QAM16")) { _Value = "16"; } else if (!strcmp(_Value, "QAM32")) { _Value = "32"; } else if (!strcmp(_Value, "QAM64")) { _Value = "64"; } std::ofstream zbx_data; std::string _time{}; time_t second; second = time(NULL); std::stringstream strstream; strstream << second; strstream >> _time; if (DEBUG) { std::cout << "IMSI:" << imsi << " Key:" << _Name << " Value:" << _Value << " Second:" << second << std::endl; } // zbx_data.open("/var/tmp/zbx_sender-" + _time, std::ios_base::app); if (DEBUG) { zbx_data.open("/tmp/debug-zbx_sender-" + _time, std::ios_base::app); } else { zbx_data.open("/var/tmp/zbx_sender-" + _time, std::ios_base::app); } zbx_data << "IMSI-" << imsi << " " << _Name << " " << second << " \"" << _Value << "\"" << std::endl; } // if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.HardwareVersion") == 0) tr069.insert({"HardwareVersion", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SoftwareVersion") == 0) tr069.insert({"SoftwareVersion", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.UpTime") == 0) tr069.insert({"UpTime", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Overview.DeviceInfo.IMEI") == 0) tr069.insert({"IMEI", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.X_TGT_IMSI") == 0) tr069.insert({"IMSI", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.MemoryStatus.Free") == 0) tr069.insert({"Free", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ProcessStatus.CPUUsage") == 0) tr069.insert({"CPUUsage", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.Time.CurrentLocalTime") == 0) tr069.insert({"CurrentLocalTime", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.1.Enable") == 0) tr069.insert({"LAN1Enable", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.2.Enable") == 0) tr069.insert({"LAN2Enable", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.SINR1") == 0) tr069.insert({"SINR1", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.SINR2") == 0) tr069.insert({"SINR2", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.EnodeBId") == 0) tr069.insert({"EnodeBId", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.CellId") == 0) tr069.insert({"CellId", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.BytesSent") == 0) tr069.insert({"BytesSent", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.BytesReceived") == 0) tr069.insert({"BytesReceived", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.PacketsSent") == 0) tr069.insert({"PacketsSent", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.PacketsReceived") == 0) tr069.insert({"PacketsReceived", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus") == 0) tr069.insert({"ConnectionStatus", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.Uptime") == 0) tr069.insert({"Uptime", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress") == 0) tr069.insert({"ExternalIPAddress", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.RSRP1") == 0) tr069.insert({"RSRP1", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.RSRP2") == 0) tr069.insert({"RSRP2", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.TX_Power") == 0) tr069.insert({"TX_Power", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.DL_MCS") == 0) tr069.insert({"DL_MCS", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.UL_MCS") == 0) tr069.insert({"UL_MCS", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Setting.Status") == 0) tr069.insert({"LTEStatus", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.ScanMode.Settings.PCILock") == 0) tr069.insert({"PCILock", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.Network_Mode.WANIPAddress") == 0) tr069.insert({"WANIPAddress", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.ManagementServer.PeriodicInformInterval") == 0) tr069.insert({"PeriodicInformInterval", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Overview.LTEStatus.DnsServer") == 0) tr069.insert({"DnsServer", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Overview.DeviceInfo.IMSI") == 0) tr069.insert({"IMSI", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.Manufacturer") == 0) tr069.insert({"Manufacturer", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ManufacturerOUI") == 0) tr069.insert({"OUI", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ModelName") == 0) tr069.insert({"ModelName", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ModelNumber") == 0) tr069.insert({"ModelNumber", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.Description") == 0) tr069.insert({"Description", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ProductClass") == 0) tr069.insert({"ProductClass", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SerialNumber") == 0) tr069.insert({"SerialNumber", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.RSRQ") == 0) tr069.insert({"RSRQ", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.DHCPServerEnable") == 0) tr069.insert({"DHCPServerEnable", _Value}); else if ( std::string(_Name).compare("InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Enable") == 0) tr069.insert({"WANEthernetInterfaceConfigEnable", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.ManagementServer.ConnectionRequestURL") == 0) tr069.insert({"ConnectionRequestURL", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.WEB_GUI.Overview.LTEStatus.DL_DataRate_Current") == 0) tr069.insert({"DL_DataRate_Current", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.WEB_GUI.Overview.LTEStatus.UL_DataRate_Current") == 0) tr069.insert({"UL_DataRate_Current", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.PCI") == 0) tr069.insert({"PCI", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.UL_Frequency") == 0) tr069.insert({"UL_Frequency", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.DL_Frequency") == 0) tr069.insert({"DL_Frequency", _Value}); else if (std::string(_Name).compare( "InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.IPInterface.1.IPInterfaceIPAddress") == 0) tr069.insert({"IPInterfaceIPAddress", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Overview.LANStatus.MacAddress") == 0) tr069.insert({"MacAddress", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ManufacturerOUI") == 0) tr069.insert({"ManufacturerOUI", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SpecVersion") == 0) tr069.insert({"SpecVersion", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ProvisioningCode") == 0) tr069.insert({"ProvisioningCode", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.Manufacturer") == 0) tr069.insert({"Manufacturer", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ManufacturerOUI") == 0) tr069.insert({"ManufacturerOUI", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ProductClass") == 0) tr069.insert({"ProductClass", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SerialNumber") == 0) tr069.insert({"SerialNumber", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ModelName") == 0) tr069.insert({"ModelName", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.RSRP0") == 0) tr069.insert({"RSRP0", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.RSRP1") == 0) tr069.insert({"RSRP1", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.RSRP2") == 0) tr069.insert({"RSRP2", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CINR0") == 0) tr069.insert({"CINR0", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CINR1") == 0) tr069.insert({"CINR1", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CINR2") == 0) tr069.insert({"CINR2", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.RSRQ") == 0) tr069.insert({"RSRQ", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.TAC") == 0) tr069.insert({"TAC", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.PCID") == 0) tr069.insert({"PCID", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.EARFCN") == 0) tr069.insert({"EARFCN", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.PWR") == 0) tr069.insert({"PWR", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.IMEI") == 0) tr069.insert({"IMEI", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.IMSI") == 0) tr069.insert({"IMSI", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.IPV4") == 0) tr069.insert({"IPV4", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.RSSI") == 0) tr069.insert({"RSSI", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ENODBID") == 0) tr069.insert({"ENODBID", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CELLID") == 0) tr069.insert({"CELLID", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.DLBAND") == 0) tr069.insert({"DLBAND", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ULBAND") == 0) tr069.insert({"ULBAND", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.TXMODE") == 0) tr069.insert({"TXMODE", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.FREQUANCE") == 0) tr069.insert({"FREQUANCE", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SINR0") == 0) tr069.insert({"SINR0", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SINR1") == 0) tr069.insert({"SINR1", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SINR2") == 0) tr069.insert({"SINR2", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.NOISE0") == 0) tr069.insert({"NOISE0", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.NOISE1") == 0) tr069.insert({"NOISE1", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.NOISE2") == 0) tr069.insert({"NOISE2", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.MODAL") == 0) tr069.insert({"MODAL", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CAR") == 0) tr069.insert({"CAR", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.BAND") == 0) tr069.insert({"BAND", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.PLMN") == 0) tr069.insert({"PLMN", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.WANUPTIME") == 0) tr069.insert({"WANUPTIME", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SYSUPTIME") == 0) tr069.insert({"SYSUPTIME", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.BITRECIEVED") == 0) tr069.insert({"BITRECIEVED", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.BITSENT") == 0) tr069.insert({"BITSENT", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CPUUSAGE") == 0) tr069.insert({"CPUUSAGE", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.MEMORYFREE") == 0) tr069.insert({"MEMORYFREE", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.TXPOWER") == 0) tr069.insert({"TXPOWER", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.PCILOCK") == 0) tr069.insert({"PCILOCK", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ULMCS") == 0) tr069.insert({"ULMCS", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.DLMCS") == 0) tr069.insert({"DLMCS", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CURRENTTIME") == 0) tr069.insert({"CURRENTTIME", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.HardwareVersion") == 0) tr069.insert({"HardwareVersion", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SoftwareVersion") == 0) tr069.insert({"SoftwareVersion", _Value}); else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ConnectionRequestURL") == 0) tr069.insert({"ConnectionRequestURL", _Value}); // } } std::ofstream zbx_data; zbx_data.open("/var/tmp/zbx_sender-" + _time, std::ios_base::app); zbx_data << "IMSI-" << imsi << " " << "BytsReceived" << " " << second << " \"" << tr069["BytesReceived"] << "\"" << std::endl; zbx_data << "IMSI-" << imsi << " " << "BytsSent" << " " << second << " \"" << tr069["BytesSent"] << "\"" << std::endl; // std::string ISOTime = currentISO8601TimeUTC(); json tr069_json{}; tr069_json["_id"] = url_encode(_id); tr069_json["_deviceId"]["_Manufacturer"] = cwmp__Inform->DeviceId->Manufacturer; tr069_json["_deviceId"]["_OUI"] = cwmp__Inform->DeviceId->OUI; tr069_json["_deviceId"]["_ProductClass"] = cwmp__Inform->DeviceId->ProductClass; tr069_json["_deviceId"]["_SerialNumber"] = cwmp__Inform->DeviceId->SerialNumber; tr069_json["_lastInform"] = ISOTime; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANConnectionDevice"]["1"]["WANIPConnection"]["1"]["Uptime"]["_value"] = tr069["Uptime"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["UL_MCS"]["_value"] = tr069["UL_MCS"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["TX_Power"]["_value"] = tr069["TX_Power"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SoftwareVersion"]["_value"] = tr069["SoftwareVersion"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["SINR2"]["_value"] = tr069["SINR2"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["SINR1"]["_value"] = tr069["SINR1"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["RSRP2"]["_value"] = tr069["RSRP2"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["RSRQ"]["_value"] = tr069["RSRQ"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["RSRQ"]["_value"] = tr069["RSRQ"]; tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["LANHostConfigManagement"]["DHCPServerEnable"]["_value"] = tr069["DHCPServerEnable"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Setting"]["Status"]["_value"] = tr069["LTEStatus"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANConnectionDevice"]["1"]["WANIPConnection"]["1"]["ConnectionStatus"]["_value"] = tr069["ConnectionStatus"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["RSRP1"]["_value"] = tr069["RSRP1"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANConnectionDevice"]["1"]["WANIPConnection"]["1"]["ExternalIPAddress"]["_value"] = tr069["ExternalIPAddress"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["DeviceInfo"]["IMSI"]["_value"] = tr069["IMSI"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["DeviceInfo"]["IMEI"]["_value"] = tr069["IMEI"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["EnodeBId"]["_value"] = tr069["EnodeBId"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["MemoryStatus"]["Free"]["_value"] = tr069["Free"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["EnodeBId"]["_value"] = tr069["EnodeBId"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["DL_MCS"]["_value"] = tr069["DL_MCS"]; tr069_json["InternetGatewayDevice"]["Time"]["CurrentLocalTime"]["_value"] = tr069["CurrentLocalTime"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ProcessStatus"]["CPUUsage"]["_value"] = tr069["CPUUsage"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["CellId"]["_value"] = tr069["CellId"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Stats"]["BytesSent"]["_value"] = tr069["BytesSent"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Stats"]["BytesReceived"]["_value"] = tr069["BytesReceived"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Stats"]["PacketsReceived"]["_value"] = tr069["PacketsReceived"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Stats"]["PacketsSent"]["_value"] = tr069["PacketsSent"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["UpTime"]["_value"] = tr069["UpTime"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["X_TGT_IMSI"]["_value"] = tr069["IMSI"]; tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["LANEthernetInterfaceConfig"]["1"]["Enable"]["_value"] = tr069["Enable"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["Network_Mode"]["WANIPAddress"]["_value"] = tr069["WANIPAddress"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["ScanMode"]["Settings"]["PCILock"]["_value"] = tr069["PCILock"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["DnsServer"]["_value"] = tr069["DnsServer"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["HardwareVersion"]["_value"] = tr069["HardwareVersion"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["Manufacturer"]["_value"] = cwmp__Inform->DeviceId->Manufacturer; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ManufacturerOUI"]["_value"] = cwmp__Inform->DeviceId->OUI; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ModelName"]["_value"] = tr069["ModelName"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ModelNumber"]["_value"] = tr069["ModelNumber"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["Description"]["_value"] = tr069["Description"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ProductClass"]["_value"] = cwmp__Inform->DeviceId->ProductClass; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SerialNumber"]["_value"] = cwmp__Inform->DeviceId->SerialNumber; tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["LANEthernetInterfaceConfig"]["1"]["Enable"]["_value"] = tr069["LAN1Enable"]; tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["LANEthernetInterfaceConfig"]["2"]["Enable"]["_value"] = tr069["LAN2Enable"]; tr069_json["InternetGatewayDevice"]["ManagementServer"]["ConnectionRequestURL"]["_value"] = tr069["ConnectionRequestURL"]; tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Enable"]["_value"] = tr069["WANEthernetInterfaceConfigEnable"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["DL_DataRate_Current"]["_value"] = tr069["DL_DataRate_Current"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["UL_DataRate_Current"]["_value"] = tr069["UL_DataRate_Current"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["PCI"]["_value"] = tr069["PCI"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LANStatus"]["MacAddress"]["_value"] = tr069["MacAddress"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["DL_Frequency"]["_value"] = tr069["DL_Frequency"]; tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["UL_Frequency"]["_value"] = tr069["UL_Frequency"]; tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["IPInterface"]["1"]["IPInterfaceIPAddress"]["_value"] = tr069["IPInterfaceIPAddress"]; tr069_json["InternetGatewayDevice"]["ManagementServer"]["PeriodicInformInterval"]["_value"] = tr069["PeriodicInformInterval"]; //ESM tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ManufacturerOUI"]["_value"] = cwmp__Inform->DeviceId->OUI; // tr069_json["InternetGatewayDevice"]["DeviceInfo"]["Manufacturer"]["_value"] = tr069["Manufacturer"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSRP1"]["_value"] = tr069["RSRP1"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSRP2"]["_value"] = tr069["RSRP2"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["CINR1"]["_value"] = tr069["CINR1"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["CINR2"]["_value"] = tr069["CINR2"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSRQ"]["_value"] = tr069["RSRQ"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["TAC"]["_value"] = tr069["TAC"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["PCID"]["_value"] = tr069["PCID"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["EARFCN"]["_value"] = tr069["EARFCN"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["PWR"]["_value"] = tr069["PWR"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["IMEI"]["_value"] = tr069["IMEI"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["IMSI"]["_value"] = tr069["IMSI"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["IPV4"]["_value"] = tr069["IPV4"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSSI"]["_value"] = tr069["RSSI"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ENODBID"]["_value"] = tr069["ENODBID"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["CELLID"]["_value"] = tr069["CELLID"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["DLBAND"]["_value"] = tr069["DLBAND"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ULBAND"]["_value"] = tr069["ULBAND"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["TXMODE"]["_value"] = tr069["TXMODE"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["FREQUANCE"]["_value"] = tr069["FREQUANCE"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SINR1"]["_value"] = tr069["SINR1"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SINR2"]["_value"] = tr069["SINR2"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["NOISE1"]["_value"] = tr069["NOISE1"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["NOISE2"]["_value"] = tr069["NOISE2"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["MODAL"]["_value"] = tr069["MODAL"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["CAR"]["_value"] = tr069["CAR"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["BAND"]["_value"] = tr069["BAND"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["PLMN"]["_value"] = tr069["PLMN"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["WANUPTIME"]["_value"] = tr069["WANUPTIME"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SYSUPTIME"]["_value"] = tr069["SYSUPTIME"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["BITRECIEVED"]["_value"] = tr069["BITRECIEVED"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["BITSENT"]["_value"] = tr069["BITSENT"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["CPUUSAGE"]["_value"] = tr069["CPUUSAGE"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["MEMORYFREE"]["_value"] = tr069["MEMORYFREE"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["TXPOWER"]["_value"] = tr069["TXPOWER"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["PCILOCK"]["_value"] = tr069["PCILOCK"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ULMCS"]["_value"] = tr069["ULMCS"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["DLMCS"]["_value"] = tr069["DLMCS"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["CURRENTTIME"]["_value"] = tr069["CURRENTTIME"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["HardwareVersion"]["_value"] = tr069["HardwareVersion"]; tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SoftwareVersion"]["_value"] = tr069["SoftwareVersion"]; // std::ofstream json_data; second = time(NULL); strstream << second; strstream >> _time; json_data.open("/var/tmp/json_data/json-" + _time, std::ios_base::app); // json_data.open("/var/tmp/json_data/" + url_encode(_id) + "_" + _time, std::ios_base::app); json_data << tr069_json.dump(4); std::string OUI = cwmp__Inform->DeviceId->OUI; (DEBUG) ? std::cout << "OUI1:" << OUI << std::endl : std::cout << "" << std::endl; mysqlpp::Connection conn(false); mysqlpp::Query query = conn.query(); try { conn.connect(DATABASE, HOST, USER, PASSWORD, PORT); if (OUI.find("D8D866") != std::string::npos) { // query << "replace into Device_List (IP,IMSI,`datetime`,update_interval,enodeb_id,cell_id,softwareversion,pcilock,description,IMEI," "rsrp1,rsrp2,rsrq,sinr1,sinr2,U_mcs,d_mcs,txpower,dhcp,ethernet_status,uptime,hardwareversion,upload_rate,download_rate," "DNS) values ('" + std::string(ip) + "','" + imsi + "',NOW()" + "," + tr069_json["InternetGatewayDevice"]["ManagementServer"]["PeriodicInformInterval"]["_value"].dump() + "," + tr069["EnodeBId"] + "," + tr069["CellId"] + ",'" + tr069["SoftwareVersion"] + "','" + tr069["PCILock"] + "'," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["Description"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["DeviceInfo"]["IMEI"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["RSRP1"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["RSRP2"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["RSRQ"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["SINR1"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["SINR2"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["DL_MCS"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["UL_MCS"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["TX_Power"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["LANHostConfigManagement"]["DHCPServerEnable"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Enable"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["UpTime"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["HardwareVersion"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["UL_DataRate_Current"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["DL_DataRate_Current"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["DnsServer"]["_value"].dump() + ");"; // // } else if (OUI.find("2020") != std::string::npos) { (DEBUG) ? std::cout << "OUI:" << cwmp__Inform->DeviceId->OUI << std::endl : std::cout << "" << std::endl; query << "replace into Device_List (IP,IMSI,`datetime`,update_interval,enodeb_id,cell_id,softwareversion,pcilock,description,IMEI," "rsrp1,rsrp2,rsrq,sinr1,sinr2,U_mcs,d_mcs,txpower,dhcp,ethernet_status,uptime,hardwareversion,upload_rate,download_rate," "DNS) values ('" + std::string(ip) + "','" + imsi + "',NOW()" + "," + "-1" + "," + tr069["ENODBID"] + "," + tr069["CELLID"] + ",'" + tr069["SoftwareVersion"] + "','" + tr069["PCILOCK"] + "'," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["Manufacturer"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["IMEI"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSRP1"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSRP2"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSRQ"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SINR1"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SINR2"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ULMCS"]["_value"].dump() + "," + validateInt(tr069_json["InternetGatewayDevice"]["DeviceInfo"]["DLMCS"]["_value"].dump()) + "," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["TXPOWER"]["_value"].dump() + "," + "'-'" + "," + "'-'" + "," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SYSUPTIME"]["_value"].dump() + "," + tr069_json["InternetGatewayDevice"]["DeviceInfo"]["HardwareVersion"]["_value"].dump() + "," + "'-'" + "," + "'-'" + "," + "'-'" + ");"; (DEBUG) ? std::cout << "Query:" << query << std::endl : std::cout << "" << std::endl; // } // std::cout << "Query: " << imsi << " :" << query << std::endl; query.execute(); } catch (mysqlpp::BadQuery er) { // handle any connection or std::cerr << "Error on IMSI-" << imsi << " :" << er.what() << std::endl; } conn.disconnect(); return SOAP_OK; } int cwmpService::FactoryReset(struct _cwmp__FactoryReset *cwmp__factoryReset, struct _cwmp__FactoryResetResponse *cwmp__factoryResetResponse) { return SOAP_OK; } int cwmpService::Reboot(struct _cwmp__Reboot *cwmp__Reboot, struct _cwmp__RebootResponse *cwmp__RebootResponse) { return SOAP_OK; } int cwmpService::CheckQueue(struct soap *soap, cwmpService *cwmpService1) { // std::cerr << "IP: " << soap->host << std::endl; soap->error = 0; std::string IMSI{}, s, id; const char *_actionParameters = ""; int action{0}; /* * { "FileType":"1", "URL":"http://172.20.9.24:808/ZLT_P11S_P13-NO_LOGO-P11PLUS-EN_48.3_update_file-all_2019_12_19_20_21_02.zip", "FilesSize":"4367707", "SuccessURL":null, "FailureURL":null } */ std::stringstream strValue; json actionParameters = {}; mysqlpp::Connection conn(false); mysqlpp::Query query = conn.query(); mysqlpp::Query _query = conn.query(); try { conn.connect(DATABASE, HOST, USER, PASSWORD, PORT); query << "select t.id, d.IMSI , t.action , t.ActionParameters from TaskList as t join Device_List as d on t.IMSI=d.IMSI where d.IP='" << soap->host << "' and t.response is null and t.Active=0 and t.`datetime` < NOW() order by id limit 1;"; mysqlpp::StoreQueryResult result = query.store(); if (result.size() == 0) return soap->error = 204; mysqlpp::StoreQueryResult::const_iterator it; for (it = result.begin(); it != result.end(); ++it) { mysqlpp::Row row = *it; strValue << row["id"]; strValue >> id; strValue << row["IMSI"]; strValue >> IMSI; action = row["action"]; _actionParameters = row["ActionParameters"]; } // std::cerr<<"Size of result+: "<host << " :" << er.what() << std::endl; } conn.disconnect(); actionParameters = json::parse(s); if (action == 1) { try { std::cerr << "sending download request for " << soap->host << std::endl; int DelaySeconds = 1; std::string str = actionParameters["FileType"]; char *FileType = new char[str.length() + 1]; strcpy(FileType, str.c_str()); str = actionParameters["URL"]; char *URL = new char[str.length() + 1]; strcpy(URL, str.c_str()); char *Username = NULL; char *Password = NULL; int FileSize = std::stoi(std::string(actionParameters["FilesSize"])); char *TargetFileName = NULL; str = actionParameters["SuccessURL"]; char *SuccessURL = new char[str.length() + 1]; strcpy(SuccessURL, str.c_str()); str = actionParameters["FailureURL"]; char *FailureURL = new char[str.length() + 1]; strcpy(FailureURL, str.c_str()); return CustomeDownload(soap, this, DelaySeconds, FileType, URL, Username, Password, FileSize, TargetFileName, SuccessURL, FailureURL); } catch (std::exception ex) { // handle any connection or std::cerr << "Error on CPE with IP: " << soap->host << " :" << ex.what() << std::endl; } } // // return CustomeDownload(soap, this, std::__cxx11::string(), std::__cxx11::string(), std::__cxx11::string(), // std::__cxx11::string(), std::__cxx11::string(), std::__cxx11::string(), // std::__cxx11::string(), // std::__cxx11::string(), std::__cxx11::string()); // return soap_closesock(soap); return soap->error = 204; } int cwmpService::CustomeDownloadResponse(struct soap *pSoap, cwmpService *pService) { std::cerr << "Upgrade Response received." << std::endl; std::stringstream strValue; std::string IMSI{}, s, id; soap->error = 0; mysqlpp::Connection conn(false); mysqlpp::Query query = conn.query(); mysqlpp::Query _query = conn.query(); try { conn.connect(DATABASE, HOST, USER, PASSWORD, PORT); query << "select t.id from TaskList as t join Device_List as d on t.IMSI=d.IMSI where d.IP='" << soap->host << "' and t.response is null and t.Active=1 order by id limit 1;"; mysqlpp::StoreQueryResult result = query.store(); if (result.size() == 0) return soap->error = 204; mysqlpp::StoreQueryResult::const_iterator it; for (it = result.begin(); it != result.end(); ++it) { mysqlpp::Row row = *it; strValue << row["id"]; strValue >> id; } } catch (mysqlpp::BadQuery er) { // handle any connection or std::cerr << "Error on CPE with IP: " << soap->host << " :" << er.what() << std::endl; } _query << "update TaskList set Response='Done' where id='" << id << "';"; _query.execute(); conn.disconnect(); // struct _cwmp__DownloadResponse cwmp__downloadResponse; // if ((soap->mode & SOAP_IO_LENGTH)) { // if (soap_envelope_begin_out(soap) // || soap_putheader(soap) // || soap_body_begin_out(soap) // || soap_put__cwmp__DownloadResponse(soap, &cwmp__downloadResponse, "cwmp:DownloadResponse", "") // || soap_body_end_out(soap) // || soap_envelope_end_out(soap)) // return soap->error; // }; // if (soap_end_count(soap) // || soap_response(soap, SOAP_OK) // || soap_envelope_begin_out(soap) // || soap_putheader(soap) // || soap_body_begin_out(soap) // || soap_put__cwmp__DownloadResponse(soap, &cwmp__downloadResponse, "cwmp:DownloadResponse", "") // || soap_body_end_out(soap) // || soap_envelope_end_out(soap) // || soap_end_send(soap)) // return soap->error; soap->keep_alive = 0; return soap_closesock(soap); }