miaopanel
1#!/usr/bin/env bash
2# Verify Go site creation without a start command (auto-detected executable).
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
14echo "== 可执行文件检测 =="
15curl -s -b /tmp/ck.txt "$BASE/api/v1/sites/executables?dir=%2Fgoauto"
16
17echo
18echo "== 创建 Go 站点(不填执行命令,使用相对目录) =="
19curl -s "${H[@]}" -d '{"kind":"go","domains":["go.auto"],"root":"/goauto","port":8131,"env":"PORT=8131","options":{"waf":true,"security_headers":true}}' \
20 "$BASE/api/v1/sites" > /tmp/go-site.json
21python3 - <<'PY'
22import json
23d = json.load(open('/tmp/go-site.json'))
24if d['code'] != 0:
25 print('create failed:', d)
26 raise SystemExit(1)
27s = d['data']
28print('id=%s name=%s root=%s port=%s start_cmd=%s' % (s['id'], s['name'], s['root'], s['port'], s['start_cmd']))
29PY
30
31sleep 2
32echo "== systemd 单元 =="
33grep -E 'ExecStart|WorkingDirectory' /etc/systemd/system/miaopanel-site-goauto.service
34systemctl is-active miaopanel-site-goauto.service
35
36echo "== 直接访问 =="
37curl -s --max-time 5 http://127.0.0.1:8131/ || echo "app not reachable"
38echo "== 经 nginx =="
39curl -s --max-time 5 -H 'Host: go.auto' http://127.0.0.1/ || echo "nginx proxy failed"
40
41SID=$(python3 -c "import json;print(json.load(open('/tmp/go-site.json'))['data']['id'])")
42echo "== 清理 =="
43curl -s "${H[@]}" -X DELETE "$BASE/api/v1/sites/$SID?remove_files=1"; echo
44ls /www/wwwroot/goauto 2>/dev/null || echo "directory removed"
45nginx -t 2>&1 | tail -1