Created
December 17, 2017 12:42
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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