diff --git a/includes/common.php b/includes/common.php index c927431f7..903f0e88e 100644 --- a/includes/common.php +++ b/includes/common.php @@ -2,14 +2,14 @@ ## Common Functions - - function get_port_by_id($port_id) { - if(is_numeric($port_id)) { + if (is_numeric($port_id)) + { $port = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` WHERE `interface_id` = '".$port_id."'")); } - if(is_array($port)){ + if (is_array($port)) + { return $port; } else { return FALSE; @@ -18,10 +18,12 @@ function get_port_by_id($port_id) function get_application_by_id($application_id) { - if(is_numeric($application_id)) { + if (is_numeric($application_id)) + { $application = mysql_fetch_assoc(mysql_query("SELECT * FROM `applications` WHERE `app_id` = '".$application_id."'")); } - if(is_array($application)){ + if (is_array($application)) + { return $application; } else { return FALSE; @@ -30,21 +32,26 @@ function get_application_by_id($application_id) function get_sensor_by_id($sensor_id) { - if(is_numeric($sensor_id)) { + if (is_numeric($sensor_id)) + { $sensor = mysql_fetch_assoc(mysql_query("SELECT * FROM `sensors` WHERE `sensor_id` = '".$sensor_id."'")); } - if(is_array($sensor)){ + if (is_array($sensor)) + { return $sensor; } else { return FALSE; } } -function get_device_id_by_interface_id($interface_id) { - if(is_numeric($interface_id)) { +function get_device_id_by_interface_id($interface_id) +{ + if (is_numeric($interface_id)) + { $device_id = mysql_result(mysql_query("SELECT `device_id` FROM `ports` WHERE `interface_id` = '".$interface_id."'"),0); } - if(is_numeric($device_id)){ + if (is_numeric($device_id)) + { return $device_id; } else { return FALSE; @@ -54,15 +61,18 @@ function get_device_id_by_interface_id($interface_id) { function ifclass($ifOperStatus, $ifAdminStatus) { $ifclass = "interface-upup"; + if ($ifAdminStatus == "down") { $ifclass = "interface-admindown"; } if ($ifAdminStatus == "up" && $ifOperStatus== "down") { $ifclass = "interface-updown"; } if ($ifAdminStatus == "up" && $ifOperStatus== "up") { $ifclass = "interface-upup"; } + return $ifclass; } function device_by_id_cache($device_id) { global $device_cache; + if (is_array($device_cache[$device_id])) { $device = $device_cache[$device_id]; @@ -70,86 +80,106 @@ function device_by_id_cache($device_id) $device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'")); $device_cache[$device_id] = $device; } + return $device; } -function truncate($substring, $max = 50, $rep = '...'){ - if(strlen($substring) < 1){ $string = $rep; } else { $string = $substring; } +function truncate($substring, $max = 50, $rep = '...') +{ + if (strlen($substring) < 1){ $string = $rep; } else { $string = $substring; } $leave = $max - strlen ($rep); - if(strlen($string) > $max){ return substr_replace($string, $rep, $leave); } else { return $string; } + if (strlen($string) > $max){ return substr_replace($string, $rep, $leave); } else { return $string; } } -function mres($string) { // short function wrapper because the real one is stupidly long and ugly. aestetics. +function mres($string) +{ // short function wrapper because the real one is stupidly long and ugly. aestetics. return mysql_real_escape_string($string); } -function getifhost($id) { - $sql = mysql_query("SELECT `device_id` from `ports` WHERE `interface_id` = '$id'"); - $result = @mysql_result($sql, 0); - return $result; +function getifhost($id) +{ + $sql = mysql_query("SELECT `device_id` from `ports` WHERE `interface_id` = '$id'"); + $result = @mysql_result($sql, 0); + + return $result; } -function gethostbyid($id) { - $sql = mysql_query("SELECT `hostname` FROM `devices` WHERE `device_id` = '$id'"); - $result = @mysql_result($sql, 0); - return $result; +function gethostbyid($id) +{ + $sql = mysql_query("SELECT `hostname` FROM `devices` WHERE `device_id` = '$id'"); + $result = @mysql_result($sql, 0); + + return $result; } function strgen ($length = 16) { - $entropy = array(0,1,2,3,4,5,6,7,8,9,'a','A','b','B','c','C','d','D','e', - 'E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n', - 'N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w', - 'W','x','X','y','Y','z','Z'); - $string = ""; - for ($i=0; $i<$length; $i++) { - $key = mt_rand(0,61); - $string .= $entropy[$key]; - } - return $string; + $entropy = array(0,1,2,3,4,5,6,7,8,9,'a','A','b','B','c','C','d','D','e', + 'E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n', + 'N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w', + 'W','x','X','y','Y','z','Z'); + $string = ""; + + for ($i=0; $i<$length; $i++) + { + $key = mt_rand(0,61); + $string .= $entropy[$key]; + } + + return $string; } -function getpeerhost($id) { - $sql = mysql_query("SELECT `device_id` from `bgpPeers` WHERE `bgpPeer_id` = '$id'"); - $result = @mysql_result($sql, 0); - return $result; +function getpeerhost($id) +{ + $sql = mysql_query("SELECT `device_id` from `bgpPeers` WHERE `bgpPeer_id` = '$id'"); + $result = @mysql_result($sql, 0); + + return $result; } -function getifindexbyid($id) { - $sql = mysql_query("SELECT `ifIndex` FROM `ports` WHERE `interface_id` = '$id'"); - $result = @mysql_result($sql, 0); - return $result; +function getifindexbyid($id) +{ + $sql = mysql_query("SELECT `ifIndex` FROM `ports` WHERE `interface_id` = '$id'"); + $result = @mysql_result($sql, 0); + + return $result; } -function getifbyid($id) { - $sql = mysql_query("SELECT * FROM `ports` WHERE `interface_id` = '$id'"); - $result = @mysql_fetch_array($sql); - return $result; +function getifbyid($id) +{ + $sql = mysql_query("SELECT * FROM `ports` WHERE `interface_id` = '$id'"); + $result = @mysql_fetch_array($sql); + + return $result; } -function getifdescrbyid($id) { - $sql = mysql_query("SELECT `ifDescr` FROM `ports` WHERE `interface_id` = '$id'"); - $result = @mysql_result($sql, 0); - return $result; +function getifdescrbyid($id) +{ + $sql = mysql_query("SELECT `ifDescr` FROM `ports` WHERE `interface_id` = '$id'"); + $result = @mysql_result($sql, 0); + + return $result; } -function getidbyname($domain){ - $sql = mysql_query("SELECT `device_id` FROM `devices` WHERE `hostname` = '$domain'"); - $result = @mysql_result($sql, 0); - return $result; +function getidbyname($domain) +{ + $sql = mysql_query("SELECT `device_id` FROM `devices` WHERE `hostname` = '$domain'"); + $result = @mysql_result($sql, 0); + + return $result; } -function gethostosbyid($id) { - $sql = mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$id'"); - $result = @mysql_result($sql, 0); - return $result; +function gethostosbyid($id) +{ + $sql = mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$id'"); + $result = @mysql_result($sql, 0); + + return $result; } function safename($name) { return preg_replace('/[^a-zA-Z0-9,._\-]/', '_', $name); - } - -?> +?> \ No newline at end of file diff --git a/includes/functions.php b/includes/functions.php index 8b03aa44e..4c1e4f380 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -137,7 +137,8 @@ function getHostOS($device) if ($os) { return $os; } else { return "generic"; } } -function formatRates($rate) { +function formatRates($rate) +{ $rate = format_si($rate) . "bps"; return $rate; } @@ -150,12 +151,15 @@ function formatstorage($rate, $round = '2') function format_si($rate) { - if ($rate >= "0.1") { + if ($rate >= "0.1") + { $sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E'); $round = Array('2','2','2','2','2','2','2','2','2'); $ext = $sizes[0]; for ($i=1; (($i < count($sizes)) && ($rate >= 1000)); $i++) { $rate = $rate / 1000; $ext = $sizes[$i]; } - } else { + } + else + { $sizes = Array('', 'm', 'u', 'n'); $round = Array('2','2','2','2'); $ext = $sizes[0]; @@ -217,7 +221,8 @@ function getImage($host) } else { if (file_exists($config['html_dir'] . "/images/os/$type" . ".png")){ $image = ''; } elseif (file_exists($config['html_dir'] . "/images/os/$type" . ".gif")){ $image = ''; } - if ($type == "linux") { + if ($type == "linux") + { $features = strtolower(trim($data['features'])); list($distro) = split(" ", $features); if (file_exists($config['html_dir'] . "/images/os/$distro" . ".png")){ $image = ''; @@ -227,10 +232,11 @@ function getImage($host) return $image; } -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"); + rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new"); mysql_query("UPDATE devices SET hostname = '$new' WHERE device_id = '$id'"); eventlog("Hostname changed -> $new (console)", $id); } @@ -248,7 +254,7 @@ function delete_port($int_id) mysql_query("DELETE FROM `bill_ports` WHERE `port_id` = '$int_id'"); mysql_query("DELETE from `pseudowires` WHERE `interface_id` = '$int_id'"); mysql_query("DELETE FROM `ports` WHERE `interface_id` = '$int_id'"); - shell_exec("rm -rf ".trim($config['rrd_dir'])."/".trim($interface['hostname'])."/".$interface['ifIndex'].".rrd"); + unlink(trim($config['rrd_dir'])."/".trim($interface['hostname'])."/".$interface['ifIndex'].".rrd"); } function delete_device($id) @@ -257,7 +263,8 @@ function delete_device($id) $host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0); mysql_query("DELETE FROM `devices` WHERE `device_id` = '$id'"); $int_query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '$id'"); - while($int_data = mysql_fetch_array($int_query)) { + while($int_data = mysql_fetch_array($int_query)) + { $int_if = $int_data['ifDescr']; $int_id = $int_data['interface_id']; delete_port($int_id); @@ -295,6 +302,7 @@ function addHost($host, $community, $snmpver, $port = 161) { if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' ) { + # FIXME internalize $snmphost = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -Oqv -$snmpver -c $community $host:$port sysName.0"); if ($snmphost == $host || $hostshort = $host) { @@ -308,8 +316,6 @@ function addHost($host, $community, $snmpver, $port = 161) function scanUDP ($host, $port, $timeout) { $handle = fsockopen($host, $port, $errno, $errstr, 2); - if (!$handle) { - } socket_set_timeout ($handle, $timeout); $write = fwrite($handle,"\x00"); if (!$write) { next; } @@ -317,7 +323,8 @@ function scanUDP ($host, $port, $timeout) $header = fread($handle, 1); $endTime = time(); $timeDiff = $endTime - $startTime; - if ($timeDiff >= $timeout) { + if ($timeDiff >= $timeout) + { fclose($handle); return 1; } else { fclose($handle); return 0; } } @@ -347,13 +354,16 @@ function formatUptime($diff, $format="long") $uptime = ""; - if ($format == "short") { + if ($format == "short") + { if ($yearsDiff > '0') { $uptime .= $yearsDiff . "y "; } if ($daysDiff > '0') { $uptime .= $daysDiff . "d "; } if ($hrsDiff > '0') { $uptime .= $hrsDiff . "h "; } if ($minsDiff > '0') { $uptime .= $minsDiff . "m "; } if ($secsDiff > '0') { $uptime .= $secsDiff . "s "; } - } else { + } + else + { if ($yearsDiff > '0') { $uptime .= $yearsDiff . " years, "; } if ($daysDiff > '0') { $uptime .= $daysDiff . " day" . ($daysDiff != 1 ? 's' : '' ) . ", "; } if ($hrsDiff > '0') { $uptime .= $hrsDiff . "h "; } @@ -366,43 +376,54 @@ function formatUptime($diff, $format="long") function isSNMPable($hostname, $community, $snmpver, $port) { global $config; + # FIXME internalize $pos = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -$snmpver -c $community -t 1 $hostname:$port sysObjectID.0"); - if ($pos == '') { + if ($pos == '') + { return false; } else { return true; } } -function isPingable($hostname) { +function isPingable($hostname) +{ global $config; $status = shell_exec($config['fping'] . " $hostname"); - if (strstr($status, "alive")) { + if (strstr($status, "alive")) + { return TRUE; } else { return FALSE; } } -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; - foreach($config['bad_if'] as $bi) { - $pos = strpos($if, $bi); - if ($pos !== FALSE) { - $nullintf = 1; - echo("$if matched $bi \n"); - } + foreach($config['bad_if'] as $bi) + { + $pos = strpos($if, $bi); + if ($pos !== FALSE) + { + $nullintf = 1; + echo("$if matched $bi \n"); + } } if (preg_match('/serial[0-9]:/', $if)) { $nullintf = '1'; } - if ($nullintf != '1') { - return 1; - } else { return 0; } + if ($nullintf != '1') + { + return 1; + } else { + return 0; + } } function utime() @@ -505,27 +526,29 @@ function hoststatus($id) return $result; } -function match_network ($nets, $ip, $first=false) +function match_network($nets, $ip, $first=false) { - $return = false; - if (!is_array ($nets)) $nets = array ($nets); - foreach ($nets as $net) { - $rev = (preg_match ("/^\!/", $net)) ? true : false; - $net = preg_replace ("/^\!/", "", $net); - $ip_arr = explode('/', $net); - $net_long = ip2long($ip_arr[0]); - $x = ip2long($ip_arr[1]); - $mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]); - $ip_long = ip2long($ip); - if ($rev) { - if (($ip_long & $mask) == ($net_long & $mask)) return false; - } else { - if (($ip_long & $mask) == ($net_long & $mask)) $return = true; - if ($first && $return) return true; - } - } + $return = false; + if (!is_array ($nets)) $nets = array ($nets); + foreach ($nets as $net) + { + $rev = (preg_match ("/^\!/", $net)) ? true : false; + $net = preg_replace ("/^\!/", "", $net); + $ip_arr = explode('/', $net); + $net_long = ip2long($ip_arr[0]); + $x = ip2long($ip_arr[1]); + $mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]); + $ip_long = ip2long($ip); + if ($rev) + { + if (($ip_long & $mask) == ($net_long & $mask)) return false; + } else { + if (($ip_long & $mask) == ($net_long & $mask)) $return = true; + if ($first && $return) return true; + } + } - return $return; + return $return; } function snmp2ipv6($ipv6_snmp) @@ -565,19 +588,22 @@ function discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_orig { $i_query = "SELECT interface_id FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"; $interface_id = mysql_result(mysql_query($i_query), 0); - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1') { + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1') + { mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')"); echo("N"); } - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1') { + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1') + { mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')"); echo("N"); } $ipv6_network_id = @mysql_result(mysql_query("SELECT `ipv6_network_id` from `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0); - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = '$ipv6_address' AND `ipv6_prefixlen` = '$ipv6_prefixlen' AND `interface_id` = '$interface_id'"), 0) == '0') { + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = '$ipv6_address' AND `ipv6_prefixlen` = '$ipv6_prefixlen' AND `interface_id` = '$interface_id'"), 0) == '0') + { mysql_query("INSERT INTO `ipv6_addresses` (`ipv6_address`, `ipv6_compressed`, `ipv6_prefixlen`, `ipv6_origin`, `ipv6_network_id`, `interface_id`) VALUES ('$ipv6_address', '$ipv6_compressed', '$ipv6_prefixlen', '$ipv6_origin', '$ipv6_network_id', '$interface_id')"); echo("+"); @@ -664,37 +690,51 @@ function notify($device,$title,$message) function formatCiscoHardware(&$device, $short = false) { - - if ($device['os'] == "ios") { - if ($device['hardware']) { - if (preg_match("/^WS-C([A-Za-z0-9]+).*/", $device['hardware'], $matches)) { - if (!$short) { - $device['hardware'] = "Cisco " . $matches[1] . " (" . $device['hardware'] . ")"; - } else { - $device['hardware'] = "Cisco " . $matches[1]; - } - } elseif (preg_match("/^CISCO([0-9]+)$/", $device['hardware'], $matches)) { - $device['hardware'] = "Cisco " . $matches[1]; - } - } else { - if (preg_match("/Cisco IOS Software, C([A-Za-z0-9]+) Software.*/", $device['sysDescr'], $matches)) { - $device['hardware'] = "Cisco " . $matches[1]; - } elseif (preg_match("/Cisco IOS Software, ([0-9]+) Software.*/", $device['sysDescr'], $matches)) { - $device['hardware'] = "Cisco " . $matches[1]; - } + if ($device['os'] == "ios") + { + if ($device['hardware']) + { + if (preg_match("/^WS-C([A-Za-z0-9]+).*/", $device['hardware'], $matches)) + { + if (!$short) + { + $device['hardware'] = "Cisco " . $matches[1] . " (" . $device['hardware'] . ")"; } + else + { + $device['hardware'] = "Cisco " . $matches[1]; + } + } + elseif (preg_match("/^CISCO([0-9]+)$/", $device['hardware'], $matches)) + { + $device['hardware'] = "Cisco " . $matches[1]; + } } + else + { + if (preg_match("/Cisco IOS Software, C([A-Za-z0-9]+) Software.*/", $device['sysDescr'], $matches)) + { + $device['hardware'] = "Cisco " . $matches[1]; + } + elseif (preg_match("/Cisco IOS Software, ([0-9]+) Software.*/", $device['sysDescr'], $matches)) + { + $device['hardware'] = "Cisco " . $matches[1]; + } + } + } } # from http://ditio.net/2008/11/04/php-string-to-hex-and-hex-to-string-functions/ function hex2str($hex) { - $string=''; - for ($i=0; $i < strlen($hex)-1; $i+=2) - { - $string .= chr(hexdec($hex[$i].$hex[$i+1])); - } - return $string; + $string=''; + + for ($i=0; $i < strlen($hex)-1; $i+=2) + { + $string .= chr(hexdec($hex[$i].$hex[$i+1])); + } + + return $string; } # Convert an SNMP hex string to regular string @@ -733,4 +773,4 @@ function include_dir($dir, $regex = "") } } -?> +?> \ No newline at end of file diff --git a/includes/rewrites.php b/includes/rewrites.php index 3a67329e7..57cef8404 100644 --- a/includes/rewrites.php +++ b/includes/rewrites.php @@ -1,12 +1,13 @@ "lowerLayerDown", ); -function translate_ifOperStatus ($ifOperStatus) { +function translate_ifOperStatus ($ifOperStatus) +{ global $translate_ifOperStatus; - if($translate_ifOperStatus['$ifOperStatus']) { + + if ($translate_ifOperStatus['$ifOperStatus']) + { $ifOperStatus = $translate_ifOperStatus['$ifOperStatus']; } + return $ifOperStatus; } @@ -86,11 +99,15 @@ $translate_ifAdminStatus = array( "3" => "testing", ); -function translate_ifAdminStatus ($ifAdminStatus) { +function translate_ifAdminStatus ($ifAdminStatus) +{ global $translate_ifAdminStatus; - if($translate_ifAdminStatus[$ifAdminStatus]) { + + if ($translate_ifAdminStatus[$ifAdminStatus]) + { $ifAdminStatus = $translate_ifAdminStatus[$ifAdminStatus]; } + return $ifAdminStatus; } @@ -278,7 +295,6 @@ $rewrite_extreme_hardware = array ( '.1.3.6.1.4.1.1916.2.79' => 'Summit X450e-48p' ); - $rewrite_ironware_hardware = array( 'snFIWGSwitch' => 'Stackable FastIron workgroup', 'snFIBBSwitch' => 'Stackable FastIron backbone', @@ -702,39 +718,37 @@ $rewrite_ironware_hardware = array( ); $rewrite_ios_features = array( - "PK9S" => "IP w/SSH LAN Only", - "LANBASEK9" => "Lan Base Crypto", - "LANBASE" => "Lan Base", - "ADVENTERPRISEK9_IVS" => "Advanced Enterprise Crypto Voice", - "ADVENTERPRISEK9" => "Advanced Enterprise Crypto", - "ADVSECURITYK9" => "Advanced Security Crypto", - "K91P" => "Provider Crypto", - "K4P" => "Provider Crypto", - "ADVIPSERVICESK9" => "Adv IP Services Crypto", - "ADVIPSERVICES" => "Adv IP Services", - "IK9P" => "IP Plus Crypto", - "K9O3SY7" => "IP ADSL FW IDS Plus IPSEC 3DES", - "SPSERVICESK9" => "SP Services Crypto", - "PK9SV" => "IP MPLS/IPV6 W/SSH + BGP", - "IS" => "IP Plus", - "IPSERVICESK9" => "IP Services Crypto", - "BROADBAND" => "Broadband", - "IPBASE" => "IP Base", - "IPSERVICE" => "IP Services", - "P" => "Service Provider", - "P11" => "Broadband Router", - "G4P5" => "NRP", - "JK9S" => "Enterprise Plus Crypto", - "IK9S" => "IP Plus Crypto", - "JK" => "Enterprise Plus", - "I6Q4L2" => "Layer 2", - "I6K2L2Q4" => "Layer 2 Crypto", - "C3H2S" => "Layer 2 SI/EI", - "_WAN" => " + WAN", + 'PK9S' => 'IP w/SSH LAN Only', + 'LANBASEK9' => 'Lan Base Crypto', + 'LANBASE' => 'Lan Base', + 'ADVENTERPRISEK9_IVS' => 'Advanced Enterprise Crypto Voice', + 'ADVENTERPRISEK9' => 'Advanced Enterprise Crypto', + 'ADVSECURITYK9' => 'Advanced Security Crypto', + 'K91P' => 'Provider Crypto', + 'K4P' => 'Provider Crypto', + 'ADVIPSERVICESK9' => 'Adv IP Services Crypto', + 'ADVIPSERVICES' => 'Adv IP Services', + 'IK9P' => 'IP Plus Crypto', + 'K9O3SY7' => 'IP ADSL FW IDS Plus IPSEC 3DES', + 'SPSERVICESK9' => 'SP Services Crypto', + 'PK9SV' => 'IP MPLS/IPV6 W/SSH + BGP', + 'IS' => 'IP Plus', + 'IPSERVICESK9' => 'IP Services Crypto', + 'BROADBAND' => 'Broadband', + 'IPBASE' => 'IP Base', + 'IPSERVICE' => 'IP Services', + 'P' => 'Service Provider', + 'P11' => 'Broadband Router', + 'G4P5' => 'NRP', + 'JK9S' => 'Enterprise Plus Crypto', + 'IK9S' => 'IP Plus Crypto', + 'JK' => 'Enterprise Plus', + 'I6Q4L2' => 'Layer 2', + 'I6K2L2Q4' => 'Layer 2 Crypto', + 'C3H2S' => 'Layer 2 SI/EI', + '_WAN' => ' + WAN', ); - - $rewrite_shortif = array ( 'tengigabitethernet' => 'Te', 'gigabitethernet' => 'Gi', @@ -805,26 +819,32 @@ $rewrite_ios_features = array( // Specific rewrite functions -function makeshortif($if) +function makeshortif ($if) { global $rewrite_shortif; + $if = fixifName ($if); $if = strtolower($if); $if = array_str_replace($rewrite_shortif, $if); + return $if; } function rewrite_ios_features ($features) { global $rewrite_ios_features; + $type = array_preg_replace($rewrite_ios_features, $features); + return ($features); } function rewrite_fortinet_hardware ($hardware) { global $rewrite_fortinet_hardware; + $hardware = $rewrite_fortinet_hardware[$hardware]; + return ($hardware); } @@ -832,15 +852,19 @@ function rewrite_fortinet_hardware ($hardware) function rewrite_extreme_hardware ($hardware) { global $rewrite_extreme_hardware; + #$hardware = array_str_replace($rewrite_extreme_hardware, $hardware); $hardware = $rewrite_extreme_hardware[$hardware]; + return ($hardware); } function rewrite_ftos_hardware ($hardware) { global $rewrite_ftos_hardware; + $hardware = $rewrite_ftos_hardware[$hardware]; + return ($hardware); } @@ -848,43 +872,53 @@ function rewrite_ftos_hardware ($hardware) function rewrite_ironware_hardware ($hardware) { global $rewrite_ironware_hardware; + $hardware = array_str_replace($rewrite_ironware_hardware, $hardware); + return ($hardware); } function rewrite_junose_hardware ($hardware) { global $rewrite_junose_hardware; + $hardware = array_str_replace($rewrite_junose_hardware, $hardware); + return ($hardware); } function fixiftype ($type) { global $rewrite_iftype; + $type = array_preg_replace($rewrite_iftype, $type); + return ($type); } function fixifName ($inf) { global $rewrite_ifname; + $inf = strtolower($inf); $inf = array_str_replace($rewrite_ifname, $inf); + return $inf; } function short_hrDeviceDescr($dev) { global $rewrite_hrDevice; + $dev = array_str_replace($rewrite_hrDevice, $dev); $dev = preg_replace("/\ +/"," ", $dev); $dev = trim($dev); + return $dev; } -function short_port_descr ($desc) { - +function short_port_descr ($desc) +{ list($desc) = explode("(", $desc); list($desc) = explode("[", $desc); list($desc) = explode("{", $desc); @@ -893,29 +927,27 @@ function short_port_descr ($desc) { $desc = trim($desc); return $desc; - } - // Underlying rewrite functions - - - function array_str_replace($array, $string) +function array_str_replace($array, $string) +{ + foreach ($array as $search => $replace) { - foreach ($array as $search => $replace) { - $string = str_replace($search, $replace, $string); - } - return $string; + $string = str_replace($search, $replace, $string); } - function array_preg_replace($array, $string) + return $string; +} + +function array_preg_replace($array, $string) +{ + foreach ($array as $search => $replace) { - foreach ($array as $search => $replace) { - $string = preg_replace($search, $replace, $string); - } - return $string; + $string = preg_replace($search, $replace, $string); } + return $string; +} - -?> +?> \ No newline at end of file diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index e22e81687..7784ed935 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -477,7 +477,8 @@ function snmp_cache_oid($oid, $device, $array, $mib = 0) return $array; } -function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0) { +function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0) +{ global $config; if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } @@ -510,7 +511,7 @@ function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0) { return $array; } -function snmp_cache_portIfIndex ($device, $array) +function snmp_cache_portIfIndex($device, $array) { global $config; @@ -538,7 +539,7 @@ function snmp_cache_portIfIndex ($device, $array) return $array; } -function snmp_cache_portName ($device, $array) +function snmp_cache_portName($device, $array) { global $config; diff --git a/includes/syslog.php b/includes/syslog.php index c1ac40011..58399dbdd 100755 --- a/includes/syslog.php +++ b/includes/syslog.php @@ -1,36 +1,47 @@ +?> \ No newline at end of file diff --git a/poll-billing.php b/poll-billing.php index 441ccc0fc..555b69635 100644 --- a/poll-billing.php +++ b/poll-billing.php @@ -3,7 +3,6 @@ $debug = "1"; - include("includes/defaults.inc.php"); include("config.php"); include("includes/functions.php"); @@ -13,106 +12,112 @@ $iter = "0"; echo("Starting Polling Session ... \n\n"); $bill_query = mysql_query("select * from bills"); -while ($bill_data = mysql_fetch_array($bill_query)) { - echo("Bill : ".$bill_data['bill_name']."\n"); - - CollectData($bill_data['bill_id']); - - $iter++; +while ($bill_data = mysql_fetch_array($bill_query)) +{ + echo("Bill : ".$bill_data['bill_name']."\n"); + CollectData($bill_data['bill_id']); + $iter++; } -function CollectData($bill_id) { - $port_query = mysql_query("select * from bill_ports as P, ports as I, devices as D where P.bill_id='$bill_id' AND I.interface_id = P.port_id AND D.device_id = I.device_id"); +function CollectData($bill_id) +{ + $port_query = mysql_query("select * from bill_ports as P, ports as I, devices as D where P.bill_id='$bill_id' AND I.interface_id = P.port_id AND D.device_id = I.device_id"); - while ($port_data = mysql_fetch_array($port_query)) { - unset($port_in_measurement); - unset($port_in_delta); - unset($last_port_in_measurement); - unset($last_port_in_delta); - unset($port_out_measurement); - unset($port_out_delta); - unset($last_port_out_measurement); - unset($last_port_out_delta); + while ($port_data = mysql_fetch_array($port_query)) + { + unset($port_in_measurement); + unset($port_in_delta); + unset($last_port_in_measurement); + unset($last_port_in_delta); + unset($port_out_measurement); + unset($port_out_delta); + unset($last_port_out_measurement); + unset($last_port_out_delta); - $port_id = $port_data['port_id']; - $host = $port_data['hostname']; + $port_id = $port_data['port_id']; + $host = $port_data['hostname']; $port = $port_data['port']; - echo("\nPolling ".$port_data['ifDescr']." on ".$port_data['hostname']."\n"); + echo("\nPolling ".$port_data['ifDescr']." on ".$port_data['hostname']."\n"); - $port_in_measurement = trim(getValue($host, $port_data['community'], $port_data['snmpver'], $port, $port_data['ifIndex'], "In")); - $port_out_measurement = trim(getValue($host, $port_data['community'], $port_data['snmpver'], $port, $port_data['ifIndex'], "Out")); + $port_in_measurement = trim(getValue($host, $port_data['community'], $port_data['snmpver'], $port, $port_data['ifIndex'], "In")); + $port_out_measurement = trim(getValue($host, $port_data['community'], $port_data['snmpver'], $port, $port_data['ifIndex'], "Out")); - echo("$port_in_measurement and $port_out_measurement \n"); + echo("$port_in_measurement and $port_out_measurement \n"); - $now = mysql_result(mysql_query("SELECT NOW()"), 0); + $now = mysql_result(mysql_query("SELECT NOW()"), 0); - $last_data = getLastPortCounter($port_id,in); - if ($last_data[state] == "ok") { - $last_port_in_measurement = $last_data[counter]; - $last_port_in_delta = $last_data[delta]; - if ($port_in_measurement > $last_port_in_measurement) { - $port_in_delta = $port_in_measurement - $last_port_in_measurement; - } else { - $port_in_delta = $last_port_in_delta; - } - } else { - $port_in_delta = '0'; - } - $pim = "INSERT INTO port_in_measurements (port_id,timestamp,counter,delta) VALUES ($port_id, '$now', $port_in_measurement, $port_in_delta) "; - #echo("$pim \n"); - $pim_query = mysql_query($pim); - unset($last_data, $last_port_in_measurement, $last_port_in_delta); + $last_data = getLastPortCounter($port_id,in); + if ($last_data[state] == "ok") + { + $last_port_in_measurement = $last_data[counter]; + $last_port_in_delta = $last_data[delta]; + if ($port_in_measurement > $last_port_in_measurement) + { + $port_in_delta = $port_in_measurement - $last_port_in_measurement; + } else { + $port_in_delta = $last_port_in_delta; + } + } else { + $port_in_delta = '0'; + } + $pim = "INSERT INTO port_in_measurements (port_id,timestamp,counter,delta) VALUES ($port_id, '$now', $port_in_measurement, $port_in_delta) "; + #echo("$pim \n"); + $pim_query = mysql_query($pim); + unset($last_data, $last_port_in_measurement, $last_port_in_delta); - $last_data = getLastPortCounter($port_id,out); - if ($last_data[state] == "ok") { - $last_port_out_measurement = $last_data[counter]; - $last_port_out_delta = $last_data[delta]; - if ($port_out_measurement > $last_port_out_measurement) { - $port_out_delta = $port_out_measurement - $last_port_out_measurement; - } else { - $port_out_delta = $last_port_out_delta; - } - } else { - $port_out_delta = '0'; - } - $pom = "INSERT INTO port_out_measurements (port_id,timestamp,counter,delta) VALUES ($port_id, '$now', $port_out_measurement, $port_out_delta) "; - #echo("$pom \n"); - $pom_query = mysql_query($pom); - unset($last_data, $last_port_in_measurement, $last_port_in_delta); + $last_data = getLastPortCounter($port_id,out); + if ($last_data[state] == "ok") + { + $last_port_out_measurement = $last_data[counter]; + $last_port_out_delta = $last_data[delta]; + if ($port_out_measurement > $last_port_out_measurement) + { + $port_out_delta = $port_out_measurement - $last_port_out_measurement; + } else { + $port_out_delta = $last_port_out_delta; + } + } else { + $port_out_delta = '0'; + } + $pom = "INSERT INTO port_out_measurements (port_id,timestamp,counter,delta) VALUES ($port_id, '$now', $port_out_measurement, $port_out_delta) "; + #echo("$pom \n"); + $pom_query = mysql_query($pom); + unset($last_data, $last_port_in_measurement, $last_port_in_delta); - $delta = $delta + $port_in_delta + $port_out_delta; - $in_delta = $in_delta + $port_in_delta; - $out_delta = $out_delta + $port_out_delta; - unset($port_in_delta,$port_out_delta,$prev_delta,$prev_timestamp,$period); + $delta = $delta + $port_in_delta + $port_out_delta; + $in_delta = $in_delta + $port_in_delta; + $out_delta = $out_delta + $port_out_delta; + unset($port_in_delta,$port_out_delta,$prev_delta,$prev_timestamp,$period); - } - $last_data = getLastMeasurement($bill_id); + } + $last_data = getLastMeasurement($bill_id); - if ($last_data[state] == "ok") { - $prev_delta = $last_data[delta]; - $prev_in_delta = $last_data[in_delta]; - $prev_out_delta = $last_data[out_delta]; - $prev_timestamp = $last_data[timestamp]; - $period = mysql_result(mysql_query("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('$prev_timestamp')"),0); - } else { - $prev_delta = '0'; - $period = '0'; - $prev_in_delta = '0'; - $prev_out_delta = '0'; - } - if( $delta < '0' ) { - $delta = $prev_delta; - $in_delta = $prev_in_delta; - $out_delta = $prev_out_delta; - } - $insert_string = "INSERT INTO bill_data (bill_id,timestamp,period,delta,in_delta,out_delta) VALUES ('$bill_id','$now','$period','$delta','$in_delta','$out_delta')"; - #echo("$insert_string\n"); - $insert_measurement = mysql_query($insert_string); + if ($last_data[state] == "ok") + { + $prev_delta = $last_data[delta]; + $prev_in_delta = $last_data[in_delta]; + $prev_out_delta = $last_data[out_delta]; + $prev_timestamp = $last_data[timestamp]; + $period = mysql_result(mysql_query("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('$prev_timestamp')"),0); + } else { + $prev_delta = '0'; + $period = '0'; + $prev_in_delta = '0'; + $prev_out_delta = '0'; + } + + if ($delta < '0' ) + { + $delta = $prev_delta; + $in_delta = $prev_in_delta; + $out_delta = $prev_out_delta; + + } + $insert_string = "INSERT INTO bill_data (bill_id,timestamp,period,delta,in_delta,out_delta) VALUES ('$bill_id','$now','$period','$delta','$in_delta','$out_delta')"; + $insert_measurement = mysql_query($insert_string); } if ($argv[1]) { CollectData($argv[1]); } - -?> - +?> \ No newline at end of file