444 lines
16 KiB
PHP
444 lines
16 KiB
PHP
<?php
|
|
include ("jpgraph/jpgraph.php");
|
|
include ("jpgraph/jpgraph_pie.php");
|
|
|
|
// These are called from the HTML further down due to the way Jpgraph renders
|
|
// Check for a type. This is not called on the first run through
|
|
$parm1 = $_GET['type'];
|
|
|
|
// For tests
|
|
// printf("TYPE=%s - %s\n",$type,$parm1);
|
|
// So we only run these if we are called with a type. Which is what happens in the html further down.
|
|
if ($parm1 == 'spamhour') {
|
|
read_and_print_spam_log('/usr/local/unjunkmgr/spamfilterstats.spam.hour', 'last hour', 'graph');
|
|
} elseif ($parm1 == 'spamday') {
|
|
read_and_print_spam_log('/usr/local/unjunkmgr/spamfilterstats.spam.day', 'last 24 hours', 'graph');
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
|
|
<html>
|
|
<head>
|
|
<title>Corporate Virus and Spam Statistics</title>
|
|
<meta http-equiv="Refresh" content="300">
|
|
<meta http-equiv="Pragma" content="no-cache">
|
|
<meta http-equiv="Expires" content="Mon, 19 Aug 2002 07:47:20 GMT">
|
|
<link rel="stylesheet" type="text/css" href="unjunkmgr.css">
|
|
</head>
|
|
|
|
<body>
|
|
<center>
|
|
<table border="3" width="940">
|
|
<tr>
|
|
<td align="center">
|
|
<h1>Corporate Spam and Virus Statistics</h1><br>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>
|
|
<table border="0" width="920" align="center">
|
|
<tr>
|
|
<!-- Top row 24 hours Spam & Virus stats -->
|
|
<td width="25%" align="center">
|
|
<h2 style="word-spacing: 0; margin-top: 0; margin-bottom: 0" align="center">Hourly Spam Statistics over last 24 hours</h2>
|
|
<h2 style="word-spacing: 0; margin-top: 0; margin-bottom: 0"><a href="spam.html"><img border="1" src="spam-day.png" width="450" height="121"></a></h2>
|
|
</td>
|
|
<td width="25%" align="center">
|
|
<h2 style="word-spacing: 0; margin-top: 0; margin-bottom: 0" align="center">Hourly Virus Statistics over last 24 hours</h2>
|
|
<h2 style="word-spacing: 0; margin-top: 0; margin-bottom: 0"><a href="virus.html"><img border="1" src="virus-day.png" width="450" height="121"></a></h2>
|
|
</td>
|
|
</tr>
|
|
<tr><td colspan="2"> </td></tr>
|
|
<tr>
|
|
<!-- Second row last hour/24 hours Spam Pie charts-->
|
|
<!-- this is where we call the script again to draw the Pie Charts-->
|
|
<td align="center"><img src="index.php?type=spamhour"></td>
|
|
<td align="center"><img src="index.php?type=spamday"></td>
|
|
|
|
</tr>
|
|
<tr><td colspan=2> </td></tr>
|
|
<!-- This does the Virus stats charts -->
|
|
<tr>
|
|
<td align="center">
|
|
<?php
|
|
read_and_print_virus_log('/usr/local/unjunkmgr/spamfilterstats.virus.hour', 'hour', 'table'); ?>
|
|
</td>
|
|
<td align="center">
|
|
<?php
|
|
read_and_print_virus_log('/usr/local/unjunkmgr/spamfilterstats.virus.day', '24 hours', 'table'); ?>
|
|
</td>
|
|
</tr>
|
|
<tr><td colspan=2> </td></tr>
|
|
<!-- This does the Spam pie charts -->
|
|
<tr>
|
|
<td align="center">
|
|
<?php //read_and_print_spam_log('/usr/local/unjunkmgr/spamfilterstats.spam.hour', 'hour', 'table');
|
|
|
|
?>
|
|
</td>
|
|
<td align="center">
|
|
<?php //read_and_print_virus_log('/usr/local/unjunkmgr/spamfilterstats.spam.day', '24 hours', 'table');
|
|
|
|
?>
|
|
</td>
|
|
</tr>
|
|
<tr><td colspan=2> </td></tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
</body>
|
|
</html>
|
|
|
|
<?php
|
|
function read_and_print_virus_log($log_filename, $text, $style)
|
|
{
|
|
|
|
if (!file_exists($log_filename) || !is_readable($log_filename) || !$fd = fopen($log_filename, "r")) {
|
|
print ('<td width="10%" align="left"><H3 style="word-spacing: 0; margin-top: 2; margin-bottom: 2; margin-left: 2" colspan=2>');
|
|
print ('Statistics database not found');
|
|
print ('</td>');
|
|
return;
|
|
}
|
|
//print ('get data virus_log');
|
|
flock($fd, 1); // get a shared lock
|
|
$linecount = 0;
|
|
while (!feof($fd)) {
|
|
$line = fgets($fd);
|
|
if ($line) {
|
|
|
|
// printf("line = %s\n",$line);
|
|
// $keys = split ("\|", $line) ;
|
|
$keys = preg_split("/\|/", $line);
|
|
|
|
$list = array();
|
|
foreach ($keys as $item) {
|
|
// $key = split ("\=", $item);
|
|
$key = preg_split("/\=/", $item);
|
|
// printf("key = %s\n",$key);
|
|
if ($key[0] == 'SCANNED') {
|
|
$scanned = $key[1];
|
|
}
|
|
if ($key[0] == 'BAD') {
|
|
$bad = $key[1];
|
|
}
|
|
if ($key[0] == 'NAME') {
|
|
$name = $key[1];
|
|
} elseif ($key[0] == 'COUNT') {
|
|
$count = $key[1];
|
|
$list['count'] = $count;
|
|
} elseif ($key[0] == 'LATEST') {
|
|
$latest = $key[1];
|
|
$list['latest'] = $latest;
|
|
}
|
|
}
|
|
|
|
if ($name) {
|
|
$list = array(
|
|
'name' => $name,
|
|
'count' => $count,
|
|
'latest' => $latest
|
|
);
|
|
$print_list[$linecount++] = $list;
|
|
}
|
|
}
|
|
}
|
|
|
|
flock($fd, 3); // release the lock
|
|
fclose($fd);
|
|
|
|
// Now print out results if they exist
|
|
if (isset($print_list)) {
|
|
$sorted_list = msort($print_list, "count", false);
|
|
}
|
|
|
|
// print_r($sorted_list);
|
|
print ('<table border="2" align="center"width="98%">');
|
|
// This will always be table - used to have 'oldstyle'
|
|
if ($style == 'table') {
|
|
print ('<tr><td width="100%" align="center" valign="top" colspan=2 bgcolor=#888888>');
|
|
print ('<H2 style="word-spacing: 0; margin-top: 0; margin-bottom: 2; margin-left: 2">');
|
|
|
|
printf("Virus Threats last %s ", $text);
|
|
print ('</td>');
|
|
print ('<tr><td width="70%" align="left" valign="top"><H3 style="word-spacing: 0; margin-top: 0; margin-bottom: 2; margin-left: 2">');
|
|
printf("Emails Scanned for Virus");
|
|
print ('</td>');
|
|
print ('<td align="right"><H3 style="word-spacing: 0; margin-top: 0; margin-bottom: 2; margin-left: 2">');
|
|
printf("%s", number_format($scanned, 0, 0, '.'));
|
|
print ('</td>');
|
|
print ('</tr>');
|
|
print ('<tr><td width="50%" align="left"><H3 style="word-spacing: 0; margin-top: 0; margin-bottom: 2; margin-left: 2">');
|
|
printf("Infected with Virus");
|
|
print ('</td>');
|
|
print ('<td align="right"><H3 style="word-spacing: 0; margin-top: 0; margin-bottom: 2; margin-left: 2">');
|
|
if ($scanned > 0) printf("%s (%.2f %%)", number_format($bad, 0, 2, '.') , number_format(($bad / $scanned) * 100, 2, '.', ''));
|
|
print ('</td>');
|
|
print ('</tr>');
|
|
}
|
|
|
|
if (isset($sorted_list)) {
|
|
// This will print emails if there are any
|
|
if ($linecount > 0) {
|
|
$linecount = 0;
|
|
|
|
print ('<tr><H3><td width="100%" align="left" valign="top" colspan=2 bgcolor=#888888>');
|
|
print ('<H4 style="word-spacing: 0; margin-top: 0; margin-bottom: 2; margin-left: 2">');
|
|
// Always table ??
|
|
if ($style == 'table') {
|
|
print ('Top Blocked Virus Threats');
|
|
} else {
|
|
printf("Top Spammed Emails last %s", $text);
|
|
}
|
|
print ('</td>');
|
|
print ('</tr>');
|
|
print ('<tr><td width="70%" align="left" bgcolor=#BBBBBB><H5 style="word-spacing: 0; margin-top: 0; margin-bottom: 2; margin-left: 2">');
|
|
// Always table ??
|
|
if ($style == 'table') {
|
|
print ('Name');
|
|
} else {
|
|
print ('Email address');
|
|
}
|
|
print ('</td>');
|
|
print ('<td align="right" bgcolor=#BBBBBB><H5 style="word-spacing: 0; margin-top: 0; margin-bottom: 2; margin-left: 2">');
|
|
print ('Count');
|
|
print ('</td>');
|
|
print ('</tr>');
|
|
|
|
foreach ($sorted_list as $item) {
|
|
|
|
print ('<tr><td width="70%" align="left"><H5 style="word-spacing: 0; margin-top: 2; margin-bottom: 2; margin-left: 2">');
|
|
printf("%s", $item['name']);
|
|
print ('</td>');
|
|
print ('<td align="right"><H5 style="word-spacing: 0; margin-top: 2; margin-bottom: 2; margin-left: 2">');
|
|
printf("%s", $item['count']);
|
|
print ('</td>');
|
|
print ('</tr>');
|
|
|
|
$linecount++;
|
|
|
|
// Only show top 10...
|
|
if ($linecount >= 10) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} // End isset
|
|
print ('</table>');
|
|
return;
|
|
}
|
|
|
|
function read_and_print_spam_log($log_filename, $text, $style)
|
|
{
|
|
|
|
if (!file_exists($log_filename) || !is_readable($log_filename) || !$fd = fopen($log_filename, "r")) {
|
|
print ('<td width="10%" align="left"><H3 style="word-spacing: 0; margin-top: 2; margin-bottom: 2; margin-left: 2" colspan=2>');
|
|
print ('Statistics database not found');
|
|
print ('</td>');
|
|
return;
|
|
}
|
|
//print ('get data spam_log');
|
|
flock($fd, 1); // get a shared lock
|
|
$linecount = 0;
|
|
while (!feof($fd)) {
|
|
$line = fgets($fd);
|
|
if ($line) {
|
|
// printf("line = %s\n",$line);
|
|
// $keys = split ("\|", $line) ;
|
|
$keys = preg_split("/\|/", $line);
|
|
$list = array();
|
|
foreach ($keys as $item) {
|
|
// $key = split ("\=", $item);
|
|
$key = preg_split("/\=/", $item);
|
|
// printf("key = %s\n",$key);
|
|
if ($key[0] == 'SCANNED') {
|
|
$scanned = $key[1];
|
|
}
|
|
if ($key[0] == 'REJECT') {
|
|
$reject = $key[1];
|
|
}
|
|
if ($key[0] == 'TAGGED') {
|
|
$tagged = $key[1];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
flock($fd, 3); // release the lock
|
|
fclose($fd);
|
|
|
|
//if ($style == 'oldstyle') {
|
|
// print('<table border="2" align="center" width="98%">');
|
|
//
|
|
// print('<tr><td width="70%" align="left"><H3 style="word-spacing: 0; margin-top: 2; margin-bottom: 2; margin-left: 2">');
|
|
// printf("Scanned for Spam");
|
|
// print('</td>');
|
|
// print('<td align="right"><H3 style="word-spacing: 0; margin-top: 2; margin-bottom: 2; margin-left: 2">');
|
|
// printf("%s",number_format($scanned,0,0,'.'));
|
|
// print('</td>');
|
|
// print('</tr>');
|
|
//
|
|
// print('<tr><td width="70%" align="left" valign="top"><H3 style="word-spacing: 0; margin-top: 0; margin-bottom: 2; margin-left: 2">');
|
|
// printf("Good");
|
|
// print('</td>');
|
|
// print('<td align="right"><H3 style="word-spacing: 0; margin-top: 0; margin-bottom: 2; margin-left: 2">');
|
|
// $good_emails = $scanned-($reject+$tagged);
|
|
// printf("%s (%.2d %%)",number_format($good_emails,0,0,'.'),($good_emails/$scanned)*100);
|
|
// print('</td>');
|
|
// print('</tr>');
|
|
//
|
|
//
|
|
// print('<tr><td width="50%" align="left"><H3 style="word-spacing: 0; margin-top: 2; margin-bottom: 2; margin-left: 2">');
|
|
// printf("Rejected as Spam");
|
|
// print('<td align="right"><H3 style="word-spacing: 0; margin-top: 2; margin-bottom: 2; margin-left: 2">');
|
|
// printf("%s (%.2d %%)",number_format($reject,0,0,'.'),($reject/$scanned)*100);
|
|
// print('</td>');
|
|
// print('</tr>');
|
|
//
|
|
// print('<tr><td width="50%" align="left"><H3 style="word-spacing: 0; margin-top: 2; margin-bottom: 2; margin-left: 2">');
|
|
// printf("Accepted but Tagged as Spam");
|
|
// print('<td align="right"><H3 style="word-spacing: 0; margin-top: 2; margin-bottom: 2; margin-left: 2">');
|
|
// printf("%s (%.2d %%)",number_format($tagged,0,0,'.'),($tagged/$scanned)*100);
|
|
// print('</td>');
|
|
// print('</tr>');
|
|
// print('<br>');
|
|
// print('</table>');
|
|
//
|
|
//} else {
|
|
$good_emails = $scanned - ($reject + $tagged);
|
|
|
|
// what if no emails went through??
|
|
if ($scanned == 0) {
|
|
|
|
include "jpgraph/jpgraph_canvas.php";
|
|
include "jpgraph/jpgraph_canvtools.php";
|
|
|
|
$g = new CanvasGraph(450, 260, 'auto');
|
|
$scale = new CanvasScale($g);
|
|
$scale->Set(0, 27, 0, 53);
|
|
$g->SetMargin(1, 2, 1, 2);
|
|
$g->SetColor('white');
|
|
$g->SetMarginColor("black");
|
|
$g->InitFrame();
|
|
|
|
$t = new CanvasRectangleText();
|
|
|
|
$t->SetFillColor('');
|
|
$t->SetFontColor('black');
|
|
$t->SetColor('');
|
|
$t->SetShadow('');
|
|
$t->SetFont(FF_ARIAL, FS_BOLD, 14);
|
|
$t->Set('No emails scanned for spam last hour', 8, 1, 8);
|
|
$t->Stroke($g->img, $scale);
|
|
|
|
$g->Stroke();
|
|
return;
|
|
}
|
|
|
|
// Some data
|
|
$data = array(
|
|
$good_emails,
|
|
$tagged,
|
|
$reject
|
|
);
|
|
|
|
// A new pie graph
|
|
$graph = new PieGraph(450, 260, 'auto');
|
|
|
|
// Setup title
|
|
$graph->title->Set("Spam Statistics " . $text);
|
|
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 14);
|
|
$graph->title->SetMargin(3); // Add a little bit more margin from the top
|
|
$graph->footer->center->Set("Generated " . date('l jS \of F Y h:i:s A'));
|
|
|
|
// Create the pie plot
|
|
$p1 = new PiePlotC($data);
|
|
// $p1->value->SetColor("navy");
|
|
$p1->SetCenter(0.35, 0.50);
|
|
|
|
$p1->SetLegends(array(
|
|
"Good (" . number_format($good_emails, 0, 0, '.') . ")",
|
|
"Tagged (" . number_format($tagged, 0, 0, '.') . ")",
|
|
"Rejected (" . number_format($reject, 0, 0, '.') . ")",
|
|
));
|
|
|
|
$graph->legend->Pos(0.10, 0.30);
|
|
$graph->legend->SetLayout(LEGEND_VERT);
|
|
|
|
$p1->SetSliceColors(array(
|
|
"green",
|
|
"orange",
|
|
"red"
|
|
));
|
|
|
|
// Create the extra text box to show scanned emails number
|
|
// $txt = new Text();
|
|
// $txt->Set("Total scanned " . number_format($scanned,0,0,'.'));
|
|
// $txt->ParagraphAlign('right');
|
|
// $txt->Show();
|
|
// $txt->SetFont(FF_VERDANA,FS_NORMAL,8);
|
|
// $txt->Pos(0.82,0.5,'center','bottom');
|
|
// $txt->SetBox('gray9','black','gray9',0,2);
|
|
// $txt->SetShadow();
|
|
// $graph->AddText($txt);
|
|
// $p1->Explode(array(0,15,15,25,15));
|
|
// Set size of pie
|
|
$p1->SetSize(0.32);
|
|
|
|
// Label font and color setup
|
|
$p1->value->SetFont(FF_VERDANA, FS_BOLD, 10);
|
|
$p1->value->SetColor('black');
|
|
|
|
// Setup the title on the center circle
|
|
$p1->midtitle->Set("Total of\n" . number_format($scanned, 0, 0, '.') . "\nscanned");
|
|
$p1->midtitle->SetFont(FF_VERDANA, FS_NORMAL, 10);
|
|
|
|
// Set color for mid circle
|
|
$p1->SetMidColor('yellow');
|
|
|
|
// Use percentage values in the legends values (This is also the default)
|
|
$p1->SetLabelType(PIE_VALUE_PER);
|
|
// $p1->SetLabelPos(0.8);
|
|
// Add plot to pie graph
|
|
$graph->Add($p1);
|
|
|
|
// .. and send the image on it's merry way to the browser
|
|
$graph->Stroke();
|
|
|
|
//}
|
|
return;
|
|
}
|
|
|
|
function msort($array, $id = "id", $sort_ascending = true)
|
|
{
|
|
$temp_array = array();
|
|
while (count($array) > 0) {
|
|
$lowest_id = 0;
|
|
$index = 0;
|
|
foreach ($array as $item) {
|
|
if (isset($item[$id])) {
|
|
if ($array[$lowest_id][$id]) {
|
|
if ($item[$id] < $array[$lowest_id][$id]) {
|
|
$lowest_id = $index;
|
|
}
|
|
}
|
|
}
|
|
$index++;
|
|
}
|
|
$temp_array[] = $array[$lowest_id];
|
|
$array = array_merge(array_slice($array, 0, $lowest_id) , array_slice($array, $lowest_id + 1));
|
|
}
|
|
if ($sort_ascending) {
|
|
return $temp_array;
|
|
} else {
|
|
return array_reverse($temp_array);
|
|
}
|
|
}
|
|
|
|
?>
|
|
|
|
|