diff --git a/.env.example b/.env.example index 1af6ff3..fbc64ce 100644 --- a/.env.example +++ b/.env.example @@ -71,6 +71,33 @@ WEBHOOK_PATH=/webhooks/gitea # Shared secret configured in Gitea > Settings > Webhooks GITEA_WEBHOOK_SECRET= +# --- Tableau de bord web (M16) ----------------------------------------------- +# Site d'administration servi par le bot : `npm run setup` pour l'assistant .env, +# puis http://WEB_HOST:WEB_PORT une fois le bot démarré. +WEB_ENABLED=false +# 127.0.0.1 par défaut : n'expose rien hors de la machine. Mettre 0.0.0.0 seulement +# derrière un reverse proxy HTTPS. +WEB_HOST=127.0.0.1 +WEB_PORT=3080 +# URL publique du tableau de bord, utilisée pour la redirection OAuth2 Discord. +# Doit correspondre exactement à une redirection déclarée dans le Developer Portal. +WEB_PUBLIC_URL=http://localhost:3080 +# Clé de signature des cookies de session (64 caractères hex). +# Générer avec : node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))" +WEB_SESSION_SECRET= +WEB_SESSION_TTL_HOURS=12 +# Developer Portal > OAuth2 > Client Secret. Requis pour la connexion au tableau de bord. +DISCORD_CLIENT_SECRET= +# Jeton d'amorçage : ouvre l'assistant de configuration sans compte Discord. +# À vider une fois le .env rempli. +WEB_SETUP_TOKEN= +# Autorise les cibles de déploiement de type « commande shell » (Owner uniquement). +WEB_ALLOW_COMMAND_DEPLOYS=false +# Autorise le bouton « Redémarrer le bot » (nécessite un superviseur type systemd/pm2). +WEB_ALLOW_RESTART=false +WEB_DEPLOY_TIMEOUT_MS=900000 +WEB_RATE_LIMIT_PER_MINUTE=240 + # --- SQLite (M1-T05) --------------------------------------------------------- DATABASE_PATH=./data/fws-bot.sqlite BACKUP_DIR=./data/backups diff --git a/src/config/env.js b/src/config/env.js index e08c0c7..72d4d98 100644 --- a/src/config/env.js +++ b/src/config/env.js @@ -79,6 +79,23 @@ export const env = Object.freeze({ secret: read('GITEA_WEBHOOK_SECRET'), }, + web: { + enabled: readBool('WEB_ENABLED'), + host: read('WEB_HOST', '127.0.0.1'), + port: readInt('WEB_PORT', 3080), + publicUrl: read('WEB_PUBLIC_URL', '').replace(/\/+$/, ''), + sessionSecret: read('WEB_SESSION_SECRET'), + sessionTtlHours: readInt('WEB_SESSION_TTL_HOURS', 12), + oauthClientSecret: read('DISCORD_CLIENT_SECRET'), + setupToken: read('WEB_SETUP_TOKEN'), + // Running shell commands from a browser is the most dangerous capability of the + // dashboard, so it stays off until it is explicitly enabled (M16-T06). + allowCommandDeploys: readBool('WEB_ALLOW_COMMAND_DEPLOYS'), + allowRestart: readBool('WEB_ALLOW_RESTART'), + deployTimeoutMs: readInt('WEB_DEPLOY_TIMEOUT_MS', 900_000), + rateLimitPerMinute: readInt('WEB_RATE_LIMIT_PER_MINUTE', 240), + }, + database: { path: read('DATABASE_PATH', './data/fws-bot.sqlite'), backupDir: read('BACKUP_DIR', './data/backups'), @@ -93,7 +110,14 @@ export const env = Object.freeze({ }); /** Values that must never appear in Discord messages or logs. */ -export const secrets = [env.discord.token, env.gitea.token, env.webhook.secret].filter(Boolean); +export const secrets = [ + env.discord.token, + env.gitea.token, + env.webhook.secret, + env.web.sessionSecret, + env.web.oauthClientSecret, + env.web.setupToken, +].filter(Boolean); export function assertRequiredEnv(keys) { const missing = keys.filter((key) => !read(key));