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