Compare commits
No commits in common. "532f2abd1e91a3cdaabb3a0fc673ab4b31d28f39" and "b5de6d9676468836fb97b352337a25eedc921512" have entirely different histories.
532f2abd1e
...
b5de6d9676
45
cfddns.sh
45
cfddns.sh
@ -109,8 +109,6 @@ errorExplain=()
|
|||||||
dnsRecords=()
|
dnsRecords=()
|
||||||
cfDetails=()
|
cfDetails=()
|
||||||
cfRecords=()
|
cfRecords=()
|
||||||
currentIP=()
|
|
||||||
recordID=()
|
|
||||||
ip4=1
|
ip4=1
|
||||||
ip6=0
|
ip6=0
|
||||||
|
|
||||||
@ -244,49 +242,6 @@ else
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
## Get existing IP address and identifier in CloudFlare's DNS records
|
|
||||||
for recordIdx in "${!cfRecords[@]}"; do
|
|
||||||
currentIP+=($(echo "${cfRecords[recordIdx]}" | \
|
|
||||||
grep -Po '(?<="content":")[^"]*'))
|
|
||||||
recordID+=($(echo "${cfRecords[recordIdx]}" | \
|
|
||||||
grep -Po '(?<="id":")[^"]*'))
|
|
||||||
echo -e "\e[1;36mIndex $recordIdx: \e[0mFor record\e[1;33m" \
|
|
||||||
"${dnsRecords[recordIdx]}\e[0m" \
|
|
||||||
"with ID: \e[1;33m${recordID[recordIdx]}\e[0m" \
|
|
||||||
"the current IP is \e[1;35m ${currentIP[recordIdx]}\e[0m"
|
|
||||||
done
|
|
||||||
|
|
||||||
## Check whether new IP matches old IP and update if they do not match
|
|
||||||
for recordIdx in "${!currentIP[@]}"; do
|
|
||||||
if [ ${currentIP[recordIdx]} = $ipAddress ]; then
|
|
||||||
echo -e "\e[0;32m${dnsRecords[recordIdx]} is up-to-date.\e[0m"
|
|
||||||
else
|
|
||||||
echo -e "\e[0;31m${dnsRecords[recordIdx]} needs updating...\e[0m"
|
|
||||||
if [ $ip4 -eq 1 ]; then
|
|
||||||
# update record at CloudFlare with new IP
|
|
||||||
update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/${cfDetails[2]}/dns_records/${recordID[recordIdx]}" -H "X-Auth-Email: ${cfDetails[0]}" -H "X-Auth-Key: ${cfDetails[1]}" -H "Content-Type: application/json" --data "{\"id\":\"${cfDetails[2]}\",\"type\":\"A\",\"proxied\":false,\"name\":\"${dnsRecords[recordIdx]}\",\"content\":\"$ipAddress\"}")
|
|
||||||
# check for success code from CloudFlare
|
|
||||||
if [[ $update == *"\"success\":true"* ]]; then
|
|
||||||
echo -e "\e[1;32m${dnsRecords[recordIdx]} updated.\e[0m]"
|
|
||||||
else
|
|
||||||
echo -e "\e[1;31m${dnsRecords[recordIdx]} update failed\e[0m"
|
|
||||||
fi
|
|
||||||
elif [ $ip6 -eq 1 ]; then
|
|
||||||
# update record at CloudFlare with new IP
|
|
||||||
update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/${cfDetails[2]}/dns_records/${recordID[recordIdx]}" -H "X-Auth-Email: ${cfDetails[0]}" -H "X-Auth-Key: ${cfDetails[1]}" -H "Content-Type: application/json" --data "{\"id\":\"${cfDetails[2]}\",\"type\":\"AAAA\",\"proxied\":false,\"name\":\"${dnsRecords[recordIdx]}\",\"content\":\"$ipAddress\"}")
|
|
||||||
# check for success code from CloudFlare
|
|
||||||
if [[ $update == *"\"success\":true"* ]]; then
|
|
||||||
echo -e "\e[1;32m${dnsRecords[recordIdx]} updated.\e[0m"
|
|
||||||
else
|
|
||||||
echo -e "\e[1;31m${dnsRecords[recordIdx]} update failed\e[0m"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
quit
|
quit
|
||||||
|
|
||||||
# this code should never be executed
|
# this code should never be executed
|
||||||
|
Loading…
Reference in New Issue
Block a user