Files
felhom.eu/documentation/audits/night-2026-09-26/tools/td.py
T
2026-09-25 15:40:19 +02:00

21 lines
1.4 KiB
Python

import re, os, time, urllib.parse
import walk as w
OUT = open(f"{w.EV}/G/T1-teardown-9202.txt", "w", buffering=1)
def say(*a):
w.say(*a); OUT.write(" ".join(map(str, a)) + "\n")
w.login()
for app in ("docmost", "nextcloud"):
code = w.remove(app); say(f"remove {app} -> {code}")
sess = open(f"{w.SC}/sess{os.getpid()}.txt").read().strip(); csrf = open(f"{w.SC}/csrf{os.getpid()}.txt").read().strip()
h = w.page("/kept-data")
items = re.findall(r'name="path" value="([^"]+)"', h)
say("kept items before:", sorted(set(items)))
for p in sorted(set(items)):
if "/nextcloud" not in p and "/docmost" not in p:
continue # only what THIS session made; the older leftovers stay as they were found
r = w.sh(["curl", "-sk", "-D", "-", "-o", "/dev/null", "-H", w.HOSTHDR, "-H", f"Cookie: {sess}", "-X", "POST",
"--data-urlencode", f"_csrf={csrf}", "--data-urlencode", f"path={p}", "--data-urlencode", "confirm=Nextcloud", f"{w.BASE}/kept-data/delete"])
loc = re.search(r"(?im)^location:\s*(\S+)", r.stdout or ""); say("delete", p, "->", urllib.parse.unquote(loc.group(1) if loc else "?")[:160])
say("kept items after:", sorted(set(re.findall(r'name="path" value="([^"]+)"', w.page("/kept-data")))))
say("left on 9202:", w.guest("docker ps -a --format '{{.Names}}' | grep -iE 'docmost|nextcloud'; docker volume ls -q | grep -iE 'docmost|nextcloud'; ls /mnt/felhom-drives/scratch_hdd/kept 2>&1; ls /mnt/felhom-drives/scratch_hdd/appdata"))