1
0

switchport.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. if (isset($_POST["regensnmp"])) {
  6. $snmp_index = $_POST["f_snmp_start"] * 1;
  7. $sSQL = "SELECT id,port from device_ports WHERE device_ports.device_id=$id order by id";
  8. $flist = mysqli_query($db_link, $sSQL);
  9. LOG_DEBUG($db_link, "Recalc snmp_index for device id: $id with start $snmp_index");
  10. while (list ($port_id, $port) = mysqli_fetch_array($flist)) {
  11. $snmp = $port + $snmp_index - 1;
  12. $new['snmp_index'] = $snmp;
  13. update_record($db_link, "device_ports", "id='$port_id'", $new);
  14. }
  15. header("Location: " . $_SERVER["REQUEST_URI"]);
  16. exit;
  17. }
  18. if (isset($_POST['save'])) {
  19. $saved = array();
  20. //button save
  21. $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
  22. for ($i = 0; $i < $len; $i ++) {
  23. $save_id = intval($_POST['save'][$i]);
  24. if ($save_id == 0) { continue; }
  25. array_push($saved,$save_id);
  26. }
  27. //select box
  28. $len = is_array($_POST['f_id']) ? count($_POST['f_id']) : 0;
  29. if ($len>0) {
  30. for ($i = 0; $i < $len; $i ++) {
  31. $save_id = intval($_POST['f_id'][$i]);
  32. if ($save_id == 0) { continue; }
  33. if (!in_array($save_id, $saved)) { array_push($saved,$save_id); }
  34. }
  35. }
  36. //save changes
  37. $len = is_array($saved) ? count($saved) : 0;
  38. for ($i = 0; $i < $len; $i ++) {
  39. $save_id = intval($saved[$i]);
  40. if ($save_id == 0) { continue; }
  41. $len_all = is_array($_POST['p_id']) ? count($_POST['p_id']) : 0;
  42. for ($j = 0; $j < $len_all; $j ++) {
  43. if (intval($_POST['p_id'][$j]) != $save_id) { continue; }
  44. $new['port_name'] = $_POST['f_name'][$j];
  45. $new['snmp_index'] = $_POST['f_snmp_index'][$j]*1;
  46. update_record($db_link, "device_ports", "id='{$save_id}'", $new);
  47. }
  48. }
  49. header("Location: " . $_SERVER["REQUEST_URI"]);
  50. exit;
  51. }
  52. unset($_POST);
  53. $device=get_record($db_link,'devices',"id=".$id);
  54. $user_info = get_record_sql($db_link,"SELECT * FROM User_list WHERE id=".$device['user_id']);
  55. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  56. print_device_submenu($page_url);
  57. print_editdevice_submenu($page_url,$id,$device['device_type'],$user_info['login']);
  58. ?>
  59. <div id="contsubmenu">
  60. <form name="def" action="switchport.php?id=<?php echo $id; ?>" method="post">
  61. <br>
  62. <?php print "<b>".WEB_device_port_list."&nbsp".$device['device_name']." - ".$device['ip']."</b><br>\n"; ?>
  63. <table class="data" cellspacing="1" cellpadding="4">
  64. <tr>
  65. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  66. <td>id</td>
  67. <td>N</td>
  68. <td><?php echo WEB_device_port_name; ?></td>
  69. <td><?php echo WEB_device_port_snmp_index; ?></td>
  70. <td><?php echo WEB_device_connected_endpoint; ?></td>
  71. <td><?php echo WEB_cell_comment; ?></td>
  72. <td><?php echo WEB_device_port_uplink; ?></td>
  73. <td><?php echo WEB_nagios; ?></td>
  74. <td><?php echo WEB_cell_skip; ?></td>
  75. <td><?php echo WEB_cell_vlan; ?></td>
  76. <td><?php echo WEB_device_snmp_port_oid_name; ?></td>
  77. <td><?php echo WEB_cell_mac_count; ?></td>
  78. </tr>
  79. <?php
  80. $sSQL = "SELECT * FROM device_ports WHERE device_ports.device_id=$id ORDER BY port";
  81. $ports=get_records_sql($db_link,$sSQL);
  82. foreach ($ports as $row) {
  83. print "<tr align=center>\n";
  84. $cl = "data";
  85. print "<td class='".$cl."' style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  86. 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";
  87. print "<td class='".$cl."' >".$row['port']."</td>\n";
  88. print "<td class='".$cl."' ><input type='text' name='f_name[]' value='{$row['port_name']}' size=5></td>\n";
  89. print "<td class='".$cl."' ><input type='text' name='f_snmp_index[]' value='{$row['snmp_index']}' size=10></td>\n";
  90. print "<td class='".$cl."'>";
  91. if (isset($row['target_port_id']) and $row['target_port_id'] > 0) {
  92. print_device_port($db_link, $row['target_port_id']);
  93. } else {
  94. print_auth_port($db_link, $row['id']);
  95. }
  96. print "</td>\n";
  97. print "<td class='".$cl."'>" . $row['comment'] . "</td>\n";
  98. print "<td class='".$cl."' >" . get_qa($row['uplink']) . "</td>\n";
  99. print "<td class='".$cl."' >" . get_qa($row['nagios']) . "</td>\n";
  100. print "<td class='".$cl."' >" . get_qa($row['skip']) . "</td>\n";
  101. $display_vlan= $row['vlan'];
  102. if (!empty($row['untagged_vlan'])) {
  103. if ($row['untagged_vlan'] != $row['vlan']) {
  104. $pattern = '/(\d+),(\d+),(\d+),(\d+),(\d+),/';
  105. $replacement = '${1},${2},${3},${4},${5}<br>U:';
  106. $display_untagged = preg_replace($pattern, $replacement, $row['untagged_vlan']);
  107. $display_vlan.=";U:".$display_untagged;
  108. }
  109. }
  110. if (!empty($row['tagged_vlan'])) {
  111. $pattern = '/(\d+),(\d+),(\d+),(\d+),(\d+),/';
  112. $replacement = '${1},${2},${3},${4},${5}<br>T:';
  113. $display_tagged = preg_replace($pattern, $replacement, $row['tagged_vlan']);
  114. $display_vlan.=";T:".$display_tagged;
  115. }
  116. $ifname= compact_port_name($row['ifName']);
  117. $f_cacti_url = get_cacti_graph($device['ip'], $row['snmp_index']);
  118. if (empty(get_const('torrus_url')) and (empty($f_cacti_url))) { $snmp_url=$ifname; }
  119. else {
  120. if (isset($f_cacti_url)) { $snmp_url = "<a href='".$f_cacti_url."'>" . $ifname . "</a>"; }
  121. if (!empty(get_const('torrus_url'))) {
  122. $normed_ifname = str_replace("/", "_", $ifname);
  123. $normed_ifname = str_replace(".", "_", $normed_ifname);
  124. $normed_ifname = trim(str_replace(" ", "_", $normed_ifname));
  125. $t_url = str_replace("HOST_IP", $device['ip'], get_const('torrus_url'));
  126. $t_url = str_replace("IF_NAME", $normed_ifname, $t_url);
  127. $snmp_url = "<a href='".$t_url."'>" . $ifname . "</a>";
  128. }
  129. }
  130. print "<td class='".$cl."'>" . $display_vlan . "</td>\n";
  131. print "<td class='".$cl."'>" . $snmp_url . "</td>\n";
  132. print "<td class='".$cl."' ><button name='write' class='j-submit-report' onclick='window.open('portmactable.php?id=" . $row['id'] . "')'>" . $row['last_mac_count'] . "</button></td>\n";
  133. print "</tr>";
  134. }
  135. print "<tr>\n";
  136. print "<td colspan=12 align=right><input type='submit' name='save' value='".WEB_btn_save."'></td>\n";
  137. print "</tr>\n";
  138. print "</table>\n";
  139. ?>
  140. <div>
  141. <?php echo WEB_device_first_port_snmp_value; ?>
  142. &nbsp
  143. <input type='text' name='f_snmp_start' value=1>
  144. <input type='submit' name='regensnmp' value='<?php echo WEB_device_recalc_snmp_port ?>'>
  145. </div>
  146. </form>
  147. <?php
  148. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.small.php");
  149. ?>