chg: [investigation] add object comment

pull/604/head
Terrtia 2023-06-26 16:28:31 +02:00
parent a0686eefcf
commit b4d536f174
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
8 changed files with 62 additions and 26 deletions

View File

@ -235,18 +235,27 @@ class Investigation(object):
objs.append(dict_obj) objs.append(dict_obj)
return objs 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 # # 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'investigations:objs:{self.uuid}', f'{obj_type}:{subtype}:{obj_id}')
r_tracking.sadd(f'obj:investigations:{obj_type}:{subtype}:{obj_id}', self.uuid) 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()) timestamp = int(time.time())
self.set_last_change(timestamp) self.set_last_change(timestamp)
def unregister_object(self, obj_id, obj_type, subtype): 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'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.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()) timestamp = int(time.time())
self.set_last_change(timestamp) self.set_last_change(timestamp)
@ -351,7 +360,7 @@ def get_investigations_selector():
for investigation_uuid in get_all_investigations(): for investigation_uuid in get_all_investigations():
investigation = Investigation(investigation_uuid) investigation = Investigation(investigation_uuid)
name = investigation.get_info() name = investigation.get_info()
l_investigations.append({"id":investigation_uuid, "name": name}) l_investigations.append({"id": investigation_uuid, "name": name})
return l_investigations return l_investigations
#{id:'8dc4b81aeff94a9799bd70ba556fa345',name:"Paris"} #{id:'8dc4b81aeff94a9799bd70ba556fa345',name:"Paris"}
@ -453,7 +462,11 @@ def api_register_object(json_dict):
if subtype == 'None': if subtype == 'None':
subtype = '' subtype = ''
obj_id = json_dict.get('id', '').replace(' ', '') 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 return res, 200
def api_unregister_object(json_dict): def api_unregister_object(json_dict):

View File

@ -264,10 +264,9 @@ class Item(AbstractObject):
""" """
if options is None: if options is None:
options = set() options = set()
meta = {'id': self.id, meta = self.get_default_meta(tags=True)
'date': self.get_date(separator=True), meta['date'] = self.get_date(separator=True)
'source': self.get_source(), meta['source'] = self.get_source()
'tags': self.get_tags(r_list=True)}
# optional meta fields # optional meta fields
if 'content' in options: if 'content' in options:
meta['content'] = self.get_content() meta['content'] = self.get_content()

View File

@ -88,7 +88,7 @@ class Screenshot(AbstractObject):
return obj return obj
def get_meta(self, options=set()): 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['img'] = get_screenshot_rel_path(self.id) ######### # TODO: Rename ME ??????
meta['tags'] = self.get_tags(r_list=True) meta['tags'] = self.get_tags(r_list=True)
if 'tags_safe' in options: if 'tags_safe' in options:

View File

@ -82,9 +82,10 @@ class AbstractDaterangeObject(AbstractObject, ABC):
return int(nb) return int(nb)
def _get_meta(self, options=[]): def _get_meta(self, options=[]):
meta_dict = {'first_seen': self.get_first_seen(), meta_dict = self.get_default_meta()
'last_seen': self.get_last_seen(), meta_dict['first_seen'] = self.get_first_seen()
'nb_seen': self.get_nb_seen()} meta_dict['last_seen'] = self.get_last_seen()
meta_dict['nb_seen'] = self.get_nb_seen()
if 'sparkline' in options: if 'sparkline' in options:
meta_dict['sparkline'] = self.get_sparkline() meta_dict['sparkline'] = self.get_sparkline()
return meta_dict return meta_dict

View File

@ -62,7 +62,7 @@ class AbstractObject(ABC):
def get_default_meta(self, tags=False): def get_default_meta(self, tags=False):
dict_meta = {'id': self.get_id(), dict_meta = {'id': self.get_id(),
'type': self.get_type(), 'type': self.get_type(),
'subtype': self.get_subtype()} 'subtype': self.get_subtype(r_str=True)}
if tags: if tags:
dict_meta['tags'] = self.get_tags() dict_meta['tags'] = self.get_tags()
return dict_meta return dict_meta

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*-coding:UTF-8 -* # -*-coding:UTF-8 -*
''' """
Blueprint Flask: ail_investigations Blueprint Flask: ail_investigations
''' """
import os import os
import sys import sys
@ -54,7 +54,13 @@ def show_investigation():
investigation_uuid = request.args.get("uuid") investigation_uuid = request.args.get("uuid")
investigation = Investigations.Investigation(investigation_uuid) investigation = Investigations.Investigation(investigation_uuid)
metadata = investigation.get_metadata(r_str=True) 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, return render_template("view_investigation.html", bootstrap_label=bootstrap_label,
metadata=metadata, investigation_objs=objs) metadata=metadata, investigation_objs=objs)
@ -169,10 +175,13 @@ def register_investigation():
object_type = request.args.get('type') object_type = request.args.get('type')
object_subtype = request.args.get('subtype') object_subtype = request.args.get('subtype')
object_id = request.args.get('id') object_id = request.args.get('id')
comment = request.args.get('comment')
for investigation_uuid in investigations_uuid: for investigation_uuid in investigations_uuid:
input_dict = {"uuid": investigation_uuid, "id": object_id, input_dict = {"uuid": investigation_uuid, "id": object_id,
"type": object_type, "subtype": object_subtype} "type": object_type, "subtype": object_subtype}
if comment:
input_dict["comment"] = comment
res = Investigations.api_register_object(input_dict) res = Investigations.api_register_object(input_dict)
if res[1] != 200: if res[1] != 200:
return create_json_response(res[0], res[1]) return create_json_response(res[0], res[1])

View File

@ -12,8 +12,8 @@
<!-- JS --> <!-- JS -->
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script> <script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<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>
</head> </head>
@ -125,11 +125,12 @@
<table id="table_sync_queues" class="table table-striped border-primary"> <table id="table_sync_queues" class="table table-striped border-primary">
<thead class="bg-dark text-white"> <thead class="bg-dark text-white">
<tr> <tr>
<th>Type</th> <th>Type</th>
<th></th> <th></th>
<th>Id</th> <th>Id</th>
<th>Tags</th> <th>Tags</th>
<th></th> <th>Comment</th>
<th></th>
</tr> </tr>
</thead> </thead>
<tbody style="font-size: 15px;"> <tbody style="font-size: 15px;">
@ -156,6 +157,11 @@
<span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }} pull-left">{{ tag }}</span> <span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }} pull-left">{{ tag }}</span>
{% endfor %} {% endfor %}
</td> </td>
<td>
{% if 'comment' in object %}
{{ object['comment']}}
{% endif %}
</td>
<td class="text-right"> <td class="text-right">
<a href="{{ url_for('investigations_b.unregister_investigation') }}?uuid={{ metadata['uuid']}}&type={{ object['type'] }}&subtype={{ object['subtype']}}&id={{ object['id']}}"> <a href="{{ url_for('investigations_b.unregister_investigation') }}?uuid={{ metadata['uuid']}}&type={{ object['type'] }}&subtype={{ object['subtype']}}&id={{ object['id']}}">
<button type="button" class="btn btn-danger"><i class="fas fa-trash-alt"></i></button> <button type="button" class="btn btn-danger"><i class="fas fa-trash-alt"></i></button>

View File

@ -14,7 +14,10 @@
<div class="input-group" > <div class="input-group" >
<input id="linvestigations" type="text" class="form-control" autocomplete="off" style="width: 760px"> <input id="linvestigations" type="text" class="form-control" autocomplete="off" style="width: 760px">
</div> </div>
<div class="form- mt-2">
<label for="inv_obj_comment">Object Comment <i>(optional)</i>:</label>
<textarea class="form-control" id="inv_obj_comment" name="inv_obj_comment" rows="2"></textarea>
</div>
</div> </div>
@ -55,8 +58,13 @@ $('#investigations_register_obj_modal').on('shown.bs.modal', function () {
}); });
function Register_Obj() { function Register_Obj() {
var uuids = linvestigations.getValue(); var uuids = linvestigations.getValue();
// TODO: REQUEST var comment = $('#inv_obj_comment').val();
window.location.replace("{{ url_for('investigations_b.register_investigation') }}?uuids=" + uuids + "&type={{ obj_type }}&subtype={{ obj_subtype }}&id={{ obj_id }}"); // 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);
} }
</script> </script>