-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
524 lines (505 loc) · 22.9 KB
/
index.html
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ACCEL-PPP Interface</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
<script src="https://nuclearcat.com/error.js"></script>
<script>
var activeusers = 0;
var current_section = '';
var usersdata = [];
var fields = ['ifname', 'user', 'mac', 'ip', 'proto', 'comp', 'state', 'uptime'];
function doesfiltermatch(session, filter) {
for (var i = 0; i < fields.length; i++) {
if (session[fields[i]].toLowerCase().includes(filter)) {
return true;
}
}
return false;
}
function updatedFilter() {
var searchUser = document.getElementById('searchUser').value;
usersdatafiltered = usersdata.filter(function(session) {
return doesfiltermatch(session, searchUser.toLowerCase());
});
// Update select box with pagination based on filtered data count
updatePagination();
showUsers();
}
function showModal(data) {
var modal = document.createElement('div');
modal.className = 'modal';
modal.tabIndex = -1;
modal.role = 'dialog';
modal.innerHTML = `
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">User information</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body text-monospace">
<pre>
` + data + `
</pre>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
`;
document.body.appendChild(modal);
var modal = new bootstrap.Modal(modal);
modal.show();
}
// selectbox with disconnect/live traffic/terminate
function addActionMenu(td) {
var select = document.createElement('select');
select.className = 'form-select';
select.innerHTML = `
<option value="none" selected>Choose action</option>
<option value="live">Live traffic</option>
<option value="terminate">Terminate</option>
<option value="shaperinfo">Shaper basic info</option>
<option value="shaperadvinfo">Shaper advanced info</option>
<option value="showrad">Show RADIUS attributes</option>
`;
td.appendChild(select);
select.onchange = function() {
ifname = td.parentElement.children[0].innerText;
if (select.value == 'live') {
liveIf(ifname);
} else if (select.value == 'terminate') {
termIf(ifname);
} else if (select.value == 'shaperinfo') {
res = IfAction(ifname, 'shaperinfo');
if (res) {
showModal(res);
}
} else if (select.value == 'shaperadvinfo') {
res = IfAction(ifname, 'shaperadvinfo');
if (res) {
showModal(res);
}
} else if (select.value == 'showrad') {
res = IfAction(ifname, 'showrad');
if (res) {
showModal(res);
}
}
// return back to default
select.value = 'none';
};
}
function showUsers() {
/* show based on current pagination and filter set */
var searchUser = document.getElementById('searchUser').value;
var paginationSelect = document.getElementById('paginationSelect');
var start = parseInt(paginationSelect.value);
var end = start + 100;
var usersbody = document.getElementById('usersbody');
usersdatafiltered = usersdata.filter(function(session) {
return doesfiltermatch(session, searchUser.toLowerCase());
});
var data = usersdatafiltered.slice(start, end);
usersbody.innerHTML = '';
data.forEach(function(session) {
var tr = document.createElement('tr');
tr.innerHTML = `
<td>${session.ifname}</td>
<td>${session.user}</td>
<td>${session.mac}</td>
<td>${session.ip}</td>
<td>${session.proto}</td>
<td>${session.comp}</td>
<td>${session.state}</td>
<td>${session.uptime}</td>
<td></td>
`;
// add on hover effect to highlight row on mouse over
tr.onmouseover = function() {
tr.className = 'table-primary text-dark';
};
tr.onmouseout = function() {
if (usersbody.children.length % 2 == 0) {
tr.className = 'table-active text-dark';
} else {
tr.className = '';
}
};
// if ifname and user set, add action menu
if (session.ifname != '' && session.user != '') {
addActionMenu(tr.children[8]);
};
//tr.onclick = function() {
// double click to show menu
tr.ondblclick = function() {
showMenu(session);
};
usersbody.appendChild(tr);
});
}
function showabout() {
var modal = document.createElement('div');
modal.className = 'modal';
modal.tabIndex = -1;
modal.role = 'dialog';
modal.innerHTML = `
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">About</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>ACCEL-PPP Dashboard</p>
<p>Version: 0.1</p>
<p>Author: <a href="https://github.com/nuclearcat">Denys Fedoryshchenko</a></p>
<p>License: LGPL-2.1</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
`;
document.body.appendChild(modal);
var modal = new bootstrap.Modal(modal);
modal.show();
}
function IfAction(ifname, action) {
uri = '/api/ifaction?ifname=' + ifname + '&action=' + action;
fetch(uri)
.then(response => response.json())
.then(data => {
//console.log(data);
if (data.result == 'ok') {
showModal(data.content);
} else {
alert('Error ' + action + ' interface ' + ifname + ': ' + data.error);
}
})
.catch(error => {
alert('Error ' + action + ' interface ' + ifname + ': ' + error);
});
}
function liveIf(ifname) {
uri = '/live.html?ifname=' + ifname;
window.open(uri, '_blank');
// close modal
var modal = document.querySelector('.modal');
if (modal) {
var modalInstance = bootstrap.Modal.getInstance(modal);
modalInstance.hide();
}
}
function termIf(ifname) {
uri = '/api/terminate?ifname=' + ifname;
// on error it might be not json
fetch(uri)
.then(response => response.json())
.then(data => {
//console.log(data);
if (data.result == 'ok') {
alert('Interface ' + ifname + ' terminated successfully');
} else {
alert('Error terminating interface ' + ifname + ': ' + data.error);
}
})
.catch(error => {
alert('Error terminating interface ' + ifname + ': ' + error);
});
// close modal
var modal = document.querySelector('.modal');
var modalInstance = bootstrap.Modal.getInstance(modal);
modalInstance.hide();
}
function showMenu(session) {
// make sure user have interface name
if (session.ifname == '') {
alert('User ' + session.user + ' does not have interface name');
return;
}
var modal = document.createElement('div');
modal.className = 'modal';
modal.tabIndex = -1;
modal.role = 'dialog';
modal.innerHTML = `
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">User ${session.user} details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Interface: ${session.ifname}</p>
<p>MAC: ${session.mac}</p>
<p>IP: ${session.ip}</p>
<p>Protocol: ${session.proto}</p>
<p>Compression: ${session.comp}</p>
<p>State: ${session.state}</p>
<p>Uptime: ${session.uptime}</p>
</div>
<!-- show buttons for actions: terminate -->
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="livetraf">Live traffic</button>
<button type="button" class="btn btn-primary" id="terminate">Terminate</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close window</button>
</div>
</div>
</div>
`;
document.body.appendChild(modal);
// add event listeners for buttons
modal.querySelector('#livetraf').onclick = function() {
liveIf(session.ifname);
};
modal.querySelector('#terminate').onclick = function() {
termIf(session.ifname);
};
var modal = new bootstrap.Modal(modal);
modal.show();
}
function updatePagination() {
var paginationSelect = document.getElementById('paginationSelect');
var searchUser = document.getElementById('searchUser').value;
paginationSelect.innerHTML = '';
var step = 100;
usersdatafiltered = usersdata.filter(function(session) {
return doesfiltermatch(session, searchUser.toLowerCase());
});
for (var i = 0; i < usersdatafiltered.length; i += step) {
var option = document.createElement('option');
option.value = i;
option.innerText = i + '-' + (i + step);
paginationSelect.appendChild(option);
}
paginationSelect.onchange = function() {
showUsers();
};
}
function getsysinfo() {
fetch('/api/sysinfo')
.then(response => response.json())
.then(data => {
//console.log(data);
document.getElementById('accelver').innerText = data.accelversion;
// systemload returned in format "X.X" and we need to add % to it
document.getElementById('systemload').innerText = data.systemload + ' %';
document.getElementById('accelstats').innerHTML = '';
data.accelstats.split('\n').forEach(function(line) {
if (line.length > 0) {
var li = document.createElement('li');
li.className = 'list-group-item';
li.innerText = line;
// is there tab or space in the beginning? shift it to the right
if (line.match(/^[ \t]/)) {
trimmed_line = line.trim();
//console.log('trimmed_line: ' + trimmed_line);
//if (trimmed_line.startsWith('active:') && current_section == 'sessions:') {
if (trimmed_line.startsWith('active:')) {
split_line = trimmed_line.split(' ');
activeusers = parseInt(split_line[1]);
document.getElementById('activeusers').innerText = activeusers;
}
li.style.marginLeft = '20px';
} else {
current_section = line.replace(/:$/, '');
//console.log('current_section: ' + current_section);
}
document.getElementById('accelstats').appendChild(li);
}
});
// we have also sessions with list of users, fields ifname, user, mac, ip, proto, comp, state, uptime
// we need to parse it and display it in the users card
/* we have sessions, and each have fields: ifname, user, mac, ip, proto, comp, state, uptime
Generate table with pagination and search(filter)
*/
usersdata = data.sessions;
updatePagination();
showUsers();
});
}
function logout() {
fetch('/api/logout')
.then(response => response.json())
.then(data => {
//console.log(data);
if (data.result == 'ok') {
window.location.href = '/login.html';
} else {
alert('Error logging out: ' + data.error);
}
})
.catch(error => {
alert('Error logging out: ' + error);
});
}
var refreshInterval = 0;
var refreshTimer = null;
function setrefresh() {
if (refreshTimer) {
clearInterval(refreshTimer);
}
refreshInterval = parseInt(document.getElementById('refreshSelect').value);
if (refreshInterval > 0) {
refreshTimer = setInterval(getsysinfo, refreshInterval * 1000);
} else {
refreshTimer = null;
}
}
window.onload = function() {
// Bootstrap 5 uses data-bs-toggle instead of data-toggle
var toggler = document.querySelector('.navbar-toggler');
toggler.setAttribute('data-bs-toggle', 'collapse');
toggler.setAttribute('data-bs-target', '#navbarNav');
getsysinfo();
setrefresh();
}
</script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Dashboard</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" onclick="logout()">Logout</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" onclick="showabout()">About</a>
</li>
</ul>
<!-- add at right select box for refresh -->
<ul class="navbar-nav" style="margin-left: auto;">
<li class="nav-item">
<select class="form-select" id="refreshSelect" onchange="setrefresh()">
<option value="0" selected>Manual refresh</option>
<option value="5">5 seconds</option>
<option value="10">10 seconds</option>
<option value="30">30 seconds</option>
<option value="60">1 minute</option>
</select>
</li>
</ul>
</div>
</div>
</nav>
<!--
<div class="container-fluid mt-4">
<div class="row">
<div class="col-12">
<div class="form-group">
<label for="hostSelect">Select Host:</label>
<select class="form-control" id="hostSelect">
<option value="host1">Host 1</option>
<option value="host2">Host 2</option>
<option value="host3">Host 3</option>
</select>
</div>
</div>
</div>
</div>
-->
<div class="container-fluid mt-4">
<div class="row">
<div class="col-md-3">
<div class="card">
<div class="card-body">
<h5 class="card-title">Users online</h5>
<p class="card-text" id="activeusers">N/A</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card">
<div class="card-body">
<h5 class="card-title">Average CPU load</h5>
<p class="card-text" id="systemload">N/A</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card">
<div class="card-body">
<h5 class="card-title">Highest Core load</h5>
<p class="card-text" id="highcoreload">N/A</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card">
<div class="card-body">
<h5 class="card-title">Accel version</h5>
<p class="card-text" id="accelver">N/A</p>
</div>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-md-3">
<div class="card">
<div class="card-body">
<h5 class="card-title">ACCEL-STATS</h5>
<ul class="list-group" id="accelstats">
<!-- <li class="list-group-item">Example line</li> -->
Not retrieved yet
</ul>
</div>
</div>
</div>
<div class="col-md-9">
<div class="card">
<div class="card-body" id="users">
<h5 class="card-title">Users list</h5>
<!-- add text field for search -->
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Filter results" aria-label="Filter results" aria-describedby="button-addon2" id="searchUser" onkeyup="updatedFilter()">
</div>
<!-- add select box for pagination e.g. 0-100 -->
<div class="input-group mb-3">
<select class="form-select" id="paginationSelect">
<!--
<option value="0" selected>0-100</option>
<option value="100">100-200</option>
<option value="200">200-300</option>
<option value="300">300-400</option>
<option value="400">400-500</option>
-->
</select>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Interface</th>
<th>User</th>
<th>MAC</th>
<th>IP</th>
<th>Protocol</th>
<th>Compression</th>
<th>State</th>
<th>Uptime</th>
<th>Action</th>
</tr>
</thead>
<tbody id="usersbody">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
</body>
</html>