2024-09-27 12:57:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Email;
|
|
|
|
|
|
|
|
class DkimDomainSetup
|
|
|
|
{
|
|
|
|
|
|
|
|
public static function run($domain)
|
|
|
|
{
|
2024-09-30 13:10:46 +00:00
|
|
|
$dkimPrivateKeyFile = '/etc/opendkim/keys/'.$domain.'/mail.private';
|
|
|
|
$dkimTextFile = '/etc/opendkim/keys/'.$domain.'/mail.txt';
|
2024-09-27 12:57:06 +00:00
|
|
|
|
|
|
|
if (is_file($dkimPrivateKeyFile)) {
|
2024-10-03 10:07:23 +00:00
|
|
|
|
|
|
|
$dkimText = file_get_contents($dkimTextFile);
|
|
|
|
$dkimText = str_replace("\r\n", "\n", $dkimText);
|
|
|
|
|
2024-09-27 12:57:06 +00:00
|
|
|
return [
|
|
|
|
'privateKey' => file_get_contents($dkimPrivateKeyFile),
|
2024-10-03 10:07:23 +00:00
|
|
|
'text' => $dkimText,
|
2024-09-27 12:57:06 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
shell_exec('sudo mkdir -p /etc/opendkim/keys/'.$domain);
|
|
|
|
shell_exec('sudo chown -R opendkim:opendkim /etc/opendkim/keys/'.$domain);
|
|
|
|
shell_exec('sudo chmod go-rw /etc/opendkim/keys/'.$domain);
|
|
|
|
|
2024-09-30 13:10:46 +00:00
|
|
|
$output = shell_exec('sudo opendkim-genkey -b 2048 -D /etc/opendkim/keys/'.$domain.' -h rsa-sha256 -r -s mail -d '.$domain.' -v');
|
2024-09-27 12:57:06 +00:00
|
|
|
|
|
|
|
$dkimPrivateKey = file_get_contents($dkimPrivateKeyFile);
|
|
|
|
$dkimText = file_get_contents($dkimTextFile);
|
2024-10-03 10:07:23 +00:00
|
|
|
$dkimText = str_replace("\r\n", "\n", $dkimText);
|
2024-09-27 12:57:06 +00:00
|
|
|
|
|
|
|
return [
|
|
|
|
'privateKey' => $dkimPrivateKey,
|
|
|
|
'text' => $dkimText,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|