#!/usr/bin/perl $version='$Id: me.pl,v 1.1 2002/03/22 02:01:04 torh Exp torh $ '; ## ## manual entry ## ## (c) th@bogus.net; this is probably a bad idea ## ## $|=1; ## $SPAMMERS="/etc/exim/.spammers"; $SIG{'INT'} = "CleanExit"; $SIG{'QUIT'} = "CleanExit"; $run=1; print "Commands:\n"; print "---------\n"; print "R:
-- remove blacklisting\n"; print "B: -- permanent blacklist\n"; print " -- temporary blacklist\n"; print "do -- generate exim blacklist\n"; print "list -- list current entries\n\n"; print "quit -- quit\n\n"; print "-----------------------------------\n"; print "Please enter addresses, one per line.\n\n"; while($run) { print "me> "; while(<>) { if(/^R:(\S+\@\S+)/){ dbmopen(%spam,$SPAMMERS,0666); if($spam{$1}) { $spam{$1}=0; print "removed: '$1'"; } else { print "error: '$1' not found\n"; } dbmclose(%spam); last; } if(/^B:(\S+\@\S+)/) { print "Permanent blacklist: $1\n"; dbmopen(%spam,$SPAMMERS,0666); $spam{$1}=-666; dbmclose(%spam); last; } if(/^(\S+\@\S+)/) { print "Temporary blacklist: $1\n"; dbmopen(%spam,$SPAMMERS,0666); $spam{$1}=time(); dbmclose(%spam); last; } if(/^do\s*$/) { GenerateList(); last; } if(/^list\s*$/) { List(); last; } if(/^quit\s*$/) { $run=0; last; } } } exit(1); sub CleanExit { print STDERR "Cleaning up ...\n"; dbmclose(%spam); exit(0); } sub GenerateList { print "generating blacklist.."; dbmopen(%spam,$SPAMMERS,0666); my($tmp)=TmpFile($TMPDIR); open(OUT,">$tmp") || die "Could not open temp file '$tmp': !$\n"; if($DEBUG) {print "DEBUG: created temp file $tmp\n";} foreach $key (keys %spam) { if($DEBUG) {print "$key : $spam{$key}";} if($spam{$key}>0 || ($spam{$key}==-666)) { print OUT "$key:black\n"; if($DEBUG) {print " (added to blacklist)";} } if($DEBUG) {print "\n";} } close(OUT); dbmclose(%spam); ## safe enough? system("mv $tmp /etc/exim/blacklist"); print "done\n"; } sub List { print "Currently in the spammers database:\n"; print "-----------------------------------\n"; dbmopen(%spam,$SPAMMERS,0666); my($c) = 0; foreach $key (keys %spam) { print "$key : $spam{$key}\n"; $c++; } print "Total: $c\n"; dbmclose(%spam); } ## TmpFile; create a temporary file (input is dir, returns filename); ## sub TmpFile { my($dir,$url)=@_; my($adr) = "ef"; ## generate random string and append to main part ## my($tfile)=$adr."_".RandChars(); ## make sure the filename doesn't exist ## $tfile=$adr."_".RandChars() while(-e "$dir/$tfile"); open(OUT,">$dir/$tfile");close(OUT); if($DEBUG>2) {print "DEBUG: tempdir is \'$dir\' , file is $tfile\n";} return($dir."/".$tfile); } ## RandChars; generates a string of 10 pseudorandom characters ## sub RandChars { my($a,$c,$i); for($i=0;$i<10;$i++) { if(rand(100)<50) {$a=65;} else {$a=97;} $c .= chr(rand(26)+$a); } return($c); }