option('ui'); $mail = $this->option('mail'); $webmail = $this->option('webmail'); $ssl = (bool)(int)$this->option('ssl'); @mkdir(self::STATE_DIR, 0755, true); foreach (['ui', 'mail', 'webmail'] as $key) { file_put_contents(self::STATE_DIR . "/{$key}", 'pending'); } $domains = ['ui' => $ui, 'mail' => $mail, 'webmail' => $webmail]; $allOk = true; // DNS prüfen foreach ($domains as $key => $domain) { if (!$domain) { file_put_contents(self::STATE_DIR . "/{$key}", 'skip'); continue; } file_put_contents(self::STATE_DIR . "/{$key}", 'running'); $hasDns = checkdnsrr($domain, 'A') || checkdnsrr($domain, 'AAAA'); if (!$hasDns) { file_put_contents(self::STATE_DIR . "/{$key}", 'nodns'); $allOk = false; } } if (!$allOk) { file_put_contents(self::STATE_DIR . '/done', '0'); Setting::set('ssl_configured', '0'); return self::SUCCESS; } // Nginx-Vhosts + optionales SSL via mailwolt-apply-domains // Das Script erstellt erst die Vhosts (mit ACME-Location), dann certbot --webroot $helper = '/usr/local/sbin/mailwolt-apply-domains'; $out = shell_exec(sprintf( 'sudo -n %s --ui-host %s --webmail-host %s --mail-host %s --ssl-auto %d 2>&1', escapeshellarg($helper), escapeshellarg($ui), escapeshellarg($webmail), escapeshellarg($mail), $ssl ? 1 : 0, )); $helperOk = $out !== null && !str_contains((string) $out, '[x]'); foreach (['ui', 'mail', 'webmail'] as $key) { $status = file_get_contents(self::STATE_DIR . "/{$key}"); if ($status === 'running' || $status === 'pending') { file_put_contents(self::STATE_DIR . "/{$key}", $helperOk ? 'done' : 'error'); } } file_put_contents(self::STATE_DIR . '/done', $helperOk ? '1' : '0'); Setting::set('ssl_configured', $helperOk ? '1' : '0'); return self::SUCCESS; } }