Add missing columns reply_type, reply_time, dnssec

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
RD WebDesign
2022-05-15 19:11:26 -03:00
parent 0327e4f1fc
commit 7fb8f94ea3
3 changed files with 86 additions and 14 deletions

View File

@@ -64,7 +64,7 @@ if (isset($_GET['getAllQueries']) && $auth)
{
$from = intval($_GET["from"]);
$until = intval($_GET["until"]);
$dbquery = "SELECT timestamp, type, domain, client, status, forward FROM queries WHERE timestamp >= :from AND timestamp <= :until ";
$dbquery = "SELECT timestamp, type, domain, client, status, forward, reply_type, reply_time, dnssec FROM queries WHERE timestamp >= :from AND timestamp <= :until ";
if(isset($_GET["types"]))
{
$types = $_GET["types"];
@@ -101,14 +101,19 @@ if (isset($_GET['getAllQueries']) && $auth)
$first = false;
}
// Convert query type ID to name, encode domain, encode destination
$query_type = getQueryTypeStr($row[1]);
// Format, encode, transform each field (if necessary).
$time = $row[0];
$query_type = getQueryTypeStr($row[1]); // Convert query type ID to name
$domain = utf8_encode(str_replace("~"," ",$row[2]));
$client = $row[3];
$status = $row[4];
$destination = utf8_encode($row[5]);
$reply_type = $row[6];
$reply_time = $row[7];
$dnssec = $row[8];
// Insert into array and output it in JSON format
// array: time type domain client status upstream destination
echo json_encode([$row[0], $query_type, $domain, $row[3], $row[4], $destination]);
echo json_encode([$time, $query_type, $domain, $client, $status, $destination, $reply_type, $reply_time, $dnssec]);
}
}

View File

@@ -180,6 +180,7 @@
<th>Domain</th>
<th>Client</th>
<th>Status</th>
<th>Reply</th>
<th>Action</th>
</tr>
</thead>
@@ -190,6 +191,7 @@
<th>Domain</th>
<th>Client</th>
<th>Status</th>
<th>Reply</th>
<th>Action</th>
</tr>
</tfoot>

View File

@@ -20,6 +20,23 @@ var datepickerManuallySelected = false;
var dateformat = "MMMM Do YYYY, HH:mm";
var replyTypes = [
"N/A",
"NODATA",
"NXDOMAIN",
"CNAME",
"IP",
"DOMAIN",
"RRNAME",
"SERVFAIL",
"REFUSED",
"NOTIMP",
"upstream error",
"DNSSEC",
"NONE",
"BLOB",
];
// Do we want to filter queries?
var GETDict = {};
window.location.search
@@ -210,6 +227,34 @@ $(function () {
tableApi = $("#all-queries").DataTable({
rowCallback: function (row, data) {
var replyid = parseInt(data[6], 10);
var dnssecStatus;
switch (data[8]) {
case "1":
dnssecStatus = '<br><span class="text-green">SECURE';
break;
case "2":
dnssecStatus = '<br><span class="text-orange">INSECURE';
break;
case "3":
dnssecStatus = '<br><span class="text-red">BOGUS';
break;
case "4":
dnssecStatus = '<br><span class="text-red">ABANDONED';
break;
case "5":
dnssecStatus = '<br><span class="text-orange">UNKNOWN';
break;
default:
// No DNSSEC
dnssecStatus = "";
}
if (dnssecStatus.length > 0) {
if (replyid === 7) dnssecStatus += " (refused upstream)";
dnssecStatus += "</span>";
}
var fieldtext,
buttontext = "",
blocked = false;
@@ -222,14 +267,18 @@ $(function () {
break;
case 2:
fieldtext =
"<span class='text-green'>OK</span> (forwarded to <br class='hidden-lg'>" +
replyid === 0
? "<span class='text-green'>OK</span> (sent to <br class='hidden-lg'>"
: "<span class='text-green'>OK</span> (answered by <br class='hidden-lg'>";
fieldtext +=
(data.length > 5 && data[5] !== "N/A" ? data[5] : "") +
dnssecStatus +
")";
buttontext =
'<button type="button" class="btn btn-default btn-sm text-red"><i class="fa fa-ban"></i> Blacklist</button>';
break;
case 3:
fieldtext = "<span class='text-green'>OK</span> <br class='hidden-lg'>(cache)";
fieldtext = "<span class='text-green'>OK</span> <br class='hidden-lg'>(cache)" + dnssecStatus;
buttontext =
'<button type="button" class="btn btn-default btn-sm text-red"><i class="fa fa-ban"></i> Blacklist</button>';
break;
@@ -305,13 +354,28 @@ $(function () {
fieldtext = "Unknown (" + parseInt(data[4], 10) + ")";
}
// Cannot block internal queries of this type
if ((data[1] === "DNSKEY" || data[1] === "DS") && data[3] === "pi.hole") buttontext = "";
$(row).addClass(blocked === true ? "blocked-row" : "allowed-row");
if (localStorage && localStorage.getItem("colorfulQueryLog_chkbox") === "true") {
$(row).addClass(blocked === true ? "text-red" : "text-green");
}
// Check for existence of sixth column and display only if not Pi-holed
var replytext =
replyid >= 0 && replyid < replyTypes.length ? replyTypes[replyid] : "? (" + replyid + ")";
replytext += '<input type="hidden" name="id" value="' + replyid + '">';
$("td:eq(4)", row).html(fieldtext);
$("td:eq(5)", row).html(buttontext);
$("td:eq(5)", row).html(replytext);
$("td:eq(6)", row).html(buttontext);
// Show response time only when reply is not N/A
if (data.length > 7 && replyid !== 0) {
$("td:eq(5)", row).append(" (" + (0.1 * data[7]).toFixed(1) + "ms)");
}
// Substitute domain by "." if empty
var domain = data[2];
@@ -343,7 +407,7 @@ $(function () {
order: [[0, "desc"]],
columns: [
{
width: "15%",
width: "12%",
render: function (data, type) {
if (type === "display") {
return moment
@@ -354,11 +418,12 @@ $(function () {
return data;
},
},
{ width: "10%" },
{ width: "40%" },
{ width: "20%", type: "ip-address" },
{ width: "10%" },
{ width: "5%" },
{ width: "9%" },
{ width: "36%" },
{ width: "10%", type: "ip-address" },
{ width: "15%" },
{ width: "9%" },
{ width: "9%" },
],
lengthMenu: [
[10, 25, 50, 100, -1],