1
1
import React , { useState } from "react" ;
2
2
3
- import { TextField , Select , FormControl , InputLabel } from "@material-ui/core" ;
3
+ import {
4
+ TextField ,
5
+ Card ,
6
+ CardActionArea ,
7
+ CardContent ,
8
+ Typography ,
9
+ Grid ,
10
+ } from "@material-ui/core" ;
4
11
import { makeStyles } from "@material-ui/core/styles" ;
5
12
6
13
const useStyles = makeStyles ( ( theme ) => ( {
@@ -9,16 +16,63 @@ const useStyles = makeStyles((theme) => ({
9
16
width : "25ch" ,
10
17
} ,
11
18
} ,
19
+ card : {
20
+ minWidth : 200 ,
21
+ margin : 10 ,
22
+ width : "fit-content" ,
23
+ } ,
24
+ actionArea : {
25
+ height : "100%" ,
26
+ width : "100%" ,
27
+ } ,
12
28
} ) ) ;
13
29
14
30
function isIP ( input ) {
15
- // From https://github. com/lukehaas/RegexHub
31
+ // From https://www.oreilly. com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html
16
32
const regex =
17
- "^(?:(?: 25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?: 25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" ;
33
+ "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).( 25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).( 25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" ;
18
34
19
35
return RegExp ( regex ) . test ( input ) ;
20
36
}
21
37
38
+ function DataCard ( props ) {
39
+ const classes = useStyles ( ) ;
40
+
41
+ return (
42
+ < Card className = { classes . card } elevation = { 3 } >
43
+ < CardContent >
44
+ < Typography align = "center" variant = "h6" >
45
+ { props . name }
46
+ </ Typography >
47
+ < Typography align = "center" variant = "body2" >
48
+ { props . data }
49
+ </ Typography >
50
+ </ CardContent >
51
+ </ Card >
52
+ ) ;
53
+ }
54
+
55
+ function LinkCard ( props ) {
56
+ const classes = useStyles ( ) ;
57
+
58
+ return (
59
+ < Card className = { classes . card } elevation = { 3 } >
60
+ < CardActionArea className = { classes . actionArea } href = { props . link } >
61
+ < CardContent >
62
+ < Typography align = "center" variant = "h6" >
63
+ { props . name }
64
+ </ Typography >
65
+ { props . data && (
66
+ < Typography align = "center" variant = "body2" >
67
+ { props . data }
68
+ </ Typography >
69
+ ) }
70
+ </ CardContent >
71
+ </ CardActionArea >
72
+ </ Card >
73
+ ) ;
74
+ }
75
+
22
76
function IPQuery ( ) {
23
77
const classes = useStyles ( ) ;
24
78
@@ -51,9 +105,9 @@ function IPQuery() {
51
105
setResult ( ( curr ) => {
52
106
return {
53
107
...curr ,
54
- data : body
55
- }
56
- } )
108
+ data : body ,
109
+ } ;
110
+ } ) ;
57
111
} ) ;
58
112
}
59
113
@@ -91,17 +145,69 @@ function IPQuery() {
91
145
{ /* Result */ }
92
146
{ result . show && < h2 > Result</ h2 > }
93
147
94
- { result . show && result . links . kibanaIndicator && (
95
- < div >
96
- < a href = { result . links . kibanaIndicator } > Kibana indicator dashboard</ a >
97
- </ div >
98
- ) }
99
- { result . show && result . links . ntopHost && (
100
- < div >
101
- < a href = { result . links . ntopHost } > Ntop host details</ a >
102
- </ div >
148
+ { result . show && result . links && < h3 > Links</ h3 > }
149
+ < Grid container spacing = { 1 } >
150
+ { result . show && result . links && result . links . kibanaIndicator && (
151
+ < LinkCard
152
+ name = "Kibana indicator"
153
+ link = { result . links . kibanaIndicator }
154
+ />
155
+ ) }
156
+
157
+ { result . show && result . links && result . links . ntopHost && (
158
+ < LinkCard name = "Ntop host details" link = { result . links . ntopHost } />
159
+ ) }
160
+ </ Grid >
161
+
162
+ { result . show && result . data && < h3 > Data</ h3 > }
163
+
164
+ < Grid container spacing = { 1 } >
165
+ { result . show && result . data && result . data . firstSeen && (
166
+ < DataCard name = "First seen by ntop" data = { result . data . firstSeen } />
167
+ ) }
168
+
169
+ { result . show && result . data && result . data . lastSeen && (
170
+ < DataCard name = "Last seen by ntop" data = { result . data . lastSeen } />
171
+ ) }
172
+
173
+ { result . show && result . data && result . data . mispMatches && (
174
+ < DataCard
175
+ name = "Attribute search matches in MISP"
176
+ data = { result . data . mispMatches }
177
+ />
178
+ ) }
179
+
180
+ { result . show &&
181
+ result . data &&
182
+ result . data . mispEvents &&
183
+ result . data . mispEvents . map ( ( event ) => {
184
+ return (
185
+ < LinkCard
186
+ name = "Misp event"
187
+ data = { event }
188
+ link = { `https://misp-sopoc.duckdns.org/events/view/${ event } ` }
189
+ />
190
+ ) ;
191
+ } ) }
192
+
193
+ { result . show &&
194
+ result . data &&
195
+ result . data . errors &&
196
+ result . data . errors . map ( ( err ) => {
197
+ return < DataCard name = "Error" data = { err } /> ;
198
+ } ) }
199
+
200
+ { result . show && result . data && result . data . statusMessage && (
201
+ < DataCard name = "Fetch error" value = { result . data . statusMessage } />
202
+ ) }
203
+ </ Grid >
204
+
205
+ { result . show && (
206
+ < React . Fragment >
207
+ < h3 > JSON</ h3 >
208
+ < xmp > { JSON . stringify ( result , null , 2 ) } </ xmp >
209
+ </ React . Fragment >
103
210
) }
104
- { result . show && JSON . stringify ( result ) }
105
211
</ React . Fragment >
106
212
) ;
107
213
}
0 commit comments