Merge pull request #207 from DL6ER/queryfilters

Be able to pass filters to queries.php
This commit is contained in:
Mcat12
2016-11-23 11:49:59 -05:00
committed by GitHub
2 changed files with 62 additions and 3 deletions
+34 -3
View File
@@ -220,11 +220,28 @@ function updateQueryTypes() {
});
}
// Credit: http://stackoverflow.com/questions/1787322/htmlspecialchars-equivalent-in-javascript/4835406#4835406
function escapeHtml(text) {
var map = {
"&": "&",
"<": "&lt;",
">": "&gt;",
"\"": "&quot;",
"\'": "&#039;"
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
}
function updateTopClientsChart() {
$.getJSON("api.php?summaryRaw&getQuerySources", function(data) {
var clienttable = $('#client-frequency').find('tbody:last');
var domain;
for (domain in data.top_sources) {
clienttable.append('<tr> <td>' + domain +
// Sanitize domain
domain = escapeHtml(domain);
var url = "<a href=\"queries.php?client="+domain+"\">"+domain+"</a>";
clienttable.append("<tr> <td>" + url +
'</td> <td>' + data.top_sources[domain] + '</td> <td> <div class="progress progress-sm"> <div class="progress-bar progress-bar-blue" style="width: ' +
data.top_sources[domain] / data.dns_queries_today * 100 + '%"></div> </div> </td> </tr> ');
}
@@ -260,14 +277,28 @@ function updateTopLists() {
$.getJSON("api.php?summaryRaw&topItems", function(data) {
var domaintable = $('#domain-frequency').find('tbody:last');
var adtable = $('#ad-frequency').find('tbody:last');
var url, domain;
for (domain in data.top_queries) {
domaintable.append('<tr> <td>' + domain +
// Sanitize domain
domain = escapeHtml(domain);
if(domain !== "pi.hole")
{
url = "<a href=\"queries.php?domain="+domain+"\">"+domain+"</a>";
}
else
{
url = domain;
}
domaintable.append("<tr> <td>" + url +
'</td> <td>' + data.top_queries[domain] + '</td> <td> <div class="progress progress-sm"> <div class="progress-bar progress-bar-green" style="width: ' +
data.top_queries[domain] / data.dns_queries_today * 100 + '%"></div> </div> </td> </tr> ');
}
for (domain in data.top_ads) {
adtable.append('<tr> <td>' + domain +
// Sanitize domain
domain = escapeHtml(domain);
url = "<a href=\"queries.php?domain="+domain+"\">"+domain+"</a>";
adtable.append("<tr> <td>" + url +
'</td> <td>' + data.top_ads[domain] + '</td> <td> <div class="progress progress-sm"> <div class="progress-bar progress-bar-yellow" style="width: ' +
data.top_ads[domain] / data.ads_blocked_today * 100 + '%"></div> </div> </td> </tr> ');
}
+28
View File
@@ -1,3 +1,14 @@
var tableApi;
function escapeRegex(text) {
var map = {
"(": "\\(",
")": "\\)",
".": "\\.",
};
return text.replace(/[().]/g, function(m) { return map[m]; });
}
$(document).ready(function() {
tableApi = $('#all-queries').DataTable( {
"rowCallback": function( row, data, index ){
@@ -40,6 +51,23 @@ $(document).ready(function() {
add(data[2],"black");
}
} );
// Do we want to filter queries?
var GETDict = {};
location.search.substr(1).split("&").forEach(function(item) {GETDict[item.split("=")[0]] = item.split("=")[1];});
if("client" in GETDict)
{
// Search in third column (zero indexed)
// Use regular expression to only show exact matches, i.e.
// don't show 192.168.0.100 when searching for 192.168.0.1
// true = use regex, false = don't use smart search
tableApi.column(3).search("^"+escapeRegex(GETDict["client"])+"$",true,false);
}
if("domain" in GETDict)
{
// Search in second column (zero indexed)
tableApi.column(2).search("^"+escapeRegex(GETDict["domain"])+"$",true,false);
}
} );
function refreshData() {