mirror of https://github.com/MISP/misp-modules
fix: [website] config + query
parent
4d0672ffdd
commit
42996e8b85
|
@ -25,19 +25,19 @@ class Session_class:
|
|||
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"""
|
||||
|
@ -103,7 +103,6 @@ class Session_class:
|
|||
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:
|
||||
|
@ -121,6 +120,7 @@ class Session_class:
|
|||
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),
|
||||
|
|
|
@ -74,7 +74,6 @@
|
|||
createApp({
|
||||
delimiters: ['[[', ']]'],
|
||||
setup() {
|
||||
const query = ref("Query")
|
||||
const modules_list = ref([])
|
||||
const misp_attributes_list = ref({})
|
||||
const attr_selected = ref([])
|
||||
|
@ -97,48 +96,43 @@
|
|||
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(!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]
|
||||
}
|
||||
if(status_site.value.includes("]")){
|
||||
status_site.value = status_site.value.split("]")[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -227,7 +221,6 @@
|
|||
|
||||
return {
|
||||
message_list,
|
||||
query,
|
||||
progress,
|
||||
modules_list,
|
||||
misp_attributes_list,
|
||||
|
|
Loading…
Reference in New Issue