syntaxer run 1/<many>

git-svn-id: http://www.observium.org/svn/observer/trunk@2963 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2012-04-05 16:10:12 +00:00
parent 7e574d329d
commit 04ec17134b
2 changed files with 247 additions and 234 deletions

View File

@@ -3,7 +3,8 @@
ini_set('allow_url_fopen', 0);
ini_set('display_errors', 0);
if (strpos($_SERVER['REQUEST_URI'], "debug")) {
if (strpos($_SERVER['REQUEST_URI'], "debug"))
{
$debug = "1";
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
@@ -22,6 +23,7 @@
include("../includes/functions.php");
include("includes/functions.inc.php");
include("includes/authenticate.inc.php");
if ($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR']) { if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; } }
require_once("includes/jpgraph/src/jpgraph.php");
require_once("includes/jpgraph/src/jpgraph_line.php");
@@ -29,9 +31,12 @@
require_once("includes/jpgraph/src/jpgraph_utils.inc.php");
require_once("includes/jpgraph/src/jpgraph_date.php");
if (is_numeric($_GET['bill_id'])) {
if ($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR']) {
if (bill_permitted($_GET['bill_id'])) {
if (is_numeric($_GET['bill_id']))
{
if ($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR'])
{
if (bill_permitted($_GET['bill_id']))
{
$bill_id = $_GET['bill_id'];
} else {
echo("Unauthorised Access Prohibited.");
@@ -66,10 +71,12 @@
$overuse_data = array();
$ticklabels = array();
if ($imgtype == "historical") {
if ($imgtype == "historical")
{
$i = "0";
foreach (dbFetchRows("SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 12", array($bill_id)) as $data) {
foreach (dbFetchRows("SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 12", array($bill_id)) as $data)
{
$datefrom = strftime("%e %b %Y", strtotime($data['bill_datefrom']));
$dateto = strftime("%e %b %Y", strtotime($data['bill_dateto']));
$datelabel = $datefrom."\n".$dateto;
@@ -77,13 +84,15 @@
$traf['out'] = $data['traf_out'];
$traf['total'] = $data['traf_total'];
if ($data['bill_type'] == "Quota") {
if ($data['bill_type'] == "Quota")
{
$traf['allowed'] = $data['bill_allowed'];
$traf['overuse'] = $data['bill_overuse'];
} else {
$traf['allowed'] = "0";
$traf['overuse'] = "0";
}
array_push($ticklabels, $datelabel);
array_push($in_data, $traf['in']);
array_push($out_data, $traf['out']);
@@ -93,9 +102,12 @@
$i++;
//print_r($data);
}
if ($i < 12) {
if ($i < 12)
{
$y = 12 - $i;
for ($x=0;$x<$y;$x++) {
for ($x=0;$x<$y;$x++)
{
$allowed = (($x == "0") ? $traf['allowed'] : "0" );
array_push($in_data, "0");
array_push($out_data, "0");
@@ -110,8 +122,10 @@
} else {
$data = array();
$average = 0;
if ($imgtype == "day") {
foreach(dbFetch("SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY DATE(timestamp) ORDER BY timestamp ASC", array($bill_id, $start, $end)) as $data) {
if ($imgtype == "day")
{
foreach (dbFetch("SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY DATE(timestamp) ORDER BY timestamp ASC", array($bill_id, $start, $end)) as $data)
{
$traf['in'] = (isset($data['traf_in']) ? $data['traf_in'] : 0);
$traf['out'] = (isset($data['traf_out']) ? $data['traf_out'] : 0);
$traf['total'] = (isset($data['traf_total']) ? $data['traf_total'] : 0);
@@ -123,17 +137,21 @@
$average += $data['traf_total'];
}
$ave_count = count($tot_data);
if ($imgbill != false) {
if ($imgbill != false)
{
$days = strftime("%e", date($end - $start)) - $ave_count - 1;
for ($x=0;$x<$days;$x++) {
for ($x=0;$x<$days;$x++)
{
array_push($ticklabels, "");
array_push($in_data, 0);
array_push($out_data, 0);
array_push($tot_data, 0);
}
}
} elseif ($imgtype == "hour") {
foreach(dbFetch("SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY HOUR(timestamp) ORDER BY timestamp ASC", array($bill_id, $start, $end)) as $data) {
} elseif ($imgtype == "hour")
{
foreach (dbFetch("SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY HOUR(timestamp) ORDER BY timestamp ASC", array($bill_id, $start, $end)) as $data)
{
$traf['in'] = (isset($data['traf_in']) ? $data['traf_in'] : 0);
$traf['out'] = (isset($data['traf_out']) ? $data['traf_out'] : 0);
$traf['total'] = (isset($data['traf_total']) ? $data['traf_total'] : 0);
@@ -146,15 +164,16 @@
}
$ave_count = count($tot_data);
}
$decimal = 0;
$average = $average / $ave_count;
for ($x=0;$x<=count($tot_data);$x++) {
for ($x=0;$x<=count($tot_data);$x++)
{
array_push($ave_data, $average);
}
$graph_name = date('M j g:ia', $start)." - ".date('M j g:ia', $end);
}
// Create the graph. These two calls are always required
$graph = new Graph($xsize, $ysize, $graph_name);
$graph->img->SetImgFormat("png");
@@ -185,7 +204,6 @@
$graph->yaxis->SetLabelFormatCallback('format_bytes_billing');
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#FFFFFF@0.5');
// Create the bar plots
$barplot_tot = new BarPlot($tot_data);
$barplot_tot->SetLegend("Traffic total");
@@ -206,8 +224,8 @@
$barplot_out->SetFillColor('lightblue@0.4');
$barplot_out->SetWeight(1);
if ($imgtype == "historical") {
if ($imgtype == "historical")
{
$barplot_over = new BarPlot($overuse_data);
$barplot_over->SetLegend("Traffic Overusage");
$barplot_over->SetColor('darkred');
@@ -233,7 +251,6 @@
$graph->Add($gbplot);
$graph->Add($lineplot_allow);
// Display the graph
$graph->Stroke();

View File

@@ -60,10 +60,6 @@ if($debug) { echo("<br />Runtime ".$run." secs");
' Rows '.($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,3).'s'.
' Column '.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,3).'s');
}
?>