mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
better bgp / ipv6 display, remove some pear stuff
git-svn-id: http://www.observium.org/svn/observer/trunk@236 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
46
cleanup.php
46
cleanup.php
@@ -6,22 +6,46 @@
|
||||
include("config.php");
|
||||
include("includes/functions.php");
|
||||
|
||||
$query = "SELECT *,A.id as id FROM ipaddr AS A, interfaces as I, devices as D
|
||||
WHERE A.interface_id = I.interface_id AND I.device_id = D.device_id AND D.status = '1'";
|
||||
#$query = "SELECT *,A.id as id FROM ipaddr AS A, interfaces as I, devices as D
|
||||
# WHERE A.interface_id = I.interface_id AND I.device_id = D.device_id AND D.status = '1'";
|
||||
|
||||
$data = mysql_query($query);
|
||||
while($row = mysql_fetch_array($data)) {
|
||||
#$data = mysql_query($query);
|
||||
#while($row = mysql_fetch_array($data)) {
|
||||
|
||||
$mask = trim(shell_exec($config['ipcalc'] . " ".$row['addr']."/".$row['cidr']." | grep Netmask: | cut -d \" \" -f 4"));
|
||||
$response = trim(`snmpget -v2c -Osq -c $row[community] $row[hostname] ipAdEntIfIndex.$row[addr] | cut -d " " -f 2`);
|
||||
$maskcheck = trim(`snmpget -v2c -Osq -c $row[community] $row[hostname] ipAdEntNetMask.$row[addr] | cut -d " " -f 2`);
|
||||
if($response == $row['ifIndex'] && $mask == $maskcheck) {
|
||||
} else {
|
||||
mysql_query("delete from ipaddr where id = '$row[id]'");
|
||||
echo("Deleted $row[addr] from $row[hostname]\n");
|
||||
# $mask = trim(shell_exec($config['ipcalc'] . " ".$row['addr']."/".$row['cidr']." | grep Netmask: | cut -d \" \" -f 4"));
|
||||
# $response = trim(`snmpget -v2c -Osq -c $row[community] $row[hostname] ipAdEntIfIndex.$row[addr] | cut -d " " -f 2`);
|
||||
# $maskcheck = trim(`snmpget -v2c -Osq -c $row[community] $row[hostname] ipAdEntNetMask.$row[addr] | cut -d " " -f 2`);
|
||||
# if($response == $row['ifIndex'] && $mask == $maskcheck) {
|
||||
# } else {
|
||||
# mysql_query("delete from ipaddr where id = '$row[id]'");
|
||||
# echo("Deleted $row[addr] from $row[hostname]\n");
|
||||
# }
|
||||
#}
|
||||
|
||||
$sql = "SELECT * FROM devices WHERE status = '1'";
|
||||
$query = mysql_query($sql);
|
||||
while($device = mysql_fetch_array($query)) {
|
||||
echo($device['hostname'] . " \n\n");
|
||||
$oids = shell_exec("snmpwalk -v2c -c ".$device['community']." ".$device['hostname']." ipAddressIfIndex.ipv6 -Osq");
|
||||
$oids = str_replace("ipAddressIfIndex.ipv6.", "", $oids); $oids = str_replace("\"", "", $oids); $oids = trim($oids);
|
||||
unset($valid_ips);
|
||||
foreach(explode("\n", $oids) as $data) {
|
||||
$data = trim($data);
|
||||
list($ipv6addr,$ifIndex) = explode(" ", $data);
|
||||
$valid_ips[] = $ipv6addr;
|
||||
}
|
||||
$sql = "SELECT * FROM ip6addr AS A, interfaces AS I, devices as D WHERE A.interface_id = I.interface_id AND I.device_id = '".$device['device_id']."'";
|
||||
$data = mysql_query($sql);
|
||||
while($row = mysql_fetch_array($data)) {
|
||||
echo($row['addr'] . "\n");
|
||||
unset($valid);
|
||||
foreach($valid_ips as $valid_ip) {
|
||||
echo($row['addr'] . " = $valid_ip ? \n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$query = "SELECT * FROM interfaces AS I, devices as D
|
||||
WHERE I.device_id = D.device_id AND D.status = '1'";
|
||||
$data = mysql_query($query);
|
||||
|
||||
@@ -40,6 +40,12 @@
|
||||
echo("$break <a class=interface-desc href=\"javascript:popUp('/netcmd.php?cmd=whois&query=$ip[addr]')\">$ip[addr]/$ip[cidr]</a>");
|
||||
$break = "<br />";
|
||||
}
|
||||
$ip6data = mysql_query("SELECT * FROM `ip6addr` WHERE `interface_id` = '" . $interface['interface_id'] . "'");
|
||||
while($ip6 = mysql_fetch_Array($ip6data)) {
|
||||
echo("$break <a class=interface-desc href=\"javascript:popUp('/netcmd.php?cmd=whois&query=$ip6[addr]')\">".Net_IPv6::compress($ip6[addr])."/$ip6[cidr]</a>");
|
||||
$break = "<br />";
|
||||
}
|
||||
|
||||
echo("</span>");
|
||||
echo("</td><td width=100>");
|
||||
if($interface['ifOperStatus'] == "up") {
|
||||
@@ -80,9 +86,12 @@ echo("</td>");
|
||||
if ( strpos($ifDescr, "oopback") === false && !$dographs) {
|
||||
$link_query = mysql_query("select * from links AS L, interfaces AS I, devices AS D WHERE L.src_if = '$if_id' AND L.dst_if = I.interface_id AND I.device_id = D.device_id");
|
||||
while($link = mysql_fetch_array($link_query)) {
|
||||
echo("<img src='images/16/connect.png' align=absmiddle alt='Directly Connected' /> " . generateiflink($link, makeshortif($link['ifDescr'])) . " on " . generatedevicelink($link) . "</a><br />");
|
||||
$br = "<br />";
|
||||
# echo("<img src='images/16/connect.png' align=absmiddle alt='Directly Connected' /> " . generateiflink($link, makeshortif($link['ifDescr'])) . " on " . generatedevicelink($link) . "</a><br />");
|
||||
# $br = "<br />";
|
||||
$int_links[$link['interface_id']] = $link['interface_id'];
|
||||
$int_links_phys[$link['interface_id']] = 1;
|
||||
}
|
||||
|
||||
unset($br);
|
||||
$adj_sql = "SELECT * FROM networks AS N, interfaces AS I, adjacencies AS A ";
|
||||
$adj_sql = $adj_sql . "WHERE I.interface_id = A.interface_id AND A.network_id = N.id ";
|
||||
@@ -92,29 +101,79 @@ echo("</td>");
|
||||
$network_id = $adjs['network_id'];
|
||||
$newsql = "SELECT * FROM adjacencies AS A, networks as N, interfaces as I, devices as D ";
|
||||
$newsql = $newsql . "WHERE N.id = '$network_id' AND A.network_id = N.id AND I.interface_id = A.interface_id AND D.device_id = I.device_id ";
|
||||
$newsql = $newsql . "AND D.device_id != '$device[id]' AND I.ifDescr NOT LIKE '%loopback%' GROUP BY D.device_id ORDER BY D.hostname";
|
||||
$newsql = $newsql . "AND D.device_id != '".$device['device_id']."' AND I.ifDescr NOT LIKE '%loopback%' GROUP BY D.device_id ORDER BY D.hostname";
|
||||
$new_query = mysql_query($newsql);
|
||||
while($new = mysql_fetch_array($new_query)) {
|
||||
if ($new['status'] == '0') { $class = "red"; } else { $class = "blue"; }
|
||||
if ($new['ignore'] == '1') {
|
||||
$class = "grey";
|
||||
if ($new['status'] == '1') { $class = "green"; }
|
||||
}
|
||||
|
||||
$this_ifid = $new['interface_id'];
|
||||
$this_hostid = $new['device_id'];
|
||||
$this_hostname = $new['hostname'];
|
||||
$this_ifname = fixifName($new['ifDescr']);
|
||||
$wq = mysql_query("select count(*) FROM links WHERE dst_if = '$this_ifid' AND src_if = $if_id;");
|
||||
if (@mysql_result($wq, 0) == '0' && $this_hostname != $hostname) {
|
||||
$graph_url = "graph.php?if=$this_ifid&from=$twoday&to=$now&width=400&height=120&type=bits'";
|
||||
echo("$br <img src='images/16/bullet_go.png' alt='Same Subnet' align=absmiddle />" . generateiflink($new, makeshortif($new['ifDescr'])) . " on " . generatedevicelink($new));
|
||||
$br = "<br />";
|
||||
}
|
||||
|
||||
$int_links[$this_ifid] = $this_ifid;
|
||||
$int_links_v4[$this_ifid] = 1;
|
||||
|
||||
|
||||
# if (@mysql_result($wq, 0) == '0' && $this_hostname != $hostname) {
|
||||
# $graph_url = "graph.php?if=$this_ifid&from=$twoday&to=$now&width=400&height=120&type=bits'";
|
||||
# echo("$br <img src='images/16/bullet_go.png' alt='Same Subnet' align=absmiddle />" . generateiflink($new, makeshortif($new['ifDescr'])) . " on " . generatedevicelink($new));
|
||||
# $br = "<br />";
|
||||
# }
|
||||
}
|
||||
}
|
||||
unset($br);
|
||||
}
|
||||
|
||||
$sql = "SELECT network_id FROM ip6addr AS A, ip6networks AS N, interfaces AS I
|
||||
WHERE A.interface_id = I.interface_id
|
||||
AND A.network = N.cidr
|
||||
AND I.interface_id = '".$interface['interface_id']."'";
|
||||
|
||||
$nets_query = mysql_query($sql);
|
||||
|
||||
while($net = mysql_fetch_array($nets_query)) {
|
||||
$network_id = $net['network_id'];
|
||||
|
||||
$sql = "SELECT I.interface_id FROM ip6addr AS A, ip6networks AS N, interfaces AS I, devices AS D
|
||||
WHERE A.interface_id = I.interface_id
|
||||
AND A.network = N.cidr
|
||||
AND N.network_id = '".$net['network_id']."' AND D.device_id = I.device_id and D.device_id != '".$device['device_id']."'";
|
||||
|
||||
$new_query = mysql_query($sql);
|
||||
while($new = mysql_fetch_array($new_query)) {
|
||||
|
||||
echo($new['network_id']);
|
||||
|
||||
$this_ifid = $new['interface_id'];
|
||||
$this_hostid = $new['device_id'];
|
||||
$this_hostname = $new['hostname'];
|
||||
$this_ifname = fixifName($new['ifDescr']);
|
||||
|
||||
$int_links[$this_ifid] = $this_ifid;
|
||||
$int_links_v6[$this_ifid] = 1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach($int_links as $int_link) {
|
||||
|
||||
$interface = mysql_fetch_array(mysql_query("SELECT * from interfaces AS I, devices AS D WHERE I.device_id = D.device_id and I.interface_id = '".$int_link."'"));
|
||||
|
||||
echo("$br");
|
||||
|
||||
if($int_links_phys[$int_link]) { echo("<img align=absmiddle src='images/16/connect.png'> "); } else {
|
||||
echo("<img align=absmiddle src='images/16/bullet_go.png'> "); }
|
||||
|
||||
echo("<b>" . generateiflink($interface, makeshortif($interface['ifDescr'])) . " on " . generatedevicelink($interface) );
|
||||
|
||||
if($int_links_v6[$int_link]) { echo(" <b style='color: #a10000;'>v6</b>"); }
|
||||
if($int_links_v4[$int_link]) { echo(" <b style='color: #00a100'>v4</b>"); }
|
||||
$br = "<br />";
|
||||
}
|
||||
|
||||
unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br);
|
||||
|
||||
echo("</td></tr>");
|
||||
|
||||
// If we're showing graphs, generate the graph and print the img tags
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
|
||||
$i = "1";
|
||||
|
||||
if($view == "alerted") {
|
||||
if($_GET['view'] == "alerted") {
|
||||
$where = "";
|
||||
} elseif ($view == "external") {
|
||||
} elseif ($_GET['view'] == "external") {
|
||||
$where = "AND D.bgpLocalAs != B.bgpPeerRemoteAs";
|
||||
} elseif ($view == "internal") {
|
||||
} elseif ($_GET['view'] == "internal") {
|
||||
$where = "AND D.bgpLocalAs = B.bgpPeerRemoteAs";
|
||||
}
|
||||
|
||||
@@ -18,20 +18,22 @@
|
||||
|
||||
if(!is_integer($i/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; }
|
||||
|
||||
if($peer['bgpPeerState'] == "established") { $col = "green"; } else { $col = "red"; $bg_colour = "#ffcccc"; }
|
||||
if($peer['bgpPeerAdminStatus'] == "start") { $admin_col = "green"; } else { $admin_col = "red"; $bg_colour = "#cccccc"; }
|
||||
if($peer['bgpPeerState'] == "established") { $col = "green"; } else { $col = "red"; $nobg_colour = "#ffcccc"; }
|
||||
if($peer['bgpPeerAdminStatus'] == "start") { $admin_col = "green"; } else { $admin_col = "gray"; }
|
||||
|
||||
if($peer['bgpPeerRemoteAs'] == $device['bgpLocalAs']) { $peer_type = "<span style='color: #00f;'>iBGP</span>"; } else { $peer_type = "<span style='color: #0a0;'>eBGP</span>"; }
|
||||
if($peer['bgpPeerRemoteAs'] == $peer['bgpLocalAs']) { $peer_type = "<span style='color: #00f;'>iBGP</span>"; } else { $peer_type = "<span style='color: #0a0;'>eBGP</span>";
|
||||
if($peer['bgpPeerRemoteAS'] >= '64512' && $peer['bgpPeerRemoteAS'] =< '65535') { $peer_type = "<span style='color: #f00;'>Priv eBGP</span>"; }
|
||||
}
|
||||
|
||||
$peerhost = mysql_fetch_array(mysql_query("SELECT * FROM ipaddr AS A, interfaces AS I, devices AS D WHERE A.addr = '".$peer['bgpPeerIdentifier']."' AND I.interface_id = A.interface_id AND D.device_id = I.device_id"));
|
||||
|
||||
if($peerhost) { $peername = generatedevicelink($peerhost); } else { unset($peername); }
|
||||
if($peerhost) { $peername = generatedevicelink($peerhost, shorthost($peerhost['hostname'])); } else { unset($peername); }
|
||||
|
||||
echo("<tr bgcolor=$bg_colour>
|
||||
<td width=20><span class=list-large><center>$i</center></span></td>
|
||||
<td width=175>".generatedevicelink($peer)."</td>
|
||||
<td width=220><span class=list-large>" . $peer['bgpPeerIdentifier'] . "</span><br />".$peername."</td>
|
||||
<td width=50>$peer_type</td>
|
||||
<td width=30><span class=list-large><center>$i</center></span></td>
|
||||
<td width=150>".generatedevicelink($peer, shorthost($peer['hostname']))."</td>
|
||||
<td width=150><span class=list-large>" . $peer['bgpPeerIdentifier'] . "</span><br />".$peername."</td>
|
||||
<td width=50><b>$peer_type</b></td>
|
||||
<td><strong>AS" . $peer['bgpPeerRemoteAs'] . "</strong><br />" . $peer['astext'] . "</td>
|
||||
<td><strong><span style='color: $admin_col;'>" . $peer['bgpPeerAdminStatus'] . "<span><br /><span style='color: $col;'>" . $peer['bgpPeerState'] . "</span></strong></td>
|
||||
<td>" .formatUptime($peer['bgpPeerFsmEstablishedTime']). "<br />
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
<?
|
||||
|
||||
include_once("common.php");
|
||||
include_once("ipv6-functions.php");
|
||||
include_once("generic.php");
|
||||
include_once("ios.php");
|
||||
include_once("unix.php");
|
||||
include_once("windows.php");
|
||||
include_once("procurve.php");
|
||||
include_once("snom.php");
|
||||
include_once("graphing.php");
|
||||
include_once("print-functions.php");
|
||||
include_once("billing-functions.php");
|
||||
include_once("cisco-entities.php");
|
||||
include_once("syslog.php");
|
||||
## Include from PEAR
|
||||
|
||||
include_once("Net/IPv4.php");
|
||||
include_once("Net/IPv6.php");
|
||||
|
||||
## Observer Includes
|
||||
|
||||
include_once($config['install_dir'] . "/includes/common.php");
|
||||
include_once($config['install_dir'] . "/includes/generic.php");
|
||||
include_once($config['install_dir'] . "/includes/ios.php");
|
||||
include_once($config['install_dir'] . "/includes/unix.php");
|
||||
include_once($config['install_dir'] . "/includes/windows.php");
|
||||
include_once($config['install_dir'] . "/includes/procurve.php");
|
||||
include_once($config['install_dir'] . "/includes/snom.php");
|
||||
include_once($config['install_dir'] . "/includes/graphing.php");
|
||||
include_once($config['install_dir'] . "/includes/print-functions.php");
|
||||
include_once($config['install_dir'] . "/includes/billing-functions.php");
|
||||
include_once($config['install_dir'] . "/includes/cisco-entities.php");
|
||||
include_once($config['install_dir'] . "/includes/syslog.php");
|
||||
|
||||
function write_dev_attrib($device_id, $attrib_type, $attrib_value) {
|
||||
$count_sql = "SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = '" . $device_id . "' AND `attrib_type` = '$attrib_type'";
|
||||
@@ -58,10 +64,10 @@ function getHostOS($hostname, $community, $snmpver) {
|
||||
|
||||
$sysDescr_cmd = $config['snmpget']." -O qv -" . $snmpver . " -c " . $community . " " . $hostname . " sysDescr.0";
|
||||
$sysDescr = str_replace("\"", "", trim(shell_exec($sysDescr_cmd)));
|
||||
$dir_handle = @opendir("includes/osdiscovery") or die("Unable to open $path");
|
||||
$dir_handle = @opendir($config['install_dir'] . "/includes/osdiscovery") or die("Unable to open $path");
|
||||
while ($file = readdir($dir_handle)) {
|
||||
if( preg_match("/^discover-([a-z0-9]*).php/", $file) ) {
|
||||
include("includes/osdiscovery/" . $file);
|
||||
include($config['install_dir'] . "includes/osdiscovery/" . $file);
|
||||
}
|
||||
}
|
||||
closedir($dir_handle);
|
||||
@@ -327,11 +333,12 @@ function delHost($id) {
|
||||
|
||||
|
||||
function addHost($host, $community, $snmpver) {
|
||||
global $config;
|
||||
list($hostshort) = explode(".", $host);
|
||||
if ( isDomainResolves($host)){
|
||||
if ( isPingable($host)) {
|
||||
if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' ) {
|
||||
$snmphost = trim(`snmpwalk -Oqv -$snmpver -c $community $host sysname | sed s/\"//g`);
|
||||
$snmphost = shell_exec($config['snmpget'] ." -Oqv -$snmpver -c $community $host sysName.0");
|
||||
if ($snmphost == $host || $hostshort = $host) {
|
||||
createHost ($host, $community, $snmpver);
|
||||
} else { echo("Given hostname does not match SNMP-read hostname!\n"); }
|
||||
@@ -443,10 +450,11 @@ function formatUptime($diff, $format="long") {
|
||||
}
|
||||
|
||||
function isSNMPable($hostname, $community, $snmpver) {
|
||||
$pos = `snmpget -$snmpver -c $community -t 1 $hostname sysDescr.0`;
|
||||
global $config;
|
||||
$pos = shell_exec($config['snmpget'] ." -$snmpver -c $community -t 1 $hostname sysDescr.0");
|
||||
if($pos == '') {
|
||||
$status='0';
|
||||
$posb = `snmpget -$snmpver -c $community -t 1 $hostname 1.3.6.1.2.1.7526.2.4`;
|
||||
$posb = shell_exec($config['snmpget'] ." -$snmpver -c $community -t 1 $hostname 1.3.6.1.2.1.7526.2.4");
|
||||
if($posb == '') { } else { $status='1'; }
|
||||
} else {
|
||||
$status='1';
|
||||
|
||||
@@ -1,286 +0,0 @@
|
||||
<?php
|
||||
|
||||
define("NET_IPV6_NO_NETMASK_MSG", "Netmask length not found");
|
||||
define("NET_IPV6_NO_NETMASK", 10);
|
||||
define("NET_IPV6_UNASSIGNED", 1);
|
||||
define("NET_IPV6_RESERVED", 11);
|
||||
define("NET_IPV6_RESERVED_NSAP", 12);
|
||||
define("NET_IPV6_RESERVED_IPX", 13);
|
||||
define("NET_IPV6_RESERVED_UNICAST_GEOGRAPHIC", 14);
|
||||
define("NET_IPV6_UNICAST_PROVIDER", 22);
|
||||
define("NET_IPV6_MULTICAST", 31);
|
||||
define("NET_IPV6_LOCAL_LINK", 42);
|
||||
define("NET_IPV6_LOCAL_SITE", 43);
|
||||
define("NET_IPV6_UNKNOWN_TYPE", 1001);
|
||||
|
||||
class Net_IPv6 {
|
||||
|
||||
function removeNetmaskSpec($ip) {
|
||||
$addr = $ip;
|
||||
if(false !== strpos($ip, '/')) {
|
||||
$elements = explode('/', $ip);
|
||||
if(2 == count($elements)) {
|
||||
$addr = $elements[0];
|
||||
}
|
||||
}
|
||||
return $addr;
|
||||
}
|
||||
|
||||
function getNetmaskSpec($ip) {
|
||||
$spec = '';
|
||||
if(false !== strpos($ip, '/')) {
|
||||
$elements = explode('/', $ip);
|
||||
if(2 == count($elements)) {
|
||||
$spec = $elements[1];
|
||||
}
|
||||
}
|
||||
return $spec;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getNetmask()
|
||||
|
||||
function getNetmask($ip, $bits = null) {
|
||||
if(null==$bits) {
|
||||
$elements = explode('/', $ip);
|
||||
if(2 == count($elements)) {
|
||||
$addr = $elements[0];
|
||||
$bits = $elements[1];
|
||||
} else {
|
||||
require_once 'PEAR.php';
|
||||
return PEAR::raiseError(NET_IPV6_NO_NETMASK_MSG, NET_IPV6_NO_NETMASK);
|
||||
}
|
||||
} else {
|
||||
$addr = $ip;
|
||||
}
|
||||
$addr = Net_IPv6::uncompress($addr);
|
||||
$binNetmask = str_repeat('1', $bits).str_repeat('0', 128 - $bits);
|
||||
return Net_IPv6::_bin2Ip(Net_IPv6::_ip2Bin($addr) & $binNetmask);
|
||||
}
|
||||
|
||||
function isInNetmask($ip, $netmask, $bits=null) {
|
||||
// try to get the bit count
|
||||
if(null == $bits) {
|
||||
$elements = explode('/', $ip);
|
||||
if(2 == count($elements)) {
|
||||
$ip = $elements[0];
|
||||
$bits = $elements[1];
|
||||
} else if(null == $bits) {
|
||||
$elements = explode('/', $netmask);
|
||||
if(2 == count($elements)) {
|
||||
$netmask = $elements[0];
|
||||
$bits = $elements[1];
|
||||
}
|
||||
if(null == $bits) {
|
||||
require_once 'PEAR.php';
|
||||
return PEAR::raiseError(NET_IPV6_NO_NETMASK_MSG, NET_IPV6_NO_NETMASK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$binIp = Net_IPv6::_ip2Bin(Net_IPv6::removeNetmaskSpec($ip));
|
||||
$binNetmask = Net_IPv6::_ip2Bin(Net_IPv6::removeNetmaskSpec($netmask));
|
||||
if(null != $bits && "" != $bits && 0 == strncmp( $binNetmask, $binIp, $bits)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function getAddressType($ip) {
|
||||
$ip = Net_IPv6::removeNetmaskSpec($ip);
|
||||
$binip = Net_IPv6::_ip2Bin($ip);
|
||||
if(0 == strncmp('1111111010', $binip, 10)) {
|
||||
return NET_IPV6_LOCAL_LINK;
|
||||
} else if(0 == strncmp('1111111011', $binip, 10)) {
|
||||
return NET_IPV6_LOCAL_SITE;
|
||||
} else if (0 == strncmp('111111100', $binip, 9)) {
|
||||
return NET_IPV6_UNASSIGNED;
|
||||
} else if (0 == strncmp('11111111', $binip, 8)) {
|
||||
return NET_IPV6_MULTICAST;
|
||||
} else if (0 == strncmp('00000000', $binip, 8)) {
|
||||
return NET_IPV6_RESERVED;
|
||||
} else if (0 == strncmp('00000001', $binip, 8) ||
|
||||
0 == strncmp('1111110', $binip, 7)) {
|
||||
return NET_IPV6_UNASSIGNED;
|
||||
} else if (0 == strncmp('0000001', $binip, 7)) {
|
||||
return NET_IPV6_RESERVED_NSAP;
|
||||
} else if (0 == strncmp('0000010', $binip, 7)) {
|
||||
return NET_IPV6_RESERVED_IPX;;
|
||||
} else if (0 == strncmp('0000011', $binip, 7) ||
|
||||
0 == strncmp('111110', $binip, 6) ||
|
||||
0 == strncmp('11110', $binip, 5) ||
|
||||
0 == strncmp('00001', $binip, 5) ||
|
||||
0 == strncmp('1110', $binip, 4) ||
|
||||
0 == strncmp('0001', $binip, 4) ||
|
||||
0 == strncmp('001', $binip, 3) ||
|
||||
0 == strncmp('011', $binip, 3) ||
|
||||
0 == strncmp('101', $binip, 3) ||
|
||||
0 == strncmp('110', $binip, 3)) {
|
||||
return NET_IPV6_UNASSIGNED;
|
||||
} else if (0 == strncmp('010', $binip, 3)) {
|
||||
return NET_IPV6_UNICAST_PROVIDER;
|
||||
} else if (0 == strncmp('100', $binip, 3)) {
|
||||
return NET_IPV6_RESERVED_UNICAST_GEOGRAPHIC;
|
||||
}
|
||||
return NET_IPV6_UNKNOWN_TYPE;
|
||||
}
|
||||
|
||||
|
||||
function Uncompress($ip) {
|
||||
$netmask = Net_IPv6::getNetmaskSpec($ip);
|
||||
$uip = Net_IPv6::removeNetmaskSpec($ip);
|
||||
|
||||
$c1 = -1;
|
||||
$c2 = -1;
|
||||
if (false !== strpos($uip, '::') ) {
|
||||
list($ip1, $ip2) = explode('::', $uip);
|
||||
|
||||
if(""==$ip1) {
|
||||
$c1 = -1;
|
||||
} else {
|
||||
$pos = 0;
|
||||
if(0 < ($pos = substr_count($ip1, ':'))) {
|
||||
$c1 = $pos;
|
||||
} else {
|
||||
$c1 = 0;
|
||||
}
|
||||
}
|
||||
if(""==$ip2) {
|
||||
$c2 = -1;
|
||||
} else {
|
||||
$pos = 0;
|
||||
if(0 < ($pos = substr_count($ip2, ':'))) {
|
||||
$c2 = $pos;
|
||||
} else {
|
||||
$c2 = 0;
|
||||
}
|
||||
}
|
||||
if(strstr($ip2, '.')) {
|
||||
$c2++;
|
||||
}
|
||||
if(-1 == $c1 && -1 == $c2) { // ::
|
||||
$uip = "0:0:0:0:0:0:0:0";
|
||||
} else if(-1==$c1) { // ::xxx
|
||||
$fill = str_repeat('0:', 7-$c2);
|
||||
$uip = str_replace('::', $fill, $uip);
|
||||
} else if(-1==$c2) { // xxx::
|
||||
$fill = str_repeat(':0', 7-$c1);
|
||||
$uip = str_replace('::', $fill, $uip);
|
||||
} else { // xxx::xxx
|
||||
$fill = str_repeat(':0:', 6-$c2-$c1);
|
||||
$uip = str_replace('::', $fill, $uip);
|
||||
$uip = str_replace('::', ':', $uip);
|
||||
}
|
||||
}
|
||||
if('' != $netmask) {
|
||||
$uip = $uip.'/'.$netmask;
|
||||
}
|
||||
return $uip;
|
||||
}
|
||||
|
||||
function Compress($ip) {
|
||||
|
||||
$netmask = Net_IPv6::getNetmaskSpec($ip);
|
||||
$ip = Net_IPv6::removeNetmaskSpec($ip);
|
||||
if (!strstr($ip, '::')) {
|
||||
$ipp = explode(':',$ip);
|
||||
for($i=0; $i<count($ipp); $i++) {
|
||||
$ipp[$i] = dechex(hexdec($ipp[$i]));
|
||||
}
|
||||
$cip = ':' . join(':',$ipp) . ':';
|
||||
preg_match_all("/(:0)+/", $cip, $zeros);
|
||||
if (count($zeros[0])>0) {
|
||||
$match = '';
|
||||
foreach($zeros[0] as $zero) {
|
||||
if (strlen($zero) > strlen($match))
|
||||
$match = $zero;
|
||||
}
|
||||
$cip = preg_replace('/' . $match . '/', ':', $cip, 1);
|
||||
}
|
||||
$cip = preg_replace('/((^:)|(:$))/', '' ,$cip);
|
||||
$cip = preg_replace('/((^:)|(:$))/', '::' ,$cip);
|
||||
}
|
||||
if('' != $netmask) {
|
||||
$cip = $cip.'/'.$netmask;
|
||||
}
|
||||
return $cip;
|
||||
}
|
||||
|
||||
function SplitV64($ip) {
|
||||
$ip = Net_IPv6::removeNetmaskSpec($ip);
|
||||
$ip = Net_IPv6::Uncompress($ip);
|
||||
if (strstr($ip, '.')) {
|
||||
$pos = strrpos($ip, ':');
|
||||
$ip{$pos} = '_';
|
||||
$ipPart = explode('_', $ip);
|
||||
return $ipPart;
|
||||
} else {
|
||||
return array($ip, "");
|
||||
}
|
||||
}
|
||||
|
||||
function checkIPv6($ip) {
|
||||
$ip = Net_IPv6::removeNetmaskSpec($ip);
|
||||
$ipPart = Net_IPv6::SplitV64($ip);
|
||||
$count = 0;
|
||||
if (!empty($ipPart[0])) {
|
||||
$ipv6 =explode(':', $ipPart[0]);
|
||||
for ($i = 0; $i < count($ipv6); $i++) {
|
||||
$dec = hexdec($ipv6[$i]);
|
||||
$hex = strtoupper(preg_replace("/^[0]{1,3}(.*[0-9a-fA-F])$/", "\\1", $ipv6[$i]));
|
||||
if ($ipv6[$i] >= 0 && $dec <= 65535 && $hex == strtoupper(dechex($dec))) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if (8 == $count) {
|
||||
return true;
|
||||
} elseif (6 == $count and !empty($ipPart[1])) {
|
||||
$ipv4 = explode('.',$ipPart[1]);
|
||||
$count = 0;
|
||||
for ($i = 0; $i < count($ipv4); $i++) {
|
||||
if ($ipv4[$i] >= 0 && (integer)$ipv4[$i] <= 255 && preg_match("/^\d{1,3}$/", $ipv4[$i])) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if (4 == $count) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function _ip2Bin($ip) {
|
||||
$binstr = '';
|
||||
$ip = Net_IPv6::removeNetmaskSpec($ip);
|
||||
$ip = Net_IPv6::Uncompress($ip);
|
||||
$parts = explode(':', $ip);
|
||||
foreach($parts as $v) {
|
||||
$str = base_convert($v, 16, 2);
|
||||
$binstr .= str_pad($str, 16, '0', STR_PAD_LEFT);
|
||||
}
|
||||
return $binstr;
|
||||
}
|
||||
|
||||
function _bin2Ip($bin) {
|
||||
$ip = "";
|
||||
if(strlen($bin)<128) {
|
||||
$bin = str_pad($str, 128, '0', STR_PAD_LEFT);
|
||||
}
|
||||
$parts = str_split($bin, "16");
|
||||
foreach($parts as $v) {
|
||||
$str = base_convert($v, 2, 16);
|
||||
$ip .= $str.":";
|
||||
}
|
||||
$ip = substr($ip, 0,-1);
|
||||
return $ip;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
22
ipv6.php
22
ipv6.php
@@ -9,11 +9,13 @@ while ($device = mysql_fetch_array($q)) {
|
||||
|
||||
echo("\n" . $device['hostname'] . " : ");
|
||||
|
||||
$oids = shell_exec("snmpwalk -v2c -c v05tr0n82 ".$device['hostname']." ipAddressIfIndex.ipv6 -Osq");
|
||||
$oids = shell_exec("snmpwalk -v2c -c ".$device['community']." ".$device['hostname']." ipAddressIfIndex.ipv6 -Osq");
|
||||
$oids = str_replace("ipAddressIfIndex.ipv6.", "", $oids); $oids = str_replace("\"", "", $oids); $oids = trim($oids);
|
||||
|
||||
foreach(explode("\n", $oids) as $data) {
|
||||
$data = trim($data);
|
||||
list($ipv6addr,$ifIndex) = explode(" ", $data);
|
||||
|
||||
$oid = "";
|
||||
$sep = ''; $adsep = '';
|
||||
unset($address);
|
||||
@@ -33,6 +35,8 @@ while ($device = mysql_fetch_array($q)) {
|
||||
$network = trim(shell_exec($config['sipcalc']." $address/$cidr | grep Subnet | cut -f 2 -d '-'"));
|
||||
$comp = trim(shell_exec($config['sipcalc']." $address/$cidr | grep Compressed | cut -f 2 -d '-'"));
|
||||
|
||||
$valid_ips[] = $address . " " . $ifIndex;
|
||||
|
||||
if (mysql_result(mysql_query("SELECT count(*) FROM `interfaces` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $cidr > '0' && $cidr < '129' && $comp != '::1') {
|
||||
$i_query = "SELECT interface_id FROM `interfaces` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'";
|
||||
$interface_id = mysql_result(mysql_query($i_query), 0);
|
||||
@@ -50,6 +54,22 @@ while ($device = mysql_fetch_array($q)) {
|
||||
echo("A");
|
||||
}
|
||||
} else { echo("."); }
|
||||
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM ip6addr AS A, interfaces AS I WHERE A.interface_id = I.interface_id AND I.device_id = '".$device['device_id']."'";
|
||||
$data = mysql_query($sql);
|
||||
while($row = mysql_fetch_array($data)) {
|
||||
unset($valid);
|
||||
foreach($valid_ips as $valid_ip) {
|
||||
if($row['addr'] . " " . $row['ifIndex'] == $valid_ip) { $valid = 1; }
|
||||
}
|
||||
if(!$valid) { echo("-"); mysql_query("DELETE FROM ip6addr WHERE ip6addr_id = '".$row['ip6addr_id']."'");}
|
||||
}
|
||||
|
||||
unset($valid_ips);
|
||||
|
||||
echo("\n");
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -250,7 +250,7 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
|
||||
if ($uptime) {
|
||||
|
||||
$old_uptime = mysql_result(mysql_query("SELECT `attrib_value` FROM `devices_attribs` WHERE `device_id` = '" . $device['device_id'] . "' AND `attrib_type` = 'uptime'"), 0);
|
||||
$old_uptime = @mysql_result(mysql_query("SELECT `attrib_value` FROM `devices_attribs` WHERE `device_id` = '" . $device['device_id'] . "' AND `attrib_type` = 'uptime'"), 0);
|
||||
|
||||
if( $uptime < $old_uptime ) {
|
||||
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
|
||||
@@ -284,7 +284,7 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
$update_query = "UPDATE `devices` SET ";
|
||||
$update_query .= $update;
|
||||
$update_query .= " WHERE `device_id` = '" . $device['device_id'] . "'";
|
||||
echo("Updating " . $device['hostname'] . "\n" . $update_query . "\n");
|
||||
echo("Updating " . $device['hostname'] . "\n");
|
||||
$update_result = mysql_query($update_query);
|
||||
} else {
|
||||
echo("No Changes to " . $device['hostname'] . "\n");
|
||||
|
||||
Reference in New Issue
Block a user