miaopanel
1#!/usr/bin/env bash
2# Inspect and clean up the Go site created through the UI.
3set -uo pipefail
4ENTRY="${1:-ipdduiyy}"
5BASE="http://127.0.0.1:8888/$ENTRY"
6PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt)
7ORIGIN="http://127.0.0.1:8888"
8
9curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H "Origin: $ORIGIN" \
10 -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/dev/null
11CSRF=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/auth/session" | python3 -c "import json,sys;print(json.load(sys.stdin)['data']['csrf'])")
12H=(-b /tmp/ck.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' -H "Origin: $ORIGIN")
13
14curl -s -b /tmp/ck.txt "$BASE/api/v1/sites" > /tmp/sites.json
15python3 - <<'PY'
16import json
17for s in json.load(open('/tmp/sites.json'))['data']:
18 if s['name'] == 'uitest-go':
19 print('site: id=%s name=%s kind=%s root=%s port=%s start_cmd=%s' % (
20 s['id'], s['name'], s['kind'], s['root'], s['port'], s['start_cmd']))
21PY
22
23echo "mode: $(stat -c '%a' /www/wwwroot/uitest/app)"
24systemctl is-active miaopanel-site-uitest-go.service
25echo "direct: $(curl -s --max-time 5 http://127.0.0.1:8080/)"
26echo "nginx: $(curl -s --max-time 5 -H 'Host: uitest.go' http://127.0.0.1/)"
27
28SID=$(python3 -c "
29import json
30rows=[s['id'] for s in json.load(open('/tmp/sites.json'))['data'] if s['name']=='uitest-go']
31print(rows[0] if rows else '')")
32if [ -n "$SID" ]; then
33 curl -s "${H[@]}" -X DELETE "$BASE/api/v1/sites/$SID?remove_files=1" >/dev/null
34 echo "cleaned up site $SID"
35fi
36ls /www/wwwroot/uitest 2>/dev/null || echo "directory removed"
37nginx -t 2>&1 | tail -1