Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage adlists #252

Merged
merged 23 commits into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
af0b405
Enable/disable all lists from /etc/pihole/adlists.default from the Se…
DL6ER Dec 15, 2016
dee11cb
Merge branch 'devel' into customizeadlists
DL6ER Dec 16, 2016
51f1bfe
Generalized the functions to allow different ad files to be loaded
DL6ER Dec 16, 2016
7b87301
Be able to add lists to the user-defined list + tell the user that th…
DL6ER Dec 16, 2016
6e7020a
Only enable/disable those lists where the status should be changed (e…
DL6ER Dec 16, 2016
c73c10f
Be able to enable/disable user lists and add multiple user lists at a…
DL6ER Dec 16, 2016
b51fbb0
Merge branch 'devel' into customizeadlists
DL6ER Dec 27, 2016
3e8e153
Add notice on whitelist page that list domains are automatically added
DL6ER Dec 27, 2016
c9f9d5f
Add shortcut to Update lists (since it is now hidden under Tools)
DL6ER Dec 27, 2016
f577045
Change from "h" to "http"
DL6ER Dec 28, 2016
1b77e75
Return lists instead of replacing them inline
DL6ER Dec 28, 2016
5735a5b
Merge branch 'devel' into customizeadlists
DL6ER Dec 30, 2016
8414ddf
Changed wording
DL6ER Dec 31, 2016
4b3173b
Merge branch 'devel' into customizeadlists
DL6ER Jan 2, 2017
ffe4000
Add "Save and Update" button
DL6ER Jan 2, 2017
c11172d
modify to work with changes in pihole#1365
PromoFaux Mar 31, 2017
42f4c51
move to a more prominent location
PromoFaux Mar 31, 2017
1f6c95a
Lists are no longer reset on updates
AzureMarker Mar 31, 2017
87b92d4
Add delete checkbox
AzureMarker Mar 31, 2017
86d8869
Handle deletion of list in savesettings.php
AzureMarker Mar 31, 2017
7a5c8e8
Use button to remove lists
AzureMarker Apr 1, 2017
db54cda
Change wording of block list label
AzureMarker Apr 1, 2017
892bc5f
:codacy:
PromoFaux Apr 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions list.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function getFullName() {
<div class="page-header">
<h1><?php getFullName(); ?></h1>
</div>
<?php if($list == "white"){ ?><p>Note that the ad list domains are automatically added to the whitelist so that a list can never get blocked by another list.</p><?php } ?>

<!-- Domain Input -->
<div class="form-group input-group">
Expand All @@ -48,6 +49,7 @@ function getFullName() {
Failure! Something went wrong.
</div>


<!-- Domain List -->
<ul class="list-group" id="list"></ul>

Expand Down
14 changes: 14 additions & 0 deletions scripts/pi-hole/js/gravity.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,23 @@ $("#gravityBtn").on("click", () => {
eventsource();
});

$("#gravityBtn").on("click", () => {
$("#gravityBtn").attr("disabled", true);
eventsource();
});

// Handle hiding of alerts
$(function(){
$("[data-hide]").on("click", function(){
$(this).closest("." + $(this).attr("data-hide")).hide();
});

// Do we want to start updating immediately?
// gravity.php?go
var searchString = window.location.search.substring(1);
if(searchString.indexOf("go") !== -1)
{
$("#gravityBtn").attr("disabled", true);
eventsource();
}
});
11 changes: 11 additions & 0 deletions scripts/pi-hole/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,14 @@ $(document).ready(function(){
$("[data-toggle=\"tooltip\"]").tooltip({"html": true, container : "body"});
});

// Handle list deletion
$("button[id^='adlist-btn-']").on("click", function (e) {
e.preventDefault();

var status = $(this).siblings("input[name^='adlist-del-']").is(":checked");
var textType = status ? "none" : "line-through";

$(this).siblings("input[name^='adlist-del-']").prop("checked", !status);
$(this).siblings("input[name^='adlist-enable-']").prop("disabled", !status);
$(this).siblings("a").css("text-decoration", textType);
});
64 changes: 64 additions & 0 deletions scripts/pi-hole/php/savesettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,35 @@ function validDomain($domain_name)
"8.20.247.20" => "Comodo"
];

$adlist = [];
function readAdlists()
{
// Reset list
$list = [];
$handle = @fopen("/etc/pihole/adlists.list", "r");
if ($handle)
{
while (($line = fgets($handle)) !== false)
{
if(substr($line, 0, 5) === "#http")
{
// Commented list
array_push($list, [false,rtrim(substr($line, 1))]);
}
elseif(substr($line, 0, 4) === "http")
{
// Active list
array_push($list, [true,rtrim($line)]);
}
}
fclose($handle);
}
return $list;
}

// Read available adlists
$adlist = readAdlists();

$error = "";
$success = "";

Expand Down Expand Up @@ -369,6 +398,41 @@ function validDomain($domain_name)

break;

case "adlists":
foreach ($adlist as $key => $value)
{
if(isset($_POST["adlist-del-".$key]))
{
// Delete list
exec("sudo pihole -a adlist del ".escapeshellcmd($value[1]));
}
elseif(isset($_POST["adlist-enable-".$key]) && !$value[0])
{
// Is not enabled, but should be
exec("sudo pihole -a adlist enable ".escapeshellcmd($value[1]));

}
elseif(!isset($_POST["adlist-enable-".$key]) && $value[0])
{
// Is enabled, but shouldn't be
exec("sudo pihole -a adlist disable ".escapeshellcmd($value[1]));
}
}

if(strlen($_POST["newuserlists"]) > 1)
{
$domains = array_filter(preg_split('/\r\n|[\r\n]/', $_POST["newuserlists"]));
foreach($domains as $domain)
{
exec("sudo pihole -a adlist add ".escapeshellcmd($domain));
}
}

// Reread available adlists
$adlist = readAdlists();

break;

default:
// Option not found
$debug = true;
Expand Down
48 changes: 46 additions & 2 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@
}
</style>

<?php // Check if ad lists should be updated after saving ...
if(isset($_POST["submit"])) {
if($_POST["submit"] == "saveupdate") {
// If that is the case -> refresh to the gravity page and start updating immediately
?>
<meta http-equiv="refresh" content="1;url=gravity.php?go">
<?php }} ?>

<?php if(isset($debug)){ ?>
<div id="alDebug" class="alert alert-warning alert-dismissible fade in" role="alert">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4><i class="icon fa fa-warning"></i> Debug</h4>
<?php print_r($_POST); ?>
<pre><?php print_r($_POST); ?></pre>
</div>
<?php } ?>

Expand Down Expand Up @@ -518,7 +526,43 @@ function convertseconds($argument) {
}

?>
<div class="box box-success">
<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">
<label>Lists used to generate Pi-hole's Gravity</label>
<?php foreach ($adlist as $key => $value) { ?>
<div class="form-group">
<div class="checkbox">
<label style="word-break: break-word;">
<input type="checkbox" name="adlist-enable-<?php echo $key; ?>" <?php if($value[0]){ ?>checked<?php } ?>>
<a href="<?php echo htmlentities ($value[1]); ?>" target="_new"><?php echo htmlentities($value[1]); ?></a>
<input type="checkbox" name="adlist-del-<?php echo $key; ?>" hidden>
<br>
<button class="btn btn-danger btn-xs" id="adlist-btn-<?php echo $key; ?>">
<span class="glyphicon glyphicon-trash"></span>
</button>
</label>
</div>
</div>
<?php } ?>
<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>
</div>
<div class="box-footer">
<input type="hidden" name="field" value="adlists">
<button type="submit" class="btn btn-primary" name="submit" value="save">Save</button>
<button type="submit" class="btn btn-primary pull-right" name="submit" value="saveupdate">Save and Update</button>
</div>
</form>
</div>
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">API</h3>
</div>
Expand Down