53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Domain;
|
|
use App\Models\DkimKey;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class InstallDkimKey implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public function __construct(
|
|
public int $domainId,
|
|
public int $dkimKeyId,
|
|
public string $privPath,
|
|
public string $dnsTxtContent,
|
|
) {}
|
|
|
|
public function handle(): void
|
|
{
|
|
$domain = Domain::findOrFail($this->domainId);
|
|
$dk = DkimKey::findOrFail($this->dkimKeyId);
|
|
|
|
$domainName = $domain->domain; // z.B. example.com
|
|
$selector = $dk->selector; // z.B. mwl1
|
|
|
|
// TXT temporär für Helper speichern (optional, damit /etc/mailwolt/dns gefüllt wird)
|
|
$tmpTxt = tempnam(sys_get_temp_dir(), 'dkim_txt_');
|
|
file_put_contents($tmpTxt, $this->dnsTxtContent);
|
|
|
|
// Root-Helper aufrufen (sudoers hast du im Installer angelegt)
|
|
$cmd = sprintf(
|
|
'sudo /usr/local/sbin/mailwolt-install-dkim %s %s %s %s',
|
|
escapeshellarg($domainName),
|
|
escapeshellarg($selector),
|
|
escapeshellarg($this->privPath),
|
|
escapeshellarg($tmpTxt)
|
|
);
|
|
|
|
exec($cmd, $out, $rc);
|
|
@unlink($tmpTxt);
|
|
|
|
if ($rc !== 0) {
|
|
throw new \RuntimeException("mailwolt-install-dkim failed (rc={$rc})");
|
|
}
|
|
}
|
|
}
|