-
Notifications
You must be signed in to change notification settings - Fork 155
/
index.php
1386 lines (1255 loc) · 62.7 KB
/
index.php
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
<?php
/*
Copyright (C) 2014-2015 Universitätsbibliothek Mannheim
See file LICENSE for license details.
Authors: Alexander Wagner, Stefan Weil, Dennis Müller
References:
File upload (general)
* http://www.php.net/manual/en/features.file-upload.post-method.php
File upload with dropzone
* http://www.dropzonejs.com/
* http://www.startutorial.com/articles/view/how-to-build-a-file-upload-form-using-dropzonejs-and-php
* http://maxoffsky.com/code-blog/howto-ajax-multiple-file-upload-in-laravel/
Websockets:
* https://en.wikipedia.org/wiki/Server-sent_events
* https://developer.mozilla.org/en-US/docs/WebSockets/Writing_WebSocket_client_applications
* http://code.google.com/p/phpwebsocket/
* http://dharman.eu/?menu=phpWebSocketsTutorial
Keyboard input
* http://jsfiddle.net/angusgrant/E3tE6/
* http://stackoverflow.com/questions/3181648/how-can-i-handle-arrowkeys-and-greater-than-in-a-javascript-function-which
* http://stackoverflow.com/questions/5597060/detecting-arrow-key-presses-in-javascript
* http://www.quirksmode.org/js/keys.html
Key symbols
* http://www.tcl.tk/man/tcl8.4/TkCmd/keysyms.htm
* wmctrl, suckless-tools (lsw, sprop, wmname, ...)
* display.im6, evince
Authorization
* http://aktuell.de.selfhtml.org/artikel/php/loginsystem/
Overlays
* http://answers.oreilly.com/topic/1823-adding-a-page-overlay-in-javascript/
*/
session_start();
if (isset($_REQUEST['monitor'])) {
$monitor = $_REQUEST['monitor'];
$_SESSION['monitor'] = $monitor;
} elseif (!isset($_SESSION['monitor'])) {
$_SESSION['monitor'] = '???';
}
$_SESSION['referer'] = 'index.php';
require_once('auth.php');
// Connect to database and get configuration constants.
require_once('DBConnector.class.php');
$dbcon = new palma\DBConnector();
// Support localisation.
require_once('i12n.php');
$user = false;
if (isset($_SESSION['username'])) {
# PHP session based authorization.
$username = $_SESSION['username'];
$address = $_SESSION['address'];
$user = "$username@$address";
} elseif (isset($_SERVER['PHP_AUTH_USER'])) {
# .htaccess basic authorization.
$user = $_SERVER['PHP_AUTH_USER'];
}
require_once('globals.php');
// file paths for vnc downloads
$winvnc = CONFIG_START_URL . "theme/" . CONFIG_THEME . "/winvnc-palma.exe";
$macvnc = CONFIG_START_URL . "theme/" . CONFIG_THEME . "/osx-vnc.dmg";
$linuxsh = CONFIG_START_URL . "theme/" . CONFIG_THEME . "/x11.sh";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PalMA</title>
<link rel="icon" href="theme/<?=CONFIG_THEME?>/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="pure-min.css">
<link rel="stylesheet" href="palma.css" type="text/css">
<script type="text/javascript" src="jquery.min.js"></script>
<script src="dropzone.min.js"></script>
<link
rel="stylesheet"
href="dropzone.min.css"
type="text/css"
/>
<script type="text/javascript">
// Screen section which responds to keyboard input.
var focus_section = '1';
function sendToNuc(command) {
var xmlHttp = new XMLHttpRequest();
if (!xmlHttp) {
// TODO
alert('XMLHttpRequest failed!');
return;
}
var url = 'control.php?' + command;
var response = "";
xmlHttp.open("get", url, true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 1) {
// Server connection established (IE only).
} else if (xmlHttp.readyState == 2) {
// Data transferred to server.
} else if (xmlHttp.readyState == 3) {
// Server is answering.
} else if (xmlHttp.readyState == 4) {
// Received all data from server.
return xmlHttp.responseText;
} else {
alert("Got xmlHttp.readyState " + xmlHttp.readyState);
}
};
xmlHttp.send(null);
//~ alert("sendToNuc " + url);
}
function keyControl(number, image, controlClass, key, handler, disabled, title) {
// "number" refers to the slected screensection
var keyHandler = getHandlerCommand(handler, key);
if ( (keyHandler == "") || (keyHandler == null) ) {
keyHandler = "default";
}
var button = document.createElement('button');
var icon = document.createElement('i');
if (!disabled) {
icon.setAttribute('class', image);
button.appendChild(icon);
button.setAttribute('class', controlClass);
button.setAttribute('onmousedown',
'sendToNuc("window=' + number + '&keydown=' + encodeURIComponent(keyHandler) + '")');
button.setAttribute('onmouseup',
'sendToNuc("window=' + number + '&keyup=' + encodeURIComponent(keyHandler) + '")');
button.setAttribute('title', title);
} else {
icon.setAttribute('class', image + " unavailable");
button.appendChild(icon);
button.setAttribute("class", "unavailable");
button.setAttribute('title', title + " " + "<?=addslashes(__('not available'))?>");
}
return button;
}
function downloadFile(screensection) {
// wrong path if copied to /home/directory
// TODO: check file and path
var url = document.URL;
var url_path = url.split("/");
var file = document.getElementById("file" + screensection).innerHTML;
var file = document.getElementById("file" + screensection).getAttribute("title");
// Download with download.php
var download = url_path[0]+"/"+url_path[1]+"/"+url_path[2]+"/"+url_path[3]+"/download.php?file="+encodeURIComponent(file);
var name = "Download";
if(file.indexOf("www.") > -1) {
window.open(file, name);
} else {
window.open(download, name);
}
}
function is_valid_url(url)
{
return url.match(/(^(ht|f)tps?:\/\/)([a-zA-Z0-9\.-])+(\.([a-zA-Z]{2,}))?(\:([0-9]{1,5}))?(\/([^\s\<\>\,\{\}\\\|\^\[\]\'])*)?$/);
}
function urlToNuc() {
var url = document.getElementById('url_field').value;
if (is_valid_url(url)) {
// Encode special characters
url = encodeURIComponent(url);
sendToNuc('openURL='+url);
} else {
var urlfield = document.getElementById('url_field');
urlfield.setAttribute('value', '<?=addslashes(__("Enter valid URL"))?>');
}
setTimeout(function(){location.reload()}, 1000);
}
function showLayout(layout, controls, window) {
//~ console.log("Layout: " + layout);
//~ for (i = 0; i < controls.length; i++) {
//~ console.log("SL " + i + ": " + controls[i]);
//~ }
document.onkeydown = function(evt) {
evt = evt || window.event;
var section = focus_section;
var handler = controls[focus_section][0];
var keyHandler;
//~ console.log("Key down: " + evt.keyCode);
switch (evt.keyCode) {
case 33: // page up
keyHandler = encodeURIComponent(getHandlerCommand(handler, 'prior'));
sendToNuc('window=' + section + '&key=' + keyHandler);
break;
case 34: // page down
keyHandler = encodeURIComponent(getHandlerCommand(handler, 'next'));
sendToNuc('window=' + section + '&key=' + keyHandler);
break;
case 35: // end
keyHandler = encodeURIComponent(getHandlerCommand(handler, 'end'));
sendToNuc('window=' + section + '&key=' + keyHandler);
break;
case 36: // home
keyHandler = encodeURIComponent(getHandlerCommand(handler, 'home'));
sendToNuc('window=' + section + '&key=' + keyHandler);
break;
case 37: // left
keyHandler = encodeURIComponent(getHandlerCommand(handler, 'left'));
sendToNuc('window=' + section + '&key=' + keyHandler);
break;
case 38: // up
keyHandler = encodeURIComponent(getHandlerCommand(handler, 'up'));
sendToNuc('window=' + section + '&key=' + keyHandler);
break;
case 39: // right
keyHandler = encodeURIComponent(getHandlerCommand(handler, 'right'));
sendToNuc('window=' + section + '&key=' + keyHandler);
break;
case 40: // down
keyHandler = encodeURIComponent(getHandlerCommand(handler, 'down'));
sendToNuc('window=' + section + '&key=' + keyHandler);
break;
}
};
document.onkeypress = function(evt) {
evt = evt || window.event;
//~ console.log("Key press: " + evt.keyCode);
var charCode = evt.which || evt.keyCode;
var charStr = String.fromCharCode(charCode);
var section = focus_section;
var handler = controls[focus_section][0];
var keyHandler;
switch (charStr) {
case "1": // select section 1
case "2": // select section 2
case "3": // select section 3
case "4": // select section 4
focus_section = charStr;
break;
case "+": // zoom in
keyHandler = encodeURIComponent(getHandlerCommand(handler, 'zoomin'));
sendToNuc('window=' + section + '&key=' + keyHandler);
break;
case "-": // zoom out
keyHandler = encodeURIComponent(getHandlerCommand(handler, 'zoomout'));
sendToNuc('window=' + section + '&key=' + keyHandler);
break;
}
};
var windowlist = document.getElementById('windowlist');
var entries = windowlist.getElementsByClassName('window_entry');
var screensection, file, status;
markCurrentLayout(layout);
for (var n = 0; n < window.length; n++) {
screensection = window[n].section;
file = window[n].file;
status = window[n].state;
entries[n].appendChild(addWindowControls(layout, controls, screensection, file, status));
}
}
function markCurrentLayout(layout) {
var layoutDivs = document.getElementsByClassName("screenlayout");
for (var i = 0 ; i < layoutDivs.length ; i++) {
var children = layoutDivs[i].getElementsByClassName("pure-button");
for (var k = 0 ; k < children.length ; k++) {
children[k].style.backgroundColor = "";
}
}
document.getElementById(layout).style.backgroundColor = "#232e58";
}
function miniDisplaySelect(element) {
sendToNuc('layout=' + element.id);
markCurrentLayout(element.id);
}
function getHandlerCommand(handle, task) {
// console.log("getHandlerCommand "+handle+" - "+task);
// to deactivate buttons just add 'undefined' as keystroke
var handler = [];
handler["default"] = {};
// handler["default"]["init"] = "";
handler["default"]["up"] = "Up";
handler["default"]["down"] = "Down";
handler["default"]["left"] = "Left";
handler["default"]["right"] = "Right";
handler["default"]["next"] = "Next";
handler["default"]["prior"] = "Prior";
handler["default"]["home"] = "Home";
handler["default"]["end"] = "End";
handler["default"]["zoomin"] = "ctrl+plus";
handler["default"]["zoomout"] = "ctrl+minus";
handler["default"]["download"] = "download";
handler["default"]["counterclockwise"] = "undefined";
handler["default"]["clockwise"] = "undefined";
// Handler for web pages.
handler["palma-browser"] = {};
handler["palma-browser"]["up"] = "Up";
handler["palma-browser"]["down"] = "Down";
handler["palma-browser"]["left"] = "Left";
handler["palma-browser"]["right"] = "Right";
handler["palma-browser"]["next"] = "Next";
handler["palma-browser"]["prior"] = "Prior";
handler["palma-browser"]["home"] = "Home";
handler["palma-browser"]["end"] = "End";
handler["palma-browser"]["zoomin"] = "ctrl+plus";
handler["palma-browser"]["zoomout"] = "ctrl+minus";
handler["palma-browser"]["download"] = "undefined";
handler["palma-browser"]["counterclockwise"] = "undefined";
handler["palma-browser"]["clockwise"] = "undefined";
// Handler for images.
handler["feh"] = {};
handler["feh"]["up"] = "alt+Up";
handler["feh"]["down"] = "alt+Down";
handler["feh"]["left"] = "alt+Left";
handler["feh"]["right"] = "alt+Right";
handler["feh"]["next"] = "alt+Next";
handler["feh"]["prior"] = "alt+Prior";
handler["feh"]["home"] = "undefined";
handler["feh"]["end"] = "undefined";
handler["feh"]["zoomin"] = "KP_Add";
handler["feh"]["zoomout"] = "KP_Subtract";
handler["feh"]["download"] = "download";
handler["feh"]["counterclockwise"] = "less";
handler["feh"]["clockwise"] = "greater";
// Controls in LibreOffice: no zoom in calc and writer, has to be activated first
// by pressing <Ctrl+Shift+o> (switch view mode on/off) not implemented yet
handler["libreoffice"] = {};
handler["libreoffice"]["up"] = "Up";
handler["libreoffice"]["down"] = "Down";
handler["libreoffice"]["left"] = "Left";
handler["libreoffice"]["right"] = "Right";
handler["libreoffice"]["next"] = "Next";
handler["libreoffice"]["prior"] = "Prior";
handler["libreoffice"]["home"] = "undefined";
handler["libreoffice"]["end"] = "undefined";
handler["libreoffice"]["zoomin"] = "undefined";
handler["libreoffice"]["zoomout"] = "undefined";
handler["libreoffice"]["download"] = "download";
handler["libreoffice"]["counterclockwise"] = "undefined";
handler["libreoffice"]["clockwise"] = "undefined";
// Handler for MS Excel and LibreOffice Calc documents.
handler["libreoffice-calc"] = {};
handler["libreoffice-calc"]["up"] = "Up";
handler["libreoffice-calc"]["down"] = "Down";
handler["libreoffice-calc"]["left"] = "Left";
handler["libreoffice-calc"]["right"] = "Right";
handler["libreoffice-calc"]["next"] = "Next";
handler["libreoffice-calc"]["prior"] = "Prior";
handler["libreoffice-calc"]["home"] = "Home";
handler["libreoffice-calc"]["end"] = "End";
handler["libreoffice-calc"]["zoomin"] = "undefined";
handler["libreoffice-calc"]["zoomout"] = "undefined";
handler["libreoffice-calc"]["download"] = "download";
handler["libreoffice-calc"]["counterclockwise"] = "undefined";
handler["libreoffice-calc"]["clockwise"] = "undefined";
// Handler for MS Powerpoint and LibreOffice Impress documents.
handler["libreoffice-impress"] = {};
handler["libreoffice-impress"]["up"] = "Up";
handler["libreoffice-impress"]["down"] = "Down";
handler["libreoffice-impress"]["left"] = "Left";
handler["libreoffice-impress"]["right"] = "Right";
handler["libreoffice-impress"]["next"] = "Next";
handler["libreoffice-impress"]["prior"] = "Prior";
handler["libreoffice-impress"]["home"] = "Home";
handler["libreoffice-impress"]["end"] = "End";
handler["libreoffice-impress"]["zoomin"] = "plus";
handler["libreoffice-impress"]["zoomout"] = "minus";
handler["libreoffice-impress"]["download"] = "download";
handler["libreoffice-impress"]["counterclockwise"] = "undefined";
handler["libreoffice-impress"]["clockwise"] = "undefined";
// Handler for MS Word and LibreOffice Writer documents.
handler["libreoffice-writer"] = {};
handler["libreoffice-writer"]["up"] = "Up";
handler["libreoffice-writer"]["down"] = "Down";
handler["libreoffice-writer"]["left"] = "Left";
handler["libreoffice-writer"]["right"] = "Right";
handler["libreoffice-writer"]["next"] = "Next";
handler["libreoffice-writer"]["prior"] = "Prior";
handler["libreoffice-writer"]["home"] = "undefined";
handler["libreoffice-writer"]["end"] = "undefined";
handler["libreoffice-writer"]["zoomin"] = "undefined";
handler["libreoffice-writer"]["zoomout"] = "undefined";
handler["libreoffice-writer"]["download"] = "download";
handler["libreoffice-writer"]["counterclockwise"] = "undefined";
handler["libreoffice-writer"]["clockwise"] = "undefined";
// Handler for videos.
handler["vlc"] = {};
handler["vlc"]["up"] = "undefined";
handler["vlc"]["down"] = "undefined";
handler["vlc"]["left"] = "undefined";
handler["vlc"]["right"] = "space";
handler["vlc"]["next"] = "undefined";
handler["vlc"]["prior"] = "undefined";
handler["vlc"]["home"] = "undefined";
handler["vlc"]["end"] = "undefined";
handler["vlc"]["zoomin"] = "undefined";
handler["vlc"]["zoomout"] = "undefined";
handler["vlc"]["download"] = "undefined";
handler["vlc"]["counterclockwise"] = "undefined";
handler["vlc"]["clockwise"] = "undefined";
// Handler for shared desktops (VNC).
handler["vnc"] = {};
handler["vnc"]["up"] = "Up";
handler["vnc"]["down"] = "Down";
handler["vnc"]["left"] = "Left";
handler["vnc"]["right"] = "Right";
handler["vnc"]["next"] = "undefined";
handler["vnc"]["prior"] = "undefined";
handler["vnc"]["home"] = "undefined";
handler["vnc"]["end"] = "undefined";
handler["vnc"]["zoomin"] = "plus";
handler["vnc"]["zoomout"] = "minus";
handler["vnc"]["download"] = "undefined";
handler["vnc"]["counterclockwise"] = "undefined";
handler["vnc"]["clockwise"] = "undefined";
// Handler for PDF documents.
handler["zathura"] = {};
handler["zathura"]["up"] = "Up";
handler["zathura"]["down"] = "Down";
handler["zathura"]["left"] = "Left";
handler["zathura"]["right"] = "Right";
handler["zathura"]["next"] = "Next";
handler["zathura"]["prior"] = "Prior";
handler["zathura"]["home"] = "Home";
handler["zathura"]["end"] = "End";
handler["zathura"]["zoomin"] = "plus";
handler["zathura"]["zoomout"] = "minus";
handler["zathura"]["download"] = "download";
handler["zathura"]["counterclockwise"] = "undefined";
handler["zathura"]["clockwise"] = "r";
var send_keys = handler["default"]["up"];
if (typeof(handler[handle]) !== "undefined") {
send_keys = handler[handle][task];
}
// console.log(send_keys);
return send_keys;
}
Dropzone.options.palmaDropzone = {
init: function() {
this.on("complete", function() {
if (this.getQueuedFiles().length == 0 && this.getUploadingFiles().length == 0) {
// File finished uploading, and there aren't any left in the queue.
// console.log("File(s) uploaded");
setTimeout(function() {
location.reload();
}, 1);
// location.reload(); // verlangt Eingabe von Enter zum wiederholten Schicken der Daten
}
});
}
};
function updateUserList(address, user) {
// Update the user list on screen from the table in the database.
// Get the <tbody> element which contains the user entries.
var list = document.getElementById('userlist');
// First we remove all existing <tr> elements.
while (list.firstChild) {
list.removeChild(list.firstChild);
}
if (address.length > 0) {
// Add an entry for each user. Iterate over addresses:
// One user may be connected several times with different devices.
// We don't expect more than one user from the same device.
var m;
for (m = 0; m < address.length; m++) {
var n;
for (n = 0; n < user.length; n++) {
if (address[m].userid == user[n].userid) {
break;
}
}
var device = address[m].device;
var tr = document.createElement('tr');
var td = document.createElement('td');
var i = document.createElement('i');
i.setAttribute('class', 'fa fa-fw fa-' + device);
td.appendChild(i);
td.appendChild(document.createTextNode(user[n].name));
tr.appendChild(td);
list.appendChild(tr);
}
} else {
<?php
if ($user) {
?>
// All users were disconnected.
alert("<?=addslashes(__('You were disconnected!'))?>");
window.location = 'logout.php';
<?php
} else {
?>
// If there is no user, we display an empty entry.
var tr = document.createElement('tr');
var td = document.createElement('td');
td.appendChild(document.createTextNode("\u00a0"));
tr.appendChild(td);
list.appendChild(tr);
<?php
}
?>
}
}
function addWindowPosition(layout, screensection) {
var position = document.createElement("div");
position.setAttribute("class", "position " + layout);
position.setAttribute('title', '<?=addslashes(__("Select screen section for display"))?>');
var s;
var button;
var icon;
var br;
switch (layout) {
case 'g1x1':
s = 1;
break;
case 'g1x2':
s = 2;
break;
case 'g2x1':
s = 2;
break;
case 'g1a2':
s = 3;
var layout_left = document.createElement('div');
layout_left.setAttribute("class", "layout_left");
var layout_right = document.createElement('div');
layout_right.setAttribute("class", "layout_right");
break;
case 'g2x2':
s = 4;
break;
}
for (var n = 1; n <= s; n++) {
br = '';
button = document.createElement("button");
button.setAttribute('value', n);
if (n == screensection) {
button.setAttribute("class", "selected");
}
button.setAttribute('onclick', "sendToNuc('switchWindows=TRUE&before=" + screensection + "&after='+(this.value))");
icon = document.createElement("i");
if (s == 1) {
icon.setAttribute("class", "fa fa-desktop fa-2x");
} else {
icon.setAttribute("class", "fa fa-desktop fa-1x");
}
button.appendChild(icon);
if ((layout == 'g1x2' && n == 1) || ((layout == 'g1a2' || layout == 'g2x2') && n == 2 )) {
br = document.createElement("br");
}
if (layout == 'g1a2' && n == 1) {
layout_left.appendChild(button);
} else if (layout == 'g1a2' && n > 1) {
layout_right.appendChild(button);
if (br) {
layout_right.appendChild(br);
}
} else {
position.appendChild(button);
if (br) {
position.appendChild(br);
}
}
}
if (layout == 'g1a2') {
position.appendChild(layout_left);
position.appendChild(layout_right);
}
return position;
}
function addWindowControls(layout, controls, screensection, file, status) {
var control = controls[screensection];
if (typeof control == "undefined") {
control = ["default", false, false, false, false,
false, false, false, false, false, false, false];
}
// get handler
var handler = control[0];
// up down left right zoomin zoomout home end prior next download
var up = control[1];
var down = control[2];
var left = control[3];
var right = control[4];
var zoomin = control[5];
var zoomout = control[6];
var home = control[7];
var end = control[8];
var prior = control[9];
var next = control[10];
var download = control[11];
var counterclockwise = control[12];
var clockwise = control[13];
var windowcontrols = document.createElement("div");
windowcontrols.setAttribute("class", "windowcontrols");
var topbar = document.createElement("div");
topbar.setAttribute("class", "topbar");
var button = document.createElement('button');
button.setAttribute("class", "toggle");
icon = document.createElement('i');
if (status == 'active') {
icon.setAttribute("class", "fa fa-eye");
} else {
icon.setAttribute("class", "fa fa-eye-slash");
}
icon.setAttribute('id', 'status_' + screensection);
button.setAttribute('title', '<?=addslashes(__("Toggle visibility"))?>');
button.setAttribute('onclick', "sendToNuc('window=" + screensection + "&toggle=TRUE')");
button.appendChild(icon);
topbar.appendChild(button);
topbar.appendChild(keyControl(screensection, 'fa fa-search-plus', 'zoomin', 'zoomin', handler, !zoomin, '<?=addslashes(__("Zoom in"))?>'));
topbar.appendChild(keyControl(screensection, 'fa fa-search-minus', 'zoomout', 'zoomout', handler, !zoomout, '<?=addslashes(__("Zoom out"))?>'));
topbar.appendChild(keyControl(screensection, 'fa fa-rotate-left', 'counterclockwise', 'counterclockwise', handler, !counterclockwise, '<?=addslashes(__("Rotate counterclockwise"))?>'));
topbar.appendChild(keyControl(screensection, 'fa fa-rotate-right', 'clockwise', 'clockwise', handler, !clockwise, '<?=addslashes(__("Rotate clockwise"))?>'));
var downloadbutton = keyControl(screensection, 'fa fa-download', 'download', 'download', handler, !download, '<?=addslashes(__("Download this item"))?>');
if(download) {
downloadbutton.setAttribute('onclick', 'downloadFile(' + screensection + ')');
}
topbar.appendChild(downloadbutton);
button = document.createElement('button');
button.setAttribute("class", "trash");
button.setAttribute('onclick', "sendToNuc('window=" + screensection + "&delete=" + file + "')");
button.setAttribute('title', '<?=addslashes(__("Remove this item"))?>');
icon = document.createElement('i');
icon.setAttribute("class", "fa fa-trash-o");
button.appendChild(icon);
topbar.appendChild(button);
var movement = document.createElement("div");
movement.setAttribute("class", "movement");
var jump = document.createElement("div");
jump.setAttribute("class", "jump");
jump.appendChild(keyControl(screensection, 'fa fa-angle-double-up', 'jumpbeginning', 'home', handler, !home, '<?=addslashes(__("Jump to start"))?>'));
jump.appendChild(keyControl(screensection, 'fa fa-angle-up', 'pageback', 'prior', handler, !prior, '<?=addslashes(__("Page up"))?>'));
jump.appendChild(keyControl(screensection, 'fa fa-angle-down', 'pageforward', 'next', handler, !next, '<?=addslashes(__("Page down"))?>'));
jump.appendChild(keyControl(screensection, 'fa fa-angle-double-down', 'jumpend', 'end', handler, !end, '<?=addslashes(__("Jump to end"))?>'));
var arrows = document.createElement("div");
arrows.setAttribute("class", "arrows");
arrows.appendChild(keyControl(screensection, 'fa fa-toggle-up', 'arrowup', 'up', handler, !up, '<?=addslashes(__("Up"))?>'));
arrows.appendChild(document.createElement("br"));
arrows.appendChild(keyControl(screensection, 'fa fa-toggle-left', 'arrowleft', 'left', handler, !left, '<?=addslashes(__("Left"))?>'));
arrows.appendChild(keyControl(screensection, 'fa fa-toggle-right', 'arrowright', 'right', handler, !right, '<?=addslashes(__("Right"))?>'));
arrows.appendChild(document.createElement("br"));
arrows.appendChild(keyControl(screensection, 'fa fa-toggle-down', 'arrowdown', 'down', handler, !down, '<?=addslashes(__("Down"))?>'));
movement.appendChild(jump);
movement.appendChild(arrows);
var position = addWindowPosition(layout, screensection);
// Putting it all together
windowcontrols.appendChild(topbar);
windowcontrols.appendChild(movement);
windowcontrols.appendChild(position);
return windowcontrols;
}
function updateWindowList(window){
var windowlist = document.getElementById('windowlist');
// remove old entries
while (windowlist.firstChild) {
windowlist.removeChild(windowlist.firstChild);
}
if (window.length == 0) {
var entry = document.createElement('div');
entry.setAttribute("class", "description");
entry.appendChild(document.createTextNode('<?=addslashes(__('Welcome'))?>, <?=htmlspecialchars($username)?>!'));
entry.appendChild(document.createElement("br"));
entry.appendChild(document.createTextNode('<?=addslashes(__('There is no shared content yet. Click below to get started!'))?>'));
var addbutton = document.createElement('button');
addbutton.setAttribute("class", "splash_add pure-button");
addbutton.setAttribute("onclick", "openTab(event, 'Add')");
var addtext = (document.createTextNode('<?=addslashes(__("Add"))?>'));
addbutton.appendChild(addtext);
var addicon = document.createElement("i");
addicon.setAttribute("class", "fa fa-plus");
addbutton.appendChild(addicon);
windowlist.appendChild(entry);
windowlist.appendChild(addbutton);
document.getElementById("closeWindows").style.display = "none";
document.getElementById("Layout").style.display = "none";
document.getElementById("controlbtn").className = "tablinks";
} else {
document.getElementById("closeWindows").style.display = "inline-block";
document.getElementById("Layout").style.display = "block";
document.getElementById("controlbtn").className = "tablinks active";
// Add an entry for each window.
var n;
for (n = 0; n < window.length; n++) {
var file = window[n].file;
var handler = window[n].handler;
var screensection = window[n].section;
var entry = document.createElement('div');
entry.setAttribute("class", "window_entry");
var divID = 'file' + screensection;
entry.setAttribute('id', divID);
var button = document.createElement('button');
button.setAttribute("class", "window_entry_button");
button.setAttribute('onclick', "openAccordion('" + divID + "')");
var icon = document.createElement('i');
if (handler.indexOf("palma-browser") > -1) {
icon.setAttribute("class", "fa fa-globe");
} else if (handler.indexOf("vnc") > -1) {
icon.setAttribute("class", "fa fa-video-camera");
} else if (handler.indexOf("vlc") > -1) {
icon.setAttribute("class", "fa fa-film");
} else if (handler.indexOf("feh") > -1) {
icon.setAttribute("class", "fa fa-picture-o");
} else if (handler.indexOf("zathura") > -1) {
icon.setAttribute("class", "fa fa-file-pdf-o");
} else {
icon.setAttribute("class", "fa fa-file");
}
button.appendChild(icon);
var title = decodeURI(decodeURIComponent(file));
// display only the last part of the URL or file name.
// Long names are truncated, and the truncation is indicated.
if (title.substring(0, 4) == 'http') {
// Remove a terminating slash from an URL.
// The full URL will be shown as a tooltip.
title = title.replace(/\/$/, '');
title = title.replace(/^.*\//, '');
entry.setAttribute('title', file);
} else {
// For files only the full base name is shown as a tooltip.
var fname = file;
title = title.replace(/^.*\//, '');
entry.setAttribute('title', fname);
}
if (title.length > 25) {
title = title.substring(0, 25) + '...';
}
button.appendChild(document.createTextNode(title));
var icon = document.createElement('i');
icon.setAttribute("class", "fa fa-caret-down accordion-icon");
button.appendChild(icon);
entry.appendChild(button);
windowlist.appendChild(entry);
}
}
}
function updateControlsBySection(window) {
// get section and handler for each window
var sectionControls = [];
for (n = 0; n < window.length; n++) {
var win_id = window[n].win_id;
var section = window[n].section;
var handler = window[n].handler;
// alert("Section: " + section + " - Handler: " + handler);
if (handler.indexOf("feh") > -1) {
// up down left right zoomin zoomout home end prior next download rotateleft rotateright
control = ["feh", true, true, true, true, true, true, false, false, false, false, true, true, true];
} else if (handler.indexOf("libreoffice") > -1) {
// Controls in LibreOffice: no zoom in calc and writer, has to be activated first
// by pressing <Ctrl+Shift+o> (switch view mode on/off) not implemented yet
control = ["libreoffice", true, true, true, true, false, false, false, false, true, true, true, false, false];
if (handler.indexOf("--calc") > -1) {
control = ["libreoffice-calc", true, true, true, true, false, false, true, true, true, true, true, false, false];
}
if (handler.indexOf("--impress") > -1) {
control = ["libreoffice-impress", true, true, true, true, true, true, true, true, true, true, true, false, false];
}
if (handler.indexOf("--writer") > -1) {
control = ["libreoffice-writer", true, true, true, true, false, false, false, false, true, true, true, false, false];
}
} else if (handler.indexOf("palma-browser") > -1) {
control = ["palma-browser", true, true, true, true, true, true, true, true, true, true, false, false, false];
} else if (handler.indexOf("vlc") > -1) {
control = ["vlc", false, false, false, true, false, false, false, false, false, false, false, false, false];
} else if (handler.indexOf("vnc") > -1) {
control = ["vnc", true, true, true, true, true, true, false, false, false, false, false, false, false];
} else if (handler.indexOf("zathura") > -1) {
control = ["zathura", true, true, true, true, true, true, true, true, true, true, true, false, true];
} else {
control = ["undefined", false, false, false, false, false, false, false, false, false, false, false, false, false];
}
sectionControls[section] = control;
}
// Fill empty sections with default values.
for (i = sectionControls.length; i < 5; i++) {
sectionControls[i] = ["default",
false, false, false, false,
false, false, false, false,
false, false, false, false, false];
}
return sectionControls;
}
function updateScreen() {
sendToNuc('window=all&closeOrphans=true');
}
function clearURLField(defaultText) {
var browseto = document.getElementById('url_field');
browseto.setAttribute('value', 'https://');
}
// lastJSON is used to reduce the database polling rate.
var lastJSON = '';
function pollDatabase() {
var xmlHttp = new XMLHttpRequest();
if (xmlHttp) {
xmlHttp.open("get", 'db.php?json=' + lastJSON, true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 2) {
// Data transferred to server.
} else if (xmlHttp.readyState == 3) {
// Server is answering.
} else if (xmlHttp.readyState == 4) {
// Received all data from server.
var status = xmlHttp.status;
if (status == 200) {
// Got valid response.
var text = xmlHttp.responseText;
lastJSON = text;
var db = JSON.parse(text);
if (db === null || Object.keys(db).length === 0) {
return;
}
var i;
var layout = '';
for (i = 0; i < db.setting.length; i++) {
if (db.setting[i].key == 'layout') {
layout = db.setting[i].value;
break;
}
}
var controls = updateControlsBySection(db.window);
// for (i = 0; i < controls.length; i++) {
// console.log(i + ": " + controls[i]);
// }
updateUserList(db.address, db.user);
updateWindowList(db.window);
showLayout(layout, controls, db.window);
// updateScreen(db.window);
setTimeout("pollDatabase()", 1);
} else {
// Got error. TODO: handle it.
}
} else {
// Got unexpected xmlHttp.readyState. TODO: handle it.
}
};
xmlHttp.send(null);
}
}
// Start polling the database.
pollDatabase();
function getOS() {
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
if (navigator.userAgent.indexOf("Android")!=-1) OSName="Android";
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) OSName="iOS";
/* Source for Android and iOS:
https://davidwalsh.name/detect-android
https://davidwalsh.name/detect-iphone
https://davidwalsh.name/detect-ipad */
return OSName;
}
function getFilePathByOS() {
var OSName = getOS();
var windows = 'download-winvnc';
var macOS = 'download-macvnc';
var linux = 'download-linux';
var download = '';
switch(OSName) {
case 'Windows': download = windows;
break;
case 'MacOS': download = macOS;
break;
case 'Linux': download = linux;
break;
case 'UNIX': download = linux;
break;
case 'Android':
case 'iOS':
document.getElementById("Screen").innerHTML = '<div class="description"><?=addslashes(__('Sorry! Screensharing for your device is currently not supported.'))?></div>';
break;
default: download = null;
}
document.getElementById(download).click();
}
function openTab(evt, tabName) {
var i, tabcontent, tablinks;
// Hide all elements with class="tabcontent"
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Remove "active" class from all elements with class="tablinks"
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
// Show current tab and add "active" class to the opening button
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
function openSubtab(evt, tabName, subtabName) {
var i, tab, subtabcontent, subtablinks;
// Hide all elements with class="subtabcontent"
tab = document.getElementById(tabName);
subtabcontent = tab.getElementsByClassName("subtabcontent");
for (i = 0; i < subtabcontent.length; i++) {