# -*- coding: utf-8 -*- """Deploy shellcrash_hub web_panel fix + verify public panel.""" from __future__ import annotations import json 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] VPS = "107.173.30.245" ROOT_PASS = "Xiao4669805" GUEST_USER = "eric" GUEST_PASS = "4669805" GUEST_PORT = 4014 HUB = ROOT / "backend" / "app" / "shellcrash_hub.py" MW = ROOT / "frontend" / "src" / "middleware.ts" def ssh(port, user, password): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(VPS, port, user, password, timeout=40, banner_timeout=80, allow_agent=False, look_for_keys=False) return c def run(c, cmd, t=120): _, o, e = c.exec_command(cmd, timeout=t) return (o.read() + e.read()).decode("utf-8", "replace") def main(): g = ssh(GUEST_PORT, GUEST_USER, GUEST_PASS) sftp = g.open_sftp() sftp.put(str(HUB), "/tmp/_up_shellcrash_hub.py") sftp.put(str(MW), "/tmp/_up_middleware.ts") sftp.close() print( run( g, f"echo '{GUEST_PASS}' | sudo -S -p '' bash -c '" "install -m 644 /tmp/_up_shellcrash_hub.py /opt/douyinWEB/backend/app/shellcrash_hub.py; " "install -m 644 /tmp/_up_middleware.ts /opt/douyinWEB/frontend/src/middleware.ts; " "cd /opt/douyinWEB/backend && .venv/bin/python -m py_compile app/shellcrash_hub.py && echo COMPILE_OK; " "systemctl restart douyinweb-api; " "'", 90, ), flush=True, ) for _ in range(15): time.sleep(2) code = run(g, "curl -sS -m 3 -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/health || echo x").strip() print("health", code, flush=True) if code == "200": break g.close() # login + web_panel with httpx.Client(base_url="https://dy.nomadro.com", timeout=30, follow_redirects=False) as client: lr = client.post("/api/auth/login", json={"username": "hackrobot", "password": "Xiao4669805@"}) print("login", lr.status_code, flush=True) wp = client.post("/api/network/shellcrash/web_panel") print("web_panel", wp.status_code, flush=True) data = wp.json() print(json.dumps({k: data.get(k) for k in ("ok", "message", "url", "direct_url", "ui_installed", "port")}, ensure_ascii=False, indent=2), flush=True) url = data.get("url") or "" # probe assets for path in ( "/shellcrash-ui/ui/", "/shellcrash-ui/version", "/shellcrash-ui/proxies", ): r = client.get(path) print(path, r.status_code, (r.headers.get("content-type") or "")[:40], flush=True) print("DONE", flush=True) if __name__ == "__main__": main()