mirror of
https://github.com/openwrt/packages.git
synced 2025-12-18 08:31:19 +00:00
ddns-scripts: cloudflare: use PATCH method, minimize changes
Using the PUT method recreates the DNS record with and only with the newly provided data. This seems unnecessary. In particular, we don't need to hardcode a TTL of 120. Any existing comment would be lost too. The only detail we need to change is the IP address. Leave everything else as it was. Signed-off-by: Gedalya Nie <gedalya@gedalya.net>
This commit is contained in:
committed by
Florian Eckert
parent
35eb372aa5
commit
0a98b6d0ed
@@ -27,9 +27,8 @@
|
||||
[ $use_https -eq 0 ] && use_https=1 # force HTTPS
|
||||
|
||||
# used variables
|
||||
local __HOST __DOMAIN __TYPE __URLBASE __PRGBASE __RUNPROG __DATA __IPV6 __ZONEID __RECID __PROXIED
|
||||
local __HOST __DOMAIN __TYPE __URLBASE __PRGBASE __RUNPROG __DATA __IPV6 __ZONEID __RECID
|
||||
local __URLBASE="https://api.cloudflare.com/client/v4"
|
||||
local __TTL=120
|
||||
|
||||
# split __HOST __DOMAIN from $domain
|
||||
# given data:
|
||||
@@ -186,16 +185,14 @@ __DATA=$(grep -o '"content":\s*"[^"]*' $DATFILE | grep -o '[^"]*$' | head -1)
|
||||
|
||||
# update is needed
|
||||
# let's build data to send
|
||||
# set proxied parameter
|
||||
__PROXIED=$(grep -o '"proxied":\s*[^",]*' $DATFILE | grep -o '[^:]*$')
|
||||
|
||||
# use file to work around " needed for json
|
||||
cat > $DATFILE << EOF
|
||||
{"id":"$__ZONEID","type":"$__TYPE","name":"$__HOST","content":"$__IP","ttl":$__TTL,"proxied":$__PROXIED}
|
||||
{"content":"$__IP"}
|
||||
EOF
|
||||
|
||||
# let's complete transfer command
|
||||
__RUNPROG="$__PRGBASE --request PUT --data @$DATFILE '$__URLBASE/zones/$__ZONEID/dns_records/$__RECID'"
|
||||
__RUNPROG="$__PRGBASE --request PATCH --data @$DATFILE '$__URLBASE/zones/$__ZONEID/dns_records/$__RECID'"
|
||||
cloudflare_transfer || return 1
|
||||
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user