#!/usr/bin/perl #FILE # $Id: notify.pl 2 2005-11-13 01:37:02Z ggw $ # notify.pl #PURPOSE # Customized per ISP notification message if spam was sent to # the spam-isolation server. Only one message should be sent every # 24 hours. #LICENSE # GPL. # Original work by Nicolas Aimetti for unixservice.com 11/2003 # Derivative work done by Gary Wallis 12/2003 for distribution # with mysqlSendmail 1.2 #NOTES # mysqlSendmail 1.2 now can handle and automate...all it needs is this # notifier.pl called correctly by .procmailrc and in the right place # and the message customized for your ISP. See CHANGE below... # use strict ; use POSIX qw(strftime); #proceso los parametros de la linea de comandos. #returns 1 if the last date of a spam notice > 24 hrs or 1 day etc. sub check_date { my $d1 = $_[0]; #actual my $d2 = $_[1]; #guardada my @ldate1; my @ldate2; @ldate1 = split(/-/,$d1); @ldate2 = split(/-/,$d2); if($ldate1[0] > $ldate2[0] ){ return 1; }elsif( $ldate1[1] > $ldate2[1] ){ return 1; }elsif( $ldate1[2] > $ldate2[2] ){ return 1; # }elsif( $ldate1[3] > $ldate2[3] ){ # return 1; # }elsif( $ldate1[4] > $ldate2[4] ){ # return 1; }else{ return 0; } return 1; } ## #variables ## my $arg; my $date; my $user; my $db_file; my $force=0; my %users; ## #proceso los argumentos ## while ( $arg = shift @ARGV){ if ( $arg =~ /^-(.*)/ ){ if( $1 eq "u"){ $user = shift @ARGV; }elsif( $1 eq "d" ){ $db_file = shift @ARGV; }elsif($1 eq "f"){ $force=1; }else{ die "invalid option: -- ",$1, "\n"; } }else{ die localtime().": invalid options\n"; } } ## # errors check ## if ( $db_file eq ""){ die localtime(). ":you must suply -d database-file option\n"; } if( $user eq ""){ die localtime().": you must suply user\n"; } ## # check date proces ## dbmopen(%users,$db_file,0664) || die localtime().": $user can't dbmopen: $!\n"; $date= join('-',(localtime())[5,4,3,2,1]); if ( check_date($date,$users{$user}) || $force ){ $users{$user} = $date; my $cDate = localtime(); my $cDate2 = strftime "%a, %d %b %Y %T",localtime; #maybe we should add a pid here also jic. my $id_left = time() . ".JuIL012Afg932"; print STDERR "$user received suspicious mail at $cDate2 (configured to make just one report by day).\n"; #log info #CHANGE this for your setup print < Date: $cDate2 -0600 From: Spam Isolation System Message-Id: <$id_left\@isp.net> To: $user\@server2.isp.net Subject: You have received suspicious mail You have recieved this email because the isp.net anti-spam system has marked a recently recieved message as spam or has found it to contain a virus. Please follow the link below to view your isolated/quarantined mail. http://server2.isp.net/webmail please use your usual login and passwd. Regards, support\@isp.net ENDL dbmclose(%users) || die "can't close db: $!"; }