Core: Add multimedia_re filter

This commit is contained in:
Gregory Soutade 2024-07-28 09:24:33 +02:00
parent c9500e2e99
commit a03b1dfc4f
2 changed files with 12 additions and 3 deletions

View File

@ -44,6 +44,7 @@ count_hit_only_visitors = False
# Multimedia extensions (not accounted as downloaded files) # Multimedia extensions (not accounted as downloaded files)
multimedia_files = ['png', 'jpg', 'jpeg', 'gif', 'ico', 'svg', multimedia_files = ['png', 'jpg', 'jpeg', 'gif', 'ico', 'svg',
'css', 'js'] 'css', 'js']
multimedia_files_re = []
# Default resources path (will be symlinked in DISPLAY_OUTPUT) # Default resources path (will be symlinked in DISPLAY_OUTPUT)
resources_path = ['resources'] resources_path = ['resources']

14
iwla.py
View File

@ -159,6 +159,9 @@ class IWLA(object):
self.excluded_domain_name = [] self.excluded_domain_name = []
for domain_name in conf.excluded_domain_name: for domain_name in conf.excluded_domain_name:
self.excluded_domain_name += [re.compile(domain_name)] self.excluded_domain_name += [re.compile(domain_name)]
self.multimedia_files_re = []
for file_re in conf.multimedia_files_re:
self.multimedia_files_re += [re.compile(file_re)]
self.plugins = [(conf.PRE_HOOK_DIRECTORY , conf.pre_analysis_hooks), self.plugins = [(conf.PRE_HOOK_DIRECTORY , conf.pre_analysis_hooks),
(conf.POST_HOOK_DIRECTORY , conf.post_analysis_hooks), (conf.POST_HOOK_DIRECTORY , conf.post_analysis_hooks),
(conf.DISPLAY_HOOK_DIRECTORY , conf.display_hooks)] (conf.DISPLAY_HOOK_DIRECTORY , conf.display_hooks)]
@ -311,13 +314,18 @@ class IWLA(object):
self.logger.debug("False") self.logger.debug("False")
return False return False
def isMultimediaFile(self, request): def isMultimediaFile(self, uri):
self.logger.debug("Is multimedia %s" % (request)) self.logger.debug("Is multimedia %s" % (uri))
for e in conf.multimedia_files: for e in conf.multimedia_files:
if request.lower().endswith(e): if uri.lower().endswith(e):
self.logger.debug("True") self.logger.debug("True")
return True return True
self.logger.debug("False") self.logger.debug("False")
for file_re in self.multimedia_files_re:
if file_re.match(uri):
self.logger.debug("Is multimedia re True")
return True
return False return False
def isValidVisitor(self, hit): def isValidVisitor(self, hit):