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

@@ -14,6 +14,7 @@ $error = null;
$notice = null;
$groups = [];
$availableIpsByGroup = [];
$usedIps = [];
try {
if (empty($metadataConfig['driver']) || empty($metadataConfig['dbname'])) {
@@ -26,7 +27,11 @@ try {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = (string)($_POST['action'] ?? '');
if ($action === 'save_group') {
$metadataRepo->saveGroup((string)($_POST['name'] ?? ''), (string)($_POST['description'] ?? ''));
$metadataRepo->saveGroup(
(string)($_POST['name'] ?? ''),
(string)($_POST['description'] ?? ''),
(string)($_POST['parent_name'] ?? '')
);
$notice = 'Gruppe gespeichert.';
} elseif ($action === 'add_range') {
$metadataRepo->addRange(
@@ -40,13 +45,35 @@ try {
$groups = $metadataRepo->listGroupsWithRanges();
$keaRepo = new KeaHostRepository(modules()->modulePdo('kea', $fallback), $metadataRepo);
$availableIpsByGroup = $metadataRepo->availableIpsByGroup(
array_merge($keaRepo->usedIpAddresses(), $metadataRepo->desiredIps()),
4096
);
$usedIps = array_merge($keaRepo->usedIpAddresses(), $metadataRepo->desiredIps());
$availableIpsByGroup = $metadataRepo->availableIpsByGroup($usedIps, 4096);
} catch (Throwable $e) {
$error = $e->getMessage();
}
$usedIpLookup = array_flip(array_filter(array_map('strval', $usedIps)));
$matrixForGroup = static function (array $group) use ($usedIpLookup): array {
$dots = [];
foreach (($group['ranges'] ?? []) as $range) {
$start = ip2long((string)($range['start_ip'] ?? ''));
$end = ip2long((string)($range['end_ip'] ?? ''));
if ($start === false || $end === false) {
continue;
}
for ($ip = $start; $ip <= $end && count($dots) < 512; $ip++) {
$address = long2ip($ip);
if ($address === false) {
continue;
}
$dots[] = [
'ip' => $address,
'used' => isset($usedIpLookup[$address]),
];
}
}
return $dots;
};
?>
<section class="kea-page">
<div class="section-head">
@@ -83,6 +110,15 @@ try {
<span>Beschreibung</span>
<input type="text" name="description">
</label>
<label class="setup-field">
<span>Uebergeordnete Gruppe</span>
<select name="parent_name">
<option value="">Keine</option>
<?php foreach ($groups as $group): ?>
<option value="<?= e((string)$group['name']) ?>"><?= e((string)$group['name']) ?></option>
<?php endforeach; ?>
</select>
</label>
<div class="setup-actions kea-edit-form__wide">
<button class="cta-button" type="submit">Gruppe speichern</button>
</div>
@@ -133,19 +169,22 @@ try {
<thead>
<tr>
<th>Gruppe</th>
<th>Untergruppe von</th>
<th>Beschreibung</th>
<th>Bereiche</th>
<th>Freie IPs</th>
<th>Matrix</th>
</tr>
</thead>
<tbody>
<?php if ($groups === []): ?>
<tr><td colspan="4" class="kea-empty">Noch keine Gruppen definiert.</td></tr>
<tr><td colspan="6" class="kea-empty">Noch keine Gruppen definiert.</td></tr>
<?php else: ?>
<?php foreach ($groups as $group): ?>
<?php $available = $availableIpsByGroup[(string)$group['name']] ?? []; ?>
<tr>
<td><?= e((string)$group['name']) ?></td>
<td><?= e((string)($group['parent_name'] ?: '-')) ?></td>
<td><?= e((string)($group['description'] ?? '-')) ?></td>
<td>
<?php if (($group['ranges'] ?? []) === []): ?>
@@ -157,6 +196,21 @@ try {
<?php endif; ?>
</td>
<td><?= e((string)count($available)) ?></td>
<td>
<?php $matrix = $matrixForGroup($group); ?>
<?php if ($matrix === []): ?>
<span class="muted">Kein Bereich</span>
<?php else: ?>
<div class="ip-matrix" aria-label="IP Matrix fuer <?= e((string)$group['name']) ?>">
<?php foreach ($matrix as $dot): ?>
<span
class="ip-dot <?= $dot['used'] ? 'is-used' : 'is-free' ?>"
title="<?= e((string)$dot['ip']) ?> · <?= $dot['used'] ? 'belegt' : 'frei' ?>"
></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>