mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
Merge pull request #831 from pi-hole/new/longterm/select_query_type
Add query type selection for Long-term Query Log
This commit is contained in:
+20
-1
@@ -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();
|
||||
|
||||
@@ -40,6 +40,44 @@ $token = $_SESSION['token'];
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<label>Query status:</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-2">
|
||||
<div class="checkbox">
|
||||
<label><input type="checkbox" id="type_gravity" checked>Blocked (exact)</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="checkbox">
|
||||
<label><input type="checkbox" id="type_forwarded" checked>OK (forwarded)</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="checkbox">
|
||||
<label><input type="checkbox" id="type_cached" checked>OK (cached)</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="checkbox">
|
||||
<label><input type="checkbox" id="type_regex" checked>Blocked (regex/wildcard)</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="checkbox">
|
||||
<label><input type="checkbox" id="type_blacklist" checked>Blocked (blacklist)</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="checkbox">
|
||||
<label><input type="checkbox" id="type_external" checked>Blocked (external)</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="timeoutWarning" class="alert alert-warning alert-dismissible fade in" role="alert" hidden="true">
|
||||
Depending on how large of a range you specified, the request may time out while Pi-hole tries to retrieve all the data.<br/><span id="err"></span>
|
||||
</div>
|
||||
|
||||
@@ -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 ){
|
||||
|
||||
Reference in New Issue
Block a user