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

Prevent ad blockers from blocking query log UI elements #2038

Closed
wants to merge 5 commits into from
Closed
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
21 changes: 19 additions & 2 deletions api_FTL.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,26 @@
$tmp = explode(" ",$line);

if(($tmp[0] === "domains_being_blocked" && !is_numeric($tmp[1])) || $tmp[0] === "status")
$stats[$tmp[0]] = $tmp[1]; // Expect string response
{
$stats[$tmp[0]] = $tmp[1];
continue;
}

if(isset($_GET['summary']))
{
if($tmp[0] !== "ads_percentage_today")
{
$stats[$tmp[0]] = number_format($tmp[1]);
}
else
{
$stats[$tmp[0]] = number_format($tmp[1], 1, '.', '');
}
}
else
$stats[$tmp[0]] = floatval($tmp[1]); // Expect float response
{
$stats[$tmp[0]] = floatval($tmp[1]);
}
}
$stats['gravity_last_updated'] = gravity_last_update(true);
$data = array_merge($data,$stats);
Expand Down
10 changes: 4 additions & 6 deletions scripts/pi-hole/js/db_queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,16 @@ var reloadCallback = function () {
}
}

var formatter = new Intl.NumberFormat();
$("h3#dns_queries").text(formatter.format(statistics[0]));
$("h3#ads_blocked_exact").text(formatter.format(statistics[2]));
$("h3#ads_wildcard_blocked").text(formatter.format(statistics[3]));
$("h3#dns_queries").text(statistics[0].toLocaleString());
$("h3#ads_blocked_exact").text(statistics[2].toLocaleString());
$("h3#ads_wildcard_blocked").text(statistics[3].toLocaleString());

var percent = 0;
if (statistics[2] + statistics[3] > 0) {
percent = (100 * (statistics[2] + statistics[3])) / statistics[0];
}

var percentage = formatter.format(Math.round(percent * 10) / 10);
$("h3#ads_percentage_today").text(percentage + " %");
$("h3#ads_percentage_today").text(parseFloat(percent).toFixed(1).toLocaleString() + " %");
};

function refreshTableData() {
Expand Down
8 changes: 4 additions & 4 deletions scripts/pi-hole/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,8 @@ function updateSummaryData(runOnce) {
data.ads_blocked_today = "connection";
data.ads_percentage_today = "to";
data.domains_being_blocked = "API";
// Adjust text
$("#temperature").html('<i class="fa fa-circle text-red"></i> FTL offline');
// Show spinner
$("#queries-over-time .overlay").show();
$("#forward-destinations-pie .overlay").show();
Expand All @@ -743,12 +745,12 @@ function updateSummaryData(runOnce) {
} else if (FTLoffline) {
// FTL was previously offline
FTLoffline = false;
$("#temperature").text(" ");
updateQueriesOverTime();
updateTopClientsChart();
updateTopLists();
}

var formatter = new Intl.NumberFormat();
//Element name might have a different name to the property of the API so we split it at |
[
"ads_blocked_today|queries_blocked_today",
Expand All @@ -761,9 +763,7 @@ function updateSummaryData(runOnce) {
var apiName = apiElName[0];
var elName = apiElName[1];
var $todayElement = elName ? $("span#" + elName) : $("span#" + apiName);
// Round to one decimal place and format locale-aware
var text = formatter.format(Math.round(data[apiName] * 10) / 10);
var textData = idx === 2 && data[apiName] !== "to" ? text + "%" : text;
var textData = idx === 2 && data[apiName] !== "to" ? data[apiName] + "%" : data[apiName];
if ($todayElement.text() !== textData && $todayElement.text() !== textData + "%") {
$todayElement.addClass("glow");
$todayElement.text(textData);
Expand Down
6 changes: 1 addition & 5 deletions scripts/pi-hole/js/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ function renderMessage(data, type, row) {
);

case "DNSMASQ_WARN":
return (
"Warning in <code>dnsmasq</code> core:<pre>" +
row.message +
'</pre> Check out <a href="https://docs.pi-hole.net/ftldns/dnsmasq_warn/" target="_blank">our documentation</a> for further information.'
);
return "Warning in <code>dnsmasq</code> core:<pre>" + row.message + "</pre>";

case "LOAD":
return (
Expand Down
51 changes: 15 additions & 36 deletions scripts/pi-hole/php/api_token.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
<html>
<head>
<style>
body {
background: #fff;
margin: 10px 0;
}

.qrcode {
text-align: center;
margin: 0 0 1em;
}

.qrcode svg {
max-width: 100%;
height: auto;
}

.token {
font-size: 14px;
word-break: break-word;
}
</style>
</head>
<body>
<html><body>
<?php
require "auth.php";
require "password.php";
check_cors();

if($auth) {
if(strlen($pwhash) > 0) {
echo '<div class="qrcode">';
if($auth)
{
if(strlen($pwhash) > 0)
{
require_once("../../vendor/qrcode.php");
$qr = QRCode::getMinimumQRCode($pwhash, QR_ERROR_CORRECT_LEVEL_Q);
// The size of each block (in pixels) should be an integer
$qr->printSVG(10);
echo "</div>";
echo 'Raw API Token: <code class="token">' . $pwhash . "</code></div>";
} else {
echo "<p>No password set</p>";
$qr->printHTML("10px");
echo "<br>Raw API Token: <code>" . $pwhash . "</code>";
}
} else {
echo "<p>Not authorized!</p>";
else
{
?><p>No password set<?php
}
}
else
{
?><p>Not authorized!</p><?php
}
?>
</body>
Expand Down
Loading