- security headers on every response (strict CSP, nosniff, frame DENY, no-referrer, HSTS behind TLS proxy) and no x-powered-by; hero image set through the CSSOM so the CSP needs no inline styles - error handler: 400 without stack trace for malformed URLs/JSON and multer errors, 500 logged in full - image uploads: type detected from the file signature (PNG/JPEG/WebP), not the client MIME type; multer part limits - storage: atomic JSON writes (tmp + rename) with mode 600, dirs 700; refuse to start when groups.json is corrupted instead of recreating admin; initial admin password written to a 600 file instead of the logs - status file read asynchronously in the background and cached, one read at a time with a 3 s timeout, so a hung NFS mount never blocks requests; cleanup refused when the status is stale or empty - launches: 10 min cooldown after a successful start (status lags behind), ssh BatchMode/ConnectTimeout/IdentitiesOnly, remote stdout/stderr kept in the server log instead of the API response Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
import { execFile } from "node:child_process";
|
|
import { promisify } from "node:util";
|
|
|
|
const execFileAsync = promisify(execFile);
|
|
|
|
async function launchServer(server) {
|
|
const profile = getStartProfile(server);
|
|
if (!profile) {
|
|
const error = new Error("Aucun profil de lancement configure");
|
|
error.code = "MISSING_START_PROFILE";
|
|
throw error;
|
|
}
|
|
|
|
if (profile === "TEST") {
|
|
return execFileAsync("/bin/echo", ["Mock start test server"], {
|
|
timeout: 60_000,
|
|
maxBuffer: 1024 * 1024,
|
|
});
|
|
}
|
|
|
|
const target = process.env[`${profile}_SSH_TARGET`];
|
|
const port = process.env[`${profile}_SSH_PORT`];
|
|
const keyFile = process.env[`${profile}_SSH_KEY_FILE`];
|
|
const command = process.env[`${profile}_START_COMMAND`];
|
|
|
|
if (!target || !command) {
|
|
const error = new Error(`Profil de lancement incomplet: ${profile}`);
|
|
error.code = "INCOMPLETE_START_PROFILE";
|
|
throw error;
|
|
}
|
|
|
|
const args = buildSshArgs({ target, port, keyFile, command });
|
|
|
|
return execFileAsync("ssh", args, {
|
|
timeout: 60_000,
|
|
maxBuffer: 1024 * 1024,
|
|
});
|
|
}
|
|
|
|
function buildSshArgs({ target, port, keyFile, command }) {
|
|
// BatchMode: jamais de question interactive (mot de passe, cle d'hote inconnue) qui
|
|
// bloquerait le lancement jusqu'au timeout.
|
|
const args = ["-o", "BatchMode=yes", "-o", "ConnectTimeout=10"];
|
|
if (port) {
|
|
args.push("-p", port);
|
|
}
|
|
if (keyFile) {
|
|
args.push("-i", keyFile, "-o", "IdentitiesOnly=yes");
|
|
}
|
|
args.push(target, command);
|
|
return args;
|
|
}
|
|
|
|
function getStartProfile(server) {
|
|
if (server.startProfile) return server.startProfile;
|
|
return "";
|
|
}
|
|
|
|
export { buildSshArgs, getStartProfile, launchServer };
|