Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1fb846d51
|
||
|
|
2b4e6f356a
|
||
|
|
405692f228
|
||
|
|
dd53c79b39
|
||
|
|
8503b41d51
|
||
|
|
f93c559a47
|
||
|
|
3d55abcb11
|
||
|
|
748a8c19e1
|
||
|
|
ce1c0f2910
|
||
|
|
2eade4dfc4
|
||
|
|
1b6aa3dd63
|
||
|
|
d518f9fd56
|
||
|
|
a61f446e44
|
||
|
|
52a5c50692
|
No files matched your search
+3
-2
@@ -75,8 +75,9 @@ GITEA_WEBHOOK_SECRET=
|
|||||||
# Site d'administration servi par le bot : `npm run setup` pour l'assistant .env,
|
# 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é.
|
# puis http://WEB_HOST:WEB_PORT une fois le bot démarré.
|
||||||
WEB_ENABLED=false
|
WEB_ENABLED=false
|
||||||
# 127.0.0.1 par défaut : n'expose rien hors de la machine. Mettre 0.0.0.0 seulement
|
# 127.0.0.1 derrière un reverse proxy installé sur la même machine.
|
||||||
# derrière un reverse proxy HTTPS.
|
# 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.
|
||||||
WEB_HOST=127.0.0.1
|
WEB_HOST=127.0.0.1
|
||||||
WEB_PORT=3080
|
WEB_PORT=3080
|
||||||
# URL publique du tableau de bord, utilisée pour la redirection OAuth2 Discord.
|
# URL publique du tableau de bord, utilisée pour la redirection OAuth2 Discord.
|
||||||
|
|||||||
@@ -27,6 +27,15 @@ await registerEvents(client);
|
|||||||
const webServer = env.web.enabled ? startWebServer({ client }) : null;
|
const webServer = env.web.enabled ? startWebServer({ client }) : null;
|
||||||
const webhookServer = env.webhook.enabled && !webhookSharesWebPort() ? startWebhookServer(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('unhandledRejection', (reason) => logger.error('Unhandled promise rejection', reason));
|
||||||
process.on('uncaughtException', (error) => logger.error('Uncaught exception', error));
|
process.on('uncaughtException', (error) => logger.error('Uncaught exception', error));
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -132,7 +132,7 @@ export function clientIp(request) {
|
|||||||
* Serves a file from `root`, refusing anything that escapes it.
|
* Serves a file from `root`, refusing anything that escapes it.
|
||||||
* Returns false when the file does not exist, so the caller can fall back.
|
* Returns false when the file does not exist, so the caller can fall back.
|
||||||
*/
|
*/
|
||||||
export async function sendStatic(response, root, requestPath, { fallback = null } = {}) {
|
export async function sendStatic(response, root, requestPath, { fallback = null, request = null } = {}) {
|
||||||
const relative = decodeURIComponent(requestPath).replace(/^\/+/, '');
|
const relative = decodeURIComponent(requestPath).replace(/^\/+/, '');
|
||||||
const resolved = path.resolve(root, relative || 'index.html');
|
const resolved = path.resolve(root, relative || 'index.html');
|
||||||
const target = resolved.startsWith(path.resolve(root)) ? resolved : null;
|
const target = resolved.startsWith(path.resolve(root)) ? resolved : null;
|
||||||
@@ -150,12 +150,24 @@ export async function sendStatic(response, root, requestPath, { fallback = null
|
|||||||
if (!info?.isFile()) return false;
|
if (!info?.isFile()) return false;
|
||||||
|
|
||||||
const extension = path.extname(file).toLowerCase();
|
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, {
|
response.writeHead(200, {
|
||||||
...SECURITY_HEADERS,
|
...SECURITY_HEADERS,
|
||||||
'Content-Type': MIME_TYPES[extension] ?? 'application/octet-stream',
|
'Content-Type': MIME_TYPES[extension] ?? 'application/octet-stream',
|
||||||
'Content-Length': info.size,
|
'Content-Length': info.size,
|
||||||
// The SPA shell must never be cached, its modules are revalidated on each load.
|
// The SPA shell must never be cached, its modules are revalidated on each load.
|
||||||
'Cache-Control': extension === '.html' ? 'no-store' : 'no-cache',
|
'Cache-Control': extension === '.html' ? 'no-store' : 'no-cache',
|
||||||
|
ETag: etag,
|
||||||
|
'Last-Modified': new Date(info.mtimeMs).toUTCString(),
|
||||||
});
|
});
|
||||||
createReadStream(file).pipe(response);
|
createReadStream(file).pipe(response);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -310,7 +310,8 @@ async function renderView(host) {
|
|||||||
const module = await import(route.module);
|
const module = await import(route.module);
|
||||||
await module.render(host, { params: segments.slice(1), state });
|
await module.render(host, { params: segments.slice(1), state });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
mount(host, h('div', { class: 'notice notice-error' }, h('p', { text: error.message })));
|
const { errorBox } = await import('./core/ui.js');
|
||||||
|
mount(host, errorBox(error.message, { retry: () => renderView(host) }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ export function toggle(checked, onChange, label) {
|
|||||||
* Renders a table. Each column is `{ key, label, render?, className? }`;
|
* Renders a table. Each column is `{ key, label, render?, className? }`;
|
||||||
* `render` returns a Node or a string.
|
* `render` returns a Node or a string.
|
||||||
*/
|
*/
|
||||||
export function table(columns, rows, { empty = 'Rien à afficher pour le moment.' } = {}) {
|
export function table(columns, rows, { empty = 'Rien à afficher pour le moment.', rowHref = null } = {}) {
|
||||||
if (!rows || rows.length === 0) {
|
if (!rows || rows.length === 0) {
|
||||||
// An empty state is where people look for the action that fills it, so it
|
// An empty state is where people look for the action that fills it, so it
|
||||||
// accepts a node and not only a sentence.
|
// accepts a node and not only a sentence.
|
||||||
@@ -107,10 +107,11 @@ export function table(columns, rows, { empty = 'Rien à afficher pour le moment.
|
|||||||
h(
|
h(
|
||||||
'tbody',
|
'tbody',
|
||||||
{},
|
{},
|
||||||
rows.map((row) =>
|
rows.map((row) => {
|
||||||
h(
|
const target = rowHref?.(row) ?? null;
|
||||||
|
const line = h(
|
||||||
'tr',
|
'tr',
|
||||||
{},
|
target ? { class: 'row-link', tabindex: '0', role: 'link' } : {},
|
||||||
columns.map((column) => {
|
columns.map((column) => {
|
||||||
const cell = h('td', { class: column.className ?? '' });
|
const cell = h('td', { class: column.className ?? '' });
|
||||||
const value = column.render ? column.render(row) : row[column.key];
|
const value = column.render ? column.render(row) : row[column.key];
|
||||||
@@ -118,8 +119,25 @@ export function table(columns, rows, { empty = 'Rien à afficher pour le moment.
|
|||||||
else cell.textContent = value === null || value === undefined ? '—' : String(value);
|
else cell.textContent = value === null || value === undefined ? '—' : String(value);
|
||||||
return cell;
|
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;
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -128,11 +146,28 @@ export function table(columns, rows, { empty = 'Rien à afficher pour le moment.
|
|||||||
export const spinner = (label = 'Chargement…') =>
|
export const spinner = (label = 'Chargement…') =>
|
||||||
h('div', { class: 'loading' }, h('span', { class: 'spinner' }), h('span', { text: label }));
|
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 } = {}) =>
|
export const errorBox = (message, { retry } = {}) =>
|
||||||
h(
|
h(
|
||||||
'div',
|
'div',
|
||||||
{ class: 'notice notice-error' },
|
{ class: 'notice notice-error' },
|
||||||
h('p', { text: message }),
|
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.',
|
||||||
|
}),
|
||||||
|
),
|
||||||
retry && button('Réessayer', retry, { tone: 'ghost' }),
|
retry && button('Réessayer', retry, { tone: 'ghost' }),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -535,6 +535,14 @@ pre code {
|
|||||||
.table tbody tr:hover {
|
.table tbody tr:hover {
|
||||||
background: color-mix(in srgb, var(--blue) 6%, transparent);
|
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 {
|
.num {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
font-variant-numeric: tabular-nums;
|
font-variant-numeric: tabular-nums;
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ export function render(host, { state }) {
|
|||||||
|
|
||||||
card(
|
card(
|
||||||
'Dépôts',
|
'Dépôts',
|
||||||
{ subtitle: 'Clique sur un dépôt pour le gérer en détail.' },
|
{ subtitle: 'Clique sur une ligne pour gérer le dépôt en détail.' },
|
||||||
table(
|
table(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -207,7 +207,10 @@ export function render(host, { state }) {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
data.repositories,
|
data.repositories,
|
||||||
{ empty: 'Aucun dépôt dans cette organisation.' },
|
{
|
||||||
|
empty: 'Aucun dépôt dans cette organisation.',
|
||||||
|
rowHref: (repository) => `#/repos/${repository.fullName}`,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ function giteaCard(gitea) {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
gitea.repositories,
|
gitea.repositories,
|
||||||
|
{ rowHref: (repository) => `#/repos/${repository.fullName}` },
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ function settingControl(setting, value, apply) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setting.type === 'enum') {
|
if (setting.type === 'enum' && Array.isArray(setting.options)) {
|
||||||
return field(
|
return field(
|
||||||
setting.label,
|
setting.label,
|
||||||
select(
|
select(
|
||||||
@@ -76,20 +76,27 @@ function settingControl(setting, value, apply) {
|
|||||||
|
|
||||||
function behaviourCard(data, level, reload) {
|
function behaviourCard(data, level, reload) {
|
||||||
const editable = level >= LEVELS.DEV;
|
const editable = level >= LEVELS.DEV;
|
||||||
const sections = data.sections ?? [];
|
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 }];
|
||||||
|
|
||||||
return h(
|
return h(
|
||||||
'div',
|
'div',
|
||||||
{ class: 'stack' },
|
{ class: 'stack' },
|
||||||
...sections.map((section) => {
|
...sections.map((section) => {
|
||||||
const settings = data.schema.filter((setting) => setting.section === section.id);
|
const settings = section.id ? schema.filter((setting) => setting.section === section.id) : schema;
|
||||||
if (settings.length === 0) return null;
|
if (settings.length === 0) return null;
|
||||||
|
|
||||||
return card(
|
return card(
|
||||||
section.title,
|
section.title,
|
||||||
{ subtitle: section.summary },
|
{ subtitle: section.summary },
|
||||||
...settings.map((setting) => {
|
...settings.map((setting) => {
|
||||||
const value = data.values[setting.key];
|
const value = values[setting.key];
|
||||||
|
|
||||||
if (!editable) {
|
if (!editable) {
|
||||||
return h(
|
return h(
|
||||||
@@ -105,7 +112,7 @@ function behaviourCard(data, level, reload) {
|
|||||||
try {
|
try {
|
||||||
const saved = await api.put(`/api/settings/values/${setting.key}`, { value: next });
|
const saved = await api.put(`/api/settings/values/${setting.key}`, { value: next });
|
||||||
toast(`« ${setting.label} » enregistré.`);
|
toast(`« ${setting.label} » enregistré.`);
|
||||||
data.values[setting.key] = saved.value;
|
values[setting.key] = saved.value;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast(error.message, 'error');
|
toast(error.message, 'error');
|
||||||
}
|
}
|
||||||
@@ -131,7 +138,13 @@ const testButton = (service, label) =>
|
|||||||
{ tone: 'ghost' },
|
{ tone: 'ghost' },
|
||||||
);
|
);
|
||||||
|
|
||||||
function connectionsCard(data) {
|
function connectionsCard(raw) {
|
||||||
|
const data = {
|
||||||
|
discord: raw.discord ?? {},
|
||||||
|
gitea: raw.gitea ?? {},
|
||||||
|
webhook: raw.webhook ?? {},
|
||||||
|
web: raw.web ?? {},
|
||||||
|
};
|
||||||
return h(
|
return h(
|
||||||
'div',
|
'div',
|
||||||
{ class: 'stack' },
|
{ class: 'stack' },
|
||||||
@@ -149,13 +162,13 @@ function connectionsCard(data) {
|
|||||||
h(
|
h(
|
||||||
'div',
|
'div',
|
||||||
{ class: 'advanced-only' },
|
{ 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('h3', { class: 'advanced-only', text: 'Salons' }),
|
||||||
h(
|
h(
|
||||||
'div',
|
'div',
|
||||||
{ class: 'advanced-only' },
|
{ 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 }))),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -397,14 +410,15 @@ function tokensCard(reload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function maintenanceCard(data) {
|
function maintenanceCard(data) {
|
||||||
|
const runtime = data.runtime ?? {};
|
||||||
return card(
|
return card(
|
||||||
'Maintenance',
|
'Maintenance',
|
||||||
{ subtitle: `Base : ${data.runtime.databasePath}` },
|
{ subtitle: `Base : ${runtime.databasePath ?? '—'}` },
|
||||||
grid(
|
grid(
|
||||||
stat('Environnement', data.runtime.nodeEnv),
|
stat('Environnement', runtime.nodeEnv),
|
||||||
stat('Niveau de log', data.runtime.logLevel),
|
stat('Niveau de log', runtime.logLevel),
|
||||||
stat('Rétention', `${data.runtime.logRetentionDays} jours`),
|
stat('Rétention', `${runtime.logRetentionDays ?? '—'} jours`),
|
||||||
stat('PID', data.runtime.pid),
|
stat('PID', runtime.pid),
|
||||||
),
|
),
|
||||||
h(
|
h(
|
||||||
'div',
|
'div',
|
||||||
@@ -425,7 +439,7 @@ function maintenanceCard(data) {
|
|||||||
},
|
},
|
||||||
{ tone: 'ghost' },
|
{ tone: 'ghost' },
|
||||||
),
|
),
|
||||||
data.web.allowRestart &&
|
data.web?.allowRestart &&
|
||||||
button(
|
button(
|
||||||
'Redémarrer le bot',
|
'Redémarrer le bot',
|
||||||
async () => {
|
async () => {
|
||||||
@@ -441,12 +455,13 @@ function maintenanceCard(data) {
|
|||||||
{ tone: 'danger' },
|
{ 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`).' }),
|
h('p', { class: 'muted', text: 'Le redémarrage depuis le site est désactivé (`WEB_ALLOW_RESTART`).' }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function referenceCard(data) {
|
function referenceCard(data) {
|
||||||
|
const reference = data.reference ?? {};
|
||||||
return card(
|
return card(
|
||||||
'Référence',
|
'Référence',
|
||||||
{ advanced: true, subtitle: 'Ce que le bot connaît, pour se repérer.' },
|
{ advanced: true, subtitle: 'Ce que le bot connaît, pour se repérer.' },
|
||||||
@@ -457,7 +472,7 @@ function referenceCard(data) {
|
|||||||
{ label: 'Valeur', className: 'num', key: 'value' },
|
{ label: 'Valeur', className: 'num', key: 'value' },
|
||||||
{ label: 'Libellé Discord', key: 'label' },
|
{ label: 'Libellé Discord', key: 'label' },
|
||||||
],
|
],
|
||||||
data.reference.accessLevels,
|
reference.accessLevels ?? [],
|
||||||
),
|
),
|
||||||
h('h3', { text: 'Catégories de tickets' }),
|
h('h3', { text: 'Catégories de tickets' }),
|
||||||
table(
|
table(
|
||||||
@@ -466,13 +481,13 @@ function referenceCard(data) {
|
|||||||
{ label: 'Libellé', key: 'label' },
|
{ label: 'Libellé', key: 'label' },
|
||||||
{ label: 'Visible par', render: (category) => category.scope.join(', ') },
|
{ label: 'Visible par', render: (category) => category.scope.join(', ') },
|
||||||
],
|
],
|
||||||
data.reference.ticketCategories,
|
reference.ticketCategories ?? [],
|
||||||
),
|
),
|
||||||
h('h3', { text: 'Types de notification' }),
|
h('h3', { text: 'Types de notification' }),
|
||||||
h(
|
h(
|
||||||
'div',
|
'div',
|
||||||
{ class: 'row' },
|
{ class: 'row' },
|
||||||
data.reference.notificationTypes.map((type) => badge(type, 'info')),
|
(reference.notificationTypes ?? []).map((type) => badge(type, 'info')),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -503,7 +518,11 @@ export function render(host, { state }) {
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
level >= LEVELS.OWNER &&
|
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 &&
|
level >= LEVELS.OWNER &&
|
||||||
|
|||||||
+26
-2
@@ -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
|
// 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.
|
// dashboard shell, which would send a visitor to a login screen.
|
||||||
const fallback = pathname === '/wiki' || pathname.startsWith('/wiki/') ? 'wiki.html' : 'index.html';
|
const fallback = pathname === '/wiki' || pathname.startsWith('/wiki/') ? 'wiki.html' : 'index.html';
|
||||||
const served = await sendStatic(response, publicDir, pathname, { fallback });
|
const served = await sendStatic(response, publicDir, pathname, { fallback, request });
|
||||||
if (!served) sendEmpty(response, 404);
|
if (!served) sendEmpty(response, 404);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -143,8 +143,32 @@ export function startWebServer({ client = null, setupOnly = false } = {}) {
|
|||||||
server.listen(env.web.port, env.web.host, () => {
|
server.listen(env.web.port, env.web.host, () => {
|
||||||
const url = env.web.publicUrl || `http://${env.web.host}:${env.web.port}`;
|
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 });
|
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.
|
// Open event streams would otherwise keep the server from closing.
|
||||||
server.on('close', closeEventStreams);
|
server.on('close', closeEventStreams);
|
||||||
return server;
|
return server;
|
||||||
|
|||||||
@@ -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`.',
|
'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.',
|
'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.',
|
'Génère `WEB_SESSION_SECRET` avec le bouton ci-dessous.',
|
||||||
'Laisse `WEB_HOST` sur `127.0.0.1` et place un reverse proxy HTTPS devant, sauf en développement local.',
|
'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.',
|
||||||
],
|
],
|
||||||
links: [{ label: 'OAuth2 du Developer Portal', url: 'https://discord.com/developers/applications' }],
|
links: [{ label: 'OAuth2 du Developer Portal', url: 'https://discord.com/developers/applications' }],
|
||||||
},
|
},
|
||||||
@@ -438,7 +438,7 @@ export const VARIABLES = Object.freeze([
|
|||||||
key: 'WEB_HOST',
|
key: 'WEB_HOST',
|
||||||
section: 'web',
|
section: 'web',
|
||||||
label: 'Interface d’écoute',
|
label: 'Interface d’écoute',
|
||||||
help: 'Garde `127.0.0.1` et place un reverse proxy HTTPS devant. `0.0.0.0` expose le site sur le réseau.',
|
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.',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
default: '127.0.0.1',
|
default: '127.0.0.1',
|
||||||
restartRequired: true,
|
restartRequired: true,
|
||||||
@@ -711,6 +711,21 @@ export function crossCheck(values) {
|
|||||||
if (!read('WEB_SESSION_SECRET')) {
|
if (!read('WEB_SESSION_SECRET')) {
|
||||||
warnings.push('Sans `WEB_SESSION_SECRET`, toutes les sessions sont perdues à chaque redémarrage.');
|
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://')) {
|
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.');
|
warnings.push('`WEB_HOST=0.0.0.0` sans HTTPS expose les cookies de session en clair sur le réseau.');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,30 @@ describe('env schema', () => {
|
|||||||
assert.ok(warnings.some((warning) => warning.includes('rejetés')));
|
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', () => {
|
it('warns when the dashboard is exposed without HTTPS', () => {
|
||||||
const warnings = crossCheck({
|
const warnings = crossCheck({
|
||||||
WEB_ENABLED: 'true',
|
WEB_ENABLED: 'true',
|
||||||
|
|||||||
@@ -95,6 +95,27 @@ describe('dashboard server', () => {
|
|||||||
assert.match(response.headers.get('content-type'), /javascript/);
|
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 () => {
|
it('sends the security headers on every response', async () => {
|
||||||
const response = await app.fetch('/');
|
const response = await app.fetch('/');
|
||||||
assert.equal(response.headers.get('x-frame-options'), 'DENY');
|
assert.equal(response.headers.get('x-frame-options'), 'DENY');
|
||||||
|
|||||||
Reference in new issue
Block a user