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