index.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <?php
  2. if(cfr('DOCSIS')) {
  3. $altercfg=rcms_parse_ini_file(CONFIG_PATH.'/alter.ini');
  4. if ($altercfg['DOCSIS_SUPPORT']) {
  5. function docsis_AjaxModemDataSource() {
  6. $query="SELECT * from `modems`";
  7. $alladdress= zb_AddressGetFulladdresslist();
  8. $alluserips= zb_UserGetAllIPs();
  9. $alluserips= array_flip($alluserips);
  10. $allmodems= simple_queryall($query);
  11. $i=1;
  12. $totalcount=sizeof($allmodems);
  13. $result='{
  14. "aaData": [';
  15. if (!empty($allmodems)) {
  16. foreach ($allmodems as $io=>$each) {
  17. $ending=($i!=$totalcount) ? ',' : '' ;
  18. if (isset($alluserips[$each['userbind']])) {
  19. @$useraddress=$alladdress[$alluserips[$each['userbind']]];
  20. } else {
  21. $useraddress='';
  22. }
  23. $actions='<a href=?module=docsis&showmodem='.$each['id'].'><img src=skins/icon_edit.gif></a>';
  24. $result.='
  25. [
  26. "'.$each['id'].'",
  27. "'.$each['maclan'].'",
  28. "'.$each['date'].'",
  29. "'.$each['ip'].'",
  30. "'.$each['userbind'].'",
  31. "'.$useraddress.'",
  32. "'.$actions.'"
  33. ]'.$ending.'
  34. ';
  35. $i++;
  36. }
  37. }
  38. $result.=']
  39. }';
  40. die($result);
  41. }
  42. function docsis_ModemsList() {
  43. $jq_dt='
  44. <script type="text/javascript" charset="utf-8">
  45. $(document).ready(function() {
  46. $(\'#docsismodemshp\').dataTable( {
  47. "oLanguage": {
  48. "sLengthMenu": "'.__('Show').' _MENU_",
  49. "sZeroRecords": "'.__('Nothing found').'",
  50. "sInfo": "'.__('Showing').' _START_ '.__('to').' _END_ '.__('of').' _TOTAL_ '.__('modems').'",
  51. "sInfoEmpty": "'.__('Showing').' 0 '.__('to').' 0 '.__('of').' 0 '.__('modems').'",
  52. "sInfoFiltered": "('.__('Filtered').' '.__('from').' _MAX_ '.__('Total').')",
  53. "sSearch": "'.__('Search').'",
  54. "sProcessing": "'.__('Processing').'...",
  55. "oPaginate": {
  56. "sFirst": "'.__('First').'",
  57. "sPrevious": "'.__('Previous').'",
  58. "sNext": "'.__('Next').'",
  59. "sLast": "'.__('Last').'"
  60. },
  61. },
  62. "aoColumns": [
  63. null,
  64. null,
  65. null,
  66. null,
  67. null,
  68. null,
  69. null
  70. ],
  71. "bPaginate": true,
  72. "bLengthChange": true,
  73. "bFilter": true,
  74. "bSort": true,
  75. "bInfo": true,
  76. "bAutoWidth": false,
  77. "bProcessing": true,
  78. "bStateSave": false,
  79. "iDisplayLength": 50,
  80. "sAjaxSource": \'?module=docsis&ajax=true\',
  81. "bDeferRender": true,
  82. "bJQueryUI": true
  83. } );
  84. } );
  85. </script>
  86. ';
  87. $result=$jq_dt.'
  88. <table width="100%" id="docsismodemshp" class="display compact">
  89. <thead>
  90. <tr class="row1">
  91. <td>'.__('ID').'</td>
  92. <td>'.__('MAC Lan').'</td>
  93. <td>'.__('Date').'</td>
  94. <td>'.__('IP').'</td>
  95. <td>'.__('Linked user').'</td>
  96. <td>'.__('Full address').'</td>
  97. <td>'.__('Actions').'</td>
  98. </tr>
  99. </thead>
  100. </table>
  101. ';
  102. show_window(__('Available DOCSIS modems'),$result);
  103. }
  104. function docsis_ModemAdd($maclan) {
  105. $maclan= mysql_real_escape_string($maclan);
  106. //random mac for usb
  107. $macusb= '14:'.'88'.':'.rand(10,99).':'.rand(10,99).':'.rand(10,99).':'.rand(10,99);
  108. $altercfg=rcms_parse_ini_file(CONFIG_PATH.'/alter.ini');
  109. $netid=$altercfg['DOCSIS_MODEM_NETID'];
  110. $nextfreeip= multinet_get_next_freeip('nethosts', 'ip', $netid);
  111. $note='';
  112. $userbind='';
  113. $basetemplate='short';
  114. $date=curdate();
  115. //check for free ip in subnet
  116. if (!empty($nextfreeip)) {
  117. $nic= str_replace('.', 'x', $nextfreeip);
  118. //check is mac unique?
  119. if ((multinet_mac_free($maclan)) AND (check_mac_format($maclan))) {
  120. $query="INSERT INTO `modems` (
  121. `id` ,
  122. `maclan` ,
  123. `macusb` ,
  124. `date` ,
  125. `ip` ,
  126. `conftemplate` ,
  127. `userbind` ,
  128. `nic` ,
  129. `note`
  130. )
  131. VALUES (
  132. NULL , '".$maclan."', '".$maclan."', '".$date."', '".$nextfreeip."', '".$basetemplate."', '' , '".$nic."', ''
  133. );";
  134. nr_query($query);
  135. $lastid= simple_get_lastid('modems');
  136. log_register("DOCSIS MODEM ADD MAC".$maclan." IP ".$nextfreeip."[".$lastid."]");
  137. multinet_add_host($netid, $nextfreeip, $maclan, '');
  138. multinet_rebuild_all_handlers();
  139. rcms_redirect("?module=docsis&showmodem=".$lastid);
  140. } else {
  141. show_window(__('Error'), __('This MAC is currently used').' '.__('This MAC have wrong format'));
  142. }
  143. } else {
  144. show_window(__('Error'),__('No free IP available in selected pool'));
  145. }
  146. }
  147. function docsis_ModemGetData($modemid) {
  148. $modemid=vf($modemid,3);
  149. $query="SELECT * from `modems` WHERE `id`='".$modemid."'";
  150. $result= simple_query($query);
  151. return ($result);
  152. }
  153. function docsis_ModemDelete($modemid) {
  154. $modemid=vf($modemid,3);
  155. $modemdata= docsis_ModemGetData($modemid);
  156. if (!empty($modemdata)) {
  157. $modemip=$modemdata['ip'];
  158. $query="DELETE from `modems` WHERE `id`='".$modemid."'";
  159. nr_query($query);
  160. log_register("DOCSIS MODEM DELETE IP ".$modemip." [".$modemid."]");
  161. multinet_delete_host($modemip);
  162. multinet_rebuild_all_handlers();
  163. }
  164. }
  165. function docsis_ModemAddForm() {
  166. $inputs= wf_TextInput('newmaclan', __('MAC Lan'), '', true, '20');
  167. $inputs.= wf_Submit(__('Create new modem'));
  168. $result= wf_Form("", 'POST', $inputs, 'glamour');
  169. return ($result);
  170. }
  171. function docsis_ModemSnmpGet() {
  172. $community= zb_StorageGet('DOCSIS_MODEM_COMMUNITY');
  173. //if first run
  174. if (empty($community)) {
  175. $community='public';
  176. zb_StorageSet('DOCSIS_MODEM_COMMUNITY', $community);
  177. log_register("DOCSIS MODEM SNMP SET `".$community."`");
  178. }
  179. return ($community);
  180. }
  181. function docsis_ModemSnmpSet($community) {
  182. zb_StorageSet('DOCSIS_MODEM_COMMUNITY', $community);
  183. log_register("DOCSIS MODEM SNMP SET `".$community."`");
  184. }
  185. function docsis_ModemSnmpWalkGet() {
  186. $path= zb_StorageGet('DOCSIS_SNMPWALK_PATH');
  187. //if first run
  188. if (empty($path)) {
  189. $path='/usr/local/bin/snmpwalk';
  190. zb_StorageSet('DOCSIS_SNMPWALK_PATH', $path);
  191. log_register("DOCSIS SNMPWALK SET `".$path."`");
  192. }
  193. return ($path);
  194. }
  195. function docsis_ModemSnmpWalkSet($path) {
  196. zb_StorageSet('DOCSIS_SNMPWALK_PATH', $path);
  197. log_register("DOCSIS SNMPWALK SET `".$path."`");
  198. }
  199. function docsis_ModemSnmpForm() {
  200. $community= docsis_ModemSnmpGet();
  201. $snmpwalkpath= docsis_ModemSnmpWalkGet();
  202. $inputs= wf_TextInput('newmodemcommunity', 'Modems SNMP community', $community, true, '20');
  203. $inputs.= wf_TextInput('newsnmpwalkpath', 'snmpwalk Path', $snmpwalkpath, true, '20');
  204. $inputs.= wf_Submit('Save');
  205. $result= wf_Form("", 'POST', $inputs, 'glamour');
  206. return ($result);
  207. }
  208. //backported from old releases "as is"
  209. function docsis_ModemDiagShow($modemid) {
  210. $modemid=vf($modemid,3);
  211. $modemdata= docsis_ModemGetData($modemid);
  212. $ip=$modemdata['ip'];
  213. $community= docsis_ModemSnmpGet();
  214. //modem status
  215. // if == 12 operational
  216. $statusc="/usr/local/bin/snmpwalk -r 0 -t 1 -v2c -c ".$community." ".$ip." 1.3.6.1.2.1.10.127.1.2.2.1.1.2 | /usr/bin/awk '{print $4}'";
  217. $status=shell_exec($statusc);
  218. if ($status==12) {
  219. $status= wf_tag('font', false, '', 'color="#009933"').__('Operational').wf_tag('font', true);
  220. } else {
  221. $status= wf_tag('font', false, '', 'color="#CC0000"').__('Offline').wf_tag('font', true);
  222. }
  223. //modem uptime
  224. $uptimec="/usr/local/bin/snmpwalk -r 0 -t 1 -v2c -c ".$community." ".$ip." 1.3.6.1.2.1.1.3.0 | /usr/bin/awk '{print $5 $6 $7}'";
  225. $uptime=shell_exec($uptimec);
  226. //modem down freq
  227. $dsfreqc="/usr/local/bin/snmpwalk -r 0 -t 1 -v2c -c ".$community." ".$ip." 1.3.6.1.2.1.10.127.1.1.1.1.2.3 | /usr/bin/awk '{print $4}'";
  228. $dsfreq=shell_exec($dsfreqc);
  229. $dsfreq=$dsfreq/1000000;
  230. //upstream freq
  231. $usfreqc="/usr/local/bin/snmpwalk -r 0 -t 1 -v2c -c ".$community." ".$ip." 1.3.6.1.2.1.10.127.1.1.2.1.2.4 | /usr/bin/awk '{print $4}'";
  232. $usfreq=shell_exec($usfreqc);
  233. $usfreq=$usfreq/1000000;
  234. //downstream SNR
  235. // real_snr=snr/10 , must be <35
  236. $dssnrc="/usr/local/bin/snmpwalk -r 0 -t 1 -v2c -c ".$community." ".$ip." 1.3.6.1.2.1.10.127.1.1.4.1.5.3 | /usr/bin/awk '{print $4}'";
  237. $dssnr=shell_exec($dssnrc);
  238. $dssnr=$dssnr/10;
  239. if ($dssnr<45) {
  240. $dssnr=wf_tag('font', false, '', 'color="#009933"').$dssnr.wf_tag('font', true);
  241. } else {
  242. $dssnr=wf_tag('font', false, '', 'color="#CC0000"').$dssnr.wf_tag('font', true);
  243. }
  244. //modem DS power
  245. // real_respower=respower/10
  246. //Need level > -13 and < 17 dBmV!
  247. $dspowerc="/usr/local/bin/snmpwalk -r 0 -t 1 -v2c -c ".$community." ".$ip." 1.3.6.1.2.1.10.127.1.1.1.1.6 | /usr/bin/awk '{print $4}'";
  248. $dspower=shell_exec($dspowerc);
  249. $dspower=$dspower/10;
  250. if (($dspower<17) AND ($dspower>-13)) {
  251. $dspower=wf_tag('font', false, '', 'color="#009933"').$dspower.wf_tag('font', true);
  252. } else {
  253. $dspower=wf_tag('font', false, '', 'color="#CC0000"').$dspower.wf_tag('font', true);
  254. }
  255. //modem US power
  256. //real_power=power/10
  257. //Need level < 51 dBmV!
  258. $uspowerc="/usr/local/bin/snmpwalk -r 0 -t 1 -v2c -c ".$community." ".$ip." 1.3.6.1.2.1.10.127.1.2.2.1.3.2 | /usr/bin/awk '{print $4}'";
  259. $uspower=shell_exec($uspowerc);
  260. $uspower=$uspower/10;
  261. if (($uspower<51) AND ($uspower>36)) {
  262. $uspower=wf_tag('font', false, '', 'color="#009933"').$uspower.wf_tag('font', true);
  263. } else {
  264. $uspower=wf_tag('font', false, '', 'color="#CC0000"').$uspower.wf_tag('font', true);
  265. }
  266. // ds modul
  267. //if == 4 QAM256
  268. //if == 3 QAM64
  269. $dsmodulc="/usr/local/bin/snmpwalk -r 0 -t 1 -v2c -c ".$community." ".$ip." 1.3.6.1.2.1.10.127.1.1.1.1.4.3 | /usr/bin/awk '{print $4}'";
  270. $dsmodul=shell_exec($dsmodulc);
  271. if ($dsmodul==4) {
  272. $dsmodul='QAM256';
  273. }
  274. if ($dsmodul==3) {
  275. $dsmodul='QAM64';
  276. }
  277. //ds annex
  278. // 3 ==
  279. // 4 == Annex B
  280. // 5 == Annex C
  281. $dsannexc="/usr/local/bin/snmpwalk -r 0 -t 1 -v2c -c ".$community." ".$ip." 1.3.6.1.2.1.10.127.1.1.1.1.7.3 | /usr/bin/awk '{print $4}'";
  282. $dsannex=shell_exec($dsannexc);
  283. if ($dsannex==3) {
  284. $dsannex='Annex A';
  285. }
  286. if ($dsannex==4) {
  287. $dsannex='Annex B';
  288. }
  289. if ($dsannex==5) {
  290. $dsannex='Annex C';
  291. }
  292. //=======================
  293. //ct in
  294. $rfinc="/usr/local/bin/snmpwalk -Os -v2c -c ".$community." ".$ip." ifHCInOctets.2 | /usr/bin/awk '{print $4}'";
  295. $rfin=shell_exec($rfinc);
  296. //ct out
  297. $rfout="/usr/local/bin/snmpwalk -Os -v2c -c ".$community." ".$ip." ifHCOutOctets.2 | /usr/bin/awk '{print $4}'";
  298. $rfout=shell_exec($rfout);
  299. $cells= wf_TableCell(__('IP'));
  300. $cells.= wf_TableCell($ip);
  301. $rows= wf_TableRow($cells, 'row3');
  302. $cells= wf_TableCell(__('Modem status'));
  303. $cells.= wf_TableCell($status);
  304. $rows.= wf_TableRow($cells, 'row3');
  305. $cells= wf_TableCell(__('Modem uptime'));
  306. $cells.= wf_TableCell($uptime);
  307. $rows.= wf_TableRow($cells, 'row3');
  308. $cells= wf_TableCell(__('DS Freq'));
  309. $cells.= wf_TableCell($dsfreq);
  310. $rows.= wf_TableRow($cells, 'row3');
  311. $cells= wf_TableCell(__('US Freq'));
  312. $cells.= wf_TableCell($usfreq);
  313. $rows.= wf_TableRow($cells, 'row3');
  314. $cells= wf_TableCell(__('DS SNR'));
  315. $cells.= wf_TableCell($dssnr);
  316. $rows.= wf_TableRow($cells, 'row3');
  317. $cells= wf_TableCell(__('DS power'));
  318. $cells.= wf_TableCell($dspower);
  319. $rows.= wf_TableRow($cells, 'row3');
  320. $cells= wf_TableCell(__('US power'));
  321. $cells.= wf_TableCell($uspower);
  322. $rows.= wf_TableRow($cells, 'row3');
  323. $cells= wf_TableCell(__('DS Modulation'));
  324. $cells.= wf_TableCell($dsmodul);
  325. $rows.= wf_TableRow($cells, 'row3');
  326. $cells= wf_TableCell(__('DS Annex'));
  327. $cells.= wf_TableCell($dsannex);
  328. $rows.= wf_TableRow($cells, 'row3');
  329. $cells= wf_TableCell(__('RF In'));
  330. $cells.= wf_TableCell($rfin);
  331. $rows.= wf_TableRow($cells, 'row3');
  332. $cells= wf_TableCell(__('RF Out'));
  333. $cells.= wf_TableCell($rfout);
  334. $rows.= wf_TableRow($cells, 'row3');
  335. $result= wf_TableBody($rows, '100%', '0');
  336. die ($result);
  337. }
  338. function docsis_ControlsShow() {
  339. $controls= wf_modal(__('Add new modem'), __('Add new modem'), docsis_ModemAddForm(), 'ubButton', '300', '150');
  340. $controls.= wf_modal(__('Monitoring options'), __('SNMP configuration'), docsis_ModemSnmpForm(), 'ubButton', '450', '200');
  341. show_window('', $controls);
  342. }
  343. function docsis_ModemProfileShow($modemid) {
  344. $modemid=vf($modemid,3);
  345. $data= docsis_ModemGetData($modemid);
  346. $netdata=array();
  347. $netdata_q="SELECT * from `nethosts` where `ip`='".$data['ip']."'";
  348. $netdata= simple_queryall($netdata_q);
  349. $netdata= print_r($netdata,true);
  350. $netdata= nl2br($netdata);
  351. $alluserips= zb_UserGetAllIPs();
  352. $alluserips= array_flip($alluserips);
  353. $result= wf_Link("?module=docsis", __('Back'), false, 'ubButton');
  354. $ajaxcontainer= wf_AjaxLoader(). wf_AjaxLink("?module=docsis&ajaxsnmp=".$modemid, __('Renew modem data'),'ajaxdata', true, 'ubButton').wf_tag('div', false, '', 'id="ajaxdata"').wf_tag('div',true);
  355. $result.=wf_modal(__('Modem diagnostics'), __('Modem diagnostics'), $ajaxcontainer, 'ubButton', '500', '400');
  356. $result.=wf_modal(__('Networking data'), __('Networking data'), $netdata, 'ubButton', '500', '400');
  357. $result.=wf_delimiter();
  358. if (!empty($data)) {
  359. $cells= wf_TableCell(__('ID'));
  360. $cells.= wf_TableCell($data['id'].' '.wf_JSAlert("?module=docsis&deletemodem=".$modemid, web_delete_icon(), __('Removing this may lead to irreparable results')));
  361. $rows= wf_TableRow($cells, 'row3');
  362. $cells= wf_TableCell(__('IP'));
  363. $cells.= wf_TableCell($data['ip']);
  364. $rows.= wf_TableRow($cells, 'row3');
  365. $cells= wf_TableCell(__('MAC Lan'));
  366. $cells.= wf_TableCell($data['maclan']);
  367. $rows.= wf_TableRow($cells, 'row3');
  368. $cells= wf_TableCell(__('Date'));
  369. $cells.= wf_TableCell($data['date']);
  370. $rows.= wf_TableRow($cells, 'row3');
  371. if (isset($alluserips[$data['userbind']])) {
  372. $bindedLogin=$alluserips[$data['userbind']];
  373. $profileLink= ' '.wf_Link('?module=userprofile&username='.$bindedLogin, web_profile_icon().' '.$bindedLogin, false, '');
  374. } else {
  375. $profileLink='';
  376. }
  377. $cells= wf_TableCell(__('Linked user'));
  378. $cells.= wf_TableCell($data['userbind'].$profileLink);
  379. $rows.= wf_TableRow($cells, 'row3');
  380. $cells= wf_TableCell(__('Notes'));
  381. $cells.= wf_TableCell($data['note']);
  382. $rows.= wf_TableRow($cells, 'row3');
  383. $result.= wf_TableBody($rows, '100%', '0', '');
  384. $inputs= wf_TextInput('edituserbind', __('Linked user'), $data['userbind'], true, '40');
  385. $inputs.= wf_TextInput('editnote', __('Notes'), $data['note'], true, '40');
  386. $inputs.=wf_Submit(__('Save'));
  387. $form= wf_Form("", 'POST', $inputs, 'glamour');
  388. $result.=$form;
  389. show_window(__('Modem profile'), $result);
  390. } else {
  391. show_window(__('Error'), __('Strange exeption'));
  392. }
  393. }
  394. // ajax calls handling
  395. if (wf_CheckGet(array('ajax'))) {
  396. docsis_AjaxModemDataSource();
  397. }
  398. //ajax modem stats
  399. if (wf_CheckGet(array('ajaxsnmp'))) {
  400. docsis_ModemDiagShow($_GET['ajaxsnmp']);
  401. }
  402. //adding new modem
  403. if (wf_CheckPost(array('newmaclan'))) {
  404. docsis_ModemAdd($_POST['newmaclan']);
  405. }
  406. //deleting modem
  407. if (wf_CheckGet(array('deletemodem'))) {
  408. docsis_ModemDelete($_GET['deletemodem']);
  409. rcms_redirect("?module=docsis");
  410. }
  411. //editing modem
  412. if ( (isset($_POST['edituserbind'])) AND (isset($_POST['editnote'])) ) {
  413. $editmodemid=vf($_GET['showmodem'],3);
  414. if (!empty($editmodemid)) {
  415. $newmodemuserbind= mysql_real_escape_string($_POST['edituserbind']);
  416. $newmodemnote= mysql_real_escape_string($_POST['editnote']);
  417. simple_update_field('modems', 'userbind', $newmodemuserbind, "WHERE `id`='".$editmodemid."'");
  418. simple_update_field('modems', 'note', $newmodemnote, "WHERE `id`='".$editmodemid."'");
  419. log_register("DOCSIS MODEM EDIT BIND `".$newmodemuserbind."` [".$editmodemid."]");
  420. rcms_redirect("?module=docsis&showmodem=".$editmodemid);
  421. } else {
  422. show_window(__('Error'), __('Strange exeption'));
  423. }
  424. }
  425. //setting modem snmp community
  426. if (wf_CheckPost(array('newmodemcommunity','newsnmpwalkpath'))) {
  427. docsis_ModemSnmpSet($_POST['newmodemcommunity']);
  428. docsis_ModemSnmpWalkSet($_POST['newsnmpwalkpath']);
  429. rcms_redirect("?module=docsis");
  430. }
  431. //show controls
  432. docsis_ControlsShow();
  433. //show modems list by default
  434. if (!wf_CheckGet(array('showmodem'))) {
  435. docsis_ModemsList();
  436. } else {
  437. docsis_ModemProfileShow($_GET['showmodem']);
  438. }
  439. zb_BillingStats(true);
  440. } else {
  441. show_window(__('Error'),__('DOCSIS support is not enabled'));
  442. }
  443. }
  444. else {
  445. show_error(__('Access denied'));
  446. }
  447. ?>