Files
nexus/public/page/debug.php
2026-03-04 01:58:26 +01:00

91 lines
2.5 KiB
PHP

<?php
require_admin();
if (!defined('APP_DEBUG_TOOL') || !APP_DEBUG_TOOL) {
echo '<div class="card">Debug-Tool ist deaktiviert.</div>';
return;
}
$debugDir = __DIR__ . '/../../debug';
if (!is_dir($debugDir)) {
echo '<div class="card">Debug-Verzeichnis fehlt.</div>';
return;
}
$files = array_values(array_filter(scandir($debugDir) ?: [], function ($f) use ($debugDir) {
if ($f === '.' || $f === '..') return false;
$path = $debugDir . '/' . $f;
return is_file($path);
}));
$selected = (string)($_GET['file'] ?? '');
$content = null;
if ($selected !== '' && preg_match('/^[a-zA-Z0-9._-]+$/', $selected)) {
$path = $debugDir . '/' . $selected;
if (is_file($path)) {
$content = file_get_contents($path);
}
}
if (isset($_GET['raw']) && $_GET['raw'] === '1') {
header('Content-Type: text/plain; charset=utf-8');
echo $content ?? '';
return;
}
?>
<div class="card">
<div class="pill">Debug</div>
<h1 style="margin-top:.75rem;">Debug Logs</h1>
<p class="muted">Hier kannst du temporäre Log-Files aus dem <code>debug/</code>-Ordner ansehen.</p>
<div style="margin-top:1rem;" class="grid">
<div class="card" style="background:var(--panel-2);">
<strong>Logs</strong>
<ul style="margin-top:.5rem;">
<?php if (!$files): ?>
<li class="muted">Keine Logs vorhanden.</li>
<?php endif; ?>
<?php foreach ($files as $f): ?>
<li>
<a class="nav-link" href="/debug?file=<?= e($f) ?>"><?= e($f) ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<div class="card" style="background:var(--panel-2);">
<strong>Inhalt</strong>
<?php if ($content === null): ?>
<p class="muted" style="margin-top:.5rem;">Wähle eine Datei.</p>
<?php else: ?>
<pre id="debug-content" style="margin-top:.5rem; white-space:pre-wrap; font-family:monospace;"><?= e($content) ?></pre>
<?php endif; ?>
</div>
</div>
</div>
<?php if ($selected !== ''): ?>
<script>
(() => {
const el = document.getElementById('debug-content');
if (!el) return;
const url = new URL(window.location.href);
url.searchParams.set('raw', '1');
let last = '';
async function tick() {
try {
const res = await fetch(url.toString(), { cache: 'no-store' });
if (!res.ok) return;
const text = await res.text();
if (text !== last) {
el.textContent = text;
last = text;
}
} catch (e) {}
}
tick();
setInterval(tick, 3000);
})();
</script>
<?php endif; ?>