Enable/disable all lists from /etc/pihole/adlists.default from the Settings page

This commit is contained in:
DL6ER
2016-12-15 17:36:26 +01:00
parent 69839aa51c
commit af0b405cd6
2 changed files with 68 additions and 0 deletions
+46
View File
@@ -34,6 +34,34 @@ function validDomain($domain_name)
"8.20.247.20" => "Comodo"
];
$adlists = [];
function readAdlists()
{
global $adlists;
$adlists = [];
$handle = fopen("/etc/pihole/adlists.default", "r");
if ($handle)
{
while (($line = fgets($handle)) !== false)
{
if(substr($line, 0, 2) === "#h")
{
// Commented list
array_push($adlists, [false,rtrim(substr($line, 1))]);
}
elseif(substr($line, 0, 1) === "h")
{
// Active list
array_push($adlists, [true,rtrim($line)]);
}
}
fclose($handle);
}
}
// Read available adlists
readAdlists();
if(isset($_POST["field"]))
{
$error = "";
@@ -294,6 +322,24 @@ function validDomain($domain_name)
break;
case "adlists":
foreach ($adlists as $key => $value)
{
if(isset($_POST["adlist-".$key]))
{
$action = "enable";
}
else
{
$action = "disable";
}
exec("sudo pihole -a adlist ".$action." ".escapeshellcmd ($value[1]));
}
// Reread available adlists
readAdlists();
break;
default:
// Option not found
$debug = true;
+22
View File
@@ -477,6 +477,28 @@
</div>
</div>
*/ ?>
<div class="box box-danger collapsed-box">
<div class="box-header with-border">
<h3 class="box-title">Pi-Hole's Block Lists</h3>
<div class="box-tools pull-right"><button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-plus"></i></button></div>
</div>
<form role="form" method="post">
<div class="box-body">
<div class="col-lg-12">
<?php foreach ($adlists as $key => $value) { ?>
<div class="form-group">
<div class="checkbox"><label style="word-break: break-word;"><input type="checkbox" name="adlist-<?php echo $key; ?>" <?php if($value[0]){ ?>checked<?php } ?>> <a href="<?php echo htmlentities ($value[1]); ?>" target="_new"><?php echo htmlentities($value[1]); ?></a></label></div>
</div>
<?php } ?>
</div>
</div>
<div class="box-footer">
<input type="hidden" name="field" value="adlists">
<label>Don't forget to use "Update Lists" afterwards</label>
<button type="submit" class="btn btn-primary pull-right">Save</button>
</div>
</form>
</div>
<div class="box box-danger">
<div class="box-header with-border">
<h3 class="box-title">System Administration</h3>