]> git.proxmox.com Git - mirror_acme.sh.git/commitdiff
Check for root domain via API
authorRolph Haspers <r.haspers@global.leaseweb.com>
Fri, 25 Oct 2019 07:25:29 +0000 (09:25 +0200)
committerRolph Haspers <r.haspers@global.leaseweb.com>
Fri, 25 Oct 2019 07:25:29 +0000 (09:25 +0200)
dnsapi/dns_leaseweb.sh

index 976ad5acb4de549f8bec81b906ccbebbf29090d1..6a75ef33e9ed85120577ebee58a351f92c4f84c1 100644 (file)
@@ -88,14 +88,24 @@ _get_root() {
   i=$(_math "$i" - 1)
 
   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
+      return 1 #not valid domain
+    fi
+
+    #Check API if domain exists
+    if _lsw_api "GET" "$h"; then
+      if [ "$_code" = "200"]; then
+        _domain="$h"
+        return 0
+      fi
+    fi
+    i=$(_math "$i" - 1)
+    if (( $i < 1)); then
+      return 1 #not found
     fi
-    _domain="$h"
-    return 0
   done
-  _debug "$domain not found"
+
   return 1
 }
 
@@ -109,6 +119,14 @@ _lsw_api() {
   export _H2="Content-Type: application/json"
   export _H1="X-Lsw-Auth: ${LSW_Key}"
 
+  if [ "$cmd" = "GET" ]; then
+    response="$(_get "$LSW_API/$domain")"
+    _code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")"
+    _debug "http response code $_code"
+    _debug response "$response"
+    return 0
+  fi
+
   if [ "$cmd" = "POST" ]; then
     data="{\"name\": \"$fulldomain.\",\"type\": \"TXT\",\"content\": [\"$txtvalue\"],\"ttl\": 60}"
     response="$(_post "$data" "$LSW_API/$domain/resourceRecordSets" "$data" "POST")"