This commit is contained in:
Bozhidar 2024-09-30 16:10:46 +03:00
parent ce62ec5ab1
commit 14f2d0cd20
6 changed files with 31 additions and 10 deletions

View file

@ -69,10 +69,12 @@ class SetupEmailServer extends Command
$postfixMysqlVirtualMailboxMapsCf = PhyreBlade::render('email::server.postfix.sql.mysql_virtual_mailbox_maps.cf',$mysqlDbDetails);
file_put_contents('/etc/postfix/sql/mysql_virtual_mailbox_maps.cf', $postfixMysqlVirtualMailboxMapsCf);
$findDkim = DomainDkim::where('domain_name', setting('email.hostname'))->first();
$postfixMainCf = PhyreBlade::render('email::server.postfix.main.cf', [
'hostName' => setting('email.hostname'),
'domain' => setting('email.domain'),
'sslPaths' => $sslPaths,
'dkim' => $findDkim,
]);
file_put_contents('/etc/postfix/main.cf', $postfixMainCf);

View file

@ -4,6 +4,7 @@ namespace Modules\Email\App\Http\Livewire;
use Livewire\Component;
use Modules\Email\App\Models\DomainDkim;
use Modules\Email\App\Models\DomainDkimSigning;
use Modules\Email\DkimDomainSetup;
class DkimSetup extends Component
@ -90,6 +91,14 @@ class DkimSetup extends Component
$findDomainDkim->private_key = $output['privateKey'];
$findDomainDkim->public_key = $output['text'];
$findDomainDkim->save();
$findDomainDkimSigning = DomainDkimSigning::where('author', '*')->where('dkim_id', $findDomainDkim->id)->first();
if (!$findDomainDkimSigning) {
$findDomainDkimSigning = new DomainDkimSigning();
$findDomainDkimSigning->author = '*';
$findDomainDkimSigning->dkim_id = $findDomainDkim->id;
$findDomainDkimSigning->save();
}
}
return $output;

View file

@ -14,5 +14,7 @@ class DomainDkim extends Model
* The attributes that are mass assignable.
*/
protected $fillable = [];
protected $table = 'domain_dkim';
}

View file

@ -15,4 +15,6 @@ class DomainDkimSigning extends Model
*/
protected $fillable = [];
protected $table = 'domain_dkim_signings';
}

View file

@ -7,8 +7,8 @@ class DkimDomainSetup
public static function run($domain)
{
$dkimPrivateKeyFile = '/etc/opendkim/keys/'.$domain.'/dkim.private';
$dkimTextFile = '/etc/opendkim/keys/'.$domain.'/dkim.txt';
$dkimPrivateKeyFile = '/etc/opendkim/keys/'.$domain.'/mail.private';
$dkimTextFile = '/etc/opendkim/keys/'.$domain.'/mail.txt';
if (is_file($dkimPrivateKeyFile)) {
return [
@ -21,7 +21,7 @@ class DkimDomainSetup
shell_exec('sudo chown -R opendkim:opendkim /etc/opendkim/keys/'.$domain);
shell_exec('sudo chmod go-rw /etc/opendkim/keys/'.$domain);
$output = shell_exec('sudo opendkim-genkey -b 2048 -D /etc/opendkim/keys/'.$domain.' -h rsa-sha256 -r -s dkim -d '.$domain.' -v');
$output = shell_exec('sudo opendkim-genkey -b 2048 -D /etc/opendkim/keys/'.$domain.' -h rsa-sha256 -r -s mail -d '.$domain.' -v');
$dkimPrivateKey = file_get_contents($dkimPrivateKeyFile);
$dkimText = file_get_contents($dkimTextFile);

View file

@ -44,7 +44,9 @@ smtp_sasl_local_domain = $myhostname
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_sender_restrictions = permit_sasl_authenticated
smtp_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination
# smtp_milters = inet:127.0.0.1:8891
@if($dkim)
smtp_milters = inet:127.0.0.1:8891
@endif
# SMTPD
@if(!empty($sslPaths))
@ -64,13 +66,17 @@ smtpd_sasl_local_domain = $myhostname
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_sender_restrictions = permit_sasl_authenticated
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination
# smtpd_milters = inet:127.0.0.1:8891
@if($dkim)
smtpd_milters = inet:127.0.0.1:8891
@endif
@if($dkim)
# DKIM
# milter_default_action = accept
# milter_protocol = 2
# non_smtpd_milters = inet:127.0.0.1:8891
# non_smtp_milters = inet:127.0.0.1:8891
milter_default_action = accept
milter_protocol = 2
non_smtpd_milters = inet:127.0.0.1:8891
non_smtp_milters = inet:127.0.0.1:8891
@endif
# Virtual Domains
virtual_mailbox_base = 0