浏览代码

added snmpv3 to web

rajven 1 年之前
父节点
当前提交
f65466d

+ 2 - 1
html/admin/devices/edit_l3int.php

@@ -5,8 +5,9 @@ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
 
 $device = get_record($db_link,'devices',"id=".$id);
+$snmp=getSnmpAccess($device);
 $user_info = get_record_sql($db_link,"SELECT * FROM User_list WHERE id=".$device['user_id']);
-$int_list = getIpAdEntIfIndex($db_link,$device['ip'],$device['community'],$device['snmp_version']);
+$int_list = getIpAdEntIfIndex($db_link,$device['ip'],$snmp);
 
 if (isset($_POST["s_remove"])) {
     $s_id = $_POST["s_id"];

+ 282 - 172
html/admin/devices/editdevice.php

@@ -1,7 +1,7 @@
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/idfilter.php");
 
 if (isset($_POST["editdevice"]) and isset($id)) {
     if (isset($_POST["f_port_count"])) {
@@ -11,13 +11,13 @@ if (isset($_POST["editdevice"]) and isset($id)) {
     }
     $sSQL = "SELECT count(id) from device_ports WHERE device_ports.device_id=$id";
     $flist = mysqli_query($db_link, $sSQL);
-    list ($d_ports) = mysqli_fetch_array($flist);
+    list($d_ports) = mysqli_fetch_array($flist);
     if ($d_ports != $sw_ports) {
         LOG_DEBUG($db_link, "Device id: $id changed port count!");
         if ($sw_ports > $d_ports) {
             $start_port = $d_ports + 1;
             LOG_DEBUG($db_link, "Device id: $id add connection for port from $start_port to $sw_ports.");
-            for ($port = $start_port; $port <= $sw_ports; $port ++) {
+            for ($port = $start_port; $port <= $sw_ports; $port++) {
                 $new['device_id'] = $id;
                 $new['snmp_index'] = $port;
                 $new['port'] = $port;
@@ -26,7 +26,7 @@ if (isset($_POST["editdevice"]) and isset($id)) {
         }
         if ($sw_ports < $d_ports) {
             LOG_DEBUG($db_link, "Device id: $id remove connection for port from $d_ports to $sw_ports");
-            for ($port = $d_ports; $port > $sw_ports; $port --) {
+            for ($port = $d_ports; $port > $sw_ports; $port--) {
                 $port_id = get_id_record($db_link, 'device_ports', "device_id='" . $id . "' and port='" . $port . "'");
                 if ($port_id) {
                     delete_record($db_link, "device_ports", "id='" . $port_id . "'");
@@ -38,206 +38,316 @@ if (isset($_POST["editdevice"]) and isset($id)) {
         }
     }
     unset($new);
-    if (isset($_POST["f_ip"])) { $new['ip'] = $_POST["f_ip"]; }
-    $cur_device = get_record_sql($db_link,"SELECT * FROM devices WHERE id=".$id);
+    if (isset($_POST["f_ip"])) {
+        $new['ip'] = $_POST["f_ip"];
+    }
+    $cur_device = get_record_sql($db_link, "SELECT * FROM devices WHERE id=" . $id);
     //main device info
-    if (!empty($new['ip'])) { $cur_auth = get_record_sql($db_link,"SELECT * FROM User_auth WHERE deleted=0 AND ip='".$new['ip']."'"); }
-    if (isset($_POST["f_device_model_id"])) { 
-        $new['device_model_id'] = $_POST["f_device_model_id"]*1;
-        $new['vendor_id'] = get_device_model_vendor($db_link,$new['device_model_id']);
-        }
-    if (isset($_POST["f_port_count"])) { $new['port_count'] = $sw_ports; }
-    if (isset($_POST["f_devtype_id"])) { $new['device_type'] = $_POST["f_devtype_id"]*1; }
-    if (isset($_POST["f_comment"])) { $new['comment'] = $_POST["f_comment"]; }
-    if (isset($_POST["f_SN"])) { $new['SN'] = $_POST["f_SN"]; }
-    if (isset($_POST["f_firmware"])) { $new['firmware'] = $_POST["f_firmware"]; }
+    if (!empty($new['ip'])) {
+        $cur_auth = get_record_sql($db_link, "SELECT * FROM User_auth WHERE deleted=0 AND ip='" . $new['ip'] . "'");
+    }
+    if (isset($_POST["f_device_model_id"])) {
+        $new['device_model_id'] = $_POST["f_device_model_id"] * 1;
+        $new['vendor_id'] = get_device_model_vendor($db_link, $new['device_model_id']);
+    }
+    if (isset($_POST["f_port_count"])) {
+        $new['port_count'] = $sw_ports;
+    }
+    if (isset($_POST["f_devtype_id"])) {
+        $new['device_type'] = $_POST["f_devtype_id"] * 1;
+    }
+    if (isset($_POST["f_comment"])) {
+        $new['comment'] = $_POST["f_comment"];
+    }
+    if (isset($_POST["f_SN"])) {
+        $new['SN'] = $_POST["f_SN"];
+    }
+    if (isset($_POST["f_firmware"])) {
+        $new['firmware'] = $_POST["f_firmware"];
+    }
     //snmp
-    if (isset($_POST["f_snmp_version"])) { $new['snmp_version'] = $_POST["f_snmp_version"] * 1; }
-    if (isset($_POST["f_community"])) { $new['community'] = substr($_POST["f_community"], 0, 50); }
-    if (isset($_POST["f_snmp3_auth_proto"])) { $new['snmp3_auth_proto'] = trim(substr($_POST["f_snmp3_auth_proto"], 0, 10)); }
-    if (isset($_POST["f_snmp3_priv_proto"])) { $new['snmp3_priv_proto'] = trim(substr($_POST["f_snmp3_priv_proto"], 0, 10)); }
-    if (isset($_POST["f_rw_community"])) { $new['rw_community'] = substr($_POST["f_rw_community"], 0, 50); }
-    if (isset($_POST["f_snmp3_user_rw"])) { $new['snmp3_user_rw'] = substr($_POST["f_snmp3_user_rw"], 0, 20); }
-    if (isset($_POST["f_snmp3_user_ro"])) { $new['snmp3_user_ro'] = substr($_POST["f_snmp3_user_ro"], 0, 20); }
-    if (isset($_POST["f_snmp3_user_rw_password"])) { $new['snmp3_user_rw_password'] = substr($_POST["f_snmp3_user_rw_password"], 0, 20); }
-    if (isset($_POST["f_snmp3_user_ro_password"])) { $new['snmp3_user_ro_password'] = substr($_POST["f_snmp3_user_ro_password"], 0, 20); }
+    if (isset($_POST["f_snmp_version"])) {
+        $new['snmp_version'] = $_POST["f_snmp_version"] * 1;
+    }
+    if (isset($_POST["f_community"])) {
+        $new['community'] = substr($_POST["f_community"], 0, 50);
+    }
+    if (isset($_POST["f_snmp3_auth_proto"])) {
+        $new['snmp3_auth_proto'] = trim(substr($_POST["f_snmp3_auth_proto"], 0, 10));
+    }
+    if (isset($_POST["f_snmp3_priv_proto"])) {
+        $new['snmp3_priv_proto'] = trim(substr($_POST["f_snmp3_priv_proto"], 0, 10));
+    }
+    if (isset($_POST["f_rw_community"])) {
+        $new['rw_community'] = substr($_POST["f_rw_community"], 0, 50);
+    }
+    if (isset($_POST["f_snmp3_user_rw"])) {
+        $new['snmp3_user_rw'] = substr($_POST["f_snmp3_user_rw"], 0, 20);
+    }
+    if (isset($_POST["f_snmp3_user_ro"])) {
+        $new['snmp3_user_ro'] = substr($_POST["f_snmp3_user_ro"], 0, 20);
+    }
+    if (isset($_POST["f_snmp3_user_rw_password"])) {
+        $new['snmp3_user_rw_password'] = substr($_POST["f_snmp3_user_rw_password"], 0, 20);
+    }
+    if (isset($_POST["f_snmp3_user_ro_password"])) {
+        $new['snmp3_user_ro_password'] = substr($_POST["f_snmp3_user_ro_password"], 0, 20);
+    }
     //acl & configuration options
-    if (isset($_POST["f_queue_enabled"])) { $new['queue_enabled'] = $_POST["f_queue_enabled"] * 1; }
-    if (isset($_POST["f_connected_user_only"])) { $new['connected_user_only'] = $_POST["f_connected_user_only"] * 1; }
-    if (isset($_POST["f_dhcp"])) { $new['dhcp'] = $_POST["f_dhcp"] * 1; }
-    if (isset($_POST["f_user_acl"])) { $new['user_acl'] = $_POST["f_user_acl"] * 1; }
-    if ($new['device_type'] == 0 ) { 
+    if (isset($_POST["f_queue_enabled"])) {
+        $new['queue_enabled'] = $_POST["f_queue_enabled"] * 1;
+    }
+    if (isset($_POST["f_connected_user_only"])) {
+        $new['connected_user_only'] = $_POST["f_connected_user_only"] * 1;
+    }
+    if (isset($_POST["f_dhcp"])) {
+        $new['dhcp'] = $_POST["f_dhcp"] * 1;
+    }
+    if (isset($_POST["f_user_acl"])) {
+        $new['user_acl'] = $_POST["f_user_acl"] * 1;
+    }
+    if ($new['device_type'] == 0) {
         $new['queue_enabled'] = 0;
         $new['connected_user_only'] = 1;
         $new['user_acl'] = 1;
-        }
+    }
     //interfaces
-    if (isset($_POST["f_wan"])) { $new['wan_int'] = $_POST["f_wan"]; }
-    if (isset($_POST["f_lan"])) { $new['lan_int'] = $_POST["f_lan"]; }
+    if (isset($_POST["f_wan"])) {
+        $new['wan_int'] = $_POST["f_wan"];
+    }
+    if (isset($_POST["f_lan"])) {
+        $new['lan_int'] = $_POST["f_lan"];
+    }
     //location
-    if (isset($_POST["f_building_id"])) { $new['building_id'] = $_POST["f_building_id"] * 1; }
+    if (isset($_POST["f_building_id"])) {
+        $new['building_id'] = $_POST["f_building_id"] * 1;
+    }
     //access
-    if (isset($_POST["f_login"])) { $new['login'] = $_POST["f_login"]; }
+    if (isset($_POST["f_login"])) {
+        $new['login'] = $_POST["f_login"];
+    }
     if (!empty($_POST["f_password"])) {
-        if (!preg_match('/^\*+$/', $_POST["f_password"])) { 
-            $new['password'] = crypt_string($_POST["f_password"]);  
-            }
+        if (!preg_match('/^\*+$/', $_POST["f_password"])) {
+            $new['password'] = crypt_string($_POST["f_password"]);
         }
-    if (isset($_POST["f_protocol"])) { $new['protocol'] = $_POST["f_protocol"]*1; }
-    if (isset($_POST["f_control_port"])) { $new['control_port'] = $_POST["f_control_port"]*1; }
-    if (isset($_POST["f_save_netflow"])) { $new['netflow_save'] = $_POST["f_save_netflow"]*1; }
+    }
+    if (isset($_POST["f_protocol"])) {
+        $new['protocol'] = $_POST["f_protocol"] * 1;
+    }
+    if (isset($_POST["f_control_port"])) {
+        $new['control_port'] = $_POST["f_control_port"] * 1;
+    }
+    if (isset($_POST["f_save_netflow"])) {
+        $new['netflow_save'] = $_POST["f_save_netflow"] * 1;
+    }
     //discovery
-    if (isset($_POST["f_discovery"])) { $new['discovery'] = $_POST["f_discovery"]; }
+    if (isset($_POST["f_discovery"])) {
+        $new['discovery'] = $_POST["f_discovery"];
+    }
     //nagios
     if (isset($_POST["f_nagios"])) {
-	$new['nagios'] = $_POST["f_nagios"] * 1;
-        if ($new['nagios'] ==0) { $new['nagios_status']='UP'; }
-	} else {
-	if (!empty($cur_auth)) {
-	    $new['nagios']=0;
-	    $new['nagios_status']=$cur_auth['nagios_status'];
-	    }
-	}
+        $new['nagios'] = $_POST["f_nagios"] * 1;
+        if ($new['nagios'] == 0) {
+            $new['nagios_status'] = 'UP';
+        }
+    } else {
+        if (!empty($cur_auth)) {
+            $new['nagios'] = 0;
+            $new['nagios_status'] = $cur_auth['nagios_status'];
+        }
+    }
     update_record($db_link, "devices", "id='$id'", $new);
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }
 
-$device=get_record($db_link,'devices',"id=".$id);
-$user_info = get_record_sql($db_link,"SELECT * FROM User_list WHERE id=".$device['user_id']);
+$device = get_record($db_link, 'devices', "id=" . $id);
+$user_info = get_record_sql($db_link, "SELECT * FROM User_list WHERE id=" . $device['user_id']);
 unset($_POST);
 
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
 
 print_device_submenu($page_url);
-print_editdevice_submenu($page_url,$id,$device['device_type'],$user_info['login']);
+print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['login']);
 
 ?>
 <div id="contsubmenu">
 
-<?php
+    <?php
     if (!empty($_GET['status'])) {
-        if ($_GET['status'] ==='locked') { print '<div id="msg">' . WEB_device_locked . '</div>'; }
+        if ($_GET['status'] === 'locked') {
+            print '<div id="msg">' . WEB_device_locked . '</div>';
+        }
     }
-?>
+    ?>
 
-<form name="def" action="editdevice.php?id=<?php echo $id; ?>" method="post">
-<table class="data">
-<tr>
-<td><?php echo WEB_cell_name; ?></td>
-<td><?php echo WEB_cell_ip; ?></td>
-<td><?php echo WEB_cell_type; ?></td>
-<?php
-if ($device['device_type']<=2) { print "<td>".WEB_device_port_count."</td>"; } else { print "<td></td>"; }
-print "</tr>";
-print "<tr>\n";
-print "<td class='data'><a href=/admin/users/edituser.php?id=".$device['user_id'].">".$user_info['login']."</a></td>\n";
-print "<td class='data'>"; print_device_ip_select($db_link,'f_ip',$device['ip'],$device['user_id']); print "</td>\n";
-print "<td class='data'>"; print_devtype_select($db_link,'f_devtype_id',$device['device_type']); print "</td>\n";
-if ($device['device_type']<=2) { print "<td class='data'><input type='text' name='f_port_count' value='".$device['port_count']."' size=5></td>\n"; } else { print "<td></td>"; }
-print "</tr>\n";
-?>
-</tr>
-<td colspan=2><?php echo WEB_cell_host_model; ?></td>
-<td><?php echo WEB_cell_host_firmware; ?></td>
-<td><?php echo WEB_cell_sn; ?></td>
-<?php
+    <form name="def" action="editdevice.php?id=<?php echo $id; ?>" method="post">
+        <table class="data">
+            <tr>
+                <td><?php echo WEB_cell_name; ?></td>
+                <td><?php echo WEB_cell_ip; ?></td>
+                <td><?php echo WEB_cell_type; ?></td>
+                <?php
+                if ($device['device_type'] <= 2) {
+                    print "<td>" . WEB_device_port_count . "</td>";
+                } else {
+                    print "<td></td>";
+                }
+                print "</tr>";
+                print "<tr>\n";
+                print "<td class='data'><a href=/admin/users/edituser.php?id=" . $device['user_id'] . ">" . $user_info['login'] . "</a></td>\n";
+                print "<td class='data'>";
+                print_device_ip_select($db_link, 'f_ip', $device['ip'], $device['user_id']);
+                print "</td>\n";
+                print "<td class='data'>";
+                print_devtype_select($db_link, 'f_devtype_id', $device['device_type']);
+                print "</td>\n";
+                if ($device['device_type'] <= 2) {
+                    print "<td class='data'><input type='text' name='f_port_count' value='" . $device['port_count'] . "' size=5></td>\n";
+                } else {
+                    print "<td></td>";
+                }
+                print "</tr>\n";
+                ?>
+            </tr>
+            <td colspan=2><?php echo WEB_cell_host_model; ?></td>
+            <td><?php echo WEB_cell_host_firmware; ?></td>
+            <td><?php echo WEB_cell_sn; ?></td>
+            <?php
 
-//common information
-print "<tr>\n";
-print "<td class='data' colspan=2>"; print_device_model_select($db_link,'f_device_model_id',$device['device_model_id']); print "</td>\n";
-print "<td class='data' ><input type='text' name='f_firmware' value='".$device['firmware']."'></td>\n";
-print "<td class='data' ><input type='text' name='f_SN' value='".$device['SN']."'></td>\n";
-print "</tr>\n";
-print "<tr><td colspan=2>".WEB_location_name."</td><td colspan=2>".WEB_cell_comment."</td>";
-print "</tr><tr>";
-print "<td class='data'>"; print_building_select($db_link, 'f_building_id', $device['building_id']); print "</td>\n";
-print "<td class='data' colspan=3><input type='text' size=50 name='f_comment' value='".$device['comment']."'></td>\n";
-print "</tr>";
+            //common information
+            print "<tr>\n";
+            print "<td class='data' colspan=2>";
+            print_device_model_select($db_link, 'f_device_model_id', $device['device_model_id']);
+            print "</td>\n";
+            print "<td class='data' ><input type='text' name='f_firmware' value='" . $device['firmware'] . "'></td>\n";
+            print "<td class='data' ><input type='text' name='f_SN' value='" . $device['SN'] . "'></td>\n";
+            print "</tr>\n";
+            print "<tr><td colspan=2>" . WEB_location_name . "</td><td colspan=2>" . WEB_cell_comment . "</td>";
+            print "</tr><tr>";
+            print "<td class='data'>";
+            print_building_select($db_link, 'f_building_id', $device['building_id']);
+            print "</td>\n";
+            print "<td class='data' colspan=3><input type='text' size=50 name='f_comment' value='" . $device['comment'] . "'></td>\n";
+            print "</tr>";
 
-//print gateway settings
-if ($device['device_type']==2) {
-    print "<tr><td>".WEB_device_access_control."</td><td>".WEB_device_dhcp_server."</td><td>".WEB_device_queues_enabled."</td><td>".WEB_device_connected_only."</td></tr>";
-    print "<tr>";
-    print "<td class='data'>"; print_qa_select('f_user_acl', $device['user_acl']); print "</td>\n"; 
-    print "<td class='data'>"; print_qa_select('f_dhcp', $device['dhcp']); print "</td>\n";
-    print "<td class='data'>"; print_qa_select('f_queue_enabled', $device['queue_enabled']); print "</td>\n";
-    print "<td class='data'>"; print_qa_select('f_connected_user_only', $device['connected_user_only']); print "</td>\n";
-    print "</tr>\n";
-    print "<tr><td colspan=2>"; print_url(WEB_list_l3_interfaces,"/admin/devices/edit_l3int.php?id=$id"); print "</td>";
-    print "<td colspan=2>"; print_url(WEB_list_gateway_subnets,"/admin/devices/edit_gw_subnets.php?id=$id"); print "</td></tr>";
-    print "<tr><td colspan=2 class='data'>"; print get_l3_interfaces($db_link,$device['id']); print "</td>";
-    print "<td colspan=2 class='data'>"; print get_gw_subnets($db_link,$device['id']); print "</td></tr>";
-}
+            //print gateway settings
+            if ($device['device_type'] == 2) {
+                print "<tr><td>" . WEB_device_access_control . "</td><td>" . WEB_device_dhcp_server . "</td><td>" . WEB_device_queues_enabled . "</td><td>" . WEB_device_connected_only . "</td></tr>";
+                print "<tr>";
+                print "<td class='data'>";
+                print_qa_select('f_user_acl', $device['user_acl']);
+                print "</td>\n";
+                print "<td class='data'>";
+                print_qa_select('f_dhcp', $device['dhcp']);
+                print "</td>\n";
+                print "<td class='data'>";
+                print_qa_select('f_queue_enabled', $device['queue_enabled']);
+                print "</td>\n";
+                print "<td class='data'>";
+                print_qa_select('f_connected_user_only', $device['connected_user_only']);
+                print "</td>\n";
+                print "</tr>\n";
+                print "<tr><td colspan=2>";
+                print_url(WEB_list_l3_interfaces, "/admin/devices/edit_l3int.php?id=$id");
+                print "</td>";
+                print "<td colspan=2>";
+                print_url(WEB_list_gateway_subnets, "/admin/devices/edit_gw_subnets.php?id=$id");
+                print "</td></tr>";
+                print "<tr><td colspan=2 class='data'>";
+                print get_l3_interfaces($db_link, $device['id']);
+                print "</td>";
+                print "<td colspan=2 class='data'>";
+                print get_gw_subnets($db_link, $device['id']);
+                print "</td></tr>";
+            }
 
-//print router settings
-if ($device['device_type']==0) {
-    print "<tr><td>".WEB_device_dhcp_server."</td><td></td><td></td><td></td></tr>";
-    print "<tr>";
-    print "<td class='data'>"; print_qa_select('f_dhcp', $device['dhcp']); 
-    print "<td class='data' colspan=4>"; print_url(WEB_list_l3_networks,"/admin/devices/edit_gw_subnets.php?id=$id");
-    print "</tr>\n";
-    }
+            //print router settings
+            if ($device['device_type'] == 0) {
+                print "<tr><td>" . WEB_device_dhcp_server . "</td><td></td><td></td><td></td></tr>";
+                print "<tr>";
+                print "<td class='data'>";
+                print_qa_select('f_dhcp', $device['dhcp']);
+                print "<td class='data' colspan=4>";
+                print_url(WEB_list_l3_networks, "/admin/devices/edit_gw_subnets.php?id=$id");
+                print "</tr>\n";
+            }
 
-//for all active network devices
-if ($device['device_type']<=2) {
-    //cli access settings
-    print "<tr><td>".WEB_cell_login."</td><td>".WEB_cell_password."</td><td>".WEB_cell_control_proto."</td><td>".WEB_cell_control_port."</td></tr>";
-    print "<tr>"; 
-    print "<td class='data'><input type='text' name='f_login' value=".$device['login']."></td>\n";
-    print "<td class='data'><input type='text' name='f_password' value='********'></td>\n";
-    print "<td class='data'>"; print_control_proto_select('f_protocol', $device['protocol']); print "</td>\n";
-    print "<td class='data'><input type='text' name='f_control_port' value=".$device['control_port']."></td>\n";
-    print "</tr>";
-    //snmp settings & discovery & nagios
-    print "<tr><td>".WEB_network_discovery."</td><td>".WEB_nagios."</td><td>".WEB_device_save_netflow."</td><td></td></tr>";
-    print "<tr>";
-    print "<td class='data'>"; print_qa_select('f_discovery', $device['discovery']); print "</td>\n";
-    print "<td class='data'>"; print_qa_select('f_nagios', $device['nagios']); print "</td>\n";
-    print "<td class='data'>"; print_qa_select('f_save_netflow', $device['netflow_save']); print "</td>\n";
-    print "<td class='data'></td></tr>";
-    }
+            //for all active network devices
+            if ($device['device_type'] <= 2) {
+                //cli access settings
+                print "<tr><td>" . WEB_cell_login . "</td><td>" . WEB_cell_password . "</td><td>" . WEB_cell_control_proto . "</td><td>" . WEB_cell_control_port . "</td></tr>";
+                print "<tr>";
+                print "<td class='data'><input type='text' name='f_login' value=" . $device['login'] . "></td>\n";
+                print "<td class='data'><input type='text' name='f_password' value='********'></td>\n";
+                print "<td class='data'>";
+                print_control_proto_select('f_protocol', $device['protocol']);
+                print "</td>\n";
+                print "<td class='data'><input type='text' name='f_control_port' value=" . $device['control_port'] . "></td>\n";
+                print "</tr>";
+                //snmp settings & discovery & nagios
+                print "<tr><td>" . WEB_network_discovery . "</td><td>" . WEB_nagios . "</td><td>" . WEB_device_save_netflow . "</td><td></td></tr>";
+                print "<tr>";
+                print "<td class='data'>";
+                print_qa_select('f_discovery', $device['discovery']);
+                print "</td>\n";
+                print "<td class='data'>";
+                print_qa_select('f_nagios', $device['nagios']);
+                print "</td>\n";
+                print "<td class='data'>";
+                print_qa_select('f_save_netflow', $device['netflow_save']);
+                print "</td>\n";
+                print "<td class='data'></td></tr>";
+            }
 
-if ($device['snmp_version'] ==3) {
-        //snmp settings
-	print "<tr><td>".WEB_snmp_version."</td><td>".WEB_snmp_v3_auth_proto."</td><td>".WEB_snmp_v3_priv_proto."</td><td></td></tr>";
-        print "<tr><td class='data'>"; print_snmp_select('f_snmp_version', $device['snmp_version']); print "</td>\n";
-        print "<td class='data'>"; print_snmp_auth_proto_select('f_snmp3_auth_proto', $device['snmp3_auth_proto']); print "</td>\n";
-        print "<td class='data'>"; print_snmp_priv_proto_select('f_snmp3_priv_proto', $device['snmp3_priv_proto']); print "</td>\n";
-    	print "<td class='data'></td>";
-        print "</tr>";
-        print "<tr><td>".WEB_snmp_v3_user_ro."</td><td>".WEB_snmp_v3_ro_password."</td><td>".WEB_snmp_v3_user_rw."</td><td>".WEB_snmp_v3_rw_password."</td><td></td>";
-	print "</tr><tr>";
-        print "<td class='data'><input type='text' name='f_snmp3_user_ro' value=".$device['snmp3_user_ro']."></td>\n";
-        print "<td class='data'><input type='text' name='f_snmp3_user_ro_password' value=".$device['snmp3_user_ro_password']."></td>\n";
-	print "<td class='data'><input type='text' name='f_snmp3_user_rw' value=".$device['snmp3_user_rw']."></td>\n";
-	print "<td class='data'><input type='text' name='f_snmp3_user_rw_password' value=".$device['snmp3_user_rw_password']."></td>\n";
-        print "</tr>\n";
-	} else {
-	print "<tr><td>".WEB_snmp_version."</td><td></td><td></td><td></td></tr>";
-        print "<tr><td class='data'>"; print_snmp_select('f_snmp_version', $device['snmp_version']); print "</td><td class='data' colspan=3></td>\n";
-        print "</tr>";
-	if ($device['snmp_version']>0) {
-            print "<tr><td>".WEB_snmp_community_ro."</td><td>".WEB_snmp_community_rw."</td><td></td><td></td></tr>";
-	    print "<tr>\n";
-    	    print "<td class='data'><input type='text' name='f_community' value=".$device['community']."></td>\n";
-	    print "<td class='data'><input type='text' name='f_rw_community' value=".$device['rw_community']."></td>\n";
-    	    print "<td class='data' colspan=2></td>";
-	    print "</tr>";
-	    }
-	}
+            if ($device['snmp_version'] == 3) {
+                //snmp settings
+                print "<tr><td>" . WEB_snmp_version . "</td><td>" . WEB_snmp_v3_auth_proto . "</td><td>" . WEB_snmp_v3_priv_proto . "</td><td></td></tr>";
+                print "<tr><td class='data'>";
+                print_snmp_select('f_snmp_version', $device['snmp_version']);
+                print "</td>\n";
+                print "<td class='data'>";
+                print_snmp_auth_proto_select('f_snmp3_auth_proto', $device['snmp3_auth_proto']);
+                print "</td>\n";
+                print "<td class='data'>";
+                print_snmp_priv_proto_select('f_snmp3_priv_proto', $device['snmp3_priv_proto']);
+                print "</td>\n";
+                print "<td class='data'></td>";
+                print "</tr>";
+                print "<tr><td>" . WEB_snmp_v3_user_ro . "</td><td>" . WEB_snmp_v3_ro_password . "</td><td>" . WEB_snmp_v3_user_rw . "</td><td>" . WEB_snmp_v3_rw_password . "</td><td></td>";
+                print "</tr><tr>";
+                print "<td class='data'><input type='text' name='f_snmp3_user_ro' value=" . $device['snmp3_user_ro'] . "></td>\n";
+                print "<td class='data'><input type='text' name='f_snmp3_user_ro_password' value=" . $device['snmp3_user_ro_password'] . "></td>\n";
+                print "<td class='data'><input type='text' name='f_snmp3_user_rw' value=" . $device['snmp3_user_rw'] . "></td>\n";
+                print "<td class='data'><input type='text' name='f_snmp3_user_rw_password' value=" . $device['snmp3_user_rw_password'] . "></td>\n";
+                print "</tr>\n";
+            } else {
+                print "<tr><td>" . WEB_snmp_version . "</td><td></td><td></td><td></td></tr>";
+                print "<tr><td class='data'>";
+                print_snmp_select('f_snmp_version', $device['snmp_version']);
+                print "</td><td class='data' colspan=3></td>\n";
+                print "</tr>";
+                if ($device['snmp_version'] > 0) {
+                    print "<tr><td>" . WEB_snmp_community_ro . "</td><td>" . WEB_snmp_community_rw . "</td><td></td><td></td></tr>";
+                    print "<tr>\n";
+                    print "<td class='data'><input type='text' name='f_community' value=" . $device['community'] . "></td>\n";
+                    print "<td class='data'><input type='text' name='f_rw_community' value=" . $device['rw_community'] . "></td>\n";
+                    print "<td class='data' colspan=2></td>";
+                    print "</tr>";
+                }
+            }
 
-//save button
-if ($device['snmp_version']>0) {
-    print "<tr><td colspan=2>".$device['ip']."::". get_device_model_name($db_link,$device['device_model_id'])."</td>";
-    print "<td><button name='mac_walk' onclick=\"window.open('mactable.php?id=" . $id . "')\">".WEB_device_mac_table."</button>";
-    print "<button name='port_walk' onclick=\"window.open('snmpwalk.php?id=" . $id . "')\">".WEB_device_walk_port_list."</button></td>";
-    } else {
-    print "<tr><td colspan=3>".$device['ip']."::". get_device_model_name($db_link,$device['device_model_id'])."</td>";
-    }
-print "<td align=right><input type='submit' name='editdevice' value='".WEB_btn_save."'></td></tr>";
-print "</table>\n";
-?>
-</form>
+            //save button
+            if ($device['snmp_version'] > 0) {
+                print "<tr><td colspan=2>" . $device['ip'] . "::" . get_device_model_name($db_link, $device['device_model_id']) . "</td>";
+                print "<td><button name='mac_walk' onclick=\"window.open('mactable.php?id=" . $id . "')\">" . WEB_device_mac_table . "</button>";
+                print "<button name='port_walk' onclick=\"window.open('snmpwalk.php?id=" . $id . "')\">" . WEB_device_walk_port_list . "</button></td>";
+            } else {
+                print "<tr><td colspan=3>" . $device['ip'] . "::" . get_device_model_name($db_link, $device['device_model_id']) . "</td>";
+            }
+            print "<td align=right><input type='submit' name='editdevice' value='" . WEB_btn_save . "'></td></tr>";
+            print "</table>\n";
+            ?>
+    </form>
 
-<?php require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.small.php"); ?>
+    <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.small.php"); ?>

+ 3 - 2
html/admin/devices/mactable.php

@@ -4,6 +4,7 @@ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
 
 $device=get_record($db_link,'devices',"id=".$id);
+$snmp = getSnmpAccess($device);
 $user_info = get_record_sql($db_link,"SELECT * FROM User_list WHERE id=".$device['user_id']);
 
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
@@ -30,11 +31,11 @@ print "<b>".WEB_device_mac_table_show."&nbsp".$device['device_name']." (".$devic
 
 $snmp_ok = 0;
 if (!empty($device['ip']) and $device['snmp_version'] > 0) {
-	$snmp_ok = check_snmp_access($device['ip'], $device['community'], $device['snmp_version']);
+	$snmp_ok = check_snmp_access($device['ip'], $snmp);
 	}
 
 if ($snmp_ok) {
-	$fdb = get_fdb_table($device['ip'], $device['community'], $device['snmp_version']);
+	$fdb = get_fdb_table($device['ip'], $snmp);
 
 	$port_by_snmp = 0;
    	foreach ($fdb as $a_mac => $a_port) {

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

@@ -4,7 +4,7 @@ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
 
 $port_id = $id;
-$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";
+$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";
 $port_info = get_record_sql($db_link, $sSQL);
 
 $device_id = $port_info["device_id"];
@@ -15,6 +15,7 @@ $ports_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);
+$snmp = getSnmpAccess($device);
 $user_info = get_record_sql($db_link,"SELECT * FROM User_list WHERE id=".$device['user_id']);
 
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
@@ -45,13 +46,13 @@ if ($port_info['vendor_id'] == 9) {
 
 $snmp_ok = 0;
 if (!empty($device['ip']) and $device['snmp_version'] > 0) {
-        $snmp_ok = check_snmp_access($device['ip'], $device['community'], $device['snmp_version']);
+        $snmp_ok = check_snmp_access($device['ip'], $snmp);
     }
 
 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']);
+    $fdb = get_fdb_table($port_info['ip'], $snmp);
     $f_port = $port_info['snmp_index'];
     $port_by_snmp = 0;
     foreach ($fdb as $a_mac => $a_port) {

+ 4 - 3
html/admin/devices/snmpwalk.php

@@ -4,6 +4,7 @@ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
 
 $device=get_record($db_link,'devices',"id=".$id);
+$snmp = getSnmpAccess($device);
 $user_info = get_record_sql($db_link,"SELECT * FROM User_list WHERE id=".$device['user_id']);
 
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
@@ -22,12 +23,12 @@ if (!apply_device_lock($db_link,$id)) {
 
 $snmp_ok = 0;
 if (!empty($device['ip']) and $device['snmp_version'] > 0) {
-	$snmp_ok = check_snmp_access($device['ip'], $device['community'], $device['snmp_version']);
+	$snmp_ok = check_snmp_access($device['ip'], $snmp);
 	}
 
 if ($snmp_ok) {
-    $interfaces = get_snmp_interfaces($device['ip'], $device['community'], $device['snmp_version']);
-    $dev_info = walk_snmp($device['ip'], $device['community'], $device['snmp_version'],SYSINFO_MIB);
+    $interfaces = get_snmp_interfaces($device['ip'], $snmp);
+    $dev_info = walk_snmp($device['ip'], $snmp,SYSINFO_MIB);
     foreach ($dev_info as $key => $value) {
         $v_data = trim(parse_snmp_value($value));
         if (!empty($v_data)) { print "$v_data<br>"; }

+ 93 - 65
html/admin/devices/switchstatus.php

@@ -4,6 +4,7 @@ require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php")
 require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/idfilter.php");
 
 $device = get_record($db_link, 'devices', "id=" . $id);
+$snmp = getSnmpAccess($device);
 $device_model = get_record($db_link, 'device_models', "id=" . $device['device_model_id']);
 
 if (isset($_POST["regensnmp"])) {
@@ -70,8 +71,8 @@ if (isset($_POST['port_off']) and $device['snmp_version'] > 0) {
 
 unset($_POST);
 
-if (!apply_device_lock($db_link,$id)) {
-    header("Location: /admin/devices/editdevice.php?id=".$id."&status=locked");
+if (!apply_device_lock($db_link, $id)) {
+    header("Location: /admin/devices/editdevice.php?id=" . $id . "&status=locked");
     exit;
 }
 
@@ -95,24 +96,21 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
         $snmp_ok = 0;
         $vlan_list = [];
         $vlan_at_port_by_snmp = 1;
-        
+
         if (!empty($device['ip']) and $device['snmp_version'] > 0) {
-            $snmp_ok = check_snmp_access($device['ip'], $device['community'], $device['snmp_version']);
+            $snmp_ok = check_snmp_access($device['ip'], $snmp);
             $modules_oids = NULL;
             if ($snmp_ok) {
-                if ($device['snmp_version'] == 2) {
-                    $modules_oids = snmp2_real_walk($device['ip'], $device['community'], CISCO_MODULES, SNMP_timeout, SNMP_retry);
-                    }
-                if ($device['snmp_version'] == 1) {
-                    $modules_oids = snmprealwalk($device['ip'], $device['community'], CISCO_MODULES, SNMP_timeout, SNMP_retry);
-                    }
-                $vlan_list = get_switch_vlans($device['vendor_id'],$device['ip'], $device['community'], $device['snmp_version']);
+                $modules_oids = walk_snmp($device["ip"], $snmp, CISCO_MODULES);
+                $vlan_list = get_switch_vlans($device['vendor_id'], $device['ip'], $snmp);
                 //if port number 1 not exists - try detect by snmp interface index
-                if (isset($vlan_list['1'])) { $vlan_at_port_by_snmp = 0; }
+                if (isset($vlan_list['1'])) {
+                    $vlan_at_port_by_snmp = 0;
                 }
-            } else {
-            $snmp_ok = 0;
             }
+        } else {
+            $snmp_ok = 0;
+        }
 
         print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
         print "<tr>\n";
@@ -133,7 +131,7 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
         print "<td>" . WEB_msg_additional . "</td>\n";
         if ($device_model['poe_out']) {
             print "<td>" . WEB_device_poe_control . "</td>\n";
-            }
+        }
         print "<td>" . WEB_device_port_control . "</td>\n";
         print "</tr>\n";
         $sSQL = "SELECT * FROM device_ports WHERE device_ports.device_id=$id ORDER BY port";
@@ -143,21 +141,21 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
             $cl = "down";
             $new_info = NULL;
 
-            $display_vlan= $row['vlan'];
-            if (!empty($row['untagged_vlan'])) { 
-                if ($row['untagged_vlan'] != $row['vlan']) { 
+            $display_vlan = $row['vlan'];
+            if (!empty($row['untagged_vlan'])) {
+                if ($row['untagged_vlan'] != $row['vlan']) {
                     $pattern = '/(\d+),(\d+),(\d+),(\d+),(\d+),/';
                     $replacement = '${1},${2},${3},${4},${5}<br>U:';
                     $display_untagged = preg_replace($pattern, $replacement, $row['untagged_vlan']);
-                    $display_vlan.=";U:".$display_untagged; 
-                    }
+                    $display_vlan .= ";U:" . $display_untagged;
                 }
-            if (!empty($row['tagged_vlan'])) { 
+            }
+            if (!empty($row['tagged_vlan'])) {
                 $pattern = '/(\d+),(\d+),(\d+),(\d+),(\d+),/';
                 $replacement = '${1},${2},${3},${4},${5}<br>T:';
                 $display_tagged = preg_replace($pattern, $replacement, $row['tagged_vlan']);
-                $display_vlan.=";T:".$display_tagged; 
-                }
+                $display_vlan .= ";T:" . $display_tagged;
+            }
 
             //fix empty port names
             if (empty($row['port_name'])) {
@@ -166,17 +164,23 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
             }
 
             if ($snmp_ok) {
-                $port_state_detail = get_port_state_detail($row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);
+                $port_state_detail = get_port_state_detail($row['snmp_index'], $device['ip'], $snmp);
                 list($poper, $padmin, $pspeed, $perrors) = explode(';', $port_state_detail);
-                if ($poper == 1) { $cl = "up"; }
+                if ($poper == 1) {
+                    $cl = "up";
+                }
                 if ($poper >= 2) {
-                    if ($padmin >= 2) { $cl = "shutdown"; } else { $cl = "down"; }
+                    if ($padmin >= 2) {
+                        $cl = "shutdown";
+                    } else {
+                        $cl = "down";
                     }
                 }
+            }
 
             print "<td class='" . $cl . "' style='padding:0'><input type=checkbox name=d_port_index[] value=" . $row['snmp_index'] . " ></td>\n";
 
-            print "<td class='" . $cl . "'><a href=\"#\" onclick=\"".open_window_url("editport.php?id=".$row['id'])." return false;\">" . $row['port'] . "</a></td>\n";
+            print "<td class='" . $cl . "'><a href=\"#\" onclick=\"" . open_window_url("editport.php?id=" . $row['id']) . " return false;\">" . $row['port'] . "</a></td>\n";
             print "<td class='" . $cl . "' >" . $row['port_name'] . "</td>\n";
             print "<td class='" . $cl . "' >" . $row['snmp_index'] . "</td>\n";
             print "<td class='" . $cl . "'>";
@@ -186,7 +190,7 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
                 print_auth_port($db_link, $row['id'], TRUE);
             }
             print "</td>\n";
-            print "<td class='" . $cl . "' >" . get_port_comment($db_link, $row['id'],$row['comment']) . "</td>\n";
+            print "<td class='" . $cl . "' >" . get_port_comment($db_link, $row['id'], $row['comment']) . "</td>\n";
             print "<td class='" . $cl . "' >" . get_qa($row['uplink']) . "</td>\n";
             print "<td class='" . $cl . "' >" . get_qa($row['nagios']) . "</td>\n";
             print "<td class='" . $cl . "' >" . get_qa($row['skip']) . "</td>\n";
@@ -196,17 +200,17 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
 
             if ($snmp_ok) {
                 //sfp information
-                $sfp_status = get_sfp_status($device['vendor_id'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version'], $modules_oids);
+                $sfp_status = get_sfp_status($device['vendor_id'], $row['snmp_index'], $device['ip'], $snmp, $modules_oids);
 
                 //interface name
-                $ifname = get_snmp_ifname($device['ip'], $device['community'], $device['snmp_version'], $row['snmp_index']);
+                $ifname = get_snmp_ifname($device['ip'], $snmp, $row['snmp_index']);
 
                 //poe information
                 if ($device_model['poe_out']) {
-                    $poe_status = get_port_poe_state($device['vendor_id'], $row['port'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);
+                    $poe_status = get_port_poe_state($device['vendor_id'], $row['port'], $row['snmp_index'], $device['ip'], $snmp);
                     if (isset($poe_status)) {
                         if ($poe_status == 1) {
-                            $port_poe_detail = get_port_poe_detail($device['vendor_id'], $row['port'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);
+                            $port_poe_detail = get_port_poe_detail($device['vendor_id'], $row['port'], $row['snmp_index'], $device['ip'], $snmp);
                             if (empty($port_poe_detail)) {
                                 $poe_info = 'POE:on';
                             } else {
@@ -223,49 +227,71 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
                 if (!empty($vlan_list)) {
                     if ($vlan_at_port_by_snmp) {
                         if (!empty($vlan_list[$row['snmp_index']])) {
-                            if (!empty($vlan_list[$row['snmp_index']]['pvid'])) { 
-                                if ($vlan_list[$row['snmp_index']]['pvid']>=1 and $vlan_list[$row['snmp_index']]['pvid']<=4094) { 
-                                    $new_info['vlan'] = $vlan_list[$row['snmp_index']]['pvid']; 
-                                    } else {
-                                    $new_info['vlan'] =1;
-                                    }
+                            if (!empty($vlan_list[$row['snmp_index']]['pvid'])) {
+                                if ($vlan_list[$row['snmp_index']]['pvid'] >= 1 and $vlan_list[$row['snmp_index']]['pvid'] <= 4094) {
+                                    $new_info['vlan'] = $vlan_list[$row['snmp_index']]['pvid'];
+                                } else {
+                                    $new_info['vlan'] = 1;
                                 }
-                            if (!empty($vlan_list[$row['snmp_index']]['tagged'])) { $new_info['tagged_vlan']=$vlan_list[$row['snmp_index']]['tagged']; } else { $new_info['tagged_vlan'] = ''; }
-                            if (!empty($vlan_list[$row['snmp_index']]['untagged'])) { $new_info['untagged_vlan']=$vlan_list[$row['snmp_index']]['untagged']; } else { $new_info['untagged_vlan'] = ''; }
                             }
-                        } else {
+                            if (!empty($vlan_list[$row['snmp_index']]['tagged'])) {
+                                $new_info['tagged_vlan'] = $vlan_list[$row['snmp_index']]['tagged'];
+                            } else {
+                                $new_info['tagged_vlan'] = '';
+                            }
+                            if (!empty($vlan_list[$row['snmp_index']]['untagged'])) {
+                                $new_info['untagged_vlan'] = $vlan_list[$row['snmp_index']]['untagged'];
+                            } else {
+                                $new_info['untagged_vlan'] = '';
+                            }
+                        }
+                    } else {
                         if (!empty($vlan_list[$row['port']])) {
-                            if (!empty($vlan_list[$row['port']]['pvid'])) { 
-                                if ($vlan_list[$row['port']]['pvid']>=1 and $vlan_list[$row['port']]['pvid']<=4094) {
-                                    $new_info['vlan'] = $vlan_list[$row['port']]['pvid']; 
-                                    } else {
-                                    $new_info['vlan'] =1;
-                                    }
+                            if (!empty($vlan_list[$row['port']]['pvid'])) {
+                                if ($vlan_list[$row['port']]['pvid'] >= 1 and $vlan_list[$row['port']]['pvid'] <= 4094) {
+                                    $new_info['vlan'] = $vlan_list[$row['port']]['pvid'];
+                                } else {
+                                    $new_info['vlan'] = 1;
                                 }
-                            if (!empty($vlan_list[$row['port']]['tagged'])) { $new_info['tagged_vlan']=$vlan_list[$row['port']]['tagged']; } else { $new_info['tagged_vlan'] = ''; }
-                            if (!empty($vlan_list[$row['port']]['untagged'])) { $new_info['untagged_vlan']=$vlan_list[$row['port']]['untagged']; } else { $new_info['untagged_vlan'] = ''; }
+                            }
+                            if (!empty($vlan_list[$row['port']]['tagged'])) {
+                                $new_info['tagged_vlan'] = $vlan_list[$row['port']]['tagged'];
+                            } else {
+                                $new_info['tagged_vlan'] = '';
+                            }
+                            if (!empty($vlan_list[$row['port']]['untagged'])) {
+                                $new_info['untagged_vlan'] = $vlan_list[$row['port']]['untagged'];
+                            } else {
+                                $new_info['untagged_vlan'] = '';
                             }
                         }
+                    }
                     $display_vlan = '';
-                    if (!empty($new_info['vlan'])) { $display_vlan = $new_info['vlan']; }
-                    if (!empty($new_info['untagged_vlan'])) { 
-                        if ($new_info['untagged_vlan'] != $new_info['vlan']) { 
+                    if (!empty($new_info['vlan'])) {
+                        $display_vlan = $new_info['vlan'];
+                    }
+                    if (!empty($new_info['untagged_vlan'])) {
+                        if ($new_info['untagged_vlan'] != $new_info['vlan']) {
                             $pattern = '/(\d+),(\d+),(\d+),(\d+),(\d+),/';
                             $replacement = '${1},${2},${3},${4},${5}<br>U:';
                             $display_untagged = preg_replace($pattern, $replacement, $new_info['untagged_vlan']);
-                            $display_vlan.=";U:".$display_untagged; 
-                            }
+                            $display_vlan .= ";U:" . $display_untagged;
                         }
-                    if (!empty($new_info['tagged_vlan'])) { 
+                    }
+                    if (!empty($new_info['tagged_vlan'])) {
                         $pattern = '/(\d+),(\d+),(\d+),(\d+),(\d+),/';
                         $replacement = '${1},${2},${3},${4},${5}<br>T:';
                         $display_tagged = preg_replace($pattern, $replacement, $new_info['tagged_vlan']);
-                        $display_vlan.=";T:".$display_tagged; 
-                        }
+                        $display_vlan .= ";T:" . $display_tagged;
+                    }
                 }
                 //interface name
-                if (!empty($ifmib_list[$row['snmp_index']])) { $ifname = $ifmib_list[$row['snmp_index']]; }
-                if (!isset($row['ifName']) or $row['ifName'] !== $ifname) { $new_info['ifName'] = $ifname; }
+                if (!empty($ifmib_list[$row['snmp_index']])) {
+                    $ifname = $ifmib_list[$row['snmp_index']];
+                }
+                if (!isset($row['ifName']) or $row['ifName'] !== $ifname) {
+                    $new_info['ifName'] = $ifname;
+                }
             }
 
             //fix port information
@@ -279,7 +305,7 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
                 $snmp_url = $ifname;
             } else {
                 if (isset($f_cacti_url)) {
-                    $snmp_url = "<a href=\"#\" onclick=\"".open_window_url($f_cacti_url)."return false;\">" . $ifname . "</a>";
+                    $snmp_url = "<a href=\"#\" onclick=\"" . open_window_url($f_cacti_url) . "return false;\">" . $ifname . "</a>";
                 }
                 if (!empty(get_const('torrus_url'))) {
                     $normed_ifname = str_replace("/", "_", $ifname);
@@ -287,7 +313,7 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
                     $normed_ifname = trim(str_replace(" ", "_", $normed_ifname));
                     $t_url = str_replace("HOST_IP", $device['ip'], get_const('torrus_url'));
                     $t_url = str_replace("IF_NAME", $normed_ifname, $t_url);
-                    $snmp_url = "<a href=\"#\" onclick=\"".open_window_url($t_url)."return false;\">" . $ifname . "</a>";
+                    $snmp_url = "<a href=\"#\" onclick=\"" . open_window_url($t_url) . "return false;\">" . $ifname . "</a>";
                 }
             }
 
@@ -331,9 +357,9 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
             }
 
             print "<td class=\"$cl_error\">" . $perrors . "</td>\n";
-                    $snmp_url = "<a href=\"#\" onclick=\"".open_window_url($f_cacti_url)." return false;\">" . $ifname . "</a>";
+            $snmp_url = "<a href=\"#\" onclick=\"" . open_window_url($f_cacti_url) . " return false;\">" . $ifname . "</a>";
 
-            print "<td class='" . $cl . "' ><button onclick=\"". open_window_url('portmactable.php?id='.$row['id'])." return false;\">" . $row['last_mac_count'] . "</button></td>\n";
+            print "<td class='" . $cl . "' ><button onclick=\"" . open_window_url('portmactable.php?id=' . $row['id']) . " return false;\">" . $row['last_mac_count'] . "</button></td>\n";
 
             print "<td class='" . $cl . "'>" . $sfp_status . " " . $poe_info . "</td>\n";
             if ($device_model['poe_out']) {
@@ -351,7 +377,9 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
                     }
                     print "</td>\n";
                 } else {
-                    print "<td class=\"data\">"; print WEB_msg_unsupported; print "</td>\n";
+                    print "<td class=\"data\">";
+                    print WEB_msg_unsupported;
+                    print "</td>\n";
                 }
             }
             if (isset($padmin) and !$row['uplink'] and !$row['skip']) {
@@ -393,6 +421,6 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
         print "<tr><td class=\"speed10M\">" . WEB_port_speed_10 . "</td><td class=\"speed100M\">" . WEB_port_speed_100 . "</td><td class=\"speed1G\">" . WEB_port_speed_1G . "</td><td class=\"speed10G\">" . WEB_port_speed_10G . "</td><tr>\n";
         print "</table>\n";
         print "</form>";
-        unset_lock_discovery($db_link,$id);
+        unset_lock_discovery($db_link, $id);
         require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.small.php");
         ?>

文件差异内容过多而无法显示
+ 394 - 1863
html/inc/common.php


+ 1712 - 0
html/inc/snmp.php

@@ -0,0 +1,1712 @@
+<?php
+
+if (!defined("CONFIG")) die("Not defined");
+
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/consts.php");
+
+function get_ifmib_index_table($ip, $snmp)
+{
+    $ifmib_map = NULL;
+
+    $is_mikrotik = walk_snmp($ip, $snmp, MIKROTIK_DHCP_SERVER);
+    $mk_ros_version = 0;
+
+    if ($is_mikrotik) {
+        $mikrotik_version = walk_snmp($ip, $snmp, MIKROTIK_ROS_VERSION);
+        $mk_ros_version = 6491;
+        $result = preg_match('/RouterOS\s+(\d)\.(\d{1,3})\.(\d{1,3})\s+/', $mikrotik_version[MIKROTIK_ROS_VERSION], $matches);
+        if ($result) {
+            $mk_ros_version = $matches[1] * 1000 + $matches[2] * 10 + $matches[3];
+        }
+    }
+
+    if ($mk_ros_version == 0 or $mk_ros_version > 6468) {
+        #fdb_index => snmp_index
+        $index_map_table = walk_snmp($ip, $snmp, IFMIB_IFINDEX_MAP);
+        #get map snmp interfaces to fdb table
+        if (isset($index_map_table) and count($index_map_table) > 0) {
+            foreach ($index_map_table as $key => $value) {
+                $key = trim($key);
+                $value = intval(trim(str_replace('INTEGER:', '', $value)));
+                $result = preg_match('/\.(\d{1,10})$/', $key, $matches);
+                if ($result) {
+                    $fdb_index = preg_replace('/^\./', '', $matches[0]);
+                    $ifmib_map[$fdb_index] = $value;
+                }
+            }
+        }
+    }
+
+    #return simple map snmp_port_index = snmp_port_index
+    if (empty($ifmib_map)) {
+        #ifindex
+        $index_table = walk_snmp($ip, $snmp, IFMIB_IFINDEX);
+        if (isset($index_table) and count($index_table) > 0) {
+            foreach ($index_table as $key => $value) {
+                $key = trim($key);
+                $value = intval(trim(str_replace('INTEGER:', '', $value)));
+                $result = preg_match('/\.(\d{1,10})$/', $key, $matches);
+                if ($result) {
+                    $fdb_index = preg_replace('/^\./', '', $matches[0]);
+                    $ifmib_map[$fdb_index] = $value;
+                }
+            }
+        }
+    }
+    return $ifmib_map;
+}
+
+#get mac table by selected snmp oid
+function get_mac_table($ip, $snmp, $oid, $index_map)
+{
+    if (!isset($ip)) {
+        return;
+    }
+
+    if (!isset($oid)) {
+        return;
+    }
+
+    $mac_table = walk_snmp($ip, $snmp, $oid);
+    if (isset($mac_table) and gettype($mac_table) == 'array' and count($mac_table) > 0) {
+        foreach ($mac_table as $key => $value) {
+            if (empty($value)) {
+                continue;
+            }
+            if (empty($key)) {
+                continue;
+            }
+            $key = trim($key);
+            $value_raw = intval(trim(str_replace('INTEGER:', '', $value)));
+            if (empty($value_raw)) {
+                continue;
+            }
+            if (!empty($index_map)) {
+                if (empty($index_map[$value_raw])) {
+                    $value = $value_raw;
+                } else {
+                    $value = $index_map[$value_raw];
+                }
+            } else {
+                $value = $value_raw;
+            }
+            $pattern = '/\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/';
+            $result = preg_match($pattern, $key, $matches);
+            if (!empty($result)) {
+                $mac_key = preg_replace('/^\./', '', $matches[0]);
+                $fdb_table[$mac_key] = $value;
+            }
+        }
+    }
+    return $fdb_table;
+}
+
+#get ip interfaces
+function getIpAdEntIfIndex($db, $ip, $snmp)
+{
+    if (!isset($ip)) {
+        return;
+    }
+    #oid+ip = index
+    $ip_table = walk_snmp($ip, $snmp, ipAdEntIfIndex);
+    #oid+index=name
+    $int_table = walk_snmp($ip, $snmp, ifDescr);
+    $result = [];
+    if (isset($ip_table) and gettype($ip_table) == 'array' and count($ip_table) > 0) {
+        foreach ($ip_table as $key => $value) {
+            if (empty($value)) {
+                continue;
+            }
+            if (empty($key)) {
+                continue;
+            }
+            $key = trim($key);
+            $interface_index = intval(trim(str_replace('INTEGER:', '', $value)));
+            if (empty($value)) {
+                continue;
+            }
+            $interface_name = $int_table[ifDescr . '.' . $interface_index];
+            $interface_name = trim(str_replace('STRING:', '', $interface_name));
+            $interface_ip = trim(str_replace(ipAdEntIfIndex . '.', '', $key));
+            if (empty($interface_name)) {
+                continue;
+            }
+            $result[$interface_index]['ip'] = $interface_ip;
+            $result[$interface_index]['index'] = $interface_index;
+            $result[$interface_index]['name'] = $interface_name;
+            //type: 0 - local, 1 - WAN
+            $result[$interface_index]['type'] = 1;
+            if (is_our_network($db, $interface_ip)) {
+                $result[$interface_index]['type'] = 0;
+            }
+        }
+    }
+    return $result;
+}
+
+#get mac table by analyze all available tables
+function get_fdb_table($ip, $snmp)
+{
+
+    if (!isset($ip)) {
+        return;
+    }
+
+    $ifindex_map = get_ifmib_index_table($ip, $snmp);
+    $fdb1_table = get_mac_table($ip, $snmp, MAC_TABLE_OID, $ifindex_map);
+    if (!empty($fdb1_table)) {
+        $fdb_table = $fdb1_table;
+    } else {
+        $fdb2_table = get_mac_table($ip, $snmp, MAC_TABLE_OID2, $ifindex_map);
+        if (!empty($fdb2_table)) {
+            $fdb_table = $fdb2_table;
+        }
+    }
+
+    $snmp_cisco = $snmp;
+
+    // maybe cisco?!
+    if (!isset($fdb_table) or empty($fdb_table) or count($fdb_table) == 0) {
+        $vlan_table = walk_snmp($ip, $snmp, CISCO_VLAN_OID);
+        if (empty($vlan_table)) {
+            return;
+        }
+        foreach ($vlan_table as $vlan_oid => $value) {
+            if (empty($vlan_oid)) {
+                continue;
+            }
+            $pattern = '/\.(\d{1,4})$/';
+            $result = preg_match($pattern, $vlan_oid, $matches);
+            if (!empty($result)) {
+                $vlan_id = preg_replace('/^\./', '', $matches[0]);
+                if ($vlan_id > 1000 and $vlan_id < 1009) {
+                    continue;
+                }
+                $snmp_cisco["ro-community"] = $snmp["ro-community"] . '@' . $vlan_id;
+                $fdb_vlan_table = get_mac_table($ip, $snmp_cisco, MAC_TABLE_OID, $ifindex_map);
+                if (!isset($fdb_vlan_table) or !$fdb_vlan_table or count($fdb_vlan_table) == 0) {
+                    $fdb_vlan_table = get_mac_table($ip, $snmp_cisco, MAC_TABLE_OID2, $ifindex_map);
+                }
+                foreach ($fdb_vlan_table as $mac => $port) {
+                    if (!isset($mac)) {
+                        continue;
+                    }
+                    $fdb_table[$mac] = $port;
+                }
+            }
+        }
+    }
+    return $fdb_table;
+}
+
+function check_snmp_access($ip, $snmp)
+{
+    if (!isset($ip)) {
+        return;
+    }
+    #check host up
+    $status = exec(escapeshellcmd("ping -W 1 -i 1 -c 3 " . $ip));
+    if (empty($status)) {
+        return;
+    }
+    #check snmp
+    $result = get_snmp($ip, $snmp, SYS_DESCR_MIB);
+    if (empty($result)) {
+        return;
+    }
+    return 1;
+}
+
+function get_port_state($port, $ip, $snmp)
+{
+    if (!isset($port)) {
+        return;
+    }
+    if (!isset($ip)) {
+        return;
+    }
+    $port_oid = PORT_STATUS_OID . '.' . $port;
+    $port_state = get_snmp($ip, $snmp, $port_oid);
+    return $port_state;
+}
+
+
+function get_last_digit($oid)
+{
+    if (!isset($oid)) {
+        return;
+    }
+    $pattern = '/\.(\d{1,})$/';
+    preg_match($pattern, $oid, $matches);
+    return $matches[1];
+}
+
+function get_cisco_sensors($ip, $snmp, $mkey)
+{
+    $index = get_last_digit($mkey);
+    $result = parse_snmp_value(get_snmp($ip, $snmp, CISCO_SFP_SENSORS . "." . $index));
+    $prec = parse_snmp_value(get_snmp($ip, $snmp, CISCO_SFP_PRECISION . "." . $index));
+    if (!isset($prec)) {
+        $prec = 1;
+    }
+    $result = round(trim($result) / (10 * $prec), 2);
+    return $result;
+}
+
+function get_snmp_ifname($ip, $snmp, $port)
+{
+    $port_name = parse_snmp_value(get_snmp($ip, $snmp, IFMIB_IFNAME . "." . $port));
+    if (empty($port_name)) {
+        $port_name = parse_snmp_value(get_snmp($ip, $snmp, IFMIB_IFDESCR . "." . $port));
+    }
+    if (empty($port_name)) {
+        $port_name = parse_snmp_value(get_snmp($ip, $snmp, IFMIB_IFALIAS . "." . $port));
+    }
+    return $port_name;
+}
+
+
+function get_snmp_interfaces($ip, $snmp)
+{
+    $result = [];
+    $ifmib_list = walk_snmp($ip, $snmp, IFMIB_IFNAME);
+    if (empty($ifmib_list)) {
+        $ifmib_list = walk_snmp($ip, $snmp, IFMIB_IFDESCR);
+    }
+    if (empty($ifmib_list)) {
+        $ifmib_list = walk_snmp($ip, $snmp, IFMIB_IFALIAS);
+    }
+    if (!empty($ifmib_list)) {
+        foreach ($ifmib_list as $key => $value) {
+            $key = trim($key);
+            $value = parse_snmp_value($value);
+            if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                $int_index = preg_replace('/^\./', '', $matches[0]);
+                $result[$int_index] = $value;
+            }
+        }
+    }
+    return $result;
+}
+
+function walk_snmp($ip, $snmp, $oid)
+{
+    snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
+    $result = NULL;
+    $version = $snmp["version"];
+    if ($version == 3) {
+        $result = snmp3_real_walk($ip, $snmp["ro-user"], 'authPriv', $snmp['auth-proto'], $snmp['ro-password'], $snmp["priv-proto"], $snmp["ro-password"], $oid, SNMP_timeout, SNMP_retry);
+    }
+    if ($version == 2) {
+        $result = snmp2_real_walk($ip,  $snmp["ro-community"], $oid, SNMP_timeout, SNMP_retry);
+    }
+    if ($version == 1) {
+        $result = snmprealwalk($ip,  $snmp["ro-community"], $oid, SNMP_timeout, SNMP_retry);
+    }
+    return $result;
+}
+
+function getSnmpAccess($device)
+{
+    $result['port']         = 161;
+    $result['version']      = $device['snmp_version'];
+    $result['ro-community'] = $device['community'];
+    $result['rw-community'] = $device['rw_community'];
+    #snmpv3
+    $result['auth-proto']   = $device['snmp3_auth_proto'];
+    $result['priv-proto']   = $device['snmp3_priv_proto'];
+    $result['ro-user']      = $device['snmp3_user_ro'];
+    $result['rw-user']      = $device['snmp3_user_rw'];
+    $result['ro-password']  = $device['snmp3_user_ro_password'];
+    $result['rw-password']  = $device['snmp3_user_rw_password'];
+    if ($result['auth-proto'] === 'sha1') {
+        $result['auth-proto'] = 'sha';
+    }
+    return $result;
+}
+
+function get_snmp_module_id($modules_oids, $port_name)
+{
+    $port_name = preg_quote(trim($port_name), '/');
+    foreach ($modules_oids as $key => $value) {
+        $pattern = '/' . $port_name . '/i';
+        preg_match($pattern, $value, $matches);
+        if (isset($matches[0])) {
+            $module_id = get_last_digit($key);
+            return $module_id;
+        }
+    }
+    return;
+}
+
+function get_sfp_status($vendor_id, $port, $ip, $snmp, $modules_oids)
+{
+    if (!isset($vendor_id)) {
+        return;
+    }
+    if (!isset($port)) {
+        return;
+    }
+    if (!isset($ip)) {
+        return;
+    }
+
+    try {
+        $status = '';
+        // eltex
+        if ($vendor_id == 2) {
+            $sfp_vendor = parse_snmp_value(get_snmp($ip, $snmp, ELTEX_SFP_VENDOR . "." . $port));
+            if (!empty($sfp_vendor)) {
+                $sfp_status_temp = ELTEX_SFP_STATUS . "." . $port . ".5";
+                $sfp_status_volt = ELTEX_SFP_STATUS . "." . $port . ".6";
+                $sfp_status_circut = ELTEX_SFP_STATUS . "." . $port . ".7";
+                $sfp_status_tx = ELTEX_SFP_STATUS . "." . $port . ".8";
+                $sfp_status_rx = ELTEX_SFP_STATUS . "." . $port . ".9";
+                $temp = parse_snmp_value(get_snmp($ip, $snmp, $sfp_status_temp));
+                $volt = parse_snmp_value(get_snmp($ip, $snmp, $sfp_status_volt));
+                $circut = parse_snmp_value(get_snmp($ip, $snmp, $sfp_status_circut));
+                $tx = parse_snmp_value(get_snmp($ip, $snmp, $sfp_status_tx));
+                $rx = parse_snmp_value(get_snmp($ip, $snmp, $sfp_status_rx));
+                $sfp_sn = parse_snmp_value(get_snmp($ip, $snmp, ELTEX_SFP_SN . "." . $port));
+                $sfp_freq = parse_snmp_value(get_snmp($ip, $snmp, ELTEX_SFP_FREQ . "." . $port));
+                if (!isset($sfp_freq) or $sfp_freq == 65535) {
+                    $sfp_freq = 'unspecified';
+                }
+                $sfp_length = parse_snmp_value(get_snmp($ip, $snmp, ELTEX_SFP_LENGTH . "." . $port));
+                $status = 'Vendor: ' . $sfp_vendor . ' Serial: ' . $sfp_sn . ' Laser: ' . $sfp_freq . ' Distance: ' . $sfp_length . '<br>';
+                if (!empty($sfp_status_temp) and $temp > 0.1) {
+                    $status .= 'Temp: ' . $temp . " C";
+                }
+                if (!empty($sfp_status_volt) and $volt > 0.1) {
+                    $status .= ' Volt: ' . round($volt / 1000000, 2) . ' V';
+                }
+                if (!empty($sfp_status_circut) and $circut > 0.1) {
+                    $status .= ' Circut: ' . round($circut / 1000, 2) . ' mA';
+                }
+                if (!empty($sfp_status_tx) and $tx > 0.1) {
+                    $status .= ' Tx: ' . round($tx / 1000, 2) . ' dBm';
+                }
+                if (!empty($sfp_status_rx) and $rx > 0.1) {
+                    $status .= ' Rx: ' . round($rx / 1000, 2) . ' dBm';
+                }
+                $status .= '<br>';
+                return $status;
+            }
+            return;
+        }
+
+        // snr
+        if ($vendor_id == 6) {
+            $sfp_vendor = parse_snmp_value(get_snmp($ip, $snmp, SNR_SFP_VendorName . "." . $port));
+            if (!empty($sfp_vendor) and $sfp_vendor != 'NULL') {
+                $oid_sfp_model_name = SNR_SFP_ModelName . "." . $port;
+                $oid_sfp_type_name = SNR_SFP_TypeName . "." . $port;
+                $oid_sfp_bitrate = SNR_SFP_BitRate . "." . $port;
+                $oid_sfp_status_volt = SNR_SFP_VOLT . "." . $port;
+                $oid_sfp_status_circut = SNR_SFP_BIAS . "." . $port;
+                $oid_sfp_status_tx = SNR_SFP_TX . "." . $port;
+                $oid_sfp_status_rx = SNR_SFP_RX . "." . $port;
+                $oid_sfp_length = SNR_SFP_WaveLength . "." . $port;
+
+                $volt = parse_snmp_value(get_snmp($ip, $snmp, $oid_sfp_status_volt));
+                $circut = parse_snmp_value(get_snmp($ip, $snmp, $oid_sfp_status_circut));
+                $tx = parse_snmp_value(get_snmp($ip, $snmp, $oid_sfp_status_tx));
+                $rx = parse_snmp_value(get_snmp($ip, $snmp, $oid_sfp_status_rx));
+                $sfp_model_name = parse_snmp_value(get_snmp($ip, $snmp, $oid_sfp_model_name));
+                $sfp_type_name = parse_snmp_value(get_snmp($ip, $snmp, $oid_sfp_type_name));
+                $sfp_freq = parse_snmp_value(get_snmp($ip, $snmp, $oid_sfp_bitrate));
+                $sfp_length = parse_snmp_value(get_snmp($ip, $snmp, $oid_sfp_length));
+
+                $status = 'Vendor: ' . $sfp_vendor . ' ' . $sfp_model_name . ' ' . $sfp_type_name . ' Speed: ' . $sfp_freq . ' Freq: ' . $sfp_length . '<br>';
+                if (!empty($sfp_status_volt) and $volt > 0.1) {
+                    $status .= ' Volt: ' . round($volt / 1000000, 2) . ' V';
+                }
+                if (!empty($sfp_status_circut) and $circut > 0.1) {
+                    $status .= ' Circut: ' . round($circut / 1000, 2) . ' mA';
+                }
+                if (!empty($sfp_status_tx) and $tx > 0.1) {
+                    $status .= ' Tx: ' . round($tx / 1000, 2) . ' dBm';
+                }
+                if (!empty($sfp_status_rx) and $rx > 0.1) {
+                    $status .= ' Rx: ' . round($rx / 1000, 2) . ' dBm';
+                }
+                $status .= '<br>';
+                return $status;
+            }
+            return;
+        }
+
+        // cisco
+        if ($vendor_id == 16) {
+            // get interface names
+            $port_name = parse_snmp_value(get_snmp($ip, $snmp, IFMIB_IFNAME . "." . $port));
+            if (empty($port_name)) {
+                $port_name = parse_snmp_value(get_snmp($ip, $snmp, IFMIB_IFDESCR . "." . $port));
+            }
+            // search module indexes
+            $port_name = preg_quote(trim($port_name), '/');
+            foreach ($modules_oids as $key => $value) {
+                $pattern = '/(' . $port_name . ' Module Temperature Sensor)/i';
+                preg_match($pattern, $value, $matches);
+                if (isset($matches[0])) {
+                    $temp = get_cisco_sensors($ip, $snmp, $key);
+                    continue;
+                }
+                $pattern = '/(' . $port_name . ' Supply Voltage Sensor)/i';
+                preg_match($pattern, $value, $matches);
+                if (isset($matches[0])) {
+                    $volt = get_cisco_sensors($ip, $snmp, $key);
+                    continue;
+                }
+                $pattern = '/(' . $port_name . ' Bias Current Sensor)/i';
+                preg_match($pattern, $value, $matches);
+                if (isset($matches[0])) {
+                    $circut = get_cisco_sensors($ip, $snmp, $key);
+                    continue;
+                }
+                $pattern = '/(' . $port_name . ' Transmit Power Sensor)/i';
+                preg_match($pattern, $value, $matches);
+                if (isset($matches[0])) {
+                    $tx = get_cisco_sensors($ip, $snmp, $key);
+                    continue;
+                }
+                $pattern = '/(' . $port_name . ' Receive Power Sensor)/i';
+                preg_match($pattern, $value, $matches);
+                if (isset($matches[0])) {
+                    $rx = get_cisco_sensors($ip, $snmp, $key);
+                    continue;
+                }
+            }
+            if (!empty($temp) and $temp > 0) {
+                $status .= 'Temp: ' . $temp . " C";
+            }
+            if (!empty($volt) and $volt > 0) {
+                $status .= ' Volt: ' . $volt . ' V';
+            }
+            if (!empty($circut) and $circut > 0) {
+                $status .= ' Circut: ' . $circut . ' mA';
+            }
+            if (!empty($tx) and abs($tx) > 0.1) {
+                $status .= ' Tx: ' . $tx . ' dBm';
+            }
+            if (!empty($rx) and abs($rx) > 0.1) {
+                $status .= ' Rx: ' . $rx . ' dBm';
+            }
+            if (!empty($status)) {
+                $status = preg_replace('/"/', '', $status);
+                $status .= '<br>';
+            }
+            return $status;
+        }
+
+        // huawei
+        if ($vendor_id == 3) {
+
+            // get interface names
+            $port_name = parse_snmp_value(get_snmp($ip, $snmp, IFMIB_IFNAME . "." . $port));
+            if (empty($port_name)) {
+                $port_name = parse_snmp_value(get_snmp($ip, $snmp, IFMIB_IFDESCR . "." . $port));
+            }
+            // search module indexes
+            $port_name = preg_quote(trim($port_name), '/');
+            foreach ($modules_oids as $key => $value) {
+                $pattern = '/' . $port_name . '/i';
+                preg_match($pattern, $value, $matches);
+                if (isset($matches[0])) {
+                    $module_id = get_last_digit($key);
+                    unset($result);
+                    $result = parse_snmp_value(get_snmp($ip, $snmp, HUAWEI_SFP_VENDOR . "." . $module_id));
+                    if (!empty($result)) {
+                        $sfp_vendor = $result;
+                    }
+                    unset($result);
+                    $result = parse_snmp_value(get_snmp($ip, $snmp, HUAWEI_SFP_SPEED . "." . $module_id));
+                    if (!empty($result)) {
+                        list($sfp_speed, $spf_lenght, $sfp_type) = explode('-', $result);
+                        if ($sfp_type == 0) {
+                            $sfp_type = 'MultiMode';
+                        }
+                        if ($sfp_type == 1) {
+                            $sfp_type = 'SingleMode';
+                        }
+                    }
+
+                    $volt = parse_snmp_value(get_snmp($ip, $snmp, HUAWEI_SFP_VOLT . "." . $module_id));
+                    $circut = parse_snmp_value(get_snmp($ip, $snmp, HUAWEI_SFP_BIASCURRENT . "." . $module_id));
+                    $tx = parse_snmp_value(get_snmp($ip, $snmp, HUAWEI_SFP_OPTTX . "." . $module_id));
+                    $rx = parse_snmp_value(get_snmp($ip, $snmp, HUAWEI_SFP_OPTRX . "." . $module_id));
+                    if (!isset($tx)) {
+                        $tx = parse_snmp_value(get_snmp($ip, $snmp, HUAWEI_SFP_TX . "." . $module_id));
+                    }
+                    if (!isset($rx)) {
+                        $rx = parse_snmp_value(get_snmp($ip, $snmp, HUAWEI_SFP_RX . "." . $module_id));
+                    }
+                    if (!empty($sfp_vendor)) {
+                        $status .= ' Name:' . $sfp_vendor . '<br>';
+                    }
+                    //                if (isset($sfp_speed)) { $status .= ' ' . $sfp_speed; }
+                    //                if (isset($spf_lenght)) { $status .= ' ' . $spf_lenght; }
+                    if ($volt > 0) {
+                        $status .= ' Volt: ' . round($volt / 1000, 2) . ' V';
+                    }
+                    if (!empty($circut) and $circut > 0) {
+                        $status .= ' Circut: ' . $circut . ' mA <br>';
+                    }
+                    if (!empty($tx)) {
+                        $tx = preg_replace('/"/', '', $tx);
+                        try {
+                            list($tx_dbm, $pattern) = explode('.', $tx);
+                            $tx_dbm = round(floatval(trim($tx_dbm)) / 100, 2);
+                        } catch (Exception $e) {
+                            $tx_dbm = 0;
+                        }
+                        if (abs($tx_dbm) > 0.1) {
+                            $status .= ' Tx: ' . $tx_dbm . ' dBm';
+                        }
+                    }
+                    if (!empty($rx)) {
+                        $rx = preg_replace('/"/', '', $rx);
+                        try {
+                            list($rx_dbm, $pattern) = explode('.', $rx);
+                            $rx_dbm = round(floatval(trim($rx_dbm)) / 100, 2);
+                        } catch (Exception $e) {
+                            $rx_dbm = 0;
+                        }
+                        if (abs($rx_dbm) > 0.1) {
+                            $status .= ' Rx: ' . $rx_dbm . ' dBm';
+                        }
+                    }
+
+                    break;
+                }
+            }
+            if (isset($status)) {
+                $status = preg_replace('/"/', '', $status);
+                $status .= '<br>';
+            }
+            return $status;
+        }
+    } catch (Exception $e) {
+        return;
+    }
+}
+
+
+function get_switch_vlans($vendor, $ip, $snmp)
+{
+
+    $switch_vlans = [];
+    $port_status  = [];
+    $vlan_status  = [];
+
+    //cisco...
+    if ($vendor == 16) {
+        //all vlan at switch
+        $vlan_list = walk_snmp($ip, $snmp, vtpVlanName);
+        if (empty($vlan_list)) {
+            return;
+        }
+        foreach ($vlan_list as $key => $value) {
+            if (empty($value)) {
+                $value = '';
+            }
+            $key = trim($key);
+            $value = parse_snmp_value($value);
+            $vlan_id = NULL;
+            if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                $vlan_id = preg_replace('/^\./', '', $matches[0]);
+            }
+            //skip service vlan
+            if (preg_match('/(1002|1003|1004|1005)/', $vlan_id)) {
+                continue;
+            }
+            if (isset($vlan_id) and !empty($vlan_id)) {
+                $switch_vlans[$vlan_id] = $value;
+            }
+        }
+
+        //native vlan for port - get list of all ports
+        $pvid_list = walk_snmp($ip, $snmp, vlanTrunkPortNativeVlan);
+        if (!empty($pvid_list)) {
+            foreach ($pvid_list as $key => $value) {
+                if (empty($value)) {
+                    $value = '';
+                }
+                $key = trim($key);
+                $value = parse_snmp_value($value);
+                $port = NULL;
+                if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                    $port = preg_replace('/^\./', '', $matches[0]);
+                }
+                if (isset($port) and !empty($port)) {
+                    $port_status[$port]['native'] = $value;
+                }
+            }
+        }
+
+        //pvid
+        $pvid_list = walk_snmp($ip, $snmp, vmVlanPvid);
+        if (!empty($pvid_list)) {
+            foreach ($pvid_list as $key => $value) {
+                if (empty($value)) {
+                    $value = '';
+                }
+                $key = trim($key);
+                $value = parse_snmp_value($value);
+                $port = NULL;
+                if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                    $port = preg_replace('/^\./', '', $matches[0]);
+                }
+                if (isset($port) and !empty($port)) {
+                    $port_status[$port]['pvid'] = $value;
+                }
+            }
+        }
+
+        //init port config
+        foreach ($port_status as &$port) {
+            if (!is_array($port)) {
+                continue;
+            }
+            if (!isset($port['pvid'])) {
+                $port['pvid'] = $port['native'];
+            }
+            $port['untagged'] = '';
+            $port['tagged'] = '';
+        }
+        unset($port);
+
+        //get vlan list at ports
+        $egress_vlan = walk_snmp($ip, $snmp, vlanTrunkPortVlansEnabled);
+        if (!empty($egress_vlan)) {
+            $j = 0;
+            foreach ($egress_vlan as $key => $value) {
+                $j++;
+                if (empty($value)) {
+                    $value = '';
+                }
+                $key = trim($key);
+                $value = parse_snmp_value($value);
+                if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                    $port = preg_replace('/^\./', '', $matches[0]);
+                }
+                if (isset($port) and !empty($port)) {
+                    //skip access ports
+                    if (!is_array($port_status[$port]) or !isset($port_status[$port]['pvid']) or !isset($port_status[$port]['native'])) {
+                        continue;
+                    }
+                    if ($port_status[$port]['pvid'] != $port_status[$port]['native']) {
+                        continue;
+                    }
+                    //get vlan at port in hex
+                    $hex_value = preg_replace('/\s+/', '', $value);
+                    $bin_value = strHexToBin($hex_value);
+                    //analyze switch vlans
+                    foreach ($switch_vlans as $vlan_id => $vlan_name) {
+                        if (isset($bin_value[$vlan_id]) and $bin_value[$vlan_id] == '1') {
+                            $port_status[$port]['tagged'] = $port_status[$port]['tagged'] . ',' . $vlan_id;
+                        }
+                    }
+                }
+            }
+        }
+
+        //remove lliding ,
+        foreach ($port_status as &$port) {
+            if (!is_array($port)) {
+                continue;
+            }
+            $port['untagged'] = preg_replace('/^,/', '', $port['untagged']);
+            $port['tagged'] = preg_replace('/^,/', '', $port['tagged']);
+        }
+        unset($port);
+
+        return $port_status;
+    }
+
+    //standart switches
+
+    //tplink
+    if ($vendor == 69) {
+        //pvid for port
+        $pvid_list = walk_snmp($ip, $snmp, TPLINK_dot1qPortVlanEntry);
+        if (!empty($pvid_list)) {
+            foreach ($pvid_list as $key => $value) {
+                if (empty($value)) {
+                    $value = '';
+                }
+                $key = trim($key);
+                $value = parse_snmp_value($value);
+                $port = NULL;
+                if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                    $port = preg_replace('/^\./', '', $matches[0]);
+                }
+                if (isset($port) and !empty($port)) {
+                    $port_status[$port]['pvid'] = $value;
+                }
+            }
+        }
+        return $port_status;
+    }
+
+    //default
+    //pvid for port
+    $pvid_list = walk_snmp($ip, $snmp, dot1qPortVlanEntry);
+    if (!empty($pvid_list)) {
+        foreach ($pvid_list as $key => $value) {
+            if (empty($value)) {
+                $value = '';
+            }
+            $key = trim($key);
+            $value = parse_snmp_value($value);
+            $port = NULL;
+            if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                $port = preg_replace('/^\./', '', $matches[0]);
+            }
+            if (isset($port) and !empty($port)) {
+                $port_status[$port]['pvid'] = $value;
+            }
+        }
+    }
+
+    //init port config
+    foreach ($port_status as &$port) {
+        if (!is_array($port)) {
+            continue;
+        }
+        $port['native'] = $port['pvid'];
+        $port['untagged'] = '';
+        $port['tagged'] = '';
+    }
+    unset($port);
+
+    //all vlan at switch
+    $vlan_list = walk_snmp($ip, $snmp, dot1qVlanStaticName);
+    if (empty($vlan_list)) {
+        return $port_status;
+    }
+    foreach ($vlan_list as $key => $value) {
+        if (empty($value)) {
+            $value = '';
+        }
+        $key = trim($key);
+        $value = parse_snmp_value($value);
+        $vlan_id = NULL;
+        if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+            $vlan_id = preg_replace('/^\./', '', $matches[0]);
+        }
+        if (isset($vlan_id) and !empty($vlan_id)) {
+            $switch_vlans[$vlan_id] = $value;
+        }
+    }
+
+    $forbidden_vlan = walk_snmp($ip, $snmp, dot1qVlanForbiddenEgressPorts);
+    if (!empty($forbidden_vlan)) {
+        foreach ($forbidden_vlan as $key => $value) {
+            if (empty($value)) {
+                $value = '';
+            }
+            $key = trim($key);
+            $value = parse_snmp_value($value);
+            if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                $vlan_id = preg_replace('/^\./', '', $matches[0]);
+            }
+            if (isset($vlan_id) and !empty($vlan_id)) {
+                $hex_value = preg_replace('/\s+/', '', $value);
+                $hex_value = preg_replace('/0*$/', '', $hex_value);
+                $bin_value = strHexToBin($hex_value);
+                for ($i = 0; $i < strlen($bin_value); $i++) {
+                    $port = $i + 1;
+                    $vlan_status['forbidden_vlan'][$vlan_id][$port] = $bin_value[$i];
+                    if ($bin_value[$i] == '1') {
+                        $port_status[$port]['forbidden'] .= ',' . $vlan_id;
+                    }
+                }
+            }
+        }
+    }
+    $untagged_vlan = walk_snmp($ip, $snmp, dot1qVlanStaticUntaggedPorts);
+    if (!empty($untagged_vlan)) {
+        foreach ($untagged_vlan as $key => $value) {
+            if (empty($value)) {
+                $value = '';
+            }
+            $key = trim($key);
+            $value = parse_snmp_value($value);
+            if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                $vlan_id = preg_replace('/^\./', '', $matches[0]);
+            }
+            if (isset($vlan_id) and !empty($vlan_id)) {
+                $hex_value = preg_replace('/\s+/', '', $value);
+                $hex_value = preg_replace('/0*$/', '', $hex_value);
+                $bin_value = strHexToBin($hex_value);
+                for ($i = 0; $i < strlen($bin_value); $i++) {
+                    $port = $i + 1;
+                    $vlan_status['untagged_vlan'][$vlan_id][$port] = $bin_value[$i];
+                    if ($bin_value[$i] == '1') {
+                        if (isset($vlan_status['forbidden_vlan']) and $vlan_status['forbidden_vlan'][$vlan_id][$port] == '0') {
+                            $port_status[$port]['untagged'] .= ',' . $vlan_id;
+                        } else {
+                            $vlan_status['untagged_vlan'][$vlan_id][$port] = '0';
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    $egress_vlan = walk_snmp($ip, $snmp, dot1qVlanStaticEgressPorts);
+    if (!empty($egress_vlan)) {
+        foreach ($egress_vlan as $key => $value) {
+            if (empty($value)) {
+                $value = '';
+            }
+            $key = trim($key);
+            $value = parse_snmp_value($value);
+            if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                $vlan_id = preg_replace('/^\./', '', $matches[0]);
+            }
+            //exclude vlan 1 from tagged vlan
+            if ($vlan_id == '1') {
+                continue;
+            }
+            if (isset($vlan_id) and !empty($vlan_id)) {
+                $hex_value = preg_replace('/\s+/', '', $value);
+                $hex_value = preg_replace('/0*$/', '', $hex_value);
+                $bin_value = strHexToBin($hex_value);
+                for ($i = 0; $i < strlen($bin_value); $i++) {
+                    $port = $i + 1;
+                    $vlan_status['egress_vlan'][$vlan_id][$port] = $bin_value[$i];
+                    //analyze egress & untagged vlans
+                    if ($bin_value[$i] == '1') {
+                        if ((!isset($vlan_status['untagged_vlan'][$vlan_id][$port]) or $vlan_status['untagged_vlan'][$vlan_id][$port] == '0') and
+                            (!isset($vlan_status['forbidden_vlan'][$vlan_id][$port]) or $vlan_status['forbidden_vlan'][$vlan_id][$port] == '0') and
+                            (!isset($port_status[$port]['pvid']) or $port_status[$port]['pvid'] != $vlan_id)
+                        ) {
+                            $vlan_status['tagged_vlan'][$vlan_id][$port] = '1';
+                            $port_status[$port]['tagged'] .= ',' . $vlan_id;
+                        } else {
+                            $vlan_status['tagged_vlan'][$vlan_id][$port] = '0';
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    foreach ($port_status as &$port) {
+        if (!is_array($port)) {
+            continue;
+        }
+        $port['untagged'] = preg_replace('/^,/', '', $port['untagged']);
+        $port['tagged'] = preg_replace('/^,/', '', $port['tagged']);
+    }
+    unset($port);
+
+    return $port_status;
+}
+
+
+function get_port_vlan($vendor, $port, $port_index, $ip, $snmp)
+{
+    if (!isset($port_index)) {
+        return;
+    }
+
+    if (!isset($ip)) {
+        return;
+    }
+
+    //default - default port index
+    $port_oid = dot1qPortVlanEntry . "." . $port_index;
+
+    //tplink
+    if ($vendor == 69) {
+        $port_oid = TPLINK_dot1qPortVlanEntry . "." . $port_index;
+    }
+
+    //huawei
+    if ($vendor == 3) {
+        $port_oid = dot1qPortVlanEntry . "." . $port;
+    }
+
+    //allied telesys
+    if ($vendor == 8) {
+        $port_oid = dot1qPortVlanEntry . "." . $port;
+    }
+
+    $port_vlan = get_snmp($ip, $snmp, $port_oid);
+    $port_vlan = preg_replace('/.*\:/', '', $port_vlan);
+    $port_vlan = intval(trim($port_vlan));
+    return $port_vlan;
+}
+
+function get_ports_poe_state($vendor_id, $ip, $snmp)
+{
+
+    if (!isset($vendor_id)) {
+        return;
+    }
+    if (!isset($ip)) {
+        return;
+    }
+
+    // default poe oid
+    $poe_status = PETH_PSE_PORT_ADMIN_ENABLE;
+
+    if ($vendor_id == 3) {
+        $poe_status = HUAWEI_POE_OID;
+    }
+    if ($vendor_id == 6) {
+        $poe_status = SNR_POE_OID;
+    }
+    if ($vendor_id == 8) {
+        $poe_status = ALLIED_POE_OID;
+    }
+    if ($vendor_id == 9) {
+        $poe_status = MIKROTIK_POE_OID;
+    }
+    if ($vendor_id == 10) {
+        $poe_status = NETGEAR_POE_OID;
+    }
+    if ($vendor_id == 15) {
+        $poe_status = HP_POE_OID;
+    }
+    if ($vendor_id == 69) {
+        $poe_status = TPLINK_POE_OID;
+    }
+
+    $result = [];
+
+    $c_state = walk_snmp($ip, $snmp, $poe_status);
+    if (isset($c_state) and !empty($c_state)) {
+        foreach ($c_state as $key => $value) {
+            if (empty($value)) {
+                $value = '';
+            }
+            $key = trim($key);
+            $value = parse_snmp_value($value);
+            $port = NULL;
+            if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                $port = preg_replace('/^\./', '', $matches[0]);
+                $result[$port] = $value;
+                // patch for mikrotik
+                if ($vendor_id == 9) {
+                    if ($value == 1) {
+                        $result[$port] = 2;
+                    }
+                    if ($value > 1) {
+                        $result[$port] = 1;
+                    }
+                }
+                //patch for tplink
+                if ($vendor_id == 69) {
+                    if ($value == 0) {
+                        $result[$port] = 2;
+                    }
+                    if ($value >= 1) {
+                        $result[$port] = 1;
+                    }
+                }
+            }
+        }
+    }
+    return $result;
+}
+
+function get_port_poe_state($vendor_id, $port, $port_snmp_index, $ip, $snmp)
+{
+    if (!isset($port)) {
+        return;
+    }
+    if (!isset($ip)) {
+        return;
+    }
+    // default poe oid
+    $poe_status = PETH_PSE_PORT_ADMIN_ENABLE . "." . $port_snmp_index;
+
+    if ($vendor_id == 3) {
+        $poe_status = HUAWEI_POE_OID . "." . $port_snmp_index;
+    }
+
+    if ($vendor_id == 6) {
+        $poe_status = SNR_POE_OID . "." . $port_snmp_index;
+    }
+
+    if ($vendor_id == 8) {
+        $poe_status = ALLIED_POE_OID . "." . $port_snmp_index;
+    }
+
+    if ($vendor_id == 15) {
+        $poe_status = HP_POE_OID . "." . $port_snmp_index;
+    }
+
+    if ($vendor_id == 9) {
+        $poe_status = MIKROTIK_POE_OID . "." . $port_snmp_index;
+    }
+
+    if ($vendor_id == 10) {
+        $poe_status = NETGEAR_POE_OID . "." . $port_snmp_index;
+    }
+
+    if ($vendor_id == 69) {
+        $poe_status = TPLINK_POE_OID . "." . $port;
+    }
+
+    $result = '';
+    $c_state = get_snmp($ip, $snmp, $poe_status);
+
+    if (isset($c_state) and !empty($c_state)) {
+        $p_state = parse_snmp_value($c_state);
+        if (empty($p_state)) {
+            return NULL;
+        }
+        // patch for mikrotik
+        if ($vendor_id == 9) {
+            if ($p_state == 1) {
+                return 2;
+            }
+            if ($p_state > 1) {
+                return 1;
+            }
+        }
+        //patch for tplink
+        if ($vendor_id == 69) {
+            if ($p_state == 0) {
+                return 2;
+            }
+            if ($p_state >= 1) {
+                return 1;
+            }
+        }
+        return $p_state;
+    }
+    return NULL;
+}
+
+function set_port_poe_state($vendor_id, $port, $port_snmp_index, $ip, $snmp, $state)
+{
+    if (!isset($ip)) {
+        return;
+    }
+
+    //default poe status
+    $poe_enable = 1;
+    $poe_disable = 2;
+
+    // default poe oid
+    $poe_status = PETH_PSE_PORT_ADMIN_ENABLE . "." . $port_snmp_index;
+
+    if ($vendor_id == 3) {
+        $poe_status = HUAWEI_POE_OID . "." . $port_snmp_index;
+    }
+
+    if ($vendor_id == 8) {
+        $poe_status = ALLIED_POE_OID . "." . $port_snmp_index;
+    }
+
+    if ($vendor_id == 15) {
+        $poe_status = HP_POE_OID . "." . $port_snmp_index;
+    }
+
+    if ($vendor_id == 10) {
+        $poe_status = NETGEAR_POE_OID . "." . $port_snmp_index;
+    }
+
+    if ($vendor_id == 69) {
+        $poe_status = TPLINK_POE_OID . "." . $port;
+        $poe_enable = 1;
+        $poe_disable = 0;
+    }
+
+    if ($state) {
+        // enable port
+        $c_state = set_snmp($ip, $snmp, $poe_status, 'i', $poe_enable);
+        return $c_state;
+    } else {
+        // disable port
+        $c_state = set_snmp($ip, $snmp, $poe_status, 'i', $poe_disable);
+        return $c_state;
+    }
+}
+
+
+function get_ports_poe_detail($vendor_id, $ip, $snmp)
+{
+    if (!isset($vendor_id)) {
+        return;
+    }
+
+    if (!isset($ip)) {
+        return;
+    }
+
+    $result = [];
+
+    $poe_class = PETH_PSE_PORT_POE_CLASS;
+
+    // eltex
+    if ($vendor_id == 2) {
+        $poe_power = ELTEX_POE_USAGE;
+        $poe_current = ELTEX_POE_CURRENT;
+        $poe_volt = ELTEX_POE_VOLT;
+    }
+
+    // huawei
+    if ($vendor_id == 3) {
+        $poe_power = HUAWEI_POE_USAGE;
+        $poe_current = HUAWEI_POE_CURRENT;
+        $poe_volt = HUAWEI_POE_VOLT;
+    }
+
+    // snr
+    if ($vendor_id == 6) {
+        $poe_class = SNR_POE_CLASS;
+        $poe_power = SNR_POE_USAGE;
+        $poe_current = SNR_POE_CURRENT;
+        $poe_volt = SNR_POE_VOLT;
+    }
+
+    // AT
+    if ($vendor_id == 8) {
+        $poe_power = ALLIED_POE_USAGE;
+        $poe_current = ALLIED_POE_CURRENT;
+        $poe_volt = ALLIED_POE_VOLT;
+    }
+
+    // mikrotik
+    if ($vendor_id == 9) {
+        $poe_power = MIKROTIK_POE_USAGE;
+        $poe_current = MIKROTIK_POE_CURRENT;
+        $poe_volt = MIKROTIK_POE_VOLT;
+    }
+
+    // netgear
+    if ($vendor_id == 10) {
+        $poe_power = NETGEAR_POE_USAGE;
+        $poe_current = NETGEAR_POE_CURRENT;
+        $poe_volt = NETGEAR_POE_VOLT;
+    }
+
+    // HP
+    if ($vendor_id == 15) {
+        $poe_power = HP_POE_USAGE;
+        $poe_volt = HP_POE_VOLT;
+    }
+
+    // TP-Link
+    if ($vendor_id == 69) {
+        $poe_power = TPLINK_POE_USAGE;
+        $poe_current = TPLINK_POE_CURRENT;
+        $poe_volt = TPLINK_POE_VOLT;
+        $poe_class = TPLINK_POE_CLASS;
+    }
+
+    if (isset($poe_power)) {
+        $c_power = walk_snmp($ip, $snmp, $poe_power);
+        if (isset($c_power)) {
+            foreach ($c_power as $key => $value) {
+                if (empty($value)) {
+                    $value = 'INT:0';
+                }
+                $key = trim($key);
+                $p_power = parse_snmp_value($value);
+                $port = NULL;
+                if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                    $port = preg_replace('/^\./', '', $matches[0]);
+                    $result[$port]['power'] = 0;
+                    $result[$port]['power_display'] = '';
+                    switch ($vendor_id) {
+                        case 9: //mikrotik
+                            $p_power = round($p_power / 10, 2);
+                            break;
+                        case 69: //tplink
+                            $p_power = round($p_power / 10, 2);
+                            break;
+                        default:
+                            $p_power = round($p_power / 1000, 2);
+                            break;
+                    }
+                    if ($p_power > 0) {
+                        $result[$port]['power'] = $p_power;
+                        $result[$port]['power_display'] = 'P: ' . $p_power . ' W';
+                    }
+                }
+            }
+        }
+    }
+
+    if (isset($poe_current)) {
+        $c_current = walk_snmp($ip, $snmp, $poe_current);
+        if (isset($c_current)) {
+            foreach ($c_current as $key => $value) {
+                if (empty($value)) {
+                    $value = 'INT:0';
+                }
+                $key = trim($key);
+                $p_current = parse_snmp_value($value);
+                $port = NULL;
+                if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                    $port = preg_replace('/^\./', '', $matches[0]);
+                    $result[$port]['current'] = 0;
+                    $result[$port]['current_display'] = '';
+                    if ($p_current > 0) {
+                        $result[$port]['current'] = $p_current;
+                        $result[$port]['current_display'] = 'C: ' . $p_current . ' mA';
+                    }
+                }
+            }
+        }
+    }
+
+    if (isset($poe_volt)) {
+        $c_volt = walk_snmp($ip, $snmp, $poe_volt);
+        if (isset($c_volt)) {
+            foreach ($c_volt as $key => $value) {
+                if (empty($value)) {
+                    $value = 'INT:0';
+                }
+                $key = trim($key);
+                $p_volt = parse_snmp_value($value);
+                $port = NULL;
+                if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                    $port = preg_replace('/^\./', '', $matches[0]);
+                    $result[$port]['volt'] = 0;
+                    $result[$port]['volt_display'] = '';
+                    switch ($vendor_id) {
+                        case 2:
+                        case 8:
+                            $p_volt = round($p_volt / 1000, 2);
+                            break;
+                        case 9:
+                        case 69:
+                            $p_volt = round($p_volt / 10, 2);
+                            break;
+                        case 15:
+                            $p_volt = round($p_volt / 100, 2);
+                            break;
+                    }
+                    if ($p_volt > 0 and $result[$port]['power'] > 0) {
+                        $result[$port]['volt'] = $p_volt;
+                        $result[$port]['volt_display'] = ' V: ' . $p_volt . " V";
+                    }
+                }
+            }
+        }
+    }
+
+    if (isset($poe_class)) {
+        $c_class = walk_snmp($ip, $snmp, $poe_class);
+        if (isset($c_class)) {
+            foreach ($c_class as $key => $value) {
+                if (empty($value)) {
+                    $value = 'INT:0';
+                }
+                $key = trim($key);
+                $p_class = parse_snmp_value($value);
+                $port = NULL;
+                if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                    $port = preg_replace('/^\./', '', $matches[0]);
+                    $result[$port]['class'] = 0;
+                    $result[$port]['class_display'] = '';
+                    switch ($vendor_id) {
+                        case 69:
+                            if ($p_class > 0 and $result[$port]['power'] > 0) {
+                                if ($p_class == 7) {
+                                    $p_class = 'class-not-defined';
+                                }
+                                $result[$port]['class_display'] = 'Class: ' . $p_class;
+                                $result[$port]['class'] = $p_class;
+                            }
+                            break;
+                        default:
+                            if ($p_class > 0 and $result[$port]['power'] > 0) {
+                                $result[$port]['class_display'] = 'Class: ' . ($p_class - 1);
+                                $result[$port]['class'] = $p_class - 1;
+                            }
+                            break;
+                    }
+                }
+            }
+        }
+    }
+
+    foreach ($result as &$port) {
+        if (!isset($port['power'])) {
+            $port['power'] = 0;
+        }
+        if (!isset($port['current'])) {
+            $port['current'] = 0;
+        }
+        if (!isset($port['volt'])) {
+            $port['volt'] = 0;
+        }
+        if (!isset($port['class'])) {
+            $port['class'] = 0;
+        }
+    }
+
+    unset($port);
+
+    return $result;
+}
+
+function get_port_poe_detail($vendor_id, $port, $port_snmp_index, $ip, $snmp)
+{
+    if (!isset($port) or !isset($port_snmp_index)) {
+        return;
+    }
+    if (!isset($ip)) {
+        return;
+    }
+    if (!isset($community)) {
+        $community = 'public';
+    }
+    if (!isset($version)) {
+        $version = '2';
+    }
+
+    $result = '';
+
+    $poe_class = PETH_PSE_PORT_POE_CLASS . $port_snmp_index;
+
+    // eltex
+    if ($vendor_id == 2) {
+        $poe_power = ELTEX_POE_USAGE . '.' . $port_snmp_index;
+        $poe_current = ELTEX_POE_CURRENT . '.' . $port_snmp_index;
+        $poe_volt = ELTEX_POE_VOLT . '.' . $port_snmp_index;
+    }
+
+    // huawei
+    if ($vendor_id == 3) {
+        $poe_power = HUAWEI_POE_USAGE . '.' . $port_snmp_index;
+        $poe_current = HUAWEI_POE_CURRENT . '.' . $port_snmp_index;
+        $poe_volt = HUAWEI_POE_VOLT . '.' . $port_snmp_index;
+    }
+
+    // snr
+    if ($vendor_id == 6) {
+        $poe_class = SNR_POE_CLASS . '.' . $port_snmp_index;
+        $poe_power = SNR_POE_USAGE . '.' . $port_snmp_index;
+        $poe_current = SNR_POE_CURRENT . '.' . $port_snmp_index;
+        $poe_volt = SNR_POE_VOLT . '.' . $port_snmp_index;
+    }
+
+    // AT
+    if ($vendor_id == 8) {
+        $poe_power = ALLIED_POE_USAGE . '.' . $port_snmp_index;
+        $poe_current = ALLIED_POE_CURRENT . '.' . $port_snmp_index;
+        $poe_volt = ALLIED_POE_VOLT . '.' . $port_snmp_index;
+    }
+
+    // mikrotik
+    if ($vendor_id == 9) {
+        $poe_power = MIKROTIK_POE_USAGE . '.' . $port_snmp_index;
+        $poe_current = MIKROTIK_POE_CURRENT . '.' . $port_snmp_index;
+        $poe_volt = MIKROTIK_POE_VOLT . '.' . $port_snmp_index;
+    }
+
+    // netgear
+    if ($vendor_id == 10) {
+        $poe_power = NETGEAR_POE_USAGE . '.' . $port_snmp_index;
+        $poe_current = NETGEAR_POE_CURRENT . '.' . $port_snmp_index;
+        $poe_volt = NETGEAR_POE_VOLT . '.' . $port_snmp_index;
+    }
+
+    // HP
+    if ($vendor_id == 15) {
+        $poe_power = HP_POE_USAGE . '.' . $port_snmp_index;
+        $poe_volt = HP_POE_VOLT . '.' . $port_snmp_index;
+    }
+
+    // TP-Link
+    if ($vendor_id == 69) {
+        $poe_power = TPLINK_POE_USAGE . '.' . $port;
+        $poe_current = TPLINK_POE_CURRENT . '.' . $port;
+        $poe_volt = TPLINK_POE_VOLT . '.' . $port;
+        $poe_class = TPLINK_POE_CLASS . "." . $port;
+    }
+
+    if (isset($poe_power)) {
+        $c_power = get_snmp($ip, $snmp, $poe_power);
+        if (isset($c_power)) {
+            $p_power = parse_snmp_value($c_power);
+            switch ($vendor_id) {
+                case 9:
+                    $p_power = round($p_power / 10, 2);
+                    break;
+                case 69:
+                    $p_power = round($p_power / 10, 2);
+                    break;
+                default:
+                    $p_power = round($p_power / 1000, 2);
+                    break;
+            }
+            if ($p_power > 0) {
+                $result .= ' P: ' . $p_power . ' W';
+            }
+        }
+    }
+
+    if (isset($poe_current)) {
+        $c_current = get_snmp($ip, $snmp, $poe_current);
+        if (isset($c_current)) {
+            $p_current = parse_snmp_value($c_current);
+            if ($p_current > 0) {
+                $result .= ' C: ' . $p_current . ' mA';
+            }
+        }
+    }
+
+    if (isset($poe_volt)) {
+        $c_volt = get_snmp($ip, $snmp, $poe_volt);
+        if (isset($c_volt)) {
+            $p_volt = parse_snmp_value($c_volt);
+            switch ($vendor_id) {
+                case 2:
+                case 8:
+                    $p_volt = round($p_volt / 1000, 2);
+                    break;
+                case 9:
+                case 69:
+                    $p_volt = round($p_volt / 10, 2);
+                    break;
+                case 15:
+                    $p_volt = round($p_volt / 100, 2);
+                    break;
+            }
+            if ($p_volt > 0 and $p_power > 0) {
+                $result .= ' V: ' . $p_volt . " V";
+            }
+        }
+    }
+
+    if (isset($poe_class)) {
+        $c_class = get_snmp($ip, $snmp, $poe_class);
+        if (isset($c_class)) {
+            $p_class = parse_snmp_value($c_class);
+            switch ($vendor_id) {
+                case 69:
+                    if ($p_class > 0 and $p_power > 0) {
+                        if ($p_class == 7) {
+                            $p_class = 'class-not-defined';
+                        }
+                        $result .= ' Class: ' . $p_class;
+                    }
+                    break;
+                default:
+                    if ($p_class > 0 and $p_power > 0) {
+                        $result .= ' Class: ' . ($p_class - 1);
+                    }
+                    break;
+            }
+        }
+    }
+
+    return $result;
+}
+
+function get_snmp($ip, $snmp, $oid)
+{
+    snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
+    $result = NULL;
+    try {
+        $version = $snmp["version"];
+        if ($version == 3) {
+            $result = snmp3_get($ip, $snmp["ro-user"], 'authPriv', $snmp['auth-proto'], $snmp['ro-password'], $snmp["priv-proto"], $snmp["ro-password"], $oid, SNMP_timeout, SNMP_retry);
+        }
+
+        if ($version == 2) {
+            $result = snmp2_get($ip, $snmp["ro-community"], $oid, SNMP_timeout, SNMP_retry);
+        }
+        if ($version == 1) {
+            $result = snmpget($ip, $snmp["ro-community"], $oid, SNMP_timeout, SNMP_retry);
+        }
+        if (empty($result)) {
+            $result = NULL;
+        }
+    } catch (Exception $e) {
+        #	echo 'Caught exception: ',  $e->getMessage(), "\n";
+        $result = NULL;
+    }
+    return $result;
+}
+
+function set_snmp($ip, $snmp, $oid, $field, $value)
+{
+    $result = false;
+    try {
+        $version = $snmp["version"];
+        if ($version == 3) {
+            $result = snmp3_set($ip, $snmp["ro-user"], 'authPriv', $snmp['auth-proto'], $snmp['ro-password'], $snmp["priv-proto"], $snmp["ro-password"], $oid, $field, $value, SNMP_timeout, SNMP_retry);
+        }
+        if ($version == 2) {
+            $result = snmp2_set($ip, $snmp["ro-community"], $oid, $field, $value, SNMP_timeout, SNMP_retry);
+        }
+        if ($version == 1) {
+            $result = snmpset($ip, $snmp["ro-community"], $oid, $field, $value, SNMP_timeout, SNMP_retry);
+        }
+    } catch (Exception $e) {
+        #	echo 'Caught exception: ',  $e->getMessage(), "\n";
+        $result = false;
+    }
+    return $result;
+}
+
+function set_port_state($vendor_id, $port, $ip, $snmp, $state)
+{
+    // port -> snmp_index!!!
+    if (!isset($port)) {
+        return;
+    }
+    if (!isset($ip)) {
+        return;
+    }
+    $port_status = PORT_ADMIN_STATUS_OID . '.' . $port;
+    if ($state == 1) {
+        // enable port
+        $c_state = set_snmp($ip, $snmp, $port_status, 'i', 1);
+        return $c_state;
+    } else {
+        // disable port
+        $c_state = set_snmp($ip, $snmp, $port_status, 'i', 2);
+        return $c_state;
+    }
+}
+
+
+function get_ports_state_detail($ip, $snmp)
+{
+
+    if (!isset($ip)) {
+        return;
+    }
+
+    $result = [];
+
+    //post status
+    $p_state = walk_snmp($ip, $snmp, PORT_STATUS_OID);
+    if (!empty($p_state)) {
+        foreach ($p_state as $key => $value) {
+            if (empty($value)) {
+                $value = '';
+            }
+            $key = trim($key);
+            $value = parse_snmp_value($value);
+            $port = NULL;
+            if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                $port = preg_replace('/^\./', '', $matches[0]);
+                $result[$port]['status'] = $value;
+                $result[$port]['admin_status'] = 0;
+                $result[$port]['speed'] = 0;
+                $result[$port]['errors'] = 0;
+            }
+        }
+    }
+
+    //admin state
+    $p_admin = walk_snmp($ip, $snmp, PORT_ADMIN_STATUS_OID);
+    if (!empty($p_admin)) {
+        foreach ($p_admin as $key => $value) {
+            if (empty($value)) {
+                $value = '';
+            }
+            $key = trim($key);
+            $value = parse_snmp_value($value);
+            $port = NULL;
+            if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                $port = preg_replace('/^\./', '', $matches[0]);
+                $result[$port]['admin_status'] = $value;
+            }
+        }
+    }
+
+    //port speed
+    $p_speed = walk_snmp($ip, $snmp, PORT_SPEED_OID);
+    if (!empty($p_speed)) {
+        foreach ($p_speed as $key => $value) {
+            if (empty($value)) {
+                $value = 'INT:0';
+            }
+            $key = trim($key);
+            $value = parse_snmp_value($value);
+            $port = NULL;
+            if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                $port = preg_replace('/^\./', '', $matches[0]);
+                $result[$port]['speed'] = $value;
+            }
+        }
+    }
+
+    //errors at
+    $p_errors = walk_snmp($ip, $snmp, PORT_ERRORS_OID);
+    if (!empty($p_errors)) {
+        foreach ($p_errors as $key => $value) {
+            if (empty($value)) {
+                $value = 'INT:0';
+            }
+            $key = trim($key);
+            $value = parse_snmp_value($value);
+            $port = NULL;
+            if (preg_match('/\.(\d{1,10})$/', $key, $matches)) {
+                $port = preg_replace('/^\./', '', $matches[0]);
+                $result[$port]['errors'] = $value;
+            }
+        }
+    }
+
+    return $result;
+}
+
+function get_port_state_detail($port, $ip, $snmp)
+{
+    if (!isset($port)) {
+        return;
+    }
+    if (!isset($ip)) {
+        return;
+    }
+    // if (!is_up($ip)) { return; }
+
+    $oper = PORT_STATUS_OID . '.' . $port;
+    $admin = PORT_ADMIN_STATUS_OID . '.' . $port;
+    $speed = PORT_SPEED_OID . '.' . $port;
+    $errors = PORT_ERRORS_OID . '.' . $port;
+    $result = '';
+    $c_state = get_snmp($ip, $snmp, $oper);
+    $p_state = parse_snmp_value($c_state);
+    $c_admin = get_snmp($ip, $snmp, $admin);
+    $p_admin = parse_snmp_value($c_admin);
+    if ($p_state == 1) {
+        $c_speed = get_snmp($ip, $snmp, $speed);
+    } else {
+        $c_speed = 'INT:0';
+    }
+    $p_speed = parse_snmp_value($c_speed);
+    $c_errors = get_snmp($ip, $snmp, $errors);
+    $p_errors = parse_snmp_value($c_errors);
+    $result = $p_state . ";" . $p_admin . ";" . $p_speed . ";" . $p_errors;
+    return $result;
+}
+
+function parse_snmp_value($value)
+{
+    if (empty($value)) {
+        return NULL;
+    }
+    if (!preg_match('/:/', $value)) {
+        return NULL;
+    }
+    list($p_type, $p_value) = explode(':', $value);
+    if (empty($p_value)) {
+        return NULL;
+    }
+    $p_value = trim($p_value);
+    $p_value = preg_replace('/^\"/', '', $p_value);
+    $p_value = preg_replace('/\"$/', '', $p_value);
+    $p_value = trim($p_value);
+    return $p_value;
+}
+
+snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
+snmp_set_enum_print(1);

+ 6 - 3
scripts/eyelib/snmp.pm

@@ -258,6 +258,8 @@ sub get_fdb_table {
     #join tables
     if ($fdb1 and $fdb3) { $fdb = { %$fdb1,%$fdb3 }; }
 
+    my $snmp_cisco = $snmp;
+
     #maybe cisco?!
     if (!$fdb) {
         my $vlan_table=snmp_get_oid($host,$snmp,$cisco_vlan_oid);
@@ -271,9 +273,10 @@ sub get_fdb_table {
                 if ($vlan_oid=~/\.([0-9]{1,4})$/) { $vlan_id=$1; }
                 next if (!$vlan_id);
                 next if ($vlan_id>1000 and $vlan_id<=1009);
-                $fdb_vlan{$vlan_id}=get_mac_table($host,$snmp.'@'.$vlan_id,$fdb_table_oid,$ifindex_map);
-                if (!$fdb_vlan{$vlan_id}) { $fdb_vlan{$vlan_id}=get_mac_table($host,$snmp.'@'.$vlan_id,$fdb_table_oid2,$ifindex_map); }
-                }
+                $snmp_cisco->{'ro-community'} = $snmp->{'ro-community'}.'@'.$vlan_id;
+                $fdb_vlan{$vlan_id}=get_mac_table($host,$snmp_cisco,$fdb_table_oid,$ifindex_map);
+                if (!$fdb_vlan{$vlan_id}) { $fdb_vlan{$vlan_id}=get_mac_table($host,$snmp_cisco,$fdb_table_oid2,$ifindex_map); }
+            }
             foreach my $vlan_id (keys %fdb_vlan) {
                 next if (!exists $fdb_vlan{$vlan_id});
                 if (defined $fdb_vlan{$vlan_id}) {

部分文件因为文件数量过多而无法显示