switchstatus.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. $snmp_ok = 0;
  75. if (!empty($device['ip']) and $device['snmp_version'] > 0) {
  76. $snmp_ok = check_snmp_access($device['ip'], $device['community'], $device['snmp_version']);
  77. $modules_oids = NULL;
  78. if ($snmp_ok) {
  79. if ($device['snmp_version'] == 2) {
  80. $modules_oids = snmp2_real_walk($device['ip'], $device['community'], CISCO_MODULES, SNMP_timeout, SNMP_retry);
  81. }
  82. if ($device['snmp_version'] == 1) {
  83. $modules_oids = snmprealwalk($device['ip'], $device['community'], CISCO_MODULES, SNMP_timeout, SNMP_retry);
  84. }
  85. }
  86. } else {
  87. $snmp_ok = 0;
  88. }
  89. print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
  90. print "<tr>\n";
  91. print "<td>id</td>\n";
  92. print "<td>" . WEB_device_port_number . "</td>\n";
  93. print "<td>" . WEB_device_port_name . "</td>\n";
  94. print "<td>" . WEB_device_port_snmp_index . "</td>\n";
  95. print "<td>" . WEB_device_connected_endpoint . "</td>\n";
  96. print "<td>" . WEB_cell_comment . "</td>\n";
  97. print "<td>" . WEB_device_port_uplink . "</td>\n";
  98. print "<td>" . WEB_nagios . "</td>\n";
  99. print "<td>" . WEB_cell_skip . "</td>\n";
  100. print "<td>" . WEB_cell_vlan . "</td>\n";
  101. print "<td>" . WEB_device_snmp_port_oid_name . "</td>\n";
  102. print "<td>" . WEB_device_port_speed . "</td>\n";
  103. print "<td>" . WEB_device_port_errors . "</td>\n";
  104. print "<td>" . WEB_cell_mac_count . "</td>\n";
  105. print "<td>" . WEB_msg_additional . "</td>\n";
  106. print "<td>" . WEB_device_poe_control . "</td>\n";
  107. print "<td>" . WEB_device_port_control . "</td>\n";
  108. print "</tr>\n";
  109. $sSQL = "SELECT * FROM device_ports WHERE device_ports.device_id=$id ORDER BY port";
  110. $ports = get_records_sql($db_link, $sSQL);
  111. foreach ($ports as $row) {
  112. print "<tr align=center>\n";
  113. $cl = "down";
  114. $new_info = NULL;
  115. //fix empty port names
  116. if (empty($row['port_name'])) {
  117. $row['port_name'] = $row['port'];
  118. $new_info['port_name'] = $row['port'];
  119. }
  120. if ($snmp_ok) {
  121. $port_state_detail = get_port_state_detail($row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);
  122. list($poper, $padmin, $pspeed, $perrors) = explode(';', $port_state_detail);
  123. if ($poper == 1) {
  124. $cl = "up";
  125. }
  126. if ($poper >= 2) {
  127. if ($padmin >= 2) {
  128. $cl = "shutdown";
  129. } else {
  130. $cl = "down";
  131. }
  132. }
  133. }
  134. print "<td class='" . $cl . "' style='padding:0'><input type=checkbox name=d_port_index[] value=" . $row['snmp_index'] . " ></td>\n";
  135. print "<td class='" . $cl . "'><a href=\"editport.php?id=" . $row['id'] . "\">" . $row['port'] . "</a></td>\n";
  136. print "<td class='" . $cl . "' >" . $row['port_name'] . "</td>\n";
  137. print "<td class='" . $cl . "' >" . $row['snmp_index'] . "</td>\n";
  138. print "<td class='" . $cl . "'>";
  139. if (isset($row['target_port_id']) and $row['target_port_id'] > 0) {
  140. print_device_port($db_link, $row['target_port_id']);
  141. } else {
  142. print_auth_port($db_link, $row['id']);
  143. }
  144. print "</td>\n";
  145. print "<td class='" . $cl . "'>" . $row['comment'] . "</td>\n";
  146. print "<td class='" . $cl . "' >" . get_qa($row['uplink']) . "</td>\n";
  147. print "<td class='" . $cl . "' >" . get_qa($row['nagios']) . "</td>\n";
  148. print "<td class='" . $cl . "' >" . get_qa($row['skip']) . "</td>\n";
  149. $poe_info = "POE:None";
  150. $vlan = $row['vlan'];
  151. $ifname = $row['ifName'];
  152. if ($snmp_ok) {
  153. $vlan = get_port_vlan($device['vendor_id'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);
  154. $ifname = get_snmp_ifname1($device['ip'], $device['community'], $device['snmp_version'], $row['snmp_index']);
  155. if (empty($ifname)) {
  156. $ifname = get_snmp_ifname2($device['ip'], $device['community'], $device['snmp_version'], $row['snmp_index']);
  157. }
  158. $sfp_status = get_sfp_status($device['vendor_id'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version'], $modules_oids);
  159. $poe_status = get_port_poe_state($device['vendor_id'], $row['port'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);
  160. if (isset($poe_status)) {
  161. if ($poe_status == 1) {
  162. $port_poe_detail = get_port_poe_detail($device['vendor_id'], $row['port'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);
  163. if (empty($port_poe_detail)) {
  164. $poe_info = 'POE:on';
  165. } else {
  166. $poe_info = $port_poe_detail;
  167. }
  168. }
  169. if ($poe_status == 2) {
  170. $poe_info = "POE:Off";
  171. }
  172. }
  173. if (empty($vlan)) {
  174. $vlan = $row['vlan'];
  175. } else {
  176. if ($vlan >= 1 and $row['vlan'] !== $vlan) {
  177. $new_info['vlan'] = $vlan;
  178. }
  179. }
  180. if (!isset($row['ifName']) or $row['ifName'] !== $ifname) {
  181. $new_info['ifName'] = $ifname;
  182. }
  183. }
  184. //fix port information
  185. if (!empty($new_info)) {
  186. update_record($db_link, "device_ports", "id=" . $row['id'], $new_info);
  187. }
  188. $ifname = compact_port_name($ifname);
  189. $f_cacti_url = get_cacti_graph($device['ip'], $row['snmp_index']);
  190. if (empty(get_const('torrus_url')) and (empty($f_cacti_url))) {
  191. $snmp_url = $ifname;
  192. } else {
  193. if (isset($f_cacti_url)) {
  194. $snmp_url = "<a href=\"$f_cacti_url\">" . $ifname . "</a>";
  195. }
  196. if (!empty(get_const('torrus_url'))) {
  197. $normed_ifname = str_replace("/", "_", $ifname);
  198. $normed_ifname = str_replace(".", "_", $normed_ifname);
  199. $normed_ifname = trim(str_replace(" ", "_", $normed_ifname));
  200. $t_url = str_replace("HOST_IP", $device['ip'], get_const('torrus_url'));
  201. $t_url = str_replace("IF_NAME", $normed_ifname, $t_url);
  202. $snmp_url = "<a href=\"$t_url\">" . $ifname . "</a>";
  203. }
  204. }
  205. print "<td class='" . $cl . "'>" . $vlan . "</td>\n";
  206. print "<td class='" . $cl . "'>" . $snmp_url . "</td>\n";
  207. $speed = "0";
  208. $cl_speed = $cl;
  209. if ($pspeed == 0) {
  210. $speed = "";
  211. }
  212. if ($pspeed == 10000000) {
  213. $speed = "10M";
  214. $cl_speed = "speed10M";
  215. }
  216. if ($pspeed == 100000000) {
  217. $speed = "100M";
  218. $cl_speed = "speed100M";
  219. }
  220. if ($pspeed == 1000000000) {
  221. $speed = "1G";
  222. $cl_speed = "speed1G";
  223. }
  224. if ($pspeed == 10000000000) {
  225. $speed = "10G";
  226. $cl_speed = "speed10G";
  227. }
  228. if ($pspeed == 4294967295) {
  229. $speed = "10G";
  230. $cl_speed = "speed10G";
  231. }
  232. if ($pspeed == 10) {
  233. $speed = "10G";
  234. $cl_speed = "speed10G";
  235. }
  236. print "<td class=\"$cl_speed\">" . $speed . "</td>\n";
  237. $cl_error = $cl;
  238. if ($perrors > 0) {
  239. $cl_error = "crc";
  240. }
  241. print "<td class=\"$cl_error\">" . $perrors . "</td>\n";
  242. 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";
  243. print "<td class='" . $cl . "'>" . $sfp_status . " " . $poe_info . "</td>\n";
  244. if (isset($poe_status) and !$row['skip'] and !$device['is_router']) {
  245. print "<td class=\"data\">";
  246. if ($device['vendor_id'] != 9) {
  247. if ($poe_status == 2) {
  248. print "<button name='poe_on[]' value='{$row['snmp_index']}'>" . WEB_device_poe_on . "</button>";
  249. }
  250. if ($poe_status == 1) {
  251. print "<button name='poe_off[]' value='{$row['snmp_index']}'>" . WEB_device_poe_off . "</button>";
  252. }
  253. } else {
  254. print WEB_msg_unsupported;
  255. }
  256. print "</td>\n";
  257. } else {
  258. print "<td>" . WEB_msg_unsupported . "</td>\n";
  259. }
  260. if (isset($padmin) and !$row['uplink'] and !$row['skip'] and !$device['is_router']) {
  261. print "<td class=\"data\">";
  262. if ($device['vendor_id'] != 9) {
  263. if ($padmin >= 2) {
  264. print "<button name='port_on[]' value='{$row['snmp_index']}'>" . WEB_device_port_on . "</button>";
  265. }
  266. if ($padmin == 1) {
  267. print "<button name='port_off[]' value='{$row['snmp_index']}'>" . WEB_device_port_off . "</button>";
  268. }
  269. } else {
  270. print WEB_msg_unsupported;
  271. }
  272. print "</td>\n";
  273. }
  274. print "</tr>";
  275. }
  276. print "<tr>\n";
  277. print "</table>\n";
  278. ?>
  279. <div>
  280. <?php echo WEB_device_first_port_snmp_value; ?>
  281. &nbsp
  282. <input type='text' name='f_snmp_start' value=1>
  283. <input type='submit' name='regensnmp' value='<?php echo WEB_device_recalc_snmp_port ?>'>
  284. </div>
  285. <?php
  286. print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
  287. print "<tr><td>" . WEB_port_status . "</td></tr>\n";
  288. print "<tr><td class=\"down\">" . WEB_port_oper_down . "</td>";
  289. print "<td class=\"up\">" . WEB_port_oper_up . "</td>";
  290. print "<td class=\"shutdown\">" . WEB_port_admin_shutdown . "</td><tr>\n";
  291. print "</table>\n";
  292. print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
  293. print "<tr><td>" . WEB_port_speed . "</td></tr>\n";
  294. 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";
  295. print "</table>\n";
  296. print "</form>";
  297. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.small.php");
  298. ?>