From 4966f01dde29bfb477b37cafae521f3f958eb1f5 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Fri, 27 Jan 2023 00:34:06 -0300 Subject: [PATCH 1/7] Use and set the unit on setupVars.conf option TEMPERATUREUNIT New behavior!!! The temperature unit will be set GLOBALLY and not per browser. - if a TEMPERATUREUNIT is set in setupVars.conf file, the value will be used. - if there is no unit set in setupVars.conf, "C" will be used; - changing the value on the web interface WILL CHANGE setupVars.conf. - if the browser has an old value set on locastorage, this will be ingnored. Signed-off-by: RD WebDesign --- api.php | 11 +++++++++++ scripts/pi-hole/js/footer.js | 20 +++++++++++--------- scripts/pi-hole/php/header_authenticated.php | 19 +++++++++++++++++-- scripts/pi-hole/php/sidebar.php | 1 + 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/api.php b/api.php index 4caecfec..213512fd 100644 --- a/api.php +++ b/api.php @@ -75,6 +75,17 @@ if (isset($_GET['enable']) && $auth) { $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!'); diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 73ab2107..28014487 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -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)) { @@ -185,11 +181,8 @@ function initCPUtemp() { } } - // Read from local storage, initialize if needed - var tempunit = localStorage ? localStorage.getItem("tempunit") : null; - if (tempunit === null) { - tempunit = "C"; - } + // Read the temperature unit from HTML code + var tempunit = $("#tempunit").text(); setCPUtemp(tempunit); @@ -200,6 +193,15 @@ function initCPUtemp() { tempunitSelector.on("change", function () { tempunit = $(this).val(); setCPUtemp(tempunit); + + // store the selected value on setupVars.conf + $.getJSON("api.php?setTempUnit=" + tempunit + "&token=" + token, function (data) { + if ("result" in data && data.result == "success") { + utils.showAlert("success", "", "Temperature unit set to " + tempunit, ""); + } else { + utils.showAlert("error", "", "", "Temperature unit not set"); + } + }); }); } } diff --git a/scripts/pi-hole/php/header_authenticated.php b/scripts/pi-hole/php/header_authenticated.php index f84ee5ef..b82fdbde 100644 --- a/scripts/pi-hole/php/header_authenticated.php +++ b/scripts/pi-hole/php/header_authenticated.php @@ -98,7 +98,22 @@ 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 { + $unit = 'C'; + } + + return array($celsius, $limit, $unit); } check_cors(); @@ -113,7 +128,7 @@ $token = $_SESSION['token']; $maxlifetime = ini_get('session.gc_maxlifetime'); // Get temperature -list($celsius, $temperaturelimit) = getTemperature(); +list($celsius, $temperaturelimit, $temperatureunit) = getTemperature(); // Get CPU load $loaddata = sys_getloadavg(); diff --git a/scripts/pi-hole/php/sidebar.php b/scripts/pi-hole/php/sidebar.php index b15a6717..1d474901 100644 --- a/scripts/pi-hole/php/sidebar.php +++ b/scripts/pi-hole/php/sidebar.php @@ -57,6 +57,7 @@ } echo ' '; echo 'Temp: '; + echo ''; echo ''; } ?> From d92df4af4cc557822cf6e2f1cc559ae76713a5c9 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Fri, 27 Jan 2023 18:05:52 -0300 Subject: [PATCH 2/7] If no unit is set on setupVars, try to use localstorage value, if exists Signed-off-by: RD WebDesign --- scripts/pi-hole/js/footer.js | 31 +++++++++++++++----- scripts/pi-hole/php/header_authenticated.php | 3 +- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 28014487..e982c0d6 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -181,8 +181,31 @@ function initCPUtemp() { } } + 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); @@ -195,13 +218,7 @@ function initCPUtemp() { setCPUtemp(tempunit); // store the selected value on setupVars.conf - $.getJSON("api.php?setTempUnit=" + tempunit + "&token=" + token, function (data) { - if ("result" in data && data.result == "success") { - utils.showAlert("success", "", "Temperature unit set to " + tempunit, ""); - } else { - utils.showAlert("error", "", "", "Temperature unit not set"); - } - }); + setSetupvarsTempUnit(tempunit); }); } } diff --git a/scripts/pi-hole/php/header_authenticated.php b/scripts/pi-hole/php/header_authenticated.php index b82fdbde..b022d4a6 100644 --- a/scripts/pi-hole/php/header_authenticated.php +++ b/scripts/pi-hole/php/header_authenticated.php @@ -110,7 +110,8 @@ function getTemperature() $unit = 'C'; } } else { - $unit = 'C'; + // no value is set in setupVars.conf + $unit = ''; } return array($celsius, $limit, $unit); From ee34c461f4caa5416b0f92c3cc01ba8a24807608 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Sun, 29 Jan 2023 03:00:33 -0300 Subject: [PATCH 3/7] Db_queries: use the same color scheme from Dashboard Signed-off-by: RD WebDesign --- db_queries.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/db_queries.php b/db_queries.php index 1bba7e59..252a6cb3 100644 --- a/db_queries.php +++ b/db_queries.php @@ -83,6 +83,19 @@ require 'scripts/pi-hole/php/header_authenticated.php';
+
+

---

+

Queries Total

+
+
+ +
+
+
+ +
+ +

---

Queries Blocked

@@ -95,7 +108,7 @@ require 'scripts/pi-hole/php/header_authenticated.php';
-
+

---

Queries Blocked (Wildcards)

@@ -106,19 +119,6 @@ require 'scripts/pi-hole/php/header_authenticated.php';
-
- -
-
-

---

-

Queries Total

-
-
- -
-
-
-
From f15d1043427db5742e8d82587ecc7e4bafb01d4e Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 30 Jan 2023 16:04:09 -0300 Subject: [PATCH 4/7] Move the temperature unit option from the "Per browser" section Signed-off-by: RD WebDesign --- settings.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/settings.php b/settings.php index f024b894..e02cbb4c 100644 --- a/settings.php +++ b/settings.php @@ -1130,6 +1130,18 @@ if (isset($piholeFTLConf['RATE_LIMIT'])) {
+
+
+
+ + +
+
+
@@ -1200,18 +1212,6 @@ if (isset($piholeFTLConf['RATE_LIMIT'])) {
-
-
-

CPU Temperature Unit

-
-
- -
-
From 0d55c511ff64763810793b064aafe40323c96b39 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Wed, 1 Feb 2023 19:02:49 -0300 Subject: [PATCH 5/7] Improving settings for Web and API - use separate tabs for Web and API - change box titles and options distribution Signed-off-by: RD WebDesign --- settings.php | 294 +++++++++++++++++++++++++--------------------- style/pi-hole.css | 4 + 2 files changed, 164 insertions(+), 134 deletions(-) diff --git a/settings.php b/settings.php index e02cbb4c..2f21449a 100644 --- a/settings.php +++ b/settings.php @@ -196,7 +196,7 @@ if (isset($setupVars['API_QUERY_LOG_SHOW'])) { ?> class="active"> DHCP +
  • class="active"> + Web interface +
  • class="active"> - API / Web interface + API
  • class="active"> Privacy @@ -1026,10 +1029,162 @@ if (isset($piholeFTLConf['RATE_LIMIT'])) {
  • - -
    + +
    +
    +
    +
    +

    Theme and Layout

    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + checked> + +
    +
    +
    + + +
    + +
    +
    +
    +
    +
    +
    +

    Interface settings (auto saved)

    +
    +
    + +
    +
    +

    Global Settings

    +
    +
    + +
    +
    +
    + + +
    +
    +
    + +
    + +
    +
    +

    Per Browser Settings

    +
    +
    + +
    +
    +
    + + +
    +
    +
    + +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +
    +
    +
    @@ -1109,138 +1264,9 @@ if (isset($piholeFTLConf['RATE_LIMIT'])) {
    -
    - -
    -
    -

    Web interface settings

    -
    -
    -
    -
    -

    Interface appearance

    - -
    -
    -
    -
    -
    - checked> - -
    -
    -
    -
    -
    -
    - - -
    -
    -
    - - -
    - -
    - -
    -
    -
    -
    -

    Per-browser settings (auto saved)

    -
    -
    -
    -
    -

    Checkbox and radio buttons

    -
    -
    - -
    -
    -
    -
    -
    - - -
    -
    -
    -
    -
    -
    - - -
    -
    -
    -
    -
    -
    - - -
    -
    -
    -
    -
    -
    + tr > .selected { left: 50%; translate: -50% -50%; } + +.faint-border { + border-color: rgba(127, 127, 127, 0.1); +} From 3961a98d8ae2c9403f9195e26b6e5d3fd5addfed Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Thu, 2 Feb 2023 18:28:35 -0300 Subject: [PATCH 6/7] Use the same wording Signed-off-by: RD WebDesign --- db_queries.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db_queries.php b/db_queries.php index 252a6cb3..6521a3c1 100644 --- a/db_queries.php +++ b/db_queries.php @@ -85,7 +85,7 @@ require 'scripts/pi-hole/php/header_authenticated.php';

    ---

    -

    Queries Total

    +

    Total Queries

    @@ -124,7 +124,7 @@ require 'scripts/pi-hole/php/header_authenticated.php';

    ---

    -

    Queries Blocked

    +

    Percentage Blocked

    From 7373cc26754ae860eb99c41adaf106ecba968fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 2 Feb 2023 23:37:19 +0100 Subject: [PATCH 7/7] Fix multiple restarts while importing with Teleporter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- scripts/pi-hole/php/func.php | 10 ++++++---- scripts/pi-hole/php/teleporter.php | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php index 6a7ed0f5..1c6652aa 100644 --- a/scripts/pi-hole/php/func.php +++ b/scripts/pi-hole/php/func.php @@ -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'])) { @@ -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'); } @@ -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'])) { @@ -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'); } diff --git a/scripts/pi-hole/php/teleporter.php b/scripts/pi-hole/php/teleporter.php index 0161a9ad..4941db91 100644 --- a/scripts/pi-hole/php/teleporter.php +++ b/scripts/pi-hole/php/teleporter.php @@ -493,6 +493,7 @@ if (isset($_POST['action'])) { 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 @@ -502,7 +503,7 @@ if (isset($_POST['action'])) { $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; } } @@ -517,6 +518,7 @@ if (isset($_POST['action'])) { 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 @@ -534,7 +536,7 @@ if (isset($_POST['action'])) { $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; } }