Skip to content

Instantly share code, notes, and snippets.

@johnd0e
Created February 4, 2025 00:28
Show Gist options
  • Save johnd0e/c6e6b987ecc8d4cf196e12ec7247be88 to your computer and use it in GitHub Desktop.
Save johnd0e/c6e6b987ecc8d4cf196e12ec7247be88 to your computer and use it in GitHub Desktop.
Update phpBB 3 forum post, replacing it's content with specified file
#!/bin/bash
# Script Name: update_post.sh
# Author: John Doe
# Date: 2025-02-04
# Description: Update phpBB 3 forum post, replacing it's content with specified file
set -o errexit
set -o nounset
set -o pipefail
USERNAME="John Doe"
PASSWORD="123456"
POST_ID=178068
FILE="new_content.md"
HOST="https://forum.farmanager.com"
LOGIN_URL="$HOST/ucp.php?mode=login"
POST_URL="$HOST/posting.php?mode=edit&p=$POST_ID"
extract_value() {
echo $OUTPUT | sed -nE "s/.*name=\"$1\"[^>]* value=\"([^\"]*)\".*/\1/p"
}
#retrieve cookies
OUTPUT=$(curl -s "$LOGIN_URL")
curl -s $LOGIN_URL -c cookies.txt \
-d "username=$USERNAME" \
-d "password=$PASSWORD" \
-d "autologin=on" \
-d "creation_time=$(extract_value creation_time)" \
-d "form_token=$(extract_value form_token)" \
-d "sid=$(extract_value sid)" \
-d "login=Login" \
| grep 'class="error"' || true
case "$(sed -n 's/.*phpbb3_sxb2q_u\t\([^\t]*\).*/\1/p' cookies.txt)" in
1)
exit 1;;
"")
exit 1;;
esac
#get necessary posting information
OUTPUT=$(curl -s $POST_URL -b cookies.txt)
#post the message
echo Posting...
sleep 1 #otherwise fails
STATUS_LINE=$(
curl $POST_URL -sib cookies.txt \
-d "subject=$(extract_value subject)" \
--data-urlencode "message@$FILE" \
-d "edit_post_message_checksum=$(extract_value edit_post_message_checksum)" \
-d "edit_post_subject_checksum=$(extract_value edit_post_subject_checksum)" \
-d "post=Submit" \
-d "no_edit_log=on" \
-d "creation_time=$(extract_value creation_time)" \
-d "form_token=$(extract_value form_token)" \
| head -n 1)
if [[ "$STATUS_LINE" == *302* ]]; then
echo Done.
else
echo Oops!
fi
#cleanup
rm cookies.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment