From 54c57ea35b539366f1e91ee14d862982d19733ac Mon Sep 17 00:00:00 2001 From: terrtia Date: Wed, 8 Nov 2023 15:46:05 +0100 Subject: [PATCH] chg: [chats] message object template --- bin/lib/ail_core.py | 2 +- bin/lib/chats_viewer.py | 6 +- bin/lib/objects/Messages.py | 10 +-- var/www/blueprints/chats_explorer.py | 21 ++---- .../templates/chats_explorer/ChatMessage.html | 73 +++++++++++++------ 5 files changed, 67 insertions(+), 45 deletions(-) diff --git a/bin/lib/ail_core.py b/bin/lib/ail_core.py index 4dce4e63..e963ba73 100755 --- a/bin/lib/ail_core.py +++ b/bin/lib/ail_core.py @@ -17,7 +17,7 @@ r_object = config_loader.get_db_conn("Kvrocks_Objects") config_loader = None AIL_OBJECTS = sorted({'chat', 'cookie-name', 'cve', 'cryptocurrency', 'decoded', 'domain', 'etag', 'favicon', 'hhhash', 'item', - 'pgp', 'screenshot', 'title', 'user-account', 'username'}) + 'message', 'pgp', 'screenshot', 'title', 'user-account', 'username'}) def get_ail_uuid(): ail_uuid = r_serv_db.get('ail:uuid') diff --git a/bin/lib/chats_viewer.py b/bin/lib/chats_viewer.py index 4e91f47c..a3ad11c6 100755 --- a/bin/lib/chats_viewer.py +++ b/bin/lib/chats_viewer.py @@ -329,7 +329,11 @@ def api_get_message(message_id): message = Messages.Message(message_id) if not message.exists(): return {"status": "error", "reason": "Unknown uuid"}, 404 - return message.get_meta({'content', 'icon', 'link', 'parent', 'parent_meta', 'user-account'}), 200 + meta = message.get_meta({'chat', 'content', 'icon', 'link', 'parent', 'parent_meta', 'user-account'}) + # if meta['chat']: + # print(meta['chat']) + # # meta['chat'] = + return meta, 200 # # # # # # # # # # LATER # # diff --git a/bin/lib/objects/Messages.py b/bin/lib/objects/Messages.py index b0ffecc6..8f3eba6b 100755 --- a/bin/lib/objects/Messages.py +++ b/bin/lib/objects/Messages.py @@ -98,8 +98,6 @@ class Message(AbstractObject): def get_chat_id(self): # TODO optimize -> use me to tag Chat chat_id = self.get_basename().rsplit('_', 1)[0] - # if chat_id.endswith('.gz'): - # chat_id = chat_id[:-3] return chat_id # TODO get Instance ID @@ -151,9 +149,9 @@ class Message(AbstractObject): def get_link(self, flask_context=False): if flask_context: - url = url_for('correlation.show_correlation', type=self.type, id=self.id) + url = url_for('chats_explorer.objects_message', type=self.type, id=self.id) else: - url = f'{baseurl}/correlation/show?type={self.type}&id={self.id}' + url = f'{baseurl}/objects/message?id={self.id}' return url def get_svg_icon(self): @@ -196,7 +194,7 @@ class Message(AbstractObject): else: timestamp = float(timestamp) timestamp = datetime.fromtimestamp(float(timestamp)) - meta['date'] = timestamp.strftime('%Y%m%d') + meta['date'] = timestamp.strftime('%Y%/m/%d') meta['hour'] = timestamp.strftime('%H:%M:%S') meta['full_date'] = timestamp.isoformat(' ') @@ -222,6 +220,8 @@ class Message(AbstractObject): meta['user-account'] = self.get_user_account(meta=True) if not meta['user-account']: meta['user-account'] = {'id': 'UNKNOWN'} + if 'chat' in options: + meta['chat'] = self.get_chat_id() # meta['encoding'] = None return meta diff --git a/var/www/blueprints/chats_explorer.py b/var/www/blueprints/chats_explorer.py index 0094629c..55cba38c 100644 --- a/var/www/blueprints/chats_explorer.py +++ b/var/www/blueprints/chats_explorer.py @@ -1,15 +1,15 @@ #!/usr/bin/env python3 # -*-coding:UTF-8 -* -''' +""" Blueprint Flask: crawler splash endpoints: dashboard, onion crawler ... -''' +""" import os import sys import json -from flask import Flask, render_template, jsonify, request, Blueprint, redirect, url_for, Response, abort, send_file +from flask import Flask, render_template, jsonify, request, Blueprint, redirect, url_for, Response, abort from flask_login import login_required, current_user # Import Role_Manager @@ -19,17 +19,9 @@ sys.path.append(os.environ['AIL_BIN']) ################################## # Import Project packages ################################## -from lib import chats_viewer - - - -############################################ - from lib import ail_core -from lib.objects import ail_objects from lib import chats_viewer -from lib.objects import Chats -from lib.objects import ChatSubChannels +from lib import Tag # ============ BLUEPRINT ============ chats_explorer = Blueprint('chats_explorer', __name__, template_folder=os.path.join(os.environ['AIL_FLASK'], 'templates/chats_explorer')) @@ -112,11 +104,12 @@ def objects_subchannel_messages(): @chats_explorer.route("/objects/message", methods=['GET']) @login_required @login_read_only -def objects_dashboard_chat(): +def objects_message(): message_id = request.args.get('id') message = chats_viewer.api_get_message(message_id) if message[1] != 200: return create_json_response(message[0], message[1]) else: message = message[0] - return render_template('ChatMessage.html', meta=message, bootstrap_label=bootstrap_label) \ No newline at end of file + return render_template('ChatMessage.html', meta=message, bootstrap_label=bootstrap_label, + modal_add_tags=Tag.get_modal_add_tags(message['id'], object_type='message')) diff --git a/var/www/templates/chats_explorer/ChatMessage.html b/var/www/templates/chats_explorer/ChatMessage.html index db7a80c3..0e96015c 100644 --- a/var/www/templates/chats_explorer/ChatMessage.html +++ b/var/www/templates/chats_explorer/ChatMessage.html @@ -9,6 +9,8 @@ + + @@ -16,6 +18,7 @@ + @@ -50,11 +60,9 @@ - - - + + - @@ -68,14 +76,12 @@ {{ meta["subtype"] }} - - + -
Object subtypeFirst seenLast seenDate UsernameNb seen
{{ meta['first_seen'] }}{{ meta['last_seen'] }}{{ meta['full_date'] }} - {% if 'username' in meta %} - {{ meta['username']['id'] }} + {% if 'username' in meta['user-account'] %} + {{ meta['user-account']['username']['id'] }} {% endif %} {{ meta['nb_seen'] }}
@@ -85,29 +91,44 @@ -
  • -
    -
    - Tags: + + +
    +
    + + {% include 'modals/edit_tag.html' %} + {% for tag in meta['tags'] %} {% endfor %} + {% include 'modals/add_tags.html' %} -
    -
  • - + + + - {% with obj_type='chat', obj_id=meta['id'], obj_subtype=meta['subtype'] %} - {% include 'modals/investigations_register_obj.html' %} - {% endwith %} - +
    +
    + + + +
    +
    + {% with obj_type=meta['type'], obj_id=meta['id'], obj_subtype=''%} + {% include 'modals/investigations_register_obj.html' %} + {% endwith %} +
    + +
    +
    +
    @@ -116,7 +137,11 @@
    - {{ meta['date'] }} +
    +

    + {{ meta['date'] }} +

    +