main.cpp 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. #include <iostream>
  2. #include "httppost.h"
  3. #include "cwmp.nsmap"
  4. #include "soapcwmpService.h"
  5. #include "plugin/threads.h"
  6. #include <vector>
  7. #include <algorithm>
  8. #include <signal.h>
  9. #include <thread>
  10. #include <fstream>
  11. #include "json.hpp"
  12. #include <mysql++/mysql++.h>
  13. #include <zdb.h>
  14. #define HOST "localhost"
  15. #define USER "acs"
  16. #define PASSWORD "159753"
  17. #define DATABASE "ACS"
  18. #define PORT 3306
  19. bool DEBUG = false;
  20. using json = nlohmann::json;
  21. //int port = 7547;
  22. int port = 7548;
  23. //int port = 8001;
  24. int POST_handler(struct soap *soap);
  25. struct http_post_handlers http_post_handlers[] = {
  26. {"POST", POST_handler},
  27. {NULL}
  28. };
  29. std::string currentISO8601TimeUTC() {
  30. std::time_t t = std::time(nullptr);
  31. std::ostringstream ss;
  32. ss << std::put_time(std::localtime(&t), "%FT%T %Z");
  33. return ss.str();
  34. }
  35. void handler(int s) {
  36. printf("Sassan Caught SIGPIPE ...\n");
  37. }
  38. void *process_request(void *arg) {
  39. cwmpService *service = (cwmpService *) arg;
  40. THREAD_DETACH(THREAD_ID);
  41. if (service) {
  42. service->serve();
  43. service->destroy(); /* clean up */
  44. delete service;
  45. }
  46. return NULL;
  47. }
  48. //<editor-fold desc="zbx_keys">
  49. //TODO: Read keys from config file and remap them to zbx_keys
  50. std::string zbx_keys[] = {"InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.Uptime",
  51. "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.UL_MCS",
  52. "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.TX_Power",
  53. "InternetGatewayDevice.DeviceInfo.SoftwareVersion",
  54. "InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.SINR2",
  55. "InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.SINR1",
  56. "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.RSRP2",
  57. "InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.RSRQ",
  58. "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.RSRQ",
  59. "InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.DHCPServerEnable",
  60. "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Setting.Status",
  61. "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus",
  62. "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.RSRP1",
  63. "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress",
  64. "InternetGatewayDevice.WEB_GUI.Overview.DeviceInfo.IMSI",
  65. "InternetGatewayDevice.WEB_GUI.Overview.DeviceInfo.IMEI",
  66. "InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.EnodeBId",
  67. "InternetGatewayDevice.DeviceInfo.MemoryStatus.Free",
  68. "InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.EnodeBId",
  69. "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.DL_MCS",
  70. "InternetGatewayDevice.Time.CurrentLocalTime",
  71. "InternetGatewayDevice.DeviceInfo.ProcessStatus.CPUUsage",
  72. "InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.CellId",
  73. "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.BytesSent",
  74. "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.BytesReceived",
  75. "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.PacketsReceived",
  76. "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.PacketsSent",
  77. "InternetGatewayDevice.DeviceInfo.UpTime",
  78. "InternetGatewayDevice.DeviceInfo.X_TGT_IMSI",
  79. "InternetGatewayDevice.WEB_GUI.Network.Network_Mode.WANIPAddress",
  80. "InternetGatewayDevice.WEB_GUI.Network.ScanMode.Settings.PCILock",
  81. "InternetGatewayDevice.WEB_GUI.Overview.LTEStatus.DnsServer",
  82. "InternetGatewayDevice.DeviceInfo.HardwareVersion",
  83. "InternetGatewayDevice.DeviceInfo.Manufacturer",
  84. "InternetGatewayDevice.DeviceInfo.ManufacturerOUI",
  85. "InternetGatewayDevice.DeviceInfo.ModelName",
  86. "InternetGatewayDevice.DeviceInfo.ModelNumber",
  87. "InternetGatewayDevice.DeviceInfo.Description",
  88. "InternetGatewayDevice.DeviceInfo.ProductClass",
  89. "InternetGatewayDevice.DeviceInfo.SerialNumber",
  90. "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.1.Enable",
  91. "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.2.Enable",
  92. "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Enable",
  93. "InternetGatewayDevice.WEB_GUI.Overview.LTEStatus.DL_DataRate_Current",
  94. "InternetGatewayDevice.WEB_GUI.Overview.LTEStatus.UL_DataRate_Current",
  95. "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.PCI",
  96. "InternetGatewayDevice.WEB_GUI.Overview.LANStatus.MacAddress",
  97. "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.DL_Frequency",
  98. "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.UL_Frequency",
  99. "InternetGatewayDevice.ManagementServer.ConnectionRequestURL",
  100. "InternetGatewayDevice.ManagementServer.PeriodicInformInterval",
  101. "InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.IPInterface.1.IPInterfaceIPAddress",
  102. //ESM
  103. "InternetGatewayDevice.DeviceInfo.SpecVersion",
  104. "InternetGatewayDevice.DeviceInfo.ProvisioningCode",
  105. // "InternetGatewayDevice.DeviceInfo.Manufacturer",
  106. "InternetGatewayDevice.DeviceInfo.ManufacturerOUI",
  107. "InternetGatewayDevice.DeviceInfo.ProductClass",
  108. "InternetGatewayDevice.DeviceInfo.SerialNumber",
  109. "InternetGatewayDevice.DeviceInfo.ModelName",
  110. "InternetGatewayDevice.DeviceInfo.RSRP1",
  111. "InternetGatewayDevice.DeviceInfo.RSRP2",
  112. "InternetGatewayDevice.DeviceInfo.CINR1",
  113. "InternetGatewayDevice.DeviceInfo.CINR2",
  114. "InternetGatewayDevice.DeviceInfo.RSRQ",
  115. "InternetGatewayDevice.DeviceInfo.TAC",
  116. "InternetGatewayDevice.DeviceInfo.PCID",
  117. "InternetGatewayDevice.DeviceInfo.EARFCN",
  118. "InternetGatewayDevice.DeviceInfo.PWR",
  119. "InternetGatewayDevice.DeviceInfo.IMEI",
  120. "InternetGatewayDevice.DeviceInfo.IMSI",
  121. "InternetGatewayDevice.DeviceInfo.IPV4",
  122. "InternetGatewayDevice.DeviceInfo.RSSI",
  123. "InternetGatewayDevice.DeviceInfo.ENODBID",
  124. "InternetGatewayDevice.DeviceInfo.CELLID",
  125. "InternetGatewayDevice.DeviceInfo.DLBAND",
  126. "InternetGatewayDevice.DeviceInfo.ULBAND",
  127. "InternetGatewayDevice.DeviceInfo.TXMODE",
  128. "InternetGatewayDevice.DeviceInfo.FREQUANCE",
  129. "InternetGatewayDevice.DeviceInfo.SINR1",
  130. "InternetGatewayDevice.DeviceInfo.SINR2",
  131. "InternetGatewayDevice.DeviceInfo.NOISE1",
  132. "InternetGatewayDevice.DeviceInfo.NOISE2",
  133. "InternetGatewayDevice.DeviceInfo.MODAL",
  134. "InternetGatewayDevice.DeviceInfo.CAR",
  135. "InternetGatewayDevice.DeviceInfo.BAND",
  136. "InternetGatewayDevice.DeviceInfo.PLMN",
  137. "InternetGatewayDevice.DeviceInfo.WANUPTIME",
  138. "InternetGatewayDevice.DeviceInfo.SYSUPTIME",
  139. "InternetGatewayDevice.DeviceInfo.BITRECIEVED",
  140. "InternetGatewayDevice.DeviceInfo.BITSENT",
  141. "InternetGatewayDevice.DeviceInfo.CPUUSAGE",
  142. "InternetGatewayDevice.DeviceInfo.MEMORYFREE",
  143. "InternetGatewayDevice.DeviceInfo.TXPOWER",
  144. "InternetGatewayDevice.DeviceInfo.PCILOCK",
  145. "InternetGatewayDevice.DeviceInfo.ULMCS",
  146. "InternetGatewayDevice.DeviceInfo.DLMCS",
  147. "InternetGatewayDevice.DeviceInfo.CURRENTTIME",
  148. "InternetGatewayDevice.DeviceInfo.HardwareVersion",
  149. "InternetGatewayDevice.DeviceInfo.SoftwareVersion",
  150. "InternetGatewayDevice.ManagementServer.ConnectionRequestURL",
  151. "InternetGatewayDevice.ManagementServer.ParameterKey",
  152. "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress"
  153. };
  154. //</editor-fold>
  155. std::string validateInt(std::string y) {
  156. int x{0};
  157. try {
  158. x = stoi(y);
  159. }
  160. catch (std::invalid_argument &e) {
  161. return "-100000";
  162. // if no conversion could be performed
  163. }
  164. catch (std::out_of_range &e) {
  165. // if the converted value would fall out of the range of the result type
  166. // or if the underlying function (std::strtol or std::strtoull) sets errno
  167. // to ERANGE.
  168. return "-100000";
  169. }
  170. catch (...) {
  171. // everything else
  172. return "-100000";
  173. }
  174. return std::to_string(x);
  175. }
  176. std::string url_encode(const std::string &value) {
  177. std::ostringstream escaped;
  178. escaped.fill('0');
  179. escaped << std::hex;
  180. for (std::string::const_iterator i = value.begin(), n = value.end(); i != n; ++i) {
  181. std::string::value_type c = (*i);
  182. // Keep alphanumeric and other accepted characters intact
  183. if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
  184. escaped << c;
  185. continue;
  186. }
  187. // Any other characters are percent-encoded
  188. escaped << std::uppercase;
  189. escaped << '%' << std::setw(2) << int((unsigned char) c);
  190. escaped << std::nouppercase;
  191. }
  192. return escaped.str();
  193. }
  194. int main(int argc, char *argv[]) {
  195. signal(SIGPIPE, handler);
  196. for (int i = 1; i < argc; i++) {
  197. if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
  198. printf("Usage: App <options>\nOptions are:\n");
  199. printf("\t -v,--version: version information\n");
  200. printf("\t -d,--debug: run in debug mode\n");
  201. printf("\t -p,--port: override port\n");
  202. printf("\t -h,--help: print this help\n");
  203. exit(0);
  204. } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
  205. std::cout << "TR069 Server Build (1.4) Powered by gSoap 2.8.83 and CMake " << std::endl;
  206. return 0;
  207. } else if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
  208. DEBUG = true;
  209. } else {
  210. if (i == argc - 1) {
  211. break;
  212. }
  213. }
  214. }
  215. if (DEBUG == true) {
  216. std::cout << "TR069 Server Started on DEBUG mode Port " << port << "(1.4)...\n" << std::endl;
  217. } else {
  218. std::cout << "TR069 Server Started on Port " << port << "(1.4)...\n" << std::endl;
  219. }
  220. cwmpService service(SOAP_XML_INDENT);
  221. service.soap->send_timeout = service.soap->recv_timeout = 5;
  222. service.soap->transfer_timeout = 60;
  223. service.soap->keep_alive = 20;
  224. service.soap->tcp_keep_alive = 1;
  225. service.soap->bind_flags |= SO_REUSEADDR;
  226. service.soap->bind_flags |= SO_REUSEPORT;
  227. service.soap->bind_flags |= MSG_NOSIGNAL;
  228. soap_init2(service.soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE);
  229. SOAP_SOCKET m = service.bind(NULL, port, 100); /* master socket */
  230. if (soap_valid_socket(m)) {
  231. while (soap_valid_socket(service.accept())) {
  232. THREAD_TYPE tid;
  233. void *arg = (void *) service.copy();
  234. if (arg)
  235. while (THREAD_CREATE(&tid, (void *(*)(void *)) process_request, arg))
  236. sleep(1);
  237. }
  238. }
  239. service.soap_stream_fault(std::cerr);
  240. service.destroy(); /* clean up */
  241. return 0;
  242. }
  243. int POST_handler(struct soap *soap) {
  244. const char *buf;
  245. size_t len;
  246. buf = soap_http_get_body(soap, &len);
  247. if (len == 0) {
  248. std::cerr << "Sassan 204...: " << buf << std::endl;
  249. return 204; // HTTP 400 Bad Request
  250. }
  251. }
  252. int cwmpService::GetParameterNames(struct _cwmp__GetParameterNames *cwmp__GetParameterNames,
  253. struct _cwmp__GetParameterNamesResponse *cwmp__GetParameterNamesResponse) { return SOAP_OK; }
  254. int cwmpService::GetParameterValues(struct _cwmp__GetParameterValues *cwmp__GetParameterValues,
  255. struct _cwmp__GetParameterValuesResponse *cwmp__GetParameterValuesResponse) { return SOAP_OK; }
  256. int cwmpService::SetParameterValues(struct _cwmp__SetParameterValues *cwmp__SetParameterValues,
  257. struct _cwmp__SetParameterValuesResponse *cwmp__SetParameterValuesResponse) {
  258. return SOAP_OK;
  259. }
  260. int cwmpService::SetParameterAttributes(
  261. struct _cwmp__SetParameterAttributes *cwmp__SetParameterAttributes,
  262. struct _cwmp__SetParameterAttributesResponse *cwmp__SetParameterAttributesResponse) { return SOAP_OK; }
  263. int cwmpService::GetParameterAttributes(struct _cwmp__GetParameterAttributes *cwmp__GetParameterAttributes,
  264. struct _cwmp__GetParameterAttributesResponse *cwmp__GetParameterAttributesResponse) { return SOAP_OK; }
  265. int cwmpService::Download(struct _cwmp__Download *cwmp__Download,
  266. struct _cwmp__DownloadResponse *cwmp__DownloadResponse) { return SOAP_OK; }
  267. int cwmpService::Upload(
  268. struct _cwmp__Upload *cwmp__Upload,
  269. struct _cwmp__UploadResponse *cwmp__UploadResponse) { return SOAP_OK; }
  270. int cwmpService::AddObject(
  271. struct _cwmp__AddObject *cwmp__AddObject,
  272. struct _cwmp__AddObjectResponse *cwmp__AddObjectResponse) { return SOAP_OK; }
  273. int cwmpService::DeleteObject(
  274. struct _cwmp__DeleteObject *cwmp__DeleteObject,
  275. struct _cwmp__DeleteObjectResponse *cwmp__DeleteObjectResponse) { return SOAP_OK; }
  276. int cwmpService::GetRPCMethods(
  277. struct _cwmp__GetRPCMethods *cwmp__GetRPCMethods,
  278. struct _cwmp__GetRPCMethodsResponse *cwmp__GetRPCMethodsResponse) { return SOAP_OK; }
  279. int cwmpService::GetParameterValuesResponse(
  280. struct _cwmp__GetParameterValuesResponse *cwmp__GetParameterValuesResponse) { return SOAP_OK; }
  281. int cwmpService::Inform(struct _cwmp__Inform *cwmp__Inform, struct _cwmp__InformResponse *cwmp__InformResponse,
  282. struct soap *soap) {
  283. std::string _id = std::string(cwmp__Inform->DeviceId->OUI) + "-" + std::string(cwmp__Inform->DeviceId->ProductClass)
  284. + "-" + std::string(cwmp__Inform->DeviceId->SerialNumber);
  285. std::cerr << "Inform Recieved from: " << url_encode(_id) << " at " << time(NULL) << std::endl;
  286. char *imsi;
  287. char *ip;
  288. auto timestamp = std::chrono::high_resolution_clock::now();
  289. std::vector<std::thread> th;
  290. std::vector<std::thread> th_acs;
  291. // int indexes[24];
  292. std::vector<int> ind;
  293. std::ofstream outfile;
  294. outfile.open("/var/tmp/tr069/" + url_encode(_id), std::ios::out | std::ios::trunc);
  295. std::ofstream mongoData;
  296. time_t second;
  297. std::string _time;
  298. std::map<std::string, std::string> tr069{};
  299. second = time(NULL);
  300. std::stringstream strstream;
  301. strstream << second;
  302. strstream >> _time;
  303. ip = soap->host;
  304. for (int i = 0; i < cwmp__Inform->ParameterList->__size; ++i) {
  305. char *_Name = cwmp__Inform->ParameterList->__ptrParameterValueStruct[i]->Name;
  306. char *_Value = cwmp__Inform->ParameterList->__ptrParameterValueStruct[i]->Value;
  307. if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.X_TGT_IMSI") == 0 or
  308. std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.IMSI") == 0) {
  309. imsi = _Value;
  310. break;
  311. }
  312. }
  313. for (int i = 0; i < cwmp__Inform->ParameterList->__size; ++i) {
  314. char *_Name = cwmp__Inform->ParameterList->__ptrParameterValueStruct[i]->Name;
  315. char *_Value = cwmp__Inform->ParameterList->__ptrParameterValueStruct[i]->Value;
  316. outfile << _Name << ": " << _Value << std::endl;
  317. // if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.X_TGT_IMSI") == 0) {
  318. // imsi = _Value;
  319. // }
  320. // if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.Network_Mode.WANIPAddress") == 0) {
  321. // ip = _Value;
  322. // }
  323. std::string cpe = cwmp__Inform->DeviceId->SerialNumber;
  324. auto j = std::find(std::begin(zbx_keys), std::end(zbx_keys), _Name);
  325. if (j != std::end(zbx_keys)) {
  326. if (
  327. !strcmp(_Name, "InternetGatewayDevice.DeviceInfo.MODAL") == 0 or
  328. !strcmp(_Name, "InternetGatewayDevice.DeviceInfo.ULMCS") == 0 or
  329. !strcmp(_Name, "InternetGatewayDevice.DeviceInfo.DLMCS") == 0 or
  330. !strcmp(_Name, "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.DL_MCS") == 0 or
  331. !strcmp(_Name, "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.UL_MCS") == 0) {
  332. if (!strcmp(_Value, "QPSK")) {
  333. _Value = "4";
  334. } else if (!strcmp(_Value, "QAM8")) {
  335. _Value = "8";
  336. } else if (!strcmp(_Value, "QAM16")) {
  337. _Value = "16";
  338. } else if (!strcmp(_Value, "QAM32")) {
  339. _Value = "32";
  340. } else if (!strcmp(_Value, "QAM64")) {
  341. _Value = "64";
  342. }
  343. std::ofstream zbx_data;
  344. std::string _time{};
  345. time_t second;
  346. second = time(NULL);
  347. std::stringstream strstream;
  348. strstream << second;
  349. strstream >> _time;
  350. if (DEBUG) {
  351. std::cout << "IMSI:" << imsi << " Key:" << _Name << " Value:" << _Value << " Second:" << second
  352. << std::endl;
  353. }
  354. // zbx_data.open("/var/tmp/zbx_sender-" + _time, std::ios_base::app);
  355. if (DEBUG) {
  356. zbx_data.open("/tmp/debug-zbx_sender-" + _time, std::ios_base::app);
  357. } else {
  358. zbx_data.open("/var/tmp/zbx_sender-" + _time, std::ios_base::app);
  359. }
  360. zbx_data << "IMSI-" << imsi << " " << _Name << " " << second << " \"" << _Value << "\"" << std::endl;
  361. }
  362. //<editor-fold desc="Map Filler">
  363. if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.HardwareVersion") == 0)
  364. tr069.insert({"HardwareVersion", _Value});
  365. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SoftwareVersion") == 0)
  366. tr069.insert({"SoftwareVersion", _Value});
  367. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.UpTime") == 0)
  368. tr069.insert({"UpTime", _Value});
  369. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Overview.DeviceInfo.IMEI") == 0)
  370. tr069.insert({"IMEI", _Value});
  371. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.X_TGT_IMSI") == 0)
  372. tr069.insert({"IMSI", _Value});
  373. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.MemoryStatus.Free") == 0)
  374. tr069.insert({"Free", _Value});
  375. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ProcessStatus.CPUUsage") == 0)
  376. tr069.insert({"CPUUsage", _Value});
  377. else if (std::string(_Name).compare("InternetGatewayDevice.Time.CurrentLocalTime") == 0)
  378. tr069.insert({"CurrentLocalTime", _Value});
  379. else if (std::string(_Name).compare(
  380. "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.1.Enable") == 0)
  381. tr069.insert({"LAN1Enable", _Value});
  382. else if (std::string(_Name).compare(
  383. "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.2.Enable") == 0)
  384. tr069.insert({"LAN2Enable", _Value});
  385. else if (std::string(_Name).compare("InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.SINR1") == 0)
  386. tr069.insert({"SINR1", _Value});
  387. else if (std::string(_Name).compare("InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.SINR2") == 0)
  388. tr069.insert({"SINR2", _Value});
  389. else if (std::string(_Name).compare("InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.EnodeBId") ==
  390. 0)
  391. tr069.insert({"EnodeBId", _Value});
  392. else if (std::string(_Name).compare("InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.CellId") == 0)
  393. tr069.insert({"CellId", _Value});
  394. else if (std::string(_Name).compare(
  395. "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.BytesSent") == 0)
  396. tr069.insert({"BytesSent", _Value});
  397. else if (std::string(_Name).compare(
  398. "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.BytesReceived") == 0)
  399. tr069.insert({"BytesReceived", _Value});
  400. else if (std::string(_Name).compare(
  401. "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.PacketsSent") == 0)
  402. tr069.insert({"PacketsSent", _Value});
  403. else if (std::string(_Name).compare(
  404. "InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Stats.PacketsReceived") == 0)
  405. tr069.insert({"PacketsReceived", _Value});
  406. else if (std::string(_Name).compare(
  407. "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus") == 0)
  408. tr069.insert({"ConnectionStatus", _Value});
  409. else if (std::string(_Name).compare(
  410. "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.Uptime") == 0)
  411. tr069.insert({"Uptime", _Value});
  412. else if (std::string(_Name).compare(
  413. "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress") == 0)
  414. tr069.insert({"ExternalIPAddress", _Value});
  415. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.RSRP1") == 0)
  416. tr069.insert({"RSRP1", _Value});
  417. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.RSRP2") == 0)
  418. tr069.insert({"RSRP2", _Value});
  419. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.TX_Power") ==
  420. 0)
  421. tr069.insert({"TX_Power", _Value});
  422. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.DL_MCS") == 0)
  423. tr069.insert({"DL_MCS", _Value});
  424. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.UL_MCS") == 0)
  425. tr069.insert({"UL_MCS", _Value});
  426. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Setting.Status") ==
  427. 0)
  428. tr069.insert({"LTEStatus", _Value});
  429. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.ScanMode.Settings.PCILock") == 0)
  430. tr069.insert({"PCILock", _Value});
  431. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.Network_Mode.WANIPAddress") == 0)
  432. tr069.insert({"WANIPAddress", _Value});
  433. else if (std::string(_Name).compare("InternetGatewayDevice.ManagementServer.PeriodicInformInterval") == 0)
  434. tr069.insert({"PeriodicInformInterval", _Value});
  435. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Overview.LTEStatus.DnsServer") == 0)
  436. tr069.insert({"DnsServer", _Value});
  437. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Overview.DeviceInfo.IMSI") == 0)
  438. tr069.insert({"IMSI", _Value});
  439. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.Manufacturer") == 0)
  440. tr069.insert({"Manufacturer", _Value});
  441. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ManufacturerOUI") == 0)
  442. tr069.insert({"OUI", _Value});
  443. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ModelName") == 0)
  444. tr069.insert({"ModelName", _Value});
  445. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ModelNumber") == 0)
  446. tr069.insert({"ModelNumber", _Value});
  447. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.Description") == 0)
  448. tr069.insert({"Description", _Value});
  449. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ProductClass") == 0)
  450. tr069.insert({"ProductClass", _Value});
  451. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SerialNumber") == 0)
  452. tr069.insert({"SerialNumber", _Value});
  453. else if (std::string(_Name).compare("InternetGatewayDevice.WANDevice.1.X_TGT_WANNetConfigInfo.RSRQ") == 0)
  454. tr069.insert({"RSRQ", _Value});
  455. else if (std::string(_Name).compare(
  456. "InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.DHCPServerEnable") == 0)
  457. tr069.insert({"DHCPServerEnable", _Value});
  458. else if (
  459. std::string(_Name).compare("InternetGatewayDevice.WANDevice.1.WANEthernetInterfaceConfig.Enable") ==
  460. 0)
  461. tr069.insert({"WANEthernetInterfaceConfigEnable", _Value});
  462. else if (std::string(_Name).compare("InternetGatewayDevice.ManagementServer.ConnectionRequestURL") == 0)
  463. tr069.insert({"ConnectionRequestURL", _Value});
  464. else if (std::string(_Name).compare(
  465. "InternetGatewayDevice.WEB_GUI.Overview.LTEStatus.DL_DataRate_Current") == 0)
  466. tr069.insert({"DL_DataRate_Current", _Value});
  467. else if (std::string(_Name).compare(
  468. "InternetGatewayDevice.WEB_GUI.Overview.LTEStatus.UL_DataRate_Current") == 0)
  469. tr069.insert({"UL_DataRate_Current", _Value});
  470. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.PCI") == 0)
  471. tr069.insert({"PCI", _Value});
  472. else if (std::string(_Name).compare(
  473. "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.UL_Frequency") == 0)
  474. tr069.insert({"UL_Frequency", _Value});
  475. else if (std::string(_Name).compare(
  476. "InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.DL_Frequency") == 0)
  477. tr069.insert({"DL_Frequency", _Value});
  478. else if (std::string(_Name).compare(
  479. "InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.IPInterface.1.IPInterfaceIPAddress") ==
  480. 0)
  481. tr069.insert({"IPInterfaceIPAddress", _Value});
  482. else if (std::string(_Name).compare("InternetGatewayDevice.WEB_GUI.Overview.LANStatus.MacAddress") == 0)
  483. tr069.insert({"MacAddress", _Value});
  484. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ManufacturerOUI") == 0)
  485. tr069.insert({"ManufacturerOUI", _Value});
  486. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SpecVersion") == 0)
  487. tr069.insert({"SpecVersion", _Value});
  488. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ProvisioningCode") == 0)
  489. tr069.insert({"ProvisioningCode", _Value});
  490. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.Manufacturer") == 0)
  491. tr069.insert({"Manufacturer", _Value});
  492. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ManufacturerOUI") == 0)
  493. tr069.insert({"ManufacturerOUI", _Value});
  494. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ProductClass") == 0)
  495. tr069.insert({"ProductClass", _Value});
  496. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SerialNumber") == 0)
  497. tr069.insert({"SerialNumber", _Value});
  498. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ModelName") == 0)
  499. tr069.insert({"ModelName", _Value});
  500. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.RSRP0") == 0)
  501. tr069.insert({"RSRP0", _Value});
  502. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.RSRP1") == 0)
  503. tr069.insert({"RSRP1", _Value});
  504. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.RSRP2") == 0)
  505. tr069.insert({"RSRP2", _Value});
  506. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CINR0") == 0)
  507. tr069.insert({"CINR0", _Value});
  508. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CINR1") == 0)
  509. tr069.insert({"CINR1", _Value});
  510. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CINR2") == 0)
  511. tr069.insert({"CINR2", _Value});
  512. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.RSRQ") == 0)
  513. tr069.insert({"RSRQ", _Value});
  514. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.TAC") == 0)
  515. tr069.insert({"TAC", _Value});
  516. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.PCID") == 0)
  517. tr069.insert({"PCID", _Value});
  518. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.EARFCN") == 0)
  519. tr069.insert({"EARFCN", _Value});
  520. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.PWR") == 0)
  521. tr069.insert({"PWR", _Value});
  522. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.IMEI") == 0)
  523. tr069.insert({"IMEI", _Value});
  524. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.IMSI") == 0)
  525. tr069.insert({"IMSI", _Value});
  526. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.IPV4") == 0)
  527. tr069.insert({"IPV4", _Value});
  528. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.RSSI") == 0)
  529. tr069.insert({"RSSI", _Value});
  530. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ENODBID") == 0)
  531. tr069.insert({"ENODBID", _Value});
  532. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CELLID") == 0)
  533. tr069.insert({"CELLID", _Value});
  534. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.DLBAND") == 0)
  535. tr069.insert({"DLBAND", _Value});
  536. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ULBAND") == 0)
  537. tr069.insert({"ULBAND", _Value});
  538. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.TXMODE") == 0)
  539. tr069.insert({"TXMODE", _Value});
  540. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.FREQUANCE") == 0)
  541. tr069.insert({"FREQUANCE", _Value});
  542. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SINR0") == 0)
  543. tr069.insert({"SINR0", _Value});
  544. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SINR1") == 0)
  545. tr069.insert({"SINR1", _Value});
  546. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SINR2") == 0)
  547. tr069.insert({"SINR2", _Value});
  548. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.NOISE0") == 0)
  549. tr069.insert({"NOISE0", _Value});
  550. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.NOISE1") == 0)
  551. tr069.insert({"NOISE1", _Value});
  552. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.NOISE2") == 0)
  553. tr069.insert({"NOISE2", _Value});
  554. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.MODAL") == 0)
  555. tr069.insert({"MODAL", _Value});
  556. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CAR") == 0)
  557. tr069.insert({"CAR", _Value});
  558. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.BAND") == 0)
  559. tr069.insert({"BAND", _Value});
  560. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.PLMN") == 0)
  561. tr069.insert({"PLMN", _Value});
  562. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.WANUPTIME") == 0)
  563. tr069.insert({"WANUPTIME", _Value});
  564. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SYSUPTIME") == 0)
  565. tr069.insert({"SYSUPTIME", _Value});
  566. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.BITRECIEVED") == 0)
  567. tr069.insert({"BITRECIEVED", _Value});
  568. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.BITSENT") == 0)
  569. tr069.insert({"BITSENT", _Value});
  570. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CPUUSAGE") == 0)
  571. tr069.insert({"CPUUSAGE", _Value});
  572. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.MEMORYFREE") == 0)
  573. tr069.insert({"MEMORYFREE", _Value});
  574. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.TXPOWER") == 0)
  575. tr069.insert({"TXPOWER", _Value});
  576. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.PCILOCK") == 0)
  577. tr069.insert({"PCILOCK", _Value});
  578. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ULMCS") == 0)
  579. tr069.insert({"ULMCS", _Value});
  580. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.DLMCS") == 0)
  581. tr069.insert({"DLMCS", _Value});
  582. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.CURRENTTIME") == 0)
  583. tr069.insert({"CURRENTTIME", _Value});
  584. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.HardwareVersion") == 0)
  585. tr069.insert({"HardwareVersion", _Value});
  586. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.SoftwareVersion") == 0)
  587. tr069.insert({"SoftwareVersion", _Value});
  588. else if (std::string(_Name).compare("InternetGatewayDevice.DeviceInfo.ConnectionRequestURL") == 0)
  589. tr069.insert({"ConnectionRequestURL", _Value});
  590. //</editor-fold>
  591. }
  592. }
  593. std::ofstream zbx_data;
  594. zbx_data.open("/var/tmp/zbx_sender-" + _time, std::ios_base::app);
  595. zbx_data << "IMSI-" << imsi << " " << "BytsReceived" << " " << second << " \"" << tr069["BytesReceived"] << "\""
  596. << std::endl;
  597. zbx_data << "IMSI-" << imsi << " " << "BytsSent" << " " << second << " \"" << tr069["BytesSent"] << "\""
  598. << std::endl;
  599. //<editor-fold desc="Json">
  600. std::string ISOTime = currentISO8601TimeUTC();
  601. json tr069_json{};
  602. tr069_json["_id"] = url_encode(_id);
  603. tr069_json["_deviceId"]["_Manufacturer"] = cwmp__Inform->DeviceId->Manufacturer;
  604. tr069_json["_deviceId"]["_OUI"] = cwmp__Inform->DeviceId->OUI;
  605. tr069_json["_deviceId"]["_ProductClass"] = cwmp__Inform->DeviceId->ProductClass;
  606. tr069_json["_deviceId"]["_SerialNumber"] = cwmp__Inform->DeviceId->SerialNumber;
  607. tr069_json["_lastInform"] = ISOTime;
  608. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANConnectionDevice"]["1"]["WANIPConnection"]["1"]["Uptime"]["_value"] = tr069["Uptime"];
  609. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["UL_MCS"]["_value"] = tr069["UL_MCS"];
  610. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["TX_Power"]["_value"] = tr069["TX_Power"];
  611. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SoftwareVersion"]["_value"] = tr069["SoftwareVersion"];
  612. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["SINR2"]["_value"] = tr069["SINR2"];
  613. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["SINR1"]["_value"] = tr069["SINR1"];
  614. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["RSRP2"]["_value"] = tr069["RSRP2"];
  615. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["RSRQ"]["_value"] = tr069["RSRQ"];
  616. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["RSRQ"]["_value"] = tr069["RSRQ"];
  617. tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["LANHostConfigManagement"]["DHCPServerEnable"]["_value"] = tr069["DHCPServerEnable"];
  618. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Setting"]["Status"]["_value"] = tr069["LTEStatus"];
  619. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANConnectionDevice"]["1"]["WANIPConnection"]["1"]["ConnectionStatus"]["_value"] = tr069["ConnectionStatus"];
  620. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["RSRP1"]["_value"] = tr069["RSRP1"];
  621. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANConnectionDevice"]["1"]["WANIPConnection"]["1"]["ExternalIPAddress"]["_value"] = tr069["ExternalIPAddress"];
  622. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["DeviceInfo"]["IMSI"]["_value"] = tr069["IMSI"];
  623. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["DeviceInfo"]["IMEI"]["_value"] = tr069["IMEI"];
  624. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["EnodeBId"]["_value"] = tr069["EnodeBId"];
  625. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["MemoryStatus"]["Free"]["_value"] = tr069["Free"];
  626. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["EnodeBId"]["_value"] = tr069["EnodeBId"];
  627. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["DL_MCS"]["_value"] = tr069["DL_MCS"];
  628. tr069_json["InternetGatewayDevice"]["Time"]["CurrentLocalTime"]["_value"] = tr069["CurrentLocalTime"];
  629. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ProcessStatus"]["CPUUsage"]["_value"] = tr069["CPUUsage"];
  630. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["CellId"]["_value"] = tr069["CellId"];
  631. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Stats"]["BytesSent"]["_value"] = tr069["BytesSent"];
  632. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Stats"]["BytesReceived"]["_value"] = tr069["BytesReceived"];
  633. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Stats"]["PacketsReceived"]["_value"] = tr069["PacketsReceived"];
  634. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Stats"]["PacketsSent"]["_value"] = tr069["PacketsSent"];
  635. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["UpTime"]["_value"] = tr069["UpTime"];
  636. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["X_TGT_IMSI"]["_value"] = tr069["IMSI"];
  637. tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["LANEthernetInterfaceConfig"]["1"]["Enable"]["_value"] = tr069["Enable"];
  638. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["Network_Mode"]["WANIPAddress"]["_value"] = tr069["WANIPAddress"];
  639. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["ScanMode"]["Settings"]["PCILock"]["_value"] = tr069["PCILock"];
  640. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["DnsServer"]["_value"] = tr069["DnsServer"];
  641. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["HardwareVersion"]["_value"] = tr069["HardwareVersion"];
  642. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["Manufacturer"]["_value"] = cwmp__Inform->DeviceId->Manufacturer;
  643. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ManufacturerOUI"]["_value"] = cwmp__Inform->DeviceId->OUI;
  644. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ModelName"]["_value"] = tr069["ModelName"];
  645. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ModelNumber"]["_value"] = tr069["ModelNumber"];
  646. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["Description"]["_value"] = tr069["Description"];
  647. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ProductClass"]["_value"] = cwmp__Inform->DeviceId->ProductClass;
  648. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SerialNumber"]["_value"] = cwmp__Inform->DeviceId->SerialNumber;
  649. tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["LANEthernetInterfaceConfig"]["1"]["Enable"]["_value"] = tr069["LAN1Enable"];
  650. tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["LANEthernetInterfaceConfig"]["2"]["Enable"]["_value"] = tr069["LAN2Enable"];
  651. tr069_json["InternetGatewayDevice"]["ManagementServer"]["ConnectionRequestURL"]["_value"] = tr069["ConnectionRequestURL"];
  652. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Enable"]["_value"] = tr069["WANEthernetInterfaceConfigEnable"];
  653. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["DL_DataRate_Current"]["_value"] = tr069["DL_DataRate_Current"];
  654. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["UL_DataRate_Current"]["_value"] = tr069["UL_DataRate_Current"];
  655. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["PCI"]["_value"] = tr069["PCI"];
  656. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LANStatus"]["MacAddress"]["_value"] = tr069["MacAddress"];
  657. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["DL_Frequency"]["_value"] = tr069["DL_Frequency"];
  658. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["UL_Frequency"]["_value"] = tr069["UL_Frequency"];
  659. tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["IPInterface"]["1"]["IPInterfaceIPAddress"]["_value"] = tr069["IPInterfaceIPAddress"];
  660. tr069_json["InternetGatewayDevice"]["ManagementServer"]["PeriodicInformInterval"]["_value"] = tr069["PeriodicInformInterval"];
  661. //ESM
  662. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ManufacturerOUI"]["_value"] = cwmp__Inform->DeviceId->OUI;
  663. // tr069_json["InternetGatewayDevice"]["DeviceInfo"]["Manufacturer"]["_value"] = tr069["Manufacturer"];
  664. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSRP1"]["_value"] = tr069["RSRP1"];
  665. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSRP2"]["_value"] = tr069["RSRP2"];
  666. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["CINR1"]["_value"] = tr069["CINR1"];
  667. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["CINR2"]["_value"] = tr069["CINR2"];
  668. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSRQ"]["_value"] = tr069["RSRQ"];
  669. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["TAC"]["_value"] = tr069["TAC"];
  670. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["PCID"]["_value"] = tr069["PCID"];
  671. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["EARFCN"]["_value"] = tr069["EARFCN"];
  672. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["PWR"]["_value"] = tr069["PWR"];
  673. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["IMEI"]["_value"] = tr069["IMEI"];
  674. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["IMSI"]["_value"] = tr069["IMSI"];
  675. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["IPV4"]["_value"] = tr069["IPV4"];
  676. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSSI"]["_value"] = tr069["RSSI"];
  677. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ENODBID"]["_value"] = tr069["ENODBID"];
  678. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["CELLID"]["_value"] = tr069["CELLID"];
  679. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["DLBAND"]["_value"] = tr069["DLBAND"];
  680. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ULBAND"]["_value"] = tr069["ULBAND"];
  681. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["TXMODE"]["_value"] = tr069["TXMODE"];
  682. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["FREQUANCE"]["_value"] = tr069["FREQUANCE"];
  683. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SINR1"]["_value"] = tr069["SINR1"];
  684. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SINR2"]["_value"] = tr069["SINR2"];
  685. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["NOISE1"]["_value"] = tr069["NOISE1"];
  686. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["NOISE2"]["_value"] = tr069["NOISE2"];
  687. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["MODAL"]["_value"] = tr069["MODAL"];
  688. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["CAR"]["_value"] = tr069["CAR"];
  689. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["BAND"]["_value"] = tr069["BAND"];
  690. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["PLMN"]["_value"] = tr069["PLMN"];
  691. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["WANUPTIME"]["_value"] = tr069["WANUPTIME"];
  692. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SYSUPTIME"]["_value"] = tr069["SYSUPTIME"];
  693. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["BITRECIEVED"]["_value"] = tr069["BITRECIEVED"];
  694. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["BITSENT"]["_value"] = tr069["BITSENT"];
  695. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["CPUUSAGE"]["_value"] = tr069["CPUUSAGE"];
  696. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["MEMORYFREE"]["_value"] = tr069["MEMORYFREE"];
  697. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["TXPOWER"]["_value"] = tr069["TXPOWER"];
  698. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["PCILOCK"]["_value"] = tr069["PCILOCK"];
  699. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ULMCS"]["_value"] = tr069["ULMCS"];
  700. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["DLMCS"]["_value"] = tr069["DLMCS"];
  701. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["CURRENTTIME"]["_value"] = tr069["CURRENTTIME"];
  702. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["HardwareVersion"]["_value"] = tr069["HardwareVersion"];
  703. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SoftwareVersion"]["_value"] = tr069["SoftwareVersion"];
  704. //ESM Extenede Data
  705. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["EnodeBId"]["_value"] = tr069["ENODBID"];
  706. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["EnodeBId"]["_value"] = tr069["ENODBID"];
  707. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["Network_Mode"]["WANIPAddress"]["_value"] = tr069["IPV4"];
  708. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANConnectionDevice"]["1"]["WANIPConnection"]["1"]["ExternalIPAddress"]["_value"] = tr069["IPV4"];
  709. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["ScanMode"]["Settings"]["PCILock"]["_value"] = tr069["PCILOCK"];
  710. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["UpTime"]["_value"] = tr069["SYSUPTIME"];
  711. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANConnectionDevice"]["1"]["WANIPConnection"]["1"]["Uptime"]["_value"] = tr069["SYSUPTIME"];
  712. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["DL_MCS"]["_value"] = tr069["DLMCS"];
  713. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["UL_MCS"]["_value"] = tr069["ULMCS"];
  714. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["CellId"]["_value"] = tr069["CELLID"];
  715. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["TX_Power"]["_value"] = tr069["TXPOWER"];
  716. tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["LANHostConfigManagement"]["DHCPServerEnable"]["_value"] = "UNKNOWN";
  717. tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["LANEthernetInterfaceConfig"]["1"]["Enable"]["_value"] = "UNKNOWN";
  718. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Setting"]["Status"]["_value"] = "UNKNOWN";
  719. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["UL_DataRate_Current"]["_value"] = -1;
  720. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["DL_DataRate_Current"]["_value"] = -1;
  721. tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["IPInterface"]["1"]["IPInterfaceIPAddress"]["_value"] = "UNKNOWN";
  722. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["DnsServer"]["_value"] = "UNKNOWN";
  723. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANConnectionDevice"]["1"]["WANIPConnection"]["1"]["ConnectionStatus"]["_value"] = "UNKNOWN";
  724. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Enable"]["_value"] = "UNKNOWN";
  725. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Setting"]["Status"]["_value"] = -1;
  726. //</editor-fold>
  727. std::ofstream json_data;
  728. second = time(NULL);
  729. strstream << second;
  730. strstream >> _time;
  731. json_data.open("/var/tmp/json_data/json-" + _time, std::ios_base::app);
  732. // json_data.open("/var/tmp/json_data/" + url_encode(_id) + "_" + _time, std::ios_base::app);
  733. json_data << tr069_json.dump(4);
  734. std::string OUI = cwmp__Inform->DeviceId->OUI;
  735. (DEBUG) ? std::cout << "OUI1:" << OUI << std::endl : std::cout << "" << std::endl;
  736. mysqlpp::Connection conn(false);
  737. mysqlpp::Query query = conn.query();
  738. try {
  739. conn.connect(DATABASE, HOST, USER, PASSWORD, PORT);
  740. if (OUI.find("D8D866") != std::string::npos) {
  741. //<editor-fold desc="Mysql-Query">
  742. query <<
  743. "replace into Device_List (IP,IMSI,`datetime`,update_interval,enodeb_id,cell_id,softwareversion,pcilock,description,IMEI,"
  744. "rsrp1,rsrp2,rsrq,sinr1,sinr2,U_mcs,d_mcs,txpower,dhcp,ethernet_status,uptime,hardwareversion,upload_rate,download_rate,"
  745. "DNS) values ('" +
  746. std::string(ip) + "','" + imsi + "',NOW()" + "," +
  747. tr069_json["InternetGatewayDevice"]["ManagementServer"]["PeriodicInformInterval"]["_value"].dump() +
  748. "," +
  749. tr069["EnodeBId"] + "," + tr069["CellId"] +
  750. ",'" + tr069["SoftwareVersion"] + "','" + tr069["PCILock"] + "'," +
  751. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["Description"]["_value"].dump() + "," +
  752. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["DeviceInfo"]["IMEI"]["_value"].dump() +
  753. "," +
  754. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["RSRP1"]["_value"].dump() +
  755. "," +
  756. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["RSRP2"]["_value"].dump() +
  757. "," +
  758. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["RSRQ"]["_value"].dump() +
  759. "," +
  760. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["SINR1"]["_value"].dump() +
  761. "," +
  762. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["X_TGT_WANNetConfigInfo"]["SINR2"]["_value"].dump() +
  763. "," +
  764. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["DL_MCS"]["_value"].dump() +
  765. "," +
  766. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["UL_MCS"]["_value"].dump() +
  767. "," +
  768. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Network"]["LTE_Setting"]["Status"]["TX_Power"]["_value"].dump() +
  769. "," +
  770. tr069_json["InternetGatewayDevice"]["LANDevice"]["1"]["LANHostConfigManagement"]["DHCPServerEnable"]["_value"].dump() +
  771. "," +
  772. tr069_json["InternetGatewayDevice"]["WANDevice"]["1"]["WANEthernetInterfaceConfig"]["Enable"]["_value"].dump() +
  773. "," +
  774. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["UpTime"]["_value"].dump() + "," +
  775. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["HardwareVersion"]["_value"].dump() + "," +
  776. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["UL_DataRate_Current"]["_value"].dump() +
  777. "," +
  778. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["DL_DataRate_Current"]["_value"].dump() +
  779. "," +
  780. tr069_json["InternetGatewayDevice"]["WEB_GUI"]["Overview"]["LTEStatus"]["DnsServer"]["_value"].dump() +
  781. ");";
  782. //</editor-fold>
  783. //<editor-fold desc="Mysql-Query">
  784. } else if (OUI.find("2020") != std::string::npos) {
  785. (DEBUG) ? std::cout << "OUI:" << cwmp__Inform->DeviceId->OUI << std::endl : std::cout << "" << std::endl;
  786. query <<
  787. "replace into Device_List (IP,IMSI,`datetime`,update_interval,enodeb_id,cell_id,softwareversion,pcilock,description,IMEI,"
  788. "rsrp1,rsrp2,rsrq,sinr1,sinr2,U_mcs,d_mcs,txpower,dhcp,ethernet_status,uptime,hardwareversion,upload_rate,download_rate,"
  789. "DNS) values ('" +
  790. std::string(ip) + "','" + imsi + "',NOW()" + "," +
  791. "-1" +
  792. "," +
  793. tr069["ENODBID"] + "," + tr069["CELLID"] +
  794. ",'" + tr069["SoftwareVersion"] + "','" + tr069["PCILOCK"] + "'," +
  795. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["Manufacturer"]["_value"].dump() + "," +
  796. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["IMEI"]["_value"].dump() +
  797. "," +
  798. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSRP1"]["_value"].dump() +
  799. "," +
  800. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSRP2"]["_value"].dump() +
  801. "," +
  802. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["RSRQ"]["_value"].dump() +
  803. "," +
  804. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SINR1"]["_value"].dump() +
  805. "," +
  806. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SINR2"]["_value"].dump() +
  807. "," +
  808. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["ULMCS"]["_value"].dump() +
  809. "," +
  810. validateInt(tr069_json["InternetGatewayDevice"]["DeviceInfo"]["DLMCS"]["_value"].dump()) +
  811. "," +
  812. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["TXPOWER"]["_value"].dump() +
  813. "," +
  814. "'-'" +
  815. "," +
  816. "'-'" +
  817. "," +
  818. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["SYSUPTIME"]["_value"].dump() +
  819. "," +
  820. tr069_json["InternetGatewayDevice"]["DeviceInfo"]["HardwareVersion"]["_value"].dump() +
  821. "," +
  822. "'-'" +
  823. "," +
  824. "'-'" +
  825. "," +
  826. "'-'" +
  827. ");";
  828. (DEBUG) ? std::cout << "Query:" << query << std::endl : std::cout << "" << std::endl;
  829. //</editor-fold>
  830. }
  831. // std::cout << "Query: " << imsi << " :" << query << std::endl;
  832. query.execute();
  833. } catch (mysqlpp::BadQuery er) { // handle any connection or
  834. std::cerr << "Error on IMSI-" << imsi << " :" << er.what() << std::endl;
  835. }
  836. conn.disconnect();
  837. return SOAP_OK;
  838. }
  839. int cwmpService::FactoryReset(struct _cwmp__FactoryReset *cwmp__factoryReset,
  840. struct _cwmp__FactoryResetResponse *cwmp__factoryResetResponse) { return SOAP_OK; }
  841. int cwmpService::Reboot(struct _cwmp__Reboot *cwmp__Reboot,
  842. struct _cwmp__RebootResponse *cwmp__RebootResponse) { return SOAP_OK; }
  843. int cwmpService::CheckQueue(struct soap *soap, cwmpService *cwmpService1) {
  844. // std::cerr << "IP: " << soap->host << std::endl;
  845. soap->error = 0;
  846. std::string IMSI{}, s, id;
  847. const char *_actionParameters = "";
  848. int action{0};
  849. /*
  850. * {
  851. "FileType":"1",
  852. "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",
  853. "FilesSize":"4367707",
  854. "SuccessURL":null,
  855. "FailureURL":null
  856. }
  857. */
  858. std::stringstream strValue;
  859. json actionParameters = {};
  860. mysqlpp::Connection conn(false);
  861. mysqlpp::Query query = conn.query();
  862. mysqlpp::Query _query = conn.query();
  863. try {
  864. conn.connect(DATABASE, HOST, USER, PASSWORD, PORT);
  865. query
  866. << "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='"
  867. << soap->host
  868. << "' and t.response is null and t.Active=0 and t.`datetime` < NOW() order by id limit 1;";
  869. mysqlpp::StoreQueryResult result = query.store();
  870. if (result.size() == 0)
  871. return soap->error = 204;
  872. mysqlpp::StoreQueryResult::const_iterator it;
  873. for (it = result.begin(); it != result.end(); ++it) {
  874. mysqlpp::Row row = *it;
  875. strValue << row["id"];
  876. strValue >> id;
  877. strValue << row["IMSI"];
  878. strValue >> IMSI;
  879. action = row["action"];
  880. _actionParameters = row["ActionParameters"];
  881. }
  882. // std::cerr<<"Size of result+: "<<result.size()<<std::endl;
  883. s = std::string(_actionParameters);
  884. _query << "update TaskList set Active=1 where id='" << id << "';";
  885. _query.execute();
  886. } catch (mysqlpp::BadQuery er) { // handle any connection or
  887. std::cerr << "Error on CPE with IP: " << soap->host << " :" << er.what() << std::endl;
  888. }
  889. conn.disconnect();
  890. actionParameters = json::parse(s);
  891. if (action == 1) {
  892. try {
  893. std::cerr << "sending download request for " << soap->host << std::endl;
  894. int DelaySeconds = 1;
  895. std::string str = actionParameters["FileType"];
  896. char *FileType = new char[str.length() + 1];
  897. strcpy(FileType, str.c_str());
  898. str = actionParameters["URL"];
  899. char *URL = new char[str.length() + 1];
  900. strcpy(URL, str.c_str());
  901. char *Username = NULL;
  902. char *Password = NULL;
  903. int FileSize = std::stoi(std::string(actionParameters["FilesSize"]));
  904. char *TargetFileName = NULL;
  905. str = actionParameters["SuccessURL"];
  906. char *SuccessURL = new char[str.length() + 1];
  907. strcpy(SuccessURL, str.c_str());
  908. str = actionParameters["FailureURL"];
  909. char *FailureURL = new char[str.length() + 1];
  910. strcpy(FailureURL, str.c_str());
  911. return CustomeDownload(soap, this, DelaySeconds, FileType, URL, Username, Password, FileSize,
  912. TargetFileName,
  913. SuccessURL, FailureURL);
  914. } catch (std::exception ex) { // handle any connection or
  915. std::cerr << "Error on CPE with IP: " << soap->host << " :" << ex.what() << std::endl;
  916. }
  917. }
  918. //
  919. // return CustomeDownload(soap, this, std::__cxx11::string(), std::__cxx11::string(), std::__cxx11::string(),
  920. // std::__cxx11::string(), std::__cxx11::string(), std::__cxx11::string(),
  921. // std::__cxx11::string(),
  922. // std::__cxx11::string(), std::__cxx11::string());
  923. // return soap_closesock(soap);
  924. return soap->error = 204;
  925. }
  926. int cwmpService::CustomeDownloadResponse(struct soap *pSoap, cwmpService *pService) {
  927. std::cerr << "Upgrade Response received." << std::endl;
  928. std::stringstream strValue;
  929. std::string IMSI{}, s, id;
  930. soap->error = 0;
  931. mysqlpp::Connection conn(false);
  932. mysqlpp::Query query = conn.query();
  933. mysqlpp::Query _query = conn.query();
  934. try {
  935. conn.connect(DATABASE, HOST, USER, PASSWORD, PORT);
  936. query
  937. << "select t.id from TaskList as t join Device_List as d on t.IMSI=d.IMSI where d.IP='"
  938. << soap->host << "' and t.response is null and t.Active=1 order by id limit 1;";
  939. mysqlpp::StoreQueryResult result = query.store();
  940. if (result.size() == 0)
  941. return soap->error = 204;
  942. mysqlpp::StoreQueryResult::const_iterator it;
  943. for (it = result.begin(); it != result.end(); ++it) {
  944. mysqlpp::Row row = *it;
  945. strValue << row["id"];
  946. strValue >> id;
  947. }
  948. } catch (mysqlpp::BadQuery er) { // handle any connection or
  949. std::cerr << "Error on CPE with IP: " << soap->host << " :" << er.what() << std::endl;
  950. }
  951. _query << "update TaskList set Response='Done' where id='" << id << "';";
  952. _query.execute();
  953. conn.disconnect();
  954. // struct _cwmp__DownloadResponse cwmp__downloadResponse;
  955. // if ((soap->mode & SOAP_IO_LENGTH)) {
  956. // if (soap_envelope_begin_out(soap)
  957. // || soap_putheader(soap)
  958. // || soap_body_begin_out(soap)
  959. // || soap_put__cwmp__DownloadResponse(soap, &cwmp__downloadResponse, "cwmp:DownloadResponse", "")
  960. // || soap_body_end_out(soap)
  961. // || soap_envelope_end_out(soap))
  962. // return soap->error;
  963. // };
  964. // if (soap_end_count(soap)
  965. // || soap_response(soap, SOAP_OK)
  966. // || soap_envelope_begin_out(soap)
  967. // || soap_putheader(soap)
  968. // || soap_body_begin_out(soap)
  969. // || soap_put__cwmp__DownloadResponse(soap, &cwmp__downloadResponse, "cwmp:DownloadResponse", "")
  970. // || soap_body_end_out(soap)
  971. // || soap_envelope_end_out(soap)
  972. // || soap_end_send(soap))
  973. // return soap->error;
  974. soap->keep_alive = 0;
  975. return soap_closesock(soap);
  976. }