# -*- coding: utf-8 -*- from __future__ import annotations import sys import time from pathlib import Path import httpx import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") ROOT = Path(__file__).resolve().parents[1] PW = "4669805" def ssh(port=4014, user="eric", password=PW): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for i in range(6): try: c.connect("107.173.30.245", port, user, password, timeout=45, banner_timeout=90, allow_agent=False, look_for_keys=False) return c except Exception as ex: print("ssh", i, type(ex).__name__, flush=True) time.sleep(2) raise RuntimeError("ssh") def run(c, cmd, timeout=120): _, o, e = c.exec_command(cmd, timeout=timeout) return (o.read() + e.read()).decode("utf-8", "replace") # Upload page + rebuild FE for checklist g = ssh() sftp = g.open_sftp() sftp.put(str(ROOT / "frontend/src/app/network/page.tsx"), "/tmp/_up_page.tsx") with sftp.file("/tmp/_fe_build.sh", "w") as f: f.write( "#!/bin/bash\n" "cd /opt/douyinWEB/frontend || exit 1\n" "export DY_INTERNAL_API_URL=http://127.0.0.1:8014 DY_PUBLIC_BASE_URL=https://dy.nomadro.com\n" "npm run build >/tmp/fe-polish.log 2>&1\n" "echo EXIT:$? >>/tmp/fe-polish.log\n" ) sftp.close() print( run( g, f"echo '{PW}' | sudo -S -p '' bash -c '" "install -m 644 /tmp/_up_page.tsx /opt/douyinWEB/frontend/src/app/network/page.tsx; " "chmod +x /tmp/_fe_build.sh; " "systemctl stop douyinweb-web || true; " "nohup /tmp/_fe_build.sh >/dev/null 2>&1 & echo BUILD'" ), flush=True, ) g.close() for i in range(40): time.sleep(12) g = ssh() st = run(g, "tail -n 2 /tmp/fe-polish.log 2>/dev/null; grep '^EXIT:' /tmp/fe-polish.log 2>/dev/null | tail -1; test -f /opt/douyinWEB/frontend/.next/BUILD_ID && echo HAS || echo NO") g.close() print(f"[{i}] {st.strip()[-200:]}", flush=True) if "EXIT:0" in st and "HAS" in st: break if "EXIT:" in st and "EXIT:0" not in st: raise SystemExit("fe fail") else: raise SystemExit("fe timeout") g = ssh() print( run( g, f"echo '{PW}' | sudo -S -p '' bash -c '" "systemctl reset-failed wg-quick@wg-dy douyinweb-web || true; " "systemctl start wg-quick@wg-dy; " "systemctl start douyinweb-web; sleep 3; " "systemctl is-active wg-quick@wg-dy douyinweb-api douyinweb-web'" ), flush=True, ) g.close() with httpx.Client(base_url="https://dy.nomadro.com", timeout=25.0, follow_redirects=False) as client: client.post("/api/auth/login", json={"username": "hackrobot", "password": "Xiao4669805@"}) net = client.get("/api/network").json() cl = net.get("physical_checklist") or {} print("checklist_ok", cl.get("ok"), "failed", cl.get("failed"), flush=True) for c in cl.get("checks") or []: print(f" [{'OK' if c.get('ok') else '!!'}] {c.get('name')}: {c.get('detail')}", flush=True) print("wg_unit", (net.get("wireguard") or {}).get("unit_wg_dy"), "active", (net.get("wireguard") or {}).get("active"), flush=True) neko = client.get("/api/youtube/neko/status").json() print("neko", "desired", neko.get("desired"), "running", neko.get("running"), "bind", neko.get("http_bind"), flush=True) if neko.get("instances"): print("studio", neko["instances"][0].get("studio_url"), flush=True) print("page", client.get("/network").status_code, flush=True) print("neko1", client.get("/neko/1/").status_code, flush=True) v = ssh(22, "root", "Xiao4669805") print(run(v, "curl -sS -m 8 -o /dev/null -w 'dylive:%{http_code}\\n' https://dylive.nomadro.com/api/health"), flush=True) v.close() print("DONE", flush=True)