2023-11-02 15:28:33 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
2023-11-08 14:46:05 +00:00
|
|
|
"""
|
2023-11-02 15:28:33 +00:00
|
|
|
Blueprint Flask: crawler splash endpoints: dashboard, onion crawler ...
|
2023-11-08 14:46:05 +00:00
|
|
|
"""
|
2023-11-02 15:28:33 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import json
|
|
|
|
|
2023-11-08 14:46:05 +00:00
|
|
|
from flask import Flask, render_template, jsonify, request, Blueprint, redirect, url_for, Response, abort
|
2023-11-02 15:28:33 +00:00
|
|
|
from flask_login import login_required, current_user
|
|
|
|
|
|
|
|
# Import Role_Manager
|
|
|
|
from Role_Manager import login_admin, login_analyst, login_read_only
|
|
|
|
|
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
|
|
|
from lib import ail_core
|
|
|
|
from lib import chats_viewer
|
2023-12-04 14:47:58 +00:00
|
|
|
from lib import Language
|
2023-11-08 14:46:05 +00:00
|
|
|
from lib import Tag
|
2023-11-02 15:28:33 +00:00
|
|
|
|
|
|
|
# ============ BLUEPRINT ============
|
|
|
|
chats_explorer = Blueprint('chats_explorer', __name__, template_folder=os.path.join(os.environ['AIL_FLASK'], 'templates/chats_explorer'))
|
|
|
|
|
|
|
|
# ============ VARIABLES ============
|
|
|
|
bootstrap_label = ['primary', 'success', 'danger', 'warning', 'info']
|
|
|
|
|
|
|
|
def create_json_response(data, status_code):
|
|
|
|
return Response(json.dumps(data, indent=2, sort_keys=True), mimetype='application/json'), status_code
|
|
|
|
|
|
|
|
# ============ FUNCTIONS ============
|
|
|
|
|
|
|
|
# ============= ROUTES ==============
|
|
|
|
|
|
|
|
@chats_explorer.route("/chats/explorer", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@login_read_only
|
|
|
|
def chats_explorer_dashboard():
|
|
|
|
return
|
|
|
|
|
|
|
|
@chats_explorer.route("chats/explorer/protocols", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@login_read_only
|
|
|
|
def chats_explorer_protocols():
|
|
|
|
protocols = chats_viewer.get_chat_protocols_meta()
|
|
|
|
return render_template('chats_protocols.html', protocols=protocols)
|
|
|
|
|
2023-11-06 15:38:31 +00:00
|
|
|
@chats_explorer.route("chats/explorer/networks", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@login_read_only
|
|
|
|
def chats_explorer_networks():
|
|
|
|
protocol = request.args.get('protocol')
|
|
|
|
networks = chats_viewer.get_chat_service_instances_by_protocol(protocol)
|
|
|
|
if len(networks) == 1:
|
|
|
|
instance_uuid = list(networks.values())[0]
|
|
|
|
return redirect(url_for('chats_explorer.chats_explorer_instance', uuid=instance_uuid))
|
|
|
|
else:
|
|
|
|
return render_template('chats_networks.html', protocol=protocol, networks=networks)
|
|
|
|
|
|
|
|
|
2023-11-02 15:28:33 +00:00
|
|
|
@chats_explorer.route("chats/explorer/instance", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@login_read_only
|
|
|
|
def chats_explorer_instance():
|
|
|
|
intance_uuid = request.args.get('uuid')
|
|
|
|
chat_instance = chats_viewer.api_get_chat_service_instance(intance_uuid)
|
|
|
|
if chat_instance[1] != 200:
|
|
|
|
return create_json_response(chat_instance[0], chat_instance[1])
|
|
|
|
else:
|
|
|
|
chat_instance = chat_instance[0]
|
|
|
|
return render_template('chat_instance.html', chat_instance=chat_instance)
|
|
|
|
|
|
|
|
@chats_explorer.route("chats/explorer/chat", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@login_read_only
|
|
|
|
def chats_explorer_chat():
|
|
|
|
chat_id = request.args.get('id')
|
|
|
|
instance_uuid = request.args.get('uuid')
|
2023-12-04 14:47:58 +00:00
|
|
|
target = request.args.get('target')
|
|
|
|
chat = chats_viewer.api_get_chat(chat_id, instance_uuid, translation_target=target)
|
2023-11-02 15:28:33 +00:00
|
|
|
if chat[1] != 200:
|
|
|
|
return create_json_response(chat[0], chat[1])
|
|
|
|
else:
|
|
|
|
chat = chat[0]
|
2023-12-04 14:47:58 +00:00
|
|
|
languages = Language.get_translation_languages()
|
|
|
|
return render_template('chat_viewer.html', chat=chat, bootstrap_label=bootstrap_label, translation_languages=languages, translation_target=target)
|
2023-11-02 15:28:33 +00:00
|
|
|
|
2023-11-13 13:10:24 +00:00
|
|
|
@chats_explorer.route("chats/explorer/messages/stats/week", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@login_read_only
|
|
|
|
def chats_explorer_messages_stats_week():
|
|
|
|
chat_id = request.args.get('id')
|
|
|
|
instance_uuid = request.args.get('uuid')
|
|
|
|
week = chats_viewer.api_get_nb_message_by_week(chat_id, instance_uuid)
|
|
|
|
if week[1] != 200:
|
|
|
|
return create_json_response(week[0], week[1])
|
|
|
|
else:
|
|
|
|
return jsonify(week[0])
|
|
|
|
|
2023-11-02 15:28:33 +00:00
|
|
|
@chats_explorer.route("/chats/explorer/subchannel", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@login_read_only
|
|
|
|
def objects_subchannel_messages():
|
|
|
|
subchannel_id = request.args.get('id')
|
|
|
|
instance_uuid = request.args.get('uuid')
|
2023-12-04 14:47:58 +00:00
|
|
|
target = request.args.get('target')
|
|
|
|
subchannel = chats_viewer.api_get_subchannel(subchannel_id, instance_uuid, translation_target=target)
|
2023-11-02 15:28:33 +00:00
|
|
|
if subchannel[1] != 200:
|
|
|
|
return create_json_response(subchannel[0], subchannel[1])
|
|
|
|
else:
|
|
|
|
subchannel = subchannel[0]
|
2023-12-04 14:47:58 +00:00
|
|
|
languages = Language.get_translation_languages()
|
|
|
|
return render_template('SubChannelMessages.html', subchannel=subchannel, bootstrap_label=bootstrap_label, translation_languages=languages, translation_target=target)
|
2023-11-02 15:28:33 +00:00
|
|
|
|
2023-11-29 15:28:25 +00:00
|
|
|
@chats_explorer.route("/chats/explorer/thread", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@login_read_only
|
|
|
|
def objects_thread_messages():
|
|
|
|
thread_id = request.args.get('id')
|
|
|
|
instance_uuid = request.args.get('uuid')
|
2023-12-04 14:47:58 +00:00
|
|
|
target = request.args.get('target')
|
|
|
|
thread = chats_viewer.api_get_thread(thread_id, instance_uuid, translation_target=target)
|
2023-11-29 15:28:25 +00:00
|
|
|
if thread[1] != 200:
|
|
|
|
return create_json_response(thread[0], thread[1])
|
|
|
|
else:
|
|
|
|
meta = thread[0]
|
2023-12-04 14:47:58 +00:00
|
|
|
languages = Language.get_translation_languages()
|
|
|
|
return render_template('ThreadMessages.html', meta=meta, bootstrap_label=bootstrap_label, translation_languages=languages, translation_target=target)
|
2023-11-02 15:28:33 +00:00
|
|
|
|
2023-11-08 09:31:51 +00:00
|
|
|
@chats_explorer.route("/objects/message", methods=['GET'])
|
2023-11-02 15:28:33 +00:00
|
|
|
@login_required
|
|
|
|
@login_read_only
|
2023-11-08 14:46:05 +00:00
|
|
|
def objects_message():
|
2023-11-08 09:31:51 +00:00
|
|
|
message_id = request.args.get('id')
|
|
|
|
message = chats_viewer.api_get_message(message_id)
|
|
|
|
if message[1] != 200:
|
|
|
|
return create_json_response(message[0], message[1])
|
2023-11-02 15:28:33 +00:00
|
|
|
else:
|
2023-11-08 09:31:51 +00:00
|
|
|
message = message[0]
|
2023-12-04 14:47:58 +00:00
|
|
|
languages = Language.get_translation_languages()
|
2023-11-08 14:46:05 +00:00
|
|
|
return render_template('ChatMessage.html', meta=message, bootstrap_label=bootstrap_label,
|
|
|
|
modal_add_tags=Tag.get_modal_add_tags(message['id'], object_type='message'))
|