Skip to content

Instantly share code, notes, and snippets.

@lindhe
Created December 17, 2017 12:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindhe/8627e289079e9727b3505f4a5c65cf5b to your computer and use it in GitHub Desktop.
Save lindhe/8627e289079e9727b3505f4a5c65cf5b to your computer and use it in GitHub Desktop.
Bash script to subscribe people to a mailman mailing list (at least on chs.chalmers.se)
#!/bin/bash
domain='example.com'
list='list-name'
password=''
file='./members.txt'
echo "Logging in..."
curl -v -L -X POST -j -b non-existing -c './'$list'.cookie' --data 'adminpw='$password'&admlogin=Let me in...' 'http://lists.'$domain'/mailman/admin/'$list
echo "Logged in!"
echo ""
echo "Extracting cookie bits"
key=$(cat $list.cookie | grep lists | cut -f 6)
val=$(cat $list.cookie | grep lists | cut -f 7)
echo "Key is $key"
echo "Val is $val"
echo ""
echo "Opening members management"
curl -v -L -X GET -b $key=$val -c './'$list'.cookie' 'http://lists.'$domain'/cgi-bin/mailman/admin/'$list'/members'
echo "Opened members management\n"
echo "Extracting new cookie bits"
key=$(cat $list.cookie | grep lists | cut -f 6)
val=$(cat $list.cookie | grep lists | cut -f 7)
echo "Key is $key"
echo "Val is $val"
echo ""
echo "Opening page to add member"
curl -v -L -o tokenpage.html -X GET -b $key=$val -c './'$list'.cookie' 'http://lists.'$domain'/cgi-bin/mailman/admin/'$list'/members/add'
echo "Redy to add member!"
echo ""
echo "Extracting new cookie bits"
key=$(cat $list.cookie | grep lists | cut -f 6)
val=$(cat $list.cookie | grep lists | cut -f 7)
echo "Key is $key"
echo "Val is $val"
echo ""
echo "Extracting token"
csrf=$(cat tokenpage.html | grep "csrf" | cut -d ' ' -f 4 | sed 's/.*"\(.*\)".*/\1/')
echo "csrf_token is $csrf"
echo ""
echo "Subscribing me..."
curl -v -L -X POST -b $key=$val -c './'$list'.cookie' \
-F csrf_token=$csrf \
-F subscribe_or_invite=0 \
-F send_welcome_msg_to_this_batch=0 \
-F send_notifications_to_list_owner=0 \
-F subscribees= \
-F subscribees_upload=@$file \
-F invitation= \
-F 'setmemberopts_btn=Submit Your Changes' \
'http://lists.'$domain'/cgi-bin/mailman/admin/'$list'/members/add'
echo "Subscribed!"
echo ""
echo "Logging out"
curl -v -L -X GET -b $key=$val -c './'$list'.cookie' 'http://lists.'$domain'/cgi-bin/mailman/admin/'$list'/logout'
echo "Logged out"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment