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>
74 lines
2.4 KiB
Python
74 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Wipe foreign SOCKS profiles from physical guest settings (fresh init)."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import httpx
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
CLEAR = r"""
|
|
import json, sys
|
|
sys.path.insert(0, "/opt/douyinWEB/backend")
|
|
from app import db
|
|
cfg = db.get_settings_map()
|
|
keys = [
|
|
"global_socks_profiles",
|
|
"shorts_upload_socks_profiles",
|
|
"global_socks_enabled",
|
|
"shorts_upload_socks_enabled",
|
|
"global_socks_profile_id",
|
|
"shorts_upload_socks_profile_id",
|
|
]
|
|
print("before_profiles", cfg.get("global_socks_profiles") or cfg.get("shorts_upload_socks_profiles"))
|
|
db.update_settings({
|
|
"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()
|
|
print("after_profiles", cfg2.get("global_socks_profiles"), cfg2.get("shorts_upload_socks_profiles"))
|
|
print("rooms", __import__("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()
|
|
with sftp.file("/tmp/_clear_socks.py", "w") as f:
|
|
f.write(CLEAR)
|
|
sftp.close()
|
|
print(run(g, "echo '4669805' | sudo -S -p '' /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")
|
|
print("network", r.status_code, flush=True)
|
|
socks = (r.json() or {}).get("socks") or {}
|
|
print("socks_profiles", socks.get("profiles"), "enabled", socks.get("enabled"), flush=True)
|
|
print("DONE", flush=True)
|