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
+40 -26
View File
@@ -34,7 +34,6 @@ function generate_device_link($device, $text=0, $linksuffix="", $start=0, $end=0
# if ($device['hardware']) { $contents .= " - ".$device['hardware']; }
$contents .= "</div>";
# if (isset($device['location'])) { $contents .= "" . htmlentities($device['location'])."<br />"; }
foreach ($graphs as $entry)
{
@@ -46,9 +45,12 @@ function generate_device_link($device, $text=0, $linksuffix="", $start=0, $end=0
$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,12 +60,15 @@ 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;
}
@@ -102,15 +107,18 @@ 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)) {
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;
@@ -119,6 +127,7 @@ function permissions_cache($user_id)
function bill_permitted($bill_id)
{
global $_SESSION; global $permissions;
if ($_SESSION['userlevel'] >= "5") {
$allowed = TRUE;
} elseif ($permissions['bill'][$bill_id]) {
@@ -126,15 +135,18 @@ function bill_permitted($bill_id)
} 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 ($_SESSION['userlevel'] >= "5")
{
$allowed = TRUE;
} elseif (device_permitted($device_id)) {
$allowed = TRUE;
@@ -143,6 +155,7 @@ function port_permitted($interface_id, $device_id = NULL)
} else {
$allowed = FALSE;
}
return $allowed;
}
@@ -167,22 +180,22 @@ 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] ) {
$allowed = true;
} else {
$allowed = false;
}
return $allowed;
}
function print_graph_tag ($args)
{
echo(generate_graph_tag ($args));
@@ -191,6 +204,7 @@ function print_graph_tag ($args)
function generate_graph_tag ($args)
{
global $config;
$sep = "?";
$url = $config['base_url'] . "/graph.php";
foreach ($args as $key => $arg)
@@ -252,15 +266,13 @@ function generate_port_link($args, $text = NULL, $type = NULL)
} else {
return fixifName($text);
}
}
function generate_port_thumbnail($args)
{
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)
@@ -280,15 +292,15 @@ function print_optionbar_start ($height = 20, $width = 0, $marginbottom = 5)
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)
@@ -302,7 +314,8 @@ function geteventicon ($message)
if (isset($icon)) { return $icon; } else { return false; }
}
function overlibprint($text) {
function overlibprint($text)
{
return "onmouseover=\"return overlib('" . $text . "');\" onmouseout=\"return nd();\"";
}
@@ -332,13 +345,14 @@ function print_message($text)
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['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"; }
return $class;
}
?>
@@ -1,7 +1,6 @@
<script type="text/javascript" src="<?php echo($config['base_url']); ?>/js/tw-sack.js"></script>
<script type="text/javascript">
var ajax = new Array();
function getInterfaceList(sel)
+21 -12
View File
@@ -1,16 +1,16 @@
<?php
# enable/disable ports/interfaces on devices.
#
$device_id = intval($_POST['device']);
$rows_updated = 0;
foreach ($_POST as $key => $val) {
if (strncmp($key,"oldval_",7) == 0) {
foreach ($_POST as $key => $val)
{
if (strncmp($key,"oldval_",7) == 0)
{
# Interface identifier passed as part of the field name
#
$interface_id = intval(substr($key,7));
$oldval = intval($val) ? 1 : 0;
@@ -18,24 +18,33 @@ foreach ($_POST as $key => $val) {
# As checkboxes are not posted when unset - we effectively need to do a diff to work
# out a set->unset case.
#
if ($oldval == $newval)
{
continue;
}
if (!mysql_query('UPDATE `ports` SET `ignore`='.$newval.' WHERE `device_id`='.$device_id.' AND `interface_id`='.$interface_id))
{
$n = -1;
}
else
{
$n = mysql_affected_rows();
}
if ($n <0) {
if ($n <0)
{
$rows_updated = -1;
break;
};
$rows_updated += $n;
};
};
}
if($rows_updated > 0) {
$rows_updated += $n;
}
}
if ($rows_updated > 0)
{
$update_message = $rows_updated . " Device record updated.";
$updated = 1;
} elseif ($rows_updated = '-1') {
+4 -2
View File
@@ -1,15 +1,17 @@
<?php
$graph_array['type'] = $graph_type;
$graph_array['id'] = $device['device_id'];
$g_i++;
if (!is_integer($g_i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
echo('<div style="background-color: '.$row_colour.';">');
echo('<div style="padding:4px 0px 0px 8px;" class=graphhead>'.$graph_title.'</div>');
include("includes/print-quadgraphs.inc.php");
echo("</div>");
echo('</div>');
?>
@@ -2,9 +2,6 @@
global $config;
#if(!$graph_type) { $graph_type = $_GET['type']; }
#if(!$device) { $device['device_id'] = getifhost($interface['interface_id']); }
$graph_array['height'] = "100";
$graph_array['width'] = "215";
$graph_array['to'] = $now;
+4 -6
View File
@@ -1,10 +1,7 @@
<?php
if(device_permitted($entry['device_id'])) {
if (device_permitted($entry['device_id']))
{
$syslog_iter++;
if (!is_integer($syslog_iter/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; }
@@ -15,7 +12,8 @@ if(!is_integer($syslog_iter/2)) { $bg_colour = $list_colour_a; } else { $bg_colo
$entry['hostname'] = shorthost($entry['hostname'], 20);
if($_GET['page'] != "device") {
if ($_GET['page'] != "device")
{
echo("<td width=160><strong>".generate_device_link($entry)."</strong></td>");
}
-1
View File
@@ -46,7 +46,6 @@ if($services['down']) { $services['bgcolour'] = "#ffcccc"; } else { $services['b
?>
<table cellpadding="2" cellspacing="0" border="0">
<tr style="background-color: <?php echo($devices[bgcolour]); ?>">
<td width="5"></td>