Added CloudFlare record check for AAAA records.
Fixed array trimming after non-existant records found.
This commit is contained in:
parent
136b8872b7
commit
b5de6d9676
27
cfddns.sh
27
cfddns.sh
@ -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
|
||||||
for cfLookup in "${dnsRecords[@]}"; do
|
if [ $ip4 -eq 1 ]; then
|
||||||
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")")
|
echo -e "\t(IP4: ${dnsRecords[*]})"
|
||||||
done
|
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")")
|
||||||
|
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,19 +221,22 @@ 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
|
||||||
quit 104
|
quit 104
|
||||||
else
|
else
|
||||||
for recordIdx in "${!cfRecords[@]}"; do
|
for recordIdx in "${!cfRecords[@]}"; do
|
||||||
echo -e "\n\e[0;33m Found ${dnsRecords[recordIdx]}" \
|
echo -e "\n\e[0;33mFound ${dnsRecords[recordIdx]}" \
|
||||||
"(Index: $recordIdx):\e[0m"
|
"(Index: $recordIdx):\e[0m"
|
||||||
echo -e "${cfRecords[recordIdx]}"
|
echo -e "${cfRecords[recordIdx]}"
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user