diff --git a/data/web/inc/functions.dkim.inc.php b/data/web/inc/functions.dkim.inc.php index 46d66d31..2a19ff09 100644 --- a/data/web/inc/functions.dkim.inc.php +++ b/data/web/inc/functions.dkim.inc.php @@ -50,10 +50,10 @@ function dkim($_action, $_data = null, $privkey = false) { if ($keypair_ressource = openssl_pkey_new($config)) { $key_details = openssl_pkey_get_details($keypair_ressource); $pubKey = implode(array_slice( - array_filter( - explode(PHP_EOL, $key_details['key']) - ), 1, -1) - ); + array_filter( + explode(PHP_EOL, $key_details['key']) + ), 1, -1) + ); // Save public key and selector to redis try { $redis->hSet('DKIM_PUB_KEYS', $domain, $pubKey); @@ -150,6 +150,7 @@ function dkim($_action, $_data = null, $privkey = false) { return false; } $private_key_input = trim($_data['private_key_file']); + $overwrite_existing = intval($_data['overwrite_existing']); $private_key_normalized = preg_replace('~\r\n?~', "\n", $private_key_input); $private_key = openssl_pkey_get_private($private_key_normalized); if ($ssl_error = openssl_error_string()) { @@ -178,12 +179,14 @@ function dkim($_action, $_data = null, $privkey = false) { return false; } if ($redis->hGet('DKIM_PUB_KEYS', $domain)) { - $_SESSION['return'][] = array( - 'type' => 'danger', - 'log' => array(__FUNCTION__, $_action, $_data, $privkey), - 'msg' => array('dkim_domain_or_sel_invalid', $domain) - ); - return false; + if ($overwrite_existing == 0) { + $_SESSION['return'][] = array( + 'type' => 'danger', + 'log' => array(__FUNCTION__, $_action, $_data, $privkey), + 'msg' => array('dkim_domain_or_sel_exists', $domain) + ); + return false; + } } if (!ctype_alnum($dkim_selector)) { $_SESSION['return'][] = array( @@ -194,6 +197,7 @@ function dkim($_action, $_data = null, $privkey = false) { return false; } try { + dkim('delete', $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);