KEA update
All checks were successful
Deploy / deploy-staging (push) Successful in 6s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-16 01:19:07 +02:00
parent 04ec9dc227
commit 9f2af4676d
8 changed files with 416 additions and 46 deletions

View File

@@ -20,6 +20,8 @@ $host = null;
$metadataRepo = null;
$groups = [];
$availableIpsByGroup = [];
$checks = [];
$hostKey = '';
try {
$pdo = modules()->modulePdo('kea', $fallback);
@@ -35,35 +37,54 @@ try {
if (!$host) {
throw new RuntimeException('KEA Eintrag wurde nicht gefunden.');
}
$hostKey = $source . ':' . (string)($host['host_id'] ?? $id);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$metadata = [
'real_name' => $_POST['real_name'] ?? '',
'device_name' => $_POST['device_name'] ?? '',
'owner' => $_POST['owner'] ?? '',
'location' => $_POST['location'] ?? '',
'device_type' => $_POST['device_type'] ?? '',
'group_name' => $_POST['group_name'] ?? '',
'desired_ip' => $_POST['desired_ip'] ?? '',
'notes' => $_POST['notes'] ?? '',
'tags' => [],
];
$desiredIp = trim((string)$metadata['desired_ip']);
if ($desiredIp !== '') {
$newHostId = $repo->reserveDisplayEntry($host, $desiredIp, $metadata);
$source = 'reservation';
$id = $newHostId;
$notice = 'Zusatzdaten gespeichert und KEA-Reservierung gesetzt.';
$action = (string)($_POST['action'] ?? 'save_metadata');
if ($action === 'dns_lookup') {
$ip = (string)($host['ipv4_address'] ?? '');
$hostname = trim((string)($host['metadata']['device_name'] ?? $host['hostname'] ?? ''));
$reverse = $ip !== '' ? gethostbyaddr($ip) : '';
$forward = $hostname !== '' ? gethostbyname($hostname) : '';
$success = ($reverse !== '' && $reverse !== $ip) || ($forward !== '' && $forward !== $hostname);
$metadataRepo->saveCheck($hostKey, 'dns', $success ? 'success' : 'warning', [
'ip' => $ip,
'hostname' => $hostname,
'reverse' => $reverse,
'forward' => $forward,
]);
$notice = $success ? 'DNS-Pruefung gespeichert.' : 'DNS-Pruefung gespeichert, aber kein eindeutiger Name gefunden.';
} else {
$metadataRepo->saveForHost(
$id,
(string)($host['dhcp_identifier'] ?? ''),
(string)($host['ipv4_address'] ?? ''),
$metadata
);
$notice = 'Zusatzdaten gespeichert.';
$metadata = [
'real_name' => $_POST['real_name'] ?? '',
'device_name' => $_POST['device_name'] ?? '',
'owner' => $_POST['owner'] ?? '',
'location' => $_POST['location'] ?? '',
'device_type' => $_POST['device_type'] ?? '',
'group_name' => $_POST['group_name'] ?? '',
'desired_ip' => $_POST['desired_ip'] ?? '',
'notes' => $_POST['notes'] ?? '',
'tags' => [],
];
$desiredIp = trim((string)$metadata['desired_ip']);
if ($desiredIp !== '') {
$newHostId = $repo->reserveDisplayEntry($host, $desiredIp, $metadata);
$source = 'reservation';
$id = $newHostId;
$notice = 'Zusatzdaten gespeichert und KEA-Reservierung gesetzt.';
} else {
$metadataRepo->saveForHost(
$id,
(string)($host['dhcp_identifier'] ?? ''),
(string)($host['ipv4_address'] ?? ''),
$metadata
);
$notice = 'Zusatzdaten gespeichert.';
}
}
$host = $repo->findDisplayByKey($source, $id) ?: $host;
$hostKey = $source . ':' . (string)($host['host_id'] ?? $id);
}
$usedIps = array_diff(
@@ -71,6 +92,7 @@ try {
[(string)($host['ipv4_address'] ?? ''), (string)($host['metadata']['desired_ip'] ?? '')]
);
$availableIpsByGroup = $metadataRepo->availableIpsByGroup($usedIps);
$checks = $metadataRepo->latestChecks([$hostKey])[$hostKey] ?? [];
} catch (Throwable $e) {
$error = $e->getMessage();
}
@@ -115,6 +137,7 @@ $selectedIp = (string)($metadata['desired_ip'] ?? '');
</div>
<form method="post" class="kea-edit-form">
<input type="hidden" name="action" value="save_metadata">
<input type="hidden" name="source" value="<?= e($source) ?>">
<input type="hidden" name="id" value="<?= e((string)$id) ?>">
@@ -168,6 +191,40 @@ $selectedIp = (string)($metadata['desired_ip'] ?? '');
</div>
</form>
</div>
<div class="kea-panel">
<div class="kea-panel__head">
<div>
<span class="pill">Pruefungen</span>
<h3>Gerätechecks</h3>
<p class="muted">Pruefergebnisse werden in der Nexus-DHCP-Datenbank gespeichert und koennen spaeter fuer Reports genutzt werden.</p>
</div>
</div>
<div class="kea-check-grid">
<div class="kea-check-card">
<h4>DNS / Hostname</h4>
<?php $dnsCheck = $checks['dns'] ?? null; ?>
<?php if ($dnsCheck): ?>
<?php $dnsResult = json_decode((string)($dnsCheck['result_json'] ?? '{}'), true) ?: []; ?>
<p class="muted">Status: <?= e((string)($dnsCheck['status'] ?? '')) ?> · <?= e((string)($dnsCheck['checked_at'] ?? '')) ?></p>
<p class="mono">Reverse: <?= e((string)($dnsResult['reverse'] ?? '-')) ?></p>
<p class="mono">Forward: <?= e((string)($dnsResult['forward'] ?? '-')) ?></p>
<?php else: ?>
<p class="muted">Noch keine DNS-Pruefung gespeichert.</p>
<?php endif; ?>
<form method="post" class="setup-actions">
<input type="hidden" name="action" value="dns_lookup">
<input type="hidden" name="source" value="<?= e($source) ?>">
<input type="hidden" name="id" value="<?= e((string)$id) ?>">
<button class="nav-link" type="submit">DNS jetzt pruefen</button>
</form>
</div>
<div class="kea-check-card">
<h4>Login-Erkennung</h4>
<p class="muted">Vorbereitet fuer spaetere HTTP/Port-Erkennung. Noch nicht automatisch aktiv, damit keine ungewollten Scans laufen.</p>
</div>
</div>
</div>
<script>
(() => {
const ipsByGroup = <?= json_encode($availableIpsByGroup, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?>;