1
0

switchstatus.php 12 KB

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