From a1b7339582f82502ac6a6591fb51535c695cf074 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 5 Nov 2024 15:22:46 +0100 Subject: [statistics] Disable non-client filter if specific filters are given --- .../statistics/inc/statisticsfilterset.inc.php | 16 ++++++++++++++++ modules-available/statistics/pages/summary.inc.php | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'modules-available') diff --git a/modules-available/statistics/inc/statisticsfilterset.inc.php b/modules-available/statistics/inc/statisticsfilterset.inc.php index 26595e93..5840821b 100644 --- a/modules-available/statistics/inc/statisticsfilterset.inc.php +++ b/modules-available/statistics/inc/statisticsfilterset.inc.php @@ -41,6 +41,22 @@ class StatisticsFilterSet $this->cache = compact('where', 'join', 'args'); } + /** + * Are there any "specific filters" in place? + * We consider filters specific that filter by precise information like + * CPU model, IP address, MAC address, etc. In those cases we might not + * want to filter non-client machines in the summary view, for example. + */ + public function hasSpecificFilters(): bool + { + $ignored = ['firstseen', 'lastseen', 'lastboot', 'runtime', 'state']; + foreach ($this->filters as $key => $_) { + if (!in_array($key, $ignored)) + return true; + } + return false; + } + public function filterNonClients() { if (Module::get('runmode') === false || $this->hasFilter('IsClientStatisticsFilter') !== null) diff --git a/modules-available/statistics/pages/summary.inc.php b/modules-available/statistics/pages/summary.inc.php index 905f5d90..a540e39e 100644 --- a/modules-available/statistics/pages/summary.inc.php +++ b/modules-available/statistics/pages/summary.inc.php @@ -31,7 +31,9 @@ class SubPage dechex((int)(abs((5 - $i) * 51)))); } - $filterSet->filterNonClients(); + if (!$filterSet->hasSpecificFilters()) { + $filterSet->filterNonClients(); + } StatisticsFilter::renderFilterBox('summary', $filterSet); Render::openTag('div', array('class' => 'row')); self::showSummary($filterSet); -- cgit v1.2.3-55-g7522