#!/usr/bin/perl # ------------------------------------------------------------------- # # blacklist2access.pl - Download domain blacklists and convert into a # sendmail access file. # # ses0s, Wed Mar 17 17:10:29 PST 2004 # ------------------------------------------------------------------- # use strict; my $VERSION = '0.1'; # ------------------------------------------------------------------- # # Edit these configuration options. # ------------------------------------------------------------------- # my $TMP_DOWNLOAD = "/tmp/blacklist2access.tmp"; my %BLACKLISTS = ( "JOEWEIN" => [ "http://www.joewein.de/sw/blacklist/dom-bl.txt", "/usr/local/etc/mail/access.JOEWEIN", "http://www.joewein.de/sw/blacklist.htm"], "TEMPLATE" => [ "blacklist_url", "ACCESS FILENAME", "ERROR blacklist_url"] ); my $FETCH_COMMAND = "/usr/bin/fetch -o"; #my $FETCH_COMMAND = "/usr/local/bin/wget -O"; ### prefer wget? # ------------------------------------------------------------------- # # You probably don't need to edit stuff below here. # ------------------------------------------------------------------- # $ENV{'HTTP_USER_AGENT'} = "blacklist2access.pl $VERSION"; for my $listname (keys %BLACKLISTS) { $listname eq 'TEMPLATE' and next; print "blacklist: $listname\n"; my ($blacklist_url, $access_file, $error_url) = @{$BLACKLISTS{$listname}}; # print "Parameters: ($blacklist_url, $access_file, $error_url)\n"; my $new_access_file = $access_file . ".new"; # make sure that multiple instances are not running (-M $TMP_DOWNLOAD > 1) and unlink $TMP_DOWNLOAD; # recover after a day if (-f $TMP_DOWNLOAD) { print "Warning! $TMP_DOWNLOAD is already kicking around your computer.\n"; print "Delete $TMP_DOWNLOAD and verify $0 is not already running.\n"; exit; # hmmm... } print "Let's get the blacklist from $blacklist_url\n" unless -f $access_file; -f $new_access_file and unlink $new_access_file; `$FETCH_COMMAND $TMP_DOWNLOAD $blacklist_url`; unless (-f $TMP_DOWNLOAD and -s $TMP_DOWNLOAD > 0) { unlink $TMP_DOWNLOAD; die "$0 failed to fetch $blacklist_url\n"; } open RAW, "<${TMP_DOWNLOAD}" or die "$0 could not open input: $!\n"; open FORMATTED, ">${new_access_file}" or die "$0 could not open output: $!\n"; my $line = 0; while () { $line++; s/[\012\015]+//; # strip DOS line endings if (/^[a-z0-9\-]{1,63}(\.[a-z0-9\-]{1,63})?\.[a-z]{2,4}$/) { # make sure we don't accept any old garbage print FORMATTED "$_\t550 \" $_ blocked, $error_url \"\n"; } else { print STDERR "Can't validate hostname on line $line of $TMP_DOWNLOAD\n"; print STDERR "$line: $_\n"; } } close FORMATTED; close RAW; -f $TMP_DOWNLOAD and unlink $TMP_DOWNLOAD; rename $new_access_file, $access_file; } __END__ I have serveral 'access.*' files and lump them together with mkaccessfile.csh The access.junk is a temporary file which keeps sendmail from tripping up. : mkaccessfile.csh : #!/bin/csh cd /usr/local/etc/mail cat access.MANUAL access.JOEWEIN access.RAPERS > access.source /usr/sbin/makemap hash access.junk < access.source mv access.junk.db access.db