From 14f2d0cd202ef91ad318b4495790ac9bc2611171 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Mon, 30 Sep 2024 16:10:46 +0300 Subject: [PATCH] update --- .../Email/App/Console/SetupEmailServer.php | 2 ++ .../Email/App/Http/Livewire/DkimSetup.php | 9 +++++++++ web/Modules/Email/App/Models/DomainDkim.php | 4 +++- .../Email/App/Models/DomainDkimSigning.php | 2 ++ web/Modules/Email/DkimDomainSetup.php | 6 +++--- .../resources/views/server/postfix/main.cf | 18 ++++++++++++------ 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/web/Modules/Email/App/Console/SetupEmailServer.php b/web/Modules/Email/App/Console/SetupEmailServer.php index a5ea216..c40e15b 100644 --- a/web/Modules/Email/App/Console/SetupEmailServer.php +++ b/web/Modules/Email/App/Console/SetupEmailServer.php @@ -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); diff --git a/web/Modules/Email/App/Http/Livewire/DkimSetup.php b/web/Modules/Email/App/Http/Livewire/DkimSetup.php index 2814f05..d9599fd 100644 --- a/web/Modules/Email/App/Http/Livewire/DkimSetup.php +++ b/web/Modules/Email/App/Http/Livewire/DkimSetup.php @@ -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; diff --git a/web/Modules/Email/App/Models/DomainDkim.php b/web/Modules/Email/App/Models/DomainDkim.php index 50937b1..553a3e0 100644 --- a/web/Modules/Email/App/Models/DomainDkim.php +++ b/web/Modules/Email/App/Models/DomainDkim.php @@ -14,5 +14,7 @@ class DomainDkim extends Model * The attributes that are mass assignable. */ protected $fillable = []; - + + protected $table = 'domain_dkim'; + } diff --git a/web/Modules/Email/App/Models/DomainDkimSigning.php b/web/Modules/Email/App/Models/DomainDkimSigning.php index ebd924b..4fb8cd9 100644 --- a/web/Modules/Email/App/Models/DomainDkimSigning.php +++ b/web/Modules/Email/App/Models/DomainDkimSigning.php @@ -15,4 +15,6 @@ class DomainDkimSigning extends Model */ protected $fillable = []; + protected $table = 'domain_dkim_signings'; + } diff --git a/web/Modules/Email/DkimDomainSetup.php b/web/Modules/Email/DkimDomainSetup.php index 809ae26..60e4767 100644 --- a/web/Modules/Email/DkimDomainSetup.php +++ b/web/Modules/Email/DkimDomainSetup.php @@ -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); diff --git a/web/Modules/Email/resources/views/server/postfix/main.cf b/web/Modules/Email/resources/views/server/postfix/main.cf index 4eaf8e9..8cd7204 100644 --- a/web/Modules/Email/resources/views/server/postfix/main.cf +++ b/web/Modules/Email/resources/views/server/postfix/main.cf @@ -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