chg: [website] fusion between expansion and hover

pull/654/head
David Cruciani 2024-02-08 15:31:06 +01:00
parent 30f84f6512
commit 0b73052ebc
No known key found for this signature in database
GPG Key ID: 8690CDE1E3994B9B
5 changed files with 78 additions and 158 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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"]:

View File

@ -20,75 +20,38 @@
<span v-if="status_site" id="status">[[status_site]]</span>
</div>
<!-- Modules selection -->
<div class="card card-body" style="margin-top: 10px;">
<h4>Modules Type</h4>
<table>
<tr>
<td>
<input type="checkbox" id="expansion_module" @click="expansion_module()" value="expansion_module">
<label class="checkbox-type-module" for="expansion_module" title="Select all expansion modules">Expansion modules</label>
</td>
<td>
<input type="checkbox" id="hover_module" @click="hover_module()" value="hover_module">
<label class="checkbox-type-module" for="hover_module" title="Select all hover modules">Hover modules</label>
</td>
</tr>
</table>
</div>
<br>
<!-- Attributes selection -->
<div v-if="misp_attributes_list.length" class="card card-body" style="margin-top: 10px;">
<div class="row" style="margin-top: 2px;">
<div>
<div>
<h4>Input Attributes</h4>
</div>
<div>
<select data-placeholder="Input" class="select2-input form-control" name="input_select" id="input_select">
<option value="None">--</option>
<template v-for="attributes in misp_attributes_list">
<option :value="attributes">[[attributes]]</option>
</template>
</select>
</div>
</div>
<div v-if="misp_attributes_list.length" style="margin-top: 10px; transform: translate(25%, 0);">
<div>
<h4>Input Attributes</h4>
</div>
<div>
<select data-placeholder="Input" class="select2-input form-control" name="input_select" id="input_select">
<option value="None">--</option>
<template v-for="attributes in misp_attributes_list">
<option :value="attributes">[[attributes]]</option>
</template>
</select>
</div>
</div>
<!-- Results modules selection -->
<template v-if="modules_list">
<div v-if="Object.keys(modules_list).length">
<div class="row" v-if="attr_selected.length">
<div class="col-5" v-if="modules_list.expansion.length">
<div class="col-5">
<h4>Expansions Modules</h4>
</div>
<select data-placeholder="Expansion" class="select2-expansion form-control" multiple name="expansion_select" id="expansion_select">
<template v-for="key in modules_list.expansion">
<option v-if="key.mispattributes.input.includes(attr_selected)" :value="key.name" :title="key.meta.description">[[key.name]]</option>
</template>
</select>
</div>
<div class="col-5" v-if="modules_list.hover.length">
<div class="col-5">
<h4>Hover Modules</h4>
</div>
<select data-placeholder="Hover" class="select2-hover form-control" multiple name="hover_select" id="hover_select">
<template v-for="key in modules_list.hover">
<option v-if="key.mispattributes.input.includes(attr_selected)" :value="key.name" :title="key.meta.description">[[key.name]]</option>
</template>
</select>
</div>
</div>
<template v-if="modules_list.length">
<div v-if="attr_selected.length" style="margin-top: 10px; width: 50%; transform: translate(50%, 0);">
<h4>Modules</h4>
<select data-placeholder="Modules" class="select2-modules form-control" multiple name="modules_select" id="modules_select">
<template v-for="key in modules_list">
<option v-if="key.mispattributes.input.includes(attr_selected)" :value="key.name" :title="key.meta.description">[[key.name]]</option>
</template>
</select>
</div>
</template>
<!-- Display in case a module as reauest_on_query activate -->
<div v-if="config_query.length" style="margin-top: 10px;" class="row">
<div v-if="config_query.length" style="margin-top: 10px; padding: 5px" class="row">
<h4>Config</h4>
<div class="card col" style="margin-top: 10px;" v-for="module in config_query">
<div class="card col-4" style="margin-top: 10px; padding: 15px" v-for="module in config_query">
<h4>[[module.name]]</h4>
<div v-for="conf in module.meta.config" class="mb-3">
<label :for="'form-'+conf+'-'+module.name" class="form-label">[[conf]]</label>
@ -112,15 +75,12 @@
delimiters: ['[[', ']]'],
setup() {
const query = ref("Query")
const modules_list = ref({})
const modules_list = ref([])
const misp_attributes_list = ref({})
const attr_selected = ref([])
const progress = ref(0)
let expansion_bool = false
let hover_bool = false
const current_query = ref()
const status_site = ref()
@ -131,6 +91,7 @@
current_query.value = $("#process-query").val()
if (!current_query.value) {
status_site.value = '↖ You need to type something'
window.scrollTo(0, 0);
return
}else{
status_site.value = ""
@ -140,8 +101,7 @@
progress.value = 0
let error_flag = false
let result_dict = {"expansion": $("#expansion_select").val(),
"hover": $("#hover_select").val(),
let result_dict = {"modules": $("#modules_select").val(),
"input": $("#input_select").val(),
"query": current_query.value
}
@ -185,26 +145,17 @@
}
async function query_modules(){
let url = ""
if(expansion_bool) url += "expansion="+expansion_bool+"&"
if(hover_bool) url += "hover="+hover_bool
let res = await fetch("/get_modules?"+url)
let res = await fetch("/get_modules")
let loc = await res.json()
modules_list.value = loc
await query_misp_attributes()
}
query_modules()
async function query_misp_attributes(){
let url = ""
if(expansion_bool) url += "expansion="+expansion_bool+"&"
if(hover_bool) url += "hover="+hover_bool
let res = await fetch("/get_list_misp_attributes?"+url)
let res = await fetch("/get_list_misp_attributes")
let loc = await res.json()
misp_attributes_list.value = loc
@ -212,7 +163,8 @@
if (!$('.select2-input').hasClass("select2-hidden-accessible")) {
$('.select2-input').select2({
theme: 'bootstrap-5'
theme: 'bootstrap-5',
width: '50%'
})
}
if (!$('.select2-expansion').hasClass("select2-hidden-accessible")) {
@ -234,31 +186,25 @@
await nextTick()
if (!$('.select2-expansion').hasClass("select2-hidden-accessible")) {
$('.select2-expansion').select2({
if (!$('.select2-modules').hasClass("select2-hidden-accessible")) {
$('.select2-modules').select2({
theme: 'bootstrap-5'
})
$('#expansion_select').on('change.select2', async function (e) {
$('#modules_select').on('change.select2', async function (e) {
let loc_list = $(this).select2('data').map(item => item.id)
config_query.value = []
for(let el in loc_list){
for(let index in modules_list.value.expansion){
if(modules_list.value.expansion[index].name == loc_list[el]){
if(modules_list.value.expansion[index].request_on_query){
config_query.value.push(modules_list.value.expansion[index])
for(let index in modules_list.value){
if(modules_list.value[index].name == loc_list[el]){
if(modules_list.value[index].request_on_query){
config_query.value.push(modules_list.value[index])
}
break
}
}
}
})
}
if (!$('.select2-hover').hasClass("select2-hidden-accessible")) {
$('.select2-hover').select2({
theme: 'bootstrap-5'
})
}
}
})
$('#input_select').on('select2:open', function (e) {
@ -266,15 +212,6 @@
})
}
async function expansion_module(){
expansion_bool = !expansion_bool
await query_modules()
}
async function hover_module(){
hover_bool = !hover_bool
await query_modules()
}
function pairedList() {
let pairs = [];
for (let i = 0; i < this.items.length; i += 2) {
@ -298,8 +235,6 @@
status_site,
config_query,
actionQuery,
expansion_module,
hover_module,
pairedList,
checked_attr,
generateCoreFormatUI

View File

@ -121,12 +121,15 @@
if (data['remaining'] > 0) {
setTimeout(pollScan, 3000);
} else {
let sum = data['complete'] - data["nb_errors"]
// Button Stop pressed
if (data['stopped'])
status_site.value = 'Stopped ! ' + data['complete'] - data["nb_errors"] + ' Success. ' + data["nb_errors"] + ' Errors. ' + data['complete'] + ' Total.'
// Display result of the search
else
status_site.value = data['complete'] - data["nb_errors"] + ' Success. ' + data["nb_errors"] + ' Errors. ' + data['complete'] + ' Total.'
if (data['stopped']){
status_site.value = 'Stopped ! ' + sum + ' Success. ' + data["nb_errors"] + ' Errors. ' + data['complete'] + ' Total.'
console.log(data['complete'] - data["nb_errors"]);
// Display result of the search
}else{
status_site.value = sum + ' Success. ' + data["nb_errors"] + ' Errors. ' + data['complete'] + ' Total.'
}
}
if (last_registered < data['registered']) {
last_registered = data['registered']