mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
Modifying excluded entries for top domains/top ads and top clients working
This commit is contained in:
@@ -4,6 +4,15 @@ function validIP($ip){
|
||||
return filter_var($secondaryIP, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false;
|
||||
}
|
||||
|
||||
// Credit: http://stackoverflow.com/a/4694816/2087442
|
||||
function validDomain($domain_name)
|
||||
{
|
||||
$validChars = preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name);
|
||||
$lengthCheck = preg_match("/^.{1,253}$/", $domain_name);
|
||||
$labelLengthCheck = preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name);
|
||||
return ( $validChars && $lengthCheck && $labelLengthCheck ); //length of each label
|
||||
}
|
||||
|
||||
$debug = $_POST;
|
||||
|
||||
$primaryDNSservers = [
|
||||
@@ -86,6 +95,66 @@ function validIP($ip){
|
||||
|
||||
break;
|
||||
|
||||
// Set domains to be excludef from being shown in Top Domains (or Ads) and Top Clients
|
||||
case "API":
|
||||
|
||||
// Explode the contests of the textareas into PHP arrays
|
||||
// \n (Unix) and \r\n (Win) will be considered as newline
|
||||
// array_filter( ... ) will remove any empty lines
|
||||
$domains = array_filter(preg_split('/\r\n|[\r\n]/', $_POST["domains"]));
|
||||
$clients = array_filter(preg_split('/\r\n|[\r\n]/', $_POST["clients"]));
|
||||
|
||||
$domainlist = "";
|
||||
$first = true;
|
||||
foreach($domains as $domain)
|
||||
{
|
||||
if(!validDomain($domain))
|
||||
{
|
||||
$error = "Entry ".$domain." is invalid!";
|
||||
break;
|
||||
}
|
||||
if(!$first)
|
||||
{
|
||||
$domainlist .= ",";
|
||||
}
|
||||
else
|
||||
{
|
||||
$first = false;
|
||||
}
|
||||
$domainlist .= $domain;
|
||||
}
|
||||
|
||||
$clientlist = "";
|
||||
$first = true;
|
||||
foreach($clients as $client)
|
||||
{
|
||||
if(!validDomain($client))
|
||||
{
|
||||
$error = "Entry ".$client." is invalid!";
|
||||
break;
|
||||
}
|
||||
if(!$first)
|
||||
{
|
||||
$clientlist .= ",";
|
||||
}
|
||||
else
|
||||
{
|
||||
$first = false;
|
||||
}
|
||||
$clientlist .= $client;
|
||||
}
|
||||
|
||||
if(!isset($error))
|
||||
{
|
||||
// All entries are okay
|
||||
$cmd = "sudo pihole -a setexcludedomains ".$domainlist;
|
||||
exec($cmd);
|
||||
$cmd = "sudo pihole -a setexcludeclients ".$clientlist;
|
||||
exec($cmd);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
break;
|
||||
|
||||
+7
-6
@@ -171,17 +171,17 @@
|
||||
</div>
|
||||
<?php
|
||||
// Exluded domains
|
||||
if(isset($setupVars["WEBUI_EXCLUDE_DOMAINS"]))
|
||||
if(isset($setupVars["API_EXCLUDE_DOMAINS"]))
|
||||
{
|
||||
$excludedDomains = explode(",", $setupVars["WEBUI_EXCLUDE_DOMAINS"]);
|
||||
$excludedDomains = explode(",", $setupVars["API_EXCLUDE_DOMAINS"]);
|
||||
} else {
|
||||
$excludedDomains = "";
|
||||
}
|
||||
|
||||
// Exluded clients
|
||||
if(isset($setupVars["WEBUI_EXCLUDE_CLIENTS"]))
|
||||
if(isset($setupVars["API_EXCLUDE_CLIENTS"]))
|
||||
{
|
||||
$excludedClients = explode(",", $setupVars["WEBUI_EXCLUDE_CLIENTS"]);
|
||||
$excludedClients = explode(",", $setupVars["API_EXCLUDE_CLIENTS"]);
|
||||
} else {
|
||||
$excludedClients = "";
|
||||
}
|
||||
@@ -198,17 +198,18 @@
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group">
|
||||
<label>Top Domains / Top Advertisers</label>
|
||||
<textarea class="form-control" rows="4" placeholder="Enter one domain per line"><?php foreach ($excludedDomains as $domain) { echo $domain."\n"; } ?></textarea>
|
||||
<textarea name="domains" class="form-control" rows="4" placeholder="Enter one domain per line"><?php foreach ($excludedDomains as $domain) { echo $domain."\n"; } ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group">
|
||||
<label>Top Clients</label>
|
||||
<textarea class="form-control" rows="4" placeholder="Enter one domain per line"><?php foreach ($excludedClient as $client) { echo $client."\n"; } ?></textarea>
|
||||
<textarea name="clients" class="form-control" rows="4" placeholder="Enter one domain per line"><?php foreach ($excludedClients as $client) { echo $client."\n"; } ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
<input type="hidden" name="field" value="API">
|
||||
<button type="submit" class="btn btn-primary pull-right">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user