Skip to content

Commit

Permalink
Add "Query adlists" feature
Browse files Browse the repository at this point in the history
  • Loading branch information
DL6ER committed Nov 22, 2016
1 parent 6230c88 commit 7f7604a
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
6 changes: 6 additions & 0 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@
<i class="fa fa-arrow-circle-down"></i> <span>Update lists</span>
</a>
</li>
<!-- Query adlists -->
<li>
<a href="queryads.php">
<i class="fa fa-search"></i> <span>Query adlists</span>
</a>
</li>
<!-- Toggle -->
<?php
if ($pistatus == "1") {
Expand Down
36 changes: 36 additions & 0 deletions js/pihole/queryads.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function eventsource() {
var ta = $("#output");
var domain = $("#domain");
if(domain.val().length === 0)
return;
var source = new EventSource("php/queryads.php?domain="+domain.val());

// Reset and show field
ta.empty();
ta.show();

source.addEventListener("message", function(e) {
ta.append(e.data);
}, false);

// Will be called when script has finished
source.addEventListener("error", function(e) {
source.close();
}, false);
}

// $(function(){
// eventsourcetest();
// });

// Handle enter button for adding domains
$(document).keypress(function(e) {
if(e.which === 13 && $("#domain").is(":focus")) {
// Enter was pressed, and the input has focus
eventsource();
}
});
// Handle button
$("#btnSearch").on("click", function() {
eventsource();
});
35 changes: 35 additions & 0 deletions php/queryads.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
// Test if domain is set
if(isset($_GET["domain"]))
{
// Remove illegal characters
$url = filter_var($_GET["domain"], FILTER_SANITIZE_URL);
if(!filter_var("http://".$url, FILTER_VALIDATE_URL ) === true)
{
die("Invalid domain!");
}
}
else
{
die("No domain provided");
}

ob_end_flush();
ini_set("output_buffering", "0");
ob_implicit_flush(true);
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');

function echoEvent($datatext) {
echo "data: ".implode("\ndata: ", explode("\n", $datatext))."\n\n";
}

// echoEvent("***START***");

$proc = popen("sudo pihole -q ".$url, 'r');
while (!feof($proc)) {
echoEvent(fread($proc, 4096));
}

// echoEvent("***END***");
?>
23 changes: 23 additions & 0 deletions queryads.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
require "header.php";
?>
<!-- Title -->
<div class="page-header">
<h1>Query list of ad-serving domains</h1>
</div>
<!-- Domain Input -->
<div class="form-group input-group">
<input id="domain" type="text" class="form-control" placeholder="Domain to look for (example.com or sub.example.com)">
<span class="input-group-btn">
<button id="btnSearch" class="btn btn-default" type="button">Search</button>
</span>
</div>

<pre id="output" style="width: 100%; height: 100%;" hidden="true"></pre>

<?php
require "footer.php";
?>


<script src="js/pihole/queryads.js"></script>

0 comments on commit 7f7604a

Please sign in to comment.