csrf_jeton(), csrf_champ() et csrf_verifier() dans inc/auth.php : un jeton par session, comparé par hash_equals, réponse 400 s'il manque ou ne correspond pas. La vérification est appelée en tête de chaque page qui traite un POST — console d'administration (membres, validation, révocation, groupes, services) et pages des membres (profil, mot de passe, inscription, renouvellement d'adhésion) —, et chaque formulaire porte le champ caché. Ajoute aussi e(), l'échappement de sortie à utiliser dans tout nouveau code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V2csyno8m71DJFKYM1vgzV
121 lines
4.4 KiB
PHP
121 lines
4.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../inc/config.php';
|
|
require_once __DIR__ . '/../inc/auth.php';
|
|
require_once __DIR__ . '/../inc/services.php';
|
|
require_once __DIR__ . '/../inc/keycloak.php';
|
|
|
|
session_start_safe();
|
|
require_admin();
|
|
csrf_verifier();
|
|
|
|
$kc_groups = kc_list_groups();
|
|
$group_names = array_column($kc_groups, 'name');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$updated = [];
|
|
foreach ($_POST as $key => $val) {
|
|
if (!str_starts_with($key, 'name_')) continue;
|
|
$idx = substr($key, 5);
|
|
$updated[] = [
|
|
'name' => trim($val),
|
|
'url' => trim($_POST["url_$idx"] ?? ''),
|
|
'description' => trim($_POST["description_$idx"] ?? ''),
|
|
'groups' => (array)($_POST["groups_$idx"] ?? []),
|
|
'visible' => isset($_POST["visible_$idx"]),
|
|
];
|
|
}
|
|
$new_name = trim($_POST['new_name'] ?? '');
|
|
if ($new_name) {
|
|
$updated[] = [
|
|
'name' => $new_name,
|
|
'url' => trim($_POST['new_url'] ?? ''),
|
|
'description' => trim($_POST['new_description'] ?? ''),
|
|
'groups' => (array)($_POST['new_groups'] ?? []),
|
|
'visible' => isset($_POST['new_visible']),
|
|
];
|
|
}
|
|
services_save($updated);
|
|
set_flash('success', 'Services sauvegardés.');
|
|
header('Location: /admin/services.php');
|
|
exit;
|
|
}
|
|
|
|
$services = services_list();
|
|
$title = 'Paramétrage des services';
|
|
require __DIR__ . '/../views/layout.php';
|
|
?>
|
|
|
|
<div class="admin-page">
|
|
<div class="page-header">
|
|
<h1>Paramétrage des services</h1>
|
|
<div class="admin-nav">
|
|
<a href="/admin/members.php">Membres</a>
|
|
<a href="/admin/groups.php">Groupes</a>
|
|
<a href="/admin/services.php" class="active">Services</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<form method="post">
|
|
<?= csrf_champ() ?>
|
|
<table class="services-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Nom</th>
|
|
<th>URL</th>
|
|
<th>Description</th>
|
|
<th>Groupes requis</th>
|
|
<th>Visible</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($services as $i => $s): ?>
|
|
<tr>
|
|
<td><input type="text" name="name_<?= $i ?>" value="<?= htmlspecialchars($s['name']) ?>" required></td>
|
|
<td><input type="url" name="url_<?= $i ?>" value="<?= htmlspecialchars($s['url']) ?>"></td>
|
|
<td><input type="text" name="description_<?= $i ?>" value="<?= htmlspecialchars($s['description']) ?>"></td>
|
|
<td>
|
|
<div class="group-checks">
|
|
<?php foreach ($group_names as $gn): ?>
|
|
<label class="group-check-label">
|
|
<input type="checkbox" name="groups_<?= $i ?>[]" value="<?= htmlspecialchars($gn) ?>"
|
|
<?= in_array($gn, $s['groups'], true) ? 'checked' : '' ?>>
|
|
<?= htmlspecialchars($gn) ?>
|
|
</label>
|
|
<?php endforeach; ?>
|
|
<?php if (!$group_names): ?>
|
|
<span class="text-muted small">Aucun groupe</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</td>
|
|
<td class="center">
|
|
<input type="checkbox" name="visible_<?= $i ?>" <?= $s['visible'] ? 'checked' : '' ?>>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<tr class="new-row">
|
|
<td><input type="text" name="new_name" placeholder="Nouveau service"></td>
|
|
<td><input type="url" name="new_url" placeholder="https://..."></td>
|
|
<td><input type="text" name="new_description" placeholder="Description"></td>
|
|
<td>
|
|
<div class="group-checks">
|
|
<?php foreach ($group_names as $gn): ?>
|
|
<label class="group-check-label">
|
|
<input type="checkbox" name="new_groups[]" value="<?= htmlspecialchars($gn) ?>">
|
|
<?= htmlspecialchars($gn) ?>
|
|
</label>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</td>
|
|
<td class="center"><input type="checkbox" name="new_visible" checked></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<div style="margin-top:1rem">
|
|
<button type="submit" class="btn-primary">Enregistrer</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require __DIR__ . '/../views/layout_end.php'; ?>
|