#!/usr/bin/perl -w ##################################################### # Copyright (c) 2006 by Web Experts Co.,Ltd. # WebSite: http://www.rvskin.com # # This program is free software. You can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License. ##################################################### use strict; use POSIX; my($option); # 0 means todays, 1 means yesterday, 2 means the past 2 days my($dayOffset); if(defined($ARGV[0])) { $dayOffset = int($ARGV[0]); } else { $dayOffset = '1'; } # Usually exim_mainlog will keep stat no more than 7 days. # You may needs to change the exim_mainlog to exim_mainlog.1 if you want to get the statistitcs for the last week my($eximMainLogPath); $eximMainLogPath = '/var/log/exim_mainlog'; if($ARGV[1]) { $eximMainLogPath = $ARGV[1]; if ($eximMainLogPath!~/\.(\d)\.gz$/ && $eximMainLogPath!~/\.(\d)$/) { print "Exim mainlog must end with .NUMBER.gz or .NUMBER \n"; print "such as /var/log/exim_mainlog.1.gz or /var/log/exim_mainlog.1\n"; exit; } chdir("/var/log"); $eximMainLogPath =~s/\.gz//; if ($eximMainLogPath=~/\.(\d)$/ && -f "${eximMainLogPath}.gz") { if (-f $eximMainLogPath) { system("rm $eximMainLogPath"); } system("gunzip -f ${eximMainLogPath}.gz"); } } # Histogram divisions per hour. The default is 0, and 0 suppresses histograms. # Valid values are: 0, 1, 2, 3, 5, 10, 15, 20, 30 or 60. my($showHistogram) = '0'; $option .= "-pattern 'Total mail blocked:..................................................................................' /'Host is ratelimited|JunkMail rejected|sender verify fail for|is blocked|SPF: |HELO required before MAIL|Bad HELO|Invalid HELO name|REJECTED - Interface|unknown user:|If you meant to send this file|virus or other harmful|Spam score too high'/ "; # Default cpanel setting $option .= "-pattern 'Verify sender at SMTP time:..........................................................................' '/sender verify fail for/' "; # Custom setting suggested by rvskin.com $option .= "-pattern 'Spam mail blocked by manual blacklist sender at the SMTP time:.......................................' '/Sender .* is blocked/' "; $option .= "-pattern 'Spam mail blocked by manual blacklist host address at the SMTP time:.................................' '/Host .* is blocked/' "; $option .= "-pattern 'Spam mail blocked by invalid HELO (HELO required before MAIL) at the SMTP time:.............' '/HELO required before MAIL/' "; $option .= "-pattern 'Spam mail blocked by invalid HELO (forged HELO) at the SMTP time:..................................' '/Bad HELO/' "; $option .= "-pattern 'Spam mail blocked by invalid HELO (host is not FQDN RFC2821 4.1.1.1 or IP RFC2821 4.1.3) at the SMTP time:...' '/Invalid HELO name/' "; $option .= "-pattern 'Spam mail blocked by invalid HELO (Interface is my IP address) at the SMTP time:.............' '/REJECTED - Interface/' "; $option .= "-pattern 'Spam mail blocked by ratelimite auto blacklist at the SMTP time:.....................................' '/Host is ratelimited/' "; $option .= "-pattern 'Spam mail blocked by setting default address to :fail: at the SMTP time:.............................' '/unknown user:/' "; $option .= "-pattern 'Spam mail blocked by RBL at the SMTP time:...........................................................' '/JunkMail rejected/' "; $option .= "-pattern 'Spam mail blocked by SPF verify failed at the SMTP time:.................................' '/SPF: /' "; $option .= "-pattern 'Spam mail blocked by illegal File extension at the SMTP time and discarded after recieving email:....' '/If you meant to send this file/' "; $option .= "-pattern 'Spam mail blocked by SA at the SMTP time or discarded after recieving email:.........................' '/Spam score too high/' "; $option .= "-pattern 'Spam mail discared by SA high score (12-15) after recieving email:...................................' '/discarded: Spam score/' "; $option .= "-pattern 'Spam mail blocked by virus scanner at the SMTP time or discarded after recieving email:..............' '/virus or other harmful/' "; # Don't display error information. $option .= '-ne '; # Don't display relaying information. $option .= '-nr '; # Don't display transport information $option .= '-nt '; # Don't display top sources/destination $option .= '-t0 '; # Don't display queue information $option .= '-q0 '; #=========Don't change lines below =================# $option .= "-h$showHistogram "; my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime(); my $timestamp = mktime ($second, $minute, $hour, $dayOfMonth - $dayOffset, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings); ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime($timestamp); my $year = 1900 + $yearOffset; $month = $month +1; if ($month < 10) { $month = '0' . $month; } if ($dayOfMonth < 10) { $dayOfMonth = '0' . $dayOfMonth; } my($dateFormat) = "${year}-${month}-${dayOfMonth}"; # Create the exim_mainlog.day if(-f $eximMainLogPath) { system("grep $dateFormat $eximMainLogPath > /var/log/exim_mainlog.$dateFormat"); my $eximStats = findEximStats(); system("$eximStats $option /var/log/exim_mainlog.$dateFormat"); unlink("/var/log/exim_mainlog.$dateFormat"); } else { print "Cannot find $eximMainLogPath \n"; } sub findEximStats { my ($eximStatsPath); $eximStatsPath = `which eximstats`; chomp($eximStatsPath); if(!-f $eximStatsPath || !$eximStatsPath) { if (-e "/usr/sbin/eximstats") { $eximStatsPath = "/usr/sbin/eximstats"; } elsif (-e "/usr/local/bin/eximstats") { $eximStatsPath = "/usr/local/bin/eximstats"; } elsif (-e "/usr/bin/eximstats") { $eximStatsPath = "/usr/bin/eximstats"; } elsif (-e "/bin/eximstats") { $eximStatsPath = "/bin/eximstats"; } } if(!-f $eximStatsPath) { $eximStatsPath = 'eximstats'; } return $eximStatsPath; } 1;