Skip to content

Commit

Permalink
chg: [website] fusion between expansion and hover
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidCruciani committed Feb 8, 2024
1 parent 30f84f6 commit 0b73052
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 158 deletions.
21 changes: 3 additions & 18 deletions webiste/app/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
48 changes: 29 additions & 19 deletions webiste/app/home_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,75 +5,76 @@


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:
Expand All @@ -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":
Expand All @@ -101,15 +103,21 @@ 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()
return True



##############
# 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,
Expand All @@ -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:
Expand Down
13 changes: 0 additions & 13 deletions webiste/app/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import uuid
from . import db
from .db_class.db import History, Session_db
from sqlalchemy import func


sessions = list()
Expand All @@ -21,23 +20,11 @@ def __init__(self, request_json) -> None:
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"]:
Expand Down
Loading

0 comments on commit 0b73052

Please sign in to comment.