From 203461033589acc589aac7907d22bcd1c01d6b5d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o=20Gastinel?=
<264859180+gastinelt@users.noreply.github.com>
Date: Thu, 29 Oct 2026 11:56:34 +0100
Subject: [PATCH] feat(beta): formulaire et gate autonomes, deploiement dns
---
.gitignore | 2 +
beta/db.py | 47 +-
beta/deploiement/dns-jobrunner-beta.py | 81 ++
beta/static/formulaire.html | 1033 ++++++++++++++++++++++--
beta/static/gate.html | 694 +++++++++++++++-
beta/static/pages.css | 651 ++++++++++++++-
6 files changed, 2406 insertions(+), 102 deletions(-)
create mode 100644 beta/deploiement/dns-jobrunner-beta.py
diff --git a/.gitignore b/.gitignore
index e7ad981..0192aed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,3 +34,5 @@ WhatsApp Video*.mp4
# Bêta testeurs : base locale, captures, codes émis (jamais dans git)
beta/data/
beta/pdf/*.ttf
+__pycache__/
+*.pyc
diff --git a/beta/db.py b/beta/db.py
index 8026520..172a7d7 100644
--- a/beta/db.py
+++ b/beta/db.py
@@ -14,9 +14,40 @@ import time
from pathlib import Path
ICI = Path(__file__).resolve().parent
-DATA = Path(os.environ.get("BETA_DATA", ICI / "data"))
ALPHABET = "ABCDEFGHJKMNPQRSTUVWXYZ23456789" # sans I, L, O, 0, 1
+
+def dossier_data():
+ return Path(os.environ.get("BETA_DATA", ICI / "data"))
+
+
+def dossier_prive():
+ """Dossier de données en 0700 (sous Windows, chmod est sans effet : voir README)."""
+ d = dossier_data()
+ d.mkdir(mode=0o700, parents=True, exist_ok=True)
+ try:
+ os.chmod(d, 0o700)
+ except OSError:
+ pass
+ return d
+
+
+class _DataProxy:
+ def __truediv__(self, other):
+ return dossier_data() / other
+
+ def __getattr__(self, name):
+ return getattr(dossier_data(), name)
+
+ def __fspath__(self):
+ return str(dossier_data())
+
+ def __str__(self):
+ return str(dossier_data())
+
+
+DATA = _DataProxy()
+
SCHEMA = """
CREATE TABLE IF NOT EXISTS codes(
id INTEGER PRIMARY KEY, label TEXT NOT NULL, code_hash TEXT NOT NULL,
@@ -52,15 +83,6 @@ CREATE TABLE IF NOT EXISTS demo_activity(
"""
-def dossier_prive():
- """Dossier de données en 0700 (sous Windows, chmod est sans effet : voir README)."""
- DATA.mkdir(mode=0o700, parents=True, exist_ok=True)
- try:
- os.chmod(DATA, 0o700)
- except OSError:
- pass
-
-
def connect(path=None, check_same_thread=True):
dossier_prive()
ancien = os.umask(0o077) # base, -wal et -shm créés en 0600
@@ -72,7 +94,7 @@ def connect(path=None, check_same_thread=True):
def _ouvrir(path, check_same_thread):
- c = sqlite3.connect(str(path or DATA / "beta.sqlite"), timeout=10, check_same_thread=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
c.execute("PRAGMA journal_mode=WAL")
c.executescript(SCHEMA)
@@ -81,8 +103,7 @@ def _ouvrir(path, check_same_thread):
def sel():
"""Sel local (créé au premier usage, hors git, jamais affiché)."""
- f = DATA / "sel.bin"
- dossier_prive()
+ f = dossier_prive() / "sel.bin"
try:
fd = os.open(f, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
with os.fdopen(fd, "wb") as fh:
diff --git a/beta/deploiement/dns-jobrunner-beta.py b/beta/deploiement/dns-jobrunner-beta.py
new file mode 100644
index 0000000..4a9a413
--- /dev/null
+++ b/beta/deploiement/dns-jobrunner-beta.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python3
+"""Ajoute l'enregistrement A beta.jobrunner.fr via l'API Infomaniak (à lancer sur cornafsuisse).
+
+Le jeton est lu dans ~/.config/infomaniak/api_token, jamais affiché ni écrit ailleurs.
+Mode par défaut : lecture seule + sauvegarde de la zone. --ajouter pour créer la ligne.
+"""
+import json
+import os
+import sys
+import time
+import urllib.error
+import urllib.request
+
+DOMAINE = "jobrunner.fr"
+SOURCE = "beta"
+CIBLE = "179.237.102.233"
+TTL = 300
+BASE = "https://api.infomaniak.com/2"
+
+
+def appel(methode, chemin, jeton, corps=None):
+ donnees = json.dumps(corps).encode() if corps is not None else None
+ req = urllib.request.Request(BASE + chemin, data=donnees, method=methode)
+ req.add_header("Authorization", "Bearer " + jeton)
+ req.add_header("Accept", "application/json")
+ if donnees is not None:
+ req.add_header("Content-Type", "application/json")
+ try:
+ with urllib.request.urlopen(req, timeout=20) as r:
+ return json.loads(r.read().decode())
+ except urllib.error.HTTPError as e:
+ try:
+ return json.loads(e.read().decode())
+ except Exception:
+ return {"result": "error", "error": {"code": "http_%d" % e.code}}
+
+
+def main():
+ ajouter = "--ajouter" in sys.argv
+ chemin_jeton = os.path.expanduser("~/.config/infomaniak/api_token")
+ with open(chemin_jeton, encoding="utf-8") as f:
+ jeton = f.read().strip()
+
+ zone = appel("GET", "/zones/%s/records" % DOMAINE, jeton)
+ if zone.get("result") != "success":
+ print("Erreur API (lecture) :", (zone.get("error") or {}).get("description") or (zone.get("error") or {}).get("code"))
+ return 1
+
+ dossier = os.path.expanduser("~/sauvegardes/dns")
+ os.makedirs(dossier, exist_ok=True)
+ nom = os.path.join(dossier, "zone-avant-jobrunner-beta-%s.json" % time.strftime("%Y%m%d-%H%M%S"))
+ with open(nom, "w", encoding="utf-8") as f:
+ json.dump(zone, f, ensure_ascii=False, indent=1)
+ os.chmod(nom, 0o600)
+ print("Sauvegarde de la zone :", nom, "(%d enregistrements)" % len(zone["data"]))
+
+ existants = [r for r in zone["data"] if r.get("source") == SOURCE]
+ print("Lignes A de la zone :")
+ for r in zone["data"]:
+ if r.get("type") == "A":
+ src = "@" if r.get("source") in ("", ".") else r.get("source")
+ print(" A %-12s -> %s (ttl %s)" % (src, r.get("target"), r.get("ttl")))
+ if existants:
+ print("Une ligne '%s' existe déjà :" % SOURCE, [(r["type"], r["target"]) for r in existants])
+ return 0
+
+ if not ajouter:
+ print("Simulation : '%s' absent. Relance avec --ajouter pour créer A %s -> %s." % (SOURCE, SOURCE, CIBLE))
+ return 0
+
+ rep = appel("POST", "/zones/%s/records" % DOMAINE, jeton,
+ {"type": "A", "source": SOURCE, "target": CIBLE, "ttl": TTL})
+ if rep.get("result") == "success":
+ print("OK : A %s.%s -> %s créé." % (SOURCE, DOMAINE, CIBLE))
+ return 0
+ print("Erreur API (création) :", (rep.get("error") or {}).get("description") or (rep.get("error") or {}).get("code"))
+ return 1
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/beta/static/formulaire.html b/beta/static/formulaire.html
index 34bf5a6..99204cf 100644
--- a/beta/static/formulaire.html
+++ b/beta/static/formulaire.html
@@ -2,59 +2,998 @@
-
-
-Formulaire testeur · JobRunner bêta
-
-
-
+
+
+Rejoindre la Bêta · JobRunner
+
+
+
-
- Devenir testeur de la bêta
- Vous testez une version d'essai de JobRunner : tout y est fictif et aucun paiement n'est réel. Vous nous dites ce qu'il faut garder ou changer.
- Contrepartie envisagée : suivre JobRunner sur les réseaux sociaux et, sous réserve de confirmation , 1 an de Pass premium. Ce n'est pas encore une promesse ferme.
- Version PDF à remplir : formulaire-testeur-jobrunner.pdf
-