Implement whitelist regex support to web interface.

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2019-07-22 21:15:50 +02:00
parent 483a3aee27
commit dfcfafd6d9
6 changed files with 33 additions and 36 deletions
-8
View File
@@ -35,13 +35,9 @@ function getFullName() {
<div class="form-group input-group">
<input id="domain" type="text" class="form-control" placeholder="Add a domain (example.com or sub.example.com)">
<span class="input-group-btn">
<?php if($list === "black") { ?>
<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>
<?php }else{ ?>
<button id="btnAdd" class="btn btn-default" type="button">Add</button>
<?php } ?>
<button id="btnRefresh" class="btn btn-default" type="button"><i class="fa fa-sync"></i></button>
</span>
</div>
@@ -66,14 +62,10 @@ function getFullName() {
<!-- Domain List -->
<?php if($list === "black") { ?>
<h3>Exact blocking</h3>
<?php } ?>
<ul class="list-group" id="list"></ul>
<?php if($list === "black") { ?>
<h3><a href="https://docs.pi-hole.net/ftldns/regex/overview/" target="_blank" title="Click for Pi-hole Regex documentation">Regex</a> &amp; Wildcard blocking</h3>
<ul class="list-group" id="list-regex"></ul>
<?php } ?>
<script src="scripts/pi-hole/js/list.js"></script>
+11 -16
View File
@@ -43,12 +43,8 @@ function addListEntry(entry, index, list, button, type)
}
function refresh(fade) {
var listw;
var list = $("#list");
if(listType === "black")
{
listw = $("#list-regex");
}
var listw = $("#list-regex");
if(fade) {
list.fadeOut(100);
if(listw)
@@ -69,9 +65,10 @@ function refresh(fade) {
if((listType === "black" &&
response.blacklist.length === 0 &&
response.regex.length === 0) ||
response.regex_blacklist.length === 0) ||
(listType === "white" &&
response.whitelist.length === 0))
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>");
@@ -82,12 +79,12 @@ function refresh(fade) {
if(listType === "white")
{
data = response.whitelist.sort();
data2 = []; // No regex data, use empty array
data2 = response.regex_whitelist.sort();
}
else if(listType === "black")
{
data = response.blacklist.sort();
data2 = response.regex.sort();
data2 = response.regex_blacklist.sort();
}
data.forEach(function (entry, index)
{
@@ -97,7 +94,7 @@ function refresh(fade) {
// Add regex domains if present in returned list data
data2.forEach(function (entry, index)
{
addListEntry(entry, index, listw, "#list-regex", "regex");
addListEntry(entry, index, listw, "#list-regex", listType+"_regex");
});
}
list.fadeIn(100);
@@ -117,9 +114,9 @@ window.onload = refresh(false);
function sub(index, entry, arg) {
var domain = $("#list #"+index);
var locallistType = listType;
if(arg === "regex")
if(arg === "black_regex" || arg === "white_regex")
{
locallistType = "regex";
locallistType = arg;
domain = $("#list-regex #"+index);
}
domain.hide("highlight");
@@ -143,14 +140,12 @@ function sub(index, entry, arg) {
function add(arg) {
var locallistType = listType;
var domain = $("#domain");
var wild = false;
if(domain.val().length === 0){
return;
}
if(arg === "wild" || arg === "regex")
if(arg === "wild")
{
locallistType = arg;
wild = true;
locallistType = listType+"_wild";
}
var alInfo = $("#alInfo");
+8 -2
View File
@@ -44,12 +44,18 @@ switch($type) {
echo shell_exec("sudo pihole -a audit ".$domains);
}
break;
case "regex":
case "black_regex":
echo shell_exec("sudo pihole --regex --web ".$domains);
break;
case "wild":
case "white_regex":
echo shell_exec("sudo pihole --whiteregex --web ".$domains);
break;
case "black_wild":
echo shell_exec("sudo pihole --wild --web ".$domains);
break;
case "white_wild":
echo shell_exec("sudo pihole --whitewild --web ".$domains);
break;
case "audit":
echo shell_exec("sudo pihole -a audit ".$domains);
break;
-1
View File
@@ -11,7 +11,6 @@ $ERRORLOG = getenv('PHP_ERROR_LOG');
if (empty($ERRORLOG)) {
$ERRORLOG = '/var/log/lighttpd/error.log';
}
$regexfile = "/etc/pihole/regex.list";
function pi_log($message) {
error_log(date('Y-m-d H:i:s') . ': ' . $message . "\n", 3, $GLOBALS['ERRORLOG']);
+6 -4
View File
@@ -21,7 +21,7 @@ function getTableContent($listname) {
global $db;
$entries = array();
$querystr = implode(" ",array("SELECT ${listname}.*,\"group\".enabled as group_enabled",
"FROM $listname",
"FROM ${listname}",
"LEFT JOIN ${listname}_by_group ON ${listname}_by_group.${listname}_id = ${listname}.id",
"LEFT JOIN \"group\" ON \"group\".id = ${listname}_by_group.group_id",
"GROUP BY domain;"));
@@ -54,13 +54,15 @@ function filterArray(&$inArray) {
switch ($listtype)
{
case "white":
$list = getTableContent("whitelist");
$exact = getTableContent("whitelist");
$regex = getTableContent("regex_whitelist");
$list = array_merge($exact, $regex);
break;
case "black":
$exact = getTableContent("blacklist");
$regex = getTableContent("regex");
$list = array_merge($exact, $regex);
$regex = getTableContent("regex_blacklist");
$list = array_merge($exact, $regex);
break;
default:
+8 -5
View File
@@ -18,7 +18,7 @@ if (empty($api)) {
// Don't check if the added item is a valid domain for regex expressions.
// Regex filters are validated by FTL on import and skipped if invalid
if($type !== "regex") {
if($type !== "black_regex" && $type !== "white_regex") {
check_domain();
}
@@ -27,13 +27,16 @@ $domain = escapeshellcmd($_POST['domain']);
switch($type) {
case "white":
exec("sudo pihole -w -q -d ".$domain);
echo shell_exec("sudo pihole -w -q -d ".$domain);
break;
case "black":
exec("sudo pihole -b -q -d ".$domain);
echo shell_exec("sudo pihole -b -q -d ".$domain);
break;
case "regex":
exec("sudo pihole --regex -q -d ".$domain);
case "black_regex":
echo shell_exec("sudo pihole --regex -q -d ".$domain);
break;
case "white_regex":
echo shell_exec("sudo pihole --whiteregex -q -d ".$domain);
break;
}