From cd43e110329cc91722ecad42c5fb42995ad2de40 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sun, 22 Feb 2015 19:28:09 +0000 Subject: [PATCH] Fixed some scrut major issues --- html/billing-graph.php | 14 +++---- html/includes/graphs/graph.inc.php | 5 +-- includes/common.php | 63 ++++++++++++++-------------- includes/discovery/functions.inc.php | 4 +- includes/functions.php | 21 ++++++---- includes/polling/functions.inc.php | 1 + 6 files changed, 58 insertions(+), 50 deletions(-) diff --git a/html/billing-graph.php b/html/billing-graph.php index f14280415..82549d8e2 100755 --- a/html/billing-graph.php +++ b/html/billing-graph.php @@ -105,14 +105,14 @@ foreach (dbFetch("SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bil { @$timestamp = $row['formatted_date']; if (!$first) { $first = $timestamp; } - @$delta = $row['delta']; - @$period = $row['period']; - @$in_delta = $row['in_delta']; - @$out_delta = $row['out_delta']; - @$in_value = round($in_delta * 8 / $period, 2); - @$out_value = round($out_delta * 8 / $period, 2); + $delta = $row['delta']; + $period = $row['period']; + $in_delta = $row['in_delta']; + $out_delta = $row['out_delta']; + $in_value = round($in_delta * 8 / $period, 2); + $out_value = round($out_delta * 8 / $period, 2); - @$last = $timestamp; + $last = $timestamp; $iter_in += $in_delta; $iter_out += $out_delta; diff --git a/html/includes/graphs/graph.inc.php b/html/includes/graphs/graph.inc.php index 8e213aa49..7e609b6ed 100644 --- a/html/includes/graphs/graph.inc.php +++ b/html/includes/graphs/graph.inc.php @@ -86,7 +86,7 @@ function graph_error($string) rrdtool_graph($graphfile, $rrd_options); if ($height > "99") { - $woo = shell_exec($rrd_cmd); + shell_exec($rrd_cmd); if ($debug) { echo("
".$rrd_cmd."
"); } if (is_file($graphfile) && !$debug) { @@ -98,7 +98,6 @@ function graph_error($string) } else { if (!$debug) { header('Content-type: image/png'); } $im = imagecreate($width, $height); - $orange = imagecolorallocate($im, 255, 225, 225); $px = (imagesx($im) - 7.5 * strlen($string)) / 2; imagestring($im, 3, $px, $height / 2 - 8, $string, imagecolorallocate($im, 128, 0, 0)); imagepng($im); @@ -113,7 +112,7 @@ if ($error_msg) { graph_error($graph_error); -} elseif (!$auth) { +} elseif ($auth === null) { // We are unauthenticated :( if ($width < 200) diff --git a/includes/common.php b/includes/common.php index 1436df8d2..bff445574 100644 --- a/includes/common.php +++ b/includes/common.php @@ -204,12 +204,12 @@ function get_port_by_id($port_id) if (is_numeric($port_id)) { $port = dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", array($port_id)); - } - if (is_array($port)) - { - return $port; - } else { - return FALSE; + if (is_array($port)) + { + return $port; + } else { + return FALSE; + } } } @@ -218,12 +218,12 @@ function get_application_by_id($application_id) if (is_numeric($application_id)) { $application = dbFetchRow("SELECT * FROM `applications` WHERE `app_id` = ?", array($application_id)); - } - if (is_array($application)) - { - return $application; - } else { - return FALSE; + if (is_array($application)) + { + return $application; + } else { + return FALSE; + } } } @@ -232,12 +232,12 @@ function get_sensor_by_id($sensor_id) if (is_numeric($sensor_id)) { $sensor = dbFetchRow("SELECT * FROM `sensors` WHERE `sensor_id` = ?", array($sensor_id)); - } - if (is_array($sensor)) - { - return $sensor; - } else { - return FALSE; + if (is_array($sensor)) + { + return $sensor; + } else { + return FALSE; + } } } @@ -246,12 +246,12 @@ function get_device_id_by_port_id($port_id) if (is_numeric($port_id)) { $device_id = dbFetchCell("SELECT `device_id` FROM `ports` WHERE `port_id` = ?", array($port_id)); - } - if (is_numeric($device_id)) - { - return $device_id; - } else { - return FALSE; + if (is_numeric($device_id)) + { + return $device_id; + } else { + return FALSE; + } } } @@ -260,12 +260,12 @@ function get_device_id_by_app_id($app_id) if (is_numeric($app_id)) { $device_id = dbFetchCell("SELECT `device_id` FROM `applications` WHERE `app_id` = ?", array($app_id)); - } - if (is_numeric($device_id)) - { - return $device_id; - } else { - return FALSE; + if (is_numeric($device_id)) + { + return $device_id; + } else { + return FALSE; + } } } @@ -494,6 +494,7 @@ function formatStorage($value, $round = '2', $sf = '3') function format_si($value, $round = '2', $sf = '3') { + $neg = 0; if ($value < "0") { $neg = 1; @@ -513,7 +514,7 @@ function format_si($value, $round = '2', $sf = '3') for ($i = 1; (($i < count($sizes)) && ($value != 0) && ($value <= 0.1)); $i++) { $value = $value * 1000; $ext = $sizes[$i]; } } - if ($neg) { $value = $value * -1; } + if ($neg == 1) { $value = $value * -1; } return format_number_short(round($value, $round),$sf).$ext; } diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 9dc4f051a..103a7eebe 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -39,12 +39,12 @@ function discover_new_device($hostname) if ( match_network($config['nets'], $ip) ) { - $remote_device_id = addHost ($dst_host); + $remote_device_id = addHost ($dst_host,''); if ($remote_device_id) { $remote_device = device_by_id_cache($remote_device_id, 1); echo("+[".$remote_device['hostname']."(".$remote_device['device_id'].")]"); discover_device($remote_device); - $remote_device = device_by_id_cache($remote_device_id, 1); + device_by_id_cache($remote_device_id, 1); return $remote_device_id; } } else { diff --git a/includes/functions.php b/includes/functions.php index 9684a475d..05b91e69f 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -108,7 +108,8 @@ function getHostOS($device) echo("| $sysDescr | $sysObjectId | "); } - $dir_handle = @opendir($config['install_dir'] . "/includes/discovery/os") or die("Unable to open $path"); + $path = $config['install_dir'] . "/includes/discovery/os"; + $dir_handle = @opendir($path) or die("Unable to open $path"); while ($file = readdir($dir_handle)) { if (preg_match("/.php$/", $file)) @@ -136,6 +137,8 @@ function interface_errors($rrd_file, $period = '-1d') // Returns the last in/out $cmd = $config['rrdtool']." fetch -s $period -e -300s $rrd_file AVERAGE | grep : | cut -d\" \" -f 4,5"; $data = trim(shell_exec($cmd)); + $in_errors = 0; + $out_errors = 0; foreach (explode("\n", $data) as $entry) { list($in, $out) = explode(" ", $entry); @@ -175,6 +178,9 @@ function getImage($device) $image = ''; } } + if (empty($image)) { + $image = ''; + } } return $image; @@ -207,6 +213,9 @@ function getImageSrc($device) $image = $config['base_url'] . '/images/os/' . $distro . '.png'; } } + if (empty($image)) { + $image = $config['base_url'] . '/images/os/generic.png'; + } } return $image; @@ -219,13 +228,14 @@ function renamehost($id, $new, $source = 'console') // FIXME does not check if destination exists! $host = dbFetchCell("SELECT `hostname` FROM `devices` WHERE `device_id` = ?", array($id)); rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new"); - $return = dbUpdate(array('hostname' => $new), 'devices', 'device_id=?', array($id)); + dbUpdate(array('hostname' => $new), 'devices', 'device_id=?', array($id)); log_event("Hostname changed -> $new ($source)", $id, 'system'); } function delete_device($id) { global $config; + $ret = ''; $host = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?", array($id)); @@ -267,8 +277,6 @@ function addHost($host, $snmpver, $port = '161', $transport = 'udp', $quiet = '0 // Test reachability if (isPingable($host)) { - $added = 0; - if (empty($snmpver)) { // Try SNMPv2c @@ -324,7 +332,7 @@ function addHost($host, $snmpver, $port = '161', $transport = 'udp', $quiet = '0 if (isSNMPable($device)) { $snmphost = snmp_get($device, "sysName.0", "-Oqv", "SNMPv2-MIB"); - if ($snmphost == "" || ($snmphost && ($snmphost == $host || $hostshort = $host))) + if (empty($snmphost) || ($snmphost && ($snmphost == $host || $hostshort = $host))) { $device_id = createHost ($host, $community, $snmpver, $port, $transport); return $device_id; @@ -369,7 +377,6 @@ function scanUDP($host, $port, $timeout) $write = fwrite($handle,"\x00"); if (!$write) { next; } $startTime = time(); - $header = fread($handle, 1); $endTime = time(); $timeDiff = $endTime - $startTime; if ($timeDiff >= $timeout) @@ -409,7 +416,7 @@ function netmask2cidr($netmask) return $addr->bitmask; } -function cidr2netmask() +function cidr2netmask($netmask) { return (long2ip(ip2long("255.255.255.255") << (32-$netmask))); } diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index 4f3419eda..15cae4b10 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -7,6 +7,7 @@ function poll_sensor($device, $class, $unit) foreach (dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ?", array($class, $device['device_id'])) as $sensor) { echo("Checking (" . $sensor['poller_type'] . ") $class " . $sensor['sensor_descr'] . "... "); + $sensor_value = ''; if ($sensor['poller_type'] == "snmp") {