-
Notifications
You must be signed in to change notification settings - Fork 232
/
home.html
241 lines (208 loc) · 9.3 KB
/
home.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!--
Author: David Cruciani
-->
{% extends 'base.html' %}
{% block content %}
<div>
<header>
</header>
<h1>MISP Modules</h1>
</div>
<hr>
<br>
<div style="width:50%; transform: translate(50%, 0);">
<div>
<input type="hidden" id="parent_id" value="{{sid}}">
<input type="text" value="{{query}}" id="process-query" placeholder="Enter here..." autofocus class="form-control" style="border-radius: 5px;" />
</div>
<span v-if="status_site" id="status">[[status_site]]</span>
</div>
<br>
<!-- Attributes selection -->
<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.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; padding: 5px" class="row">
<h4>Config</h4>
<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>
<input type="text" class="form-control" :id="'form-'+conf+'-'+module.name">
<span style="color: brown;" :id="'error-'+conf+'-'+module.name"></span>
</div>
</div>
</div>
<br/>
<button class="btn btn-primary" @click="actionQuery()">Query</button>
{% endblock %}
{% block script %}
<script type="module">
const { createApp, ref, onMounted, nextTick, defineComponent} = Vue
import {message_list} from '/static/js/toaster.js'
createApp({
delimiters: ['[[', ']]'],
setup() {
const modules_list = ref([])
const misp_attributes_list = ref({})
const attr_selected = ref([])
const progress = ref(0)
const current_query = ref()
const status_site = ref()
const config_query = ref([])
async function actionQuery(){
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 = ""
}
progress.value = 0
let error_flag = false
let result_dict = {"modules": $("#modules_select").val(),
"input": $("#input_select").val(),
"query": current_query.value,
"parent_id": $("#parent_id").val()
}
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()
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]
}
}
}
}
async function query_modules(){
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 res = await fetch("/get_list_misp_attributes")
let loc = await res.json()
misp_attributes_list.value = loc
await nextTick()
if (!$('.select2-input').hasClass("select2-hidden-accessible")) {
$('.select2-input').select2({
theme: 'bootstrap-5',
width: '50%'
})
}
if (!$('.select2-expansion').hasClass("select2-hidden-accessible")) {
$('.select2-expansion').select2({
theme: 'bootstrap-5'
})
}
if (!$('.select2-hover').hasClass("select2-hidden-accessible")) {
$('.select2-hover').select2({
theme: 'bootstrap-5'
})
}
$('#input_select').on('change.select2', async function (e) {
attr_selected.value = $(this).select2('data').map(item => item.id)[0]
if(attr_selected.value == 'None' ){
attr_selected.value = []
}
await nextTick()
if (!$('.select2-modules').hasClass("select2-hidden-accessible")) {
$('.select2-modules').select2({
theme: 'bootstrap-5'
})
$('#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){
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
}
}
}
})
}
})
$('#input_select').on('select2:open', function (e) {
document.querySelector('.select2-search__field').focus();
})
}
function pairedList() {
let pairs = [];
for (let i = 0; i < this.items.length; i += 2) {
pairs.push(this.items.slice(i, i + 2));
}
return pairs;
}
function checked_attr(arr1){
return arr1.includes(attr_selected.value)
}
return {
message_list,
progress,
modules_list,
misp_attributes_list,
attr_selected,
status_site,
config_query,
actionQuery,
pairedList,
checked_attr,
generateCoreFormatUI
}
}
}).mount('.container-fluid')
</script>
{% endblock %}