@@ -46,9 +46,9 @@ logger() {
4646}
4747fcurl () {
4848 if [[ -n ${CF_APITOKEN} ]]; then
49- curl -s -H " Accept: application/json" -H " Content-Type: application/json" -H " Authorization: Bearer ${CF_APITOKEN} " " $@ "
49+ curl -fsL -H " User-Agent: hotio/cloudflareddns " -H " Accept: application/json" -H " Content-Type: application/json" -H " Authorization: Bearer ${CF_APITOKEN} " " $@ "
5050 else
51- curl -s -H " Accept: application/json" -H " Content-Type: application/json" -H " X-Auth-Email: ${CF_USER} " -H " X-Auth-Key: ${CF_APIKEY} " " $@ "
51+ curl -fsL -H " User-Agent: hotio/cloudflareddns " -H " Accept: application/json" -H " Content-Type: application/json" -H " X-Auth-Email: ${CF_USER} " -H " X-Auth-Key: ${CF_APIKEY} " " $@ "
5252 fi
5353}
5454fapprise () {
@@ -190,7 +190,7 @@ while true; do
190190
191191 if [[ -z ${zonelist} ]]; then
192192 logger " Requesting zone list from Cloudflare."
193- response=$( fcurl -X GET " https://api.cloudflare.com/client/v4/zones" | jq -r ' .result[] | {id, name}' )
193+ response=$( fcurl -X GET " https://api.cloudflare.com/client/v4/zones" | jq -r ' .result[] | {id, name}' 2> /dev/null )
194194 if [[ -n " ${response} " ]]; then
195195 zonelist=$( jq . <<< " ${response}" )
196196 logger " Response:\n${zonelist} " DEBUG
@@ -224,7 +224,7 @@ while true; do
224224 dnsrecord=" "
225225 if [[ -n ${zoneid} ]]; then
226226 logger " Requesting DNS records from Cloudflare."
227- dnsrecord=$( fcurl -X GET " https://api.cloudflare.com/client/v4/zones/${zoneid} /dns_records?name=${host} " | jq -rc ' .result[]|select(.type=="A" or .type=="AAAA")| {id, name, type, content, proxied, ttl} ' )
227+ dnsrecord=$( fcurl -X GET " https://api.cloudflare.com/client/v4/zones/${zoneid} /dns_records?name=${host} " | jq -rc ' .result[]|select(.type=="A" or .type=="AAAA")| {id, name, type, content} ' 2> /dev/null )
228228 if [[ -n " ${dnsrecord} " ]]; then
229229 logger " Response:\n$( jq . <<< " ${dnsrecord}" ) " DEBUG
230230 logger " Writing DNS records to cache file [${cache} ]." INFO
@@ -244,9 +244,7 @@ while true; do
244244 # #################################################
245245 if [[ -n ${dnsrecord} ]]; then
246246 while IFS=$' \n ' read -r record; do
247- id=$( jq -r ' .id' <<< " ${record}" )
248- proxied=$( jq -r ' .proxied' <<< " ${record}" )
249- ttl=$( jq -r ' .ttl' <<< " ${record}" )
247+ id=$( jq -r ' .id' <<< " ${record}" )
250248 ip=$( jq -r ' .content' <<< " ${record}" )
251249 type=$( jq -r ' .type' <<< " ${record}" )
252250
@@ -278,7 +276,7 @@ while true; do
278276 logger " [${id} ][${type} ] Checking if update is needed."
279277 if [[ ${ip} != " ${newip} " ]]; then
280278 logger " [${id} ][${type} ] Updating DNS record."
281- response=$( fcurl -X PUT " https://api.cloudflare.com/client/v4/zones/${zoneid} /dns_records/${id} " --data ' {"type":" ' " ${type} " ' ","name":" ' " ${host} " ' "," content":"' " ${newip} " ' ","ttl": ' " ${ttl} " ' ,"proxied": ' " ${proxied} " ' }' )
279+ response=$( fcurl -X PATCH " https://api.cloudflare.com/client/v4/zones/${zoneid} /dns_records/${id} " --data ' {"content":"' " ${newip} " ' "}' )
282280 if [[ $( jq -r ' .success' <<< " ${response}" ) == false ]]; then
283281 logger " Error response:\n$( jq . <<< " ${response}" ) " ERROR
284282 elif [[ $( jq -r ' .success' <<< " ${response}" ) == true ]]; then
0 commit comments