$end - 3600) $start = $end - 3600;
if ($start < $end - 864*36525*2) $start = $end - 864*36525*2;
if ($ip == "0.0.0.0")
{
$title = "All internet traffic";
}
else
{
$title = "Internet traffic for $ip";
}
$span = $end - $start;
if ($span < 3600) $span = sprintf ("%d minutes", $span/60);
elseif ($span < 86400*2) $span = sprintf ("%d hours", $span/3600);
elseif ($span < 86400*90) $span = sprintf ("%d days", $span/86400);
elseif ($span == 864*36525 && $now == $end) $span = "year";
elseif ($span == 864*36525 && $now != $end) $span = "1 year";
elseif ($span < 864*36525*2) $span = sprintf ("%d months", $span/864*12/36525);
else $span = sprintf ("%d years", $span/864/36525);
$title .= " - ";
if ($now == $end) $title .= "last ";
$title .= $span;
if (!file_exists ("data/$ip.rrd"))
exit;
$timerange = str_replace (":", "\\:",
"From "
. strftime ("%F %T", $start)
. " to "
. strftime ("%F %T", $end));
header ("Content-type: image/png");
$cmd = "rrdtool graph -";
$cmd .= " --imgformat=PNG";
$cmd .= " --width=400";
$cmd .= " --height=150";
$cmd .= " --start=$start";
$cmd .= " --end=$end";
$cmd .= " --alt-autoscale-max";
$cmd .= " --lower-limit=0";
$cmd .= " --base=1000";
$cmd .= " --slope-mode";
$cmd .= " --title=\"$title\"";
$cmd .= " --vertical-label=\"bytes per second\"";
$cmd .= " COMMENT:\"$timerange\\c\"";
$cmd .= " COMMENT:\" \\n\"";
$cmd .= " DEF:a=data/$ip.rrd:in:AVERAGE DEF:b=data/$ip.rrd:in:MAX";
$cmd .= " DEF:c=data/$ip.rrd:out:AVERAGE DEF:d=data/$ip.rrd:out:MAX";
$cmd .= " AREA:a#00cf00ff:\"Download\" GPRINT:a:LAST:\"Cur\\:%8.2lf %s\" GPRINT:a:AVERAGE:\"Avg\\:%8.2lf %s\" GPRINT:b:MAX:\"Max\\:%8.2lf %s\\n\"";
$cmd .= " LINE1:c#002a97ff:\"Upload \" GPRINT:c:LAST:\"Cur\\:%8.2lf %s\" GPRINT:c:AVERAGE:\"Avg\\:%8.2lf %s\" GPRINT:d:MAX:\"Max\\:%8.2lf %s\"";
passthru ($cmd);
exit;
}
elseif (isset ($_REQUEST["tables"]))
{
$top = 0 + $_REQUEST["top"];
if (!$top) $top = 10;
if (!$adminmode || isset ($_REQUEST["ip"])) $top = 0;
foreach (array("month", "day") as $period)
{
print_traffic_table (array ("period" => $period,
"ip" => $ip,
"top" => $top));
print "
\n";
}
exit;
}
?>
$period,
"ip" => $ip,
"top" => $top));
print " \n"; } ?> | $ip)); ?> |