Merge pull request #20 from Sailboat265/main

Fix duplicate record and record being mysteriously deleted
This commit is contained in:
Jason K 2021-10-23 15:35:39 +08:00 committed by GitHub
commit d151789229
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -6,6 +6,7 @@ auth_method="token" # Set to "global" for Global
auth_key="" # Your API Token or Global API Key auth_key="" # Your API Token or Global API Key
zone_identifier="" # Can be found in the "Overview" tab of your domain zone_identifier="" # Can be found in the "Overview" tab of your domain
record_name="" # Which record you want to be synced 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 proxy=false # Set the proxy to true or false
@ -34,7 +35,10 @@ fi
########################################### ###########################################
logger "DDNS Updater: Check Initiated" 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 ## 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 ## 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 "X-Auth-Email: $auth_email" \
-H "$auth_header $auth_key" \ -H "$auth_header $auth_key" \
-H "Content-Type: application/json" \ -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 ## Report the status