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 <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2020-02-14 20:21:01 +01:00
parent 843e46d84a
commit 2d975b8bac
9 changed files with 98 additions and 629 deletions

View File

@@ -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";
}
?>
<!-- Title -->
<div class="page-header">
<h1>Domain group management</h1>
<h1><?php echo $pagetitle; ?> management</h1>
</div>
<!-- Domain Input -->
@@ -20,7 +28,7 @@
<!-- /.box-header -->
<div class="box-header with-border">
<h3 class="box-title">
Add a new domain
Add a new <?php echo $adjective; ?> domain
</h3>
</div>
<!-- /.box-header -->
@@ -33,10 +41,17 @@
<div class="col-md-2">
<label for="ex2">Type:</label>
<select id="new_type" class="form-control">
<option value="0">Exact whitelist</option>
<option value="1">Exact blacklist</option>
<option value="2">Regex whitelist</option>
<option value="3">Regex blacklist</option>
<?php if($type === "all" || $type === "white") { ?>
<option value="0">Exact whitelist</option>
<option value="2">Regex whitelist</option>
<?php } if($type === "white") { ?>
<option value="2W">Wildcard whitelist</option>
<?php } if($type === "all" || $type === "black") { ?>
<option value="1">Exact blacklist</option>
<option value="3">Regex blacklist</option>
<?php } if($type === "black") { ?>
<option value="3W">Wildcard blacklist</option>
<?php } ?>
</select>
</div>
<div class="col-md-4">
@@ -56,7 +71,7 @@
<div class="box" id="domains-list">
<div class="box-header with-border">
<h3 class="box-title">
List of configured domains
List of <?php echo $adjective; ?> domains
</h3>
</div>
<!-- /.box-header -->

View File

@@ -1,84 +0,0 @@
<?php /*
* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* 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";
$list = isset($_GET['l']) ? $_GET['l'] : '';
if ($list == "white")
{
$listtitle = "Whitelist";
$heading = "whitelisting";
}
elseif ($list == "black")
{
$listtitle = "Blacklist";
$heading = "blocking";
}
else
{
echo "Invalid list parameter ".$list;
require "scripts/pi-hole/php/footer.php";
die();
}
?>
<!-- Send list type to JS -->
<div id="list-type" hidden><?php echo $list ?></div>
<!-- Title -->
<div class="page-header">
<h1><?php echo $listtitle; ?></h1>
</div>
<div class="row">
<div class="col-md-6">
<label for="ex1">Domain:</label>
<input id="domain" type="text" class="form-control" placeholder="Add a domain (example.com)">
</div>
<div class="col-md-6">
<label for="ex2">Comment:</label>
<div class="form-group input-group">
<input id="comment" type="text" class="form-control" placeholder="Include a comment (optional)">
<span class="input-group-btn">
<button id="btnAdd" class="btn btn-default" type="button">Add (exact)</button>
<button id="btnAddWildcard" class="btn btn-default" type="button">Add (wildcard)</button>
<button id="btnAddRegex" class="btn btn-default" type="button">Add (regex)</button>
<button id="btnRefresh" class="btn btn-default" type="button"><i class="fa fa-sync"></i></button>
</span>
</div>
</div>
</div>
<!-- Alerts -->
<div id="alInfo" class="alert alert-info alert-dismissible fade in" role="alert" hidden="true">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Adding to the <?php echo $listtitle; ?>...
</div>
<div id="alSuccess" class="alert alert-success alert-dismissible fade in" role="alert" hidden="true">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<span id="success-message"></span>
</div>
<div id="alFailure" class="alert alert-danger alert-dismissible fade in" role="alert" hidden="true">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Failure! Something went wrong, see output below:<br/><br/><pre><span id="err"></span></pre>
</div>
<div id="alWarning" class="alert alert-warning alert-dismissible fade in" role="alert" hidden="true">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
At least one domain was already present, see output below:<br/><br/><pre><span id="warn"></span></pre>
</div>
<!-- Domain List -->
<h3 id="h3-exact" hidden="true">Exact <?php echo $heading; ?></h3>
<ul class="list-group" id="list"></ul>
<h3 id="h3-regex" hidden="true"><a href="https://docs.pi-hole.net/ftldns/regex/overview/" rel="noopener" target="_blank" title="Click for Pi-hole Regex documentation">Regex</a> &amp; Wildcard <?php echo $heading; ?></h3>
<ul class="list-group" id="list-regex"></ul>
<script src="scripts/pi-hole/js/list.js"></script>
<?php
require "scripts/pi-hole/php/footer.php";
?>

View File

@@ -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() {
'<code id="domain" title="' + tooltip + '">' + data.domain + "</code>"
);
$("td:eq(1)", row).html(
'<select id="type" class="form-control">' +
var whitelist_options = "";
if (showtype === "all" || showtype === "white") {
whitelist_options =
'<option value="0"' +
(data.type === 0 ? " selected" : "") +
">Exact whitelist</option>" +
'<option value="1"' +
(data.type === 1 ? " selected" : "") +
">Exact blacklist</option>" +
'<option value="2"' +
(data.type === 2 ? " selected" : "") +
">Regex whitelist</option>" +
">Regex whitelist</option>";
}
var blacklist_options = "";
if (showtype === "all" || showtype === "black") {
blacklist_options =
'<option value="1"' +
(data.type === 1 ? " selected " : " ") +
">Exact blacklist</option>" +
'<option value="3"' +
(data.type === 3 ? " selected" : "") +
">Regex blacklist</option>" +
">Regex blacklist</option>";
}
$("td:eq(1)", row).html(
'<select id="type" class="form-control">' +
whitelist_options +
blacklist_options +
"</select>"
);
$("#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('<select id="multiselect" multiple="multiple"></select>');
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('<select id="multiselect" multiple="multiple"></select>');
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(
$("<option />")
.val(groups[i].id)
.text(groups[i].name + extra)
);
}
sel.append(
$("<option />")
.val(groups[i].id)
.text(groups[i].name + extra)
);
// Select assigned groups
sel.val(data.groups);
// Initialize multiselect
sel.multiselect({ includeSelectAllOption: true });
sel.on("change", editDomain);
}
// Highlight row
@@ -137,19 +163,17 @@ function initTable() {
.addClass("highlight");
}
// Select assigned groups
sel.val(data.groups);
// Initialize multiselect
sel.multiselect({ includeSelectAllOption: true });
sel.on("change", editDomain);
var button =
'<button class="btn btn-danger btn-xs deleteDomain" type="button" data-id="' +
data.id +
'">' +
'<span class="glyphicon glyphicon-trash"></span>' +
"</button>";
$("td:eq(5)", row).html(button);
if (showtype === "all") {
$("td:eq(5)", row).html(button);
} else {
$("td:eq(4)", row).html(button);
}
},
dom:
"<'row'<'col-sm-4'l><'col-sm-8'f>>" +
@@ -179,6 +203,8 @@ function initTable() {
data.search.search = "";
// Reset visibility of ID column
data.columns[0].visible = false;
// Show group assignment column only on full page
data.columns[5].visible = showtype === "all";
// Apply loaded state to table
return data;
},

View File

@@ -1,287 +0,0 @@
/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
// IE likes to cache too much :P
$.ajaxSetup({ cache: false });
// Get PHP info
var token = $("#token").text();
var listType = $("#list-type").html();
var fullName = listType === "white" ? "Whitelist" : "Blacklist";
function addListEntry(entry, index, list, button, type) {
var disabled = [];
if (entry.enabled === "0") disabled.push("individual");
// For entry.group_enabled we either get "0" (= disabled by a group),
// "1" (= enabled by a group), or "" (= not managed by a group)
if (entry.group_enabled === "0") disabled.push("group");
var used = disabled.length === 0 ? "used" : "not-used";
var comment = entry.comment.length > 0 ? "&nbsp;-&nbsp;" + entry.comment : "";
var disabled_message =
disabled.length > 0 ? "&nbsp;-&nbsp;disabled due to " + disabled.join(" + ") + " setting" : "";
var date_added = new Date(parseInt(entry.date_added) * 1000);
var date_modified = new Date(parseInt(entry.date_modified) * 1000);
var tooltip =
"Added: " + date_added.toLocaleString() + "\nModified: " + date_modified.toLocaleString();
list.append(
'<li id="' +
index +
'" class="list-group-item ' +
used +
' clearfix">' +
'<span title="' +
tooltip +
'" data-toggle="tooltip" data-placement="right">' +
entry.domain +
comment +
disabled_message +
"</span>" +
'<button class="btn btn-danger btn-xs pull-right" type="button">' +
'<span class="glyphicon glyphicon-trash"></span></button></li>'
);
// Handle button
$(button + " #" + index).on("click", "button", function() {
sub(index, entry.domain, type);
});
}
function refresh(fade) {
var list = $("#list");
var listw = $("#list-regex");
if (fade) {
list.fadeOut(100);
listw.fadeOut(100);
}
$.ajax({
url: "scripts/pi-hole/php/get.php",
method: "get",
data: { list: listType },
success: function(response) {
list.html("");
listw.html("");
if (
(listType === "black" &&
response.blacklist.length === 0 &&
response.regex_blacklist.length === 0) ||
(listType === "white" &&
response.whitelist.length === 0 &&
response.regex_whitelist.length === 0)
) {
$("h3").hide();
list.html(
'<div class="alert alert-info" role="alert">Your ' + fullName + " is empty!</div>"
);
} else {
var data, data2;
if (listType === "white") {
data = response.whitelist.sort();
data2 = response.regex_whitelist.sort();
} else if (listType === "black") {
data = response.blacklist.sort();
data2 = response.regex_blacklist.sort();
}
if (data.length > 0) {
$("#h3-exact").fadeIn(100);
}
if (data2.length > 0) {
$("#h3-regex").fadeIn(100);
}
data.forEach(function(entry, index) {
addListEntry(entry, index, list, "#list", "exact");
});
data2.forEach(function(entry, index) {
addListEntry(entry, index, listw, "#list-regex", listType + "_regex");
});
}
list.fadeIn(100);
listw.fadeIn(100);
},
error: function() {
$("#alFailure").show();
}
});
}
window.addEventListener("load", refresh(false));
function sub(index, entry, arg) {
var list = "#list";
var heading = "#h3-exact";
var locallistType = listType;
if (arg === "black_regex" || arg === "white_regex") {
list = "#list-regex";
heading = "#h3-regex";
locallistType = arg;
}
var alInfo = $("#alInfo");
var alSuccess = $("#alSuccess");
var alFailure = $("#alFailure");
var err = $("#err");
var msg = $("#success-message");
var domain = $(list + " #" + index);
domain.hide("highlight");
$.ajax({
url: "scripts/pi-hole/php/sub.php",
method: "post",
data: { domain: entry, list: locallistType, token: token },
success: function(response) {
if (response.indexOf("Success") === -1) {
alFailure.show();
err.html(response);
alFailure.delay(8000).fadeOut(2000, function() {
alFailure.hide();
});
alInfo.delay(8000).fadeOut(2000, function() {
alInfo.hide();
});
} else {
alSuccess.show();
msg.html(response);
alSuccess.delay(1000).fadeOut(2000, function() {
alSuccess.hide();
});
alInfo.delay(1000).fadeOut(2000, function() {
alInfo.hide();
});
domain.remove();
if ($(list + " li").length === 0) {
$(heading).fadeOut(100);
}
}
},
error: function() {
alert("Failed to remove the domain!");
domain.show({ queue: true });
}
});
}
function add(type) {
var domain = $("#domain");
if (domain.val().length === 0) {
return;
}
var comment = $("#comment");
var alInfo = $("#alInfo");
var alSuccess = $("#alSuccess");
var alFailure = $("#alFailure");
var alWarning = $("#alWarning");
var err = $("#err");
var msg = $("#success-message");
alInfo.show();
alSuccess.hide();
alFailure.hide();
alWarning.hide();
$.ajax({
url: "scripts/pi-hole/php/add.php",
method: "post",
data: { domain: domain.val().trim(), comment: comment.val(), list: type, token: token },
success: function(response) {
if (response.indexOf("Success") === -1) {
alFailure.show();
err.html(response);
alFailure.delay(8000).fadeOut(2000, function() {
alFailure.hide();
});
alInfo.delay(8000).fadeOut(2000, function() {
alInfo.hide();
});
} else {
alSuccess.show();
msg.html(response);
alSuccess.delay(1000).fadeOut(2000, function() {
alSuccess.hide();
});
alInfo.delay(1000).fadeOut(2000, function() {
alInfo.hide();
});
domain.val("");
comment.val("");
refresh(true);
}
},
error: function() {
alFailure.show();
err.html("");
alFailure.delay(1000).fadeOut(2000, function() {
alFailure.hide();
});
alInfo.delay(1000).fadeOut(2000, function() {
alInfo.hide();
});
}
});
}
// Handle enter button for adding domains
$(document).keypress(function(e) {
if (e.which === 13 && $("#domain,#comment").is(":focus")) {
// Enter was pressed, and the input has focus
add(listType);
}
});
// Handle buttons
$("#btnAdd").on("click", function() {
add(listType);
});
$("#btnAddWildcard").on("click", function() {
add(listType + "_wild");
});
$("#btnAddRegex").on("click", function() {
add(listType + "_regex");
});
$("#btnRefresh").on("click", function() {
refresh(true);
});
// Handle hiding of alerts
$(function() {
$("[data-hide]").on("click", function() {
$(this)
.closest("." + $(this).attr("data-hide"))
.hide();
});
});
// Wrap form-group's buttons to next line when viewed on a small screen
$(window).on("resize", function() {
if ($(window).width() < 991) {
$(".form-group.input-group")
.removeClass("input-group")
.addClass("input-group-block");
$(".form-group.input-group-block > input").css("margin-bottom", "5px");
$(".form-group.input-group-block > .input-group-btn")
.removeClass("input-group-btn")
.addClass("btn-block text-center");
} else {
$(".form-group.input-group-block")
.removeClass("input-group-block")
.addClass("input-group");
$(".form-group.input-group > input").css("margin-bottom", "");
$(".form-group.input-group > .btn-block.text-center")
.removeClass("btn-block text-center")
.addClass("input-group-btn");
}
});
$(document).ready(function() {
$(window).trigger("resize");
});

View File

@@ -1,78 +0,0 @@
<?php
/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
require_once('auth.php');
$list = $_POST['list'];
// Perform all of the authentication for list editing
// when NOT invoked and authenticated from API
if (empty($api)) {
list_verify($list);
}
// Split individual domains into array
$domains = preg_split('/\s+/', trim($_POST['domain']));
$comment = trim($_POST['comment']);
// Convert domain name to IDNA ASCII form for international domains
foreach($domains as &$domain)
{
$domain = idn_to_ascii($domain);
}
// Only check domains we add to the exact lists.
// Regex are validated by FTL during import
$check_lists = ["white","black","audit"];
if(in_array($list, $check_lists)) {
check_domain($domains);
}
require_once("func.php");
require_once("database.php");
$GRAVITYDB = getGravityDBFilename();
$db = SQLite3_connect($GRAVITYDB, SQLITE3_OPEN_READWRITE);
switch($list) {
case "white":
$domains = array_map('strtolower', $domains);
echo add_to_table($db, "domainlist", $domains, $comment, false, false, ListType::whitelist);
break;
case "black":
$domains = array_map('strtolower', $domains);
echo add_to_table($db, "domainlist", $domains, $comment, false, false, ListType::blacklist);
break;
case "white_regex":
echo add_to_table($db, "domainlist", $domains, $comment, false, false, ListType::regex_whitelist);
break;
case "white_wild":
echo add_to_table($db, "domainlist", $domains, $comment, true, false, ListType::regex_whitelist);
break;
case "black_regex":
echo add_to_table($db, "domainlist", $domains, $comment, false, false, ListType::regex_blacklist);
break;
case "black_wild":
echo add_to_table($db, "domainlist", $domains, $comment, true, false, ListType::regex_blacklist);
break;
case "audit":
echo add_to_table($db, "domain_audit", $domains, $comment);
break;
default:
die("Invalid list!");
}
// Reload lists in pihole-FTL after having added something
echo shell_exec("sudo pihole restartdns reload");
?>

View File

@@ -1,85 +0,0 @@
<?php
/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
if(!isset($_GET['list']))
die("Missing parameter");
$listtype = $_GET['list'];
require_once("func.php");
require("database.php");
$GRAVITYDB = getGravityDBFilename();
$db = SQLite3_connect($GRAVITYDB);
function getTableContent($type) {
global $db;
$entries = array();
$querystr = implode(" ",array("SELECT domainlist.*,\"group\".enabled as group_enabled",
"FROM domainlist",
"LEFT JOIN domainlist_by_group ON domainlist_by_group.domainlist_id = domainlist.id",
"LEFT JOIN \"group\" ON \"group\".id = domainlist_by_group.group_id",
"WHERE type = $type",
"GROUP BY domain;"));
$results = $db->query($querystr);
while($results !== false && $res = $results->fetchArray(SQLITE3_ASSOC))
{
$utf8_domain = idn_to_utf8($res['domain']);
// Convert domain name to international form
// if applicable
if($res['domain'] !== $utf8_domain)
{
$res['domain'] = $utf8_domain.' ('.$res['domain'].')';
}
array_push($entries, $res);
}
return $entries;
}
function filterArray(&$inArray) {
$outArray = array();
foreach ($inArray as $key => $value)
{
if (is_array($value))
{
$outArray[htmlspecialchars($key)] = filterArray($value);
}
else
{
$outArray[htmlspecialchars($key)] = htmlspecialchars($value);
}
}
return $outArray;
}
switch ($listtype)
{
case "white":
$exact = array("whitelist" => getTableContent(ListType::whitelist));
$regex = array("regex_whitelist" => getTableContent(ListType::regex_whitelist));
$list = array_merge($exact, $regex);
break;
case "black":
$exact = array("blacklist" => getTableContent(ListType::blacklist));
$regex = array("regex_blacklist" => getTableContent(ListType::regex_blacklist));
$list = array_merge($exact, $regex);
break;
default:
die("Invalid list parameter");
break;
}
// Protect against XSS attacks
$output = filterArray($list);
// Return results
header('Content-type: application/json');
echo json_encode($output);

View File

@@ -329,7 +329,13 @@ if ($_POST['action'] == 'get_groups') {
} elseif ($_POST['action'] == 'get_domains') {
// List all available groups
try {
$query = $db->query('SELECT * FROM domainlist;');
$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";
}
$query = $db->query('SELECT * FROM domainlist'.$limit);
if (!$query) {
throw new Exception('Error while querying gravity\'s domainlist table: ' . $db->lastErrorMsg());
}
@@ -369,12 +375,19 @@ if ($_POST['action'] == 'get_groups') {
throw new Exception('While preparing statement: ' . $db->lastErrorMsg());
}
$type = intval($_POST['type']);
$type = intval($_POST['type'][0]);
$domain = $_POST['domain'];
if(strlen($_POST['type']) === 2 && $_POST['type'][1] === 'W')
{
// Apply wildcard-style formatting
$domain = "(\\.|^)".str_replace(".","\\.",$domain)."$";
}
// Convert domain name to IDNA ASCII form for international domains
$domain = idn_to_ascii($_POST['domain']);
if($type === ListType::whitelist || $type === ListType::blacklist)
{
// Convert domain name to IDNA ASCII form for international domains
$domain = idn_to_ascii($domain);
// If adding to the exact lists, we convert the domain lower case and check whether it is valid
$domain = strtolower($domain);
if(filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) === false)

View File

@@ -428,13 +428,13 @@ if($auth) {
</div>
<!-- sidebar menu: : style can be found in sidebar.less -->
<?php
if($scriptname === "list.php")
if($scriptname === "groups-domains.php")
{
if($_GET["l"] === "white")
if($_GET["type"] === "white")
{
$scriptname = "whitelist";
}
elseif($_GET["l"] === "black")
elseif($_GET["type"] === "black")
{
$scriptname = "blacklist";
}
@@ -486,13 +486,13 @@ if($auth) {
</li>
<!-- Whitelist -->
<li<?php if($scriptname === "whitelist"){ ?> class="active"<?php } ?>>
<a href="list.php?l=white">
<a href="groups-domains.php?type=white">
<i class="fa fa-check-circle "></i> <span>Whitelist</span>
</a>
</li>
<!-- Blacklist -->
<li<?php if($scriptname === "blacklist"){ ?> class="active"<?php } ?>>
<a href="list.php?l=black">
<a href="groups-domains.php?type=black">
<i class="fa fa-ban"></i> <span>Blacklist</span>
</a>
</li>

View File

@@ -1,51 +0,0 @@
<?php
/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
require_once('auth.php');
$type = $_POST['list'];
// Perform all of the authentication for list editing
// when NOT invoked and authenticated from API
if (empty($api)) {
list_verify($type);
}
// Split individual domains into array
$domains = preg_split('/\s+/', trim($_POST['domain']));
require_once("func.php");
require("database.php");
$GRAVITYDB = getGravityDBFilename();
$db = SQLite3_connect($GRAVITYDB, SQLITE3_OPEN_READWRITE);
switch($type) {
case "white":
echo remove_from_table($db, "domainlist", $domains, false, ListType::whitelist);
break;
case "black":
echo remove_from_table($db, "domainlist", $domains, false, ListType::blacklist);
break;
case "white_regex":
echo remove_from_table($db, "domainlist", $domains, false, ListType::regex_whitelist);
break;
case "black_regex":
echo remove_from_table($db, "domainlist", $domains, false, ListType::regex_blacklist);
break;
default:
die("Invalid list!");
}
// Reload lists in pihole-FTL after having removed something
echo shell_exec("sudo pihole restartdns reload");
?>