miaopanel
1#!/usr/bin/env bash
2# Create a test site (no cert) for UI screenshots, or delete it with "clean".
3set -uo pipefail
4ACTION="${1:-prepare}"
5ENTRY="${2:-ipdduiyy}"
6DOMAIN="${3:-186-241-74-221.sslip.io}"
7BASE="http://127.0.0.1:8888/$ENTRY"
8PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt)
9ORIGIN="http://127.0.0.1:8888"
10
11curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H "Origin: $ORIGIN" \
12 -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/dev/null
13CSRF=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/auth/session" | python3 -c "import json,sys;print(json.load(sys.stdin)['data']['csrf'])")
14H=(-b /tmp/ck.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' -H "Origin: $ORIGIN")
15
16SID=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/sites" | python3 -c "
17import json,sys
18rows=[s['id'] for s in json.load(sys.stdin)['data'] if '$DOMAIN' in s['domains']]
19print(rows[0] if rows else '')")
20
21if [ "$ACTION" = "clean" ]; then
22 if [ -n "$SID" ]; then
23 curl -s "${H[@]}" -X DELETE "$BASE/api/v1/sites/$SID?remove_files=1" >/dev/null
24 echo "deleted site $SID"
25 else
26 echo "site not found"
27 fi
28 exit 0
29fi
30
31if [ -z "$SID" ]; then
32 curl -s "${H[@]}" -d "{\"kind\":\"static\",\"domains\":[\"$DOMAIN\"],\"options\":{\"waf\":true,\"security_headers\":true}}" \
33 "$BASE/api/v1/sites" | head -c 200
34 echo
35else
36 echo "site already exists: $SID"
37fi