diff --git a/api_db.php b/api_db.php index a36e1bb0..320a9a31 100644 --- a/api_db.php +++ b/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(); diff --git a/db_lists.php b/db_lists.php index 13792277..55665ea7 100644 --- a/db_lists.php +++ b/db_lists.php @@ -22,21 +22,43 @@ $token = $_SESSION['token'];

Compute Top Lists from the Pi-hole query database

-
- -
- - -
-
- -
- +
+ +
+

+ Request information from Pi-hole's long-term database +

+
+ +
+
+
+ +
+ +
+
+ +
+ +
+
+
+
+
+
+ + +
+
+ + +
+
+
- -
diff --git a/scripts/pi-hole/js/db_lists.js b/scripts/pi-hole/js/db_lists.js index 3f055fe8..9cede2f3 100644 --- a/scripts/pi-hole/js/db_lists.js +++ b/scripts/pi-hole/js/db_lists.js @@ -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() diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index a8596b8f..667e3807 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -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();