Browse Source

dns_pdns.sh: Allow "." as root zone

Rafael Gieschke 7 years ago
parent
commit
4ae108009c
1 changed files with 10 additions and 7 deletions
  1. 10 7
      dnsapi/dns_pdns.sh

+ 10 - 7
dnsapi/dns_pdns.sh

@@ -90,7 +90,7 @@ set_record() {
   full=$2
   full=$2
   txtvalue=$3
   txtvalue=$3
 
 
-  if ! _pdns_rest "PATCH" "/api/v1/servers/$PDNS_ServerId/zones/$root." "{\"rrsets\": [{\"changetype\": \"REPLACE\", \"name\": \"$full.\", \"type\": \"TXT\", \"ttl\": $PDNS_Ttl, \"records\": [{\"name\": \"$full.\", \"type\": \"TXT\", \"content\": \"\\\"$txtvalue\\\"\", \"disabled\": false, \"ttl\": $PDNS_Ttl}]}]}"; then
+  if ! _pdns_rest "PATCH" "/api/v1/servers/$PDNS_ServerId/zones/$root" "{\"rrsets\": [{\"changetype\": \"REPLACE\", \"name\": \"$full.\", \"type\": \"TXT\", \"ttl\": $PDNS_Ttl, \"records\": [{\"name\": \"$full.\", \"type\": \"TXT\", \"content\": \"\\\"$txtvalue\\\"\", \"disabled\": false, \"ttl\": $PDNS_Ttl}]}]}"; then
     _err "Set txt record error."
     _err "Set txt record error."
     return 1
     return 1
   fi
   fi
@@ -107,7 +107,7 @@ rm_record() {
   root=$1
   root=$1
   full=$2
   full=$2
 
 
-  if ! _pdns_rest "PATCH" "/api/v1/servers/$PDNS_ServerId/zones/$root." "{\"rrsets\": [{\"changetype\": \"DELETE\", \"name\": \"$full.\", \"type\": \"TXT\"}]}"; then
+  if ! _pdns_rest "PATCH" "/api/v1/servers/$PDNS_ServerId/zones/$root" "{\"rrsets\": [{\"changetype\": \"DELETE\", \"name\": \"$full.\", \"type\": \"TXT\"}]}"; then
     _err "Delete txt record error."
     _err "Delete txt record error."
     return 1
     return 1
   fi
   fi
@@ -122,7 +122,7 @@ rm_record() {
 notify_slaves() {
 notify_slaves() {
   root=$1
   root=$1
 
 
-  if ! _pdns_rest "PUT" "/api/v1/servers/$PDNS_ServerId/zones/$root./notify"; then
+  if ! _pdns_rest "PUT" "/api/v1/servers/$PDNS_ServerId/zones/$root/notify"; then
     _err "Notify slaves error."
     _err "Notify slaves error."
     return 1
     return 1
   fi
   fi
@@ -144,15 +144,18 @@ _get_root() {
 
 
   while true; do
   while true; do
     h=$(printf "%s" "$domain" | cut -d . -f $i-100)
     h=$(printf "%s" "$domain" | cut -d . -f $i-100)
-    if [ -z "$h" ]; then
-      return 1
-    fi
 
 
     if _contains "$_zones_response" "\"name\": \"$h.\""; then
     if _contains "$_zones_response" "\"name\": \"$h.\""; then
-      _domain="$h"
+      _domain="$h."
+      if [ -z "$h" ]; then
+        _domain="=2E"
+      fi
       return 0
       return 0
     fi
     fi
 
 
+    if [ -z "$h" ]; then
+      return 1
+    fi
     i=$(_math $i + 1)
     i=$(_math $i + 1)
   done
   done
   _debug "$domain not found"
   _debug "$domain not found"