Feat(site): rendu serveur PHP — paquets en SQLite, releases Gitea, build ISO

- Front controller page.php + inc/site.php : coquille et pages rendues
  en PHP (accueil, dl, paquets, paquets/N, equipe, contact, 404) ; les
  URLs ne changent pas et l'apparence est conservée.
- Paquets stockés dans la base SQLite partagée (table packages),
  éditables depuis l'onglet 📦 Paquets de /admin/bugs, avec bouton de
  synchronisation des releases depuis l'API Gitea du dépôt lié.
  Repli automatique sur packages.json si la base est vide.
- Releases ISO de la page Téléchargements récupérées côté serveur
  (Gitea FWS/ISO sinon GitHub) avec cache fichier 10 min ; note de
  release rendue en Markdown serveur (Voir plus / Voir moins).
- Suppression du routeur SPA et des chargeurs JS devenus inutiles
  (app.js, packages.js, downloads.js, creators-loader.js, index.html) ;
  restent nav.js, note-toggle.js et hero-carousel.js.
- Panneau admin : onglet Build ISO (git pull sur main, build.sh avec
  repli setup-aur.sh, terminal des logs en direct), durcissement UTF-8
  à l'écriture des paquets (json_encode ne casse plus sur des accents
  mal encodés), 404 réels et gardes d'accès direct sur les corps PHP.
This commit is contained in:
BlackAngelTV committed 2026-09-14 13:19:37 +02:00
1 parent 34b3f1cf3c
commit 1775adceaa
34 files changed
+2799 -1862

No files matched your search

+319 -2
View File
@@ -81,11 +81,101 @@ function excerpt(string $s, int $len = 140): string
return mb_substr($s, 0, $len - 1) . '…';
}
/* ── Paquets : parsing / formatage des champs « une ligne par entrée » ── */
function parse_pipe_lines(string $raw, int $fields): array
{
$out = [];
foreach (preg_split('/\r?\n/', $raw) as $line) {
$line = trim($line);
if ($line === '') {
continue;
}
$parts = array_map('trim', explode('|', $line));
$parts = array_pad($parts, $fields, '');
$out[] = array_slice($parts, 0, $fields);
}
return $out;
}
function links_from_lines(string $raw): array
{
$out = [];
foreach (parse_pipe_lines($raw, 2) as $pair) {
[$label, $url] = $pair;
if ($url === '') {
$url = $label;
$label = '';
}
if ($url === '') {
continue;
}
$out[] = ['label' => $label !== '' ? $label : $url, 'url' => $url];
}
return $out;
}
function changelog_from_lines(string $raw): array
{
$out = [];
foreach (parse_pipe_lines($raw, 3) as $parts) {
[$version, $date, $notes] = $parts;
if ($version === '' && $date === '' && $notes === '') {
continue;
}
$out[] = ['version' => $version, 'date' => $date !== '' ? $date : null, 'notes' => $notes];
}
return $out;
}
function screens_from_lines(string $raw): array
{
$out = [];
foreach (parse_pipe_lines($raw, 3) as $parts) {
[$src, $alt, $caption] = $parts;
if ($src === '') {
continue;
}
$out[] = ['src' => $src, 'alt' => $alt !== '' ? $alt : null, 'caption' => $caption !== '' ? $caption : null];
}
return $out;
}
function lines_from_links(array $links): string
{
$lines = [];
foreach ($links as $l) {
$lines[] = ($l['label'] ?? '') . ' | ' . ($l['url'] ?? '');
}
return implode("\n", $lines);
}
function lines_from_changelog(array $cl): string
{
$lines = [];
foreach ($cl as $e) {
$lines[] = ($e['version'] ?? '') . ' | ' . ($e['date'] ?? '') . ' | ' . ($e['notes'] ?? '');
}
return implode("\n", $lines);
}
function lines_from_screens(array $s): string
{
$lines = [];
foreach ($s as $e) {
$lines[] = ($e['src'] ?? '') . ' | ' . ($e['alt'] ?? '') . ' | ' . ($e['caption'] ?? '');
}
return implode("\n", $lines);
}
/* ───────────────────────── actions POST ───────────────────────── */
$error = null;
$notice = null;
$freshInvite = '';
/* Message ponctuel d'une action précédente (stocké en session pour la redirection) */
$flash = $_SESSION['flash'] ?? null;
unset($_SESSION['flash']);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
@@ -197,12 +287,119 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$up->execute([':h' => password_hash($new, PASSWORD_DEFAULT), ':id' => $uid]);
$notice = 'Mot de passe modifié avec succès.';
}
} elseif ($action === 'pkg_save') {
$name = trim((string) ($_POST['name'] ?? ''));
if ($name === '') {
$error = 'Le nom du paquet est obligatoire.';
} else {
$pdo = fws_bugs_db();
$savedId = fws_packages_save($pdo, [
'id' => (int) ($_POST['pkg_id'] ?? 0),
'slug' => (string) ($_POST['slug'] ?? ''),
'name' => $name,
'tagline' => (string) ($_POST['tagline'] ?? ''),
'description' => (string) ($_POST['description'] ?? ''),
'since' => (string) ($_POST['since'] ?? ''),
'since_label' => (string) ($_POST['since_label'] ?? ''),
'latest_name' => (string) ($_POST['latest_name'] ?? ''),
'latest_date' => (string) ($_POST['latest_date'] ?? ''),
'links' => links_from_lines((string) ($_POST['links'] ?? '')),
'screens' => screens_from_lines((string) ($_POST['screens'] ?? '')),
'changelog' => changelog_from_lines((string) ($_POST['changelog'] ?? '')),
]);
$wasEdit = (int) ($_POST['pkg_id'] ?? 0) > 0;
$_SESSION['flash'] = ['ok' => $wasEdit
? "Paquet « $name » mis à jour."
: "Paquet « $name » créé."];
header('Location: index.php?view=packages');
exit;
}
} elseif ($action === 'pkg_delete') {
$pkgId = (int) ($_POST['pkg_id'] ?? 0);
$pdo = fws_bugs_db();
fws_packages_delete($pdo, $pkgId);
$_SESSION['flash'] = ['ok' => "Paquet #$pkgId supprimé."];
header('Location: index.php?view=packages');
exit;
} elseif ($action === 'pkg_sync_gitea') {
/* Rafraîchit latest + historique d'un paquet depuis l'API Gitea
(le dépôt est déduit de ses liens « Gitea » / « Releases »). */
$pkgId = (int) ($_POST['pkg_id'] ?? 0);
$pdo = fws_bugs_db();
$st = $pdo->prepare('SELECT * FROM packages WHERE id = :id');
$st->execute([':id' => $pkgId]);
$row = $st->fetch();
if ($row === false) {
$_SESSION['flash'] = ['err' => "Paquet #$pkgId introuvable."];
header('Location: index.php?view=packages');
exit;
}
$links = json_decode((string) $row['links'], true) ?: [];
$repo = null;
foreach ($links as $link) {
if (preg_match('~^https?://gitea\.nocode-var\.tech/([^/]+)/([^/]+)/?$~i', (string) ($link['url'] ?? ''), $m)) {
$repo = ['owner' => $m[1], 'name' => $m[2]];
break;
}
}
if ($repo === null) {
$_SESSION['flash'] = ['err' => 'Aucun lien Gitea (gitea.nocode-var.tech) dans ce paquet : synchronisation impossible.'];
header('Location: index.php?view=packages');
exit;
}
require_once __DIR__ . '/../../inc/site.php';
$releases = fws_site_gitea_releases($repo['owner'], $repo['name']);
if ($releases === []) {
$_SESSION['flash'] = ['err' => 'Gitea ne renvoie aucune release pour ' . $repo['owner'] . '/' . $repo['name'] . '.'];
header('Location: index.php?view=packages');
exit;
}
$first = $releases[0];
$changelog = [];
foreach ($releases as $rel) {
$notes = trim(strip_tags((string) fws_markdown((string) ($rel['body'] ?? ''))));
if (mb_strlen($notes) > 200) {
$notes = rtrim(mb_substr($notes, 0, 200)) . '…';
}
$changelog[] = [
'version' => (string) ($rel['tag_name'] ?? ''),
'date' => isset($rel['published_at']) ? substr((string) $rel['published_at'], 0, 10) : null,
'notes' => $notes,
];
}
fws_packages_save($pdo, [
'id' => $pkgId,
'slug' => (string) $row['slug'],
'name' => (string) $row['name'],
'tagline' => (string) $row['tagline'],
'description' => (string) $row['description'],
'since' => (string) ($row['since'] ?? ''),
'since_label' => (string) $row['since_label'],
'latest_name' => (string) ($first['tag_name'] ?? ''),
'latest_date' => isset($first['published_at']) ? substr((string) $first['published_at'], 0, 10) : '',
'links' => $links,
'screens' => json_decode((string) $row['screens'], true) ?: [],
'changelog' => $changelog,
]);
$_SESSION['flash'] = ['ok' => 'Paquet « ' . $row['name'] . ' » synchronisé depuis Gitea (' . count($releases) . ' releases).'];
header('Location: index.php?view=packages');
exit;
}
}
}
$user = current_user();
/* Message ponctuel laissé par une action (après redirection) */
if ($flash !== null) {
if (!empty($flash['err'])) {
$error = (string) $flash['err'];
}
if (!empty($flash['ok'])) {
$notice = (string) $flash['ok'];
}
}
/* ───────────────────────── routage vues ───────────────────────── */
try {
@@ -214,6 +411,8 @@ try {
$view_id = (int) ($_GET['id'] ?? 0);
$view_invites = ($_GET['view'] ?? '') === 'invites' && $view_id === 0;
$view_packages = ($_GET['view'] ?? '') === 'packages' && $view_id === 0;
$edit_pkg_id = $view_packages ? (int) ($_GET['edit'] ?? 0) : 0;
/* Compteurs pour les filtres */
$counts = ['tous' => 0];
@@ -293,10 +492,13 @@ form.inline { display: inline; }
.login-box { max-width: 380px; margin: 12vh auto; }
.login-box .card { padding: 28px; }
.login-box h1 { font-size: 1.25rem; margin-top: 0; }
input[type=text], input[type=password] {
input[type=text], input[type=password], input[type=date], textarea {
width: 100%; padding: 9px 11px; margin: 6px 0 14px;
background: #0b1120; border: 1px solid #334155; border-radius: 8px; color: #e2e8f0; font-size: .95rem;
font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
label { font-size: .85rem; color: #cbd5e1; }
.back { margin-bottom: 12px; display: inline-block; }
.pager { display: flex; gap: 8px; margin-top: 16px; }
@@ -357,8 +559,10 @@ table.list th { color: #94a3b8; font-size: .72rem; text-transform: uppercase; le
</header>
<div class="navtabs">
<a href="index.php" class="<?= $view_invites ? '' : 'active' ?>">🐞 Signalements</a>
<a href="index.php" class="<?= ($view_invites || $view_packages) ? '' : 'active' ?>">🐞 Signalements</a>
<a href="index.php?view=invites" class="<?= $view_invites ? 'active' : '' ?>">👥 Invitations & comptes</a>
<a href="index.php?view=packages" class="<?= $view_packages ? 'active' : '' ?>">📦 Paquets</a>
<?php if (fws_bugs_can_build($user['name'])): ?><a href="build.php">🔨 Build ISO</a><?php endif; ?>
</div>
<?php if ($error): ?><div class="flash err"><?= h($error) ?></div><?php endif; ?>
@@ -548,6 +752,119 @@ table.list th { color: #94a3b8; font-size: .72rem; text-transform: uppercase; le
</form>
</div>
<?php elseif ($view_packages): /* ─────────── PAQUETS ─────────── */
$pkgRows = $pdo->query('SELECT * FROM packages ORDER BY id ASC')->fetchAll();
$editing = null;
if ($edit_pkg_id > 0) {
foreach ($pkgRows as $pr) {
if ((int) $pr['id'] === $edit_pkg_id) {
$editing = $pr;
break;
}
}
if ($editing === null) {
$edit_pkg_id = 0;
}
}
$form = $editing !== null ? $editing : [
'id' => 0, 'slug' => '', 'name' => '', 'tagline' => '', 'description' => '',
'since' => null, 'since_label' => 'FWS', 'latest_name' => '', 'latest_date' => null,
'links' => '[]', 'screens' => '[]', 'changelog' => '[]',
];
$fLinks = lines_from_links((array) (json_decode((string) $form['links'], true) ?: []));
$fScreens = lines_from_screens((array) (json_decode((string) $form['screens'], true) ?: []));
$fChangelog = lines_from_changelog((array) (json_decode((string) $form['changelog'], true) ?: []));
?>
<div class="card">
<h3><?= $editing !== null ? '✏️ Modifier « ' . h($editing['name']) . ' »' : '➕ Nouveau paquet' ?></h3>
<?php if ($editing !== null): ?><p style="font-size:.85rem;color:#94a3b8"><a href="index.php?view=packages">← Annuler la modification</a></p><?php endif; ?>
<p style="font-size:.85rem;color:#94a3b8">Les champs « une ligne par entrée » utilisent le format <code>Label | URL</code> (liens),
<code>Version | Date | Notes</code> (historique) et <code>src | alt | légende</code> (captures).</p>
<form method="post" style="display:grid;gap:2px;max-width:680px">
<input type="hidden" name="action" value="pkg_save">
<input type="hidden" name="csrf" value="<?= h(csrf_token()) ?>">
<input type="hidden" name="pkg_id" value="<?= (int) $form['id'] ?>">
<div class="grid2">
<div>
<label for="pkg_name">Nom *</label>
<input type="text" id="pkg_name" name="name" required value="<?= h($form['name']) ?>">
</div>
<div>
<label for="pkg_slug">Slug / id (vide = auto)</label>
<input type="text" id="pkg_slug" name="slug" value="<?= h($form['slug']) ?>" placeholder="ex. fws-pacmanage">
</div>
</div>
<label for="pkg_tagline">Tagline</label>
<input type="text" id="pkg_tagline" name="tagline" value="<?= h($form['tagline']) ?>">
<label for="pkg_desc">Description</label>
<textarea id="pkg_desc" name="description" rows="3"><?= h($form['description']) ?></textarea>
<div class="grid2">
<div>
<label for="pkg_since">Disponible depuis (date)</label>
<input type="date" id="pkg_since" name="since" value="<?= h((string) ($form['since'] ?? '')) ?>">
</div>
<div>
<label for="pkg_since_label">Badge « depuis »</label>
<input type="text" id="pkg_since_label" name="since_label" value="<?= h($form['since_label']) ?>" placeholder="V1.0.0 / En développement">
</div>
<div>
<label for="pkg_latest_name">Dernière release (nom)</label>
<input type="text" id="pkg_latest_name" name="latest_name" value="<?= h($form['latest_name']) ?>" placeholder="V1.2.1">
</div>
<div>
<label for="pkg_latest_date">Date de la release</label>
<input type="date" id="pkg_latest_date" name="latest_date" value="<?= h((string) ($form['latest_date'] ?? '')) ?>">
</div>
</div>
<label for="pkg_links">Liens utiles — une ligne par lien : <code>Label | URL</code></label>
<textarea id="pkg_links" name="links" rows="3" placeholder="Gitea | https://gitea.nocode-var.tech/FWS/FWS-PacManage"><?= h($fLinks) ?></textarea>
<label for="pkg_changelog">Historique — une ligne par version : <code>Version | Date | Notes</code></label>
<textarea id="pkg_changelog" name="changelog" rows="5" placeholder="V1.2.1 | 2026-08-29 | Correction de bugs"><?= h($fChangelog) ?></textarea>
<label for="pkg_screens">Captures d'écran — une ligne : <code>src | alt | légende</code></label>
<textarea id="pkg_screens" name="screens" rows="2" placeholder="/p/assets/img/… | Alt | Légende"><?= h($fScreens) ?></textarea>
<button class="btn primary" type="submit" style="justify-self:start;margin-top:4px">💾 Enregistrer</button>
</form>
</div>
<div class="card">
<h3>📦 Paquets (<?= count($pkgRows) ?>)</h3>
<?php if (!$pkgRows): ?>
<p class="empty">Aucun paquet. Créez le premier avec le formulaire ci-dessus.</p>
<?php else: ?>
<table class="list">
<tr><th>#</th><th>Nom</th><th>Dernière release</th><th></th></tr>
<?php foreach ($pkgRows as $pr): ?>
<tr>
<td><?= (int) $pr['id'] ?></td>
<td>
<strong><?= h($pr['name']) ?></strong>
<?php if ($pr['slug'] !== ''): ?><br><span style="font-size:.75rem;color:#64748b"><?= h($pr['slug']) ?></span><?php endif; ?>
<?php if ($pr['tagline'] !== ''): ?><br><span style="font-size:.8rem;color:#94a3b8"><?= h($pr['tagline']) ?></span><?php endif; ?>
</td>
<td><?= h($pr['latest_name'] !== '' ? $pr['latest_name'] . ($pr['latest_date'] !== null ? ' — ' . $pr['latest_date'] : '') : '—') ?></td>
<td style="text-align:right;white-space:nowrap">
<a class="btn small" href="index.php?view=packages&edit=<?= (int) $pr['id'] ?>">✏️ Modifier</a>
<form class="inline" method="post" onsubmit="return confirm('Synchroniser « <?= h($pr['name']) ?> » depuis Gitea ? (latest + historique)')">
<input type="hidden" name="action" value="pkg_sync_gitea">
<input type="hidden" name="csrf" value="<?= h(csrf_token()) ?>">
<input type="hidden" name="pkg_id" value="<?= (int) $pr['id'] ?>">
<button class="btn small" type="submit" title="Rafraîchit la dernière release et l'historique depuis Gitea">🔄 Gitea</button>
</form>
<form class="inline" method="post" onsubmit="return confirm('Supprimer le paquet « <?= h($pr['name']) ?> » ?')">
<input type="hidden" name="action" value="pkg_delete">
<input type="hidden" name="csrf" value="<?= h(csrf_token()) ?>">
<input type="hidden" name="pkg_id" value="<?= (int) $pr['id'] ?>">
<button class="btn small danger" type="submit">🗑 Supprimer</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</div>
<?php else: /* ─────────── LISTE ─────────── */
$filter = $_GET['status'] ?? 'tous';