fix(beta): API admin limitee a admin.jobrunner.fr, effacement et purge des testeurs, plafonds des captures, deconnexion en POST
- X-Admin seul ne suffit plus : Host doit etre admin.jobrunner.fr (le vhost public transmet les en-tetes du visiteur) - feedback.tester_id : retours lies au testeur, effaces avec lui (captures comprises) - codes.py effacer-testeur / purger (simulation par defaut) - captures : 30/jour/auteur, 500 Mo au total, 5 Go libres minimum - /__beta/logout en POST avec X-Beta (F5) - 5 tests ajoutes (30 au total) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
7148f3d04b
révision
1228bf47aa
5 fichiers modifiés
+233
-28
Aucun fichier ne correspond à votre recherche
+54
-1
@@ -63,7 +63,7 @@ CREATE TABLE IF NOT EXISTS attempts(
|
||||
CREATE TABLE IF NOT EXISTS audit(
|
||||
id INTEGER PRIMARY KEY, ts REAL NOT NULL, event TEXT NOT NULL, code_id INTEGER, ip_hash TEXT, detail TEXT);
|
||||
CREATE TABLE IF NOT EXISTS feedback(
|
||||
id INTEGER PRIMARY KEY, ts REAL NOT NULL, code_id INTEGER, page TEXT, text TEXT NOT NULL,
|
||||
id INTEGER PRIMARY KEY, ts REAL NOT NULL, code_id INTEGER, tester_id INTEGER, page TEXT, text TEXT NOT NULL,
|
||||
shot TEXT, viewport TEXT, ua TEXT, kind TEXT);
|
||||
CREATE TABLE IF NOT EXISTS testers(
|
||||
id INTEGER PRIMARY KEY, ts REAL NOT NULL, nom TEXT, prenom TEXT, email TEXT, tel TEXT,
|
||||
@@ -109,6 +109,11 @@ def _migrer(c):
|
||||
if "last_seen" not in cols_t:
|
||||
c.execute("ALTER TABLE testers ADD COLUMN last_seen REAL")
|
||||
|
||||
cols_f = [r[1] for r in c.execute("PRAGMA table_info(feedback)").fetchall()]
|
||||
if "tester_id" not in cols_f:
|
||||
c.execute("ALTER TABLE feedback ADD COLUMN tester_id INTEGER")
|
||||
# Avant ce correctif, un testeur libre était rangé dans code_id avec son id de testeur :
|
||||
# impossible de les distinguer à coup sûr, ces lignes anciennes sont laissées telles quelles.
|
||||
cols_s = [r[1] for r in c.execute("PRAGMA table_info(sessions)").fetchall()]
|
||||
if "tester_id" not in cols_s:
|
||||
c.execute("ALTER TABLE sessions ADD COLUMN tester_id INTEGER")
|
||||
@@ -130,6 +135,54 @@ def purger_anciennes_ip(c):
|
||||
pass
|
||||
|
||||
|
||||
def _supprimer_captures(c, where, args):
|
||||
n = 0
|
||||
for r in c.execute(f"SELECT shot FROM feedback WHERE shot IS NOT NULL AND ({where})", args).fetchall():
|
||||
f = Path(str(DATA)) / "retours" / Path(str(r[0])).name # nom de fichier seul, jamais de chemin
|
||||
try:
|
||||
f.unlink()
|
||||
n += 1
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
return n
|
||||
|
||||
|
||||
def effacer_testeur(c, tester_id):
|
||||
"""Effacement individuel (droit RGPD) : testeur, sessions, retours et captures liés. Renvoie le nb de retours."""
|
||||
_supprimer_captures(c, "tester_id=?", (tester_id,))
|
||||
n = c.execute("DELETE FROM feedback WHERE tester_id=?", (tester_id,)).rowcount
|
||||
c.execute("DELETE FROM sessions WHERE tester_id=?", (tester_id,))
|
||||
c.execute("DELETE FROM testers WHERE id=?", (tester_id,))
|
||||
c.commit()
|
||||
return n
|
||||
|
||||
|
||||
def purger(c, avant_ts, journaux_jours=30, audit_jours=183, simulation=True):
|
||||
"""Purge des testeurs inscrits avant `avant_ts` (avec leurs retours et captures), des retours par code
|
||||
antérieurs, des tentatives de plus de `journaux_jours` et du journal de plus de `audit_jours`.
|
||||
Simulation par défaut : renvoie seulement le bilan."""
|
||||
now = time.time()
|
||||
ids = [r[0] for r in c.execute("SELECT id FROM testers WHERE ts < ?", (avant_ts,)).fetchall()]
|
||||
bilan = {
|
||||
"testeurs": len(ids),
|
||||
"retours_testeurs": sum(c.execute("SELECT COUNT(*) FROM feedback WHERE tester_id=?", (i,)).fetchone()[0] for i in ids),
|
||||
"retours_codes": c.execute("SELECT COUNT(*) FROM feedback WHERE tester_id IS NULL AND ts < ?", (avant_ts,)).fetchone()[0],
|
||||
"tentatives": c.execute("SELECT COUNT(*) FROM attempts WHERE ts < ?", (now - journaux_jours * 86400,)).fetchone()[0],
|
||||
"audit": c.execute("SELECT COUNT(*) FROM audit WHERE ts < ?", (now - audit_jours * 86400,)).fetchone()[0],
|
||||
}
|
||||
if simulation:
|
||||
return bilan
|
||||
for i in ids:
|
||||
effacer_testeur(c, i)
|
||||
_supprimer_captures(c, "tester_id IS NULL AND ts < ?", (avant_ts,))
|
||||
c.execute("DELETE FROM feedback WHERE tester_id IS NULL AND ts < ?", (avant_ts,))
|
||||
c.execute("DELETE FROM attempts WHERE ts < ?", (now - journaux_jours * 86400,))
|
||||
c.execute("DELETE FROM audit WHERE ts < ?", (now - audit_jours * 86400,))
|
||||
c.commit()
|
||||
journal(c, "purge", None, None, " ".join(f"{k}={v}" for k, v in bilan.items()))
|
||||
return bilan
|
||||
|
||||
|
||||
def _ouvrir(path, check_same_thread):
|
||||
c = sqlite3.connect(str(path or dossier_prive() / "beta.sqlite"), timeout=10, check_same_thread=check_same_thread)
|
||||
c.row_factory = sqlite3.Row
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur