Files
PS_Launcher/server/admin/audit.php
j.foucher 92f4fd16e8 Backoffice: PHP admin web UI for licenses, versions, audit
Self-contained admin under /PS_Launcher/admin/ on the same OVH host. No
JS framework, no Composer deps — just PHP 8.3 + sessions + a small CSS.

Auth & infrastructure
---------------------
- admin/lib/Auth.php: session + CSRF helper. Login via password_hash /
  password_verify. session_regenerate_id on successful login.
  config.example.php gains admin_password_hash, generated by:
  php -r "echo password_hash('PWD', PASSWORD_DEFAULT);"
- admin/lib/Layout.php: shared header/footer/nav, formatBytes,
  csrfField helpers.
- admin/.htaccess: noindex / X-Frame-Options DENY / X-Content-Type
  nosniff / blocks lib/*.php from web access.
- admin/assets/style.css: matches launcher's dark theme — same
  Brush.* palette mapped to CSS vars, vivid green/blue/amber status
  pills consistent with the WPF UI.

Pages
-----
- index.php (Dashboard): KPIs (active/expired/revoked licenses, machines
  seen 30d, validations 24h), manifest signature status, last 10
  audit_log entries.
- licenses.php: full CRUD.
  * Émettre: owner, expiration date, max machines, internal notes →
    generates a PRSRV-XXXX-XXXX-XXXX-XXXX key, displays it ONCE in a
    green callout (DB stores the key; the message stays only on this
    request, never shown again).
  * Prolonger (per-row, expandable form), Revoke / Unrevoke,
    Reset machines (frees all slots for that license).
  * Status badge: active / expired / revoked.
- versions.php: edit the manifest from the web.
  * Add a version: number + release date + minLicenseDate + release
    notes Markdown (creates releasenotes/{version}.md). Sets default
    download URL to {base_url}/builds/proserve-{version}.zip.
  * Per-row Méta (edit minLicenseDate / releasedAt), Notes (edit md
    inline), toggle availableForDownload, Delete entry.
  * 🔁 Sync (sign-manifest) button: shells out to
    `php tools/sign-manifest.php` and shows its stdout — recomputes
    sha256/sizeBytes for every uploaded ZIP, bumps `latest`, signs
    Ed25519. Visual indicators on each row: zip presence, hash
    computed yes/no, signature status.
  * Lists orphan ZIPs in builds/ that no manifest entry references.
- audit.php: paginated audit_log viewer (100/page) with event-type
  filter dropdown. JOINs licenses to show owner_name. Color-codes
  events (validate_ok green, expired amber, invalid/revoked red).

Server README rewritten to document the full setup flow:
1. Create MySQL DB, run migrations/001_init.sql
2. Copy config.example.php → config.php, fill db credentials
3. php tools/generate-keypair.php → paste into config.php and into the
   client's Resources/server-pubkey.txt
4. Set admin_password_hash in config.php
5. Login at /PS_Launcher/admin/

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 10:21:52 +02:00

122 lines
4.6 KiB
PHP

<?php
declare(strict_types=1);
require __DIR__ . '/lib/Auth.php';
require __DIR__ . '/lib/Layout.php';
require __DIR__ . '/../api/lib/Db.php';
use PSLauncher\Admin\Auth;
use PSLauncher\Admin\Layout;
use PSLauncher\Db;
Auth::requireLogin();
$config = require __DIR__ . '/../api/config.php';
$db = Db::get($config);
$page = max(1, (int)($_GET['page'] ?? 1));
$pageSize = 100;
$offset = ($page - 1) * $pageSize;
$filter = trim((string)($_GET['event'] ?? ''));
$where = '';
$params = [];
if ($filter !== '') {
$where = 'WHERE event = ?';
$params[] = $filter;
}
$total = (int)$db->prepare("SELECT COUNT(*) FROM audit_log $where")->execute($params) ?? 0;
$totalStmt = $db->prepare("SELECT COUNT(*) FROM audit_log $where");
$totalStmt->execute($params);
$total = (int)$totalStmt->fetchColumn();
$totalPages = max(1, (int)ceil($total / $pageSize));
$listStmt = $db->prepare("SELECT a.*, l.owner_name FROM audit_log a LEFT JOIN licenses l ON l.id = a.license_id $where ORDER BY a.id DESC LIMIT $pageSize OFFSET $offset");
$listStmt->execute($params);
$rows = $listStmt->fetchAll();
$eventTypes = $db->query('SELECT DISTINCT event FROM audit_log ORDER BY event')->fetchAll(\PDO::FETCH_COLUMN);
Layout::header('Audit', 'audit');
?>
<h1>Audit log</h1>
<div class="card">
<form method="get" class="toolbar">
<label style="margin: 0;">Filtrer par événement :</label>
<select name="event" onchange="this.form.submit()">
<option value="">Tous (<?= number_format($total) ?>)</option>
<?php foreach ($eventTypes as $ev): ?>
<option value="<?= htmlspecialchars($ev) ?>" <?= $ev === $filter ? 'selected' : '' ?>>
<?= htmlspecialchars($ev) ?>
</option>
<?php endforeach; ?>
</select>
<?php if ($filter !== ''): ?>
<a href="audit.php" class="btn btn-secondary">Réinitialiser</a>
<?php endif; ?>
<span class="muted" style="margin-left: auto;">page <?= $page ?> / <?= $totalPages ?> • <?= number_format($total) ?> entrée(s)</span>
</form>
<?php if (empty($rows)): ?>
<p class="muted">Aucune entrée d'audit.</p>
<?php else: ?>
<table>
<thead>
<tr>
<th>Date</th>
<th>Événement</th>
<th>License</th>
<th>IP</th>
<th>Détail</th>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $r):
$cls = match($r['event']) {
'validate_ok' => 'badge-success',
'validate_invalid', 'validate_revoked', 'machine_limit' => 'badge-danger',
'validate_expired' => 'badge-warning',
default => 'badge-secondary',
};
$detail = $r['detail'] ? json_decode($r['detail'], true) : null;
?>
<tr>
<td class="muted" style="white-space: nowrap;"><?= htmlspecialchars($r['ts']) ?></td>
<td><span class="badge <?= $cls ?>"><?= htmlspecialchars($r['event']) ?></span></td>
<td>
<?php if ($r['license_id']): ?>
#<?= htmlspecialchars((string)$r['license_id']) ?>
<?php if ($r['owner_name']): ?>
<span class="muted">(<?= htmlspecialchars($r['owner_name']) ?>)</span>
<?php endif; ?>
<?php else: ?>
<span class="muted">—</span>
<?php endif; ?>
</td>
<td class="muted"><?= htmlspecialchars($r['ip'] ?? '—') ?></td>
<td class="muted">
<?php if ($detail): ?>
<code style="font-size: 11px;"><?= htmlspecialchars(json_encode($detail, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)) ?></code>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="toolbar" style="margin-top:16px; justify-content: space-between;">
<div>
<?php if ($page > 1): ?>
<a href="?<?= http_build_query(['event' => $filter, 'page' => $page - 1]) ?>" class="btn btn-secondary">← Précédent</a>
<?php endif; ?>
</div>
<div>
<?php if ($page < $totalPages): ?>
<a href="?<?= http_build_query(['event' => $filter, 'page' => $page + 1]) ?>" class="btn btn-secondary">Suivant →</a>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</div>
<?php Layout::footer();