diff --git a/plugins/post_analysis/filter_users.py b/plugins/post_analysis/filter_users.py index 048db1e..682ce8f 100644 --- a/plugins/post_analysis/filter_users.py +++ b/plugins/post_analysis/filter_users.py @@ -37,8 +37,8 @@ Conf values needed : filtered_ip : list of ip (string) create_filtered_page* -Filter is a list of filter description combined by AND operator -Filter description is a list of 3 elements : +Filter can be a function or a list of filter description combined by AND operator +Filter description can be a function or a list of 3 elements : * Field to match in visits * Operator '=', '==', '!=', '>', '>=', '<', '<=' for int value @@ -47,6 +47,19 @@ Filter description is a list of 3 elements : For easiest config, you can indicate both 'remote_addr' or 'ip' in field element +function prototype is func(iwla, hit) and must return True or False + +Example : + +def my_filter(iwla, hit): + return True + +filtered_users = [ + [['viewed_pages', '>=', '5'], ['viewed_hits', '>=', '5']], + [['viewed_hits', '>=', '5'], my_filter], + my_filter, +] + Output files : None @@ -91,8 +104,14 @@ class IWLAPostAnalysisFilterUsers(IPlugin): self.filters = self.iwla.getConfValue('filtered_users', []) self.ip_filters = self.iwla.getConfValue('filtered_ip', []) for _filter in self.filters: - for sub_filter in _filter: - self._check_filter(sub_filter) + if type(_filter) == list: + for sub_filter in _filter: + if not callable(sub_filter): + self._check_filter(sub_filter) + elif callable(_filter): + continue + else: + raise Exception(f'Invalid filter {_filter}') return True def __do_filter(self, hit, _filter): @@ -124,9 +143,18 @@ class IWLAPostAnalysisFilterUsers(IPlugin): return True for _filter in self.filters: + if callable(_filter): + if _filter(self.iwla, hits[ip]): + return True + continue + # Must match all sub filters filtered = True for sub_filter in _filter: - if not self.__do_filter(hits[ip], sub_filter): + if callable(sub_filter): + if not sub_filter(self.iwla, hits[ip]): + filtered = False + break + elif not self.__do_filter(hits[ip], sub_filter): filtered = False break if filtered: @@ -134,6 +162,9 @@ class IWLAPostAnalysisFilterUsers(IPlugin): return False def hook(self): + if not len(self.filters) and not len(self.ip_filters): + return + hits = self.iwla.getValidVisitors() if len(self.filters) or len(self.ip_filters):