switchstatus.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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['poe_on']) and $device['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. $sSQL = "SELECT port from device_ports WHERE device_id=".$id." and snmp_index=".$port_index;
  24. $port = get_record_sql($db_link,$sSQL);
  25. LOG_DEBUG($db_link, "Device id: ".$id." enable poe at port ".$port['port']." snmp index ".$port_index);
  26. set_port_poe_state($device['vendor_id'], $port['port'], $port_index, $device['ip'], $device['rw_community'], $device['snmp_version'], 1);
  27. }
  28. header("Location: " . $_SERVER["REQUEST_URI"]);
  29. exit;
  30. }
  31. if (isset($_POST['poe_off']) and $device['snmp_version']>0) {
  32. $len = is_array($_POST['poe_off']) ? count($_POST['poe_off']) : 0;
  33. for ($i = 0; $i < $len; $i ++) {
  34. $port_index = intval($_POST['poe_off'][$i]);
  35. $sSQL = "SELECT port from device_ports WHERE device_id=".$id." and snmp_index=".$port_index;
  36. $port = get_record_sql($db_link,$sSQL);
  37. LOG_DEBUG($db_link, "Device id: ".$id." disable poe at port ".$port['port']." snmp index ".$port_index);
  38. set_port_poe_state($device['vendor_id'], $port['port'], $port_index, $device['ip'], $device['rw_community'], $device['snmp_version'], 0);
  39. }
  40. header("Location: " . $_SERVER["REQUEST_URI"]);
  41. exit;
  42. }
  43. if (isset($_POST['port_on']) and $device['snmp_version']>0) {
  44. $len = is_array($_POST['port_on']) ? count($_POST['port_on']) : 0;
  45. for ($i = 0; $i < $len; $i ++) {
  46. $port_index = intval($_POST['port_on'][$i]);
  47. LOG_DEBUG($db_link, "Device id: $id enable port with snmp index $port_index");
  48. set_port_state($device['vendor_id'], $port_index, $device['ip'], $device['rw_community'], $device['snmp_version'], 1);
  49. }
  50. header("Location: " . $_SERVER["REQUEST_URI"]);
  51. exit;
  52. }
  53. if (isset($_POST['port_off']) and $device['snmp_version']>0) {
  54. $len = is_array($_POST['port_off']) ? count($_POST['port_off']) : 0;
  55. for ($i = 0; $i < $len; $i ++) {
  56. $port_index = intval($_POST['port_off'][$i]);
  57. LOG_DEBUG($db_link, "Device id: $id disable port with snmp index $port_index");
  58. set_port_state($device['vendor_id'], $port_index, $device['ip'], $device['rw_community'], $device['snmp_version'], 0);
  59. }
  60. header("Location: " . $_SERVER["REQUEST_URI"]);
  61. exit;
  62. }
  63. unset($_POST);
  64. $user_info = get_record_sql($db_link,"SELECT * FROM User_list WHERE id=".$device['user_id']);
  65. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  66. print_device_submenu($page_url);
  67. print_editdevice_submenu($page_url,$id,$device['device_type'],$user_info['login']);
  68. ?>
  69. <div id="contsubmenu">
  70. <form name="def" action="switchstatus.php?id=<?php echo $id; ?>" method="post">
  71. <?php
  72. print "<br>\n";
  73. print "<b>".WEB_device_port_state_list."&nbsp".$device['device_name']." - ".$device['ip']."</b><br>\n";
  74. if ($device['snmp_version']>0) {
  75. $snmp_ok = check_snmp_access($device['ip'], $device['community'], $device['snmp_version']);
  76. $modules_oids = NULL;
  77. if ($snmp_ok) {
  78. if ($device['snmp_version'] == 2) {
  79. $modules_oids = snmp2_real_walk($device['ip'], $device['community'], CISCO_MODULES);
  80. }
  81. if ($device['snmp_version'] == 1) {
  82. $modules_oids = snmprealwalk($device['ip'], $device['community'], CISCO_MODULES);
  83. }
  84. }
  85. } else { $snmp_ok = 0; }
  86. print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
  87. print "<tr>\n";
  88. print "<td>id</td>\n";
  89. print "<td>".WEB_device_port_number."</td>\n";
  90. print "<td>".WEB_device_port_name."</td>\n";
  91. print "<td>".WEB_device_port_snmp_index."</td>\n";
  92. print "<td>".WEB_device_connected_endpoint."</td>\n";
  93. print "<td>".WEB_cell_comment."</td>\n";
  94. print "<td>".WEB_device_port_uplink."</td>\n";
  95. print "<td>".WEB_nagios."</td>\n";
  96. print "<td>".WEB_cell_skip."</td>\n";
  97. print "<td>".WEB_cell_vlan."</td>\n";
  98. print "<td>".WEB_device_snmp_port_oid_name."</td>\n";
  99. print "<td>".WEB_device_port_speed."</td>\n";
  100. print "<td>".WEB_device_port_errors."</td>\n";
  101. print "<td>".WEB_cell_mac_count."</td>\n";
  102. print "<td>".WEB_msg_additional."</td>\n";
  103. print "<td>".WEB_device_poe_control."</td>\n";
  104. print "<td>".WEB_device_port_control."</td>\n";
  105. print "</tr>\n";
  106. $sSQL = "SELECT * FROM device_ports WHERE device_ports.device_id=$id ORDER BY port";
  107. $ports=get_records_sql($db_link,$sSQL);
  108. foreach ($ports as $row) {
  109. print "<tr align=center>\n";
  110. $cl = "down";
  111. $new_info = NULL;
  112. //fix empty port names
  113. if (empty($row['port_name'])) { $row['port_name']=$row['port']; $new_info['port_name']=$row['port']; }
  114. if (isset($device['ip']) and ($device['ip'] != '') and $snmp_ok) {
  115. $port_state_detail = get_port_state_detail($row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version'], $device['fdb_snmp_index']);
  116. list ($poper, $padmin, $pspeed, $perrors) = explode(';', $port_state_detail);
  117. if ($poper == 1 ) { $cl = "up"; }
  118. if ($poper >= 2 ) {
  119. if ($padmin >=2) { $cl = "shutdown"; } else { $cl = "down"; }
  120. }
  121. }
  122. print "<td class='".$cl."' style='padding:0'><input type=checkbox name=d_port_index[] value=".$row['snmp_index']." ></td>\n";
  123. print "<td class='".$cl."'><a href=\"editport.php?id=".$row['id']."\">" . $row['port'] . "</a></td>\n";
  124. print "<td class='".$cl."' >" . $row['port_name'] . "</td>\n";
  125. print "<td class='".$cl."' >" . $row['snmp_index'] . "</td>\n";
  126. print "<td class='".$cl."'>";
  127. if (isset($row['target_port_id']) and $row['target_port_id'] > 0) {
  128. print_device_port($db_link, $row['target_port_id']);
  129. } else {
  130. print_auth_port($db_link, $row['id']);
  131. }
  132. print "</td>\n";
  133. print "<td class='".$cl."'>" . $row['comment'] . "</td>\n";
  134. print "<td class='".$cl."' >" . get_qa($row['uplink']) . "</td>\n";
  135. print "<td class='".$cl."' >" . get_qa($row['nagios']) . "</td>\n";
  136. print "<td class='".$cl."' >" . get_qa($row['skip']) . "</td>\n";
  137. $poe_info="POE:None";
  138. $vlan = $row['vlan'];
  139. $ifname= $row['ifName'];
  140. if ($snmp_ok) {
  141. $vlan = get_port_vlan($device['vendor_id'], $row['port'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version'], $device['fdb_snmp_index']);
  142. $ifname = get_snmp_ifname1($device['ip'], $device['community'], $device['snmp_version'], $row['snmp_index']);
  143. if (empty($ifname)) { $ifname = get_snmp_ifname2($device['ip'], $device['community'], $device['snmp_version'], $row['snmp_index']); }
  144. $sfp_status = get_sfp_status($device['vendor_id'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version'], $modules_oids);
  145. $poe_status = get_port_poe_state($device['vendor_id'], $row['port'],$row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);
  146. if (isset($poe_status)) {
  147. if ($poe_status == 1) {
  148. $port_poe_detail = get_port_poe_detail($device['vendor_id'], $row['port'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);
  149. if (empty($port_poe_detail)) { $poe_info = 'POE:on'; } else { $poe_info = $port_poe_detail; }
  150. }
  151. if ($poe_status == 2) { $poe_info="POE:Off"; }
  152. }
  153. if (!isset($vlan)) { $vlan = $row['vlan']; } else {
  154. if ($row['vlan']!==$vlan) { $new_info['vlan']=$vlan; }
  155. }
  156. if (!isset($row['ifName']) or $row['ifName'] !== $ifname) { $new_info['ifName']=$ifname; }
  157. }
  158. //fix port information
  159. if (!empty($new_info)) { update_record($db_link, "device_ports", "id=".$row['id'], $new_info); }
  160. $ifname=compact_port_name($ifname);
  161. $f_cacti_url = get_cacti_graph($device['ip'], $row['snmp_index']);
  162. if (empty(get_const('torrus_url')) and (empty($f_cacti_url))) { $snmp_url=$ifname; }
  163. else {
  164. if (isset($f_cacti_url)) { $snmp_url = "<a href=\"$f_cacti_url\">" . $ifname . "</a>"; }
  165. if (!empty(get_const('torrus_url'))) {
  166. $normed_ifname = str_replace("/", "_", $ifname);
  167. $normed_ifname = str_replace(".", "_", $normed_ifname);
  168. $normed_ifname = trim(str_replace(" ", "_", $normed_ifname));
  169. $t_url = str_replace("HOST_IP", $device['ip'], get_const('torrus_url'));
  170. $t_url = str_replace("IF_NAME", $normed_ifname, $t_url);
  171. $snmp_url = "<a href=\"$t_url\">" . $ifname . "</a>";
  172. }
  173. }
  174. print "<td class='".$cl."'>" . $vlan . "</td>\n";
  175. print "<td class='".$cl."'>" . $snmp_url . "</td>\n";
  176. $speed = "0";
  177. $cl_speed = $cl;
  178. if ($pspeed == 0) { $speed = ""; }
  179. if ($pspeed == 10000000) { $speed = "10M"; $cl_speed = "speed10M"; }
  180. if ($pspeed == 100000000) { $speed = "100M"; $cl_speed = "speed100M"; }
  181. if ($pspeed == 1000000000) { $speed = "1G"; $cl_speed = "speed1G"; }
  182. if ($pspeed == 10000000000) { $speed = "10G"; $cl_speed = "speed10G"; }
  183. if ($pspeed == 4294967295) { $speed = "10G"; $cl_speed = "speed10G"; }
  184. if ($pspeed == 10) { $speed = "10G"; $cl_speed = "speed10G"; }
  185. print "<td class=\"$cl_speed\">" . $speed . "</td>\n";
  186. $cl_error = $cl;
  187. if ($perrors > 0) { $cl_error = "crc"; }
  188. print "<td class=\"$cl_error\">" . $perrors . "</td>\n";
  189. 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";
  190. print "<td class='".$cl."'>" . $sfp_status. " ". $poe_info."</td>\n";
  191. if (isset($poe_status) and ! $row['skip'] and ! $device['is_router']) {
  192. print "<td class=\"data\">";
  193. if ($device['vendor_id'] != 9) {
  194. if ($poe_status == 2) {
  195. print "<button name='poe_on[]' value='{$row['snmp_index']}'>".WEB_device_poe_on."</button>";
  196. }
  197. if ($poe_status == 1) {
  198. print "<button name='poe_off[]' value='{$row['snmp_index']}'>".WEB_device_poe_off."</button>";
  199. }
  200. } else {
  201. print WEB_msg_unsupported;
  202. }
  203. print "</td>\n";
  204. } else {
  205. print "<td>".WEB_msg_unsupported."</td>\n";
  206. }
  207. if (isset($padmin) and ! $row['uplink'] and ! $row['skip'] and ! $device['is_router']) {
  208. print "<td class=\"data\">";
  209. if ($device['vendor_id'] != 9) {
  210. if ($padmin >=2) {
  211. print "<button name='port_on[]' value='{$row['snmp_index']}'>".WEB_device_port_on."</button>";
  212. }
  213. if ($padmin ==1) {
  214. print "<button name='port_off[]' value='{$row['snmp_index']}'>".WEB_device_port_off."</button>";
  215. }
  216. } else {
  217. print WEB_msg_unsupported;
  218. }
  219. print "</td>\n";
  220. }
  221. print "</tr>";
  222. }
  223. print "<tr>\n";
  224. print "</table>\n";
  225. ?>
  226. <div>
  227. <?php echo WEB_device_first_port_snmp_value; ?>
  228. &nbsp
  229. <input type='text' name='f_snmp_start' value=1>
  230. <input type='submit' name='regensnmp' value='<?php echo WEB_device_recalc_snmp_port ?>'>
  231. </div>
  232. <?php
  233. print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
  234. print "<tr><td>".WEB_port_status."</td></tr>\n";
  235. print "<tr><td class=\"down\">".WEB_port_oper_down."</td>";
  236. print "<td class=\"up\">".WEB_port_oper_up."</td>";
  237. print "<td class=\"shutdown\">".WEB_port_admin_shutdown."</td><tr>\n";
  238. print "</table>\n";
  239. print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
  240. print "<tr><td>".WEB_port_speed."</td></tr>\n";
  241. print "<tr><td class=\"speed10M\">".WEB_port_speed_10."</td><td class=\"speed100M\">".WEB_port_speed_100."</td><td class=\"speed1G\">".WEB_port_speed_1G."</td><td class=\"speed10G\">".WEB_port_speed_10G."</td><tr>\n";
  242. print "</table>\n";
  243. print "</form>";
  244. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.small.php");
  245. ?>