1
0

portmactable.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. $port_id = $id;
  6. $sSQL = "SELECT DP.device_id, DP.port, DP.snmp_index, D.device_name, D.ip, D.snmp_version, D.community, D.vendor_id FROM `device_ports` AS DP, devices AS D WHERE D.id = DP.device_id AND DP.id=$port_id";
  7. $port_info = get_record_sql($db_link, $sSQL);
  8. $device_id = $port_info["device_id"];
  9. $sSQL = "SELECT port, snmp_index FROM `device_ports` WHERE device_id=".$device_id;
  10. $ports_info = get_records_sql($db_link, $sSQL);
  11. $ports_by_snmp_index=NULL;
  12. foreach ($ports_info as &$row) { $ports_by_snmp_index[$row["snmp_index"]]=$row["port"]; }
  13. $device=get_record($db_link,'devices',"id=".$device_id);
  14. $user_info = get_record_sql($db_link,"SELECT * FROM User_list WHERE id=".$device['user_id']);
  15. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  16. if (!apply_device_lock($db_link,$device_id)) {
  17. header("Location: /admin/devices/editdevice.php?id=".$device_id."&status=locked");
  18. exit;
  19. }
  20. print_device_submenu($page_url);
  21. print_editdevice_submenu($page_url,$device_id,$device['device_type'],$user_info['login']);
  22. ?>
  23. <div id="contsubmenu">
  24. <?php
  25. $display_name = " ".$port_info['port']." свича ".$port_info['device_name'];
  26. print "<b>".$port_info['device_name']." [".$port_info['port']."] </b><br>\n";
  27. $sw_auth=NULL;
  28. $sw_mac=NULL;
  29. if ($port_info['vendor_id'] == 9) {
  30. $sw_auth = get_record_sql($db_link,"SELECT mac FROM User_auth WHERE deleted=0 and ip='".$port_info['ip']."'");
  31. $sw_mac = mac_simplify($sw_auth['mac']);
  32. $sw_mac = preg_replace("/.{2}$/","",$sw_mac);
  33. }
  34. $snmp_ok = 0;
  35. if (!empty($device['ip']) and $device['snmp_version'] > 0) {
  36. $snmp_ok = check_snmp_access($device['ip'], $device['community'], $device['snmp_version']);
  37. }
  38. if ($snmp_ok and $port_info['snmp_index'] > 0) {
  39. print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
  40. print "<tr><td colspan=2><b>".WEB_device_port_mac_table_show."</b></td></tr>\n";
  41. $fdb = get_fdb_table($port_info['ip'], $port_info['community'], $port_info['snmp_version']);
  42. $f_port = $port_info['snmp_index'];
  43. $port_by_snmp = 0;
  44. foreach ($fdb as $a_mac => $a_port) {
  45. if (!empty($ports_by_snmp_index[$a_port])) { $port_by_snmp=1; break; }
  46. }
  47. if (!$port_by_snmp) { $f_port = $port_info['port']; }
  48. foreach ($fdb as $a_mac => $a_port) {
  49. if ($a_port == $f_port) {
  50. $a_mac = dec_to_hex($a_mac);
  51. //mikrotik patch
  52. if (!empty($sw_mac) and preg_match('/^'.$sw_mac.'/',mac_simplify($a_mac))) { continue; }
  53. print "<tr>";
  54. $auth = get_auth_by_mac($db_link, $a_mac);
  55. print "<td class=\"data\">" .$auth['auth'] . "</td><td class=\"data\">". $auth['mac']."</td>\n";
  56. print "</tr>";
  57. }
  58. }
  59. print "</table>\n";
  60. } else { print "No SNMP access!"; }
  61. unset_lock_discovery($db_link,$device_id);
  62. ?>
  63. <table class="data">
  64. <tr>
  65. <td><?php echo WEB_cell_mac; ?></td>
  66. <td><?php echo WEB_cell_login; ?></td>
  67. <td><?php echo WEB_cell_last_found; ?></td>
  68. </tr>
  69. <?php
  70. print "<b>".WEB_device_port_mac_table_history."</b><br>\n";
  71. $d_sql = "select A.ip,A.ip_int,A.mac,A.id,A.dns_name,A.last_found from User_auth as A, connections as C where C.port_id=$port_id and A.id=C.auth_id order by A.ip_int";
  72. $t_device = mysqli_query($db_link, $d_sql);
  73. while (list ($f_ip, $f_int, $f_mac, $f_auth_id, $f_dns, $f_last) = mysqli_fetch_array($t_device)) {
  74. $name = $f_ip;
  75. if (isset($f_dns) and $f_dns != '') {
  76. $name = $f_dns;
  77. }
  78. print "<tr>";
  79. print "<td class=\"data\">" . expand_mac($db_link,$f_mac) . "</td>\n";
  80. print "<td class=\"data\"><a href=\"/admin/users/editauth.php?id=$f_auth_id\">" . $name . "</a></td>\n";
  81. print "<td class=\"data\">$f_last</td>\n";
  82. print "</tr>";
  83. }
  84. $maclist = mysqli_query($db_link, "SELECT mac,timestamp from Unknown_mac where port_id=$port_id order by timestamp desc");
  85. while (list ($fmac, $f_last) = mysqli_fetch_array($maclist)) {
  86. print "<tr>";
  87. print "<td class=\"data\">" . expand_mac($db_link,$fmac) . "</td>\n";
  88. print "<td class=\"data\">Unknown</td>\n";
  89. print "<td class=\"data\">$f_last</td>\n";
  90. print "</tr>";
  91. }
  92. print "</table>\n";
  93. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.small.php");
  94. ?>