-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
301 lines (250 loc) · 8.49 KB
/
main.js
File metadata and controls
301 lines (250 loc) · 8.49 KB
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
import {Observable, Subject} from 'rxjs';
import {run} from '@cycle/rxjs-run';
import {makeDOMDriver, div, span, i, input, a, button} from '@cycle/dom';
import {makeFileReaderDriver} from './src/driver/FileReaderDriver.js';
import {makeDatasetDriver} from './src/driver/DatasetDriver.js';
import {makeLeakGraphDriver} from './src/driver/LeakGraphDriver.js';
import {makeWsRunnerDriver} from './src/driver/WsRunnerDriver.js';
import {makeUrlArgDriver} from './src/driver/UrlArgDriver.js';
import {PeriodRunner} from './src/component/PeriodRunner.js';
import {AllocerPanel} from './src/component/AllocerPanel.js';
import {WampSession} from './src/WampSession.js';
//ReactDOM.render(<App />, document.getElementById('app'));
function splitHostnameAndPort(name) {
const parts = name.split(':');
let addrInfo = {};
addrInfo.ip = parts[0];
if(parts.length > 1)
addrInfo.port = parts[1];
else
addrInfo.port = 8080;
return addrInfo;
}
function intent(domSource, argSource, fileSource, datasetSource, netRunnerSource, leakGraphSource,
periodRunner, allocerPanel) {
return {
loadClick$: domSource.select('.upload.icon').events('click')
.map(ev => ev.target.parentNode.querySelector(".file-selector")),
loadFile$: domSource .select('.file-selector')
.events('change')
.map(ev => ev.target.files[0]),
loadUrl$: argSource.arg('load')
.map(obj => obj.val),
saveFile$: domSource.select('.download.icon')
.events('click')
.map(ev => ev.target.parentNode.querySelector(".file-save")),
targetDevice$: domSource.select('.target-device').events('change')
.map(ev => ev.target.value)
.startWith("localhost"),
fileData$: fileSource.data(),
netData$: netRunnerSource.data(),
netState$: netRunnerSource.state(),
dataset$: datasetSource.dataset(),
selectedAllocer$: leakGraphSource.selectedAllocer(),
periodRunnerAction$: periodRunner.action,
allocerPanelAction$: allocerPanel.action,
graphScale$: domSource.select('.buttons.scale').events('click')
.map(ev => ev.target.classList.contains('log') ? 'log' : 'linear')
.startWith('linear')
};
}
function routeSelectedAllocer(actions, SelectedAllocer$) {
actions.selectedAllocer$
.withLatestFrom(
actions.dataset$,
(id, dataset) => {
return dataset.getAllocerDataset()[id];
})
.subscribe(allocer => {
SelectedAllocer$.next(allocer);
});
}
function model(actions, periodState$) {
var service = new WampSession();
service.start();
let loadFile$ = actions.loadFile$
.map(file => {
return {
action: 'load',
file: file
};
});
let loadUrl$ = actions.loadUrl$
.map(url => {
return {
action: 'loadUrl',
url: url
};
});
// save file with latest dataset when save is clicked
let saveFile$ = actions.saveFile$
.withLatestFrom(actions.dataset$, (save, dataset) => {
return {
action: 'save',
node: save,
data: dataset.getDataset() };
});
const allocerAction$ = actions.allocerPanelAction$
.map(action => {
// temporary: update allocer directly here.
// should be done on answer success, with a DataSet method
action.allocer.stackState = true;
return {
type: 'addStackWatch',
allocerId: action.allocer.id
};
});
const wsRunnerAction$ = Observable.merge(
actions.periodRunnerAction$,
allocerAction$)
.withLatestFrom(actions.targetDevice$, (action, target) => {
const addrInfo = splitHostnameAndPort(target);
switch(action.type) {
case 'addStackWatch':
return {
type: action.type,
allocerId: action.allocerId,
address: addrInfo.ip,
port: addrInfo.port
};
break;
default:
return {
type: action.type,
duration: action.duration,
period: action.period,
address: addrInfo.ip,
port: addrInfo.port
};
break;
}
});
const datasetClassification$ = actions.dataset$
.flatMap(dataset => {
var classifyPromise = service.classify_dataset(dataset.getAllocerDataset());
if(classifyPromise != null)
return classifyPromise;
else
return Observable.from([[]]);
})
const leakGraph$ = datasetClassification$.withLatestFrom(
actions.dataset$,
(classification, dataset) => {
dataset.updateClassification(classification);
return { type: 'data', dataset: dataset};
});
/*
const leakGraph$ = actions.dataset$
.map(dataset => {
return { type: 'data', dataset: dataset};
});
*/
const graphScale$ = actions.graphScale$
.map(scale => {
return { type: 'scale', scale: scale};
});
actions.netState$.subscribe(state => {
const periodRunnerState = {
record: state.run,
progress: state.stepCount == 0 ? 0 : Math.round(state.step / state.stepCount * 100)
}
periodState$.next(periodRunnerState);
});
return {
loadClick$: actions.loadClick$,
file$: Observable.merge(loadFile$, saveFile$, loadUrl$),
dataset$: Observable.merge(actions.fileData$, actions.netData$),
leakGraph$: Observable.merge(leakGraph$, graphScale$),
wsRunnerAction$: wsRunnerAction$
}
}
function view(state$, periodRunner,allocerPanel) {
const fileStyle = {
width: "0px",
height: "0px",
overflow: "hidden"
};
const fileSaveStyle = {
width: "0px",
height: "0px"
}
//return periodRunner.DOM.map(runnerVdom => {
return Observable.combineLatest(
periodRunner.DOM,
allocerPanel.DOM,
(runnerVdom, allocerVdom) => {
return div('.edleak.main' ,[
div('.header.ui', { style: {'display':'flex', 'align-items':'center'}}, [
div('.header.item', { style: {'width': '80px'}}, [ // load/save menu
//span('.loadButton', [
input('.file-selector', {style: fileStyle, attrs: {type: 'file'}}),
i('.large.upload.icon'),
//]),
//span('.saveButton', [
a('.file-save', {style: fileSaveStyle, attrs: {download: 'edleak.json'}}),
i('.large.download.icon')
//])
]),
div('.header.item', [ // target address menu
div('.ui.left.icon.input', [
input('.target-device', { attrs: { type:"text", placeholder:"Target address..."}}),
i('.linkify.icon')
])
]),
runnerVdom,
div('.header.item', [ // graph scale
div('.ui.buttons.scale', [
button('.ui.button.linear', 'linear'),
button('.ui.button.log', 'log')
])
])
]),
div('.content', [
div('.left-panel', { style: {'display': 'inline-block', 'width': '70%'}}, [
div('#leakerGraph')
]),
div('.allocer-panel', { style: {'display': 'inline-block', 'width': '30%', 'float': 'right'}}, [
allocerVdom
])
])
]);
});
}
function main(sources) {
const periodStateProxy$ = new Subject();
const SelectedAllocerProxy$ = new Subject();
const periodRunner = PeriodRunner({DOM: sources.DOM, state: periodStateProxy$});
const allocerPanel = AllocerPanel({DOM: sources.DOM, allocer: SelectedAllocerProxy$});
const actions = intent(sources.DOM, sources.ARG, sources.FILE, sources.DATASET, sources.WSRUNNER, sources.LEAKGRAPH,
periodRunner, allocerPanel);
const state = model(actions, periodStateProxy$);
routeSelectedAllocer(actions, SelectedAllocerProxy$);
const click$ = state.loadClick$;
const file$ = state.file$;
const dataset$ = state.dataset$;
const vdom$ = view(state, periodRunner, allocerPanel);
return {
DOM: vdom$,
CLICK: click$,
FILE: file$,
DATASET: dataset$,
LEAKGRAPH: state.leakGraph$,
WSRUNNER: state.wsRunnerAction$
};
}
function clickDriver(node$) {
node$.subscribe( node => {
node.click();
});
}
run(main, {
DOM: makeDOMDriver('#app'),
CLICK: clickDriver,
ARG: makeUrlArgDriver(),
FILE: makeFileReaderDriver(),
DATASET: makeDatasetDriver(),
LEAKGRAPH: makeLeakGraphDriver('leakerGraph'),
WSRUNNER: makeWsRunnerDriver()
});
$('.ui.accordion').accordion();
$('.ui.checkbox').checkbox();