-
Notifications
You must be signed in to change notification settings - Fork 471
/
SideFilters.js
323 lines (301 loc) · 9.06 KB
/
SideFilters.js
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/**
* React Component for SideFilters. It is child component used by Report Component.
* Uses props or say Report function to update the filter arrays like selectedGroup etc.
* Also renders different actions to be performed on the target.
* Aim here to prevent SideFilters's re-rendering on props/state updates other than filter arrays.
*/
import React from "react";
import Plugins from "../Plugins/index";
import { templatesNames, getDocxReportFromJSON } from "./Export.js";
import {
Pane,
Strong,
Tab,
Tablist,
Text,
Icon,
Menu,
Popover,
Position,
Dialog,
toaster
} from "evergreen-ui";
import { loadTargetExport } from "./actions";
import {
makeSelectFetchTargetExport,
makeSelectTargetExportError,
makeSelectTargetExportLoading
} from "./selectors";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
export class SideFilters extends React.Component {
constructor(props, context) {
super(props, context);
this.handleGroupSelect = this.handleGroupSelect.bind(this);
this.handleTypeSelect = this.handleTypeSelect.bind(this);
this.handleFilterShow = this.handleFilterShow.bind(this);
this.handleFilterClose = this.handleFilterClose.bind(this);
this.handlePluginShow = this.handlePluginShow.bind(this);
this.handlePluginClose = this.handlePluginClose.bind(this);
this.handleAlertMsg = this.handleAlertMsg.bind(this);
this.resetTargetState = this.resetTargetState.bind(this);
this.getDocxReportFromJSON = getDocxReportFromJSON.bind(this);
this.getDocx = this.getDocx.bind(this);
this.state = {
filterShow: false,
pluginShow: false
};
}
/**
* Funtion to generate docx format.
* Uses REST API - /api/targets/<target_id>/export/
* docxtemplater takes a JSON and docx template and outputs output docx.
*/
getDocx(template) {
this.props.onFetchTargetExport(this.props.targetData[0]);
setTimeout(() => {
if (this.props.exportError !== false) {
toaster.danger("Server replied: " + this.props.exportError);
} else {
this.getDocxReportFromJSON(this.props.exportData, template);
}
}, 500);
}
/**
* Function handles the plugin group filter
* @param {string} selectedKey Group filter key
*/
handleGroupSelect(selectedKey) {
this.props.updateFilter("plugin_group", selectedKey);
}
/**
* Function handles the plugin type filter
* @param {string} selectedKey Type filter key
*/
handleTypeSelect(selectedKey) {
this.props.updateFilter("plugin_type", selectedKey);
}
/**
* Function handles the closing of advanced filter dialog box
*/
handleFilterClose() {
this.setState({ filterShow: false });
}
/**
* Function handles the opening of advanced filter dialog box
*/
handleFilterShow() {
this.setState({ filterShow: true });
}
/**
* Function handles the closing of Run plugins dialog box
*/
handlePluginClose() {
this.setState({ pluginShow: false });
}
/**
* Function handles the opening of Run plugins dialog box
*/
handlePluginShow() {
this.setState({ pluginShow: true });
}
/**
* Function renders the alert box after running plugins.
* @param {string} alertStyle Type of toaster to be renders
* @param {string} alertMsg Message to be appeared on the toaster
*/
handleAlertMsg(alertStyle, alertMsg) {
if (alertStyle === "success") {
toaster.success(alertMsg);
}
if (alertStyle === "warning") {
toaster.warning(alertMsg);
}
if (alertStyle === "danger") {
toaster.danger(alertMsg);
}
}
resetTargetState() {
//Its working as a mock function for plugin component
}
render() {
const {
targetData,
selectedGroup,
selectedType,
clearFilters,
updateReport
} = this.props;
const groups = ["web", "network", "auxiliary"];
const types = [
"exploit",
"semi_passive",
"dos",
"selenium",
"smb",
"active",
"bruteforce",
"external",
"grep",
"passive"
];
const PluginProps = {
handlePluginClose: this.handlePluginClose,
pluginShow: this.state.pluginShow,
selectedTargets: targetData,
handleAlertMsg: this.handleAlertMsg,
resetTargetState: this.resetTargetState
};
return (
<Pane
display="flex"
flexDirection="column"
data-test="sideFiltersComponent"
>
<Strong marginBottom={10}> Actions</Strong>
<Tablist
display="flex"
flexDirection="column"
width={200}
marginBottom={30}
>
<Tab
key="filter"
onSelect={this.handleFilterShow}
justifyContent="left"
>
<Icon color="info" icon="filter" marginRight={10} />
<Text color="#337ab7">Filter</Text>
</Tab>
<Tab key="refresh" onSelect={updateReport} justifyContent="left">
<Icon color="success" icon="refresh" marginRight={10} />
<Text color="#337ab7">Refresh</Text>
</Tab>
<Tab
key="plugins"
onSelect={this.handlePluginShow}
justifyContent="left"
>
<Icon color="danger" icon="fork" marginRight={10} />
<Text color="#337ab7">Run Plugins</Text>
</Tab>
<Tab
key="sessions"
// onSelect={() => this.handleGroupSelect(group)}
justifyContent="left"
>
<Icon color="warning" icon="flag" marginRight={10} />
<Text color="#337ab7">User Sessions</Text>
</Tab>
<Popover
position={Position.BOTTOM_LEFT}
content={
<Menu>
<Menu.Group title="Select template">
{templatesNames.map((template, index) => {
return (
<Menu.Item
key={index}
icon="git-repo"
onSelect={() => this.getDocx(template)}
>
{template}
</Menu.Item>
);
})}
</Menu.Group>
</Menu>
}
>
<Tab key="export" justifyContent="left">
<Icon icon="export" marginRight={10} />
<Text color="#337ab7">Export Report</Text>
<Icon icon="caret-down" marginLeft={5} />
</Tab>
</Popover>
</Tablist>
{/* Action list Ends*/}
{/* Group filter starts*/}
<Strong marginBottom={10}> Plugin Group</Strong>
<Tablist
display="flex"
flexDirection="column"
width={200}
marginBottom={30}
>
{groups.map((group, index) => (
<Tab
key={index}
id={index}
onSelect={() => this.handleGroupSelect(group)}
isSelected={selectedGroup.indexOf(group) > -1}
aria-controls={`panel-${group}`}
justifyContent="left"
>
<Text color="#337ab7">{group.replace("_", " ")}</Text>
</Tab>
))}
</Tablist>
{/* Group filter ends*/}
{/* Type Filter starts*/}
<Strong marginBottom={10}> Plugin Type</Strong>
<Tablist display="flex" flexDirection="column" width={200}>
{types.map((type, index) => (
<Tab
key={index}
id={index}
onSelect={() => this.handleTypeSelect(type)}
isSelected={selectedType.indexOf(type) > -1}
aria-controls={`panel-${type}`}
justifyContent="left"
>
<Text color="#337ab7">{type.replace("_", " ")}</Text>
</Tab>
))}
</Tablist>
{/* Type Filter Ends*/}
<Dialog
isShown={this.state.filterShow}
title="Advance filter"
intent="danger"
onCloseComplete={this.handleFilterClose}
confirmLabel="Clear Filters"
onConfirm={clearFilters}
>
Dialog content
</Dialog>
<Plugins {...PluginProps} />
</Pane>
);
}
}
SideFilters.propTypes = {
targetData: PropTypes.array,
selectedGroup: PropTypes.array,
selectedType: PropTypes.array,
updateFilter: PropTypes.func,
clearFilters: PropTypes.func,
updateReport: PropTypes.func,
exportLoading: PropTypes.bool,
exportError: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
exportData: PropTypes.oneOfType([
PropTypes.object.isRequired,
PropTypes.bool.isRequired
]),
onFetchTargetExport: PropTypes.func
};
const mapStateToProps = createStructuredSelector({
exportData: makeSelectFetchTargetExport,
exportLoading: makeSelectTargetExportLoading,
exportError: makeSelectTargetExportError
});
const mapDispatchToProps = dispatch => {
return {
onFetchTargetExport: target_id => dispatch(loadTargetExport(target_id))
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(SideFilters);