#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys from pathlib import Path import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") ROOT = Path(__file__).resolve().parents[1] REMOTE_SH = r""" set -e BL=/opt/douyinWEB/backend/neko/browser-launch.sh # ensure current host content cat /tmp/browser-launch.sh.tmfix > "$BL" chmod 755 "$BL" cat /tmp/policies.json.tmfix > /opt/douyinWEB/backend/neko/policies/policies.json cat /tmp/Preferences.tmfix > /opt/douyinWEB/backend/neko/tampermonkey-seed/Default/Preferences MF=/opt/douyinWEB/backend/neko/tampermonkey-seed/Default/Extensions/dhdgffkkebhmkfjojejmpbldmpobfkfo/5.5.0_0/manifest.json [ -f "$MF" ] && cat /tmp/tm_manifest.json.tmfix > "$MF" HOST_MD5=$(md5sum "$BL" | awk '{print $1}') echo "host_md5 $HOST_MD5" for i in 1 2; do name=douyinweb-ops-neko-$i echo "===== REMOUNT $name =====" docker stop "$name" docker start "$name" sleep 3 CTR_MD5=$(docker exec "$name" md5sum /etc/neko/browser-launch.sh | awk '{print $1}') echo "ctr_md5 $CTR_MD5" docker exec "$name" grep -n "Offline Tampermonkey\|tm_load_dir" /etc/neko/browser-launch.sh | head -5 || echo "MISSING_TM_BLOCK" done # wait for chrome up sleep 15 for i in 1 2; do name=douyinweb-ops-neko-$i echo "===== WAIT chrome $name =====" for n in $(seq 1 30); do if docker exec "$name" supervisorctl status google-chrome 2>/dev/null | grep -q RUNNING; then break fi sleep 2 done docker exec "$name" supervisorctl status google-chrome || true done sleep 12 for i in 1 2; do name=douyinweb-ops-neko-$i echo "===== PROBE $name =====" docker exec -i "$name" python3 - <<'PY' import json, os, re, urllib.request from pathlib import Path ext="dhdgffkkebhmkfjojejmpbldmpobfkfo" pref=Path("/home/neko/.config/google-chrome/Default/Preferences") e={} if pref.exists(): e=((json.loads(pref.read_text()).get("extensions") or {}).get("settings") or {}).get(ext) or {} print("state", e.get("state"), "loc", e.get("location"), "webstore", e.get("from_webstore"), "disable", e.get("disable_reasons")) pol=json.loads(Path("/etc/opt/chrome/policies/managed/policies.json").read_text()) print("forcelist", pol.get("ExtensionInstallForcelist")) 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 and "load-extension" in cmd: m=re.search(r"--load-extension=([^ ]+)", cmd) print("load_extension", m.group(1) if m else None) found=True break if not found: print("load_extension NOT_FOUND") try: tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=5).read()) except Exception as ex: print("cdp_err", ex); 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)) for t in sw: print(" ", t.get("url")) print("tm_pages", sum(1 for t in tabs if "chrome-extension://dhdgff" in (t.get("url") or ""))) print("live_ops_sw", sum(1 for t in tabs if t.get("type")=="service_worker" and "live-ops" in (t.get("url") or ""))) 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() for remote, local in { "/tmp/browser-launch.sh.tmfix": ROOT / "backend/neko/browser-launch.sh", "/tmp/policies.json.tmfix": ROOT / "backend/neko/policies/policies.json", "/tmp/Preferences.tmfix": ROOT / "backend/neko/tampermonkey-seed/Default/Preferences", "/tmp/tm_manifest.json.tmfix": ROOT / "backend/neko/tampermonkey-seed/Default/Extensions/dhdgffkkebhmkfjojejmpbldmpobfkfo/5.5.0_0/manifest.json", }.items(): with sftp.file(remote, "wb") as f: f.write(local.read_bytes()) with sftp.file("/tmp/_tm_remount.sh", "wb") as f: f.write(REMOTE_SH.encode()) sftp.close() _i, o, e = c.exec_command("echo 4669805 | sudo -S -p '' bash /tmp/_tm_remount.sh", timeout=420) print((o.read() + e.read()).decode("utf-8", "replace")) c.close() if __name__ == "__main__": main()