[Tutor] spamguard is cooking in the kitchen

Kirk Bailey idiot1@netzero.net
Sun, 15 Sep 2002 20:14:55 -0400


Hey gang, anyone tired of getting spam?

OK, calm down, stop yelling, stop swearing, stop throwing printouts.

Me too.
How about a Local Delivery Agent that blocks out any email identity you do not
have on your approved poster list for your account? with web forms to let you or
them add them easy, and an overriding persona non grata only you can access
which prevents naughty people from posting or adding themselves, even if they
try?

Here is a untested and very buggy first approximation at SPAMGUARD, the local
delivery agent with antispam provisions. I invite discussion.

#!/usr/local/bin/python
#
# This is spamguard V:1.0.0 COPYRIGHT 2002 by Kirk D Bailey
#
# It is part of the SPAMGUARD suite,
# which suite is also COPYRIGHT 2002 by Kirk D Bailey.
# This program is a local delivery agent, with refusal features.
# it is invoked by sendmail for local delivery of mail.
################################################################################
#           Python can be studied and aquired at http://www.python.org/ !!!
#########1#########2#########3#########4#########5#########6#########7#########8
# that line is 80 char across, try to stay within it if you can.
#
# ADMIN. AND LEGAL STUFF:
# This program is SHAREWARE; you can try it for 30 days from the date of
# installation for free. Continued use will require paying a fee of $25 one
time;
# this gets you a license for one computer. A site wide license costs $50,
# allowing unlimited installs for a single site. It is FREE for hobby use.
#
#20
# 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. In addition, you may have
# to modify it to work properly on your server's setup.
# You should contact Mr. Kirk Bailey for licensing this suite.
#
#	Kirk D Bailey
#	10163 115 ave n
#	Largo FL 33773
#	highprimate@howlermonkey.net
#30   727-393-2161 (10am-3pm EST m-f, 3-8pm sat, 12-6 pm sundays.
#
###############################################################################
#   OWNERSHIP AND PERMISSION ISSUES
#   make sure this script runs as a TRUSTED USER-
#   and NOT as root!!! You set that up in the Sendmail Config file
(sendmail.cf).
#   Make sure that a NON-priviliged user OWNS
#   this script, and that it runs as that identity!
#   Generally, this is accomplished by making sure it is owned by that user.
#40 Permission on all scripts must be 755, files as 666, and dirs as 744.
#
###############################################################################
#  RESERVED FOR FUTURE TECHNOBABBLE
#
#
#
#
#
###############################################################################
#50 LISTS WILL BOUNCE! Users must add them to the ok2post file with the web
form.
#
###############################################################################
#
#
import os, os.path, sys, string, smtp, rfc822         # MUST be invoked!
#
#           CONFIGURATION SECTION
#           =====================
# NOTE that this script is SUPPOSED to be installed in the web cgi-bin!
#60 
# ok, where am I? I just woke up!
fullpathtoscript = os.path.split(os.path.abspath(sys.argv[0]))
print fullpathtoscript	# debug code, delete later.
#
# ok, now my config file is supposed to be RIGHT HERE with me!
# So let's read the thing!
f1=open(fullpathtoscript[0]+"/spamguard.cf",'r')
#
# Tell me little file, who am I?
webdomain=string.strip(f1.readline())	#70 read the domain name
pathtopop=string.strip(f1.readline())	# read the pathto the user pop files
f1.close()
# note the path to pop files MUST end in '/'!!!!!
#

# and who is this email to?
username=sys.argv[1]
#
# receive the message and eat it alive and digest it.
fullmessage=sys.stdin				#80
#
# digest it,
Message = rfc822.Message(fullmessage)	# read the incoming message in.
#
# then extract the From: field contents
from = string.strip(Message['From'])	# Extract the sender's from field.
#
# each *local* user has a file which email is appended to, and a dir where
# personal files are stored, which in FreeBSD is /usr/home/(username).
#90 that dir is where their ok2post and nongrata files are stored.
#
# open the ok2post file
f1=open("/usr/home/"+ username+'/'+'ok2post','r') # open the approved posters,
ok2post=f1.readlines()					  # read in the complete file,
f1.close()							  # and close the file
#
# same thing now for the nongrata persona file.
f1=open("usr/home/"+username+'/'+nongrata',r,)	# open the unwelcome poster file,	
nongrata=f1.readlines()					# read in all the banned persons,
f1.close()							#100 and close the file
#
if from in nongrata:
	sys.exit()			# don't even bother with it, just exit. They are an unperson.
# No replys, no bounces, no more mess or wasted clock cycles, BOOM, they're
gone.
#
if from in ok2post:		# if they are authorized, just deliver the mail!
	f1=open(pathtopopfile+username,'a')				# open the user's mailbox file,
	f1.write(fullmessage)						# write the entire message to it,
	f1.close()								# then close the mailbox
	sys.exit()								#110 and go back to sleep.
else:					# we do this block for not yet authorized posters
	msg=msg+"To: "+ from+"\n"					# Reply to the professed sender,
	msg=msg+'From: critter@'+localhost+"\n"			# with a from which will EAT bounces.
	msg=msg + "Subject: Unauthorized posting to account:" +  + "\n"	# by feeding
them to /dev/nul !
	msg=msg + "X-Loop: postmaster@"+ domainname + "\n"	# Breaks mail loops, good
idea really
	msg=msg + "X-spamfilter: SPAMGUARD V:1.0.0" + CRLF	# Shameless self promotion
	msg=msg + "Reply-To: postmaster@"+ localhost +"\n"	# to help REAL senders.
	msg=msg + """
To whom it may concern;
Recently, someone using this account tried to send a message to \" """ +
username + "@" + localhost + """.
It was never delivered, and has been destroyed. Here is why.

This site uses SPAMGUARD to intercept unauthorized messages. The
INTENT is to stop spam from ever landing in the mailbox. ANY message
not coming from an approved source is deleted. An unknown sender is
simply replied to with this letter. PERSONA NON GRATA don't even get
this much, their letter is simply destroyed, with no reply. As you got
this letter, your email address does not currently appear on the persona
non grata list.

WHY SPAMGUARD?
SPAM is Unsolicited Bulk Email (UBE, or junk Email), and is a growing
problem for the internet. It is generally dishonest to some degree,
unsubscribe features in it not only often do not work, but the submitted
email address being unsubscribed tends to be sold to others later!

Worse, the accounts used to send these things are usually throwaway
accounts, and are often already deleted by the time you get around to
firing off a testy complaint letter to the source. Worst of all, it is
tying up bandwidth, mailbox storage, and processor time all across the
net- spam is a form of distributed theft of service. Therefore, we are
forced in self defense to resort to strong measures to resist this
tidal wave of unpermissioned advertising. The management here has
chosen to employ spamguard to block unauthorized transmissions to this
account. We apologize for any inconvience this causes you.

HOW DOES IT WORK?
Most spam is sent by a computer program in a mass mailing, and replies like
this are almost never seen by a real person, let alone acted upon. Spamguard
feeds unauthorized mail to the trash heap, and sends off this letter explaining
what is happening and what to do about it. The letter goes to the address shown
in the letter someone tried to send here.

If the sending address declared in the mail is bogus, it bounces  back to us
at a specially prepared alias, which feeds directly into that trash heap- we
call it '/dev/nul'. Less processor time, and NO human time.

We considered using a bogus top level domain name (the part after the '.',
such as yahoo.foo, but as we are critical of fraud, it is somewhat
hypocritical to employ it, even for a good cause). This would have caused it to
stay in the sending network and not tie up bandwidth, but we like to stay above
the spammer's moral level.

Therefore, this feature locks out 99% of all spam. With our persona non grata
features, a user may place a real person who is annoying on a refuse list, and
that
should handle the other 1%; Goodbye spam! :-)

HOW DO I BECOME AUTHORIZED?
To become authorized to post to this account, either the account owner must go
to a web page and place your address on the list, or you must go to that page
and place your address on the list. SPAMBOTS currently cannot do this. When the
rats CAN, we will invent a better raptrap.

To become authorized to send to this account, please click on this link:
    """ + 'http://www.'+localhost+'/cgi-bin/spamguard1.py?' + username + """

fill in your email address EXACTLY AS IT APPEARS HERE:
        """ + from + """
        
a mouse copy would be a good idea. Then click [SUBMIT].

Unless you are on the persona non grata list, you will be added to the ok2post
list, and thereafter your may send email to this account normally. IF YOU ARE
on that non grata list, all hope is lost, but at least the results page will
declare this fact to you.


Respectfully,
             The Postmaster at """+ localhost + "\n\n"
#190
#
# 
#
#
#
#
to_addr=from					# set up the envlope data TO:
from_addr='critter@'+localhost		# and FROM:
server = smtplib.SMTP('localhost')		# you MIGHT want to comment this out; Your
Milage May Vary.
server.sendmail(from_addr, to_addr, msg)	#200 send envlope and msg!
server.quit()					# then close the connection.
#
# end of program.


-- 

end

Respectfully,
             Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                           +--------+
-------------------------------------------
Introducing NetZero Long Distance
Unlimited Long Distance only $29.95/ month!
Sign Up Today! www.netzerolongdistance.com