forked from pi-hole/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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***"); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |