108 lines
3.9 KiB
Python
108 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Diagnose ops-neko profile damage: Google login / cookies / backups."""
|
|
import sys
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
SH = r"""
|
|
set -e
|
|
echo "===== profile dirs ====="
|
|
for i in 1 2; do
|
|
p=/opt/douyinWEB/backend/data/ops_neko/profiles/$i
|
|
echo "--- profile $i ---"
|
|
ls -la "$p/Default" 2>/dev/null | head -40 || echo MISSING
|
|
echo "size:"
|
|
du -sh "$p" "$p/Default" 2>/dev/null || true
|
|
for f in Cookies "Login Data" "Web Data" Preferences "Secure Preferences" "Network/Cookies" "Account Web Data"; do
|
|
fp="$p/Default/$f"
|
|
if [ -e "$fp" ]; then
|
|
echo "OK $f $(stat -c '%s %y' "$fp")"
|
|
else
|
|
echo "NO $f"
|
|
fi
|
|
done
|
|
# google account hints in Preferences
|
|
python3 - <<PY
|
|
import json
|
|
from pathlib import Path
|
|
p=Path("/opt/douyinWEB/backend/data/ops_neko/profiles/$i/Default/Preferences")
|
|
if not p.exists():
|
|
print("no prefs"); raise SystemExit
|
|
d=json.loads(p.read_text(encoding="utf-8", errors="replace"))
|
|
acct=d.get("account_info") or d.get("account_values") or d.get("google") or {}
|
|
print("account_info_keys", list((d.get("account_info") or [{}])[0].keys())[:20] if isinstance(d.get("account_info"), list) and d.get("account_info") else type(d.get("account_info")).__name__)
|
|
ai=d.get("account_info")
|
|
if isinstance(ai, list):
|
|
for a in ai[:3]:
|
|
print(" account", {k:a.get(k) for k in ("email","full_name","given_name","gaia_id") if k in a})
|
|
signin=d.get("signin") or {}
|
|
print("signin_keys", list(signin.keys())[:15] if isinstance(signin, dict) else signin)
|
|
profile=d.get("profile") or {}
|
|
print("profile_name", profile.get("name"), "gaia", profile.get("gaia_name"), "user_name", profile.get("user_name"))
|
|
ext=((d.get("extensions") or {}).get("settings") or {})
|
|
print("ext_count", len(ext), "has_tm", "dhdgffkkebhmkfjojejmpbldmpobfkfo" in ext)
|
|
# cookie db rough
|
|
import sqlite3, os
|
|
for cpath in ["Cookies","Network/Cookies"]:
|
|
fp=p.parent/cpath
|
|
if not fp.exists():
|
|
continue
|
|
try:
|
|
con=sqlite3.connect(f"file:{fp}?mode=ro", uri=True)
|
|
cur=con.cursor()
|
|
cur.execute("select count(*) from cookies")
|
|
total=cur.fetchone()[0]
|
|
cur.execute("select count(*) from cookies where host_key like '%google%' or host_key like '%youtube%'")
|
|
gy=cur.fetchone()[0]
|
|
cur.execute("select host_key, name from cookies where host_key like '%google%' or host_key like '%youtube%' limit 15")
|
|
rows=cur.fetchall()
|
|
print(cpath, "cookies", total, "google_yt", gy, "sample", rows[:8])
|
|
con.close()
|
|
except Exception as e:
|
|
print(cpath, "err", e)
|
|
PY
|
|
done
|
|
|
|
echo "===== backups? ====="
|
|
find /opt/douyinWEB/backend/data/ops_neko -maxdepth 3 -type d \( -name '*bak*' -o -name '*backup*' -o -name '*old*' \) 2>/dev/null | head
|
|
ls -la /opt/douyinWEB/backend/data/ops_neko/ 2>/dev/null
|
|
find /opt/douyinWEB -name '*ops_neko*bak*' 2>/dev/null | head
|
|
ls /tmp/*ops*neko* 2>/dev/null | head
|
|
ls /tmp/*profile* 2>/dev/null | head
|
|
|
|
echo "===== current chrome tabs / urls ====="
|
|
for i in 1 2; do
|
|
name=douyinweb-ops-neko-$i
|
|
echo "--- $name ---"
|
|
docker exec "$name" python3 - <<'PY' 2>/dev/null || echo cdp_fail
|
|
import json, urllib.request
|
|
try:
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=4).read())
|
|
except Exception as e:
|
|
print("err", e); raise SystemExit
|
|
for t in tabs:
|
|
if t.get("type") in ("page","service_worker"):
|
|
print(t.get("type"), (t.get("url") or "")[:120])
|
|
PY
|
|
done
|
|
"""
|
|
|
|
|
|
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/_diag_ops_profiles.sh", "wb") as f:
|
|
f.write(SH.encode())
|
|
sftp.close()
|
|
_i, o, e = c.exec_command("echo 4669805 | sudo -S -p '' bash /tmp/_diag_ops_profiles.sh", timeout=120)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|