From 4966f01dde29bfb477b37cafae521f3f958eb1f5 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Fri, 27 Jan 2023 00:34:06 -0300 Subject: [PATCH 1/4] 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 4caecfecd..213512fd4 100644 --- a/api.php +++ b/api.php @@ -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!'); diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 73ab2107b..28014487c 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 f84ee5efc..b82fdbdeb 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 @@ 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(); diff --git a/scripts/pi-hole/php/sidebar.php b/scripts/pi-hole/php/sidebar.php index b15a67178..1d474901b 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/4] 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 28014487c..e982c0d69 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 b82fdbdeb..b022d4a62 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 f15d1043427db5742e8d82587ecc7e4bafb01d4e Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 30 Jan 2023 16:04:09 -0300 Subject: [PATCH 3/4] 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 f024b894b..e02cbb4c3 100644 --- a/settings.php +++ b/settings.php @@ -1130,6 +1130,18 @@ +
+
+
+ + +
+
+
@@ -1200,18 +1212,6 @@ -
-
-

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 4/4] 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 e02cbb4c3..2f21449ae 100644 --- a/settings.php +++ b/settings.php @@ -196,7 +196,7 @@ ?> class="active"> DHCP +
  • class="active"> + Web interface +
  • class="active"> - API / Web interface + API
  • class="active"> Privacy @@ -1026,10 +1029,162 @@
  • - -
    + +
    +
    +
    +
    +

    Theme and Layout

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

    Interface settings (auto saved)

    +
    +
    + +
    +
    +

    Global Settings

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

    Per Browser Settings

    +
    +
    + +
    +
    +
    + + +
    +
    +
    + +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +
    +
    +
    @@ -1109,138 +1264,9 @@
    -
    - -
    -
    -

    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); +}