From 6958f5003965f3aeee31aa259942ef81b3052cd5 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 13 Jan 2017 13:37:36 +0100 Subject: [PATCH 1/3] Change data-mask extension to one that supports both IPv4 and IPv6 addresses. Add IPv6 DNS server fields on the settings page --- scripts/pi-hole/js/settings.js | 11 ++++ ...jquery.input-ip-address-control-1.0.min.js | 7 +++ settings.php | 50 ++++++++++++++----- 3 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 scripts/vendor/jquery.input-ip-address-control-1.0.min.js diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js index 27620f5a..8b0f8b82 100644 --- a/scripts/pi-hole/js/settings.js +++ b/scripts/pi-hole/js/settings.js @@ -2,6 +2,17 @@ $(function () { $("[data-mask]").inputmask(); }); +$(function(){ + $("#DNS1IPv4").ipAddress({s:4}); + $("#DNS2IPv4").ipAddress({s:4}); + $("#DNS1IPv6").ipAddress({v:6}); + $("#DNS2IPv6").ipAddress({v:6}); + + $("#DHCPfrom").ipAddress({s:4}); + $("#DHCPto").ipAddress({s:4}); + $("#DHCProuter").ipAddress({s:4}); +}); + $(".confirm-reboot").confirm({ text: "Are you sure you want to send a reboot command to your Pi-Hole?", title: "Confirmation required", diff --git a/scripts/vendor/jquery.input-ip-address-control-1.0.min.js b/scripts/vendor/jquery.input-ip-address-control-1.0.min.js new file mode 100644 index 00000000..54281c4d --- /dev/null +++ b/scripts/vendor/jquery.input-ip-address-control-1.0.min.js @@ -0,0 +1,7 @@ +/*! + * jQuery Input Ip Address Control : v0.1beta (2010/11/09 16:15:43) + * Copyright (c) 2010 jquery-input-ip-address-control@googlecode.com + * Licensed under the MIT license and GPL licenses. + * + */ +eval(function(p,a,c,k,e,d){e=function(c){return(c35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(l($){Q.1o.1t=l(){E=/\\b(?:(?:25[0-5]|2[0-4][0-9]|[1m]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[1m]?[0-9][0-9]?)\\b/;h E.1a(p.1i())};Q.1o.1S=l(){E=/\\b([A-16-9]{1,4}:){7}([A-16-9]{1,4})\\b/i;h E.1a(p.1i())};$.1X.1h({y:l(u,c){f(p.z==0)h;f(1k u==\'1f\'){c=(1k c==\'1f\')?c:u;h p.1d(l(){f(p.18){p.1s();p.18(u,c)}w f(p.1e){t C=p.1e();C.1L(S);C.1z(\'10\',c);C.1b(\'10\',u);C.1w()}})}w{f(p[0].18){u=p[0].1u;c=p[0].1C}w f(14.12&&14.12.19){t C=14.12.19();u=0-C.1D().1b(\'10\',-1E);c=u+C.1H.z}h{u:u,c:c}}},1B:l(s){s=$.1h({v:4},s);f(s.v==4){s.W=M I(\'[0-9]\',\'g\');s.r=\'R.R.R.R\'}f(s.v==6){s.W=M I(\'[A-16-9]\',\'1x\');s.r=\'x:x:x:x:x:x:x:x\'}s.D=s.r.K(\'\').Y();s.q=s.r.X(M I(s.D,\'g\'),\'\').K(\'\').Y();s.O=s.r.K(s.q).Y();h $(p).1d(l(){t a={k:T,n:T,o:T,d:T};a.d=$(p);f(a.d.m()==\'\'||!J(a.d.m()))a.d.m(s.r);a.d.1j(\'1Z\',(s.v==4?15:1c)).1j(\'1W\',(s.v==4?15:1c));l J(o){h 24("o.21"+s.v+"()")};l P(){a.k=a.d.y();a.o=J(L(a.d.m()))?L(a.d.m()):a.o;a.n=a.d.m().K(\'\')};l 1n(o){t G=o.K(s.q);1p(t j=0;j0)G[j]+=s.D}h G.H(s.q)};l L(o){t E=M I(s.O,\'g\');t 1g=M I(s.D,\'g\');h o.X(E,\'0\').X(1g,\'\')};l 11(e){1R(e.1Q){U 8:f(a.n[a.k.c-1]!=s.q){a.n[a.k.c-1]=s.D;a.d.m(a.n.H("")).m()}a.d.y(a.k.c-1);h B;V;U 13:U 1T:a.d.17();V;U 1P:f(a.n[a.k.c]!=s.q&&a.k.c=20&&e.F<=1N)||e.F>1J){f(Q.1q(e.F).1y(s.W)){a.n[a.k.c]=Q.1q(e.F);f(!J(L(a.n.H(\'\')))){f((a.k.c==0||a.n[a.k.c-1]==s.q)){1p(t i=a.k.c+1;i
From
- disabled> + disabled>
@@ -206,7 +206,7 @@
To
- disabled> + disabled>
@@ -215,7 +215,7 @@
Router
- disabled> + disabled>
@@ -365,9 +365,17 @@ { $piHoleDNS1 = $primaryDNSservers[$setupVars["PIHOLE_DNS_1"]]; } + elseif(strpos($setupVars["PIHOLE_DNS_1"],".")) + { + $piHoleDNS1 = "Customv4"; + } + elseif(strpos($setupVars["PIHOLE_DNS_1"],":")) + { + $piHoleDNS1 = "Customv6"; + } else { - $piHoleDNS1 = "Custom"; + $piHoleDNS1 = "unknown"; } } else { $piHoleDNS1 = "unknown"; @@ -378,9 +386,17 @@ { $piHoleDNS2 = $secondaryDNSservers[$setupVars["PIHOLE_DNS_2"]]; } + elseif(strpos($setupVars["PIHOLE_DNS_2"],".")) + { + $piHoleDNS2 = "Customv4"; + } + elseif(strpos($setupVars["PIHOLE_DNS_2"],":")) + { + $piHoleDNS2 = "Customv6"; + } else { - $piHoleDNS2 = "Custom"; + $piHoleDNS2 = "unknown"; } } else { $piHoleDNS2 = "unknown"; @@ -435,12 +451,17 @@
$value) { ?>
- +
checked>
- value=""> + value=""> +
+ +
+
checked>
+ value="">
@@ -448,12 +469,17 @@
$value) { ?>
- +
checked>
- value=""> + value=""> +
+ +
+
checked>
+ value="">
@@ -736,6 +762,6 @@ ?> - + From 0924f20214ee8d0807ae68db9c6d901040b2499a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 13 Jan 2017 13:47:06 +0100 Subject: [PATCH 2/3] Required backend changes in savesettings.php --- scripts/pi-hole/php/savesettings.php | 27 +++++++++++++++++++++------ settings.php | 16 ++++++++-------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php index d9aadbce..70ac8ea4 100644 --- a/scripts/pi-hole/php/savesettings.php +++ b/scripts/pi-hole/php/savesettings.php @@ -6,7 +6,7 @@ if(basename($_SERVER['SCRIPT_FILENAME']) !== "settings.php") } function validIP($address){ - return !filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false; + return !filter_var($address, FILTER_VALIDATE_IP) === false; } // Check for existance of variable @@ -61,9 +61,13 @@ function validDomain($domain_name) $secondaryDNS = $_POST["secondaryDNS"]; // Get primary DNS server IP address - if($primaryDNS === "Custom") + if($primaryDNS === "Customv4") { - $primaryIP = $_POST["DNS1IP"]; + $primaryIP = $_POST["DNS1IPv4"]; + } + elseif($primaryDNS === "Customv6") + { + $primaryIP = $_POST["DNS1IPv6"]; } else { @@ -77,11 +81,22 @@ function validDomain($domain_name) } // Get secondary DNS server IP address - if($secondaryDNS === "Custom") + if($secondaryDNS === "Customv4") { - if(strlen($_POST["DNS2IP"]) > 0) + if(strlen($_POST["DNS2IPv4"]) > 0) { - $secondaryIP = $_POST["DNS2IP"]; + $secondaryIP = $_POST["DNS2IPv4"]; + } + else + { + $secondaryIP = "none"; + } + } + elseif($secondaryDNS === "Customv6") + { + if(strlen($_POST["DNS2IPv6"]) > 0) + { + $secondaryIP = $_POST["DNS2IPv6"]; } else { diff --git a/settings.php b/settings.php index d53e5b5d..d538a5f3 100644 --- a/settings.php +++ b/settings.php @@ -453,14 +453,14 @@ $value) { ?>
-
checked>
+
checked>
value="">
-
checked>
+
checked>
value="">
@@ -471,15 +471,15 @@ $value) { ?>
-
checked>
+
checked>
value="">
-
checked>
- value=""> + value="">
From 6760ba80a7362f912c3f3def7f54a9ce487e9166 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 13 Jan 2017 17:49:16 +0100 Subject: [PATCH 3/3] Allow multiple upstream DNS server selection --- scripts/pi-hole/js/settings.js | 8 +- scripts/pi-hole/php/savesettings.php | 95 ++++++++------------ settings.php | 124 +++++++++++++-------------- 3 files changed, 100 insertions(+), 127 deletions(-) diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js index 8b0f8b82..36a12ccd 100644 --- a/scripts/pi-hole/js/settings.js +++ b/scripts/pi-hole/js/settings.js @@ -3,10 +3,10 @@ $(function () { }); $(function(){ - $("#DNS1IPv4").ipAddress({s:4}); - $("#DNS2IPv4").ipAddress({s:4}); - $("#DNS1IPv6").ipAddress({v:6}); - $("#DNS2IPv6").ipAddress({v:6}); + $("#custom1val").ipAddress({s:4}); + $("#custom2val").ipAddress({s:4}); + $("#custom3val").ipAddress({v:6}); + $("#custom4val").ipAddress({v:6}); $("#DHCPfrom").ipAddress({s:4}); $("#DHCPto").ipAddress({s:4}); diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php index 70ac8ea4..d83cfdb9 100644 --- a/scripts/pi-hole/php/savesettings.php +++ b/scripts/pi-hole/php/savesettings.php @@ -32,20 +32,17 @@ function validDomain($domain_name) return ( $validChars && $lengthCheck && $labelLengthCheck ); //length of each label } - $primaryDNSservers = [ - "8.8.8.8" => "Google", - "208.67.222.222" => "OpenDNS", - "4.2.2.1" => "Level3", - "199.85.126.10" => "Norton", - "8.26.56.26" => "Comodo" - ]; - - $secondaryDNSservers = [ - "8.8.4.4" => "Google", - "208.67.220.220" => "OpenDNS", - "4.2.2.2" => "Level3", - "199.85.127.10" => "Norton", - "8.20.247.20" => "Comodo" + $DNSserverslist = [ + "8.8.8.8" => "Google (Primary)", + "208.67.222.222" => "OpenDNS (Primary)", + "4.2.2.1" => "Level3 (Primary)", + "199.85.126.10" => "Norton (Primary)", + "8.26.56.26" => "Comodo (Primary)", + "8.8.4.4" => "Google (Secondary)", + "208.67.220.220" => "OpenDNS (Secondary)", + "4.2.2.2" => "Level3 (Secondary)", + "199.85.127.10" => "Norton (Secondary)", + "8.20.247.20" => "Comodo (Secondary)" ]; $error = ""; @@ -57,61 +54,38 @@ function validDomain($domain_name) switch ($_POST["field"]) { // Set DNS server case "DNS": - $primaryDNS = $_POST["primaryDNS"]; - $secondaryDNS = $_POST["secondaryDNS"]; - // Get primary DNS server IP address - if($primaryDNS === "Customv4") + $DNSservers = []; + // Add selected predefined servers to list + foreach ($DNSserverslist as $key => $value) { - $primaryIP = $_POST["DNS1IPv4"]; - } - elseif($primaryDNS === "Customv6") - { - $primaryIP = $_POST["DNS1IPv6"]; - } - else - { - $primaryIP = array_flip($primaryDNSservers)[$primaryDNS]; - } - - // Validate primary IP - if (!validIP($primaryIP)) - { - $error .= "Primary IP (".$primaryIP.") is invalid!
"; - } - - // Get secondary DNS server IP address - if($secondaryDNS === "Customv4") - { - if(strlen($_POST["DNS2IPv4"]) > 0) + if(array_key_exists("DNSserver".str_replace(".","_",$key),$_POST)) { - $secondaryIP = $_POST["DNS2IPv4"]; - } - else - { - $secondaryIP = "none"; + array_push($DNSservers,$key); } } - elseif($secondaryDNS === "Customv6") + + // Test custom server fields + for($i=1;$i<=4;$i++) { - if(strlen($_POST["DNS2IPv6"]) > 0) + if(array_key_exists("custom".$i,$_POST)) { - $secondaryIP = $_POST["DNS2IPv6"]; + $IP = $_POST["custom".$i."val"]; + if(validIP($IP)) + { + array_push($DNSservers,$IP); + } + else + { + $error .= "IP (".$IP.") is invalid!
"; + } } - else - { - $secondaryIP = "none"; - } - } - else - { - $secondaryIP = array_flip($secondaryDNSservers)[$secondaryDNS]; } - // Validate secondary IP - if (!validIP($secondaryIP) && $secondaryIP != "none" && strlen($secondaryIP) > 0) + // Check if at least one DNS server has been added + if(count($DNSservers) < 1) { - $error .= "Secondary IP (".$secondaryIP.") is invalid!
"; + $error .= "No DNS server has been selected.
"; } // Check if domain-needed is requested @@ -147,8 +121,9 @@ function validDomain($domain_name) // If there has been no error we can save the new DNS server IPs if(!strlen($error)) { - exec("sudo pihole -a setdns ".$primaryIP." ".$secondaryIP." ".$extra); - $success .= "The DNS settings have been updated"; + $IPs = implode (",", $DNSservers); + exec("sudo pihole -a setdns ".$IPs." ".$extra); + $success .= "The DNS settings have been updated (using ".count($DNSservers)." DNS servers)"; } else { diff --git a/settings.php b/settings.php index d538a5f3..714821ce 100644 --- a/settings.php +++ b/settings.php @@ -360,46 +360,41 @@
- +
- $value) { ?>
- -
-
checked>
- value=""> -
- -
-
checked>
- value=""> -
+ $value) { ?> +
+ +
- +
- $value) { ?>
- +
-
checked>
- value=""> +
checked>
+ value="">
- +
-
checked>
- value=""> +
checked>
+ value=""> +
+ +
+
checked>
+ value=""> +
+ +
+
checked>
+ value="">