bind_add_dkim_zone_master.sh: add support for subdomains.

This commit is contained in:
Christoph 2019-01-08 03:32:51 +01:00
parent cb2698c5f7
commit 37ec179832

View File

@ -10,6 +10,8 @@
# - error:
# - 10: Missing option for zone definition
# - 15: DKIM domain not supported by this nameserver
# - 16: No responsible zone found
# - 17: No Nameserver found
# - 20: Adding Zone definition failed
# - 21: Adding Zonefile failed
# - 22: Change owner for newly created zonefile failed
@ -75,6 +77,9 @@ usage() {
error:
10: Missing option for zone definition
15: DKIM domain not supported by this nameserver
16: No responsible zone found
17: No Nameserver found
20: Add Zone definition failed
21: Adding Zonefile failed
22: Change owner for newly created zonefile failed
@ -347,7 +352,7 @@ fi
if [[ -z "$ALLOW_TRANSFER_OPTION" ]] ; then
error "Missing 'allow-update' option for zone definition .."
clean_up
clean_up 10
else
# - Eliminate trailing ';' characters
# -
@ -364,8 +369,8 @@ SOA_ADMIN_EMAIL="${SOA_ADMIN_EMAIL/@/.}"
zone="_domainkey.$dkim_domain"
zone_file="${ZONE_FILE_MASTER_DIR}/${zone}.${ZONE_FILE_SUFFIX}"
new_dkim_zone="_domainkey.$dkim_domain"
new_zone_file="${ZONE_FILE_MASTER_DIR}/${new_dkim_zone}.${ZONE_FILE_SUFFIX}"
_zone_configuration_exists=false
@ -422,24 +427,45 @@ fi
# - Get DNS server
# -
echononl "Get Namservers for domain '$dkim_domain'"
dns_servers="$(dig +short $dkim_domain NS)"
if [[ -n "$dns_servers" ]]; then
echononl "Get responsible zone for domain '$dkim_domain'.."
found=true
zone="${dkim_domain}"
dns_servers="$(dig +short $zone NS 2>/dev/null)"
while [[ -z "$dns_servers" ]] ; do
zone=${zone#*.}
if [[ ! $zone =~ \. ]]; then
found=false
break
fi
dns_servers="$(dig +short $zone NS 2>/dev/null)"
done
if $found ; then
echo_ok
info "Found responsible zone for '${dkim_domain}': \033[37m\033[1m${zone}\033[m"
echononl "Get nameservers for domain '${zone}'.."
declare -i _count=0
for _dns_server in $dns_servers ; do
if [[ $_count -eq 0 ]]; then
_tmp_dns_server="$_dns_server"
else
_tmp_dns_server="$_tmp_dns_server $_dns_server"
fi
dns_server_arr+=("$_dns_server")
if [[ ${#dns_server_arr[@]} -eq 0 ]]; then
echo_failed
error "Determin DNS servers for domain '$zone' failed!"
clean_up 17
else
echo_ok
info "Found nameservers \033[37m\033[1m${_tmp_dns_server}\033[m"
fi
done
else
echo_failed
error "Determin DNS servers for domain '$dkim_domain' failed!"
error "No responsible zone for '$dkim_domain' found!"
clean_up 16
fi
# - This is needed, because the dns servers are requested above, in
# - an IFS='' environment!
# -
declare -i i=0
for _dns_server in $dns_servers ; do
dns_server_arr+=("$_dns_server")
done
if ! $_zone_configuration_exists ; then
@ -461,9 +487,9 @@ if ! $_zone_configuration_exists ; then
echononl "Add zone definition to '$ZONES_DECLARATION_FILE' .."
cat <<EOF >> $ZONES_DECLARATION_FILE 2> $log_file
zone "${zone}" {
zone "${new_dkim_zone}" {
type master;
file "${zone_file}";
file "${new_zone_file}";
allow-update { key ${TSIG_KEY_NAME}. ; };
allow-transfer {$ALLOW_TRANSFER_OPTION};
};
@ -483,7 +509,7 @@ fi
# -
echononl "Add zone definition to '$ZONES_DECLARATION_FILE' .."
_failed=false
cat <<EOF > "${zone_file}" 2> $log_file
cat <<EOF > "${new_zone_file}" 2> $log_file
\$TTL 43200
@ IN SOA ${SOA_PRIMARY_MASTER}. ${SOA_ADMIN_EMAIL}. (
0 ; serial
@ -496,7 +522,7 @@ EOF
if [[ $? -eq 0 ]]; then
for _dns_server in ${dns_server_arr[@]} ; do
echo "@ IN NS $_dns_server" >> "${zone_file}" 2> $log_file
echo "@ IN NS $_dns_server" >> "${new_zone_file}" 2> $log_file
if [[ $? -ne 0 ]] ; then
_failed=true
fi
@ -518,7 +544,7 @@ fi
# - Change owner for newly created zone file
# -
echononl "Change owner for newly created zone file.."
chown ${BIND_USER}:$BIND_GROUP "${ZONE_FILE_MASTER_DIR}/${zone}.zone" > $log_file 2>&1
chown ${BIND_USER}:$BIND_GROUP "${new_zone_file}" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else