Add per-client and per-domain filtering for the long-term lists page

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2020-04-10 10:32:10 +02:00
parent 592c101e5b
commit e8e436b5fd
4 changed files with 101 additions and 15 deletions

View File

@@ -168,9 +168,26 @@ if (isset($_GET['topClients']) && $auth)
{
$limit = "WHERE timestamp <= :until";
}
if(isset($_GET["client"]) && strlen($_GET["client"]) > 0)
{
$limit .= " AND client = :client";
$client = urldecode($_GET["client"]);
}
if(isset($_GET["domain"]) && strlen($_GET["domain"]) > 0)
{
$limit .= " AND domain = :domain";
$domain = urldecode($_GET["domain"]);
}
$stmt = $db->prepare('SELECT client,count(client) FROM queries '.$limit.' GROUP by client order by count(client) desc limit 20');
$stmt->bindValue(":from", intval($_GET['from']), SQLITE3_INTEGER);
$stmt->bindValue(":until", intval($_GET['until']), SQLITE3_INTEGER);
if(isset($client))
$stmt->bindValue(":client", $client, SQLITE3_TEXT);
if(isset($domain))
$stmt->bindValue(":domain", $domain, SQLITE3_TEXT);
$results = $stmt->execute();
$clientnums = array();
@@ -219,9 +236,26 @@ if (isset($_GET['topDomains']) && $auth)
{
$limit = " AND timestamp <= :until";
}
if(isset($_GET["client"]) && strlen($_GET["client"]) > 0)
{
$limit .= " AND client = :client";
$client = urldecode($_GET["client"]);
}
if(isset($_GET["domain"]) && strlen($_GET["domain"]) > 0)
{
$limit .= " AND domain = :domain";
$domain = urldecode($_GET["domain"]);
}
$stmt = $db->prepare('SELECT domain,count(domain) FROM queries WHERE (STATUS == 2 OR STATUS == 3)'.$limit.' GROUP by domain order by count(domain) desc limit 20');
$stmt->bindValue(":from", intval($_GET['from']), SQLITE3_INTEGER);
$stmt->bindValue(":until", intval($_GET['until']), SQLITE3_INTEGER);
if(isset($client))
$stmt->bindValue(":client", $client, SQLITE3_TEXT);
if(isset($domain))
$stmt->bindValue(":domain", $domain, SQLITE3_TEXT);
$results = $stmt->execute();
$domains = array();
@@ -269,9 +303,26 @@ if (isset($_GET['topAds']) && $auth)
{
$limit = " AND timestamp <= :until";
}
if(isset($_GET["client"]) && strlen($_GET["client"]) > 0)
{
$limit .= " AND client = :client";
$client = urldecode($_GET["client"]);
}
if(isset($_GET["domain"]) && strlen($_GET["domain"]) > 0)
{
$limit .= " AND domain = :domain";
$domain = urldecode($_GET["domain"]);
}
$stmt = $db->prepare('SELECT domain,count(domain) FROM queries WHERE (STATUS == 1 OR STATUS == 4)'.$limit.' GROUP by domain order by count(domain) desc limit 10');
$stmt->bindValue(":from", intval($_GET['from']), SQLITE3_INTEGER);
$stmt->bindValue(":until", intval($_GET['until']), SQLITE3_INTEGER);
if(isset($client))
$stmt->bindValue(":client", $client, SQLITE3_TEXT);
if(isset($domain))
$stmt->bindValue(":domain", $domain, SQLITE3_TEXT);
$results = $stmt->execute();
$addomains = array();

View File

@@ -22,21 +22,43 @@ $token = $_SESSION['token'];
<h1>Compute Top Lists from the Pi-hole query database</h1>
</div>
<div class="row">
<div class="col-md-12">
<!-- Date Input -->
<div class="form-group">
<label>Date and time range:</label>
<div class="input-group">
<div class="input-group-addon">
<i class="far fa-clock"></i>
</div>
<input type="button" class="form-control pull-right" id="querytime" value="Click to select date and time range">
<div class="box">
<!-- /.box-header -->
<div class="box-header with-border">
<h3 class="box-title">
Request information from Pi-hole's long-term database
</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="row">
<div class="col-md-12">
<!-- Date Input -->
<div class="form-group">
<label>Date and time range:</label>
<div class="input-group">
<div class="input-group-addon">
<i class="far fa-clock"></i>
</div>
<input type="button" class="form-control pull-right" id="querytime" value="Click to select date and time range">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label for="client">Limit to specific client:</label>
<input id="client" type="url" class="form-control" placeholder="Leave empty for all clients" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off">
</div>
<div class="col-md-6">
<label for="domain">Limit to specific domain:</label>
<input id="domain" type="url" class="form-control" placeholder="Leave empty for all domains" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off">
</div>
</div>
</div>
</div>
<!-- /.input group -->
</div>
</div>
</div>

View File

@@ -89,7 +89,11 @@ function escapeHtml(text) {
function updateTopClientsChart() {
$("#client-frequency .overlay").show();
$.getJSON("api_db.php?topClients&from=" + from + "&until=" + until, function(data) {
var client = encodeURIComponent($("#client").val());
var domain = encodeURIComponent($("#domain").val());
$.getJSON("api_db.php?topClients&from=" + from + "&until=" + until + "&client=" + client + "&domain=" + domain, function(data) {
// Clear tables before filling them with data
$("#client-frequency td")
.parent()
@@ -145,7 +149,11 @@ function updateTopClientsChart() {
function updateTopDomainsChart() {
$("#domain-frequency .overlay").show();
$.getJSON("api_db.php?topDomains&from=" + from + "&until=" + until, function(data) {
var client = encodeURIComponent($("#client").val());
var domain = encodeURIComponent($("#domain").val());
$.getJSON("api_db.php?topDomains&from=" + from + "&until=" + until + "&client=" + client + "&domain=" + domain, function(data) {
// Clear tables before filling them with data
$("#domain-frequency td")
.parent()
@@ -194,7 +202,11 @@ function updateTopDomainsChart() {
function updateTopAdsChart() {
$("#ad-frequency .overlay").show();
$.getJSON("api_db.php?topAds&from=" + from + "&until=" + until, function(data) {
var client = encodeURIComponent($("#client").val());
var domain = encodeURIComponent($("#domain").val());
$.getJSON("api_db.php?topAds&from=" + from + "&until=" + until + "&client=" + client + "&domain=" + domain, function(data) {
// Clear tables before filling them with data
$("#ad-frequency td")
.parent()

View File

@@ -283,6 +283,7 @@ $(document).ready(function() {
}
);
$("td:eq(4)", row).click(function() {
console.log("Adding");
var new_tab = window.open("groups-domains.php?domainid=" + data[9], "_blank");
if (new_tab) {
new_tab.focus();