Skip to content

Commit 151ad39

Browse files
author
Kristan Kenney
committed
Ensure DKIM records are not lost when changing DNS template
If the server also hosts mail for the domain, ensure that DKIM records are not lost when changing between default/child-ns templates.
1 parent 3001220 commit 151ad39

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

bin/v-change-dns-domain-tpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ echo "$template_data" |\
9595
-e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf
9696
records="$(wc -l $USER_DATA/dns/$domain.conf |cut -f 1 -d ' ')"
9797

98+
# Refresh DKIM records in DNS if signing key exists for domain
99+
if [ "$template" = "default" ] || [ "$template" = "child-ns" ]; then
100+
if [ ! -z "MAIL_SYSTEM" ] && [ -f $HOMEDIR/$user/conf/mail/$domain/dkim.pem ]; then
101+
check_dns_domain=$(is_object_valid 'dns' 'DOMAIN' "$domain")
102+
if [ "$?" -eq 0 ]; then
103+
p=$(cat $USER_DATA/mail/$domain.pub|grep -v ' KEY---'|tr -d '\n')
104+
record='_domainkey'
105+
policy="\"t=y; o=~;\""
106+
$BIN/v-add-dns-record $user $domain $record TXT "$policy" '' '' 'no'
107+
108+
record='mail._domainkey'
109+
selector="\"v=DKIM1\; k=rsa\; p=$p\""
110+
$BIN/v-add-dns-record $user $domain $record TXT "$selector"
111+
fi
112+
fi
113+
fi
114+
98115
# Updating zone
99116
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
100117
update_domain_serial

0 commit comments

Comments
 (0)