From ec571625a4dee99acff1a2cef75a48aa57df82cb Mon Sep 17 00:00:00 2001 From: tbrehm Date: Thu, 22 Aug 2013 11:56:36 +0000 Subject: [PATCH] Updated dkim support. Thanks to Florian for the patch. --- install/dist/lib/fedora.lib.php | 13 ++ install/dist/lib/gentoo.lib.php | 13 ++ install/dist/lib/opensuse.lib.php | 13 ++ install/lib/installer_base.lib.php | 9 ++ install/tpl/debian_postfix.conf.master | 4 +- install/tpl/fedora_postfix.conf.master | 4 +- install/tpl/gentoo_postfix.conf.master | 4 +- install/tpl/opensuse_postfix.conf.master | 4 +- .../web/admin/lib/lang/de_server_config.lng | 2 + .../web/admin/lib/lang/fr_server_config.lng | 2 + interface/web/dns/lib/lang/de_dns_dkim.lng | 8 + interface/web/dns/lib/lang/de_dns_wizard.lng | 1 + interface/web/dns/lib/lang/fr_dns_dkim.lng | 8 + interface/web/dns/lib/lang/fr_dns_wizard.lng | 1 + .../web/mail/lib/lang/de_mail_domain.lng | 6 + .../web/mail/lib/lang/fr_mail_domain.lng | 7 + .../web/mail/templates/mail_domain_edit.htm | 29 ++-- .../mail_plugin_dkim.inc.php | 150 +++++++++--------- 18 files changed, 180 insertions(+), 98 deletions(-) create mode 100644 interface/web/dns/lib/lang/de_dns_dkim.lng create mode 100644 interface/web/dns/lib/lang/fr_dns_dkim.lng diff --git a/install/dist/lib/fedora.lib.php b/install/dist/lib/fedora.lib.php index 61130a136..a590fad94 100644 --- a/install/dist/lib/fedora.lib.php +++ b/install/dist/lib/fedora.lib.php @@ -152,6 +152,19 @@ class installer_dist extends installer_base { //* mysql-virtual_relayrecipientmaps.cf $this->process_postfix_config('mysql-virtual_relayrecipientmaps.cf'); + //* postfix-dkim + $full_file_name=$config_dir.'/tag_as_originating.re'; + if(is_file($full_file_name)) { + copy($full_file_name, $config_dir.$configfile.'~'); + } + wf($full_file_name,'/^/ FILTER amavis:[127.0.0.1]:10026'); + + $full_file_name=$config_dir.'/tag_as_foreign.re'; + if(is_file($full_file_name)) { + copy($full_file_name, $config_dir.$configfile.'~'); + } + wf($full_file_name,'/^/ FILTER amavis:[127.0.0.1]:10024'); + //* Changing mode and group of the new created config files. caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', __FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed'); diff --git a/install/dist/lib/gentoo.lib.php b/install/dist/lib/gentoo.lib.php index 382689cd5..f5358ddb5 100644 --- a/install/dist/lib/gentoo.lib.php +++ b/install/dist/lib/gentoo.lib.php @@ -156,6 +156,19 @@ class installer extends installer_base $command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters'; caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); } + + //* postfix-dkim + $full_file_name=$config_dir.'/tag_as_originating.re'; + if(is_file($full_file_name)) { + copy($full_file_name, $config_dir.$configfile.'~'); + } + $this->write_config_file($full_file_name,'/^/ FILTER amavis:[127.0.0.1]:10026'); + + $full_file_name=$config_dir.'/tag_as_foreign.re'; + if(is_file($full_file_name)) { + copy($full_file_name, $config_dir.$configfile.'~'); + } + $this->write_config_file($full_file_name,'/^/ FILTER amavis:[127.0.0.1]:10024'); //* Chmod and chown the .mailfilter file $command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter'; diff --git a/install/dist/lib/opensuse.lib.php b/install/dist/lib/opensuse.lib.php index 7a2fa264d..034897cc4 100644 --- a/install/dist/lib/opensuse.lib.php +++ b/install/dist/lib/opensuse.lib.php @@ -151,6 +151,19 @@ class installer_dist extends installer_base { //* mysql-virtual_relayrecipientmaps.cf $this->process_postfix_config('mysql-virtual_relayrecipientmaps.cf'); + //* postfix-dkim + $full_file_name=$config_dir.'/tag_as_originating.re'; + if(is_file($full_file_name)) { + copy($full_file_name, $config_dir.$configfile.'~'); + } + wf($full_file_name,'/^/ FILTER amavis:[127.0.0.1]:10026'); + + $full_file_name=$config_dir.'/tag_as_foreign.re'; + if(is_file($full_file_name)) { + copy($full_file_name, $config_dir.$configfile.'~'); + } + wf($full_file_name,'/^/ FILTER amavis:[127.0.0.1]:10024'); + //* Changing mode and group of the new created config files. caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', __FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed'); diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 1e8459e2a..e43d0bb70 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -665,6 +665,15 @@ class installer_base { //* mysql-virtual_relayrecipientmaps.cf $this->process_postfix_config('mysql-virtual_relayrecipientmaps.cf'); + //* postfix-dkim + $full_file_name=$config_dir.'/tag_as_originating.re'; + if(is_file($full_file_name)) copy($full_file_name, $config_dir.$configfile.'~'); + wf($full_file_name,'/^/ FILTER amavis:[127.0.0.1]:10026'); + + $full_file_name=$config_dir.'/tag_as_foreign.re'; + if(is_file($full_file_name)) copy($full_file_name, $config_dir.$configfile.'~'); + wf($full_file_name,'/^/ FILTER amavis:[127.0.0.1]:10024'); + //* Changing mode and group of the new created config files. caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', __FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed'); diff --git a/install/tpl/debian_postfix.conf.master b/install/tpl/debian_postfix.conf.master index 85f5d07bc..e5564c84e 100644 --- a/install/tpl/debian_postfix.conf.master +++ b/install/tpl/debian_postfix.conf.master @@ -20,7 +20,7 @@ transport_maps = hash:/var/lib/mailman/data/transport-mailman, proxy:mysql:{conf relay_domains = mysql:{config_dir}/mysql-virtual_relaydomains.cf relay_recipient_maps = mysql:{config_dir}/mysql-virtual_relayrecipientmaps.cf proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps -smtpd_sender_restrictions = check_sender_access mysql:{config_dir}/mysql-virtual_sender.cf +smtpd_sender_restrictions = check_sender_access mysql:{config_dir}/mysql-virtual_sender.cf regexp:{config_dir}/tag_as_originating.re, permit_mynetworks, check_sender_access regexp:{config_dir}/tag_as_foreign.re smtpd_client_restrictions = check_client_access mysql:{config_dir}/mysql-virtual_client.cf smtpd_client_message_rate_limit = 100 maildrop_destination_concurrency_limit = 1 @@ -30,4 +30,4 @@ header_checks = regexp:{config_dir}/header_checks mime_header_checks = regexp:{config_dir}/mime_header_checks nested_header_checks = regexp:{config_dir}/nested_header_checks body_checks = regexp:{config_dir}/body_checks -owner_request_special = no \ No newline at end of file +owner_request_special = no diff --git a/install/tpl/fedora_postfix.conf.master b/install/tpl/fedora_postfix.conf.master index c84bd11bf..35c3cac13 100644 --- a/install/tpl/fedora_postfix.conf.master +++ b/install/tpl/fedora_postfix.conf.master @@ -17,7 +17,7 @@ transport_maps = hash:/var/lib/mailman/data/transport-mailman, proxy:mysql:{conf relay_domains = mysql:{config_dir}/mysql-virtual_relaydomains.cf relay_recipient_maps = mysql:{config_dir}/mysql-virtual_relayrecipientmaps.cf proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps -smtpd_sender_restrictions = check_sender_access mysql:{config_dir}/mysql-virtual_sender.cf +smtpd_sender_restrictions = check_sender_access mysql:{config_dir}/mysql-virtual_sender.cf regexp:{config_dir}/tag_as_originating.re, permit_mynetworks, check_sender_access regexp:{config_dir}/tag_as_foreign.re smtpd_client_restrictions = check_client_access mysql:{config_dir}/mysql-virtual_client.cf smtpd_client_message_rate_limit = 100 maildrop_destination_concurrency_limit = 1 @@ -27,4 +27,4 @@ header_checks = regexp:{config_dir}/header_checks mime_header_checks = regexp:{config_dir}/mime_header_checks nested_header_checks = regexp:{config_dir}/nested_header_checks body_checks = regexp:{config_dir}/body_checks -inet_interfaces = all \ No newline at end of file +inet_interfaces = all diff --git a/install/tpl/gentoo_postfix.conf.master b/install/tpl/gentoo_postfix.conf.master index c84bd11bf..35c3cac13 100644 --- a/install/tpl/gentoo_postfix.conf.master +++ b/install/tpl/gentoo_postfix.conf.master @@ -17,7 +17,7 @@ transport_maps = hash:/var/lib/mailman/data/transport-mailman, proxy:mysql:{conf relay_domains = mysql:{config_dir}/mysql-virtual_relaydomains.cf relay_recipient_maps = mysql:{config_dir}/mysql-virtual_relayrecipientmaps.cf proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps -smtpd_sender_restrictions = check_sender_access mysql:{config_dir}/mysql-virtual_sender.cf +smtpd_sender_restrictions = check_sender_access mysql:{config_dir}/mysql-virtual_sender.cf regexp:{config_dir}/tag_as_originating.re, permit_mynetworks, check_sender_access regexp:{config_dir}/tag_as_foreign.re smtpd_client_restrictions = check_client_access mysql:{config_dir}/mysql-virtual_client.cf smtpd_client_message_rate_limit = 100 maildrop_destination_concurrency_limit = 1 @@ -27,4 +27,4 @@ header_checks = regexp:{config_dir}/header_checks mime_header_checks = regexp:{config_dir}/mime_header_checks nested_header_checks = regexp:{config_dir}/nested_header_checks body_checks = regexp:{config_dir}/body_checks -inet_interfaces = all \ No newline at end of file +inet_interfaces = all diff --git a/install/tpl/opensuse_postfix.conf.master b/install/tpl/opensuse_postfix.conf.master index c84bd11bf..35c3cac13 100644 --- a/install/tpl/opensuse_postfix.conf.master +++ b/install/tpl/opensuse_postfix.conf.master @@ -17,7 +17,7 @@ transport_maps = hash:/var/lib/mailman/data/transport-mailman, proxy:mysql:{conf relay_domains = mysql:{config_dir}/mysql-virtual_relaydomains.cf relay_recipient_maps = mysql:{config_dir}/mysql-virtual_relayrecipientmaps.cf proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps -smtpd_sender_restrictions = check_sender_access mysql:{config_dir}/mysql-virtual_sender.cf +smtpd_sender_restrictions = check_sender_access mysql:{config_dir}/mysql-virtual_sender.cf regexp:{config_dir}/tag_as_originating.re, permit_mynetworks, check_sender_access regexp:{config_dir}/tag_as_foreign.re smtpd_client_restrictions = check_client_access mysql:{config_dir}/mysql-virtual_client.cf smtpd_client_message_rate_limit = 100 maildrop_destination_concurrency_limit = 1 @@ -27,4 +27,4 @@ header_checks = regexp:{config_dir}/header_checks mime_header_checks = regexp:{config_dir}/mime_header_checks nested_header_checks = regexp:{config_dir}/nested_header_checks body_checks = regexp:{config_dir}/body_checks -inet_interfaces = all \ No newline at end of file +inet_interfaces = all diff --git a/interface/web/admin/lib/lang/de_server_config.lng b/interface/web/admin/lib/lang/de_server_config.lng index acb6b3dd8..59cdfdd8a 100644 --- a/interface/web/admin/lib/lang/de_server_config.lng +++ b/interface/web/admin/lib/lang/de_server_config.lng @@ -19,6 +19,8 @@ $wb['fastcgi_bin_txt'] = 'FastCGI Bin'; $wb['module_txt'] = 'Modul'; $wb['maildir_path_txt'] = 'Maildir Pfad'; $wb['homedir_path_txt'] = 'Homedir Pfad'; +$wb["dkim_path_txt"] = 'DKIM Pfad'; +$wb["dkim_path_error"] = 'DKIM Pfad nicht gefunden oder nicht beschreibbar.'; $wb['mailuser_uid_txt'] = 'Mailbenutzer UID'; $wb['mailuser_gid_txt'] = 'Mailbenutzer GID'; $wb['mailuser_name_txt'] = 'Mailbenutzer Name'; diff --git a/interface/web/admin/lib/lang/fr_server_config.lng b/interface/web/admin/lib/lang/fr_server_config.lng index eabca449d..32779c783 100644 --- a/interface/web/admin/lib/lang/fr_server_config.lng +++ b/interface/web/admin/lib/lang/fr_server_config.lng @@ -18,6 +18,8 @@ $wb['fastcgi_bin_txt'] = 'Exécutable FastCGI'; $wb['module_txt'] = 'Module'; $wb['maildir_path_txt'] = 'Chemin Maildir'; $wb['homedir_path_txt'] = 'Chemin Homedir'; +$wb['dkim_path_txt'] = 'Chemin DKIM'; +$wb['dkim_path_error'] = 'Le chemin DKIM n\'est pas trouvé ou ne peut être écrit.'; $wb['mailuser_uid_txt'] = 'UID de l\'utilisateur mail'; $wb['mailuser_gid_txt'] = 'GID de l\'utilisateur mail'; $wb['mailuser_name_txt'] = 'Nom d\'utilisateur mail'; diff --git a/interface/web/dns/lib/lang/de_dns_dkim.lng b/interface/web/dns/lib/lang/de_dns_dkim.lng new file mode 100644 index 000000000..97f04b7f7 --- /dev/null +++ b/interface/web/dns/lib/lang/de_dns_dkim.lng @@ -0,0 +1,8 @@ + diff --git a/interface/web/dns/lib/lang/de_dns_wizard.lng b/interface/web/dns/lib/lang/de_dns_wizard.lng index bb90167b2..5a8158b16 100644 --- a/interface/web/dns/lib/lang/de_dns_wizard.lng +++ b/interface/web/dns/lib/lang/de_dns_wizard.lng @@ -9,6 +9,7 @@ $wb['btn_save_txt'] = 'DNS Eintrag hinzufügen'; $wb['btn_cancel_txt'] = 'Abbrechen'; $wb['domain_txt'] = 'Domain'; $wb['email_txt'] = 'E-Mail Adresse'; +$wb['dkim_txt'] = 'DKIM aktiviert'; $wb['ns1_txt'] = 'NS 1'; $wb['ns2_txt'] = 'NS 2'; $wb['ip_txt'] = 'IP Adresse'; diff --git a/interface/web/dns/lib/lang/fr_dns_dkim.lng b/interface/web/dns/lib/lang/fr_dns_dkim.lng new file mode 100644 index 000000000..f64c89b8c --- /dev/null +++ b/interface/web/dns/lib/lang/fr_dns_dkim.lng @@ -0,0 +1,8 @@ + diff --git a/interface/web/dns/lib/lang/fr_dns_wizard.lng b/interface/web/dns/lib/lang/fr_dns_wizard.lng index db2f0e413..592256f74 100644 --- a/interface/web/dns/lib/lang/fr_dns_wizard.lng +++ b/interface/web/dns/lib/lang/fr_dns_wizard.lng @@ -6,6 +6,7 @@ $wb['btn_save_txt'] = 'Créer l\'enregistrement DNS'; $wb['btn_cancel_txt'] = 'Annuler'; $wb['domain_txt'] = 'Domaine'; $wb['email_txt'] = 'Email'; +$wb['dkim_txt'] = 'DKIM activé'; $wb['ns1_txt'] = 'NS 1'; $wb['ns2_txt'] = 'NS 2'; $wb['ip_txt'] = 'Adresse IP'; diff --git a/interface/web/mail/lib/lang/de_mail_domain.lng b/interface/web/mail/lib/lang/de_mail_domain.lng index ff6da2ab1..3d1b15056 100644 --- a/interface/web/mail/lib/lang/de_mail_domain.lng +++ b/interface/web/mail/lib/lang/de_mail_domain.lng @@ -3,6 +3,12 @@ $wb['server_id_txt'] = 'Server'; $wb['domain_txt'] = 'Domain'; $wb['type_txt'] = 'Typ'; $wb['active_txt'] = 'Aktiv'; +$wb["dkim_txt"] = 'DKIM aktivieren +$wb["dkim_private_txt"] = 'DKIM Private-key'; +$wb["dkim_public_txt"] = 'DKIM Public-key\nfor information only'; +$wb["dkim_generate_txt"] = 'erstelle DKIM Private-key'; +$wb["dkim_dns_txt"] = 'DNS-Record (TYPE TXT)

add this record to your DNS'; +$wb["dkim_private_key_error"] = 'ungueltiger DKIM-Private key'; $wb['domain_error_empty'] = 'Domain ist leer'; $wb['domain_error_unique'] = 'Doppelte Domain.'; $wb['domain_error_regex'] = 'Ungültiger Domainname.'; diff --git a/interface/web/mail/lib/lang/fr_mail_domain.lng b/interface/web/mail/lib/lang/fr_mail_domain.lng index 55e8c2607..969b9700e 100644 --- a/interface/web/mail/lib/lang/fr_mail_domain.lng +++ b/interface/web/mail/lib/lang/fr_mail_domain.lng @@ -3,6 +3,13 @@ $wb['server_id_txt'] = 'Serveur'; $wb['domain_txt'] = 'Domaine'; $wb['type_txt'] = 'Type'; $wb['active_txt'] = 'Actif'; +$wb['dkim_txt'] = 'Activer DKIM'; +$wb['dkim_private_txt'] = 'Clé privée DKIM'; +$wb['dkim_public_txt'] = 'Clé publique DKIM\npour information seulement'; +$wb['dkim_generate_txt'] = 'Générer la clé privée DKIM'; +$wb['dkim_dns_txt'] = 'Enregistrement DNS (TYPE TXT)

Ajouter l\'enregistrement à votre DNS'; +$wb['dkim_private_key_error'] = 'Clé privée DKIM invalide'; +$wb['dkim_settings_txt'] = 'DomainKeys Identified Mail (DKIM)'; $wb['domain_error_empty'] = 'Le domaine est vide.'; $wb['domain_error_unique'] = 'Dupliquer le domaine.'; $wb['domain_error_regex'] = 'Le domaine est invalide.'; diff --git a/interface/web/mail/templates/mail_domain_edit.htm b/interface/web/mail/templates/mail_domain_edit.htm index 6426e67ba..703515b87 100644 --- a/interface/web/mail/templates/mail_domain_edit.htm +++ b/interface/web/mail/templates/mail_domain_edit.htm @@ -69,17 +69,16 @@
- -{tmpl_var name='dkim_generate_txt'} -
-
- - -
- - - - + +{tmpl_var name='dkim_generate_txt'} + +
+ +
+ + + + @@ -87,7 +86,7 @@ - - - - + + + + diff --git a/server/plugins-available/mail_plugin_dkim.inc.php b/server/plugins-available/mail_plugin_dkim.inc.php index 1a50cee94..0bea953bb 100644 --- a/server/plugins-available/mail_plugin_dkim.inc.php +++ b/server/plugins-available/mail_plugin_dkim.inc.php @@ -1,9 +1,9 @@ -plugins->registerEvent('mail_domain_delete',$this->plugin_name,'domain_dkim_delete'); - $app->plugins->registerEvent('mail_domain_insert',$this->plugin_name,'domain_dkim_insert'); - $app->plugins->registerEvent('mail_domain_update',$this->plugin_name,'domain_dkim_update'); - } - - /* + $app->plugins->registerEvent('mail_domain_delete',$this->plugin_name,'domain_dkim_delete'); + $app->plugins->registerEvent('mail_domain_insert',$this->plugin_name,'domain_dkim_insert'); + $app->plugins->registerEvent('mail_domain_update',$this->plugin_name,'domain_dkim_update'); + } + + /* This function gets the amavisd-config file */ - function get_amavis_config() { - $pos_config=array( - '/etc/amavisd.conf', - '/etc/amavisd.conf/50-user', - '/etc/amavis/conf.d/50-user' - ); - $amavis_configfile=''; - foreach($pos_config as $conf) { + function get_amavis_config() { + $pos_config=array( + '/etc/amavisd.conf', + '/etc/amavisd.conf/50-user', + '/etc/amavis/conf.d/50-user' + ); + $amavis_configfile=''; + foreach($pos_config as $conf) { if (is_file($conf)) { $amavis_configfile=$conf; break; @@ -105,58 +105,58 @@ class mail_plugin_dkim { $check=false; } } else { - $app->log('Unable to write DKIM settings; Check your config!',LOGLEVEL_ERROR); - $check=false; - } - return $check; - } - + $app->log('Unable to write DKIM settings; Check your config!',LOGLEVEL_ERROR); + $check=false; + } + return $check; + } + /* This function restarts amavis */ function restart_amavis() { - global $app,$conf; - $initfile=$conf['init_scripts'].'/amavis'; - $app->log('Restarting amavis.',LOGLEVEL_DEBUG); - exec(escapeshellarg($conf['init_scripts']).escapeshellarg('/amavis').' restart',$output); - foreach($output as $logline) $app->log($logline,LOGLEVEL_DEBUG); - } - - /* - This function writes the keyfiles (public and private) - */ - function write_dkim_key($key_file,$key_value,$key_domain) { - global $app,$mailconfig; + global $app,$conf; + $initfile=$conf['init_scripts'].'/amavis'; + $app->log('Reloading amavis.',LOGLEVEL_DEBUG); + exec(escapeshellarg($conf['init_scripts']).escapeshellarg('/amavis').' reload',$output); + foreach($output as $logline) $app->log($logline,LOGLEVEL_DEBUG); + } + + /* + This function writes the keyfiles (public and private) + */ + function write_dkim_key($key_file,$key_value,$key_domain) { + global $app,$mailconfig; $success=false; if (!file_put_contents($key_file.'.private',$key_value) === false) { - $app->log('Saved DKIM Private-key to '.$key_file.'.private',LOGLEVEL_DEBUG); - $success=true; - /* now we get the DKIM Public-key */ - exec('cat '.escapeshellarg($key_file.'.private').'|openssl rsa -pubout',$pubkey,$result); - $public_key=''; - foreach($pubkey as $values) $public_key=$public_key.$values."\n"; - /* save the DKIM Public-key in dkim-dir */ - if (!file_put_contents($key_file.'.public',$public_key) === false) - $app->log('Saved DKIM Public to '.$key_domain.'.',LOGLEVEL_DEBUG); - else $app->log('Unable to save DKIM Public to '.$key_domain.'.',LOGLEVEL_WARNING); - } - return $success; - } + $app->log('Saved DKIM Private-key to '.$key_file.'.private',LOGLEVEL_DEBUG); + $success=true; + /* now we get the DKIM Public-key */ + exec('cat '.escapeshellarg($key_file.'.private').'|openssl rsa -pubout',$pubkey,$result); + $public_key=''; + foreach($pubkey as $values) $public_key=$public_key.$values."\n"; + /* save the DKIM Public-key in dkim-dir */ + if (!file_put_contents($key_file.'.public',$public_key) === false) + $app->log('Saved DKIM Public to '.$key_domain.'.',LOGLEVEL_DEBUG); + else $app->log('Unable to save DKIM Public to '.$key_domain.'.',LOGLEVEL_WARNING); + } + return $success; + } /* This function removes the keyfiles */ - function remove_dkim_key($key_file,$key_domain) { - global $app; - if (file_exists($key_file.'.private')) { - exec('rm -f '.escapeshellarg($key_file.'.private')); - $app->log('Deleted the DKIM Private-key for '.$key_domain.'.',LOGLEVEL_DEBUG); - } else $app->log('Unable to delete the DKIM Private-key for '.$key_domain.' (not found).',LOGLEVEL_DEBUG); - if (file_exists($key_file.'.public')) { - exec('rm -f '.escapeshellarg($key_file.'.public')); - $app->log('Deleted the DKIM Public-key for '.$key_domain.'.',LOGLEVEL_DEBUG); - } else $app->log('Unable to delete the DKIM Public-key for '.$key_domain.' (not found).',LOGLEVEL_DEBUG); - } + function remove_dkim_key($key_file,$key_domain) { + global $app; + if (file_exists($key_file.'.private')) { + exec('rm -f '.escapeshellarg($key_file.'.private')); + $app->log('Deleted the DKIM Private-key for '.$key_domain.'.',LOGLEVEL_DEBUG); + } else $app->log('Unable to delete the DKIM Private-key for '.$key_domain.' (not found).',LOGLEVEL_DEBUG); + if (file_exists($key_file.'.public')) { + exec('rm -f '.escapeshellarg($key_file.'.public')); + $app->log('Deleted the DKIM Public-key for '.$key_domain.'.',LOGLEVEL_DEBUG); + } else $app->log('Unable to delete the DKIM Public-key for '.$key_domain.' (not found).',LOGLEVEL_DEBUG); + } /* This function adds the entry to the amavisd-config @@ -201,13 +201,13 @@ class mail_plugin_dkim { $mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail'); if ( substr($mail_config['dkim_path'],strlen($mail_config['dkim_path'])-1) == '/' ) $mail_config['dkim_path'] = substr($mail_config['dkim_path'],0,strlen($mail_config['dkim_path'])-1); - if ($this->write_dkim_key($mail_config['dkim_path']."/".$data['new']['domain'],$data['new']['dkim_private'],$data['new']['domain'])) { - $this->add_to_amavis($data['new']['domain']); - } else { - $app->log('Error saving the DKIM Private-key for '.$data['new']['domain'].' - DKIM is not enabled for the domain.',LOGLEVEL_ERROR); - } - } - + if ($this->write_dkim_key($mail_config['dkim_path']."/".$data['new']['domain'],$data['new']['dkim_private'],$data['new']['domain'])) { + $this->add_to_amavis($data['new']['domain']); + } else { + $app->log('Error saving the DKIM Private-key for '.$data['new']['domain'].' - DKIM is not enabled for the domain.',LOGLEVEL_ERROR); + } + } + /* This function controlls the removement of keyfiles (public and private) and the entry in the amavisd-config @@ -227,12 +227,12 @@ class mail_plugin_dkim { function domain_dkim_delete($event_name,$data) { if (isset($data['old']['dkim']) && $data['old']['dkim'] == 'y') $this->remove_dkim($data['old']); } - - function domain_dkim_insert($event_name,$data) { - if (isset($data['new']['dkim']) && $data['new']['dkim']=='y' && $this->check_system($data)) { - $this->add_dkim($data); - } - } + + function domain_dkim_insert($event_name,$data) { + if (isset($data['new']['dkim']) && $data['new']['dkim']=='y' && $this->check_system($data)) { + $this->add_dkim($data); + } + } function domain_dkim_update($event_name,$data) { global $app; -- GitLab