Skip to content

Commit

Permalink
Add per-browser setting to ignore non-fatal dnsmasq warnings
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Feb 26, 2022
1 parent e4d293a commit 21964cf
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
5 changes: 4 additions & 1 deletion api_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ function parseDBData($results, $interval, $from, $until) {

if (isset($_GET['status']))
{
$results = $db->query('SELECT COUNT(*) FROM message;');
$extra = ";";
if(isset($_GET["ignore"]) && $_GET["ignore"] === 'DNSMASQ_WARN')
$extra = "WHERE type != 'DNSMASQ_WARN';";
$results = $db->query('SELECT COUNT(*) FROM message '.$extra);

if(!is_bool($results))
$result = array('message_count' => $results->fetchArray()[0]);
Expand Down
28 changes: 17 additions & 11 deletions scripts/pi-hole/js/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,24 @@ function piholeChange(action, duration) {
}

function checkMessages() {
$.getJSON("api_db.php?status", function (data) {
if ("message_count" in data && data.message_count > 0) {
var title =
data.message_count > 1
? "There are " + data.message_count + " warnings. Click for further details."
: "There is one warning. Click for further details.";

$("#pihole-diagnosis").prop("title", title);
$("#pihole-diagnosis-count").text(data.message_count);
$("#pihole-diagnosis").removeClass("hidden");
var ignoreNonfatal = localStorage
? localStorage.getItem("hideNonfatalDnsmasqWarnings_chkbox")
: false;
$.getJSON(
"api_db.php?status" + (ignoreNonfatal === "true" ? "&ignore=DNSMASQ_WARN" : ""),
function (data) {
if ("message_count" in data && data.message_count > 0) {
var title =
data.message_count > 1
? "There are " + data.message_count + " warnings. Click for further details."
: "There is one warning. Click for further details.";

$("#pihole-diagnosis").prop("title", title);
$("#pihole-diagnosis-count").text(data.message_count);
$("#pihole-diagnosis").removeClass("hidden");
}
}
});
);
}

function testCookies() {
Expand Down
25 changes: 24 additions & 1 deletion scripts/pi-hole/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */

/* global utils:false */
/* global utils:false, checkMessages:false */
var token = $("#token").text();

$(function () {
Expand Down Expand Up @@ -446,3 +446,26 @@ $('button[id="removedynamic"]').on("click", function () {
},
});
});

// Non-fatal dnsmasq warnings toggle
$(function () {
var nonfatalwarnigns = $("#hideNonfatalDnsmasqWarnings");
var chkboxData = localStorage ? localStorage.getItem("hideNonfatalDnsmasqWarnings_chkbox") : null;

if (chkboxData !== null) {
// Restore checkbox state
nonfatalwarnigns.prop("checked", chkboxData === "true");
} else {
// Initialize checkbox
nonfatalwarnigns.prop("checked", false);
if (localStorage) {
localStorage.setItem("hideNonfatalDnsmasqWarnings_chkbox", false);
}
}

nonfatalwarnigns.click(function () {
localStorage.setItem("hideNonfatalDnsmasqWarnings_chkbox", nonfatalwarnigns.prop("checked"));
// Call check messages to make new setting effective
checkMessages();
});
});
10 changes: 9 additions & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ function convertseconds($argument)
<div class="col-md-6">
<div class="box box-warning">
<div class="box-header with-border">
<h3 class="box-title">Styling (auto saved, per-browser)</h3>
<h3 class="box-title">Per-browser settings (auto saved)</h3>
</div>
<div class="box-body">
<div class="row">
Expand Down Expand Up @@ -1217,6 +1217,14 @@ function convertseconds($argument)
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div>
<input type="checkbox" name="hideNonfatalDnsmasqWarnings" id="hideNonfatalDnsmasqWarnings" value="no">
<label for="hideNonfatalDnsmasqWarnings"><strong>Hide non-fatal <code>dnsmasq</code> warnings</strong></label>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 21964cf

Please sign in to comment.