Added CloudFlare record check for AAAA records.

Fixed array trimming after non-existant records found.
This commit is contained in:
Asif Bacchus 2018-09-12 06:20:06 -06:00
parent 136b8872b7
commit b5de6d9676

View File

@ -196,16 +196,24 @@ fi
## Check if desired record(s) exist at CloudFlare ## Check if desired record(s) exist at CloudFlare
echo -e "\e[0;36mPerforming CloudFlare lookup on specified DNS records...\e[0m" echo -e "\e[0;36mPerforming CloudFlare lookup on specified DNS records...\e[0m"
echo -e "\t(${dnsRecords[*]})" # perform checks on A or AAAA records based on invocation options
if [ $ip4 -eq 1 ]; then
echo -e "\t(IP4: ${dnsRecords[*]})"
for cfLookup in "${dnsRecords[@]}"; do for cfLookup in "${dnsRecords[@]}"; do
cfRecords+=("$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/${cfDetails[2]}/dns_records?name=$cfLookup&type=A" -H "X-Auth-Email: ${cfDetails[0]}" -H "X-Auth-Key: ${cfDetails[1]}" -H "Content-Type: application/json")") cfRecords+=("$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/${cfDetails[2]}/dns_records?name=$cfLookup&type=A" -H "X-Auth-Email: ${cfDetails[0]}" -H "X-Auth-Key: ${cfDetails[1]}" -H "Content-Type: application/json")")
done done
elif [ $ip6 -eq 1 ]; then
echo -e "\t(IP6: ${dnsRecords[*]})"
for cfLookup in "${dnsRecords[@]}"; do
cfRecords+=("$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/${cfDetails[2]}/dns_records?name=$cfLookup&type=AAAA" -H "X-Auth-Email: ${cfDetails[0]}" -H "X-Auth-Key: ${cfDetails[1]}" -H "Content-Type: application/json")")
done
fi
# check for curl errors # check for curl errors
cfLookupResult=$(echo "$?") cfLookupResult=$(echo "$?")
if [ "$cfLookupResult" -ne 0 ]; then if [ "$cfLookupResult" -ne 0 ]; then
quit 254 quit 254
fi fi
# check for any non-existant domain names and contract array accordingly # check for any non-existant domain names and remove from array
for recordIdx in "${!cfRecords[@]}"; do for recordIdx in "${!cfRecords[@]}"; do
if [[ ${cfRecords[recordIdx]} == *"\"count\":0"* ]]; then if [[ ${cfRecords[recordIdx]} == *"\"count\":0"* ]]; then
# inform user that domain not found in CloudFlare DNS records # inform user that domain not found in CloudFlare DNS records
@ -213,12 +221,15 @@ for recordIdx in "${!cfRecords[@]}"; do
"CloudFlare DNS records***\e[0m" "CloudFlare DNS records***\e[0m"
# remove the entry from the dnsRecords array # remove the entry from the dnsRecords array
unset dnsRecords[$recordIdx] unset dnsRecords[$recordIdx]
dnsRecords=("${dnsRecords[@]}")
# remove the entry from the records array # remove the entry from the records array
unset cfRecords[$recordIdx] unset cfRecords[$recordIdx]
cfRecords=("${cfRecords[@]}")
fi fi
done done
# contract the dnsRecords and cfRecords arrays to re-order them after any
# deleted records
dnsRecords=("${dnsRecords[@]}")
cfRecords=("${cfRecords[@]}")
# after trimming errant records, it's possible dnsRecords array is empty # after trimming errant records, it's possible dnsRecords array is empty
# check for this condition and exit (nothing to do), otherwise list arrays # check for this condition and exit (nothing to do), otherwise list arrays
if [ -z ${dnsRecords} ]; then if [ -z ${dnsRecords} ]; then