diff --git a/bin/lib/chats_viewer.py b/bin/lib/chats_viewer.py index 3584a04f..a358c0a6 100755 --- a/bin/lib/chats_viewer.py +++ b/bin/lib/chats_viewer.py @@ -17,6 +17,7 @@ sys.path.append(os.environ['AIL_BIN']) ################################## # Import Project packages ################################## +from lib.ail_core import generate_uuid from lib.ConfigLoader import ConfigLoader from lib.objects import Chats from lib.objects import ChatSubChannels @@ -592,6 +593,64 @@ def get_message_report(l_mess): # TODO Force language + translation return chats, messages +# # # # # # # # # # # # # # +# # +# ChatMonitoringRequest # +# # +# # # # # # # # # # # # # # + +def get_chats_monitoring_requests(): + return r_obj.smembers(f'chats:requests') + +def get_chats_monitoring_requests_metas(): + requests = [] + for r in get_chats_monitoring_requests(): + cr = ChatsMonitoringRequest(r) + requests.append(cr.get_meta()) + return requests + +class ChatsMonitoringRequest: + def __init__(self, r_uuid): + self.uuid = r_uuid + + def _get_field(self, name): + return r_obj.hget(f'chats:request:{self.uuid}', name) + + def _set_field(self, name, value): + r_obj.hset(f'chats:request:{self.uuid}', name, value) + + def exists(self): + r_obj.exists(f'chats:request:{self.uuid}') + + def get_meta(self): + return {'uuid': self.uuid, + 'date': self._get_field('date'), + 'creator': self._get_field('creator'), + 'chat_type': self._get_field('chat_type'), + 'invite': self._get_field('invite'), + 'username': self._get_field('username'), + 'description': self._get_field('description'), + } + + def create(self, creator, chat_type, invite, username, description): + self._set_field('chat_type', chat_type) + self._set_field('creator', creator) + self._set_field('date', datetime.now().strftime('%Y-%m-%d %H:%M:%S')) + if invite: + self._set_field('invite', invite) + if username: + self._set_field('username', username) + if description: + self._set_field('description', description) + r_obj.sadd(f'chats:requests', self.uuid) + +def create_chat_monitoring_requests(creator, chat_type, invite, username, description): + r_uuid = generate_uuid() + chat_request = ChatsMonitoringRequest(r_uuid) + chat_request.create(creator, chat_type, invite, username, description) + return r_uuid + + #### FIX #### def fix_correlations_subchannel_message(): diff --git a/var/www/blueprints/chats_explorer.py b/var/www/blueprints/chats_explorer.py index b50a9e59..56f21b4f 100644 --- a/var/www/blueprints/chats_explorer.py +++ b/var/www/blueprints/chats_explorer.py @@ -221,6 +221,35 @@ def objects_thread_messages_download(): #### #### +@chats_explorer.route("/chats/explorer/chat/monitoring/request", methods=['GET', 'POST']) +@login_required +@login_user_no_api +def chat_monitoring_request(): + if request.method == 'POST': + user_id = current_user.get_user_id() + chat_type = request.form.get('type') + username = request.form.get('username') + invite = request.form.get('invite') + description = request.form.get('description') + if chat_type not in ['discord', 'telegram']: + return create_json_response({"status": "error", "reason": "Invalid Chat Type"}, 400) + if not username and not invite and not description: + return create_json_response({"status": "error", "reason": "Please provide a username/username/invite/comment"}, 400) + cm_uuid = chats_viewer.create_chat_monitoring_requests(user_id, chat_type, invite, username, description) + return render_template('request_chat_monitoring.html', uuid=cm_uuid) + else: + return render_template('request_chat_monitoring.html') + + +@chats_explorer.route("/chats/explorer/chat/monitoring/request/admin", methods=['GET']) +@login_required +@login_admin +def chat_monitoring_requests(): + metas = chats_viewer.get_chats_monitoring_requests_metas() + return render_template('chat_monitoring_requests.html', metas=metas) + +#### #### + @chats_explorer.route("/objects/message", methods=['GET']) @login_required diff --git a/var/www/static/image/tm.png b/var/www/static/image/tm.png new file mode 100644 index 00000000..1ee1d860 Binary files /dev/null and b/var/www/static/image/tm.png differ diff --git a/var/www/templates/chats_explorer/chat_monitoring_requests.html b/var/www/templates/chats_explorer/chat_monitoring_requests.html new file mode 100644 index 00000000..e79290a4 --- /dev/null +++ b/var/www/templates/chats_explorer/chat_monitoring_requests.html @@ -0,0 +1,85 @@ + + + + + AIL-Framework + + + + + + + + + + + + + + + + + + + {% include 'nav_bar.html' %} + +
+
+ + {% include 'sidebars/sidebar_objects.html' %} + +
+ +

Monitoring Requests:

+ + + + + + + + + + + + + + + {% for meta in metas %} + + + + + + + + + + {% endfor %} + +
UUIDDateCreatorTypeUsernameInviteDescription
+ {{ meta['uuid'] }} + {{ meta['date'] }}{{ meta['creator'] }}{{ meta['chat_type'] }}{{ meta['username'] }}{{ meta['invite'] }}{{ meta['description'] }}
+ + +
+ +
+
+ + + + diff --git a/var/www/templates/chats_explorer/chats_protocols.html b/var/www/templates/chats_explorer/chats_protocols.html index a2c25ded..6870a220 100644 --- a/var/www/templates/chats_explorer/chats_protocols.html +++ b/var/www/templates/chats_explorer/chats_protocols.html @@ -51,6 +51,25 @@

No Protocol/Chats Imported

{% endif %} +
+
+
+
+
+
+{# #} +
+ +
+

+ + Request Chat Monitoring +

+
+
+
+
+ diff --git a/var/www/templates/chats_explorer/request_chat_monitoring.html b/var/www/templates/chats_explorer/request_chat_monitoring.html new file mode 100644 index 00000000..8f271cfb --- /dev/null +++ b/var/www/templates/chats_explorer/request_chat_monitoring.html @@ -0,0 +1,106 @@ + + + + + AIL-Framework + + + + + + + + + + + + + + + + {% include 'nav_bar.html' %} + +
+
+ + {% include 'sidebars/sidebar_objects.html' %} + +
+ +
+
+

+ + Request Chat Monitoring +

+
+
+ + {% if uuid %} +

Chat Monitoring Request {{ uuid }} Created

+ {% endif %} + +
+ + + + +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ +
+ + +
+ +
+
+ + +
+ +
+
+ + + +