# -*- coding: utf-8 -*- r'''完整验证:登录 -> 后台页看到「抢救报告」-> 下载报告。 上一轮失败是因为我 curl 用错了接口(POST /login 只传 password), 实际是 POST /admin/login 且要 username + password 两个字段。 ''' from __future__ import annotations import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT / "_build")) from devssh import run # noqa: E402 REMOTE = r''' RELAY=/root/lanremote-relay B=http://127.0.0.1:8080 echo "════ 0. 账号与密码 ════" grep -m1 '^ADMIN_USER' $RELAY/relay.py | sed 's/^/ /' echo " 密码文件长度: $(wc -c < $RELAY/data/admin_password.txt) 字节" echo echo "════ 1. 造报告 ════" printf '这是一份演练报告。\n\n 判断:**本机是好的,问题在隧道或 Cloudflare 那一侧**。\n' \ > "$RELAY/rescue_reports/19700101-000000-demo.txt" ls $RELAY/rescue_reports/ | sed 's/^/ /' echo echo "════ 2. 登录(POST /admin/login,username + password)════" PASS=$(cat $RELAY/data/admin_password.txt 2>/dev/null) rm -f /tmp/ck3.txt curl -s -c /tmp/ck3.txt -o /dev/null -w ' HTTP %{http_code}\n' --max-time 10 \ -d "username=" -d "password=$PASS" $B/admin/login echo " cookie 文件:" grep -c lr_admin /tmp/ck3.txt 2>/dev/null | sed 's/^/ 找到 lr_admin: /' echo echo "════ 3. 带登录拿后台页 ════" curl -s -b /tmp/ck3.txt -o /tmp/adm3.html -w ' HTTP %{http_code} 大小 %{size_download} 字节\n' \ --max-time 10 $B/zhongzhuanzhan echo " 含「抢救报告」: $(grep -c '抢救报告' /tmp/adm3.html)" echo " 含演练报告文件名: $(grep -c '19700101-000000-demo.txt' /tmp/adm3.html)" echo " 含「下载区」: $(grep -c '下载区' /tmp/adm3.html)" echo echo "════ 4. 带登录下载报告 ════" curl -s -b /tmp/ck3.txt -o /tmp/rep3.txt -w ' HTTP %{http_code} 大小 %{size_download} 字节\n' \ --max-time 10 "$B/rescue/19700101-000000-demo.txt" echo " 内容第一行: $(head -1 /tmp/rep3.txt)" echo " 缓存头: $(curl -s -b /tmp/ck3.txt -D- -o /dev/null --max-time 10 \ "$B/rescue/19700101-000000-demo.txt" | grep -i 'cache-control' | tr -d '\r')" echo echo "════ 5. 不带登录(应该 401)════" curl -s -o /dev/null -w ' HTTP %{http_code}\n' --max-time 10 \ "$B/rescue/19700101-000000-demo.txt" echo echo "════ 6. X-Admin 头(脚本通道)也要能下 ════" curl -s -o /dev/null -w ' HTTP %{http_code}\n' --max-time 10 \ -H "X-Admin: $PASS" "$B/rescue/19700101-000000-demo.txt" echo echo "════ 清理 ════" rm -f "$RELAY/rescue_reports/19700101-000000-demo.txt" /tmp/ck3.txt /tmp/adm3.html /tmp/rep3.txt ''' def main() -> int: out = run(REMOTE, timeout=200) text = out[1] if isinstance(out, tuple) else str(out) print(text) return 0 if __name__ == "__main__": sys.exit(main())