9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] spamoff
@ 2003-09-01 14:54 boyd
  0 siblings, 0 replies; 3+ messages in thread
From: boyd @ 2003-09-01 14:54 UTC (permalink / raw)
  To: 9fans

#!/bin/rc

# spamoff addr mbox

# set user to be you
user=boyd
mdir=/usr/$user/lib/mail	# somewhere to put the below
allow=$mdir/allow		# addr's you'll accept mail from
audit=$mdir/audit		# audit trail
errors=$mdir/errors		# error log

myname=`{basename $0}
{
	echo $myname $*
	cat /dev/user
	echo
	lc /env
	pwd
	ls -l
	ls -l /tmp
	echo

} > $audit

fn err {
	echo $myname: $* > $errors
	exit $"*
}

fn match {
	addr=$1
	awk -v 'addr='$addr '
BEGIN {
	addr=tolower(addr)	# 822 addresses are case insensitive
	e = 1
}

tolower($0) == addr {
	e=0
	exit
}

END { exit e }
' $allow
}

fn bitch {
	addr=$1
	mbox=$2

	if (match $addr) {
		cat > $mbox
		exit
	}

	code=`{echo $myname$user$pid | md5sum}

	echo $code

	# apart from the rc here document bug we probably don't have a /tmp

	{
		echo Either you''''re a spammer or I don''''t like you or I don''''t know you.
		echo
		echo Email me this rejected message with:
		echo
		echo '	'$code
		echo
		echo in the Subject: line and I''''ll decide if I''''ll add you to my list
		echo of people I''''ll accept mail from.
	} | cat /fd/0 > $audit

	err rejected mail from $addr $code
}

#if (! test -w $errors -a -A $errors -a -L $errors) {
if (! test -w $errors -a -A $errors) {
	exit $myname:' '$errors:' existance/mode/permission problem'
}

if (! test -r $allow) {
	err $allow:' existance/permission problem'
}

switch ($#*) {
case 0
	err no args

case 1
	err args: $*

case 2
	bitch $*

case *
	err args: $*
}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] spamoff
  2003-09-26  0:58 boyd
@ 2003-09-26  2:26 ` ron minnich
  0 siblings, 0 replies; 3+ messages in thread
From: ron minnich @ 2003-09-26  2:26 UTC (permalink / raw)
  To: 9fans

my favorite part of the attachment:
//GO.SYSIN DD spamoff


I still miss the 'old' dd command, which looked so much like a DD
statement.

ron



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [9fans] spamoff
@ 2003-09-26  0:58 boyd
  2003-09-26  2:26 ` ron minnich
  0 siblings, 1 reply; 3+ messages in thread
From: boyd @ 2003-09-26  0:58 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 341 bytes --]

here is a first cut.  if you can read rc you can work it out.

just change:

    user=boyd

to be:

    user=<you>

stick it in $home/bin/rc and then:

    spamoff -c

use it at your peril.  bugs/flames to me.

btw: it assumes $home/^(lib log) exist.

bbtw: it's chucked away 1000's of spams and has been in use for a week.

[-- Attachment #2.1: Type: text/plain, Size: 314 bytes --]

The following attachment had content that we can't
prove to be harmless.  To avoid possible automatic
execution, we changed the content headers.
The original header was:

	Content-Disposition: attachment; filename=spamoff.bundle
	Content-Type: text/plain; charset="US-ASCII"
	Content-Transfer-Encoding: 7bit

[-- Attachment #2.2: spamoff.bundle.suspect --]
[-- Type: application/octet-stream, Size: 3907 bytes --]

# To unbundle, run this file
echo spamoff
sed 's/.//' >spamoff <<'//GO.SYSIN DD spamoff'
-#!/bin/rc
-
-#
-# spamoff addr mbox
-#
-# to setup: spamoff -c
-#
-
-rfork en
-
-ramfs >[2] /dev/null
-
-# set user to be you
-user=boyd
-
-lib=/usr/$user/lib/mail		# somewhere to put the below
-log=/usr/$user/log/mail
-allow=$lib/allow		# addr's you'll accept mail from
-audit=$log/audit		# audit trail
-errors=$log/errors		# error log
-rejects=$log/rejects		# list of addresses and codes
-
-upas=upas			# upas bin
-mp=/tmp/upasfs.$pid		# upas mbox file-system mount point
-ctl=$mp/ctl
-mbox=$mp/mbox/1
-
-myname=`{basename $0}
-
-# install like mail -c
-
-switch ($#*^$1) {
-case 1-c
-	flag +e
-
-	pipeto=/mail/box/$user/pipeto
-
-	{
-		echo '#!/bin/rc'
-		echo
-		echo /usr/$user/bin/rc/$myname '$*'
-	} > $pipeto
-
-	chmod +x $pipeto
-
-	for (i in $lib $log) {
-		if (! test -d $i)
-			mkdir $i
-	}
-
-	for (i in $audit $allow $errors $rejects) > $i
-
-	for (i in $audit $errors $rejects) {
-		chmod 622 $i
-		chmod +al $i
-	}
-
-	echo 'postmaster
-'$user'
-local!$user
-' > $allow
-
-	exit
-}
-
-# get $upas/fs to smash the message into manageable pieces
-mkdir $mp || exit mkdir
-msgtmp=/tmp/pipeto.$pid
-bind -ac /mail/tmp /tmp
-cat > $msgtmp
-$upas/fs -f $msgtmp -m $mp
-
-# try to cleanp the mess we have made
-fn cleanup {
-	unmount $mp
-	rm -f $mp
-	rm -f $msgtmp
-	unmount /tmp
-}
-
-# report error and give up
-fn err {
-	echo $myname: $* > $errors
-	cleanup
-	exit ''
-}
-
-# match $1 against a 'white list'
-fn match {
-	awk -v 'addr='$1 '
-BEGIN { e = 1}
-
-$0 ~ /^#.*/ || $0 == "" { next }
-
-$0 == addr {
-	e = 0
-	exit
-}
-
-END { exit e }
-' $allow
-}
-
-# see if it had been rejected, but is ok now
-fn reject {
-	awk -v 'addr='$1 -v 'code='$2 '
-BEGIN {	e = 1 }
-
-$1 == addr && $2 == code {
-	e = 0
-	exit
-}
-
-END { exit e }
-' $rejects > $audit
-}
-
-# deliver it or bitch about it to the sender
-fn bitch {
-	to=$1
-	mfile=$2
-
-	# 822 addresses are case insensitive, so go for lower case
-	addr=`{tr A-Z a-z < $mbox/replyto >[2] /dev/null}
-
-	# this had better be ok
-	if (~ $addr '')
-		err null reply address
-
-	# spammers sometimes bounce 'em back
-	if (~ $addr /dev/null)
-		err bounce from '<'$addr'>'
-
-	if (match $addr || reject $addr `{cat $mbox/subject >[2] /dev/null}) {
-		$upas/deliver $to $mbox/replyto $mfile < $mbox/raw
-		cleanup
-		exit ''
-	}
-
-	code=`{echo $myname$pid$addr | md5sum}
-
-	echo $code
-
-	{
-		echo From: $user
-		echo Subject: $user''''s $myname autoresponder
-		echo
-		echo Either you''''re a spammer or I don''''t like you or I don''''t know you.
-		echo
-		echo Email me this rejected message with exactly this code:
-		echo
-		echo '    '$code
-		echo
-		echo in the Subject: line and I''''ll decide if I''''ll add you to my list
-		echo of people I''''ll accept mail from.
-		echo
-		echo '    ---- Original Message ----'
-		echo
-		cat $mbox/raw
-
-	} | $upas/send $addr
-
-	# so we can $upas/fs it later, if necessary
-	#
-	# this is lunacy, but correct
-	#$upas/deliver $to $mbox/replyto $audit < $mbox/raw
-
-	# this is manageable, but not correct
-	$upas/deliver $to $mbox/replyto $audit < $mbox/rawheader
-
-	echo $addr $code > $rejects
-	err rejected mail from $addr $code
-}
-
-# these files had better be setup right
-
-if (! test -w $errors -a -A $errors -a -L $errors) {
-	echo $myname: $errors: existance/mode/permission problem >[1=2]
-	exit $errors
-}
-
-for (i in $audit $rejects) {
-	if (! test -w $i -a -A $i -a -L $i) {
-		err $i: existance/permission problem
-	}
-}
-
-if (! test -r $allow) {
-	err $allow: existance/permission problem
-}
-
-switch ($#*) {
-case 2
-	bitch $*
-
-case *
-	err args: $*
-}
//GO.SYSIN DD spamoff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-09-26  2:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-01 14:54 [9fans] spamoff boyd
2003-09-26  0:58 boyd
2003-09-26  2:26 ` ron minnich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).