mirror of
https://github.com/pi-hole/web.git
synced 2026-04-25 11:19:59 +01:00
Directly modify gravity tables from the lists pages.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
2
list.php
2
list.php
@@ -49,7 +49,7 @@ function getFullName() {
|
|||||||
</div>
|
</div>
|
||||||
<div id="alSuccess" class="alert alert-success alert-dismissible fade in" role="alert" hidden="true">
|
<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">×</span></button>
|
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
Success! The list will refresh.
|
Success!
|
||||||
</div>
|
</div>
|
||||||
<div id="alFailure" class="alert alert-danger alert-dismissible fade in" role="alert" hidden="true">
|
<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">×</span></button>
|
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
|||||||
@@ -119,6 +119,11 @@ function sub(index, entry, arg) {
|
|||||||
heading = "#h3-regex";
|
heading = "#h3-regex";
|
||||||
locallistType = arg;
|
locallistType = arg;
|
||||||
}
|
}
|
||||||
|
var alInfo = $("#alInfo");
|
||||||
|
var alSuccess = $("#alSuccess");
|
||||||
|
var alFailure = $("#alFailure");
|
||||||
|
var alWarning = $("#alWarning");
|
||||||
|
|
||||||
var domain = $(list+" #"+index);
|
var domain = $(list+" #"+index);
|
||||||
domain.hide("highlight");
|
domain.hide("highlight");
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -126,14 +131,29 @@ function sub(index, entry, arg) {
|
|||||||
method: "post",
|
method: "post",
|
||||||
data: {"domain":entry, "list":locallistType, "token":token},
|
data: {"domain":entry, "list":locallistType, "token":token},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
if(response.length !== 0){
|
if (response.indexOf("Success") === -1) {
|
||||||
return;
|
alFailure.show();
|
||||||
}
|
err.html(response);
|
||||||
|
alFailure.delay(8000).fadeOut(2000, function() {
|
||||||
|
alFailure.hide();
|
||||||
|
});
|
||||||
|
alInfo.delay(8000).fadeOut(2000, function() {
|
||||||
|
alInfo.hide();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
alSuccess.show();
|
||||||
|
alSuccess.delay(1000).fadeOut(2000, function() {
|
||||||
|
alSuccess.hide();
|
||||||
|
});
|
||||||
|
alInfo.delay(1000).fadeOut(2000, function() {
|
||||||
|
alInfo.hide();
|
||||||
|
});
|
||||||
domain.remove();
|
domain.remove();
|
||||||
if($(list+" li").length < 1)
|
if($(list+" li").length < 1)
|
||||||
{
|
{
|
||||||
$(heading).fadeOut(100);
|
$(heading).fadeOut(100);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: function(jqXHR, exception) {
|
error: function(jqXHR, exception) {
|
||||||
alert("Failed to remove the domain!");
|
alert("Failed to remove the domain!");
|
||||||
@@ -163,16 +183,7 @@ function add(type) {
|
|||||||
method: "post",
|
method: "post",
|
||||||
data: {"domain":domain.val().trim(), "list":type, "token":token},
|
data: {"domain":domain.val().trim(), "list":type, "token":token},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
if (response.indexOf(" already exists in ") !== -1) {
|
if (response.indexOf("Success") === -1) {
|
||||||
alWarning.show();
|
|
||||||
warn.html(response);
|
|
||||||
alWarning.delay(8000).fadeOut(2000, function() {
|
|
||||||
alWarning.hide();
|
|
||||||
});
|
|
||||||
alInfo.delay(8000).fadeOut(2000, function() {
|
|
||||||
alInfo.hide();
|
|
||||||
});
|
|
||||||
} else if (response.indexOf("DONE") === -1) {
|
|
||||||
alFailure.show();
|
alFailure.show();
|
||||||
err.html(response);
|
err.html(response);
|
||||||
alFailure.delay(8000).fadeOut(2000, function() {
|
alFailure.delay(8000).fadeOut(2000, function() {
|
||||||
|
|||||||
@@ -18,47 +18,90 @@ if (empty($api)) {
|
|||||||
|
|
||||||
// Don't check if the added item is a valid domain for regex expressions. Regex
|
// 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
|
// filters are validated by FTL on import and skipped if invalid
|
||||||
if($type !== "regex") {
|
$check_lists = ["white","black","audit"];
|
||||||
|
if(in_array($list, $check_lists)) {
|
||||||
check_domain();
|
check_domain();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escape shell metacharacters
|
// Escape shell metacharacters
|
||||||
$domains = escapeshellcmd($_POST['domain']);
|
$domains = explode(",",$_POST['domain']);
|
||||||
|
|
||||||
|
require_once("func.php");
|
||||||
|
|
||||||
|
require("database.php");
|
||||||
|
$GRAVITYDB = getGravityDBFilename();
|
||||||
|
$db = SQLite3_connect($GRAVITYDB, SQLITE3_OPEN_READWRITE);
|
||||||
|
|
||||||
|
function add_to_table($table, $domains, $wildcardstyle=false)
|
||||||
|
{
|
||||||
|
global $db;
|
||||||
|
// Prepare SQLite statememt
|
||||||
|
$stmt = $db->prepare("INSERT OR IGNORE INTO ".$table." (domain) VALUES (:domain);");
|
||||||
|
|
||||||
|
// Return early if we prepare the SQLite statement
|
||||||
|
if(!$stmt)
|
||||||
|
{
|
||||||
|
echo "Failed to prepare statement for ".$table." table.";
|
||||||
|
echo $sql;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop over domains and inject the lines into the database
|
||||||
|
$num = 0;
|
||||||
|
foreach($domains as $row)
|
||||||
|
{
|
||||||
|
if($wildcardstyle)
|
||||||
|
$line = "(\\.|^)".str_replace(".","\\.",$row)."$";
|
||||||
|
else
|
||||||
|
$line = $row;
|
||||||
|
|
||||||
|
$stmt->bindValue(":domain", $line, SQLITE3_TEXT);
|
||||||
|
|
||||||
|
if($stmt->execute() && $stmt->reset() && $stmt->clear())
|
||||||
|
$num++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$stmt->close();
|
||||||
|
return "Error, added: ".$num."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close database connection and return number or processed rows
|
||||||
|
$stmt->close();
|
||||||
|
return "Success, added: ".$num."\n";
|
||||||
|
}
|
||||||
|
|
||||||
switch($type) {
|
switch($type) {
|
||||||
case "white":
|
case "white":
|
||||||
if(!isset($_POST["auditlog"]))
|
if(isset($_POST["auditlog"]))
|
||||||
echo shell_exec("sudo pihole -w --web ".$domains);
|
echo add_to_table("domain_audit", $domains);
|
||||||
else
|
echo add_to_table("whitelist", $domains);
|
||||||
{
|
|
||||||
echo shell_exec("sudo pihole -w --web ".$domains);
|
|
||||||
echo shell_exec("sudo pihole -a audit ".$domains);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "black":
|
|
||||||
if(!isset($_POST["auditlog"]))
|
|
||||||
echo shell_exec("sudo pihole -b --web ".$domains);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
echo shell_exec("sudo pihole -b --web ".$domains);
|
|
||||||
echo shell_exec("sudo pihole -a audit ".$domains);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "black_regex":
|
|
||||||
echo shell_exec("sudo pihole --regex --web ".$domains);
|
|
||||||
break;
|
|
||||||
case "white_regex":
|
|
||||||
echo shell_exec("sudo pihole --white-regex --web ".$domains);
|
|
||||||
break;
|
|
||||||
case "black_wild":
|
|
||||||
echo shell_exec("sudo pihole --wild --web ".$domains);
|
|
||||||
break;
|
|
||||||
case "white_wild":
|
|
||||||
echo shell_exec("sudo pihole --white-wild --web ".$domains);
|
|
||||||
break;
|
|
||||||
case "audit":
|
|
||||||
echo shell_exec("sudo pihole -a audit ".$domains);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
case "black":
|
||||||
|
if(isset($_POST["auditlog"]))
|
||||||
|
echo add_to_table("domain_audit", $domains);
|
||||||
|
echo add_to_table("blacklist", $domains);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "black_regex":
|
||||||
|
echo add_to_table("regex_blacklist", $domains);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "white_regex":
|
||||||
|
echo add_to_table("regex_whitelist", $domains);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "black_wild":
|
||||||
|
echo add_to_table("regex_blacklist", $domains, true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "white_wild":
|
||||||
|
echo add_to_table("regex_whitelist", $domains, true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "audit":
|
||||||
|
echo add_to_table("domain_audit", $domains);
|
||||||
|
break;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -16,28 +16,64 @@ if (empty($api)) {
|
|||||||
list_verify($type);
|
list_verify($type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't check if the added item is a valid domain for regex expressions.
|
// Escape shell metacharacters
|
||||||
// Regex filters are validated by FTL on import and skipped if invalid
|
$domains = explode(",",$_POST['domain']);
|
||||||
if($type !== "black_regex" && $type !== "white_regex") {
|
|
||||||
check_domain();
|
require_once("func.php");
|
||||||
|
|
||||||
|
require("database.php");
|
||||||
|
$GRAVITYDB = getGravityDBFilename();
|
||||||
|
$db = SQLite3_connect($GRAVITYDB, SQLITE3_OPEN_READWRITE);
|
||||||
|
|
||||||
|
function remove_from_table($table, $domains)
|
||||||
|
{
|
||||||
|
global $db;
|
||||||
|
// Prepare SQLite statememt
|
||||||
|
$stmt = $db->prepare("DELETE FROM ".$table." WHERE domain = :domain;");
|
||||||
|
|
||||||
|
// Return early if we prepare the SQLite statement
|
||||||
|
if(!$stmt)
|
||||||
|
{
|
||||||
|
echo "Failed to prepare statement for ".$table." table.";
|
||||||
|
echo $sql;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escape shell metacharacters
|
// Loop over domains and remove the lines from the database
|
||||||
$domain = escapeshellcmd($_POST['domain']);
|
$num = 0;
|
||||||
|
foreach($domains as $row)
|
||||||
|
{
|
||||||
|
$stmt->bindValue(":domain", $row, SQLITE3_TEXT);
|
||||||
|
|
||||||
|
if($stmt->execute() && $stmt->reset() && $stmt->clear())
|
||||||
|
$num++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$stmt->close();
|
||||||
|
return "Error, removed: ".$num."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close database connection and return number or processed rows
|
||||||
|
$stmt->close();
|
||||||
|
return "Success, removed: ".$num."\n";
|
||||||
|
}
|
||||||
|
|
||||||
switch($type) {
|
switch($type) {
|
||||||
case "white":
|
case "white":
|
||||||
echo shell_exec("sudo pihole -w -q -d ".$domain);
|
echo remove_from_table("whitelist", $domains);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "black":
|
case "black":
|
||||||
echo shell_exec("sudo pihole -b -q -d ".$domain);
|
echo remove_from_table("blacklist", $domains);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "black_regex":
|
case "black_regex":
|
||||||
echo shell_exec("sudo pihole --regex -q -d ".$domain);
|
echo remove_from_table("regex_blacklist", $domains);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "white_regex":
|
case "white_regex":
|
||||||
echo shell_exec("sudo pihole --white-regex -q -d ".$domain);
|
echo remove_from_table("regex_whitelist", $domains);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user