portmactable.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. if (empty($port_info)) {
  9. header("Location: /admin/devices/editdevice.php?id=".$device_id);
  10. exit;
  11. }
  12. $device_id = $port_info["device_id"];
  13. $sSQL = "SELECT port, snmp_index FROM `device_ports` WHERE device_id=".$device_id;
  14. $ports_info = get_records_sql($db_link, $sSQL);
  15. if (empty($ports_info)) {
  16. header("Location: /admin/devices/editdevice.php?id=".$device_id);
  17. exit;
  18. }
  19. $ports_by_snmp_index=NULL;
  20. foreach ($ports_info as &$row) { $ports_by_snmp_index[$row["snmp_index"]]=$row["port"]; }
  21. $device=get_record($db_link,'devices',"id=".$device_id);
  22. if (empty($device)) {
  23. header("Location: /admin/devices/index.php");
  24. exit;
  25. }
  26. $snmp = getSnmpAccess($device);
  27. $user_info = get_record_sql($db_link,"SELECT * FROM user_list WHERE id=".$device['user_id']);
  28. if (empty($user_info)) {
  29. header("Location: /admin/devices/index.php");
  30. exit;
  31. }
  32. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  33. if (!apply_device_lock($db_link,$device_id)) {
  34. header("Location: /admin/devices/editdevice.php?id=".$device_id."&status=locked");
  35. exit;
  36. }
  37. print_device_submenu($page_url);
  38. print_editdevice_submenu($page_url,$device_id,$device['device_type'],$user_info['login']);
  39. ?>
  40. <div id="contsubmenu">
  41. <?php
  42. $display_name = " ".$port_info['port']." свича ".$port_info['device_name'];
  43. print "<b>".$port_info['device_name']." [".$port_info['port']."] </b><br>\n";
  44. $sw_auth=NULL;
  45. $sw_mac=NULL;
  46. $sw_auth = get_record_sql($db_link,"SELECT mac FROM user_auth WHERE deleted=0 and ip='".$port_info['ip']."'");
  47. if (!empty($sw_auth)) {
  48. $sw_mac = mac_simplify($sw_auth['mac']);
  49. $sw_mac = preg_replace("/.{2}$/","",$sw_mac);
  50. }
  51. $snmp_ok = 0;
  52. if (!empty($device['ip']) and $device['snmp_version'] > 0) {
  53. $snmp_ok = check_snmp_access($device['ip'], $snmp);
  54. }
  55. if ($snmp_ok and $port_info['snmp_index'] > 0) {
  56. print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
  57. print "<tr><td colspan=2><b>".WEB_device_port_mac_table_show."</b></td></tr>\n";
  58. $fdb = get_fdb_table($port_info['ip'], $snmp);
  59. $f_port = $port_info['snmp_index'];
  60. $port_by_snmp = 0;
  61. if (!empty($fdb)) {
  62. foreach ($fdb as $a_mac => $a_port) {
  63. if (!empty($ports_by_snmp_index[$a_port])) { $port_by_snmp=1; break; }
  64. }
  65. }
  66. if (!$port_by_snmp) { $f_port = $port_info['port']; }
  67. if (!empty($fdb)) {
  68. foreach ($fdb as $a_mac => $a_port) {
  69. if ($a_port == $f_port) {
  70. $a_mac = dec_to_hex($a_mac);
  71. //mikrotik patch
  72. if (!empty($sw_mac) and preg_match('/^'.$sw_mac.'/',mac_simplify($a_mac))) { continue; }
  73. print "<tr>";
  74. $auth = get_auth_by_mac($db_link, $a_mac);
  75. if (!empty($auth)) {
  76. print "<td class=\"data\">" .$auth['auth'] . "</td><td class=\"data\">". $auth['mac']."</td>\n";
  77. }
  78. print "</tr>";
  79. }
  80. }
  81. }
  82. print "</table>\n";
  83. } else { print "No SNMP access!"; }
  84. unset_lock_discovery($db_link,$device_id);
  85. ?>
  86. <table class="data">
  87. <tr>
  88. <td><?php echo WEB_cell_mac; ?></td>
  89. <td><?php echo WEB_cell_login; ?></td>
  90. <td><?php echo WEB_cell_last_found; ?></td>
  91. </tr>
  92. <?php
  93. print "<b>".WEB_device_port_mac_table_history."</b><br>\n";
  94. $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";
  95. $t_device = get_records_sql($db_link, $d_sql);
  96. if (!empty($t_device)) {
  97. foreach ($t_device as $row) {
  98. $name = $row['ip'];
  99. if (!empty($row['dns_name']) and isset($row['dns'])) { $name = $row['dns_name']; }
  100. print "<tr>";
  101. print "<td class=\"data\">" . expand_mac($db_link,$row['mac']) . "</td>\n";
  102. print "<td class=\"data\"><a href=\"/admin/users/editauth.php?id=".$row['id']."\">" . $name . "</a></td>\n";
  103. print "<td class=\"data\">".$row['last_found']."</td>\n";
  104. print "</tr>";
  105. }
  106. }
  107. $maclist = get_records_sql($db_link, "SELECT mac,timestamp from unknown_mac where port_id=$port_id order by timestamp desc");
  108. if (!empty($maclist)) {
  109. foreach ($maclist as $row) {
  110. print "<tr>";
  111. print "<td class=\"data\">" . expand_mac($db_link,$row['mac']) . "</td>\n";
  112. print "<td class=\"data\">Unknown</td>\n";
  113. print "<td class=\"data\">".$row['timestamp']."</td>\n";
  114. print "</tr>";
  115. }
  116. }
  117. print "</table>\n";
  118. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.simple.php");
  119. ?>