~brecht/pamphlets.me

366096a40246e90e5ac7274e52f7ae522ecc82cf — Brecht Savelkoul a month ago c0e314f
Write basic posting CLI
1 files changed, 21 insertions(+), 0 deletions(-)

A pamphlet.sh
A pamphlet.sh => pamphlet.sh +21 -0
@@ 0,0 1,21 @@
#!/usr/bin/env bash

set -euo pipefail

cookies="$TMPDIR/session-$1"

request () {
	curl -S -s -c "$cookies" -b "$cookies" "$@"
}

code=$(request -o /dev/null --write-out "%{http_code}\n" "https://$1/admin/write")

if [ "$code" != 200 ]; then
	csrf=$(request "https://$1/admin/login" | htmlq 'input[name=csrf_token]' --attribute value)
	echo "Password: " && read -s pw
	request "https://$1/admin/login" -d "csrf_token=$csrf&password=$pw" -o /dev/null
else
	csrf=$(request "https://$1/admin/write" | htmlq 'input[name=csrf_token]' --attribute value)
fi

request "https://$1/admin/actions/new" -d "csrf_token=$csrf&content=$2&visibility=PUBLIC"