mirror of
https://github.com/pi-hole/web.git
synced 2025-12-25 05:05:33 +00:00
Modify adlists subpage of the settings page to sources the lists from the gravity database.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -6,8 +6,23 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license */
|
||||
|
||||
function getGravityDBFilename()
|
||||
{
|
||||
// Get possible non-standard location of FTL's database
|
||||
$FTLsettings = parse_ini_file("/etc/pihole/pihole-FTL.conf");
|
||||
if(isset($FTLsettings["GRAVITYDB"]))
|
||||
{
|
||||
return $FTLsettings["GRAVITYDB"];
|
||||
}
|
||||
else
|
||||
{
|
||||
return "/etc/pihole/gravity.db";
|
||||
}
|
||||
}
|
||||
|
||||
function SQLite3_connect_try($filename, $mode, $trytoreconnect)
|
||||
{ try
|
||||
{
|
||||
try
|
||||
{
|
||||
// connect to database
|
||||
return new SQLite3($filename, $mode);
|
||||
|
||||
@@ -13,18 +13,8 @@ $listtype = $_GET['list'];
|
||||
|
||||
require_once("func.php");
|
||||
|
||||
// Get possible non-standard location of FTL's database
|
||||
$FTLsettings = parse_ini_file("/etc/pihole/pihole-FTL.conf");
|
||||
if(isset($FTLsettings["GRAVITYDB"]))
|
||||
{
|
||||
$GRAVITYDB = $FTLsettings["GRAVITYDB"];
|
||||
}
|
||||
else
|
||||
{
|
||||
$GRAVITYDB = "/etc/pihole/gravity.db";
|
||||
}
|
||||
|
||||
require("database.php");
|
||||
$GRAVITYDB = getGravityDBFilename();
|
||||
$db = SQLite3_connect($GRAVITYDB);
|
||||
|
||||
function getTableContent($listname) {
|
||||
|
||||
@@ -155,37 +155,22 @@ function readDNSserversList()
|
||||
return $list;
|
||||
}
|
||||
|
||||
require_once("database.php");
|
||||
$adlist = [];
|
||||
function readAdlists()
|
||||
{
|
||||
// Reset list
|
||||
$list = [];
|
||||
$handle = @fopen("/etc/pihole/adlists.list", "r");
|
||||
if ($handle)
|
||||
$db = SQLite3_connect(getGravityDBFilename());
|
||||
if ($db)
|
||||
{
|
||||
while (($line = fgets($handle)) !== false)
|
||||
$results = $db->query("SELECT * FROM adlists");
|
||||
|
||||
while($results !== false && $res = $results->fetchArray(SQLITE3_ASSOC))
|
||||
{
|
||||
if(strlen($line) < 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
elseif($line[0] === "#")
|
||||
{
|
||||
// Comments start either with "##" or "# "
|
||||
if($line[1] !== "#" &&
|
||||
$line[1] !== " ")
|
||||
{
|
||||
// Commented list
|
||||
array_push($list, [false,rtrim(substr($line, 1))]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Active list
|
||||
array_push($list, [true,rtrim($line)]);
|
||||
}
|
||||
array_push($list, $res);
|
||||
}
|
||||
fclose($handle);
|
||||
$db->close();
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
@@ -689,18 +674,18 @@ function readAdlists()
|
||||
if(isset($_POST["adlist-del-".$key]))
|
||||
{
|
||||
// Delete list
|
||||
exec("sudo pihole -a adlist del ".escapeshellcmd($value[1]));
|
||||
exec("sudo pihole -a adlist del ".escapeshellcmd($value["address"]));
|
||||
}
|
||||
elseif(isset($_POST["adlist-enable-".$key]) && !$value[0])
|
||||
elseif(isset($_POST["adlist-enable-".$key]) && $value["enabled"] !== 1)
|
||||
{
|
||||
// Is not enabled, but should be
|
||||
exec("sudo pihole -a adlist enable ".escapeshellcmd($value[1]));
|
||||
exec("sudo pihole -a adlist enable ".escapeshellcmd($value["address"]));
|
||||
|
||||
}
|
||||
elseif(!isset($_POST["adlist-enable-".$key]) && $value[0])
|
||||
elseif(!isset($_POST["adlist-enable-".$key]) && $value["enabled"] === 1)
|
||||
{
|
||||
// Is enabled, but shouldn't be
|
||||
exec("sudo pihole -a adlist disable ".escapeshellcmd($value[1]));
|
||||
exec("sudo pihole -a adlist disable ".escapeshellcmd($value["address"]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -266,10 +266,10 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array("sysadmin", "blocklists"
|
||||
<?php foreach ($adlist as $key => $value) { ?>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" name="adlist-enable-<?php echo $key; ?>" <?php if ($value[0]){ ?>checked<?php } ?>>
|
||||
<input type="checkbox" name="adlist-enable-<?php echo $key; ?>" <?php if ($value["enabled"] === 1){ ?>checked<?php } ?>>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<?php echo htmlentities($value[1]); ?>" target="_new" id="adlist-text-<?php echo $key; ?>"><?php echo htmlentities($value[1]); ?></a>
|
||||
<a href="<?php echo htmlentities($value["address"]); ?>" target="_new" id="adlist-text-<?php echo $key; ?>"><?php echo htmlentities($value["address"]); ?></a>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<button class="btn btn-danger btn-xs" id="adlist-btn-<?php echo $key; ?>">
|
||||
|
||||
Reference in New Issue
Block a user