adasd
This commit is contained in:
26
modules/kea/migrations/001_1.0.0_baseline.php
Normal file
26
modules/kea/migrations/001_1.0.0_baseline.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Database;
|
||||
use App\ModuleMigrationContext;
|
||||
use App\Repository\KeaHostMetadataRepository;
|
||||
|
||||
return new class {
|
||||
public function up(ModuleMigrationContext $context): void
|
||||
{
|
||||
$settings = $context->settings();
|
||||
$fallback = is_array($context->module['metadata_db_defaults'] ?? null)
|
||||
? $context->module['metadata_db_defaults']
|
||||
: [];
|
||||
$config = is_array($settings['metadata_db'] ?? null)
|
||||
? array_replace($fallback, $settings['metadata_db'])
|
||||
: $fallback;
|
||||
|
||||
if (empty($config['driver']) || empty($config['dbname'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$repo = new KeaHostMetadataRepository(Database::createFromArray($config));
|
||||
$repo->ensureSchema();
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"title": "KEA DHCP",
|
||||
"version": "1.0.0",
|
||||
"schema_version": 1,
|
||||
"description": "Verwaltung von KEA DHCP Hosts und Reservierungen.",
|
||||
"menu": [
|
||||
{ "label": "Hosts", "href": "/module/kea" },
|
||||
|
||||
@@ -18,6 +18,7 @@ $error = null;
|
||||
$notice = null;
|
||||
$host = null;
|
||||
$metadataRepo = null;
|
||||
$groups = [];
|
||||
|
||||
try {
|
||||
$pdo = modules()->modulePdo('kea', $fallback);
|
||||
@@ -27,6 +28,7 @@ try {
|
||||
|
||||
$metadataRepo = new KeaHostMetadataRepository(Database::createFromArray($metadataConfig));
|
||||
$metadataRepo->ensureSchema();
|
||||
$groups = $metadataRepo->listGroups();
|
||||
$repo = new KeaHostRepository($pdo, $metadataRepo);
|
||||
$host = $repo->findDisplayByKey($source, $id);
|
||||
if (!$host) {
|
||||
@@ -40,16 +42,26 @@ try {
|
||||
'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' => [],
|
||||
];
|
||||
$metadataRepo->saveForHost(
|
||||
$id,
|
||||
(string)($host['dhcp_identifier'] ?? ''),
|
||||
(string)($host['ipv4_address'] ?? ''),
|
||||
$metadata
|
||||
);
|
||||
$notice = 'Zusatzdaten gespeichert.';
|
||||
$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;
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
@@ -114,6 +126,20 @@ $metadata = is_array($host['metadata'] ?? null) ? $host['metadata'] : [];
|
||||
<span>Gerätetyp</span>
|
||||
<input type="text" name="device_type" value="<?= e((string)($metadata['device_type'] ?? '')) ?>">
|
||||
</label>
|
||||
<label class="setup-field">
|
||||
<span>Gruppe</span>
|
||||
<input type="text" name="group_name" list="kea-groups" value="<?= e((string)($metadata['group_name'] ?? '')) ?>">
|
||||
<datalist id="kea-groups">
|
||||
<?php foreach ($groups as $group): ?>
|
||||
<option value="<?= e($group) ?>"></option>
|
||||
<?php endforeach; ?>
|
||||
</datalist>
|
||||
</label>
|
||||
<label class="setup-field">
|
||||
<span>Feste IP</span>
|
||||
<input type="text" name="desired_ip" value="<?= e((string)($metadata['desired_ip'] ?? '')) ?>" placeholder="<?= e((string)($host['ipv4_address'] ?? '')) ?>">
|
||||
<small class="muted">Wenn gesetzt, wird der Eintrag als KEA-Reservierung gespeichert.</small>
|
||||
</label>
|
||||
<label class="setup-field kea-edit-form__wide">
|
||||
<span>Notizen</span>
|
||||
<textarea name="notes" rows="4"><?= e((string)($metadata['notes'] ?? '')) ?></textarea>
|
||||
|
||||
@@ -15,6 +15,12 @@ $metadataRepo = null;
|
||||
$hosts = [];
|
||||
$error = null;
|
||||
$warnings = [];
|
||||
$stats = [
|
||||
'total' => 0,
|
||||
'reservations' => 0,
|
||||
'leases' => 0,
|
||||
'groups' => [],
|
||||
];
|
||||
|
||||
try {
|
||||
$pdo = modules()->modulePdo('kea', $fallback);
|
||||
@@ -30,8 +36,20 @@ try {
|
||||
|
||||
$repo = new KeaHostRepository($pdo, $metadataRepo);
|
||||
$hosts = $repo->findAll(50);
|
||||
$stats['total'] = count($hosts);
|
||||
foreach ($hosts as $host) {
|
||||
if (($host['source'] ?? '') === 'lease') {
|
||||
$stats['leases']++;
|
||||
} else {
|
||||
$stats['reservations']++;
|
||||
}
|
||||
$group = trim((string)($host['metadata']['group_name'] ?? ''));
|
||||
if ($group !== '') {
|
||||
$stats['groups'][$group] = ($stats['groups'][$group] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$error = "Datenbankfehler: " . $e->getMessage();
|
||||
}
|
||||
|
||||
module_tpl('kea', 'dashboard', compact('hosts', 'error', 'warnings'));
|
||||
module_tpl('kea', 'dashboard', compact('hosts', 'error', 'warnings', 'stats'));
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* @var array $hosts Die Liste der KEA-Hosts.
|
||||
* @var string|null $error Eine Fehlermeldung, falls vorhanden.
|
||||
* @var array $warnings Hinweise, falls Zusatzdaten nicht geladen werden konnten.
|
||||
* @var array $stats Kennzahlen fuer die Uebersicht.
|
||||
*/
|
||||
?>
|
||||
<section class="kea-page">
|
||||
@@ -27,6 +28,25 @@
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<div class="stats">
|
||||
<div class="stat-card">
|
||||
<span class="stat-label">Einträge</span>
|
||||
<span class="stat-value"><?= e((string)($stats['total'] ?? 0)) ?></span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-label">Reservierungen</span>
|
||||
<span class="stat-value"><?= e((string)($stats['reservations'] ?? 0)) ?></span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-label">Leases</span>
|
||||
<span class="stat-value"><?= e((string)($stats['leases'] ?? 0)) ?></span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-label">Gruppen</span>
|
||||
<span class="stat-value"><?= e((string)count($stats['groups'] ?? [])) ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="kea-panel">
|
||||
<div class="kea-panel__head">
|
||||
<div>
|
||||
@@ -45,13 +65,14 @@
|
||||
<th>MAC Adresse</th>
|
||||
<th>Echter Name</th>
|
||||
<th>Standort</th>
|
||||
<th>Gruppe</th>
|
||||
<th>Aktion</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($hosts)): ?>
|
||||
<tr>
|
||||
<td colspan="7" class="kea-empty">
|
||||
<td colspan="8" class="kea-empty">
|
||||
Keine Reservierungen oder aktiven Leases gefunden.
|
||||
</td>
|
||||
</tr>
|
||||
@@ -62,7 +83,7 @@
|
||||
<span class="pill"><?= ($host['source'] ?? '') === 'lease' ? 'Lease' : 'Reservierung' ?></span>
|
||||
</td>
|
||||
<td>
|
||||
<?= e($host['hostname'] ?: 'Unbekannt') ?>
|
||||
<?= e((string)($host['metadata']['device_name'] ?? $host['metadata']['real_name'] ?? $host['display_name'] ?? $host['hostname'] ?? 'Unbekannt')) ?>
|
||||
</td>
|
||||
<td class="mono">
|
||||
<?= e($host['ipv4_address']) ?>
|
||||
@@ -76,6 +97,9 @@
|
||||
<td>
|
||||
<?= e((string)($host['metadata']['location'] ?? '-')) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= e((string)($host['metadata']['group_name'] ?? '-')) ?>
|
||||
</td>
|
||||
<td>
|
||||
<a class="nav-link" href="/module/kea/edit?source=<?= e((string)($host['source'] ?? 'reservation')) ?>&id=<?= e((string)($host['host_id'] ?? '0')) ?>">
|
||||
Bearbeiten
|
||||
|
||||
Reference in New Issue
Block a user