mirror of
https://github.com/pi-hole/web.git
synced 2026-02-15 07:25:39 +00:00
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:
51
api_db.php
51
api_db.php
@@ -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();
|
||||
|
||||
46
db_lists.php
46
db_lists.php
@@ -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>
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user