switchport.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. $device=get_record($db_link,'devices',"id=".$id);
  6. if (isset($_POST["regensnmp"])) {
  7. $snmp_index = $_POST["f_snmp_start"] * 1;
  8. $sSQL = "SELECT id,port from device_ports WHERE device_ports.device_id=$id order by id";
  9. $flist = mysqli_query($db_link, $sSQL);
  10. LOG_DEBUG($db_link, "Recalc snmp_index for device id: $id with start $snmp_index");
  11. while (list ($port_id, $port) = mysqli_fetch_array($flist)) {
  12. $snmp = $port + $snmp_index - 1;
  13. $new['snmp_index'] = $snmp;
  14. update_record($db_link, "device_ports", "id='$port_id'", $new);
  15. }
  16. header("Location: " . $_SERVER["REQUEST_URI"]);
  17. exit;
  18. }
  19. if (isset($_POST['save'])) {
  20. $saved = array();
  21. //button save
  22. $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
  23. for ($i = 0; $i < $len; $i ++) {
  24. $save_id = intval($_POST['save'][$i]);
  25. if ($save_id == 0) { continue; }
  26. array_push($saved,$save_id);
  27. }
  28. //select box
  29. $len = is_array($_POST['f_id']) ? count($_POST['f_id']) : 0;
  30. if ($len>0) {
  31. for ($i = 0; $i < $len; $i ++) {
  32. $save_id = intval($_POST['f_id'][$i]);
  33. if ($save_id == 0) { continue; }
  34. if (!in_array($save_id, $saved)) { array_push($saved,$save_id); }
  35. }
  36. }
  37. //save changes
  38. $len = is_array($saved) ? count($saved) : 0;
  39. for ($i = 0; $i < $len; $i ++) {
  40. $save_id = intval($saved[$i]);
  41. if ($save_id == 0) { continue; }
  42. $len_all = is_array($_POST['p_id']) ? count($_POST['p_id']) : 0;
  43. for ($j = 0; $j < $len_all; $j ++) {
  44. if (intval($_POST['p_id'][$j]) != $save_id) { continue; }
  45. $new['port_name'] = $_POST['f_name'][$j];
  46. $new['snmp_index'] = $_POST['f_snmp_index'][$j]*1;
  47. update_record($db_link, "device_ports", "id='{$save_id}'", $new);
  48. }
  49. }
  50. header("Location: " . $_SERVER["REQUEST_URI"]);
  51. exit;
  52. }
  53. unset($_POST);
  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,$device_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. $vlan = $row['vlan'];
  102. $ifname= compact_port_name($row['ifName']);
  103. $f_cacti_url = get_cacti_graph($device['ip'], $row['snmp_index']);
  104. if (empty(get_const('torrus_url')) and (empty($f_cacti_url))) { $snmp_url=$ifname; }
  105. else {
  106. if (isset($f_cacti_url)) { $snmp_url = "<a href='".$f_cacti_url."'>" . $ifname . "</a>"; }
  107. if (!empty(get_const('torrus_url'))) {
  108. $normed_ifname = str_replace("/", "_", $ifname);
  109. $normed_ifname = str_replace(".", "_", $normed_ifname);
  110. $normed_ifname = trim(str_replace(" ", "_", $normed_ifname));
  111. $t_url = str_replace("HOST_IP", $device['ip'], get_const('torrus_url'));
  112. $t_url = str_replace("IF_NAME", $normed_ifname, $t_url);
  113. $snmp_url = "<a href='".$t_url."'>" . $ifname . "</a>";
  114. }
  115. }
  116. print "<td class='".$cl."'>" . $vlan . "</td>\n";
  117. print "<td class='".$cl."'>" . $snmp_url . "</td>\n";
  118. 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";
  119. print "</tr>";
  120. }
  121. print "<tr>\n";
  122. print "<td colspan=6>".WEB_device_first_port_snmp_value."</td>\n";
  123. print "<td class='data'><input type='text' name='f_snmp_start' value=1></td>\n";
  124. print "<td><input type='submit' name='regensnmp' value='".WEB_device_recalc_snmp_port."'></td>\n";
  125. print "<td colspan=5 align=right><input type='submit' name='save' value='".WEB_btn_save."'></td>\n";
  126. print "</tr>\n";
  127. print "</table>\n";
  128. ?>
  129. </form>
  130. <?php
  131. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.small.php");
  132. ?>