From fa57171937398d20ff0ea7360082407dc0a5fadd Mon Sep 17 00:00:00 2001 From: terrtia Date: Fri, 22 Mar 2024 11:37:35 +0100 Subject: [PATCH] chg: [trackers match] show objects date --- bin/lib/objects/Items.py | 2 ++ bin/lib/objects/Messages.py | 6 ++++++ bin/lib/objects/abstract_daterange_object.py | 2 ++ bin/lib/objects/abstract_object.py | 3 +++ bin/lib/objects/abstract_subtype_object.py | 5 +++++ var/www/blueprints/hunters.py | 2 +- var/www/templates/hunter/tracker_show.html | 18 +++++++++++++----- 7 files changed, 32 insertions(+), 6 deletions(-) diff --git a/bin/lib/objects/Items.py b/bin/lib/objects/Items.py index 8204017d..a55fd631 100755 --- a/bin/lib/objects/Items.py +++ b/bin/lib/objects/Items.py @@ -305,6 +305,8 @@ class Item(AbstractObject): meta['investigations'] = self.get_investigations() if 'link' in options: meta['link'] = self.get_link(flask_context=True) + if 'last_full_date' in options: + meta['last_full_date'] = f"{meta['date'][0:4]}-{meta['date'][5:7]}-{meta['date'][8:10]}" # meta['encoding'] = None return meta diff --git a/bin/lib/objects/Messages.py b/bin/lib/objects/Messages.py index 09645cf3..aea92577 100755 --- a/bin/lib/objects/Messages.py +++ b/bin/lib/objects/Messages.py @@ -92,6 +92,10 @@ class Message(AbstractObject): timestamp = self.get_timestamp() return datetime.utcfromtimestamp(float(timestamp)).strftime('%Y%m%d') + def get_last_full_date(self): + timestamp = datetime.utcfromtimestamp(float(self.get_timestamp())) + return timestamp.strftime('%Y-%m-%d %H:%M:%S') + def get_timestamp(self): dirs = self.id.split('/') return dirs[1] @@ -255,6 +259,8 @@ class Message(AbstractObject): meta['date'] = timestamp.strftime('%Y/%m/%d') meta['hour'] = timestamp.strftime('%H:%M:%S') meta['full_date'] = timestamp.isoformat(' ') + if 'last_full_date' in options: + meta['last_full_date'] = meta['full_date'] meta['source'] = self.get_source() # optional meta fields diff --git a/bin/lib/objects/abstract_daterange_object.py b/bin/lib/objects/abstract_daterange_object.py index f6cb62e6..8c2b6b1f 100755 --- a/bin/lib/objects/abstract_daterange_object.py +++ b/bin/lib/objects/abstract_daterange_object.py @@ -88,6 +88,8 @@ class AbstractDaterangeObject(AbstractObject, ABC): meta_dict['nb_seen'] = self.get_nb_seen() if 'sparkline' in options: meta_dict['sparkline'] = self.get_sparkline() + if 'last_full_date'in options: + meta_dict['last_full_date'] = self.get_last_full_date() return meta_dict def set_first_seen(self, first_seen): diff --git a/bin/lib/objects/abstract_object.py b/bin/lib/objects/abstract_object.py index 551ad155..c6db93b7 100755 --- a/bin/lib/objects/abstract_object.py +++ b/bin/lib/objects/abstract_object.py @@ -67,6 +67,9 @@ class AbstractObject(ABC): def get_global_id(self): return f'{self.get_type()}:{self.get_subtype(r_str=True)}:{self.get_id()}' + def get_last_full_date(self): + return None + def get_default_meta(self, tags=False, link=False): dict_meta = {'id': self.get_id(), 'type': self.get_type(), diff --git a/bin/lib/objects/abstract_subtype_object.py b/bin/lib/objects/abstract_subtype_object.py index e02e71e9..71d9d267 100755 --- a/bin/lib/objects/abstract_subtype_object.py +++ b/bin/lib/objects/abstract_subtype_object.py @@ -85,6 +85,11 @@ class AbstractSubtypeObject(AbstractObject, ABC): else: return int(nb) + def get_last_full_date(self): + last_seen = self.get_last_seen() + if last_seen: + return f'{last_seen[0:4]}-{last_seen[4:6]}-{last_seen[6:8]}' + def _get_meta(self, options=None): if options is None: options = set() diff --git a/var/www/blueprints/hunters.py b/var/www/blueprints/hunters.py index 1002f6e0..42bbf4bb 100644 --- a/var/www/blueprints/hunters.py +++ b/var/www/blueprints/hunters.py @@ -174,7 +174,7 @@ def show_tracker(): if date_from: date_from, date_to = Date.sanitise_daterange(date_from, date_to) objs = tracker.get_objs_by_daterange(date_from, date_to) - meta['objs'] = ail_objects.get_objects_meta(objs, flask_context=True) + meta['objs'] = ail_objects.get_objects_meta(objs, options={'last_full_date'}, flask_context=True) else: date_from = '' date_to = '' diff --git a/var/www/templates/hunter/tracker_show.html b/var/www/templates/hunter/tracker_show.html index 62c387b6..a6d2315d 100644 --- a/var/www/templates/hunter/tracker_show.html +++ b/var/www/templates/hunter/tracker_show.html @@ -258,7 +258,7 @@ Type Id - Tags + Last Date @@ -280,11 +280,19 @@ {{ object['id']}} + {% if object['tags'] %} +
+ {% for tag in object['tags'] %} + {{ tag }} + {% endfor %} +
+ {% endif %} + - {% for tag in object['tags'] %} - {{ tag }} - {% endfor %} + {% if object['last_full_date'] %} + {{ object['last_full_date']}} + {% endif %} {# #} @@ -342,7 +350,7 @@ $('#myTable_').DataTable({ "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]], "iDisplayLength": 10, - "order": [[0, "asc"]] + "order": [[3, "desc"]] }); sparkline("sparkline", {{ meta['sparkline'] }}, {});