diff --git a/api_FTL.php b/api_FTL.php index f8b777cb..927bbbba 100644 --- a/api_FTL.php +++ b/api_FTL.php @@ -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);