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