Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
109 lines
4.0 KiB
Python
109 lines
4.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
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"
|
|
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(VPS, port, user, password, timeout=45, banner_timeout=60, 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=90):
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
g = ssh()
|
|
sftp = g.open_sftp()
|
|
for rel in ("backend/app/singbox_manager.py", "backend/app/main.py", "backend/app/network_hub.py", "backend/app/global_socks.py"):
|
|
sftp.put(str(ROOT / rel), f"/tmp/_up_{Path(rel).name}")
|
|
print("put", rel, flush=True)
|
|
sftp.close()
|
|
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{PW}' | sudo -S -p '' bash -c '"
|
|
"install -m 644 /tmp/_up_singbox_manager.py /opt/douyinWEB/backend/app/singbox_manager.py; "
|
|
"install -m 644 /tmp/_up_main.py /opt/douyinWEB/backend/app/main.py; "
|
|
"install -m 644 /tmp/_up_network_hub.py /opt/douyinWEB/backend/app/network_hub.py; "
|
|
"install -m 644 /tmp/_up_global_socks.py /opt/douyinWEB/backend/app/global_socks.py; "
|
|
"python3 -m py_compile /opt/douyinWEB/backend/app/singbox_manager.py /opt/douyinWEB/backend/app/main.py /opt/douyinWEB/backend/app/network_hub.py; "
|
|
"echo COMPILE_OK; "
|
|
"grep -q DY_PUBLIC_BASE_URL /etc/systemd/system/douyinweb-api.service || "
|
|
" sed -i \"/Environment=DY_SESSION_SECRET=/a Environment=DY_PUBLIC_BASE_URL=https://dy.nomadro.com\" /etc/systemd/system/douyinweb-api.service; "
|
|
"systemctl daemon-reload; "
|
|
"systemctl kill -s SIGKILL douyinweb-api || true; "
|
|
"sleep 1; systemctl reset-failed douyinweb-api || true; "
|
|
"systemctl start douyinweb-api; sleep 2; systemctl is-active douyinweb-api"
|
|
"'",
|
|
60,
|
|
),
|
|
flush=True,
|
|
)
|
|
for i in range(10):
|
|
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", 10)
|
|
print("health", code.strip(), flush=True)
|
|
if "200" in code:
|
|
break
|
|
g.close()
|
|
|
|
print("=== API checks ===", flush=True)
|
|
with httpx.Client(base_url="https://dy.nomadro.com", timeout=25.0, follow_redirects=False) as client:
|
|
r = client.post("/api/auth/login", json={"username": "hackrobot", "password": "Xiao4669805@"})
|
|
print("login", r.status_code, flush=True)
|
|
r2 = client.get("/api/network")
|
|
print("network", r2.status_code, flush=True)
|
|
if r2.status_code == 200:
|
|
data = r2.json()
|
|
print("keys", sorted(data.keys()), flush=True)
|
|
socks = data.get("socks") or {}
|
|
print("socks", json.dumps(socks, ensure_ascii=False)[:500], flush=True)
|
|
wg = data.get("wireguard") or {}
|
|
print("wg", json.dumps(wg, ensure_ascii=False)[:400], flush=True)
|
|
else:
|
|
print(r2.text[:400], flush=True)
|
|
r3 = client.get("/api/youtube/neko/status")
|
|
print("neko", r3.status_code, (r3.text or "")[:500], flush=True)
|
|
print("page", client.get("/network").status_code, flush=True)
|
|
print("neko1", client.get("https://dy.nomadro.com/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()
|
|
|
|
g = ssh()
|
|
print(
|
|
run(
|
|
g,
|
|
"echo '4669805' | sudo -S -p '' bash -c "
|
|
"'sqlite3 /opt/douyinWEB/backend/data/monitor.db \"select count(*) from rooms;\"; "
|
|
"docker ps --filter name=douyinweb-neko --format \"{{.Names}} {{.Status}}\"'",
|
|
20,
|
|
),
|
|
flush=True,
|
|
)
|
|
g.close()
|
|
print("DONE", flush=True)
|