misp-modules/website/app/history/history.py

90 lines
2.8 KiB
Python
Raw Normal View History

2024-02-15 15:33:41 +01:00
import json
2024-02-29 10:15:16 +01:00
from flask import Flask, Blueprint, render_template, request, jsonify, session as sess
2024-02-15 15:33:41 +01:00
from . import history_core as HistoryModel
2024-02-29 10:15:16 +01:00
from ..utils.utils import admin_user_active
2024-02-15 15:33:41 +01:00
history_blueprint = Blueprint(
'history',
__name__,
template_folder='templates',
static_folder='static'
)
@history_blueprint.route("/history", methods=["GET"])
def history():
"""View all history"""
2024-02-29 10:15:16 +01:00
sess["admin_user"] = admin_user_active()
2024-02-15 15:33:41 +01:00
return render_template("history.html")
@history_blueprint.route("/get_history", methods=["GET"])
def get_history():
"""Get all history"""
2024-02-19 10:27:48 +01:00
page = request.args.get('page', 1, type=int)
histories, nb_pages = HistoryModel.get_history(page)
return {"history": histories, "nb_pages": nb_pages}
2024-02-15 15:33:41 +01:00
@history_blueprint.route("/history_session", methods=["GET"])
def history_session():
"""View all history"""
2024-02-29 10:15:16 +01:00
sess["admin_user"] = admin_user_active()
2024-02-15 15:33:41 +01:00
return render_template("history_session.html", tree_view=False)
@history_blueprint.route("/get_history_session", methods=["GET"])
def get_history_session():
"""Get all history"""
histories = HistoryModel.get_history_session()
if histories:
return histories
return {}
@history_blueprint.route("/get_current_query_history", methods=["GET"])
def get_current_query_history():
"""Get current query history"""
return HistoryModel.get_current_query_history()
2024-02-15 15:33:41 +01:00
@history_blueprint.route("/save_history/<sid>", methods=["GET"])
def save_history(sid):
return HistoryModel.save_history_core(sid)
@history_blueprint.route("/history_tree", methods=["GET"])
def history_tree():
"""View all history"""
2024-02-29 10:15:16 +01:00
sess["admin_user"] = admin_user_active()
2024-02-15 15:33:41 +01:00
return render_template("history_session.html", tree_view=True)
@history_blueprint.route("/get_history_tree", methods=["GET"])
def get_history_tree():
"""Get all history"""
histories = HistoryModel.get_history_tree()
if histories:
return histories
return {}
@history_blueprint.route("/get_history_tree/<sid>", methods=["GET"])
def get_history_tree_uuid(sid):
"""Get all history"""
histories = HistoryModel.get_history_tree_uuid(sid)
if histories:
return histories
return {}
@history_blueprint.route("/get_history_session/<sid>", methods=["GET"])
def get_history_session_uuid(sid):
"""Get all history"""
histories = HistoryModel.get_history_session_uuid(sid)
if histories:
return histories
return {}
@history_blueprint.route("/history/remove_node_session/<sid>", methods=["GET"])
def remove_node_session(sid):
HistoryModel.remove_node_session(sid)
return {"message": "Node deleted", "toast_class": "success-subtle"}
@history_blueprint.route("/history/remove_node_tree/<sid>", methods=["GET"])
def remove_node_tree(sid):
HistoryModel.remove_node_tree(sid)
return {"message": "Node deleted", "toast_class": "success-subtle"}