mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
Merge pull request #209 from DL6ER/queryads
Query list of ad-serving domains via Web UI
This commit is contained in:
@@ -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") {
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
@@ -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));
|
||||
}
|
||||
?>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user