File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -260,7 +260,7 @@ SetDNSServers() {
260260 local ip
261261 ip=" ${array[index]// \\ #/# } "
262262
263- if valid_ip " ${ip} " ; then
263+ if valid_ip " ${ip} " || valid_ip6 " ${ip} " ; then
264264 add_setting " PIHOLE_DNS_$(( index+ 1 )) " " ${ip} "
265265 else
266266 echo -e " ${CROSS} Invalid IP has been passed"
Original file line number Diff line number Diff line change @@ -1031,6 +1031,24 @@ valid_ip() {
10311031 return " ${stat} "
10321032}
10331033
1034+ valid_ip6 () {
1035+ local ip=${1}
1036+ local stat=1
1037+
1038+ # One IPv6 element is 16bit: 0000 - FFFF
1039+ local ipv6elem=" [0-9a-fA-F]{1,4}"
1040+ # CIDR for IPv6 is 1- 128 bit
1041+ local v6cidr=" (\\ /([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])){0,1}"
1042+ # build a full regex string from the above parts
1043+ local regex=" ^(((${ipv6elem} ))((:${ipv6elem} ))*::((${ipv6elem} ))*((:${ipv6elem} ))*|((${ipv6elem} ))((:${ipv6elem} )){7})${v6cidr} $"
1044+
1045+ [[ ${ip} =~ ${regex} ]]
1046+
1047+ stat=$?
1048+ # Return the exit code
1049+ return " ${stat} "
1050+ }
1051+
10341052# A function to choose the upstream DNS provider(s)
10351053setDNS () {
10361054 # Local, named variables
You can’t perform that action at this time.
0 commit comments