Use current time and maxlogage to limit the time range

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
RD WebDesign
2023-04-25 19:31:27 -03:00
parent 086aa51c90
commit 6ce4ad972b
+25 -6
View File
@@ -75,16 +75,26 @@ if (isset($_GET['getMaxlogage']) && $auth) {
}
if (isset($_GET['overTimeData10mins']) && $auth) {
$maxlogage = getMaxlogage();
$return = callFTLAPI('overTime');
if (array_key_exists('FTLnotrunning', $return)) {
if (array_key_exists('FTLnotrunning', $return) || $maxlogage < 0) {
$data = array('FTLnotrunning' => true);
} else {
$domains_over_time = array();
$ads_over_time = array();
// Use current time and maxlogage to limit the time range
$time_end = time();
$time_start = $time_end - ($maxlogage * 3600);
foreach ($return as $line) {
$tmp = explode(' ', $line);
$domains_over_time[intval($tmp[0])] = intval($tmp[1]);
$ads_over_time[intval($tmp[0])] = intval($tmp[2]);
$timeslot = intval($tmp[0]);
if ($timeslot >= $time_start && $timeslot <= $time_end) {
$domains_over_time[$timeslot] = intval($tmp[1]);
$ads_over_time[$timeslot] = intval($tmp[2]);
}
}
$result = array(
@@ -398,16 +408,25 @@ if (isset($_GET['getClientNames']) && $auth) {
}
if (isset($_GET['overTimeDataClients']) && $auth) {
$return = callFTLAPI('ClientsoverTime');
$maxlogage = getMaxlogage();
if (array_key_exists('FTLnotrunning', $return)) {
$return = callFTLAPI('ClientsoverTime');
if (array_key_exists('FTLnotrunning', $return) || $maxlogage < 0) {
$data = array('FTLnotrunning' => true);
} else {
$over_time = array();
// Use current time and maxlogage to limit the time range
$time_end = time();
$time_start = $time_end - ($maxlogage * 3600);
foreach ($return as $line) {
$tmp = explode(' ', $line);
for ($i = 0; $i < count($tmp) - 1; ++$i) {
$over_time[intval($tmp[0])][$i] = floatval($tmp[$i + 1]);
$timeslot = intval($tmp[0]);
if ($timeslot >= $time_start && $timeslot <= $time_end) {
$over_time[$timeslot][$i] = floatval($tmp[$i + 1]);
}
}
}
$result = array('over_time' => $over_time);