From 2d975b8bacf54e0dbc969da68b8cb09a1ca78209 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 14 Feb 2020 20:21:01 +0100 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 4/4] 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);