From 7f7604a6af97d581144f429ed03353d682c75242 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 22 Nov 2016 15:23:30 +0100 Subject: [PATCH 1/6] Add "Query adlists" feature --- header.php | 6 ++++++ js/pihole/queryads.js | 36 ++++++++++++++++++++++++++++++++++++ php/queryads.php | 35 +++++++++++++++++++++++++++++++++++ queryads.php | 23 +++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 js/pihole/queryads.js create mode 100644 php/queryads.php create mode 100644 queryads.php diff --git a/header.php b/header.php index 54b4da1e..76284ef6 100644 --- a/header.php +++ b/header.php @@ -242,6 +242,12 @@ Update lists + +
  • + + Query adlists + +
  • diff --git a/queryads.php b/queryads.php new file mode 100644 index 00000000..82d22603 --- /dev/null +++ b/queryads.php @@ -0,0 +1,23 @@ + + + + +
    + + + + +
    + + + + + + + From 7f779e482f9f16f1a45af95273fe18c354932e13 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 22 Nov 2016 15:30:51 +0100 Subject: [PATCH 2/6] Check if url does exists (try to resolve!) --- php/queryads.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/php/queryads.php b/php/queryads.php index 5c56a273..fddcebae 100644 --- a/php/queryads.php +++ b/php/queryads.php @@ -4,7 +4,8 @@ if(isset($_GET["domain"])) { // Remove illegal characters $url = filter_var($_GET["domain"], FILTER_SANITIZE_URL); - if(!filter_var("http://".$url, FILTER_VALIDATE_URL ) === true) + // Is this a valid domain? + if(!filter_var(gethostbyname($url), FILTER_VALIDATE_IP)) { die("Invalid domain!"); } From 64d532a95cd15c4a18f9eb3589a547a7e933842f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 22 Nov 2016 15:36:16 +0100 Subject: [PATCH 3/6] Pass "Invalid domain!" error message to user --- js/pihole/queryads.js | 2 ++ php/queryads.php | 36 +++++++++++++++++------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/js/pihole/queryads.js b/js/pihole/queryads.js index d0da2412..b7693bab 100644 --- a/js/pihole/queryads.js +++ b/js/pihole/queryads.js @@ -2,7 +2,9 @@ function eventsource() { var ta = $("#output"); var domain = $("#domain"); if(domain.val().length === 0) + { return; + } var source = new EventSource("php/queryads.php?domain="+domain.val()); // Reset and show field diff --git a/php/queryads.php b/php/queryads.php index fddcebae..9faac669 100644 --- a/php/queryads.php +++ b/php/queryads.php @@ -1,20 +1,4 @@ From 83cf008fcab9d911aef51cceb872150f0be8fcce Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 22 Nov 2016 15:43:12 +0100 Subject: [PATCH 4/6] Fixed comment --- js/pihole/queryads.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/pihole/queryads.js b/js/pihole/queryads.js index b7693bab..26061d42 100644 --- a/js/pihole/queryads.js +++ b/js/pihole/queryads.js @@ -25,7 +25,7 @@ function eventsource() { // eventsourcetest(); // }); -// Handle enter button for adding domains +// Handle enter button $(document).keypress(function(e) { if(e.which === 13 && $("#domain").is(":focus")) { // Enter was pressed, and the input has focus From 9f3b2e2bdaafc45ee8bd80a5391fabefb74dbf0e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 22 Nov 2016 16:38:28 +0100 Subject: [PATCH 5/6] Changed title of the new page --- queryads.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queryads.php b/queryads.php index 82d22603..4392c01f 100644 --- a/queryads.php +++ b/queryads.php @@ -3,7 +3,7 @@ ?>
    From 5b15755014d398f9f4ec6365758b964852db25a7 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 23 Nov 2016 12:18:27 +0100 Subject: [PATCH 6/6] Added new check for validity of domain name --- php/queryads.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/php/queryads.php b/php/queryads.php index 9faac669..eedb4a22 100644 --- a/php/queryads.php +++ b/php/queryads.php @@ -9,13 +9,20 @@ function echoEvent($datatext) { echo "data: ".implode("\ndata: ", explode("\n", $datatext))."\n\n"; } +// Credit: http://stackoverflow.com/a/4694816/2087442 +function is_valid_domain_name($domain_name) +{ + return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name) //valid chars check + && preg_match("/^.{1,253}$/", $domain_name) //overall length check + && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name) ); //length of each label +} + // Test if domain is set if(isset($_GET["domain"])) { - // Remove illegal characters - $url = filter_var($_GET["domain"], FILTER_SANITIZE_URL); // Is this a valid domain? - if(!filter_var(gethostbyname($url), FILTER_VALIDATE_IP)) + $url = $_GET["domain"]; + if(!is_valid_domain_name($url)) { echoEvent("Invalid domain!"); die();