From 7ae7f25580dbab0e49ff0d208ba876be1485d468 Mon Sep 17 00:00:00 2001 From: andryyy Date: Sat, 11 Jun 2022 11:42:11 +0200 Subject: [PATCH] [Web] Re-use DKIM key if available --- data/web/inc/functions.dkim.inc.php | 2 +- data/web/inc/functions.mailbox.inc.php | 22 ++++++++++++++++++++-- data/web/lang/lang.de.json | 1 + data/web/lang/lang.en.json | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/data/web/inc/functions.dkim.inc.php b/data/web/inc/functions.dkim.inc.php index 85d3c6c1..29b32d5d 100644 --- a/data/web/inc/functions.dkim.inc.php +++ b/data/web/inc/functions.dkim.inc.php @@ -197,7 +197,7 @@ function dkim($_action, $_data = null, $privkey = false) { return false; } try { - dkim('delete', (array)$domain); + dkim('delete', array('domains' => $domain)); $redis->hSet('DKIM_PUB_KEYS', $domain, $pem_public_key); $redis->hSet('DKIM_SELECTORS', $domain, $dkim_selector); $redis->hSet('DKIM_PRIV_KEYS', $dkim_selector . '.' . $domain, $private_key_normalized); diff --git a/data/web/inc/functions.mailbox.inc.php b/data/web/inc/functions.mailbox.inc.php index 623f6c38..7f8ff3ac 100644 --- a/data/web/inc/functions.mailbox.inc.php +++ b/data/web/inc/functions.mailbox.inc.php @@ -599,7 +599,16 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) { ratelimit('edit', 'domain', array('rl_value' => $_data['rl_value'], 'rl_frame' => $_data['rl_frame'], 'object' => $domain)); } if (!empty($_data['key_size']) && !empty($_data['dkim_selector'])) { - dkim('add', array('key_size' => $_data['key_size'], 'dkim_selector' => $_data['dkim_selector'], 'domains' => $domain)); + if (!empty($redis->hGet('DKIM_SELECTORS', $domain))) { + $_SESSION['return'][] = array( + 'type' => 'success', + 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr), + 'msg' => 'domain_add_dkim_available' + ); + } + else { + dkim('add', array('key_size' => $_data['key_size'], 'dkim_selector' => $_data['dkim_selector'], 'domains' => $domain)); + } } if (!empty($restart_sogo)) { $restart_response = json_decode(docker('post', 'sogo-mailcow', 'restart'), true); @@ -929,7 +938,16 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) { ratelimit('edit', 'domain', array('rl_value' => $_data['rl_value'], 'rl_frame' => $_data['rl_frame'], 'object' => $alias_domain)); } if (!empty($_data['key_size']) && !empty($_data['dkim_selector'])) { - dkim('add', array('key_size' => $_data['key_size'], 'dkim_selector' => $_data['dkim_selector'], 'domains' => $alias_domain)); + if (!empty($redis->hGet('DKIM_SELECTORS', $alias_domain))) { + $_SESSION['return'][] = array( + 'type' => 'success', + 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr), + 'msg' => 'domain_add_dkim_available' + ); + } + else { + dkim('add', array('key_size' => $_data['key_size'], 'dkim_selector' => $_data['dkim_selector'], 'domains' => $alias_domain)); + } } $_SESSION['return'][] = array( 'type' => 'success', diff --git a/data/web/lang/lang.de.json b/data/web/lang/lang.de.json index 44dc8285..7167290f 100644 --- a/data/web/lang/lang.de.json +++ b/data/web/lang/lang.de.json @@ -921,6 +921,7 @@ "deleted_syncjob": "Sync-Jobs-ID %s gelöscht", "deleted_syncjobs": "Sync-Jobs gelöscht: %s", "dkim_added": "DKIM-Key %s wurde hinzugefügt", + "domain_add_dkim_available": "Ein DKIM-Key existierte bereits", "dkim_duplicated": "DKIM-Key der Domain %s wurde auf Domain %s kopiert", "dkim_removed": "DKIM-Key %s wurde entfernt", "domain_added": "Domain %s wurde angelegt", diff --git a/data/web/lang/lang.en.json b/data/web/lang/lang.en.json index 8445641f..0a384071 100644 --- a/data/web/lang/lang.en.json +++ b/data/web/lang/lang.en.json @@ -928,6 +928,7 @@ "deleted_syncjob": "Deleted syncjob ID %s", "deleted_syncjobs": "Deleted syncjobs: %s", "dkim_added": "DKIM key %s has been saved", + "domain_add_dkim_available": "A DKIM key did already exist", "dkim_duplicated": "DKIM key for domain %s has been copied to %s", "dkim_removed": "DKIM key %s has been removed", "domain_added": "Added domain %s",