modify to work with changes in pihole#1365

This commit is contained in:
Adam Warner
2017-03-31 21:05:53 +01:00
parent ffe40009f1
commit c11172d7c4
2 changed files with 12 additions and 34 deletions

View File

@@ -48,13 +48,12 @@ function validDomain($domain_name)
"8.20.247.20" => "Comodo"
];
$adlistsdefault = [];
$adlistsuser = [];
function readAdlists($listname)
$adlist = [];
function readAdlists()
{
// Reset list
$list = [];
$handle = @fopen("/etc/pihole/adlists.".$listname, "r");
$handle = @fopen("/etc/pihole/adlists.list", "r");
if ($handle)
{
while (($line = fgets($handle)) !== false)
@@ -76,8 +75,7 @@ function readAdlists($listname)
}
// Read available adlists
$adlistsdefault = readAdlists("default");
$adlistsuser = readAdlists("user");
$adlist = readAdlists();
$error = "";
$success = "";
@@ -401,32 +399,18 @@ function readAdlists($listname)
break;
case "adlists":
foreach ($adlistsdefault as $key => $value)
foreach ($adlist as $key => $value)
{
if(isset($_POST["adlist-".$key]) && !$value[0])
{
// Is not enabled, but should be
exec("sudo pihole -a adlist enable default ".escapeshellcmd ($value[1]));
exec("sudo pihole -a adlist enable ".escapeshellcmd ($value[1]));
}
elseif(!isset($_POST["adlist-".$key]) && $value[0])
{
// Is enabled, but shouldn't be
exec("sudo pihole -a adlist disable default ".escapeshellcmd ($value[1]));
}
}
foreach ($adlistsuser as $key => $value)
{
if(isset($_POST["userlist-".$key]) && !$value[0])
{
// Is not enabled, but should be
exec("sudo pihole -a adlist enable user ".escapeshellcmd ($value[1]));
}
elseif(!isset($_POST["userlist-".$key]) && $value[0])
{
// Is enabled, but shouldn't be
exec("sudo pihole -a adlist disable user ".escapeshellcmd ($value[1]));
exec("sudo pihole -a adlist disable ".escapeshellcmd ($value[1]));
}
}
@@ -435,13 +419,13 @@ function readAdlists($listname)
$domains = array_filter(preg_split('/\r\n|[\r\n]/', $_POST["newuserlists"]));
foreach($domains as $domain)
{
exec("sudo pihole -a adlist add user ".escapeshellcmd($domain));
exec("sudo pihole -a adlist add ".escapeshellcmd($domain));
}
}
// Reread available adlists
$adlistsdefault = readAdlists("default");
$adlistsuser = readAdlists("user");
$adlist = readAdlists();
break;
default:

View File

@@ -655,18 +655,12 @@ if(isset($_POST["submit"])) {
<div class="box-body">
<div class="col-lg-12">
<label>Lists suggested by the Pi-hole team (reset on updates)</label>
<?php foreach ($adlistsdefault as $key => $value) { ?>
<?php foreach ($adlist 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 } ?>
<label>User defined list (preserved on updates)</label>
<?php foreach ($adlistsuser as $key => $value) { ?>
<div class="form-group">
<div class="checkbox"><label style="word-break: break-word;"><input type="checkbox" name="userlist-<?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 class="form-group">
<div class="form-group">
<textarea name="newuserlists" class="form-control" rows="1" placeholder="Enter one URL per line to add new ad lists"></textarea>
</div>
</div>