Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.36 KB | None | 0 0
  1. <?php
  2. /* lms-laserver-CMTS.php
  3. * moduł LMS do obsługi urządzeń CMTS
  4. * 2016 Rafał Zając Lanserver.pl
  5. */
  6.  
  7. require('/usr/share/php/HTTP/Request2.php');
  8. //------------------------------------------
  9. $cmts_host = isset($CONFIG['cmts']['host']) ? $CONFIG['cmts']['host'] : '';
  10. $cmts_port = isset($CONFIG['cmts']['port']) ? $CONFIG['cmts']['port'] : '';
  11. $cmts_user = isset($CONFIG['cmts']['user']) ? $CONFIG['cmts']['user'] : '';
  12. $cmts_pass = isset($CONFIG['cmts']['pass']) ? $CONFIG['cmts']['pass'] : '';
  13.  
  14. $lettsmall = ['a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'w', 'v', 'x', 'y', 'z'];
  15. $lettbig = ['A','B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'W', 'V', 'X', 'Y', 'Z'];
  16.  
  17. $request = new HTTP_Request2('http://'.$cmts_host.':'.$cmts_port.'/download/CM.csv');
  18. $request->setAuth($cmts_user, $cmts_pass, HTTP_Request2::AUTH_DIGEST);
  19. $response = $request->send();
  20.  
  21. $cm_file = str_getcsv($response->getBody());
  22.  
  23. $splitter = array();
  24. $count = 0; $index = 1;
  25. foreach($cm_file as $line){
  26.  
  27. if($count > 0)$splitter[$index][$count] = $line;
  28. if($count == 20) { //if($count == 15)
  29. $count = 0;
  30. $index = $index + 1;
  31. } else
  32. $count = $count + 1;
  33. }
  34. $main_sorted = array();
  35. foreach($splitter as $key => $tmp){
  36.  
  37. if (strpos($tmp[1], '-') !== false) {
  38. $tmp[1] = str_replace("-"," / ", $tmp[1]);
  39. }
  40. if (strpos($tmp[1], ';') !== false) {
  41. $tmp[1] = str_replace(";"," <br><img src='img/node.gif' style='height: 12px; width: 12px'> ", $tmp[1]);
  42. }
  43. if(strlen($tmp[1]) > 3) $tmp[1] .= "&nbsp;";
  44.  
  45. $main_sorted[$tmp[3]] = [
  46. 'num_cpes' => $tmp[1],'sid' => $tmp[2],
  47. 'mac' => str_replace($lettsmall, $lettbig,trim($tmp[3])),'ip' => $tmp[4],
  48. 'status' => $tmp[5],'version' => $tmp[8],
  49. 'channel_ds' => $tmp[9],'channel_us' => $tmp[10],
  50. 'power_ds' => $tmp[12],'power_us' => $tmp[13],
  51. 'snr_ds' => $tmp[14],'snr_us' => $tmp[15],
  52. 'rate_ds' => $tmp[16],'rate_us' => $tmp[17],
  53. 'model' => $tmp[20]];
  54.  
  55. }
  56. // WYWALAMY PIERWSZY WPIS (HEADER Z CSV)
  57. unset($main_sorted['MAC']);
  58. $lms_netdevlist = $LMS->GetNetDevList();
  59. //echo "<pre>";print_r($lms_netdevlist);die;
  60. foreach($lms_netdevlist as $dev => $devdata){
  61. if(isset($devdata['id'])){
  62. $lms_netdevipinfo = $LMS->GetNetDevIps($devdata['id']);
  63. if($lms_netdevipinfo[0]){
  64. $dev_mac = $lms_netdevipinfo[0]['mac'];
  65. foreach($main_sorted as $modem => $modemdata){
  66. if($dev_mac == $modemdata['mac']){
  67. $lms_devlink = $LMS->GetNetdevLinkedNodes($devdata['id']);
  68. if($lms_devlink[0]){
  69. $customerid = $lms_devlink[0]['ownerid'];
  70. $customer = $LMS->GetCustomer($customerid);
  71. if(!empty($customer['post_name'])) $customer['customername'] = $customer['post_name'];
  72. if(strlen($customer['customername']) > 35) $customer['customername'] = substr($customer['customername'], 0,32)."...";
  73. // JEŚLI POLA POST TO ADRES Z NICH
  74. if($devdata['location'])
  75. {
  76. $customer['address'] = $devdata['location'];
  77. }
  78. else
  79. {
  80. if(!empty($customer['post_address']) AND !empty($customer['post_zip']) AND !empty($customer['post_address'])) {
  81. $customer['address'] = $customer['post_address'].";".$customer['post_zip'].";".$customer['post_city'];
  82. } else {
  83. $customer['address'] = $customer['address'].";".$customer['zip'].";".$customer['city'];
  84. }
  85. }
  86. if(strlen($customer['address']) > 42) $customer['address'] = substr($customer['address'], 0,39)."...";
  87. // echo "<pre>";print_r($customer);die;
  88. //DODAJEMY DANE DO ARRYA Z CMTS
  89. $main_sorted[$modem]['lms_customer_info'] = $customer;
  90. $main_sorted[$modem]['lms_device_info'] = $devdata;
  91. $main_sorted[$modem]['lms_ips_info'] = $lms_netdevipinfo[0];
  92. $main_sorted[$modem]['lms_device_links'] = $lms_devlink;
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }
  99.  
  100. $totalcounter = 0;
  101. $onlinecounter = 0;
  102. $sort_address = array();
  103. foreach ($main_sorted as $idx => $modem) {
  104. $totalcounter += 1;
  105. if($modem['status'] == 'Online')
  106. $onlinecounter += 1;
  107.  
  108. if(isset($modem['lms_customer_info'])) {
  109. if(strlen($modem['lms_customer_info']['address']) > 4){
  110. $pol = ['ż', 'ź', 'ć', 'ń', 'ą', 'ś', 'ł', 'ę', 'ó', 'Ż', 'Ź', 'Ć', 'Ń', 'Ą', 'Ś', 'Ł', 'Ę', 'Ó'];
  111. $eng = ['z', 'z', 'c', 'n', 'a', 's', 'l', 'e', 'o', 'Z', 'Z', 'C', 'N', 'A', 'S', 'L', 'E', 'O'];
  112. $s = strtoupper(str_replace($pol, $eng, $modem['lms_customer_info']['address']));
  113. $sort_address[$s][] = $idx;
  114. } else {
  115. $s = '0000';
  116. $sort_address[$s][] = $idx;
  117. }
  118. } else {
  119. $s = '0000';
  120. $sort_address[$s][] = $idx;
  121. }
  122. }
  123. ksort($sort_address);
  124. $final_sort = array();
  125. foreach ($sort_address as $idx => $macarr) {
  126. foreach ($macarr as $idy => $mac) {
  127. $final_sort[] = $main_sorted[$mac];
  128. }
  129. }
  130.  
  131. // echo "<pre>";print_r($final_sort);die;
  132.  
  133. $SMARTY->assign('totalcounter',$totalcounter);
  134. $SMARTY->assign('onlinecounter',$onlinecounter);
  135. $SMARTY->assign('modemlist',$final_sort);
  136. $SMARTY->display('lanserver/cmts/cmstatus.html');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement