This is a very simple script that will take your mail statistics, and display them. Optionally, you can have them thrown into a db for viewing.

For the db (if you want it), create a db. Inside of that, create a table called mailstats, using the following (in phpmyadmin, or whatever you're comfortable with)
Code:
 CREATE TABLE `mailstats` (
`date` VARCHAR( 255 ) NOT NULL ,
`total` VARCHAR( 255 ) NOT NULL ,
`rejected` VARCHAR( 255 ) NOT NULL ,
`rbl` VARCHAR( 255 ) NOT NULL ,
`relay` VARCHAR( 255 ) NOT NULL ,
`SA` VARCHAR( 255 ) NOT NULL ,
`verify` VARCHAR( 255 ) NOT NULL ,
`lookup` VARCHAR( 255 ) NOT NULL ,
`dictionary` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `date` )
) ENGINE = MYISAM CHARACTER SET latin1 COLLATE latin1_swedish_ci
This will create the necessary db, and is necessary ONLY if you're going to use the logging functions.

Now, for the php script: Save the following as whatever file you like (I use /bin/mailstats), make sure to chmod the file inside the shell:

Code:
chmod a+x /bin/mailstats
PHP Code:
#!/usr/local/bin/php
<?
//Uncomment the below line if you want to use the db portion of this
//connect_db();
print "Gathering mail stats\n";
//Make sure to change the logfiles if necessary. You should only change these two instances
$logfile="/var/log/exim_mainlog";
$rejectfile="/var/log/exim_rejectlog";
$mainacc=shell_exec("grep \"SMTP connection from\" $logfile -c");
$reject1 shell_exec("grep RBL $rejectfile -c");
$reject2 shell_exec("grep \"relay\" $rejectfile -c");
$reject3 shell_exec("grep \"score too high\" $rejectfile -c");
$reject4 shell_exec("grep \"Sender verify failed\" $rejectfile -c");
$reject5 shell_exec("grep \"host lookup did not complete\" $rejectfile -c");
$rejectotal shell_exec("grep rejected $rejectfile -c");
$dictionary shell_exec("grep \"dictionary attack\" $rejectfile -c");

print 
"Connections: $mainacc";
print 
"Rejected: $rejectotal";
print 
"RBL: $reject1";
print 
"Relay: $reject2";
print 
"SA Score: $reject3";
print 
"Sender Verify: $reject4";
print 
"Host Lookup: $reject5";
//Uncomment the below line if you want to use the db portion of this
//insert_stats($mainacc, $rejectotal,$reject1,$reject2,$reject3,$reject4,$reject5, $dictionary);
function insert_stats($mainacc,$rejected,$reject1,$reject2,$reject3,$reject4,$reject5,$dictionary)
$date=date('m-d-Y');
$query="SELECT date FROM mailstats WHERE date='$date'";
$result=mysql_query($query) or die(mysql_error());
$numrows=mysql_num_rows($result);
if (
$numrows 1)
{
$query="INSERT into mailstats VALUES('$date','$mainacc','$rejected','$reject1','$reject2','$reject3','$reject4','$reject5','$dictionary')";
$result=mysql_query($query) or die(mysql_error());
}
if (
$numrows 0)
{
$query="UPDATE mailstats SET
total='
$mainacc',
rejected='
$rejected',
rbl='
$reject1',
relay='
$reject2',
SA='
$reject3',
verify='
$reject4',
lookup='
$reject5',
dictionary='
$dictionary'
WHERE date='
$date'";
$result=mysql_query($query) or die(mysql_error());
}
}
function 
connect_db()
{
//fill out the db_name, $db_username, $db_pass fields if you want to use this
$db_name="";
$dbtype="MySQL";
$hostname="localhost";
$db_username="";
$db_password="";
$db_failure=mysql_error();
$dbh=mysql_connect ("$hostname""$db_username""$db_password") or die("DB Connection Problems");
mysql_select_db ("$db_name");
}
?>
Now, for the cron:
Code:
*/15 * * * * /bin/mailstats > /dev/null
Add that to your root crontab. This will update the db every 15 minutes. Only necessary (of course ) if you're using the db, otherwise, it's somewhat worthless.

This has been tested pretty extensively on 2 cpanel servers, no problems had. I'm in the process of developing something like this that will report on ALL domains, but that's going to take a bit more time.