diff --git a/bin/lib/Investigations.py b/bin/lib/Investigations.py index 1944d00f..9c6def0f 100755 --- a/bin/lib/Investigations.py +++ b/bin/lib/Investigations.py @@ -235,18 +235,27 @@ class Investigation(object): objs.append(dict_obj) return objs + def get_objects_comment(self, obj_global_id): + return r_tracking.hget(f'investigations:objs:comment:{self.uuid}', obj_global_id) + + def set_objects_comment(self, obj_global_id, comment): + if comment: + r_tracking.hset(f'investigations:objs:comment:{self.uuid}', obj_global_id, comment) + # # TODO: def register_object(self, Object): in OBJECT CLASS - def register_object(self, obj_id, obj_type, subtype): + def register_object(self, obj_id, obj_type, subtype, comment=''): r_tracking.sadd(f'investigations:objs:{self.uuid}', f'{obj_type}:{subtype}:{obj_id}') r_tracking.sadd(f'obj:investigations:{obj_type}:{subtype}:{obj_id}', self.uuid) + if comment: + self.set_objects_comment(f'{obj_type}:{subtype}:{obj_id}', comment) timestamp = int(time.time()) self.set_last_change(timestamp) - def unregister_object(self, obj_id, obj_type, subtype): r_tracking.srem(f'investigations:objs:{self.uuid}', f'{obj_type}:{subtype}:{obj_id}') r_tracking.srem(f'obj:investigations:{obj_type}:{subtype}:{obj_id}', self.uuid) + r_tracking.hdel(f'investigations:objs:comment:{self.uuid}', f'{obj_type}:{subtype}:{obj_id}') timestamp = int(time.time()) self.set_last_change(timestamp) @@ -351,7 +360,7 @@ def get_investigations_selector(): for investigation_uuid in get_all_investigations(): investigation = Investigation(investigation_uuid) name = investigation.get_info() - l_investigations.append({"id":investigation_uuid, "name": name}) + l_investigations.append({"id": investigation_uuid, "name": name}) return l_investigations #{id:'8dc4b81aeff94a9799bd70ba556fa345',name:"Paris"} @@ -453,7 +462,11 @@ def api_register_object(json_dict): if subtype == 'None': subtype = '' obj_id = json_dict.get('id', '').replace(' ', '') - res = investigation.register_object(obj_id, obj_type, subtype) + + comment = json_dict.get('comment', '') + # if comment: + # comment = escape(comment) + res = investigation.register_object(obj_id, obj_type, subtype, comment=comment) return res, 200 def api_unregister_object(json_dict): diff --git a/bin/lib/objects/Items.py b/bin/lib/objects/Items.py index 2e35497e..03c6f2cd 100755 --- a/bin/lib/objects/Items.py +++ b/bin/lib/objects/Items.py @@ -264,10 +264,9 @@ class Item(AbstractObject): """ if options is None: options = set() - meta = {'id': self.id, - 'date': self.get_date(separator=True), - 'source': self.get_source(), - 'tags': self.get_tags(r_list=True)} + meta = self.get_default_meta(tags=True) + meta['date'] = self.get_date(separator=True) + meta['source'] = self.get_source() # optional meta fields if 'content' in options: meta['content'] = self.get_content() diff --git a/bin/lib/objects/Screenshots.py b/bin/lib/objects/Screenshots.py index 19ae3754..26f8543f 100755 --- a/bin/lib/objects/Screenshots.py +++ b/bin/lib/objects/Screenshots.py @@ -88,7 +88,7 @@ class Screenshot(AbstractObject): return obj def get_meta(self, options=set()): - meta = {'id': self.id} + meta = self.get_default_meta() meta['img'] = get_screenshot_rel_path(self.id) ######### # TODO: Rename ME ?????? meta['tags'] = self.get_tags(r_list=True) if 'tags_safe' in options: diff --git a/bin/lib/objects/abstract_daterange_object.py b/bin/lib/objects/abstract_daterange_object.py index b96c5ec4..5ec103d0 100755 --- a/bin/lib/objects/abstract_daterange_object.py +++ b/bin/lib/objects/abstract_daterange_object.py @@ -82,9 +82,10 @@ class AbstractDaterangeObject(AbstractObject, ABC): return int(nb) def _get_meta(self, options=[]): - meta_dict = {'first_seen': self.get_first_seen(), - 'last_seen': self.get_last_seen(), - 'nb_seen': self.get_nb_seen()} + meta_dict = self.get_default_meta() + meta_dict['first_seen'] = self.get_first_seen() + meta_dict['last_seen'] = self.get_last_seen() + meta_dict['nb_seen'] = self.get_nb_seen() if 'sparkline' in options: meta_dict['sparkline'] = self.get_sparkline() return meta_dict diff --git a/bin/lib/objects/abstract_object.py b/bin/lib/objects/abstract_object.py index cb7595ad..2423a294 100755 --- a/bin/lib/objects/abstract_object.py +++ b/bin/lib/objects/abstract_object.py @@ -62,7 +62,7 @@ class AbstractObject(ABC): def get_default_meta(self, tags=False): dict_meta = {'id': self.get_id(), 'type': self.get_type(), - 'subtype': self.get_subtype()} + 'subtype': self.get_subtype(r_str=True)} if tags: dict_meta['tags'] = self.get_tags() return dict_meta diff --git a/var/www/blueprints/investigations_b.py b/var/www/blueprints/investigations_b.py index 8c1d592b..cf3cf688 100644 --- a/var/www/blueprints/investigations_b.py +++ b/var/www/blueprints/investigations_b.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 # -*-coding:UTF-8 -* -''' +""" Blueprint Flask: ail_investigations -''' +""" import os import sys @@ -54,7 +54,13 @@ def show_investigation(): investigation_uuid = request.args.get("uuid") investigation = Investigations.Investigation(investigation_uuid) metadata = investigation.get_metadata(r_str=True) - objs = ail_objects.get_objects_meta(investigation.get_objects(), flask_context=True) + objs = [] + for obj in investigation.get_objects(): + obj_meta = ail_objects.get_object_meta(obj["type"], obj["subtype"], obj["id"], flask_context=True) + comment = investigation.get_objects_comment(f'{obj["type"]}:{obj["subtype"]}:{obj["id"]}') + if comment: + obj_meta['comment'] = comment + objs.append(obj_meta) return render_template("view_investigation.html", bootstrap_label=bootstrap_label, metadata=metadata, investigation_objs=objs) @@ -169,10 +175,13 @@ def register_investigation(): object_type = request.args.get('type') object_subtype = request.args.get('subtype') object_id = request.args.get('id') + comment = request.args.get('comment') for investigation_uuid in investigations_uuid: input_dict = {"uuid": investigation_uuid, "id": object_id, "type": object_type, "subtype": object_subtype} + if comment: + input_dict["comment"] = comment res = Investigations.api_register_object(input_dict) if res[1] != 200: return create_json_response(res[0], res[1]) diff --git a/var/www/templates/investigations/view_investigation.html b/var/www/templates/investigations/view_investigation.html index 4cfcd06e..3848b736 100644 --- a/var/www/templates/investigations/view_investigation.html +++ b/var/www/templates/investigations/view_investigation.html @@ -12,8 +12,8 @@ - - + + @@ -125,11 +125,12 @@ - - - + + + - + + @@ -156,6 +157,11 @@ {{ tag }} {% endfor %} +
TypeIdTypeId TagsComment
+ {% if 'comment' in object %} + {{ object['comment']}} + {% endif %} + diff --git a/var/www/templates/modals/investigations_register_obj.html b/var/www/templates/modals/investigations_register_obj.html index edac2853..50a6ca02 100644 --- a/var/www/templates/modals/investigations_register_obj.html +++ b/var/www/templates/modals/investigations_register_obj.html @@ -14,7 +14,10 @@
- +
+ + +
@@ -55,8 +58,13 @@ $('#investigations_register_obj_modal').on('shown.bs.modal', function () { }); function Register_Obj() { - var uuids = linvestigations.getValue(); - // TODO: REQUEST - window.location.replace("{{ url_for('investigations_b.register_investigation') }}?uuids=" + uuids + "&type={{ obj_type }}&subtype={{ obj_subtype }}&id={{ obj_id }}"); + var uuids = linvestigations.getValue(); + var comment = $('#inv_obj_comment').val(); + // TODO: REQUEST + var url = "{{ url_for('investigations_b.register_investigation') }}?uuids=" + uuids + "&type={{ obj_type }}&subtype={{ obj_subtype }}&id={{ obj_id }}" + if (comment) { + url += "&comment=" + comment; + } + window.location.replace(url); }