switchport.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
  5. // Перегенерация SNMP-индексов
  6. if (getPOST("regensnmp") !== null) {
  7. $snmp_index = (int)getPOST("f_snmp_start", null, 1);
  8. $sSQL = "SELECT id, port FROM device_ports WHERE device_ports.device_id = ? ORDER BY id";
  9. $flist = get_records_sql($db_link, $sSQL, [$id]);
  10. LOG_DEBUG($db_link, "Recalc snmp_index for device id: $id with start $snmp_index");
  11. foreach ($flist as $row) {
  12. $snmp = $row['port'] + $snmp_index - 1;
  13. update_record($db_link, "device_ports", "id = ?", ['snmp_index' => $snmp], [$row['id']]);
  14. }
  15. header("Location: " . $_SERVER["REQUEST_URI"]);
  16. exit;
  17. }
  18. // Сохранение ОТМЕЧЕННЫХ портов
  19. if (getPOST("save") !== null) {
  20. $selected_ids = getPOST("f_id", null, []); // отмеченные чекбоксы
  21. $all_ids = getPOST("p_id", null, []); // все ID
  22. $port_names = getPOST("f_name", null, []);
  23. $snmp_indices = getPOST("f_snmp_index", null, []);
  24. if (!empty($selected_ids) && is_array($selected_ids)) {
  25. $selected_ids = array_map('intval', $selected_ids);
  26. $selected_set = array_flip($selected_ids);
  27. foreach ($all_ids as $i => $id) {
  28. $id = (int)$id;
  29. if ($id <= 0 || !isset($selected_set[$id])) continue;
  30. $new = [
  31. 'port_name' => trim($port_names[$i] ?? ''),
  32. 'snmp_index' => (int)($snmp_indices[$i] ?? 0)
  33. ];
  34. update_record($db_link, "device_ports", "id = ?", $new, [$id]);
  35. }
  36. }
  37. header("Location: " . $_SERVER["REQUEST_URI"]);
  38. exit;
  39. }
  40. unset($_POST);
  41. $device=get_record($db_link,'devices',"id=?", [$id]);
  42. $user_info = get_record_sql($db_link,"SELECT * FROM user_list WHERE id=?", [ $device['user_id'] ]);
  43. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  44. print_device_submenu($page_url);
  45. print_editdevice_submenu($page_url,$id,$device['device_type'],$user_info['login']);
  46. ?>
  47. <div id="contsubmenu">
  48. <form name="def" action="switchport.php?id=<?php echo $id; ?>" method="post">
  49. <br>
  50. <?php print "<b>".WEB_device_port_list."&nbsp".$device['device_name']." - ".$device['ip']."</b><br>\n"; ?>
  51. <table class="data" cellspacing="1" cellpadding="4">
  52. <tr>
  53. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  54. <td>id</td>
  55. <td>N</td>
  56. <td><?php echo WEB_device_port_name; ?></td>
  57. <td><?php echo WEB_device_port_snmp_index; ?></td>
  58. <td><?php echo WEB_device_connected_endpoint; ?></td>
  59. <td><?php echo WEB_cell_description; ?></td>
  60. <td><?php echo WEB_device_port_uplink; ?></td>
  61. <td><?php echo WEB_nagios; ?></td>
  62. <td><?php echo WEB_cell_skip; ?></td>
  63. <td><?php echo WEB_cell_vlan; ?></td>
  64. <td><?php echo WEB_device_snmp_port_oid_name; ?></td>
  65. <td><?php echo WEB_cell_mac_count; ?></td>
  66. </tr>
  67. <?php
  68. $sSQL = "SELECT * FROM device_ports WHERE device_ports.device_id=? ORDER BY port";
  69. $ports=get_records_sql($db_link,$sSQL, [ $id ]);
  70. foreach ($ports as $row) {
  71. print "<tr align=center>\n";
  72. $cl = "data";
  73. print "<td class='".$cl."' style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  74. print "<td class='data'><input type='hidden' name='p_id[]' value='{$row['id']}'><a href='editport.php?id=".$row['id']."'>{$row['id']}</a></td>\n";
  75. print "<td class='".$cl."' >".$row['port']."</td>\n";
  76. print "<td class='".$cl."' ><input type='text' name='f_name[]' value='{$row['port_name']}' size=5></td>\n";
  77. print "<td class='".$cl."' ><input type='text' name='f_snmp_index[]' value='{$row['snmp_index']}' size=10></td>\n";
  78. print "<td class='".$cl."'>";
  79. if (isset($row['target_port_id']) and $row['target_port_id'] > 0) {
  80. print_device_port($db_link, $row['target_port_id']);
  81. } else {
  82. print_auth_port($db_link, $row['id'],FALSE);
  83. }
  84. print "</td>\n";
  85. print "<td class='".$cl."'>" . get_port_description($db_link, $row['id'],$row['description']) . "</td>\n";
  86. print_td_yes($row['uplink'],FALSE,$cl);
  87. print_td_yes($row['nagios'],FALSE,$cl);
  88. print_td_yes($row['skip'],FALSE,$cl);
  89. $display_vlan= $row['vlan'];
  90. if (!empty($row['untagged_vlan'])) {
  91. if ($row['untagged_vlan'] != $row['vlan']) {
  92. $pattern = '/(\d+),(\d+),(\d+),(\d+),(\d+),/';
  93. $replacement = '${1},${2},${3},${4},${5}<br>U:';
  94. $display_untagged = preg_replace($pattern, $replacement, $row['untagged_vlan']);
  95. $display_vlan.=";U:".$display_untagged;
  96. }
  97. }
  98. if (!empty($row['tagged_vlan'])) {
  99. $pattern = '/(\d+),(\d+),(\d+),(\d+),(\d+),/';
  100. $replacement = '${1},${2},${3},${4},${5}<br>T:';
  101. $display_tagged = preg_replace($pattern, $replacement, $row['tagged_vlan']);
  102. $display_vlan.=";T:".$display_tagged;
  103. }
  104. $ifname= compact_port_name($row['ifName']);
  105. $f_cacti_url = get_cacti_graph($device['ip'], $row['snmp_index']);
  106. if (empty(get_const('torrus_url')) and (empty($f_cacti_url))) { $snmp_url=$ifname; }
  107. else {
  108. if (isset($f_cacti_url)) { $snmp_url = "<a href='".$f_cacti_url."'>" . $ifname . "</a>"; }
  109. if (!empty(get_const('torrus_url'))) {
  110. $normed_ifname = str_replace("/", "_", $ifname);
  111. $normed_ifname = str_replace(".", "_", $normed_ifname);
  112. $normed_ifname = trim(str_replace(" ", "_", $normed_ifname));
  113. $t_url = str_replace("HOST_IP", $device['ip'], get_const('torrus_url'));
  114. $t_url = str_replace("IF_NAME", $normed_ifname, $t_url);
  115. $snmp_url = "<a href='".$t_url."'>" . $ifname . "</a>";
  116. }
  117. }
  118. print "<td class='".$cl."'>" . $display_vlan . "</td>\n";
  119. print "<td class='".$cl."'>" . $snmp_url . "</td>\n";
  120. print "<td class='".$cl."' ><button onclick=\"". open_window_url('portmactable.php?id='.$row['id'])." return false;\">" . $row['last_mac_count'] . "</button></td>\n";
  121. print "</tr>";
  122. }
  123. print "<tr>\n";
  124. print "<td colspan=12 align=right><input type='submit' name='save' value='".WEB_btn_save."'></td>\n";
  125. print "</tr>\n";
  126. print "</table>\n";
  127. ?>
  128. <div>
  129. <?php echo WEB_device_first_port_snmp_value; ?>
  130. &nbsp
  131. <input type='text' name='f_snmp_start' value=1>
  132. <input type='submit' name='regensnmp' value='<?php echo WEB_device_recalc_snmp_port ?>'>
  133. </div>
  134. </form>
  135. <?php
  136. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.simple.php");
  137. ?>