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

138 lines
5.4 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Compare TM + login on physical vs VPS assign Nekos (douyinweb-neko-*)."""
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
INSIDE = r'''
import json, os, re, urllib.request
from pathlib import Path
ext="dhdgffkkebhmkfjojejmpbldmpobfkfo"
base=Path("/home/neko/.config/google-chrome/Default")
pref=base/"Preferences"
e={}
ai=[]
if pref.exists():
d=json.loads(pref.read_text(encoding="utf-8", errors="replace"))
e=((d.get("extensions") or {}).get("settings") or {}).get(ext) or {}
ai=d.get("account_info") or []
emails=[a.get("email") for a in ai if isinstance(a, dict) and a.get("email")] if isinstance(ai, list) else []
print("emails", emails)
print("tm_state", e.get("state"), "loc", e.get("location"), "webstore", e.get("from_webstore"), "disable", e.get("disable_reasons"))
sp=base/"Secure Preferences"
print("secure_bytes", sp.stat().st_size if sp.exists() else None)
ext_dir=base/"Extensions"/ext
print("ext_exists", ext_dir.exists())
les=base/"Local Extension Settings"/ext
print("les_exists", les.exists(), "les_files", len(list(les.iterdir())) if les.exists() else 0)
# load-extension
found=False
for pid in os.listdir("/proc"):
if not pid.isdigit(): continue
try:
cmd=open(f"/proc/{pid}/cmdline","rb").read().replace(b"\x00", b" ").decode("utf-8","replace")
except Exception:
continue
if "google-chrome" in cmd and "--type=" not in cmd:
m=re.search(r"--load-extension=([^ ]+)", cmd)
print("load_ext", m.group(1) if m else "NONE")
found=True
break
if not found:
print("load_ext NO_CHROME")
try:
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=3).read())
except Exception as ex:
print("cdp_err", type(ex).__name__); tabs=[]
sw=[t for t in tabs if t.get("type")=="service_worker" and "dhdgff" in (t.get("url") or "")]
print("tm_sw", len(sw))
# script in LES
hits=0
if les.exists():
for p in les.rglob("*"):
if p.is_file() and p.stat().st_size < 20_000_000:
try:
raw=p.read_bytes()
except Exception:
continue
if b"YouTube Studio Auto Dismiss" in raw:
hits+=1
print("script_hits", hits)
try:
pol=json.loads(Path("/etc/opt/chrome/policies/managed/policies.json").read_text())
print("forcelist", pol.get("ExtensionInstallForcelist"))
except Exception as ex:
print("pol_err", ex)
'''
HOST_CHECK = r'''
echo "=== host browser-launch / policies ==="
grep -nE "Offline Tampermonkey|tm_load_dir|load-extension" /opt/douyinWEB/backend/neko/browser-launch.sh | head -15
python3 - <<'PY'
import json
from pathlib import Path
p=Path("/opt/douyinWEB/backend/neko/policies/policies.json")
d=json.loads(p.read_text())
print("host_forcelist", d.get("ExtensionInstallForcelist"))
print("host_jsonImport", bool((((d.get("3rdparty") or {}).get("extensions") or {}).get("dhdgffkkebhmkfjojejmpbldmpobfkfo") or {}).get("jsonImport")))
seed=Path("/opt/douyinWEB/backend/neko/tampermonkey-seed/Default")
print("seed_ext", (seed/"Extensions/dhdgffkkebhmkfjojejmpbldmpobfkfo").exists())
print("seed_les", (seed/"Local Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo").exists())
pref=seed/"Preferences"
if pref.exists():
e=((json.loads(pref.read_text()).get("extensions") or {}).get("settings") or {}).get("dhdgffkkebhmkfjojejmpbldmpobfkfo") or {}
print("seed_pref loc", e.get("location"), "webstore", e.get("from_webstore"))
PY
echo "=== containers ==="
docker ps -a --format "{{.Names}} {{.Status}}" | grep -E "douyinweb-neko-[0-9]+$" | sort
'''
def probe(label: str, host: str, port: int, user: str, password: str, sudo: bool, slots: list[int]) -> None:
print(f"\n########## {label} ##########")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(host, port, user, password, timeout=40, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
with sftp.file("/tmp/_cmp_neko_tm_host.sh", "wb") as f:
f.write(HOST_CHECK.encode())
with sftp.file("/tmp/_cmp_neko_tm_inside.py", "wb") as f:
f.write(INSIDE.encode())
sftp.close()
prefix = f"echo {password} | sudo -S -p '' " if sudo else ""
out = _run(c, f"{prefix}bash /tmp/_cmp_neko_tm_host.sh", 60)
print(out)
for i in slots:
name = f"douyinweb-neko-{i}"
print(f"----- {name} -----")
cmd = (
f"{prefix}bash -lc 'docker ps --format {{{{.Names}}}} | grep -qx {name} || {{ echo NOT_RUNNING; exit 0; }}; "
f"docker exec -i {name} python3 - < /tmp/_cmp_neko_tm_inside.py'"
)
# stdin via docker exec -i needs file inside container
cmd = f"""{prefix}bash -lc '
if ! docker ps --format "{{{{.Names}}}}" | grep -qx {name}; then echo NOT_RUNNING; exit 0; fi
docker exec -i {name} tee /tmp/_cmp_neko_tm_inside.py < /tmp/_cmp_neko_tm_inside.py >/dev/null
docker exec {name} python3 /tmp/_cmp_neko_tm_inside.py
'"""
print(_run(c, cmd, 60))
c.close()
def _run(c, cmd, timeout=60) -> str:
_i, o, e = c.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace")
def main() -> None:
# Physical via FRP :4014
probe("PHYSICAL", "107.173.30.245", 4014, "eric", "4669805", True, [1, 2, 3, 7, 8])
# VPS direct
probe("VPS", "107.173.30.245", 22, "root", "Xiao4669805", False, [1, 2, 3, 7, 8])
if __name__ == "__main__":
main()