mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-22 22:27:17 +00:00
chg: [investigation] add object comment
This commit is contained in:
parent
a0686eefcf
commit
b4d536f174
8 changed files with 62 additions and 26 deletions
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
<!-- JS -->
|
||||
<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/jquery.dataTables.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>
|
||||
|
||||
</head>
|
||||
|
@ -125,11 +125,12 @@
|
|||
<table id="table_sync_queues" class="table table-striped border-primary">
|
||||
<thead class="bg-dark text-white">
|
||||
<tr>
|
||||
<th>Type</th>
|
||||
<th></th>
|
||||
<th>Id</th>
|
||||
<th>Type</th>
|
||||
<th></th>
|
||||
<th>Id</th>
|
||||
<th>Tags</th>
|
||||
<th></th>
|
||||
<th>Comment</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody style="font-size: 15px;">
|
||||
|
@ -156,6 +157,11 @@
|
|||
<span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }} pull-left">{{ tag }}</span>
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td>
|
||||
{% if 'comment' in object %}
|
||||
{{ object['comment']}}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<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>
|
||||
|
|
|
@ -14,7 +14,10 @@
|
|||
<div class="input-group" >
|
||||
<input id="linvestigations" type="text" class="form-control" autocomplete="off" style="width: 760px">
|
||||
</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>
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue