chg: [chats] add discord threads, Forum channel

dev
terrtia 2023-12-04 10:26:02 +01:00
parent 93ef541862
commit 941838ab76
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
8 changed files with 78 additions and 13 deletions

View File

@ -182,8 +182,6 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
return chat return chat
# def process_subchannels(self):
# pass
def process_subchannel(self, obj, date, timestamp, reply_id=None): # TODO CREATE DATE def process_subchannel(self, obj, date, timestamp, reply_id=None): # TODO CREATE DATE
meta = self.json_data['meta']['chat']['subchannel'] meta = self.json_data['meta']['chat']['subchannel']
@ -216,12 +214,17 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
p_subchannel_id = meta['parent'].get('subchannel') p_subchannel_id = meta['parent'].get('subchannel')
p_message_id = meta['parent'].get('message') p_message_id = meta['parent'].get('message')
# print(thread_id, p_chat_id, p_subchannel_id, p_message_id)
if p_chat_id == self.get_chat_id() and p_subchannel_id == self.get_subchannel_id(): if p_chat_id == self.get_chat_id() and p_subchannel_id == self.get_subchannel_id():
thread = ChatThreads.create(thread_id, self.get_chat_instance_uuid(), p_chat_id, p_subchannel_id, p_message_id, obj_chat) thread = ChatThreads.create(thread_id, self.get_chat_instance_uuid(), p_chat_id, p_subchannel_id, p_message_id, obj_chat)
thread.add(date, obj) thread.add(date, obj)
thread.add_message(obj.get_global_id(), self.get_message_id(), timestamp, reply_id=reply_id) thread.add_message(obj.get_global_id(), self.get_message_id(), timestamp, reply_id=reply_id)
# TODO OTHERS CORRELATIONS TO ADD # TODO OTHERS CORRELATIONS TO ADD
if meta.get('name'):
thread.set_name(meta['name'])
return thread return thread
# TODO # TODO
@ -308,8 +311,10 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
else: else:
chat_id = self.get_chat_id() chat_id = self.get_chat_id()
thread_id = self.get_thread_id()
channel_id = self.get_subchannel_id()
message_id = self.get_message_id() message_id = self.get_message_id()
message_id = Messages.create_obj_id(self.get_chat_instance_uuid(), chat_id, message_id, timestamp) message_id = Messages.create_obj_id(self.get_chat_instance_uuid(), chat_id, message_id, timestamp, channel_id=channel_id, thread_id=thread_id)
message = Messages.Message(message_id) message = Messages.Message(message_id)
# create empty message if message don't exists # create empty message if message don't exists
if not message.exists(): if not message.exists():

View File

@ -290,6 +290,12 @@ def get_chat_meta_from_global_id(chat_global_id):
chat = Chats.Chat(chat_id, instance_uuid) chat = Chats.Chat(chat_id, instance_uuid)
return chat.get_meta() return chat.get_meta()
def get_threads_metas(threads):
metas = []
for thread in threads:
metas.append(ChatThreads.ChatThread(thread['id'], thread['subtype']).get_meta(options={'name', 'nb_messages'}))
return metas
def get_username_meta_from_global_id(username_global_id): def get_username_meta_from_global_id(username_global_id):
_, instance_uuid, username_id = username_global_id.split(':', 2) _, instance_uuid, username_id = username_global_id.split(':', 2)
username = Usernames.Username(username_id, instance_uuid) username = Usernames.Username(username_id, instance_uuid)
@ -305,7 +311,7 @@ def api_get_chat(chat_id, chat_instance_uuid):
chat = Chats.Chat(chat_id, chat_instance_uuid) chat = Chats.Chat(chat_id, chat_instance_uuid)
if not chat.exists(): if not chat.exists():
return {"status": "error", "reason": "Unknown chat"}, 404 return {"status": "error", "reason": "Unknown chat"}, 404
meta = chat.get_meta({'created_at', 'icon', 'info', 'subchannels', 'username'}) meta = chat.get_meta({'created_at', 'icon', 'info', 'subchannels', 'threads', 'username'})
if meta['username']: if meta['username']:
meta['username'] = get_username_meta_from_global_id(meta['username']) meta['username'] = get_username_meta_from_global_id(meta['username'])
if meta['subchannels']: if meta['subchannels']:
@ -326,9 +332,11 @@ def api_get_subchannel(chat_id, chat_instance_uuid):
subchannel = ChatSubChannels.ChatSubChannel(chat_id, chat_instance_uuid) subchannel = ChatSubChannels.ChatSubChannel(chat_id, chat_instance_uuid)
if not subchannel.exists(): if not subchannel.exists():
return {"status": "error", "reason": "Unknown subchannel"}, 404 return {"status": "error", "reason": "Unknown subchannel"}, 404
meta = subchannel.get_meta({'chat', 'created_at', 'icon', 'nb_messages'}) meta = subchannel.get_meta({'chat', 'created_at', 'icon', 'nb_messages', 'threads'})
if meta['chat']: if meta['chat']:
meta['chat'] = get_chat_meta_from_global_id(meta['chat']) meta['chat'] = get_chat_meta_from_global_id(meta['chat'])
if meta.get('threads'):
meta['threads'] = get_threads_metas(meta['threads'])
if meta.get('username'): if meta.get('username'):
meta['username'] = get_username_meta_from_global_id(meta['username']) meta['username'] = get_username_meta_from_global_id(meta['username'])
meta['messages'], meta['tags_messages'] = subchannel.get_messages() meta['messages'], meta['tags_messages'] = subchannel.get_messages()

View File

@ -84,10 +84,13 @@ class ChatSubChannel(AbstractChatObject):
meta['chat'] = self.get_chat() meta['chat'] = self.get_chat()
if 'img' in options: if 'img' in options:
meta['img'] = self.get_img() meta['img'] = self.get_img()
if 'nb_messages': if 'nb_messages' in options:
meta['nb_messages'] = self.get_nb_messages() meta['nb_messages'] = self.get_nb_messages()
if 'created_at': if 'created_at' in options:
meta['created_at'] = self.get_created_at(date=True) meta['created_at'] = self.get_created_at(date=True)
if 'threads' in options:
meta['threads'] = self.get_threads()
print(meta['threads'])
return meta return meta
def get_misp_object(self): def get_misp_object(self):

View File

@ -73,6 +73,8 @@ class ChatThread(AbstractChatObject):
meta['id'] = self.id meta['id'] = self.id
meta['subtype'] = self.subtype meta['subtype'] = self.subtype
meta['tags'] = self.get_tags(r_list=True) meta['tags'] = self.get_tags(r_list=True)
if 'name':
meta['name'] = self.get_name()
if 'nb_messages': if 'nb_messages':
meta['nb_messages'] = self.get_nb_messages() meta['nb_messages'] = self.get_nb_messages()
# created_at ??? # created_at ???

View File

@ -86,6 +86,9 @@ class Chat(AbstractChatObject):
meta['nb_subchannels'] = self.get_nb_subchannels() meta['nb_subchannels'] = self.get_nb_subchannels()
if 'created_at': if 'created_at':
meta['created_at'] = self.get_created_at(date=True) meta['created_at'] = self.get_created_at(date=True)
if 'threads' in options:
meta['threads'] = self.get_threads()
print(meta['threads'])
return meta return meta
def get_misp_object(self): def get_misp_object(self):

View File

@ -88,10 +88,10 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
def get_threads(self): def get_threads(self):
threads = [] threads = []
for obj_global_id in self.get_childrens(): for child in self.get_childrens():
obj_type, _ = obj_global_id.split(':', 1) obj_type, obj_subtype, obj_id = child.split(':', 2)
if obj_type == 'chat-thread': if obj_type == 'chat-thread':
threads.append(obj_global_id) threads.append({'type': obj_type, 'subtype': obj_subtype, 'id': obj_id})
return threads return threads
def get_created_at(self, date=False): def get_created_at(self, date=False):
@ -242,6 +242,7 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
for mess_id in self.get_cached_message_reply(message_id): for mess_id in self.get_cached_message_reply(message_id):
self.add_obj_children(obj_global_id, mess_id) self.add_obj_children(obj_global_id, mess_id)
# def get_deleted_messages(self, message_id):
# get_messages_meta ???? # get_messages_meta ????

View File

@ -132,6 +132,43 @@
</div> </div>
</div> </div>
{% if subchannel['threads'] %}
<table id="tablethreads" class="table">
<thead class="bg-dark text-white">
<tr>
<th>Name</th>
<th>Created at</th>
<th>First seen</th>
<th>Last seen</th>
<th>Nb Messages</th>
</tr>
</thead>
<tbody>
{% for thread in subchannel['threads'] %}
<tr>
<td>
<a href="{{ url_for('chats_explorer.objects_thread_messages')}}?uuid={{ thread['subtype'] }}&id={{ thread['id'] }}">{{ thread['name'] }} <i class="far fa-comment"></i> {{ thread['nb_messages'] }} Messages</a>
</td>
<td>{{ thread["created_at"] }}</td>
<td>
{% if thread['first_seen'] %}
{{ thread['first_seen'][0:4] }}-{{ thread['first_seen'][4:6] }}-{{ thread['first_seen'][6:8] }}
{% endif %}
</td>
<td>
{% if thread['last_seen'] %}
{{ thread['last_seen'][0:4] }}-{{ thread['last_seen'][4:6] }}-{{ thread['last_seen'][6:8] }}
{% endif %}
</td>
<td>{{ thread['nb_messages'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% for tag in subchannel['tags_messages'] %} {% for tag in subchannel['tags_messages'] %}
<span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">{{ tag }} <span class="badge badge-light">{{ subchannel['tags_messages'][tag] }}</span></span> <span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">{{ tag }} <span class="badge badge-light">{{ subchannel['tags_messages'][tag] }}</span></span>
{% endfor %} {% endfor %}
@ -182,7 +219,13 @@
$(document).ready(function(){ $(document).ready(function(){
$("#page-Decoded").addClass("active"); $("#page-Decoded").addClass("active");
$("#nav_chat").addClass("active"); $("#nav_chat").addClass("active");
{% if subchannel['threads'] %}
$('#tablethreads').DataTable({
"aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
"iDisplayLength": 10,
"order": [[ 3, "desc" ]]
});
{% endif %}
}); });
function toggle_sidebar(){ function toggle_sidebar(){

View File

@ -62,7 +62,7 @@
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>ID</th> <th>Name</th>
<th>Parent</th> <th>Parent</th>
<th>First seen</th> <th>First seen</th>
<th>Last seen</th> <th>Last seen</th>
@ -72,7 +72,7 @@
<tbody> <tbody>
<tr> <tr>
<td> <td>
{{ meta['id'] }} {{ meta['name'] }}
</td> </td>
<td> <td>
{% if meta['first_seen'] %} {% if meta['first_seen'] %}