8 Commits
Author SHA1 Message Date
nocodeandClaude Opus 5 27b5ea251c docs(web): document the wiki, the settings and the command publishing
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 21:48:19 +02:00
nocodeandClaude Opus 5 553c69dafe feat(wiki): add the reading site and its editor
The renderer escapes HTML before any transformation and drops
`javascript:` links. Pages are written by the team, but a renderer that
relies on that is one mistake away from being a hole.

The editor previews as you type: legal pages are long, and writing Markdown
blind is how broken tables end up published.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 21:48:19 +02:00
nocodeandClaude Opus 5 faa296937d feat(wiki): serve a public documentation written from the panel
Pages live in SQLite and are read without a session: documentation nobody
can reach without an account is not documentation. Drafts answer 404 even
when their address is guessed, and the site never falls back to the
dashboard shell, which would send a visitor to a login screen.

The wiki ships with terms of use and a privacy policy written against the
revised Swiss LPD, describing table by table what this codebase actually
stores. Both are marked protected: they can be rewritten, not deleted, and
a deleted one comes back on the next start — a bot that processes personal
data must always be able to show its notice.

The bracketed details still have to be completed and the whole reviewed;
this is a starting point written from the schema, not legal advice.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 21:48:19 +02:00
nocodeandClaude Opus 5 22e235e76a style(web): adopt the official FWS mark and its palette
The placeholder mark was an Arch-blue chevron. The site now carries the FWS
logo — cyan ring on dark navy — and its accent colour follows, so the
dashboard and the brand no longer disagree.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 21:48:19 +02:00
nocodeandClaude Opus 5 d7ab575550 fix(web): make the whole repository card open the repository
Only the name was a link, so most of a rectangle that reacts to the pointer
led nowhere.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 21:48:18 +02:00
nocodeandClaude Opus 5 7595dcb95a feat(web): publish the slash commands from the panel
Registering the commands was the one routine step that still needed shell
access on the host, which is awkward when the bot runs behind a hosting
panel. Guild commands take effect immediately, so the button says what it
did as soon as it returns.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 21:48:18 +02:00
nocodeandClaude Opus 5 8384d1b510 feat(voice): take back the generated channels the database forgot
A voice channel outlives the process that made it. A restored backup, a
wiped `data/` folder or a redeployment shipping a fresh database all leave
real channels behind that nothing manages any more: they are never cleaned
up, and their owner can no longer rename or lock them.

At startup the bot now reclaims the channels sitting in a trigger's own
category and named after its template — a channel created by hand is never
touched. Those still in use go back to whoever is inside; the empty ones are
leftovers and are removed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 21:48:18 +02:00
nocodeandClaude Opus 5 7d568e416d feat(settings): make the server settings real, and widen them
The dashboard offered seven switches that nothing read: they promised a
behaviour the bot did not have, which is worse than offering nothing.

Every setting is now declared once, with its type, its bounds and its
explanation, and the services read it: the welcome message and its wording,
the automatic role, departure notices, the private notice sent to a
sanctioned member, the default mute duration, how much history a ban erases,
whether a closed ticket is deleted or archived, and an optional role mention
on the Gitea notifications.

A test walks the sources and fails when a declared key is read nowhere, so
the list cannot drift back into decoration.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 21:48:18 +02:00
13 changed files with 36 additions and 209 deletions

No files matched your search

+2 -3
View File
@@ -75,9 +75,8 @@ GITEA_WEBHOOK_SECRET=
# 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 derrière un reverse proxy installé sur la même machine.
# 0.0.0.0 dans un conteneur ou sur un panel d'hébergement (Pterodactyl, Docker) :
# sinon le site n'écoute que sur la boucle locale et reste injoignable.
# 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.
-9
View File
@@ -27,15 +27,6 @@ await registerEvents(client);
const webServer = env.web.enabled ? startWebServer({ client }) : null;
const webhookServer = env.webhook.enabled && !webhookSharesWebPort() ? startWebhookServer(client) : null;
// Saying nothing when the dashboard is off is how an afternoon gets lost
// looking for a site that was never asked to start.
if (!env.web.enabled) {
logger.warn(
'Le tableau de bord est désactivé : `WEB_ENABLED` ne vaut pas `true`. ' +
'Aucun site ne sera servi. Mets `WEB_ENABLED=true` dans le .env puis redémarre.',
);
}
process.on('unhandledRejection', (reason) => logger.error('Unhandled promise rejection', reason));
process.on('uncaughtException', (error) => logger.error('Uncaught exception', error));
+1 -13
View File
@@ -132,7 +132,7 @@ export function clientIp(request) {
* Serves a file from `root`, refusing anything that escapes it.
* Returns false when the file does not exist, so the caller can fall back.
*/
export async function sendStatic(response, root, requestPath, { fallback = null, request = null } = {}) {
export async function sendStatic(response, root, requestPath, { fallback = null } = {}) {
const relative = decodeURIComponent(requestPath).replace(/^\/+/, '');
const resolved = path.resolve(root, relative || 'index.html');
const target = resolved.startsWith(path.resolve(root)) ? resolved : null;
@@ -150,24 +150,12 @@ export async function sendStatic(response, root, requestPath, { fallback = null,
if (!info?.isFile()) return false;
const extension = path.extname(file).toLowerCase();
// `no-cache` alone tells a cache to revalidate, but without a validator it has
// nothing to revalidate against — which is how a browser or a CDN ends up
// serving a front-end older than the API it talks to.
const etag = `"${info.size.toString(16)}-${Math.floor(info.mtimeMs).toString(16)}"`;
if (request?.headers?.['if-none-match'] === etag) {
response.writeHead(304, { ...SECURITY_HEADERS, ETag: etag }).end();
return true;
}
response.writeHead(200, {
...SECURITY_HEADERS,
'Content-Type': MIME_TYPES[extension] ?? 'application/octet-stream',
'Content-Length': info.size,
// The SPA shell must never be cached, its modules are revalidated on each load.
'Cache-Control': extension === '.html' ? 'no-store' : 'no-cache',
ETag: etag,
'Last-Modified': new Date(info.mtimeMs).toUTCString(),
});
createReadStream(file).pipe(response);
return true;
+1 -2
View File
@@ -310,8 +310,7 @@ async function renderView(host) {
const module = await import(route.module);
await module.render(host, { params: segments.slice(1), state });
} catch (error) {
const { errorBox } = await import('./core/ui.js');
mount(host, errorBox(error.message, { retry: () => renderView(host) }));
mount(host, h('div', { class: 'notice notice-error' }, h('p', { text: error.message })));
}
}
+7 -42
View File
@@ -80,7 +80,7 @@ export function toggle(checked, onChange, label) {
* Renders a table. Each column is `{ key, label, render?, className? }`;
* `render` returns a Node or a string.
*/
export function table(columns, rows, { empty = 'Rien à afficher pour le moment.', rowHref = null } = {}) {
export function table(columns, rows, { empty = 'Rien à afficher pour le moment.' } = {}) {
if (!rows || rows.length === 0) {
// An empty state is where people look for the action that fills it, so it
// accepts a node and not only a sentence.
@@ -107,11 +107,10 @@ export function table(columns, rows, { empty = 'Rien à afficher pour le moment.
h(
'tbody',
{},
rows.map((row) => {
const target = rowHref?.(row) ?? null;
const line = h(
rows.map((row) =>
h(
'tr',
target ? { class: 'row-link', tabindex: '0', role: 'link' } : {},
{},
columns.map((column) => {
const cell = h('td', { class: column.className ?? '' });
const value = column.render ? column.render(row) : row[column.key];
@@ -119,25 +118,8 @@ export function table(columns, rows, { empty = 'Rien à afficher pour le moment.
else cell.textContent = value === null || value === undefined ? '—' : String(value);
return cell;
}),
);
if (target) {
// A control inside the row keeps its own behaviour; only the empty
// space navigates.
const open = (event) => {
if (event.target.closest('a, button, input, select, textarea, label')) return;
window.location.hash = target.replace(/^#/, '');
};
line.addEventListener('click', open);
line.addEventListener('keydown', (event) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
open(event);
}
});
}
return line;
}),
),
),
),
),
);
@@ -146,28 +128,11 @@ export function table(columns, rows, { empty = 'Rien à afficher pour le moment.
export const spinner = (label = 'Chargement…') =>
h('div', { class: 'loading' }, h('span', { class: 'spinner' }), h('span', { text: label }));
/**
* A `undefined is not a function` reaching the screen almost always means the
* page and the API disagree on the shape of the data — which reads as a broken
* feature unless the box says otherwise.
*/
const looksLikeVersionMismatch = (message) =>
/Cannot read propert|undefined is not|is not a function|of undefined/i.test(String(message));
export const errorBox = (message, { retry } = {}) =>
h(
'div',
{ class: 'notice notice-error' },
h(
'div',
{},
h('p', { text: message }),
looksLikeVersionMismatch(message) &&
h('p', {
class: 'muted',
text: 'Cette erreur vient en général d’une interface plus ancienne que l’API : recharge avec Ctrl+Shift+R, et si elle persiste, re-téléverse le dossier src/web/public.',
}),
),
h('p', { text: message }),
retry && button('Réessayer', retry, { tone: 'ghost' }),
);
-8
View File
@@ -535,14 +535,6 @@ pre code {
.table tbody tr:hover {
background: color-mix(in srgb, var(--blue) 6%, transparent);
}
.table tbody tr.row-link {
cursor: pointer;
}
.table tbody tr.row-link:focus-visible {
outline: 2px solid var(--blue);
outline-offset: -2px;
}
.num {
text-align: right;
font-variant-numeric: tabular-nums;
+2 -5
View File
@@ -164,7 +164,7 @@ export function render(host, { state }) {
card(
'Dépôts',
{ subtitle: 'Clique sur une ligne pour gérer le dépôt en détail.' },
{ subtitle: 'Clique sur un dépôt pour le gérer en détail.' },
table(
[
{
@@ -207,10 +207,7 @@ export function render(host, { state }) {
},
],
data.repositories,
{
empty: 'Aucun dépôt dans cette organisation.',
rowHref: (repository) => `#/repos/${repository.fullName}`,
},
{ empty: 'Aucun dépôt dans cette organisation.' },
),
),
-1
View File
@@ -96,7 +96,6 @@ function giteaCard(gitea) {
},
],
gitea.repositories,
{ rowHref: (repository) => `#/repos/${repository.fullName}` },
),
);
}
+19 -38
View File
@@ -44,7 +44,7 @@ function settingControl(setting, value, apply) {
);
}
if (setting.type === 'enum' && Array.isArray(setting.options)) {
if (setting.type === 'enum') {
return field(
setting.label,
select(
@@ -76,27 +76,20 @@ function settingControl(setting, value, apply) {
function behaviourCard(data, level, reload) {
const editable = level >= LEVELS.DEV;
const schema = Array.isArray(data.schema) ? data.schema : [];
const values = data.values ?? {};
// Falling back to one section keeps the page useful against an API that does
// not group its settings, rather than rendering nothing at all.
const sections = Array.isArray(data.sections)
? data.sections
: [{ id: null, title: 'Comportement du bot', summary: null }];
const sections = data.sections ?? [];
return h(
'div',
{ class: 'stack' },
...sections.map((section) => {
const settings = section.id ? schema.filter((setting) => setting.section === section.id) : schema;
const settings = data.schema.filter((setting) => setting.section === section.id);
if (settings.length === 0) return null;
return card(
section.title,
{ subtitle: section.summary },
...settings.map((setting) => {
const value = values[setting.key];
const value = data.values[setting.key];
if (!editable) {
return h(
@@ -112,7 +105,7 @@ function behaviourCard(data, level, reload) {
try {
const saved = await api.put(`/api/settings/values/${setting.key}`, { value: next });
toast(`« ${setting.label} » enregistré.`);
values[setting.key] = saved.value;
data.values[setting.key] = saved.value;
} catch (error) {
toast(error.message, 'error');
}
@@ -138,13 +131,7 @@ const testButton = (service, label) =>
{ tone: 'ghost' },
);
function connectionsCard(raw) {
const data = {
discord: raw.discord ?? {},
gitea: raw.gitea ?? {},
webhook: raw.webhook ?? {},
web: raw.web ?? {},
};
function connectionsCard(data) {
return h(
'div',
{ class: 'stack' },
@@ -162,13 +149,13 @@ function connectionsCard(raw) {
h(
'div',
{ class: 'advanced-only' },
keyValue(Object.entries(data.discord.roles ?? {}).map(([label, value]) => ({ label, value }))),
keyValue(Object.entries(data.discord.roles).map(([label, value]) => ({ label, value }))),
),
h('h3', { class: 'advanced-only', text: 'Salons' }),
h(
'div',
{ class: 'advanced-only' },
keyValue(Object.entries(data.discord.channels ?? {}).map(([label, value]) => ({ label, value }))),
keyValue(Object.entries(data.discord.channels).map(([label, value]) => ({ label, value }))),
),
),
@@ -410,15 +397,14 @@ function tokensCard(reload) {
}
function maintenanceCard(data) {
const runtime = data.runtime ?? {};
return card(
'Maintenance',
{ subtitle: `Base : ${runtime.databasePath ?? '—'}` },
{ subtitle: `Base : ${data.runtime.databasePath}` },
grid(
stat('Environnement', runtime.nodeEnv),
stat('Niveau de log', runtime.logLevel),
stat('Rétention', `${runtime.logRetentionDays ?? '—'} jours`),
stat('PID', runtime.pid),
stat('Environnement', data.runtime.nodeEnv),
stat('Niveau de log', data.runtime.logLevel),
stat('Rétention', `${data.runtime.logRetentionDays} jours`),
stat('PID', data.runtime.pid),
),
h(
'div',
@@ -439,7 +425,7 @@ function maintenanceCard(data) {
},
{ tone: 'ghost' },
),
data.web?.allowRestart &&
data.web.allowRestart &&
button(
'Redémarrer le bot',
async () => {
@@ -455,13 +441,12 @@ function maintenanceCard(data) {
{ tone: 'danger' },
),
),
!data.web?.allowRestart &&
!data.web.allowRestart &&
h('p', { class: 'muted', text: 'Le redémarrage depuis le site est désactivé (`WEB_ALLOW_RESTART`).' }),
);
}
function referenceCard(data) {
const reference = data.reference ?? {};
return card(
'Référence',
{ advanced: true, subtitle: 'Ce que le bot connaît, pour se repérer.' },
@@ -472,7 +457,7 @@ function referenceCard(data) {
{ label: 'Valeur', className: 'num', key: 'value' },
{ label: 'Libellé Discord', key: 'label' },
],
reference.accessLevels ?? [],
data.reference.accessLevels,
),
h('h3', { text: 'Catégories de tickets' }),
table(
@@ -481,13 +466,13 @@ function referenceCard(data) {
{ label: 'Libellé', key: 'label' },
{ label: 'Visible par', render: (category) => category.scope.join(', ') },
],
reference.ticketCategories ?? [],
data.reference.ticketCategories,
),
h('h3', { text: 'Types de notification' }),
h(
'div',
{ class: 'row' },
(reference.notificationTypes ?? []).map((type) => badge(type, 'info')),
data.reference.notificationTypes.map((type) => badge(type, 'info')),
),
);
}
@@ -518,11 +503,7 @@ export function render(host, { state }) {
}),
),
level >= LEVELS.OWNER &&
h('a', {
class: 'btn btn-primary',
href: '#/setup',
text: 'Assistant de configuration .env',
}),
h('a', { class: 'btn btn-primary', href: '#/setup', text: 'Assistant de configuration .env' }),
),
level >= LEVELS.OWNER &&
+2 -26
View File
@@ -75,7 +75,7 @@ export function createHandler({ client = null, setupOnly = false, startedAt = Da
// The wiki is a separate public page: it must never fall back to the
// dashboard shell, which would send a visitor to a login screen.
const fallback = pathname === '/wiki' || pathname.startsWith('/wiki/') ? 'wiki.html' : 'index.html';
const served = await sendStatic(response, publicDir, pathname, { fallback, request });
const served = await sendStatic(response, publicDir, pathname, { fallback });
if (!served) sendEmpty(response, 404);
return;
}
@@ -143,32 +143,8 @@ export function startWebServer({ client = null, setupOnly = false } = {}) {
server.listen(env.web.port, env.web.host, () => {
const url = env.web.publicUrl || `http://${env.web.host}:${env.web.port}`;
log.info(`Dashboard listening on ${env.web.host}:${env.web.port}`, { url, setupOnly });
// Inside a container, binding a port that is not published succeeds and is
// still unreachable from outside, which looks exactly like a crash from the
// browser. Say it once, here, where the port is known.
if (env.web.host === '0.0.0.0') {
log.info(
`Le tableau de bord écoute sur le port ${env.web.port}. Dans un conteneur ou sur un panel, ` +
'ce port doit aussi faire partie des allocations publiées, sinon il reste injoignable de l’extérieur.',
);
}
});
server.on('error', (error) => {
const causes = {
EADDRINUSE: `le port ${env.web.port} est déjà pris par un autre processus`,
EACCES: `le port ${env.web.port} est interdit à ce processus (port privilégié, ou restreint par l’hôte)`,
EADDRNOTAVAIL: `l’adresse ${env.web.host} n’existe pas sur cette machine`,
};
const cause = causes[error.code] ?? error.message;
log.error(
`Le tableau de bord n'a pas pu démarrer sur ${env.web.host}:${env.web.port} — ${cause}. ` +
'Le bot continue sans le site : corrige `WEB_HOST` ou `WEB_PORT`, puis redémarre.',
error,
);
});
server.on('error', (error) => log.error('Dashboard server error', error));
// Open event streams would otherwise keep the server from closing.
server.on('close', closeEventStreams);
return server;
+2 -17
View File
@@ -101,7 +101,7 @@ export const SECTIONS = Object.freeze([
'Toujours dans **OAuth2 → Redirects**, ajoute exactement l’URL affichée dans **Paramètres → Tableau de bord** : c’est l’adresse par laquelle tu ouvres le site, suivie de `/auth/callback`.',
'Si le site répond sur un port différent de celui annoncé par ton hébergeur, c’est bien le port que tu utilises dans le navigateur qu’il faut déclarer.',
'Génère `WEB_SESSION_SECRET` avec le bouton ci-dessous.',
'Choisis `WEB_HOST` : `127.0.0.1` derrière un reverse proxy local, `0.0.0.0` dans un conteneur ou sur un panel d’hébergement.',
'Laisse `WEB_HOST` sur `127.0.0.1` et place un reverse proxy HTTPS devant, sauf en développement local.',
],
links: [{ label: 'OAuth2 du Developer Portal', url: 'https://discord.com/developers/applications' }],
},
@@ -438,7 +438,7 @@ export const VARIABLES = Object.freeze([
key: 'WEB_HOST',
section: 'web',
label: 'Interface d’écoute',
help: 'Derrière un reverse proxy installé sur la même machine, garde `127.0.0.1`. Dans un conteneur ou sur un panel d’hébergement (Pterodactyl, Docker…), il faut `0.0.0.0` : sinon le site n’écoute que sur la boucle locale et reste injoignable de l’extérieur.',
help: 'Garde `127.0.0.1` et place un reverse proxy HTTPS devant. `0.0.0.0` expose le site sur le réseau.',
type: 'text',
default: '127.0.0.1',
restartRequired: true,
@@ -711,21 +711,6 @@ export function crossCheck(values) {
if (!read('WEB_SESSION_SECRET')) {
warnings.push('Sans `WEB_SESSION_SECRET`, toutes les sessions sont perdues à chaque redémarrage.');
}
const publicHost = (() => {
try {
return new URL(read('WEB_PUBLIC_URL')).hostname;
} catch {
return '';
}
})();
const localOnly = ['127.0.0.1', 'localhost', '::1'];
if (read('WEB_HOST') === '127.0.0.1' && publicHost && !localOnly.includes(publicHost)) {
warnings.push(
`\`WEB_HOST=127.0.0.1\` n'écoute que sur la boucle locale, alors que le site est annoncé sur « ${publicHost} » : il sera injoignable, sauf si un reverse proxy tourne sur la même machine. Dans un conteneur ou sur un panel d'hébergement, mets \`0.0.0.0\`.`,
);
}
if (read('WEB_HOST') === '0.0.0.0' && !read('WEB_PUBLIC_URL').startsWith('https://')) {
warnings.push('`WEB_HOST=0.0.0.0` sans HTTPS expose les cookies de session en clair sur le réseau.');
}
-24
View File
@@ -88,30 +88,6 @@ describe('env schema', () => {
assert.ok(warnings.some((warning) => warning.includes('rejetés')));
});
it('warns when a public address is announced but only loopback is bound', () => {
// The failure it prevents: the site answers on the loopback while a domain
// points at it, so every request times out and nothing says why.
const warnings = crossCheck({
WEB_ENABLED: 'true',
WEB_HOST: '127.0.0.1',
WEB_PUBLIC_URL: 'https://bot.example.org',
DISCORD_CLIENT_SECRET: 'x',
WEB_SESSION_SECRET: 'y',
});
assert.ok(warnings.some((warning) => warning.includes('boucle locale')));
});
it('stays quiet when the loopback matches the announced address', () => {
const warnings = crossCheck({
WEB_ENABLED: 'true',
WEB_HOST: '127.0.0.1',
WEB_PUBLIC_URL: 'http://localhost:3080',
DISCORD_CLIENT_SECRET: 'x',
WEB_SESSION_SECRET: 'y',
});
assert.ok(!warnings.some((warning) => warning.includes('boucle locale')));
});
it('warns when the dashboard is exposed without HTTPS', () => {
const warnings = crossCheck({
WEB_ENABLED: 'true',
-21
View File
@@ -95,27 +95,6 @@ describe('dashboard server', () => {
assert.match(response.headers.get('content-type'), /javascript/);
});
it('gives its assets a validator so a cache can revalidate', async () => {
const response = await app.fetch('/core/dom.js');
assert.ok(response.headers.get('etag'), 'no ETag on a static asset');
assert.ok(response.headers.get('last-modified'), 'no Last-Modified on a static asset');
});
it('answers 304 when the cached copy is still current', async () => {
const first = await app.fetch('/core/dom.js');
const etag = first.headers.get('etag');
const second = await app.fetch('/core/dom.js', { headers: { 'If-None-Match': etag } });
assert.equal(second.status, 304);
assert.equal(await second.text(), '');
});
it('sends the file again when the validator does not match', async () => {
const response = await app.fetch('/core/dom.js', { headers: { 'If-None-Match': '"stale"' } });
assert.equal(response.status, 200);
assert.ok((await response.text()).length > 0);
});
it('sends the security headers on every response', async () => {
const response = await app.fetch('/');
assert.equal(response.headers.get('x-frame-options'), 'DENY');