diff --git a/auditlog.php b/auditlog.php index 4f105a70..33ed04ac 100644 --- a/auditlog.php +++ b/auditlog.php @@ -68,14 +68,9 @@ -
-

Important: Note that black- and whitelisted domains are not automatically applied on this page to avoid restarting the DNS service too often. Instead, click on this button, to have the new settings become effective:

- -
- diff --git a/custom_dns.php b/custom_dns.php index f1506dab..7e639959 100644 --- a/custom_dns.php +++ b/custom_dns.php @@ -29,11 +29,11 @@
- +
- +
diff --git a/db_queries.php b/db_queries.php index 601b56ad..0035807f 100644 --- a/db_queries.php +++ b/db_queries.php @@ -45,34 +45,39 @@ $token = $_SESSION['token'];
-
+
- + +
+
+
-
+
- + +
+
+
-
+
- + +
+
+
-
+
- +
-
-
- +
-
-
- +
diff --git a/gravity.php b/gravity.php index d86be424..b73cf514 100644 --- a/gravity.php +++ b/gravity.php @@ -15,7 +15,7 @@
@@ -72,6 +73,7 @@
+ Known clients: +
+
- - + +
@@ -59,6 +60,7 @@ ID IP address + Comment Group assignment Action @@ -72,6 +74,7 @@ +
-

- Add a new domain + Add a new domain or regex filter

-
-
- - -
-
- - -
-
- - + +
- +
+
+ +

- List of configured domains + List of entries

@@ -65,7 +118,7 @@ ID - Domain + Domain/RegEx Type Status Comment @@ -82,6 +135,7 @@
+
+ \ No newline at end of file diff --git a/list.php b/list.php deleted file mode 100644 index 95fbcd1a..00000000 --- a/list.php +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - -
-
- - -
-
- -
- - - - - - - -
-
-
- - - - - - - - - -
    - -
      - - - - diff --git a/scripts/pi-hole/js/auditlog.js b/scripts/pi-hole/js/auditlog.js index d1e34d4f..3850b5de 100644 --- a/scripts/pi-hole/js/auditlog.js +++ b/scripts/pi-hole/js/auditlog.js @@ -6,8 +6,7 @@ * Please see LICENSE file for your rights under this license. */ // Define global variables -var auditList = [], - auditTimeout; +var auditTimeout = null; // Credit: http://stackoverflow.com/questions/1787322/htmlspecialchars-equivalent-in-javascript/4835406#4835406 function escapeHtml(text) { @@ -46,7 +45,7 @@ function updateTopLists() { domain = escapeHtml(domain); url = '' + domain + ""; domaintable.append( - " " + + "" + url + " " + data.top_queries[domain] + @@ -68,7 +67,7 @@ function updateTopLists() { printdomain + " (wildcard blocked)"; adtable.append( - " " + + "" + url + " " + data.top_ads[domain] + @@ -77,7 +76,7 @@ function updateTopLists() { } else { url = '' + printdomain + ""; adtable.append( - " " + + "" + url + " " + data.top_ads[domain] + @@ -89,8 +88,14 @@ function updateTopLists() { $("#domain-frequency .overlay").hide(); $("#ad-frequency .overlay").hide(); - // Update top lists data every second - setTimeout(updateTopLists, 1000); + // Update top lists data every ten seconds + // Updates are also triggered by button actions + // and reset the running timer + if (auditTimeout !== null) { + window.clearTimeout(auditTimeout); + } + + auditTimeout = setTimeout(updateTopLists, 10000); }); } @@ -99,10 +104,32 @@ function add(domain, list) { $.ajax({ url: "scripts/pi-hole/php/add.php", method: "post", - data: { domain: domain, list: list, token: token } + data: { domain: domain, list: list, token: token }, + success: function() { + updateTopLists(); + }, + error: function(jqXHR, exception) { + console.log(exception); + } }); } +function blacklistUrl(url) { + // We add to audit last as it will reload the table on success + add(url, "black"); + add(url, "audit"); +} + +function whitelistUrl(url) { + // We add to audit last as it will reload the table on success + add(url, "white"); + add(url, "audit"); +} + +function auditUrl(url) { + add(url, "audit"); +} + $(document).ready(function() { // Pull in data via AJAX updateTopLists(); @@ -110,11 +137,9 @@ $(document).ready(function() { $("#domain-frequency tbody").on("click", "button", function() { var url = $(this) .parents("tr")[0] - .textContent.split(" ")[0]; + .textContent.split(" ")[0]; if ($(this).context.textContent === " Blacklist") { - add(url, "audit"); - add(url, "black"); - $("#gravityBtn").prop("disabled", false); + blacklistUrl(url); } else { auditUrl(url); } @@ -123,36 +148,11 @@ $(document).ready(function() { $("#ad-frequency tbody").on("click", "button", function() { var url = $(this) .parents("tr")[0] - .textContent.split(" ")[0] - .split(" ")[0]; + .textContent.split(" ")[0]; if ($(this).context.textContent === " Whitelist") { - add(url, "audit"); - add(url, "white"); - $("#gravityBtn").prop("disabled", false); + whitelistUrl(url); } else { auditUrl(url); } }); }); - -function auditUrl(url) { - if (auditList.indexOf(url) > -1) { - return; - } - - if (auditTimeout) { - clearTimeout(auditTimeout); - } - - auditList.push(url); - // wait 3 seconds to see if more domains need auditing - // and batch them all into a single request - auditTimeout = setTimeout(function() { - add(auditList.join(" "), "audit"); - auditList = []; - }, 3000); -} - -$("#gravityBtn").on("click", function() { - window.location.replace("gravity.php?go"); -}); diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js index d7f4fe12..f8c22119 100644 --- a/scripts/pi-hole/js/db_queries.js +++ b/scripts/pi-hole/js/db_queries.js @@ -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(","); } @@ -282,13 +294,13 @@ $(document).ready(function() { break; case 4: color = "red"; - fieldtext = "Blocked (regex/wildcard)"; + fieldtext = "Blocked (regex blacklist)"; buttontext = ''; break; case 5: color = "red"; - fieldtext = "Blocked (blacklist)"; + fieldtext = "Blocked (exact blacklist)"; buttontext = ''; break; @@ -307,6 +319,24 @@ $(document).ready(function() { fieldtext = "Blocked (external, NXRA)"; buttontext = ""; break; + case 9: + color = "red"; + fieldtext = "Blocked (gravity, CNAME)"; + buttontext = + ''; + break; + case 10: + color = "red"; + fieldtext = "Blocked (regex blacklist, CNAME)"; + buttontext = + ''; + break; + case 11: + color = "red"; + fieldtext = "Blocked (exact blacklist, CNAME)"; + buttontext = + ''; + break; default: color = "black"; fieldtext = "Unknown"; diff --git a/scripts/pi-hole/js/groups-adlists.js b/scripts/pi-hole/js/groups-adlists.js index 625a3f83..a7a8c89f 100644 --- a/scripts/pi-hole/js/groups-adlists.js +++ b/scripts/pi-hole/js/groups-adlists.js @@ -5,71 +5,11 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global moment:false */ +/* global utils:false */ var table; var groups = []; var token = $("#token").html(); -var info = null; - -function showAlert(type, icon, title, message) { - var opts = {}; - title = " " + title + "
      "; - switch (type) { - case "info": - opts = { - type: "info", - icon: "glyphicon glyphicon-time", - title: title, - message: message - }; - info = $.notify(opts); - break; - case "success": - opts = { - type: "success", - icon: icon, - title: title, - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - case "warning": - opts = { - type: "warning", - icon: "glyphicon glyphicon-warning-sign", - title: title, - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - case "error": - opts = { - type: "danger", - icon: "glyphicon glyphicon-remove", - title: " Error, something went wrong!
      ", - message: message - }; - if (info) { - info.update(opts); - } else { - $.notify(opts); - } - - break; - default: - } -} function get_groups() { $.post( @@ -83,19 +23,10 @@ function get_groups() { ); } -function datetime(date) { - return moment.unix(Math.floor(date)).format("Y-MM-DD HH:mm:ss z"); -} - $(document).ready(function() { $("#btnAdd").on("click", addAdlist); get_groups(); - - $("#select").on("change", function() { - $("#ip-custom").val(""); - $("#ip-custom").prop("disabled", $("#select option:selected").val() !== "custom"); - }); }); function initTable() { @@ -115,46 +46,50 @@ function initTable() { { data: null, width: "80px", orderable: false } ], drawCallback: function() { - $(".deleteAdlist").on("click", deleteAdlist); + $('button[id^="deleteAdlist_"]').on("click", deleteAdlist); }, rowCallback: function(row, data) { + $(row).attr("data-id", data.id); var tooltip = "Added: " + - datetime(data.date_added) + + utils.datetime(data.date_added) + "\nLast modified: " + - datetime(data.date_modified) + + utils.datetime(data.date_modified) + "\nDatabase ID: " + data.id; $("td:eq(0)", row).html( - '' + data.address + "" + '' + data.address + "" ); var disabled = data.enabled === 0; $("td:eq(1)", row).html( - '" + '" ); - var status = $("#status", row); - status.bootstrapToggle({ + var statusEl = $("#status_" + data.id, row); + statusEl.bootstrapToggle({ on: "Enabled", off: "Disabled", size: "small", onstyle: "success", width: "80px" }); - status.on("change", editAdlist); + statusEl.on("change", editAdlist); - $("td:eq(2)", row).html( - '' - ); - var comment = $("#comment", row); - comment.val(data.comment); - comment.on("change", editAdlist); + $("td:eq(2)", row).html(''); + var commentEl = $("#comment_" + data.id, row); + commentEl.val(data.comment); + commentEl.on("change", editAdlist); $("td:eq(3)", row).empty(); - $("td:eq(3)", row).append(''); - var sel = $("#multiselect", row); + $("td:eq(3)", row).append( + '
      ' + + '
      ' + ); + var selectEl = $("#multiselect_" + data.id, row); // Add all known groups for (var i = 0; i < groups.length; i++) { var extra = ""; @@ -162,7 +97,7 @@ function initTable() { extra = " (disabled)"; } - sel.append( + selectEl.append( $("