From 158c132c979586be77c6cabf940aba851c66f531 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 5 Mar 2020 20:31:23 +0000 Subject: [PATCH 1/5] Split domain input into two separate fields. Signed-off-by: DL6ER --- groups-domains.php | 41 +++++++++++++-------- scripts/pi-hole/js/groups-domains.js | 55 +++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 16 deletions(-) diff --git a/groups-domains.php b/groups-domains.php index ca99dfc54..180f6cda1 100644 --- a/groups-domains.php +++ b/groups-domains.php @@ -28,7 +28,7 @@

- Add a new domain + Add a new domain or regex filter

@@ -38,25 +38,36 @@ -
+
+ + +
+
+
+
+
+
+
+
+ +
-
+ + 01"> + +
+
+ +
+
- +
diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index 4fa76365a..7dc8fe5d3 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -37,6 +37,37 @@ $(document).ready(function() { showtype = GETDict.type; } + // Disable regex field when typing into domains field + // bind is not only triggered on key but also clipboard events + $('#new_domain').bind('input', function () { + if ($('#new_domain').val().length > 0) { + $('#new_regex').prop( "disabled", true ); + } else { + $('#new_regex').prop( "disabled", false ); + } + }); + + // Disable domain field when typing into regex field + $('#new_regex').bind('input', function () { + if ($('#new_regex').val().length > 0) { + $('#new_domain').prop( "disabled", true ); + $('#wildcard_checkbox').prop( "disabled", true ); + } else { + $('#new_domain').prop( "disabled", false ); + $('#wildcard_checkbox').prop( "disabled", false ); + } + }); + + // Disable domain field when typing into regex field + $('#wildcard_checkbox').change(function () { + if ($('#wildcard_checkbox').prop("checked")) { + $('#new_regex').text( "" ); + $('#new_regex').prop( "disabled", true ); + } else { + $('#new_regex').prop( "disabled", false ); + } + }); + $("#btnAdd").on("click", addDomain); get_groups(); @@ -276,13 +307,34 @@ function initTable() { function addDomain() { var domain = $("#new_domain").val(); + var regex = $("#new_regex").val(); + var wildcard_checkbox = $("#wildcard_checkbox").prop("checked"); var type = $("#new_type").val(); var comment = $("#new_comment").val(); utils.disableAll(); utils.showAlert("info", "", "Adding domain...", domain); - if (domain.length === 0) { + // Determine type + if (domain.length > 0) { + if (wildcard_checkbox) { + // Strip "*." if specified by user in wildcard mode + if(domain.startsWith("*.")) { + domain = domain.substr(2); + } + if (type == 0) { + type = "2W"; + } else { + type = "4W"; + } + } + } else if (regex.length > 0 && type == 0) { + domain = regex; + type = "2"; + } else if (regex.length > 0 && type == 1) { + domain = regex; + type = "3"; + } else { utils.enableAll(); utils.showAlert("warning", "", "Warning", "Please specify a domain"); return; @@ -305,6 +357,7 @@ function addDomain() { utils.showAlert("success", "glyphicon glyphicon-plus", "Successfully added domain", domain); $("#new_domain").val(""); $("#new_comment").val(""); + $("#new_regex").val(""); table.ajax.reload(); } else utils.showAlert("error", "", "Error while adding new domain", response.message); }, From 2186bb0ca9bc6d89ad73ef260a2db5caadcdb778 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 5 Mar 2020 20:40:38 +0000 Subject: [PATCH 2/5] Codestyle changes Signed-off-by: DL6ER --- scripts/pi-hole/js/groups-domains.js | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index 7dc8fe5d3..0838b525c 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -39,32 +39,32 @@ $(document).ready(function() { // Disable regex field when typing into domains field // bind is not only triggered on key but also clipboard events - $('#new_domain').bind('input', function () { - if ($('#new_domain').val().length > 0) { - $('#new_regex').prop( "disabled", true ); + $("#new_domain").bind("input", function () { + if ($("#new_domain").val().length > 0) { + $("#new_regex").prop("disabled", true); } else { - $('#new_regex').prop( "disabled", false ); + $("#new_regex").prop("disabled", false); } }); // Disable domain field when typing into regex field - $('#new_regex').bind('input', function () { - if ($('#new_regex').val().length > 0) { - $('#new_domain').prop( "disabled", true ); - $('#wildcard_checkbox').prop( "disabled", true ); + $("#new_regex").bind("input", function () { + if ($("#new_regex").val().length > 0) { + $("#new_domain").prop("disabled", true); + $("#wildcard_checkbox").prop("disabled", true); } else { - $('#new_domain').prop( "disabled", false ); - $('#wildcard_checkbox').prop( "disabled", false ); + $("#new_domain").prop("disabled", false); + $("#wildcard_checkbox").prop("disabled", false); } }); // Disable domain field when typing into regex field - $('#wildcard_checkbox').change(function () { - if ($('#wildcard_checkbox').prop("checked")) { - $('#new_regex').text( "" ); - $('#new_regex').prop( "disabled", true ); + $("#wildcard_checkbox").change(function () { + if ($("#wildcard_checkbox").prop("checked")) { + $("#new_regex").text(""); + $("#new_regex").prop("disabled", true); } else { - $('#new_regex').prop( "disabled", false ); + $("#new_regex").prop("disabled", false); } }); From 56de14a425cb3ca9305641b8eca52eb26ae485f8 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 5 Mar 2020 22:07:07 +0000 Subject: [PATCH 3/5] Fix checkout layout on full/limited domain pages. Signed-off-by: DL6ER --- groups-domains.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/groups-domains.php b/groups-domains.php index 180f6cda1..a9ae7f918 100644 --- a/groups-domains.php +++ b/groups-domains.php @@ -49,6 +49,10 @@
+
36"> +
+ +
@@ -61,10 +65,6 @@ 01"> -
-
- -
From 8ca08c17fe9218c63d6834946fb1cf2f27f41550 Mon Sep 17 00:00:00 2001 From: TheME Date: Sun, 8 Mar 2020 14:33:48 +0100 Subject: [PATCH 4/5] tabs for new domain/regex input Signed-off-by: Th3M3 --- groups-domains.php | 101 ++++++++++------ scripts/pi-hole/js/groups-domains.js | 167 ++++++++++++++++----------- 2 files changed, 164 insertions(+), 104 deletions(-) diff --git a/groups-domains.php b/groups-domains.php index a9ae7f918..f35e73e12 100644 --- a/groups-domains.php +++ b/groups-domains.php @@ -25,7 +25,6 @@
-

Add a new domain or regex filter @@ -33,56 +32,84 @@

-
-
- - -
-
- - + -
-
-
+ -
-
36"> -
- + +
+
- -
- - -
- - 01"> -
- - -
- +
+
+ +

- List of domains + List of entries

@@ -91,7 +118,7 @@ ID - Domain + Domain/RegEx Type Status Comment diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index 0838b525c..0b82c8265 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -37,38 +37,23 @@ $(document).ready(function() { showtype = GETDict.type; } - // Disable regex field when typing into domains field - // bind is not only triggered on key but also clipboard events - $("#new_domain").bind("input", function () { - if ($("#new_domain").val().length > 0) { - $("#new_regex").prop("disabled", true); - } else { - $("#new_regex").prop("disabled", false); - } - }); - - // Disable domain field when typing into regex field - $("#new_regex").bind("input", function () { - if ($("#new_regex").val().length > 0) { - $("#new_domain").prop("disabled", true); - $("#wildcard_checkbox").prop("disabled", true); - } else { - $("#new_domain").prop("disabled", false); - $("#wildcard_checkbox").prop("disabled", false); + // sync description fields, reset inactive inputs on tab change + $('a[data-toggle="tab"]').on("shown.bs.tab", function() { + var tabHref = $(this).attr("href"); + var val; + if (tabHref === "#tab_domain") { + val = $("#new_regex_comment").val(); + $("#new_domain_comment").val(val); + $("#new_regex").val(""); + } else if (tabHref === "#tab_regex") { + val = $("#new_domain_comment").val(); + $("#new_regex_comment").val(val); + $("#new_domain").val(""); + $("#wildcard_checkbox").prop("checked", false); } }); - // Disable domain field when typing into regex field - $("#wildcard_checkbox").change(function () { - if ($("#wildcard_checkbox").prop("checked")) { - $("#new_regex").text(""); - $("#new_regex").prop("disabled", true); - } else { - $("#new_regex").prop("disabled", false); - } - }); - - $("#btnAdd").on("click", addDomain); + $("#add2black, #add2white").on("click", addDomain); get_groups(); }); @@ -306,37 +291,53 @@ function initTable() { } function addDomain() { - var domain = $("#new_domain").val(); - var regex = $("#new_regex").val(); - var wildcard_checkbox = $("#wildcard_checkbox").prop("checked"); - var type = $("#new_type").val(); - var comment = $("#new_comment").val(); + var action = this.id; + var tabHref = $('a[data-toggle="tab"][aria-expanded="true"]').attr("href"); + var wildcardEl = $("#wildcard_checkbox"); + var wildcard_checked = wildcardEl.prop("checked"); + var type; + + // current tab's inputs + var domain_regex, domainEl, commentEl; + if (tabHref === "#tab_domain") { + domain_regex = "domain"; + domainEl = $("#new_domain"); + commentEl = $("#new_domain_comment"); + } else if (tabHref === "#tab_regex") { + domain_regex = "regex"; + domainEl = $("#new_regex"); + commentEl = $("#new_regex_comment"); + } + + var domain = domainEl.val(); + var comment = commentEl.val(); utils.disableAll(); - utils.showAlert("info", "", "Adding domain...", domain); + utils.showAlert("info", "", "Adding " + domain_regex + "...", domain); - // Determine type if (domain.length > 0) { - if (wildcard_checkbox) { - // Strip "*." if specified by user in wildcard mode - if(domain.startsWith("*.")) { - domain = domain.substr(2); - } - if (type == 0) { - type = "2W"; - } else { - type = "4W"; - } + // strip "*." if specified by user in wildcard mode + if (domain_regex === "domain" && wildcard_checked && domain.startsWith("*.")) { + domain = domain.substr(2); + } + + // determine list type + if (domain_regex === "domain" && action === "add2black" && wildcard_checked) { + type = "3W"; + } else if (domain_regex === "domain" && action === "add2black" && !wildcard_checked) { + type = "1"; + } else if (domain_regex === "domain" && action === "add2white" && wildcard_checked) { + type = "2W"; + } else if (domain_regex === "domain" && action === "add2white" && !wildcard_checked) { + type = "0"; + } else if (domain_regex === "regex" && action === "add2black") { + type = "3"; + } else if (domain_regex === "regex" && action === "add2white") { + type = "2"; } - } else if (regex.length > 0 && type == 0) { - domain = regex; - type = "2"; - } else if (regex.length > 0 && type == 1) { - domain = regex; - type = "3"; } else { utils.enableAll(); - utils.showAlert("warning", "", "Warning", "Please specify a domain"); + utils.showAlert("warning", "", "Warning", "Please specify a " + domain_regex); return; } @@ -354,16 +355,23 @@ function addDomain() { success: function(response) { utils.enableAll(); if (response.success) { - utils.showAlert("success", "glyphicon glyphicon-plus", "Successfully added domain", domain); - $("#new_domain").val(""); - $("#new_comment").val(""); - $("#new_regex").val(""); + utils.showAlert( + "success", + "glyphicon glyphicon-plus", + "Successfully added " + domain_regex, + domain + ); + domainEl.val(""); + commentEl.val(""); + wildcardEl.prop("checked", false); table.ajax.reload(); - } else utils.showAlert("error", "", "Error while adding new domain", response.message); + } else { + utils.showAlert("error", "", "Error while adding new " + domain_regex, response.message); + } }, error: function(jqXHR, exception) { utils.enableAll(); - utils.showAlert("error", "", "Error while adding new domain", jqXHR.responseText); + utils.showAlert("error", "", "Error while adding new " + domain_regex, jqXHR.responseText); console.log(exception); } }); @@ -379,6 +387,13 @@ function editDomain() { var comment = tr.find("#comment_" + id).val(); var groups = tr.find("#multiselect_" + id).val(); + var domain_regex; + if (type === "0" || type === "1") { + domain_regex = "domain"; + } else if (type === "2" || type === "3") { + domain_regex = "regex"; + } + var done = "edited"; var not_done = "editing"; switch (elem) { @@ -414,7 +429,7 @@ function editDomain() { } utils.disableAll(); - utils.showAlert("info", "", "Editing domain...", name); + utils.showAlert("info", "", "Editing " + domain_regex + "...", name); $.ajax({ url: "scripts/pi-hole/php/groups.php", method: "post", @@ -434,14 +449,14 @@ function editDomain() { utils.showAlert( "success", "glyphicon glyphicon-pencil", - "Successfully " + done + " domain", + "Successfully " + done + " " + domain_regex, domain ); } else utils.showAlert( "error", "", - "Error while " + not_done + " domain with ID " + id, + "Error while " + not_done + " " + domain_regex + " with ID " + id, response.message ); }, @@ -450,7 +465,7 @@ function editDomain() { utils.showAlert( "error", "", - "Error while " + not_done + " domain with ID " + id, + "Error while " + not_done + " " + domain_regex + " with ID " + id, jqXHR.responseText ); console.log(exception); @@ -462,9 +477,17 @@ function deleteDomain() { var tr = $(this).closest("tr"); var id = tr.attr("data-id"); var domain = tr.find("#domain_" + id).text(); + var type = tr.find("#type_" + id).val(); + + var domain_regex; + if (type === "0" || type === "1") { + domain_regex = "domain"; + } else if (type === "2" || type === "3") { + domain_regex = "regex"; + } utils.disableAll(); - utils.showAlert("info", "", "Deleting domain...", domain); + utils.showAlert("info", "", "Deleting " + domain_regex + "...", domain); $.ajax({ url: "scripts/pi-hole/php/groups.php", method: "post", @@ -476,7 +499,7 @@ function deleteDomain() { utils.showAlert( "success", "glyphicon glyphicon-trash", - "Successfully deleted domain", + "Successfully deleted " + domain_regex, domain ); table @@ -484,12 +507,22 @@ function deleteDomain() { .remove() .draw(false); } else { - utils.showAlert("error", "", "Error while deleting domain with ID " + id, response.message); + utils.showAlert( + "error", + "", + "Error while deleting " + domain_regex + " with ID " + id, + response.message + ); } }, error: function(jqXHR, exception) { utils.enableAll(); - utils.showAlert("error", "", "Error while deleting domain with ID " + id, jqXHR.responseText); + utils.showAlert( + "error", + "", + "Error while deleting " + domain_regex + " with ID " + id, + jqXHR.responseText + ); console.log(exception); } }); From 3222103ce886049a09aa272363b4d444b0b8600e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 15 Mar 2020 19:00:15 +0000 Subject: [PATCH 5/5] Improve wildcard hint Signed-off-by: DL6ER --- groups-domains.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/groups-domains.php b/groups-domains.php index f35e73e12..fdfbdd81c 100644 --- a/groups-domains.php +++ b/groups-domains.php @@ -53,7 +53,7 @@
- wildcard: Check this box if you want to involve + Checkbox "wildcard": Check this box if you want to involve all subdomains. The entered domain will be converted to a RegEx filter while adding.