-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgrid.php
More file actions
executable file
·1208 lines (1102 loc) · 45.1 KB
/
Copy pathgrid.php
File metadata and controls
executable file
·1208 lines (1102 loc) · 45.1 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
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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<?php
/**************************************************************
* Hostmon - grid.php
* Author - Isaac Assegai
* This page allows the user to actively or passively monitor
* Several devices at one time. The user has the ability to
* re-arrange the page and resize the interface to the different
* devices being monitored.
**************************************************************/
include_once("php/functions.php");
include_once("php/db.php");
$userName = "Guest";
$adminLevel;
$loggedIn = false;
$yellowAlarm = getAlarm('yellow');
$redAlarm = getAlarm('red');
if(!isset($_SESSION)) session_start();
//this is really a bad idea to check if we are logged in with a get variable,
//can't seem to get the session variable to set in login-backend.php like i was planning
if(isset($_GET['login'])){ //if login has just logged us in
if($_SESSION['loggedIn']){
$userName = $_SESSION['usr'];
$adminLevel = $_SESSION['admin_level'];
$loggedIn = true;
}
}else if(isset($_SESSION)){ //if we are already logged in but just updating the page.
if($_SESSION['loggedIn']){
$userName = $_SESSION['usr'];
$adminLevel = $_SESSION['admin_level'];
$loggedIn = true;
}
}
$pageTitle = $adminLevel."Hostmon - ".$userName;
$devices = getActiveDevices($userName); // returns the initial active devices
$gridPositions = getGridPositions(count($devices)); // returns a 2d array with initial grid positions and sizes
?>
<?php if($loggedIn):?>
<html class="main_grid">
<!-- Grid.html is currently having issues with event listeners. -->
<head>
<title><?php echo $pageTitle ?></title>
<link rel="stylesheet" type="text/css" href="css/gridster.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link href="css/bootstrap-tour-standalone.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css">
<link href="css/uploadfile.css" rel="stylesheet">
<a class="menu" href="#" id="tour-menu">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</a>
<div id="onlineDot" class="dotUnknown playPager"></div>
<?php echo Menu();?>
<!-- This is the entire page, where the grid can roam. -->
<section class="grid">
<div class="gridster" id="frontGrid">
<h5 class="version"><?php echo getCurrentVersion();?></h5>
<ul class='gridlist'>
<!-- each grid is parsed from the devices array, each grid is placed using the gridPositions array. -->
<?php for($i=0;$i<count($devices);$i++) : ?>
<li href="device.php?ip=<?php echo $devices[$i]['ip'];?>" id="first" rel="#overlay" data-row="<?php echo $gridPositions[$i]['yp'] ?>" data-col="<?php echo $gridPositions[$i]['xp'] ?>" data-sizex="<?php echo $gridPositions[$i]['xs'] ?>" data-sizey="<?php echo $gridPositions[$i]['ys'] ?>" onclick="loadDevice('0');">
<button onClick="removeDevice('<?php echo $devices[$i]['id'];?>', '<?php echo $devices[$i]['ip']; ?>');" id="removeButton">Remove</button>
<img src="images/up-arrow.png" class="grow"><img src="images/down-arrow.png" class="shrink">
<div class="device_record" >
<h1><?php echo $devices[$i]['name']; ?></h1>
<h2><?php echo $devices[$i]['ip']; ?></h2>
<h3>1ms</h3>
<canvas id="<?php echo $devices[$i]['ip'];?>"></canvas>
<canvas class="graph secondImage" id="<?php echo $devices[$i]['ip'];?>"
style="display:<?php if($gridPositions[$i]['ys'] != 4){ echo 'none';}else{echo 'block';}?>;"></canvas>
<div id="statusmark"></div>
</div>
</li>
<?php endfor; ?>
<!-- embedded php based on the following code
<li href="device.php?ip=gmail.com" rel="#overlay" data-row="1" data-col="5" data-sizex="4" data-sizey="4" onclick="loadDevice('0');">
<img src="images/up-arrow.png" class="grow"><img src="images/down-arrow.png" class="shrink">
<div class="device_record">
<h1>Gmail Service</h1>
<h2>gmail.com</h2>
<h3>1ms</h3>
<canvas class="graph" id="gmail.com"></canvas><canvas class="graph secondImage" id="gmail.com"></canvas>
<div id="statusmark"></div>
</div>
</li> -->
<li data-row="7" data-col="1" data-sizex="1" data-sizey="1" id="newDeviceOpener">
<div id="addNewDeviceImageContainer">
<img src="images/plus.png" id="addNewDeviceImage">
</div>
</li>
</ul>
</div>
<div class="close"></div>
<div id="newDeviceDialog" title="Add New Device">
<form id="newDeviceForm">
<fieldset>
<input type="text" name="deviceName" id="deviceName" placeholder="Device Name" class="text ui-widget-content ui-corner-all">
<input type="text" name="deviceIP" id="deviceIP" placeholder="Device IP" class="text ui-widget-content ui-corner-all">
<input type="textarea" name="deviceNote" id="deviceNote" placeholder="Initial Note" class="textarea ui-widget-content ui-corner-all">
<!-- Allow form submission with keyboard without duplicating the dialog button -->
<!--<input type="submit" id="newDeviceSubmit">-->
</fieldset>
</form>
</div>
</section>
<!-- overlayed element -->
<div class="apple_overlay" id="overlay">
<!-- the external content is loaded inside this tag -->
<div class="contentWrap"></div>
<script type="text/javascript" src="js/jquery.tools.min.js"></script>
<script src="js/jquery-ui.js"></script>
<script src="js/jquery.md5.js"></script>
<script src="js/menu.js"></script>
<script src="js/hostmonChart.js"></script>
<script type="text/javascript" src="js/jquery.gridster.min.js" charster="utf-8"></script>
<script src="js/bootstrap-tour-standalone.min.js"></script>
<script src="js/uploadfile.min.js"></script>
<script type="text/javascript">
var gridster = 0;
var dragged = false; // Used to keep the device.php overlay from loading when a grid is being dragged.
var gridGraphTimeOut; //Used to disable ajax updating of the page when device.php is overlayed.
var tour; //used to construct tours
var overlay; //Overlay used to display device.
var adminLevel = <?php echo $adminLevel; ?>;
var redAudioElement; //used to play alarms with audioElement.play();
var yellowAudioElement; //used to play alarms with audioElement.play();
var yellowAlarm = "<?php echo $yellowAlarm; ?>";
var redAlarm = "<?php echo $redAlarm; ?>";
var newDeviceDialog = $("#newDeviceDialog");
var resizing = false; //Used to keep overlay from opening when pressed grow button.
//Initialize Gridster
gridster = $("#frontGrid > ul").gridster({
widget_margins: [5, 5],
widget_base_dimensions: [95, 95],
min_cols: 8,
draggable: {
start: function(event, ui) {
console.log("dragged");
dragged = true; //keeps overlay from loading while we are dragging.
},
stop: function(event, ui) {
console.log("stopped dragging");
// dragged = false;
}
}
}).data('gridster');
var onMouseWheel = function(e) {
var browser = $.browser;
e = e.originalEvent;
var delta = e.wheelDelta>0||e.detail<0?1:-1;
delta = 0 - delta;
// alert(delta);
//scrolling only works on mozilla with an html tag
//scrolling only works on safari/opera with a body tag.
if ($.browser.mozilla && $.browser.version >= "1.8" ){
var scrollTop = $("html").scrollTop();
$("html").scrollTop(scrollTop+(delta*15));
}else{
var scrollTop = $("body").scrollTop();
$("body").scrollTop(scrollTop+(delta*15));
}
}
$("body").bind("mousewheel DOMMouseScroll", onMouseWheel);
//Initialize and draw every canvas on the page.
c = initializeCanvas("can1");
for(i = 0; i < c.length; i++){
canvas = c[i];
canvas.height = canvas.width/3;
colorCanvas(canvas, "#51bbff");
drawGraph(canvas);
}
// Separates a string in ajax. Probably Used for adding a new device?
function getMessage(result){
var message = result.substring(0, result.indexOf("|"));
return message;
}
// Separates a string in ajax. Probably Used for adding a new device?
function getDisplay(result){
var display = result.substring(result.indexOf("|")+1, result.length);
return display;
}
//sends ajax call to server to remove device with $id from active_devices table
function removeDevice(id, ip){
console.log("removeDevice("+id+");");
var postData = {
removeDevice:id
};
$.ajax({
type:"POST",
data : postData,
url: 'php/grid-backend.php',
success: function(result,status,xhr) {
var message = getMessage(result);
var display = getDisplay(result);
console.log("removeDevice success: " + message);
if(message.indexOf("DeviceExists") != -1){
//$(".ui-dialog-title").html("holy crap")
//alert();
}
//quick and dirty hack, reload the page
location.reload();
// alert("message: " + message);
// alert("display: " + display);
},
complete: function(result,status,xhr) {
//alert("complete: " + result);
},
error: function(xhr,status,error){
alert("Error in addNewDevice ajax call: " + error);
}
});
}
//Sends an ajax call to the server to add a new device, then it displays it.
function addNewDevice(){
var deviceName = $("#deviceName").val();
var deviceIP = $("#deviceIP").val();
var deviceNote = $("#deviceNote").val();
//alert(deviceName + deviceIP + deviceNote);
var postData = {
addNewDevice:'true',
deviceName:deviceName,
deviceIP:deviceIP,
deviceNote:deviceNote,
userName:'<?php echo $userName; ?>'
};
// alert(JSON.stringify(postData));
$.ajax({
type:"POST",
data : postData,
url: 'php/grid-backend.php',
success: function(result,status,xhr) {
var message = getMessage(result);
var display = getDisplay(result);
if(message.indexOf("DeviceExists") != -1){
//$(".ui-dialog-title").html("holy crap")
//alert();
}
var ps = getNewGridPositionAndSize(); //Finds where we are supposed to place the new grid.
var widget = gridster.add_widget( display, ps[0], ps[1], ps[2], ps[3]); //adds a new grid to gridster
//overlay.overlay(overlay.getConf());//re-register overlay listeners?
widget = widget.get(0);
var grow = $(widget).find(".grow");
location.reload(); //shortcut hack for adding new devices.
// alert("message: " + message);
// alert("display: " + display);
},
complete: function(result,status,xhr) {
//alert("complete: " + result);
$("li[rel]").overlay(overlay.getConf());
},
error: function(xhr,status,error){
alert("Error in addNewDevice ajax call: " + error);
}
});
newDeviceDialog.dialog( "close" ); //closes the add new device dialog.
}
// Finds the last grid position, and positions a device at the position of the newDeviceOpener
function getNewGridPositionAndSize(){
var sizeX = $("#newDeviceOpener").attr("data-sizex");
var sizeY = $("#newDeviceOpener").attr("data-sizey");
var posX = $("#newDeviceOpener").attr("data-col");
var posY = $("#newDeviceOpener").attr("data-row");
var returnVal = [sizeX, sizeY, posX, posY];
return returnVal;
}
// Used to be used to load the device, now it only makes sure that when a device is loaded, drag resets.
function loadDevice(id) {
//if(!dragged){
//loading the device now happens when user clicks the li[rel]
//this function only resets the dragged variable now.
//} // RESET DRAGGED SINCE CLICK EVENT IS FIRED AFTER drag stop
//dragged = 0;
}
// Resizes a grid when the user clicks on a "grow button".
//$('.grow').on('click', function(event) {
//COME BACK
$(".gridlist").on('click', '.grow', function(event){
resizing = true;
event.stopImmediatePropagation(); // this stops the overlay from popping up.
//event.preventDefault(); // this stops the overlay from popping up.
var grid = gridster;
var widget = $(this).parent();
var xSize = widget.attr("data-sizex");
var ySize = widget.attr("data-sizey");
// We need to figure out the size to grow to, based on the current grid size.
var x = 0;
var y = 0;
if(xSize == 1 && ySize == 1){
x = 2;
y = 2;
}else if(xSize == 2 && ySize == 2){
x = 4;
y = 2;
}else if(xSize == 4 && ySize == 2){
x = 4;
y = 4;
}else{ // do nothing, we are as big as we get.
x = xSize;
y = ySize;
}
var can = $(widget).children(".device_record").children("canvas");
var data = updateGridGraphData(can, x, y); // Redraw the Canvas charts in this grid.
if(y == 4){ //If our grid is 4 rows high, we want to show the hourly graph as well.
updateGridGraphData(can[1], x, y); // Get info from server and draw the hourly graph.
$(can[1]).show(); //make sure it's visible
}else{
updateGridGraphData(can[1], x, y); //draw the hourly graph even if it's hidden in this case.
$(can[1]).hide(); //make sure it's invisible
}
grid.resize_widget(widget, x, y, true); // Resizes the grid itself. May want to do this before redrawing the graphs.
}); // End of grow code.
// Resizes a grid widget whenever a user clicks it's "shrink button"
$('.gridlist').on('click', '.shrink', function(event) {
event.stopImmediatePropagation(); // Stop the device.php page from popping up when shrink button is clicked.
var grid = gridster;
var widget = $(this).parent();
var xSize = widget.attr("data-sizex");
var ySize = widget.attr("data-sizey");
//Figure out what size to shrink the widget to based on its current size.
var x = 0;
var y = 0;
if(xSize == 1 && ySize == 1){ //we are as small as we get, keep this size.
x = xSize;
y = ySize;
}else if(xSize == 2 && ySize == 2){
x = 1;
y = 1;
}else if(xSize == 4 && ySize == 2){
x = 2;
y = 2;
}else{ // do nothing, we are as big as we get.
x = 4;
y = 2;
}
// Get the graph on this widget and update it.
var can = $(widget).children(".device_record").children("canvas");
var data = updateGridGraphData(can, x, y); // Retrieve data from server and display on graph.
if(y == 4){ // A widget with 4 rows should display the hourly graph as well as the minute one.
updateGridGraphData(can[1], x, y); // Get info from server and draw the hourly graph.
$(can[1]).show(); //make sure it's visible
}else{
$(can[1]).hide(); //make sure it's invisible
}
grid.resize_widget(widget, x, y, true); // Resize the widget itself. May want to put this before the drawing code above.
}); //End of Shrink event.
// Event Called when user opens a device. This load's and overlays the device.php page over grid.php.
overlay = $("li[rel]").overlay({
top:top,
mask: 'darkred',
effect: 'apple',
fixed: false,
top: '1%',
onBeforeLoad: function(event) {
if(dragged){
console.log("yes dragged");
dragged = false;
return false; //when dragging, don't popup.
}else{
console.log("no dragged");
}
var targ = event.target.className;
console.log("target: " + targ);
console.log("loading overlay menu Open: " + menuOpen);
if(menuOpen){
//The following code is repeaded here and in menu.js
console.log("close menu");
clearTimeout(getBackendRunningTimeout); // Remove the timer.
clearTimeout(menuTimeout); // Remove the timer.
$('body').removeClass('menu-open');
$('nav').removeClass('open');
$(".ajax-file-upload-container").fadeOut(); //cause upload messages to disappear
$("#eventsmessage").fadeOut(); //cause upload messages to disappear
menuOpen = false;
return false;
}
if(targ == "grow" || targ == "shrink"){
console.log("target was grow or shrink");
//return false;
this.getOverlay().close(); //prevent overlay from opening.
}
clearTimeout(gridGraphTimeOut); // disable updating of the main page, when second page is open.
var wrap = this.getOverlay().find(".contentWrap"); // grab wrapper element inside content
console.log(wrap);
wrap.load(this.getTrigger().attr("href")); // load the page specified in the trigger (the device clicked) to the overlay
},
onClose: function() {
$('.menu').fadeIn(); // Fade the menu button back in when the overlay is closed.
gridGraphTimeOut = setTimeout(updateGridGraphs, 5000); // Re-allow updating of main page when second page closes.
// Are we re-initializing gridster here? Do we need to do this?
gridster = $("#frontGrid > ul").gridster({
widget_margins: [5, 5],
widget_base_dimensions: [95, 95],
min_cols: 8,
draggable: {
start: function(event, ui) {
dragged = true;
}
}
}).data('gridster');
if(!tour.ended())tour.next();
},// End onClose.
onLoad: function() {
// tour.redraw();
if(!tour.ended()) tour.next();
},
api: true
}); // End overlay Event.
//$("#newDeviceDialog").parents('div').css("border-color", "white");
// Contructs and adds a new device dialog to the screen.
newDeviceDialog.dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
},
buttons: [ { text: "Add Device", id: "addDeviceButton", click: function() { addNewDevice(); } } ]
}); //End of newDeviceDialog.
// Handles when a user clicks on the new Device Button.
$( "#newDeviceOpener" ).click( function(event) {
if(!dragged){
if(!menuOpen) //only want to open dialog if the menu is not open
newDeviceDialog.dialog( "open" ); // Opens the new device dialog.
}else{
//Don't do anything, but set dragged to false.
dragged = false;
}
if(!tour.ended())tour.next();
}); // End of newDeviceOpener click handler
// Event Handler called when document is first loaded. Intializes the update of the grid graphs.
$(document).ready(function() {
newDeviceDialog = $("#newDeviceDialog");
setTimeout('updateGridGraphs()',10);
//alert("about to set menu config info");
setMenuConfigInfo(true); //we don't want it to start repeating
/*setup alarms*/
/*
redAudioElement = document.createElement('audio');
redAudioElement.setAttribute('src', 'alarms/firePager.mp3');
redAudioElement.setAttribute('preload', 'preload');
redAudioElement.setAttribute('id', 'redAudioElement');
yellowAudioElement = document.createElement('audio');
yellowAudioElement.setAttribute('src', 'alarms/bleep.mp3');
yellowAudioElement.setAttribute('preload', 'preload');
yellowAudioElement.setAttribute('id', 'yellowAudioElement');
$.get();
redAudioElement.addEventListener("load", function() {
}, true);
$('.playPager').click(function() {
redAudioElement.play();
});
$('.pausePager').click(function() {
redAudioElement.pause();
});
yellowAudioElement.addEventListener("load", function() {
}, true);
$('.playBleep').click(function() {
yellowAudioElement.play();
});
$('.pauseBleep').click(function() {
yellowAudioElement.pause();
});
*/
/*
$("#yellowuploader").uploadFile({
url:"php/uploadFile.php",
acceptFiles: "audio/*",
fileName:"myfile",
onLoad:function(obj){
},
onSubmit:function(files){
if (files.toString().toLowerCase().indexOf("mp3") >= 0){
}else{
$("#eventsmessage").html($("#eventsmessage").html()+"<br/>Error, wrong file format. .mp3 ONLY!");
return false;
}
},
onSuccess:function(files,data,xhr,pd){
$("#eventsmessage").html($("#eventsmessage").html()+"<br/>Success for: "+JSON.stringify(data));
},
afterUploadAll:function(obj){
$("#eventsmessage").html($("#eventsmessage").html()+"<br/>All files are uploaded");
},
onError: function(files,status,errMsg,pd){
$("#eventsmessage").html($("#eventsmessage").html()+"<br/>Error for: "+JSON.stringify(errMsg));
},
onCancel:function(files,pd){
$("#eventsmessage").html($("#eventsmessage").html()+"<br/>Canceled files: "+JSON.stringify(files));
}
});
$("#reduploader").uploadFile({
url:"php/uploadFile.php",
acceptFiles: "audio/*",
fileName:"myfile",
onLoad:function(obj){
},
onSubmit:function(files){
if (files.toString().toLowerCase().indexOf("mp3") >= 0){
}else{
$("#eventsmessage").html($("#eventsmessage").html()+"<br/>Error, wrong file format. .mp3 ONLY!");
return false;
}
},
onSuccess:function(files,data,xhr,pd){
$("#eventsmessage").html($("#eventsmessage").html()+"<br/>Success for: "+JSON.stringify(data));
},
afterUploadAll:function(obj){
$("#eventsmessage").html($("#eventsmessage").html()+"<br/>All files are uploaded");
},
onError: function(files,status,errMsg,pd){
$("#eventsmessage").html($("#eventsmessage").html()+"<br/>Error for: "+JSON.stringify(errMsg));
},
onCancel:function(files,pd){
$("#eventsmessage").html($("#eventsmessage").html()+"<br/>Canceled files: "+JSON.stringify(files));
}
});
*/
tour = new Tour({
debug: true,
steps: [
{
element: "#tour-menu",
title: "Welcome To Hostmon!",
content: "You can use hostmon to continously monitor the latency to any device on the public internet."
},
{
element: "#newDeviceOpener",
title: "Adding A Device",
content: "Click the + symbol to add a new device.",
onShow: function(){
//we want to close the $newDeviceDialog incaase its open from the next step of the tour
//$("#newDeviceDialog").dialog("close");
newDeviceDialog.dialog("close");
}
},
{
element: "#deviceName",
title: "Insert Device Name",
content: "This is the name you will be referring to this device by in Hostmon.",
onShow: function(){
//$( "#newDeviceDialog" ).dialog( "open" ); // Opens the new device dialog.
newDeviceDialog.dialog( "open" ); // Opens the new device dialog.
}
},
{
element: '#deviceIP',
title: "Insert Ip / Hostname",
content: "This can be an IP, Hostname, or Domain name. Anything you can ping should work."
},
{
element: '#deviceNote',
title: "Make A Note About Device",
content: "Make a note to help yourself remember why you are adding this device. This note will show in the device page."
},
{
element: '#addDeviceButton',
title: "Click Add Device",
content: "The device you added will starting being monitored immediately."
},
{
element: '#first',
title: "You first Device",
content: "Each Device Box shows you the status of that device at a glance.",
onShow: function(){
//$("#newDeviceDialog").dialog("close");
newDeviceDialog.dialog("close");
}
},
{
element: '#first',
placement: "bottom",
title: "Resizing",
content: "Use the White arrows to resize the box. You can also drag and drop all boxes to different locations.",
onShow: function(){
//$("#newDeviceDialog").dialog("close");
newDeviceDialog.dialog("close");
}
},
{
element: '#first',
title: "Click the Graph",
content: "This will bring up the device page. ",
template: "<div class='popover tour'> \
<div class='arrow'></div> \
<h3 class='popover-title'></h3> \
<div class='popover-content'></div> \
<div class='popover-navigation'> \
<button class='btn btn-default' data-role='prev'>« Prev</button> \
<span data-role='separator'>|</span> \
<button class='btn btn-default' data-role='end'>End tour</button> \
</div> \
</div>",
},
{
element: '#FiveMinuteLine',
title: "5 Minute Graph",
content: "The 5 Minute graph shows the last 5 minutes of history in 15 second increments.",
},
{
title: "Hourly Graph",
content: "Click here to pull up the Hourly graph. The Hourly graph shows the last Hour of history in 5 minute increments.",
template: "<div class='popover tour'> \
<div class='arrow'></div> \
<h3 class='popover-title'></h3> \
<div class='popover-content'></div> \
<div class='popover-navigation'> \
<button class='btn btn-default' data-role='prev'>« Prev</button> \
<span data-role='separator'>|</span> \
<button class='btn btn-default' data-role='end'>End tour</button> \
</div> \
</div>",
placement: "bottom"
},
{
element: '#dayLineHandle',
title: "Daily Graph",
content: "Click here to pull up the Daily Graph. The Daily Graph shows the last Day of History in Hourly increments.",
placement: "bottom",
template: "<div class='popover tour'> \
<div class='arrow'></div> \
<h3 class='popover-title'></h3> \
<div class='popover-content'></div> \
<div class='popover-navigation'> \
<button class='btn btn-default' data-role='prev'>« Prev</button> \
<span data-role='separator'>|</span> \
<button class='btn btn-default' data-role='end'>End tour</button> \
</div> \
</div>",
},
{
element: '#FiveMinutePolar',
title: "Five Minute Polar Chart",
content: "This chart gives quick reference so we can see the distribution of values at a glance.",
placement: "left"
},
{
element: '#hourPolarHandle',
title: "Click Hourly Polar Graph",
content: "The hourly Polar Graph gives us a quick reference so we can see the hourly distribution of values at a glance.",
template: "<div class='popover tour'> \
<div class='arrow'></div> \
<h3 class='popover-title'></h3> \
<div class='popover-content'></div> \
<div class='popover-navigation'> \
<button class='btn btn-default' data-role='prev'>« Prev</button> \
<span data-role='separator'>|</span> \
<button class='btn btn-default' data-role='end'>End tour</button> \
</div> \
</div>",
placement: "left"
},
{
element: '#dayPolarHandle',
title: "Click Day Polar Graph",
content: "The daily Polar Graph gives us a quick reference so we can see the daily distribution of values at a glance.",
template: "<div class='popover tour'> \
<div class='arrow'></div> \
<h3 class='popover-title'></h3> \
<div class='popover-content'></div> \
<div class='popover-navigation'> \
<button class='btn btn-default' data-role='prev'>« Prev</button> \
<span data-role='separator'>|</span> \
<button class='btn btn-default' data-role='end'>End tour</button> \
</div> \
</div>",
placement: "left"
},
{
element: '.plus',
title: "Click + to Add Notes",
content: "Adding notes is useful for tracking issues with a device. Notes can be left and reviewed for every use. Click the + button to start adding a new note now.",
template: "<div class='popover tour'> \
<div class='arrow'></div> \
<h3 class='popover-title'></h3> \
<div class='popover-content'></div> \
<div class='popover-navigation'> \
<button class='btn btn-default' data-role='prev'>« Prev</button> \
<span data-role='separator'>|</span> \
<button class='btn btn-default' data-role='end'>End tour</button> \
</div> \
</div>",
placement: "bottom"
},
{
element: '#noteInputText',
title: "Input Your Note Here",
content: "Input any notes or observations you have about this device here.",
placement: "left"
},
{
element: '#noteSubmitButton',
title: "Click Submit to submit note.",
content: "This note will be viewable by all other users.",
template: "<div class='popover tour'> \
<div class='arrow'></div> \
<h3 class='popover-title'></h3> \
<div class='popover-content'></div> \
<div class='popover-navigation'> \
<button class='btn btn-default' data-role='prev'>« Prev</button> \
<span data-role='separator'>|</span> \
<button class='btn btn-default' data-role='end'>End tour</button> \
</div> \
</div>",
placement: "bottom"
},
{
element: 'a.close',
title: "Click the X to close this device.",
content: "All devices are monitored in the background all the time. Click the X and you will be able to explore other devices.",
template: "<div class='popover tour'> \
<div class='arrow'></div> \
<h3 class='popover-title'></h3> \
<div class='popover-content'></div> \
<div class='popover-navigation'> \
<button class='btn btn-default' data-role='prev'>« Prev</button> \
<span data-role='separator'>|</span> \
<button class='btn btn-default' data-role='end'>End tour</button> \
</div> \
</div>",
placement: "left",
},
{
element: "#onlineDot",
title: "Backend Indicator",
content: "Indicator Light shows Green when the backend is running, and red when it is not.",
placement: "bottom"
},
{
element: '#tour-menu',
title: "Click the Menu Icon",
content: "The menu gives you the ability to adjust account and machine settings.",
template: "<div class='popover tour'> \
<div class='arrow'></div> \
<h3 class='popover-title'></h3> \
<div class='popover-content'></div> \
<div class='popover-navigation'> \
<button class='btn btn-default' data-role='prev'>« Prev</button> \
<span data-role='separator'>|</span> \
<button class='btn btn-default' data-role='end'>End tour</button> \
</div> \
</div>",
placement: "left",
},
{
element: ".changePassword2",
title: "Change Password",
content: "You can change your password here. Input your new password two times, and click the set button. The password field will blink blue if your password has been changed successfully, and it will blink red if not.",
placement: "bottom"
}
]});
//Check if user is an admin, if they are then show them the admin tour of the menu.
if(adminLevel == 10){
//Since we already have some of the data we want encoded at the title attirbute of several
//menu options, we are just going to grab that info straight from the DOM and display
//it in our tour.
var avgGoalTitle = $("#avgGoalTitle").attr("title");
var startingThreadsTitle = $("#startingThreadsTitle").attr("title");
var maxThreadsTitle = $("#maxThreadsTitle").attr("title");
var tRemovalTitle = $("#tRemovalTitle").attr("title");
var tAddTitle = $("#tAddTitle").attr("title");
var runsPerThreadTitle = $("#runsPerThreadTitle").attr("title");
var pingsDBTitle = $("#pingsDBTitle").attr("title");
var minuteAgeTitle = $("#minuteAgeTitle").attr("title");
var hourAgeTitle = $("#hourAgeTitle").attr("title");
var dayAgeTitle = $("#dayAgeTitle").attr("title");
var weekAgeTitle = $("#weekAgeTitle").attr("title");
var pingMinuteTitle = $("#pingMinuteTitle").attr("title");
var pingHourTitle = $("#pingHourTitle").attr("title");
var pingDayTitle = $("#pingDayTitle").attr("title");
var pingWeekTitle = $("#pingDayTitle").attr("title");
tour.addStep({
element: "#stopStartButton",
title: "Start/Stop the Backend.",
content: "<font color='red'>Admin Only Option.</font> <br> Hit the start button and a command will be sent to the backend to start. <br> Hit the stop button and a command will be sent to the backend to stop. <br> If succussfully started the Message 'Backend Started' will flash in green letters. <br> If succussfully stopped the words 'Backend Stopped' will flash in red.",
placement: "right"
});
tour.addStep({
element: ".adminLvl",
title: "Add New User",
content: "<font color='red'>Admin Only Option.</font> <br> Set username and password. <br> <br> Admin LVL's: <br> 0: Unapproved sign up. - This user cannot yet login. <br> 1 - 9: Normal Users - Cannot access admin functions. <br> 10: Admin - Can do anything.",
placement: "bottom"
});
tour.addStep({
element: ".removeUserErrorOutput",
title: "Remove User",
content: "<font color='red'>Admin Only Option.</font> <br> Input user name and hit set to remove given user.",
placement: "bottom"
});
tour.addStep({
element: "#averageGoalButton",
title: "Average Goal Time Per Ping",
content: "<font color='red'>Admin Only Option.</font> <br> " + avgGoalTitle + " <br> A Minimum of 5000ms is recommended.",
placement: "bottom"
});
tour.addStep({
element: "#startingThreadsButton",
title: "Starting Threads",
content: "<font color='red'>Admin Only Option.</font> <br> " + startingThreadsTitle + " <br> The higher this value, the larger the memory requirements of the backend when initially ran.",
placement: "right"
});
tour.addStep({
element: "#maxThreadsButton",
title: "The maximum amount of threads the backend can run at a single time.",
content: "<font color='red'>Admin Only Option.</font> <br> " + maxThreadsTitle + " <br> A Minimum of 10 and a maximum of 75 threads is recommended.",
placement: "right"
});
tour.addStep({
element: "#tRemovalButton",
title: "Thread Removal Co-efficient",
content: "<font color='red'>Admin Only Option.</font> <br> " + tRemovalTitle,
placement: "right"
});
tour.addStep({
element: "#tAddButton",
title: "Thread Adding Co-efficient",
content: "<font color='red'>Admin Only Option.</font> <br> " + tAddTitle,
placement: "right"
});
tour.addStep({
element: "#runsPerThreadButton",
title: "Runs / Thread",
content: "<font color='red'>Admin Only Option.</font> <br> " + runsPerThreadTitle + " <br> A value of 5 seems normal.",
placement: "right"
});
tour.addStep({
element: "#pingsDBButton",
title: "Pings / DB Call",
content: "<font color='red'>Admin Only Option.</font> <br> " + pingsDBTitle + " <br> A higher value means the DB gets written to less, and will be under less stress. However the time between updates on the front end will suffer accordingly.",
placement: "right"
});
tour.addStep({
element: "#minuteAgeButton",
title: "Minute Graph Aging",
content: "<font color='red'>Admin Only Option.</font> <br> " + minuteAgeTitle + " <br> 9,000,000 ms is default.",
placement: "right"
});
tour.addStep({
element: "#hourAgeButton",
title: "Hour Graph Aging",
content: "<font color='red'>Admin Only Option.</font> <br> " + hourAgeTitle + " <br> 14,400,000 is default.",
placement: "right"
});
tour.addStep({
element: "#dayAgeButton",
title: "Day Graph Aging",
content: "<font color='red'>Admin Only Option.</font> <br> " + dayAgeTitle + " <br> 345,600,000 is default.",
placement: "right"
});
tour.addStep({
element: "#weekAgeButton",
title: "Week Graph Aging",
content: "<font color='red'>Admin Only Option.</font> <br> " + weekAgeTitle + " <br> 2,419,200,000 is default.",
placement: "right"
});
tour.addStep({
element: "#pingMinuteButton",
title: "Time Averaged in Hour Table",
content: "<font color='red'>Admin Only Option.</font> <br> " + pingMinuteTitle + " <br> 300,000 is default.",
placement: "right"
});
tour.addStep({
element: "#pingHourButton",
title: "Time Averaged in Day Table",
content: "<font color='red'>Admin Only Option.</font> <br> " + pingHourTitle + " <br> 3,600,000 is default.",
placement: "right"
});
tour.addStep({
element: "#pingDayButton",
title: "Time Averaged in Week Table",
content: "<font color='red'>Admin Only Option.</font> <br> " + pingDayTitle + " <br> 86,400,000 is default.",
placement: "right"
});
tour.addStep({
element: "#pingWeekButton",
title: "Time Averaged in Year Table",
content: "<font color='red'>Admin Only Option.</font> <br> " + pingWeekTitle + " <br> 604,800,000 is default.",
placement: "right"
});
}
//Last Step of tour, used if user is an admin, or not
tour.addStep({
element: "#logoutButton",
title: "Logout Here",
content: "Logout to keep those dirty good for nothings away from your precious hostmon.",
placement: "top"
});
// Initialize the tour
tour.init();
// Start the tour
tour.start();
});
// Query the server and redraw a specific graphs data.
function drawGridGraph(c, data, col, row){
var array_data = String(data).split(" "); // Seperate the data into an array.
var parent = $(c).parent(); // The Canvas' Parent
var grandparent = $(parent).parent(); //The Canvas' Grandparent.
var width = $(grandparent).width(); // We need the Grandparents dimensions to know the canvas' limits.
var height = $(grandparent).height();
var widthLimit = width;
var heightLimit = height;
// The problem is, we aren't checking if this is a 2nd image, it's taking
// the value from the hour table.
if(array_data[0] == "737"){
var hello = "hello";
}
if(!$(c).hasClass("secondImage")){ // we don't want to update color when hour graph is processed