true, 'samesite' => 'Lax', 'secure' => (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https'), ]); session_start(); function h_build(string $s): string { return htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); } function current_user_build(): ?array { return isset($_SESSION['admin_user_id']) ? [ 'id' => (int) $_SESSION['admin_user_id'], 'name' => (string) $_SESSION['admin_username'], ] : null; } function csrf_token_build(): string { if (empty($_SESSION['csrf'])) { $_SESSION['csrf'] = bin2hex(random_bytes(32)); } return $_SESSION['csrf']; } function csrf_ok_build(): bool { return hash_equals($_SESSION['csrf'] ?? '', $_POST['csrf'] ?? ''); } /** Lecture du token Gitea stocké localement (api/bugs/data/build/git-auth.env, jamais commité). */ function build_gitea_auth_build(): array { global $DATA; $f = $DATA . '/git-auth.env'; $out = ['username' => '', 'token' => '']; if (is_file($f)) { $s = (string) file_get_contents($f); if (preg_match("/^FWS_GIT_USER='([^']*)'$/m", $s, $m) === 1) { $out['username'] = $m[1]; } if (preg_match("/^FWS_GIT_TOKEN='([^']*)'$/m", $s, $m) === 1) { $out['token'] = $m[1]; } } return $out; } /** Écriture du token Gitea (token vide → fichier retiré). */ function build_save_gitea_auth_build(string $username, string $token): void { global $DATA; if (!is_dir($DATA)) { @mkdir($DATA, 0775, true); } $f = $DATA . '/git-auth.env'; if ($token === '') { @unlink($f); return; } $sq = static fn(string $v): string => str_replace(["\\", "'"], ["\\\\", "\\'"], $v); file_put_contents( $f, "FWS_GIT_USER='" . $sq($username !== '' ? $username : 'fws') . "'\n" . "FWS_GIT_TOKEN='" . $sq($token) . "'\n", LOCK_EX ); @chmod($f, 0600); } /* ── Chemins (sous api/bugs/data/, jamais commité) ── */ $DATA = __DIR__ . '/../../api/bugs/data/build'; $LOG = $DATA . '/build.log'; $PIDF = $DATA . '/build.pid'; $RUN = __DIR__ . '/run-build.sh'; $user = current_user_build(); /** PID du process de build s'il tourne encore, sinon false. */ function build_running_build(): int|false { global $PIDF; $pid = is_file($PIDF) ? trim((string) file_get_contents($PIDF)) : ''; if ($pid === '' || !ctype_digit($pid)) { return false; } exec('kill -0 ' . (int) $pid . ' 2>/dev/null', $out, $rc); return $rc === 0 ? (int) $pid : false; } /** Dernier code de sortie du pipeline lu dans le log (null si pas encore terminé). */ function build_last_rc_build(): ?int { global $LOG; if (!is_file($LOG) || filesize($LOG) === 0) { return null; } $tail = (string) file_get_contents($LOG, false, null, max(0, filesize($LOG) - 4096)); if (preg_match('/Fin du pipeline \(code (-?\d+)\)/', $tail, $m) === 1) { return (int) $m[1]; } return null; } /* ───────────────────────── API (act=…) ───────────────────────── */ $act = $_GET['act'] ?? $_POST['act'] ?? ''; $isApi = $act !== ''; if ($isApi) { header('Content-Type: application/json; charset=utf-8'); header('Cache-Control: no-store'); if ($user === null) { http_response_code(401); exit(json_encode(['ok' => false, 'error' => 'Non connecté.'])); } if (!fws_bugs_can_build($user['name'])) { http_response_code(403); exit(json_encode(['ok' => false, 'error' => 'Ce compte n’est pas autorisé à lancer des builds.'])); } $running = build_running_build(); if ($act === 'state') { echo json_encode(['ok' => true, 'running' => $running !== false, 'pid' => $running]); exit; } if ($act === 'auth_status') { $a = build_gitea_auth_build(); echo json_encode(['ok' => true, 'configured' => $a['token'] !== '', 'username' => $a['username']]); exit; } if ($act === 'tail') { $pos = max(-1, (int) ($_GET['pos'] ?? 0)); $size = is_file($LOG) ? (int) filesize($LOG) : 0; $start = 0; if ($pos === -1) { // Premier chargement : ne ramener que la fin d'un éventuel vieux log. $start = max(0, $size - 150000); } elseif ($pos > 0 && $pos <= $size) { $start = $pos; } $text = ''; if ($size > $start) { $fh = fopen($LOG, 'rb'); if ($fh !== false) { if ($start > 0) { fseek($fh, $start); } $raw = (string) stream_get_contents($fh); fclose($fh); // Nettoyage : codes ANSI retirés, octets invalides ignorés. $text = (string) preg_replace('/\x1B\[[0-9;?]*[ -\/]*[@-~]/', '', $raw); $text = (string) preg_replace('/\x1B\][^\x07\x1B]*(\x07|\x1B\\)/', '', $text); $text = iconv('UTF-8', 'UTF-8//IGNORE', $text); } } $running = build_running_build(); echo json_encode([ 'ok' => true, 'running' => $running !== false, 'pos' => (int) $size, 'rc' => build_last_rc_build(), 'text' => $text, ]); exit; } if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST' || !csrf_ok_build()) { http_response_code(403); exit(json_encode(['ok' => false, 'error' => 'Jeton de sécurité invalide.'])); } if ($act === 'start') { if ($running !== false) { http_response_code(409); exit(json_encode(['ok' => false, 'error' => 'Un build est déjà en cours.'])); } exec('timeout 8 docker info >/dev/null 2>&1', $out, $drc); if ($drc !== 0) { http_response_code(503); exit(json_encode(['ok' => false, 'error' => 'Moteur Docker injoignable (Docker Desktop arrêté ?).'])); } if (!is_dir($DATA) && !@mkdir($DATA, 0775, true)) { http_response_code(500); exit(json_encode(['ok' => false, 'error' => 'Impossible de créer ' . $DATA])); } @unlink($LOG); @unlink($PIDF); $cmd = 'nohup bash ' . escapeshellarg($RUN) . ' > ' . escapeshellarg($LOG) . ' 2>&1 & echo $!'; exec($cmd, $out2, $src); $pid = (int) ($out2[0] ?? 0); if ($pid > 0) { file_put_contents($PIDF, (string) $pid); } echo json_encode(['ok' => $src === 0 && $pid > 0, 'pid' => $pid]); exit; } if ($act === 'stop') { exec('docker rm -f fws-iso-build >/dev/null 2>&1', $o1, $rc1); $stopped = $running; if ($running !== false) { exec('kill ' . $running . ' 2>/dev/null'); @unlink($PIDF); } echo json_encode(['ok' => true, 'stopped' => $stopped !== false || $rc1 === 0]); exit; } if ($act === 'clear') { if ($running !== false) { http_response_code(409); exit(json_encode(['ok' => false, 'error' => 'Arrêtez d’abord le build en cours.'])); } @unlink($LOG); @unlink($PIDF); echo json_encode(['ok' => true]); exit; } if ($act === 'save_auth') { build_save_gitea_auth_build( trim((string) ($_POST['username'] ?? '')), trim((string) ($_POST['token'] ?? '')) ); $a = build_gitea_auth_build(); echo json_encode(['ok' => true, 'configured' => $a['token'] !== '', 'username' => $a['username']]); exit; } http_response_code(400); exit(json_encode(['ok' => false, 'error' => 'Action inconnue.'])); } /* ───────────────────────── PAGES ───────────────────────── */ if ($user === null) { header('Location: index.php'); exit; } $allowed = fws_bugs_can_build($user['name']); header('Content-Type: text/html; charset=utf-8'); ?> Build ISO — FWS Linux

🔨 Build ISO

Connecté : · dépôt : D:\FWS-ISO (branche main)

Accès restreint

Votre compte () n'est pas autorisé à lancer des builds. Seul le compte admin le peut (voir fws_bugs_can_build() dans api/bugs/db.php).

← Retour aux signalements

🔑 Accès Gitea (pour le git pull)

Le dépôt D:\FWS-ISO est privé et le build tourne dans un conteneur sans tes identifiants Windows : crée un token dans Gitea (Settings → Applications → Generate New Token, lecture du dépôt) puis enregistre-le ici. Il n'est stocké que sur ce serveur — jamais commité, jamais affiché dans les logs.

…

🖥️ Terminal du build

État : inconnu… · Git Bash lancerait ici : git checkout main && git pull && bash build.sh
Chargement du terminal…

Le build se déroule dans un conteneur archlinux jetable (via Docker Desktop, comme build.sh à la main) : passage sur main → git pull → bash build.sh ; en cas d'échec de build, bash setup-aur.sh est lancé puis build.sh est relancé. Si le checkout de main est bloqué par des modifications locales non commitées dans D:\FWS-ISO, le build s'arrête proprement sans rien toucher. L'ISO sort dans D:\FWS-ISO\out\. Peut prendre 30 min et plus — laissez l'onglet ouvert, les logs défilent en direct.