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>
93 lines
2.9 KiB
Python
93 lines
2.9 KiB
Python
# -*- 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]
|
|
|
|
CLEAR = r"""
|
|
import sys
|
|
sys.path.insert(0, "/opt/douyinWEB/backend")
|
|
from app import db
|
|
cfg = db.get_settings_map()
|
|
raw = cfg.get("global_socks_profiles") or cfg.get("shorts_upload_socks_profiles") or []
|
|
print("before_count", len(raw) if isinstance(raw, list) else -1)
|
|
db.update_settings_map({
|
|
"global_socks_profiles": [],
|
|
"shorts_upload_socks_profiles": [],
|
|
"global_socks_enabled": False,
|
|
"shorts_upload_socks_enabled": False,
|
|
"global_socks_profile_id": "",
|
|
"shorts_upload_socks_profile_id": "",
|
|
})
|
|
cfg2 = db.get_settings_map()
|
|
raw2 = cfg2.get("global_socks_profiles") or cfg2.get("shorts_upload_socks_profiles") or []
|
|
print("after_count", len(raw2) if isinstance(raw2, list) else -1)
|
|
import sqlite3
|
|
print("rooms", sqlite3.connect("/opt/douyinWEB/backend/data/monitor.db").execute("select count(*) from rooms").fetchone()[0])
|
|
"""
|
|
|
|
|
|
def ssh(port=4014, user="eric", password="4669805"):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(5):
|
|
try:
|
|
c.connect("107.173.30.245", 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=60):
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
g = ssh()
|
|
sftp = g.open_sftp()
|
|
sftp.put(str(ROOT / "backend/app/global_socks.py"), "/tmp/_up_global_socks.py")
|
|
with sftp.file("/tmp/_clear_socks.py", "w") as f:
|
|
f.write(CLEAR)
|
|
sftp.close()
|
|
print(
|
|
run(
|
|
g,
|
|
"echo '4669805' | sudo -S -p '' bash -c '"
|
|
"install -m 644 /tmp/_up_global_socks.py /opt/douyinWEB/backend/app/global_socks.py; "
|
|
"/opt/douyinWEB/backend/.venv/bin/python /tmp/_clear_socks.py"
|
|
"'",
|
|
40,
|
|
),
|
|
flush=True,
|
|
)
|
|
g.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@"})
|
|
r = client.get("/api/network")
|
|
socks = (r.json() or {}).get("socks") or {}
|
|
print(
|
|
"network",
|
|
r.status_code,
|
|
"profiles_len",
|
|
len(socks.get("profiles") or []),
|
|
"enabled",
|
|
socks.get("enabled"),
|
|
"active_id",
|
|
repr(socks.get("active_profile_id")),
|
|
flush=True,
|
|
)
|
|
r2 = client.get("/api/youtube/neko/status")
|
|
print("neko", r2.status_code, "running_field", (r2.json() or {}).get("running"), flush=True)
|
|
print("neko1_http", client.get("/neko/1/").status_code, flush=True)
|
|
print("DONE", flush=True)
|