Feat: syncSysmailDomain bei saveDomains – anlegen, umbenennen oder überspringen

Beim Speichern der Domains wird geprüft ob sysmail.<BASE_DOMAIN> bereits stimmt.
Falls nicht vorhanden: anlegen. Falls Domain geändert: alte löschen + neu erstellen.
Falls bereits korrekt: nichts tun.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
main v1.1.371
boban 2026-04-26 23:46:17 +02:00
parent 6bb2d09621
commit fb6573598d
1 changed files with 35 additions and 0 deletions

View File

@ -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);