# -*- coding: utf-8 -*- """Find dy_cookie on known hosts; fix auth kick.""" from __future__ import annotations import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") HOSTS = [ ("ypp", "192.227.152.110", "Leaf448772566"), ("dy", "108.174.50.68", "Xiao4669805"), ("old", "107.173.30.245", "Xiao4669805"), ] FIND = r""" import os, glob from pathlib import Path # db cookie try: import sys sys.path.insert(0,'/opt/douyinWEB/backend') os.chdir('/opt/douyinWEB/backend') from app import db db.init_db() c=str(db.get_settings_map().get('dy_cookie') or '') print('DB', len(c)) except Exception as e: print('DB_ERR', e) # files cands=[] for p in [ '/opt/douyinWEB/config/douyin_cookie.ini', '/opt/douyinWEB/backend/config/douyin_cookie.ini', '/root/sh2/config/config.ini', '/opt/sh2/config/config.ini', '/www/wwwroot/*/config.ini', ]: for f in glob.glob(p): cands.append(f) print('FILES', cands[:20]) for f in cands[:10]: try: t=Path(f).read_text(encoding='utf-8', errors='replace') if '抖音cookie' in t or 'dy_cookie' in t or 'sessionid' in t.lower(): print('HIT', f, 'len', len(t)) except Exception as e: print('READ_ERR', f, e) # grep settings sqlite directly import sqlite3 for dbp in ['/opt/douyinWEB/backend/data/monitor.db','/opt/tiktokWEB/backend/data/monitor.db']: if not os.path.exists(dbp): continue try: conn=sqlite3.connect(dbp) row=conn.execute("select length(value) from kv_settings where key='dy_cookie'").fetchone() print('SQL', dbp, row) conn.close() except Exception as e: print('SQL_ERR', dbp, e) """ def main() -> None: for name, host, pw in HOSTS: print("=" * 40, name, host) try: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(host, 22, "root", pw, timeout=25, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() with sftp.file("/tmp/_find_cookie.py", "w") as f: f.write(FIND) sftp.close() _, o, e = c.exec_command( "python3 /tmp/_find_cookie.py 2>&1 || " "cd /opt/douyinWEB/backend && .venv/bin/python /tmp/_find_cookie.py 2>&1", timeout=60, ) print(o.read().decode("utf-8", "replace")[:2500]) c.close() except Exception as exc: print("FAIL", exc) if __name__ == "__main__": main()