douyinWEB/scripts/_check_opsneko_login_left.py
2026-09-13 22:10:49 -05:00

80 lines
2.7 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
SH = r"""
echo "===== regular neko cookie auth check ====="
for i in 1 2 3; do
python3 - <<PY
import sqlite3, json
from pathlib import Path
i="$i"
fp=Path(f"/opt/douyinWEB/backend/data/neko/profiles/{i}/Default/Cookies")
pref=Path(f"/opt/douyinWEB/backend/data/neko/profiles/{i}/Default/Preferences")
ai=[]
if pref.exists():
d=json.loads(pref.read_text(encoding='utf-8', errors='replace'))
ai=[a.get('email') for a in (d.get('account_info') or []) if isinstance(a, dict)]
print(f"neko-{i} emails={ai} cookies_size={fp.stat().st_size if fp.exists() else None}")
if fp.exists():
con=sqlite3.connect(f"file:{fp}?mode=ro", uri=True)
cur=con.cursor()
cur.execute("select count(*) from cookies")
print(" total", cur.fetchone()[0])
cur.execute("select host_key, name from cookies where name like '%SID%' or name like '%SAPISID%' or name like '%LSID%' or name='SID' limit 20")
print(" auth", cur.fetchall())
con.close()
PY
done
echo "===== Local State / first-install times ====="
ls -la /opt/douyinWEB/backend/data/ops_neko/profiles/1/Local\ State /opt/douyinWEB/backend/data/ops_neko/profiles/2/Local\ State 2>/dev/null
stat /opt/douyinWEB/backend/data/ops_neko/profiles/*/Default/Cookies | grep -E 'File:|Modify|Size'
echo "===== ops hub / assign pairing still in DB? ====="
python3 - <<'PY'
import sqlite3
from pathlib import Path
for db in [
Path('/opt/douyinWEB/backend/data/monitor.db'),
Path('/opt/douyinWEB/backend/data/ops_neko.db'),
]:
if not db.exists():
print('missing', db); continue
print('DB', db, db.stat().st_size)
con=sqlite3.connect(f'file:{db}?mode=ro', uri=True)
cur=con.cursor()
cur.execute("select name from sqlite_master where type='table' order by 1")
tables=[r[0] for r in cur.fetchall()]
print(' tables', tables[:40])
for t in tables:
if any(x in t.lower() for x in ('ops','neko','hub','cred','pair','assign','studio')):
try:
cur.execute(f'select count(*) from {t}')
print(f' {t}:', cur.fetchone()[0])
except Exception as e:
print(' err', t, e)
con.close()
PY
"""
def main() -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
with sftp.file("/tmp/_check_login_left.sh", "wb") as f:
f.write(SH.encode())
sftp.close()
_i, o, e = c.exec_command("echo 4669805 | sudo -S -p '' bash /tmp/_check_login_left.sh", timeout=90)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
if __name__ == "__main__":
main()