1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2024-12-04 10:24:42 +02:00

[Web] Add DKIM key when adding a domain or alias domain (#4254)

Signed-off-by: Kristian Feldsam <feldsam@gmail.com>
This commit is contained in:
Kristian Feldsam 2021-09-01 16:51:10 +02:00 committed by GitHub
parent 54c4d7e49c
commit c1dcb529f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 8 deletions

View File

@ -5,14 +5,6 @@ function dkim($_action, $_data = null, $privkey = false) {
global $lang;
switch ($_action) {
case 'add':
if ($_SESSION['mailcow_cc_role'] != "admin") {
$_SESSION['return'][] = array(
'type' => 'danger',
'log' => array(__FUNCTION__, $_action, $_data, ),
'msg' => 'access_denied'
);
return false;
}
$key_length = intval($_data['key_size']);
$dkim_selector = (isset($_data['dkim_selector'])) ? $_data['dkim_selector'] : 'dkim';
$domains = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['domains']));
@ -42,6 +34,14 @@ function dkim($_action, $_data = null, $privkey = false) {
);
continue;
}
if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) {
$_SESSION['return'][] = array(
'type' => 'danger',
'log' => array(__FUNCTION__, $_action, $_data),
'msg' => array('access_denied', $domain)
);
continue;
}
$config = array(
"digest_alg" => "sha256",
"private_key_bits" => $key_length,

View File

@ -579,6 +579,9 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
if (!empty(intval($_data['rl_value']))) {
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($restart_sogo)) {
$restart_response = json_decode(docker('post', 'sogo-mailcow', 'restart'), true);
if ($restart_response['type'] == "success") {
@ -906,6 +909,9 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
if (!empty(intval($_data['rl_value']))) {
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));
}
$_SESSION['return'][] = array(
'type' => 'success',
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),

View File

@ -165,6 +165,22 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
</div>
</div>
<hr>
<div class="form-group">
<label class="control-label col-sm-2" for="dkim_selector"><?=$lang['admin']['dkim_domains_selector'];?></label>
<div class="col-sm-10">
<input class="form-control" id="dkim_selector" name="dkim_selector" value="dkim">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="key_size"><?=$lang['admin']['dkim_key_length'];?></label>
<div class="col-sm-10">
<select data-style="btn btn-default btn-sm" class="form-control" id="key_size" name="key_size">
<option data-subtext="bits">1024</option>
<option data-subtext="bits">2048</option>
</select>
</div>
</div>
<hr>
<div class="form-group">
<label class="control-label col-sm-2"><?=$lang['add']['backup_mx_options'];?></label>
<div class="col-sm-10">
@ -381,6 +397,23 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
</select>
</div>
</div>
<hr>
<div class="form-group">
<label class="control-label col-sm-2" for="dkim_selector"><?=$lang['admin']['dkim_domains_selector'];?></label>
<div class="col-sm-10">
<input class="form-control" id="dkim_selector" name="dkim_selector" value="dkim">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="key_size"><?=$lang['admin']['dkim_key_length'];?></label>
<div class="col-sm-10">
<select data-style="btn btn-default btn-sm" class="form-control" id="key_size" name="key_size">
<option data-subtext="bits">1024</option>
<option data-subtext="bits">2048</option>
</select>
</div>
</div>
<hr>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-xs-lg visible-xs-block visible-sm-inline visible-md-inline visible-lg-inline btn-success" data-action="add_item" data-id="add_alias_domain" data-api-url='add/alias-domain' data-api-attr='{}' href="#"><?=$lang['admin']['add'];?></button>