/g' | tr '@' '\n' | grep edit.php | grep "$top_domain")"
- _debug2 subdomain_csv "$subdomain_csv"
-
- # The above beauty ends with striping out rows that do not have an
- # href to edit.php and do not have the top domain we are looking for.
- # So all we should be left with is CSV of table of subdomains we are
- # interested in.
-
- # Now we have to read through this table and extract the data we need
- lines="$(echo "$subdomain_csv" | wc -l)"
- i=0
- found=0
- while [ "$i" -lt "$lines" ]; do
- i="$(_math "$i" + 1)"
- line="$(echo "$subdomain_csv" | sed -n "${i}p")"
- _debug2 line "$line"
- if [ $found = 0 ] && _contains "$line" "$top_domain | "; then
- # this line will contain DNSdomainid for the top_domain
- DNSdomainid="$(echo "$line" | _egrep_o "edit_domain_id *= *.*>" | cut -d = -f 2 | cut -d '>' -f 1)"
- _debug2 DNSdomainid "$DNSdomainid"
- found=1
- else
- # lines contain DNS records for all subdomains
- DNSname="$(echo "$line" | _egrep_o 'edit.php.*' | cut -d '>' -f 2 | cut -d '<' -f 1)"
- _debug2 DNSname "$DNSname"
- DNStype="$(echo "$line" | sed 's/' -f 2 | cut -d '<' -f 1)"
- _debug2 DNStype "$DNStype"
- if [ "$DNSname" = "$fulldomain" ] && [ "$DNStype" = "TXT" ]; then
- DNSdataid="$(echo "$line" | _egrep_o 'data_id=.*' | cut -d = -f 2 | cut -d '>' -f 1)"
- # Now get current value for the TXT record. This method may
- # not produce accurate results as the value field is truncated
- # on this webpage. To get full value we would need to load
- # another page. However we don't really need this so long as
- # there is only one TXT record for the acme challenge subdomain.
- DNSvalue="$(echo "$line" | sed 's/ | ' -f 2 | cut -d '<' -f 1)"
- _debug2 DNSvalue "$DNSvalue"
- if [ $found != 0 ]; then
- break
- # we are breaking out of the loop at the first match of DNS name
- # and DNS type (if we are past finding the domainid). This assumes
- # that there is only ever one TXT record for the LetsEncrypt/acme
- # challenge subdomain. This seems to be a reasonable assumption
- # as the acme client deletes the TXT record on successful validation.
- fi
- else
- DNSname=""
- DNStype=""
- fi
- fi
- done
-
- _debug "DNSname: $DNSname DNStype: $DNStype DNSdomainid: $DNSdomainid DNSdataid: $DNSdataid"
- _debug "DNSvalue: $DNSvalue"
-
- if [ -z "$DNSdomainid" ]; then
- # If domain ID is empty then something went wrong (top level
- # domain not found at FreeDNS).
- if [ "$attempts" = "0" ]; then
- # exhausted maximum retry attempts
- _debug "$htmlpage"
- _debug "$subdomain_csv"
- _err "Domain $top_domain not found at FreeDNS"
- return 1
- fi
- else
- # break out of the 'retry' loop... we have found our domain ID
+ # We may have to cycle through the domain name to find the
+ # TLD that we own...
+ i=1
+ wmax="$(echo "$fulldomain" | tr '.' ' ' | wc -w)"
+ while [ "$i" -lt "$wmax" ]; do
+ # split our full domain name into two parts...
+ sub_domain="$(echo "$fulldomain" | cut -d. -f -"$i")"
+ i="$(_math "$i" + 1)"
+ top_domain="$(echo "$fulldomain" | cut -d. -f "$i"-100)"
+ _debug "sub_domain: $sub_domain"
+ _debug "top_domain: $top_domain"
+
+ DNSdomainid="$(_freedns_domain_id "$top_domain")"
+ if [ "$?" = "0" ]; then
+ _info "Domain $top_domain found at FreeDNS, domain_id $DNSdomainid"
break
+ else
+ _info "Domain $top_domain not found at FreeDNS, try with next level of TLD"
fi
- _info "Domain $top_domain not found at FreeDNS"
- _info "Retry loading subdomain page ($attempts attempts remaining)"
done
- if [ -z "$DNSdataid" ]; then
- # If data ID is empty then specific subdomain does not exist yet, need
- # to create it this should always be the case as the acme client
- # deletes the entry after domain is validated.
- _freedns_add_txt_record "$FREEDNS_COOKIE" "$DNSdomainid" "$sub_domain" "$txtvalue"
- return $?
- else
- if [ "$txtvalue" = "$DNSvalue" ]; then
- # if value in TXT record matches value requested then DNS record
- # does not need to be updated. But...
- # Testing value match fails. Website is truncating the value field.
- # So for now we will always go down the else path. Though in theory
- # should never come here anyway as the acme client deletes
- # the TXT record on successful validation, so we should not even
- # have found a TXT record !!
- _info "No update necessary for $fulldomain at FreeDNS"
- return 0
- else
- # Delete the old TXT record (with the wrong value)
- if _freedns_delete_txt_record "$FREEDNS_COOKIE" "$DNSdataid"; then
- # And add in new TXT record with the value provided
- _freedns_add_txt_record "$FREEDNS_COOKIE" "$DNSdomainid" "$sub_domain" "$txtvalue"
- fi
- return $?
- fi
+ if [ -z "$DNSdomainid" ]; then
+ # If domain ID is empty then something went wrong (top level
+ # domain not found at FreeDNS).
+ _err "Domain $top_domain not found at FreeDNS"
+ return 1
fi
- return 0
+
+ # Add in new TXT record with the value provided
+ _debug "Adding TXT record for $fulldomain, $txtvalue"
+ _freedns_add_txt_record "$FREEDNS_COOKIE" "$DNSdomainid" "$sub_domain" "$txtvalue"
+ return $?
}
#Usage: fulldomain txtvalue
@@ -186,65 +93,48 @@ dns_freedns_rm() {
# Need to read cookie from conf file again in case new value set
# during login to FreeDNS when TXT record was created.
- # acme.sh does not have a _readaccountconf() function
- FREEDNS_COOKIE="$(_read_conf "$ACCOUNT_CONF_PATH" "FREEDNS_COOKIE")"
+ FREEDNS_COOKIE="$(_readaccountconf "FREEDNS_COOKIE")"
_debug "FreeDNS login cookies: $FREEDNS_COOKIE"
- # Sometimes FreeDNS does not return the subdomain page but rather
- # returns a page regarding becoming a premium member. This usually
- # happens after a period of inactivity. Immediately trying again
- # returns the correct subdomain page. So, we will try twice to
- # load the page and obtain our TXT record.
- attempts=2
- while [ "$attempts" -gt "0" ]; do
- attempts="$(_math "$attempts" - 1)"
-
- htmlpage="$(_freedns_retrieve_subdomain_page "$FREEDNS_COOKIE")"
+ TXTdataid="$(_freedns_data_id "$fulldomain" "TXT")"
+ if [ "$?" != "0" ]; then
+ _info "Cannot delete TXT record for $fulldomain, record does not exist at FreeDNS"
+ return 1
+ fi
+ _debug "Data ID's found, $TXTdataid"
+
+ # now we have one (or more) TXT record data ID's. Load the page
+ # for that record and search for the record txt value. If match
+ # then we can delete it.
+ lines="$(echo "$TXTdataid" | wc -l)"
+ _debug "Found $lines TXT data records for $fulldomain"
+ i=0
+ while [ "$i" -lt "$lines" ]; do
+ i="$(_math "$i" + 1)"
+ dataid="$(echo "$TXTdataid" | sed -n "${i}p")"
+ _debug "$dataid"
+
+ htmlpage="$(_freedns_retrieve_data_page "$FREEDNS_COOKIE" "$dataid")"
if [ "$?" != "0" ]; then
+ if [ "$using_cached_cookies" = "true" ]; then
+ _err "Has your FreeDNS username and password changed? If so..."
+ _err "Please export as FREEDNS_User / FREEDNS_Password and try again."
+ fi
return 1
fi
- subdomain_csv="$(echo "$htmlpage" | tr -d "\n\r" | _egrep_o ' |