1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
#!/usr/bin/perl -w
##########################################################################
# $Id: amavis,v 1.12 2004/06/21 14:59:05 kirk Exp $
##########################################################################
########################################################
# This was written and is maintained by:
# Jim O'Halloran <jim@kendle.com.au>
#
# Please send all comments, suggestions, bug reports,
# etc, to jim@kendle.com.au.
########################################################
$Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};
$CleanMsgs = 0;
$InfectedMsgs = 0;
$SpamMsgs = 0;
$BannedNames = 0;
$BadHeaders = 0;
$IntentionallyDrop = 0;
# Parse logfile
while (defined($ThisLine = <STDIN>)) {
$From = "";
$Towards = "";
$Virus = "";
$FileName = "";
$ThisLine =~ s/^\([\d-]+\) //;
while ($ThisLine =~ s/\.\.\.$//) {
chomp($ThisLine);
$NextLine = <STDIN>;
$NextLine =~ s/^\([\d-]+\) \.\.\.//;
$ThisLine .= $NextLine;
}
if ( ($ThisLine =~ /^do_ascii/)
or ($ThisLine =~ /^Found av scanner/)
or ($ThisLine =~ /^Found myself/)
or ($ThisLine =~ /^Module/)
or ($ThisLine =~ /^TIMING/)
or ($ThisLine =~ /^Checking/)
or ($ThisLine =~ /^(ESMTP|FWD|SEND) via/)
or ($ThisLine =~ /^spam_scan/)
or ($ThisLine =~ /^Not-Delivered/)
or ($ThisLine =~ /^SpamControl/)
or ($ThisLine =~ /^Net/)
or ($ThisLine =~ /^Perl/)
or ($ThisLine =~ /^ESMTP/)
or ($ThisLine =~ /^LMTP/)
or ($ThisLine =~ /^.* code[ \t]+(NOT)? loaded/)
or ($ThisLine =~ /^tempdir being removed/)
or ($ThisLine =~ /^Found primary av scanner/)
or ($ThisLine =~ /^Found \$[\S]+[\s]+at/)
or ($ThisLine =~ /^No \$[\S]+,[\s]+not using it/)
or ($ThisLine =~ /^Found secondary av scanner/)
or ($ThisLine =~ /^Using internal av scanner code/)
or ($ThisLine =~ /^mail_via_smtp/)
or ($ThisLine =~ /^local delivery: /)
or ($ThisLine =~ /^cached [a-zA-Z0-9]+ /)
or ($ThisLine =~ /^starting. amavisd at/) ) {
# We don't care about these
} elsif ($ThisLine =~ /^Passed, /) {
$CleanMsgs++;
} elsif (($FileName, $From) = ( $ThisLine =~ /^BANNED name\/type \(([^\)]+)\)\, \<([^\>]*)\>/ )) {
$BannedNames++;
if ($Detail >= 10) {
$Banned{$FileName}{$From}++;
}; # if
} elsif (($Virus, $From) = ( $ThisLine =~ /^(Virus found - quarantined|INFECTED) \(([^\)]+)\)\, [\(\<]([^\>\)]*)[\)\>]/ )) {
$InfectedMsgs++;
if ($Detail >= 5) {
$Virustypes{$Virus}++;
}; # if
if ($Detail >= 10) {
$Viruses{$Virus}{$From}++;
}; # if
} elsif (($Fromspam, $Towards) = ( $ThisLine =~ /^SPAM, [\(\<]([^\>\)]+)[\)\>] -\> [\(\<]([^\>\)]+)[\)\>]/ )) {
$SpamMsgs++;
if ($Detail >= 5) {
$Spamtypes{$Towards}++;
}; # if
if ($Detail >= 10) {
$Spams{$Towards}{$Fromspam}++;
}; # if
} elsif (($From, $Why) = ( $ThisLine =~ /^BAD HEADER from [\(\<]([^\>\)]+)[\)\>]: (.*) in message header/ )) {
$BadHeaders++;
if ($Detail >= 10) {
$Headers{$From}{$Why}++;
}; # if
} elsif ( $ThisLine =~ /^NOTICE: DSN contains VIRUS; bounce is not bouncable, mail intentionally dropped/ ) {
$IntentionallyDrop++;
$InfectedMsgs++;
} elsif ( $ThisLine =~ /^NOTICE: DSN contains BANNED NAME; bounce is not bouncable, mail intentionally dropped/ ) {
$IntentionallyDrop++;
$BannedNames++;
} elsif ( $ThisLine =~ /^NOTICE: DSN contains VIRUS & BANNED NAME; bounce is not bouncable, mail intentionally dropped/ ) {
$IntentionallyDrop++;
$BannedNames++;
$InfectedMsgs++;
} elsif ( $ThisLine =~ /^NOTICE: DSN contains VIRUS & BAD HEADER; bounce is not bouncable, mail intentionally dropped/ ) {
$IntentionallyDrop++;
$BadHeaders++;
$InfectedMsgs++;
} elsif ( $ThisLine =~ /^NOTICE: DSN contains VIRUS & BANNED NAME & BAD HEADER; bounce is not bouncable, mail intentionally dropped/ ) {
$IntentionallyDrop++;
$BadHeaders++;
$InfectedMsgs++;
$BannedNames++;
} else {
# Report any unmatched entries...
chomp($ThisLine);
$OtherList{$ThisLine}++;
} # else
} # while
#######################################################
# Output report
if ($CleanMsgs > 0) {
print "\n$CleanMsgs messages checked and passed.\n";
}; # if
if ($InfectedMsgs > 0) {
print "$InfectedMsgs virus infected messages were found.\n";
}; # if
if ($SpamMsgs > 0) {
print "$SpamMsgs spam messages were found.\n";
}; # if
if ($BannedNames > 0) {
print "$BannedNames messages rejected with banned file names.\n";
}; # if
if ($BadHeaders > 0) {
print "$BadHeaders messages with bad headers were found.\n";
}; # if
if ($IntentionallyDrop > 0) {
print "$IntentionallyDrop messages intentionally dropped (bad DSN).\n";
};
if ((keys %Viruses)) {
print "\nViruses Detected:\n";
foreach $Virus (sort keys %Viruses) {
if ($Detail < 10 && $Detail >= 5) {
print " $Virus: $Virustypes{$Virus} Times(s)\n";
} elsif ($Detail >= 10) {
$VirCount = 0;
$OutString = "";
foreach $From (sort keys %{ $Viruses{$Virus}}) {
$VirCount += $Viruses{$Virus}{$From};
$OutString .= " $From $Viruses{$Virus}{$From} Time(s)\n";
}; # foreach
print " $Virus: $VirCount Times(s) From:\n$OutString\n";
}; # if
}; # foreach
}; # if
if ((keys %Spams)) {
print "\nSpam Detected:\n";
foreach $Towards (sort keys %Spams) {
if ($Detail < 10 && $Detail >= 5) {
print " Spam to $Towards: $Spamtypes{$Towards} Times(s)\n";
} elsif ($Detail >=10) {
$SpamCount = 0;
$OutString = "";
foreach $From (sort keys %{ $Spams{$Towards}}) {
$SpamCount += $Spams{$Towards}{$From};
$OutString .= " $From $Spams{$Towards}{$From} Time(s)\n";
}; # foreach
print " Spam to $Towards: $SpamCount Times(s) From:\n$OutString\n";
}; # if
}; # foreach
}; # if
if ((keys %Headers) && $Detail >= 10) {
print "\nBad Headers Detected:\n";
foreach $From (sort keys %Headers) {
$Count = 0;
$OutString = "";
foreach $Why (sort keys %{ $Headers{$From}}) {
$Count += $Headers{$From}{$Why};
$OutString .= " $Why $Headers{$From}{$Why} Time(s)\n";
}; # foreach
print " Bad Header from $From: $Count Times(s) Reason(s):\n$OutString\n";
}; # foreach
}; # if
if (keys %Banned) {
print "\nBanned File Names:\n";
foreach $FileName (sort keys %Banned) {
$BanCount = 0;
$OutString = "";
foreach $From (sort keys %{ $Banned{$FileName}}) {
$BanCount += $Banned{$FileName}{$From};
$OutString .= " $From $Banned{$FileName}{$From} Time(s)\n";
}; # foreach
print " $FileName: $BanCount Times(s) From:\n$OutString\n";
}; # foreach
}; # if
if (keys %OtherList) {
print "\n\n**Unmatched Entries**\n";
foreach $line (sort {$OtherList{$b}<=>$OtherList{$a} } keys %OtherList) {
print " $line: $OtherList{$line} Time(s)\n";
}; # foreach
}; # if
exit(0);
# vi: shiftwidth=3 tabstop=3 et
|