chg: [chats] message object template

This commit is contained in:
terrtia 2023-11-08 15:46:05 +01:00
parent e0f70c5072
commit 54c57ea35b
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
5 changed files with 67 additions and 45 deletions

View file

@ -17,7 +17,7 @@ r_object = config_loader.get_db_conn("Kvrocks_Objects")
config_loader = None config_loader = None
AIL_OBJECTS = sorted({'chat', 'cookie-name', 'cve', 'cryptocurrency', 'decoded', 'domain', 'etag', 'favicon', 'hhhash', 'item', 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(): def get_ail_uuid():
ail_uuid = r_serv_db.get('ail:uuid') ail_uuid = r_serv_db.get('ail:uuid')

View file

@ -329,7 +329,11 @@ def api_get_message(message_id):
message = Messages.Message(message_id) message = Messages.Message(message_id)
if not message.exists(): if not message.exists():
return {"status": "error", "reason": "Unknown uuid"}, 404 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 # # # # # # # # # # LATER
# # # #

View file

@ -98,8 +98,6 @@ class Message(AbstractObject):
def get_chat_id(self): # TODO optimize -> use me to tag Chat def get_chat_id(self): # TODO optimize -> use me to tag Chat
chat_id = self.get_basename().rsplit('_', 1)[0] chat_id = self.get_basename().rsplit('_', 1)[0]
# if chat_id.endswith('.gz'):
# chat_id = chat_id[:-3]
return chat_id return chat_id
# TODO get Instance ID # TODO get Instance ID
@ -151,9 +149,9 @@ class Message(AbstractObject):
def get_link(self, flask_context=False): def get_link(self, flask_context=False):
if flask_context: 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: else:
url = f'{baseurl}/correlation/show?type={self.type}&id={self.id}' url = f'{baseurl}/objects/message?id={self.id}'
return url return url
def get_svg_icon(self): def get_svg_icon(self):
@ -196,7 +194,7 @@ class Message(AbstractObject):
else: else:
timestamp = float(timestamp) timestamp = float(timestamp)
timestamp = datetime.fromtimestamp(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['hour'] = timestamp.strftime('%H:%M:%S')
meta['full_date'] = timestamp.isoformat(' ') meta['full_date'] = timestamp.isoformat(' ')
@ -222,6 +220,8 @@ class Message(AbstractObject):
meta['user-account'] = self.get_user_account(meta=True) meta['user-account'] = self.get_user_account(meta=True)
if not meta['user-account']: if not meta['user-account']:
meta['user-account'] = {'id': 'UNKNOWN'} meta['user-account'] = {'id': 'UNKNOWN'}
if 'chat' in options:
meta['chat'] = self.get_chat_id()
# meta['encoding'] = None # meta['encoding'] = None
return meta return meta

View file

@ -1,15 +1,15 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*-coding:UTF-8 -* # -*-coding:UTF-8 -*
''' """
Blueprint Flask: crawler splash endpoints: dashboard, onion crawler ... Blueprint Flask: crawler splash endpoints: dashboard, onion crawler ...
''' """
import os import os
import sys import sys
import json 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 from flask_login import login_required, current_user
# Import Role_Manager # Import Role_Manager
@ -19,17 +19,9 @@ sys.path.append(os.environ['AIL_BIN'])
################################## ##################################
# Import Project packages # Import Project packages
################################## ##################################
from lib import chats_viewer
############################################
from lib import ail_core from lib import ail_core
from lib.objects import ail_objects
from lib import chats_viewer from lib import chats_viewer
from lib.objects import Chats from lib import Tag
from lib.objects import ChatSubChannels
# ============ BLUEPRINT ============ # ============ BLUEPRINT ============
chats_explorer = Blueprint('chats_explorer', __name__, template_folder=os.path.join(os.environ['AIL_FLASK'], 'templates/chats_explorer')) 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']) @chats_explorer.route("/objects/message", methods=['GET'])
@login_required @login_required
@login_read_only @login_read_only
def objects_dashboard_chat(): def objects_message():
message_id = request.args.get('id') message_id = request.args.get('id')
message = chats_viewer.api_get_message(message_id) message = chats_viewer.api_get_message(message_id)
if message[1] != 200: if message[1] != 200:
return create_json_response(message[0], message[1]) return create_json_response(message[0], message[1])
else: else:
message = message[0] message = message[0]
return render_template('ChatMessage.html', meta=message, bootstrap_label=bootstrap_label) return render_template('ChatMessage.html', meta=message, bootstrap_label=bootstrap_label,
modal_add_tags=Tag.get_modal_add_tags(message['id'], object_type='message'))

View file

@ -9,6 +9,8 @@
<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/tags.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ url_for('static', filename='css/ail-project.css') }}" rel="stylesheet">
<!-- JS --> <!-- JS -->
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script> <script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
@ -16,6 +18,7 @@
<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script> <script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script> <script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script> <script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/tags.js') }}"></script>
<style> <style>
.chat-message-left, .chat-message-left,
@ -27,6 +30,13 @@
flex-direction: row-reverse; flex-direction: row-reverse;
margin-left: auto margin-left: auto
} }
.divider:after,
.divider:before {
content: "";
flex: 1;
height: 2px;
background: #eee;
}
</style> </style>
</head> </head>
<body> <body>
@ -50,11 +60,9 @@
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>Object subtype</th> <th></th>
<th>First seen</th> <th>Date</th>
<th>Last seen</th>
<th>Username</th> <th>Username</th>
<th>Nb seen</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -68,14 +76,12 @@
</svg> </svg>
{{ meta["subtype"] }} {{ meta["subtype"] }}
</td> </td>
<td>{{ meta['first_seen'] }}</td> <td>{{ meta['full_date'] }}</td>
<td>{{ meta['last_seen'] }}</td>
<td> <td>
{% if 'username' in meta %} {% if 'username' in meta['user-account'] %}
{{ meta['username']['id'] }} {{ meta['user-account']['username']['id'] }}
{% endif %} {% endif %}
</td> </td>
<td>{{ meta['nb_seen'] }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -85,29 +91,44 @@
</div> </div>
</div> </div>
</li> </li>
<li class="list-group-item py-0"> </ul>
<br>
<div class="mb-3"> <div>
Tags: <h5>
<span>
{% include 'modals/edit_tag.html' %}
{% for tag in meta['tags'] %} {% for tag in meta['tags'] %}
<button class="btn btn-{{ bootstrap_label[loop.index0 % 5] }}" data-toggle="modal" data-target="#edit_tags_modal" <button class="btn btn-{{ bootstrap_label[loop.index0 % 5] }}" data-toggle="modal" data-target="#edit_tags_modal"
data-tagid="{{ tag }}" data-objtype="chat" data-objsubtype="{{ meta["subtype"] }}" data-objid="{{ meta["id"] }}"> data-tagid="{{ tag }}" data-objtype="{{ meta['type'] }}" data-objsubtype="" data-objid="{{ meta['id'] }}">
{{ tag }} {{ tag }}
</button> </button>
{% endfor %} {% endfor %}
{% include 'modals/add_tags.html' %}
<button type="button" class="btn btn-light" data-toggle="modal" data-target="#add_tags_modal"> <button type="button" class="btn btn-light" data-toggle="modal" data-target="#add_tags_modal">
<i class="far fa-plus-square"></i> <i class="far fa-plus-square"></i>
</button> </button>
</div> </span>
</li> </h5>
</ul> </div>
{% with obj_type='chat', obj_id=meta['id'], obj_subtype=meta['subtype'] %} <div class="d-flex flex-row-reverse bd-highlight">
{% include 'modals/investigations_register_obj.html' %} <div>
{% endwith %} <a href="{{ url_for('correlation.show_correlation')}}?type={{ meta['type'] }}&id={{ meta['id'] }}" target="_blank">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#investigations_register_obj_modal"> <button class="btn btn-lg btn-info"><i class="fas fa-project-diagram"></i> Correlations Graph</button>
<i class="fas fa-microscope"></i> Investigations </a>
</button> </div>
<div>
{% with obj_type=meta['type'], obj_id=meta['id'], obj_subtype=''%}
{% include 'modals/investigations_register_obj.html' %}
{% endwith %}
<div class="mr-2">
<button type="button" class="btn btn-lg btn-primary" data-toggle="modal" data-target="#investigations_register_obj_modal">
<i class="fas fa-microscope"></i> Investigations
</button>
</div>
</div>
</div>
</div> </div>
</div> </div>
@ -116,7 +137,11 @@
<div class="position-relative"> <div class="position-relative">
<div class="chat-messages p-2"> <div class="chat-messages p-2">
<span class="badge badge-secondary mb-2">{{ meta['date'] }}</span> <div class="divider d-flex align-items-center mb-4">
<p class="text-center h2 mx-3 mb-0" style="color: #a2aab7;">
<span class="badge badge-secondary mb-2" id="date_section_{{ meta['date'] }}">{{ meta['date'] }}</span>
</p>
</div>
<div class="chat-message-left pb-1"> <div class="chat-message-left pb-1">
<div> <div>