Taking feedback from timetoexpire

Changed back so that curl is used by default, however dig can be used
as a backup if curl is not installed on the system. Additionally took
my fear of code injection into account by sanitizing the remote input
through a regex.
This commit is contained in:
9cco 2022-02-25 12:24:17 +01:00
parent ff6a8df63c
commit 9d2e7fcc8a
1 changed files with 7 additions and 9 deletions

View File

@ -17,18 +17,16 @@ slackuri="" # URI for Slack WebHook "http
###########################################
## Check if we have a public IP
###########################################
command -v dig &> /dev/null
# Use the DNS lookup if dig is available.
if [[ $? -eq 0 ]]; then
# Use curl if curl is available
if [[ $(command -v curl &> /dev/null; echo $?) ]]; then
ip=$(curl -s https://api.ipify.org || curl -s https://ipv4.icanhazip.com/)
elif [[ $(command -v dig &> /dev/null; echo $?) ]]; then
ip=$(dig +short myip.opendns.com @resolver1.opendns.com);
fi
if [[ $ip -eq "" ]]; then
ip=$(curl -s https://api.ipify.org || curl -s https://ipv4.icanhazip.com/)
fi
if [[ "${ip}" == "" ]]; then
logger -s "DDNS Updater: No public IP found"
exit 1
if [[ ! $ip =~ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} ]]; then
logger -s "DDNS Updater: Failed to find a valid IP."
exit 1
fi
###########################################