');
- if ($style == 'table') {
- print('');
- print('');
-
- printf("Virus Threats last %s ",$text);
- print(' | ');
- print('
');
- printf("Emails Scanned for Virus");
- print(' | ');
- print('');
- printf("%s",number_format($scanned,0,0,'.'));
- print(' | ');
- print('
');
- print('');
- printf("Infected with Virus");
- print(' | ');
- print('');
- if ($scanned>0) printf("%s (%.2f %%)",number_format($bad,0,2,'.'), number_format(($bad/$scanned)*100,2,'.',''));
- print(' | ');
- print('
');
- }
-
- if ($linecount > 0) {
- $linecount = 0;
-
- print('');
- print('');
- if ($style == 'table') {
- print('Top Blocked Virus Threats');
- } else {
- printf("Top Spammed Emails last %s",$text);
+ // Now print out results if they exist
+ if (isset($print_list)) {
+ $sorted_list = msort($print_list, "count", false);
}
- print(' | ');
- print('
');
- print('');
- if ($style == 'table') {
- print('Name');
- } else {
- print('Email address');
- }
- print(' | ');
- print('');
- print('Count');
- print(' | ');
- print('
');
-
- foreach ($sorted_list as $item) {
-
- print('');
- printf("%s",$item['name']);
- print(' | ');
- print('');
- printf("%s",$item['count']);
- print(' | ');
- print('
');
-
- $linecount++;
-
- # Only show top 10...
- if ($linecount >= 10) {
- break;
- }
- }
- }
- print('
');
- return;
-}
+ // print_r($sorted_list);
+ print ('');
+ // This will always be table - used to have 'oldstyle'
+ if ($style == 'table') {
+ print ('');
+ print ('');
-function read_and_print_spam_log ($log_filename,$text,$style) {
+ printf("Virus Threats last %s ", $text);
+ print (' | ');
+ print ('
');
+ printf("Emails Scanned for Virus");
+ print (' | ');
+ print ('');
+ printf("%s", number_format($scanned, 0, 0, '.'));
+ print (' | ');
+ print ('
');
+ print ('');
+ printf("Infected with Virus");
+ print (' | ');
+ print ('');
+ if ($scanned > 0) printf("%s (%.2f %%)", number_format($bad, 0, 2, '.') , number_format(($bad / $scanned) * 100, 2, '.', ''));
+ print (' | ');
+ print ('
');
+ }
- if(!file_exists($log_filename) || !is_readable($log_filename) || !$fd = fopen($log_filename, "r")) {
- print('');
- print('Statistics database not found');
- print(' | ');
+ if (isset($sorted_list)) {
+ // This will print emails if there are any
+ if ($linecount > 0) {
+ $linecount = 0;
+
+ print ('');
+ print ('');
+ // Always table ??
+ if ($style == 'table') {
+ print ('Top Blocked Virus Threats');
+ } else {
+ printf("Top Spammed Emails last %s", $text);
+ }
+ print (' | ');
+ print ('
');
+ print ('');
+ // Always table ??
+ if ($style == 'table') {
+ print ('Name');
+ } else {
+ print ('Email address');
+ }
+ print (' | ');
+ print ('');
+ print ('Count');
+ print (' | ');
+ print ('
');
+
+ foreach ($sorted_list as $item) {
+
+ print ('');
+ printf("%s", $item['name']);
+ print (' | ');
+ print ('');
+ printf("%s", $item['count']);
+ print (' | ');
+ print ('
');
+
+ $linecount++;
+
+ // Only show top 10...
+ if ($linecount >= 10) {
+ break;
+ }
+ }
+ }
+ } // End isset
+ print ('
');
return;
- }
+}
- 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);
+function read_and_print_spam_log($log_filename, $text, $style)
+{
- if ($key[0] == 'SCANNED') {
- $scanned = $key[1];
- }
- if ($key[0] == 'REJECT') {
- $reject = $key[1];
- }
- if ($key[0] == 'TAGGED') {
- $tagged = $key[1];
+ if (!file_exists($log_filename) || !is_readable($log_filename) || !$fd = fopen($log_filename, "r")) {
+ print ('');
- print('');
- printf("Scanned for Spam");
- print(' | ');
- print('');
- printf("%s",number_format($scanned,0,0,'.'));
- print(' | ');
- print('
');
-
- print('');
- printf("Good");
- print(' | ');
- print('');
- $good_emails = $scanned-($reject+$tagged);
- printf("%s (%.2d %%)",number_format($good_emails,0,0,'.'),($good_emails/$scanned)*100);
- print(' | ');
- print('
');
-
-
- print('');
- printf("Rejected as Spam");
- print('');
- printf("%s (%.2d %%)",number_format($reject,0,0,'.'),($reject/$scanned)*100);
- print(' | ');
- print(' |
');
-
- print('');
- printf("Accepted but Tagged as Spam");
- print('');
- printf("%s (%.2d %%)",number_format($tagged,0,0,'.'),($tagged/$scanned)*100);
- print(' | ');
- print(' |
');
- print('
');
- print('
');
+ flock($fd, 3); // release the lock
+ fclose($fd);
- } else {
- $good_emails = $scanned-($reject+$tagged);
+ //if ($style == 'oldstyle') {
+ // print('');
+ //
+ // print('');
+ // printf("Scanned for Spam");
+ // print(' | ');
+ // print('');
+ // printf("%s",number_format($scanned,0,0,'.'));
+ // print(' | ');
+ // print('
');
+ //
+ // print('');
+ // printf("Good");
+ // print(' | ');
+ // print('');
+ // $good_emails = $scanned-($reject+$tagged);
+ // printf("%s (%.2d %%)",number_format($good_emails,0,0,'.'),($good_emails/$scanned)*100);
+ // print(' | ');
+ // print('
');
+ //
+ //
+ // print('');
+ // printf("Rejected as Spam");
+ // print('');
+ // printf("%s (%.2d %%)",number_format($reject,0,0,'.'),($reject/$scanned)*100);
+ // print(' | ');
+ // print(' |
');
+ //
+ // print('');
+ // printf("Accepted but Tagged as Spam");
+ // print('');
+ // printf("%s (%.2d %%)",number_format($tagged,0,0,'.'),($tagged/$scanned)*100);
+ // print(' | ');
+ // print(' |
');
+ // print('
');
+ // print('
');
+ //
+ //} else {
+ $good_emails = $scanned - ($reject + $tagged);
- # what if no emails went through??
+ // what if no emails went through??
if ($scanned == 0) {
- include "jpgraph/jpgraph_canvas.php";
- include "jpgraph/jpgraph_canvtools.php";
+ 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 = 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;
+ $g->Stroke();
+ return;
}
// Some data
- $data = array($reject,$tagged,$good_emails);
+ $data = array(
+ $good_emails,
+ $tagged,
+ $reject
+ );
// A new pie graph
- $graph = new PieGraph(450,260,'auto');
+ $graph = new PieGraph(450, 260, 'auto');
// Setup title
$graph->title->Set("Spam Statistics " . $text);
- $graph->title->SetFont(FF_ARIAL,FS_BOLD,14);
+ $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("Rejected (" . number_format($reject,0,0,'.') . ")" ,
- "Tagged (" . number_format($tagged,0,0,'.') . ")" ,
- "Good (" . number_format($good_emails,0,0,'.') . ")"
- ));
-
- $graph->legend->Pos(0.05,0.65);
-
- $p1->SetSliceColors(array("red","orange","green"));
-
- # 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));
+ // $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->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);
+ $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);
+ // $p1->SetLabelPos(0.8);
// Add plot to pie graph
$graph->Add($p1);
- // .. and send the image on it's marry way to the browser
+ // .. and send the image on it's merry way to the browser
$graph->Stroke();
- }
- return;
+ //}
+ 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;
- }
+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++;
}
- }
- $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);
}
- $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);
- }
}
+?>
+