get('kea'); $fallback = $module['db_defaults'] ?? []; $settings = modules()->settings('kea'); $metadataFallback = is_array($module['metadata_db_defaults'] ?? null) ? $module['metadata_db_defaults'] : []; $metadataConfig = is_array($settings['metadata_db'] ?? null) ? array_replace($metadataFallback, $settings['metadata_db']) : $metadataFallback; $metadataRepo = null; $hosts = []; $error = null; $warnings = []; $stats = [ 'total' => 0, 'reservations' => 0, 'leases' => 0, 'groups' => [], ]; try { $pdo = modules()->modulePdo('kea', $fallback); if (!empty($metadataConfig['driver']) && !empty($metadataConfig['dbname'])) { try { $metadataRepo = new KeaHostMetadataRepository(Database::createFromArray($metadataConfig)); $metadataRepo->ensureSchema(); } catch (\Throwable $e) { $warnings[] = 'Nexus DHCP Zusatzdatenbank nicht verfuegbar: ' . $e->getMessage(); $metadataRepo = null; } } $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', 'stats'));