diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js index 27620f5a7..36a12ccd6 100644 --- a/scripts/pi-hole/js/settings.js +++ b/scripts/pi-hole/js/settings.js @@ -2,6 +2,17 @@ $(function () { $("[data-mask]").inputmask(); }); +$(function(){ + $("#custom1val").ipAddress({s:4}); + $("#custom2val").ipAddress({s:4}); + $("#custom3val").ipAddress({v:6}); + $("#custom4val").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/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php index d9aadbce4..d83cfdb93 100644 --- a/scripts/pi-hole/php/savesettings.php +++ b/scripts/pi-hole/php/savesettings.php @@ -6,7 +6,7 @@ } 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 @@ -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,46 +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 === "Custom") - { - $primaryIP = $_POST["DNS1IP"]; - } - else - { - $primaryIP = array_flip($primaryDNSservers)[$primaryDNS]; - } - // Validate primary IP - if (!validIP($primaryIP)) + $DNSservers = []; + // Add selected predefined servers to list + foreach ($DNSserverslist as $key => $value) { - $error .= "Primary IP (".$primaryIP.") is invalid!
"; + if(array_key_exists("DNSserver".str_replace(".","_",$key),$_POST)) + { + array_push($DNSservers,$key); + } } - // Get secondary DNS server IP address - if($secondaryDNS === "Custom") + // Test custom server fields + for($i=1;$i<=4;$i++) { - if(strlen($_POST["DNS2IP"]) > 0) - { - $secondaryIP = $_POST["DNS2IP"]; - } - else + if(array_key_exists("custom".$i,$_POST)) { - $secondaryIP = "none"; + $IP = $_POST["custom".$i."val"]; + if(validIP($IP)) + { + array_push($DNSservers,$IP); + } + else + { + $error .= "IP (".$IP.") is invalid!
"; + } } } - 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 @@ -132,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/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 000000000..54281c4da --- /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>
@@ -360,30 +360,41 @@ function convertseconds($argument) {
- +
- $value) { ?>
- -
-
checked>
- value=""> -
+ $value) { ?> +
+ +
- +
- $value) { ?>
- + +
+
checked>
+ value=""> +
+ +
+
checked>
+ value=""> +
+ +
+
checked>
+ value=""> +
+
-
checked>
- value=""> +
checked>
+ value="">
@@ -736,6 +760,6 @@ function convertseconds($argument) { ?> - +