Phpbb 3.0 edit post with curl from bash script

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
kot7k
Registered User
Posts: 4
Joined: Sat Jan 26, 2013 3:28 pm

Phpbb 3.0 edit post with curl from bash script

Post by kot7k » Wed Oct 04, 2017 2:53 pm

Hi i really didnt know where to post this, but here it is in case someone can help me.
i just wanted to make a little bash script to automatize some actions i do on my forum on a regular basis. I was perfectly able to reply to a post in my forum following this example:

Code: Select all

#!/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
However i wanted to edit my post, I found this in this webpage: http://fabianmaass.de/?p=133 The guy also says that if you want to edit a post instead of reply to it you have to change some lines to this:

Code: Select all

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
I did it but what curl returns to me is the post contanting my edited message also with the submit button on it. So it seems to fill the text but doesnt seem to click on submit button. No changes are made on my forum post. Anyone knows what i am missing? Cause reply code works, and i am also sending post=Submit in edit code too.

User avatar
AmigoJack
Registered User
Posts: 4950
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Phpbb 3.0 edit post with curl from bash script

Post by AmigoJack » Tue Oct 10, 2017 7:25 am

kot7k wrote:
Wed Oct 04, 2017 2:53 pm
is the post contanting my edited message also with the submit button on it
That is no post - that's the editor. And you also haven't said if it contains a preview or error messages.

I wonder how it works for you fine in the first place, since in both examples you don't provide any post subject. Your scripts also make nowhere sure the variables filled thru grep actually have content - how about printing this to your shell so you halfway know where things break?

Submitting an edited post on this board looks like this:

Code: Select all

POST https://www.phpbb.com/community/posting.php?mode=edit&f=0&t=0&p=0
Origin: https://www.phpbb.com
User-Agent: curl or else
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryzIv55cbiQLSUmhRM
Accept: text/html;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en;q=0.9
Cookie: phpbb3_1fh61_u=0; phpbb3_1fh61_k=; phpbb3_1fh61_sid=d3x212baccf7d9x7d5d8x283049b9d7x
with this content:

Code: Select all

addbbcode20: 100
attach_sig: on
creation_time: 1507619293
edit_post_message_checksum: 65f5fxc7fe29x552c57fx898fx8b479b
edit_post_subject_checksum: a0x97cfxc79x63cbbc5x36576a2c190d
form_token: edcx93ebx520b85ax0efe8dx892ff78722d1x270
lastclick: 1507619293
message: any content
post: Submit
show_panel: options-panel
subject: Re: the topic title
The worst thing about censorship is ███████████

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: JoshyPHP and 5 guests