miaopanel
1#!/usr/bin/env bash
2# End-to-end smoke test executed on the target host after installation.
3# Usage: bash smoke-linux.sh <entry>
4set -uo pipefail
5ENTRY="${1:?usage: smoke-linux.sh <entry>}"
6BASE="http://127.0.0.1:8888/${ENTRY}"
7PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt)
8
9code=$(curl -s -o /tmp/login.out -w '%{http_code}' -c /tmp/ck.txt \
10 -H 'Content-Type: application/json' -H 'Origin: http://127.0.0.1:8888' \
11 -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login")
12echo "login http=$code $(head -c 120 /tmp/login.out)"
13CSRF=$(python3 -c "import json;print(json.load(open('/tmp/login.out'))['data']['csrf'])" 2>/dev/null)
14[ -n "$CSRF" ] || { echo "登录失败,终止"; exit 1; }
15
16echo "--- nginx 状态 ---"
17curl -s -b /tmp/ck.txt "$BASE/api/v1/system/nginx" | python3 -m json.tool 2>/dev/null | head -20
18
19echo "--- 创建静态站点 demo.test ---"
20curl -s -b /tmp/ck.txt -H 'Content-Type: application/json' -H 'Origin: http://127.0.0.1:8888' \
21 -H "X-CSRF-Token: $CSRF" \
22 -d '{"name":"demo","kind":"static","domains":["demo.test"],"options":{"waf":true,"security_headers":true}}' \
23 "$BASE/api/v1/sites" | head -c 400
24echo
25echo "--- nginx -t ---"
26nginx -t 2>&1
27
28echo "--- 站点访问 ---"
29curl -s -o /dev/null -w 'demo.test -> %{http_code}\n' -H 'Host: demo.test' http://127.0.0.1/
30curl -s -o /dev/null -w '敏感文件 .git -> %{http_code}\n' -H 'Host: demo.test' http://127.0.0.1/.git/config
31curl -s -o /dev/null -w '扫描器 UA sqlmap -> %{http_code}\n' -A 'sqlmap/1.0' -H 'Host: demo.test' http://127.0.0.1/
32curl -s -H 'Host: demo.test' http://127.0.0.1/ | head -3
33
34echo "--- 安全响应头 ---"
35curl -s -D - -o /dev/null -H 'Host: demo.test' http://127.0.0.1/ | grep -iE 'x-content-type|x-frame|referrer|permissions' || true
36
37echo "--- 生成的文件 ---"
38ls -1 /www/server/panel/vhost/nginx/extension/demo/ 2>/dev/null