- Code cleanup by Bastian Widmer.

git-svn-id: http://www.observium.org/svn/observer/trunk@1957 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Geert Hauwaerts
2011-03-22 20:27:39 +00:00
parent 0c4e6b5dfc
commit 6501cd29b5
45 changed files with 3657 additions and 3655 deletions
+11 -11
View File
@@ -2,11 +2,11 @@
if ($_GET['debug'])
{
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
}
include("../includes/defaults.inc.php");
@@ -20,11 +20,11 @@ if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; }
if (is_numeric($_GET['device_id']))
{
$ports = mysql_query("SELECT * FROM ports WHERE device_id = '".$_GET['device_id']."'");
while ($interface = mysql_fetch_array($ports))
{
echo("obj.options[obj.options.length] = new Option('".$interface['ifDescr']." - ".$interface['ifAlias']."','".$interface['interface_id']."');\n");
}
$ports = mysql_query("SELECT * FROM ports WHERE device_id = '".$_GET['device_id']."'");
while ($interface = mysql_fetch_array($ports))
{
echo("obj.options[obj.options.length] = new Option('".$interface['ifDescr']." - ".$interface['ifAlias']."','".$interface['interface_id']."');\n");
}
}
?>
?>
+75 -75
View File
@@ -2,11 +2,11 @@
if ($_GET['debug'])
{
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
} else { ini_set('display_errors', 0); }
include("../includes/defaults.inc.php");
@@ -21,16 +21,16 @@ include("includes/jpgraph/src/jpgraph_utils.inc.php");
if (is_numeric($_GET['bill_id']))
{
if (bill_permitted($_GET['bill_id']))
{
$bill_id = $_GET['bill_id'];
} else {
if (bill_permitted($_GET['bill_id']))
{
$bill_id = $_GET['bill_id'];
} else {
echo("Unauthorised Access Prohibited.");
exit;
}
} else {
echo("Unauthorised Access Prohibited.");
exit;
}
} else {
echo("Unauthorised Access Prohibited.");
exit;
}
$start = $_GET[from];
@@ -86,68 +86,68 @@ $data = mysql_query($sql);
while ($row = mysql_fetch_array($data))
{
@$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 / $div, 2);
@$out_value = round($out_delta * 8 / $period / $div, 2);
@$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 / $div, 2);
@$out_value = round($out_delta * 8 / $period / $div, 2);
#@$data[] = $in_value + $out_value;
#@$in_data[] = $in_value;
#@$out_data[] = $out_value;
# @$ticks[] = $timestamp;
#@$per_data[] = $rate_95th / 1000;
#@$ave_data[] = $rate_average / 1000;
#@$data[] = $in_value + $out_value;
#@$in_data[] = $in_value;
#@$out_data[] = $out_value;
# @$ticks[] = $timestamp;
#@$per_data[] = $rate_95th / 1000;
#@$ave_data[] = $rate_average / 1000;
@$last = $timestamp;
@$last = $timestamp;
$iter_in = $iter_in + $in_delta;
$iter_out = $iter_out + $out_delta;
$iter_period = $iter_period + $period;
$iter_in = $iter_in + $in_delta;
$iter_out = $iter_out + $out_delta;
$iter_period = $iter_period + $period;
if ($iter == $count)
{
$out_data[$i] = round($iter_out * 8 / $iter_period / $div, 2);
$in_data[$i] = round($iter_in * 8 / $iter_period / $div, 2);
$tot_data[$i] = $out_data[$i] + $in_data[$i];
$ticks[$i] = date('M j g:ia', $timestamp);
$ticks[$i] = $timestamp;
if ($dur < 172800)
if ($iter == $count)
{
$hour = date('h', $timestamp);
if ($hour != $lasthour) { $tickPositions[] = $i; $tickLabels[] = date('ga', $timestamp); }
$lasthour = $hour;
} elseif ($dur < 604800) {
$day = date('d', $timestamp);
if ($day != $lastday) { $tickPositions[] = $i; $tickLabels[] = date('D', $timestamp); $h = 0; }
$lastday = $day;
$out_data[$i] = round($iter_out * 8 / $iter_period / $div, 2);
$in_data[$i] = round($iter_in * 8 / $iter_period / $div, 2);
$tot_data[$i] = $out_data[$i] + $in_data[$i];
$ticks[$i] = date('M j g:ia', $timestamp);
$ticks[$i] = $timestamp;
$hour = trim(date('g', $timestamp));
if ($hour != $lasthour)
{
if ($hour == '12') { $tickMinPositions[] = $i; $h = 0; } $h++;
}
if ($dur < 172800)
{
$hour = date('h', $timestamp);
if ($hour != $lasthour) { $tickPositions[] = $i; $tickLabels[] = date('ga', $timestamp); }
$lasthour = $hour;
} elseif ($dur < 604800) {
$day = date('d', $timestamp);
if ($day != $lastday) { $tickPositions[] = $i; $tickLabels[] = date('D', $timestamp); $h = 0; }
$lastday = $day;
$lasthour = $hour;
} else {
$day = date('d', $timestamp);
if ($day != $lastday) { $tickPositions[] = $i; $tickLabels[] = date('dS', $timestamp); }
$lastday = $day;
$hour = trim(date('g', $timestamp));
if ($hour != $lasthour)
{
if ($hour == '12') { $tickMinPositions[] = $i; $h = 0; } $h++;
}
$lasthour = $hour;
} else {
$day = date('d', $timestamp);
if ($day != $lastday) { $tickPositions[] = $i; $tickLabels[] = date('dS', $timestamp); }
$lastday = $day;
}
$per_data[$i] = $rate_95th / $div;
$ave_data[$i] = $rate_average / $div;
$timestamps[$i] = $timestamp;
$iter = "1";
$i++;
unset($iter_out, $iter_in, $iter_period);
}
$per_data[$i] = $rate_95th / $div;
$ave_data[$i] = $rate_average / $div;
$timestamps[$i] = $timestamp;
$iter = "1";
$i++;
unset($iter_out, $iter_in, $iter_period);
}
$iter++;
$iter++;
}
#print_r($ticks);
@@ -175,9 +175,9 @@ $graph->xaxis->SetFont(FF_FONT1,FS_BOLD);
if (count($tickPositions) > 24)
{
$graph->xaxis->SetTextLabelInterval(6);
$graph->xaxis->SetTextLabelInterval(6);
} elseif (count($tickPositions) > 12) {
$graph->xaxis->SetTextLabelInterval(2);
$graph->xaxis->SetTextLabelInterval(2);
}
$graph->xaxis->SetPos('min');
@@ -219,14 +219,14 @@ $lineplot_out->SetColor("blue");
if ($_GET['95th'])
{
$lineplot_95th = new LinePlot($per_data);
$lineplot_95th ->SetColor("red");
$lineplot_95th = new LinePlot($per_data);
$lineplot_95th ->SetColor("red");
}
if ($_GET['ave'])
{
$lineplot_ave = new LinePlot($ave_data);
$lineplot_ave ->SetColor("red");
$lineplot_ave = new LinePlot($ave_data);
$lineplot_ave ->SetColor("red");
}
#$graph->legend->SetLayout(LEGEND_HOR);
@@ -238,14 +238,14 @@ $graph->Add($lineplot_out);
if ($_GET['95th'])
{
$graph->Add($lineplot_95th);
$graph->Add($lineplot_95th);
}
if ($_GET['ave'])
{
$graph->Add($lineplot_ave);
$graph->Add($lineplot_ave);
}
$graph->stroke();
?>
?>
+110 -110
View File
@@ -17,11 +17,11 @@
*/
if($_GET['debug']) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
}
include("../includes/defaults.inc.php");
@@ -36,21 +36,21 @@ include("includes/authenticate.inc.php");
if(!$_SESSION['authenticated']) { echo("not authenticated"); exit; }
function makeTextBlock($text, $fontfile, $fontsize, $width) {
// TODO: handle explicit line-break!
$words = explode(' ', $text);
$lines = array($words[0]);
$currentLine = 0;
foreach ($words as $word) {
$lineSize = imagettfbbox($fontsize, 0, $fontfile, $lines[$currentLine] . ' ' . $word);
if($lineSize[2] - $lineSize[0] < $width) {
$lines[$currentLine] .= ' ' . $word;
} else {
$currentLine++;
$lines[$currentLine] = $word;
}
}
error_log(sprintf('Handles message "%s", %d words => %d/%d lines', $text, count($words), $currentLine, count($lines)));
return implode("\n", $lines);
// TODO: handle explicit line-break!
$words = explode(' ', $text);
$lines = array($words[0]);
$currentLine = 0;
foreach ($words as $word) {
$lineSize = imagettfbbox($fontsize, 0, $fontfile, $lines[$currentLine] . ' ' . $word);
if($lineSize[2] - $lineSize[0] < $width) {
$lines[$currentLine] .= ' ' . $word;
} else {
$currentLine++;
$lines[$currentLine] = $word;
}
}
error_log(sprintf('Handles message "%s", %d words => %d/%d lines', $text, count($words), $currentLine, count($lines)));
return implode("\n", $lines);
}
/**
@@ -61,65 +61,65 @@ function makeTextBlock($text, $fontfile, $fontsize, $width) {
* @msg Complete error message to display in place of graph content
*/
function error($code, $code_msg, $title, $msg) {
global $config;
header(sprintf("HTTP/1.0 %d %s", $code, $code_msg));
header("Pragma: no-cache");
header("Expires: Mon, 01 Jan 2008 00:00:00 CET");
header("Content-Type: image/png");
$w = $config['rrd_width']+81;
$h = $config['rrd_height']+79;
global $config;
header(sprintf("HTTP/1.0 %d %s", $code, $code_msg));
header("Pragma: no-cache");
header("Expires: Mon, 01 Jan 2008 00:00:00 CET");
header("Content-Type: image/png");
$w = $config['rrd_width']+81;
$h = $config['rrd_height']+79;
$png = imagecreate($w, $h);
$c_bkgnd = imagecolorallocate($png, 240, 240, 240);
$c_fgnd = imagecolorallocate($png, 255, 255, 255);
$c_blt = imagecolorallocate($png, 208, 208, 208);
$c_brb = imagecolorallocate($png, 160, 160, 160);
$c_grln = imagecolorallocate($png, 114, 114, 114);
$c_grarr = imagecolorallocate($png, 128, 32, 32);
$c_txt = imagecolorallocate($png, 0, 0, 0);
$c_etxt = imagecolorallocate($png, 64, 0, 0);
$png = imagecreate($w, $h);
$c_bkgnd = imagecolorallocate($png, 240, 240, 240);
$c_fgnd = imagecolorallocate($png, 255, 255, 255);
$c_blt = imagecolorallocate($png, 208, 208, 208);
$c_brb = imagecolorallocate($png, 160, 160, 160);
$c_grln = imagecolorallocate($png, 114, 114, 114);
$c_grarr = imagecolorallocate($png, 128, 32, 32);
$c_txt = imagecolorallocate($png, 0, 0, 0);
$c_etxt = imagecolorallocate($png, 64, 0, 0);
if (function_exists('imageantialias'))
imageantialias($png, true);
imagefilledrectangle($png, 0, 0, $w, $h, $c_bkgnd);
imagefilledrectangle($png, 51, 33, $w-31, $h-47, $c_fgnd);
imageline($png, 51, 30, 51, $h-43, $c_grln);
imageline($png, 48, $h-46, $w-28, $h-46, $c_grln);
imagefilledpolygon($png, array(49, 30, 51, 26, 53, 30), 3, $c_grarr);
imagefilledpolygon($png, array($w-28, $h-48, $w-24, $h-46, $w-28, $h-44), 3, $c_grarr);
imageline($png, 0, 0, $w, 0, $c_blt);
imageline($png, 0, 1, $w, 1, $c_blt);
imageline($png, 0, 0, 0, $h, $c_blt);
imageline($png, 1, 0, 1, $h, $c_blt);
imageline($png, $w-1, 0, $w-1, $h, $c_brb);
imageline($png, $w-2, 1, $w-2, $h, $c_brb);
imageline($png, 1, $h-2, $w, $h-2, $c_brb);
imageline($png, 0, $h-1, $w, $h-1, $c_brb);
if (function_exists('imageantialias'))
imageantialias($png, true);
imagefilledrectangle($png, 0, 0, $w, $h, $c_bkgnd);
imagefilledrectangle($png, 51, 33, $w-31, $h-47, $c_fgnd);
imageline($png, 51, 30, 51, $h-43, $c_grln);
imageline($png, 48, $h-46, $w-28, $h-46, $c_grln);
imagefilledpolygon($png, array(49, 30, 51, 26, 53, 30), 3, $c_grarr);
imagefilledpolygon($png, array($w-28, $h-48, $w-24, $h-46, $w-28, $h-44), 3, $c_grarr);
imageline($png, 0, 0, $w, 0, $c_blt);
imageline($png, 0, 1, $w, 1, $c_blt);
imageline($png, 0, 0, 0, $h, $c_blt);
imageline($png, 1, 0, 1, $h, $c_blt);
imageline($png, $w-1, 0, $w-1, $h, $c_brb);
imageline($png, $w-2, 1, $w-2, $h, $c_brb);
imageline($png, 1, $h-2, $w, $h-2, $c_brb);
imageline($png, 0, $h-1, $w, $h-1, $c_brb);
imagestring($png, 4, ceil(($w-strlen($title)*imagefontwidth(4)) / 2), 10, $title, $c_txt);
imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt);
if (function_exists('imagettfbbox') && is_file($config['error_font'])) {
// Detailled error message
$fmt_msg = makeTextBlock($msg, $errorfont, 10, $w-86);
$fmtbox = imagettfbbox(12, 0, $errorfont, $fmt_msg);
imagettftext($png, 10, 0, 55, 35+3+imagefontwidth(5)-$fmtbox[7]+$fmtbox[1], $c_txt, $errorfont, $fmt_msg);
} else {
imagestring($png, 4, 53, 35+6+imagefontwidth(5), $msg, $c_txt);
}
imagestring($png, 4, ceil(($w-strlen($title)*imagefontwidth(4)) / 2), 10, $title, $c_txt);
imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt);
if (function_exists('imagettfbbox') && is_file($config['error_font'])) {
// Detailled error message
$fmt_msg = makeTextBlock($msg, $errorfont, 10, $w-86);
$fmtbox = imagettfbbox(12, 0, $errorfont, $fmt_msg);
imagettftext($png, 10, 0, 55, 35+3+imagefontwidth(5)-$fmtbox[7]+$fmtbox[1], $c_txt, $errorfont, $fmt_msg);
} else {
imagestring($png, 4, 53, 35+6+imagefontwidth(5), $msg, $c_txt);
}
imagepng($png);
imagedestroy($png);
imagepng($png);
imagedestroy($png);
}
/**
* No RRD files found that could match request
*/
function error404($title, $msg) {
return error(404, "Not found", $title, $msg);
return error(404, "Not found", $title, $msg);
}
function error500($title, $msg) {
return error(500, "Not found", $title, $msg);
return error(500, "Not found", $title, $msg);
}
@@ -127,37 +127,37 @@ function error500($title, $msg) {
* Incomplete / invalid request
*/
function error400($title, $msg) {
return error(400, "Bad request", $title, $msg);
return error(400, "Bad request", $title, $msg);
}
// Process input arguments
$host = read_var('host', $_GET, null);
if (is_null($host))
return error400("?/?-?/?", "Missing host name");
return error400("?/?-?/?", "Missing host name");
else if (!is_string($host))
return error400("?/?-?/?", "Expecting exactly 1 host name");
return error400("?/?-?/?", "Expecting exactly 1 host name");
else if (strlen($host) == 0)
return error400("?/?-?/?", "Host name may not be blank");
return error400("?/?-?/?", "Host name may not be blank");
$plugin = read_var('plugin', $_GET, null);
if (is_null($plugin))
return error400($host.'/?-?/?', "Missing plugin name");
return error400($host.'/?-?/?', "Missing plugin name");
else if (!is_string($plugin))
return error400($host.'/?-?/?', "Plugin name must be a string");
return error400($host.'/?-?/?', "Plugin name must be a string");
else if (strlen($plugin) == 0)
return error400($host.'/?-?/?', "Plugin name may not be blank");
return error400($host.'/?-?/?', "Plugin name may not be blank");
$pinst = read_var('plugin_instance', $_GET, '');
if (!is_string($pinst))
return error400($host.'/'.$plugin.'-?/?', "Plugin instance name must be a string");
return error400($host.'/'.$plugin.'-?/?', "Plugin instance name must be a string");
$type = read_var('type', $_GET, '');
if (is_null($type))
return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Missing type name");
return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Missing type name");
else if (!is_string($type))
return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name must be a string");
return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name must be a string");
else if (strlen($type) == 0)
return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name may not be blank");
return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name may not be blank");
$tinst = read_var('type_instance', $_GET, '');
@@ -166,10 +166,10 @@ $graph_identifier = $host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/'.$ty
$timespan = read_var('timespan', $_GET, $config['timespan'][0]['name']);
$timespan_ok = false;
foreach ($config['timespan'] as &$ts)
if ($ts['name'] == $timespan)
$timespan_ok = true;
if ($ts['name'] == $timespan)
$timespan_ok = true;
if (!$timespan_ok)
return error400($graph_identifier, "Unknown timespan requested");
return error400($graph_identifier, "Unknown timespan requested");
$logscale = (boolean)read_var('logarithmic', $_GET, false);
$tinylegend = (boolean)read_var('tinylegend', $_GET, false);
@@ -177,7 +177,7 @@ $tinylegend = (boolean)read_var('tinylegend', $_GET, false);
// Check that at least 1 RRD exists for the specified request
$all_tinst = collectd_list_tinsts($host, $plugin, $pinst, $type);
if (count($all_tinst) == 0)
return error404($graph_identifier, "No rrd file found for graphing");
return error404($graph_identifier, "No rrd file found for graphing");
// Now that we are read, do the bulk work
load_graph_definitions($logscale, $tinylegend);
@@ -188,49 +188,49 @@ $tinst = strlen($tinst) == 0 ? null : $tinst;
$opts = array();
$opts['timespan'] = $timespan;
if ($logscale)
$opts['logarithmic'] = 1;
$opts['logarithmic'] = 1;
if ($tinylegend)
$opts['tinylegend'] = 1;
$opts['tinylegend'] = 1;
$rrd_cmd = false;
if (isset($MetaGraphDefs[$type])) {
$identifiers = array();
foreach ($all_tinst as &$atinst)
$identifiers[] = collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, $atinst);
collectd_flush($identifiers);
$rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $all_tinst, $opts);
$identifiers = array();
foreach ($all_tinst as &$atinst)
$identifiers[] = collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, $atinst);
collectd_flush($identifiers);
$rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $all_tinst, $opts);
} else {
if (!in_array(is_null($tinst) ? '' : $tinst, $all_tinst))
return error404($host.'/'.$plugin.(!is_null($pinst) ? '-'.$pinst : '').'/'.$type.(!is_null($tinst) ? '-'.$tinst : ''), "No rrd file found for graphing");
collectd_flush(collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, is_null($tinst) ? '' : $tinst));
if (isset($GraphDefs[$type]))
$rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst);
else
$rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst);
if (!in_array(is_null($tinst) ? '' : $tinst, $all_tinst))
return error404($host.'/'.$plugin.(!is_null($pinst) ? '-'.$pinst : '').'/'.$type.(!is_null($tinst) ? '-'.$tinst : ''), "No rrd file found for graphing");
collectd_flush(collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, is_null($tinst) ? '' : $tinst));
if (isset($GraphDefs[$type]))
$rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst);
else
$rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst);
}
if(isset($rrd_cmd))
{
if($config['rrdcached']) { $rrd_cmd .= " --daemon ".$config['rrdcached'] . " "; }
if($_GET['from']) { $from = mres($_GET['from']); }
if($_GET['to']) { $to = mres($_GET['to']); }
$rrd_cmd .= " -s " . $from . " -e " . $to;
if($config['rrdcached']) { $rrd_cmd .= " --daemon ".$config['rrdcached'] . " "; }
if($_GET['from']) { $from = mres($_GET['from']); }
if($_GET['to']) { $to = mres($_GET['to']); }
$rrd_cmd .= " -s " . $from . " -e " . $to;
}
if (isset($_GET['debug'])) {
header('Content-Type: text/plain; charset=utf-8');
printf("Would have executed:\n%s\n", $rrd_cmd);
return 0;
header('Content-Type: text/plain; charset=utf-8');
printf("Would have executed:\n%s\n", $rrd_cmd);
return 0;
} else if ($rrd_cmd) {
header('Content-Type: image/png');
header('Cache-Control: max-age=60');
$rt = 0;
passthru($rrd_cmd, $rt);
if ($rt != 0)
return error500($graph_identifier, "RRD failed to generate the graph: ".$rt);
return $rt;
header('Content-Type: image/png');
header('Cache-Control: max-age=60');
$rt = 0;
passthru($rrd_cmd, $rt);
if ($rt != 0)
return error500($graph_identifier, "RRD failed to generate the graph: ".$rt);
return $rt;
} else {
return error500($graph_identifier, "Failed to tell RRD how to generate the graph");
return error500($graph_identifier, "Failed to tell RRD how to generate the graph");
}
?>
+1 -1
View File
@@ -2,4 +2,4 @@
include("includes/graphs/graph.inc.php");
?>
?>
+40 -40
View File
@@ -6,17 +6,17 @@ ini_set('display_errors', 0);
if (strpos($_SERVER['REQUEST_URI'], "debug"))
{
$debug = "1";
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', E_ALL);
$debug = "1";
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', E_ALL);
} else {
$debug = FALSE;
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('error_reporting', 0);
$debug = FALSE;
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('error_reporting', 0);
}
include("../includes/defaults.inc.php");
@@ -35,18 +35,18 @@ $year = time() - (365 * 24 * 60 * 60);
# Load the settings for Multi-Tenancy.
if (is_array($config['branding'])) {
if ($config['branding'][$_SERVER['SERVER_NAME']])
{
foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval)
if ($config['branding'][$_SERVER['SERVER_NAME']])
{
eval("\$config['" . $confitem . "'] = \$confval;");
foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval)
{
eval("\$config['" . $confitem . "'] = \$confval;");
}
} else {
foreach ($config['branding']['default'] as $confitem => $confval)
{
eval("\$config['" . $confitem . "'] = \$confval;");
}
}
} else {
foreach ($config['branding']['default'] as $confitem => $confval)
{
eval("\$config['" . $confitem . "'] = \$confval;");
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -67,16 +67,16 @@ if ($config['page_refresh']) { echo("<meta http-equiv='refresh' content='".$conf
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<script type="text/javascript" src="js/mktree.js"></script>
<script type="text/javascript" src="js/sorttable.js"></script>
<script type="text/javascript">
<script type="text/javascript">
<!-- Begin
function popUp(URL)
{
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=550,height=600');");
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=550,height=600');");
}
// End -->
</script>
</script>
<script type="text/javascript" src="js/overlib.js"></script>
<div id="center">
@@ -93,23 +93,23 @@ function popUp(URL)
<?php
if ($_SESSION['authenticated'])
{
## Authenticated. Print a page.
if (isset($_GET['page']) && !strstr("..", $_GET['page']) && is_file("pages/" . $_GET['page'] . ".inc.php"))
{
include("pages/" . $_GET['page'] . ".inc.php");
} else {
if (isset($config['front_page']) && is_file($config['front_page']))
## Authenticated. Print a page.
if (isset($_GET['page']) && !strstr("..", $_GET['page']) && is_file("pages/" . $_GET['page'] . ".inc.php"))
{
include($config['front_page']);
include("pages/" . $_GET['page'] . ".inc.php");
} else {
include("pages/front/default.php");
if (isset($config['front_page']) && is_file($config['front_page']))
{
include($config['front_page']);
} else {
include("pages/front/default.php");
}
}
}
} else {
## Not Authenticated. Print login.
include("pages/logon.inc.php");
exit;
## Not Authenticated. Print login.
include("pages/logon.inc.php");
exit;
}
?>
</div>
@@ -125,9 +125,9 @@ echo('<br />Powered by <a href="http://www.observium.org" target="_blank">Observ
if (file_exists('.svn/entries'))
{
$svn = File('.svn/entries');
echo('-SVN r' . trim($svn[3]));
unset($svn);
$svn = File('.svn/entries');
echo('-SVN r' . trim($svn[3]));
unset($svn);
}
echo('</a>. Copyright &copy; 2006-'. date("Y"). ' by Adam Armstrong. All rights reserved.');
+133 -133
View File
@@ -12,18 +12,18 @@ include("includes/authenticate.inc.php");
if (is_array($config['branding']))
{
if ($config['branding'][$_SERVER['SERVER_NAME']])
{
foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval)
if ($config['branding'][$_SERVER['SERVER_NAME']])
{
eval("\$config['" . $confitem . "'] = \$confval;");
foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval)
{
eval("\$config['" . $confitem . "'] = \$confval;");
}
} else {
foreach ($config['branding']['default'] as $confitem => $confval)
{
eval("\$config['" . $confitem . "'] = \$confval;");
}
}
} else {
foreach ($config['branding']['default'] as $confitem => $confval)
{
eval("\$config['" . $confitem . "'] = \$confval;");
}
}
}
if (isset($_GET['device'])) { $where = "WHERE device_id = ".$_GET['device']; } else { $where = ""; }
@@ -31,148 +31,148 @@ $deviceresult = mysql_query("SELECT * from devices $where");
if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
{
$map = "digraph G { sep=0.01; size=\"12,5.5\"; pack=100; bgcolor=transparent; splines=true; overlap=scale; concentrate=0; epsilon=0.001; rankdir=0;
node [ fontname=\"helvetica\", fontstyle=bold, style=filled, color=white, fillcolor=lightgrey, overlap=false;];
edge [ bgcolor=white; fontname=\"helvetica\"; fontstyle=bold; arrowhead=dot; arrowtail=dot];
graph [bgcolor=transparent;];\n\n";
$map = "digraph G { sep=0.01; size=\"12,5.5\"; pack=100; bgcolor=transparent; splines=true; overlap=scale; concentrate=0; epsilon=0.001; rankdir=0;
node [ fontname=\"helvetica\", fontstyle=bold, style=filled, color=white, fillcolor=lightgrey, overlap=false;];
edge [ bgcolor=white; fontname=\"helvetica\"; fontstyle=bold; arrowhead=dot; arrowtail=dot];
graph [bgcolor=transparent;];\n\n";
if (!$_SESSION['authenticated'])
{
$map .= "\"Not authenticated\" [fontsize=20 fillcolor=\"lightblue\" URL=\"/\" shape=box3d]\n";
}
else
{
while ($device = mysql_fetch_array($deviceresult))
if (!$_SESSION['authenticated'])
{
if ($device)
{
$sql = "SELECT * from ports AS I, links AS L WHERE I.device_id = ".$device['device_id']." AND L.local_interface_id = I.interface_id ORDER BY L.remote_hostname";
$links = mysql_query($sql);
if (mysql_num_rows($links))
{
$map .= "\"".$device['hostname']."\" [fontsize=20 fillcolor=\"lightblue\" URL=\"{$config['base_url']}/device/".$device['device_id']."/map/\" shape=box3d]\n";
}
while ($link = mysql_fetch_array($links))
{
$local_interface_id = $link['local_interface_id'];
$remote_interface_id = $link['remote_interface_id'];
$i = 0; $done = 0;
while (isset($linkdone) && $i < count($linkdone))
{
if ($linkdone[$i] == "$remote_interface_id $local_interface_id") { $done = 1; }
$i++;
}
if (!$done)
{
$linkdone[] = "$local_interface_id $remote_interface_id";
$links++;
if ($link['ifSpeed'] >= "10000000000")
{
$info = "color=red3 style=\"setlinewidth(6)\"";
} elseif ($link['ifSpeed'] >= "1000000000") {
$info = "color=lightblue style=\"setlinewidth(4)\"";
} elseif ($link['ifSpeed'] >= "100000000") {
$info = "color=lightgrey style=\"setlinewidth(2)\"";
} elseif ($link['ifSpeed'] >= "10000000") {
$info = "style=\"setlinewidth(1)\"";
} else {
$info = "style=\"setlinewidth(1)\"";
}
$src = $device['hostname'];
if ($remote_interface_id)
{
$dst = mysql_result(mysql_query("SELECT `hostname` FROM `devices` AS D, `ports` AS I WHERE I.interface_id = '$remote_interface_id' AND D.device_id = I.device_id"),0);
$dst_host = mysql_result(mysql_query("SELECT D.device_id FROM `devices` AS D, `ports` AS I WHERE I.interface_id = '$remote_interface_id' AND D.device_id = I.device_id"),0);
} else {
$dst_host = $link['remote_hostname'];
$dst = $link['remote_hostname'];
}
$sif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE `interface_id`=" . $link['local_interface_id'])),$device);
if ($remote_interface_id)
{
$dif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE `interface_id`=" . $link['remote_interface_id'])));
} else {
$dif['label'] = $link['remote_port'];
$dif['interface_id'] = $link['remote_hostname'] . $link['remote_port'];
}
$map .= "\"" . $sif['interface_id'] . "\" [label=\"" . $sif['label'] . "\", fontsize=12, fillcolor=lightblue URL=\"{$config['base_url']}/device/".$device['device_id']."/interface/$local_interface_id/\"]\n";
if (!$ifdone[$src][$sif['interface_id']])
{
$map .= "\"$src\" -> \"" . $sif['interface_id'] . "\" [weight=500000, arrowsize=0, len=0];\n";
$ifdone[$src][$sif['interface_id']] = 1;
}
$map .= "\"$dst\" [URL=\"{$config['base_url']}/device/$dst_host/map/\" fontsize=20 shape=box3d]\n";
if ($dst_host == $device['device_id'] || $where == '') {
$map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"{$config['base_url']}/device/$dst_host/interface/$remote_interface_id/\"]\n";
} else {
$map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . " \", fontsize=12, fillcolor=lightgray, URL=\"{$config['base_url']}/device/$dst_host/interface/$remote_interface_id/\"]\n";
}
if (!$ifdone[$dst][$dif['interface_id']])
{
$map .= "\"" . $dif['interface_id'] . "\" -> \"$dst\" [weight=500000, arrowsize=0, len=0];\n";
$ifdone[$dst][$dif['interface_id']] = 1;
}
$map .= "\"" . $sif['interface_id'] . "\" -> \"" . $dif['interface_id'] . "\" [weight=1, arrowhead=normal, arrowtail=normal, len=2, $info] \n";
}
}
$done = 0;
}
$map .= "\"Not authenticated\" [fontsize=20 fillcolor=\"lightblue\" URL=\"/\" shape=box3d]\n";
}
}
else
{
while ($device = mysql_fetch_array($deviceresult))
{
if ($device)
{
$sql = "SELECT * from ports AS I, links AS L WHERE I.device_id = ".$device['device_id']." AND L.local_interface_id = I.interface_id ORDER BY L.remote_hostname";
$links = mysql_query($sql);
$map .= "
if (mysql_num_rows($links))
{
$map .= "\"".$device['hostname']."\" [fontsize=20 fillcolor=\"lightblue\" URL=\"{$config['base_url']}/device/".$device['device_id']."/map/\" shape=box3d]\n";
}
while ($link = mysql_fetch_array($links))
{
$local_interface_id = $link['local_interface_id'];
$remote_interface_id = $link['remote_interface_id'];
$i = 0; $done = 0;
while (isset($linkdone) && $i < count($linkdone))
{
if ($linkdone[$i] == "$remote_interface_id $local_interface_id") { $done = 1; }
$i++;
}
if (!$done)
{
$linkdone[] = "$local_interface_id $remote_interface_id";
$links++;
if ($link['ifSpeed'] >= "10000000000")
{
$info = "color=red3 style=\"setlinewidth(6)\"";
} elseif ($link['ifSpeed'] >= "1000000000") {
$info = "color=lightblue style=\"setlinewidth(4)\"";
} elseif ($link['ifSpeed'] >= "100000000") {
$info = "color=lightgrey style=\"setlinewidth(2)\"";
} elseif ($link['ifSpeed'] >= "10000000") {
$info = "style=\"setlinewidth(1)\"";
} else {
$info = "style=\"setlinewidth(1)\"";
}
$src = $device['hostname'];
if ($remote_interface_id)
{
$dst = mysql_result(mysql_query("SELECT `hostname` FROM `devices` AS D, `ports` AS I WHERE I.interface_id = '$remote_interface_id' AND D.device_id = I.device_id"),0);
$dst_host = mysql_result(mysql_query("SELECT D.device_id FROM `devices` AS D, `ports` AS I WHERE I.interface_id = '$remote_interface_id' AND D.device_id = I.device_id"),0);
} else {
$dst_host = $link['remote_hostname'];
$dst = $link['remote_hostname'];
}
$sif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE `interface_id`=" . $link['local_interface_id'])),$device);
if ($remote_interface_id)
{
$dif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE `interface_id`=" . $link['remote_interface_id'])));
} else {
$dif['label'] = $link['remote_port'];
$dif['interface_id'] = $link['remote_hostname'] . $link['remote_port'];
}
$map .= "\"" . $sif['interface_id'] . "\" [label=\"" . $sif['label'] . "\", fontsize=12, fillcolor=lightblue URL=\"{$config['base_url']}/device/".$device['device_id']."/interface/$local_interface_id/\"]\n";
if (!$ifdone[$src][$sif['interface_id']])
{
$map .= "\"$src\" -> \"" . $sif['interface_id'] . "\" [weight=500000, arrowsize=0, len=0];\n";
$ifdone[$src][$sif['interface_id']] = 1;
}
$map .= "\"$dst\" [URL=\"{$config['base_url']}/device/$dst_host/map/\" fontsize=20 shape=box3d]\n";
if ($dst_host == $device['device_id'] || $where == '') {
$map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"{$config['base_url']}/device/$dst_host/interface/$remote_interface_id/\"]\n";
} else {
$map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . " \", fontsize=12, fillcolor=lightgray, URL=\"{$config['base_url']}/device/$dst_host/interface/$remote_interface_id/\"]\n";
}
if (!$ifdone[$dst][$dif['interface_id']])
{
$map .= "\"" . $dif['interface_id'] . "\" -> \"$dst\" [weight=500000, arrowsize=0, len=0];\n";
$ifdone[$dst][$dif['interface_id']] = 1;
}
$map .= "\"" . $sif['interface_id'] . "\" -> \"" . $dif['interface_id'] . "\" [weight=1, arrowhead=normal, arrowtail=normal, len=2, $info] \n";
}
}
$done = 0;
}
}
}
$map .= "
};";
if ($_GET['debug'] == 1) { echo("<pre>$map</pre>");exit(); }
if ($_GET['debug'] == 1) { echo("<pre>$map</pre>");exit(); }
switch ($_GET['format'])
{
case 'svg':
switch ($_GET['format'])
{
case 'svg':
case 'png':
break;
break;
default:
$_GET['format'] = 'png';
}
$_GET['format'] = 'png';
}
if ($links > 10) ### Unflatten if there are more than 10 links. beyond that it gets messy
{
if ($links > 10) ### Unflatten if there are more than 10 links. beyond that it gets messy
{
$maptool = 'unflatten -f -l 5 |dot';
} else {
} else {
$maptool = 'dot';
}
}
if ($where == '') { $maptool = 'neato -Gpack'; }
if ($where == '') { $maptool = 'neato -Gpack'; }
$img = shell_exec("echo \"".addslashes($map)."\" | $maptool -T".$_GET['format']."");
if ($_GET['format'] == "png") {
$img = shell_exec("echo \"".addslashes($map)."\" | $maptool -T".$_GET['format']."");
if ($_GET['format'] == "png") {
header("Content-type: image/".$_GET['format']);
} elseif ($_GET['format'] == "svg") {
} elseif ($_GET['format'] == "svg") {
header("Content-type: image/svg+xml");
$img = str_replace("<a ", '<a target="_parent" ', $img);
}
echo("$img");
}
echo("$img");
}
else
{
if ($_SESSION['authenticated']) ## FIXME level 10 only?
{
echo('<center>
<object data="'. $config['base_url'] . '/map.php?format=svg" type="image/svg+xml">
</object>
</center>');
}
if ($_SESSION['authenticated']) ## FIXME level 10 only?
{
echo('<center>
<object data="'. $config['base_url'] . '/map.php?format=svg" type="image/svg+xml">
</object>
</center>');
}
}
?>
?>
+29 -29
View File
@@ -5,10 +5,10 @@ ini_set('display_errors', 0);
if ($_GET[debug])
{
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', E_ALL);
}
include("../includes/defaults.inc.php");
@@ -20,36 +20,36 @@ include("includes/authenticate.inc.php");
if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; }
if ($_GET['query'] && $_GET['cmd']) {
$host = $_GET['query'];
if (Net_IPv6::checkIPv6($host)||Net_IPv4::validateip($host)||preg_match("/^[a-zA-Z0-9.-]*$/", $host)) {
switch ($_GET['cmd']) {
case 'whois':
$cmd = $config['whois'] . " $host | grep -v \%";
break;
case 'ping':
$cmd = $config['ping'] . " -c 5 $host";
break;
case 'tracert':
$cmd = $config['mtr'] . " -r -c 5 $host";
break;
case 'nmap':
if ($_SESSION['userlevel'] != '10')
{
echo("insufficient privileges");
} else {
$cmd = $config['nmap'] . " $host";
$host = $_GET['query'];
if (Net_IPv6::checkIPv6($host)||Net_IPv4::validateip($host)||preg_match("/^[a-zA-Z0-9.-]*$/", $host)) {
switch ($_GET['cmd']) {
case 'whois':
$cmd = $config['whois'] . " $host | grep -v \%";
break;
case 'ping':
$cmd = $config['ping'] . " -c 5 $host";
break;
case 'tracert':
$cmd = $config['mtr'] . " -r -c 5 $host";
break;
case 'nmap':
if ($_SESSION['userlevel'] != '10')
{
echo("insufficient privileges");
} else {
$cmd = $config['nmap'] . " $host";
}
break;
}
break;
}
if (!empty($cmd))
{
$output = `$cmd`;
if (!empty($cmd))
{
$output = `$cmd`;
}
}
}
}
$output = trim($output);
echo("<pre>$output</pre>");
?>
?>
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
phpinfo();
phpinfo();
?>