#!/usr/bin/perl use strict; use warnings; my $logfile = $ARGV[0] || "/var/amavis/amavis.log"; my $fprotdir = $ARGV[1] || "/var/virusmails"; my $virprog = $ARGV[2] || "f-prot"; my ($loc, $vir); open(LOGFILE, '<', $logfile) or die "Unable to open $logfile for reading: $!"; while ( my $line = ) { chomp $line; if ( $line =~ /Infection:/ ) { ($loc, $vir) = ( split( / /, $line ) )[0, 3]; } elsif ( $line =~ /quarantined/ ) { my ($file, $time, $month, $day) = ( split( / /, $line ) )[12, 3, 0, 2]; my $date = "$day $month $time"; print "At $date $virprog detected a virus\nfound in $loc\n"; print "Name virus: $vir\nMessage saved as: $fprotdir/$file\n"; Checkwhosi( $file ); } } close LOGFILE or die "Unable to close $logfile : $!"; print "no viri received\n" if ! $vir; sub Checkwhosi { my $file_name = shift; my $file_fqn = "$fprotdir/$file_name"; open(VIRFILE, '<', $file_fqn) or die "Unable to open $file_fqn for reading : $!"; my ($senderserv, $sserv2, %header); while ( my $line = ) { chomp $line; if ( $line =~ /Received:/ ) { ($senderserv, $sserv2) = ( split( / /, $line ) )[2,3]; $sserv2 =~ s/[(\[\]]//g; } elsif ( $line =~ /(From|To|Subject):/ ) { $header{ $1 } = ( split( / /, $line ) )[1]; } } print map{defined $header{$_} ? "$_: $header{$_}\n" : () } qw(To From Subject); print "Virus Mailserver: $senderserv\nipadres server: $sserv2\n"; print "-" x 23, "\n"; close(VIRFILE) || die "Error closing viral log file: $!"; }