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>
133 lines
4.8 KiB
Python
133 lines
4.8 KiB
Python
import paramiko, json
|
|
|
|
HOST = "107.173.30.245"
|
|
USER = "root"
|
|
PASSWORD = "Xiao4669805"
|
|
DB_PATH = "/opt/douyinWEB/backend/data/monitor.db"
|
|
|
|
def ssh_run(c, cmd, timeout=30):
|
|
_s, out, err = c.exec_command(cmd, timeout=timeout)
|
|
return out.read().decode("utf-8","replace").strip(), err.read().decode("utf-8","replace").strip()
|
|
|
|
AUDIT_PY = r"""
|
|
import sqlite3, json, time
|
|
|
|
db = '/opt/douyinWEB/backend/data/monitor.db'
|
|
conn = sqlite3.connect(db)
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
def q(sql, *args):
|
|
try:
|
|
return conn.execute(sql, args).fetchall()
|
|
except Exception as e:
|
|
return [f"ERROR: {e}"]
|
|
|
|
print("=" * 60)
|
|
print("ROOMS")
|
|
rows = q("SELECT id, room_id, platform, title, status, enabled, monitor_status FROM rooms ORDER BY created_at DESC LIMIT 20")
|
|
for r in rows:
|
|
if isinstance(r, str): print(r); continue
|
|
print(f" [{r['id'][:8]}] {r['platform']} | {r['room_id']} | {r['title'][:30] if r['title'] else ''} | status={r['status']} enabled={r['enabled']} monitor={r['monitor_status']}")
|
|
print(f" TOTAL: {q('SELECT count(*) FROM rooms')[0][0]}")
|
|
|
|
print()
|
|
print("=" * 60)
|
|
print("SESSIONS (last 10)")
|
|
rows = q("SELECT id, room_id, platform, title, status, start_time FROM sessions ORDER BY start_time DESC LIMIT 10")
|
|
for r in rows:
|
|
if isinstance(r, str): print(r); continue
|
|
import datetime
|
|
ts = datetime.datetime.fromtimestamp(r['start_time']).strftime('%Y-%m-%d %H:%M') if r['start_time'] else ''
|
|
print(f" [{r['id'][:8]}] {r['platform']} | {r['title'][:30] if r['title'] else ''} | {r['status']} | {ts}")
|
|
print(f" TOTAL: {q('SELECT count(*) FROM sessions')[0][0]}")
|
|
|
|
print()
|
|
print("=" * 60)
|
|
print("EVENTS (last 5)")
|
|
rows = q("SELECT id, session_id, event_type, data, created_at FROM events ORDER BY created_at DESC LIMIT 5")
|
|
for r in rows:
|
|
if isinstance(r, str): print(r); continue
|
|
print(f" {r['event_type']} | data={str(r['data'])[:60]}")
|
|
print(f" TOTAL: {q('SELECT count(*) FROM events')[0][0]}")
|
|
|
|
print()
|
|
print("=" * 60)
|
|
print("CHANNEL_GROUPS")
|
|
rows = q("SELECT id, name, platform, channel_url, enabled, last_status FROM channel_groups ORDER BY created_at DESC")
|
|
for r in rows:
|
|
if isinstance(r, str): print(r); continue
|
|
print(f" [{r['id'][:8]}] {r['platform']} | {r['name']} | url={r['channel_url'][:40] if r['channel_url'] else ''} | enabled={r['enabled']} status={r['last_status']}")
|
|
print(f" TOTAL: {q('SELECT count(*) FROM channel_groups')[0][0]}")
|
|
|
|
print()
|
|
print("=" * 60)
|
|
print("BLACKLIST")
|
|
rows = q("SELECT id, room_id, reason FROM blacklist LIMIT 10")
|
|
for r in rows:
|
|
if isinstance(r, str): print(r); continue
|
|
print(f" {r['room_id']} | {r['reason']}")
|
|
print(f" TOTAL: {q('SELECT count(*) FROM blacklist')[0][0]}")
|
|
|
|
print()
|
|
print("=" * 60)
|
|
print("KV_SETTINGS (key/value overview, no secrets)")
|
|
rows = q("SELECT key, value FROM kv_settings ORDER BY key")
|
|
skip_keys = {'admin_password_hash','dy_cookie','access_token','refresh_token','client_secret'}
|
|
for r in rows:
|
|
if isinstance(r, str): print(r); continue
|
|
k = r['key']
|
|
v = r['value']
|
|
if k in skip_keys:
|
|
v = '***'
|
|
elif len(str(v)) > 80:
|
|
v = str(v)[:80] + '...'
|
|
print(f" {k} = {v}")
|
|
|
|
print()
|
|
print("=" * 60)
|
|
print("SHORTS_CHANNELS")
|
|
rows = q("SELECT id, name, youtube_channel_id, enabled, daily_min, daily_max, oauth_ok FROM shorts_channels")
|
|
for r in rows:
|
|
if isinstance(r, str): print(r); continue
|
|
print(f" [{r['id'][:8]}] {r['name']} | yt={r['youtube_channel_id']} | enabled={r['enabled']} oauth={r['oauth_ok']} daily={r['daily_min']}-{r['daily_max']}")
|
|
print(f" TOTAL: {q('SELECT count(*) FROM shorts_channels')[0][0]}")
|
|
|
|
print()
|
|
print("=" * 60)
|
|
print("SHORTS_JOBS (last 10 + status summary)")
|
|
rows = q("SELECT status, count(*) as c FROM shorts_jobs GROUP BY status")
|
|
for r in rows:
|
|
if isinstance(r, str): print(r); continue
|
|
print(f" status={r['status']} count={r['c']}")
|
|
print(f" TOTAL: {q('SELECT count(*) FROM shorts_jobs')[0][0]}")
|
|
|
|
conn.close()
|
|
"""
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False)
|
|
|
|
# write audit script
|
|
sftp = c.open_sftp()
|
|
with sftp.open("/tmp/_audit.py", "w") as f:
|
|
f.write(AUDIT_PY)
|
|
sftp.close()
|
|
|
|
out, err = ssh_run(c, "python3 /tmp/_audit.py", timeout=60)
|
|
print(out)
|
|
if err:
|
|
print("STDERR:", err[:500])
|
|
|
|
# Also check stash@{1} for channel_groups
|
|
print("\n" + "="*60)
|
|
print("STASH channel_groups count:")
|
|
out2, _ = ssh_run(c, "python3 -c \"import sqlite3; c=sqlite3.connect('/tmp/monitor_stash1.db'); print(c.execute('select count(*) from channel_groups').fetchone()[0])\"")
|
|
print(out2)
|
|
|
|
print("\nSTASH channel_groups rows:")
|
|
out3, _ = ssh_run(c, "python3 -c \"import sqlite3; c=sqlite3.connect('/tmp/monitor_stash1.db'); c.row_factory=sqlite3.Row; [print(dict(r)) for r in c.execute('SELECT id,name,platform,channel_url,enabled FROM channel_groups').fetchall()]\"")
|
|
print(out3)
|
|
|
|
c.close()
|