From ee563a79d34bed67e560236e3c94ee0c79443a8b Mon Sep 17 00:00:00 2001 From: terrtia Date: Wed, 27 Mar 2024 11:03:27 +0100 Subject: [PATCH] chg: [trackers] UI: remove object from tracker --- bin/lib/Tracker.py | 16 +++++++- var/www/blueprints/hunters.py | 16 ++++++++ var/www/templates/hunter/tracker_show.html | 7 ++++ .../modals/tracker_remove_object.html | 39 +++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 var/www/templates/modals/tracker_remove_object.html diff --git a/bin/lib/Tracker.py b/bin/lib/Tracker.py index f2f536d3..227213db 100755 --- a/bin/lib/Tracker.py +++ b/bin/lib/Tracker.py @@ -385,7 +385,7 @@ def remove(self, obj_type, subtype, obj_id): r_tracker.srem(f'obj:tracker:{obj_type}:{subtype}:{obj_id}:{self.uuid}', date) r_tracker.srem(f'obj:trackers:{obj_type}:{subtype}:{obj_id}', self.uuid) - r_tracker.srem(f'tracker:objs:{self.uuid}', f'{obj_type}:{subtype}:{obj_id}') + r_tracker.srem(f'tracker:objs:{self.uuid}:{obj_type}', f'{subtype}:{obj_id}') self.update_daterange() # TODO escape custom tags @@ -1055,6 +1055,20 @@ def api_delete_tracker(data, user_id): tracker = Tracker(tracker_uuid) return tracker.delete(), 200 +def api_tracker_remove_object(data, user_id): + tracker_uuid = data.get('uuid') + res = api_check_tracker_acl(tracker_uuid, user_id) + if res: + return res + + tracker = Tracker(tracker_uuid) + object_gid = data.get('gid') + try: + obj_type, subtype, obj_id = object_gid.split(':', 2) + except (AttributeError, IndexError): + return {"status": "error", "reason": "Invalid Object"}, 400 + return tracker.remove(obj_type, subtype, obj_id), 200 + ## -- CREATE TRACKER -- ## #################### diff --git a/var/www/blueprints/hunters.py b/var/www/blueprints/hunters.py index 42bbf4bb..ac4d9a7b 100644 --- a/var/www/blueprints/hunters.py +++ b/var/www/blueprints/hunters.py @@ -372,6 +372,22 @@ def get_json_tracker_graph(): res = Tracker.get_trackers_graph_by_day([tracker_uuid]) return jsonify(res) +@hunters.route('/tracker/object/remove', methods=['GET']) +@login_required +@login_analyst +def tracker_object_remove(): + user_id = current_user.get_id() + tracker_uuid = request.args.get('uuid') + object_global_id = request.args.get('gid') + res = Tracker.api_tracker_remove_object({'uuid': tracker_uuid, 'gid': object_global_id}, user_id) + if res[1] != 200: + return create_json_response(res[0], res[1]) + else: + if request.referrer: + return redirect(request.referrer) + else: + return redirect(url_for('hunters.show_tracker', uuid=tracker_uuid)) + #################### # RETRO HUNT # diff --git a/var/www/templates/hunter/tracker_show.html b/var/www/templates/hunter/tracker_show.html index a6d2315d..df51a809 100644 --- a/var/www/templates/hunter/tracker_show.html +++ b/var/www/templates/hunter/tracker_show.html @@ -44,6 +44,8 @@ {% include 'nav_bar.html' %} +{% include 'modals/tracker_remove_object.html' %} +
{% include 'hunter/menu_sidebar.html' %} @@ -295,6 +297,11 @@
Yara Rule:
{% endif %} + + {# #} {# #} {# #} diff --git a/var/www/templates/modals/tracker_remove_object.html b/var/www/templates/modals/tracker_remove_object.html new file mode 100644 index 00000000..3a7f1d3d --- /dev/null +++ b/var/www/templates/modals/tracker_remove_object.html @@ -0,0 +1,39 @@ + + +