Explorar o código

fixed the mac-address-table poll for cisco switches

Roman Dmitriev %!s(int64=2) %!d(string=hai) anos
pai
achega
f0da4e95d6
Modificáronse 4 ficheiros con 19 adicións e 8 borrados
  1. 13 3
      html/admin/devices/portmactable.php
  2. 1 1
      html/inc/common.php
  3. 1 1
      html/inc/consts.php
  4. 4 3
      scripts/fetch_new_arp.pl

+ 13 - 3
html/admin/devices/portmactable.php

@@ -9,13 +9,18 @@ $port_info = get_record_sql($db_link, $sSQL);
 
 $device_id = $port_info["device_id"];
 
+$sSQL = "SELECT DP.port, DP.snmp_index FROM `device_ports` AS DP, devices AS D WHERE D.id = DP.device_id AND DP.device_id=".$device_id;
+$ports_info = get_records_sql($db_link, $sSQL);
+$port_by_snmp_index=NULL;
+foreach ($ports_info as &$row) { $ports_by_snmp_index[$row["snmp_index"]]=$row["port"]; }
+
 $device=get_record($db_link,'devices',"id=".$device_id);
 $user_info = get_record_sql($db_link,"SELECT * FROM User_list WHERE id=".$device['user_id']);
 
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
 
 if (!apply_device_lock($db_link,$device_id)) {
-    header("Location: /admin/devices/editdevice.php&id=".$id."&status=locked");
+    header("Location: /admin/devices/editdevice.php?id=".$device_id."&status=locked");
     exit;
 }
 
@@ -42,14 +47,19 @@ $snmp_ok = 0;
 if (!empty($device['ip']) and $device['snmp_version'] > 0) {
         $snmp_ok = check_snmp_access($device['ip'], $device['community'], $device['snmp_version']);
     }
-    
 
 if ($snmp_ok and $port_info['snmp_index'] > 0) {
     print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
     print "<tr><td colspan=2><b>".WEB_device_port_mac_table_show."</b></td></tr>\n";
     $fdb = get_fdb_table($port_info['ip'], $port_info['community'], $port_info['snmp_version']);
+    $f_port = $port_info['snmp_index'];
+    $port_by_snmp = 0;
+    foreach ($fdb as $a_mac => $a_port) {
+        if (!empty($ports_by_snmp_index[$a_port])) { $port_by_snmp=1; break; }
+    }
+    if (!$port_by_snmp) { $f_port = $port_info['port']; }
     foreach ($fdb as $a_mac => $a_port) {
-        if ($a_port == $port_info['snmp_index']) {
+        if ($a_port == $f_port) {
             $a_mac = dec_to_hex($a_mac);
             //mikrotik patch
             if (!empty($sw_mac) and preg_match('/^'.$sw_mac.'/',mac_simplify($a_mac))) { continue; }

+ 1 - 1
html/inc/common.php

@@ -2315,7 +2315,7 @@ function get_mac_table($ip, $community, $version, $oid, $index_map)
     }
 
     $mac_table = walk_snmp($ip, $community, $version, $oid);
-    if (isset($mac_table) and count($mac_table) > 0) {
+    if (isset($mac_table) and gettype($mac_table) == 'array' and count($mac_table) > 0) {
         foreach ($mac_table as $key => $value) {
             if (empty($value)) {
                 continue;

+ 1 - 1
html/inc/consts.php

@@ -52,7 +52,7 @@ define("CISCO_DESCR",".1.3.6.1.2.1.1.1.0");
 define("CISCO_MODULES",".1.3.6.1.2.1.47.1.1.1.1.7");
 define("CISCO_SFP_SENSORS",".1.3.6.1.4.1.9.9.91.1.1.1.1.4");
 define("CISCO_SFP_PRECISION",".1.3.6.1.4.1.9.9.91.1.1.1.1.3");
-define("CISCO_VLAN_OID",".1.3.6.1.4.1.9.9.9.46.1.3.1.1.2");
+define("CISCO_VLAN_OID",".1.3.6.1.4.1.9.9.46.1.3.1.1.2");
 
 define("HUAWEI_SFP_VENDOR",".1.3.6.1.4.1.2011.5.25.31.1.1.2.1.11");
 define("HUAWEI_SFP_SPEED",".1.3.6.1.4.1.2011.5.25.31.1.1.2.1.2");

+ 4 - 3
scripts/fetch_new_arp.pl

@@ -290,9 +290,10 @@ foreach my $mac (keys %$fdb) {
     my $port = $fdb->{$mac};
     next if (!$port);
     #real port number
-    if (!exists $port_snmp_index{$port}) { next; }
-    #get real port number by snmp our snmp index
-    $port=$port_snmp_index{$port};
+    if (exists $port_snmp_index{$port}) {
+        #get real port number by snmp our snmp index
+        $port=$port_snmp_index{$port};
+        }
     if (!exists $port_index{$port}) { next; }
     #mikrotik patch - skip mikrotik device mac
     if ($sw_mac and $mac=~/^$sw_mac/i) { next; }