switchstatus.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. $switch=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['poe_on']) and $switch['snmp_version']>0) {
  20. $len = is_array($_POST['poe_on']) ? count($_POST['poe_on']) : 0;
  21. for ($i = 0; $i < $len; $i ++) {
  22. $port_index = intval($_POST['poe_on'][$i]);
  23. LOG_DEBUG($db_link, "Device id: $id enable poe at port snmp index $port_index");
  24. set_port_poe_state($switch['vendor_id'], $port_index, $switch['ip'], $switch['rw_community'], $switch['snmp_version'], 1);
  25. }
  26. header("Location: " . $_SERVER["REQUEST_URI"]);
  27. exit;
  28. }
  29. if (isset($_POST['poe_off']) and $switch['snmp_version']>0) {
  30. $len = is_array($_POST['poe_off']) ? count($_POST['poe_off']) : 0;
  31. for ($i = 0; $i < $len; $i ++) {
  32. $port_index = intval($_POST['poe_off'][$i]);
  33. LOG_DEBUG($db_link, "Device id: $id disable poe at port snmp index $port_index");
  34. set_port_poe_state($switch['vendor_id'], $port_index, $switch['ip'], $switch['rw_community'], $switch['snmp_version'], 0);
  35. }
  36. header("Location: " . $_SERVER["REQUEST_URI"]);
  37. exit;
  38. }
  39. if (isset($_POST['port_on']) and $switch['snmp_version']>0) {
  40. $len = is_array($_POST['port_on']) ? count($_POST['port_on']) : 0;
  41. for ($i = 0; $i < $len; $i ++) {
  42. $port_index = intval($_POST['port_on'][$i]);
  43. LOG_DEBUG($db_link, "Device id: $id enable port with snmp index $port_index");
  44. set_port_state($switch['vendor_id'], $port_index, $switch['ip'], $switch['rw_community'], $switch['snmp_version'], 1);
  45. }
  46. header("Location: " . $_SERVER["REQUEST_URI"]);
  47. exit;
  48. }
  49. if (isset($_POST['port_off']) and $switch['snmp_version']>0) {
  50. $len = is_array($_POST['port_off']) ? count($_POST['port_off']) : 0;
  51. for ($i = 0; $i < $len; $i ++) {
  52. $port_index = intval($_POST['port_off'][$i]);
  53. LOG_DEBUG($db_link, "Device id: $id disable port with snmp index $port_index");
  54. set_port_state($switch['vendor_id'], $port_index, $switch['ip'], $switch['rw_community'], $switch['snmp_version'], 0);
  55. }
  56. header("Location: " . $_SERVER["REQUEST_URI"]);
  57. exit;
  58. }
  59. unset($_POST);
  60. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  61. print_editdevice_submenu($page_url,$id,$device['device_type']);
  62. ?>
  63. <div id="cont">
  64. <form name="def" action="switchstatus.php?id=<?php echo $id; ?>" method="post">
  65. <?php
  66. print "<br>\n";
  67. print "<b>Состояние портов ".$switch['device_name']." - ".$switch['ip']."</b><br>\n";
  68. if ($switch['snmp_version']>0) {
  69. $snmp_ok = check_snmp_access($switch['ip'], $switch['community'], $switch['snmp_version']);
  70. $modules_oids = NULL;
  71. if ($snmp_ok) {
  72. global $cisco_modules;
  73. if ($switch['snmp_version'] == 2) {
  74. $modules_oids = snmp2_real_walk($switch['ip'], $switch['community'], $cisco_modules);
  75. }
  76. if ($switch['snmp_version'] == 1) {
  77. $modules_oids = snmprealwalk($switch['ip'], $switch['community'], $cisco_modules);
  78. }
  79. }
  80. } else { $snmp_ok = 0; }
  81. print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
  82. print "<tr>\n";
  83. print "<td>id</td>\n";
  84. print "<td>N</td>\n";
  85. print "<td>Порт</td>\n";
  86. print "<td>snmp</td>\n";
  87. print "<td>Юзер|Device</td>\n";
  88. print "<td>Комментарий</td>\n";
  89. print "<td>Uplink</td>\n";
  90. print "<td>Nagios</td>\n";
  91. print "<td>Skip</td>\n";
  92. print "<td>Vlan</td>\n";
  93. print "<td>IfName</td>\n";
  94. print "<td>Speed</td>\n";
  95. print "<td>Errors</td>\n";
  96. print "<td>Mac count</td>\n";
  97. print "<td>Additional</td>\n";
  98. print "<td>POE Control</td>\n";
  99. print "<td>Port Control</td>\n";
  100. print "</tr>\n";
  101. $sSQL = "SELECT * FROM device_ports WHERE device_ports.device_id=$id ORDER BY port";
  102. $ports=get_records_sql($db_link,$sSQL);
  103. foreach ($ports as $row) {
  104. print "<tr align=center>\n";
  105. $cl = "down";
  106. $new_info = NULL;
  107. //fix empty port names
  108. if (empty($row['port_name'])) { $row['port_name']=$row['port']; $new_info['port_name']=$row['port']; }
  109. if (isset($switch['ip']) and ($switch['ip'] != '') and $snmp_ok) {
  110. $port_state_detail = get_port_state_detail($row['snmp_index'], $switch['ip'], $switch['community'], $switch['snmp_version'], $switch['fdb_snmp_index']);
  111. list ($poper, $padmin, $pspeed, $perrors) = explode(';', $port_state_detail);
  112. if ($poper == 1 ) { $cl = "up"; }
  113. if ($poper >= 2 ) {
  114. if ($padmin >=2) { $cl = "shutdown"; } else { $cl = "down"; }
  115. }
  116. }
  117. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=d_port_index[] value=".$row['snmp_index']." ></td>\n";
  118. print "<td class=\"$cl\"><a href=\"editport.php?id=".$row['id']."\">" . $row['port'] . "</a></td>\n";
  119. print "<td class=\"$cl\" >" . $row['port_name'] . "</td>\n";
  120. print "<td class=\"$cl\" >" . $row['snmp_index'] . "</td>\n";
  121. print "<td class=\"$cl\">";
  122. if (isset($row['target_port_id']) and $row['target_port_id'] > 0) {
  123. print_device_port($db_link, $row['target_port_id']);
  124. } else {
  125. print_auth_port($db_link, $row['id']);
  126. }
  127. print "</td>\n";
  128. print "<td class=\"$cl\">" . $row['comment'] . "</td>\n";
  129. print "<td class=\"$cl\" >" . get_qa($row['uplink']) . "</td>\n";
  130. print "<td class=\"$cl\" >" . get_qa($row['nagios']) . "</td>\n";
  131. print "<td class=\"$cl\" >" . get_qa($row['skip']) . "</td>\n";
  132. $poe_info="POE:None";
  133. $vlan = $row['vlan'];
  134. $ifname= $row['ifName'];
  135. if ($snmp_ok) {
  136. $vlan = get_port_vlan($row['port'], $row['snmp_index'], $switch['ip'], $switch['community'], $switch['snmp_version'], $switch['fdb_snmp_index']);
  137. $ifname = get_snmp_ifname1($switch['ip'], $switch['community'], $switch['snmp_version'], $row['snmp_index']);
  138. if (empty($ifname)) { $ifname = get_snmp_ifname2($switch['ip'], $switch['community'], $switch['snmp_version'], $row['snmp_index']); }
  139. $sfp_status = get_sfp_status($switch['vendor_id'], $row['snmp_index'], $switch['ip'], $switch['community'], $switch['snmp_version'], $modules_oids);
  140. $poe_status = get_port_poe_state($switch['vendor_id'], $row['snmp_index'], $switch['ip'], $switch['community'], $switch['snmp_version']);
  141. if (isset($poe_status)) {
  142. if ($poe_status == 1) {
  143. $port_poe_detail = get_port_poe_detail($switch['vendor_id'], $row['snmp_index'], $switch['ip'], $switch['community'], $switch['snmp_version']);
  144. $poe_info="POE:On " . $port_poe_detail;
  145. }
  146. if ($poe_status == 2) { $poe_info="POE:Off"; }
  147. }
  148. if (!isset($vlan)) { $vlan = $row['vlan']; } else {
  149. if ($row['vlan']!==$vlan) { $new_info['vlan']=$vlan; }
  150. }
  151. if (!isset($row['ifName']) or $row['ifName'] !== $ifname) { $new_info['ifName']=$ifname; }
  152. }
  153. //fix port information
  154. if (!empty($new_info)) { update_record($db_link, "device_ports", "id=".$row['id'], $new_info); }
  155. $ifname=compact_port_name($ifname);
  156. global $torrus_url;
  157. $f_cacti_url = get_cacti_graph($switch['ip'], $row['snmp_index']);
  158. if (! isset($torrus_url) and (! isset($f_cacti_url))) { $snmp_url=$ifname; }
  159. else {
  160. if (isset($f_cacti_url)) { $snmp_url = "<a href=\"$f_cacti_url\">" . $ifname . "</a>"; }
  161. if (isset($torrus_url)) {
  162. $normed_ifname = str_replace("/", "_", $ifname);
  163. $normed_ifname = str_replace(".", "_", $normed_ifname);
  164. $normed_ifname = trim(str_replace(" ", "_", $normed_ifname));
  165. $t_url = str_replace("HOST_IP", $switch['ip'], $torrus_url);
  166. $t_url = str_replace("IF_NAME", $normed_ifname, $t_url);
  167. $snmp_url = "<a href=\"$t_url\">" . $ifname . "</a>";
  168. }
  169. }
  170. print "<td class=\"$cl\">" . $vlan . "</td>\n";
  171. print "<td class=\"$cl\">" . $snmp_url . "</td>\n";
  172. $speed = "0";
  173. $cl_speed = $cl;
  174. if ($pspeed == 0) { $speed = ""; }
  175. if ($pspeed == 10000000) { $speed = "10M"; $cl_speed = "speed10M"; }
  176. if ($pspeed == 100000000) { $speed = "100M"; $cl_speed = "speed100M"; }
  177. if ($pspeed == 1000000000) { $speed = "1G"; $cl_speed = "speed1G"; }
  178. if ($pspeed == 10000000000) { $speed = "10G"; $cl_speed = "speed10G"; }
  179. if ($pspeed == 4294967295) { $speed = "10G"; $cl_speed = "speed10G"; }
  180. if ($pspeed == 10) { $speed = "10G"; $cl_speed = "speed10G"; }
  181. print "<td class=\"$cl_speed\">" . $speed . "</td>\n";
  182. $cl_error = $cl;
  183. if ($perrors > 0) { $cl_error = "crc"; }
  184. print "<td class=\"$cl_error\">" . $perrors . "</td>\n";
  185. 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";
  186. print "<td class=\"$cl\">" . $sfp_status. " ". $poe_info."</td>\n";
  187. if (isset($poe_status) and ! $row['skip'] and ! $switch['is_router']) {
  188. print "<td class=\"data\">";
  189. if ($switch['vendor_id'] != 9) {
  190. if ($poe_status == 2) {
  191. print "<button name='poe_on[]' value='{$row['snmp_index']}'>POE On</button>";
  192. }
  193. if ($poe_status == 1) {
  194. print "<button name='poe_off[]' value='{$row['snmp_index']}'>POE Off</button>";
  195. }
  196. } else {
  197. print "Not supported";
  198. }
  199. print "</td>\n";
  200. } else {
  201. print "<td>Not supported</td>\n";
  202. }
  203. if (isset($padmin) and ! $row['uplink'] and ! $row['skip'] and ! $switch['is_router']) {
  204. print "<td class=\"data\">";
  205. if ($switch['vendor_id'] != 9) {
  206. if ($padmin >=2) {
  207. print "<button name='port_on[]' value='{$row['snmp_index']}'>Enable port</button>";
  208. }
  209. if ($padmin ==1) {
  210. print "<button name='port_off[]' value='{$row['snmp_index']}'>Shutdown port</button>";
  211. }
  212. } else {
  213. print "Not supported";
  214. }
  215. print "</td>\n";
  216. }
  217. print "</tr>";
  218. }
  219. print "<tr>\n";
  220. print "<td colspan=10>snmp start &nbsp<input type=\"text\" name='f_snmp_start' value=1></td>\n";
  221. print "<td><input type=\"submit\" name=\"regensnmp\" value=\"Обновить snmp\"></td>\n";
  222. print "</tr>\n";
  223. print "</table>\n";
  224. print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
  225. print "<tr><td>Port status</td></tr>\n";
  226. print "<tr><td class=\"down\">Oper down</td><td class=\"up\">Oper up</td><td class=\"shutdown\">Admin shutdown</td><tr>\n";
  227. print "</table>\n";
  228. print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
  229. print "<tr><td>Port speed</td></tr>\n";
  230. print "<tr><td class=\"speed10M\">10M</td><td class=\"speed100M\">100M</td><td class=\"speed1G\">1G</td><td class=\"speed10G\">10G</td><tr>\n";
  231. print "</table>\n";
  232. print "</form>";
  233. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.small.php");
  234. ?>