Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27b5ea251c
|
||
|
|
553c69dafe
|
||
|
|
faa296937d
|
||
|
|
22e235e76a
|
||
|
|
d7ab575550
|
||
|
|
7595dcb95a
|
||
|
|
8384d1b510
|
||
|
|
7d568e416d
|
No files matched your search
+2
-3
@@ -75,9 +75,8 @@ 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 derrière un reverse proxy installé sur la même machine.
|
# 127.0.0.1 par défaut : n'expose rien hors de la machine. Mettre 0.0.0.0 seulement
|
||||||
# 0.0.0.0 dans un conteneur ou sur un panel d'hébergement (Pterodactyl, Docker) :
|
# derrière un reverse proxy HTTPS.
|
||||||
# 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,15 +27,6 @@ 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));
|
||||||
|
|
||||||
|
|||||||
+1
-13
@@ -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, request = null } = {}) {
|
export async function sendStatic(response, root, requestPath, { fallback = 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,24 +150,12 @@ 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,8 +310,7 @@ 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) {
|
||||||
const { errorBox } = await import('./core/ui.js');
|
mount(host, h('div', { class: 'notice notice-error' }, h('p', { text: error.message })));
|
||||||
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.', rowHref = null } = {}) {
|
export function table(columns, rows, { empty = 'Rien à afficher pour le moment.' } = {}) {
|
||||||
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,11 +107,10 @@ export function table(columns, rows, { empty = 'Rien à afficher pour le moment.
|
|||||||
h(
|
h(
|
||||||
'tbody',
|
'tbody',
|
||||||
{},
|
{},
|
||||||
rows.map((row) => {
|
rows.map((row) =>
|
||||||
const target = rowHref?.(row) ?? null;
|
h(
|
||||||
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];
|
||||||
@@ -119,25 +118,8 @@ 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;
|
|
||||||
}),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -146,28 +128,11 @@ 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(
|
h('p', { text: message }),
|
||||||
'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,14 +535,6 @@ 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 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(
|
table(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -207,10 +207,7 @@ 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,7 +96,6 @@ 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' && Array.isArray(setting.options)) {
|
if (setting.type === 'enum') {
|
||||||
return field(
|
return field(
|
||||||
setting.label,
|
setting.label,
|
||||||
select(
|
select(
|
||||||
@@ -76,27 +76,20 @@ 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 schema = Array.isArray(data.schema) ? data.schema : [];
|
const sections = data.sections ?? [];
|
||||||
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 = 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;
|
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 = values[setting.key];
|
const value = data.values[setting.key];
|
||||||
|
|
||||||
if (!editable) {
|
if (!editable) {
|
||||||
return h(
|
return h(
|
||||||
@@ -112,7 +105,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é.`);
|
||||||
values[setting.key] = saved.value;
|
data.values[setting.key] = saved.value;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast(error.message, 'error');
|
toast(error.message, 'error');
|
||||||
}
|
}
|
||||||
@@ -138,13 +131,7 @@ const testButton = (service, label) =>
|
|||||||
{ tone: 'ghost' },
|
{ tone: 'ghost' },
|
||||||
);
|
);
|
||||||
|
|
||||||
function connectionsCard(raw) {
|
function connectionsCard(data) {
|
||||||
const data = {
|
|
||||||
discord: raw.discord ?? {},
|
|
||||||
gitea: raw.gitea ?? {},
|
|
||||||
webhook: raw.webhook ?? {},
|
|
||||||
web: raw.web ?? {},
|
|
||||||
};
|
|
||||||
return h(
|
return h(
|
||||||
'div',
|
'div',
|
||||||
{ class: 'stack' },
|
{ class: 'stack' },
|
||||||
@@ -162,13 +149,13 @@ function connectionsCard(raw) {
|
|||||||
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 }))),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -410,15 +397,14 @@ function tokensCard(reload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function maintenanceCard(data) {
|
function maintenanceCard(data) {
|
||||||
const runtime = data.runtime ?? {};
|
|
||||||
return card(
|
return card(
|
||||||
'Maintenance',
|
'Maintenance',
|
||||||
{ subtitle: `Base : ${runtime.databasePath ?? '—'}` },
|
{ subtitle: `Base : ${data.runtime.databasePath}` },
|
||||||
grid(
|
grid(
|
||||||
stat('Environnement', runtime.nodeEnv),
|
stat('Environnement', data.runtime.nodeEnv),
|
||||||
stat('Niveau de log', runtime.logLevel),
|
stat('Niveau de log', data.runtime.logLevel),
|
||||||
stat('Rétention', `${runtime.logRetentionDays ?? '—'} jours`),
|
stat('Rétention', `${data.runtime.logRetentionDays} jours`),
|
||||||
stat('PID', runtime.pid),
|
stat('PID', data.runtime.pid),
|
||||||
),
|
),
|
||||||
h(
|
h(
|
||||||
'div',
|
'div',
|
||||||
@@ -439,7 +425,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 () => {
|
||||||
@@ -455,13 +441,12 @@ 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.' },
|
||||||
@@ -472,7 +457,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' },
|
||||||
],
|
],
|
||||||
reference.accessLevels ?? [],
|
data.reference.accessLevels,
|
||||||
),
|
),
|
||||||
h('h3', { text: 'Catégories de tickets' }),
|
h('h3', { text: 'Catégories de tickets' }),
|
||||||
table(
|
table(
|
||||||
@@ -481,13 +466,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(', ') },
|
||||||
],
|
],
|
||||||
reference.ticketCategories ?? [],
|
data.reference.ticketCategories,
|
||||||
),
|
),
|
||||||
h('h3', { text: 'Types de notification' }),
|
h('h3', { text: 'Types de notification' }),
|
||||||
h(
|
h(
|
||||||
'div',
|
'div',
|
||||||
{ class: 'row' },
|
{ 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 &&
|
level >= LEVELS.OWNER &&
|
||||||
h('a', {
|
h('a', { class: 'btn btn-primary', href: '#/setup', text: 'Assistant de configuration .env' }),
|
||||||
class: 'btn btn-primary',
|
|
||||||
href: '#/setup',
|
|
||||||
text: 'Assistant de configuration .env',
|
|
||||||
}),
|
|
||||||
),
|
),
|
||||||
|
|
||||||
level >= LEVELS.OWNER &&
|
level >= LEVELS.OWNER &&
|
||||||
|
|||||||
+2
-26
@@ -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, request });
|
const served = await sendStatic(response, publicDir, pathname, { fallback });
|
||||||
if (!served) sendEmpty(response, 404);
|
if (!served) sendEmpty(response, 404);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -143,32 +143,8 @@ 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.',
|
||||||
'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' }],
|
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: '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',
|
type: 'text',
|
||||||
default: '127.0.0.1',
|
default: '127.0.0.1',
|
||||||
restartRequired: true,
|
restartRequired: true,
|
||||||
@@ -711,21 +711,6 @@ 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,30 +88,6 @@ 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,27 +95,6 @@ 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