2009-09-07 11:07:59 +00:00
|
|
|
<?php
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2010-02-20 17:22:22 +00:00
|
|
|
# Discover ports
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2010-07-05 19:21:36 +00:00
|
|
|
echo("Ports : ");
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2010-02-08 03:36:07 +00:00
|
|
|
|
2011-05-18 23:08:45 +00:00
|
|
|
$ports = array();
|
|
|
|
$ports = snmpwalk_cache_oid($device, "ifDescr", $port_stats, "IF-MIB");
|
|
|
|
#$ports = snmpwalk_cache_oid($device, "ifName", $port_stats, "IF-MIB");
|
|
|
|
#$ports = snmpwalk_cache_oid($device, "ifType", $port_stats, "IF-MIB");
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2010-07-05 19:21:36 +00:00
|
|
|
$interface_ignored = 0;
|
|
|
|
$interface_added = 0;
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2011-05-18 23:08:45 +00:00
|
|
|
foreach ($ports as $ifIndex => $port)
|
2011-03-26 19:12:24 +00:00
|
|
|
{
|
2011-05-18 23:08:45 +00:00
|
|
|
|
|
|
|
if (is_port_valid($port, $device))
|
2011-03-26 19:12:24 +00:00
|
|
|
{
|
2011-05-18 23:08:45 +00:00
|
|
|
if ($device['os'] == "vmware" && preg_match("/Device ([a-z0-9]+) at .*/", $port['ifDescr'], $matches)) { $port['ifDescr'] = $matches[1]; }
|
|
|
|
$port['ifDescr'] = fixifName($port['ifDescr']);
|
|
|
|
if ($debug) echo("\n $if ");
|
|
|
|
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) == '0')
|
2011-03-26 19:12:24 +00:00
|
|
|
{
|
2011-05-18 23:08:45 +00:00
|
|
|
mysql_query("INSERT INTO `ports` (`device_id`,`ifIndex`,`ifDescr`) VALUES ('".$device['device_id']."','$ifIndex','".mres($port['ifDescr'])."')");
|
|
|
|
# Add Interface
|
|
|
|
echo("+");
|
|
|
|
} else {
|
|
|
|
mysql_query("UPDATE `ports` SET `deleted` = '0' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'");
|
|
|
|
echo(".");
|
2010-07-05 19:21:36 +00:00
|
|
|
}
|
2011-05-18 23:08:45 +00:00
|
|
|
$int_exists[] = "$ifIndex";
|
|
|
|
} else {
|
|
|
|
# Ignored Interface
|
|
|
|
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0')
|
2011-03-26 19:12:24 +00:00
|
|
|
{
|
2011-05-18 23:08:45 +00:00
|
|
|
mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'");
|
|
|
|
# Delete Interface
|
|
|
|
echo("-"); ## Deleted Interface
|
2011-03-16 17:53:20 +00:00
|
|
|
} else {
|
2011-05-18 23:08:45 +00:00
|
|
|
echo("X"); ## Ignored Interface
|
2010-07-05 19:21:36 +00:00
|
|
|
}
|
2011-03-16 17:53:20 +00:00
|
|
|
}
|
2010-07-05 19:21:36 +00:00
|
|
|
}
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2010-07-05 19:21:36 +00:00
|
|
|
$sql = "SELECT * FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `deleted` = '0'";
|
|
|
|
$query = mysql_query($sql);
|
2008-04-03 21:52:59 +00:00
|
|
|
|
2011-04-06 13:54:50 +00:00
|
|
|
while ($test_if = mysql_fetch_assoc($query))
|
2011-03-26 19:12:24 +00:00
|
|
|
{
|
2010-07-05 19:21:36 +00:00
|
|
|
unset($exists);
|
|
|
|
$i = 0;
|
2011-03-26 19:12:24 +00:00
|
|
|
while ($i < count($int_exists) && !isset($exists))
|
|
|
|
{
|
2010-07-05 19:21:36 +00:00
|
|
|
$this_if = $test_if['ifIndex'];
|
|
|
|
if ($int_exists[$i] == $this_if) { $exists = 1; }
|
|
|
|
$i++;
|
|
|
|
}
|
2011-03-26 19:12:24 +00:00
|
|
|
if (!$exists)
|
|
|
|
{
|
2010-07-05 19:21:36 +00:00
|
|
|
echo("-");
|
|
|
|
mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE interface_id = '" . $test_if['interface_id'] . "'");
|
2008-04-03 21:52:59 +00:00
|
|
|
}
|
2010-07-05 19:21:36 +00:00
|
|
|
}
|
2008-04-03 21:52:59 +00:00
|
|
|
|
2010-07-05 19:21:36 +00:00
|
|
|
unset($temp_exists);
|
|
|
|
echo("\n");
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2011-05-18 23:08:45 +00:00
|
|
|
?>
|