diff --git a/app/Livewire/Ui/System/SettingsForm.php b/app/Livewire/Ui/System/SettingsForm.php index 8fd461c..d54b5cc 100644 --- a/app/Livewire/Ui/System/SettingsForm.php +++ b/app/Livewire/Ui/System/SettingsForm.php @@ -216,6 +216,8 @@ class SettingsForm extends Component $this->applyDomains(false); } + $this->syncSysmailDomain(); + $this->loadSslStatus(); $this->dispatch('toast', type: 'done', badge: 'Domains', @@ -223,6 +225,39 @@ class SettingsForm extends Component text: 'Konfiguration wurde übernommen.', duration: 4000); } + private function syncSysmailDomain(): void + { + $platformBase = strtolower(config('mailpool.platform_zone', env('BASE_DOMAIN', ''))); + if (!$platformBase || $platformBase === 'example.com') return; + + $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; + + // 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, + ]); + } catch (\Throwable $e) { + \Illuminate\Support\Facades\Log::error('SystemDomainSeeder failed', ['error' => $e->getMessage()]); + } + } + private function cleanDomain(string $value): string { $value = trim($value);