Skip to content

Commit b29a423

Browse files
authored
Pi-hole web v5.18.4 (#2523)
2 parents fb1b5c3 + acb7892 commit b29a423

9 files changed

Lines changed: 242 additions & 161 deletions

File tree

api.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@
7575
$data = array_merge($data, $current);
7676
$data = array_merge($data, $latest);
7777
$data = array_merge($data, $branches);
78+
} elseif (isset($_GET['setTempUnit'])) {
79+
$unit = strtolower($_GET['setTempUnit']);
80+
if ($unit == 'c' || $unit == 'f' || $unit == 'k') {
81+
pihole_execute('-a -'.$unit);
82+
$result = 'success';
83+
} else {
84+
// invalid unit
85+
$result = 'error';
86+
}
87+
88+
$data = array_merge($data, array('result' => $result));
7889
} elseif (isset($_GET['list'])) {
7990
if (!$auth) {
8091
exit('Not authorized!');

db_queries.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,21 @@
8484
<!-- small box -->
8585
<div class="small-box bg-aqua no-user-select">
8686
<div class="inner">
87-
<h3 class="statistic" id="queries_blocked_exact">---</h3>
88-
<p>Queries Blocked</p>
87+
<h3 class="statistic" id="dns_queries">---</h3>
88+
<p>Total Queries</p>
8989
</div>
9090
<div class="icon">
91-
<i class="fas fa-hand-paper"></i>
91+
<i class="fas fa-globe-americas"></i>
9292
</div>
9393
</div>
9494
</div>
9595
<!-- ./col -->
9696
<div class="col-lg-3 col-xs-12">
9797
<!-- small box -->
98-
<div class="small-box bg-aqua no-user-select">
98+
<div class="small-box bg-red no-user-select">
9999
<div class="inner">
100-
<h3 class="statistic" id="queries_wildcard_blocked">---</h3>
101-
<p>Queries Blocked (Wildcards)</p>
100+
<h3 class="statistic" id="queries_blocked_exact">---</h3>
101+
<p>Queries Blocked</p>
102102
</div>
103103
<div class="icon">
104104
<i class="fas fa-hand-paper"></i>
@@ -108,13 +108,13 @@
108108
<!-- ./col -->
109109
<div class="col-lg-3 col-xs-12">
110110
<!-- small box -->
111-
<div class="small-box bg-green no-user-select">
111+
<div class="small-box bg-red no-user-select">
112112
<div class="inner">
113-
<h3 class="statistic" id="dns_queries">---</h3>
114-
<p>Queries Total</p>
113+
<h3 class="statistic" id="queries_wildcard_blocked">---</h3>
114+
<p>Queries Blocked (Wildcards)</p>
115115
</div>
116116
<div class="icon">
117-
<i class="fas fa-globe-americas"></i>
117+
<i class="fas fa-hand-paper"></i>
118118
</div>
119119
</div>
120120
</div>
@@ -124,7 +124,7 @@
124124
<div class="small-box bg-yellow no-user-select">
125125
<div class="inner">
126126
<h3 class="statistic" id="queries_percentage_today">---</h3>
127-
<p>Queries Blocked</p>
127+
<p>Percentage Blocked</p>
128128
</div>
129129
<div class="icon">
130130
<i class="fas fa-chart-pie"></i>

scripts/pi-hole/js/footer.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ function initCheckboxRadioStyle() {
160160

161161
function initCPUtemp() {
162162
function setCPUtemp(unit) {
163-
if (localStorage) {
164-
localStorage.setItem("tempunit", tempunit);
165-
}
166-
167163
var temperature = parseFloat($("#rawtemp").text());
168164
var displaytemp = $("#tempdisplay");
169165
if (!isNaN(temperature)) {
@@ -185,10 +181,30 @@ function initCPUtemp() {
185181
}
186182
}
187183

188-
// Read from local storage, initialize if needed
189-
var tempunit = localStorage ? localStorage.getItem("tempunit") : null;
190-
if (tempunit === null) {
191-
tempunit = "C";
184+
function setSetupvarsTempUnit(unit, showmsg = true) {
185+
var token = encodeURIComponent($("#token").text());
186+
$.getJSON("api.php?setTempUnit=" + unit + "&token=" + token, function (data) {
187+
if (showmsg === true) {
188+
if ("result" in data && data.result === "success") {
189+
utils.showAlert("success", "", "Temperature unit set to " + unit, "");
190+
} else {
191+
utils.showAlert("error", "", "", "Temperature unit not set");
192+
}
193+
}
194+
});
195+
}
196+
197+
// Read the temperature unit from HTML code
198+
var tempunit = $("#tempunit").text();
199+
if (!tempunit) {
200+
// if no value was set in setupVars.conf, tries to retrieve the old config from localstorage
201+
tempunit = localStorage ? localStorage.getItem("tempunit") : null;
202+
if (tempunit === null) {
203+
tempunit = "C";
204+
} else {
205+
// if some value was found on localstorage, set the value in setupVars.conf
206+
setSetupvarsTempUnit(tempunit, false);
207+
}
192208
}
193209

194210
setCPUtemp(tempunit);
@@ -200,6 +216,9 @@ function initCPUtemp() {
200216
tempunitSelector.on("change", function () {
201217
tempunit = $(this).val();
202218
setCPUtemp(tempunit);
219+
220+
// store the selected value on setupVars.conf
221+
setSetupvarsTempUnit(tempunit);
203222
});
204223
}
205224
}

scripts/pi-hole/php/func.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function getCustomDNSEntries()
220220
return $entries;
221221
}
222222

223-
function addCustomDNSEntry($ip = '', $domain = '', $reload = '', $json = true)
223+
function addCustomDNSEntry($ip = '', $domain = '', $reload = '', $json = true, $teleporter = false)
224224
{
225225
try {
226226
if (isset($_REQUEST['ip'])) {
@@ -279,7 +279,8 @@ function addCustomDNSEntry($ip = '', $domain = '', $reload = '', $json = true)
279279
foreach ($domains as $domain) {
280280
pihole_execute('-a addcustomdns '.$ip.' '.$domain.' '.$reload);
281281
}
282-
if ($num > 0) {
282+
// restart only if not called from teleporter.php as it handles restarts itself
283+
if (($num > 0) && (!$teleporter)) {
283284
pihole_execute('restartdns');
284285
}
285286

@@ -397,7 +398,7 @@ function getCustomCNAMEEntries()
397398
return $entries;
398399
}
399400

400-
function addCustomCNAMEEntry($domain = '', $target = '', $reload = '', $json = true)
401+
function addCustomCNAMEEntry($domain = '', $target = '', $reload = '', $json = true, $teleporter = false)
401402
{
402403
try {
403404
if (isset($_REQUEST['domain'])) {
@@ -460,7 +461,8 @@ function addCustomCNAMEEntry($domain = '', $target = '', $reload = '', $json = t
460461
pihole_execute('-a addcustomcname '.$d.' '.$target.' '.$reload);
461462
}
462463

463-
if ($num > 0) {
464+
// restart only if not called from teleporter.php as it handles restarts itself
465+
if (($num > 0) && (!$teleporter)) {
464466
pihole_execute('restartdns');
465467
}
466468

scripts/pi-hole/php/header_authenticated.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,23 @@ function getTemperature()
9898
$limit = null;
9999
}
100100

101-
return array($celsius, $limit);
101+
// Get user-defined temperature limit if set
102+
if (isset($setupVars['TEMPERATUREUNIT'])) {
103+
switch (strtoupper($setupVars['TEMPERATUREUNIT'])) {
104+
case 'F':
105+
case 'K':
106+
$unit = strtoupper($setupVars['TEMPERATUREUNIT']);
107+
break;
108+
109+
default:
110+
$unit = 'C';
111+
}
112+
} else {
113+
// no value is set in setupVars.conf
114+
$unit = '';
115+
}
116+
117+
return array($celsius, $limit, $unit);
102118
}
103119

104120
check_cors();
@@ -113,7 +129,7 @@ function getTemperature()
113129
$maxlifetime = ini_get('session.gc_maxlifetime');
114130

115131
// Get temperature
116-
list($celsius, $temperaturelimit) = getTemperature();
132+
list($celsius, $temperaturelimit, $temperatureunit) = getTemperature();
117133

118134
// Get CPU load
119135
$loaddata = sys_getloadavg();

scripts/pi-hole/php/sidebar.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
}
5858
echo '<span id="temperature"><i class="fa fa-w fa-fire '.$tempcolor.'" style="width: 1em !important"></i> ';
5959
echo 'Temp:&nbsp;<span id="rawtemp" hidden>'.$celsius.'</span>';
60+
echo '<span id="tempunit" hidden>'.$temperatureunit.'</span>';
6061
echo '<span id="tempdisplay"></span></span>';
6162
}
6263
?>

scripts/pi-hole/php/teleporter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ function noun($num)
493493
if (isset($_POST['localdnsrecords']) && $file->getFilename() === 'custom.list') {
494494
ob_start();
495495
$reload = 'false';
496+
$teleporter = true;
496497
if ($flushtables) {
497498
// Defined in func.php included via auth.php
498499
// passing reload="false" will not restart Pi-hole
@@ -502,7 +503,7 @@ function noun($num)
502503
$localdnsrecords = process_file(file_get_contents($file));
503504
foreach ($localdnsrecords as $record) {
504505
list($ip, $domain) = explode(' ', $record);
505-
if (addCustomDNSEntry($ip, $domain, $reload, false)) {
506+
if (addCustomDNSEntry($ip, $domain, $reload, false, $teleporter)) {
506507
++$num;
507508
}
508509
}
@@ -517,6 +518,7 @@ function noun($num)
517518
if (isset($_POST['localcnamerecords']) && $file->getFilename() === '05-pihole-custom-cname.conf') {
518519
ob_start();
519520
$reload = 'false';
521+
$teleporter = true;
520522
if ($flushtables) {
521523
// Defined in func.php included via auth.php
522524
// passing reload="false" will not restart Pi-hole
@@ -534,7 +536,7 @@ function noun($num)
534536
$domain = implode(',', array_slice($explodedLine, 0, -1));
535537
$target = $explodedLine[count($explodedLine) - 1];
536538

537-
if (addCustomCNAMEEntry($domain, $target, $reload, false)) {
539+
if (addCustomCNAMEEntry($domain, $target, $reload, false, $teleporter)) {
538540
++$num;
539541
}
540542
}

0 commit comments

Comments
 (0)