Skip to content

Commit

Permalink
Remove black/whitelist from group pages
Browse files Browse the repository at this point in the history
Signed-off-by: Christian König <ckoenig@posteo.de>
  • Loading branch information
yubiuser committed Jul 16, 2022
1 parent f8e25e1 commit 96866fa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 73 deletions.
25 changes: 6 additions & 19 deletions groups-domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@
* 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";
}
?>

<!-- Title -->
<div class="page-header">
<h1><?php echo $pagetitle; ?> management</h1>
<h1>Domain management</h1>
</div>

<!-- Domain Input -->
Expand All @@ -27,7 +19,7 @@
<div class="box" id="add-group">
<div class="box-header with-border">
<h3 class="box-title">
Add a new <?php echo $adjective; ?> domain or regex filter
Add a new domain or regex filter
</h3>
</div>
<!-- /.box-header -->
Expand Down Expand Up @@ -92,19 +84,14 @@
<div>
<p><strong>Note:</strong><br>
The domain or regex filter will be automatically assigned to the Default Group.<br>
Other groups can optionally be assigned
<?php if ($type === "white" || $type === "black") { ?>
within <a href="groups-domains.php">Group Management > Domains</a>.
<?php } else {?>
in the list below (using <b>Group assignment</b>).
<?php } ?></p>
Other groups can optionally be assigned in the list below (using <b>Group assignment</b>).
</p>
</div>
<div class="btn-toolbar pull-right" role="toolbar" aria-label="Toolbar with buttons">
<?php if ( $type !== "white" ) { ?>
<?php { ?>
<div class="btn-group" role="group" aria-label="Third group">
<button type="button" class="btn btn-primary" id="add2black">Add to Blacklist</button>
</div>
<?php } if ( $type !== "black" ) { ?>
<div class="btn-group" role="group" aria-label="Third group">
<button type="button" class="btn btn-primary" id="add2white">Add to Whitelist</button>
</div>
Expand All @@ -123,7 +110,7 @@
<div class="box" id="domains-list">
<div class="box-header with-border">
<h3 class="box-title">
List of <?php echo $adjective; ?> entries
List of configured domains
</h3>
</div>
<!-- /.box-header -->
Expand Down
45 changes: 13 additions & 32 deletions scripts/pi-hole/js/groups-domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var table;
var groups = [];
var token = $("#token").text();
var GETDict = {};
var showtype = "all";

function getGroups() {
$.post(
Expand All @@ -33,9 +32,6 @@ $(function () {
GETDict[item.split("=")[0]] = item.split("=")[1];
});

if ("type" in GETDict && (GETDict.type === "white" || GETDict.type === "black")) {
showtype = GETDict.type;
}

// sync description fields, reset inactive inputs on tab change
$('a[data-toggle="tab"]').on("shown.bs.tab", function () {
Expand Down Expand Up @@ -116,7 +112,7 @@ function initTable() {
table = $("#domainsTable").DataTable({
ajax: {
url: "scripts/pi-hole/php/groups.php",
data: { action: "get_domains", showtype: showtype, token: token },
data: { action: "get_domains", token: token },
type: "POST",
},
order: [[0, "asc"]],
Expand All @@ -127,7 +123,7 @@ function initTable() {
{ data: "type", searchable: false },
{ data: "enabled", searchable: false },
{ data: "comment" },
{ data: "groups", searchable: false, visible: showtype === "all" },
{ data: "groups", searchable: false, visible: true },
{ data: null, width: "22px", orderable: false },
],
columnDefs: [
Expand Down Expand Up @@ -171,35 +167,24 @@ function initTable() {
"</code>"
);

var whitelistOptions = "";
if (showtype === "all" || showtype === "white") {
whitelistOptions =
// Drop-down type selector
$("td:eq(2)", row).html(
'<select id="type_' +
data.id +
'" class="form-control">' +
'<option value="0"' +
(data.type === 0 ? " selected" : "") +
">Exact whitelist</option>" +
'<option value="2"' +
(data.type === 2 ? " selected" : "") +
">Regex whitelist</option>";
}

var blacklistOptions = "";
if (showtype === "all" || showtype === "black") {
blacklistOptions =
">Regex whitelist</option>" +
'<option value="1"' +
(data.type === 1 ? " selected " : " ") +
">Exact blacklist</option>" +
'<option value="3"' +
(data.type === 3 ? " selected" : "") +
">Regex blacklist</option>";
}

$("td:eq(2)", row).html(
'<select id="type_' +
data.id +
'" class="form-control">' +
whitelistOptions +
blacklistOptions +
"</select>"
">Regex blacklist</option>" +
"</select>"
);
var typeEl = $("#type_" + data.id, row);
typeEl.on("change", editDomain);
Expand Down Expand Up @@ -379,8 +364,8 @@ function initTable() {

// Reset visibility of ID column
data.columns[0].visible = false;
// Show group assignment column only on full page
data.columns[6].visible = showtype === "all";
// Show group assignment
data.columns[6].visible = true;
// Apply loaded state to table
return data;
},
Expand Down Expand Up @@ -588,11 +573,7 @@ function editDomain() {
var type = tr.find("#type_" + id).val();
var status = tr.find("#status_" + id).is(":checked") ? 1 : 0;
var comment = utils.escapeHtml(tr.find("#comment_" + id).val());

// Show group assignment field only if in full domain management mode
// if not included, just use the row data.
var rowData = table.row(tr).data();
var groups = table.column(6).visible() ? tr.find("#multiselect_" + id).val() : rowData.groups;
var groups = tr.find("#multiselect_" + id).val();

var domainRegex;
if (type === "0" || type === "1") {
Expand Down
6 changes: 1 addition & 5 deletions scripts/pi-hole/php/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,7 @@ function verify_ID_array($arr)
// List all available groups
try {
$limit = "";
if (isset($_POST["showtype"]) && $_POST["showtype"] === "white"){
$limit = " WHERE type = 0 OR type = 2";
} elseif (isset($_POST["showtype"]) && $_POST["showtype"] === "black"){
$limit = " WHERE type = 1 OR type = 3";
} elseif (isset($_POST["type"]) && is_numeric($_POST["type"])){
if (isset($_POST["type"]) && is_numeric($_POST["type"])){
$limit = " WHERE type = " . $_POST["type"];
}
$query = $db->query('SELECT * FROM domainlist'.$limit);
Expand Down
17 changes: 0 additions & 17 deletions scripts/pi-hole/php/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,23 +386,6 @@ function pidofFTL()
</div>
</div>
<!-- sidebar menu: : style can be found in sidebar.less -->
<?php
if($scriptname === "groups-domains.php" && isset($_GET['type']))
{
if($_GET["type"] === "white")
{
$scriptname = "whitelist";
}
elseif($_GET["type"] === "black")
{
$scriptname = "blacklist";
}
}
if(!$auth && (!isset($indexpage) || isset($_GET['login'])))
{
$scriptname = "login";
}
?>
<ul class="sidebar-menu" data-widget="tree">
<li class="header text-uppercase">Main</li>
<!-- Home Page -->
Expand Down

0 comments on commit 96866fa

Please sign in to comment.