From 066bb140444566e48bd5c0bb3d0f3c5606ae9337 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 7 Jan 2017 19:46:45 -0500 Subject: [PATCH 1/4] Add multiple domains separated by whitespace --- scripts/pi-hole/js/list.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index de2692ad..35b6687d 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -65,9 +65,8 @@ function refresh(fade) { window.onload = refresh(false); -function add() { - var domain = $("#domain"); - if(domain.val().length === 0){ +function add(domain) { + if(domain.length === 0){ return; } @@ -80,7 +79,7 @@ function add() { $.ajax({ url: "scripts/pi-hole/php/add.php", method: "post", - data: {"domain":domain.val(), "list":listType, "token":token}, + data: {"domain":domain, "list":listType, "token":token}, success: function(response) { if (response.indexOf("not a valid argument") >= 0 || response.indexOf("is not a valid domain") >= 0) { @@ -99,7 +98,6 @@ function add() { alInfo.delay(1000).fadeOut(2000, function() { alInfo.hide(); }); - domain.val(""); refresh(true); } }, @@ -113,21 +111,26 @@ function add() { }); } }); + $("#domain").val(""); } - +function handleAdd() { + $("#domain").val().split(/\s+/).forEach(function (domain) { + add(domain); + }); +} // Handle enter button for adding domains $(document).keypress(function(e) { if(e.which === 13 && $("#domain").is(":focus")) { // Enter was pressed, and the input has focus - add(); + handleAdd(); } }); // Handle buttons $("#btnAdd").on("click", function() { - add(); + handleAdd(); }); $("#btnRefresh").on("click", function() { refresh(true); From f5ac5105e38ce7a3721d852342ea6c265630f057 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 10:34:45 +0100 Subject: [PATCH 2/4] Revert "Add multiple domains separated by whitespace" This reverts commit 066bb140444566e48bd5c0bb3d0f3c5606ae9337. --- scripts/pi-hole/js/list.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index 35b6687d..de2692ad 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -65,8 +65,9 @@ function refresh(fade) { window.onload = refresh(false); -function add(domain) { - if(domain.length === 0){ +function add() { + var domain = $("#domain"); + if(domain.val().length === 0){ return; } @@ -79,7 +80,7 @@ function add(domain) { $.ajax({ url: "scripts/pi-hole/php/add.php", method: "post", - data: {"domain":domain, "list":listType, "token":token}, + data: {"domain":domain.val(), "list":listType, "token":token}, success: function(response) { if (response.indexOf("not a valid argument") >= 0 || response.indexOf("is not a valid domain") >= 0) { @@ -98,6 +99,7 @@ function add(domain) { alInfo.delay(1000).fadeOut(2000, function() { alInfo.hide(); }); + domain.val(""); refresh(true); } }, @@ -111,26 +113,21 @@ function add(domain) { }); } }); - $("#domain").val(""); } -function handleAdd() { - $("#domain").val().split(/\s+/).forEach(function (domain) { - add(domain); - }); -} + // Handle enter button for adding domains $(document).keypress(function(e) { if(e.which === 13 && $("#domain").is(":focus")) { // Enter was pressed, and the input has focus - handleAdd(); + add(); } }); // Handle buttons $("#btnAdd").on("click", function() { - handleAdd(); + add(); }); $("#btnRefresh").on("click", function() { refresh(true); From 3808f74d4d40511981e9281e13085c25feccc240 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 10:37:20 +0100 Subject: [PATCH 3/4] Change function check_domain() to validate multiple domains separated by spaces --- scripts/pi-hole/php/auth.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/pi-hole/php/auth.php b/scripts/pi-hole/php/auth.php index 3283bab5..188b47b6 100644 --- a/scripts/pi-hole/php/auth.php +++ b/scripts/pi-hole/php/auth.php @@ -103,9 +103,13 @@ function check_csrf($token) { function check_domain() { if(isset($_POST['domain'])){ - $validDomain = is_valid_domain_name($_POST['domain']); - if(!$validDomain){ - log_and_die(htmlspecialchars($_POST['domain']. ' is not a valid domain')); + $domains = explode(" ",$_POST['domain']); + foreach($domains as $domain) + { + $validDomain = is_valid_domain_name($domain); + if(!$validDomain){ + log_and_die(htmlspecialchars($domain. ' is not a valid domain')); + } } } } From b6695f98826cb2025f5233f5aef094c465f436ea Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 10:40:21 +0100 Subject: [PATCH 4/4] Show failure response in error message (e.g. abd<>.de is not a valid domain) --- list.php | 2 +- scripts/pi-hole/js/list.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/list.php b/list.php index dc8097c1..7b62afd9 100644 --- a/list.php +++ b/list.php @@ -45,7 +45,7 @@ function getFullName() { diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index de2692ad..573cd499 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -74,6 +74,7 @@ function add() { var alInfo = $("#alInfo"); var alSuccess = $("#alSuccess"); var alFailure = $("#alFailure"); + var err = $("#err"); alInfo.show(); alSuccess.hide(); alFailure.hide(); @@ -85,10 +86,11 @@ function add() { if (response.indexOf("not a valid argument") >= 0 || response.indexOf("is not a valid domain") >= 0) { alFailure.show(); - alFailure.delay(1000).fadeOut(2000, function() { + err.html(response); + alFailure.delay(4000).fadeOut(2000, function() { alFailure.hide(); }); - alInfo.delay(1000).fadeOut(2000, function() { + alInfo.delay(4000).fadeOut(2000, function() { alInfo.hide(); }); } else {