From 599f3ca9534fca89dff00be717debffac055636b Mon Sep 17 00:00:00 2001 From: terrtia Date: Mon, 18 Mar 2024 15:53:20 +0100 Subject: [PATCH] chg: [chat] add chat default + basic card --- bin/lib/Tag.py | 4 +- bin/lib/objects/Chats.py | 2 +- bin/lib/objects/ail_objects.py | 5 +- var/www/blueprints/chats_explorer.py | 4 +- var/www/blueprints/tags_ui.py | 27 ++++-- .../chats_explorer/basic_card_chat.html | 67 ++++++++++++++ .../templates/chats_explorer/card_chat.html | 88 +++++++++++++++++++ .../templates/chats_explorer/card_image.html | 2 +- .../templates/chats_explorer/chat_viewer.html | 64 +------------- .../correlation/show_correlation.html | 2 + var/www/templates/modals/edit_tag.html | 2 +- 11 files changed, 189 insertions(+), 78 deletions(-) create mode 100644 var/www/templates/chats_explorer/basic_card_chat.html create mode 100644 var/www/templates/chats_explorer/card_chat.html diff --git a/bin/lib/Tag.py b/bin/lib/Tag.py index 1dacbfe8..15edcd0a 100755 --- a/bin/lib/Tag.py +++ b/bin/lib/Tag.py @@ -1558,14 +1558,14 @@ def get_obj_date(object_type, object_id): return None # 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: return ({'status': 'error', 'reason': 'object id not found'}, 404) if not tags: return ({'status': 'error', 'reason': 'No Tag(s) specified'}, 400) 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: return res diff --git a/bin/lib/objects/Chats.py b/bin/lib/objects/Chats.py index dde776b0..0e6dadd0 100755 --- a/bin/lib/objects/Chats.py +++ b/bin/lib/objects/Chats.py @@ -51,7 +51,7 @@ def delete(self): def get_link(self, flask_context=False): 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: url = f'{baseurl}/correlation/show?type={self.type}&subtype={self.subtype}&id={self.id}' return url diff --git a/bin/lib/objects/ail_objects.py b/bin/lib/objects/ail_objects.py index 63248a79..14a035a4 100755 --- a/bin/lib/objects/ail_objects.py +++ b/bin/lib/objects/ail_objects.py @@ -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): obj = get_object(obj_type, subtype, id) - meta = obj.get_meta() - meta['icon'] = obj.get_svg_icon() + meta = obj.get_meta(options={'icon', 'info', 'nb_participants'}) + # 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': meta['sparkline'] = obj.get_sparkline() if obj_type == 'cve': diff --git a/var/www/blueprints/chats_explorer.py b/var/www/blueprints/chats_explorer.py index e24abe82..3363a29b 100644 --- a/var/www/blueprints/chats_explorer.py +++ b/var/www/blueprints/chats_explorer.py @@ -92,7 +92,9 @@ def chats_explorer_chat(): else: chat = chat[0] 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']) @login_required diff --git a/var/www/blueprints/tags_ui.py b/var/www/blueprints/tags_ui.py index f833ab16..2bf7faef 100644 --- a/var/www/blueprints/tags_ui.py +++ b/var/www/blueprints/tags_ui.py @@ -170,7 +170,11 @@ def tag_confirm(): if not obj.exists(): abort(404) 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') @login_required @@ -192,22 +196,27 @@ def add_tags(): if res[1] != 200: 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_analyst def delete_tag(): - - object_type = request.args.get('object_type') - object_id = request.args.get('object_id') - subtype = '' # TODO: handle subtype object + object_type = request.args.get('type') + subtype = request.args.get('subtype', '') + object_id = request.args.get('id') 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: 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') diff --git a/var/www/templates/chats_explorer/basic_card_chat.html b/var/www/templates/chats_explorer/basic_card_chat.html new file mode 100644 index 00000000..6598a472 --- /dev/null +++ b/var/www/templates/chats_explorer/basic_card_chat.html @@ -0,0 +1,67 @@ + + +
+
+

+ + + + {{ meta["svg_icon"]["icon"] }} + + + {% if meta['username'] %}{{ meta["username"]["id"] }} {% else %} {{ meta['name'] }}{% endif %} : +

+
+
+ + {% if meta["tags_safe"] %} + {% if meta['icon'] %} + {{ meta['id'] }} + {% endif %} + {% else %} + + + + + {% endif %} + + + + + + + + {{meta["first_seen"]}} + + + + {{meta["last_seen"]}} + + + + + + + + + {{meta["nb_subchannels"]}}   + + + + {{meta["nb_participants"]}} + + + +
+ {% for tag in meta['tags'] %} + {{ tag }} + {% endfor %} +
+ +
+ {% include 'objects/block_object_footer_small.html' %} +
\ No newline at end of file diff --git a/var/www/templates/chats_explorer/card_chat.html b/var/www/templates/chats_explorer/card_chat.html new file mode 100644 index 00000000..982297b9 --- /dev/null +++ b/var/www/templates/chats_explorer/card_chat.html @@ -0,0 +1,88 @@ + + + +{% with modal_add_tags=ail_tags %} + {% include 'modals/add_tags.html' %} +{% endwith %} + +{% include 'modals/edit_tag.html' %} + + +
+
+

{% if meta['username'] %}{{ meta["username"]["id"] }} {% else %} {{ meta['name'] }}{% endif %} :

+ {% if meta['icon'] %} +
{{ meta['id'] }}
+ {% endif %} +
    +
  • + + + + + + + + + + + + + + + + + + + + + + + +
    NameIDCreated atFirst SeenLast SeenNB Sub-ChannelsParticipants
    {{ meta['name'] }}{{ meta['id'] }}{{ meta['created_at'] }} + {% if meta['first_seen'] %} + {{ meta['first_seen'][0:4] }}-{{ meta['first_seen'][4:6] }}-{{ meta['first_seen'][6:8] }} + {% endif %} + + {% if meta['last_seen'] %} + {{ meta['last_seen'][0:4] }}-{{ meta['last_seen'][4:6] }}-{{ meta['last_seen'][6:8] }} + {% endif %} + {{ meta['nb_subchannels'] }} + {{ meta['nb_participants']}} +
    + {% if meta['info'] %} +
  • +
    {{ meta['info'] }}
    + {% if meta['translation_info'] %} +
    +
    {{ meta['translation_info'] }}
    + {% endif %} +
  • + {% endif %} + +
  • +
    + Tags: + {% for tag in meta['tags'] %} + + {% endfor %} + +
    +
  • +
+ + {% with obj_type=meta['type'], obj_id=meta['id'], obj_subtype=meta['subtype'] %} + {% include 'modals/investigations_register_obj.html' %} + {% endwith %} + + +
+
\ No newline at end of file diff --git a/var/www/templates/chats_explorer/card_image.html b/var/www/templates/chats_explorer/card_image.html index 058e3c0d..9e382aea 100644 --- a/var/www/templates/chats_explorer/card_image.html +++ b/var/www/templates/chats_explorer/card_image.html @@ -13,7 +13,7 @@ } -
+

{{ meta["id"] }} :

    diff --git a/var/www/templates/chats_explorer/chat_viewer.html b/var/www/templates/chats_explorer/chat_viewer.html index ecf45fd5..872f3b55 100644 --- a/var/www/templates/chats_explorer/chat_viewer.html +++ b/var/www/templates/chats_explorer/chat_viewer.html @@ -54,67 +54,9 @@
    -
    - -
    -

    {% if chat['username'] %}{{ chat["username"]["id"] }} {% else %} {{ chat['name'] }}{% endif %} :

    - {% if chat['icon'] %} -
    {{ chat['id'] }}
    - {% endif %} -
      -
    • - - - - - - - - - - - - - - - - - - - - - - - -
      NameIDCreated atFirst SeenLast SeenNB Sub-ChannelsParticipants
      {{ chat['name'] }}{{ chat['id'] }}{{ chat['created_at'] }} - {% if chat['first_seen'] %} - {{ chat['first_seen'][0:4] }}-{{ chat['first_seen'][4:6] }}-{{ chat['first_seen'][6:8] }} - {% endif %} - - {% if chat['last_seen'] %} - {{ chat['last_seen'][0:4] }}-{{ chat['last_seen'][4:6] }}-{{ chat['last_seen'][6:8] }} - {% endif %} - {{ chat['nb_subchannels'] }} - {{ chat['nb_participants']}} -
      - {% if chat['info'] %} -
    • -
      {{ chat['info'] }}
      - {% if chat['translation_info'] %} -
      -
      {{ chat['translation_info'] }}
      - {% endif %} -
    • - {% endif %} - -
    - -
    -
    - - {% for tag in chat['tags_messages'] %} - {{ tag }} {{ chat['tags_messages'][tag] }} - {% endfor %} + {% with meta=chat %} + {% include 'chats_explorer/card_chat.html' %} + {% endwith %} {% if chat['subchannels'] %}

    Sub-Channels:

    diff --git a/var/www/templates/correlation/show_correlation.html b/var/www/templates/correlation/show_correlation.html index a4286471..67d71a5d 100644 --- a/var/www/templates/correlation/show_correlation.html +++ b/var/www/templates/correlation/show_correlation.html @@ -101,6 +101,8 @@ {% if dict_object["object_type"] == "pgp" %} {% include 'correlation/metadata_card_pgp.html' %} + {% elif dict_object["object_type"] == "chat" %} + {% include 'chats_explorer/card_chat.html' %} {% elif dict_object["object_type"] == "cryptocurrency" %} {% include 'correlation/metadata_card_cryptocurrency.html' %} {% elif dict_object["object_type"] == "username" %} diff --git a/var/www/templates/modals/edit_tag.html b/var/www/templates/modals/edit_tag.html index 512c8277..ad1e4189 100644 --- a/var/www/templates/modals/edit_tag.html +++ b/var/www/templates/modals/edit_tag.html @@ -51,6 +51,6 @@

    Warning< 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_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); })