Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CNAME blocking states and show more details in CNAME blocking #1144

Merged
merged 6 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions db_queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,39 @@
<label>Query status:</label>
</div>
<div class="form-group">
<div class="col-md-2">
<div class="col-md-3">
<div class="checkbox">
<label><input type="checkbox" id="type_gravity" checked>Blocked (exact)</label>
<label><input type="checkbox" id="type_forwarded" checked><strong>Permitted: </strong>forwarded</label>
</div>
</div>
<div class="col-md-2">
<div class="checkbox">
<label><input type="checkbox" id="type_forwarded" checked>OK (forwarded)</label>
<label><input type="checkbox" id="type_cached" checked><strong>Permitted: </strong>cached</label>
</div>
</div>
<div class="col-md-2">
<div class="col-md-3">
<div class="checkbox">
<label><input type="checkbox" id="type_cached" checked>OK (cached)</label>
<label><input type="checkbox" id="type_gravity" checked><strong>Blocked: </strong>gravity</label>
</div>
</div>
<div class="col-md-2">
<div class="checkbox">
<label><input type="checkbox" id="type_regex" checked>Blocked (regex/wildcard)</label>
<label><input type="checkbox" id="type_external" checked><strong>Blocked: </strong>external</label>
</div>
</div>
<div class="col-md-2">
<div class="col-md-3">
<div class="checkbox">
<label><input type="checkbox" id="type_blacklist" checked><strong>Blocked: </strong>exact blacklist</label>
</div>
<div class="checkbox">
<label><input type="checkbox" id="type_blacklist" checked>Blocked (blacklist)</label>
<label><input type="checkbox" id="type_regex" checked><strong>Blocked: </strong>regex blacklist</label>
</div>
</div>
<div class="col-md-2">
<div class="col-md-3">
<div class="checkbox">
<label><input type="checkbox" id="type_gravity_CNAME" checked><strong>Blocked: </strong>gravity (CNAME)</label>
</div>
<div class="checkbox">
<label><input type="checkbox" id="type_blacklist_CNAME" checked><strong>Blocked: </strong>exact blacklist (CNAME)</label>
</div>
<div class="checkbox">
<label><input type="checkbox" id="type_external" checked>Blocked (external)</label>
<label><input type="checkbox" id="type_regex_CNAME" checked><strong>Blocked: </strong>regex blacklist (CNAME)</label>
</div>
</div>
</div>
Expand Down
34 changes: 32 additions & 2 deletions scripts/pi-hole/js/db_queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ function getQueryTypes() {
queryType.push([6, 7, 8]);
}

if ($("#type_gravity_CNAME").prop("checked")) {
queryType.push(9);
}

if ($("#type_regex_CNAME").prop("checked")) {
queryType.push(10);
}

if ($("#type_blacklist_CNAME").prop("checked")) {
queryType.push(11);
}

return queryType.join(",");
}

Expand Down Expand Up @@ -282,13 +294,13 @@ $(document).ready(function() {
break;
case 4:
color = "red";
fieldtext = "Blocked <br class='hidden-lg'>(regex/wildcard)";
fieldtext = "Blocked <br class='hidden-lg'>(regex blacklist)";
buttontext =
'<button type="button" class="btn btn-default btn-sm text-green"><i class="fas fa-check"></i> Whitelist</button>';
break;
case 5:
color = "red";
fieldtext = "Blocked <br class='hidden-lg'>(blacklist)";
fieldtext = "Blocked <br class='hidden-lg'>(exact blacklist)";
buttontext =
'<button type="button" class="btn btn-default btn-sm text-green"><i class="fas fa-check"></i> Whitelist</button>';
break;
Expand All @@ -307,6 +319,24 @@ $(document).ready(function() {
fieldtext = "Blocked <br class='hidden-lg'>(external, NXRA)";
buttontext = "";
break;
case 9:
color = "red";
fieldtext = "Blocked (gravity, CNAME)";
buttontext =
'<button type="button" class="btn btn-default btn-sm text-green"><i class="fas fa-check"></i> Whitelist</button>';
break;
case 10:
color = "red";
fieldtext = "Blocked <br class='hidden-lg'>(regex blacklist, CNAME)";
buttontext =
'<button type="button" class="btn btn-default btn-sm text-green"><i class="fas fa-check"></i> Whitelist</button>';
break;
case 11:
color = "red";
fieldtext = "Blocked <br class='hidden-lg'>(exact blacklist, CNAME)";
buttontext =
'<button type="button" class="btn btn-default btn-sm text-green"><i class="fas fa-check"></i> Whitelist</button>';
break;
default:
color = "black";
fieldtext = "Unknown";
Expand Down
27 changes: 27 additions & 0 deletions scripts/pi-hole/js/groups-domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
var table;
var groups = [];
var token = $("#token").html();
var GETDict = {};

function get_groups() {
$.post(
Expand All @@ -24,6 +25,13 @@ function get_groups() {
}

$(document).ready(function() {
window.location.search
.substr(1)
.split("&")
.forEach(function(item) {
GETDict[item.split("=")[0]] = item.split("=")[1];
});

$("#btnAdd").on("click", addDomain);

get_groups();
Expand Down Expand Up @@ -122,6 +130,13 @@ function initTable() {
);
}

// Highlight row
if ("domainid" in GETDict && data.id === parseInt(GETDict.domainid)) {
$(row)
.find("td")
.addClass("highlight");
}

// Select assigned groups
sel.val(data.groups);
// Initialize multiselect
Expand Down Expand Up @@ -166,6 +181,18 @@ function initTable() {
data.columns[0].visible = false;
// Apply loaded state to table
return data;
},
initComplete: function() {
if ("domainid" in GETDict) {
var pos = table
.column(0, { order: "current" })
.data()
.indexOf(parseInt(GETDict.domainid));
if (pos >= 0) {
var page = Math.floor(pos / table.page.info().length);
table.page(page).draw(false);
}
}
}
});

Expand Down
65 changes: 55 additions & 10 deletions scripts/pi-hole/js/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ $(document).ready(function() {
}

// Query status
var blocked, fieldtext, buttontext, colorClass;
var blocked,
fieldtext,
buttontext,
colorClass,
isCNAME = false;

switch (data[4]) {
case "1":
blocked = true;
Expand All @@ -192,14 +197,26 @@ $(document).ready(function() {
case "4":
blocked = true;
colorClass = "text-red";
fieldtext = "Blocked <br class='hidden-lg'>(regex/wildcard)";
fieldtext = "Blocked <br class='hidden-lg'>(regex blacklist)";

if (data.length > 9 && data[9] > -1) {
fieldtext =
"<a href='groups-domains.php?domainid=" +
data[9] +
"' class=" +
colorClass +
">" +
fieldtext +
' <i class="fas fa-link"></i></a>';
}

buttontext =
'<button type="button" class="btn btn-default btn-sm text-green"><i class="fas fa-check"></i> Whitelist</button>';
break;
case "5":
blocked = true;
colorClass = "text-red";
fieldtext = "Blocked <br class='hidden-lg'>(blacklist)";
fieldtext = "Blocked <br class='hidden-lg'>(exact blacklist)";
buttontext =
'<button type="button" class="btn btn-default btn-sm text-green"><i class="fas fa-check"></i> Whitelist</button>';
break;
Expand All @@ -221,22 +238,48 @@ $(document).ready(function() {
fieldtext = "Blocked <br class='hidden-lg'>(external, NXRA)";
buttontext = "";
break;
case "9":
blocked = true;
colorClass = "text-red";
fieldtext = "Blocked (gravity, CNAME)";
buttontext =
'<button type="button" class="btn btn-default btn-sm text-green"><i class="fas fa-check"></i> Whitelist</button>';
isCNAME = true;
break;
case "10":
blocked = true;
colorClass = "text-red";
fieldtext = "Blocked <br class='hidden-lg'>(regex blacklist, CNAME)";
buttontext =
'<button type="button" class="btn btn-default btn-sm text-green"><i class="fas fa-check"></i> Whitelist</button>';
isCNAME = true;
break;
case "11":
blocked = true;
colorClass = "text-red";
fieldtext = "Blocked <br class='hidden-lg'>(exact blacklist, CNAME)";
buttontext =
'<button type="button" class="btn btn-default btn-sm text-green"><i class="fas fa-check"></i> Whitelist</button>';
isCNAME = true;
break;
default:
blocked = false;
colorClass = "text-black";
fieldtext = "Unknown (" + parseInt(data[4]) + ")";
buttontext = "";
}

// Add extra label when blocking happend during deep CNAME inspection
if (blocked && data.length > 6 && data[6] === "3") {
fieldtext += "<br>CNAME";
}

$(row).addClass(colorClass);
$("td:eq(4)", row).html(fieldtext);
$("td:eq(6)", row).html(buttontext);

// Add domain in CNAME chain causing the query to have been blocked
var domain = data[2];
var CNAME_domain = data[8];
if (isCNAME) {
$("td:eq(2)", row).text(domain + "\n(blocked " + CNAME_domain + ")");
}

// Check for existence of sixth column and display only if not Pi-holed
var replytext;
if (data.length > 6 && !blocked) {
Expand Down Expand Up @@ -387,14 +430,16 @@ $(document).ready(function() {
// Domain
api.$("td:eq(2)").click(function() {
if (autofilter()) {
api.search(this.textContent).draw();
var domain = this.textContent.split("\n")[0];
api.search(domain).draw();
$("#resetButton").show();
}
});
api.$("td:eq(2)").hover(
function() {
if (autofilter()) {
this.title = "Click to show only queries with domain " + this.textContent;
var domain = this.textContent.split("\n")[0];
this.title = "Click to show only queries with domain " + domain;
this.style.color = "#72afd2";
} else {
this.title = "";
Expand Down
4 changes: 4 additions & 0 deletions style/pi-hole.css
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,7 @@
.text-vivid-blue {
color: #36f !important;
}

td.highlight {
background-color: yellow;
}