chore: import MCTF services

- Added all seven issued service trees without omissions.
- Preserved the supplied runtime configuration, binaries, and assets.
This commit is contained in:
TakuyaYagam1 committed 2026-11-29 12:25:29 +03:00
commit 13f936bee9
1222 files changed
+21280

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
FROM python:3.12-slim-bookworm
RUN useradd --uid 10001 --user-group --no-create-home --shell /usr/sbin/nologin ledger-cleaner \
&& install -d -m 0700 -o ledger-cleaner -g ledger-cleaner /var/lib/chrome-ledger
COPY --chmod=755 cleaner.sh /cleaner.sh
COPY cleaner.py /cleaner.py
USER ledger-cleaner
HEALTHCHECK --interval=10m --timeout=5s --start-period=90s --retries=2 CMD python3 -c "import os,time; p='/tmp/cleaner-last-success'; raise SystemExit(0 if os.path.exists(p) and time.time()-os.path.getmtime(p)<720 else 1)"
CMD ["/cleaner.sh"]
+54
View File
@@ -0,0 +1,54 @@
import os
import sqlite3
from datetime import UTC, datetime, timedelta
RETENTION = timedelta(minutes=10)
def main():
connection = sqlite3.connect(os.environ["LEDGER_DB"], timeout=5)
connection.execute("PRAGMA busy_timeout = 5000")
connection.execute("PRAGMA foreign_keys = ON")
tables = {
row[0]
for row in connection.execute("SELECT name FROM sqlite_master WHERE type = 'table'")
}
cutoff = (datetime.now(UTC) - RETENTION).isoformat()
deleted = []
if "auth_sessions" in tables:
cursor = connection.execute(
"DELETE FROM auth_sessions WHERE expires_at <= ?",
(int(datetime.now(UTC).timestamp()),),
)
deleted.append(f"sessions={cursor.rowcount}")
if "implant_challenges" in tables:
cursor = connection.execute(
"DELETE FROM implant_challenges WHERE created_at <= ?",
(cutoff,),
)
deleted.append(f"challenges={cursor.rowcount}")
if "implants" in tables:
cursor = connection.execute(
"DELETE FROM implants WHERE created_at <= ?",
(cutoff,),
)
deleted.append(f"implants={cursor.rowcount}")
if "users" in tables and "implants" in tables:
cursor = connection.execute(
"DELETE FROM users WHERE created_at <= ? "
"AND NOT EXISTS (SELECT 1 FROM implants WHERE implants.user_id = users.id)",
(cutoff,),
)
deleted.append(f"users={cursor.rowcount}")
connection.commit()
connection.execute("PRAGMA wal_checkpoint(PASSIVE)")
connection.execute("PRAGMA optimize")
connection.execute("PRAGMA incremental_vacuum").fetchall()
connection.close()
print("cleaned " + " ".join(deleted), flush=True)
if __name__ == "__main__":
main()
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
while true; do
if python3 /cleaner.py; then
touch /tmp/cleaner-last-success
fi
sleep 600
done