This commit is contained in:
Matt Groves 2024-04-01 23:26:09 +08:00 committed by GitHub
commit 97173daddf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -144,30 +144,45 @@ _namecom_login() {
} }
_namecom_get_root() { _namecom_get_root() {
domain=$1 full_domain=$1
i=2
p=1
if ! _namecom_rest GET "domains"; then # Strip the subdomain from the full domain
return 1 domain=$(echo "$full_domain" | sed 's/.*\.\([^.]*\.[^.]*\)$/\1/')
fi
# Need to exclude the last field (tld) # Initialize variables for pagination
numfields=$(echo "$domain" | _egrep_o "\." | wc -l) _page=1
while [ $i -le "$numfields" ]; do
host=$(printf "%s" "$domain" | cut -d . -f $i-100) while true; do
_debug host "$host" if ! _namecom_rest GET "domains?page=$_page&perPage=1000"; then
if [ -z "$host" ]; then _debug "Error: Failed to retrieve domains from API"
return 1 return 1
fi fi
if _contains "$response" "$host"; then _debug "Response for $full_domain: $response"
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
_domain="$host" # Check if the domain is found in the current page
if echo "$response" | grep -q "\"domainName\":\"$domain\""; then
_debug "Domain $domain found in the response"
# Extract the subdomain from the full domain
_sub_domain=$(echo "$full_domain" | sed "s/\.$domain$//")
_domain=$domain
_debug "Subdomain for $full_domain: $_sub_domain"
_debug "Domain: $_domain"
return 0 return 0
else
_debug "Domain $domain not found in the current page"
fi
# Check if there are more pages
if echo "$response" | grep -q '"nextPage":'; then
_page=$(_math "$_page" + 1)
_debug "Moving to the next page $_page for domain $full_domain"
else
_debug "No more pages to search for domain $full_domain"
break
fi fi
p=$i
i=$(_math "$i" + 1)
done done
_debug "Domain $domain not found in any page"
return 1 return 1
} }