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:
parent
ff6a8df63c
commit
9d2e7fcc8a
|
@ -17,17 +17,15 @@ 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"
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue