Exemplo n.º 1
0
function get_netscreen_arp_table($site, &$device)
{
    global $debug, $scan_date;
    /* get the atifIndexes for the device */
    $atifIndexes = xform_indexed_data(".1.3.6.1.2.1.3.1.1.1", $device, 6);
    if (sizeof($atifIndexes)) {
        $ifIntcount = 1;
    } else {
        $ifIntcount = 0;
    }
    if ($ifIntcount != 0) {
        $atifIndexes = xform_indexed_data(".1.3.6.1.2.1.4.22.1.1", $device, 5);
    }
    mactrack_debug("atifIndexes data collection complete");
    /* get the atPhysAddress for the device */
    if ($ifIntcount != 0) {
        $atPhysAddress = xform_indexed_data(".1.3.6.1.2.1.4.22.1.2", $device, 5);
    } else {
        $atPhysAddress = xform_indexed_data(".1.3.6.1.2.1.3.1.1.2", $device, 6);
    }
    /* convert the mac address if necessary */
    $keys = array_keys($atPhysAddress);
    $i = 0;
    if (sizeof($atPhysAddress)) {
        foreach ($atPhysAddress as $atAddress) {
            $atPhysAddress[$keys[$i]] = xform_mac_address($atAddress);
            $i++;
        }
    }
    mactrack_debug("atPhysAddress data collection complete");
    /* get the atPhysAddress for the device */
    if ($ifIntcount != 0) {
        $atNetAddress = xform_indexed_data(".1.3.6.1.2.1.4.22.1.3", $device, 5);
    } else {
        $atNetAddress = xform_indexed_data(".1.3.6.1.2.1.3.1.1.3", $device, 6);
    }
    mactrack_debug("atNetAddress data collection complete");
    /* get the ifNames for the device */
    $keys = array_keys($atifIndexes);
    $i = 0;
    if (sizeof($atifIndexes)) {
        foreach ($atifIndexes as $atifIndex) {
            $atEntries[$i]["atifIndex"] = $atifIndex;
            $atEntries[$i]["atPhysAddress"] = $atPhysAddress[$keys[$i]];
            $atEntries[$i]["atNetAddress"] = xform_net_address($atNetAddress[$keys[$i]]);
            $i++;
        }
    }
    mactrack_debug("atEntries assembly complete.");
    /* output details to database */
    if (sizeof($atEntries)) {
        foreach ($atEntries as $atEntry) {
            $insert_string = "REPLACE INTO mac_track_ips " . "(site_id,device_id,hostname,device_name,port_number," . "mac_address,ip_address,scan_date)" . " VALUES ('" . $device["site_id"] . "','" . $device["device_id"] . "','" . $device["hostname"] . "','" . $device["device_name"] . "','" . $atEntry["atifIndex"] . "','" . $atEntry["atPhysAddress"] . "','" . $atEntry["atNetAddress"] . "','" . $scan_date . "')";
            //		mactrack_debug("SQL: " . $insert_string);
            db_execute($insert_string);
        }
    }
    /* save ip information for the device */
    $device["ips_total"] = sizeof($atEntries);
    db_execute("UPDATE mac_track_devices SET ips_total ='" . $device["ips_total"] . "' WHERE device_id='" . $device["device_id"] . "'");
    mactrack_debug("HOST: " . $device["hostname"] . ", IP address information collection complete");
}
Exemplo n.º 2
0
function get_IOS_dot1dTpFdbEntry_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;
    $device["vlans_total"] = 0;
    /* Variables to determine VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.46.1.3.1.1.2", $device);
    $vlan_names = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.46.1.3.1.1.4", $device);
    $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.46.1.6.1.1.14", $device);
    $device["vlans_total"] = sizeof($vlan_ids) - 3;
    mactrack_debug("There are " . (sizeof($vlan_ids) - 3) . " VLANS.");
    /* 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);
    /* get the Voice VLAN information if it exists */
    $portVoiceVLANs = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.87.1.4.1.1.37.0", $device);
    if (sizeof($portVoiceVLANs) > 0) {
        $vvlans = TRUE;
    } else {
        $portVoiceVLANs = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.68.1.5.1.1.1", $device);
        if (sizeof($portVoiceVLANs) > 0) {
            $vvlans = TRUE;
        } else {
            $vvlans = FALSE;
        }
    }
    mactrack_debug("Cisco Voice VLAN collection complete");
    if ($vvlans) {
        mactrack_debug("Voice VLANs exist on this device");
    } else {
        mactrack_debug("Voice VLANs do not exist on this device");
    }
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
            if ($vvlans) {
                $ifInterfaces[$ifIndex]["vVlanID"] = @$portVoiceVLANs[$ifIndex];
            }
            if ($ifInterfaces[$ifIndex]["ifType"] == 6) {
                $device["ports_total"]++;
            }
            if ($ifInterfaces[$ifIndex]["trunkPortState"] == "1") {
                $device["ports_trunk"]++;
            }
        }
    }
    mactrack_debug("ifInterfaces assembly complete.");
    /* build VLAN array from results */
    $i = 0;
    $j = 0;
    $active_vlans = array();
    if (sizeof($vlan_ids)) {
        foreach ($vlan_ids as $vlan_number => $vlanStatus) {
            $vlanName = $vlan_names[$vlan_number];
            if ($vlanStatus == 1) {
                /* vlan is operatinal */
                switch ($vlan_number) {
                    case "1002":
                    case "1003":
                    case "1004":
                    case "1005":
                        $active_vlan_ports = 0;
                        break;
                    default:
                        if ($device["snmp_version"] < "3") {
                            $snmp_readstring = $device["snmp_readstring"] . "@" . $vlan_number;
                            $active_vlan_ports = cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.2.1.17.1.2.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"]);
                        } else {
                            $active_vlan_ports = cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.2.1.17.1.2.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $vlan_number, $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
                        }
                        if (!is_numeric($active_vlan_ports) || $active_vlan_ports < 0) {
                            $active_vlan_ports = 0;
                        }
                        mactrack_debug("VLAN Analysis for VLAN: " . $vlan_number . "/" . $vlanName . " is complete. ACTIVE PORTS: " . $active_vlan_ports);
                        if ($active_vlan_ports > 0) {
                            /* does the vlan have active ports on it */
                            $active_vlans[$j]["vlan_id"] = $vlan_number;
                            $active_vlans[$j]["vlan_name"] = $vlanName;
                            $active_vlans[$j]["active_ports"] = $active_vlan_ports;
                            $active_vlans++;
                            $j++;
                        }
                }
            }
            $i++;
        }
    }
    if (sizeof($active_vlans)) {
        $i = 0;
        /* get the port status information */
        foreach ($active_vlans as $active_vlan) {
            if ($device["snmp_version"] < "3") {
                $snmp_readstring = $device["snmp_readstring"] . "@" . $active_vlan["vlan_id"];
            } else {
                $snmp_readstring = "cisco@" . $active_vlan["vlan_id"];
            }
            mactrack_debug("Processing has begun for VLAN: " . $active_vlan["vlan_id"]);
            if ($highPort == 0) {
                $active_vlans[$i]["port_results"] = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, $snmp_readstring, FALSE);
            } else {
                $active_vlans[$i]["port_results"] = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, $snmp_readstring, FALSE, $lowPort, $highPort);
            }
            /* get bridge port mappings */
            /* get bridge port to ifIndex mappings */
            mactrack_debug("Bridge port information about to be collected.");
            mactrack_debug("VLAN_ID: " . $active_vlans[$i]["vlan_id"] . ", VLAN_NAME: " . $active_vlans[$i]["vlan_name"] . ", ACTIVE PORTS: " . sizeof($active_vlans[$i]["port_results"]));
            if (sizeof($active_vlans[$i]["port_results"]) > 0) {
                $brPorttoifIndexes[$i] = xform_standard_indexed_data(".1.3.6.1.2.1.17.1.4.1.2", $device, $snmp_readstring);
                mactrack_debug("Bridge port information collection complete.");
            }
            $i++;
        }
        $i = 0;
        $j = 0;
        $port_array = array();
        mactrack_debug("Final cross check's now being performed.");
        if (sizeof($active_vlans)) {
            foreach ($active_vlans as $active_vlan) {
                if (sizeof($active_vlan["port_results"])) {
                    foreach ($active_vlan["port_results"] as $port_result) {
                        $ifIndex = @$brPorttoifIndexes[$j][$port_result["port_number"]];
                        $ifType = @$ifInterfaces[$ifIndex]["ifType"];
                        $portNumber = @$ifInterfaces[$ifIndex]["ifName"];
                        $portName = @$ifInterfaces[$ifIndex]["ifAlias"];
                        $portTrunk = @$portTrunking[$ifName];
                        if ($vvlans) {
                            $vVlanID = @$portVoiceVLANs[$ifIndex];
                        } else {
                            $vVlanID = -1;
                        }
                        $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
                        /* only output legitamate end user ports */
                        if ($ifType == 6) {
                            if ($portTrunkStatus == "2" || empty($portTrunkStatus) || $vVlanID > 0 && $vVlanID <= 1000) {
                                $port_array[$i]["vlan_id"] = $active_vlan["vlan_id"];
                                $port_array[$i]["vlan_name"] = $active_vlan["vlan_name"];
                                $port_array[$i]["port_number"] = $portNumber;
                                $port_array[$i]["port_name"] = $portName;
                                $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]);
                                $device["ports_active"]++;
                                $i++;
                                mactrack_debug("VLAN: " . $active_vlan["vlan_id"] . ", " . "NAME: " . $active_vlan["vlan_name"] . ", " . "PORT: " . $portNumber . ", " . "NAME: " . $portName . ", " . "MAC: " . $port_result["mac_address"]);
                            }
                        }
                    }
                }
                $j++;
            }
        }
        /* display completion message */
        print "\nINFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $device["ports_total"] . ", ACTIVE PORTS: " . $device["ports_active"] . "\n";
        $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 "\nINFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", No active end devices on this device.\n";
        $device["snmp_status"] = HOST_UP;
        $device["last_runmessage"] = "Data collection completed ok.  No active end devices on this device.";
    }
    return $device;
}
Exemplo n.º 3
0
function get_JEX_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 VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.2636.3.40.1.5.1.5.1.5", $device);
    $vlan_names = xform_standard_indexed_data(".1.3.6.1.4.1.2636.3.40.1.5.1.5.1.2", $device);
    /* get VLAN Trunk status */
    $device["vlans_total"] = sizeof($vlan_ids) - 1;
    mactrack_debug("VLAN data collected. There are " . (sizeof($vlan_ids) - 1) . " VLANS.");
    /* 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");
    /* get and store the interfaces table */
    $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, FALSE);
    foreach ($ifIndexes as $ifIndex) {
        $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
        if ($ifInterfaces[$ifIndex]["ifType"] == "propVirtual(53)" or $ifInterfaces[$ifIndex]["ifType"] == "ieee8023adLag(161)") {
            $device["ports_total"]++;
        }
        if ($ifInterfaces[$ifIndex]["trunkPortState"] == 3) {
            $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 = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE);
        $mac_results = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.2", $device);
        $port_results = xform_stripped_oid(".1.3.6.1.2.1.17.1.4.1.2", $device);
        $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 = $port_results[$mac_result];
                $ifType = $ifInterfaces[$ifIndex]["ifType"];
                $ifName = $ifInterfaces[$ifIndex]["ifName"];
                $portName = $ifName;
                $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
                /* only output legitamate end user ports */
                //if ((($ifType >= 6) && ($ifType <= 9)) and ( $portName != "" or $portName != "1" )) {
                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"] = @$port_results[$mac_result];
                    $port_array[$i]["port_name"] = trim($ifName);
                    $port_array[$i]["mac_address"] = xform_mac_address($Xmac);
                    $device["ports_active"]++;
                    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;
}
Exemplo n.º 4
0
function collect_mactrack_data($start, $site_id = 0) {
	global $max_run_duration, $config, $debug, $scan_date;

	if (defined('CACTI_BASE_PATH')) {
		$config["base_path"] = CACTI_BASE_PATH;
	}

	/* reset the processes table */
	db_execute("TRUNCATE TABLE mac_track_processes");

	/* dns resolver binary */
	$resolver_launched = FALSE;

	if (read_config_option("mt_reverse_dns") == "on") {
		$dns_resolver_required = TRUE;
	}else{
		$dns_resolver_required = FALSE;
	}

	/* get php binary path */
	$command_string = read_config_option("path_php_binary");

	/* save the scan date information */
	if ($site_id == '') {
		$scan_date = date("Y-m-d H:i:s");
		db_execute("REPLACE INTO settings (name, value) VALUES ('mt_scan_date', '$scan_date')");
	}

	/* just in case we've run too long */
	$exit_mactrack = FALSE;

	/* start mainline processing, order by site_id to keep routers grouped with switches */
	if ($site_id > 0) {
		$device_ids = db_fetch_assoc("SELECT device_id FROM mac_track_devices WHERE site_id='" . $site_id . "' and disabled=''");
	}else{
		$device_ids = db_fetch_assoc("SELECT device_id FROM mac_track_devices WHERE disabled='' ORDER BY site_id");
	}

	$total_devices = sizeof($device_ids);

	$concurrent_processes = read_config_option("mt_processes");

	if ($debug == TRUE) {
		$e_debug = " -d";
	}else{
		$e_debug = "";
	}

	if ($site_id) {
		$e_site = " -sid=$site_id";
	}else{
		$e_site = "";
	}

	/* add the parent process to the process list */
	db_process_add("-1");

	if ($total_devices > 0) {
		/* grab arpwatch data */
		if (read_config_option("mt_arpwatch") == "on") {
			$arp_db     = read_config_option("mt_arpwatch_path");
			$delim      = read_config_option("mt_mac_delim");
			$mac_ip_dns = array();

			if (file_exists($arp_db)) {
				$arp_dat = fopen($arp_db, "r");

				if ($arp_dat) {
					while (!feof($arp_dat)) {
						$line = fgets($arp_dat, 4096);

						if ($line != null) {
							$line = explode ("	", $line);

							$mac_ad = explode(":",$line[0]);
							for ($k=0;$k<6;$k++) {
								$mac_ad[$k] = strtoupper($mac_ad[$k]);
								if (1 == strlen($mac_ad[$k])) {
									$mac_ad[$k] = "0" . $mac_ad[$k];
								}
							}

							/* create the mac address */
							$mac = $mac_ad[0] . $delim . $mac_ad[1] . $delim . $mac_ad[2] . $delim . $mac_ad[3] . $delim . $mac_ad[4] . $delim . $mac_ad[5];

							/* update the array */
							$mac_ip_dns[$mac]["ip"]  = $line[1];
							$mac_ip_dns[$mac]["dns"] = $line[3];
						}
					}
					fclose($arp_dat);

					mactrack_debug("ARPWATCH: IP, DNS & MAC collection complete with ArpWatch");
				}else{
					cacti_log("ERROR: cannot open file ArpWatch database '$arp_db'");exit;
				}
			}
		}

		/* scan through all devices */
		$j = 0;
		$i = 0;
		$last_time = strtotime("now");
		$processes_available = $concurrent_processes;
		while ($j < $total_devices) {
			/* retreive the number of concurrent mac_track processes to run */
			/* default to 10 for now */
			$concurrent_processes = db_fetch_cell("SELECT value FROM settings WHERE name='mt_processes'");

			for ($i = 0; $i < $processes_available; $i++) {
				if (($j+$i) >= $total_devices) break;

				$extra_args = " -q " . $config["base_path"] . "/plugins/mactrack/mactrack_scanner.php -id=" . $device_ids[$i+$j]["device_id"] . $e_debug;
				mactrack_debug("CMD: " . $command_string . $extra_args);
				exec_background($command_string, $extra_args);
			}
			$j = $j + $i;

			/* launch the dns resolver if it hasn't been yet */
			if (($dns_resolver_required) && (!$resolver_launched)) {
				sleep(2);
				exec_background($command_string, " -q " . $config["base_path"] . "/plugins/mactrack/mactrack_resolver.php" . $e_debug . $e_site);
				$resolver_launched = TRUE;
				mactrack_debug("DNS Resolver process launched");
			}

			mactrack_debug("A process cycle launch just completed.");

			/* wait the correct number of seconds for proccesses prior to
			   attempting to update records */
			sleep(2);
			$current_time = strtotime("now");
			if (($current_time - $last_time) > read_config_option("mt_dns_prime_interval")) {
				/* resolve some ip's to mac addresses to let the resolver knock them out */
				db_execute("UPDATE mac_track_temp_ports
							INNER JOIN mac_track_ips
							ON (mac_track_temp_ports.mac_address=mac_track_ips.mac_address
							AND mac_track_temp_ports.site_id=mac_track_ips.site_id)
							SET mac_track_temp_ports.ip_address=mac_track_ips.ip_address,
							mac_track_temp_ports.updated=1
							WHERE mac_track_temp_ports.updated=0 AND mac_track_ips.scan_date='$scan_date'");
				mactrack_debug("Interum IP addresses to MAC addresses association pass complete.");

				$last_time = $current_time;
			}

			$processes_running = db_fetch_cell("SELECT count(*) FROM mac_track_processes");

			if ($dns_resolver_required) {
				$processes_available = $concurrent_processes - $processes_running + 1;
			}else{
				$processes_available = $concurrent_processes - $processes_running;
			}

			/* take time to check for an exit condition */
			list($micro,$seconds) = explode(" ", microtime());
			$current = $seconds + $micro;

			/* exit if we've run too long */
			if (($current - $start) > $max_run_duration) {
				$exit_mactrack = TRUE;
				cacti_log("ERROR: MacTracking timed out during main script processing.\n");
				db_execute("DELETE FROM settings WHERE name='mactrack_process_status'");
				db_process_remove("-1");
				break;
			}else{
				db_execute("REPLACE INTO settings SET name='mactrack_process_status', value='Total:$total_devices Completed:$j'");
			}
		}

		/* wait for last process to exit */
		$processes_running = db_fetch_cell("SELECT count(*) FROM mac_track_processes WHERE device_id > 0");
		while (($processes_running > 0) && (!$exit_mactrack)) {
			$processes_running = db_fetch_cell("SELECT count(*) FROM mac_track_processes WHERE device_id > 0");
			$devices_running = db_fetch_cell("SELECT group_concat(CAST(`device_id` as CHAR) SEPARATOR ', ') as t FROM mac_track_processes;");
			/* wait the correct number of seconds for proccesses prior to
			   attempting to update records */
			sleep(2);
			$current_time = strtotime("now");
			if (($current_time - $last_time) > read_config_option("mt_dns_prime_interval")) {
				/* resolve some ip's to mac addresses to let the resolver knock them out */
				db_execute("UPDATE mac_track_temp_ports
							INNER JOIN mac_track_ips
							ON (mac_track_temp_ports.mac_address=mac_track_ips.mac_address
							AND mac_track_temp_ports.site_id=mac_track_ips.site_id)
							SET mac_track_temp_ports.ip_address=mac_track_ips.ip_address,
							mac_track_temp_ports.updated=1
							WHERE mac_track_temp_ports.updated=0 AND mac_track_ips.scan_date='$scan_date'");
				mactrack_debug("Interum IP addresses to MAC addresses association pass complete.");
			}

			/* take time to check for an exit condition */
			list($micro,$seconds) = explode(" ", microtime());
			$current = $seconds + $micro;

			/* exit if we've run too long */
			if (($current - $start) > $max_run_duration) {
				$exit_mactrack = TRUE;
				cacti_log("ERROR: MacTracking timed out during main script processing.\n");
				break;
			}

			mactrack_debug("Waiting on " . $processes_running . " with id = [" . $devices_running ."] to complete prior to exiting.");
		}

		/* if arpwatch is enabled, let's let it pick up the stragglers, based upon IP address first */
		if ((read_config_option("mt_arpwatch") == "on") && (sizeof($mac_ip_dns))) {
			$ports = db_fetch_assoc("SELECT site_id, device_id, mac_address
				FROM mac_track_temp_ports
				WHERE updated=0");

			if (sizeof($ports)) {
			foreach($ports as $port) {
				if (isset($mac_ip_dns[$port["mac_address"]])) {
					db_execute("UPDATE mac_track_temp_ports
						SET updated=1, ip_address='" . $mac_ip_dns[$port["mac_address"]]["ip"] . "'" .
						($mac_ip_dns[$port["mac_address"]]["dns"] != '' ? ", dns_hostname='" . $mac_ip_dns[$port["mac_address"]]["dns"] . "'" : "") . "
						WHERE site_id=" . $port["site_id"] . "
						AND device_id=" . $port["device_id"] . "
						AND mac_address='" . $port["mac_address"] . "'");
				}
			}
			}
		}

		/* resolve some ip's to mac addresses to let the resolver knock them out */
		db_execute("UPDATE mac_track_temp_ports
					INNER JOIN mac_track_ips
					ON (mac_track_temp_ports.mac_address=mac_track_ips.mac_address
					AND mac_track_temp_ports.site_id=mac_track_ips.site_id)
					SET mac_track_temp_ports.ip_address=mac_track_ips.ip_address
					WHERE mac_track_temp_ports.updated=0 AND mac_track_ips.scan_date='$scan_date'");
		mactrack_debug("Interum IP addresses to MAC addresses association pass complete.");

		/* populate the vendor_macs for this pass */
		db_execute("UPDATE mac_track_temp_ports SET vendor_mac=SUBSTRING(mac_address,1,8);");
		mactrack_debug("MAC addresses to Vendor MACS association pass complete.");

		/* update the vlan id's table */
		db_execute("UPDATE mac_track_vlans SET present='0'");
		db_execute("INSERT INTO mac_track_vlans (vlan_id, site_id, device_id, vlan_name, present) SELECT vlan_id, site_id, device_id, vlan_name, '1' AS present FROM mac_track_temp_ports ON DUPLICATE KEY UPDATE vlan_name=VALUES(vlan_name), present=VALUES(present);");
		db_execute("DELETE FROM mac_track_vlans WHERE present='0'");
		mactrack_debug("MAC VLAN's in VLAN Table Updated.");

		/* let the resolver know that the parent process is finished and then wait
		   for the resolver if applicable */
		db_process_remove("-1");

		while (!$exit_mactrack) {
			/* checking to see if the resolver is running */
			$resolver_running = db_fetch_row("SELECT * FROM mac_track_processes WHERE device_id=0");

			if (sizeof($resolver_running) == 0) {
				break;
			}

			/* take time to check for an exit condition */
			list($micro,$seconds) = explode(" ", microtime());
			$current = $seconds + $micro;

			/* exit if we've run too long */
			if (($current - $start) > $max_run_duration) {
				$exit_mactrack = TRUE;
				cacti_log("ERROR: MacTracking timed out during main script processing.\n");
				break;
			}
		}

		/* transfer temp port results into permanent table */
		db_execute("INSERT INTO mac_track_ports
					(site_id, device_id, hostname, dns_hostname, device_name,
					vlan_id, vlan_name, mac_address, vendor_mac, ip_address,
					port_number, port_name, scan_date, authorized)
					SELECT site_id, device_id, hostname, dns_hostname, device_name,
					vlan_id, vlan_name, mac_address, vendor_mac, ip_address,
					port_number, port_name, scan_date, authorized
					FROM mac_track_temp_ports
					ON DUPLICATE KEY UPDATE site_id=VALUES(site_id), hostname=VALUES(hostname),
					device_name=VALUES(device_name), vlan_id=VALUES(vlan_id), vlan_name=VALUES(vlan_name),
					vendor_mac=VALUES(vendor_mac), ip_address=VALUES(ip_address), dns_hostname=VALUES(dns_hostname),
					port_name=VALUES(port_name), authorized=VALUES(authorized)");
		mactrack_debug("Finished transferring scan results to main table.");

		/* transfer the subnet information, although primative, into the ip_ranges table */
		$ip_ranges = db_fetch_assoc("SELECT SUBSTRING_INDEX(`ip_address`,'.',3) AS ip_range,
					site_id,
					COUNT(DISTINCT ip_address) AS ips_current,
					scan_date AS ips_current_date
					FROM mac_track_temp_ports
					WHERE ip_address != ''
					GROUP BY ip_range, site_id");

		if (is_array($ip_ranges)) {
			foreach($ip_ranges as $ip_range) {
				$range_record = db_fetch_row("SELECT * FROM mac_track_ip_ranges WHERE ip_range='" . $ip_range["ip_range"] .
					"' AND site_id='" . $ip_range["site_id"] . "'");

				if (sizeof($range_record) == 0) {
					db_execute("REPLACE INTO `mac_track_ip_ranges`
						(ip_range, site_id, ips_current, ips_current_date)
						VALUES ('" .
						$ip_range["ip_range"] . "'," .
						$ip_range["site_id"] . ",'" .
						$ip_range["ips_current"] . "','" .
						$ip_range["ips_current_date"] . "')");
				}else{
					db_execute("UPDATE `mac_track_ip_ranges`
						SET ips_current='" . $ip_range["ips_current"] . "', " .
						"ips_current_date='" . $ip_range["ips_current_date"] . "'" .
						"WHERE ip_range='" . $range_record["ip_range"] . "' AND " .
						"site_id='" . $range_record["site_id"] . "'");
				}
			}
		}

		/* update the max values if required */
		db_execute("UPDATE `mac_track_ip_ranges`
					SET ips_max=ips_current, ips_max_date=ips_current_date
					WHERE ips_current > ips_max");

		/* collect statistics */
		if ($site_id == 0) {
			$stats = db_fetch_assoc("SELECT site_id,
							count(device_id) as total_devices,
							sum(ports_active) as total_oper_ports,
							sum(macs_active) as total_macs,
							sum(ports_total) as total_user_ports
							FROM mac_track_devices
							GROUP BY site_id");
		}else{
			$stats = db_fetch_assoc("SELECT site_id,
							count(device_id) as total_devices,
							sum(ports_active) as total_oper_ports,
							sum(macs_active) as total_macs,
							sum(ports_total) as total_user_ports
							FROM mac_track_devices
							WHERE site_id='$site_id'
							GROUP BY site_id");
		}

		/* collect total device errors */
		$errors = db_fetch_assoc("SELECT site_id, snmp_status, count(device_id) as total_device_errors
						FROM mac_track_devices
						GROUP BY site_id, snmp_status");

		$ips = array_rekey(db_fetch_assoc("SELECT site_id, count(ip_address) as total_ips
						FROM mac_track_ips
						WHERE scan_date='$scan_date'
						GROUP BY site_id"), "site_id", "total_ips");

		foreach($errors as $error) {
			if (!isset($error_count[$error["site_id"]])) {
				$error_count[$error["site_id"]] = 0;
			}
			if ($error["snmp_status"] <> 3) {
				$error_count[$error["site_id"]] += $error["total_device_errors"];
			}
		}

		foreach($stats as $stat) {
			$num_ips = @$ips[$stat["site_id"]];
			if (empty($num_ips)) $num_ips = 0;

			$update_string = "UPDATE mac_track_sites SET " .
				"total_devices='" . $stat["total_devices"] . "', " .
				"total_ips='" . $num_ips . "', " .
				"total_macs='" . $stat["total_macs"] . "', " .
				"total_oper_ports='" . $stat["total_oper_ports"] . "', " .
				"total_user_ports='" . $stat["total_user_ports"] . "', " .
				"total_device_errors='" . $error_count[$stat["site_id"]] . "' " .
				"WHERE site_id='" . $stat["site_id"] . "'";

			db_execute($update_string);
		}
		mactrack_debug("Finished updating site table with collection statistics.");

		/* process macwatch data */
		$macwatches = db_fetch_assoc("SELECT * FROM mac_track_macwatch");
		if (sizeof($macwatches)) {
			$from     = read_config_option("mt_from_email");
			$fromname = read_config_option("mt_from_name");

			foreach($macwatches as $record) {
				/* determine if we should check this one */
				$found = db_fetch_row("SELECT *
					FROM mac_track_temp_ports
					WHERE mac_address='" . $record["mac_address"] . "'");

				if (sizeof($found)) {
					/* set the subject */
					$subject = "MACAUTH Notification: Mac Address '" . $record["mac_address"] . "' Found, For: '" . $record["name"] . "'";

					/* set the message with replacements */
					$message = str_replace("<IP>", $found["ip_address"], $record["description"]);
					$message = str_replace("<MAC>", $found["mac_address"], $message);
					$message = str_replace("<TICKET>", $record["ticket_number"], $message);
					$message = str_replace("<SITENAME>", db_fetch_cell("SELECT site_name FROM mac_track_sites WHERE site_id=" . $found["site_id"]), $message);
					$message = str_replace("<DEVICEIP>", $found["hostname"], $message);
					$message = str_replace("<DEVICENAME>", $found["device_name"], $message);
					$message = str_replace("<PORTNUMBER>", $found["port_number"], $message);
					$message = str_replace("<PORTNAME>", $found["port_name"], $message);

					/* send out the email */
					if (!$record["discovered"] || $record["notify_schedule"] >= "2") {
						$mail = true;

						if ($record["notify_schedule"] > 2) {
							if (strtotime($record["date_last_notif"]) + $record["notify_schedule"] > time()) {
								$mail = false;
							}
						}

						if ($mail) {
							mactrack_mail($record["email_addresses"], $from, $fromname, $subject, $message, $headers = '');
						}
					}

					/* update the the correct information */
					db_execute("UPDATE mac_track_macwatch
						SET
							discovered=1,
							date_last_seen=NOW()" .
							(strtotime($record["date_first_seen"]) == 0 ? ", date_first_seen=NOW()":"") . "
						WHERE mac_address='" . $record["mac_address"] . "'");
				}
			}
		}

		/* process macauth data */
		$mac_auth_frequency = read_config_option("mt_macauth_email_frequency");
		if ($mac_auth_frequency != "disabled") {
			$last_macauth_time = read_config_option("mt_last_macauth_time");

			/* if it's time to e-mail */
			if (($last_macauth_time + ($mac_auth_frequency*60) > time()) ||
				($mac_auth_frequency == 0)) {
				mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_time);
			}
		}

		/* process aggregated data */
		db_execute("UPDATE mac_track_aggregated_ports SET active_last=0;");
		db_execute("INSERT INTO mac_track_aggregated_ports
			(site_id, device_id, hostname, device_name,
			vlan_id, vlan_name, mac_address, vendor_mac, ip_address, dns_hostname,
			port_number, port_name, date_last, first_scan_date, count_rec, active_last, authorized)
			SELECT site_id, device_id, hostname, device_name,
			vlan_id, vlan_name, mac_address, vendor_mac, ip_address, dns_hostname,
			port_number, port_name, scan_date, scan_date, 1, 1, authorized
			FROM mac_track_temp_ports
			ON DUPLICATE KEY UPDATE count_rec=count_rec+1, active_last=1, date_last=mac_track_temp_ports.scan_date");

		/* purge the ip address and temp port table */
		db_execute("TRUNCATE TABLE mac_track_temp_ports");
		db_execute("DELETE FROM mac_track_ips WHERE scan_date<'$scan_date'");
		db_execute("OPTIMIZE TABLE mac_track_ips");
		db_execute("TRUNCATE TABLE mac_track_scan_dates");
		db_execute("REPLACE INTO mac_track_scan_dates (SELECT DISTINCT scan_date from mac_track_ports);");
	}else{
		cacti_log("NOTE: MACTRACK has no devices to process at this time\n");
	}
}
Exemplo n.º 5
0
function get_extreme_arp_table($site, &$device, $extremeware = false)
{
    global $debug, $scan_date;
    /*
    EXTREME-FDB-MIB::extremeFdbIpFdbIPAddress : The IP Address of the IP FDB entry.
    .1.3.6.1.4.1.1916.1.16.2.1.2
    EXTREME-FDB-MIB::extremeFdbIpFdbMacAddress : The MAC address corresponding to the IP Address.
    .1.3.6.1.4.1.1916.1.16.2.1.3
    EXTREME-FDB-MIB::extremeFdbIpFdbVlanIfIndex : The ifIndex of the Vlan on which this ip is learned.
    .1.3.6.1.4.1.1916.1.16.2.1.4
    EXTREME-FDB-MIB::extremeFdbIpFdbPortIfIndex : The IfIndex of the port on which this entry was learned.
    .1.3.6.1.4.1.1916.1.16.2.1.5
    EXTREME-VLAN-MIB::extremeVlanIfIndex.<vlanid> = index
    .1.3.6.1.4.1.1916.1.2.1.2.1.1
    EXTREME-VLAN-MIB::extremeVlanIfDescr.<vlanid> = description
    .1.3.6.1.4.1.1916.1.2.1.2.1.2
    EXTREME-VLAN-MIB::extremeVlanIfVlanId.<vlanid> = tag id
    .1.3.6.1.4.1.1916.1.2.1.2.1.10
    BRIDGE-MIB::dot1dBasePortIfIndex : get Ifindex from extremeFdbIpFdbPortIfIndex
    .1.3.6.1.2.1.17.1.4.1.2
    IF-MIB::ifName : get name of port from IfIndex
    .1.3.6.1.2.1.31.1.1.1.1
    */
    if ($extremeware) {
        // for extremeware use standard apr table + ifDescr for interface name
        /* get the atifIndexes for the device */
        $atifIndexes = xform_stripped_oid(".1.3.6.1.2.1.3.1.1.1", $device);
        $atEntries = array();
        if (sizeof($atifIndexes)) {
            mactrack_debug("atifIndexes data collection complete");
            $atPhysAddress = xform_stripped_oid(".1.3.6.1.2.1.3.1.1.2", $device);
            mactrack_debug("atPhysAddress data collection complete");
            $atNetAddress = xform_stripped_oid(".1.3.6.1.2.1.3.1.1.3", $device);
            mactrack_debug("atNetAddress data collection complete");
            $ifDescr = xform_stripped_oid(".1.3.6.1.2.1.2.2.1.2", $device);
            mactrack_debug("ifDescr data collection complete");
        }
        $i = 0;
        if (sizeof($atifIndexes)) {
            foreach ($atifIndexes as $key => $atifIndex) {
                $atEntries[$i]["atifIndex"] = $ifDescr[$atifIndex];
                $atEntries[$i]["atPhysAddress"] = xform_mac_address($atPhysAddress[$key]);
                $atEntries[$i]["atNetAddress"] = xform_net_address($atNetAddress[$key]);
                $i++;
            }
        }
    } else {
        /* get the atifIndexes for the device */
        $FdbPortIfIndex = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.2.1.5", $device);
        $atEntries = array();
        if (sizeof($FdbPortIfIndex)) {
            mactrack_debug("FdbPortIfIndex data collection complete");
            $FdbMacAddress = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.2.1.3", $device);
            mactrack_debug("FdbMacAddress data collection complete");
            $FdbIPAddress = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.2.1.2", $device);
            mactrack_debug("FdbIPAddress data collection complete");
            $FdbVlanIfIndex = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.2.1.4", $device);
            mactrack_debug("FdbVlanIfIndex data collection complete");
            $VlanIfVlanId = xform_stripped_oid(".1.3.6.1.4.1.1916.1.2.1.2.1.10", $device);
            mactrack_debug("VlanIfVlanId data collection complete");
            $BasePortIfIndex = xform_stripped_oid(".1.3.6.1.2.1.17.1.4.1.2", $device);
            mactrack_debug("BasePortIfIndex data collection complete");
            $ifName = xform_stripped_oid(".1.3.6.1.2.1.31.1.1.1.1", $device);
            mactrack_debug("ifName data collection complete");
        }
        $i = 0;
        if (sizeof($FdbPortIfIndex)) {
            foreach ($FdbPortIfIndex as $key => $PortIndex) {
                $atEntries[$i]["atifIndex"] = $ifName[$BasePortIfIndex[$PortIndex]] . ", vlan:" . $VlanIfVlanId[$FdbVlanIfIndex[$key]];
                $atEntries[$i]["atPhysAddress"] = xform_mac_address($FdbMacAddress[$key]);
                $atEntries[$i]["atNetAddress"] = xform_net_address($FdbIPAddress[$key]);
                $i++;
            }
        }
        mactrack_debug("atEntries assembly complete.");
    }
    /* output details to database */
    if (sizeof($atEntries)) {
        foreach ($atEntries as $atEntry) {
            $insert_string = "REPLACE INTO mac_track_ips " . "(site_id,device_id,hostname,device_name,port_number," . "mac_address,ip_address,scan_date)" . " VALUES ('" . $device["site_id"] . "','" . $device["device_id"] . "','" . $device["hostname"] . "','" . $device["device_name"] . "','" . $atEntry["atifIndex"] . "','" . $atEntry["atPhysAddress"] . "','" . $atEntry["atNetAddress"] . "','" . $scan_date . "')";
            //mactrack_debug("SQL: " . $insert_string);
            db_execute($insert_string);
        }
    }
    /* save ip information for the device */
    $device["ips_total"] = sizeof($atEntries);
    db_execute("UPDATE mac_track_devices SET ips_total ='" . $device["ips_total"] . "' WHERE device_id='" . $device["device_id"] . "'");
    mactrack_debug("HOST: " . $device["hostname"] . ", IP address information collection complete: nb IP=" . sizeof($atEntries) . ".");
}
Exemplo n.º 6
0
function get_3Com_base_dot1dTpFdbEntry_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_descr = array();
    $port_number = 0;
    $ports_active = 0;
    $active_ports = 0;
    $ports_total = 0;
    /* cisco uses a hybrid read string, if one is not defined, use the default */
    if ($snmp_readstring == "") {
        $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);
    $i = 0;
    foreach ($active_ports_array as $port_info) {
        if ($ifInterfaces[$indexes[$i]]["ifType"] >= 6 && $ifInterfaces[$indexes[$i]]["ifType"] <= 9 || $ifInterfaces[$indexes[$i]]["ifType"] == 117) {
            if ($port_info == 1) {
                $ports_active++;
            }
            $ports_total++;
        }
        $i++;
    }
    if ($store_to_db) {
        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;
    }
    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.4.3.1.3", $device, $snmp_readstring);
        /* get device active port numbers */
        $port_numbers = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.2", $device, $snmp_readstring);
        /* get the ignore ports list from device */
        $ignore_ports = port_list_to_array($device["ignorePorts"]);
        /* determine user ports for this device and transfer user ports to
        		   a new array.
        		*/
        $i = 0;
        foreach ($port_numbers as $key => $port_number) {
            if ($highPort == 0 || $port_number >= $lowPort && $port_number <= $highPort) {
                $ifname = $ifInterfaces[$bridgePortIfIndexes[$port_number]]["ifName"];
                if (!in_array($ifname, $ignore_ports)) {
                    if (@$port_status[$key] == "3") {
                        $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;
        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) {
                    /* some hubs do not always return a port number in the bridge table.
                    			   test for it by isset and substiture the port number from the ifTable
                    			   if it isnt in the bridge table
                    			*/
                    if (isset($bridgePortIfIndexes[$port_key["port_number"]])) {
                        $brPortIfIndex = @$bridgePortIfIndexes[$port_key["port_number"]];
                    } else {
                        $brPortIfIndex = @$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 == 117) && !isset($ifInterfaces[$brPortIfIndex]["portLink"])) {
                    /* 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[$brPortIfIndex]["ifName"];
                    $i++;
                }
            }
        }
        mactrack_debug("Port number information collected.");
        /* map mac address */
        /* only continue if there were user ports defined */
        if (sizeof($new_port_key_array) > 0) {
            /* get the bridges active MAC addresses */
            $port_macs = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.1", $device, $snmp_readstring);
            foreach ($port_macs as $key => $port_mac) {
                $port_macs[$key] = xform_mac_address($port_mac);
            }
            foreach ($new_port_key_array as $key => $port_key) {
                $new_port_key_array[$key]["mac_address"] = @$port_macs[$port_key["key"]];
                mactrack_debug("INDEX: '" . $key . "' MAC ADDRESS: " . $new_port_key_array[$key]["mac_address"]);
            }
            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;
    }
}
Exemplo n.º 7
0
                mactrack_debug('ERROR: Both Primary and Seconary DNS timed out, please increase timeout. Placing both DNS servers back online now.');
                $secondary_down = FALSE;
                $primary_down = FALSE;
            }
            $unresolved_ips[$key]['dns_hostname'] = $dns_hostname;
        }
        mactrack_debug('DNS host association complete.');
        /* output updated details to database */
        foreach ($unresolved_ips as $unresolved_ip) {
            $insert_string = 'REPLACE INTO mac_track_temp_ports 
				(site_id,device_id,hostname,dns_hostname,device_name,vlan_id,vlan_name,
				mac_address,vendor_mac,ip_address,port_number,port_name,scan_date)
				VALUES (' . $unresolved_ip['site_id'] . ',' . $unresolved_ip['device_id'] . ',' . db_qstr($unresolved_ip['hostname']) . ',' . db_qstr($unresolved_ip['dns_hostname']) . ',' . db_qstr($unresolved_ip['device_name']) . ',' . $unresolved_ip['vlan_id'] . ',' . db_qstr($unresolved_ip['vlan_name']) . ',' . db_qstr($unresolved_ip['mac_address']) . ',' . db_qstr($unresolved_ip['vendor_mac']) . ',' . db_qstr($unresolved_ip['ip_address']) . ',' . db_qstr($unresolved_ip['port_number']) . ',' . db_qstr($unresolved_ip['port_name']) . ',' . db_qstr($unresolved_ip['scan_date']) . ')';
            db_execute($insert_string);
        }
        mactrack_debug('Records updated with DNS information included.');
    }
    if ($break) {
        break;
    }
}
/* allow parent to close by removing process and then exit */
db_process_remove(0);
exit;
/*	display_help - displays the usage of the function */
function display_help()
{
    $info = plugin_mactrack_version();
    print "Network MacTracker IP Resolver Version " . $info['version'] . ", " . COPYRIGHT_YEARS . "\n";
    print "usage: mactrack_resolver.php [-sid=ID] [-d] [-h] [--help] [-v] [--version]\n\n";
    print "-sid=ID       - The site id to resolve for\n";
Exemplo n.º 8
0
function get_dlink_l2_dot1dTpFdbEntry_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;
    /* cisco uses a hybrid read string, if one is not defined, use the default */
    if ($snmp_readstring == "") {
        $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);
    $i = 0;
    foreach ($active_ports_array as $port_info) {
        //print ("=type--]=[". $ifInterfaces[$indexes[$i]]["ifType"] . "]\n");
        if (convert_dlink_data($ifInterfaces[$indexes[$i]]["ifType"]) >= 6 && convert_dlink_data($ifInterfaces[$indexes[$i]]["ifType"]) <= 9 || convert_dlink_data($ifInterfaces[$indexes[$i]]["ifType"]) == 117) {
            if (convert_dlink_data($port_info) == 1) {
                $ports_active++;
            }
            $ports_total++;
        }
        $i++;
    }
    if ($store_to_db) {
        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;
    }
    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);
        $vlan_names = xform_standard_indexed_data(".1.3.6.1.2.1.17.7.1.4.3.1.1", $device, $snmp_readstring);
        $port_status = xform_stripped_oid("1.3.6.1.2.1.17.7.1.2.2.1.3", $device, $snmp_readstring);
        /* get device active port numbers */
        $port_numbers = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.2", $device, $snmp_readstring);
        /* get device active port numbers */
        //$vlan_id = get_vlan_id_oid($port_numbers);
        /* get device active port numbers */
        //$vlan_ids = xform_dlink_vlan_associations($device, $snmp_readstring);
        /* get the ignore ports list from device */
        $ignore_ports = port_list_to_array($device["ignorePorts"]);
        /* determine user ports for this device and transfer user ports to
        		   a new array.
        		*/
        $i = 0;
        foreach ($port_numbers as $key => $port_number) {
            if ($highPort == 0 || $port_number >= $lowPort && $port_number <= $highPort) {
                if (!in_array($port_number, $ignore_ports)) {
                    if (@$port_status[$key] == "3" || @$port_status[$key] == "1") {
                        $port_key_array[$i]["key"] = $key;
                        $port_key_array[$i]["port_number"] = $port_number;
                        //print ("---------->>>key(i)=[$key] port_number=[$port_number] ]\n");
                        $i++;
                    }
                }
            }
        }
        $i = 0;
        // foreach ($vlan_ids as $key => $vlan_item) {
        //						$port_key_array[$i]["key"] = $key;
        // $port_key_array[$i]["vlan_id"] = $vlan_item["vlan_id"];
        // $port_key_array[$i]["vlan_name"] = $vlan_item["vlan_name"];
        //print ("---------->>>key(i)=[$i = $vlan_item] vlan_id=[" . $vlan_item["vlan_id"] . "][" . $vlan_item["vlan_name"] . "]\n");
        // $i++;
        // }
        //    $i = 0;
        //		foreach ($vlan_ids as $key => $vlan_name) {
        //						//$port_key_array[$i]["key"] = $key;
        //						$port_key_array[$i]["vlan_name"] = $vlan_name[$i]["vlan_name"];
        //						print ("---------->>>key(i)=[$i] vlan_name=[" .  $vlan_name[$i]["vlan_name"] . "]\n");
        //						$i++;
        //		}
        /* compare the user ports to the brige port data, store additional
        		   relevant data about the port.
        		*/
        $ifNames = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.18", $device);
        $i = 0;
        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) {
                    /* some hubs do not always return a port number in the bridge table.
                    			   test for it by isset and substiture the port number from the ifTable
                    			   if it isnt in the bridge table
                    			*/
                    if (isset($bridgePortIfIndexes[$port_key["port_number"]])) {
                        $brPortIfIndex = @$bridgePortIfIndexes[$port_key["port_number"]];
                    } else {
                        $brPortIfIndex = @$port_key["port_number"];
                    }
                    $brPortIfType = @$ifInterfaces[$brPortIfIndex]["ifType"];
                } else {
                    $brPortIfIndex = $port_key["port_number"];
                    $brPortIfType = @$ifInterfaces[$port_key["port_number"]]["ifType"];
                }
                if ((convert_dlink_data($brPortIfType) >= 6 && convert_dlink_data($brPortIfType) <= 9 || convert_dlink_data($brPortIfType) == 117) && !isset($ifInterfaces[$brPortIfIndex]["portLink"])) {
                    /* set some defaults  */
                    $new_port_key_array[$i]["vlan_id"] = get_dlink_vlan_id($port_key["key"]);
                    $new_port_key_array[$i]["vlan_name"] = $vlan_names[$new_port_key_array[$i]["vlan_id"]];
                    $new_port_key_array[$i]["mac_address"] = dlink_convert_macs($port_key["key"]);
                    $new_port_key_array[$i]["port_number"] = $port_key["port_number"];
                    $new_port_key_array[$i]["port_name"] = @$ifNames[$port_key["port_number"]];
                    //print ("===bef key=[". $port_key[$i]["vlan_id"] . "]\n");
                    /* 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]["mac_address"] = dlink_convert_macs($port_key["key"]);
                    //					print ("===check key=[". $new_port_key_array["key"] . "] = [" . $port_key["key"] . "]\n");
                    //					print ("===check key2[". $new_port_key_array[$i]["key"] . "] = [" . $port_key[$i]["key"] . "]\n");
                    //print ("----------key(i)=[$i]-[$key] port=[" . $new_port_key_array[$i]["port_number"] . "] vlan_id=[" . $new_port_key_array[$i]["vlan_id"] . "] mac_address=[" . $new_port_key_array[$i]["mac_address"] . "]  vlan_name=[" . $new_port_key_array[$i]["vlan_name"] . "]\n");
                    //mactrack_debug("INDEX: [$i]-[" . $port_key["key"] . "] port=[" . $new_port_key_array[$i]["port_number"] . "] vlan_id=[" . $new_port_key_array[$i]["vlan_id"] . "] mac_address=[" . $new_port_key_array[$i]["mac_address"] . "]  vlan_name=[" . $new_port_key_array[$i]["vlan_name"] . "]");
                    $i++;
                }
            }
        }
        mactrack_debug("Port number information collected.");
        /* map mac address */
        /* only continue if there were user ports defined */
        // 		if (sizeof($new_port_key_array) > 0) {
        // 			/* get the bridges active MAC addresses */
        // // 			$port_macs = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.1", $device, $snmp_readstring);
        // 			$port_macs = xform_dlink_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.2", $device, $snmp_readstring);
        //
        // 			foreach ($port_macs as $key => $port_mac) {
        //
        // //print ("===bef key=[". $key . "]\n");
        // //print ("===bef port_macs[key]=[". $port_macs[$key] . "]\n");
        // 				$port_macs[$key] = xform_mac_address($port_mac);
        // //print ("===aft port_macs[key]=[". $port_macs[$key] . "]\n");
        // 			}
        //
        // 			foreach ($new_port_key_array as $key => $port_key) {
        //
        // //				print ("===++++++==[key]=[". $port_key["key"] . "]\n");
        //
        // 			}
        // 			foreach ($port_macs as $key => $port_mac) {
        //
        // //				print ("===------==[key]=[". @$port_mac[4] . "]\n");
        //
        // 			}
        //
        // 			foreach ($new_port_key_array as $key => $port_key) {
        // 				$new_port_key_array[$key]["mac_address"] = @$port_macs[$port_key["key"]];
        // 				//print ("==key=[$key] = [". $new_port_key_array[$key]["mac_address"] . "] port=[" . $new_port_key_array[$key]["port_number"] . "]\n");
        //         //print ("==2aft port_key[key]=[". $port_key["key"] . "]\n");
        //         //print ("==2aft port_macs[port_key[key]]=[". @$port_macs[$port_key["key"]] . "]\n");
        //         //$new_port_key_array[$key]["vlan_id"] = @$port_macs[$port_key["key"]]["vlan_id"];
        // //        print ("===check key3[". $new_port_key_array[$key] . "] = [ " . $port_macs[$port_key["key"]] . "]\n");
        //
        // 				mactrack_debug("INDEX: '". $key . "' MAC ADDRESS: key=" . $port_key["key"] . "=[" . $port_key["key"] . "] vlan_id=[" . $port_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"] = "WARNING: Poller did not find active ports on this device.";
        } 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;
    }
}
Exemplo n.º 9
0
function get_repeater_rev4_ports($site, &$device, $lowPort, $highPort)
{
    global $debug, $scan_date;
    $snmp_readstring = get_repeater_snmp_readstring($device);
    if (strlen($snmp_readstring) > 0) {
        $ports_active = @cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.4.1.52.4.1.1.1.4.1.1.5.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"]) - 1;
        $ports_total = @cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.4.1.52.4.1.1.1.4.1.1.4.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"]) - 1;
        /* get the ignore ports list */
        $ignore_ports = port_list_to_array($device["ignorePorts"]);
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $ports_total . ", ACTIVE PORTS: " . $ports_active;
        if ($debug) {
            print "\n";
        }
        $device["vlans_total"] = 0;
        $device["ports_total"] = $ports_total;
        if ($ports_active >= 0) {
            $device["ports_active"] = $ports_active;
        } else {
            $device["ports_active"] = 0;
        }
        if ($device["snmp_version"] == 2) {
            $snmp_version = "2c";
        } else {
            $snmp_version = $device["snmp_version"];
        }
        $port_keys = array();
        $return_array = array();
        $new_port_key_array = array();
        $port_number = 0;
        $nextOID = ".1.3.6.1.4.1.52.4.1.1.1.4.1.5.2.1.2";
        $to = ceil($device["snmp_timeout"] / 1000);
        $i = 0;
        $previous_port = 0;
        while (1) {
            $exec_string = trim(read_config_option("path_snmpgetnext") . " -c " . $snmp_readstring . " -OnUQ -v " . $snmp_version . " -r " . $device["snmp_retries"] . " -t " . $to . " " . $device["hostname"] . ":" . $device["snmp_port"] . " " . $nextOID);
            exec($exec_string, $return_array, $return_code);
            list($nextOID, $port_number) = explode("=", $return_array[$i]);
            if ($port_number < $previous_port) {
                break;
            }
            if ($port_number <= $highPort && $port_number >= $lowPort) {
                if (!in_array($port_number, $ignore_ports)) {
                    /* set defaults for devices in case they don't have/support vlans */
                    $new_port_key_array[$i]["vlan_id"] = "N/A";
                    $new_port_key_array[$i]["vlan_name"] = "N/A";
                    $new_port_key_array[$i]["port_name"] = "N/A";
                    $new_port_key_array[$i]["key"] = trim(substr($nextOID, 36));
                    $new_port_key_array[$i]["port_number"] = trim(strtr($port_number, " ", ""));
                }
                $previous_port = trim(strtr($port_number, " ", ""));
            } else {
                break;
            }
            mactrack_debug("CMD: " . $exec_string . ", PORT: " . $port_number);
            $i++;
            $port_number = "";
        }
        if (sizeof($new_port_key_array) > 0) {
            /* map mac address */
            $i = 0;
            foreach ($new_port_key_array as $port_key) {
                $OID = ".1.3.6.1.4.1.52.4.1.1.1.4.1.5.2.1.1." . $port_key["key"];
                $mac_address = @cacti_snmp_get($device["hostname"], $snmp_readstring, $OID, $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"]);
                $new_port_key_array[$i]["mac_address"] = xform_mac_address($mac_address);
                mactrack_debug("OID: " . $OID . ", MAC ADDRESS: " . $new_port_key_array[$i]["mac_address"]);
                $i++;
            }
            $device["last_runmessage"] = "Data collection completed ok";
        } else {
            mactrack_debug("INFO: The following device has no active ports: " . $site . "/" . $device["hostname"] . "\n");
            $device["last_runmessage"] = "Data collection completed ok";
        }
    } else {
        mactrack_debug("ERROR: Could not determine snmp_readstring for host: " . $site . "/" . $device["hostname"] . "\n");
        $device["snmp_status"] = HOST_ERROR;
        $device["last_runmessage"] = "ERROR: Could not determine snmp_readstring for host.";
    }
    if (!$debug) {
        print " - Complete\n";
    }
    $device["ports_active"] = $ports_active;
    $device["macs_active"] = sizeof($new_port_key_array);
    db_store_device_port_results($device, $new_port_key_array, $scan_date);
    return $device;
}
Exemplo n.º 10
0
function get_netscreen_arp_table($site, &$device)
{
    global $debug, $scan_date;
    /* get the atifIndexes for the device */
    $atifIndexes = xform_indexed_data('.1.3.6.1.2.1.3.1.1.1', $device, 6);
    if (sizeof($atifIndexes)) {
        $ifIntcount = 1;
    } else {
        $ifIntcount = 0;
    }
    if ($ifIntcount != 0) {
        $atifIndexes = xform_indexed_data('.1.3.6.1.2.1.4.22.1.1', $device, 5);
    }
    mactrack_debug(__('atifIndexes data collection complete'));
    /* get the atPhysAddress for the device */
    if ($ifIntcount != 0) {
        $atPhysAddress = xform_indexed_data('.1.3.6.1.2.1.4.22.1.2', $device, 5);
    } else {
        $atPhysAddress = xform_indexed_data('.1.3.6.1.2.1.3.1.1.2', $device, 6);
    }
    /* convert the mac address if necessary */
    $keys = array_keys($atPhysAddress);
    $i = 0;
    if (sizeof($atPhysAddress)) {
        foreach ($atPhysAddress as $atAddress) {
            $atPhysAddress[$keys[$i]] = xform_mac_address($atAddress);
            $i++;
        }
    }
    mactrack_debug(__('atPhysAddress data collection complete'));
    /* get the atPhysAddress for the device */
    if ($ifIntcount != 0) {
        $atNetAddress = xform_indexed_data('.1.3.6.1.2.1.4.22.1.3', $device, 5);
    } else {
        $atNetAddress = xform_indexed_data('.1.3.6.1.2.1.3.1.1.3', $device, 6);
    }
    mactrack_debug(__('atNetAddress data collection complete'));
    /* get the ifNames for the device */
    $keys = array_keys($atifIndexes);
    $i = 0;
    if (sizeof($atifIndexes)) {
        foreach ($atifIndexes as $atifIndex) {
            $atEntries[$i]['atifIndex'] = $atifIndex;
            $atEntries[$i]['atPhysAddress'] = $atPhysAddress[$keys[$i]];
            $atEntries[$i]['atNetAddress'] = xform_net_address($atNetAddress[$keys[$i]]);
            $i++;
        }
    }
    mactrack_debug(__('atEntries assembly complete.'));
    /* output details to database */
    if (sizeof($atEntries)) {
        foreach ($atEntries as $atEntry) {
            $insert_string = 'REPLACE INTO mac_track_ips 
				(site_id,device_id,hostname,device_name,port_number,
				mac_address,ip_address,scan_date)
				 VALUES (' . $device['site_id'] . ',' . $device['device_id'] . ',' . db_qstr($device['hostname']) . ',' . db_qstr($device['device_name']) . ',' . db_qstr($atEntry['atifIndex']) . ',' . db_qstr($atEntry['atPhysAddress']) . ',' . db_qstr($atEntry['atNetAddress']) . ',' . db_qstr($scan_date) . ')';
            db_execute($insert_string);
        }
    }
    /* save ip information for the device */
    $device['ips_total'] = sizeof($atEntries);
    db_execute('UPDATE mac_track_devices SET ips_total =' . $device['ips_total'] . ' WHERE device_id=' . $device['device_id']);
    mactrack_debug(__('HOST: %s, IP address information collection complete', $device['hostname']));
}
Exemplo n.º 11
0
function get_procurve_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;
    $active_vlans = array();
    /* get VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.11.2.14.11.5.1.3.1.1.4.1.2", $device);
    /* get VLAN Trunk status */
    $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.11.2.14.11.5.1.3.1.1.8.1.1.1", $device);
    $device["vlans_total"] = sizeof($vlan_ids);
    mactrack_debug("VLAN data collected. There are " . sizeof($vlan_ids) . " VLANS.");
    /* 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");
    /* get and store the interfaces table */
    $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, FALSE);
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
            if ($ifInterfaces[$ifIndex]["ifType"] >= 6 && $ifInterfaces[$ifIndex]["ifType"] <= 9) {
                $device["ports_total"]++;
            }
            if ($ifInterfaces[$ifIndex]["trunkPortState"] == 3) {
                $device["ports_trunk"]++;
            }
        }
    }
    mactrack_debug("ifInterfaces assembly complete.");
    $i = 0;
    if (sizeof($vlan_ids)) {
        foreach ($vlan_ids as $vlan_id => $vlan_name) {
            $active_vlans[$i]["vlan_id"] = $vlan_id;
            $active_vlans[$i]["vlan_name"] = $vlan_name;
            $active_vlans++;
            $i++;
        }
    }
    if (sizeof($active_vlans)) {
        $i = 0;
        /* get the port status information */
        $port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE);
        $port_vlan_data = xform_standard_indexed_data(".1.3.6.1.4.1.11.2.14.11.5.1.3.1.1.5.1.2", $device);
        $i = 0;
        $j = 0;
        $port_array = array();
        if (sizeof($port_results)) {
            foreach ($port_results as $port_result) {
                $ifIndex = $port_result["port_number"];
                $ifType = $ifInterfaces[$ifIndex]["ifType"];
                $ifName = $ifInterfaces[$ifIndex]["ifName"];
                $portName = $ifName;
                $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
                /* only output legitamate end user ports */
                if ($ifType >= 6 && $ifType <= 9) {
                    $port_array[$i]["vlan_id"] = @$port_vlan_data[$port_result["port_number"]];
                    $port_array[$i]["vlan_name"] = @$vlan_ids[$port_array[$i]["vlan_id"]];
                    $port_array[$i]["port_number"] = @$port_result["port_number"];
                    $port_array[$i]["port_name"] = $portName;
                    $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]);
                    $device["ports_active"]++;
                    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;
}
Exemplo n.º 12
0
function get_norbay_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 VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.2272.1.3.2.1.2", $device);
    $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.2272.1.3.3.1.4", $device);
    $device["vlans_total"] = sizeof($vlan_ids);
    mactrack_debug("There are " . sizeof($vlan_ids) . " VLANS.");
    /* 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");
    /* get and store the interfaces table */
    $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, FALSE);
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
            $ifInterfaces[$ifIndex]["vlannum"] = @$vlan_ids[$ifIndex];
            $ifInterfaces[$ifIndex]["ifOperStatus"] = mactrack_strip_alpha($ifInterfaces[$ifIndex]["ifOperStatus"]);
            if ($ifInterfaces[$ifIndex]["ifType"] == 6) {
                $device["ports_total"]++;
            }
            if ($ifInterfaces[$ifIndex]["ifOperStatus"] == 1) {
                $device["ports_active"]++;
            }
            if ($ifInterfaces[$ifIndex]["trunkPortState"] == 2) {
                mactrack_debug("Found Port Trunk: " . $ifInterfaces[$ifIndex]["ifDescr"]);
                $device["ports_trunk"]++;
            }
        }
    }
    mactrack_debug("ifInterfaces assembly complete.");
    $i = 0;
    if (sizeof($vlan_ids)) {
        foreach ($vlan_ids as $vlan_id => $vlan_name) {
            $active_vlans[$i]["vlan_id"] = $vlan_id;
            $active_vlans[$i]["vlan_name"] = $vlan_name;
            $active_vlans++;
            $i++;
        }
    }
    if (sizeof($active_vlans)) {
        $i = 0;
        /* get the port status information */
        $port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE);
        $port_vlan_data = xform_dot1q_vlan_associations($device);
        $i = 0;
        $j = 0;
        $port_array = array();
        if (sizeof($port_results)) {
            foreach ($port_results as $port_result) {
                $ifIndex = $port_result["port_number"];
                $ifType = $ifInterfaces[$ifIndex]["ifType"];
                $ifName = $ifInterfaces[$ifIndex]["ifName"];
                $ifDescr = $ifInterfaces[$ifIndex]["ifDescr"];
                if (strpos($ifDescr, "BayStack") === false) {
                    $portName = preg_replace("/ifc[0-9]+ /", "", $ifName);
                } else {
                    $portName = preg_replace("/BayStack - /", "", $ifDescr);
                }
                $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
                /* only output legitamate end user ports */
                if ($ifType == 6 && $portTrunkStatus == 1) {
                    $port_array[$i]["vlan_id"] = @$port_vlan_data[$port_result["key"]];
                    $port_array[$i]["vlan_name"] = @$vlan_ids[$port_array[$i]["vlan_id"]];
                    $port_array[$i]["port_number"] = @$port_result["port_number"];
                    $port_array[$i]["port_name"] = $portName;
                    $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]);
                    $device["ports_active"]++;
                    foreach ($port_array as $test_array) {
                        if ($test_array["port_name"] == $portName && $test_array["mac_address"] != $port_result["mac_address"]) {
                            $port_array[$i]["port_number"] = @$port_result["port_number"] . " - *";
                        }
                    }
                    mactrack_debug("VLAN: " . $port_array[$i]["vlan_id"] . ", " . "NAME: " . $port_array[$i]["vlan_name"] . ", " . "PORT: " . $ifInterfaces[$ifIndex]["ifName"] . ", " . "NUMBER: " . $port_array[$i]["port_number"] . ", " . "NAME: " . $port_array[$i]["port_name"] . ", " . "MAC: " . $port_array[$i]["mac_address"]);
                    $i++;
                }
                $j++;
            }
        }
        /* display completion message */
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . trim(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;
}
Exemplo n.º 13
0
                    $device['last_runmessage'] = 'WARNING: Scanning Function Does Not Exist.';
                    $device['snmp_status'] = HOST_ERROR;
                }
            } else {
                mactrack_debug('WARNING: SITE: ' . $site . ', IP: ' . $device['hostname'] . ', TYPE: ' . substr($device['snmp_sysDescr'], 0, 40) . ', ERROR: IP Scanning Function in Device Type Table Is Null.');
                $device['last_runmessage'] = 'WARNING: Scanning Function in Device Type Table Is Null.';
                $device['snmp_status'] = HOST_ERROR;
            }
        } else {
            mactrack_debug('WARNING: SITE: ' . $site . ', IP: ' . $device['hostname'] . ', TYPE: ' . substr($device['snmp_sysDescr'], 0, 40) . ', ERROR: Device Type Not Found in Device Type Table.');
            $device['last_runmessage'] = 'WARNING: Device Type Not Found in Device Type Table.';
            $device['snmp_status'] = HOST_ERROR;
        }
    }
} else {
    mactrack_debug('WARNING: SITE: ' . $site . ', IP: ' . $device['hostname'] . ', TYPE: ' . substr($device['snmp_sysDescr'], 0, 40) . ', ERROR: Device unreachable.');
    $device['last_runmessage'] = 'Device unreachable.';
    $host_up = FALSE;
}
/* update the database with device status information */
db_update_device_status($device, $host_up, $scan_date, $start_time);
db_process_remove($device_id);
exit;
/*	display_help - displays the usage of the function */
function display_help()
{
    $info = plugin_mactrack_version();
    print "Network MacTracker Version " . $info['version'] . ", " . COPYRIGHT_YEARS . "\n\n";
    print "usage: mactrack_device.php -id=host_id [-w] [-d] [-h] [--help] [-v] [--version]\n\n";
    print "-id=host_id   - the mac_track_devices host_id to scan\n";
    print "-d | --debug  - Display verbose output during execution\n";
Exemplo n.º 14
0
function sync_cacti_to_mactrack($device) {
	
	/* do we want to "Sync Cacti Device to MacTrack Device"
	 * AND has the device already been assigned a "valid" MacTrack device id 
	 * (aka: has the device been saved successfully) */
	if ((read_config_option("mt_update_policy", true) == 2) &&
		($device["id"] > 0)) {

		# $devices holds the whole row from host table
		# now fetch the related device from mac_track_devices, if any
		$mt_device = db_fetch_row("SELECT * from mac_track_devices WHERE host_id=" . $device["id"]);

		if (is_array($mt_device)) {
			# update mac_track_device
			$device_id = api_mactrack_device_save(
			$mt_device["device_id"], 			# not a host column
			$device["id"],
			$mt_device["site_id"],				# not a host column (wait for 088)
			$device["hostname"],
			$device["description"],
			$mt_device["scan_type"],			# not a host column
			$mt_device["snmp_options"],			# not a host column
			$device["snmp_community"],
			$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"],
			$mt_device["snmp_retries"],
			$device["max_oids"],
			$mt_device["ignorePorts"],			# not a host column
			$device["notes"],
			$mt_device["user_name"], 			# not a host column
			$mt_device["user_password"],		# not a host column
			$mt_device["term_type"],
			$mt_device["private_key_path"],
			(isset($mt_device["disabled"]) ? $mt_device["disabled"] : "")); # not a host column

			mactrack_debug("MacTrack device: (" . $mt_device["device_id"] . ") successfully updated");
		}
	}
	# for use with next hook in chain
	return $device;
}
Exemplo n.º 15
0
					$device["last_runmessage"] = "WARNING: Scanning Function Does Not Exist.";
					$device["snmp_status"] = HOST_ERROR;
				}
			}else{
				mactrack_debug("WARNING: SITE: " . $site . ", IP: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"],0,40) . ", ERROR: IP Scanning Function in Device Type Table Is Null.");
				$device["last_runmessage"] = "WARNING: Scanning Function in Device Type Table Is Null.";
				$device["snmp_status"] = HOST_ERROR;
			}
		}else{
			mactrack_debug("WARNING: SITE: " . $site . ", IP: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"],0,40) . ", ERROR: Device Type Not Found in Device Type Table.");
			$device["last_runmessage"] = "WARNING: Device Type Not Found in Device Type Table.";
			$device["snmp_status"] = HOST_ERROR;
		}
	}
}else{
	mactrack_debug("WARNING: SITE: " . $site . ", IP: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"],0,40) . ", ERROR: Device unreachable.");
	$device["last_runmessage"] = "Device unreachable.";

	$host_up = FALSE;
}

/* update the database with device status information */
db_update_device_status($device, $host_up, $scan_date, $start_time);
db_process_remove($device_id);
exit;

/*	display_help - displays the usage of the function */
function display_help () {
	print "Network MacTracker Version 1.0, Copyright 2004-2010 - The Cacti Group\n\n";
	print "usage: mactrack_device.php -id=host_id [-w] [-d] [-h] [--help] [-v] [--version]\n\n";
	print "-id=host_id   - the mac_track_devices host_id to scan\n";
Exemplo n.º 16
0
function get_foundry_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;
    $device["vlans_total"] = 0;
    $device["ports_dual_mode"] = 0;
    /* get VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.1991.1.1.3.2.7.1.21", $device);
    /* get VLAN Trunk status */
    $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.1991.1.1.3.3.5.1.4", $device);
    $device["vlans_total"] = sizeof($vlan_trunkstatus);
    mactrack_debug("VLAN data collected. There are " . sizeof($vlan_ids) . " VLANS.");
    /* 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");
    /* get the ifTypes for the device */
    $ifTypes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.3", $device);
    mactrack_debug("ifTypes data collection complete.");
    /* get the ifNames for the device */
    $ifNames = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.1", $device);
    mactrack_debug("ifNames data collection complete.");
    /* get ports that happen to be link ports */
    $link_ports = get_link_port_status($device);
    mactrack_debug("ipAddrTable scanning for link ports data collection complete.");
    /* get ports that have no vlan id (non dual-mode) */
    $port_dualmode = xform_standard_indexed_data(".1.3.6.1.4.1.1991.1.1.3.3.5.1.24", $device);
    mactrack_debug("ifVlanId data collection complete.");
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            $ifInterfaces[$ifIndex]["ifIndex"] = $ifIndex;
            $ifInterfaces[$ifIndex]["ifName"] = @$ifNames[$ifIndex];
            $ifInterfaces[$ifIndex]["ifType"] = $ifTypes[$ifIndex];
            $ifInterfaces[$ifIndex]["linkPort"] = @$link_ports[$ifIndex];
            $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
            $ifInterfaces[$ifIndex]["ifVlanId"] = @$port_dualmode[$ifIndex];
        }
    }
    mactrack_debug("ifInterfaces assembly complete.");
    /* calculate the number of end user ports */
    if (sizeof($ifTypes)) {
        foreach ($ifTypes as $ifType) {
            if ($ifType >= 6 && $ifType <= 9) {
                $device["ports_total"]++;
            }
        }
    }
    mactrack_debug("Total Ports = " . $device["ports_total"]);
    /* calculate the number of trunk ports */
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            if ($ifInterfaces[$ifIndex]["trunkPortState"] == 1 && $ifInterfaces[$ifIndex]["ifVlanId"] == 0) {
                $device["ports_trunk"]++;
            }
        }
    }
    mactrack_debug("Total Trunk Ports = " . $device["ports_trunk"]);
    /* get VLAN details */
    $i = 0;
    if (sizeof($vlan_ids)) {
        foreach ($vlan_ids as $vlan_id => $vlan_name) {
            $active_vlans[$i]["vlan_id"] = $vlan_id;
            $active_vlans[$i]["vlan_name"] = $vlan_name;
            $active_vlans++;
            mactrack_debug("VLAN ID = " . $active_vlans[$i]["vlan_id"] . " VLAN Name = " . $active_vlans[$i]["vlan_name"]);
            $i++;
        }
    }
    if (sizeof($active_vlans)) {
        /* get the port status information */
        $port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE);
        $port_vlan_data = xform_standard_indexed_data(".1.3.6.1.4.1.1991.1.1.3.2.6.1.1", $device);
        $i = 0;
        $j = 0;
        $port_array = array();
        if (sizeof($port_results)) {
            foreach ($port_results as $port_result) {
                $ifIndex = $port_result["port_number"];
                $ifType = $ifTypes[$ifIndex];
                $ifName = $ifNames[$ifIndex];
                $portName = $ifName;
                $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
                mactrack_debug("Port Number = " . $ifIndex . " Type = " . $ifType . " Name = " . $ifName . " Port Name = " . $portName . " Trunk Status = " . $portTrunkStatus);
                /* only output legitimate end user ports */
                if ($ifType >= 6 && $ifType <= 9) {
                    $port_array[$i]["vlan_id"] = @$port_vlan_data[$port_result["port_number"]];
                    $port_array[$i]["vlan_name"] = @$vlan_ids[$port_array[$i]["vlan_id"]];
                    $port_array[$i]["port_number"] = @$port_result["port_number"];
                    $port_array[$i]["port_name"] = $portName;
                    $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]);
                    $device["ports_active"]++;
                    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++;
            }
            $active_ports_array = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.8", $device);
            $indexes = array_keys($active_ports_array);
            $i = 0;
            if (sizeof($active_ports_array)) {
                foreach ($active_ports_array as $port_info) {
                    $port_info = mactrack_strip_alpha($port_info);
                    $ifInterfaces[$indexes[$i]]["ifType"] = mactrack_strip_alpha($ifInterfaces[$indexes[$i]]["ifType"]);
                    mactrack_debug($ifInterfaces[$indexes[$i]]["ifType"]);
                    if ($ifInterfaces[$indexes[$i]]["ifType"] >= 6 && $ifInterfaces[$indexes[$i]]["ifType"] <= 9 || $ifInterfaces[$indexes[$i]]["ifType"] == 71) {
                        if ($port_info == 1) {
                            $device["ports_active"]++;
                        }
                        $i++;
                    }
                }
            }
            $device["ports_active"] = $device["ports_active"] - $device["ports_trunk"];
            /* get IP Addresses */
            $gateway = cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.4.1.1991.1.1.2.1.10.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"]);
            mactrack_debug("INFO: GATEWAY: " . $gateway);
            /* 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 devices 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;
}
Exemplo n.º 17
0
function sync_cacti_to_mactrack($device)
{
    /* do we want to 'Sync Cacti Device to MacTrack Device'
     * AND has the device already been assigned a 'valid' MacTrack device id
     * (aka: has the device been saved successfully) */
    if (read_config_option('mt_update_policy', true) == 2 && $device['id'] > 0) {
        # $devices holds the whole row from host table
        # now fetch the related device from mac_track_devices, if any
        $mt_device = db_fetch_row('SELECT * from mac_track_devices WHERE host_id=' . $device['id']);
        if (!isset($mt_device['snmp_engine_id'])) {
            $mt_device['snmp_engine_id'] = '';
        }
        if (is_array($mt_device)) {
            # update mac_track_device
            $device_id = api_mactrack_device_save($mt_device['device_id'], $device['id'], $mt_device['site_id'], $device['hostname'], $device['description'], $mt_device['scan_type'], $mt_device['snmp_options'], $device['snmp_community'], $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_engine_id'], $device['snmp_port'], $device['snmp_timeout'], $mt_device['snmp_retries'], $device['max_oids'], $mt_device['ignorePorts'], $device['notes'], $mt_device['user_name'], $mt_device['user_password'], $mt_device['term_type'], $mt_device['private_key_path'], isset($mt_device['disabled']) ? $mt_device['disabled'] : '');
            mactrack_debug('MacTrack device: (' . $mt_device['device_id'] . ') successfully updated');
        }
    }
    # for use with next hook in chain
    return $device;
}
Exemplo n.º 18
0
function get_CTAlias_table($site, &$device)
{
    global $debug, $scan_date;
    mactrack_debug("FUNCTION: get_CTAlias_table started");
    /* get the CTAlias Table for the device */
    $CTAliasInterfaces = xform_indexed_data(".1.3.6.1.4.1.52.4.1.3.7.1.1.1.1.3", $device, 2);
    mactrack_debug("CTAliasInterfaces data collection complete: " . sizeof($CTAliasInterfaces));
    /* get the CTAliasMacAddress for the device */
    $CTAliasMacAddress = xform_indexed_data(".1.3.6.1.4.1.52.4.1.3.7.1.1.1.1.4", $device, 2);
    mactrack_debug("CTAliasMacAddress data collection complete: " . sizeof($CTAliasMacAddress));
    /* convert the mac address if necessary */
    $keys = array_keys($CTAliasMacAddress);
    $i = 0;
    foreach ($CTAliasMacAddress as $MacAddress) {
        $CTAliasMacAddress[$keys[$i]] = xform_mac_address($MacAddress);
        $i++;
    }
    /* get the CTAliasProtocol Table for the device */
    $CTAliasProtocol = xform_indexed_data(".1.3.6.1.4.1.52.4.1.3.7.1.1.1.1.6", $device, 2);
    mactrack_debug("CTAliasProtocol data collection complete: " . sizeof($CTAliasProtocol));
    /* get the CTAliasAddressText for the device */
    $CTAliasAddressText = xform_indexed_data(".1.3.6.1.4.1.52.4.1.3.7.1.1.1.1.9", $device, 2);
    mactrack_debug("CTAliasAddressText data collection complete: " . sizeof($CTAliasAddressText));
    /* get the ifNames for the device */
    $keys = array_keys($CTAliasInterfaces);
    $i = 0;
    $CTAliasEntries = array();
    foreach ($CTAliasInterfaces as $ifIndex) {
        $CTAliasEntries[$i]["ifIndex"] = $ifIndex;
        #		$CTAliasEntries[$i]["timestamp"] = @substr($keys[$i], 0, stripos($keys[$i], '.'));
        $CTAliasEntries[$i]["timestamp"] = $keys[$i];
        $CTAliasEntries[$i]["CTAliasProtocol"] = @$CTAliasProtocol[$keys[$i]];
        $CTAliasEntries[$i]["CTAliasMacAddress"] = @$CTAliasMacAddress[$keys[$i]];
        #		$CTAliasEntries[$i]["CTAliasAddressText"] = @xform_net_address($CTAliasAddressText[$keys[$i]]);
        $CTAliasEntries[$i]["CTAliasAddressText"] = @$CTAliasAddressText[$keys[$i]];
        $i++;
    }
    mactrack_debug("CTAliasEntries assembly complete: " . sizeof($CTAliasEntries));
    /* output details to database */
    if (count($CTAliasEntries) > 0) {
        foreach ($CTAliasEntries as $CTAliasEntry) {
            /* drop non-IP protocols */
            if ($CTAliasEntry["CTAliasProtocol"] != 1) {
                continue;
            }
            $insert_string = "REPLACE INTO mac_track_ips " . "(site_id,device_id,hostname,device_name,port_number," . "mac_address,ip_address,scan_date)" . " VALUES ('" . $device["site_id"] . "','" . $device["device_id"] . "','" . $device["hostname"] . "'," . db_qstr($device["device_name"]) . ",'" . $CTAliasEntry["ifIndex"] . "','" . $CTAliasEntry["CTAliasMacAddress"] . "','" . $CTAliasEntry["CTAliasAddressText"] . "','" . $scan_date . "')";
            #			mactrack_debug("SQL: " . $insert_string);
            db_execute($insert_string);
        }
    }
    /* save ip information for the device */
    $device["ips_total"] = sizeof($CTAliasEntries);
    db_execute("UPDATE mac_track_devices SET ips_total ='" . $device["ips_total"] . "' WHERE device_id='" . $device["device_id"] . "'");
    mactrack_debug("HOST: " . $device["hostname"] . ", IP address information collection complete: " . $device["ips_total"]);
}
Exemplo n.º 19
0
function get_enterasys_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;
    $device["vlans_total"] = 0;
    /* get VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.52.4.1.2.16.4.4.1.2", $device);
    /* get VLAN Trunk status */
    $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.52.4.1.2.16.3.1.1.5.4", $device);
    $device["vlans_total"] = sizeof($vlan_trunkstatus);
    mactrack_debug("VLAN data collected. There are " . sizeof($vlan_ids) . " VLANS.");
    /* 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");
    /* get the ifTypes for the device */
    $ifTypes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.3", $device);
    mactrack_debug("ifTypes data collection complete.");
    /* get the ifNames for the device */
    $ifNames = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.1", $device);
    mactrack_debug("ifNames data collection complete.");
    /* get ports that happen to be link ports */
    $link_ports = get_link_port_status($device);
    mactrack_debug("ipAddrTable scanning for link ports data collection complete.");
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            $ifInterfaces[$ifIndex]["ifIndex"] = $ifIndex;
            $ifInterfaces[$ifIndex]["ifName"] = @$ifNames[$ifIndex];
            $ifInterfaces[$ifIndex]["ifType"] = mactrack_strip_alpha($ifTypes[$ifIndex]);
            $ifInterfaces[$ifIndex]["linkPort"] = @$link_ports[$ifIndex];
            $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
        }
    }
    mactrack_debug("ifInterfaces assembly complete.");
    /* calculate the number of end user ports */
    if (sizeof($ifTypes)) {
        foreach ($ifTypes as $ifType) {
            $ifType = mactrack_strip_alpha($ifType);
            if ($ifType >= 6 && $ifType <= 9) {
                $device["ports_total"]++;
            }
        }
    }
    mactrack_debug("Total Ports = " . $device["ports_total"]);
    /* calculate the number of trunk ports */
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            if ($ifInterfaces[$ifIndex]["trunkPortState"] == 1) {
                $device["ports_trunk"]++;
            }
        }
    }
    mactrack_debug("Total Trunk Ports = " . $device["ports_trunk"]);
    /* get VLAN details */
    $i = 0;
    if (sizeof($vlan_ids)) {
        foreach ($vlan_ids as $vlan_id => $vlan_name) {
            $active_vlans[$i]["vlan_id"] = $vlan_id;
            $active_vlans[$i]["vlan_name"] = $vlan_name;
            $active_vlans++;
            $i++;
        }
    }
    if (sizeof($active_vlans)) {
        /* get the port status information */
        $port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE);
        $port_vlan_data = xform_standard_indexed_data(".1.3.6.1.4.1.52.4.1.2.16.3.1.1.3.4", $device);
        $i = 0;
        $j = 0;
        $port_array = array();
        foreach ($port_results as $port_result) {
            mactrack_debug("Got Here");
            $ifIndex = $port_result["port_number"];
            $ifType = mactrack_strip_alpha($ifTypes[$ifIndex]);
            $ifName = $ifNames[$ifIndex];
            $portName = $ifName;
            $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
            /* only output legitimate end user ports */
            if ($ifType >= 6 && $ifType <= 9) {
                $port_array[$i]["vlan_id"] = @$port_vlan_data[$port_result["port_number"]];
                $port_array[$i]["vlan_name"] = @$vlan_ids[$port_array[$i]["vlan_id"]];
                $port_array[$i]["port_number"] = @$port_result["port_number"];
                $port_array[$i]["port_name"] = $portName;
                $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]);
                $device["ports_active"]++;
                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 devices 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;
}
Exemplo n.º 20
0
function get_base_dell_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, removing text junk as the dell's don't return just a plain numeric value */
    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;
    }
    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, removing text junk as the dell's don't return just a plain numeric value*/
        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;
    }
}