Skip to content

Instantly share code, notes, and snippets.

@tombusby
Created July 13, 2018 12:11
Show Gist options
  • Save tombusby/5929423dda5df69569c3895045e421e3 to your computer and use it in GitHub Desktop.
Save tombusby/5929423dda5df69569c3895045e421e3 to your computer and use it in GitHub Desktop.
Cypherpunks Mailing List Majordomo Perl Config Scripts
"|/usr/bin/procmail -t"
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/
MAILDIR=$HOME/Mail
#DEFAULT=$MAILDIR/received
DEFAULT=/dev/null
LOGFILE=$MAILDIR/procmail.log
WHITELIST=/home/cpunk/cypherpunks-posters
SHELL=/bin/sh
PATH=/usr/local/bin:/usr/bin:/bin
# testing: log everything
:0 c
$MAILDIR/received
# nuke mailer-daemon and [email protected] mail here so we don't loop:
:0
* (^From:.*MAILER-DAEMON@.*|^From:.*[email protected].*)
/dev/null
# keep a cache of message ids so we only send out one copy of
# each email:
:0 Wh: msgid.lock
| formail -D 1280000 msgid.cache
# grab replies to majordomo 'who' commands to the other CDRs and
# add them to the posters list:
:0
* ^Subject: Majordomo results:.*who.*
| /home/cpunk/bin/modposterlist cypherpunks-posters
# delete other Majordomo stuff:
:0
* (^Subject: Majordomo results:.*|\
^Subject: BOUNCE cypherpunks@.*)
/dev/null2
#
# check that the From: sender is a known poster
#FROM=`formail -XFrom: -r -t -xTo: | tr -d ' '`
FROM=`formail -t -xFrom: | sed -e 's/^.*<//' -e 's/>.*$//'`
# do filtering against the whitelist
:0
* ? echo "$FROM" | /home/cpunk/bin/whitelistcheck $WHITELIST
{
# testing:
#:0 c
#!root
# cc: the other CDRs:
:0 c
* !^X-Loop:.*minder.net.*
[email protected]
##:0 c
##[email protected]
## commented out 12/5/01, ssz is off the net
##:0 c
##* !^X-Loop:.*ssz.com.*
##[email protected]
# changed @algebra.com to @ak47.algebra.com on 11/28/01
# because algebra.com is MXd to ak47-stump-related.algebra.com
# which revsrse-lookups to ak47.algebra.com, so we won't
# deliver mail to them.
:0 c
* !^X-Loop:.*algebra.com.*
[email protected]
## cyberpass.net added 6/22/01
##:0 c
##* !^X-Loop:.*cyberpass.net.*
##[email protected]
:0 c
* !^X-Loop:.*ds.pro-ns.net.*
[email protected]
## CCC CDR added 9/28/01
## commented because mail bouncing 11/29/02
##:0 c
##* !^X-Loop:.*ccc.de.*
##[email protected]
:0
* !^X-Loop:.*lne.com
[email protected]
}
# attempt to post PGP-encrypted mail:
:0 EB
* .*BEGIN PGP.*
[email protected]
# attempt to post anything that looks like a reply:
:0 EB
* (^----- Original Message| .*wrote:$)
[email protected]
# attempt to post mail with hashcash:
:0 EB
* ^X-Hashcash:
[email protected]
This is the README for the filtering CDR code written by Eric Murray.
This README is dated 4/13/01.
This README (and the code) assumes that you're already familiar with
Majordomo and are running a CDR or are about to and are familiar with
how it works.
The aliases (/etc/mail/aliases) for the filtering CDR look like this:
cypherpunks: "| /home/cpunk/bin/clean_cpunks | /home/majordom/demime - |/home/majordom/wrapper resend -l cypherpunks -h yoursite.com cypherpunks-goingout"
cypherpunks-goingout: :include:/home/majordom/lists/cypherpunks
cypherpunks-request: admin, majordomo
cypherpunks-approval: admin
owner-cypherpunks: admin
cypherpunks-owner: admin
cpunks: cpunk
The code in the tar file:
src/send_subscribers isn't used.
src/cpadd is called on the command line by the admin to
add an address to the allowed posters list.
Usage: cpadd [email protected]
src/cpadd.pl does the same thing, but in perl, so it can
be setuid.
src/cpforward is also used by the admin and called from
the command line. It expects mail on stdin. The mail
that it expects is BOUNCE mail from majordomo, which contains
all the headers of the original mail in the body. It
finds the poster's address and adds that to the allowed
posters list.
src/modposterlist is what parses the replies to the Majordomo
who commands that are used to maintain the allowed posters list.
src/get_addrs is called by src/modposterlist to help with the parsing.
.procmailrc is the procmail rules file. It drives the whole thing.
.spamrulesfile is the rules file for spammaster.
src/clean_cpunks just filters the incoming mail- it gets rid
of some headers I don't like, deletes old X-loop headers, and
gets rid of the CDR in the Subject from Jim's node.
Modify to suit.
src/clean_cpunks.new does the same and looks for the
Approved: LISTMEMBER CPUNK header that some folks put in
their mail, and adds them to the posters list if they did so
and wern't on it.
Demime (http://scifi.squawk.com/demime.html)
strips mime-encoded shit from mail. I recommend using it.
Majordomo hacks:
majordomo.pl:
sub main'addr_match {
local($a1) = &main'chop_nl(shift);
local($a2) = &main'chop_nl(shift);
local($partial) = shift; # may be "undef"
print STDERR "addr_match: enter\n" if $DEBUG;
print STDERR "addr_match: comparing $a1 against $a2\n" if $DEBUG;
> # ERICM:
> # allow for wild cards (*@remailer.com) in allowed-posters lists:
> if ($a2 =~ /^\*@/) {
> $a2 =~ s/\*//;
> $a1 =~ s/^.*@/@/;
> }
This addition lets you add addreses like "*.remailer.org" to
the allowed posters list. Some remailers (i.e. hushmail)
let users pick names, or assign different named for each user.
majordomo:
I had to comment out the line that reads:
squawk("$listdir/$clean_list: uid = $uid, gid = $gid. EUID = $>, EGID = $)\n");
It's around line 450, in do_unsubscribe.
#!/usr/bin/perl
#
# clean up headers on incoming-to-list cpunks mail
#
while(<>) {
next if (/^X-Mailing-List: cypherpunks\@.*/);
next if (/^X-List-Admin: list\@.*/);
next if (/^X-Acceptable-Languages:.*/);
# get rid of incoming X-spam
next if (/^X-spam:.*/);
next if (/^X-Spam:.*/);
# reply-to in list mail is wrong.
next if (/^Reply-To:.*/);
next if (/^Reply-to:.*/);
# delete any old X-loop lines:
next if (/^X-[Ll]oop: .*/);
# delete CDR in Subject:
s/^Subject:\s*CDR:/Subject: /;
s/^Subject:\s*R[Ee]:\s*CDR:/Subject: Re: /;
s/^Subject:\s*\[cdr\]\s*/Subject: /;
s/^Subject:\s*R[Ee]:\s*\[cdr\]\s*/Subject: Re: /;
# fix Re: Re:
s/^Subject:\s*R[Ee]:\s*R[Ee]:/Subject: Re:/;
if (/^Message-[Ii][Dd]:.*/) {
if (! />\s*$/) {
# someone split the message_id!
chomp;
$messageid = $_;
next; # get the rest
}
}
if (defined $messageid) {
# print out the whole messageid
$_ =~ s/^\s+//g;
$messageid .= $_;
$_ = $messageid;
undef $messageid;
}
print $_;
}
#!/usr/bin/perl
#
# clean up headers on outgoing cpunks mail
#
$cplist = "cplist";
$cpadd = "bin/cpadd";
while(<>) {
next if (/^X-Mailing-List: cypherpunks\@.*/);
next if (/^X-List-Admin: list\@.*/);
next if (/^X-Acceptable-Languages:.*/);
# reply-to in list mail is wrong.
next if (/^Reply-To:.*/);
next if (/^Reply-to:.*/);
# delete any old X-loop lines:
next if (/^X-[Ll]oop: .*/);
# delete CDR in Subject:
s/^Subject:\s*CDR:/Subject: /;
s/^Subject:\s*R[Ee]:\s*CDR:/Subject: Re: /;
# fix Re: Re:
s/^Subject:\s*R[Ee]:\s*R[Ee]:/Subject: Re:/;
# look for Approved: LISTMEMBER CPUNK header, and add
# the sender to the posters list if they're not already there.
if (/^From: .*/) {
$from = $_;
chomp($from);
$from =~ s/^From:\s*//;
}
if (/^Approved: LISTMEMBER CPUNK/ && $from) {
&add_to_list($from);
}
print $_;
}
sub add_to_list {
my($from) = $_;
open(L,"$cplist") || die "can't open $cplist: $?\n";
while(<L>) {
chomp;
if ($_ eq $from) {
# already present, bail
return;
}
}
close(L);
system("$cpadd $from");
}
#!/usr/bin/perl
#
# clean up headers on incoming-to-list cpunks mail
#
while(<>) {
next if (/^X-Mailing-List: cypherpunks\@.*/);
next if (/^X-List-Admin: list\@.*/);
next if (/^X-Acceptable-Languages:.*/);
# get rid of incoming X-spam
next if (/^X-spam:.*/);
next if (/^X-Spam:.*/);
# reply-to in list mail is wrong.
next if (/^Reply-To:.*/);
next if (/^Reply-to:.*/);
# delete any old X-loop lines:
next if (/^X-[Ll]oop: .*/);
# delete CDR in Subject:
s/^Subject:\s*CDR:/Subject: /;
s/^Subject:\s*R[Ee]:\s*CDR:/Subject: Re: /;
s/^Subject:\s*\[cdr\]\s*/Subject: /;
# fix Re: Re:
s/^Subject:\s*R[Ee]:\s*R[Ee]:/Subject: Re:/;
print $_;
}
#!/bin/sh
cd /home/cpunk
cp cplist cplist.bak
for i in $*
do
echo "${i}" >> cplist
done
# feed it into the master list:
a="cypherpunks-posters"
# sort & uniq the old and new lists, and include a list of known remailers:
cat remailers cplist $a /home/majordom/lists/cypherpunks | sort \
| uniq > $a.tmp && chown cpunk.cool $a.tmp && chmod a+r $a.tmp && mv $a.tmp $a
#!/usr/bin/perl
chdir("/home/cpunk");
$ENV{'PATH'} = "/home/cpunk/bin:/bin:/sbin:/usr/local/bin:/usr/bin:/usr/sbin";
system("/bin/cp cplist cplist.bak");
open(CP,">>cplist") || die "can't open cplist: $!\n";
foreach (@ARGV) {
print CP "$_\n";
}
close(CP);
# feed it into the master list:
system("/bin/cat remailers cplist /home/majordom/lists/cypherpunks cypherpunks-posters | sort | uniq > cypherpunks-posters.tmp");
#system("chown cpunk.cpunk cypherpunks-posters.tmp");
system("chmod 664 cypherpunks-posters.tmp");
system("/bin/rm cypherpunks-posters; mv cypherpunks-posters.tmp cypherpunks-posters");
#!/usr/bin/perl
#
# forward BOUNCE mail to the cypherpunks list, stripping out the
# local majordomo headers
$listname = "cypherpunks";
# testing:
#$listname = "ericm";
$tmp = "/tmp/cpunk_forward.$$";
open(OUT,">$tmp") || die "can't open tmp file $tmp: $!\n";
while(<>) {
s/----- Forwarded message//;
last if (/----- End forwarded message -----/);
if (! $in_body && $got_from && /^$/) {
$in_body++;
next;
}
if (/^From:/) {
$got_from++;
}
if ($in_body) {
if (/^Message-I[Dd]/) {
$msgid = $_;
/.*\>$/ or $wrapped_msgid++;
next;
}
# process line after msgid:
if ($msgid) {
if ($wrapped_msgid) {
# msgid wrapped... unwrap it
s/^\s*//;
chomp($msgid);
print OUT "$msgid";
print OUT "$_";
undef $wrapped_msgid;
undef $msgid;
next; # already printed current line
}
else {
print OUT "$msgid";
undef $msgid;
}
}
if (/^From:/ && ! $from) {
# the first inner From:
$from = $_;
chomp($from);
$from =~ s/^From:\s*//;
$from =~ s/^.*<//;
$from =~ s/>.*$//;
$from =~ s/\(.*\)//;
}
if (/^Subject:/) {
$subject = $_;
chomp($subject);
$subject =~ s/^Subject: //;
}
s/^To: /X-Orig-To: /;
next if (/^X-spam.*/);
print OUT "To: $listname\@lne.com\n" if (/X-Orig-To/);
print OUT "$_";
next;
}
}
close OUT;
# let me edit the post:
#system("/bin/vi $tmp");
# now add the sender to the allowed-posters list:
system("/home/cpunk/bin/cpadd.pl $from");
# now send the post:
#system("(/usr/sbin/sendmail -oi -oee -f\"$from\" $listname\@lne.com < $tmp && rm $tmp)");
#!/usr/bin/perl
$log = "/home/cpunk/Mail/who.log";
while(<>) {
next if (/^$/);
if (/^From:/) { $from = $_; chomp($from); }
if (/^Date/) {$date = $_; chomp($date); }
if (/Members of list/) { $inlist++; next; }
if (/^\d*.*subscribers/) { undef $inlist; }
if ($inlist) {
next if $_ !~ (/^.*@.*\..*$/); # not an '@' addr
print $_;
$num++;
}
}
# log that we got it:
open(LOG,">>$log") || die "can't open $log: $!\n";
printf(LOG "%s %s %d\n",$from,$date,$num);
close LOG;
#!/bin/sh
# read in the response from majordomo & filter out everything but
# the addresses:
cd /home/cpunk
cat | /home/cpunk/bin/get_addrs > /tmp/list.$$
cp cypherpunks-posters cypherpunks-posters.bak
a="cypherpunks-posters"
#b="/home/majordom/lists/cypherpunks"
# sort & uniq the old and new lists, and include a list of known remailers:
cat /tmp/list.$$ $a remailers cplist $b | sort \
| uniq > $a.tmp && chown cpunk.cpunk $a.tmp && chmod 664 $a.tmp && mv $a.tmp $a \
&& rm -f /tmp/list.$$
#!/usr/bin/perl
# echo "$FROM" | egrep -i -f $WHITELIST
#
$rc=1; # failed
$file=shift || die "usage: whitelistcheck <file>";
open(FH,$file) || die "can't open $file: $?\n";
while(<FH>) {
chomp;
$pat[$num++] = $_;
}
close(FH);
while(<>)
{
chomp;
foreach $i (0 .. $num) {
if ($pat[$i] =~ /\*/) {
$t = $pat[$i];
$t =~ s/\*/\.\*/g;
$pat[$i] = $t;
}
if ($_ =~ /$pat[$i]/i) {
$rc = 0; # succeeded
print "$_\n";
last;
}
}
}
exit($rc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment