mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
Add new button to allow both regex filters and legacy wildcards (get automatically converted to regex format)
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -37,7 +37,8 @@ function getFullName() {
|
||||
<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 (regex)</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 } ?>
|
||||
@@ -66,7 +67,7 @@ function getFullName() {
|
||||
<?php } ?>
|
||||
<ul class="list-group" id="list"></ul>
|
||||
<?php if($list === "black") { ?>
|
||||
<h3>Regex blocking</h3>
|
||||
<h3>Regex & Wildcard blocking</h3>
|
||||
<ul class="list-group" id="list-regex"></ul>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
@@ -126,12 +126,14 @@ window.onload = refresh(false);
|
||||
function add(arg) {
|
||||
var locallistType = listType;
|
||||
var domain = $("#domain");
|
||||
var wild = false;
|
||||
if(domain.val().length === 0){
|
||||
return;
|
||||
}
|
||||
if(arg === "wild")
|
||||
if(arg === "wild" || arg === "regex")
|
||||
{
|
||||
locallistType = "wild";
|
||||
locallistType = arg;
|
||||
wild = true;
|
||||
}
|
||||
|
||||
var alInfo = $("#alInfo");
|
||||
@@ -146,8 +148,8 @@ function add(arg) {
|
||||
method: "post",
|
||||
data: {"domain":domain.val().trim(), "list":locallistType, "token":token},
|
||||
success: function(response) {
|
||||
if (locallistType !== "wild" && response.indexOf("] Pi-hole blocking is ") === -1 ||
|
||||
locallistType === "wild" && response.length > 1) {
|
||||
if (!wild && response.indexOf("] Pi-hole blocking is ") === -1 ||
|
||||
wild && response.length > 1) {
|
||||
alFailure.show();
|
||||
err.html(response);
|
||||
alFailure.delay(4000).fadeOut(2000, function() {
|
||||
@@ -200,6 +202,10 @@ $("#btnAddWildcard").on("click", function() {
|
||||
add("wild");
|
||||
});
|
||||
|
||||
$("#btnAddRegex").on("click", function() {
|
||||
add("regex");
|
||||
});
|
||||
|
||||
$("#btnRefresh").on("click", function() {
|
||||
refresh(true);
|
||||
});
|
||||
|
||||
+23
-12
@@ -14,6 +14,23 @@ $type = $_POST['list'];
|
||||
// All of the verification for list editing
|
||||
list_verify($type);
|
||||
|
||||
function add_regex($regex)
|
||||
{
|
||||
global $regexfile;
|
||||
if(file_put_contents($regexfile, "\n".$regex, FILE_APPEND) === FALSE)
|
||||
{
|
||||
$err = error_get_last()["message"];
|
||||
echo "Unable to add regex \"".htmlspecialchars($_POST['domain'])."\" to ${regexfile}<br>Error message: $err";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Send SIGHUP to pihole-FTL using a frontend command
|
||||
// to force reloading of the regex domains
|
||||
// This will also wipe the resolver's cache
|
||||
echo exec("sudo pihole restartdns reload");
|
||||
}
|
||||
}
|
||||
|
||||
switch($type) {
|
||||
case "white":
|
||||
if(!isset($_POST["auditlog"]))
|
||||
@@ -34,18 +51,12 @@ switch($type) {
|
||||
}
|
||||
break;
|
||||
case "wild":
|
||||
if(file_put_contents($regexfile, "\n".$_POST['domain'], FILE_APPEND) === FALSE)
|
||||
{
|
||||
$err = error_get_last()["message"];
|
||||
echo "Unable to add regex \"".htmlspecialchars($_POST['domain'])."\" to ${regexfile}<br>Error message: $err";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Send SIGHUP to pihole-FTL using a frontend command
|
||||
// to force reloading of the regex domains
|
||||
// This will also wipe the resolver's cache
|
||||
echo exec("sudo pihole restartdns reload");
|
||||
}
|
||||
// Escape "." so it won't be interpreted as the wildcard character
|
||||
$domain = str_replace(".","\.",$_POST['domain']);
|
||||
// Add regex filter for legacy wildcard behavior
|
||||
add_regex("((^)|(\.))".$domain."$");
|
||||
case "regex":
|
||||
add_regex($_POST['domain']);
|
||||
case "audit":
|
||||
echo exec("sudo pihole -a audit ${_POST['domain']}");
|
||||
break;
|
||||
|
||||
@@ -139,7 +139,7 @@ function list_verify($type) {
|
||||
// valid domain for regex expressions
|
||||
// Regex filters are validated by FTL
|
||||
// on import and skipped if invalid
|
||||
if($_POST['list'] !== "wild")
|
||||
if($_POST['list'] !== "regex")
|
||||
{
|
||||
check_domain();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user