diff --git a/app/Livewire/Ui/System/SettingsForm.php b/app/Livewire/Ui/System/SettingsForm.php index 942c54e..fceb857 100644 --- a/app/Livewire/Ui/System/SettingsForm.php +++ b/app/Livewire/Ui/System/SettingsForm.php @@ -197,7 +197,6 @@ class SettingsForm extends Component { $this->validate($this->domainRules(), $this->domainMessages()); - // Normalize: strip schema + trailing slashes $this->ui_domain = $this->cleanDomain($this->ui_domain); $this->mail_domain = $this->cleanDomain($this->mail_domain); $this->webmail_domain = $this->cleanDomain($this->webmail_domain); @@ -208,24 +207,38 @@ class SettingsForm extends Component 'webmail_domain' => $this->webmail_domain, ]); - // Immer .env aktualisieren — unabhängig von DNS oder Nginx $this->syncDomainsToEnv(); - // Nginx-Konfiguration (ohne certbot) — nur wenn alle Domains gesetzt sind + $warnings = []; + if ($this->ui_domain && $this->mail_domain && $this->webmail_domain) { - $this->applyDomains(false); + $nginxOk = $this->applyDomains(false); + if ($nginxOk === false) { + $warnings[] = 'Nginx konnte nicht neu geladen werden — DNS noch nicht aktiv oder Helper fehlt.'; + } } - $this->syncSysmailDomain(); + $sysmailErr = $this->syncSysmailDomain(); + if ($sysmailErr) { + $warnings[] = 'System-Domain: ' . $sysmailErr; + } $this->loadSslStatus(); - $this->dispatch('toast', type: 'done', badge: 'Domains', - title: 'Domains gespeichert', - text: 'Konfiguration wurde übernommen.', duration: 4000); + if ($warnings) { + $this->dispatch('toast', type: 'warn', badge: 'Domains', + title: 'Domains gespeichert — mit Hinweisen', + text: implode(' · ', $warnings), + duration: 0); + } else { + $this->dispatch('toast', type: 'done', badge: 'Domains', + title: 'Domains gespeichert', + text: 'Konfiguration wurde übernommen.', + duration: 4000); + } } - private function syncSysmailDomain(): void + private function syncSysmailDomain(): ?string { // BASE_DOMAIN aus config, env oder mail_domain ableiten $platformBase = strtolower((string) config('mailpool.platform_zone', '')); @@ -242,37 +255,35 @@ class SettingsForm extends Component : $mailDomain; } } - if (!$platformBase || $platformBase === 'example.com') return; + if (!$platformBase || $platformBase === 'example.com') return null; - $systemSub = strtolower(config('mailpool.platform_system_zone', 'sysmail')); + $systemSub = strtolower(config('mailpool.platform_system_zone', 'sysmail')); $expectedFqdn = "{$systemSub}.{$platformBase}"; - // Bestehende System-Domain suchen (is_system=true, nicht is_server) $existing = \App\Models\Domain::where('is_system', true) ->where(fn($q) => $q->whereNull('is_server')->orWhere('is_server', false)) ->first(); - // Alles passt → nichts tun - if ($existing && $existing->domain === $expectedFqdn) return; + if ($existing && $existing->domain === $expectedFqdn) return null; - // Alte System-Domain + Postfächer löschen falls Domain geändert if ($existing && $existing->domain !== $expectedFqdn) { \App\Models\MailUser::where('domain_id', $existing->id)->forceDelete(); $existing->forceDelete(); } - // Neu anlegen via Seeder try { Artisan::call('db:seed', [ '--class' => 'Database\\Seeders\\SystemDomainSeeder', '--force' => true, ]); \Illuminate\Support\Facades\Log::info('SystemDomainSeeder ok', ['fqdn' => $expectedFqdn]); + return null; } catch (\Throwable $e) { \Illuminate\Support\Facades\Log::error('SystemDomainSeeder failed', [ 'fqdn' => $expectedFqdn, 'error' => $e->getMessage(), ]); + return $e->getMessage(); } } @@ -383,7 +394,7 @@ class SettingsForm extends Component } } - private function applyDomains(bool $sslAuto = false): void + private function applyDomains(bool $sslAuto = false): bool { // DNS prüfen — Warnung anzeigen, aber Nginx trotzdem versuchen $unreachable = []; @@ -395,7 +406,7 @@ class SettingsForm extends Component if ($unreachable) { Log::info('mailwolt-apply-domains skipped (DNS not ready)', ['unreachable' => $unreachable]); - return; + return false; } $helper = '/usr/local/sbin/mailwolt-apply-domains'; @@ -415,9 +426,11 @@ class SettingsForm extends Component if ($ok) { Setting::set('ssl_configured', '1'); - } else { - Log::warning('mailwolt-apply-domains failed', ['output' => $output]); + return true; } + + Log::warning('mailwolt-apply-domains failed', ['output' => $output]); + return false; } private function syncDomainsToEnv(): void