#!/usr/bin/env bash # Create a test site (no cert) for UI screenshots, or delete it with "clean". set -uo pipefail ACTION="${1:-prepare}" ENTRY="${2:-ipdduiyy}" DOMAIN="${3:-186-241-74-221.sslip.io}" BASE="http://127.0.0.1:8888/$ENTRY" PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt) ORIGIN="http://127.0.0.1:8888" curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H "Origin: $ORIGIN" \ -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/dev/null CSRF=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/auth/session" | python3 -c "import json,sys;print(json.load(sys.stdin)['data']['csrf'])") H=(-b /tmp/ck.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' -H "Origin: $ORIGIN") SID=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/sites" | python3 -c " import json,sys rows=[s['id'] for s in json.load(sys.stdin)['data'] if '$DOMAIN' in s['domains']] print(rows[0] if rows else '')") if [ "$ACTION" = "clean" ]; then if [ -n "$SID" ]; then curl -s "${H[@]}" -X DELETE "$BASE/api/v1/sites/$SID?remove_files=1" >/dev/null echo "deleted site $SID" else echo "site not found" fi exit 0 fi if [ -z "$SID" ]; then curl -s "${H[@]}" -d "{\"kind\":\"static\",\"domains\":[\"$DOMAIN\"],\"options\":{\"waf\":true,\"security_headers\":true}}" \ "$BASE/api/v1/sites" | head -c 200 echo else echo "site already exists: $SID" fi