-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathutil.mjs
98 lines (83 loc) · 2.15 KB
/
util.mjs
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
import validator from 'validator'
import dayjs from 'dayjs'
const regEx = /\d+/
export function isRequest(method) {
return !regEx.test(method)
}
export function whereBuilder(cond) {
// day
// start
let re = [
`create_time >= '${cond.day} ${cond.start}'`,
`create_time <= '${cond.day} ${cond.stop}'`
]
if (cond.caller.length > 0) {
if (cond.caller.indexOf('*') >= 0) {
re.push(`from_user like '${cond.caller.replaceAll('*', '%')}'`)
} else {
re.push(`from_user = '${cond.caller}'`)
}
}
if (cond.callee.length > 0) {
if (cond.callee.indexOf('*') >= 0) {
re.push(`to_user like '${cond.callee.replaceAll('*', '%')}'`)
} else {
re.push(`to_user = '${cond.callee}'`)
}
}
return re
}
export function conditionChecker(cond) {
// day
if (!validator.isDate(cond.day)) {
return false
}
// start
if (!validator.isTime(cond.start)) {
return false
}
// stop
if (!validator.isTime(cond.stop)) {
return false
}
if (cond.msg_min != "" && !validator.isInt(cond.msg_min)) {
return false
}
// msg_min
// caller
// callee
return True
}
export function getProtocolName(num) {
if (num === 6) {
return 'TCP'
}
if (num === 17) {
return 'UDP'
}
if (num === 22) {
return 'TLS'
}
if (num === 50) {
return 'ESP'
}
return 'Unknown'
}
export function createSeqHtml(seq) {
const res = []
seq.forEach((item, index) => {
let dis = 0
if (index !== 0) {
const a = dayjs(seq[index].CreateTime).unix() + '.' + seq[index].TimestampMicro
const b = dayjs(seq[index - 1].CreateTime).unix() + '.' + seq[index - 1].TimestampMicro
dis = parseFloat(a) - parseFloat(b)
}
res.push(
`${item.src_host}-${isRequest(item.sip_method) ? '' : '-'}>${item.dst_host}: F${index} **${item.sip_method}** ${item.response_desc} ${dis.toFixed(2)}s`,
)
})
res.push('terminators box')
return {
html: res.join('\n'),
}
}