Skip to content

Commit b4275af

Browse files
committed
Mark that the zone is managed, thus dkim can be auto added
1 parent 7b4d443 commit b4275af

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

interface/web/mail/lib/lang/en_mail_domain.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ $wb['no_policy'] = '- not enabled -';
2020
$wb['error_not_allowed_server_id'] = 'Chosen server is not allowed for this account.';
2121
$wb['dkim_selector_txt'] = 'DKIM-Selector';
2222
$wb['dkim_selector_error'] = 'Invalid DKIM-Selector. Use only lower-case alphanumeric characters (a-z or 0-9) up to 63 chars';
23+
$wb['dkim_auto_dns_txt'] = 'Managed zone, dns updated automatically';
2324
$wb['relayhost_txt'] = 'Relayhost';
2425
$wb['relayhost_user_txt'] = 'Relayhost User';
2526
$wb['relayhost_password_txt'] = 'Relayhost Password';

interface/web/mail/mail_domain_edit.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ function onShowEnd() {
259259
$app->tpl->setVar('dkim_public', $rec['dkim_public'], true);
260260
if (!empty($rec['dkim_public'])) $app->tpl->setVar('dns_record', $dns_record, true);
261261

262+
if($this->id > 0) {
263+
$soa = $this->find_soa_domain($this->dataRecord['domain']);
264+
if ( !empty($soa) ) {
265+
$app->tpl->setVar('dkim_auto_dns', $app->tform->lng('dkim_auto_dns_txt'), true);
266+
}
267+
}
268+
262269
$csrf_token = $app->auth->csrf_token_get('mail_domain_del');
263270
$app->tpl->setVar('_csrf_id', $csrf_token['csrf_id']);
264271
$app->tpl->setVar('_csrf_key', $csrf_token['csrf_key']);
@@ -372,12 +379,8 @@ function onAfterInsert() {
372379

373380
//* create dns-record with dkim-values if the zone exists
374381
if ( $this->dataRecord['active'] == 'y' && $this->dataRecord['dkim'] == 'y' ) {
375-
$soaDomain = $this->dataRecord['domain'].'.';
376-
while ((!isset($soa) && (substr_count($soaDomain,'.') > 1))) {
377-
$soa = $app->db->queryOneRecord("SELECT id AS zone, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, server_id, ttl, serial FROM dns_soa WHERE active = 'Y' AND origin = ?", $soaDomain);
378-
$soaDomain = preg_replace("/^[^\.]+\./","",$soaDomain);
379-
}
380-
if ( isset($soa) && !empty($soa) ) $this->update_dns($this->dataRecord, $soa);
382+
$soa = $this->find_soa_domain($this->dataRecord['domain']);
383+
if ( !empty($soa) ) $this->update_dns($this->dataRecord, $soa);
381384
}
382385

383386
}
@@ -690,15 +693,11 @@ function onAfterUpdate() {
690693
$selector = @($this->dataRecord['dkim_selector'] != $this->oldDataRecord['dkim_selector']) ? true : false;
691694
$dkim_private = @($this->dataRecord['dkim_private'] != $this->oldDataRecord['dkim_private']) ? true : false;
692695

693-
$soaDomain = $domain.'.';
694-
while ((!isset($soa) && (substr_count($soaDomain,'.') > 1))) {
695-
$soa = $app->db->queryOneRecord("SELECT id AS zone, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, server_id, ttl, serial FROM dns_soa WHERE active = 'Y' AND origin = ?", $soaDomain);
696-
$soaDomain = preg_replace("/^[^\.]+\./","",$soaDomain);
697-
}
696+
$soa = $this->find_soa_domain($this->dataRecord['domain']);
698697

699698
if ( ($selector || $dkim_private || $dkim_active) && $dkim_active )
700699
//* create a new record only if the dns-zone exists
701-
if ( isset($soa) && !empty($soa) ) {
700+
if ( !empty($soa) ) {
702701
$this->update_dns($this->dataRecord, $soa);
703702
}
704703
if (! $dkim_active) {
@@ -718,6 +717,20 @@ function onAfterUpdate() {
718717

719718
}
720719

720+
/**
721+
* Lookup if we host a dns zone for this domain.
722+
*/
723+
private function find_soa_domain($domain) {
724+
global $app;
725+
$soaDomain = $domain . '.';
726+
$soa = null;
727+
while ((!isset($soa) && (substr_count($soaDomain,'.') > 1))) {
728+
$soa = $app->db->queryOneRecord("SELECT id AS zone, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, server_id, ttl, serial FROM dns_soa WHERE active = 'Y' AND origin = ?", $soaDomain);
729+
$soaDomain = preg_replace("/^[^\.]+\./","",$soaDomain);
730+
}
731+
return $soa;
732+
}
733+
721734
private function update_dns($dataRecord, $new_rr) {
722735
global $app, $conf;
723736

interface/web/mail/templates/mail_domain_edit.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
</div>
130130

131131
<div class="form-group">
132-
<label for="dns_record" class="col-sm-3 control-label">{tmpl_var name='dkim_dns_txt'}</label>
132+
<label for="dns_record" class="col-sm-3 control-label">{tmpl_var name='dkim_dns_txt'}<tmpl_if name='dkim_auto_dns'><br />{tmpl_var name='dkim_auto_dns'}</tmpl_if></label>
133133
<div class="col-sm-9"><textarea class="form-control" name="dns_record" id="dns_record" rows='10' cols='30' readonly>{tmpl_var name='dns_record'}</textarea></div>
134134
</div>
135135

0 commit comments

Comments
 (0)