Refactor dns_freemyip.sh for enhanced compatibility (#7166)

* Refactor dns_freemyip.sh for clarity and compatibility

Updated dns_freemyip.sh for better readability and compatibility with ASUSWRT-Merlin. Improved error handling and response logging.

* Update author information in dns_freemyip.sh

* replace both loops with POSIX shell counters

replace both loops with POSIX shell counters

* Typo

Typo

* Fix error message for freemyip API request failure

Remove existing token leak. Not my regression.

* Refactor retry logic and improve error handling

* Remove unnecessary blank lines in dns_freemyip.sh

* Clean up dns_freemyip.sh by removing blank lines

Removed unnecessary blank lines in the script to improve readability.
This commit is contained in:
Joel Samson
2026-08-02 21:34:41 +08:00
committed by GitHub
Unverified
parent 0565443622
commit bf90b845b2
+20 -9
View File
@@ -6,7 +6,7 @@ Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_freemyip
Options: Options:
FREEMYIP_Token API Token FREEMYIP_Token API Token
Issues: github.com/acmesh-official/acme.sh/issues/6247 Issues: github.com/acmesh-official/acme.sh/issues/6247
Author: Recolic Keghart <root@recolic.net>, @Giova96 Author: Recolic Keghart <root@recolic.net>, @Giova96, ExtremeFiretop
' '
FREEMYIP_DNS_API="https://freemyip.com/update?" FREEMYIP_DNS_API="https://freemyip.com/update?"
@@ -68,22 +68,30 @@ dns_freemyip_rm() {
return $? return $?
} }
################ Private functions below ################ ################ Private functions below ################
_get_root() { _get_root() {
_fmi_d="$1" _fmi_d="$1"
echo "$_fmi_d" | rev | cut -d '.' -f 1-3 | rev echo "$_fmi_d" | sed 's/.*\.\([^.]*\.[^.]*\.[^.]*\)$/\1/'
} }
# There is random failure while calling freemyip API too fast. This function automatically retry until success. # There is random failure while calling freemyip API too fast. This function automatically retry until success.
_freemyip_get_until_ok() { _freemyip_get_until_ok() {
_fmi_url="$1" _fmi_url="$1"
for i in $(seq 1 8); do _fmi_i=1
_debug "HTTP GET freemyip.com API '$_fmi_url', retry $i/8..." while [ "$_fmi_i" -le 8 ]; do
_get "$_fmi_url" | tee /dev/fd/2 | grep OK && return 0 _debug "HTTP GET freemyip.com API '$_fmi_url', retry $_fmi_i/8..."
_fmi_response="$(_get "$_fmi_url")"
printf '%s\n' "$_fmi_response" >&2
if _contains "$_fmi_response" "OK"; then
return 0
fi
_sleep 1 # DO NOT send the request too fast _sleep 1 # DO NOT send the request too fast
_fmi_i=$((_fmi_i + 1))
done done
_err "Failed to request freemyip API: $_fmi_url . Server does not say 'OK'" _err "Failed to request freemyip API. Server does not say 'OK'"
return 1 return 1
} }
@@ -93,13 +101,16 @@ _is_root_domain_published() {
_webroot="$(_get_root "$_fmi_d")" _webroot="$(_get_root "$_fmi_d")"
_info "Verifying '""$_fmi_d""' freemyip webroot (""$_webroot"") is not published yet" _info "Verifying '""$_fmi_d""' freemyip webroot (""$_webroot"") is not published yet"
for i in $(seq 1 3); do _fmi_i=1
_debug "'$_webroot' ns lookup, retry $i/3..." while [ "$_fmi_i" -le 3 ]; do
_debug "'$_webroot' ns lookup, retry $_fmi_i/3..."
if [ "$(_ns_lookup "$_fmi_d" TXT)" ]; then if [ "$(_ns_lookup "$_fmi_d" TXT)" ]; then
_debug "'$_webroot' already has a TXT record published!" _debug "'$_webroot' already has a TXT record published!"
return 0 return 0
fi fi
_sleep 10 # Give it some time to propagate the TXT record _sleep 10 # Give it some time to propagate the TXT record
_fmi_i=$((_fmi_i + 1))
done done
return 1 return 1
} }