Skip to content

Commit

Permalink
fix: [website] config + query
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidCruciani committed Feb 9, 2024
1 parent 4d0672f commit 42996e8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 53 deletions.
24 changes: 12 additions & 12 deletions webiste/app/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ def __init__(self, request_json) -> None:
self.modules_list = request_json["modules"]
self.nb_errors = 0
self.config_module = self.config_module_setter(request_json)


def config_module_setter(self, request_json):
if request_json["config"]:
for query in self.modules_list:
if not query in request_json["config"]:
request_json["config"][query] = {}
module = HomeModel.get_module_by_name(query)
mcs = HomeModel.get_module_config_module(module.id)
for mc in mcs:
config_db = HomeModel.get_config(mc.config_id)
request_json["config"][query][config_db.name] = mc.value
return request_json["config"]
return {}
"""Setter for config for all modules used"""
for query in self.modules_list:
if not query in request_json["config"]:
request_json["config"][query] = {}
module = HomeModel.get_module_by_name(query)
mcs = HomeModel.get_module_config_module(module.id)
for mc in mcs:
config_db = HomeModel.get_config(mc.config_id)
request_json["config"][query][config_db.name] = mc.value
return request_json["config"]

def start(self):
"""Start all worker"""
Expand Down Expand Up @@ -103,7 +103,6 @@ def process(self):
if work[1] in self.config_module:
loc_config = self.config_module[work[1]]


if loc_query:
send_to = {"module": work[1], "attribute": loc_query, "config": loc_config}
else:
Expand All @@ -121,6 +120,7 @@ def get_result(self):
return self.result

def save_info(self):
"""Save info in the db"""
s = Session_db(
uuid=str(self.id),
modules_list=json.dumps(self.modules_list),
Expand Down
75 changes: 34 additions & 41 deletions webiste/app/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ <h4>[[module.name]]</h4>
createApp({
delimiters: ['[[', ']]'],
setup() {
const query = ref("Query")
const modules_list = ref([])
const misp_attributes_list = ref({})
const attr_selected = ref([])
Expand All @@ -97,48 +96,43 @@ <h4>[[module.name]]</h4>
status_site.value = ""
}

if (query.value == 'Query') {
progress.value = 0
let error_flag = false
progress.value = 0
let error_flag = false

let result_dict = {"modules": $("#modules_select").val(),
"input": $("#input_select").val(),
"query": current_query.value
}
result_dict["config"] = {}
for(let el in config_query.value){
result_dict["config"][config_query.value[el].name] = {}
for(let conf in config_query.value[el].meta.config){
$("#error-"+config_query.value[el].meta.config[conf]+"-"+config_query.value[el].name).text("")
let loc = $("#form-"+config_query.value[el].meta.config[conf]+"-"+config_query.value[el].name).val()
if(!loc){
error_flag = true
$("#error-"+config_query.value[el].meta.config[conf]+"-"+config_query.value[el].name).text("Please enter value")
}else{
result_dict["config"][config_query.value[el].name][config_query.value[el].meta.config[conf]] = loc
}
let result_dict = {"modules": $("#modules_select").val(),
"input": $("#input_select").val(),
"query": current_query.value
}
result_dict["config"] = {}
for(let el in config_query.value){
result_dict["config"][config_query.value[el].name] = {}
for(let conf in config_query.value[el].meta.config){
$("#error-"+config_query.value[el].meta.config[conf]+"-"+config_query.value[el].name).text("")
let loc = $("#form-"+config_query.value[el].meta.config[conf]+"-"+config_query.value[el].name).val()
if(!loc){
error_flag = true
$("#error-"+config_query.value[el].meta.config[conf]+"-"+config_query.value[el].name).text("Please enter value")
}else{
result_dict["config"][config_query.value[el].name][config_query.value[el].meta.config[conf]] = loc
}
}
if(!error_flag){
const res = await fetch('/run_modules',{
headers: { "X-CSRFToken": $("#csrf_token").val(), "Content-Type": "application/json" },
method: "POST",
body: JSON.stringify(result_dict)
})
if(await res.status == 201){
let loc = await res.json()
query.value = 'Stop'
console.log(loc['id']);
await nextTick()
window.location.href="/query/" + loc['id']
}else{
let loc = await res.json()
query.value = 'Query'
status_site.value = loc['message'] || 'Something went wrong'

if(status_site.value.includes("]")){
status_site.value = status_site.value.split("]")[1]
}
}
if(!error_flag){
const res = await fetch('/run_modules',{
headers: { "X-CSRFToken": $("#csrf_token").val(), "Content-Type": "application/json" },
method: "POST",
body: JSON.stringify(result_dict)
})
if(await res.status == 201){
let loc = await res.json()
await nextTick()
window.location.href="/query/" + loc['id']
}else{
let loc = await res.json()
status_site.value = loc['message'] || 'Something went wrong'

if(status_site.value.includes("]")){
status_site.value = status_site.value.split("]")[1]
}
}
}
Expand Down Expand Up @@ -227,7 +221,6 @@ <h4>[[module.name]]</h4>

return {
message_list,
query,
progress,
modules_list,
misp_attributes_list,
Expand Down

0 comments on commit 42996e8

Please sign in to comment.