";
+ $link .= "onmouseover=\"return overlib('
" . $interface['hostname'] . " - " . fixifName($interface['ifDescr']) . "
";
$link .= $interface['ifAlias'] . "

'".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">$text";
return $link;
}
-function generatedevicelink($device, $text=0, $start=0, $end=0) {
+function generatedevicelink($device, $text=0, $start=0, $end=0)
+{
global $twoday; global $day; global $now; global $config;
if(!$start) { $start = $day; }
if(!$end) { $end = $now; }
@@ -279,7 +285,8 @@ function generatedevicelink($device, $text=0, $start=0, $end=0) {
}
-function device_traffic_image($device, $width, $height, $from, $to) {
+function device_traffic_image($device, $width, $height, $from, $to)
+{
return "

";
}
@@ -293,7 +300,8 @@ function devclass($device) {
}
-function getImage($host) {
+function getImage($host)
+{
$sql = "SELECT * FROM `devices` WHERE `device_id` = '$host'";
$data = mysql_fetch_array(mysql_query($sql));
$type = strtolower($data['os']);
@@ -310,7 +318,8 @@ $type = strtolower($data['os']);
}
-function renamehost($id, $new) {
+function renamehost($id, $new)
+{
global $config;
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
shell_exec("mv ".$config['rrd_dir']."/$host ".$config['rrd_dir']."/$new");
@@ -318,7 +327,8 @@ function renamehost($id, $new) {
mysql_query("INSERT INTO eventlog (host, datetime, message) VALUES ('" . $id . "', NULL, NOW(), 'Hostname changed -> $new (console)')");
}
-function delHost($id) {
+function delHost($id)
+{
global $config;
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
mysql_query("DELETE FROM `devices` WHERE `device_id` = '$id'");
@@ -348,7 +358,8 @@ function delHost($id) {
}
-function addHost($host, $community, $snmpver) {
+function addHost($host, $community, $snmpver)
+{
global $config;
list($hostshort) = explode(".", $host);
if ( isDomainResolves($host)){
@@ -367,7 +378,8 @@ function overlibprint($text) {
return "onmouseover=\"return overlib('" . $text . "');\" onmouseout=\"return nd();\"";
}
-function scanUDP ($host, $port, $timeout) {
+function scanUDP ($host, $port, $timeout)
+{
$handle = fsockopen($host, $port, &$errno, &$errstr, 2);
if (!$handle) {
}
@@ -389,23 +401,9 @@ function scanUDP ($host, $port, $timeout) {
}
}
-function humanmedia($media) {
- $media = preg_replace("/^ethernetCsmacd$/", "Ethernet", $media);
- $media = preg_replace("/^softwareLoopback$/", "Loopback", $media);
- $media = preg_replace("/^tunnel$/", "Tunnel", $media);
- $media = preg_replace("/^propVirtual$/", "Virtual Int", $media);
- $media = preg_replace("/^ppp$/", "PPP", $media);
- $media = preg_replace("/^ds1$/", "DS1", $media);
- $media = preg_replace("/^pos$/", "POS", $media);
- $media = preg_replace("/^sonet$/", "SONET", $media);
- $media = preg_replace("/^slip$/", "SLIP", $media);
- $media = preg_replace("/^mpls$/", "MPLS Layer", $media);
- $media = preg_replace("/^l2vlan$/", "VLAN Subif", $media);
- $media = preg_replace("/^atm$/", "ATM", $media);
- $media = preg_replace("/^aal5$/", "ATM AAL5", $media);
- $media = preg_replace("/^atmSubInterface$/", "ATM Subif", $media);
- $media = preg_replace("/^propPointToPointSerial$/", "PtP Serial", $media);
-
+function humanmedia($media)
+{
+ array_preg_replace($rewrite_iftype, $media);
return $media;
}
@@ -440,17 +438,20 @@ function humanspeed($speed) {
}
-function netmask2cidr($netmask) {
+function netmask2cidr($netmask)
+{
list ($network, $cidr) = explode("/", trim(`ipcalc $address/$mask | grep Network | cut -d" " -f 4`));
return $cidr;
}
-function cidr2netmask() {
+function cidr2netmask()
+{
return (long2ip(ip2long("255.255.255.255")
<< (32-$netmask)));
}
-function formatUptime($diff, $format="long") {
+function formatUptime($diff, $format="long")
+{
$yearsDiff = floor($diff/31536000);
$diff -= $yearsDiff*31536000;
$daysDiff = floor($diff/86400);
@@ -476,7 +477,8 @@ function formatUptime($diff, $format="long") {
return "$uptime";
}
-function isSNMPable($hostname, $community, $snmpver) {
+function isSNMPable($hostname, $community, $snmpver)
+{
global $config;
$pos = shell_exec($config['snmpget'] ." -$snmpver -c $community -t 1 $hostname sysDescr.0");
if($pos == '') {
@@ -489,7 +491,8 @@ function isSNMPable($hostname, $community, $snmpver) {
return $status;
}
-function isPingable($hostname) {
+function isPingable($hostname)
+{
global $config;
$status = shell_exec($config['fping'] . " $hostname");
if(strstr($status, "alive")) {
@@ -500,11 +503,13 @@ function isPingable($hostname) {
}
-function is_odd($number) {
+function is_odd($number)
+{
return $number & 1; // 0 = even, 1 = odd
}
-function isValidInterface($if) {
+function isValidInterface($if)
+{
global $config;
$if = strtolower($if);
$nullintf = 0;
@@ -521,7 +526,8 @@ function isValidInterface($if) {
} else { return 0; }
}
-function ifclass($ifOperStatus, $ifAdminStatus) {
+function ifclass($ifOperStatus, $ifAdminStatus)
+{
$ifclass = "interface-upup";
if ($ifAdminStatus == "down") { $ifclass = "interface-admindown"; }
if ($ifAdminStatus == "up" && $ifOperStatus== "down") { $ifclass = "interface-updown"; }
@@ -529,68 +535,16 @@ function ifclass($ifOperStatus, $ifAdminStatus) {
return $ifclass;
}
-function makeshortif($if) {
- $if = strtolower($if);
- $if = str_replace("tengigabitethernet","Te", $if);
- $if = str_replace("gigabitethernet","Gi", $if);
- $if = str_replace("fastethernet","Fa", $if);
- $if = str_replace("ethernet","Et", $if);
- $if = str_replace("serial","Se", $if);
- $if = str_replace("pos","Pos", $if);
- $if = str_replace("port-channel","Po", $if);
- $if = str_replace("atm","Atm", $if);
- $if = str_replace("null", "Null", $if);
- $if = str_replace("loopback","Lo", $if);
- $if = str_replace("dialer","Di", $if);
- $if = str_replace("vlan","Vlan", $if);
- $if = str_replace("tunnel","Tunnel", $if);
- return $if;
-}
-
-function utime() {
+function utime()
+{
$time = explode( " ", microtime());
$usec = (double)$time[0];
$sec = (double)$time[1];
return $sec + $usec;
}
-function fixiftype ($type) {
- $type = str_replace("ethernetCsmacd", "Ethernet", $type);
- $type = str_replace("tunnel", "Tunnel", $type);
- $type = str_replace("softwareLoopback", "Software Loopback", $type);
- $type = str_replace("propVirtual", "Ethernet VLAN", $type);
- $type = str_replace("ethernetCsmacd", "Ethernet", $type);
- $type = str_replace("l2vlan", "Ethernet VLAN", $type);
- $type = str_replace("frameRelay", "Frame Relay", $type);
- $type = str_replace("propPointToPointSerial", "PointToPoint Serial", $type);
- return ($type);
-}
-
-function fixifName ($inf) {
- $inf = str_replace("ether", "Ether", $inf);
- $inf = str_replace("gig", "Gig", $inf);
- $inf = str_replace("fast", "Fast", $inf);
- $inf = str_replace("ten", "Ten", $inf);
- $inf = str_replace("bvi", "BVI", $inf);
- $inf = str_replace("vlan", "Vlan", $inf);
- $inf = str_replace("ether", "Ether", $inf);
- $inf = str_replace("-802.1q Vlan subif", "", $inf);
- $inf = str_replace("-802.1q", "", $inf);
- $inf = str_replace("tunnel", "Tunnel", $inf);
- $inf = str_replace("serial", "Serial", $inf);
- $inf = str_replace("-aal5 layer", " aal5", $inf);
- $inf = str_replace("null", "Null", $inf);
- $inf = str_replace("atm", "ATM", $inf);
- $inf = str_replace("port-channel", "Port-Channel", $inf);
- $inf = str_replace("dial", "Dial", $inf);
- $inf = str_replace("hp procurve switch software loopback interface", "Loopback Interface", $inf);
- $inf = str_replace("control plane interface", "Control Plane", $inf);
- $inf = str_replace("loop", "Loop", $inf);
- $inf = preg_replace("/^([0-9]+)$/", "Interface \\0", $inf);
- return $inf;
-}
-
-function fixIOSFeatures($features){
+function fixIOSFeatures($features)
+{
$features = preg_replace("/^PK9S$/", "IP w/SSH LAN Only", $features);
$features = str_replace("LANBASEK9", "Lan Base Crypto", $features);
$features = str_replace("LANBASE", "Lan Base", $features);