# -*- coding: utf-8 -*- """Push network_hub + install script; quick SC http probe.""" from __future__ import annotations import sys from pathlib import Path import httpx import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") ROOT = Path(__file__).resolve().parents[1] GUEST_PW = "4669805" def main() -> int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( "107.173.30.245", 4014, "eric", GUEST_PW, timeout=40, banner_timeout=80, allow_agent=False, look_for_keys=False, ) sftp = c.open_sftp() sftp.put(str(ROOT / "backend/app/network_hub.py"), "/tmp/_up_network_hub.py") data = (ROOT / "scripts/linux/install_shellcrash.sh").read_bytes() data = data.replace(b"\r\n", b"\n").replace(b"\r", b"\n") with sftp.file("/tmp/_up_install_sc.sh", "wb") as f: f.write(data) page = (ROOT / "frontend/src/app/network/page.tsx").read_bytes() with sftp.file("/tmp/_up_page.tsx", "wb") as f: f.write(page) sftp.close() _, o, e = c.exec_command( f"echo '{GUEST_PW}' | sudo -S -p '' bash -c '" "install -m 644 /tmp/_up_network_hub.py /opt/douyinWEB/backend/app/network_hub.py; " "install -m 755 /tmp/_up_install_sc.sh /opt/douyinWEB/scripts/linux/install_shellcrash.sh; " "install -m 644 /tmp/_up_page.tsx /opt/douyinWEB/frontend/src/app/network/page.tsx; " "systemctl restart douyinweb-api; sleep 2; " "systemctl is-active douyinweb-api shellcrash; " "curl -sS -m 5 -o /dev/null -w http_mixed:%{http_code}\\\\n -x http://127.0.0.1:7890 http://connectivitycheck.gstatic.com/generate_204 || echo http_mixed:fail; " "curl -sS -m 5 -o /dev/null -w https_direct:%{http_code}\\\\n https://www.google.com/generate_204 || echo https_direct:fail" "'", timeout=60, ) print((o.read() + e.read()).decode("utf-8", "replace")) c.close() with httpx.Client(base_url="https://dy.nomadro.com", timeout=20.0) as client: client.post("/api/auth/login", json={"username": "hackrobot", "password": "Xiao4669805@"}) j = client.get("/api/network").json() sc = j.get("shellcrash") or {} cl = j.get("physical_checklist") or {} print("sc", sc.get("installed"), sc.get("running"), sc.get("unit"), flush=True) print("ok=", cl.get("ok"), "failed=", cl.get("failed"), flush=True) for x in cl.get("checks") or []: print(f" [{'OK' if x.get('ok') else '!!'}] {x.get('name')}: {x.get('detail')}", flush=True) print("DONE", flush=True) return 0 if __name__ == "__main__": raise SystemExit(main())