Allow custom DNS servers with port.

This commit is contained in:
ryt51V 2016-02-27 20:44:49 +00:00
parent 3a46e7fc0a
commit d63dcb9778

View file

@ -321,6 +321,26 @@ function valid_ip()
return $stat return $stat
} }
function valid_ip_and_port()
{
# Validate IP and port matches dnsmasq conf syntax
# For example '127.0.0.1#40'
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}#[0-9]{1,5}$ ]]; then
OIFS=$IFS
IFS='.#'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 \
&& ${ip[4]} -le 65535 ]]
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
@ -375,16 +395,16 @@ setDNS(){
prePopulate="$piholeDNS1, $piholeDNS2" prePopulate="$piholeDNS1, $piholeDNS2"
fi fi
piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" $r $c "$prePopulate" 3>&1 1>&2 2>&3) piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'\n\nIf the DNS server uses a custom port, append it following the hash symbol.\n\nFor example '127.0.0.1#40, 127.0.0.1#41'" $r $c "$prePopulate" 3>&1 1>&2 2>&3)
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 if ! (valid_ip $piholeDNS1 || valid_ip_and_port $piholeDNS1) || [ ! $piholeDNS1 ]; then
piholeDNS1=$strInvalid piholeDNS1=$strInvalid
fi fi
if ! valid_ip $piholeDNS2 && [ $piholeDNS2 ]; then if ! (valid_ip $piholeDNS2 || valid_ip_and_port $piholeDNS2) && [ $piholeDNS2 ]; then
piholeDNS2=$strInvalid piholeDNS2=$strInvalid
fi fi