From 2afb52233304802de10b5231b2b12e4b0d6184f8 Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Wed, 16 Mar 2011 18:28:52 +0000 Subject: [PATCH] just another cleanup commit, don't mind me... git-svn-id: http://www.observium.org/svn/observer/trunk@1885 61d68cd4-352d-0410-923a-c4978735b2b8 --- html/includes/authenticate.inc.php | 32 ++-- .../includes/authentication/http-auth.inc.php | 4 +- html/includes/authentication/mysql.inc.php | 2 +- html/includes/functions.inc.php | 160 ++++++++++-------- html/includes/hostbox.inc.php | 10 +- .../javascript-interfacepicker.inc.php | 3 +- html/includes/port-edit.inc.php | 81 +++++---- html/includes/print-device-graph.php | 8 +- html/includes/print-interface-adsl.inc.php | 36 ++-- html/includes/print-interface-graphs.inc.php | 19 +-- html/includes/print-menubar.php | 20 +-- html/includes/print-syslog.inc | 18 +- html/includes/print-vlan.inc.php | 6 +- html/includes/print-vrf.inc | 6 +- html/includes/topnav.inc | 7 +- 15 files changed, 215 insertions(+), 197 deletions(-) diff --git a/html/includes/authenticate.inc.php b/html/includes/authenticate.inc.php index ae08a9664..598e36e6f 100644 --- a/html/includes/authenticate.inc.php +++ b/html/includes/authenticate.inc.php @@ -1,20 +1,20 @@ -RRD Log Directory is missing ({$config['rrd_dir']}). Graphing may fail."); -if(!is_dir($config['temp_dir'])) +if (!is_dir($config['temp_dir'])) echo("
Temp Directory is missing ({$config['tmp_dir']}). Graphing may fail.
"); -if(!is_writable($config['temp_dir'])) +if (!is_writable($config['temp_dir'])) echo("
Temp Directory is not writable ({$config['tmp_dir']}). Graphing may fail.
"); -if(isset($_GET['logout']) && $_SESSION['authenticated']) { +if (isset($_GET['logout']) && $_SESSION['authenticated']) { mysql_query("INSERT INTO authlog (`user`,`address`,`result`) VALUES ('" . $_SESSION['username'] . "', '".$_SERVER["REMOTE_ADDR"]."', 'logged out')"); unset($_SESSION); session_destroy(); @@ -24,13 +24,13 @@ if(isset($_GET['logout']) && $_SESSION['authenticated']) { $auth_message = "Logged Out"; } -if(isset($_GET['username']) && isset($_GET['password'])){ +if (isset($_GET['username']) && isset($_GET['password'])){ $_SESSION['username'] = mres($_GET['username']); $_SESSION['password'] = mres($_GET['password']); -} elseif(isset($_POST['username']) && isset($_POST['password'])){ +} elseif (isset($_POST['username']) && isset($_POST['password'])){ $_SESSION['username'] = mres($_POST['username']); $_SESSION['password'] = mres($_POST['password']); -} elseif(isset($_COOKIE['username']) && isset($_COOKIE['password'])){ +} elseif (isset($_COOKIE['username']) && isset($_COOKIE['password'])){ $_SESSION['username'] = mres($_COOKIE['username']); $_SESSION['password'] = mres($_COOKIE['password']); } @@ -58,25 +58,25 @@ if (isset($_SESSION['username'])) { $_SESSION['userlevel'] = get_userlevel($_SESSION['username']); $_SESSION['user_id'] = get_userid($_SESSION['username']); - if(!$_SESSION['authenticated']) + if (!$_SESSION['authenticated']) { $_SESSION['authenticated'] = true; mysql_query("INSERT INTO authlog (`user`,`address`,`result`) VALUES ('".$_SESSION['username']."', '".$_SERVER["REMOTE_ADDR"]."', 'logged in')"); header("Location: ".$_SERVER['REQUEST_URI']); } - if(isset($_POST['remember'])) + if (isset($_POST['remember'])) { setcookie("username", $_SESSION['username'], time()+60*60*24*100, "/"); setcookie("password", $_SESSION['password'], time()+60*60*24*100, "/"); } $permissions = permissions_cache($_SESSION['user_id']); - } - elseif (isset($_SESSION['username'])) - { - $auth_message = "Authentication Failed"; + } + elseif (isset($_SESSION['username'])) + { + $auth_message = "Authentication Failed"; unset ($_SESSION['authenticated']); mysql_query("INSERT INTO authlog (`user`,`address`,`result`) VALUES ('".$_SESSION['username']."', '".$_SERVER["REMOTE_ADDR"]."', 'authentication failure')"); } -} +} ?> diff --git a/html/includes/authentication/http-auth.inc.php b/html/includes/authentication/http-auth.inc.php index 35c32c465..a66fa2b1a 100644 --- a/html/includes/authentication/http-auth.inc.php +++ b/html/includes/authentication/http-auth.inc.php @@ -4,14 +4,14 @@ function authenticate($username,$password) { global $config; - if(isset($_SERVER['REMOTE_USER'])) + if (isset($_SERVER['REMOTE_USER'])) { $_SESSION['username'] = mres($_SERVER['REMOTE_USER']); $sql = "SELECT username FROM `users` WHERE `username`='".$_SESSION['username'] . "'";; $query = mysql_query($sql); $row = @mysql_fetch_array($query); - if($row['username'] && $row['username'] == $_SESSION['username']) + if ($row['username'] && $row['username'] == $_SESSION['username']) { return 1; } diff --git a/html/includes/authentication/mysql.inc.php b/html/includes/authentication/mysql.inc.php index 9885c45fb..74ae3f307 100644 --- a/html/includes/authentication/mysql.inc.php +++ b/html/includes/authentication/mysql.inc.php @@ -6,7 +6,7 @@ function authenticate($username,$password) $sql = "SELECT username FROM `users` WHERE `username`='".$username."' AND `password`='".$encrypted."'"; $query = mysql_query($sql); $row = @mysql_fetch_array($query); - if($row['username'] && $row['username'] == $username) + if ($row['username'] && $row['username'] == $username) { return 1; } diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 12999f34c..94617298f 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -1,6 +1,6 @@ ".$device['hostname']; - if($device['hardware']) { $contents .= " - ".$device['hardware']; } + if ($device['hardware']) { $contents .= " - ".$device['hardware']; } $contents .= ""; $contents .= "
"; - if($device['os']) { $contents .= mres($config['os'][$device['os']]['text']); } - if($device['version']) { $contents .= " ".mres($device['version']); } - if($device['features']) { $contents .= " (".mres($device['features']).")"; } -# if($device['hardware']) { $contents .= " - ".$device['hardware']; } + if ($device['os']) { $contents .= mres($config['os'][$device['os']]['text']); } + if ($device['version']) { $contents .= " ".mres($device['version']); } + if ($device['features']) { $contents .= " (".mres($device['features']).")"; } +# if ($device['hardware']) { $contents .= " - ".$device['hardware']; } $contents .= "
"; - # if (isset($device['location'])) { $contents .= "" . htmlentities($device['location'])."
"; } foreach ($graphs as $entry) { $graph = $entry['graph']; - $graphhead = $entry['text']; + $graphhead = $entry['text']; $contents .= '
'; $contents .= ''.$graphhead.'
'; $contents .= ''; $contents .= ''; $contents .= '
'; } + $text = htmlentities($text); $link = overlib_link($url, $text, $contents, $class); - if(device_permitted($device['device_id'])) { + + if (device_permitted($device['device_id'])) + { return $link; } else { return $device['hostname']; @@ -58,16 +60,19 @@ function generate_device_link($device, $text=0, $linksuffix="", $start=0, $end=0 return $link; } -function overlib_link($url, $text, $contents, $class) { +function overlib_link($url, $text, $contents, $class) +{ global $config; + $contents = str_replace("\"", "\'", $contents); $output = ""; $output .= $text.""; + return $output; } -function generate_graph_popup($graph_array) +function generate_graph_popup($graph_array) { global $config; ## Take $graph_array and print day,week,month,year graps in overlib, hovered over graph @@ -98,65 +103,73 @@ function print_graph_popup($graph_array) -function permissions_cache($user_id) +function permissions_cache($user_id) { $permissions = array(); $query = mysql_query("SELECT * FROM devices_perms WHERE user_id = '".$user_id."'"); - while($device = mysql_fetch_assoc($query)) { - $permissions['device'][$device['device_id']] = 1; + while ($device = mysql_fetch_assoc($query)) + { + $permissions['device'][$device['device_id']] = 1; } $query = mysql_query("SELECT * FROM ports_perms WHERE user_id = '".$user_id."'"); - while($port = mysql_fetch_assoc($query)) { + while ($port = mysql_fetch_assoc($query)) + { $permissions['port'][$port['interface_id']] = 1; } $query = mysql_query("SELECT * FROM bill_perms WHERE user_id = '".$user_id."'"); - while($bill = mysql_fetch_assoc($query)) { + while ($bill = mysql_fetch_assoc($query)) + { $permissions['bill'][$bill['bill_id']] = 1; } return $permissions; } -function bill_permitted($bill_id) +function bill_permitted($bill_id) { global $_SESSION; global $permissions; + if ($_SESSION['userlevel'] >= "5") { $allowed = TRUE; - } elseif ( $permissions['bill'][$bill_id]) { + } elseif ($permissions['bill'][$bill_id]) { $allowed = TRUE; } else { $allowed = FALSE; } - return $allowed; + return $allowed; } + function port_permitted($interface_id, $device_id = NULL) { global $_SESSION; global $permissions; - if(!is_numeric($device_id)) { $device_id = get_device_id_by_interface_id($interface_id); } - if ($_SESSION['userlevel'] >= "5") { + if (!is_numeric($device_id)) { $device_id = get_device_id_by_interface_id($interface_id); } + + if ($_SESSION['userlevel'] >= "5") + { $allowed = TRUE; - } elseif ( device_permitted($device_id)) { + } elseif (device_permitted($device_id)) { $allowed = TRUE; - } elseif ( $permissions['port'][$interface_id]) { + } elseif ($permissions['port'][$interface_id]) { $allowed = TRUE; } else { $allowed = FALSE; } + return $allowed; } function application_permitted($app_id, $device_id = NULL) { global $_SESSION; global $permissions; - if(is_numeric($app_id)) + if (is_numeric($app_id)) { - if(!$device_id) { $device_id = device_by_id_cache ($app_id); } + if (!$device_id) { $device_id = device_by_id_cache ($app_id); } if ($_SESSION['userlevel'] >= "5") { $allowed = TRUE; - } elseif ( device_permitted($device_id)) { + } elseif (device_permitted($device_id)) { $allowed = TRUE; - } elseif ( $permissions['application'][$app_id]) { + } elseif ($permissions['application'][$app_id]) { $allowed = TRUE; } else { $allowed = FALSE; @@ -167,33 +180,34 @@ function application_permitted($app_id, $device_id = NULL) return $allowed; } - function device_permitted($device_id) { global $_SESSION; global $permissions; - if ($_SESSION['userlevel'] >= "5") { + + if ($_SESSION['userlevel'] >= "5") + { $allowed = true; - } elseif ( $permissions['device'][$device_id] ) { + } elseif ($permissions['device'][$device_id] ) { $allowed = true; } else { $allowed = false; } - return $allowed; + return $allowed; } - -function print_graph_tag ($args) +function print_graph_tag ($args) { echo(generate_graph_tag ($args)); } -function generate_graph_tag ($args) +function generate_graph_tag ($args) { global $config; + $sep = "?"; $url = $config['base_url'] . "/graph.php"; - foreach ($args as $key => $arg) + foreach ($args as $key => $arg) { $url .= $sep.$key."=".$arg; $sep="&"; @@ -202,7 +216,7 @@ function generate_graph_tag ($args) } -function print_percentage_bar ($width, $height, $percent, $left_text, $left_colour, $left_background, $right_text, $right_colour, $right_background) +function print_percentage_bar ($width, $height, $percent, $left_text, $left_colour, $left_background, $right_text, $right_colour, $right_background) { $output = '
@@ -219,15 +233,15 @@ function generate_port_link($args, $text = NULL, $type = NULL) { global $twoday; global $now; global $config; global $day; global $month; $args = ifNameDescr($args); - if(!$text) { $text = fixIfName($args['label']); } - if($type) { $args['graph_type'] = $type; } - if(!$args['graph_type']) { $args['graph_type'] = 'port_bits'; } - + if (!$text) { $text = fixIfName($args['label']); } + if ($type) { $args['graph_type'] = $type; } + if (!$args['graph_type']) { $args['graph_type'] = 'port_bits'; } + $class = ifclass($args['ifOperStatus'], $args['ifAdminStatus']); - if(!isset($args['hostname'])) { $args = array_merge($args, device_by_id_cache($args['device_id'])); } + if (!isset($args['hostname'])) { $args = array_merge($args, device_by_id_cache($args['device_id'])); } $content = "
".$args['hostname']." - " . fixifName($args['label']) . "
"; - if($args['ifAlias']) { $content .= $args['ifAlias']."
"; } + if ($args['ifAlias']) { $content .= $args['ifAlias']."
"; } $content .= "
"; $graph_array['type'] = $args['graph_type']; $graph_array['legend'] = "yes"; @@ -244,26 +258,24 @@ function generate_port_link($args, $text = NULL, $type = NULL) $graph_array['from'] = $config['year']; $content .= generate_graph_tag($graph_array); $content .= "
"; - + $url = $config['base_url']."/device/".$args['device_id']."/interface/" . $args['interface_id'] . "/"; - if(port_permitted($args['interface_id'])) { + if (port_permitted($args['interface_id'])) { return overlib_link($url, $text, $content, $class); } else { return fixifName($text); } - } -function generate_port_thumbnail($args) +function generate_port_thumbnail($args) { - if(!$args['bg']) { $args['bg'] = "FFFFF"; } + if (!$args['bg']) { $args['bg'] = "FFFFF"; } $args['content'] = ""; - $output = generate_port_link($args, $args['content']); - echo($output); + echo generate_port_link($args, $args['content']); } -function print_optionbar_start ($height = 20, $width = 0, $marginbottom = 5) +function print_optionbar_start ($height = 20, $width = 0, $marginbottom = 5) { echo("
@@ -278,20 +290,20 @@ function print_optionbar_start ($height = 20, $width = 0, $marginbottom = 5) } -function print_optionbar_end () +function print_optionbar_end() { - echo("
+ echo('
- - - - - - - "); + + + + + + + '); } -function geteventicon ($message) +function geteventicon($message) { if ($message == "Device status changed to Down") { $icon = "server_connect.png"; } if ($message == "Device status changed to Up") { $icon = "server_go.png"; } @@ -302,17 +314,18 @@ function geteventicon ($message) if (isset($icon)) { return $icon; } else { return false; } } -function overlibprint($text) { - return "onmouseover=\"return overlib('" . $text . "');\" onmouseout=\"return nd();\""; +function overlibprint($text) +{ + return "onmouseover=\"return overlib('" . $text . "');\" onmouseout=\"return nd();\""; } -function humanmedia($media) +function humanmedia($media) { array_preg_replace($rewrite_iftype, $media); return $media; } -function humanspeed($speed) +function humanspeed($speed) { $speed = formatRates($speed); if ($speed == "") { $speed = "-"; } @@ -329,16 +342,17 @@ function print_message($text) echo('
'.$text.'
'); } -function devclass($device) +function devclass($device) { - if (isset($device['status']) && $device['status'] == '0') { $class = "list-device-down"; } else { $class = "list-device"; } - if (isset($device['ignore']) && $device['ignore'] == '1') { + if (isset($device['status']) && $device['status'] == '0') { $class = "list-device-down"; } else { $class = "list-device"; } + if (isset($device['ignore']) && $device['ignore'] == '1') + { $class = "list-device-ignored"; if (isset($device['status']) && $device['status'] == '1') { $class = "list-device-ignored-up"; } - } - if (isset($device['disabled']) && $device['disabled'] == '1') { $class = "list-device-disabled"; } + } + if (isset($device['disabled']) && $device['disabled'] == '1') { $class = "list-device-disabled"; } + return $class; } - -?> +?> \ No newline at end of file diff --git a/html/includes/hostbox.inc.php b/html/includes/hostbox.inc.php index 46fcc6ae4..4c33fbbaa 100644 --- a/html/includes/hostbox.inc.php +++ b/html/includes/hostbox.inc.php @@ -1,6 +1,6 @@ ' . $image . ' ' . generate_device_link($device) . '
' . $device['sysName'] . ' '); - if($port_count) { echo(' '.$port_count); } + if ($port_count) { echo(' '.$port_count); } echo('
'); - if($sensor_count) { echo(' '.$sensor_count); } + if ($sensor_count) { echo(' '.$sensor_count); } echo(' diff --git a/html/includes/javascript-interfacepicker.inc.php b/html/includes/javascript-interfacepicker.inc.php index 835f438bd..010e2b170 100644 --- a/html/includes/javascript-interfacepicker.inc.php +++ b/html/includes/javascript-interfacepicker.inc.php @@ -1,14 +1,13 @@