From 171bf81b113bc99db821cf314ee29e214d91abf9 Mon Sep 17 00:00:00 2001 From: rdwebdesign Date: Tue, 1 Feb 2022 16:22:24 -0300 Subject: [PATCH] Retreives maxlogage calling api_FTL.php FTL defines MAXLOGAGE value. PHP retrieves the value and converts seconds to hours Javascript calls the API to update the value. Signed-off-by: rdwebdesign --- api_FTL.php | 10 ++++++++++ index.php | 15 +++------------ scripts/pi-hole/js/index.js | 12 ++++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/api_FTL.php b/api_FTL.php index b58a3eda..b7bcf9fe 100644 --- a/api_FTL.php +++ b/api_FTL.php @@ -61,6 +61,16 @@ else $data = array_merge($data,$stats); } + if (isset($_GET["getMaxlogage"]) && $auth) { + sendRequestFTL("maxlogage"); + // Convert seconds to hours and rounds to one decimal place. + $ret = round(intval(getResponseFTL()[0]) / 3600, 1); + // Return 24h if value is 0, empty, null or non numeric. + $ret = $ret ?: 24; + + $data = array_merge($data, array("maxlogage" => $ret)); + } + if (isset($_GET['overTimeData10mins'])) { sendRequestFTL("overTime"); diff --git a/index.php b/index.php index 90402817..8adb2101 100644 --- a/index.php +++ b/index.php @@ -5,19 +5,10 @@ * * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ + $indexpage = true; require "scripts/pi-hole/php/header.php"; require_once "scripts/pi-hole/php/gravity.php"; - -function getinterval() -{ - global $piholeFTLConf; - if (isset($piholeFTLConf["MAXLOGAGE"])) { - return min(round(floatval($piholeFTLConf["MAXLOGAGE"]), 1), 24); - } else { - return "24"; - } -} ?> @@ -84,7 +75,7 @@ function getinterval()
-

Total queries over last hours

+

Total queries over last 24 hours

@@ -109,7 +100,7 @@ function getinterval()
-

Client activity over last hours

+

Client activity over last 24 hours

diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 3442f342..d7cce8e2 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -862,8 +862,20 @@ function doughnutTooltip(tooltipItems, data) { ); } +var maxlogage = "24"; +function getMaxlogage() { + $.getJSON("api.php?getMaxlogage", function (data) { + if (!("FTLnotrunning" in data)) { + maxlogage = data.maxlogage; + } + }).done(function () { + $(".maxlogage-interval").html(maxlogage); + }); +} + $(function () { // Pull in data via AJAX + getMaxlogage(); updateSummaryData(); var gridColor = $(".graphs-grid").css("background-color");