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:
DL6ER
2019-04-28 20:42:50 +02:00
parent 406a946b24
commit ced7174c37
4 changed files with 32 additions and 42 deletions

View File

@@ -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"]));
}
}