Skip to content

Commit

Permalink
Pi-hole web v5.18.4 (#2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
PromoFaux authored Feb 10, 2023
2 parents fb1b5c3 + acb7892 commit b29a423
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 161 deletions.
11 changes: 11 additions & 0 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@
$data = array_merge($data, $current);
$data = array_merge($data, $latest);
$data = array_merge($data, $branches);
} elseif (isset($_GET['setTempUnit'])) {
$unit = strtolower($_GET['setTempUnit']);
if ($unit == 'c' || $unit == 'f' || $unit == 'k') {
pihole_execute('-a -'.$unit);
$result = 'success';
} else {
// invalid unit
$result = 'error';
}

$data = array_merge($data, array('result' => $result));
} elseif (isset($_GET['list'])) {
if (!$auth) {
exit('Not authorized!');
Expand Down
22 changes: 11 additions & 11 deletions db_queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,21 @@
<!-- small box -->
<div class="small-box bg-aqua no-user-select">
<div class="inner">
<h3 class="statistic" id="queries_blocked_exact">---</h3>
<p>Queries Blocked</p>
<h3 class="statistic" id="dns_queries">---</h3>
<p>Total Queries</p>
</div>
<div class="icon">
<i class="fas fa-hand-paper"></i>
<i class="fas fa-globe-americas"></i>
</div>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-12">
<!-- small box -->
<div class="small-box bg-aqua no-user-select">
<div class="small-box bg-red no-user-select">
<div class="inner">
<h3 class="statistic" id="queries_wildcard_blocked">---</h3>
<p>Queries Blocked (Wildcards)</p>
<h3 class="statistic" id="queries_blocked_exact">---</h3>
<p>Queries Blocked</p>
</div>
<div class="icon">
<i class="fas fa-hand-paper"></i>
Expand All @@ -108,13 +108,13 @@
<!-- ./col -->
<div class="col-lg-3 col-xs-12">
<!-- small box -->
<div class="small-box bg-green no-user-select">
<div class="small-box bg-red no-user-select">
<div class="inner">
<h3 class="statistic" id="dns_queries">---</h3>
<p>Queries Total</p>
<h3 class="statistic" id="queries_wildcard_blocked">---</h3>
<p>Queries Blocked (Wildcards)</p>
</div>
<div class="icon">
<i class="fas fa-globe-americas"></i>
<i class="fas fa-hand-paper"></i>
</div>
</div>
</div>
Expand All @@ -124,7 +124,7 @@
<div class="small-box bg-yellow no-user-select">
<div class="inner">
<h3 class="statistic" id="queries_percentage_today">---</h3>
<p>Queries Blocked</p>
<p>Percentage Blocked</p>
</div>
<div class="icon">
<i class="fas fa-chart-pie"></i>
Expand Down
35 changes: 27 additions & 8 deletions scripts/pi-hole/js/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ function initCheckboxRadioStyle() {

function initCPUtemp() {
function setCPUtemp(unit) {
if (localStorage) {
localStorage.setItem("tempunit", tempunit);
}

var temperature = parseFloat($("#rawtemp").text());
var displaytemp = $("#tempdisplay");
if (!isNaN(temperature)) {
Expand All @@ -185,10 +181,30 @@ function initCPUtemp() {
}
}

// Read from local storage, initialize if needed
var tempunit = localStorage ? localStorage.getItem("tempunit") : null;
if (tempunit === null) {
tempunit = "C";
function setSetupvarsTempUnit(unit, showmsg = true) {
var token = encodeURIComponent($("#token").text());
$.getJSON("api.php?setTempUnit=" + unit + "&token=" + token, function (data) {
if (showmsg === true) {
if ("result" in data && data.result === "success") {
utils.showAlert("success", "", "Temperature unit set to " + unit, "");
} else {
utils.showAlert("error", "", "", "Temperature unit not set");
}
}
});
}

// Read the temperature unit from HTML code
var tempunit = $("#tempunit").text();
if (!tempunit) {
// if no value was set in setupVars.conf, tries to retrieve the old config from localstorage
tempunit = localStorage ? localStorage.getItem("tempunit") : null;
if (tempunit === null) {
tempunit = "C";
} else {
// if some value was found on localstorage, set the value in setupVars.conf
setSetupvarsTempUnit(tempunit, false);
}
}

setCPUtemp(tempunit);
Expand All @@ -200,6 +216,9 @@ function initCPUtemp() {
tempunitSelector.on("change", function () {
tempunit = $(this).val();
setCPUtemp(tempunit);

// store the selected value on setupVars.conf
setSetupvarsTempUnit(tempunit);
});
}
}
Expand Down
10 changes: 6 additions & 4 deletions scripts/pi-hole/php/func.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function getCustomDNSEntries()
return $entries;
}

function addCustomDNSEntry($ip = '', $domain = '', $reload = '', $json = true)
function addCustomDNSEntry($ip = '', $domain = '', $reload = '', $json = true, $teleporter = false)
{
try {
if (isset($_REQUEST['ip'])) {
Expand Down Expand Up @@ -279,7 +279,8 @@ function addCustomDNSEntry($ip = '', $domain = '', $reload = '', $json = true)
foreach ($domains as $domain) {
pihole_execute('-a addcustomdns '.$ip.' '.$domain.' '.$reload);
}
if ($num > 0) {
// restart only if not called from teleporter.php as it handles restarts itself
if (($num > 0) && (!$teleporter)) {
pihole_execute('restartdns');
}

Expand Down Expand Up @@ -397,7 +398,7 @@ function getCustomCNAMEEntries()
return $entries;
}

function addCustomCNAMEEntry($domain = '', $target = '', $reload = '', $json = true)
function addCustomCNAMEEntry($domain = '', $target = '', $reload = '', $json = true, $teleporter = false)
{
try {
if (isset($_REQUEST['domain'])) {
Expand Down Expand Up @@ -460,7 +461,8 @@ function addCustomCNAMEEntry($domain = '', $target = '', $reload = '', $json = t
pihole_execute('-a addcustomcname '.$d.' '.$target.' '.$reload);
}

if ($num > 0) {
// restart only if not called from teleporter.php as it handles restarts itself
if (($num > 0) && (!$teleporter)) {
pihole_execute('restartdns');
}

Expand Down
20 changes: 18 additions & 2 deletions scripts/pi-hole/php/header_authenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,23 @@ function getTemperature()
$limit = null;
}

return array($celsius, $limit);
// Get user-defined temperature limit if set
if (isset($setupVars['TEMPERATUREUNIT'])) {
switch (strtoupper($setupVars['TEMPERATUREUNIT'])) {
case 'F':
case 'K':
$unit = strtoupper($setupVars['TEMPERATUREUNIT']);
break;

default:
$unit = 'C';
}
} else {
// no value is set in setupVars.conf
$unit = '';
}

return array($celsius, $limit, $unit);
}

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

// Get temperature
list($celsius, $temperaturelimit) = getTemperature();
list($celsius, $temperaturelimit, $temperatureunit) = getTemperature();

// Get CPU load
$loaddata = sys_getloadavg();
Expand Down
1 change: 1 addition & 0 deletions scripts/pi-hole/php/sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
}
echo '<span id="temperature"><i class="fa fa-w fa-fire '.$tempcolor.'" style="width: 1em !important"></i> ';
echo 'Temp:&nbsp;<span id="rawtemp" hidden>'.$celsius.'</span>';
echo '<span id="tempunit" hidden>'.$temperatureunit.'</span>';
echo '<span id="tempdisplay"></span></span>';
}
?>
Expand Down
6 changes: 4 additions & 2 deletions scripts/pi-hole/php/teleporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ function noun($num)
if (isset($_POST['localdnsrecords']) && $file->getFilename() === 'custom.list') {
ob_start();
$reload = 'false';
$teleporter = true;
if ($flushtables) {
// Defined in func.php included via auth.php
// passing reload="false" will not restart Pi-hole
Expand All @@ -502,7 +503,7 @@ function noun($num)
$localdnsrecords = process_file(file_get_contents($file));
foreach ($localdnsrecords as $record) {
list($ip, $domain) = explode(' ', $record);
if (addCustomDNSEntry($ip, $domain, $reload, false)) {
if (addCustomDNSEntry($ip, $domain, $reload, false, $teleporter)) {
++$num;
}
}
Expand All @@ -517,6 +518,7 @@ function noun($num)
if (isset($_POST['localcnamerecords']) && $file->getFilename() === '05-pihole-custom-cname.conf') {
ob_start();
$reload = 'false';
$teleporter = true;
if ($flushtables) {
// Defined in func.php included via auth.php
// passing reload="false" will not restart Pi-hole
Expand All @@ -534,7 +536,7 @@ function noun($num)
$domain = implode(',', array_slice($explodedLine, 0, -1));
$target = $explodedLine[count($explodedLine) - 1];

if (addCustomCNAMEEntry($domain, $target, $reload, false)) {
if (addCustomCNAMEEntry($domain, $target, $reload, false, $teleporter)) {
++$num;
}
}
Expand Down
Loading

0 comments on commit b29a423

Please sign in to comment.