-
Notifications
You must be signed in to change notification settings - Fork 459
/
App.js
252 lines (228 loc) · 10.2 KB
/
App.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
import React, { Component } from 'react';
import './css/App.css';
import VeloNavigator from './components/sidebar/navigator.js';
import VeloClientSearch from './components/clients/search.js';
import VeloClientList from './components/clients/clients-list.js';
import VeloHostInfo from './components/clients/host-info.js';
import ServerInfo from './components/server/server-info.js';
import ClientSetterFromRoute from './components/clients/client_info.js';
import VeloClientSummary from './components/clients/client-summary.js';
import VFSViewer from './components/vfs/browse-vfs.js';
import VeloLiveClock from './components/utils/clock.js';
import ClientFlowsView from './components/flows/client-flows-view.js';
import ServerFlowsView from './components/flows/server-flows-view.js';
import Notebook from './components/notebooks/notebook.js';
import FullScreenNotebook from './components/notebooks/full_notebook.js';
import FullScreenHuntNotebook from './components/hunts/hunt-full-notebook.js';
import FullScreenFlowNotebook from './components/flows/flow-full-notebook.js';
import ArtifactInspector from './components/artifacts/artifacts.js';
import Users from './components/users/users.js';
import VeloHunts from './components/hunts/hunts.js';
import UserDashboard from './components/sidebar/user-dashboard.js';
import Form from 'react-bootstrap/Form';
import UserLabel from './components/users/user-label.js';
import EventMonitoring from './components/events/events.js';
import SnackbarProvider from 'react-simple-snackbar';
import Snackbar from './components/core/snackbar.js';
import Welcome from './components/welcome/welcome.js';
import LoginPage from './components/welcome/login.js';
import LogoffPage from './components/welcome/logoff.js';
import KeyboardHelp from './components/core/keyboard-help.js';
import { UserSettings } from './components/core/user.js';
import { ContextMenuPopup } from './components/utils/context.js';
import { Switch, Route } from "react-router-dom";
import { Join } from './components/utils/paths.js';
import { withRouter } from "react-router-dom";
import Navbar from 'react-bootstrap/Navbar';
import Nav from 'react-bootstrap/Nav';
import SidebarKeyNavigator from './components/sidebar/hotkeys.js';
import './themes/no-theme.css';
import './themes/veloci-light.css';
import './themes/veloci-dark.css';
import './themes/pink-light.css';
import './themes/github-dimmed-dark.css';
import './themes/ncurses.css';
import './themes/coolgray-dark.css';
/* This is the main App page.
We maintain internal state:
client - the currently selected client the user will interact
with. We hold the entire client info object in the top level
state.
query - the current search query typed into the top toolbar - this
is always exposed and only changed by the user. It allows us to
re-search for the same term quickly.
The client information is populated via the setClient() callback by:
1. VeloClientList component receiving a click on a table row.
*/
class App extends Component {
state = {
client: {},
// The file listing in the current directory.
current_node: {},
// The current row within the current node that is selected.
selected_row: {},
query: "",
query_version: "",
}
// Called to update the current client.
setClient = (client) => {
this.setState({client: client});
};
setClientSearch = (query) => {
let now = new Date();
this.setState({query: query, query_version: now.getTime()});
this.props.history.push('/search/' + (query || "all"));
};
updateCurrentNode = (node) => {
this.setState({current_node: node});
}
// Renders the entire app as normal.
renderApp() {
// We need to prepare a vfs_path for the navigator to link
// to. Depending on the current node, we make a link with or
// without a final "/".
let vfs_path = "/";
if (this.state.current_node && this.state.current_node.path) {
let path = [...this.state.current_node.path];
let name = this.state.current_node.selected && this.state.current_node.selected.Name;
if (name) {
path.push(name);
vfs_path = Join(path);
} else {
vfs_path = Join(path) + "/";
}
}
return <div>
<Navbar fixed="top" className="main-navbar justify-content-between">
<Form inline>
<VeloNavigator
vfs_path={vfs_path}
client={this.state.client} />
<VeloClientSearch
setSearch={this.setClientSearch}
/>
</Form>
<VeloClientSummary
setClient={this.setClient}
client={this.state.client}/>
<UserLabel className="navbar-text"/>
</Navbar>
<div id="content">
<Switch>
<Route path="/dashboard">
<UserDashboard />
</Route>
<Route exact path="/" component={Welcome}/>
<Route exact path="/welcome" component={Welcome}/>
<Route path="/search/:query?">
<VeloClientList
setSearch={this.setClientSearch}
version={this.state.query_version}
query={this.state.query}
setClient={this.setClient}
/>
</Route>
<Route path="/artifacts/:artifact?">
<ArtifactInspector client={this.state.client}/>
</Route>
<Route path="/users/:user?" component={Users}/>
<Route path="/hunts/:hunt_id?/:tab?">
<VeloHunts/>
</Route>
<Route path="/host/:client_id([^/]{7,})/:action?">
<ClientSetterFromRoute
client={this.state.client}
setClient={this.setClient} />
<VeloHostInfo
client={this.state.client}
setClient={this.setClient}
/>
</Route>
<Route path="/host/:client_id(server)/:action?">
<ServerInfo />
</Route>
<Route path="/vfs/:client_id/:vfs_path(.*)">
<ClientSetterFromRoute client={this.state.client} setClient={this.setClient} />
<VFSViewer client={this.state.client}
selectedRow={this.state.selected_row}
updateCurrentNode={this.updateCurrentNode}
node={this.state.current_node}
vfs_path={this.state.vfs_path} />
</Route>
{/* ClientFlowsView will only be invoked when the
* client looks like a client id - the
* ServerFlowsView is invoked when client_id ==
* "server". For now we assume the client_id is
* longer than 7 chars
*/}
<Route path="/collected/:client_id([^/]{7,})/:flow_id?/:tab?">
<ClientSetterFromRoute client={this.state.client} setClient={this.setClient} />
<ClientFlowsView client={this.state.client} />
</Route>
<Route path="/collected/server/:flow_id?/:tab?">
<ServerFlowsView />
</Route>
<Route path="/notebooks/:notebook_id?">
<Notebook />
</Route>
<Route path="/events/:client_id([^/]{7,})/:artifact?/:time?">
<ClientSetterFromRoute client={this.state.client} setClient={this.setClient} />
<EventMonitoring client={this.state.client}/>
</Route>
<Route path="/events/server/:artifact?/:time?">
<EventMonitoring client={{client_id: ""}}/>
</Route>
</Switch>
</div>
<Navbar fixed="bottom" className="app-footer justify-content-between ">
<Nav></Nav>
<Nav>
<VeloLiveClock className="float-right" />
<Snackbar />
</Nav>
</Navbar>
</div>;
}
renderMainPage() {
return (
<div>
<UserSettings>
<SnackbarProvider>
<SidebarKeyNavigator client={this.state.client}/>
<Switch>
<Route path="/fullscreen/notebooks/:notebook_id">
<FullScreenNotebook />
</Route>
<Route path="/fullscreen/hunts/:hunt_id/notebook">
<FullScreenHuntNotebook />
</Route>
<Route path="/fullscreen/collected/:client_id/:flow_id/notebook">
<FullScreenFlowNotebook />
</Route>
<Route>
{ this.renderApp() }
</Route>
</Switch>
<KeyboardHelp />
</SnackbarProvider>
<ContextMenuPopup/>
</UserSettings>
</div>
);
};
render() {
// This is an error injected into the main page by the server
// template renderer. We pick it up from here and override
// rendering the main page with this special login page.
if (window.ErrorState) {
if (window.ErrorState.Type === "Login") {
return <LoginPage/>;
}
if (window.ErrorState.Type === "Logoff") {
return <LogoffPage/>;
}
}
return this.renderMainPage();
};
}
export default withRouter(App);