Bash script to post/edit phpbb forum posts
If anyone has the desire to automate forum posts for whatever reasons, here is a bash script that will do:
#!/bin/bash
LOGINURL="http://.../ucp.php?mode=login"
POSTURL="http://.../posting.php?mode=reply&f=xx&t=xx"
USERNAME="..."
PASSWORD="..."
#retrieve cookies
curl -s -d "username=$USERNAME" \
        -d "password=$PASSWORD" \
        -d "login=Login" $LOGINURL -c cookies.txt
#get necessary posting information
curl -s $POSTURL -b cookies.txt -o "post.html"
#yes - this could be improved
postid=$(grep 'topic_cur_post_id' post.html | cut -d'"' -f6)
lastclick=$(grep 'lastclick' post.html | cut -d'"' -f12)
creationtime=$(grep 'creation_time' post.html | cut -d'"' -f6)
formtoken=$(grep 'form_token' post.html | cut -d'"' -f6)
POST="whatever you want to post...."
#wait some seconds -- won't work without
echo "waiting 10 seconds..." && sleep 10
#post your message
curl --data-urlencode "message=$POST" \
     -d "topic_cur_post_id=$postid" \
     -d "lastclick=$lastclick" \
     -d "creation_time=$creationtime" \
     -d "form_token=$formtoken" \
     -d "post=Submit" $POSTURL -b cookies.txt
#cleanup
rm cookies.txt
rm post.html
if you want to edit a post, you can skip the post_id:
lastclick=$(grep 'lastclick' post.html | cut -d'"' -f6)
creationtime=$(grep 'creation_time' post.html | cut -d'"' -f6)
formtoken=$(grep 'form_token' post.html | cut -d'"' -f6)
curl --data-urlencode "message=$POST" \
     --data-urlencode "edit_reason=$EDIT_REASON" \
     -d "lastclick=$lastclick"  \
     -d "creation_time=$creationtime" \
     -d "form_token=$formtoken" \
     -d "post=Submit" $EDITURL -b cookies.txt
			You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.
 
								 
							 
					
Comments are closed.