Rechtebechebung für User mit Sudorechte

main
boban 2025-10-19 23:38:39 +02:00
parent 260570b5a8
commit b80ff05a0a
1 changed files with 48 additions and 6 deletions

View File

@ -164,25 +164,67 @@ class DkimService
{
$name = $domain instanceof Domain ? $domain->domain : $domain;
// Selektoren ermitteln
if (is_null($selector)) {
// alle Selector aus DB holen und nacheinander entfernen
$keys = $domain instanceof Domain
? $domain->dkimKeys()->pluck('selector')->all()
: \App\Models\DkimKey::whereHas('domain', fn($q) => $q->where('domain', $name))
->pluck('selector')->all();
$keys = $keys ?: ['mwl1']; // notfalls versuchen wir Standard
$keys = $keys ?: ['mwl1'];
} else {
$keys = [$selector];
}
foreach ($keys as $sel) {
Process::run(['sudo','-n','/usr/local/sbin/mailwolt-remove-dkim',$name,$sel]);
$cmd = ['sudo','-n','/usr/local/sbin/mailwolt-remove-dkim',$name,$sel];
$res = \Illuminate\Support\Facades\Process::timeout(30)->run($cmd);
Log::info('DKIM remove exit', [
'domain' => $name,
'selector' => $sel,
'exit' => $res->exitCode(),
'out' => $res->output(),
'err' => $res->errorOutput(),
]);
if ($res->failed()) {
throw new \RuntimeException('OpenDKIM-Remove fehlgeschlagen: '.$res->errorOutput());
}
}
// Dienst neu laden (ohne Fehler abbrechen)
Process::run(['sudo','-n','/bin/systemctl','reload','opendkim']);
// Dienst neu laden (best effort)
\Illuminate\Support\Facades\Process::run(['sudo','-n','/bin/systemctl','reload','opendkim']);
}
// public function removeForDomain(Domain|string $domain, ?string $selector = null): void
// {
// $name = $domain instanceof Domain ? $domain->domain : $domain;
//
// if (is_null($selector)) {
// // alle Selector aus DB holen und nacheinander entfernen
// $keys = $domain instanceof Domain
// ? $domain->dkimKeys()->pluck('selector')->all()
// : \App\Models\DkimKey::whereHas('domain', fn($q) => $q->where('domain', $name))
// ->pluck('selector')->all();
//
// $keys = $keys ?: ['mwl1']; // notfalls versuchen wir Standard
// } else {
// $keys = [$selector];
// }
//
// foreach ($keys as $sel) {
// Process::run(['sudo','-n','/usr/local/sbin/mailwolt-remove-dkim',$name,$sel]);
// }
//
// // Dienst neu laden (ohne Fehler abbrechen)
// Process::run(['sudo','-n','/bin/systemctl','reload','opendkim']);
//
// $res = Process::timeout(30)->run($cmd);
// Log::info('DKIM install exit', [
// 'exit' => $res->exitCode(),
// 'out' => $res->output(),
// 'err' => $res->errorOutput(),
// ]);
// }
// public function removeForDomain(Domain|string $domain, ?string $selector = null): void