forked from FWS/FWS-TEMPLATE-Website-OnePage
Preview thumbnails for package screenshots and the API test link assumed a root deployment; use fws_url() and derive the scheme from the request instead of hardcoding https.
1267 lines
58 KiB
PHP
1267 lines
58 KiB
PHP
<?php
|
||
/**
|
||
* FWS Linux — Panneau admin des signalements de bugs.
|
||
*
|
||
* URL : https://fwslinux.fr/admin/bugs/
|
||
*
|
||
* Authentification : session PHP + utilisateurs stockés dans la base SQLite
|
||
* (créés avec admin/bugs/init.php). Passwords hachés avec password_hash().
|
||
*/
|
||
|
||
declare(strict_types=1);
|
||
|
||
require __DIR__ . '/../../api/bugs/db.php';
|
||
require_once __DIR__ . '/../../api/bugs/discord.php';
|
||
|
||
session_set_cookie_params([
|
||
'httponly' => true,
|
||
'samesite' => 'Lax',
|
||
'secure' => (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https'),
|
||
]);
|
||
session_start();
|
||
|
||
$STATUSES = [
|
||
'nouveau' => '🆕 Nouveau',
|
||
'en_cours' => '🔧 En cours',
|
||
'resolu' => '✅ Résolu',
|
||
'ignore' => '🙈 Ignoré',
|
||
];
|
||
$STATUS_COLORS = [
|
||
'nouveau' => '#38bdf8',
|
||
'en_cours' => '#fbbf24',
|
||
'resolu' => '#4ade80',
|
||
'ignore' => '#94a3b8',
|
||
];
|
||
|
||
/* ───────────────────────── helpers ───────────────────────── */
|
||
|
||
function h(?string $s): string
|
||
{
|
||
return htmlspecialchars((string) $s, ENT_QUOTES, 'UTF-8');
|
||
}
|
||
|
||
function current_user(): ?array
|
||
{
|
||
return isset($_SESSION['admin_user_id']) ? [
|
||
'id' => (int) $_SESSION['admin_user_id'],
|
||
'name' => (string) $_SESSION['admin_username'],
|
||
] : null;
|
||
}
|
||
|
||
function csrf_token(): string
|
||
{
|
||
if (empty($_SESSION['csrf'])) {
|
||
$_SESSION['csrf'] = bin2hex(random_bytes(32));
|
||
}
|
||
return $_SESSION['csrf'];
|
||
}
|
||
|
||
function csrf_ok(): bool
|
||
{
|
||
return hash_equals($_SESSION['csrf'] ?? '', $_POST['csrf'] ?? '');
|
||
}
|
||
|
||
function format_date(string $utc): string
|
||
{
|
||
try {
|
||
$d = new DateTime($utc, new DateTimeZone('UTC'));
|
||
$d->setTimezone(new DateTimeZone('Europe/Paris'));
|
||
return $d->format('d/m/Y H:i');
|
||
} catch (Throwable $e) {
|
||
return $utc;
|
||
}
|
||
}
|
||
|
||
function excerpt(string $s, int $len = 140): string
|
||
{
|
||
$s = trim(preg_replace('/\s+/', ' ', $s) ?? '');
|
||
if (mb_strlen($s) <= $len) {
|
||
return $s;
|
||
}
|
||
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;
|
||
}
|
||
|
||
/* ── Paquets : images (max 5, stockées sous p/assets/img/packages/) ── */
|
||
|
||
define('FWS_PKG_IMG_MAX', 5);
|
||
|
||
function fws_admin_packages_img_dir(): string
|
||
{
|
||
/* __DIR__ = admin/bugs → racine du site = deux niveaux au-dessus. */
|
||
return dirname(__DIR__, 2) . '/p/assets/img/packages';
|
||
}
|
||
|
||
/** Src web « /p/assets/img/packages/… » si l'image est dans le dossier géré, sinon null. */
|
||
function fws_admin_managed_img_web(string $src): ?string
|
||
{
|
||
$prefix = '/p/assets/img/packages/';
|
||
if (strncmp($src, $prefix, strlen($prefix)) !== 0) {
|
||
return null;
|
||
}
|
||
$name = basename($src);
|
||
if ($name === '' || str_contains($name, '..')) {
|
||
return null;
|
||
}
|
||
return $prefix . $name;
|
||
}
|
||
|
||
/** Supprime une image gérée si plus aucun paquet ne la référence. */
|
||
function fws_admin_delete_img_if_unused(PDO $pdo, string $src): void
|
||
{
|
||
$web = fws_admin_managed_img_web($src);
|
||
if ($web === null) {
|
||
return; /* image hors du dossier géré (chemin manuel) : on n'y touche pas */
|
||
}
|
||
$st = $pdo->prepare('SELECT COUNT(*) FROM packages WHERE screens LIKE :pat');
|
||
$st->execute([':pat' => '%' . $web . '%']);
|
||
if ((int) $st->fetchColumn() > 0) {
|
||
return; /* encore utilisée par un autre paquet */
|
||
}
|
||
$abs = dirname(__DIR__, 2) . $web;
|
||
if (is_file($abs)) {
|
||
@unlink($abs);
|
||
}
|
||
}
|
||
|
||
/** Valide et stocke un upload d'image de paquet. Renvoie le src web.
|
||
* Lance RuntimeException avec un message clair si le fichier est refusé. */
|
||
function fws_admin_store_screen_upload(array $file, string $slug): string
|
||
{
|
||
if (($file['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
|
||
throw new RuntimeException('Envoi impossible (code ' . (string) ($file['error'] ?? '?') . ').');
|
||
}
|
||
if (($file['size'] ?? 0) <= 0 || ($file['size'] ?? 0) > 2 * 1024 * 1024) {
|
||
throw new RuntimeException('« ' . (string) ($file['name'] ?? '?') . ' » dépasse 2 Mo.');
|
||
}
|
||
$ext = strtolower(pathinfo((string) ($file['name'] ?? ''), PATHINFO_EXTENSION));
|
||
$allowed = ['jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'webp' => 'image/webp', 'gif' => 'image/gif'];
|
||
if (!isset($allowed[$ext])) {
|
||
throw new RuntimeException('« ' . (string) ($file['name'] ?? '?') . ' » : format non supporté (jpg, png, webp, gif).');
|
||
}
|
||
$info = @getimagesize((string) ($file['tmp_name'] ?? ''));
|
||
if ($info === false || ($info['mime'] ?? '') !== $allowed[$ext]) {
|
||
throw new RuntimeException('« ' . (string) ($file['name'] ?? '?') . ' » n\'est pas une image valide.');
|
||
}
|
||
$dir = fws_admin_packages_img_dir();
|
||
if (!is_dir($dir) && !@mkdir($dir, 0775, true) && !is_dir($dir)) {
|
||
throw new RuntimeException('Impossible de créer le dossier des images.');
|
||
}
|
||
@chmod($dir, 0777); /* bind-mount Docker : tout appartient à root */
|
||
$base = trim(preg_replace('/[^a-zA-Z0-9-]+/', '-', $slug) ?? '', '-');
|
||
if ($base === '') {
|
||
$base = 'paquet';
|
||
}
|
||
$name = $base . '-' . bin2hex(random_bytes(8)) . '.' . $ext;
|
||
if (!@move_uploaded_file((string) ($file['tmp_name'] ?? ''), $dir . '/' . $name)) {
|
||
throw new RuntimeException('Échec de l\'enregistrement de « ' . (string) ($file['name'] ?? '?') . ' ».');
|
||
}
|
||
@chmod($dir . '/' . $name, 0644);
|
||
return '/p/assets/img/packages/' . $name;
|
||
}
|
||
|
||
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'] ?? '';
|
||
|
||
if ($action === 'login') {
|
||
$username = trim((string) ($_POST['username'] ?? ''));
|
||
$password = (string) ($_POST['password'] ?? '');
|
||
try {
|
||
$pdo = fws_bugs_db();
|
||
$st = $pdo->prepare('SELECT * FROM admin_users WHERE username = :u');
|
||
$st->execute([':u' => $username]);
|
||
$user = $st->fetch();
|
||
if ($user !== false && password_verify($password, $user['password_hash'])) {
|
||
session_regenerate_id(true);
|
||
$_SESSION['admin_user_id'] = (int) $user['id'];
|
||
$_SESSION['admin_username'] = (string) $user['username'];
|
||
$_SESSION['csrf'] = bin2hex(random_bytes(32));
|
||
header('Location: index.php');
|
||
exit;
|
||
}
|
||
$error = 'Identifiants incorrects.';
|
||
} catch (Throwable $e) {
|
||
$error = 'Erreur base de données : ' . $e->getMessage();
|
||
}
|
||
} elseif (current_user() !== null) {
|
||
if (!csrf_ok()) {
|
||
$error = 'Jeton de sécurité invalide, rechargez la page.';
|
||
} elseif ($action === 'logout') {
|
||
$_SESSION = [];
|
||
session_destroy();
|
||
header('Location: index.php');
|
||
exit;
|
||
} elseif ($action === 'set_status') {
|
||
$id = (int) ($_POST['id'] ?? 0);
|
||
$status = (string) ($_POST['status'] ?? '');
|
||
if (!isset($STATUSES[$status])) {
|
||
$error = 'Statut inconnu.';
|
||
} else {
|
||
$pdo = fws_bugs_db();
|
||
$st = $pdo->prepare('SELECT status, discord_thread_id FROM bug_reports WHERE id = :id');
|
||
$st->execute([':id' => $id]);
|
||
$row = $st->fetch();
|
||
$st = $pdo->prepare('UPDATE bug_reports SET status = :s WHERE id = :id');
|
||
$st->execute([':s' => $status, ':id' => $id]);
|
||
$notice = "Signalement #$id marqué « " . $STATUSES[$status] . " ».";
|
||
|
||
/* Prévenir Discord (best-effort) */
|
||
if ($row !== false && !empty($row['discord_thread_id'])) {
|
||
try {
|
||
$actor = current_user()['name'] ?? '';
|
||
fws_bugs_discord_status_change([
|
||
'thread_id' => (string) $row['discord_thread_id'],
|
||
'old_status' => (string) ($row['status'] ?? ''),
|
||
'new_status' => $status,
|
||
'actor' => (string) $actor,
|
||
]);
|
||
} catch (Throwable $e) {
|
||
error_log('[fws-bugs] discord statut : ' . $e->getMessage());
|
||
}
|
||
}
|
||
header('Location: index.php?id=' . $id);
|
||
exit;
|
||
}
|
||
} elseif ($action === 'delete') {
|
||
$id = (int) ($_POST['id'] ?? 0);
|
||
$pdo = fws_bugs_db();
|
||
$st = $pdo->prepare('DELETE FROM bug_reports WHERE id = :id');
|
||
$st->execute([':id' => $id]);
|
||
$notice = "Signalement #$id supprimé.";
|
||
header('Location: index.php');
|
||
exit;
|
||
} elseif ($action === 'gen_invite') {
|
||
$days = (int) ($_POST['days'] ?? 7);
|
||
if (!in_array($days, [0, 1, 7, 30, 90], true)) {
|
||
$days = 7;
|
||
}
|
||
$pdo = fws_bugs_db();
|
||
try {
|
||
$freshInvite = fws_bugs_create_invite($pdo, (string) (current_user()['name'] ?? ''), $days);
|
||
$notice = 'Code d\'invitation généré.';
|
||
} catch (Throwable $e) {
|
||
$error = 'Erreur : ' . $e->getMessage();
|
||
}
|
||
} elseif ($action === 'revoke_invite') {
|
||
$inviteId = (int) ($_POST['invite_id'] ?? 0);
|
||
$pdo = fws_bugs_db();
|
||
$st = $pdo->prepare("UPDATE invite_codes SET revoked_at = datetime('now') WHERE id = :id AND used_by IS NULL AND revoked_at IS NULL");
|
||
$st->execute([':id' => $inviteId]);
|
||
$notice = $st->rowCount() > 0
|
||
? 'Code d\'invitation révoqué : il ne fonctionnera plus.'
|
||
: 'Impossible de révoquer ce code (déjà utilisé ou déjà révoqué).';
|
||
} elseif ($action === 'change_password') {
|
||
$cur = (string) ($_POST['current_password'] ?? '');
|
||
$new = (string) ($_POST['new_password'] ?? '');
|
||
$confirm = (string) ($_POST['confirm_password'] ?? '');
|
||
$uid = (int) current_user()['id'];
|
||
$pdo = fws_bugs_db();
|
||
$st = $pdo->prepare('SELECT password_hash FROM admin_users WHERE id = :id');
|
||
$st->execute([':id' => $uid]);
|
||
$row = $st->fetch();
|
||
if ($row === false || !password_verify($cur, $row['password_hash'])) {
|
||
$error = 'Mot de passe actuel incorrect.';
|
||
} elseif (strlen($new) < 8) {
|
||
$error = 'Nouveau mot de passe trop court (8 caractères minimum).';
|
||
} elseif ($new !== $confirm) {
|
||
$error = 'Les deux nouveaux mots de passe ne correspondent pas.';
|
||
} else {
|
||
$up = $pdo->prepare('UPDATE admin_users SET password_hash = :h WHERE id = :id');
|
||
$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();
|
||
|
||
/* Captures d'écran : existantes conservées (avec légendes
|
||
éditées) + nouveaux envois, 5 maximum par paquet. */
|
||
$pkgIdPost = (int) ($_POST['pkg_id'] ?? 0);
|
||
$oldRow = null;
|
||
if ($pkgIdPost > 0) {
|
||
$stOld = $pdo->prepare('SELECT screens FROM packages WHERE id = :id');
|
||
$stOld->execute([':id' => $pkgIdPost]);
|
||
$oldRow = $stOld->fetch() ?: null;
|
||
}
|
||
$oldScreens = $oldRow !== null
|
||
? (array) (json_decode((string) $oldRow['screens'], true) ?: [])
|
||
: [];
|
||
|
||
$keep = array_fill_keys((array) ($_POST['keep_screens'] ?? []), true);
|
||
$captions = (array) ($_POST['captions'] ?? []);
|
||
$screens = [];
|
||
$removedSrcs = [];
|
||
foreach ($oldScreens as $os) {
|
||
$src = (string) ($os['src'] ?? '');
|
||
if ($src === '' || !isset($keep[$src])) {
|
||
/* Décochée : le fichier sera supprimé APRÈS la mise à
|
||
jour en base (sinon elle le compte encore en usage). */
|
||
if ($src !== '') {
|
||
$removedSrcs[] = $src;
|
||
}
|
||
continue;
|
||
}
|
||
$cap = isset($captions[$src]) ? trim((string) $captions[$src]) : '';
|
||
$screens[] = [
|
||
'src' => $src,
|
||
'alt' => ($os['alt'] ?? '') !== '' ? (string) $os['alt'] : $name,
|
||
'caption' => $cap !== '' ? $cap : null,
|
||
];
|
||
}
|
||
|
||
$newFiles = (array) ($_FILES['new_screens'] ?? []);
|
||
$countNew = is_array($newFiles['name'] ?? null) ? count($newFiles['name']) : 0;
|
||
|
||
/* Indices des fichiers réellement envoyés (pas les slots vides). */
|
||
$uploadIdx = [];
|
||
for ($i = 0; $i < $countNew; $i++) {
|
||
if ((int) ($newFiles['error'][$i] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_NO_FILE
|
||
|| (string) ($newFiles['name'][$i] ?? '') !== '') {
|
||
$uploadIdx[] = $i;
|
||
}
|
||
}
|
||
|
||
/* Limite vérifiée AVANT tout stockage : refus clair, rien n'est
|
||
écrit (ni base ni fichiers) si le total dépasse la limite. */
|
||
if (count($screens) + count($uploadIdx) > FWS_PKG_IMG_MAX) {
|
||
$error = 'Maximum ' . FWS_PKG_IMG_MAX . ' images par paquet : '
|
||
. count($screens) . ' conservée(s) + ' . count($uploadIdx)
|
||
. ' envoyée(s). Retirez-en d\'abord.';
|
||
} else {
|
||
$slugPost = trim((string) ($_POST['slug'] ?? ''));
|
||
if ($slugPost === '') {
|
||
$slugPost = trim(preg_replace('/[^a-zA-Z0-9]+/', '-', $name) ?? '', '-');
|
||
}
|
||
$storedThisRequest = [];
|
||
foreach ($uploadIdx as $i) {
|
||
try {
|
||
$src = fws_admin_store_screen_upload([
|
||
'name' => (string) $newFiles['name'][$i],
|
||
'type' => (string) ($newFiles['type'][$i] ?? ''),
|
||
'tmp_name' => (string) ($newFiles['tmp_name'][$i] ?? ''),
|
||
'error' => (int) ($newFiles['error'][$i] ?? UPLOAD_ERR_NO_FILE),
|
||
'size' => (int) ($newFiles['size'][$i] ?? 0),
|
||
], $slugPost);
|
||
$storedThisRequest[] = $src;
|
||
$screens[] = ['src' => $src, 'alt' => $name, 'caption' => null];
|
||
} catch (RuntimeException $ex) {
|
||
/* Un fichier invalide annule tout : on ne garde pas
|
||
des images déjà stockées mais non enregistrées. */
|
||
foreach ($storedThisRequest as $tmpSrc) {
|
||
@unlink(dirname(__DIR__, 2) . $tmpSrc);
|
||
}
|
||
$error = $ex->getMessage();
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if ($error === null) {
|
||
fws_packages_save($pdo, [
|
||
'id' => $pkgIdPost,
|
||
'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,
|
||
'changelog' => changelog_from_lines((string) ($_POST['changelog'] ?? '')),
|
||
]);
|
||
/* La base est à jour : on peut maintenant supprimer les
|
||
fichiers décochés devenus orphelins. */
|
||
foreach ($removedSrcs as $rsrc) {
|
||
fws_admin_delete_img_if_unused($pdo, $rsrc);
|
||
}
|
||
$wasEdit = $pkgIdPost > 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();
|
||
/* On note les images du paquet, on supprime la ligne, puis on
|
||
nettoie les fichiers devenus orphelins (la base ne doit plus
|
||
les référencer au moment de la vérification). */
|
||
$stDel = $pdo->prepare('SELECT screens FROM packages WHERE id = :id');
|
||
$stDel->execute([':id' => $pkgId]);
|
||
$rowDel = $stDel->fetch();
|
||
$orphanSrcs = [];
|
||
if ($rowDel !== false) {
|
||
foreach ((array) (json_decode((string) $rowDel['screens'], true) ?: []) as $os) {
|
||
$s = (string) ($os['src'] ?? '');
|
||
if ($s !== '') {
|
||
$orphanSrcs[] = $s;
|
||
}
|
||
}
|
||
}
|
||
fws_packages_delete($pdo, $pkgId);
|
||
foreach ($orphanSrcs as $osrc) {
|
||
fws_admin_delete_img_if_unused($pdo, $osrc);
|
||
}
|
||
$_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 {
|
||
$pdo = fws_bugs_db();
|
||
} catch (Throwable $e) {
|
||
http_response_code(500);
|
||
exit('Erreur base de données : ' . h($e->getMessage()));
|
||
}
|
||
|
||
$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];
|
||
foreach ($STATUSES as $k => $v) {
|
||
$counts[$k] = 0;
|
||
}
|
||
foreach ($pdo->query('SELECT status, COUNT(*) c FROM bug_reports GROUP BY status') as $row) {
|
||
$s = $row['status'];
|
||
if (isset($counts[$s])) {
|
||
$counts[$s] = (int) $row['c'];
|
||
$counts['tous'] += (int) $row['c'];
|
||
}
|
||
}
|
||
|
||
/* ───────────────────────── affichage ───────────────────────── */
|
||
|
||
header('Content-Type: text/html; charset=utf-8');
|
||
?><!doctype html>
|
||
<html lang="fr">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<meta name="robots" content="noindex,nofollow">
|
||
<title>Signalements — FWS Linux</title>
|
||
<style>
|
||
:root { color-scheme: dark; }
|
||
* { box-sizing: border-box; }
|
||
body {
|
||
margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
|
||
background: #0b1120; color: #e2e8f0; line-height: 1.5;
|
||
}
|
||
.wrap { max-width: 1000px; margin: 0 auto; padding: 24px 16px 80px; }
|
||
header.top {
|
||
display: flex; align-items: center; justify-content: space-between;
|
||
gap: 12px; padding: 14px 0; border-bottom: 1px solid #1e293b; margin-bottom: 20px;
|
||
}
|
||
header.top h1 { font-size: 1.15rem; margin: 0; }
|
||
header.top .sub { font-size: .8rem; color: #94a3b8; }
|
||
a { color: #38bdf8; text-decoration: none; }
|
||
a:hover { text-decoration: underline; }
|
||
.btn {
|
||
display: inline-block; border: 1px solid #334155; background: #1e293b; color: #e2e8f0;
|
||
padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: .85rem;
|
||
text-decoration: none; line-height: 1.4;
|
||
}
|
||
.btn:hover { background: #334155; text-decoration: none; }
|
||
.btn.primary { background: #0284c7; border-color: #0284c7; color: #fff; }
|
||
.btn.danger { background: transparent; border-color: #7f1d1d; color: #f87171; }
|
||
.btn.danger:hover { background: #7f1d1d; color: #fff; }
|
||
.btn.small { padding: 3px 9px; font-size: .78rem; }
|
||
.card {
|
||
background: #111a2e; border: 1px solid #1e293b; border-radius: 12px;
|
||
padding: 16px; margin-bottom: 12px;
|
||
}
|
||
.card h3 { margin: 0 0 4px; font-size: 1rem; }
|
||
.card .meta { font-size: .78rem; color: #94a3b8; display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 8px; }
|
||
.badge {
|
||
display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600;
|
||
}
|
||
.badge.type { background: #1e293b; color: #cbd5e1; }
|
||
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: .9rem; }
|
||
.flash.err { background: #450a0a; color: #fca5a5; border: 1px solid #7f1d1d; }
|
||
.flash.ok { background: #052e16; color: #86efac; border: 1px solid #166534; }
|
||
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
|
||
.filters a { border: 1px solid #334155; padding: 4px 12px; border-radius: 99px; font-size: .82rem; }
|
||
.filters a.active { background: #0284c7; border-color: #0284c7; color: #fff; }
|
||
.empty { text-align: center; color: #64748b; padding: 50px 0; }
|
||
pre.logs {
|
||
background: #0b1120; border: 1px solid #1e293b; border-radius: 8px;
|
||
padding: 12px; overflow: auto; max-height: 360px; font-size: .78rem; white-space: pre-wrap; word-break: break-word;
|
||
}
|
||
table.detail td { padding: 6px 0; vertical-align: top; }
|
||
table.detail td.k { color: #94a3b8; font-size: .8rem; width: 110px; padding-right: 12px; }
|
||
form.inline { display: inline; }
|
||
.status-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; align-items: center; }
|
||
/* login */
|
||
.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=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; }
|
||
|
||
/* ── Picker d'images des paquets ── */
|
||
.pkg-screens-picker {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
||
gap: 10px;
|
||
margin: 4px 0 6px;
|
||
}
|
||
.pkg-shot {
|
||
margin: 0;
|
||
border: 1px solid #1e293b;
|
||
border-radius: 10px;
|
||
overflow: hidden;
|
||
background: #0f172a;
|
||
display: grid;
|
||
gap: 4px;
|
||
padding: 6px;
|
||
}
|
||
.pkg-shot img {
|
||
width: 100%;
|
||
height: 70px;
|
||
object-fit: cover;
|
||
border-radius: 6px;
|
||
display: block;
|
||
}
|
||
.pkg-shot-keep {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 5px;
|
||
font-size: .72rem;
|
||
color: #94a3b8;
|
||
cursor: pointer;
|
||
}
|
||
.pkg-shot-keep input { accent-color: #0284c7; }
|
||
.pkg-shot input[type="text"] {
|
||
font-size: .75rem;
|
||
padding: 3px 6px;
|
||
}
|
||
.pkg-shot-add {
|
||
display: grid;
|
||
place-content: center;
|
||
justify-items: center;
|
||
gap: 2px;
|
||
min-height: 118px;
|
||
border-style: dashed;
|
||
cursor: pointer;
|
||
}
|
||
.pkg-shot-add:hover { border-color: #0284c7; }
|
||
.pkg-shot-plus { font-size: 1.6rem; color: #38bdf8; cursor: pointer; }
|
||
.pkg-shot-label {
|
||
font-size: .75rem;
|
||
color: #94a3b8;
|
||
text-align: center;
|
||
cursor: pointer;
|
||
}
|
||
.pkg-shot-label small { color: #64748b; }
|
||
.pkg-shot label { color: inherit; }
|
||
label { font-size: .85rem; color: #cbd5e1; }
|
||
.back { margin-bottom: 12px; display: inline-block; }
|
||
.pager { display: flex; gap: 8px; margin-top: 16px; }
|
||
.navtabs { display: flex; gap: 8px; margin: 0 0 16px; }
|
||
.navtabs a { border: 1px solid #334155; padding: 5px 14px; border-radius: 99px; font-size: .85rem; text-decoration: none; color: #cbd5e1; }
|
||
.navtabs a.active { background: #0284c7; border-color: #0284c7; color: #fff; }
|
||
.invite-form { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-top: 10px; }
|
||
.invite-form label { margin: 0; }
|
||
.invite-form select { background: #0b1120; color: #e2e8f0; border: 1px solid #334155; border-radius: 8px; padding: 9px 11px; font-size: .9rem; }
|
||
.invite-box { margin-top: 14px; padding: 14px; border: 1px dashed #38bdf8; border-radius: 10px; background: #0c1a2b; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: .9rem; }
|
||
.invite-code { font-size: 1.2rem; letter-spacing: .08em; font-weight: 700; color: #7dd3fc; font-family: ui-monospace, Consolas, monospace; }
|
||
table.list { width: 100%; border-collapse: collapse; font-size: .88rem; }
|
||
table.list th, table.list td { text-align: left; padding: 7px 8px; border-bottom: 1px solid #1e293b; vertical-align: middle; }
|
||
table.list th { color: #94a3b8; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
|
||
.login-register { text-align: center; margin-top: 14px; font-size: .85rem; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="wrap">
|
||
|
||
<?php if ($user === null): /* ─────────── LOGIN ─────────── */ ?>
|
||
|
||
<div class="login-box">
|
||
<div class="card">
|
||
<h1>🔒 Panneau des signalements</h1>
|
||
<?php if (($_GET['registered'] ?? '') === '1'): ?><div class="flash ok">✅ Compte créé ! Connectez-vous avec vos identifiants.</div><?php endif; ?>
|
||
<?php if ($error): ?><div class="flash err"><?= h($error) ?></div><?php endif; ?>
|
||
<?php if ($counts['tous'] === 0): ?>
|
||
<p style="font-size:.85rem;color:#94a3b8">
|
||
Aucun compte admin pour l'instant.<br>Créez-le dans le conteneur :
|
||
</p>
|
||
<pre class="logs">docker exec -it fws-files php /var/www/html/admin/bugs/init.php</pre>
|
||
<?php endif; ?>
|
||
<form method="post" autocomplete="on">
|
||
<input type="hidden" name="action" value="login">
|
||
<label for="username">Nom d'utilisateur</label>
|
||
<input type="text" id="username" name="username" required autofocus>
|
||
<label for="password">Mot de passe</label>
|
||
<input type="password" id="password" name="password" required>
|
||
<button class="btn primary" type="submit" style="width:100%;padding:10px">Se connecter</button>
|
||
</form>
|
||
<p class="login-register">Pas encore de compte ? <a href="register.php">S'inscrire avec un code d'invitation</a></p>
|
||
</div>
|
||
</div>
|
||
|
||
<?php else: /* ─────────── ESPACE ADMIN ─────────── */ ?>
|
||
|
||
<header class="top">
|
||
<div>
|
||
<h1>🐞 Signalements de bugs</h1>
|
||
<div class="sub">Connecté : <?= h($user['name']) ?> · Base SQLite · <a href="<?= h(fws_url('/api/bugs.php')) ?>" target="_blank">tester l'API</a></div>
|
||
</div>
|
||
<form class="inline" method="post">
|
||
<input type="hidden" name="action" value="logout">
|
||
<input type="hidden" name="csrf" value="<?= h(csrf_token()) ?>">
|
||
<button class="btn" type="submit">Déconnexion</button>
|
||
</form>
|
||
</header>
|
||
|
||
<div class="navtabs">
|
||
<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; ?>
|
||
<?php if ($notice): ?><div class="flash ok"><?= h($notice) ?></div><?php endif; ?>
|
||
|
||
<?php if ($view_id > 0): /* ─────────── DÉTAIL ─────────── */
|
||
|
||
$st = $pdo->prepare('SELECT * FROM bug_reports WHERE id = :id');
|
||
$st->execute([':id' => $view_id]);
|
||
$r = $st->fetch();
|
||
if ($r === false):
|
||
?>
|
||
<p class="empty">Signalement #<?= $view_id ?> introuvable.</p>
|
||
<a href="index.php" class="btn">← Retour à la liste</a>
|
||
<?php else: ?>
|
||
<a href="index.php" class="back">← Retour à la liste</a>
|
||
<div class="card">
|
||
<div style="display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap;align-items:baseline">
|
||
<h3>#<?= (int) $r['id'] ?> — <?= h($r['title'] !== '' ? $r['title'] : '(sans titre)') ?></h3>
|
||
<span class="badge" style="background:<?= $STATUS_COLORS[$r['status']] ?>33;color:<?= $STATUS_COLORS[$r['status']] ?>"><?= h($STATUSES[$r['status']] ?? $r['status']) ?></span>
|
||
</div>
|
||
<div class="meta">
|
||
<span>📅 <?= h(format_date($r['created_at'])) ?></span>
|
||
<span>📦 <?= h($r['app'] !== '' ? $r['app'] : '?') ?> <?= h($r['version']) ?></span>
|
||
<span class="badge type"><?= h($r['type']) ?></span>
|
||
</div>
|
||
|
||
<?php if ($r['description'] !== ''): ?>
|
||
<p style="white-space:pre-wrap;margin:10px 0"><?= h($r['description']) ?></p>
|
||
<?php endif; ?>
|
||
|
||
<table class="detail">
|
||
<?php if ($r['email'] !== ''): ?>
|
||
<tr><td class="k">E-mail</td><td><a href="mailto:<?= h($r['email']) ?>"><?= h($r['email']) ?></a></td></tr>
|
||
<?php endif; ?>
|
||
<?php if ($r['system_info'] !== ''): ?>
|
||
<tr><td class="k">Système</td><td style="white-space:pre-wrap"><?= h($r['system_info']) ?></td></tr>
|
||
<?php endif; ?>
|
||
<tr><td class="k">IP</td><td><?= h($r['ip'] !== '' ? $r['ip'] : '?') ?></td></tr>
|
||
<tr><td class="k">User-agent</td><td style="font-size:.78rem;color:#94a3b8"><?= h($r['user_agent']) ?></td></tr>
|
||
<?php if (!empty($r['discord_post_url'])): ?>
|
||
<tr><td class="k">Discord</td><td><a href="<?= h($r['discord_post_url']) ?>" target="_blank" rel="noopener">Voir le post dans le forum ↗</a></td></tr>
|
||
<?php elseif (!empty($r['discord_thread_id'])): ?>
|
||
<tr><td class="k">Discord</td><td style="color:#94a3b8">post créé (lien indisponible)</td></tr>
|
||
<?php endif; ?>
|
||
</table>
|
||
|
||
<?php if ($r['logs'] !== ''): ?>
|
||
<div style="margin-top:12px">
|
||
<div style="font-size:.8rem;color:#94a3b8;margin-bottom:6px">📜 Logs :</div>
|
||
<pre class="logs"><?= h($r['logs']) ?></pre>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<div class="status-row">
|
||
<span style="font-size:.85rem;color:#94a3b8">Changer le statut :</span>
|
||
<?php foreach ($STATUSES as $sk => $sv):
|
||
if ($sk === $r['status']) continue; ?>
|
||
<form class="inline" method="post">
|
||
<input type="hidden" name="action" value="set_status">
|
||
<input type="hidden" name="csrf" value="<?= h(csrf_token()) ?>">
|
||
<input type="hidden" name="id" value="<?= (int) $r['id'] ?>">
|
||
<input type="hidden" name="status" value="<?= $sk ?>">
|
||
<button class="btn small" type="submit"><?= h($sv) ?></button>
|
||
</form>
|
||
<?php endforeach; ?>
|
||
<span style="flex:1"></span>
|
||
<form class="inline" method="post" onsubmit="return confirm('Supprimer définitivement le signalement #<?= (int) $r['id'] ?> ?')">
|
||
<input type="hidden" name="action" value="delete">
|
||
<input type="hidden" name="csrf" value="<?= h(csrf_token()) ?>">
|
||
<input type="hidden" name="id" value="<?= (int) $r['id'] ?>">
|
||
<button class="btn small danger" type="submit">🗑 Supprimer</button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<?php endif; /* fin détail */ ?>
|
||
|
||
<?php elseif ($view_invites): /* ─────────── INVITATIONS & COMPTES ─────────── */
|
||
|
||
$invites = $pdo->query('SELECT * FROM invite_codes ORDER BY id DESC LIMIT 200')->fetchAll();
|
||
$users = $pdo->query('SELECT id, username, created_at FROM admin_users ORDER BY id')->fetchAll();
|
||
$userNames = [];
|
||
foreach ($users as $u) {
|
||
$userNames[(int) $u['id']] = (string) $u['username'];
|
||
}
|
||
$now = date('Y-m-d H:i:s');
|
||
?>
|
||
|
||
<div class="card">
|
||
<h3>🎟️ Générer un code d'invitation</h3>
|
||
<p style="font-size:.85rem;color:#94a3b8">Le code est <strong>à usage unique</strong> : donnez-le à la personne, elle l'utilise sur la page
|
||
<a href="register.php" target="_blank" rel="noopener">admin/bugs/register.php</a> pour créer son compte (nom + mot de passe).</p>
|
||
<form method="post" class="invite-form">
|
||
<input type="hidden" name="action" value="gen_invite">
|
||
<input type="hidden" name="csrf" value="<?= h(csrf_token()) ?>">
|
||
<label for="days">Valable</label>
|
||
<select name="days" id="days">
|
||
<option value="1">1 jour</option>
|
||
<option value="7" selected>7 jours</option>
|
||
<option value="30">30 jours</option>
|
||
<option value="90">90 jours</option>
|
||
<option value="0">Sans expiration</option>
|
||
</select>
|
||
<button class="btn primary" type="submit">Générer le code</button>
|
||
</form>
|
||
<?php if ($freshInvite !== ''): ?>
|
||
<div class="invite-box">
|
||
<span>🎉 Nouveau code à donner :</span>
|
||
<code class="invite-code" id="freshCode"><?= h($freshInvite) ?></code>
|
||
<button class="btn small" type="button"
|
||
onclick="var t=document.getElementById('freshCode').textContent.trim();if(navigator.clipboard){navigator.clipboard.writeText(t);}this.textContent='✅ Copié';">📋 Copier</button>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h3>Codes générés (<?= count($invites) ?>)</h3>
|
||
<?php if (!$invites): ?>
|
||
<p class="empty">Aucun code pour l'instant.</p>
|
||
<?php else: ?>
|
||
<table class="list">
|
||
<tr><th>Code</th><th>Créé</th><th>Expire</th><th>Statut</th><th>Utilisé par</th><th></th></tr>
|
||
<?php foreach ($invites as $inv):
|
||
$isRevoked = $inv['revoked_at'] !== null;
|
||
$isUsed = $inv['used_by'] !== null;
|
||
$isExpired = !$isUsed && !$isRevoked && $inv['expires_at'] !== null && $inv['expires_at'] < $now;
|
||
if ($isRevoked) { $stLabel = 'Révoqué'; $stColor = '#f87171'; }
|
||
elseif ($isUsed) { $stLabel = 'Utilisé'; $stColor = '#94a3b8'; }
|
||
elseif ($isExpired) { $stLabel = 'Expiré'; $stColor = '#fbbf24'; }
|
||
else { $stLabel = 'Actif'; $stColor = '#4ade80'; }
|
||
?>
|
||
<tr>
|
||
<td style="font-family:ui-monospace,Consolas,monospace;letter-spacing:.05em"><?= h($inv['code']) ?></td>
|
||
<td><?= h(format_date((string) $inv['created_at'])) ?><?= $inv['created_by'] !== '' ? ' · ' . h($inv['created_by']) : '' ?></td>
|
||
<td><?= $inv['expires_at'] !== null ? h(format_date((string) $inv['expires_at'])) : '∞ jamais' ?></td>
|
||
<td><span class="badge" style="background:<?= $stColor ?>22;color:<?= $stColor ?>"><?= $stLabel ?></span></td>
|
||
<td><?= $inv['used_by'] !== null
|
||
? h($userNames[(int) $inv['used_by']] ?? '#'.$inv['used_by']) . ' · ' . h(format_date((string) $inv['used_at']))
|
||
: '' ?></td>
|
||
<td style="text-align:right">
|
||
<?php if (!$isUsed && !$isRevoked && !$isExpired): ?>
|
||
<form class="inline" method="post" onsubmit="return confirm('Révoquer ce code ? Il ne fonctionnera plus.')">
|
||
<input type="hidden" name="action" value="revoke_invite">
|
||
<input type="hidden" name="csrf" value="<?= h(csrf_token()) ?>">
|
||
<input type="hidden" name="invite_id" value="<?= (int) $inv['id'] ?>">
|
||
<button class="btn small danger" type="submit">Révoquer</button>
|
||
</form>
|
||
<?php endif; ?>
|
||
</td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</table>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h3>👥 Comptes existants (<?= count($users) ?>)</h3>
|
||
<p style="font-size:.85rem;color:#94a3b8">Tous les comptes peuvent consulter et traiter les signalements. Chacun peut modifier son propre mot de passe ci-dessous.</p>
|
||
<?php if (!$users): ?>
|
||
<p class="empty">Aucun compte.</p>
|
||
<?php else: ?>
|
||
<table class="list">
|
||
<tr><th>Nom</th><th>Créé le</th></tr>
|
||
<?php foreach ($users as $u): ?>
|
||
<tr>
|
||
<td><?= h($u['username']) ?></td>
|
||
<td><?= h(format_date((string) $u['created_at'])) ?></td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</table>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h3>🔑 Mon mot de passe</h3>
|
||
<p style="font-size:.85rem;color:#94a3b8">Connecté en tant que <strong><?= h($user['name']) ?></strong>. Le nouveau mot de passe doit faire au moins 8 caractères.</p>
|
||
<form method="post" style="display:grid;gap:2px;max-width:420px">
|
||
<input type="hidden" name="action" value="change_password">
|
||
<input type="hidden" name="csrf" value="<?= h(csrf_token()) ?>">
|
||
<label for="current_password">Mot de passe actuel</label>
|
||
<input type="password" id="current_password" name="current_password" required autocomplete="current-password">
|
||
<label for="new_password">Nouveau mot de passe</label>
|
||
<input type="password" id="new_password" name="new_password" required minlength="8" autocomplete="new-password">
|
||
<label for="confirm_password">Confirmer le nouveau mot de passe</label>
|
||
<input type="password" id="confirm_password" name="confirm_password" required minlength="8" autocomplete="new-password">
|
||
<button class="btn primary" type="submit" style="justify-self:start;margin-top:4px">Mettre à jour le mot de passe</button>
|
||
</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) ?: []));
|
||
/* Captures actuelles du paquet (picker d'images). */
|
||
$formScreensData = [];
|
||
foreach ((array) (json_decode((string) $form['screens'], true) ?: []) as $fsd) {
|
||
if (is_array($fsd) && (string) ($fsd['src'] ?? '') !== '') {
|
||
$formScreensData[] = $fsd;
|
||
}
|
||
}
|
||
$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" enctype="multipart/form-data" 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>Captures d'écran (<?= count($formScreensData) ?>/<?= FWS_PKG_IMG_MAX ?>) — décochez pour retirer</label>
|
||
<div class="pkg-screens-picker">
|
||
<?php $remaining = FWS_PKG_IMG_MAX - count($formScreensData); foreach ($formScreensData as $fs): $src = (string) ($fs['src'] ?? ''); if ($src === '') continue; ?>
|
||
<figure class="pkg-shot">
|
||
<img src="<?= h(function_exists('fws_url') ? fws_url($src) : $src) ?>" alt="">
|
||
<label class="pkg-shot-keep"><input type="checkbox" name="keep_screens[]" value="<?= h($src) ?>" checked> garder</label>
|
||
<input type="text" name="captions[<?= h($src) ?>]" value="<?= h((string) ($fs['caption'] ?? '')) ?>" placeholder="Légende (optionnelle)">
|
||
</figure>
|
||
<?php endforeach; ?>
|
||
<?php if ($remaining > 0): ?>
|
||
<figure class="pkg-shot pkg-shot-add">
|
||
<label for="pkg_new_screens" class="pkg-shot-plus" title="Ajouter des images">+</label>
|
||
<input type="file" id="pkg_new_screens" name="new_screens[]" accept="image/png,image/jpeg,image/webp,image/gif" multiple style="display:none">
|
||
<label for="pkg_new_screens" class="pkg-shot-label">Ajouter…<br><small><?= $remaining ?> restante(s)</small></label>
|
||
</figure>
|
||
<?php endif; ?>
|
||
</div>
|
||
<small id="pkg-new-hint" style="color:#94a3b8;font-size:.78rem">JPG / PNG / WebP / GIF — 2 Mo max par image, <?= FWS_PKG_IMG_MAX ?> images max par paquet. Elles sont servies sur tout le site (cartes, page détail, menu).</small>
|
||
<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';
|
||
if (!isset($counts[$filter])) $filter = 'tous';
|
||
$page = max(1, (int) ($_GET['page'] ?? 1));
|
||
$perPage = 25;
|
||
|
||
$where = '';
|
||
$params = [];
|
||
if ($filter !== 'tous') {
|
||
$where = 'WHERE status = :status';
|
||
$params[':status'] = $filter;
|
||
}
|
||
$st = $pdo->prepare("SELECT COUNT(*) FROM bug_reports $where");
|
||
$st->execute($params);
|
||
$total = (int) $st->fetchColumn();
|
||
$pages = max(1, (int) ceil($total / $perPage));
|
||
$page = min($page, $pages);
|
||
$offset = ($page - 1) * $perPage;
|
||
|
||
$st = $pdo->prepare(
|
||
"SELECT * FROM bug_reports $where ORDER BY id DESC LIMIT :lim OFFSET :off"
|
||
);
|
||
$st->bindValue(':lim', $perPage, PDO::PARAM_INT);
|
||
$st->bindValue(':off', $offset, PDO::PARAM_INT);
|
||
foreach ($params as $k => $v) $st->bindValue($k, $v);
|
||
$st->execute();
|
||
$reports = $st->fetchAll();
|
||
?>
|
||
|
||
<div class="filters">
|
||
<?php foreach ($counts as $k => $c): ?>
|
||
<a href="index.php?status=<?= $k ?>" class="<?= $filter === $k ? 'active' : '' ?>">
|
||
<?= $k === 'tous' ? 'Tous' : h($STATUSES[$k]) ?> (<?= $c ?>)
|
||
</a>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
|
||
<?php if ($total === 0): ?>
|
||
<p class="empty">Aucun signalement <?= $filter !== 'tous' ? 'avec ce statut' : '' ?> pour le moment. 🎉</p>
|
||
<?php else: ?>
|
||
<?php foreach ($reports as $r): ?>
|
||
<a href="index.php?id=<?= (int) $r['id'] ?>" style="text-decoration:none;color:inherit">
|
||
<div class="card">
|
||
<div style="display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap;align-items:baseline">
|
||
<h3>#<?= (int) $r['id'] ?> — <?= h($r['title'] !== '' ? $r['title'] : '(sans titre)') ?></h3>
|
||
<span class="badge" style="background:<?= $STATUS_COLORS[$r['status']] ?>33;color:<?= $STATUS_COLORS[$r['status']] ?>"><?= h($STATUSES[$r['status']] ?? $r['status']) ?></span>
|
||
</div>
|
||
<div class="meta">
|
||
<span>📅 <?= h(format_date($r['created_at'])) ?></span>
|
||
<span>📦 <?= h($r['app'] !== '' ? $r['app'] : '?') ?> <?= h($r['version']) ?></span>
|
||
<span class="badge type"><?= h($r['type']) ?></span>
|
||
<?php if ($r['email'] !== ''): ?><span>✉️ <?= h($r['email']) ?></span><?php endif; ?>
|
||
</div>
|
||
<?php if ($r['description'] !== ''): ?>
|
||
<p style="margin:4px 0 0;font-size:.9rem;color:#cbd5e1"><?= h(excerpt($r['description'])) ?></p>
|
||
<?php endif; ?>
|
||
</div>
|
||
</a>
|
||
<?php endforeach; ?>
|
||
|
||
<?php if ($pages > 1): ?>
|
||
<div class="pager">
|
||
<?php if ($page > 1): ?><a class="btn" href="index.php?status=<?= $filter ?>&page=<?= $page - 1 ?>">← Précédent</a><?php endif; ?>
|
||
<span style="align-self:center;font-size:.85rem;color:#94a3b8">Page <?= $page ?> / <?= $pages ?></span>
|
||
<?php if ($page < $pages): ?><a class="btn" href="index.php?status=<?= $filter ?>&page=<?= $page + 1 ?>">Suivant →</a><?php endif; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
<?php endif; ?>
|
||
|
||
<?php endif; /* fin liste */ ?>
|
||
|
||
<?php endif; /* fin espace admin */ ?>
|
||
|
||
</div>
|
||
|
||
<script>
|
||
/* Picker d'images des paquets : aperçu immédiat des fichiers choisis,
|
||
limite dure au nombre maximum autorisé. */
|
||
(function () {
|
||
var picker = document.querySelector('.pkg-screens-picker');
|
||
var input = document.getElementById('pkg_new_screens');
|
||
if (!picker || !input) return;
|
||
|
||
var addFigure = input.closest('.pkg-shot-add');
|
||
var existing = picker.querySelectorAll('.pkg-shot:not(.pkg-shot-add)').length;
|
||
var max = <?= (int) FWS_PKG_IMG_MAX ?>;
|
||
var hint = document.getElementById('pkg-new-hint');
|
||
var hintText = hint ? hint.textContent : '';
|
||
|
||
input.addEventListener('change', function () {
|
||
var room = max - existing;
|
||
var files = Array.prototype.slice.call(input.files || []);
|
||
if (files.length > room) {
|
||
alert('Maximum ' + max + ' images par paquet (' + room + ' restante(s)).');
|
||
input.value = '';
|
||
return;
|
||
}
|
||
/* Retire l'ancien aperçu puis montre les nouveaux. */
|
||
picker.querySelectorAll('.pkg-shot-preview').forEach(function (n) { n.remove(); });
|
||
files.forEach(function (f) {
|
||
var fig = document.createElement('figure');
|
||
fig.className = 'pkg-shot pkg-shot-preview';
|
||
var img = document.createElement('img');
|
||
img.alt = f.name;
|
||
img.style.opacity = '0.85';
|
||
var cap = document.createElement('div');
|
||
cap.style.cssText = 'font-size:.7rem;color:#64748b;overflow:hidden;text-overflow:ellipsis;white-space:nowrap';
|
||
cap.textContent = f.name;
|
||
fig.appendChild(img);
|
||
fig.appendChild(cap);
|
||
picker.insertBefore(fig, addFigure);
|
||
if (URL && URL.createObjectURL) {
|
||
var url = URL.createObjectURL(f);
|
||
img.src = url;
|
||
fig.addEventListener('remove', function () { URL.revokeObjectURL(url); });
|
||
}
|
||
});
|
||
});
|
||
|
||
/* On désactive proprement le champ si l'utilisateur décoche des images
|
||
existantes (le nombre maximal est vérifié côté serveur de toute façon). */
|
||
if (hint) {
|
||
picker.addEventListener('change', function (ev) {
|
||
var cb = ev.target.closest('input[type=checkbox]');
|
||
if (!cb) return;
|
||
var fig = cb.closest('.pkg-shot');
|
||
if (fig) fig.style.opacity = cb.checked ? '1' : '0.35';
|
||
});
|
||
}
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|