chg: [chat] add chat default + basic card

This commit is contained in:
terrtia 2024-03-18 15:53:20 +01:00
parent e92bf72f64
commit 599f3ca953
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
11 changed files with 189 additions and 78 deletions

View file

@ -1558,14 +1558,14 @@ def get_obj_date(object_type, object_id):
return None return None
# API QUERY # API QUERY
def api_delete_obj_tags(tags=[], object_id=None, object_type="item"): def api_delete_obj_tags(tags=[], object_id=None, object_type="item", subtype=''):
if not object_id: if not object_id:
return ({'status': 'error', 'reason': 'object id not found'}, 404) return ({'status': 'error', 'reason': 'object id not found'}, 404)
if not tags: if not tags:
return ({'status': 'error', 'reason': 'No Tag(s) specified'}, 400) return ({'status': 'error', 'reason': 'No Tag(s) specified'}, 400)
for tag in tags: for tag in tags:
res = delete_object_tag(tag, object_type, object_id, subtype='') res = delete_object_tag(tag, object_type, object_id, subtype=subtype)
if res: if res:
return res return res

View file

@ -51,7 +51,7 @@ class Chat(AbstractChatObject):
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, subtype=self.subtype, id=self.id) url = url_for('chats_explorer.chats_explorer_chat', subtype=self.subtype, id=self.id)
else: else:
url = f'{baseurl}/correlation/show?type={self.type}&subtype={self.subtype}&id={self.id}' url = f'{baseurl}/correlation/show?type={self.type}&subtype={self.subtype}&id={self.id}'
return url return url

View file

@ -254,8 +254,9 @@ def get_objects_meta(objs, options=set(), flask_context=False):
def get_object_card_meta(obj_type, subtype, id, related_btc=False): def get_object_card_meta(obj_type, subtype, id, related_btc=False):
obj = get_object(obj_type, subtype, id) obj = get_object(obj_type, subtype, id)
meta = obj.get_meta() meta = obj.get_meta(options={'icon', 'info', 'nb_participants'})
meta['icon'] = obj.get_svg_icon() # meta['icon'] = obj.get_svg_icon()
meta['svg_icon'] = obj.get_svg_icon()
if subtype or obj_type == 'cookie-name' or obj_type == 'cve' or obj_type == 'etag' or obj_type == 'title' or obj_type == 'favicon' or obj_type == 'hhhash': if subtype or obj_type == 'cookie-name' or obj_type == 'cve' or obj_type == 'etag' or obj_type == 'title' or obj_type == 'favicon' or obj_type == 'hhhash':
meta['sparkline'] = obj.get_sparkline() meta['sparkline'] = obj.get_sparkline()
if obj_type == 'cve': if obj_type == 'cve':

View file

@ -92,7 +92,9 @@ def chats_explorer_chat():
else: else:
chat = chat[0] chat = chat[0]
languages = Language.get_translation_languages() languages = Language.get_translation_languages()
return render_template('chat_viewer.html', chat=chat, bootstrap_label=bootstrap_label, translation_languages=languages, translation_target=target) return render_template('chat_viewer.html', chat=chat, bootstrap_label=bootstrap_label,
ail_tags=Tag.get_modal_add_tags(chat['id'], chat['type'], chat['subtype']),
translation_languages=languages, translation_target=target)
@chats_explorer.route("chats/explorer/messages/stats/week", methods=['GET']) @chats_explorer.route("chats/explorer/messages/stats/week", methods=['GET'])
@login_required @login_required

View file

@ -170,7 +170,11 @@ def tag_confirm():
if not obj.exists(): if not obj.exists():
abort(404) abort(404)
Tag.confirm_tag(tag, obj) Tag.confirm_tag(tag, obj)
return redirect(obj.get_link(flask_context=True))
if request.referrer:
return redirect(request.referrer)
else:
return redirect(obj.get_link(flask_context=True))
@tags_ui.route('/tag/add_tags') @tags_ui.route('/tag/add_tags')
@login_required @login_required
@ -192,22 +196,27 @@ def add_tags():
if res[1] != 200: if res[1] != 200:
return str(res[0]) return str(res[0])
return redirect(ail_objects.get_object_link(object_type, object_subtype, object_id, flask_context=True)) if request.referrer:
return redirect(request.referrer)
else:
return redirect(ail_objects.get_object_link(object_type, object_subtype, object_id, flask_context=True))
@tags_ui.route('/tag/delete_tag') @tags_ui.route('/tag/delete_tag') # TODO FIX REQUEST PARAMETER
@login_required @login_required
@login_analyst @login_analyst
def delete_tag(): def delete_tag():
object_type = request.args.get('type')
object_type = request.args.get('object_type') subtype = request.args.get('subtype', '')
object_id = request.args.get('object_id') object_id = request.args.get('id')
subtype = '' # TODO: handle subtype object
tag = request.args.get('tag') tag = request.args.get('tag')
res = Tag.api_delete_obj_tags(tags=[tag], object_id=object_id, object_type=object_type) res = Tag.api_delete_obj_tags(tags=[tag], object_id=object_id, object_type=object_type, subtype=subtype)
if res[1] != 200: if res[1] != 200:
return str(res[0]) return str(res[0])
return redirect(ail_objects.get_object_link(object_type, subtype, object_id, flask_context=True)) if request.referrer:
return redirect(request.referrer)
else:
return redirect(ail_objects.get_object_link(object_type, subtype, object_id, flask_context=True))
@tags_ui.route('/tag/get_all_tags') @tags_ui.route('/tag/get_all_tags')

View file

@ -0,0 +1,67 @@
<style>
.object_image {
filter: blur(5px);
}
</style>
<div class="card">
<div class="card-header">
<h4 class="text-secondary mb-0">
<svg height="30" width="30">
<g class="nodes">
<circle cx="15" cy="15" r="15" fill="{{ meta["svg_icon"]["color"] }}"></circle>
<text x="15" y="15" text-anchor="middle" dominant-baseline="central" class="{{ meta["svg_icon"]["style"] }}" font-size="16px">{{ meta["svg_icon"]["icon"] }}</text>
</g>
</svg>
{% if meta['username'] %}{{ meta["username"]["id"] }} {% else %} {{ meta['name'] }}{% endif %} :
</h4>
</div>
<div class="card-body py-0">
<span class="">
{% if meta["tags_safe"] %}
{% if meta['icon'] %}
<span><img src="{{ url_for('objects_image.image', filename=meta['icon'])}}" class="my-1" alt="{{ meta['id'] }}" width="200" height="200"></span>
{% endif %}
{% else %}
<span class="my-2 fa-stack fa-8x">
<i class="fas fa-stack-1x fa-image"></i>
<i class="fas fa-stack-2x fa-ban" style="color:Red"></i>
</span>
{% endif %}
</span>
<span>
<span class="badge badge-dark">
<span class="badge badge-info" style="font-size: 0.8rem;">
<i class="fas fa-hourglass-start"></i>
</span>
{{meta["first_seen"]}}
<span class="badge badge-light mx-1" style="font-size: 1rem;">
<i class="far fa-calendar-alt"></i>
</span>
{{meta["last_seen"]}}
<span class="badge badge-secondary" style="font-size: 0.8rem;">
<i class="fas fa-hourglass-end"></i>
</span>
</span>
<span class="badge badge-dark">
<span class="badge badge-info" style="font-size: 0.8rem;">
<i class="far fa-comments"></i>
</span>
{{meta["nb_subchannels"]}}&nbsp;&nbsp;
<span class="badge badge-info" style="font-size: 0.8rem;">
<i class="fas fa-user-circle"></i>
</span>
{{meta["nb_participants"]}}
</span>
</span>
<div class="">
{% for tag in meta['tags'] %}
<span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">{{ tag }}</span>
{% endfor %}
</div>
</div>
{% include 'objects/block_object_footer_small.html' %}
</div>

View file

@ -0,0 +1,88 @@
<link href="{{ url_for('static', filename='css/tags.css') }}" rel="stylesheet" type="text/css" />
<script src="{{ url_for('static', filename='js/tags.js') }}"></script>
{% with modal_add_tags=ail_tags %}
{% include 'modals/add_tags.html' %}
{% endwith %}
{% include 'modals/edit_tag.html' %}
<div class="card my-1">
<div class="card-header">
<h4 class="text-secondary">{% if meta['username'] %}{{ meta["username"]["id"] }} {% else %} {{ meta['name'] }}{% endif %} :</h4>
{% if meta['icon'] %}
<div><img src="{{ url_for('objects_image.image', filename=meta['icon'])}}" class="mb-2" alt="{{ meta['id'] }}" width="200" height="200"></div>
{% endif %}
<ul class="list-group mb-2">
<li class="list-group-item py-0">
<table class="table">
<thead class="">
<tr>
<th>Name</th>
<th>ID</th>
<th>Created at</th>
<th>First Seen</th>
<th>Last Seen</th>
<th>NB Sub-Channels</th>
<th>Participants</th>
</tr>
</thead>
<tbody style="font-size: 15px;">
<tr>
<td>{{ meta['name'] }}</td>
<td>{{ meta['id'] }}</td>
<td>{{ meta['created_at'] }}</td>
<td>
{% if meta['first_seen'] %}
{{ meta['first_seen'][0:4] }}-{{ meta['first_seen'][4:6] }}-{{ meta['first_seen'][6:8] }}
{% endif %}
</td>
<td>
{% if meta['last_seen'] %}
{{ meta['last_seen'][0:4] }}-{{ meta['last_seen'][4:6] }}-{{ meta['last_seen'][6:8] }}
{% endif %}
</td>
<td>{{ meta['nb_subchannels'] }}</td>
<td>
<a href="{{ url_for('chats_explorer.chats_explorer_chat_participants')}}?type=chat&subtype={{ meta['subtype'] }}&id={{ meta['id'] }}"><i class="far fa-user-circle"></i> {{ meta['nb_participants']}}</a>
</td>
</tr>
</tbody>
</table>
{% if meta['info'] %}
<li class="list-group-item py-0">
<pre class="my-0">{{ meta['info'] }}</pre>
{% if meta['translation_info'] %}
<hr class="m-1">
<pre class="my-0 text-secondary">{{ meta['translation_info'] }}</pre>
{% endif %}
</li>
{% endif %}
<li class="list-group-item py-0">
<div class="my-2">
Tags:
{% 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="{{ meta['type'] }}" data-objsubtype="{{ meta['subtype'] }}" data-objid="{{ meta["id"] }}">
{{ tag }}
</button>
{% endfor %}
<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>
{% with obj_type=meta['type'], 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>
</div>

View file

@ -13,7 +13,7 @@
} }
</style> </style>
<div class="card"> <div class="card my-1">
<div class="card-header"> <div class="card-header">
<h4 class="text-secondary">{{ meta["id"] }} :</h4> <h4 class="text-secondary">{{ meta["id"] }} :</h4>
<ul class="list-group mb-2"> <ul class="list-group mb-2">

View file

@ -54,67 +54,9 @@
<div class="col-12 col-lg-10" id="core_content"> <div class="col-12 col-lg-10" id="core_content">
<div class="card my-3"> {% with meta=chat %}
{% include 'chats_explorer/card_chat.html' %}
<div class="card-header" style="background-color:#d9edf7;font-size: 15px"> {% endwith %}
<h4 class="text-secondary">{% if chat['username'] %}{{ chat["username"]["id"] }} {% else %} {{ chat['name'] }}{% endif %} :</h4>
{% if chat['icon'] %}
<div><img src="{{ url_for('objects_image.image', filename=chat['icon'])}}" class="mb-2" alt="{{ chat['id'] }}" width="200" height="200"></div>
{% endif %}
<ul class="list-group mb-2">
<li class="list-group-item py-0">
<table class="table">
<thead class="">
<tr>
<th>Name</th>
<th>ID</th>
<th>Created at</th>
<th>First Seen</th>
<th>Last Seen</th>
<th>NB Sub-Channels</th>
<th>Participants</th>
</tr>
</thead>
<tbody style="font-size: 15px;">
<tr>
<td>{{ chat['name'] }}</td>
<td>{{ chat['id'] }}</td>
<td>{{ chat['created_at'] }}</td>
<td>
{% if chat['first_seen'] %}
{{ chat['first_seen'][0:4] }}-{{ chat['first_seen'][4:6] }}-{{ chat['first_seen'][6:8] }}
{% endif %}
</td>
<td>
{% if chat['last_seen'] %}
{{ chat['last_seen'][0:4] }}-{{ chat['last_seen'][4:6] }}-{{ chat['last_seen'][6:8] }}
{% endif %}
</td>
<td>{{ chat['nb_subchannels'] }}</td>
<td>
<a href="{{ url_for('chats_explorer.chats_explorer_chat_participants')}}?type=chat&subtype={{ chat['subtype'] }}&id={{ chat['id'] }}"><i class="far fa-user-circle"></i> {{ chat['nb_participants']}}</a>
</td>
</tr>
</tbody>
</table>
{% if chat['info'] %}
<li class="list-group-item py-0">
<pre class="my-0">{{ chat['info'] }}</pre>
{% if chat['translation_info'] %}
<hr class="m-1">
<pre class="my-0 text-secondary">{{ chat['translation_info'] }}</pre>
{% endif %}
</li>
{% endif %}
</li>
</ul>
</div>
</div>
{% for tag in chat['tags_messages'] %}
<span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">{{ tag }} <span class="badge badge-light">{{ chat['tags_messages'][tag] }}</span></span>
{% endfor %}
{% if chat['subchannels'] %} {% if chat['subchannels'] %}
<h4 class="mt-2">Sub-Channels:</h4> <h4 class="mt-2">Sub-Channels:</h4>

View file

@ -101,6 +101,8 @@
{% if dict_object["object_type"] == "pgp" %} {% if dict_object["object_type"] == "pgp" %}
{% include 'correlation/metadata_card_pgp.html' %} {% include 'correlation/metadata_card_pgp.html' %}
{% elif dict_object["object_type"] == "chat" %}
{% include 'chats_explorer/card_chat.html' %}
{% elif dict_object["object_type"] == "cryptocurrency" %} {% elif dict_object["object_type"] == "cryptocurrency" %}
{% include 'correlation/metadata_card_cryptocurrency.html' %} {% include 'correlation/metadata_card_cryptocurrency.html' %}
{% elif dict_object["object_type"] == "username" %} {% elif dict_object["object_type"] == "username" %}

View file

@ -51,6 +51,6 @@ $('#edit_tags_modal').on('show.bs.modal', function (event) {
tag_confirm.show(); tag_confirm.show();
modal.find('#modal_tag_confirm').prop("href", "{{ url_for('tags_ui.tag_confirm') }}?type="+ objtype +"&subtype="+ objsubtype +"&id="+ objid +"&tag="+ tagid); modal.find('#modal_tag_confirm').prop("href", "{{ url_for('tags_ui.tag_confirm') }}?type="+ objtype +"&subtype="+ objsubtype +"&id="+ objid +"&tag="+ tagid);
} }
modal.find('#modal_tag_edit_delete_tag').prop("href", "{{ url_for('tags_ui.delete_tag') }}?object_type="+ objtype +"&object_id="+ objid +"&tag="+ tagid); modal.find('#modal_tag_edit_delete_tag').prop("href", "{{ url_for('tags_ui.delete_tag') }}?type="+ objtype +"&subtype="+ objsubtype +"&id="+ objid +"&tag="+ tagid);
}) })
</script> </script>