Skip to content

Commit

Permalink
chg: [chats] message object template
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrtia committed Nov 8, 2023
1 parent e0f70c5 commit 54c57ea
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 45 deletions.
2 changes: 1 addition & 1 deletion bin/lib/ail_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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')
Expand Down
6 changes: 5 additions & 1 deletion bin/lib/chats_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# #
Expand Down
10 changes: 5 additions & 5 deletions bin/lib/objects/Messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ def get_message_id(self): # TODO optimize

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
Expand Down Expand Up @@ -151,9 +149,9 @@ def get_html2text_content(self, content=None, ignore_links=False):

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):
Expand Down Expand Up @@ -196,7 +194,7 @@ def get_meta(self, options=None, timestamp=None):
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(' ')

Expand All @@ -222,6 +220,8 @@ def get_meta(self, options=None, timestamp=None):
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
Expand Down
21 changes: 7 additions & 14 deletions var/www/blueprints/chats_explorer.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,17 +19,9 @@
##################################
# 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'))
Expand Down Expand Up @@ -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)
return render_template('ChatMessage.html', meta=message, bootstrap_label=bootstrap_label,
modal_add_tags=Tag.get_modal_add_tags(message['id'], object_type='message'))
73 changes: 49 additions & 24 deletions var/www/templates/chats_explorer/ChatMessage.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
<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/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 -->
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="{{ url_for('static', filename='js/popper.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/dataTables.bootstrap.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/tags.js') }}"></script>

<style>
.chat-message-left,
Expand All @@ -27,6 +30,13 @@
flex-direction: row-reverse;
margin-left: auto
}
.divider:after,
.divider:before {
content: "";
flex: 1;
height: 2px;
background: #eee;
}
</style>
</head>
<body>
Expand All @@ -50,11 +60,9 @@ <h3 class="text-secondary">{{ meta["id"] }} :</h3>
<table class="table">
<thead>
<tr>
<th>Object subtype</th>
<th>First seen</th>
<th>Last seen</th>
<th></th>
<th>Date</th>
<th>Username</th>
<th>Nb seen</th>
</tr>
</thead>
<tbody>
Expand All @@ -68,14 +76,12 @@ <h3 class="text-secondary">{{ meta["id"] }} :</h3>
</svg>
{{ meta["subtype"] }}
</td>
<td>{{ meta['first_seen'] }}</td>
<td>{{ meta['last_seen'] }}</td>
<td>{{ meta['full_date'] }}</td>
<td>
{% if 'username' in meta %}
{{ meta['username']['id'] }}
{% if 'username' in meta['user-account'] %}
{{ meta['user-account']['username']['id'] }}
{% endif %}
</td>
<td>{{ meta['nb_seen'] }}</td>
</tr>
</tbody>
</table>
Expand All @@ -85,29 +91,44 @@ <h3 class="text-secondary">{{ meta["id"] }} :</h3>
</div>
</div>
</li>
<li class="list-group-item py-0">
<br>
<div class="mb-3">
Tags:
</ul>

<div>
<h5>
<span>
{% include 'modals/edit_tag.html' %}

{% for tag in meta['tags'] %}
<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 }}
</button>
{% endfor %}
{% include 'modals/add_tags.html' %}
<button type="button" class="btn btn-light" data-toggle="modal" data-target="#add_tags_modal">
<i class="far fa-plus-square"></i>
</button>
</div>
</li>
</ul>
</span>
</h5>
</div>

{% with obj_type='chat', obj_id=meta['id'], obj_subtype=meta['subtype'] %}
{% include 'modals/investigations_register_obj.html' %}
{% endwith %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#investigations_register_obj_modal">
<i class="fas fa-microscope"></i> Investigations
</button>
<div class="d-flex flex-row-reverse bd-highlight">
<div>
<a href="{{ url_for('correlation.show_correlation')}}?type={{ meta['type'] }}&id={{ meta['id'] }}" target="_blank">
<button class="btn btn-lg btn-info"><i class="fas fa-project-diagram"></i> Correlations Graph</button>
</a>
</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>
Expand All @@ -116,7 +137,11 @@ <h3 class="text-secondary">{{ meta["id"] }} :</h3>
<div class="position-relative">
<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>
Expand Down

0 comments on commit 54c57ea

Please sign in to comment.