portmactable.php 4.2 KB

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