From 4cc9608a3f3835a7269e11f02f8c5095c353760c Mon Sep 17 00:00:00 2001 From: terrtia Date: Tue, 7 Nov 2023 15:24:40 +0100 Subject: [PATCH] chg: [chats explorer] show chats/subchannels creation date --- bin/lib/chats_viewer.py | 6 +++--- bin/lib/objects/ChatSubChannels.py | 2 ++ bin/lib/objects/Chats.py | 2 ++ bin/lib/objects/abstract_chat_object.py | 8 ++++++-- var/www/templates/chats_explorer/SubChannelMessages.html | 4 ++-- var/www/templates/chats_explorer/chat_instance.html | 8 +++++--- var/www/templates/chats_explorer/chat_viewer.html | 6 +++++- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/bin/lib/chats_viewer.py b/bin/lib/chats_viewer.py index 69b9c4af..c2ced4d8 100755 --- a/bin/lib/chats_viewer.py +++ b/bin/lib/chats_viewer.py @@ -173,7 +173,7 @@ class ChatServiceInstance: if 'chats' in options: meta['chats'] = [] for chat_id in self.get_chats(): - meta['chats'].append(Chats.Chat(chat_id, self.uuid).get_meta({'nb_subchannels'})) + meta['chats'].append(Chats.Chat(chat_id, self.uuid).get_meta({'created_at', 'nb_subchannels'})) return meta def get_nb_chats(self): @@ -297,7 +297,7 @@ def api_get_chat(chat_id, chat_instance_uuid): chat = Chats.Chat(chat_id, chat_instance_uuid) if not chat.exists(): return {"status": "error", "reason": "Unknown chat"}, 404 - meta = chat.get_meta({'img', 'info', 'subchannels', 'username'}) + meta = chat.get_meta({'created_at', 'img', 'info', 'subchannels', 'username'}) if meta['subchannels']: meta['subchannels'] = get_subchannels_meta_from_global_id(meta['subchannels']) else: @@ -308,7 +308,7 @@ def api_get_subchannel(chat_id, chat_instance_uuid): subchannel = ChatSubChannels.ChatSubChannel(chat_id, chat_instance_uuid) if not subchannel.exists(): return {"status": "error", "reason": "Unknown chat"}, 404 - meta = subchannel.get_meta({'chat', 'img', 'nb_messages'}) + meta = subchannel.get_meta({'chat', 'created_at', 'img', 'nb_messages'}) if meta['chat']: meta['chat'] = get_chat_meta_from_global_id(meta['chat']) meta['messages'], meta['tags_messages'] = subchannel.get_messages() diff --git a/bin/lib/objects/ChatSubChannels.py b/bin/lib/objects/ChatSubChannels.py index 8d73524a..e3601ce1 100755 --- a/bin/lib/objects/ChatSubChannels.py +++ b/bin/lib/objects/ChatSubChannels.py @@ -86,6 +86,8 @@ class ChatSubChannel(AbstractChatObject): meta['img'] = self.get_img() if 'nb_messages': meta['nb_messages'] = self.get_nb_messages() + if 'created_at': + meta['created_at'] = self.get_created_at(date=True) return meta def get_misp_object(self): diff --git a/bin/lib/objects/Chats.py b/bin/lib/objects/Chats.py index f4e3bd72..a0e6dea1 100755 --- a/bin/lib/objects/Chats.py +++ b/bin/lib/objects/Chats.py @@ -84,6 +84,8 @@ class Chat(AbstractChatObject): meta['subchannels'] = self.get_subchannels() if 'nb_subchannels': meta['nb_subchannels'] = self.get_nb_subchannels() + if 'created_at': + meta['created_at'] = self.get_created_at(date=True) return meta def get_misp_object(self): diff --git a/bin/lib/objects/abstract_chat_object.py b/bin/lib/objects/abstract_chat_object.py index 2025f23c..e7e67e92 100755 --- a/bin/lib/objects/abstract_chat_object.py +++ b/bin/lib/objects/abstract_chat_object.py @@ -94,8 +94,12 @@ class AbstractChatObject(AbstractSubtypeObject, ABC): threads.append(obj_global_id) return threads - def get_created_at(self): - return self._get_field('created_at') + def get_created_at(self, date=False): + created_at = self._get_field('created_at') + if date and created_at: + created_at = datetime.fromtimestamp(float(created_at)) + created_at = created_at.isoformat(' ') + return created_at def set_created_at(self, timestamp): self._set_field('created_at', timestamp) diff --git a/var/www/templates/chats_explorer/SubChannelMessages.html b/var/www/templates/chats_explorer/SubChannelMessages.html index 9c173342..d3ccf2d4 100644 --- a/var/www/templates/chats_explorer/SubChannelMessages.html +++ b/var/www/templates/chats_explorer/SubChannelMessages.html @@ -63,7 +63,7 @@ Name -{# Chat Instance#} + Created at First seen Last seen Username @@ -73,9 +73,9 @@ -{# {{ subchannel["subtype"] }}#} {{ subchannel['name'] }} + {{ subchannel["created_at"] }} {% if subchannel['first_seen'] %} {{ subchannel['first_seen'][0:4] }}-{{ subchannel['first_seen'][4:6] }}-{{ subchannel['first_seen'][6:8] }} diff --git a/var/www/templates/chats_explorer/chat_instance.html b/var/www/templates/chats_explorer/chat_instance.html index 9a32d71d..419b8116 100644 --- a/var/www/templates/chats_explorer/chat_instance.html +++ b/var/www/templates/chats_explorer/chat_instance.html @@ -67,9 +67,10 @@ Icon Name ID + Created at First Seen Last Seen - NB Chats + NB SubChannels @@ -78,8 +79,9 @@ {{ chat['id'] }} - {{ chat['name'] }} + {{ chat['name'] }} {{ chat['id'] }} + {{ chat['created_at'] }} {% if chat['first_seen'] %} {{ chat['first_seen'][0:4] }}-{{ chat['first_seen'][4:6] }}-{{ chat['first_seen'][6:8] }} @@ -109,7 +111,7 @@ $('#tablechats').DataTable({ "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]], "iDisplayLength": 10, - "order": [[ 4, "desc" ]] + "order": [[ 5, "desc" ]] }); }); diff --git a/var/www/templates/chats_explorer/chat_viewer.html b/var/www/templates/chats_explorer/chat_viewer.html index 1d6d961a..1b93b322 100644 --- a/var/www/templates/chats_explorer/chat_viewer.html +++ b/var/www/templates/chats_explorer/chat_viewer.html @@ -60,6 +60,7 @@ Icon Name ID + Created at First Seen Last Seen NB Sub-Channels @@ -70,6 +71,7 @@ {{ chat['name'] }} {{ chat['id'] }} + {{ chat['created_at'] }} {% if chat['first_seen'] %} {{ chat['first_seen'][0:4] }}-{{ chat['first_seen'][4:6] }}-{{ chat['first_seen'][6:8] }} @@ -107,6 +109,7 @@ Icon Name ID + Created at First Seen Last Seen NB Messages @@ -120,6 +123,7 @@ {{ meta['name'] }} {{ meta['id'] }} + {{ meta['created_at'] }} {% if meta['first_seen'] %} {{ meta['first_seen'][0:4] }}-{{ meta['first_seen'][4:6] }}-{{ meta['first_seen'][6:8] }} @@ -220,7 +224,7 @@ $('#tablesubchannels').DataTable({ "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]], "iDisplayLength": 10, - "order": [[ 4, "desc" ]] + "order": [[ 5, "desc" ]] }); {% endif %} });