switchstatus.php 17 KB

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