mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Verify Custom DNS IP is a valid IP address
This commit is contained in:
parent
800d2f0859
commit
0ebb7eecdb
1 changed files with 54 additions and 7 deletions
|
@ -304,6 +304,23 @@ setStaticIPv4() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function valid_ip()
|
||||||
|
{
|
||||||
|
local ip=$1
|
||||||
|
local stat=1
|
||||||
|
|
||||||
|
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||||
|
OIFS=$IFS
|
||||||
|
IFS='.'
|
||||||
|
ip=($ip)
|
||||||
|
IFS=$OIFS
|
||||||
|
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
|
||||||
|
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
|
||||||
|
stat=$?
|
||||||
|
fi
|
||||||
|
return $stat
|
||||||
|
}
|
||||||
|
|
||||||
setDNS(){
|
setDNS(){
|
||||||
DNSChoseCmd=(whiptail --separate-output --radiolist "Select Upstream DNS Provider. To use your own, select Custom." $r $c 6)
|
DNSChoseCmd=(whiptail --separate-output --radiolist "Select Upstream DNS Provider. To use your own, select Custom." $r $c 6)
|
||||||
DNSChooseOptions=(Google "" on
|
DNSChooseOptions=(Google "" on
|
||||||
|
@ -343,9 +360,16 @@ setDNS(){
|
||||||
Custom)
|
Custom)
|
||||||
until [[ $DNSSettingsCorrect = True ]]
|
until [[ $DNSSettingsCorrect = True ]]
|
||||||
do
|
do
|
||||||
|
|
||||||
|
strInvalid="Invalid"
|
||||||
|
|
||||||
if [ ! $piholeDNS1 ]; then
|
if [ ! $piholeDNS1 ]; then
|
||||||
prePopulate=""
|
if [ ! $piholeDNS2 ]; then
|
||||||
elif [ $piholeDNS1 ] && [ ! $piholeDNS2 ]; then
|
prePopulate=""
|
||||||
|
else
|
||||||
|
prePopulate=", $piholeDNS2"
|
||||||
|
fi
|
||||||
|
elif [ $piholeDNS1 ] && [ ! $piholeDNS2 ]; then
|
||||||
prePopulate="$piholeDNS1"
|
prePopulate="$piholeDNS1"
|
||||||
elif [ $piholeDNS1 ] && [ $piholeDNS2 ]; then
|
elif [ $piholeDNS1 ] && [ $piholeDNS2 ]; then
|
||||||
prePopulate="$piholeDNS1, $piholeDNS2"
|
prePopulate="$piholeDNS1, $piholeDNS2"
|
||||||
|
@ -355,16 +379,39 @@ setDNS(){
|
||||||
if [[ $? = 0 ]];then
|
if [[ $? = 0 ]];then
|
||||||
piholeDNS1=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}')
|
piholeDNS1=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}')
|
||||||
piholeDNS2=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}')
|
piholeDNS2=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}')
|
||||||
|
|
||||||
|
if ! valid_ip $piholeDNS1 || [ ! $piholeDNS1 ]; then
|
||||||
|
piholeDNS1=$strInvalid
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! valid_ip $piholeDNS2 && [ $piholeDNS2 ]; then
|
||||||
|
piholeDNS2=$strInvalid
|
||||||
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "::: Cancel selected, exiting...."
|
echo "::: Cancel selected, exiting...."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c) then
|
if [ $piholeDNS1 == $strInvalid ] || [ $piholeDNS2 == $strInvalid ]; then
|
||||||
DNSSettingsCorrect=True
|
whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c
|
||||||
else
|
|
||||||
# If the settings are wrong, the loop continues
|
if [ $piholeDNS1 == $strInvalid ]; then
|
||||||
|
piholeDNS1=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $piholeDNS2 == $strInvalid ]; then
|
||||||
|
piholeDNS2=""
|
||||||
|
fi
|
||||||
|
|
||||||
DNSSettingsCorrect=False
|
DNSSettingsCorrect=False
|
||||||
|
else
|
||||||
|
if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c) then
|
||||||
|
DNSSettingsCorrect=True
|
||||||
|
else
|
||||||
|
# If the settings are wrong, the loop continues
|
||||||
|
DNSSettingsCorrect=False
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue