diff --git a/app/Livewire/Ui/Nx/Dashboard.php b/app/Livewire/Ui/Nx/Dashboard.php index 6f5e6e1..5961d9e 100644 --- a/app/Livewire/Ui/Nx/Dashboard.php +++ b/app/Livewire/Ui/Nx/Dashboard.php @@ -10,6 +10,7 @@ use App\Models\SandboxRoute; use App\Models\Setting as SettingModel; use App\Support\CacheVer; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\DB; use Livewire\Attributes\Layout; use Livewire\Attributes\Title; use Livewire\Component; @@ -20,13 +21,7 @@ class Dashboard extends Component { public function render() { - $cached = Cache::get(CacheVer::k('health:services'), []); - $rows = $cached['rows'] ?? []; - $services = array_map(fn($r) => [ - 'name' => $r['label'] ?? ucfirst($r['name']), - 'type' => $r['hint'] ?? '', - 'status' => ($r['ok'] ?? false) ? 'online' : 'offline', - ], $rows); + $services = $this->loadServices(); [$cpu, $cpuCores, $cpuMhz] = $this->cpu(); [$ramPercent, $ramUsed, $ramTotal] = $this->ram(); @@ -78,6 +73,55 @@ class Dashboard extends Component } + private function loadServices(): array + { + // 1) Monit-Cache (populated by RunHealthChecks job) + $cached = Cache::get(CacheVer::k('health:services'), []); + $rows = $cached['rows'] ?? []; + + // 2) Fallback: use woltguard.php cards with active systemd/tcp probes + if (empty($rows)) { + $cards = config('woltguard.cards', []); + foreach ($cards as $key => $card) { + $isOk = false; + foreach ($card['sources'] as $src) { + if ($this->probeSource($src)) { $isOk = true; break; } + } + $rows[] = ['label' => $card['label'], 'hint' => $card['hint'], 'ok' => $isOk]; + } + } + + return array_map(fn($r) => [ + 'name' => $r['label'] ?? ucfirst($r['name'] ?? ''), + 'type' => $r['hint'] ?? '', + 'status' => ($r['ok'] ?? false) ? 'online' : 'offline', + ], $rows); + } + + private function probeSource(string $src): bool + { + if (str_starts_with($src, 'systemd:')) { + $unit = substr($src, 8); + $exit = null; + @exec("systemctl is-active --quiet " . escapeshellarg($unit) . " 2>/dev/null", $_, $exit); + return $exit === 0; + } + if (str_starts_with($src, 'tcp:')) { + [, $host, $port] = explode(':', $src, 3); + $fp = @fsockopen($host, (int)$port, $e1, $e2, 1); + if (is_resource($fp)) { fclose($fp); return true; } + return false; + } + if (str_starts_with($src, 'socket:')) { + return @file_exists(substr($src, 7)); + } + if ($src === 'db') { + try { \Illuminate\Support\Facades\DB::connection()->getPdo(); return true; } + catch (\Throwable) { return false; } + } + return false; + } + private function ports(): array { $check = [25, 465, 587, 110, 143, 993, 995, 80, 443]; diff --git a/config/woltguard.php b/config/woltguard.php index b4f6eb5..0cd92d7 100644 --- a/config/woltguard.php +++ b/config/woltguard.php @@ -64,6 +64,10 @@ return [ ], // Sonstiges + 'monit' => [ + 'label' => 'Monit', 'hint' => 'Prozess-Monitoring', + 'sources' => ['systemd:monit', 'tcp:127.0.0.1:2812'], + ], 'fail2ban' => [ 'label' => 'Fail2Ban', 'hint' => 'SSH / Mail Protection', 'sources' => ['systemd:fail2ban'],