#!/usr/bin/perl # auto spam blocker using rblsmtpd - April 27, 2001 # Copyright 2001 Ben Livingston # Released under the GNU General Public License Version 2 # Viewable online at http://www.gnu.org/copyleft/gpl.html # This is intended to read an email on stdin and add an entry # in the Qmail tcp.smtp file to block the last received-from # server. You will need to write a quick shell script to run # the tcprules program. (This program calls that script.) $date = time; $tcp_smtp = "/var/qmail/alias/tcp.smtp"; $from = "Spam Blocker "; $to = "support\@localhost"; while () { if (/^From /) { $x=1; $y=1; } if (($x) && (/^Received: from /)) { /\((.*@)?([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\)$/; $ip_line = $_; $ip = $2; undef $x; } elsif (($y) && (/^Subject: /)) { $subject=$'; undef $y; } } if ($ip) { $host = `host $ip`; `echo -e \"From: $from\nTo: $to\nSubject: Spam filter added\n\nIP: $ip\n\nHost: $host\n$ip_line\nSubject: $subject" | sendmail -t`; `echo "$ip:allow,ADD_DATE=\\"$date\\",RBLSMTPD=\\"We are denying mail from your ip address. Reason: spam.\\"" >> $tcp_smtp`; `/var/qmail/bin/update_rules`; }