Browse Source

knot plugin: find responsible DNS zone by SOA queries

pull/3708/head
Nils Wisiol 3 years ago
parent
commit
1a1eb66150
  1. 29
      dnsapi/dns_knot.sh

29
dnsapi/dns_knot.sh

@ -71,20 +71,31 @@ EOF
# returns
# _domain=domain.com
_get_root() {
domain=$1
i="$(echo "$fulldomain" | tr '.' ' ' | wc -w)"
i=$(_math "$i" - 1)
ancestor="${1}."
while true; do
h=$(printf "%s" "$domain" | cut -d . -f "$i"-100)
if [ -z "$h" ]; then
while true; do # loops over all ancestors of $1
# count labels
num_labels="$(echo "$ancestor" | tr '.' ' ' | wc -w)"
# abort if empty
if [ "$num_labels" -eq "0" ]; then
# error: could not find SOA record anywhere
_debug "no SOA record found in any ancestor of $1"
return 1
fi
_domain="$h"
# query for SOA at current ancestor
if [ -n "$(dig SOA +short "${ancestor}")" ]; then
# found SOA record
_info "found SOA at $ancestor"
_domain="${ancestor%?}"
return 0
fi
# cut one label from the left
ancestor=$(printf "%s" "${ancestor}" | cut -d . -f 2-)
done
_debug "$domain not found"
return 1
}
_checkKey() {

Loading…
Cancel
Save