فهرست منبع

add TP-Link poe support

rajven 3 سال پیش
والد
کامیت
05665b18ea
4فایلهای تغییر یافته به همراه141 افزوده شده و 82 حذف شده
  1. 1 0
      docs/mysql/mysql.sql
  2. 9 5
      html/admin/devices/switchstatus.php
  3. 57 70
      html/inc/common.php
  4. 74 7
      html/inc/consts.php

+ 1 - 0
docs/mysql/mysql.sql

@@ -975,6 +975,7 @@ INSERT INTO `vendors` (`id`, `name`) VALUES(65, 'Barco');
 INSERT INTO `vendors` (`id`, `name`) VALUES(66, 'Trassir');
 INSERT INTO `vendors` (`id`, `name`) VALUES(67, 'Testo');
 INSERT INTO `vendors` (`id`, `name`) VALUES(68, 'Hw-group');
+INSERT INTO `vendors` (`id`, `name`) VALUES(69, 'TP-Link');
 
 --
 -- Индексы сохранённых таблиц

+ 9 - 5
html/admin/devices/switchstatus.php

@@ -23,8 +23,10 @@ if (isset($_POST['poe_on']) and $device['snmp_version']>0) {
     $len = is_array($_POST['poe_on']) ? count($_POST['poe_on']) : 0;
     for ($i = 0; $i < $len; $i ++) {
         $port_index = intval($_POST['poe_on'][$i]);
-        LOG_DEBUG($db_link, "Device id: $id enable poe at port snmp index $port_index");
-        set_port_poe_state($device['vendor_id'], $port_index, $device['ip'], $device['rw_community'], $device['snmp_version'], 1);
+        $sSQL = "SELECT port from device_ports WHERE device_id=".$id." and snmp_index=".$port_index;
+        $port = get_record_sql($db_link,$sSQL);
+        LOG_DEBUG($db_link, "Device id: ".$id." enable poe at port ".$port['port']." snmp index ".$port_index);
+        set_port_poe_state($device['vendor_id'], $port['port'], $port_index, $device['ip'], $device['rw_community'], $device['snmp_version'], 1);
     }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
@@ -34,8 +36,10 @@ if (isset($_POST['poe_off']) and $device['snmp_version']>0) {
     $len = is_array($_POST['poe_off']) ? count($_POST['poe_off']) : 0;
     for ($i = 0; $i < $len; $i ++) {
         $port_index = intval($_POST['poe_off'][$i]);
-        LOG_DEBUG($db_link, "Device id: $id disable poe at port snmp index $port_index");
-        set_port_poe_state($device['vendor_id'], $port_index, $device['ip'], $device['rw_community'], $device['snmp_version'], 0);
+        $sSQL = "SELECT port from device_ports WHERE device_id=".$id." and snmp_index=".$port_index;
+        $port = get_record_sql($db_link,$sSQL);
+        LOG_DEBUG($db_link, "Device id: ".$id." disable poe at port ".$port['port']." snmp index ".$port_index);
+        set_port_poe_state($device['vendor_id'], $port['port'], $port_index, $device['ip'], $device['rw_community'], $device['snmp_version'], 0);
     }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
@@ -156,7 +160,7 @@ if ($device['snmp_version']>0) {
             $ifname = get_snmp_ifname1($device['ip'], $device['community'], $device['snmp_version'], $row['snmp_index']);
             if (empty($ifname)) { $ifname = get_snmp_ifname2($device['ip'], $device['community'], $device['snmp_version'], $row['snmp_index']); }
             $sfp_status = get_sfp_status($device['vendor_id'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version'], $modules_oids);
-            $poe_status = get_port_poe_state($device['vendor_id'], $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'], $device['community'], $device['snmp_version']);
             if (isset($poe_status)) {
                 if ($poe_status == 1) {
                     $port_poe_detail = get_port_poe_detail($device['vendor_id'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);

+ 57 - 70
html/inc/common.php

@@ -1749,12 +1749,12 @@ function get_ifmib_index_table ($ip, $community, $version)
 {
 $ifmib_map = NULL;
 $index_table = walk_snmp($ip, $community, $version, IFMIB_IFINDEX_MAP);
-$is_mikrotik = walk_snmp($ip, $community, $version, '.1.3.6.1.2.1.9999.1.1.1.1.0');
+$is_mikrotik = walk_snmp($ip, $community, $version, MIKROTIK_DHCP_SERVER);
 $mk_ros_version = 6497;
 
 if ($is_mikrotik) {
-    $mikrotik_version = walk_snmp($ip, $community, $version, '.1.0.8802.1.1.2.1.3.4.0');
-    $result = preg_match('/RouterOS\s+(\d)\.(\d{1,3})\.(\d{1,3})\s+/',$mikrotik_version['.1.0.8802.1.1.2.1.3.4.0'],$matches);
+    $mikrotik_version = walk_snmp($ip, $community, $version, MIKROTIK_ROS_VERSION);
+    $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];
         }
@@ -1944,7 +1944,7 @@ function check_snmp_access($ip, $community, $version)
     if (! isset($version)) {
         $version = '2';
     }
-    $result = get_snmp($ip, $community, $version, '.1.3.6.1.2.1.1.1.0');
+    $result = get_snmp($ip, $community, $version, SYS_DESCR_MIB);
     if (!isset($result)) { return; }
     return 1;
 }
@@ -2235,9 +2235,8 @@ function get_port_vlan($port, $port_index, $ip, $community, $version, $fdb_by_sn
     return $port_vlan;
 }
 
-function get_port_poe_state($vendor_id, $port, $ip, $community, $version)
+function get_port_poe_state($vendor_id, $port, $port_snmp_index, $ip, $community, $version)
 {
-    // port = snmp_index!!!!
     if (! isset($port)) {
         return;
     }
@@ -2250,7 +2249,6 @@ function get_port_poe_state($vendor_id, $port, $ip, $community, $version)
     if (! isset($version)) {
         $version = '2';
     }
-    // if (!is_up($ip)) { return; }
 
     // default poe oid
     $poe_status = PETH_PSE_PORT_ADMIN_ENABLE . "." . $port;
@@ -2268,13 +2266,17 @@ function get_port_poe_state($vendor_id, $port, $ip, $community, $version)
     }
 
     if ($vendor_id == 9) {
-        $poe_status = MIKROTIK_POE_OID . "." . $port;
+        $poe_status = MIKROTIK_POE_OID . "." . $port_snmp_index;
     }
 
     if ($vendor_id == 10) {
         $poe_status = NETGEAR_POE_OID . "." . $port;
     }
 
+    if ($vendor_id == 69) {
+        $poe_status = TPLINK_POE_OID . "." . $port;
+    }
+
     $result = '';
     $c_state = get_snmp($ip, $community, $version, $poe_status);
     if (!empty($c_state)) {
@@ -2288,36 +2290,24 @@ function get_port_poe_state($vendor_id, $port, $ip, $community, $version)
     return;
 }
 
-function set_port_poe_state($vendor_id, $port, $ip, $community, $version, $state)
+function set_port_poe_state($vendor_id, $port, $port_snmp_index, $ip, $community, $version, $state)
 {
-    // port -> snmp_index!!!
-    if (! isset($port)) {
-        return;
-    }
-    if (! isset($ip)) {
-        return;
-    }
-    if (! isset($community)) {
-        $community = 'public';
-    }
-    if (! isset($version)) {
-        $version = '2';
-    }
-    // if (!is_up($ip)) { return; }
+    if (! isset($ip)) { return; }
+
+    if (! isset($community)) { $community = 'public'; }
+    if (! isset($version)) { $version = '2'; }
+
     // default poe oid
-    $poe_status = PETH_PSE_PORT_ADMIN_ENABLE . "." . $port;
-    if ($vendor_id == 3) {
-        $poe_status = HUAWEI_POE_OID . "." . $port;
-    }
-    if ($vendor_id == 8) {
-        $poe_status = ALLIED_POE_OID . "." . $port;
-    }
-    if ($vendor_id == 15) {
-        $poe_status = HP_POE_OID . "." . $port;
-    }
-    if ($vendor_id == 10) {
-        $poe_status = NETGEAR_POE_OID . "." . $port;
-    }
+    $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; }
 
     if ($state) {
         // enable port
@@ -2330,66 +2320,63 @@ function set_port_poe_state($vendor_id, $port, $ip, $community, $version, $state
     }
 }
 
-function get_port_poe_detail($vendor_id, $port, $ip, $community, $version)
+function get_port_poe_detail($vendor_id, $port, $port_snmp_index, $ip, $community, $version)
 {
-    // port = snmp_index!!!!
-    if (! isset($port)) {
-        return;
-    }
-    if (! isset($ip)) {
-        return;
-    }
-    if (! isset($community)) {
-        $community = 'public';
-    }
-    if (! isset($version)) {
-        $version = '2';
-    }
-    // if (!is_up($ip)) { return; }
+    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 = '.1.3.6.1.2.1.105.1.1.1.10.1.' . $port;
+    $poe_class = PETH_PSE_PORT_POE_CLASS .'.' . $port_snmp_index;
 
     // eltex
     if ($vendor_id == 2) {
-        $poe_power = '.1.3.6.1.4.1.89.108.1.1.5.1.' . $port;
-        $poe_current = '.1.3.6.1.4.1.89.108.1.1.4.1.' . $port;
-        $poe_volt = '.1.3.6.1.4.1.89.108.1.1.3.1.' . $port;
+        $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 = '.1.3.6.1.4.1.2011.5.25.195.3.1.10.' . $port;
-        $poe_current = '.1.3.6.1.4.1.4526.11.15.1.1.1.3.1.' . $port;
-        $poe_volt = '.1.3.6.1.4.1.2011.5.25.195.3.1.14.' . $port;
+        $poe_power = HUAWEI_POE_USAGE . '.' . $port_snmp_index;
+        $poe_current = HUAWEI_POE_CURRENT .'.' . $port_snmp_index;
+        $poe_volt = HUAWEI_POE_VOLT . '.' . $port_snmp_index;
     }
 
     // AT
     if ($vendor_id == 8) {
-        $poe_power = '.1.3.6.1.4.1.89.108.1.1.5.1.' . $port;
-        $poe_current = '.1.3.6.1.4.1.89.108.1.1.4.1.' . $port;
-        $poe_volt = '.1.3.6.1.4.1.89.108.1.1.3.1.' . $port;
+        $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;
-        $poe_current = MIKROTIK_POE_CURRENT . '.' . $port;
-        $poe_volt = MIKROTIK_POE_VOLT . '.' . $port;
+        $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 = '.1.3.6.1.4.1.4526.11.15.1.1.1.2.1.' . $port;
-        $poe_current = '.1.3.6.1.4.1.4526.11.15.1.1.1.3.1.' . $port;
-        $poe_volt = '.1.3.6.1.4.1.4526.11.15.1.1.1.4.1.' . $port;
+        $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 = '.1.3.6.1.4.1.25506.2.14.1.1.4.1.' . $port;
-        $poe_volt = '.1.3.6.1.4.1.25506.2.14.1.1.3.1.' . $port;
+        $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_snmp_index;
+        $poe_current = TPLINK_POE_CURRENT .'.' . $port_snmp_index;
+        $poe_volt = TPLINK_POE_VOLT . '.' . $port_snmp_index;
     }
 
     if (isset($poe_power)) {
@@ -2525,7 +2512,7 @@ function set_port_for_group($db, $group_id, $place_id, $state)
         }
         LOG_INFO($db, "At device $d_name [$d_ip] $mode port $d_port for auth_id: $a_id ($a_ip [$a_name])");
         set_port_state($d_vendor_id, $d_snmp_index, $d_ip, $d_community, $d_snmp, $state);
-        set_port_poe_state($d_vendor_id, $d_snmp_index, $d_ip, $d_community, $d_snmp, $state);
+        set_port_poe_state($d_vendor_id, $d_port, $d_snmp_index, $d_ip, $d_community, $d_snmp, $state);
     }
     LOG_INFO($db, 'Mass port state change stopped.');
 }

+ 74 - 7
html/inc/consts.php

@@ -8,6 +8,11 @@ define("PORT_SPEED_OID",".1.3.6.1.2.1.2.2.1.5.");
 define("PORT_ERRORS_OID",".1.3.6.1.2.1.2.2.1.14.");
 define("PORT_VLAN_OID",".1.3.6.1.2.1.17.7.1.4.5.1.1.");
 
+define("IFMIB_IFINDEX",".1.3.6.1.2.1.2.2.1.1");
+define("IFMIB_IFINDEX_MAP",".1.3.6.1.2.1.17.1.4.1.2");
+define("IFMIB_IFDESCR",".1.3.6.1.2.1.2.2.1.2");
+define("IFMIB_IFNAME",".1.3.6.1.2.1.31.1.1.1.1");
+
 define("MAC_TABLE_OID",".1.3.6.1.2.1.17.7.1.2.2.1.2");
 define("MAC_TABLE_OID2",".1.3.6.1.2.1.17.4.3.1.2");
 define("MAC_TABLE_STR_OID",".1.3.6.1.2.1.17.4.3.1.2");
@@ -25,11 +30,6 @@ define("CISCO_SFP_SENSORS",".1.3.6.1.4.1.9.9.91.1.1.1.1.4");
 define("CISCO_SFP_PRECISION",".1.3.6.1.4.1.9.9.91.1.1.1.1.3");
 define("CISCO_VLAN_OID",".1.3.6.1.4.1.9.9.9.46.1.3.1.1.2");
 
-define("IFMIB_IFINDEX",".1.3.6.1.2.1.2.2.1.1");
-define("IFMIB_IFINDEX_MAP",".1.3.6.1.2.1.17.1.4.1.2");
-define("IFMIB_IFDESCR",".1.3.6.1.2.1.2.2.1.2");
-define("IFMIB_IFNAME",".1.3.6.1.2.1.31.1.1.1.1");
-
 define("HUAWEI_SFP_VENDOR",".1.3.6.1.4.1.2011.5.25.31.1.1.2.1.11");
 define("HUAWEI_SFP_SPEED",".1.3.6.1.4.1.2011.5.25.31.1.1.2.1.2");
 define("HUAWEI_SFP_VOLT",".1.3.6.1.4.1.2011.5.25.31.1.1.3.1.6");
@@ -39,13 +39,59 @@ define("HUAWEI_SFP_BIASCURRENT",".1.3.6.1.4.1.2011.5.25.31.1.1.3.1.31");
 define("HUAWEI_SFP_RX",".1.3.6.1.4.1.2011.5.25.31.1.1.3.1.8");
 define("HUAWEI_SFP_TX",".1.3.6.1.4.1.2011.5.25.31.1.1.3.1.9");
 
+//POE Default mib
+//POE class
+define("PETH_PSE_PORT_POE_CLASS",".1.3.6.1.2.1.105.1.1.1.10.1");
+//POE enable
 define("PETH_PSE_PORT_ADMIN_ENABLE",".1.3.6.1.2.1.105.1.1.1.3.1");
+
+//Eltex
+define("ELTEX_POE_OID",".1.3.6.1.4.1.14988.1.1.15.1.1.3");
+// VOLTAGE
+define("ELTEX_POE_VOLT",".1.3.6.1.4.1.89.108.1.1.3.1");
+// CURRENT
+define("ELTEX_POE_CURRENT",".1.3.6.1.4.1.89.108.1.1.4.1");
+// POWER USAGE
+define("ELTEX_POE_USAGE",".1.3.6.1.4.1.89.108.1.1.5.1");
+
+// huawei
 define("HUAWEI_POE_OID",".1.3.6.1.4.1.2011.5.25.195.3.1.3");
+// VOLTAGE
+define("HUAWEI_POE_VOLT",".1.3.6.1.4.1.2011.5.25.195.3.1.14");
+// CURRENT
+define("HUAWEI_POE_CURRENT",".1.3.6.1.4.1.4526.11.15.1.1.1.3.1");
+// POWER USAGE
+define("HUAWEI_POE_USAGE",".1.3.6.1.4.1.2011.5.25.195.3.1.10");
+
+// AT
 define("ALLIED_POE_OID",".1.3.6.1.2.1.105.1.1.1.3.1");
-define("HP_POE_OID",".1.3.6.1.2.1.105.1.1.1.3.1");
+// VOLTAGE
+define("ALLIED_POE_VOLT",".1.3.6.1.4.1.89.108.1.1.3.1");
+// CURRENT
+define("ALLIED_POE_CURRENT",".1.3.6.1.4.1.89.108.1.1.4.1");
+// POWER USAGE
+define("ALLIED_POE_USAGE",".1.3.6.1.4.1.89.108.1.1.5.1");
+
+// netgear
 define("NETGEAR_POE_OID",".1.3.6.1.4.1.4526.11.15.1.1.1.6.1");
-define("MIKROTIK_POE_OID",".1.3.6.1.4.1.14988.1.1.15.1.1.3");
+// VOLTAGE
+define("NETGEAR_POE_VOLT",".1.3.6.1.4.1.4526.11.15.1.1.1.4.1");
+// CURRENT
+define("NETGEAR_POE_CURRENT",".1.3.6.1.4.1.4526.11.15.1.1.1.3.1");
+// POWER USAGE
+define("NETGEAR_POE_USAGE",".1.3.6.1.4.1.4526.11.15.1.1.1.2.1");
 
+// HP
+define("HP_POE_OID",".1.3.6.1.2.1.105.1.1.1.3.1");
+// VOLTAGE
+define("HP_POE_VOLT",".1.3.6.1.4.1.25506.2.14.1.1.3.1");
+// CURRENT
+define("HP_POE_CURRENT",".1.3.6.1.4.1.25506.2.14.1.1.2.1");
+// POWER USAGE
+define("HP_POE_USAGE",".1.3.6.1.4.1.25506.2.14.1.1.4.1");
+
+//MIKROTIK
+define("MIKROTIK_POE_OID",".1.3.6.1.4.1.14988.1.1.15.1.1.3");
 //INTERFACE ID
 define("MIKROTIK_POE_INT",".1.3.6.1.4.1.14988.1.1.15.1.1.1");
 // INTERFACE NAMES
@@ -57,8 +103,29 @@ define("MIKROTIK_POE_CURRENT",".1.3.6.1.4.1.14988.1.1.15.1.1.5");
 // POWER USAGE IN DW (DEVIWATT)
 define("MIKROTIK_POE_USAGE",".1.3.6.1.4.1.14988.1.1.15.1.1.6");
 
+//TP-Link
+// INTEGER {off(0), turning-on(1), on(2), overload(3), short(4), nonstandard-pd(5),voltage-high(6), voltage-low(7),hardware-fault(8),overtemperature(9)
+define("TPLINK_POE_OID",".1.3.6.1.4.1.11863.6.56.1.1.2.1.1.11");
+//POE POWER, Displays the port's real time power supply in 0.1W.
+define("TPLINK_POE_USAGE",".1.3.6.1.4.1.11863.6.56.1.1.2.1.1.7");
+//POE CURRENT, Displays the port's real time current in 1mA.
+define("TPLINK_POE_CURRENT",".1.3.6.1.4.1.11863.6.56.1.1.2.1.1.8");
+//POE VOLT, Displays the port's real time voltage in 0.1V.
+define("TPLINK_POE_VOLT",".1.3.6.1.4.1.11863.6.56.1.1.2.1.1.9");
+
+//default mib for detect snmp work
+//SNMPv2-MIB::system
 define("SYSINFO_MIB",".1.3.6.1.2.1.1");
+//sysDescr.0
+define("SYS_DESCR_MIB",".1.3.6.1.2.1.1.1.0");
+
+//ident Mikrotik
+//MikroTik DHCP server
+define("MIKROTIK_DHCP_SERVER",".1.3.6.1.2.1.9999.1.1.1.1.0");
+//MikroTik RouterOS version - for patch mac-address-table
+define("MIKROTIK_ROS_VERSION",".1.0.8802.1.1.2.1.3.4.0");
 
+// log levels
 define("L_ERROR",0);
 define("L_WARNING",1);
 define("L_INFO",2);