ddns-scripts-cloudflare: allow explicit zone_id

When zone id is explicitly provided, there is no need for the API token to have read permission. Inspired by acme.sh's cloudflare logic.

Signed-off-by: Glen Huang <heyhgl@gmail.com>
This commit is contained in:
Glen Huang 2022-01-09 13:02:58 +08:00
parent e7547d980d
commit 78ef7d7379
2 changed files with 15 additions and 11 deletions

View file

@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=ddns-scripts PKG_NAME:=ddns-scripts
PKG_VERSION:=2.8.2 PKG_VERSION:=2.8.2
PKG_RELEASE:=20 PKG_RELEASE:=21
PKG_LICENSE:=GPL-2.0 PKG_LICENSE:=GPL-2.0

View file

@ -134,6 +134,9 @@ else
fi fi
__PRGBASE="$__PRGBASE --header 'Content-Type: application/json' " __PRGBASE="$__PRGBASE --header 'Content-Type: application/json' "
if [ -n "$zone_id"]; then
__ZONEID="$zone_id"
else
# read zone id for registered domain.TLD # read zone id for registered domain.TLD
__RUNPROG="$__PRGBASE --request GET '$__URLBASE/zones?name=$__DOMAIN'" __RUNPROG="$__PRGBASE --request GET '$__URLBASE/zones?name=$__DOMAIN'"
cloudflare_transfer || return 1 cloudflare_transfer || return 1
@ -143,6 +146,7 @@ __ZONEID=$(grep -o '"id":\s*"[^"]*' $DATFILE | grep -o '[^"]*$' | head -1)
write_log 4 "Could not detect 'zone id' for domain.tld: '$__DOMAIN'" write_log 4 "Could not detect 'zone id' for domain.tld: '$__DOMAIN'"
return 127 return 127
} }
fi
# read record id for A or AAAA record of host.domain.TLD # read record id for A or AAAA record of host.domain.TLD
__RUNPROG="$__PRGBASE --request GET '$__URLBASE/zones/$__ZONEID/dns_records?name=$__HOST&type=$__TYPE'" __RUNPROG="$__PRGBASE --request GET '$__URLBASE/zones/$__ZONEID/dns_records?name=$__HOST&type=$__TYPE'"