portmactable.php 3.7 KB

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