diff --git a/Excel/dev/Auth/auth_cli.py b/Excel/dev/Auth/auth_cli.py deleted file mode 100644 index 17b8b3c..0000000 --- a/Excel/dev/Auth/auth_cli.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env python3 -import os, sys, argparse, datetime -from pathlib import Path -import mysql.connector, bcrypt - -def load_env_near_exe(): - base = Path(sys.executable).parent if getattr(sys, "frozen", False) else Path(__file__).resolve().parent - env_path = base / ".env" - if env_path.exists(): - for line in env_path.read_text(encoding="utf-8").splitlines(): - line = line.strip() - if not line or line.startswith("#") or "=" not in line: - continue - k, v = line.split("=", 1) - os.environ.setdefault(k.strip(), v.strip()) - -def read_stdin() -> str: - return sys.stdin.read().rstrip("\r\n") - -def main(): - load_env_near_exe() - - ap = argparse.ArgumentParser(description="Auth bcrypt pour Excel") - ap.add_argument("--user", required=True, help="NomUtilisateur (clé primaire)") - ap.add_argument("--password-stdin", action="store_true", help="Lire le mot de passe via STDIN") - ap.add_argument("--debug", action="store_true", help="Afficher les détails de connexion") - args = ap.parse_args() - - if not args.password_stdin: - print("ERR|Utiliser --password-stdin et fournir le mot de passe via STDIN", flush=True); return 2 - - password = read_stdin() - if not password: - print("ERR|Mot de passe vide", flush=True); return 2 - - host = os.getenv("DB_HOST", "localhost") - db = os.getenv("DB_NAME") - user = os.getenv("DB_USER") - pwd = os.getenv("DB_PASSWORD") - port = int(os.getenv("DB_PORT", "3306")) - - ssl_ca = os.getenv("DB_SSL_CA") - ssl_cert = os.getenv("DB_SSL_CERT") - ssl_key = os.getenv("DB_SSL_KEY") - ssl_opts = {} - if ssl_ca: - ssl_opts["ssl_ca"] = ssl_ca - if ssl_cert: ssl_opts["ssl_cert"] = ssl_cert - if ssl_key: ssl_opts["ssl_key"] = ssl_key - - if args.debug: - print(f"DEBUG host={host} port={port} db={db} user={user} ssl={'on' if ssl_opts else 'off'}", flush=True) - - try: - conn = mysql.connector.connect( - host=host, port=port, database=db, user=user, password=pwd, - connection_timeout=6, **ssl_opts - ) - cur = conn.cursor(dictionary=True) - cur.execute(""" - SELECT NomUtilisateur, Nom_complet, Site, MotDePasseHash, DateExpiration - FROM Utilisateurs - WHERE NomUtilisateur = %s - LIMIT 1 - """, (args.user,)) - row = cur.fetchone() - cur.close(); conn.close() - except Exception as e: - print(f"ERR|Connexion base impossible{': ' + str(e) if args.debug else ''}", flush=True) - return 3 - - if not row or not row.get("MotDePasseHash"): - print("ERR|Utilisateur ou mot de passe invalide", flush=True); return 1 - - try: - ok = bcrypt.checkpw(password.encode("utf-8"), row["MotDePasseHash"].encode("ascii")) - except Exception: - ok = False - if not ok: - print("ERR|Utilisateur ou mot de passe invalide", flush=True); return 1 - - exp = row.get("DateExpiration") - if exp is not None: - today = datetime.date.today() - exp_date = exp if hasattr(exp, "year") else getattr(exp, "date", lambda: today)() - if exp_date < today: - print(f"ERR|Compte expiré le {exp_date.isoformat()}", flush=True); return 2 - - site = row.get("Site") or "" - nom = row.get("Nom_complet") or "" - print(f"OK|Site={site}|NomComplet={nom}", flush=True) - return 0 - -if __name__ == "__main__": - sys.exit(main()) diff --git a/Excel/dev/Ratio_dev.xlsm b/Excel/dev/Ratio_dev.xlsm index ce5ca03..ae4adda 100644 Binary files a/Excel/dev/Ratio_dev.xlsm and b/Excel/dev/Ratio_dev.xlsm differ diff --git a/Excel/prod/Ratio_prod.xlsm b/Excel/prod/Ratio_prod.xlsm index 5cd51d6..ae4adda 100644 Binary files a/Excel/prod/Ratio_prod.xlsm and b/Excel/prod/Ratio_prod.xlsm differ