82 lines
2.8 KiB
Python
82 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Probe Tampermonkey load status inside ops-neko containers."""
|
|
import sys
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
PROBE = r'''
|
|
import json, urllib.request
|
|
from pathlib import Path
|
|
ext="dhdgffkkebhmkfjojejmpbldmpobfkfo"
|
|
p=Path("/home/neko/.config/google-chrome/Default/Preferences")
|
|
d=json.loads(p.read_text())
|
|
e=((d.get("extensions") or {}).get("settings") or {}).get(ext) or {}
|
|
print("state", e.get("state"))
|
|
print("location", e.get("location"))
|
|
print("from_webstore", e.get("from_webstore"))
|
|
print("path", e.get("path"))
|
|
print("disable_reasons", e.get("disable_reasons"))
|
|
print("was_installed_by_oem", e.get("was_installed_by_oem"))
|
|
pol_path=Path("/etc/opt/chrome/policies/managed/policies.json")
|
|
pol=json.loads(pol_path.read_text())
|
|
print("forcelist", pol.get("ExtensionInstallForcelist"))
|
|
print("jsonImport", ((pol.get("3rdparty") or {}).get("extensions") or {}).get(ext))
|
|
# CDP tabs
|
|
try:
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=4).read())
|
|
except Exception as ex:
|
|
print("cdp_err", ex)
|
|
tabs=[]
|
|
print("tabs_total", len(tabs))
|
|
for t in tabs:
|
|
u=t.get("url") or ""
|
|
if "dhdgff" in u or t.get("type")=="service_worker":
|
|
print("TAB", t.get("type"), t.get("title"), u[:120])
|
|
# check extension dir
|
|
ext_root=Path("/home/neko/.config/google-chrome/Default/Extensions")/ext
|
|
print("ext_exists", ext_root.exists())
|
|
if ext_root.exists():
|
|
vers=sorted([x.name for x in ext_root.iterdir() if x.is_dir()])
|
|
print("versions", vers)
|
|
if vers:
|
|
mf=ext_root/vers[0]/"manifest.json"
|
|
if mf.exists():
|
|
m=json.loads(mf.read_text())
|
|
print("manifest_name", m.get("name"), "version", m.get("version"), "mv", m.get("manifest_version"))
|
|
# LES
|
|
les=Path("/home/neko/.config/google-chrome/Default/Local Extension Settings")/ext
|
|
print("les_exists", les.exists())
|
|
if les.exists():
|
|
print("les_files", sorted([x.name for x in les.iterdir()])[:20])
|
|
'''
|
|
|
|
|
|
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)
|
|
for i in (1, 2):
|
|
name = f"douyinweb-ops-neko-{i}"
|
|
print(f"===== {name} =====")
|
|
cmd = f"docker exec {name} python3 -c {json_quote(PROBE)}"
|
|
# write probe via stdin
|
|
_i, o, e = c.exec_command(
|
|
f"echo 4669805 | sudo -S -p '' docker exec -i {name} python3 -",
|
|
timeout=60,
|
|
)
|
|
_i.write(PROBE.encode())
|
|
_i.channel.shutdown_write()
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out)
|
|
c.close()
|
|
|
|
|
|
def json_quote(_s: str) -> str:
|
|
return ""
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|