From d637f2a0eead835ff89dc60bd57c8b768bae22c7 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Tue, 9 Jul 2024 14:05:40 +0200 Subject: [PATCH] new: [backend:user_activity] Improved user activity filtering --- notification.py | 17 +++++++++++++++++ server.py | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/notification.py b/notification.py index 4c6be5d..01d815d 100644 --- a/notification.py +++ b/notification.py @@ -197,4 +197,21 @@ def is_accepted_notification(notification) -> bool: return True elif action in config.live_logs_accepted_scope[scope]: return True + return False + + +def is_accepted_user_activity(notification) -> bool: + global VERBOSE_MODE + + if notification['user_agent'] == 'misp-exercise-dashboard': # Ignore message generated from this app + return False + if '@' not in notification['user']: # Ignore message from system + return False + + scope, action = get_scope_action_from_url(notification['url']) + if scope in config.uesr_activity_accepted_scope: + if config.uesr_activity_accepted_scope == '*': + return True + elif action in config.uesr_activity_accepted_scope[scope]: + return True return False \ No newline at end of file diff --git a/server.py b/server.py index 9d879d5..0534dc7 100755 --- a/server.py +++ b/server.py @@ -150,10 +150,11 @@ async def handleMessage(topic, s, message): if notification_model.is_accepted_notification(notification): notification_model.record_notification(notification) ZMQ_MESSAGE_COUNT_LAST_TIMESPAN += 1 + await sio.emit('notification', notification) + if notification_model.is_accepted_user_activity(notification): user_id = notification_model.get_user_id(data) if user_id is not None: USER_ACTIVITY[user_id] += 1 - await sio.emit('notification', notification) user_id = notification_model.get_user_id(data) if user_id is not None: