Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dedicated black/whitelist pages + redesign menu #2266

Merged
merged 7 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion groups-adlists.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<div class="box" id="adlists-list">
<div class="box-header with-border">
<h3 class="box-title">
List of configured adlists
List of adlists
</h3>
</div>
<!-- /.box-header -->
Expand Down
25 changes: 5 additions & 20 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,23 +84,16 @@
<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" ) { ?>
<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>
<?php } ?>
</div>
</div>
<!-- /.box-body -->
Expand All @@ -123,7 +108,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 domains
</h3>
</div>
<!-- /.box-header -->
Expand Down
2 changes: 1 addition & 1 deletion groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<div class="box" id="groups-list">
<div class="box-header with-border">
<h3 class="box-title">
List of configured groups
List of groups
</h3>
</div>
<!-- /.box-header -->
Expand Down
6 changes: 3 additions & 3 deletions scripts/pi-hole/js/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ function countDown() {

//Stop and remove timer when user enabled early
if ($("#pihole-enable").is(":hidden")) {
ena.text("Enable");
ena.text("Enable Blocking");
return;
}

if (seconds > 0) {
setTimeout(countDown, 1000);
ena.text("Enable (" + secondsTimeSpanToHMS(seconds) + ")");
ena.text("Enable Blocking (" + secondsTimeSpanToHMS(seconds) + ")");
} else {
ena.text("Enable");
ena.text("Enable Blocking");
piholeChanged("enabled");
if (localStorage) {
localStorage.removeItem("countDownTarget");
Expand Down
171 changes: 72 additions & 99 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,10 +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 () {
var tabHref = $(this).attr("href");
Expand Down Expand Up @@ -116,7 +111,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 +122,7 @@ function initTable() {
{ data: "type", searchable: false },
{ data: "enabled", searchable: false },
{ data: "comment" },
{ data: "groups", searchable: false, visible: showtype === "all" },
{ data: "groups", searchable: false },
{ data: null, width: "22px", orderable: false },
],
columnDefs: [
Expand Down Expand Up @@ -171,34 +166,23 @@ 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 +
">Regex blacklist</option>" +
"</select>"
);
var typeEl = $("#type_" + data.id, row);
Expand All @@ -223,79 +207,78 @@ function initTable() {
commentEl.val(utils.unescapeHtml(data.comment));
commentEl.on("change", editDomain);

// Show group assignment field only if in full domain management mode
if (table.column(6).visible()) {
$("td:eq(5)", row).empty();
$("td:eq(5)", row).append(
'<select class="selectpicker" id="multiselect_' + data.id + '" multiple></select>'
);
var selectEl = $("#multiselect_" + data.id, row);
// Add all known groups
for (var i = 0; i < groups.length; i++) {
var dataSub = "";
if (!groups[i].enabled) {
dataSub = 'data-subtext="(disabled)"';
}

selectEl.append(
$("<option " + dataSub + "/>")
.val(groups[i].id)
.text(groups[i].name)
);
// Group assignment field
$("td:eq(5)", row).empty();
$("td:eq(5)", row).append(
'<select class="selectpicker" id="multiselect_' + data.id + '" multiple></select>'
);
var selectEl = $("#multiselect_" + data.id, row);
// Add all known groups
for (var i = 0; i < groups.length; i++) {
var dataSub = "";
if (!groups[i].enabled) {
dataSub = 'data-subtext="(disabled)"';
}

// Select assigned groups
selectEl.val(data.groups);
// Initialize bootstrap-select
selectEl
// fix dropdown if it would stick out right of the viewport
.on("show.bs.select", function () {
var winWidth = $(window).width();
var dropdownEl = $("body > .bootstrap-select.dropdown");
if (dropdownEl.length > 0) {
dropdownEl.removeClass("align-right");
var width = dropdownEl.width();
var left = dropdownEl.offset().left;
if (left + width > winWidth) {
dropdownEl.addClass("align-right");
}
}
})
.on("changed.bs.select", function () {
// enable Apply button
if ($(applyBtn).prop("disabled")) {
$(applyBtn)
.addClass("btn-success")
.prop("disabled", false)
.on("click", function () {
editDomain.call(selectEl);
});
}
})
.on("hide.bs.select", function () {
// Restore values if drop-down menu is closed without clicking the Apply button
if (!$(applyBtn).prop("disabled")) {
$(this).val(data.groups).selectpicker("refresh");
$(applyBtn).removeClass("btn-success").prop("disabled", true).off("click");
}
})
.selectpicker()
.siblings(".dropdown-menu")
.find(".bs-actionsbox")
.prepend(
'<button type="button" id=btn_apply_' +
data.id +
' class="btn btn-block btn-sm" disabled>Apply</button>'
);
selectEl.append(
$("<option " + dataSub + "/>")
.val(groups[i].id)
.text(groups[i].name)
);
}

// Select assigned groups
selectEl.val(data.groups);
// Initialize bootstrap-select
selectEl
// fix dropdown if it would stick out right of the viewport
.on("show.bs.select", function () {
var winWidth = $(window).width();
var dropdownEl = $("body > .bootstrap-select.dropdown");
if (dropdownEl.length > 0) {
dropdownEl.removeClass("align-right");
var width = dropdownEl.width();
var left = dropdownEl.offset().left;
if (left + width > winWidth) {
dropdownEl.addClass("align-right");
}
}
})
.on("changed.bs.select", function () {
// enable Apply button
if ($(applyBtn).prop("disabled")) {
$(applyBtn)
.addClass("btn-success")
.prop("disabled", false)
.on("click", function () {
editDomain.call(selectEl);
});
}
})
.on("hide.bs.select", function () {
// Restore values if drop-down menu is closed without clicking the Apply button
if (!$(applyBtn).prop("disabled")) {
$(this).val(data.groups).selectpicker("refresh");
$(applyBtn).removeClass("btn-success").prop("disabled", true).off("click");
}
})
.selectpicker()
.siblings(".dropdown-menu")
.find(".bs-actionsbox")
.prepend(
'<button type="button" id=btn_apply_' +
data.id +
' class="btn btn-block btn-sm" disabled>Apply</button>'
);

var applyBtn = "#btn_apply_" + data.id;

// Highlight row (if url parameter "domainid=" is used)
if ("domainid" in GETDict && data.id === parseInt(GETDict.domainid, 10)) {
$(row).find("td").addClass("highlight");
}

// Add delete domain button
var button =
'<button type="button" class="btn btn-danger btn-xs" id="deleteDomain_' +
data.id +
Expand All @@ -304,11 +287,7 @@ function initTable() {
'">' +
'<span class="far fa-trash-alt"></span>' +
"</button>";
if (table.column(6).visible()) {
$("td:eq(6)", row).html(button);
} else {
$("td:eq(5)", row).html(button);
}
$("td:eq(6)", row).html(button);
},
select: {
style: "multi",
Expand Down Expand Up @@ -379,8 +358,6 @@ 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";
// Apply loaded state to table
return data;
},
Expand Down Expand Up @@ -588,11 +565,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
Loading