# -*- coding: utf-8 -*- """Explain physical Douyin risk: proxy settings + poll load.""" from __future__ import annotations import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") REMOTE = r''' import sqlite3, json, os, urllib.request p="/opt/douyinWEB/backend/data/monitor.db" con=sqlite3.connect(p); con.row_factory=sqlite3.Row # settings keys related to dy proxy / risk keys=("http_proxy","dy_cookie","global_pause_on_risk_sec","check_interval_offline_sec","check_interval_live_sec","request_interval_sec","request_jitter_sec","max_concurrent_checks","monitor_enabled","global_socks_enabled","egress_mode") # get from settings table tabs={r[0] for r in con.execute("SELECT name FROM sqlite_master WHERE type='table'")} print("tables_settings", "settings" in tabs or "kv_settings" in tabs) for t in ("settings","kv_settings","app_settings"): if t not in tabs: continue cols=[r[1] for r in con.execute(f"PRAGMA table_info({t})")] print("settings_table", t, cols[:12]) rows=con.execute(f"SELECT * FROM {t}").fetchall() # try key/value if "key" in cols and "value" in cols: for r in rows: k=str(r["key"]) if any(x in k for x in ("proxy","cookie","interval","concurrent","pause","risk","monitor","egress","socks","jitter")): v=str(r["value"]) if "cookie" in k.lower(): v=f"len={len(v)} set={bool(v.strip())}" print("kv", k, "=", v[:120]) else: # single row map for r in rows[:1]: d=dict(r) for k,v in d.items(): if any(x in k for x in ("proxy","cookie","interval","concurrent","pause","risk","monitor","egress","socks","jitter")): vs=str(v) if "cookie" in k.lower(): vs=f"len={len(vs)} set={bool(vs.strip())}" print("col", k, "=", vs[:120]) rooms=con.execute("SELECT COUNT(*) c FROM rooms").fetchone()["c"] en=con.execute("SELECT COUNT(*) c FROM rooms WHERE enabled=1").fetchone()["c"] print("rooms", rooms, "enabled", en) # recent risk events count last hour-ish if "events" in tabs: cols=[r[1] for r in con.execute("PRAGMA table_info(events)")] # created_at? n=con.execute("SELECT COUNT(*) c FROM events WHERE kind='risk'").fetchone()["c"] print("risk_events_total", n) for r in con.execute("SELECT created_at, message, room_id, anchor_name FROM events WHERE kind='risk' ORDER BY rowid DESC LIMIT 5"): print("risk", dict(r)) con.close() # egress / proxy env of running api import subprocess print("--- api env ---") out=subprocess.check_output("tr '\\0' '\\n' < /proc/$(pgrep -f 'uvicorn app.main' | head -1)/environ 2>/dev/null | grep -iE 'proxy|egress|socks|HTTP' || true", shell=True, text=True) print(out[:800] or "(no proxy env)") # curl douyin web/enter without cookie briefly print("--- curl live.douyin.com ---") import subprocess as sp r=sp.run(["curl","-sS","-m","8","-o","/tmp/dy_probe.txt","-w","%{http_code} %{content_type} %{size_download}","https://live.douyin.com/"], capture_output=True, text=True) print("home", r.stdout, r.stderr[:100]) head=open("/tmp/dy_probe.txt","rb").read(200) print("home_head", head[:120]) # ip r2=sp.run(["curl","-sS","-m","5","https://ipinfo.io/json"], capture_output=True, text=True) print("egress_ip", r2.stdout[:300]) ''' c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=45, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() with sftp.file("/tmp/_dy_risk.py", "w") as f: f.write(REMOTE) sftp.close() _, o, e = c.exec_command( "echo '4669805' | sudo -S -p '' /opt/douyinWEB/backend/.venv/bin/python /tmp/_dy_risk.py", timeout=90, ) print((o.read() + e.read()).decode("utf-8", "replace")) c.close()