From 0b73052ebc34d194d59f31caa9823635936a70fb Mon Sep 17 00:00:00 2001 From: David Cruciani Date: Thu, 8 Feb 2024 15:31:06 +0100 Subject: [PATCH] chg: [website] fusion between expansion and hover --- webiste/app/home.py | 21 +---- webiste/app/home_core.py | 48 ++++++----- webiste/app/session.py | 13 --- webiste/app/templates/home.html | 141 +++++++++---------------------- webiste/app/templates/query.html | 13 +-- 5 files changed, 78 insertions(+), 158 deletions(-) diff --git a/webiste/app/home.py b/webiste/app/home.py index 9a39535..5dba99e 100644 --- a/webiste/app/home.py +++ b/webiste/app/home.py @@ -37,14 +37,7 @@ def query(sid): @home_blueprint.route("/get_modules") def get_modules(): """Return all modules available""" - expansion = "" - hover = "" - - if "expansion" in request.args: - expansion = request.args.get("expansion") - if "hover" in request.args: - hover = request.args.get("hover") - res = HomeModel.get_modules(expansion, hover) + res = HomeModel.get_modules() if "message" in res: return res, 404 @@ -53,15 +46,7 @@ def get_modules(): @home_blueprint.route("/get_list_misp_attributes") def get_list_misp_attributes(): """Return all misp attributes for input and output""" - expansion = "" - hover = "" - - if "expansion" in request.args: - expansion = request.args.get("expansion") - if "hover" in request.args: - hover = request.args.get("hover") - - res = HomeModel.get_list_misp_attributes(expansion, hover) + res = HomeModel.get_list_misp_attributes() if "message" in res: return res, 404 @@ -72,7 +57,7 @@ def run_modules(): """Run modules""" if "query" in request.json: if "input" in request.json: - if "expansion" in request.json or "hover" in request.json: + if "modules" in request.json: session = SessionModel.Session_class(request.json) session.start() SessionModel.sessions.append(session) diff --git a/webiste/app/home_core.py b/webiste/app/home_core.py index edd996f..73ff5b9 100644 --- a/webiste/app/home_core.py +++ b/webiste/app/home_core.py @@ -5,75 +5,76 @@ from .db_class.db import History, Module, Config, Module_Config, Session_db def get_module(mid): + """Return a module by id""" return Module.query.get(mid) def get_module_by_name(name): + """Return a module by name""" return Module.query.filter_by(name=name).first() def get_config(cid): + """Return a config by id""" return Config.query.get(cid) def get_config_by_name(name): + """Return a config by name""" return Config.query.filter_by(name=name).first() def get_module_config_module(mid): + """Return a moudle_config by module id""" return Module_Config.query.filter_by(module_id=mid).all() def get_module_config_both(mid, cid): + """Return a moudle_config by module id and config id""" return Module_Config.query.filter_by(module_id=mid, config_id=cid).first() def get_session(sid): + """Return a session by id""" return Session_db.query.filter_by(uuid=sid).first() -def get_modules(expansion, hover): +def get_modules(): + """Return all modules for expansion and hover types""" res = query_get_module() if not "message" in res: - loc_list = dict() - loc_list["expansion"] = list() - loc_list["hover"] = list() + loc_list = list() for module in res: module_db = get_module_by_name(module["name"]) module_loc = module module_loc["request_on_query"] = module_db.request_on_query if module_db.is_active: - if expansion: - if "expansion" in module["meta"]["module-type"]: - loc_list["expansion"].append(module_loc) - if hover: - if "hover" in module["meta"]["module-type"]: - loc_list["hover"].append(module_loc) - loc_list["expansion"].sort(key=lambda x: x["name"]) - loc_list["hover"].sort(key=lambda x: x["name"]) + if "expansion" in module["meta"]["module-type"] or "hover" in module["meta"]["module-type"]: + if not module_loc in loc_list: + loc_list.append(module_loc) + loc_list.sort(key=lambda x: x["name"]) return loc_list return res def util_get_attr(module, loc_list): + """Additional algo for get_list_misp_attributes""" if "input" in module["mispattributes"]: for input in module["mispattributes"]["input"]: if not input in loc_list: loc_list.append(input) return loc_list -def get_list_misp_attributes(expansion, hover): +def get_list_misp_attributes(): + """Return all types of attributes used in expansion and hover""" res = query_get_module() if not "message" in res: loc_list = list() for module in res: if get_module_by_name(module["name"]).is_active: - if expansion: - if "expansion" in module["meta"]["module-type"]: - loc_list = util_get_attr(module, loc_list) - if hover: - if "hover" in module["meta"]["module-type"]: - loc_list = util_get_attr(module, loc_list) + if "expansion" in module["meta"]["module-type"] or "hover" in module["meta"]["module-type"]: + loc_list = util_get_attr(module, loc_list) loc_list.sort() return loc_list return res def get_modules_config(): + """Return configs for all modules """ modules = Module.query.order_by(Module.name).all() modules_list = [] for module in modules: @@ -88,6 +89,7 @@ def get_modules_config(): def change_config_core(request_json): + """Change config for a module""" module = get_module_by_name(request_json["module_name"]) for element in request_json: if not element == "module_name": @@ -101,6 +103,7 @@ def change_config_core(request_json): return True def change_status_core(module_id): + """Active or deactive a module""" module = get_module(module_id) module.is_active = not module.is_active db.session.commit() @@ -108,8 +111,13 @@ def change_status_core(module_id): +############## +# Session DB # +############## + def get_status_db(session): glob_query = json.loads(session.glob_query) + """Return status of a session""" result = json.loads(session.result) return{ 'id': session.uuid, @@ -122,9 +130,11 @@ def get_status_db(session): } def get_result_db(session): + """Return result of a session""" return json.loads(session.result) def get_history(): + """Return history""" histories_list = list() histories = History.query.all() for history in histories: diff --git a/webiste/app/session.py b/webiste/app/session.py index 0153a66..a8ec324 100644 --- a/webiste/app/session.py +++ b/webiste/app/session.py @@ -7,7 +7,6 @@ from . import home_core as HomeModel import uuid from . import db from .db_class.db import History, Session_db -from sqlalchemy import func sessions = list() @@ -21,23 +20,11 @@ class Session_class: self.stopped = False self.result_stopped = dict() self.result = dict() - self.expansion = self.expansion_setter(request_json) - self.hover = self.hover_setter(request_json) self.query = request_json["query"] self.input_query = request_json["input"] self.glob_query = self.expansion + self.hover self.nb_errors = 0 self.config_module = self.config_module_setter(request_json) - - def expansion_setter(self, request_json): - if "expansion" in request_json: - return request_json["expansion"] - return [] - - def hover_setter(self, request_json): - if "hover" in request_json: - return request_json["hover"] - return [] def config_module_setter(self, request_json): if request_json["config"]: diff --git a/webiste/app/templates/home.html b/webiste/app/templates/home.html index b178ab7..02f3e49 100644 --- a/webiste/app/templates/home.html +++ b/webiste/app/templates/home.html @@ -20,75 +20,38 @@ [[status_site]] - -
-

Modules Type

- - - - - -
- - - - - -
-
- +
-
-
-
-
-

Input Attributes

-
-
- -
-
+
+
+

Input Attributes

+
+
+
-