mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Also validate IPV6 in the setdns
function
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
parent
3aaf9d89b3
commit
3205606fc3
2 changed files with 19 additions and 1 deletions
|
@ -260,7 +260,7 @@ SetDNSServers() {
|
||||||
local ip
|
local ip
|
||||||
ip="${array[index]//\\#/#}"
|
ip="${array[index]//\\#/#}"
|
||||||
|
|
||||||
if valid_ip "${ip}" ; then
|
if valid_ip "${ip}" || valid_ip6 "${ip}" ; then
|
||||||
add_setting "PIHOLE_DNS_$((index+1))" "${ip}"
|
add_setting "PIHOLE_DNS_$((index+1))" "${ip}"
|
||||||
else
|
else
|
||||||
echo -e " ${CROSS} Invalid IP has been passed"
|
echo -e " ${CROSS} Invalid IP has been passed"
|
||||||
|
|
|
@ -1031,6 +1031,24 @@ valid_ip() {
|
||||||
return "${stat}"
|
return "${stat}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
valid_ip6() {
|
||||||
|
local ip=${1}
|
||||||
|
local stat=1
|
||||||
|
|
||||||
|
# One IPv6 element is 16bit: 0000 - FFFF
|
||||||
|
local ipv6elem="[0-9a-fA-F]{1,4}"
|
||||||
|
# CIDR for IPv6 is 1- 128 bit
|
||||||
|
local v6cidr="(\\/([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])){0,1}"
|
||||||
|
# build a full regex string from the above parts
|
||||||
|
local regex="^(((${ipv6elem}))((:${ipv6elem}))*::((${ipv6elem}))*((:${ipv6elem}))*|((${ipv6elem}))((:${ipv6elem})){7})${v6cidr}$"
|
||||||
|
|
||||||
|
[[ ${ip} =~ ${regex} ]]
|
||||||
|
|
||||||
|
stat=$?
|
||||||
|
# Return the exit code
|
||||||
|
return "${stat}"
|
||||||
|
}
|
||||||
|
|
||||||
# A function to choose the upstream DNS provider(s)
|
# A function to choose the upstream DNS provider(s)
|
||||||
setDNS() {
|
setDNS() {
|
||||||
# Local, named variables
|
# Local, named variables
|
||||||
|
|
Loading…
Reference in a new issue