forked from FWS/FWS-TEMPLATE-Website-OnePage
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:
1 parent
34b3f1cf3c
commit
1775adceaa
34 files changed
+2799
-1862
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* FWS Linux — configuration locale des notifications Discord.
|
||||
* FWS Linux — configuration locale des notifications Discord + build ISO.
|
||||
*
|
||||
* Copie ce fichier en « config.local.php » et remplis-le :
|
||||
*
|
||||
@@ -22,15 +22,24 @@
|
||||
* (Activer le mode développeur Discord → réseau du navigateur, ou via un
|
||||
* outil type Discord API avec le bot).
|
||||
*
|
||||
* 4) gitea_token (requis pour l'onglet « Build ISO ») : le dépôt
|
||||
* D:\FWS-ISO est privé sur gitea.nocode-var.tech, et le build tourne dans
|
||||
* un conteneur qui n'a pas tes identifiants Windows. Génère un token dans
|
||||
* Gitea → Settings → Applications → Generate New Token (scope : lecture
|
||||
* du dépôt / read:repository), puis colle-le ici.
|
||||
* Le token n'est JAMAIS commité, ni affiché dans les logs du build.
|
||||
*
|
||||
* config.local.php n'est PAS commité (secret) — il est dans .gitignore.
|
||||
*/
|
||||
return [
|
||||
'webhook_url' => 'https://discord.com/api/webhooks/REMPLACE_PAR_ID/REMPLACE_PAR_TOKEN',
|
||||
'bot_token' => '',
|
||||
'tags' => [
|
||||
'webhook_url' => 'https://discord.com/api/webhooks/REMPLACE_PAR_ID/REMPLACE_PAR_TOKEN',
|
||||
'bot_token' => '',
|
||||
'gitea_username' => '', // optionnel : nom du compte Gitea (défaut « fws »)
|
||||
'gitea_token' => '', // token Gitea (lecture dépôt) pour le build ISO
|
||||
'tags' => [
|
||||
'nouveau' => '',
|
||||
'en_cours' => '',
|
||||
'resolu' => '',
|
||||
'ignore' => '',
|
||||
],
|
||||
];
|
||||
];
|
||||
@@ -2,3 +2,7 @@
|
||||
*.sqlite
|
||||
*.sqlite-wal
|
||||
*.sqlite-shm
|
||||
fws_bugs.sqlite
|
||||
|
||||
# Logs / états de l'onglet « Build ISO » (admin/bugs/build.php)
|
||||
/build/
|
||||
+206
-1
@@ -6,6 +6,36 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/* ───────────── UTF-8 (partagé avec inc/site.php, gardes function_exists) ── */
|
||||
|
||||
if (!function_exists('fws_utf8_str')) {
|
||||
/** UTF-8 valide obligatoire : les octets invalides (Windows-1252…) sont
|
||||
* convertis, sinon json_encode échoue et casse tout l'appelant. */
|
||||
function fws_utf8_str(string $s): string
|
||||
{
|
||||
if (mb_check_encoding($s, 'UTF-8')) {
|
||||
return $s;
|
||||
}
|
||||
$conv = @mb_convert_encoding($s, 'UTF-8', 'Windows-1252');
|
||||
return is_string($conv) ? $conv : (string) mb_convert_encoding($s, 'UTF-8', 'UTF-8');
|
||||
}
|
||||
|
||||
function fws_utf8_arr(array $a): array
|
||||
{
|
||||
$out = [];
|
||||
foreach ($a as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$out[$k] = fws_utf8_arr($v);
|
||||
} elseif (is_string($v)) {
|
||||
$out[$k] = fws_utf8_str($v);
|
||||
} else {
|
||||
$out[$k] = $v;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
function fws_bugs_db(): PDO
|
||||
{
|
||||
static $pdo = null;
|
||||
@@ -98,6 +128,25 @@ function fws_bugs_schema(PDO $pdo): void
|
||||
)'
|
||||
);
|
||||
|
||||
/* Paquets du site (données gérées depuis le panneau admin) */
|
||||
$pdo->exec(
|
||||
'CREATE TABLE IF NOT EXISTS packages (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
slug TEXT NOT NULL DEFAULT \'\',
|
||||
name TEXT NOT NULL DEFAULT \'\',
|
||||
tagline TEXT NOT NULL DEFAULT \'\',
|
||||
description TEXT NOT NULL DEFAULT \'\',
|
||||
since TEXT,
|
||||
since_label TEXT NOT NULL DEFAULT \'FWS\',
|
||||
latest_name TEXT NOT NULL DEFAULT \'\',
|
||||
latest_date TEXT,
|
||||
links TEXT NOT NULL DEFAULT \'[]\',
|
||||
screens TEXT NOT NULL DEFAULT \'[]\',
|
||||
changelog TEXT NOT NULL DEFAULT \'[]\',
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime(\'now\'))
|
||||
)'
|
||||
);
|
||||
|
||||
/* Schéma (re)créé : s'assurer que le fichier reste inscriptible par Apache */
|
||||
@chmod(__DIR__ . '/data/fws_bugs.sqlite', 0666);
|
||||
}
|
||||
@@ -108,7 +157,7 @@ function fws_bugs_schema(PDO $pdo): void
|
||||
*/
|
||||
function fws_bugs_next_id(PDO $pdo, string $table): int
|
||||
{
|
||||
if (!in_array($table, ['bug_reports', 'admin_users', 'invite_codes'], true)) {
|
||||
if (!in_array($table, ['bug_reports', 'admin_users', 'invite_codes', 'packages'], true)) {
|
||||
throw new InvalidArgumentException('Table inconnue : ' . $table);
|
||||
}
|
||||
$used = [];
|
||||
@@ -200,3 +249,159 @@ function fws_bugs_client_ip(): string
|
||||
}
|
||||
return substr((string) ($_SERVER['REMOTE_ADDR'] ?? ''), 0, 64);
|
||||
}
|
||||
|
||||
/**
|
||||
* Comptes autorisés à lancer un build ISO (onglet « Build ISO » du panneau).
|
||||
* Le build pilote le moteur Docker : à n'accorder qu'aux comptes de confiance.
|
||||
*/
|
||||
function fws_bugs_can_build(string $username): bool
|
||||
{
|
||||
return in_array(strtolower(trim($username)), ['admin'], true);
|
||||
}
|
||||
|
||||
/* ───────────────────────── paquets du site ───────────────────────── */
|
||||
|
||||
/**
|
||||
* Convertit une ligne brute de la table `packages` au format JSON
|
||||
* utilisé par le site (identique à l'ancien packages.json).
|
||||
*/
|
||||
function fws_packages_row_to_json(array $r): array
|
||||
{
|
||||
$latest = null;
|
||||
if ((string) ($r['latest_name'] ?? '') !== '') {
|
||||
$latest = [
|
||||
'name' => fws_utf8_str((string) $r['latest_name']),
|
||||
'date' => ($r['latest_date'] ?? null) !== null ? fws_utf8_str((string) $r['latest_date']) : null,
|
||||
];
|
||||
}
|
||||
return fws_utf8_arr([
|
||||
'id' => (string) $r['slug'],
|
||||
'name' => (string) $r['name'],
|
||||
'tagline' => (string) $r['tagline'],
|
||||
'description' => (string) $r['description'],
|
||||
'since' => ($r['since'] ?? null) !== null ? (string) $r['since'] : null,
|
||||
'sinceLabel' => (string) ($r['since_label'] ?? 'FWS'),
|
||||
'latest' => $latest,
|
||||
'links' => json_decode((string) $r['links'], true) ?: [],
|
||||
'screens' => json_decode((string) $r['screens'], true) ?: [],
|
||||
'changelog' => json_decode((string) $r['changelog'], true) ?: [],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tous les paquets, ordonnés par id (l'ordre = la position sur le site,
|
||||
* ex : /?p/paquets/1/ est l'id 1).
|
||||
*/
|
||||
function fws_packages_all(PDO $pdo): array
|
||||
{
|
||||
$out = [];
|
||||
foreach ($pdo->query('SELECT * FROM packages ORDER BY id ASC') as $r) {
|
||||
$out[] = fws_packages_row_to_json($r);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enregistre un paquet (insert si id = 0, sinon update).
|
||||
* Les colonnes JSON (links, screens, changelog) sont passées en tableaux PHP.
|
||||
*/
|
||||
function fws_packages_save(PDO $pdo, array $d): int
|
||||
{
|
||||
$id = (int) ($d['id'] ?? 0);
|
||||
$slug = trim((string) ($d['slug'] ?? ''));
|
||||
if ($slug === '') {
|
||||
$slug = trim(preg_replace('/[^a-zA-Z0-9]+/', '-', (string) ($d['name'] ?? '')) ?? '', '-');
|
||||
}
|
||||
$sinceLabel = trim((string) ($d['since_label'] ?? ''));
|
||||
if ($sinceLabel === '') {
|
||||
$sinceLabel = 'FWS';
|
||||
}
|
||||
$data = [
|
||||
':slug' => fws_utf8_str($slug),
|
||||
':name' => fws_utf8_str(trim((string) ($d['name'] ?? ''))),
|
||||
':tagline' => fws_utf8_str(trim((string) ($d['tagline'] ?? ''))),
|
||||
':description' => fws_utf8_str(trim((string) ($d['description'] ?? ''))),
|
||||
':since' => ($d['since'] ?? '') !== '' ? (string) $d['since'] : null,
|
||||
':since_label' => fws_utf8_str($sinceLabel),
|
||||
':latest_name' => fws_utf8_str(trim((string) ($d['latest_name'] ?? ''))),
|
||||
':latest_date' => ($d['latest_date'] ?? '') !== '' ? (string) $d['latest_date'] : null,
|
||||
':links' => (string) json_encode(fws_utf8_arr((array) ($d['links'] ?? [])), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
||||
':screens' => (string) json_encode(fws_utf8_arr((array) ($d['screens'] ?? [])), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
||||
':changelog' => (string) json_encode(fws_utf8_arr((array) ($d['changelog'] ?? [])), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
||||
];
|
||||
|
||||
if ($id > 0) {
|
||||
$data[':id'] = $id;
|
||||
$st = $pdo->prepare(
|
||||
'UPDATE packages SET slug = :slug, name = :name, tagline = :tagline,
|
||||
description = :description, since = :since, since_label = :since_label,
|
||||
latest_name = :latest_name, latest_date = :latest_date,
|
||||
links = :links, screens = :screens, changelog = :changelog,
|
||||
updated_at = datetime(\'now\') WHERE id = :id'
|
||||
);
|
||||
$st->execute($data);
|
||||
return $id;
|
||||
}
|
||||
|
||||
$id = fws_bugs_next_id($pdo, 'packages');
|
||||
$data[':id'] = $id;
|
||||
$st = $pdo->prepare(
|
||||
'INSERT INTO packages (id, slug, name, tagline, description, since, since_label,
|
||||
latest_name, latest_date, links, screens, changelog)
|
||||
VALUES (:id, :slug, :name, :tagline, :description, :since, :since_label,
|
||||
:latest_name, :latest_date, :links, :screens, :changelog)'
|
||||
);
|
||||
$st->execute($data);
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime un paquet (l'id pourra être réutilisé ensuite).
|
||||
*/
|
||||
function fws_packages_delete(PDO $pdo, int $id): void
|
||||
{
|
||||
$st = $pdo->prepare('DELETE FROM packages WHERE id = :id');
|
||||
$st->execute([':id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Import initial : si la table `packages` est vide et que l'ancien
|
||||
* packages.json existe toujours, on l'importe une seule fois.
|
||||
*/
|
||||
function fws_packages_seed_if_empty(PDO $pdo): int
|
||||
{
|
||||
$count = (int) $pdo->query('SELECT COUNT(*) FROM packages')->fetchColumn();
|
||||
if ($count > 0) {
|
||||
return 0;
|
||||
}
|
||||
$file = dirname(__DIR__) . '/../p/paquets/packages.json';
|
||||
if (!is_file($file)) {
|
||||
return 0;
|
||||
}
|
||||
$data = json_decode((string) file_get_contents($file), true);
|
||||
if (!is_array($data)) {
|
||||
return 0;
|
||||
}
|
||||
$n = 0;
|
||||
foreach ($data as $p) {
|
||||
if (!is_array($p)) {
|
||||
continue;
|
||||
}
|
||||
fws_packages_save($pdo, [
|
||||
'id' => 0,
|
||||
'slug' => (string) ($p['id'] ?? ''),
|
||||
'name' => (string) ($p['name'] ?? ''),
|
||||
'tagline' => (string) ($p['tagline'] ?? ''),
|
||||
'description' => (string) ($p['description'] ?? ''),
|
||||
'since' => (string) ($p['since'] ?? ''),
|
||||
'since_label' => (string) ($p['sinceLabel'] ?? 'FWS'),
|
||||
'latest_name' => (string) ($p['latest']['name'] ?? ''),
|
||||
'latest_date' => (string) ($p['latest']['date'] ?? ''),
|
||||
'links' => $p['links'] ?? [],
|
||||
'screens' => $p['screens'] ?? [],
|
||||
'changelog' => $p['changelog'] ?? [],
|
||||
]);
|
||||
$n++;
|
||||
}
|
||||
return $n;
|
||||
}
|
||||
Reference in new issue
Block a user