Files
MUA-Mikes-Unraid-Agent/scripts/mua.page
T
Mikei386andClaude Opus 5.5 b8d89ffd9c release: MUA 2026.11.20.r036
Read-only shell
- Accept a full command line (`command`) and parse it without /bin/sh:
  quotes, escapes, ~, pipes between allowed programs, ; && ||, globs in
  absolute paths; 2>&1 and 2>/dev/null are tolerated. Pipeline stages run
  with strictly single-quoted, pre-validated literals only.
- Per-program option policies that understand combined short flags,
  --opt=value and GNU abbreviations. Closes bypasses: ip abbreviations
  (ip a a / ip r d / ip link s), dmesg -c/-Tc/--console-level=, ss -tK/-D,
  date operands, sort -o, uniq output file, file -C.
- Block credential files (shadow, SSH private keys, mua.conf, admin token,
  /proc/*/environ, docker config.v2.json); redact password hashes, private
  PEM keys and WireGuard keys in output. MUA API key and admin token are
  never emitted by any tool.
- More diagnostic programs (echo, printf, sort, uniq, cut, tr, findmnt,
  sensors, zpool/zfs read verbs, mdcmd status, ...). grep without matches
  is reported as no_match instead of an error.

Process handling
- Spawn every child in its own process group; timeouts kill the whole
  tree. The MCP hard timeout kills exactly the processes of that call.
- Async jobs: command in its own file (exit no longer loses the exit
  code), new unraid_system_job_cancel, finished jobs pruned after 7 days.

Other
- Cache toolbox discovery briefly; validate and bound session IDs; /health
  shows version/port only with a valid token; constant-time admin token
  check; auto-granted tools are logged and shown in the WebGUI.
- Remove the legacy PHP server (mcp/), drop old packages from dist/, pin
  @types/bun.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 21:51:14 +01:00

238 lines
23 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
Menu="Utilities"
Type="xmenu"
Title="MUA"
Icon="cubes"
---
<?php
/** MUA WebGUI — sicherheitsorientierte Verwaltung. */
$port = (int)(getenv('MUA_PORT') ?: 3002);
$config_port = (int)(getenv('MUA_CONFIG_PORT') ?: 3013);
$pidfile = getenv('MUA_PIDFILE') ?: '/var/run/mua.pid';
$binary = getenv('MUA_BINARY') ?: '/usr/local/bin/mua';
$admin_token_file = getenv('MUA_ADMIN_TOKEN_FILE') ?: '/var/run/mua-admin.token';
$admin_token = is_readable($admin_token_file) ? trim(file_get_contents($admin_token_file)) : '';
$unraid_csrf = $var['csrf_token'] ?? '';
$host_ip = $_SERVER['SERVER_ADDR'] ?? '127.0.0.1';
function mua_api($method, $path, $payload, $token, $port) {
if (!$token) return [0, null];
$ch = curl_init('http://127.0.0.1:' . $port . $path);
$headers = ['X-MUA-Admin-Token: ' . $token];
$options = [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 5, CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_HTTPHEADER => $headers, CURLOPT_PROXY => ''];
if ($method === 'POST') {
$options[CURLOPT_POST] = true;
if ($payload !== null) {
$options[CURLOPT_POSTFIELDS] = json_encode($payload);
$headers[] = 'Content-Type: application/json';
$options[CURLOPT_HTTPHEADER] = $headers;
}
}
curl_setopt_array($ch, $options);
$raw = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [$code, $raw !== false ? json_decode($raw, true) : null];
}
function csrf_value($token, $offset = 0) {
return hash_hmac('sha256', gmdate('Y-m-d-H', time() + $offset * 3600), $token);
}
function mua_health($config_port, $admin_token) {
// Readiness via the protected loopback channel. No insecure TLS bypass or
// plaintext probe against a configured HTTPS MCP endpoint.
[$code, $status] = mua_api('GET', '/status', null, $admin_token, $config_port);
return $code === 200 && is_array($status) ? $status : null;
}
$running = false;
$pid = null;
if (file_exists($pidfile)) {
$pid = trim(file_get_contents($pidfile));
$running = $pid && is_numeric($pid) && @posix_kill((int)$pid, 0);
}
$health_data = mua_health($config_port, $admin_token);
$health_ok = is_array($health_data) && ($health_data['status'] ?? '') === 'ok';
$running_version = $health_data['version'] ?? '';
$scheme = ($health_data['scheme'] ?? '') === 'https' ? 'https' : 'http';
$endpoint = $health_ok ? $scheme . '://' . (str_contains($host_ip, ':') ? '[' . $host_ip . ']' : $host_ip) . ':' . ($health_data['port'] ?? $port) . '/mcp' : 'Nicht verfügbar – Dienst/Logs prüfen';
[$config_code, $config] = mua_api('GET', '/config', null, $admin_token, $config_port);
$config_ok = $config_code === 200 && is_array($config);
$flash_msg = '';
$flash_type = '';
$new_api_key = '';
$csrf = csrf_value($admin_token);
$readonly = [
'unraid_docker_list', 'unraid_docker_inspect', 'unraid_docker_logs',
'unraid_docker_analyze_logs', 'unraid_docker_processes', 'unraid_docker_stats',
'unraid_docker_info', 'unraid_network_inventory', 'unraid_network_list',
'unraid_network_inspect', 'unraid_network_host_state', 'unraid_system_connection_test',
'unraid_system_shell_readonly', 'unraid_docker_update_status',
'unraid_system_health', 'unraid_storage_status', 'unraid_disk_health',
'unraid_notifications_list', 'unraid_shares_list', 'unraid_share_inspect',
'unraid_files_inventory',
];
$operator = array_merge($readonly, [
'unraid_network_audit_tcp', 'unraid_network_lan_probe',
'unraid_ca_search', 'unraid_ca_install_preview',
'unraid_docker_start', 'unraid_docker_stop', 'unraid_docker_restart',
]);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$posted_csrf = $_POST['mua_csrf'] ?? '';
$csrf_ok = $admin_token && (hash_equals(csrf_value($admin_token), $posted_csrf) || hash_equals(csrf_value($admin_token, -1), $posted_csrf));
if (!$csrf_ok) {
$flash_msg = 'Sicherheitsprüfung fehlgeschlagen. Seite neu laden und erneut versuchen.';
$flash_type = 'err';
} else {
$action = $_POST['action'] ?? '';
$payload = null;
if ($action === 'generate_key') $payload = ['generate' => true];
if ($action === 'preset_readonly') $payload = ['enabledTools' => $readonly, 'allToolsEnabled' => false];
if ($action === 'preset_operator') $payload = ['enabledTools' => $operator, 'allToolsEnabled' => false];
if ($action === 'preset_none') $payload = ['enabledTools' => [], 'allToolsEnabled' => false];
if ($action === 'preset_all') $payload = ['enabledTools' => [], 'allToolsEnabled' => true];
if ($action === 'save_toolbox') $payload = ['toolboxEnabled' => isset($_POST['toolbox_enabled'])];
if ($action === 'save_tls') $payload = ['tls' => [
'enabled' => isset($_POST['tls_enabled']),
'source' => $_POST['tls_source'] ?? 'manual',
'unraidChoice' => $_POST['tls_unraid_choice'] ?? '',
'certFile' => $_POST['tls_cert_file'] ?? '',
'keyFile' => $_POST['tls_key_file'] ?? '',
]];
if ($action === 'save_tools') {
$selected = [];
foreach (($config['allTools'] ?? []) as $tool) {
$name = is_array($tool) ? ($tool['name'] ?? '') : $tool;
if ($name && isset($_POST['tool_' . $name])) $selected[] = $name;
}
$payload = ['enabledTools' => $selected, 'allToolsEnabled' => false];
}
if ($action === 'restart') {
[$code, $result] = mua_api('POST', '/restart', null, $admin_token, $config_port);
$flash_msg = $code === 200 ? 'MUA wird neu gestartet.' : 'Neustart fehlgeschlagen (HTTP ' . $code . ').' . (is_string($result['error'] ?? null) ? ' ' . $result['error'] : '');
$flash_type = $code === 200 ? 'ok' : 'err';
} elseif ($payload !== null) {
[$code, $result] = mua_api('POST', '/config', $payload, $admin_token, $config_port);
if ($code === 200 && is_array($result) && ($result['ok'] ?? false)) {
$new_api_key = $result['generatedApiKey'] ?? '';
$flash_msg = $action === 'save_tls' ? 'TLS-Einstellungen geprüft und gespeichert. Zum Anwenden Dienst ausdrücklich neu starten.' : ($new_api_key ? 'Neuer API-Key erzeugt. Jetzt kopieren – er wird nur dieses eine Mal angezeigt.' : 'Sicherheitseinstellungen gespeichert.');
$flash_type = 'ok';
[$config_code, $config] = mua_api('GET', '/config', null, $admin_token, $config_port);
$config_ok = $config_code === 200 && is_array($config);
} else {
$flash_msg = 'Speichern fehlgeschlagen (HTTP ' . $code . ').' . ($action === 'save_tls' && is_string($result['error'] ?? null) ? ' ' . $result['error'] : '');
$flash_type = 'err';
}
}
}
}
$transport = is_array($config['transport'] ?? null) ? $config['transport'] : [];
$tls = is_array($transport['tls'] ?? null) ? $transport['tls'] : [];
$tls_source = ($tls['source'] ?? 'unraid') === 'manual' ? 'manual' : 'unraid';
$unraid_tls = is_array($transport['unraid'] ?? null) ? $transport['unraid'] : [];
$unraid_choices = is_array($unraid_tls['choices'] ?? null) ? $unraid_tls['choices'] : [];
$tls_locked = !$config_ok || !empty($transport['envOverride']);
$enabled_tools = $config['enabledTools'] ?? [];
$all_tools_enabled = (bool)($config['allToolsEnabled'] ?? false);
$all_tools = $config['allTools'] ?? [];
$auto_granted = is_array($config['autoGrantedTools'] ?? null) ? $config['autoGrantedTools'] : [];
$toolbox = is_array($config['toolbox'] ?? null) ? $config['toolbox'] : [];
$toolbox_available = (bool)($toolbox['available'] ?? false);
$toolbox_enabled = (bool)($toolbox['enabled'] ?? false);
$toolbox_containers = is_array($toolbox['containers'] ?? null) ? $toolbox['containers'] : [];
$risk_groups = ['read' => [], 'active' => [], 'write' => [], 'critical' => []];
foreach ($all_tools as $tool) {
if (!is_array($tool)) $tool = ['name' => $tool, 'description' => '', 'risk' => 'read'];
$risk = $tool['risk'] ?? 'read';
if (!isset($risk_groups[$risk])) $risk = 'read';
$risk_groups[$risk][] = $tool;
}
$risk_labels = [
'read' => ['Nur Lesen', 'Liest Status und Diagnoseinformationen.', 'mua-risk-safe'],
'active' => ['Aktive Prüfungen', 'Baut gezielt Netzwerkverbindungen für Tests auf.', 'mua-risk-notice'],
'write' => ['Betrieb steuern', 'Startet, stoppt oder startet Container neu.', 'mua-risk-warn'],
'critical' => ['Kritischer Zugriff', 'Verändert Container oder führt uneingeschränkte Root-Befehle aus.', 'mua-risk-danger'],
];
$active_count = $all_tools_enabled ? count($all_tools) : count($enabled_tools);
?>
<style>
.mua-wrap{max-width:1280px}.mua-hero{display:flex;justify-content:space-between;align-items:flex-start;gap:18px;margin:12px 0 20px}.mua-title h2{margin:0 0 5px;font-size:1.55rem}.mua-muted{color:#777}.mua-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(285px,1fr));gap:14px;margin:14px 0;align-items:start}.mua-card{border:1px solid #d8d8d8;border-radius:9px;padding:16px;background:rgba(255,255,255,.03)}.mua-card h3{margin:0 0 8px}.mua-status{padding:11px 14px;border-radius:7px;margin:10px 0;border:1px solid}.mua-status.ok,.mua-risk-safe{border-color:#43a047;background:rgba(67,160,71,.11)}.mua-status.err,.mua-risk-danger{border-color:#e53935;background:rgba(229,57,53,.11)}.mua-status.warn,.mua-risk-warn{border-color:#fb8c00;background:rgba(251,140,0,.12)}.mua-risk-notice{border-color:#1e88e5;background:rgba(30,136,229,.10)}.mua-pill{display:inline-block;padding:3px 9px;border-radius:20px;font-size:.82em;font-weight:600;border:1px solid currentColor}.mua-endpoint{font-size:1.05em;word-break:break-all}.mua-key{display:block;padding:12px;border:1px solid #43a047;border-radius:6px;word-break:break-all;font-size:1.04em;background:rgba(67,160,71,.08)}.mua-actions{display:flex;flex-wrap:wrap;gap:8px;margin:10px 0}.mua-btn{padding:8px 14px;border-radius:5px;border:1px solid #aaa;cursor:pointer}.mua-btn-primary{background:#168bd2;color:#fff;border-color:#168bd2}.mua-btn-danger{background:#c62828;color:#fff;border-color:#c62828}.mua-tool{display:grid;grid-template-columns:22px minmax(0,1fr);gap:8px;padding:9px 0;border-top:1px solid rgba(128,128,128,.2);align-items:start}.mua-tool:first-of-type{border-top:0}.mua-tool code{font-size:.86em;overflow-wrap:anywhere}.mua-tool small{display:block;color:#777;margin-top:3px;line-height:1.35}.mua-section{margin-top:24px}.mua-summary{font-size:1.08em}.mua-preset{margin:0}.mua-details td:first-child{width:190px;font-weight:600}@media(max-width:700px){.mua-hero{display:block}.mua-actions{display:grid}.mua-btn{width:100%}}
.mua-btn:disabled{opacity:.45;cursor:not-allowed}.mua-switch{display:flex;align-items:flex-start;gap:10px;margin:12px 0}.mua-switch input{margin-top:4px}.mua-switch span{line-height:1.4}
</style>
<div class="mua-wrap">
<div class="mua-hero"><div class="mua-title"><h2>MUA · Mikes Unraid Agent</h2><div class="mua-muted">Sicherer MCP-Zugriff auf Docker, Netzwerk und Unraid-Systemfunktionen</div></div><div><span class="mua-pill <?= $running && $health_ok ? 'mua-risk-safe' : 'mua-risk-danger' ?>"><?= $running && $health_ok ? '● Dienst bereit' : '● Dienst gestört' ?></span></div></div>
<?php if ($flash_msg): ?><div class="mua-status <?= htmlspecialchars($flash_type) ?>"><?= htmlspecialchars($flash_msg) ?></div><?php endif; ?>
<?php if ($new_api_key): ?><div class="mua-status ok"><strong>Neuer API-Key – einmalige Anzeige</strong><code class="mua-key" id="mua-new-key"><?= htmlspecialchars($new_api_key) ?></code><button type="button" class="mua-btn" onclick="navigator.clipboard.writeText(document.getElementById('mua-new-key').textContent)">In Zwischenablage kopieren</button></div><?php endif; ?>
<div class="mua-grid">
<div class="mua-card"><h3>Dienst</h3><p class="mua-summary"><?= $health_ok ? '✅ MCP-Listener gestartet (lokaler Status)' : '❌ Lokaler Bereitschaftstest fehlgeschlagen' ?></p><div class="mua-muted">Version <?= htmlspecialchars($running_version ?: '—') ?> · PID <?= htmlspecialchars((string)($pid ?: '—')) ?></div></div>
<div class="mua-card"><h3>Zugriffsprofil</h3><p class="mua-summary"><strong><?= $active_count ?></strong> von <?= count($all_tools) ?> Werkzeugen aktiv</p><div class="mua-muted"><?= $all_tools_enabled ? 'Vollzugriff – einschließlich kritischer Werkzeuge' : ($active_count === 0 ? 'Komplett gesperrt' : 'Benutzerdefinierte Freigabe') ?></div></div>
<div class="mua-card"><h3>Authentifizierung</h3><p class="mua-summary"><?= $config_ok ? '✅ Bearer-Key aktiv' : '❌ Verwaltung nicht erreichbar' ?></p><div class="mua-muted"><?= htmlspecialchars($config['apiKeyMasked'] ?? 'nicht verfügbar') ?></div></div>
</div>
<div class="mua-card"><h3>MCP-Endpunkt</h3><code class="mua-endpoint"><?= htmlspecialchars($endpoint) ?></code><p class="mua-muted">Streamable HTTP · JSON-RPC 2.0 · Bearer-Authentifizierung erforderlich</p></div>
<div class="mua-section"><h2>HTTPS / TLS</h2><div class="mua-card">
<p>Aktiver Transport: <strong><?= $health_ok ? strtoupper($scheme) : 'unbekannt' ?></strong>. TLS schützt denselben MCP-Port inklusive <code>/health</code>; Bearer-Key und Toolfreigaben bleiben unverändert.</p>
<?php if (!empty($transport['restartRequired'])): ?><div class="mua-status warn">Gespeicherte Einstellungen sind noch nicht aktiv. Nach Prüfung Dienst ausdrücklich neu starten.</div><?php endif; ?>
<?php if (!empty($transport['error'])): ?><div class="mua-status err"><?= htmlspecialchars($transport['error']) ?></div><?php endif; ?>
<?php if (!empty($transport['envOverride'])): ?><p>Durch Umgebungsvariablen verwaltet; WebGUI-Änderung gesperrt.</p><?php endif; ?>
<form method="post"><input type="hidden" name="csrf_token" value="<?= htmlspecialchars($unraid_csrf) ?>"><input type="hidden" name="mua_csrf" value="<?= htmlspecialchars($csrf) ?>"><input type="hidden" name="action" value="save_tls">
<fieldset <?= $tls_locked ? 'disabled' : '' ?>><legend>TLS-Konfiguration</legend>
<label class="mua-switch"><input type="checkbox" name="tls_enabled" <?= !empty($tls['enabled']) ? 'checked' : '' ?>><span><strong>HTTPS aktivieren</strong><br>Ohne gültiges Zertifikat und passenden Schlüssel startet MUA nicht. Kein automatischer HTTP-Fallback.</span></label>
<p><label>Zertifikatquelle<br><select name="tls_source" onchange="document.getElementById('mua-tls-expert').open=this.value==='manual'">
<option value="unraid" <?= $tls_source === 'unraid' ? 'selected' : '' ?>>Unraid-WebGUI-Zertifikat verwenden</option>
<option value="manual" <?= $tls_source === 'manual' ? 'selected' : '' ?>>Expertenoption: eigene Zertifikatspfade</option>
</select></label></p>
<p>Im Unraid-Modus werden die wirksamen WebGUI-Zertifikate aus der erzeugten nginx-Konfiguration und Management-Laufzeitdaten erkannt. Du musst keinen Dateipfad kennen. Es wird kein Zertifikat erzeugt oder verändert.</p>
<?php if (!empty($unraid_tls['error'])): ?><div class="mua-status warn"><?= htmlspecialchars($unraid_tls['error']) ?></div><?php endif; ?>
<p><label>WebGUI-Zertifikat / Zugriffsname<br><select name="tls_unraid_choice">
<option value=""><?= count($unraid_choices) === 1 ? 'Einziges erkanntes WebGUI-Zertifikat verwenden' : 'Bei mehreren Zertifikaten bitte ausdrücklich auswählen' ?></option>
<?php foreach ($unraid_choices as $choice): ?>
<option value="<?= htmlspecialchars($choice['id'] ?? '') ?>" <?= ($tls['unraidChoice'] ?? '') === ($choice['id'] ?? '') ? 'selected' : '' ?>><?= htmlspecialchars($choice['label'] ?? 'WebGUI-Zertifikat') ?></option>
<?php endforeach; ?></select></label></p>
<details id="mua-tls-expert" <?= $tls_source === 'manual' ? 'open' : '' ?>><summary>Expertenoption: absolute PEM-Pfade (nur bei manueller Quelle)</summary>
<p><label>Zertifikat / Fullchain (PEM, absoluter Pfad)<br><input type="text" name="tls_cert_file" maxlength="4096" style="width:95%" value="<?= htmlspecialchars($tls['certFile'] ?? '') ?>" placeholder="/persistenter/pfad/fullchain.pem"></label></p>
<p><label>Privater Schlüssel (PEM, unverschlüsselt, absoluter Pfad)<br><input type="text" name="tls_key_file" maxlength="4096" style="width:95%" value="<?= htmlspecialchars($tls['keyFile'] ?? '') ?>" placeholder="/persistenter/pfad/privkey.pem"></label></p>
</details>
<button type="submit" class="mua-btn mua-btn-primary">TLS prüfen und speichern</button></fieldset></form>
<p class="mua-muted">Keine Schlüssel hochladen/einfügen. Unraid-Modus: nur aktiv konfigurierte HTTPS-WebGUI-Zertifikate, keine Suche nach der neuesten PEM-Datei. Mehrere SNI-Identitäten brauchen eine ausdrückliche Auswahl; unbekannte Konfigurationen werden abgelehnt. Expertenmodus: beide Pfade dürfen dasselbe Bundle bezeichnen. Nur den öffentlichen Zertifikatsteil zum Client übertragen, niemals das Bundle. Zertifikat und WebGUI-Laufzeitkonfiguration müssen beim Start lesbar sein. Clients benötigen gezielten Trust und einen Hostnamen/IP im Zertifikat-SAN; die angezeigte Server-IP gegebenenfalls ersetzen. Speichern ändert den laufenden Listener nicht; Erneuerung und Aktivierung erfordern ausdrücklich Neustart. Verwaltung bleibt HTTP auf 127.0.0.1:<?= $config_port ?>. Lokale Bereitschaft ist kein Client-Trust-Test.</p>
</div></div>
<div class="mua-section"><h2>Agent-Werkzeugcontainer</h2><div class="mua-card <?= !$toolbox_available ? '' : ($toolbox_enabled ? 'mua-risk-safe' : 'mua-risk-notice') ?>">
<?php if ($toolbox_available): ?>
<p class="mua-summary">✅ Gefunden: <?php foreach ($toolbox_containers as $i => $container): ?><?= $i ? ', ' : '' ?><strong><?= htmlspecialchars($container['name'] ?? 'unbekannt') ?></strong> <span class="mua-muted">(<?= htmlspecialchars($container['state'] ?? 'unbekannt') ?>)</span><?php endforeach; ?></p>
<form method="post"><input type="hidden" name="csrf_token" value="<?= htmlspecialchars($unraid_csrf) ?>"><input type="hidden" name="mua_csrf" value="<?= htmlspecialchars($csrf) ?>"><input type="hidden" name="action" value="save_toolbox"><label class="mua-switch"><input type="checkbox" name="toolbox_enabled" <?= $toolbox_enabled ? 'checked' : '' ?>><span><strong>Werkzeugcontainer für KI-Agenten bereitstellen</strong><br><span class="mua-muted">Blendet <code>unraid_toolbox_status</code> und <code>unraid_toolbox_exec</code> für MCP-Clients ein. Der Container wird dynamisch über sein Label erkannt.</span></span></label><button type="submit" class="mua-btn mua-btn-primary">Einstellung speichern</button></form>
<?php else: ?>
<p class="mua-summary mua-muted">Kein Werkzeugcontainer erkannt</p>
<label class="mua-switch"><input type="checkbox" disabled><span><strong>Werkzeugcontainer für KI-Agenten bereitstellen</strong><br><span class="mua-muted">Nicht verfügbar. Erstelle einen Docker-Container und versehe ihn mit dem Label <code>mike.ai.role=toolbox</code>. Danach diese Seite neu laden.</span></span></label><button type="button" class="mua-btn" disabled>Einstellung speichern</button>
<?php endif; ?>
</div></div>
<div class="mua-section"><h2>Schnelle Sicherheitsprofile</h2><p class="mua-muted">„Nur Lesen“ ist die empfohlene Dauerstellung. Weitergehende Rechte nur bei konkretem Bedarf freigeben.</p><div class="mua-actions">
<?php foreach ([['preset_readonly','Nur Lesen (empfohlen)',''],['preset_operator','Betrieb + Diagnose',''],['preset_none','Alles sperren',''],['preset_all','Vollzugriff','danger']] as $preset): ?>
<form method="post" class="mua-preset" onsubmit="<?= $preset[0] === 'preset_all' ? "return confirm('Vollzugriff aktiviert auch Container-Umbau und uneingeschränkte Root-Shell. Wirklich freigeben?');" : '' ?>"><input type="hidden" name="csrf_token" value="<?= htmlspecialchars($unraid_csrf) ?>"><input type="hidden" name="mua_csrf" value="<?= htmlspecialchars($csrf) ?>"><input type="hidden" name="action" value="<?= $preset[0] ?>"><button class="mua-btn <?= $preset[2] === 'danger' ? 'mua-btn-danger' : ($preset[0] === 'preset_readonly' ? 'mua-btn-primary' : '') ?>" type="submit"><?= $preset[1] ?></button></form>
<?php endforeach; ?></div></div>
<div class="mua-section"><h2>Werkzeuge im Detail</h2>
<?php if (!empty($auto_granted)): ?><div class="mua-status warn">Automatisch ergänzt (durch bestehende, gleich starke Freigaben gedeckt): <code><?= htmlspecialchars(implode(', ', $auto_granted)) ?></code>. Sie folgen ihrer Hauptfreigabe (z.B. Root-Shell → Async-Jobs) und entfallen mit ihr.</div><?php endif; ?>
<form method="post"><input type="hidden" name="csrf_token" value="<?= htmlspecialchars($unraid_csrf) ?>"><input type="hidden" name="mua_csrf" value="<?= htmlspecialchars($csrf) ?>"><input type="hidden" name="action" value="save_tools"><div class="mua-grid">
<?php foreach ($risk_groups as $risk => $tools): $meta=$risk_labels[$risk]; ?>
<div class="mua-card <?= $meta[2] ?>"><h3><?= $meta[0] ?> <span class="mua-pill"><?= count($tools) ?></span></h3><p class="mua-muted"><?= $meta[1] ?></p>
<?php foreach ($tools as $tool): $name=$tool['name']; $checked=$all_tools_enabled || in_array($name,$enabled_tools,true); ?>
<label class="mua-tool"><input type="checkbox" name="tool_<?= htmlspecialchars($name) ?>" <?= $checked ? 'checked' : '' ?>><span><code><?= htmlspecialchars($name) ?></code><small><?= htmlspecialchars($tool['description'] ?? '') ?></small></span></label>
<?php endforeach; ?></div><?php endforeach; ?>
</div><button type="submit" class="mua-btn mua-btn-primary">Benutzerdefinierte Auswahl speichern</button></form></div>
<div class="mua-section"><h2>API-Key</h2><div class="mua-card"><p>Der vollständige Schlüssel wird nicht dauerhaft angezeigt. Beim Erzeugen erscheint er genau einmal; danach ist nur noch die Endung sichtbar.</p><form method="post" onsubmit="return confirm('Der bisherige Schlüssel wird sofort ungültig. Neuen Schlüssel erzeugen?');"><input type="hidden" name="csrf_token" value="<?= htmlspecialchars($unraid_csrf) ?>"><input type="hidden" name="mua_csrf" value="<?= htmlspecialchars($csrf) ?>"><input type="hidden" name="action" value="generate_key"><button type="submit" class="mua-btn">Neuen API-Key erzeugen</button></form></div></div>
<div class="mua-section"><h2>Technische Details</h2><table class="mua-details"><tr><td>Version</td><td><?= htmlspecialchars($running_version ?: '—') ?></td></tr><tr><td>MCP-Port</td><td><?= $port ?></td></tr><tr><td>Verwaltung</td><td>127.0.0.1:<?= $config_port ?> · separater Admin-Token</td></tr><tr><td>Konfiguration</td><td><code>/boot/config/plugins/mua/mua.conf</code></td></tr><tr><td>Audit-Protokoll</td><td><code>/var/log/plugins/mua-audit.log</code> (keine Argumente oder Inhalte)</td></tr></table><form method="post" onsubmit="return confirm('MUA-Service neu starten?');"><input type="hidden" name="csrf_token" value="<?= htmlspecialchars($unraid_csrf) ?>"><input type="hidden" name="mua_csrf" value="<?= htmlspecialchars($csrf) ?>"><input type="hidden" name="action" value="restart"><button type="submit" class="mua-btn">Dienst neu starten</button></form></div>
</div>