Re: [PHP] mailserver logfile analyser

2005-03-03 Thread woldhekkie
thanks verry much RICHARD,

learning to program is hell for newbies.
tried vb.net, autoit,purebasic,asp and more.
Not one of them is perfect.
It seems php is easyer learning than asp, so i will stick with php. Our 
mail/webserver does both.

I deeply respect programmers. it would be nice if i could also think my 
programs.
But i am just an administrator.
One question:
A php programmer like you can program anything, but do you ? Can you make 
money with it.
Or is it just like everything else: verry difficult.

regards,

Erik

P.S. Nice music



Richard Lynch [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]
 woldhekkie wrote:
 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;

 $emails = array(); //maybe use $froms = array(); $tos = array();

 echo TABLE BORDER=3;
 echo TRTD ALIGN=\center\ From:/TDTD
 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)));

 $emails[$from]++; //maybe use $froms[$email]++;

 //Fancier version:
 $emails[$from] = isset($emails[$from]) ? $emails[$from] + 1 : 1;

   echo TRTD.$from./TD;
 }
   if(strstr($line,RCPT TO )) {
   $start=strpos($line,);
   $end=strpos($line,);

 //Same pattern as above
 $to = str_replace(,  , str_replace(,  ,
 substr($line,$start,$end-$start)));
 $emails[$to]++;

   echo TD . str_replace(,  , str_replace(,  ,
 substr($line,$start,$end-$start)))./TD;
   }
   }
   }
 echo /TR/TABLE;
 fclose($fp);
   }
 echo Totaal aantal:  $aantal BR;

 echo Top 10:table;
 arsort($emails);
 reset($emails);
 for ($i = 0; $i  10; $i++){
  list($email, $count) = each($emails);
  echo trtd align='right'$email/tdtd
 align='right'$count/td/tr\n;
 }
 echo /table;

 //If you want $froms/$tos separate, copy/paste code above and do it for 
 both

 ?

 -- 
 Like Music?
 http://l-i-e.com/artists.htm 

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



[PHP] mailserver logfile analyser

2005-03-02 Thread woldhekkie
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 TRTD ALIGN=\center\ From:/TDTD 
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 TRTD.$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