diff --git a/api_db.php b/api_db.php
index 567e2c32..daa04813 100644
--- a/api_db.php
+++ b/api_db.php
@@ -101,7 +101,26 @@ if (isset($_GET['getAllQueries']) && $auth)
{
$from = intval($_GET["from"]);
$until = intval($_GET["until"]);
- $stmt = $db->prepare("SELECT timestamp, type, domain, client, status FROM queries WHERE timestamp >= :from AND timestamp <= :until ORDER BY timestamp ASC");
+ $dbquery = "SELECT timestamp, type, domain, client, status FROM queries WHERE timestamp >= :from AND timestamp <= :until ";
+ if(isset($_GET["types"]))
+ {
+ $types = $_GET["types"];
+ if(preg_match("/^[0-9]+(?:,[0-9]+)*$/", $types) === 1)
+ {
+ // Append selector to DB query. The used regex ensures
+ // that only numbers, separated by commas are accepted
+ // to avoid code injection and other malicious things
+ // We accept only valid lists like "1,2,3"
+ // We reject ",2,3", "1,2," and similar arguments
+ $dbquery .= "AND status IN (".$types.") ";
+ }
+ else
+ {
+ die("Error. Selector types specified using an invalid format.");
+ }
+ }
+ $dbquery .= "ORDER BY timestamp ASC";
+ $stmt = $db->prepare($dbquery);
$stmt->bindValue(":from", intval($from), SQLITE3_INTEGER);
$stmt->bindValue(":until", intval($until), SQLITE3_INTEGER);
$results = $stmt->execute();
diff --git a/db_queries.php b/db_queries.php
index 3c81e201..ddb633f2 100644
--- a/db_queries.php
+++ b/db_queries.php
@@ -40,6 +40,44 @@ $token = $_SESSION['token'];
+
+
Depending on how large of a range you specified, the request may time out while Pi-hole tries to retrieve all the data.
diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js
index d2317e6b..f50d9802 100644
--- a/scripts/pi-hole/js/db_queries.js
+++ b/scripts/pi-hole/js/db_queries.js
@@ -130,17 +130,47 @@ function handleAjaxError( xhr, textStatus, error ) {
}
else if(xhr.responseText.indexOf("Connection refused") >= 0)
{
- alert( "An error occured while loading the data: Connection refused. Is FTL running?" );
+ alert( "An error occurred while loading the data: Connection refused. Is FTL running?" );
}
else
{
- alert( "An unknown error occured while loading the data.\n"+xhr.responseText );
+ alert( "An unknown error occurred while loading the data.\n"+xhr.responseText );
}
$("#all-queries_processing").hide();
tableApi.clear();
tableApi.draw();
}
+function getQueryTypes()
+{
+ var queryType = [];
+ if($("#type_gravity").prop("checked"))
+ {
+ queryType.push(1);
+ }
+ if($("#type_forwarded").prop("checked"))
+ {
+ queryType.push(2);
+ }
+ if($("#type_cached").prop("checked"))
+ {
+ queryType.push(3);
+ }
+ if($("#type_regex").prop("checked"))
+ {
+ queryType.push(4);
+ }
+ if($("#type_blacklist").prop("checked"))
+ {
+ queryType.push(5);
+ }
+ if($("#type_external").prop("checked"))
+ {
+ queryType.push(6);
+ }
+ return queryType.join(",");
+}
+
var reloadCallback = function()
{
timeoutWarning.hide();
@@ -176,6 +206,12 @@ var reloadCallback = function()
function refreshTableData() {
timeoutWarning.show();
var APIstring = "api_db.php?getAllQueries&from="+from+"&until="+until;
+ // Check if query type filtering is enabled
+ var queryType = getQueryTypes();
+ if(queryType !== "1,2,3,4,5,6")
+ {
+ APIstring += "&types="+queryType;
+ }
statistics = [0,0,0];
tableApi.ajax.url(APIstring).load(reloadCallback);
}
@@ -192,6 +228,12 @@ $(document).ready(function() {
{
APIstring = "api_db.php?getAllQueries=empty";
}
+ // Check if query type filtering is enabled
+ var queryType = getQueryTypes();
+ if(queryType !== 63) // 63 (0b00111111) = all possible query types are selected
+ {
+ APIstring += "&types="+queryType;
+ }
tableApi = $("#all-queries").DataTable( {
"rowCallback": function( row, data, index ){