set_phpbb_html_homepage.sh 1.21 KB
Newer Older
Lucas Cimon's avatar
Lucas Cimon committed
1
#!/bin/bash
2
# Enabling Bash strict mode:
Lucas Cimon's avatar
Lucas Cimon committed
3
set -o errexit -o nounset -o pipefail
4
urlencode () {  # Bash function to perform URLencoding on stdin
Lucas Cimon's avatar
Lucas Cimon committed
5
    python3 -c 'import sys; from urllib.parse import quote_plus; sys.stdout.writelines([quote_plus(line) for line in sys.stdin])'
Lucas Cimon's avatar
Lucas Cimon committed
6
}
7
# Authenticating & storing the sid cookie in a file:
Lucas Cimon's avatar
Lucas Cimon committed
8
curl -Ls --fail -c cookies.txt https://laubergedesreveurs.forumactif.com/login --data-raw "username=${USERNAME:?}&password=${PASSWORD:?}&autologin=on&redirect=&query=&login=Connexion" -o out.html
9
# Ensuring auth was successful:
Lucas Cimon's avatar
Lucas Cimon committed
10
grep -qF $USERNAME out.html || { echo "Login as $USERNAME failed"; exit 1; }
11
# Extracting the tid:
Lucas Cimon's avatar
Lucas Cimon committed
12
tid=$(grep -F tid= out.html | sed 's/.*tid=\([^&]\+\)&.*/\1/' | head -n 1)
13
# Uploading a new version of index.html:
Lucas Cimon's avatar
Lucas Cimon committed
14
curl -Ls --fail -b cookies.txt "https://laubergedesreveurs.forumactif.com/admin/?part=modules&sub=html&extended_admin=1&tid=$tid" --data-raw "title=Homepage&forumact_template=0&set_homepage=1&html=$(urlencode < index.html)&mode=go_edit&editor=wysiwyg&page=1&submit=Valider" -o out.html
15
# Ensuring upload was successful:
Lucas Cimon's avatar
Lucas Cimon committed
16
grep -qF "Votre page HTML a bien été modifiée" out.html || { echo "Homepage update failed failed"; exit 1; }
17
# Final cleanup:
Lucas Cimon's avatar
Lucas Cimon committed
18
rm cookies.txt out.html