Skip to content

Commit 3205606

Browse files
committed
Also validate IPV6 in the setdns function
Signed-off-by: Adam Warner <[email protected]>
1 parent 3aaf9d8 commit 3205606

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

advanced/Scripts/webpage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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"

automated install/basic-install.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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)
10351053
setDNS() {
10361054
# Local, named variables

0 commit comments

Comments
 (0)