mailserver logfile analyser

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Our mailserver writes a logfile every day, but it takes hours to analyse it 
manualy.

I (newby) am trying to write a php script that reads the the logfile line by 
line and try to get a top 50 of spammers/clients that mail too much...

I can get line by line all information like email-adres, from , to , bytes 
send , but how to store it in a array ?
If a line is read and the emailadres already pressent in the array, it 
should not ad this emailadress again, but add a counter +1

In the end i want an array containing all emailadreses and how often they 
were counted.

This is how far i get: (sorry, it is in Dutch)
It shows all from and to emailadresses. Not bad for a newby, but it took one 
week to do.....

<?php
$fp="";$line="";$aantal=0;

echo "<TABLE BORDER=3>";
echo "<TR><TD ALIGN=\"center\"> From:</TD><TD 
ALIGN=\"center\">To:</TD></TR>";
if($fp = fopen("C:\smtp\SMTP-Activity-050226.log","r")) {
    while (!feof ($fp)) {
       $line = fgets($fp, 4096);
       if(strstr($line,"SMTP-IN")) {
          if(strstr($line,"MAIL FROM" )) {
          $aantal++;
          $start=strpos($line,"<");
          $end=strpos($line,">");
          $from=str_replace(">", " ", str_replace("<", " ", 
substr($line,$start,$end-$start)));
          echo "<TR><TD>".$from."</TD>";
                    }
          if(strstr($line,"RCPT TO" )) {
          $start=strpos($line,"<");
          $end=strpos($line,">");
          echo "<TD>" . str_replace(">", " ", str_replace("<", " ", 
substr($line,$start,$end-$start)))."</TD>";
          }
          }
          }
echo "</TR></TABLE>";
fclose($fp);
          }
echo "Totaal aantal:  $aantal <BR>";
?> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux