just another cleanup commit, don't mind me...

git-svn-id: http://www.observium.org/svn/observer/trunk@1885 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2011-03-16 18:28:52 +00:00
parent 372ada594e
commit 2afb522333
15 changed files with 215 additions and 197 deletions

View File

@ -1,6 +1,6 @@
<?php
function generate_device_link($device, $text=0, $linksuffix="", $start=0, $end=0)
function generate_device_link($device, $text=0, $linksuffix="", $start=0, $end=0)
{
global $twoday; global $day; global $now; global $config;
@ -16,39 +16,41 @@ function generate_device_link($device, $text=0, $linksuffix="", $start=0, $end=0
elseif (isset($config['os'][$device['os_group']]['over']))
{
$graphs = $config['os'][$device['os_group']]['over'];
}
}
else
{
$graphs = $config['os']['default']['over'];
$graphs = $config['os']['default']['over'];
}
$url = $config['base_url']."/device/" . $device['device_id'] . "/" . $linksuffix;
$contents = "<div class=list-large>".$device['hostname'];
if($device['hardware']) { $contents .= " - ".$device['hardware']; }
if ($device['hardware']) { $contents .= " - ".$device['hardware']; }
$contents .= "</div>";
$contents .= "<div>";
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 .= "</div>";
# if (isset($device['location'])) { $contents .= "" . htmlentities($device['location'])."<br />"; }
foreach ($graphs as $entry)
{
$graph = $entry['graph'];
$graphhead = $entry['text'];
$graphhead = $entry['text'];
$contents .= '<div style="width: 708px">';
$contents .= '<span style="margin-left: 5px; font-size: 12px; font-weight: bold;">'.$graphhead.'</span><br />';
$contents .= '<img src="' . $config['base_url'] . "/graph.php?id=" . $device['device_id'] . "&amp;from=$start&amp;to=$end&amp;width=275&amp;height=100&amp;type=$graph&amp;legend=no" . '" style="margin: 2px;">';
$contents .= '<img src="' . $config['base_url'] . "/graph.php?id=" . $device['device_id'] . "&amp;from=".$config['week']."&amp;to=$end&amp;width=275&amp;height=100&amp;type=$graph&amp;legend=no" . '" style="margin: 2px;">';
$contents .= '</div>';
}
$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 = "<a class='".$class."' href='".$url."'";
$output .= " onmouseover=\"return overlib('".$contents."'".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">";
$output .= $text."</a>";
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 = '
<div style="font-size:11px;">
@ -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 = "<div class=list-large>".$args['hostname']." - " . fixifName($args['label']) . "</div>";
if($args['ifAlias']) { $content .= $args['ifAlias']."<br />"; }
if ($args['ifAlias']) { $content .= $args['ifAlias']."<br />"; }
$content .= "<div style=\'width: 850px\'>";
$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 .= "</div>";
$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'] = "<img src='graph.php?type=".$args['graph_type']."&id=".$args['interface_id']."&from=".$args['from']."&to=".$args['to']."&width=".$args['width']."&height=".$args['height']."&legend=no&bg=".$args['bg']."'>";
$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("
<div style='text-align: center; margin-top: 0px; margin-bottom: ".$marginbottom."px; " . ($width ? 'max-width: ' . $width . (strstr($width,'%') ? '' : 'px') . '; ' : '') . "'>
@ -278,20 +290,20 @@ function print_optionbar_start ($height = 20, $width = 0, $marginbottom = 5)
}
function print_optionbar_end ()
function print_optionbar_end()
{
echo(" </div>
echo(' </div>
</div>
<b class='rounded'>
<b class='rounded5'></b>
<b class='rounded4'></b>
<b class='rounded3'></b>
<b class='rounded2'><b></b></b>
<b class='rounded1'><b></b></b></b>
</div>");
<b class="rounded">
<b class="rounded5"></b>
<b class="rounded4"></b>
<b class="rounded3"></b>
<b class="rounded2"><b></b></b>
<b class="rounded1"><b></b></b></b>
</div>');
}
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('<table class="messagebox" cellpadding="3"><tr><td><img src="/images/16/tick.png" align="absmiddle"> '.$text.'</td></tr></table>');
}
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;
}
?>
?>