diff --git a/lib/mactrack_tplink.php b/lib/mactrack_tplink.php new file mode 100644 index 0000000..1914fe4 --- /dev/null +++ b/lib/mactrack_tplink.php @@ -0,0 +1,174 @@ + +*/ + +/* register this functions scanning functions */ +if (!isset($mactrack_scanning_functions)) { $mactrack_scanning_functions = array(); } +array_push($mactrack_scanning_functions, "get_tplink_dot1q_switch_ports"); + +/* get_tplink_dot1q_switch_ports - This is a basic function that will scan the dot1d + OID tree for all switch port to MAC address association and stores in the + mac_track_temp_ports table for future processing in the finalization steps of the + scanning process. +*/ +function get_tplink_dot1q_switch_ports($site, &$device, $lowPort = 0, $highPort = 0) { + global $debug, $scan_date; + + /* initialize port counters */ + $device["ports_total"] = 0; + $device["ports_active"] = 0; + $device["ports_trunk"] = 0; + + /* get the ifIndexes for the device */ + $ifIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.1", $device); + mactrack_debug("ifIndexes data collection complete"); + + $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, FALSE); + + /* initialize variables */ + $port_keys = array(); + $return_array = array(); + $new_port_key_array = array(); + $port_key_array = array(); + $port_number = 0; + $ports_active = 0; + $active_ports = 0; + $ports_total = 0; + + /* get the operational status of the ports */ + $active_ports_array = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.8", $device); + $indexes = array_keys($active_ports_array); + + $bridgePortIfIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.17.1.4.1.2", $device ); + + $i = 0; + if (sizeof($active_ports_array)) { + foreach($active_ports_array as $port_info) { + $port_info = mactrack_strip_alpha($port_info); + + if ( isset( $bridgePortIfIndexes[$ifInterfaces[$indexes[$i]]["ifIndex"]] ) ) { + if ((($ifInterfaces[$indexes[$i]]["ifType"] >= 6) && + ($ifInterfaces[$indexes[$i]]["ifType"] <= 9)) || + ($ifInterfaces[$indexes[$i]]["ifType"] == 71)) { + if ($port_info == 1) { + $ports_active++; + } + $ports_total++; + } + } + $i++; + } + } + + print("INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"],0,40) . ", TOTAL PORTS: " . $ports_total . ", OPER PORTS: " . $ports_active); + if ($debug) { + print("\n"); + } + + $device["ports_active"] = $ports_active; + $device["ports_total"] = $ports_total; + $device["macs_active"] = 0; + + /* get VLAN information */ + $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.11863.6.14.1.2.1.1.1", $device); + $vlan_names = xform_standard_indexed_data(".1.3.6.1.4.1.11863.6.14.1.2.1.1.2", $device); + $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.11863.6.14.1.1.1.1.2", $device); + + $device["vlans_total"] = sizeof($vlan_ids) - 1; + mactrack_debug("VLAN data collected. There are " . (sizeof($vlan_ids) - 1) . " VLANS."); + foreach($ifIndexes as $ifIndex) { + if ( isset( $vlan_trunkstatus[$ifIndex] ) && $vlan_trunkstatus[$ifIndex] == 1 ) { + $device["ports_trunk"]++; + } + } + mactrack_debug("ports total : " . $device["ports_total"] . ", ports_trunk: " . $device["ports_trunk"]); + mactrack_debug("ifInterfaces assembly complete."); + + $i = 0; + foreach($vlan_ids as $vlan_id => $vlan_num) { + $active_vlans[$vlan_id]["vlan_id"] = $vlan_num; + $active_vlans[$vlan_id]["vlan_name"] = $vlan_names[$vlan_id]; + $active_vlans++; + + $i++; + } + mactrack_debug("Vlan assembly complete."); + + if (sizeof($active_vlans) > 0) { + $i = 0; + /* get the port status information */ + $port_results = xform_stripped_oid ( ".1.3.6.1.2.1.17.1.4.1.2", $device ); + $mac_results = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.2", $device ); + + $i = 1; + foreach ( $port_results as $port ) + { + $nport_results[$i++] = $port; + } + $i = 0; + $j = 0; + $port_array = array(); + foreach($mac_results as $num => $mac_result) { + if ( $mac_result != 0 ) { + $Xvlanid = substr ( $num, 0, strpos ( $num, "." ) ); + $Xmac = mach ( substr ( $num, strpos ( $num, ".") + 1 ) ); + + $ifIndex = $nport_results[$mac_result]; + $ifType = $ifInterfaces[$ifIndex]["ifType"]; + $ifName = $ifInterfaces[$ifIndex]["ifName"]; + $portName = $ifName; + $portTrunkStatus = $vlan_trunkstatus[$ifIndex]; + + /* only output legitamate end user ports */ + if ( $portName != "" and $portName != "1" ) { + $port_array[$i]["vlan_id"] = $active_vlans[$Xvlanid]["vlan_id"];//@$vlan_ids[$Xvlanid]; + $port_array[$i]["vlan_name"] = $active_vlans[$Xvlanid]["vlan_name"];//@$vlan_names[$Xvlandid]; + $port_array[$i]["port_number"] = $mac_result; + $port_array[$i]["port_name"] = trim ( $ifName ); + $port_array[$i]["mac_address"] = xform_mac_address($Xmac); + + mactrack_debug("VLAN: " . $port_array[$i]["vlan_id"] . ", " . + "NAME: " . $port_array[$i]["vlan_name"] . ", " . + "PORT: " . $ifIndex . ", " . + "NAME: " . $port_array[$i]["port_name"] . ", " . + "MAC: " . $port_array[$i]["mac_address"]); + + $i++; + } + $j++; + } + } + + /* display completion message */ + print("INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"],0,40) . ", TOTAL PORTS: " . $device["ports_total"] . ", ACTIVE PORTS: " . $device["ports_active"]); + $device["last_runmessage"] = "Data collection completed ok"; + $device["macs_active"] = sizeof($port_array); + db_store_device_port_results($device, $port_array, $scan_date); + }else{ + print("INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"],0,40) . ", No active devcies on this network device."); + $device["snmp_status"] = HOST_UP; + $device["last_runmessage"] = "Data collection completed ok. No active devices on this network device."; + } + + return $device; +} diff --git a/lib/mactrack_trendnet.php b/lib/mactrack_trendnet.php new file mode 100644 index 0000000..23ee4dd --- /dev/null +++ b/lib/mactrack_trendnet.php @@ -0,0 +1,264 @@ + +*/ + +/* register this functions scanning functions */ +if (!isset($mactrack_scanning_functions)) { $mactrack_scanning_functions = array(); } +array_push($mactrack_scanning_functions, "get_trendnet_dot1q_switch_ports"); + +/* get_trendnet_dot1q_switch_ports - This is a basic function that will scan the dot1d + OID tree for all switch port to MAC address association and stores in the + mac_track_temp_ports table for future processing in the finalization steps of the + scanning process. +*/ +function get_trendnet_dot1q_switch_ports($site, &$device, $lowPort = 0, $highPort = 0) { + global $debug, $scan_date; + + /* initialize port counters */ + $device["ports_total"] = 0; + $device["ports_active"] = 0; + $device["ports_trunk"] = 0; + + /* get the ifIndexes for the device */ + $ifIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.1", $device); + mactrack_debug("ifIndexes data collection complete"); + + $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, TRUE); + + /* sanitize ifInterfaces by removing text from ifType field */ + if (sizeof($ifInterfaces)) { + foreach($ifInterfaces as $key => $tempInterfaces){ + preg_match("/[0-9]{1,3}/", $tempInterfaces["ifType"], $newType); + $ifInterfaces[$key]["ifType"] = $newType[0]; + } + } + + get_base_trendnet_dot1qFdb_ports($site, $device, $ifInterfaces, "", TRUE, $lowPort, $highPort); + + return $device; +} +/* get_base_trendnet_dot1qFdb_ports - This function will grab information from the + port bridge snmp table and return it to the calling progrem for further processing. + This is a foundational function for all vendor data collection functions. + This was mainly copied from the default dot1q function in mactrack_functions.php + but was modified to work with Dell switches +*/ +function get_base_trendnet_dot1qFdb_ports($site, &$device, &$ifInterfaces, $snmp_readstring = "", $store_to_db = TRUE, $lowPort = 1, $highPort = 9999) { + global $debug, $scan_date; + + /* initialize variables */ + $port_keys = array(); + $return_array = array(); + $new_port_key_array = array(); + $port_key_array = array(); + $port_number = 0; + $ports_active = 0; + $active_ports = 0; + $ports_total = 0; + $snmp_readstring = $device["snmp_readstring"]; + + /* get the operational status of the ports */ + $active_ports_array = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.8", $device); + $indexes = array_keys($active_ports_array); + + /* Sanitize active ports array */ + if (sizeof($active_ports_array)) { + foreach($active_ports_array as $key => $tempPorts){ + preg_match("/[0-9]{1,3}/",$tempPorts,$newStatus); + $active_ports_array[$key]=$newStatus[0]; + } + } + + $i = 0; + if (sizeof($active_ports_array)) { + foreach($active_ports_array as $port_info) { + if ((($ifInterfaces[$indexes[$i]]["ifType"] >= 6) && + ($ifInterfaces[$indexes[$i]]["ifType"] <= 9)) || + ($ifInterfaces[$indexes[$i]]["ifType"] == 71)) { + if ($port_info == 1) { + $ports_active++; + } + $ports_total++; + } + $i++; + } + } + + if ($store_to_db) { + print("\nINFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"],0,40) . ", TOTAL PORTS: " . $ports_total . ", OPER PORTS: " . $ports_active); if ($debug) { + print("\n"); + } + + $device["ports_active"] = $ports_active; + $device["ports_total"] = $ports_total; + $device["macs_active"] = 0; + } + + /* get VLAN information */ + $vlan_names = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.4.3.1.1", $device, $snmp_readstring); + $device["vlans_total"] = sizeof($vlan_names) - 1; + mactrack_debug("VLAN data collected. There are " . (sizeof($vlan_names) - 1) . " VLANS."); + + $port_status = xform_stripped_oid(".1.3.6.1.4.1.28866.2.18.116.7.1.4.7.1.2", $device, $snmp_readstring); + if (sizeof($port_status)) { + foreach($port_status as $key => $tempStatus){ + if ( $tempStatus == 2 ) + $device["ports_trunk"]++; + } + } + + mactrack_debug("vlans total : " . $device["vlans_total"] . ", ports_trunk: " . $device["ports_trunk"]); + mactrack_debug("Vlan assembly complete."); + + if ($ports_active > 0) { + /* get bridge port to ifIndex mapping */ + $bridgePortIfIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.17.1.4.1.2", $device, $snmp_readstring); + + $port_status = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.3", $device, $snmp_readstring); + /* Sanitize port_status array */ + if (sizeof($port_status)) { + foreach($port_status as $key => $tempStatus){ + preg_match("/[0-9]{1,3}/",$tempStatus,$newStatus); + $port_status[$key]=$newStatus[0]; + } + } + //print_r($port_status); + /* get device active port numbers + This is the OID that shows the mac address as the index and the port as the value*/ + $port_numbers = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.2", $device, $snmp_readstring); + + /* get the ignore ports list from device */ + $ignore_ports = port_list_to_array($device["ignorePorts"]); + + /* get the bridge root port so we don't capture active ports on it */ + $bridge_root_port = @cacti_snmp_get($device["hostname"], $snmp_readstring, + ".1.3.6.1.2.1.17.2.7.0", $device["snmp_version"], + $device["snmp_username"], $device["snmp_password"], + $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], + $device["snmp_priv_protocol"], $device["snmp_context"], + $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]); + + /* determine user ports for this device and transfer user ports to + a new array. + */ + $i = 0; + if (sizeof($port_numbers)) { + foreach ($port_numbers as $key => $port_number) { + if (($highPort == 0) || + (($port_number >= $lowPort) && + ($port_number <= $highPort) && + ($bridge_root_port != $port_number))) { + + if (!in_array($port_number, $ignore_ports)) { + if ((@$port_status[$key] == "3") || (@$port_status[$key] == "5")) { + $port_key_array[$i]["key"] = $key; + $port_key_array[$i]["port_number"] = $port_number; + + $i++; + } + } + } + } + } + + /* compare the user ports to the brige port data, store additional + relevant data about the port. + */ + $i = 0; + if (sizeof($port_key_array)) { + foreach ($port_key_array as $port_key) { + /* map bridge port to interface port and check type */ + if ($port_key["port_number"] > 0) { + if (sizeof($bridgePortIfIndexes) != 0) { + $brPortIfIndex = @$bridgePortIfIndexes[$port_key["port_number"]]; + $brPortIfType = @$ifInterfaces[$brPortIfIndex]["ifType"]; + }else{ + $brPortIfIndex = $port_key["port_number"]; + $brPortIfType = @$ifInterfaces[$port_key["port_number"]]["ifType"]; + } + + if ((($brPortIfType >= 6) && ($brPortIfType <= 9)) || ($brPortIfType == 71)) { + /* set some defaults */ + $new_port_key_array[$i]["vlan_id"] = "N/A"; + $new_port_key_array[$i]["vlan_name"] = "N/A"; + $new_port_key_array[$i]["mac_address"] = "NOT USER"; + $new_port_key_array[$i]["port_number"] = "NOT USER"; + $new_port_key_array[$i]["port_name"] = "N/A"; + + /* now set the real data */ + $new_port_key_array[$i]["key"] = $port_key["key"]; + $new_port_key_array[$i]["port_number"] = $port_key["port_number"]; + $new_port_key_array[$i]["port_name"] = $ifInterfaces[$port_key["port_number"]]["ifAlias"]; + $i++; + } + } + } + } + mactrack_debug("Port number information collected."); + + /* map mac address */ + /* only continue if there were user ports defined */ + if (sizeof($new_port_key_array)) { + foreach ($new_port_key_array as $key => $port_mac) { + $new_port_key_array[$key]["mac_address"] = dell_mac_address_convert($port_mac["key"]); + mactrack_debug("INDEX: '". $key . "' MAC ADDRESS: " . $new_port_key_array[$key]["mac_address"]); + } + + /* Map Vlan names to pvid's */ + $vlan_names = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.4.3.1.1", $device, $snmp_readstring); + + + /* map pvid's to ports with vlan names*/ + if (sizeof($new_port_key_array)) { + foreach ($new_port_key_array as $key => $port){ + $temp_array = explode(".", $port["key"]); + $new_port_key_array[$key]["vlan_id"] = $temp_array[0]; + $new_port_key_array[$key]["vlan_name"] = @$vlan_names[$new_port_key_array[$key]["vlan_id"]]; + } + } + mactrack_debug("Port mac address information collected."); + }else{ + mactrack_debug("No user ports on this network."); + } + }else{ + mactrack_debug("No user ports on this network."); + } + + if ($store_to_db) { + if ($ports_active <= 0) { + $device["last_runmessage"] = "Data collection completed ok"; + }elseif (sizeof($new_port_key_array) > 0) { + $device["last_runmessage"] = "Data collection completed ok"; + $device["macs_active"] = sizeof($new_port_key_array); + db_store_device_port_results($device, $new_port_key_array, $scan_date); + }else{ + $device["last_runmessage"] = "WARNING: Poller did not find active ports on this device."; + } + + if(!$debug) { + print(" - Complete\n"); + } + }else{ + return $new_port_key_array; + } +} + diff --git a/lib/mactrack_vendors.php b/lib/mactrack_vendors.php index 21efa33..30c382d 100644 --- a/lib/mactrack_vendors.php +++ b/lib/mactrack_vendors.php @@ -38,3 +38,5 @@ include_once(dirname(__FILE__) . "/mactrack_linux.php"); include_once(dirname(__FILE__) . "/mactrack_norbay.php"); include_once(dirname(__FILE__) . "/mactrack_norbay_ng.php"); +include_once(dirname(__FILE__) . "/mactrack_tplink.php"); +include_once(dirname(__FILE__) . "/mactrack_trendnet.php");