Compare commits

...

2 Commits

Author SHA1 Message Date
Asif Bacchus aa10ba23e1 Changed echo section to display CloudFlare results based on array index. 2018-09-12 04:39:37 -06:00
Asif Bacchus b435a3d6e3 Fixed array processing for record lookup.
Updated testing echo section.
2018-09-12 04:17:48 -06:00
1 changed files with 28 additions and 7 deletions

View File

@ -72,6 +72,7 @@ unset accountFile
unset ipAddress
dnsRecords=()
cfDetails=()
record=()
ip4=1
ip6=0
@ -149,13 +150,19 @@ fi
## Check if desired record(s) exist at CloudFlare
for counter in "${dnsRecords[@]}"; do
record=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/ \
${cfDetails[2]}/dns_records?name=${dnsRecords[counter]}&type=A" \
-H "X-Auth-Email: ${cfDetails[0]}" \
-H "X-Auth-Key: ${cfDetails[1]}" \
-H "Content-Type: application/json")
echo -e "\e[0;36mPerforming CloudFlare lookup on specified DNS records...\e[0m"
for cfLookup in "${dnsRecords[@]}"; do
record+=("$(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
cfLookupResult=$(echo "$?")
if [ "$ipLookupResult" -ne 0 ]; then
echo -e "\e[1;31mThere was a problem accessing the CloudFlare API"
echo -e "\e[0;31mPlease re-run this script later.\e[0m"
exit 254
else
echo -e "\e[0;36m...done"
fi
### Echo results (testing)
echo -e "\nBased on parameters provided:"
@ -169,5 +176,19 @@ if [ $ip4 -eq 1 ]; then
elif [ $ip6 -eq 1 ]; then
echo -e "\e[0;92mUpdating AAAA records"
fi
echo -e "\e[0;92mPointing records to IP: $ipAddress\e[0m\n"
echo -e "\e[0;92mPointing records to IP: $ipAddress"
echo -e "\e[0m\n"
echo -e "\e[0;39mRecord check:"
echo "Array length: ${#record[@]}"
echo "Results:"
for recordIdx in "${!record[@]}"; do
echo -e "\n\e[0;33mResult for ${dnsRecords[recordIdx]}:\e[0m"
if [[ ${record[recordIdx]} == *"\"count\":0"* ]]; then
echo -e "\e[0;31m***not found in your CloudFlare DNS records***\e[0m"
else
echo -e "${record[recordIdx]}"
fi
done
exit 0