Merge pull request #209 from DL6ER/queryads

Query list of ad-serving domains via Web UI
This commit is contained in:
Mcat12
2016-11-23 11:35:15 -05:00
committed by GitHub
4 changed files with 108 additions and 0 deletions
+6
View File
@@ -256,6 +256,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") {
+38
View File
@@ -0,0 +1,38 @@
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
$(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();
});
+41
View File
@@ -0,0 +1,41 @@
<?php
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";
}
// Credit: http://stackoverflow.com/a/4694816/2087442
function is_valid_domain_name($domain_name)
{
return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name) //valid chars check
&& preg_match("/^.{1,253}$/", $domain_name) //overall length check
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name) ); //length of each label
}
// Test if domain is set
if(isset($_GET["domain"]))
{
// Is this a valid domain?
$url = $_GET["domain"];
if(!is_valid_domain_name($url))
{
echoEvent("Invalid domain!");
die();
}
}
else
{
echoEvent("No domain provided");
die();
}
$proc = popen("sudo pihole -q ".$url, 'r');
while (!feof($proc)) {
echoEvent(fread($proc, 4096));
}
?>
+23
View File
@@ -0,0 +1,23 @@
<?php
require "header.php";
?>
<!-- Title -->
<div class="page-header">
<h1>Find Ad Domain In Lists</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>