From 2d975b8bacf54e0dbc969da68b8cb09a1ca78209 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 14 Feb 2020 20:21:01 +0100 Subject: [PATCH 01/10] Simplify domain management by using the same page for both locations where domains can be edited. This removes a large amount of duplicated code, each prone to its own bugs. Signed-off-by: DL6ER --- groups-domains.php | 29 ++- list.php | 84 -------- scripts/pi-hole/js/groups-domains.js | 82 +++++--- scripts/pi-hole/js/list.js | 287 --------------------------- scripts/pi-hole/php/add.php | 78 -------- scripts/pi-hole/php/get.php | 85 -------- scripts/pi-hole/php/groups.php | 21 +- scripts/pi-hole/php/header.php | 10 +- scripts/pi-hole/php/sub.php | 51 ----- 9 files changed, 98 insertions(+), 629 deletions(-) delete mode 100644 list.php delete mode 100644 scripts/pi-hole/js/list.js delete mode 100644 scripts/pi-hole/php/add.php delete mode 100644 scripts/pi-hole/php/get.php delete mode 100644 scripts/pi-hole/php/sub.php diff --git a/groups-domains.php b/groups-domains.php index 9c4659e4..ca99dfc5 100644 --- a/groups-domains.php +++ b/groups-domains.php @@ -6,11 +6,19 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ require "scripts/pi-hole/php/header.php"; + $type = "all"; + $pagetitle = "Domain"; + $adjective = ""; + if (isset($_GET['type']) && ($_GET['type'] === "white" || $_GET['type'] === "black")) { + $type = $_GET['type']; + $pagetitle = ucfirst($type)."list"; + $adjective = $type."listed"; + } ?> @@ -20,7 +28,7 @@

- Add a new domain + Add a new domain

@@ -33,10 +41,17 @@
@@ -56,7 +71,7 @@

- List of configured domains + List of domains

diff --git a/list.php b/list.php deleted file mode 100644 index 95fbcd1a..00000000 --- a/list.php +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - -
-
- - -
-
- -
- - - - - - - -
-
-
- - - - - - - - - -
    - -
      - - - - diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index e48045e2..7e38d4b8 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -11,6 +11,7 @@ var table; var groups = []; var token = $("#token").html(); var GETDict = {}; +var showtype = "all"; function get_groups() { $.post( @@ -32,6 +33,10 @@ $(document).ready(function() { GETDict[item.split("=")[0]] = item.split("=")[1]; }); + if ("type" in GETDict && (GETDict.type === "white" || GETDict.type === "black")) { + showtype = GETDict.type; + } + $("#btnAdd").on("click", addDomain); get_groups(); @@ -46,7 +51,7 @@ function initTable() { table = $("#domainsTable").DataTable({ ajax: { url: "scripts/pi-hole/php/groups.php", - data: { action: "get_domains", token: token }, + data: { action: "get_domains", showtype: showtype, token: token }, type: "POST" }, order: [[0, "asc"]], @@ -74,20 +79,32 @@ function initTable() { '' + data.domain + "" ); - $("td:eq(1)", row).html( - '' + + whitelist_options + + blacklist_options + "" ); $("#type", row).on("change", editDomain); @@ -113,21 +130,30 @@ function initTable() { $("#comment", row).val(data.comment); $("#comment", row).on("change", editDomain); - $("td:eq(4)", row).empty(); - $("td:eq(4)", row).append(''); - var sel = $("#multiselect", row); - // Add all known groups - for (var i = 0; i < groups.length; i++) { - var extra = ""; - if (!groups[i].enabled) { - extra = " (disabled)"; + // Show group assignment field only if in full domain management mode + if (showtype === "all") { + $("td:eq(4)", row).empty(); + $("td:eq(4)", row).append(''); + var sel = $("#multiselect", row); + // Add all known groups + for (var i = 0; i < groups.length; i++) { + var extra = ""; + if (!groups[i].enabled) { + extra = " (disabled)"; + } + + sel.append( + $("
      class="active"> - + Whitelist class="active"> - + Blacklist diff --git a/scripts/pi-hole/php/sub.php b/scripts/pi-hole/php/sub.php deleted file mode 100644 index cdee3ceb..00000000 --- a/scripts/pi-hole/php/sub.php +++ /dev/null @@ -1,51 +0,0 @@ - From d584c2e2c2306a88d1f3774f0c1a3dfd96ce0f95 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 15 Feb 2020 18:18:46 +0100 Subject: [PATCH 02/10] Re-add add.php as it is used by the Query Log as well as the blocking page. Signed-off-by: DL6ER --- scripts/pi-hole/php/add.php | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 scripts/pi-hole/php/add.php diff --git a/scripts/pi-hole/php/add.php b/scripts/pi-hole/php/add.php new file mode 100644 index 00000000..1866ebed --- /dev/null +++ b/scripts/pi-hole/php/add.php @@ -0,0 +1,79 @@ + + From ef57abdbdd9ee6ab6249847a5d1ee025b5263dac Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 16 Feb 2020 07:59:07 +0100 Subject: [PATCH 03/10] Enhance wrapping for long regex lines on the domains list pages. Signed-off-by: DL6ER --- scripts/pi-hole/js/groups-domains.js | 2 +- style/pi-hole.css | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index 7e38d4b8..6f25da31 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -76,7 +76,7 @@ function initTable() { "\nDatabase ID: " + data.id; $("td:eq(0)", row).html( - '' + data.domain + "" + '' + data.domain + "" ); var whitelist_options = ""; diff --git a/style/pi-hole.css b/style/pi-hole.css index eb986c22..827e3788 100644 --- a/style/pi-hole.css +++ b/style/pi-hole.css @@ -242,4 +242,14 @@ td.highlight { background-color: yellow; -} \ No newline at end of file +} + +code.breakall +{ + white-space: -moz-pre-wrap; + white-space: -pre-wrap; + white-space: -o-pre-wrap; + white-space: pre-wrap; + word-break: break-all; + word-wrap: break-word; /* Internet Explorer 5.5+ */ +} From 0c1f3b3d143e2db7d6f0450702c85ad725ac990d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 16 Feb 2020 08:00:03 +0100 Subject: [PATCH 04/10] Depend display of group assigmnent delect field on number of visible columns. Signed-off-by: DL6ER --- scripts/pi-hole/js/groups-domains.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index 6f25da31..7bbf1ec3 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -131,7 +131,7 @@ function initTable() { $("#comment", row).on("change", editDomain); // Show group assignment field only if in full domain management mode - if (showtype === "all") { + if (table.column(5).visible()) { $("td:eq(4)", row).empty(); $("td:eq(4)", row).append(''); var sel = $("#multiselect", row); @@ -169,7 +169,7 @@ function initTable() { '">' + '' + ""; - if (showtype === "all") { + if (table.column(5).visible()) { $("td:eq(5)", row).html(button); } else { $("td:eq(4)", row).html(button); From ed24f5c41a9bbfcfbc2dbdad58b4742fc5b9cc89 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 16 Feb 2020 09:07:22 +0100 Subject: [PATCH 05/10] Enable visibility of overflow to table-responsive to ensure the group assignment dropdown doesn't get hidden when opened. Signed-off-by: DL6ER --- style/pi-hole.css | 1 + 1 file changed, 1 insertion(+) diff --git a/style/pi-hole.css b/style/pi-hole.css index b17a4a17..1aef8edd 100644 --- a/style/pi-hole.css +++ b/style/pi-hole.css @@ -72,6 +72,7 @@ .table-responsive { -webkit-overflow-scrolling: touch; + overflow: visible; } /* Optimize Queries-Table for small screens */ From 9248b1eaadc1b92c642894cb88860682bdcefa2c Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 16 Feb 2020 13:31:34 +0000 Subject: [PATCH 06/10] Make dropdown selection boxes scrollable Signed-off-by: Adam Warner --- style/pi-hole.css | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/style/pi-hole.css b/style/pi-hole.css index 1aef8edd..1f2a3c35 100644 --- a/style/pi-hole.css +++ b/style/pi-hole.css @@ -252,3 +252,9 @@ td.highlight { .pointer { cursor: pointer; } + +.multiselect-container{ + + max-height:200px; + overflow:auto; + } \ No newline at end of file From b5e77648ad14d778fe4711e9c6e7ad7ea2a8d2fe Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 16 Feb 2020 15:51:42 +0000 Subject: [PATCH 07/10] drop up instead of down if there are less than 200 px to the bottom of the screen Signed-off-by: Adam Warner --- scripts/pi-hole/js/groups-clients.js | 18 +++++++++++++++++- style/pi-hole.css | 8 +------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/scripts/pi-hole/js/groups-clients.js b/scripts/pi-hole/js/groups-clients.js index 71e0e585..c5a93224 100644 --- a/scripts/pi-hole/js/groups-clients.js +++ b/scripts/pi-hole/js/groups-clients.js @@ -120,7 +120,23 @@ function initTable() { // Select assigned groups sel.val(data.groups); // Initialize multiselect - sel.multiselect({ includeSelectAllOption: true }); + sel.multiselect({ + includeSelectAllOption: true, + buttonContainer: '
      ', + maxHeight: 200, + onDropdownShown: function() { + var el = $("#container" + data.id); + var top = el[0].getBoundingClientRect().top; + var bottom = $(window).height() - top - el.height(); + if (bottom < 200) { + el.addClass("dropup"); + } + + if (bottom > 200) { + el.removeClass("dropup"); + } + } + }); sel.on("change", editClient); var button = diff --git a/style/pi-hole.css b/style/pi-hole.css index 1f2a3c35..fa1600f7 100644 --- a/style/pi-hole.css +++ b/style/pi-hole.css @@ -251,10 +251,4 @@ td.highlight { .pointer { cursor: pointer; -} - -.multiselect-container{ - - max-height:200px; - overflow:auto; - } \ No newline at end of file +} \ No newline at end of file From a7a99ea69342b690af33edcdadb6708fde0f18ff Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 16 Feb 2020 16:10:14 +0000 Subject: [PATCH 08/10] update multiselects on other group pages with the same logic Signed-off-by: Adam Warner --- scripts/pi-hole/js/groups-adlists.js | 18 +++++++++++++++++- scripts/pi-hole/js/groups-domains.js | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/groups-adlists.js b/scripts/pi-hole/js/groups-adlists.js index f16e1bc5..96b0316e 100644 --- a/scripts/pi-hole/js/groups-adlists.js +++ b/scripts/pi-hole/js/groups-adlists.js @@ -108,7 +108,23 @@ function initTable() { // Select assigned groups sel.val(data.groups); // Initialize multiselect - sel.multiselect({ includeSelectAllOption: true }); + sel.multiselect({ + includeSelectAllOption: true, + buttonContainer: '
      ', + maxHeight: 200, + onDropdownShown: function() { + var el = $("#container" + data.id); + var top = el[0].getBoundingClientRect().top; + var bottom = $(window).height() - top - el.height(); + if (bottom < 200) { + el.addClass("dropup"); + } + + if (bottom > 200) { + el.removeClass("dropup"); + } + } + }); sel.on("change", editAdlist); var button = diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index e48045e2..dbf0d1f1 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -140,7 +140,23 @@ function initTable() { // Select assigned groups sel.val(data.groups); // Initialize multiselect - sel.multiselect({ includeSelectAllOption: true }); + sel.multiselect({ + includeSelectAllOption: true, + buttonContainer: '
      ', + maxHeight: 200, + onDropdownShown: function() { + var el = $("#container" + data.id); + var top = el[0].getBoundingClientRect().top; + var bottom = $(window).height() - top - el.height(); + if (bottom < 200) { + el.addClass("dropup"); + } + + if (bottom > 200) { + el.removeClass("dropup"); + } + } + }); sel.on("change", editDomain); var button = From 211bcc999f4a140f540884c6e2d43df70b384b63 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 16 Feb 2020 17:33:52 +0000 Subject: [PATCH 09/10] Whejn dropdown is shown, move it outside of the datatable container (at the same absolute position) When it is closed, put it back where it came from Signed-off-by: Adam Warner --- scripts/pi-hole/js/groups-adlists.js | 18 +++++++++++++++++- scripts/pi-hole/js/groups-clients.js | 18 +++++++++++++++++- scripts/pi-hole/js/groups-domains.js | 18 +++++++++++++++++- style/pi-hole.css | 1 - 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/scripts/pi-hole/js/groups-adlists.js b/scripts/pi-hole/js/groups-adlists.js index 96b0316e..0c5bc604 100644 --- a/scripts/pi-hole/js/groups-adlists.js +++ b/scripts/pi-hole/js/groups-adlists.js @@ -89,7 +89,11 @@ function initTable() { comment.on("change", editAdlist); $("td:eq(3)", row).empty(); - $("td:eq(3)", row).append(''); + $("td:eq(3)", row).append( + '
      ' + ); var sel = $("#multiselect", row); // Add all known groups for (var i = 0; i < groups.length; i++) { @@ -123,6 +127,18 @@ function initTable() { if (bottom > 200) { el.removeClass("dropup"); } + + var offset = el.offset(); + $("body").append(el); + el.css("position", "absolute"); + el.css("top", offset.top + "px"); + el.css("left", offset.left + "px"); + }, + onDropdownHide: function() { + var el = $("#container" + data.id); + var home = $("#selectHome" + data.id); + home.append(el); + el.removeAttr("style"); } }); sel.on("change", editAdlist); diff --git a/scripts/pi-hole/js/groups-clients.js b/scripts/pi-hole/js/groups-clients.js index c5a93224..14d9323e 100644 --- a/scripts/pi-hole/js/groups-clients.js +++ b/scripts/pi-hole/js/groups-clients.js @@ -101,7 +101,11 @@ function initTable() { $("td:eq(0)", row).html(ip_name); $("td:eq(1)", row).empty(); - $("td:eq(1)", row).append(''); + $("td:eq(1)", row).append( + '
      ' + ); var sel = $("#multiselect", row); // Add all known groups for (var i = 0; i < groups.length; i++) { @@ -135,6 +139,18 @@ function initTable() { if (bottom > 200) { el.removeClass("dropup"); } + + var offset = el.offset(); + $("body").append(el); + el.css("position", "absolute"); + el.css("top", offset.top + "px"); + el.css("left", offset.left + "px"); + }, + onDropdownHide: function() { + var el = $("#container" + data.id); + var home = $("#selectHome" + data.id); + home.append(el); + el.removeAttr("style"); } }); sel.on("change", editClient); diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index dbf0d1f1..ee3b1b7f 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -114,7 +114,11 @@ function initTable() { $("#comment", row).on("change", editDomain); $("td:eq(4)", row).empty(); - $("td:eq(4)", row).append(''); + $("td:eq(4)", row).append( + '
      ' + ); var sel = $("#multiselect", row); // Add all known groups for (var i = 0; i < groups.length; i++) { @@ -155,6 +159,18 @@ function initTable() { if (bottom > 200) { el.removeClass("dropup"); } + + var offset = el.offset(); + $("body").append(el); + el.css("position", "absolute"); + el.css("top", offset.top + "px"); + el.css("left", offset.left + "px"); + }, + onDropdownHide: function() { + var el = $("#container" + data.id); + var home = $("#selectHome" + data.id); + home.append(el); + el.removeAttr("style"); } }); sel.on("change", editDomain); diff --git a/style/pi-hole.css b/style/pi-hole.css index fa1600f7..d116a8a2 100644 --- a/style/pi-hole.css +++ b/style/pi-hole.css @@ -72,7 +72,6 @@ .table-responsive { -webkit-overflow-scrolling: touch; - overflow: visible; } /* Optimize Queries-Table for small screens */ From 7274b9bca70e0617b0215d6146b2c99f136e3ccc Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 16 Feb 2020 21:16:06 +0100 Subject: [PATCH 10/10] Only use IDN subroutines when the module is available. We have seen reports that at least DietPi is having issues with not matching PHP base and extension versions. Signed-off-by: DL6ER --- scripts/pi-hole/php/add.php | 3 ++- scripts/pi-hole/php/groups.php | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/pi-hole/php/add.php b/scripts/pi-hole/php/add.php index 1eb6b8d1..147dd355 100644 --- a/scripts/pi-hole/php/add.php +++ b/scripts/pi-hole/php/add.php @@ -22,7 +22,8 @@ $comment = trim($_POST['comment']); // Convert domain name to IDNA ASCII form for international domains // Do this only for exact domains, not for regex filters -if ($list === "white" || $list === "black") { +// Only do it when the php-intl extension is available +if (extension_loaded("intl") && ($list === "white" || $list === "black")) { foreach($domains as &$domain) { $domain = idn_to_ascii($domain); diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index 00f5268c..ad606110 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -352,10 +352,12 @@ if ($_POST['action'] == 'get_groups') { array_push($groups, $gres['group_id']); } $res['groups'] = $groups; - if ($res['type'] === ListType::whitelist || $res['type'] === ListType::blacklist) { + if (extension_loaded("intl") && + ($res['type'] === ListType::whitelist || + $res['type'] === ListType::blacklist) ) { $utf8_domain = idn_to_utf8($res['domain']); // Convert domain name to international form - // if applicable + // if applicable and extension is available if($res['domain'] !== $utf8_domain) { $res['domain'] = $utf8_domain.' ('.$res['domain'].')'; @@ -389,7 +391,11 @@ if ($_POST['action'] == 'get_groups') { if ($type === ListType::whitelist || $type === ListType::blacklist) { // Convert domain name to IDNA ASCII form for international // domains and convert the domain to lower case - $domain = strtolower(idn_to_ascii($domain)); + // Only use IDN routine when php-intl is available + if (extension_loaded("intl")) { + $domain = idn_to_ascii($domain); + } + $domain = strtolower($domain); // Check validity of domain if(filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) === false)