From 7f1e80e0000b26550467ccfdd3bfb82b5bbcd76f Mon Sep 17 00:00:00 2001 From: Sailboat265 Date: Thu, 21 Oct 2021 01:38:10 +0800 Subject: [PATCH] Update cloudflare-template.sh --- cloudflare-template.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cloudflare-template.sh b/cloudflare-template.sh index 3fbca66..c419cf4 100644 --- a/cloudflare-template.sh +++ b/cloudflare-template.sh @@ -6,6 +6,7 @@ auth_method="token" # Set to "global" for Global auth_key="" # Your API Token or Global API Key zone_identifier="" # Can be found in the "Overview" tab of your domain record_name="" # Which record you want to be synced +ttl="3600" # Set the DNS TTL (seconds) proxy=false # Set the proxy to true or false @@ -34,7 +35,10 @@ fi ########################################### logger "DDNS Updater: Check Initiated" -record=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records?name=$record_name" -H "X-Auth-Email: $auth_email" -H "$auth_header $auth_key" -H "Content-Type: application/json") +record=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records?type=A&name=$record_name" \ + -H "X-Auth-Email: $auth_email" \ + -H "$auth_header $auth_key" \ + -H "Content-Type: application/json") ########################################### ## Check if the domain has an A record @@ -62,11 +66,11 @@ record_identifier=$(echo "$record" | sed -E 's/.*"id":"(\w+)".*/\1/') ########################################### ## Change the IP@Cloudflare using the API ########################################### -update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_identifier" \ +update=$(curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_identifier" \ -H "X-Auth-Email: $auth_email" \ -H "$auth_header $auth_key" \ -H "Content-Type: application/json" \ - --data "{\"id\":\"$zone_identifier\",\"type\":\"A\",\"proxied\":${proxy},\"name\":\"$record_name\",\"content\":\"$ip\"}") + --data "{\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\",\"ttl\":\"$ttl\",\"proxied\":${proxy}}") ########################################### ## Report the status