# -*- coding: utf-8 -*- r'''验证 /rescue/ 鉴权修复是否真的生效。 上一轮部署后还是 HTTP 000。要分清是: * 代码没传上去 / 进程没重启(改动没生效) * 还是代码有新问题 ''' 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 "════ 1. 设备上 relay.py 里那段代码长什么样 ════" grep -n -A6 'if path.startswith("/rescue/")' $RELAY/relay.py | head -40 | sed 's/^/ /' echo echo "════ 2. 进程是什么时候起的 vs relay.py 修改时间 ════" PID=$(systemctl show -p MainPID --value lanremote-relay) echo " PID=$PID 启动: $(ps -o lstart= -p $PID 2>/dev/null)" echo " relay.py 改于: $(stat -c '%y' $RELAY/relay.py)" echo echo "════ 3. 再来一次详细请求 ════" printf '报告\n 判断:测试\n' > $RELAY/rescue_reports/19700101-000000-demo.txt curl -sv --max-time 8 "$B/rescue/19700101-000000-demo.txt" 2>&1 | tail -20 | sed 's/^/ /' echo echo "════ 4. 对照:一个不存在的普通路径 ════" curl -s -o /dev/null -w ' /nothing-here -> %{http_code}\n' --max-time 6 "$B/nothing-here" echo echo "════ 5. 对照:/download/ 上不存在的文件(那条没加鉴权)════" curl -s -o /dev/null -w ' /download/none.txt -> %{http_code}\n' --max-time 6 "$B/download/none.txt" rm -f $RELAY/rescue_reports/19700101-000000-demo.txt ''' def main() -> int: out = run(REMOTE, timeout=180) text = out[1] if isinstance(out, tuple) else str(out) print(text) return 0 if __name__ == "__main__": sys.exit(main())