From d63dcb9778fc3fca96daebf7d0f1378e269f49c1 Mon Sep 17 00:00:00 2001 From: ryt51V Date: Sat, 27 Feb 2016 20:44:49 +0000 Subject: [PATCH] Allow custom DNS servers with port. --- automated install/basic-install.sh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index b3e6202f..927f00ac 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -321,6 +321,26 @@ function valid_ip() 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(){ DNSChoseCmd=(whiptail --separate-output --radiolist "Select Upstream DNS Provider. To use your own, select Custom." $r $c 6) DNSChooseOptions=(Google "" on @@ -375,16 +395,16 @@ setDNS(){ prePopulate="$piholeDNS1, $piholeDNS2" 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 piholeDNS1=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') 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 fi - if ! valid_ip $piholeDNS2 && [ $piholeDNS2 ]; then + if ! (valid_ip $piholeDNS2 || valid_ip_and_port $piholeDNS2) && [ $piholeDNS2 ]; then piholeDNS2=$strInvalid fi