#!/usr/bin/perl -w #pl-SaPd 0.1j - 07/18/2001 #SMTP after POP Daemon for Sendmail/Qpoppper #copyright (C) 2001 by Chris (rc@networkz.ch) #This program is free software; you can redistribute it and/or #modify it under the terms of the GNU General Public License #as published by the Free Software Foundation; either version 2 #of the License, or (at your option) any later version. #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. #settings #check logfile every n seconds $timeout="5"; #logfile location $logfile="/var/log/qpopper" ; #addresses are vaild for n seconds (3600 = 1 hour) $seconds_valid=7200; #after n x $timeout, acccess database is recreated #(this is used to purge old addresses) $max_runs=360; $current_run=358; #location of files $temp_list="/tmp/pl-SaPd.map"; $access_db="/etc/mail/access.db"; #let this address always relay $always_relay="127"; #now the fun part... while () { $check1=`ls -l $logfile` ; sleep $timeout ; $current_run++; #print "$current_run \n"; $check2=`ls -l $logfile` ; if ($current_run == $max_runs){ $check2="time to update list"; $current_run=1; } if ($check1 ne $check2){ push @validarray, $always_relay; #routine to get valid ip's from logfile #print "searching log for valids \n"; #open(LOGFILE, "$logfile"); open(LOGFILE, "tail -n 20 $logfile |") || die "cannot fork: $!" ; $current_time=time; while () { #print ; $test=grep(/Stats/, $_); if ($test eq "1") { #split to get date and address @el=split; $month=$el[0]; $day=$el[1]; $timestring=$el[2]; $year=$el[3]; $hname=$el[11]; $ip=$el[12]; @timearray=split(/:/,$timestring); $hour=$timearray[0]; $minute=$timearray[1]; #calculate unix timestamp $pop3_time=`date --date "$month $day $hour:$minute $year" +%s`; chomp $pop3_time; $diff=$current_time - $pop3_time; #generate an array with unique, valid values if ($diff < $seconds_valid){ #see if hname/ip is already in list $test_if_unique=grep(/$ip|$hname/, @validarray); if ($test_if_unique < 1 ){ push @validarray, $ip, $hname; } } } }#end of routine to get valid ip's from logfile close LOGFILE; #write list to generate db $cmd=`rm -f $temp_list`; for (@validarray){ $cmd=`echo $_ RELAY >> $temp_list`; } $make=`makemap hash $access_db < $temp_list`; $logger=`logger -t pl-SaPd[$$] -p mail.notice DB rebuildt`; undef @validarray; undef $make; undef $logger; }#end if (check eq check) }#end main while