# -*- coding: utf-8 -*- from __future__ import annotations import json import sys import time import httpx import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") VPS = "107.173.30.245" CHECK = r""" import sqlite3 from pathlib import Path from app import global_socks dbp = Path("data/monitor.db") con = sqlite3.connect(dbp) n_rooms = con.execute("select count(*) from rooms").fetchone()[0] print("rooms", n_rooms) con.close() try: profiles = global_socks.load_profiles() except Exception: profiles = global_socks.list_profiles() if hasattr(global_socks, "list_profiles") else [] print("socks_count", len(profiles or [])) print("default_profiles_empty", len(global_socks.DEFAULT_PROFILES) == 0) """ def ssh(port, user, pw): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for i in range(5): try: c.connect(VPS, port, user, pw, 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") print("=== login + network ===", 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) print(json.dumps({k: data.get(k) for k in list(data)[:6]}, ensure_ascii=False)[:600], flush=True) r3 = client.get("/api/youtube/neko/status") print("neko", r3.status_code, (r3.text or "")[:450], flush=True) r4 = client.get("/network") print("page /network", r4.status_code, "loc", r4.headers.get("location"), flush=True) g = ssh(4014, "eric", "4669805") sftp = g.open_sftp() with sftp.file("/tmp/_fresh_check.py", "w") as f: f.write(CHECK) sftp.close() print( run( g, "echo '4669805' | sudo -S -p '' " "bash -c 'cd /opt/douyinWEB/backend && .venv/bin/python /tmp/_fresh_check.py'", 40, ), flush=True, ) g.close() print("DONE", flush=True)