Domain Create Modal anpassen Fehler auf Null
parent
f6305ba591
commit
50202b5245
|
|
@ -88,24 +88,114 @@ class DkimService
|
||||||
// 'dns_txt' => "v=DKIM1; k=rsa; p={$publicKeyBase}",
|
// 'dns_txt' => "v=DKIM1; k=rsa; p={$publicKeyBase}",
|
||||||
// 'bits' => $bits,
|
// 'bits' => $bits,
|
||||||
// ];
|
// ];
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public function generateForDomain(Domain $domain, int $bits = 2048, string $selector = null): array
|
||||||
|
// {
|
||||||
|
// // 1) Selector zentral aus der Config (Fallback 'mwl1')
|
||||||
|
// $selector = $selector ?: (string) config('mailpool.defaults.dkim_selector', 'mwl1');
|
||||||
|
//
|
||||||
|
// $dirKey = $this->safeKey($domain);
|
||||||
|
// $selKey = $this->safeKey($selector, 32);
|
||||||
|
//
|
||||||
|
// $disk = Storage::disk('local');
|
||||||
|
// $baseRel = "dkim/{$dirKey}";
|
||||||
|
// $privRel = "{$baseRel}/{$selKey}.pem";
|
||||||
|
// $pubRel = "{$baseRel}/{$selKey}.pub";
|
||||||
|
//
|
||||||
|
// $privAbs = method_exists($disk, 'path')
|
||||||
|
// ? $disk->path($privRel) // -> /var/www/mailwolt/storage/app/private/dkim/<id>/<selector>.pem
|
||||||
|
// : storage_path('app/private/'.$privRel); // Fallback falls 'path' nicht existiert
|
||||||
|
//
|
||||||
|
// $pubAbs = method_exists($disk, 'path')
|
||||||
|
// ? $disk->path($pubRel)
|
||||||
|
// : storage_path('app/private/'.$pubRel);
|
||||||
|
//
|
||||||
|
// // 2) Idempotent: existiert das Paar schon?
|
||||||
|
// if ($disk->exists($privRel) && $disk->exists($pubRel)) {
|
||||||
|
// $privateKey = $disk->get($privRel);
|
||||||
|
// $publicKeyPem = $disk->get($pubRel);
|
||||||
|
// $publicKeyBase = self::extractPublicKeyBase64($publicKeyPem);
|
||||||
|
// if (strlen($publicKeyBase) < 300) {
|
||||||
|
// throw new \RuntimeException('DKIM: Public Key zu kurz – vermutlich Parsing-Fehler.');
|
||||||
|
// }
|
||||||
|
// return [
|
||||||
|
// 'selector' => $selKey,
|
||||||
|
// 'priv_path' => $privAbs,
|
||||||
|
// 'pub_path' => $pubAbs,
|
||||||
|
// 'public_pem' => $publicKeyPem,
|
||||||
|
// 'private_pem' => $privateKey,
|
||||||
|
// 'dns_name' => "{$selKey}._domainkey",
|
||||||
|
// 'dns_txt' => "v=DKIM1; k=rsa; p={$publicKeyBase}",
|
||||||
|
// 'bits' => $bits,
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 3) Neu generieren
|
||||||
|
// $disk->makeDirectory($baseRel);
|
||||||
|
//
|
||||||
|
// $res = openssl_pkey_new([
|
||||||
|
// 'private_key_type' => OPENSSL_KEYTYPE_RSA,
|
||||||
|
// 'private_key_bits' => $bits,
|
||||||
|
// ]);
|
||||||
|
// if ($res === false) {
|
||||||
|
// throw new \RuntimeException('DKIM: openssl_pkey_new() fehlgeschlagen: ' . (openssl_error_string() ?: 'unbekannt'));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// $privateKey = '';
|
||||||
|
// if (!openssl_pkey_export($res, $privateKey)) {
|
||||||
|
// throw new \RuntimeException('DKIM: openssl_pkey_export() fehlgeschlagen: ' . (openssl_error_string() ?: 'unbekannt'));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// $details = openssl_pkey_get_details($res);
|
||||||
|
// if ($details === false || empty($details['key'])) {
|
||||||
|
// throw new \RuntimeException('DKIM: Public Key konnte nicht gelesen werden.');
|
||||||
|
// }
|
||||||
|
// $publicKeyPem = $details['key'];
|
||||||
|
// $publicKeyBase = self::extractPublicKeyBase64($publicKeyPem);
|
||||||
|
// if (strlen($publicKeyBase) < 300) {
|
||||||
|
// throw new \RuntimeException('DKIM: Public Key zu kurz – vermutlich Parsing-Fehler.');
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!$disk->put($privRel, $privateKey)) {
|
||||||
|
// throw new \RuntimeException("DKIM: Private-Key schreiben fehlgeschlagen: {$privRel}");
|
||||||
|
// }
|
||||||
|
// if (!$disk->put($pubRel, $publicKeyPem)) {
|
||||||
|
// throw new \RuntimeException("DKIM: Public-Key schreiben fehlgeschlagen: {$pubRel}");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return [
|
||||||
|
// 'selector' => $selKey,
|
||||||
|
// 'priv_path' => $privAbs,
|
||||||
|
// 'pub_path' => $pubAbs,
|
||||||
|
// 'public_pem' => $publicKeyPem,
|
||||||
|
// 'private_pem' => $privateKey,
|
||||||
|
// 'dns_name' => "{$selKey}._domainkey",
|
||||||
|
// 'dns_txt' => "v=DKIM1; k=rsa; p={$publicKeyBase}",
|
||||||
|
// 'bits' => $bits,
|
||||||
|
// ];
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public function generateForDomain(Domain $domain, int $bits = 2048, string $selector = null): array
|
public function generateForDomain(Domain $domain, int $bits = 2048, string $selector = null): array
|
||||||
{
|
{
|
||||||
// 1) Selector zentral aus der Config (Fallback 'mwl1')
|
// 1) Selector (Fallback mwl1)
|
||||||
$selector = $selector ?: (string) config('mailpool.defaults.dkim_selector', 'mwl1');
|
$selector = $selector ?: (string) config('mailpool.defaults.dkim_selector', 'mwl1');
|
||||||
|
|
||||||
$dirKey = $this->safeKey($domain);
|
$dirKey = $this->safeKey($domain);
|
||||||
$selKey = $this->safeKey($selector, 32);
|
$selKey = $this->safeKey($selector, 32);
|
||||||
|
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local'); // root: /var/www/mailwolt/storage/app/private
|
||||||
$baseRel = "dkim/{$dirKey}";
|
$baseRel = "dkim/{$dirKey}";
|
||||||
$privRel = "{$baseRel}/{$selKey}.pem";
|
$privRel = "{$baseRel}/{$selKey}.pem";
|
||||||
$pubRel = "{$baseRel}/{$selKey}.pub";
|
$pubRel = "{$baseRel}/{$selKey}.pub";
|
||||||
|
|
||||||
|
// Absolute Pfade (robust gegen geändertes Disk-Root)
|
||||||
|
$privAbs = method_exists($disk, 'path') ? $disk->path($privRel) : storage_path('app/private/'.$privRel);
|
||||||
|
$pubAbs = method_exists($disk, 'path') ? $disk->path($pubRel) : storage_path('app/private/'.$pubRel);
|
||||||
|
|
||||||
// 2) Idempotent: existiert das Paar schon?
|
// 2) Idempotent: existiert das Paar schon?
|
||||||
if ($disk->exists($privRel) && $disk->exists($pubRel)) {
|
if ($disk->exists($privRel) && $disk->exists($pubRel)) {
|
||||||
$privateKey = $disk->get($privRel);
|
$privateKey = $disk->get($privRel); // ← Inhalte laden, nicht Pfade!
|
||||||
$publicKeyPem = $disk->get($pubRel);
|
$publicKeyPem = $disk->get($pubRel);
|
||||||
$publicKeyBase = self::extractPublicKeyBase64($publicKeyPem);
|
$publicKeyBase = self::extractPublicKeyBase64($publicKeyPem);
|
||||||
if (strlen($publicKeyBase) < 300) {
|
if (strlen($publicKeyBase) < 300) {
|
||||||
|
|
@ -113,8 +203,8 @@ class DkimService
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
'selector' => $selKey,
|
'selector' => $selKey,
|
||||||
'priv_path' => $disk->path($privRel),
|
'priv_path' => $privAbs,
|
||||||
'pub_path' => $disk->path($pubRel),
|
'pub_path' => $pubAbs,
|
||||||
'public_pem' => $publicKeyPem,
|
'public_pem' => $publicKeyPem,
|
||||||
'private_pem' => $privateKey,
|
'private_pem' => $privateKey,
|
||||||
'dns_name' => "{$selKey}._domainkey",
|
'dns_name' => "{$selKey}._domainkey",
|
||||||
|
|
@ -158,8 +248,8 @@ class DkimService
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'selector' => $selKey,
|
'selector' => $selKey,
|
||||||
'priv_path' => $disk->path($privRel),
|
'priv_path' => $privAbs,
|
||||||
'pub_path' => $disk->path($pubRel),
|
'pub_path' => $pubAbs,
|
||||||
'public_pem' => $publicKeyPem,
|
'public_pem' => $publicKeyPem,
|
||||||
'private_pem' => $privateKey,
|
'private_pem' => $privateKey,
|
||||||
'dns_name' => "{$selKey}._domainkey",
|
'dns_name' => "{$selKey}._domainkey",
|
||||||
|
|
@ -167,6 +257,7 @@ class DkimService
|
||||||
'bits' => $bits,
|
'bits' => $bits,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function safeKey($value, int $max = 64): string
|
protected function safeKey($value, int $max = 64): string
|
||||||
{
|
{
|
||||||
if (is_object($value)) {
|
if (is_object($value)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue