-
Notifications
You must be signed in to change notification settings - Fork 0
/
webLCM.html
583 lines (552 loc) · 18.4 KB
/
webLCM.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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
<!DOCTYPE html>
<!--
Copyright (c) 2017, Laird
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
Contact: support@lairdconnect.com
-->
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<title>WebLCM</title>
<!-- Bootstrap core CSS -->
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="assets/css/dashboard.css" rel="stylesheet">
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/button-adjuster.js"></script>
<!-- http://jqueryui.com/download/#!version=1.11.4&themeParams=none&components=1111111111111111101111111111111111111 -->
<script src="assets/js/jquery-ui.min.js"></script>
<!-- http://touchpunch.furf.com/mit.txt -->
<script src="assets/js/jquery.ui.touch-punch.min.js"></script>
<!-- https://github.com/Mottie/tablesorter -->
<script type="text/javascript" src="assets/js/jquery.tablesorter.min.js"></script>
<script>
var intervalId;
var defines = [];
var main_menu_list = [];
var mini_menu_list = [];
$.ajax({
url: "php/defines.php",
type: "POST",
contentType: "application/json",
retry: 1,
error: function(){
if (this.retry < 5){
this.retry++;
$.ajax(this);
return;
}
},
})
.done(function( data ) {
defines = data;
var index = 0;
consoleLog(data);
for (var key in defines.PLUGINS.list) {
if (defines.PLUGINS.list[key] == true){
loadjscssfile(key, "js");
addPlugin(0, key, index);
index++;
}
}
checkLocks();
});
function consoleLog(message){
if (defines.DEBUG == 1 | defines.DEBUG == 3){
console.log(message);
}
}
function checkLocks(){
if (defines.IGNORE_SESSION == defines.SDCERR.SDCERR_SUCCESS && defines.SESSION == defines.SDCERR.SDCERR_SUCCESS){
$("#loggin").addClass("hidden");
$(".locked").removeClass("hidden");
} else if (defines.SESSION == defines.SDCERR.SDCERR_SUCCESS){
$("#loggin").addClass("hidden");
$("#loggout").removeClass("hidden");
$(".locked").removeClass("hidden");
}
}
function loadjscssfile(key, filetype){
var jsPath = "../plugins/" + key + "/" + key + "." + filetype;
if (filetype=="js"){ //if jsPath is a external JavaScript file
var fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", jsPath);
}
if (typeof fileref!="undefined"){
document.getElementsByTagName("head")[0].appendChild(fileref);
consoleLog("Loaded:" + jsPath);
fileref.onload = function(){
window[key + "AUTORUN"](0);
}
}
}
function addPlugin(retry, key, index){
var pluginPath = "../plugins/" + key + "/" + key + ".html";
$.ajax({
url: pluginPath,
data: {},
type: "GET",
dataType: "html",
})
.done(function( data ) {
main_menu_list[index] = $(data)[1];
mini_menu_list[index] = $(data)[3];
if (defines.PLUGINS.count == main_menu_list.length){
$("#main_menu").append(main_menu_list);
$("#mini_menu").append(mini_menu_list);
consoleLog(main_menu_list);
consoleLog(mini_menu_list);
}
checkLocks();
})
.fail(function() {
consoleLog("Error, couldn't get " + pluginPath + ".. retrying");
if (retry < 5){
retry++;
addPlugin(retry, key, index);
} else {
consoleLog("Retry max attempt reached");
}
});
}
function clearReturnData(){
$("[id^='return']").removeClass();
$("[id^='return']").html("");
}
function notificationPermission(){
//Ask for notification permission
Notification.requestPermission();
}
function checkNotifyPermission(){
if (typeof Notification === 'undefined' || !Notification){
$("#enableNotify").addClass("disabled");
$("#enableNotify").html("Not Supported");
return;
}
if (Notification.permission === "granted"){
$("#enableNotify").html("Enabled");
$("#enableNotify").addClass("disabled");
$("#disableNotify").removeClass("hidden");
}
}
function sendNotification(title, message){
if (typeof Notification === 'undefined' || !Notification){
return false;
}
if (Notification.permission === "granted"){
var mobile = document.getElementById("mobileMenu");
//Dont show notifications on mobile
if (mobile.offsetParent === null){
var notification = new Notification(title, {
icon: 'assets/img/logo.png',
body: message,
});
return true;
}
}
return false;
}
function dismissibleAlerts(){
var returnData = document.getElementById("returnDataHelp");
var dismissButton = document.createElement("button");
var dismissSpan = document.createElement("span");
var spanX = document.createTextNode("X");
dismissButton.className = "close";
dismissButton.appendChild(dismissSpan);
dismissButton.onclick = function() {
clearReturnData();
};
dismissSpan.appendChild(spanX);
returnData.appendChild(dismissButton);
}
function SDCERRtoString(SDCERR){
$("[id^='return']").removeClass();
switch(parseInt(SDCERR)) {
case defines.SDCERR.SDCERR_SUCCESS:
if (!sendNotification("Success", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-success");
$("[id^='return']").html("Success");
}
break;
case defines.SDCERR.SDCERR_FAIL:
if (!sendNotification("Failure", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("Failure");
}
break;
case defines.SDCERR.SDCERR_INVALID_NAME:
if (!sendNotification("Invalid Name", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("Invalid Name");
}
break;
case defines.SDCERR.SDCERR_INVALID_CONFIG:
if (!sendNotification("Invalid Config", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("Invalid Config");
}
break;
case defines.SDCERR.SDCERR_INVALID_DELETE:
if (!sendNotification("Invalid Delete", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("Invalid Delete");
}
break;
case defines.SDCERR.SDCERR_POWERCYCLE_REQUIRED:
if (!sendNotification("Power Cycle Required", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-info");
$("[id^='return']").html("Power Cycle Required");
}
break;
case defines.SDCERR.SDCERR_INVALID_PARAMETER:
if (!sendNotification("Invalid Parameter", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("Invalid Parameter");
}
break;
case defines.SDCERR.SDCERR_INVALID_EAP_TYPE:
if (!sendNotification("Invalid EAP TYPE", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("Invalid EAP TYPE");
}
break;
case defines.SDCERR.SDCERR_INVALID_WEP_TYPE:
if (!sendNotification("Invalid WEP TYPE", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("Invalid WEP TYPE");
}
break;
case defines.SDCERR.SDCERR_INVALID_FILE:
if (!sendNotification("Invalid File", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("Invalid File");
}
break;
case defines.SDCERR.SDCERR_INSUFFICIENT_MEMORY:
if (!sendNotification("Insufficient Memory", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("Insufficient Memory");
}
break;
case defines.SDCERR.SDCERR_NOT_IMPLEMENTED:
if (!sendNotification("Not Implemented", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("Not Implemented");
}
break;
case defines.SDCERR.SDCERR_NO_HARDWARE:
if (!sendNotification("No Hardware", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("No Hardware");
}
break;
case defines.SDCERR.SDCERR_INVALID_VALUE:
if (!sendNotification("Invalid Value", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("Invalid Value");
}
break;
default:
if (!sendNotification("Unknown Data", "")){
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html("Unknown Data");
}
}
dismissibleAlerts();
}
function CustomErrMsg(message){
if (!sendNotification("Failure", message)){
if (message.length >= 20){
$("#returnDataNav").css( "fontSize", "12px" );
}
$("[id^='return']").removeClass();
$("[id^='return']").addClass("alert alert-dismissible alert-danger");
$("[id^='return']").html(message);
dismissibleAlerts();
}
}
function enterKeyPress(e){
if(e.keyCode === 13){ //enter key
e.preventDefault();
login(0);
}
}
function login(retry){
var creds = {
username: document.getElementById("username").value,
password: document.getElementById("password").value,
}
// Clear any old return code message
clearReturnData()
$.ajax({
url: "php/login.php",
data: JSON.stringify(creds),
type: "POST",
contentType: "application/json",
})
.done(function( data ) {
consoleLog(data);
if (data.SDCERR == defines.SDCERR.SDCERR_SUCCESS){
$("#loggin").addClass("hidden");
$("#loggout").removeClass("hidden");
$(".locked").removeClass("hidden");
clearReturnData();
} else {
if (data.LOCKED){
CustomErrMsg("System is locked: " + data.TIME_LEFT + " seconds left");
} else {
CustomErrMsg("Credentials are invalid");
}
}
document.getElementById("username").value = null;
document.getElementById("password").value = null;
})
.fail(function() {
consoleLog("Error, couldn't get startSession.php.. retrying");
if (retry < 5){
retry++;
login(retry);
} else {
consoleLog("Retry max attempt reached");
}
});
}
function logout(retry){
$.ajax({
url: "php/logout.php",
data: {},
type: "GET",
contentType: "application/json",
})
.done(function( data ) {
if (data.SDCERR == defines.SDCERR.SDCERR_SUCCESS){
$("#loggout").addClass("hidden");
$("#loggin").removeClass("hidden");
$(".locked").addClass("hidden");
clickStatusPage();
}
document.getElementById("username").value = null;
document.getElementById("password").value = null;
})
.fail(function() {
consoleLog("Error, couldn't get stopSession.php.. retrying");
if (retry < 5){
retry++;
loggout(retry);
} else {
consoleLog("Retry max attempt reached");
}
});
}
function clickSettingsPage(retry) {
$.ajax({
url: "/html/settings.html",
data: {},
type: "GET",
dataType: "html",
})
.done(function(data){
if (intervalId){
clearInterval(intervalId);
intervalId = 0;
}
$("li").removeClass("active");
$('#main_section').html(data);
clearReturnData();
$("#helpText").html("Password must be 8 to 20 characters, and contain at least one numeric digit, one uppercase and one lowercase letter. ");
$("#helpText").append("Leading and trailing whitespace will get removed.");
checkNotifyPermission();
})
.fail(function() {
consoleLog("Error, couldn't get settings.html.. retrying");
if (retry < 5){
retry++;
clickSettingsPage(retry);
} else {
consoleLog("Retry max attempt reached");
}
});
}
function onclickSetUserPass(field,current,attempt,check){
var userName = document.getElementById("userName");
var passWord = document.getElementById("passWord");
if (field.id == "userName"){
if (field.checked == true){
current.disabled = false;
attempt.disabled = false;
check.disabled = false;
} else {
current.disabled = true;
attempt.disabled = true;
check.disabled = true;
current.value = "";
attempt.value = "";
check.value = "";
}
} else if (field.id == "passWord"){
if (field.checked == true){
current.disabled = false;
attempt.disabled = false;
check.disabled = false;
} else {
current.disabled = true;
attempt.disabled = true;
check.disabled = true;
current.value = "";
attempt.value = "";
check.value = "";
}
}
if (userName.checked != true && passWord.checked != true){
$("#submitButton").addClass("disabled");
}
}
function onChangeSubmit(){
$("#submitButton").removeClass("disabled");
}
function submitSetUserPass(retry,userName,passWord){
var credentials = {
currentUserName: document.getElementById("currentUserName").value,
currentPassWord: document.getElementById("currentPassWord").value,
}
var newUserName = document.getElementById("newUserName").value;
var newPassWord = document.getElementById("newPassWord").value;
if (userName.checked == true){
if (newUserName != document.getElementById("checkUserName").value){
CustomErrMsg("New username does not match");
return;
}
if (newUserName.trim().length <= 0){
CustomErrMsg("New username cannot be blank");
return;
}
credentials.newUserName = newUserName;
}
if (passWord.checked == true){
var passw = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$/;
if (newPassWord != document.getElementById("checkPassWord").value){
CustomErrMsg("New password does not match");
return;
}
if(!newPassWord.match(passw)){
CustomErrMsg("Password not strong enough");
return;
}
credentials.newPassWord = newPassWord;
}
$.ajax({
url: "/php/setUserPass.php",
type: "POST",
data: JSON.stringify(credentials),
contentType: "application/json",
})
.done(function( msg ) {
if (msg.SESSION == defines.SDCERR.SDCERR_FAIL){
expiredSession();
return;
}
consoleLog(msg);
SDCERRtoString(msg.SDCERR);
$("#submitButton").addClass("disabled");
})
.fail(function() {
consoleLog("Failed to get credential data, retrying");
if (retry < 5){
retry++;
submitSetUserPass(retry);
} else {
consoleLog("Retry max attempt reached");
}
});
}
function expiredSession(){
$("#loggout").addClass("hidden");
$("#loggin").removeClass("hidden");
$(".locked").addClass("hidden");
clickStatusPage();
}
</script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button id="mobileMenu" type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand hidden-xs hidden-sm" href="#">WebLCM</a>
<img class="navbar-brand img-responsive visible-xs-block visible-sm-block" alt="Brand" src="/assets/img/logo_white.png" width="90" height="34" style="padding-left:2px;padding-right:0px;">
<span class="navbar-brand visible-xs-block visible-sm-block" style="padding-top:13px;padding-left:8px;padding-right:8px;">
<span id="returnDataNav" class="" style="padding-left:8px;padding-right:8px;" role="alert"></span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<form id="loggin" class="navbar-form navbar-right">
<div class="form-group">
<input type="text" id="username" placeholder="Username" class="form-control">
</div>
<div class="form-group">
<input type="password" id="password" placeholder="Password" class="form-control" onkeypress="enterKeyPress(event)">
</div>
<div class="form-group">
<input type="submit" onclick="login(0)" class="btn btn-default" href="#" value="Sign in">
</div>
</form>
<form id="loggout" class="navbar-form navbar-right hidden">
<div class="form-group">
<button type="button" onclick="clickSettingsPage(0)" class="btn btn-default" aria-label="Left Align">
<span class="glyphicon glyphicon-cog" aria-hidden="true"></span>
</button>
<a type="button" onclick="logout(0)" class="btn btn-default" href="#">Log out</a>
</div>
</form>
<ul class="nav navbar-nav navbar-right" id="mini_menu">
<li class="hidden"><a href="#">Settings</a></li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-xs-3 col-sm-3 col-md-2 sidebar hidden-xs">
<ul class="nav nav-sidebar" id="main_menu">
</ul>
</div>
<div class="col-xs-12 col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<div class="row placeholders">
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8 placeholder">
<p id="main_section"></p>
</div>
<div id="helpSection" class="col-md-4 col-lg-4 hidden-xs hidden-sm placeholder">
<div id="returnDataHelp" class="" role="alert"></div>
<img src="/assets/img/logo.png" width="320" height="87" class="img-responsive" alt="Responsive image" style="border-radius: 0%" ondragstart="return false;">
<h4>Need help?</h4>
<span id="helpText" class="text-muted">This page shows the current state of WiFi</span>
<br>
<span id="infoText" class="text-muted"></span>
</div>
</div>
</div>
</div>
</div>
</body>
</html>