1
0

switchport.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".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. }
  17. if (isset($_POST['save'])) {
  18. $saved = array();
  19. //button save
  20. $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
  21. for ($i = 0; $i < $len; $i ++) {
  22. $save_id = intval($_POST['save'][$i]);
  23. if ($save_id == 0) { continue; }
  24. array_push($saved,$save_id);
  25. }
  26. //select box
  27. $len = is_array($_POST['f_id']) ? count($_POST['f_id']) : 0;
  28. if ($len>0) {
  29. for ($i = 0; $i < $len; $i ++) {
  30. $save_id = intval($_POST['f_id'][$i]);
  31. if ($save_id == 0) { continue; }
  32. if (!in_array($save_id, $saved)) { array_push($saved,$save_id); }
  33. }
  34. }
  35. //save changes
  36. $len = is_array($saved) ? count($saved) : 0;
  37. for ($i = 0; $i < $len; $i ++) {
  38. $save_id = intval($saved[$i]);
  39. if ($save_id == 0) { continue; }
  40. $len_all = is_array($_POST['p_id']) ? count($_POST['p_id']) : 0;
  41. for ($j = 0; $j < $len_all; $j ++) {
  42. if (intval($_POST['p_id'][$j]) != $save_id) { continue; }
  43. $new['port_name'] = $_POST['f_name'][$j];
  44. $new['snmp_index'] = $_POST['f_snmp_index'][$j]*1;
  45. update_record($db_link, "device_ports", "id='{$save_id}'", $new);
  46. }
  47. }
  48. header("Location: " . $_SERVER["REQUEST_URI"]);
  49. }
  50. $switch=get_record($db_link,'devices',"id=".$id);
  51. unset($_POST);
  52. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  53. print_editdevice_submenu($page_url,$id);
  54. ?>
  55. <div id="cont">
  56. <form name="def" action="switchport.php?id=<? echo $id; ?>" method="post">
  57. <br>
  58. <?php print "<b>Список портов ".$switch['device_name']." - ".$switch['ip']."</b><br>\n"; ?>
  59. <table class="data" cellspacing="1" cellpadding="4">
  60. <tr>
  61. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  62. <td>id</td>
  63. <td>N</td>
  64. <td>Порт</td>
  65. <td>snmp index</td>
  66. <td>Юзер|Device</td>
  67. <td>Комментарий</td>
  68. <td>Uplink</td>
  69. <td>Nagios</td>
  70. <td>Skip</td>
  71. <td>Vlan</td>
  72. <td>ifName</td>
  73. <td>Mac count</td>
  74. </tr>
  75. <?php
  76. $sSQL = "SELECT * FROM device_ports WHERE device_ports.device_id=$id ORDER BY port";
  77. $ports=get_records_sql($db_link,$sSQL);
  78. foreach ($ports as $row) {
  79. print "<tr align=center>\n";
  80. $cl = "data";
  81. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  82. 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";
  83. print "<td class=\"$cl\" >".$row['port']."</td>\n";
  84. print "<td class=\"$cl\" ><input type=\"text\" name='f_name[]' value='{$row['port_name']}' size=5></td>\n";
  85. print "<td class=\"$cl\" ><input type=\"text\" name='f_snmp_index[]' value='{$row['snmp_index']}' size=10></td>\n";
  86. print "<td class=\"$cl\">";
  87. if (isset($row['target_port_id']) and $row['target_port_id'] > 0) {
  88. print_device_port($db_link, $row['target_port_id']);
  89. } else {
  90. print_auth_port($db_link, $row['id']);
  91. }
  92. print "</td>\n";
  93. print "<td class=\"$cl\">" . $row['comment'] . "</td>\n";
  94. print "<td class=\"$cl\" >" . get_qa($row['uplink']) . "</td>\n";
  95. print "<td class=\"$cl\" >" . get_qa($row['nagios']) . "</td>\n";
  96. print "<td class=\"$cl\" >" . get_qa($row['skip']) . "</td>\n";
  97. $vlan = $row['vlan'];
  98. $ifname= compact_port_name($row['ifName']);
  99. global $torrus_url;
  100. $f_cacti_url = get_cacti_graph($switch['ip'], $row['snmp_index']);
  101. if (! isset($torrus_url) and (! isset($f_cacti_url))) { $snmp_url=$ifname; }
  102. else {
  103. if (isset($f_cacti_url)) { $snmp_url = "<a href=\"$f_cacti_url\">" . $ifname . "</a>"; }
  104. if (isset($torrus_url)) {
  105. $normed_ifname = str_replace("/", "_", $ifname);
  106. $normed_ifname = str_replace(".", "_", $normed_ifname);
  107. $normed_ifname = trim(str_replace(" ", "_", $normed_ifname));
  108. $t_url = str_replace("HOST_IP", $switch['ip'], $torrus_url);
  109. $t_url = str_replace("IF_NAME", $normed_ifname, $t_url);
  110. $snmp_url = "<a href=\"$t_url\">" . $ifname . "</a>";
  111. }
  112. }
  113. print "<td class=\"$cl\">" . $vlan . "</td>\n";
  114. print "<td class=\"$cl\">" . $snmp_url . "</td>\n";
  115. 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";
  116. print "</tr>";
  117. }
  118. print "<tr>\n";
  119. print "<td colspan=6>snmp start</td>\n";
  120. print "<td class=\"data\"><input type=\"text\" name='f_snmp_start' value=1></td>\n";
  121. print "<td><input type=\"submit\" name=\"regensnmp\" value=\"Обновить snmp\"></td>\n";
  122. print "<td colspan=5 align=right><input type=\"submit\" name=\"save\" value=\"Сохранить\"></td>\n";
  123. print "</tr>\n";
  124. print "</table>\n";
  125. ?>
  126. </form>
  127. <?
  128. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.small.php");
  129. ?>