Completed work on mobile guest sharing page.
Ylian Saint-Hilaire committed
Jan 5, 2022 at 11:57 UTC
d6583706ac3b0c0f228eaed0e3d0cb9957953f5b
2 files changed
+45
-2689
views/sharing-mobile-old.handlebars
deleted
-2486
@@ -1,2486 +0,0 @@
1
-<!DOCTYPE html>
2
-<html lang="en" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
3
-<head>
4
- <meta charset="utf-8">
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
- <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
- <meta name="viewport" content="user-scalable=1.0,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0" />
8
- <meta name="format-detection" content="telephone=no" />
9
- <meta name="robots" content="noindex,nofollow">
10
- <link type="text/css" href="styles/style.css" media="screen" rel="stylesheet" title="CSS" />
11
- <link type="text/css" href="styles/style-sharing.css" media="screen" rel="stylesheet" title="CSS" />
12
- <link type="text/css" href="styles/xterm.css" media="screen" rel="stylesheet" title="CSS" />
13
- <link rel="apple-touch-icon" href="/favicon-303x303.png" />
14
- <meta name="apple-mobile-web-app-capable" content="yes">
15
- <meta name="apple-mobile-web-app-status-bar-style" content="#ffffff">
16
- <meta name="apple-mobile-web-app-title" content="{{{title}}}">
17
- <script type="text/javascript" src="scripts/common-0.0.1{{min}}.js"></script>
18
- <script type="text/javascript" src="scripts/amt-redir-ws-0.1.0{{{min}}}.js"></script>
19
- <script type="text/javascript" src="scripts/amt-wsman-ws-0.2.0{{{min}}}.js"></script>
20
- <script type="text/javascript" src="scripts/agent-redir-ws-0.1.1{{{min}}}.js"></script>
21
- <script type="text/javascript" src="scripts/agent-redir-rtc-0.1.0{{{min}}}.js"></script>
22
- <script type="text/javascript" src="scripts/agent-desktop-0.0.2{{min}}.js"></script>
23
- <script type="text/javascript" src="scripts/amt-desktop-0.0.2{{min}}.js"></script>
24
- <script type="text/javascript" src="scripts/amt-terminal-0.0.2{{min}}.js"></script>
25
- <script type="text/javascript" src="scripts/zlib{{min}}.js"></script>
26
- <script type="text/javascript" src="scripts/zlib-inflate{{min}}.js"></script>
27
- <script type="text/javascript" src="scripts/zlib-adler32{{min}}.js"></script>
28
- <script type="text/javascript" src="scripts/zlib-crc32{{min}}.js"></script>
29
- <script type="text/javascript" src="scripts/amt-terminal-0.0.2{{min}}.js"></script>
30
- <script type="text/javascript" src="scripts/xterm{{{min}}}.js"></script>
31
- <script type="text/javascript" src="scripts/xterm-addon-fit{{{min}}}.js"></script>
32
- <script keeplink=1 type="text/javascript" src="scripts/filesaver.min.js"></script>
33
- <title>{{{title}}}</title>
34
- <style>
35
-
36
- .deskButton {
37
- box-shadow: 0px 0px 10px #000;
38
- border-radius:20px;
39
- position:absolute;
40
- right:10px;
41
- top:10px;
42
- cursor:pointer;
43
- background-color:#AAA;
44
- z-index:1000;
45
- }
46
-
47
- .menuButton{
48
- box-shadow: 0px 0px 10px #000;
49
- border-radius:10px;
50
- display:inline-block;
51
- width:120px;
52
- background-color:#AAA;
53
- text-align:center;
54
- padding:8px;
55
- cursor:pointer;
56
- margin:10px;
57
- z-index:1000;
58
- }
59
-
60
- #dialog {
61
- z-index:1000;
62
- background-color:#EEE;
63
- box-shadow:0px 0px 15px #666;
64
- font-family:Arial,Helvetica,sans-serif;
65
- border-radius:5px;
66
- position:fixed;
67
- top:90px;
68
- width:300px;
69
- }
70
-
71
- .night #dialog {
72
- color: black;
73
- background-color:#AAA;
74
- }
75
-
76
- </style>
77
-</head>
78
-<body style="overflow:hidden;background-color:black;margin:0;padding:0;border:0;font-size:13px;font-family:\'Trebuchet MS\', Arial, Helvetica, sans-serif">
79
- <div id=p11 class="noselect" style="overflow:hidden;position:absolute;left:0;top:0;right:0;bottom:32px;display:none">
80
- <div id=p10dialog style="z-index:1000;background-color:#EEE;box-shadow:0px 0px 15px #666;font-family:Arial,Helvetica,sans-serif;border-radius:5px;position:fixed;top:30px;width:300px;left:30px;display:none">
81
- <div style="width:100%;background-color:#003366;color:#FFF;border-radius:5px 5px 0 0">
82
- <div style=padding:5px>Keyboard Shortcuts Customization</div>
83
- <div style=width:100%;margin:6px></div>
84
- </div>
85
- <div style="margin-right:16px;margin-left:8px"><div id=p10dialog2 style="margin:auto;margin:3px"></div></div>
86
- <div style="padding:10px;margin-bottom:20px"><input type="button" value="OK" style="float:right;width:80px" onclick="deskCustomizeKeysEx()"></div>
87
- </div>
88
- <img id="deskkeybutton1" src="images/mobile-desk-exit.png" class="deskButton" style="top:10px;display:none" onclick="exitButton(event)" />
89
- <img id="deskkeybutton3a" src="images/mobile-desk-menu-open.png" class="deskButton" style="top:60px;display:none" onclick="toggleMenu(false)" />
90
- <img id="deskkeybutton3b" src="images/mobile-desk-menu-close.png" class="deskButton" style="top:60px;display:none" onclick="toggleMenu(true)" />
91
- <img id="deskkeybutton4a" src="images/mobile-desk-mouse-left.png" class="deskButton" style="top:110px;display:none" onclick="deskChangeMouseButton(0)" />
92
- <img id="deskkeybutton4b" src="images/mobile-desk-mouse-right.png" class="deskButton" style="top:110px;display:none" onclick="deskChangeMouseButton(1)" />
93
- <img id="deskkeybutton5a" src="images/mobile-desk-scale-out.png" class="deskButton" style="top:160px;display:none" onclick="deskChangeFullscreenZoom()" />
94
- <img id="deskkeybutton5b" src="images/mobile-desk-scale-in.png" class="deskButton" style="top:160px;display:none" onclick="deskChangeFullscreenZoom()" />
95
- <img id="deskkeybutton2a" src="images/mobile-desk-keyboard-open.png" class="deskButton" style="top:210px;display:none" onclick="toggleKeyboard()" />
96
- <img id="deskkeybutton2b" src="images/mobile-desk-keyboard-close.png" class="deskButton" style="top:210px;display:none" onclick="toggleKeyboard()" />
97
- <div style="position:absolute;top:0;left:0;z-index:200;opacity:0;width:1px;height:1px">
98
- <input id="softKeyboard" autocapitalize="off" autocomplete="off" type="text" spellcheck="false" style="z-index:200;opacity:0;width:1px;height:1px" onfocus="keyboardFocusChange()" onblur="keyboardFocusChange()" />
99
- </div>
100
- <div id="deskButtonMenu" style="display:none;position:absolute;top:10px;left:10px;right:55px;bottom:10px;z-index:1000"></div>
101
- <div id=deskarea0 style="position:absolute;top:0px;left:0px;right:0px;bottom:0px">
102
- <div id=deskarea1 class="areaHead" style="line-height:24px">
103
- <div class="toright2">
104
- <span id="p11power"></span>
105
- <input id="deskFullScreen" type="button" value="Full Screen" style="display:none" onkeypress="return false" onkeydown="return false" onclick="deskToggleFull(event)" class="mR" />
106
- <input id="deskActionsSettings" type="button" value="Settings..." onkeypress="return false" onkeydown="return false" onclick="showDesktopSettings()" class="mR" />
107
- <div id="deskRecordIcon" class='deskareaicon' title="Server is recording this session" style="display:none;background-color:red;width:12px;height:12px;border-radius:6px;margin-top:5px"></div>
108
- </div>
109
- <div>
110
- <div id="idx_deskFullBtn2" onclick=deskToggleFull(event)> ✖</div>
111
- <span id=connectbutton1span><input type=button id=connectbutton1 cmenu="deskConnectButton" value="Connect" onclick=connectDesktop(event,3) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span>
112
- <span id=connectbutton1hspan> <input type=button id=connectbutton1h value="HW Connect" title="Connect using Intel AMT hardware KVM" onclick=connectDesktop(event,2) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span>
113
- <span id=disconnectbutton1span> <input type=button id=disconnectbutton1 value="Disconnect" onclick=connectDesktop(event,0) onkeypress="return false" onkeydown="return false" /></span>
114
- <span id="deskstatus">Disconnected</span><span id="deskmetadata"></span>
115
- </div>
116
- </div>
117
- <div id=deskarea3x style="max-height:calc(100vh - 60px);height:calc(100vh - 60px);">
118
- <div id=DeskParent>
119
- <canvas id=Desk width=640 height=480 oncontextmenu="return false" onmousedown=dmousedown(event) onmouseup=dmouseup(event) onmousemove=dmousemove(event) onmousewheel=dmousewheel(event)></canvas>
120
- </div>
121
- <div id=p11DeskConsoleMsg style="display:none;text-align:left;cursor:pointer;position:absolute;left:30px;top:17px;color:yellow;background-color:rgba(0,0,0,0.6);padding:10px;border-radius:5px" onclick=clearConsoleMsg()></div>
122
- </div>
123
- <div id=deskarea4 class="areaFoot" style="min-height:24px">
124
- <div class="toright2">
125
- <span id="DeskLatency" title="Desktop Session Latency"></span>
126
- <span id="DeskTimer" style="display:none" title="Session time"></span>
127
- <select id=termdisplays style="display:none" onchange=deskSetDisplay(event) onkeypress="return false" onkeydown="return false"></select>
128
- <span id=DeskSaveImageButton title="Save a screenshot of the remote desktop"><img src='images/icon-camera.png' onclick=deskSaveImage() height=16 width=16 style=padding-top:2px /></span>
129
- </div>
130
- <div style="height:22px">
131
- <select id="deskkeys">
132
- <option value=10>Ctrl+Alt+Del</option>
133
- <option value=5>Win</option>
134
- <option value=0>Win+Down</option>
135
- <option value=1>Win+Up</option>
136
- <option value=2>Win+L</option>
137
- <option value=3>Win+M</option>
138
- <option value=4>Shift+Win+M</option>
139
- <option value=6>Win+R</option>
140
- <option value=7>Alt-F4</option>
141
- <option value=8>Ctrl-W</option>
142
- <option value=9>Alt-Tab</option>
143
- <option value=11>Win+Left</option>
144
- <option value=12>Win+Right</option>
145
- </select>
146
- <input id="DeskWD" type=button value="Send" onkeypress="return false" onkeydown="return false" onclick="deskSendKeys()" />
147
- <input id="DeskClip" style="" type="button" value="Clipboard" onkeypress="return false" onkeydown="return false" onclick="showDeskClip()" />
148
- <input id="DeskType" style="" type="button" value="Type" onkeypress="return false" onkeydown="return false" onclick="showDeskType()" />
149
- <label><span id="DeskControlSpan" title="Toggle mouse and keyboard input"><input id="DeskControl" type="checkbox" onkeypress="return false" onkeydown="return false" onclick="toggleKvmControl()" />Input</span></label>
150
- </div>
151
- </div>
152
- </div>
153
- </div>
154
- <div id=p12 class="noselect" style="overflow:hidden;position:absolute;left:0;top:0;right:0;bottom:32px;display:none;background-color:black">
155
- <div id="p12warning" onclick=showFeaturesDlg()>
156
- <div class="icon2"></div>
157
- <div class="warningbox">Intel® AMT Redirection port or KVM feature is disabled<span id="p12warninga">, click here to enable it.</span></div>
158
- </div>
159
- <div id="p12warning2" onclick=showPowerActionDlg()>
160
- <div class="icon2"></div>
161
- <div class="warningbox">Remote computer is not powered on, click here to issue a power command.</div>
162
- </div>
163
- <div class="areaHead" style="position:absolute;top:0;left:0;right:0;height:24px">
164
- <div class="toright2">
165
- <div id="termRecordIcon" class='deskareaicon' title="Server is recording this session" style="display:none;background-color:red;width:12px;height:12px;border-radius:6px;margin-top:5px;margin-left:5px"></div>
166
- <div id="p12power" style="margin-top:3px;margin-right:4px;float:right"></div>
167
- </div>
168
- <div>
169
- <span id="connectbutton2span"><input type="button" id="connectbutton2" cmenu="termConnectButton" value="Connect" onclick=connectTerminal(event,1) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span>
170
- <span id="disconnectbutton2span"> <input type="button" id="disconnectbutton2" value="Disconnect" onclick=connectTerminal(event,0) onkeypress="return false" onkeydown="return false" /></span>
171
- <span id="termstatus">Disconnected</span><span id="termtitle"></span>
172
- </div>
173
- </div>
174
- <div id="termarea3xdiv" style="position:absolute;top:28px;bottom:28px;left:0;right:0"></div>
175
- <div class="areaFoot" style="position:absolute;bottom:0;left:0;right:0;height:24px">
176
- <div class="toright2">
177
- <span id="TermLatency" title="Terminal Session Latency"></span>
178
- <span id="TermTimer" title="Session time"></span>
179
- <span id="terminalSettingsButtons" style="display:none">
180
- <input id="id_tcrbutton" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="CR+LF" title="Toggle what the return key will send" onclick="termToggleCr()" />
181
- <input id="id_tfxkeysbutton" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="Intel (F10 = ESC+[OM)" title="Toggle F1 to F10 keys emulation type" onclick="termToggleFx()" />
182
- <input id="id_ttypebutton" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="Extended Ascii" title="Toggle terminal emulation type" onclick="termToggleType()" />
183
- </span>
184
- <span id="terminalSizeDropDown" style="display:none">
185
- <select id="termSizeList" onkeypress="return false"><option value="1">80x25</option><option value="2">100x30</option></select>
186
- </span>
187
- <span id="specialKeyDropDown">
188
- <select id="specialkeylist" onkeypress="return false"></select>
189
- <input id="specialkeylistinput" type="button" onkeypress="return false" class="bottombutton" value="Send" title="Send the selected special key" onclick="sendSpecialKey()" />
190
- </span>
191
- </div>
192
- <div>
193
-
194
- <input type=button onkeypress="return false" onkeydown="return false" class="bottombutton" id="ctrlcbutton" value="Ctl-C" onclick="termSendKey(3,'ctrlcbutton')" />
195
- <input type=button onkeypress="return false" onkeydown="return false" class="bottombutton" id="ctrlxbutton" value="Ctl-X" onclick="termSendKey(24,'ctrlxbutton')" />
196
- <input type=button onkeypress="return false" onkeydown="return false" class="bottombutton" id="escbutton" value="ESC" onclick="termSendKey(27,'escbutton')" />
197
- <input type=button onkeypress="return false" onkeydown="return false" class="bottombutton" id="bsbutton" value="Backspace" onclick="termSendKey(8,'bsbutton')" style="display:none" />
198
- <input type=button onkeypress="return false" onkeydown="return false" class="bottombutton" id="pastebutton" value="Paste" title="Paste text into the terminal" onclick="showTermPasteDialog()" style="display:none" />
199
- </div>
200
- </div>
201
- <div id=p12TermConsoleMsg style="display:none;text-align:left;cursor:pointer;position:absolute;left:30px;top:45px;color:yellow;background-color:rgba(0,0,0,0.6);padding:10px;border-radius:5px" onclick=p12clearConsoleMsg()></div>
202
- </div>
203
- <div id=p13 class="noselect" style="overflow:hidden;position:absolute;left:0;top:0;right:0;bottom:32px;display:none;background-color:white">
204
- <div id="p13toolbar" style="position:absolute;left:0;top:0;right:0;bottom:28px">
205
- <div class="areaHead">
206
- <div class="toright2">
207
- <div id="filesRecordIcon" class='deskareaicon' title="Server is recording this session" style="display:none;background-color:red;width:12px;height:12px;border-radius:6px;margin-top:5px;margin-left:5px"></div>
208
- <div id="p13power" style="margin-top:3px;margin-right:4px;float:right"></div>
209
- </div>
210
- <div>
211
- <input id=p13Connect value="Connect" onclick=connectFiles(event) type="button" />
212
- <span id=p13Status>Disconnected</span>
213
- </div>
214
- </div>
215
- <div id="fileArea2" class="areaHead2" valign=bottom>
216
- <div id="p13rightOfButtons" class="toright2"></div>
217
- <div>
218
- <input type=button id=p13FolderUp disabled="disabled" onclick="p13folderup()" value="Up" />
219
- <input type=button id=p13SelectAllButton disabled="disabled" onclick="p13selectallfile()" value="Select All" />
220
- <input type=button id=p13RenameFileButton disabled="disabled" value="Rename" onclick="p13renamefile()" />
221
- <input type=button id=p13DeleteFileButton disabled="disabled" value="Delete" onclick="p13deletefile()" />
222
- <input type=button id=p13ViewFileButton disabled="disabled" value="Edit" onclick="p13viewfile()" />
223
- <input type=button id=p13NewFolderButton disabled="disabled" value="New Folder" onclick="p13createfolder()" />
224
- <input type=button id=p13UploadButton disabled="disabled" value="Upload" onclick="p13uploadFile()" />
225
- <input type=button id=p13CutButton disabled="disabled" value="Cut" onclick="p13copyFile(1)" />
226
- <input type=button id=p13CopyButton disabled="disabled" value="Copy" onclick="p13copyFile(0)" />
227
- <input type=button id=p13PasteButton disabled="disabled" value="Paste" onclick="p13pasteFile()" />
228
- <input type=button id=p13ZipButton disabled="disabled" value="Zip" onclick="p13zipFiles()" />
229
- <input type=button id=p13RefreshButton disabled="disabled" value="Refresh" onclick="p13folderup(9999)" />
230
- <input type=button id=p13FindButton disabled="disabled" value="Find" onclick="p13findfile()" />
231
- </div>
232
- </div>
233
- <div class="areaHead3" style="line-height:28px">
234
- <div class="toright2">
235
- <select id=p13sortdropdown onchange=p13updateFiles()>
236
- <option value=1 selected="selected">Sort by name</option>
237
- <option value=2>Sort by size</option>
238
- <option value=3>Sort by date</option>
239
- <option value=4>Descend by name</option>
240
- <option value=5>Descend by size</option>
241
- <option value=6>Descend by date</option>
242
- </select>
243
- </div>
244
- <div> <span id="p13currentpath"></span></div>
245
- </div>
246
- <div id="fileArea4" style="height:calc(100vh - 146px)">
247
- <div id=p13FilesConsoleMsg style="display:none;text-align:left;cursor:pointer;position:absolute;left:30px;top:165px;color:yellow;background-color:rgba(0,0,0,0.6);padding:10px;border-radius:5px" onclick=p13clearConsoleMsg()></div>
248
- <div id="p13filetable" style="width:100%;height:100%">
249
- <div id="p13bigok" style="display:none"><b>✓</b></div>
250
- <div id="p13bigfail" style="display:none"><b>✗</b></div>
251
- <span id="p13files"></span>
252
- </div>
253
- </div>
254
- </div>
255
- <div class="areaFoot" style="position:absolute;left:0;right:0;bottom:0;height:28px">
256
- <span id="p13bottomstatus"></span>
257
- </div>
258
- </div>
259
- <div id=xfooter style="height:32px;width:100%;text-align:center;background-color:#113962;position:absolute;bottom:0px;margin:0;padding:0">
260
- <table id=xfooterMenu cellpadding=0 cellspacing=0 style="height:32px;width:100%;color:white;cursor:pointer;table-layout:fixed"></table>
261
- </div>
262
- <div id=dialog class="noselect" style="display:none">
263
- <div id=dialogHeader>
264
- <div tabindex=0 id=id_dialogclose onclick=setDialogMode() onkeypress="if (event.key == 'Enter') setDialogMode()">✖</div>
265
- <div id=id_dialogtitle></div>
266
- </div>
267
- <div id=dialogBody>
268
- <div id=dialog1>
269
- <div id=id_dialogMessage style=""></div>
270
- </div>
271
- <div id=dialog2 style="">
272
- <div id=id_dialogOptions></div>
273
- </div>
274
- <div id=dialog7 style="margin:auto;margin:3px">
275
- <div id="d7meshkvm">
276
- <h4 style="width:100%;border-bottom:1px solid gray">Agent Remote Desktop</h4>
277
- <table style="width:100%">
278
- <tr>
279
- <td>
280
- Quality
281
- </td>
282
- <td style="width:100px">
283
- <select id="d7bitmapquality" style="float:right;width:200px" dir="rtl"></select>
284
- </td>
285
- </tr>
286
- <tr>
287
- <td>
288
- Scaling
289
- </td>
290
- <td style="width:100px">
291
- <select id="d7bitmapscaling" style="float:right;width:200px" dir="rtl">
292
- <option selected=selected value=1024>100%</option>
293
- <option value=896>87.5%</option>
294
- <option value=768>75%</option>
295
- <option value=640>62.5%</option>
296
- <option value=512>50%</option>
297
- <option value=384>37.5%</option>
298
- <option value=256>25%</option>
299
- <option value=128>12.5%</option>
300
- </select>
301
- </td>
302
- </tr>
303
- <tr>
304
- <td>
305
- Rate
306
- </td>
307
- <td style="width:100px">
308
- <select id="d7framelimiter" style="float:right;width:200px" dir="rtl">
309
- <option selected=selected value=50>Fast</option>
310
- <option value=100>Medium</option>
311
- <option value=400>Slow</option>
312
- <option value=1000>Very slow</option>
313
- </select>
314
- </td>
315
- </tr>
316
- <tr>
317
- <td></td>
318
- <td>
319
- <label style="display:block" id="d7deskAutoLockLabel"><input type="checkbox" id="d7deskAutoLock" />Lock on Disconnect</label>
320
- </td>
321
- </tr>
322
- </table>
323
- </div>
324
- <div id="d7amtkvm">
325
- <h4 style="width:100%;border-bottom:1px solid gray">Intel® AMT Hardware KVM</h4>
326
- <table style="width:100%">
327
- <tr>
328
- <td>Encoding</td>
329
- <td style="width:100px">
330
- <select id="d7desktopmode" style="float:right;width:200px">
331
- <option value="1">RLE8, Fastest</option>
332
- <option value="2">RLE16, Recommended</option>
333
- <option value="3">RAW8, Slow</option>
334
- <option value="4">RAW16, Very Slow</option>
335
- </select>
336
- </td>
337
- </tr>
338
- </table>
339
- </div>
340
- </div>
341
- </div>
342
- <div id="idx_dlgButtonBar">
343
- <input id="idx_dlgCancelButton" type="button" value="Cancel" style="" onclick="dialogclose(0)">
344
- <input id="idx_dlgOkButton" type="button" value="OK" style="" onclick="dialogclose(1)">
345
- <div><input id="idx_dlgDeleteButton" type="button" value="Delete" style="display:none" onclick="dialogclose(2)"></div>
346
- </div>
347
- </div>
348
- <script>
349
- var sessionActivity = null;
350
- var desktop = null;
351
- var agentPresent = true;
352
- var intelAmtPresent = false;
353
- var desktopsettings = { encoding: 2, showfocus: false, showmouse: true, showcad: true, quality: 40, scaling: 1024, framerate: 100, localkeymap: false };
354
- var serverPublicNamePort = '{{{serverDnsName}}}:{{{serverPublicPort}}}';
355
- var domain = '{{{domain}}}';
356
- var domainUrl = '{{{domainurl}}}';
357
- var authCookie = '{{{authCookie}}}';
358
- var viewOnly = parseInt('{{{viewOnly}}}');
359
- var urlargs = parseUriArgs();
360
- var debugmode = urlargs.debug;
361
- var attemptWebRTC = false;
362
- var updateSessionTimer = null;
363
- var deskKeyboardShortcuts = [];
364
- var StatusStrs = ["Disconnected", "Connecting...", "Setup...", "Connected", "Intel® AMT Connected"];
365
- var nodeName = decodeURIComponent('{{{nodeName}}}');
366
- var webPageFullScreen = false;
367
- var expire = '{{{expire}}}';
368
- if (expire != '') {
369
- QH('p11power', printFlexDateTime(new Date(parseInt(expire))));
370
- QH('p12power', printFlexDateTime(new Date(parseInt(expire))));
371
- QH('p13power', printFlexDateTime(new Date(parseInt(expire))));
372
- }
373
- var features = parseInt('{{{features}}}');
374
- var features2 = parseInt('{{{features2}}}');
375
-
376
- // Load desktop settings
377
- var t = null;
378
- try { t = localStorage.getItem('desktopsettings'); } catch (ex) { }
379
- if (t != null) { try { desktopsettings = JSON.parse(t); } catch (ex) { } }
380
- if (((features2 & 1) == 0) && (desktopsettings.quality > 60)) { desktopsettings.quality = 60; }
381
-
382
- // Terminal
383
- var terminal = null;
384
- var xterm = null;
385
- var xtermfit = null;
386
- var xtermResizeTimer = null;
387
-
388
- // Files
389
- var files = null
390
-
391
- // Console messages timers
392
- var p11DeskConsoleMsgTimer = null;
393
- var p12TermConsoleMsgTimer = null;
394
- var p13FilesConsoleMsgTimer = null;
395
-
396
- function start() {
397
- window.onresize = center;
398
- center();
399
- document.onkeypress = ondeskkeypress;
400
- document.onkeydown = ondeskkeydown;
401
- document.onkeyup = ondeskkeyup;
402
- //document.onkeypress = ondockeypress;
403
- //document.onkeydown = ondockeydown;
404
- //document.onkeyup = ondockeyup;
405
- setupDesktop();
406
- setupTerminal();
407
- setupFiles();
408
-
409
- // Set the document title
410
- if (nodeName.length > 0) { document.title += ' - ' + nodeName; }
411
-
412
- // View only mode
413
- if (viewOnly == 1) {
414
- QV('deskkeys', false);
415
- QV('DeskWD', false);
416
- QV('DeskClip', false);
417
- QV('DeskType', false);
418
- QV('DeskControlSpan', false);
419
- }
420
-
421
- // Setup upload drag & drop
422
- Q('p13filetable').addEventListener('drop', p13fileDragDrop, false);
423
- Q('p13filetable').addEventListener('dragover', p13fileDragOver, false);
424
- Q('p13filetable').addEventListener('dragleave', p13fileDragLeave, false);
425
-
426
- // Setup feature visibility
427
- QV('LeftMenuDesktop', features & 2);
428
- QV('LeftMenuTerminal', features & 1);
429
- QV('LeftMenuFiles', features & 4);
430
- if (features & 2) { go(11); } // Goto desktop
431
- else if (features & 1) { go(12); } // Goto terminal
432
- else if (features & 4) { go(13); } // Goto files
433
- deskAdjust();
434
-
435
- // Set the user's desktop shortcut keys
436
- deskKeyboardShortcuts = [];
437
- var deskKeyboardShortcutsStr = '0x0A002E,0x100000,0x100028,0x100026,0x10004C,0x10004D,0x11004D,0x100052,0x020073,0x080057,0x020009,0x100025,0x100027'.split(',');
438
- for (var i in deskKeyboardShortcutsStr) { deskKeyboardShortcuts.push(parseInt(deskKeyboardShortcutsStr[i])); }
439
- updateDeskShortcutKeys();
440
- //updateTermShortcutKeys();
441
- }
442
-
443
- //
444
- // Desktop
445
- //
446
-
447
- function isInputAllowed() { return (viewOnly != 1) && (Q('DeskControl').checked == true); }
448
- function clearConsoleMsg() { QH('p11DeskConsoleMsg', ''); }
449
-
450
- function deskAdjust() {
451
- if ((xxcurrentView == 12) && (terminal != null) && (xtermfit != null)) { xtermfit.fit(); } // Terminal
452
- QS('fileArea4')['height'] = 'calc(100vh - ' + (90 + Q('fileArea2').clientHeight) + 'px)'; // Files
453
-
454
- if (fullscreen) {
455
- QS('Desk')['margin-top'] = null;
456
- QS('Desk')['margin-bottom'] = null;
457
- QS('deskarea3x')['padding-right'] = '55px';
458
- QS('Desk').width = '100%';
459
- QS('Desk').height = '100%';
460
- var parentH = Q('p11').clientHeight, parentW = Q('p11').clientWidth;
461
- var deskH = Q('deskarea3x').clientHeight, deskW = Q('deskarea3x').clientWidth - 55;
462
- if (parentH > deskH) { QS('deskarea3x').top = ((parentH - deskH) / 2) + 'px'; } else { QS('deskarea3x').top = null; }
463
- if (parentW > deskW) { QS('deskarea3x').left = ((parentW - deskW) / 2) + 'px'; } else { QS('deskarea3x').left = null; }
464
- } else {
465
- var parentH = Q('DeskParent').clientHeight, parentW = Q('DeskParent').clientWidth;
466
- var deskH = Q('Desk').height, deskW = Q('Desk').width;
467
-
468
- // Fixed aspect ratio
469
- if ((parentH / parentW) > (deskH / deskW)) {
470
- var hNew = ((deskH * parentW) / deskW) + 'px';
471
- QS('Desk').height = hNew;
472
- QS('Desk').width = '100%';
473
- } else {
474
- var wNew = ((deskW * parentH) / deskH) + 'px';
475
- QS('Desk').height = '100%';
476
- QS('Desk').width = wNew;
477
- }
478
- QS('Desk')['margin-top'] = null;
479
- QS('deskarea3x')['padding-right'] = null;
480
- }
481
- }
482
-
483
- function setupDesktop() {
484
- // Setup the remote desktop
485
- if (desktop != null) { desktop.Stop(); desktop = null; }
486
-
487
- // If the device desktop is already connected in multi-desktop, use that.
488
- if (desktop == null) {
489
- // Device is not already connected, just setup a blank canvas
490
- QH('DeskParent', '<canvas id=Desk oncontextmenu="return false" onmousedown=dmousedown(event) onmouseup=dmouseup(event) onmousemove=dmousemove(event)></canvas>');
491
-
492
- // Setup the mouse wheel
493
- Q('Desk').addEventListener('DOMMouseScroll', function (e) { return dmousewheel(e); });
494
- Q('Desk').addEventListener('mousewheel', function (e) { return dmousewheel(e); });
495
- }
496
- updateDesktopButtons();
497
- deskAdjust();
498
- updateMetadata(desktop, 'deskmetadata');
499
- }
500
-
501
- // Show and enable the right buttons
502
- function updateDesktopButtons() {
503
- var deskState = 0;
504
- if (desktop != null) { deskState = desktop.State; }
505
-
506
- // Show the right buttons
507
- QV('disconnectbutton1span', (deskState != 0));
508
- QV('connectbutton1span', (deskState == 0) && (agentPresent));
509
- QV('connectbutton1hspan', (deskState == 0) && (intelAmtPresent));
510
-
511
- // Show the right settings
512
- QV('d7meshkvm', agentPresent && ((deskState == 0) || (desktop.contype == 1)));
513
- QV('d7amtkvm', intelAmtPresent && ((deskState == 0) || (desktop.contype == 2)));
514
-
515
- // Enable buttons
516
- QE('connectbutton1', agentPresent);
517
- QE('connectbutton1h', intelAmtPresent);
518
- //QV('DeskClip', agentPresent && ((desktop == null) || (desktop.contype != 2))); // Clipboard not supported on macOS
519
- QV('DeskClip', false); // Clipboard not supported on this page
520
- QE('DeskClip', deskState == 3);
521
- QE('DeskType', deskState == 3);
522
- QV('DeskWD', viewOnly != 1);
523
- QE('DeskWD', deskState == 3);
524
- QV('deskkeys', viewOnly != 1);
525
- QE('deskkeys', deskState == 3);
526
-
527
- // Display this only if we have Chat & Notify permissions
528
- QV('DeskSaveImageButton', (deskState == 3) && (Q('Desk')['toBlob'] != null));
529
- QV('DeskControlSpan', viewOnly != 1);
530
- QV('deskActionsBtn', true);
531
- QV('deskActionsSettings', (deskState != 3));
532
- Q('DeskControl').checked = true;
533
- QS('DeskControlSpan').color = Q('DeskControl').checked ? null : 'red';
534
- }
535
-
536
- // Used to translate incoming agent console messages
537
- var agentConsoleMessages = ['', "Waiting for user to grant access...", "Denied", "Failed to start remote terminal session, {0} ({1})", "Timeout", "Received invalid network data"];
538
- function formatAgentConsoleMessage(msg, msgid, msgargs) {
539
- var r;
540
- if (msgargs == null) { msgargs = []; }
541
- while (msgargs.length < 3) { msgargs.push(''); } // We need to call the format function in a way that works with older browsers and minifier, can't use apply() or ...
542
- if (msgid && (msgid < agentConsoleMessages.length)) { r = EscapeHtml(format(agentConsoleMessages[msgid], (msgargs[0]), (msgargs[1]), (msgargs[2]))); } else { r = EscapeHtml(msg); }
543
- return r.split('\n').join('<br />') + '<br /><br />';
544
- }
545
-
546
- function connectDesktop(e, contype, tsid, consent) {
547
- if (xxdialogMode) return;
548
- if ((e != null) && (e.shiftKey != false) && (contype == 3)) { contype = 1; } // If the shift key is not pressed, don't try to ask for session list.
549
- QV('p11DeskSessionSelector', false);
550
- p11clearConsoleMsg();
551
- if (desktop == null) {
552
- if (contype == 2) {
553
- // Setup the Intel AMT remote desktop
554
- //if ((desktopNode.intelamt.user == null) || (desktopNode.intelamt.user == '')) { editDeviceAmtSettings(desktopNode._id, connectDesktop, 2); return; }
555
- desktop = CreateAmtRedirect(CreateAmtRemoteDesktop('Desk'), authCookie);
556
- desktop.debugmode = debugmode;
557
- desktop.onStateChanged = onDesktopStateChange;
558
- desktop.m.stopInput = (viewOnly == 1);
559
- desktop.m.bpp = (desktopsettings.encoding == 1 || desktopsettings.encoding == 3) ? 1 : 2;
560
- desktop.m.useZRLE = (desktopsettings.encoding < 3);
561
- desktop.m.localKeyMap = desktopsettings.localkeymap;
562
- desktop.m.showmouse = desktopsettings.showmouse;
563
- desktop.m.onScreenSizeChange = deskAdjust;
564
- desktop.m.onKvmData = function (x) {
565
- //console.log('onKvmData (' + x.length + '): ' + x);
566
- // Send the presense probe only once if needed.
567
- if (x.length == 0) { if (!desktop.m._sentPresence) { desktop.m._sentPresence = true; desktop.m.sendKvmData(JSON.stringify({ action: 'present', ver: 1 })); } return; }
568
- var data = null;
569
- try { data = JSON.parse(x); } catch (e) { }
570
- if ((data != null) && (data.action != null)) {
571
- if (data.action == 'restart') {
572
- // Clear WebRTC channel
573
- webRtcDesktopReset();
574
- desktop.m.sendKvmData(JSON.stringify({ action: 'present', ver: 1 }));
575
- } else if ((data.action == 'present') && (webRtcDesktop == null)) {
576
- // Setup WebRTC channel
577
- webRtcDesktop = { platform: data.platform };
578
- var configuration = null; //{ "iceServers": [ { 'urls': 'stun:stun.services.mozilla.com' }, { 'urls': 'stun:stun.l.google.com:19302' } ] };
579
- if (typeof RTCPeerConnection !== 'undefined') { webRtcDesktop.webrtc = new RTCPeerConnection(configuration); }
580
- else if (typeof webkitRTCPeerConnection !== 'undefined') { webRtcDesktop.webrtc = new webkitRTCPeerConnection(configuration); }
581
-
582
- webRtcDesktop.webchannel = webRtcDesktop.webrtc.createDataChannel("DataChannel", {}); // { ordered: false, maxRetransmits: 2 }
583
- webRtcDesktop.webchannel.onopen = function () {
584
- // Switch to software KVM
585
- //if (urlvars && urlvars['kvmdatatrace']) { console.log('WebRTC Data Channel Open'); }
586
- console.log('WebRTC Data Channel Open');
587
- Q('deskstatus').textContent = StatusStrs[desktop.State] + ", Soft-KVM";
588
- desktop.m.hold(true);
589
- webRtcDesktop.webRtcActive = true;
590
- webRtcDesktop.softdesktop = CreateKvmDataChannel(webRtcDesktop.webchannel, CreateAgentRemoteDesktop('Desk', Q('id_mainarea')), desktop.m);
591
- webRtcDesktop.softdesktop.m.setRotation(desktop.m.rotation);
592
- webRtcDesktop.softdesktop.m.onScreenSizeChange = deskAdjust;
593
- if (desktopsettings.quality) { webRtcDesktop.softdesktop.m.CompressionLevel = desktopsettings.quality; } // Number from 1 to 100. 50 or less is best.
594
- if (desktopsettings.scaling) { webRtcDesktop.softdesktop.m.ScalingLevel = desktopsettings.scaling; }
595
- webRtcDesktop.softdesktop.Start();
596
-
597
- // Check if we can get remote file access
598
- // ###BEGIN###{DesktopInbandFiles}
599
- /*
600
- QV('go24', true); // Files
601
- downloadFile = null;
602
- p24files = webRtcDesktop.softdesktop;
603
- p24targetpath = '';
604
- webRtcDesktop.softdesktop.onControlMsg = onFilesControlData;
605
- webRtcDesktop.softdesktop.sendCtrlMsg(JSON.stringify({ action: 'ls', reqid: 1, path: '' })); // Ask for the root folder
606
- */
607
- // ###END###{DesktopInbandFiles}
608
- }
609
- webRtcDesktop.webchannel.onclose = function (event) {
610
- //if (urlvars['kvmdatatrace']) { console.log('WebRTC Data Channel Closed'); }
611
- console.log('WebRTC Data Channel Closed');
612
- webRtcDesktopReset();
613
- }
614
- webRtcDesktop.webrtc.onicecandidate = function (e) {
615
- if (e.candidate == null) {
616
- desktop.m.sendKvmData(JSON.stringify({ action: 'offer', ver: 1, sdp: webRtcDesktop.webrtcoffer.sdp }));
617
- } else {
618
- webRtcDesktop.webrtcoffer.sdp += ('a=' + e.candidate.candidate + '\r\n'); // New candidate, add it to the SDP
619
- }
620
- }
621
- webRtcDesktop.webrtc.oniceconnectionstatechange = function () {
622
- if ((webRtcDesktop != null) && (webRtcDesktop.webrtc != null) && ((webRtcDesktop.webrtc.iceConnectionState == 'disconnected') || (webRtcDesktop.webrtc.iceConnectionState == 'failed'))) { /*console.log('WebRTC ICE Failed');*/ webRtcDesktopReset(); }
623
- }
624
- webRtcDesktop.webrtc.createOffer(function (offer) {
625
- // Got the offer
626
- webRtcDesktop.webrtcoffer = offer;
627
- webRtcDesktop.webrtc.setLocalDescription(offer, function () { }, webRtcDesktopReset);
628
- }, webRtcDesktopReset, { mandatory: { OfferToReceiveAudio: false, OfferToReceiveVideo: false } });
629
- } else if ((data.action == 'answer') && (webRtcDesktop != null)) {
630
- // Complete the WebRTC channel
631
- webRtcDesktop.webrtc.setRemoteDescription(new RTCSessionDescription({ type: 'answer', sdp: data.sdp }), function () { }, webRtcDesktopReset);
632
- }
633
- }
634
- };
635
- desktop.Start(null, 16994, '*', '*', 0);
636
- desktop.contype = 2;
637
- } else if ((contype == null) || (contype == 1) || (contype == 3)) {
638
- // Setup the Mesh Agent remote desktop
639
- desktop = CreateAgentRedirect(null, CreateAgentRemoteDesktop('Desk'), serverPublicNamePort, authCookie, null, domainUrl);
640
- desktop.m.stopInput = (viewOnly == 1);
641
- desktop.m.mouseCursorActive(true);
642
- desktop.debugmode = debugmode;
643
- desktop.m.debugmode = debugmode;
644
- desktop.attemptWebRTC = attemptWebRTC;
645
- desktop.options = {};
646
- if (tsid != null) { desktop.options.tsid = tsid; }
647
- if (consent != null) { desktop.options.consent = consent; }
648
- desktop.onStateChanged = onDesktopStateChange;
649
- desktop.onConsoleMessageChange = function () {
650
- if (desktop.consoleMessage) {
651
- Q('p11DeskConsoleMsg').innerHTML += formatAgentConsoleMessage(desktop.consoleMessage, desktop.consoleMessageId, desktop.consoleMessageArgs);
652
- QV('p11DeskConsoleMsg', true);
653
- if (p11DeskConsoleMsgTimer != null) { clearTimeout(p11DeskConsoleMsgTimer); }
654
- if (desktop.consoleMessageTimeout) { p11DeskConsoleMsgTimer = setTimeout(p11clearConsoleMsg, desktop.consoleMessageTimeout * 1000); }
655
- } else {
656
- p11clearConsoleMsg();
657
- }
658
- }
659
- desktop.onMetadataChange = function (metadata) { updateMetadata(desktop, 'deskmetadata'); }
660
- desktop.m.CompressionLevel = desktopsettings.quality; // Number from 1 to 100. 50 or less is best.
661
- desktop.m.ScalingLevel = desktopsettings.scaling;
662
- if (desktopsettings.framerate) { desktop.m.FrameRateTimer = desktopsettings.framerate; }
663
- desktop.m.onDisplayinfo = deskDisplayInfo;
664
- desktop.m.onScreenSizeChange = deskAdjust;
665
- desktop.Start(null);
666
- desktop.latency.callback = function (ms) { console.log('latency', ms); updateSessionTime(); };
667
- desktop.contype = 1;
668
- }
669
- } else {
670
- // Disconnect and clean up the remote desktop
671
- desktop.Stop();
672
- webRtcDesktopReset();
673
- desktop = null;
674
- //if (pluginHandler != null) { pluginHandler.callHook('onDesktopDisconnect'); }
675
- }
676
- }
677
-
678
- function updateMetadata(conn, elementid) {
679
- var str = '', viewerCount = 0;
680
- if (conn && (conn.State == 3)) {
681
- if (conn.metadata && conn.metadata.users) { for (var i in conn.metadata.users) { viewerCount += conn.metadata.users[i]; } }
682
- if (viewerCount > 1) { str = '<span onclick=showSessionMetadata(1) style=cursor:pointer>' + format(", {0} watching", viewerCount) + '</span>'; }
683
- }
684
- QH('deskmetadata', str);
685
- if ((conn == desktop) && (xxdialogTag == ('sessionMetadata1'))) { showSessionMetadata(1); }
686
- }
687
-
688
- function showSessionMetadata(cid) {
689
- if (xxdialogMode && (xxdialogTag != ('sessionMetadata' + cid))) return;
690
- if (xxdialogMode) { setDialogMode(0); }
691
- var conn = null;
692
- if (cid == 1) { conn = desktop; }
693
- if (conn && conn.metadata) {
694
- var x = '';
695
- if (conn.metadata.startTime) { x += addHtmlValue4("Start Time", printDateTime(new Date(conn.metadata.startTime))); }
696
- if (conn.metadata.users) {
697
- for (var i in conn.metadata.users) {
698
- var val = (conn.metadata.users[i] == 1) ? "1 connection" : format("{0} connections", conn.metadata.users[i]);
699
- var username = i.split('/')[2];
700
- if ((users != null) && (users[i] != null)) { username = users[i].name; }
701
- x += addHtmlValue4(format("User \"{0}\"", username), val);
702
- }
703
- }
704
- setDialogMode(2, "Session Information", 1, null, x, 'sessionMetadata' + cid);
705
- }
706
- }
707
-
708
- function p11clearConsoleMsg() { QH('p11DeskConsoleMsg', ''); QV('p11DeskConsoleMsg', false); if (p11DeskConsoleMsgTimer) { clearTimeout(p11DeskConsoleMsgTimer); p11DeskConsoleMsgTimer = null; } }
709
- function p12clearConsoleMsg() { QH('p12TermConsoleMsg', ''); QV('p12TermConsoleMsg', false); if (p12TermConsoleMsgTimer) { clearTimeout(p12TermConsoleMsgTimer); p12TermConsoleMsgTimer = null; } }
710
- function p13clearConsoleMsg() { QH('p13FilesConsoleMsg', ''); QV('p13FilesConsoleMsg', false); if (p13FilesConsoleMsgTimer) { clearTimeout(p13FilesConsoleMsgTimer); p13FilesConsoleMsgTimer = null; } }
711
-
712
- var webRtcDesktop = null;
713
- function webRtcDesktopReset() {
714
- if (webRtcDesktop == null) return;
715
- if (webRtcDesktop.softdesktop != null) { webRtcDesktop.softdesktop.Stop(); webRtcDesktop.softdesktop = null; }
716
- if (webRtcDesktop.webchannel != null) { try { webRtcDesktop.webchannel.close(); } catch (e) { } webRtcDesktop.webchannel = null; }
717
- if (webRtcDesktop.webrtc != null) { try { webRtcDesktop.webrtc.close(); } catch (e) { } webRtcDesktop.webrtc = null; }
718
- webRtcDesktop = null;
719
- // Switch back to hardware KVM
720
- if (desktop && desktop.m) {
721
- desktop.m.hold(false);
722
- Q('deskstatus').textContent = StatusStrs[desktop.State];
723
- }
724
- // ###BEGIN###{DesktopInbandFiles}
725
- /*
726
- p24files = null;
727
- p24downloadFileCancel() // If any downloads are in process, cancel them.
728
- p24uploadFileCancel(); // If any uploads are in process, cancel them.
729
- QV('go24', false); // Files
730
- if (currentView == 24) { go(14); }
731
- */
732
- // ###END###{DesktopInbandFiles}
733
- }
734
-
735
- function onDesktopStateChange(xdesktop, state) {
736
- var xstate = state;
737
- if ((xstate == 3) && (xdesktop.contype == 2)) { xstate++; }
738
- var str = StatusStrs[xstate];
739
- if ((desktop != null) && (desktop.webRtcActive == true)) { str += ", WebRTC"; }
740
- //if (desktop.m.stopInput == true) { str += ', Loopback'; }
741
- QH('deskstatus', str);
742
- QV('deskFullScreen', state == 3);
743
- QV('deskActionsSettings', state != 3);
744
- switch (state) {
745
- case 0:
746
- // Stop recording
747
- if (desktop.m.recordedData != null) { deskRecordSession(); }
748
-
749
- // Disconnect and clean up the remote desktop
750
- desktop.Stop();
751
- desktop = null;
752
- QV('termdisplays', false);
753
- QV('deskRecordIcon', false);
754
- if (fullscreen == true) { deskToggleFull(); }
755
- webRtcDesktopReset();
756
- deskPreferedStickyDisplay = 0;
757
- break;
758
- case 2:
759
- break;
760
- case 3:
761
- if (desktop && (desktop.serverIsRecording == true)) { QV('deskRecordIcon', true); }
762
- desktop.startTime = new Date();
763
- if (updateSessionTimer == null) { updateSessionTimer = setInterval(updateSessionTime, 1000); }
764
- break;
765
- default:
766
- //console.log('Unknown onDesktopStateChange state', state);
767
- break;
768
- }
769
- updateDesktopButtons();
770
- deskAdjust();
771
- setTimeout(deskAdjust, 50);
772
- updateMetadata(desktop, 'deskmetadata');
773
- }
774
-
775
- function updateSessionTime() {
776
- // Desktop
777
- var latencyStr = '', seconds = 0;
778
- if (desktop && desktop.startTime) {
779
- if (desktop.latency && (desktop.latency.current >= 0)) { latencyStr = format('{0} ms, ', desktop.latency.current); }
780
- seconds = Math.floor((new Date() - desktop.startTime) / 1000);
781
- QH('DeskTimer', latencyStr + zeroPad(Math.floor(seconds / 3600), 2) + ':' + zeroPad((Math.floor(seconds / 60) % 60), 2) + ':' + zeroPad((seconds % 60), 2));
782
- } else {
783
- QH('DeskTimer', '');
784
- }
785
-
786
- if (desktop == null) { clearInterval(updateSessionTimer); updateSessionTimer = null; }
787
- }
788
-
789
- function showDesktopSettings() {
790
- if (xxdialogMode) return;
791
- applyDesktopSettings();
792
- updateDesktopButtons();
793
- setDialogMode(7, "Remote Desktop Settings", 3, showDesktopSettingsChanged);
794
- }
795
-
796
- function showDesktopSettingsChanged() {
797
- desktopsettings.encoding = d7desktopmode.value;
798
- desktopsettings.quality = d7bitmapquality.value;
799
- desktopsettings.scaling = d7bitmapscaling.value;
800
- desktopsettings.framerate = d7framelimiter.value;
801
- desktopsettings.swapmouse = d7deskSwapMouse.checked;
802
- desktopsettings.remotekeymap = d7deskRemoteKeyMap.checked;
803
- desktopsettings.localkeymap = d7localKeyMap.checked;
804
- localStorage.setItem('desktopsettings', JSON.stringify(desktopsettings));
805
- applyDesktopSettings();
806
- if (desktop) {
807
- if (desktop.contype == 1) {
808
- desktop.m.SwapMouse = desktopsettings.swapmouse;
809
- desktop.m.remoteKeyMap = desktopsettings.remotekeymap;
810
- if (desktop.State != 0) {
811
- desktop.m.SendCompressionLevel(1, desktopsettings.quality, desktopsettings.scaling, desktopsettings.framerate);
812
- }
813
- }
814
- if (desktop.contype == 2) {
815
- if (desktop.State != 0) { desktop.Stop(); setTimeout(function () { connectDesktop(null, 2); }, 50); }
816
- }
817
- }
818
- }
819
-
820
- function applyDesktopSettings() {
821
- var r = '', ops = (features2 & 1) ? [90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 1] : [60, 50, 40, 30, 20, 10, 5, 1]
822
- for (var i in ops) { r += '<option value=' + ops[i] + '>' + ops[i] + '%</option>'; }
823
- QH('d7bitmapquality', r);
824
- d7desktopmode.value = desktopsettings.encoding;
825
- d7bitmapquality.value = 40; // Default value
826
- if (ops.indexOf(parseInt(desktopsettings.quality)) >= 0) { d7bitmapquality.value = desktopsettings.quality; }
827
- d7bitmapscaling.value = desktopsettings.scaling;
828
- if (desktopsettings.framerate) { d7framelimiter.value = desktopsettings.framerate; } else { d7framelimiter.value = 100; }
829
- if (desktopsettings.swapmouse != null) { d7deskSwapMouse.checked = desktopsettings.swapmouse; }
830
- if (desktopsettings.remotekeymap != null) { d7deskRemoteKeyMap.checked = desktopsettings.remotekeymap; }
831
- if (desktopsettings.localkeymap) { d7localKeyMap.checked = desktopsettings.localkeymap; }
832
- }
833
-
834
- function toggleMenu(x) {
835
- if (xxdialogMode) return;
836
- QV('deskButtonMenu', fullscreen && !x && (xxcurrentView == 11));
837
- QV('termButtonMenu', fullscreen && !x && (xxcurrentView == 12));
838
- QV('deskkeybutton3a', fullscreen && x);
839
- QV('deskkeybutton3b', fullscreen && !x);
840
- }
841
-
842
- function deskChangeMouseButton(x) {
843
- if (xxdialogMode) return;
844
- if (desktop == null) return;
845
- desktop.m.SwapMouse = !desktop.m.SwapMouse;
846
- QV('deskkeybutton4a', fullscreen && (!desktop.m.SwapMouse));
847
- QV('deskkeybutton4b', fullscreen && (desktop.m.SwapMouse));
848
- }
849
-
850
- function deskChangeFullscreenZoom() {
851
- if (xxdialogMode) return;
852
- if (xxcurrentView == 11) {
853
- if (desktop == null) return;
854
- if (fullscreenzoom == 1) { fullscreenzoom = 0.5; } else { fullscreenzoom = 1; }
855
- QV('deskkeybutton5a', fullscreen && (fullscreenzoom == 1));
856
- QV('deskkeybutton5b', fullscreen && (fullscreenzoom != 1));
857
- QS('deskarea3x').width = (desktop.m.ScreenWidth * fullscreenzoom) + 'px';
858
- QS('deskarea3x').height = (desktop.m.ScreenHeight * fullscreenzoom) + 'px';
859
- deskAdjust();
860
- }
861
- if (xxcurrentView == 12) {
862
- if (terminal == null) return;
863
- xterm.setOption('fontSize', (xterm.getOption('fontSize') == 15) ? 10 : 15)
864
- }
865
- }
866
-
867
- var fullscreen = false;
868
- var fullscreenzoom = 1;
869
- function deskToggleFull(e) {
870
- var xtermActive = !((urlargs.xterm === 0) || ((terminal != null) && (xterm == null)));
871
- fullscreen = !fullscreen;
872
- if (fullscreen) {
873
- QV('deskarea1', false);
874
- QV('deskarea4', false);
875
- QV('xfooter', false);
876
- QS('p11').bottom = '0px';
877
- QS('deskarea0').overflow = 'scroll';
878
- QS('deskarea3x').width = (desktop.m.ScreenWidth * fullscreenzoom) + 'px';
879
- QS('deskarea3x').height = QS('deskarea3x')['max-height'] = (desktop.m.ScreenHeight * fullscreenzoom) + 'px';
880
- QS('deskarea3x')['padding-right'] = '55px';
881
- if (xtermActive) {
882
- // XTerm terminal
883
- //QS('termTable')['position'] = 'absolute';
884
- //QS('termTable')['top'] = QS('termTable')['bottom'] = QS('termTable')['left'] = QS('termTable')['right'] = '0';
885
- } else {
886
- // Legacy terminal
887
- //QS('termTable')['height'] = '100%';
888
- //QS('termTable')['max-height'] = '100%';
889
- }
890
- } else {
891
- QV('deskarea1', true);
892
- QV('deskarea4', true);
893
- QV('xfooter', true);
894
- QS('p11').bottom = '32px';
895
- QS('deskarea0').overflow = null;
896
- QS('deskarea3x').width = null;
897
- QS('deskarea3x').height = QS('deskarea3x')['max-height'] = 'calc(100vh - 60px)';
898
- QS('deskarea3x')['padding-right'] = null;
899
- if (xtermActive) {
900
- // XTerm terminal
901
- //QS('termTable')['position'] = null;
902
- //QS('termTable')['top'] = QS('termTable')['bottom'] = QS('termTable')['left'] = QS('termTable')['right'] = null;
903
- } else {
904
- // Legacy terminal
905
- //QS('termTable')['height'] = 'calc(100vh - ' + (75 + xh) + 'px)';
906
- //QS('termTable')['max-height'] = 'calc(100vh - ' + (75 + xh) + 'px)';
907
- }
908
- }
909
-
910
- inputAllowed = true; // todo
911
-
912
- // Show full screen buttons if needed
913
- QV('deskkeybutton1', fullscreen);
914
- if (xxcurrentView == 11) { // Desktop panel is being shown (11 = Desktop, 12 = Terminal)
915
- // Move shortcut key to desktop position
916
- QS('deskkeybutton2a').top = QS('deskkeybutton2b').top = '210px';
917
- // Move the zoom button to normal or top position
918
- QS('deskkeybutton5a').top = QS('deskkeybutton5b').top = (inputAllowed) ? '160px' : '60px'; // Zoom
919
- QV('deskkeybutton2a', fullscreen && inputAllowed);
920
- QV('deskkeybutton2b', false);
921
- QV('deskkeybutton3a', fullscreen && inputAllowed);
922
- QV('deskkeybutton3b', false);
923
- QV('deskkeybutton4a', fullscreen && inputAllowed && (!desktop.m.SwapMouse));
924
- QV('deskkeybutton4b', fullscreen && inputAllowed && (desktop.m.SwapMouse));
925
- QV('deskkeybutton5a', fullscreen && (fullscreenzoom == 1));
926
- QV('deskkeybutton5b', fullscreen && (fullscreenzoom != 1));
927
- }
928
- if (xxcurrentView == 12) {
929
- // Move right buttons to terminal position
930
- //QS('deskkeybutton3a').top = QS('deskkeybutton3b').top = '60px'; // Shortcuts
931
- //QS('deskkeybutton5a').top = QS('deskkeybutton5b').top = '110px'; // Zoom
932
- QS('deskkeybutton2a').top = QS('deskkeybutton2b').top = '110px'; // Keyboard
933
- QV('deskkeybutton2a', fullscreen);
934
- QV('deskkeybutton2b', false);
935
- QV('deskkeybutton3a', fullscreen);
936
- QV('deskkeybutton3b', false);
937
- QV('deskkeybutton4a', false);
938
- QV('deskkeybutton4b', false);
939
- QV('deskkeybutton5a', false);
940
- QV('deskkeybutton5a', false);
941
- //QV('deskkeybutton5a', xterm.getOption('fontSize') == 15);
942
- //QV('deskkeybutton5b', xterm.getOption('fontSize') != 15);
943
- }
944
-
945
- if (xxcurrentView == 11) { deskAdjust(); }
946
- updateDesktopButtons();
947
- //adjustPanels();
948
- //setTimeout(adjustPanels, 10);
949
- //setTimeout(function() { xtermfit.fit(); }, 10);
950
- if (xterm != null) { if (xxcurrentView == 12) { xtermfit.fit(); xterm.focus(); } }
951
- }
952
-
953
- function mdeskAdjust(mod, sw, sh, cv) {
954
- if (!mod || !sw || !sh || !cv) return;
955
-
956
- // Check if we are in single desktop mode
957
- if (cv.id == 'Desk') { deskAdjust(); return; }
958
-
959
- // Figure out and adjust the size to fill the width of the div
960
- var vsize = [{ x: 180, y: 101 }, { x: 302, y: 169 }, { x: 454, y: 255 }][Q('sizeselect').selectedIndex];
961
- var realw = vsize.x + 2, tw = Q('xdevices').clientWidth - 30, xw = Math.floor(tw / realw);
962
- xw = realw + Math.floor((tw - (xw * realw)) / xw);
963
- vsize.y = vsize.y * (xw / vsize.x);
964
- vsize.x = xw;
965
- var mh = vsize.y, mw = vsize.x;
966
- if (mod.State != 0) { mh = vsize.y; mw = (sw / sh) * vsize.y; }
967
- QS(cv.id)['max-height'] = mh + 'px';
968
- QS(cv.id)['max-width'] = mw + 'px';
969
- QS(cv.id)['margin-top'] = '0';
970
- QS(cv.id)['margin-bottom'] = '0';
971
- }
972
-
973
- // Remote desktop special key combos for Windows
974
- function deskSendKeys() {
975
- if (xxdialogMode || desktop == null || desktop.State != 3) return;
976
- var ks = Q('deskkeys').value;
977
- if (ks == 0) { // WIN+Down arrow
978
- if (desktop.contype == 2) {
979
- desktop.m.sendkey([[0xffe7, 1], [0xff54, 1], [0xff54, 0], [0xffe7, 0]]); // Intel AMT: Meta-left down, Down arrow press, Down arrow release, Meta-left release
980
- } else {
981
- desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN, 0x5B], [desktop.m.KeyAction.DOWN, 40], [desktop.m.KeyAction.UP, 40], [desktop.m.KeyAction.EXUP, 0x5B]]); // Agent: L-Winkey press, Down arrow press, Down arrow release, L-Winkey release
982
- }
983
- } else if (ks == 1) { // WIN+Up arrow
984
- if (desktop.contype == 2) {
985
- desktop.m.sendkey([[0xffe7, 1], [0xff52, 1], [0xff52, 0], [0xffe7, 0]]); // Intel AMT: Meta-left down, Up arrow press, Up arrow release, Meta-left release
986
- } else {
987
- desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN, 0x5B], [desktop.m.KeyAction.DOWN, 38], [desktop.m.KeyAction.UP, 38], [desktop.m.KeyAction.EXUP, 0x5B]]); // MeshAgent: L-Winkey press, Up arrow press, Up arrow release, L-Winkey release
988
- }
989
- } else if (ks == 2) { // WIN+L arrow
990
- if (desktop.contype == 2) {
991
- desktop.m.sendkey([[0xffe7, 1], [0x6c, 1], [0x6c, 0], [0xffe7, 0]]); // Intel AMT: Meta-left down, 'l' press, 'l' release, Meta-left release
992
- } else {
993
- desktop.sendCtrlMsg('{"action":"lock"}');
994
- //desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN,0x5B],[desktop.m.KeyAction.DOWN,76],[desktop.m.KeyAction.UP,76],[desktop.m.KeyAction.EXUP,0x5B]]); // MeshAgent: L-Winkey press, 'L' press, 'L' release, L-Winkey release
995
- //desktop.m.SendKeyMsgKC(desktop.m.KeyAction.EXDOWN, 0x5B);
996
- //desktop.m.SendKeyMsgKC(desktop.m.KeyAction.DOWN, 76);
997
- //desktop.m.SendKeyMsgKC(desktop.m.KeyAction.UP, 76);
998
- //desktop.m.SendKeyMsgKC(desktop.m.KeyAction.EXUP, 0x5B);
999
- }
1000
- } else if (ks == 3) { // WIN+M arrow
1001
- if (desktop.contype == 2) {
1002
- desktop.m.sendkey([[0xffe7, 1], [0x6d, 1], [0x6d, 0], [0xffe7, 0]]); // Intel AMT: Meta-left down, 'm' press, 'm' release, Meta-left release
1003
- } else {
1004
- desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN, 0x5B], [desktop.m.KeyAction.DOWN, 77], [desktop.m.KeyAction.UP, 77], [desktop.m.KeyAction.EXUP, 0x5B]]); // MeshAgent: L-Winkey press, 'M' press, 'M' release, L-Winkey release
1005
- }
1006
- } else if (ks == 4) { // Shift+WIN+M arrow
1007
- if (desktop.contype == 2) {
1008
- desktop.m.sendkey([[0xffe1, 1], [0xffe7, 1], [0x6d, 1], [0x6d, 0], [0xffe7, 0], [0xffe1, 0]]); // Intel AMT: Shift-left down, Meta-left down, 'm' press, 'm' release, Meta-left release, Shift-left release
1009
- } else {
1010
- desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.DOWN, 16], [desktop.m.KeyAction.EXDOWN, 0x5B], [desktop.m.KeyAction.DOWN, 77], [desktop.m.KeyAction.UP, 77], [desktop.m.KeyAction.EXUP, 0x5B], [desktop.m.KeyAction.UP, 16]]); // MeshAgent: L-shift press, L-Winkey press, 'M' press, 'M' release, L-Winkey release, L-shift release
1011
- }
1012
- } else if (ks == 5) { // WIN
1013
- if (desktop.contype == 2) {
1014
- desktop.m.sendkey([[0xffe7, 1], [0xffe7, 0]]); // Intel AMT: Meta-left down, Meta-left release
1015
- } else {
1016
- desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN, 0x5B], [desktop.m.KeyAction.EXUP, 0x5B]]); // MeshAgent: L-Winkey press, L-Winkey release
1017
- }
1018
- } else if (ks == 6) { // WIN+R
1019
- if (desktop.contype == 2) {
1020
- desktop.m.sendkey([[0xffe7, 1], [0x72, 1], [0x72, 0], [0xffe7, 0]]); // Intel AMT: Meta-left down, 'r' press, 'r' release, Meta-left release
1021
- } else {
1022
- desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN, 0x5B], [desktop.m.KeyAction.DOWN, 82], [desktop.m.KeyAction.UP, 82], [desktop.m.KeyAction.EXUP, 0x5B]]); // MeshAgent: L-Winkey press, 'R' press, 'R' release, L-Winkey release
1023
- }
1024
- } else if (ks == 7) { // ALT-F4
1025
- if (desktop.contype == 2) {
1026
- desktop.m.sendkey([[0xffe9, 1], [0xffc1, 1], [0xffc1, 0], [0xffe9, 0]]); // Intel AMT: Alt down, 'F4' press, 'F4' release, Alt release
1027
- } else {
1028
- desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN, 18], [desktop.m.KeyAction.DOWN, 115], [desktop.m.KeyAction.UP, 115], [desktop.m.KeyAction.EXUP, 18]]); // MeshAgent: Alt press, 'F4' press, 'F4' release, Alt release
1029
- }
1030
- } else if (ks == 8) { // CTRL-W
1031
- if (desktop.contype == 2) {
1032
- desktop.m.sendkey([[0xffe3, 1], [0x77, 1], [0x77, 0], [0xffe3, 0]]); // Intel AMT: Ctrl down, 'w' press, 'w' release, Ctrl release
1033
- } else {
1034
- desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN, 17], [desktop.m.KeyAction.DOWN, 87], [desktop.m.KeyAction.UP, 87], [desktop.m.KeyAction.EXUP, 17]]); // MeshAgent: Ctrl press, 'W' press, 'W' release, Ctrl release
1035
- }
1036
- } else if (ks == 9) { // ALT-TAB
1037
- if (desktop.contype == 2) {
1038
- desktop.m.sendkey([[0xffe9, 1], [0xff09, 1], [0xff09, 0], [0xffe9, 0]]); // Intel AMT: Alt down, 'TAB' press, 'TAB' release, Alt release
1039
- } else {
1040
- desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN, 18], [desktop.m.KeyAction.DOWN, 9], [desktop.m.KeyAction.UP, 9], [desktop.m.KeyAction.EXUP, 18]]); // MeshAgent: Alt press, 'TAB' press, 'TAB' release, Alt release
1041
- }
1042
- } else if (ks == 10) { // CTRL-ALT-DEL
1043
- desktop.m.sendcad();
1044
- } else if (ks == 11) { // WIN-LEFT
1045
- if (desktop.contype == 2) {
1046
- desktop.m.sendkey([[0xffe7, 1], [0xff51, 1], [0xff51, 0], [0xffe7, 0]]); // Intel AMT: Meta-left down, Left arrow press, Left arrow release, Meta-left release
1047
- } else {
1048
- desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN, 0x5B], [desktop.m.KeyAction.DOWN, 37], [desktop.m.KeyAction.UP, 37], [desktop.m.KeyAction.EXUP, 0x5B]]);
1049
- }
1050
- } else if (ks == 12) { // WIN-RIGHT
1051
- if (desktop.contype == 2) {
1052
- desktop.m.sendkey([[0xffe7, 1], [0xff53, 1], [0xff53, 0], [0xffe7, 0]]); // Intel AMT: Meta-left down, Right arrow press, Right arrow release, Meta-left release
1053
- } else {
1054
- desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN, 0x5B], [desktop.m.KeyAction.DOWN, 39], [desktop.m.KeyAction.UP, 39], [desktop.m.KeyAction.EXUP, 0x5B]]);
1055
- }
1056
- }
1057
- }
1058
-
1059
-
1060
- var gotKeyPressEvent = false;
1061
- function ondeskkeypress(e, t) {
1062
- setSessionActivity();
1063
- if (desktop && !xxdialogMode && (xxcurrentView == 11)) {
1064
- gotKeyPressEvent = true;
1065
- Q('softKeyboard').value = '';
1066
- // Check what keys we are allows to send
1067
- var inputAllowed = true; // TODO
1068
- if (inputAllowed == false) return false;
1069
- return desktop.m.handleKeys(e);
1070
- }
1071
- if (terminal && !xxdialogMode && (xxcurrentView == 12) (t !== 1)) {
1072
- if (e.altKey == true) { return true; }
1073
- gotKeyPressEvent = true;
1074
- Q('softKeyboard').value = '';
1075
- var k = 0;
1076
- if (e.charCode != 0) { k = e.charCode; } else if (e.keyCode != 0) { k = e.keyCode; }
1077
- if (k != 0) {
1078
- if (terminal.urlname == 'sshterminalrelay.ashx') {
1079
- // SSH
1080
- terminal.socket.send('~' + String.fromCharCode(k));
1081
- } else {
1082
- // Agent
1083
- terminal.sendText(String.fromCharCode(k));
1084
- }
1085
- }
1086
- return false;
1087
- }
1088
- }
1089
-
1090
- function ondeskkeydown(e, t) {
1091
- setSessionActivity();
1092
- if (desktop && !xxdialogMode && (xxcurrentView == 11)) {
1093
- gotKeyPressEvent = false;
1094
- Q('softKeyboard').value = '';
1095
- // Check what keys we are allows to send
1096
- var inputAllowed = true; // TODO
1097
- if (inputAllowed == false) return false;
1098
- return desktop.m.handleKeyDown(e);
1099
- }
1100
- if (terminal && !xxdialogMode && (xxcurrentView == 12) && (t !== 1)) {
1101
- if (e.altKey == true) { return true; }
1102
- Q('softKeyboard').value = '';
1103
- gotKeyPressEvent = false;
1104
- var k = 0;
1105
- if (e.charCode != 0) { k = e.charCode; } else if (e.keyCode != 0) { k = e.keyCode; }
1106
- if (k == 8) { terminal.sendText(String.fromCharCode(k)); } // Enter and backspace
1107
- else if (e.ctrlKey && (k >= 64) && (k <= 95)) {
1108
- // Ctrl keys
1109
- if (terminal.urlname == 'sshterminalrelay.ashx') {
1110
- // SSH
1111
- terminal.socket.send('~' + String.fromCharCode(k - 64));
1112
- } else {
1113
- // Agent
1114
- terminal.sendText(String.fromCharCode(k - 64));
1115
- }
1116
- }
1117
- }
1118
- }
1119
-
1120
- function ondeskkeyup(e, t) {
1121
- setSessionActivity();
1122
- if (desktop && !xxdialogMode && (xxcurrentView == 11)) {
1123
- var inputStr = Q('softKeyboard').value;
1124
- Q('softKeyboard').value = '';
1125
- // Check what keys we are allows to send
1126
- var inputAllowed = true; // TODO
1127
- if (inputAllowed == false) return false;
1128
- if ((gotKeyPressEvent == false) && (inputStr.length > 0) && desktop.m.SendKeyUnicode) {
1129
- // This is a mobile keyboard, we need to send that is in the input control.
1130
- var inputchar = inputStr[inputStr.length - 1].charCodeAt(0);
1131
- desktop.m.SendKeyUnicode(desktop.m.KeyAction.DOWN, inputchar);
1132
- desktop.m.SendKeyUnicode(desktop.m.KeyAction.UP, inputchar);
1133
- } else {
1134
- return desktop.m.handleKeyUp(e);
1135
- }
1136
- }
1137
- if (terminal && !xxdialogMode && (xxcurrentView == 12) && (gotKeyPressEvent == false) && (t !== 1)) {
1138
- if (e.altKey == true) { return true; }
1139
- var inputStr = Q('softKeyboard').value;
1140
- Q('softKeyboard').value = '';
1141
- if (terminal.urlname == 'sshterminalrelay.ashx') {
1142
- // SSH
1143
- terminal.socket.send('~' + inputStr);
1144
- } else {
1145
- // Agent
1146
- if (inputStr) terminal.sendText(inputStr);
1147
- }
1148
- return false;
1149
- }
1150
- }
1151
-
1152
-
1153
- // Remote desktop typing
1154
- function showDeskType() {
1155
- if (xxdialogMode || desktop == null || desktop.State != 3) return;
1156
- Q('DeskType').blur();
1157
- var x = '<div>' + "Enter text and click OK to remotely type it using a US english keyboard. Make sure to place the remote cursor at the correct position before proceeding." + '<div>';
1158
- x += '<textarea id=d2typeText style="margin-top:5px;width:100%;height:184px;resize:none" maxlength=2000></textarea>';
1159
- setDialogMode(2, "Remote Keyboard Entry", 3, showDeskTypeEx, x);
1160
- Q('d2typeText').focus();
1161
- }
1162
-
1163
- var AmtDeskTypeTimer = null;
1164
- var AmtDeskTypeContent = null;
1165
- var DeskTypeTranslate = { 39: 222, 42: 106, 43: 107, 44: 188, 45: 189, 46: 190, 47: 191, 59: 186, 61: 187, 91: 219, 92: 220, 93: 221, 96: 192, 191: 111 };
1166
- var DeskTypeShiftTranslate = { 33: 49, 34: 222, 35: 51, 36: 52, 37: 53, 38: 55, 40: 57, 41: 48, 58: 186, 60: 188, 62: 190, 63: 191, 64: 50, 94: 54, 95: 189, 106: 56, 107: 187, 123: 219, 124: 220, 125: 221, 126: 192 };
1167
- function showDeskTypeEx() {
1168
- var txt = Q('d2typeText').value, ltxt = Q('d2typeText').value.toUpperCase(), x = [], shift = false;
1169
- if (desktop.contype == 2) {
1170
- // Intel AMT
1171
- for (var i in txt) { var a = txt.charCodeAt(i); x.push([a, 1], [a, 0]); }
1172
- AmtDeskTypeContent = x;
1173
- AmtDeskTypeTimer = setInterval(function () {
1174
- var key = AmtDeskTypeContent.shift();
1175
- if (desktop) { desktop.m.sendkey(key[0], key[1]); }
1176
- if ((desktop == null) || (AmtDeskTypeContent.length == 0)) { clearInterval(AmtDeskTypeTimer); AmtDeskTypeContent = null; }
1177
- }, 10);
1178
- } else {
1179
- // MeshAgent
1180
- for (var i in txt) {
1181
- var a = txt.charCodeAt(i), b = ltxt.charCodeAt(i);
1182
- if (((a >= 65) && (a <= 90)) || ((a >= 97) && (a <= 122))) {
1183
- if ((a == b) && (shift == false)) { x.push([desktop.m.KeyAction.DOWN, 16]); shift = true; } // LShift down
1184
- if ((a != b) && (shift == true)) { x.push([desktop.m.KeyAction.UP, 16]); shift = false; } // LShift up
1185
- } else if ((a >= 48) && (a <= 57)) {
1186
- if (shift == true) { x.push([desktop.m.KeyAction.UP, 16]); shift = false; } // Shift up
1187
- } else if (DeskTypeTranslate[a]) {
1188
- if (shift == true) { x.push([desktop.m.KeyAction.UP, 16]); shift = false; } // Shift up
1189
- b = DeskTypeTranslate[a];
1190
- } else if (DeskTypeShiftTranslate[a]) {
1191
- if (shift == false) { x.push([desktop.m.KeyAction.DOWN, 16]); shift = true; } // LShift down
1192
- b = DeskTypeShiftTranslate[a];
1193
- }
1194
- x.push([desktop.m.KeyAction.DOWN, b], [desktop.m.KeyAction.UP, b]);
1195
- }
1196
- if (shift == true) { x.push([desktop.m.KeyAction.UP, 16]); shift = false; } // Shift up
1197
- desktop.m.SendKeyMsgKC(x);
1198
- }
1199
- }
1200
-
1201
- /*
1202
- // Show clipboard dialog
1203
- function showDeskClip() {
1204
- if (xxdialogMode || desktop == null || desktop.State != 3) return;
1205
- Q('DeskClip').blur();
1206
- var x = '';
1207
- x += '<input id=dlgClipGet type=button value="Get Clipboard" style=width:120px onclick=showDeskClipGet()>';
1208
- x += '<input id=dlgClipSet type=button value="Set Clipboard" style=width:120px onclick=showDeskClipSet()>';
1209
- x += '<div id=dlgClipStatus style="display:inline-block;margin-left:8px" ></div>';
1210
- x += '<textarea id=d2clipText style="width:100%;height:184px;resize:none" maxlength=65535></textarea>';
1211
- x += '<input type=button value="Close" style=width:80px;float:right onclick=dialogclose(0)><div style=height:26px;margin-top:3px><span id=linuxClipWarn style=display:none>' + "Remote clipboard is valid for 60 seconds." + '</span> </div><div></div>';
1212
- setDialogMode(2, "Remote Clipboard", 8, null, x, 'clipboard');
1213
- Q('d2clipText').focus();
1214
- }
1215
-
1216
- function showDeskClipGet() {
1217
- if (desktop == null || desktop.State != 3) return;
1218
- meshserver.send({ action: 'msg', type: 'getclip', nodeid: currentNode._id });
1219
- }
1220
-
1221
- function showDeskClipSet() {
1222
- if (desktop == null || desktop.State != 3) return;
1223
- meshserver.send({ action: 'msg', type: 'setclip', nodeid: currentNode._id, data: Q('d2clipText').value });
1224
- //QV('linuxClipWarn', currentNode && currentNode.agent && (currentNode.agent.id > 4) && (currentNode.agent.id != 21) && (currentNode.agent.id != 22));
1225
- }
1226
- */
1227
-
1228
- // Send CTRL-ALT-DEL
1229
- function sendCAD() {
1230
- if (xxdialogMode || desktop == null || desktop.State != 3) return;
1231
- desktop.m.sendcad();
1232
- }
1233
-
1234
- // Toggle mouse and keyboard input
1235
- function toggleKvmControl() { QS('DeskControlSpan').color = Q('DeskControl').checked ? null : 'red'; }
1236
-
1237
- // Save the desktop image to file
1238
- function deskSaveImage() {
1239
- if (xxdialogMode || desktop == null || desktop.State != 3) return;
1240
- var d = new Date(), n = "Desktop" + '-' + d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2) + '-' + ('0' + d.getHours()).slice(-2) + '-' + ('0' + d.getMinutes()).slice(-2);
1241
- Q('Desk')['toBlob'](function (blob) { saveAs(blob, n + '.png'); });
1242
- }
1243
-
1244
- function deskDisplayInfo(sender, displays, selDisplay) {
1245
- var displayCount = 0, displaySelector = '';
1246
- for (var i in displays) {
1247
- displayCount++;
1248
- displaySelector += '<option' + ((selDisplay == i) ? ' selected' : '') + ' value=' + i + '>' + displays[i] + '</option>';
1249
- if ((deskPreferedStickyDisplay == i) && (selDisplay != deskPreferedStickyDisplay)) { desktop.m.SetDisplay(i); }
1250
- deskPreferedStickyDisplay = -1;
1251
- }
1252
- QH('termdisplays', displaySelector);
1253
- QV('termdisplays', displayCount > 1);
1254
- }
1255
-
1256
- function deskGetDisplayNumbers(e) { desktop.m.GetDisplayNumbers(); }
1257
- var deskPreferedStickyDisplay = -1;
1258
- function deskSetDisplay(e) { desktop.m.SetDisplay(deskPreferedStickyDisplay = parseInt(Q('termdisplays').value)); Q('termdisplays').blur(); }
1259
-
1260
- // Double click detection. This is important for macOS.
1261
- var dblClickDetectArgs = { t: 0, x: 0, y: 0 };
1262
- function dblClickDetect(e) {
1263
- if (e.buttons != 1) return;
1264
- var t = Date.now();
1265
- if (((t - dblClickDetectArgs.t) < 250) && (Math.abs(e.clientX - dblClickDetectArgs.x) < 2) && (Math.abs(e.clientY - dblClickDetectArgs.y) < 2)) {
1266
- if (!xxdialogMode && desktop != null && isInputAllowed()) { if ((webRtcDesktop != null) && (webRtcDesktop.softdesktop != null)) { webRtcDesktop.softdesktop.m.mousedblclick(e); desktop.m.sendKeepAlive(); } else { desktop.m.mousedblclick(e); } }
1267
- }
1268
- dblClickDetectArgs.t = t;
1269
- dblClickDetectArgs.x = e.clientX;
1270
- dblClickDetectArgs.y = e.clientY;
1271
- }
1272
-
1273
- function dmousedown(e) { setSessionActivity(); if ((!xxdialogMode && desktop != null)) { if (fullscreen) { e.addx = Q('deskarea0').scrollLeft * (1 / fullscreenzoom); e.addy = Q('deskarea0').scrollTop * (1 / fullscreenzoom); } desktop.m.mousedown(e); } }
1274
- function dmouseup(e) { setSessionActivity(); if ((!xxdialogMode && desktop != null)) { if (fullscreen) { e.addx = Q('deskarea0').scrollLeft * (1 / fullscreenzoom); e.addy = Q('deskarea0').scrollTop * (1 / fullscreenzoom); } desktop.m.mouseup(e); } }
1275
- function dmousemove(e) { setSessionActivity(); if ((!xxdialogMode && desktop != null)) { if (fullscreen) { e.addx = Q('deskarea0').scrollLeft * (1 / fullscreenzoom); e.addy = Q('deskarea0').scrollTop * (1 / fullscreenzoom); } desktop.m.mousemove(e); } }
1276
- function dmousewheel(e) { setSessionActivity(); if ((!xxdialogMode && desktop != null) && desktop.m.mousewheel) { if (fullscreen) { e.addx = Q('deskarea0').scrollLeft * (1 / fullscreenzoom); e.addy = Q('deskarea0').scrollTop * (1 / fullscreenzoom); } desktop.m.mousewheel(e); haltEvent(e); return true; } return false; }
1277
-
1278
- var keyboardShown = false;
1279
- var keyboardShownTimer = null;
1280
- var fullScreenMode = false;
1281
- function toggleKeyboard() {
1282
- if (xxdialogMode) return;
1283
- if (keyboardShownTimer != null) { clearTimeout(keyboardShownTimer); }
1284
- if (keyboardShown) { Q('softKeyboard').blur(); keyboardShown = false; } else { Q('softKeyboard').focus(); keyboardShown = true; }
1285
- QV('deskkeybutton2a', fullscreen && !keyboardShown);
1286
- QV('deskkeybutton2b', fullscreen && keyboardShown);
1287
- }
1288
-
1289
- function keyboardFocusChange() {
1290
- keyboardShownTimer = setTimeout(function () {
1291
- keyboardShownTimer = null;
1292
- keyboardShown = (Q('softKeyboard') == document.activeElement);
1293
- QV('deskkeybutton2a', fullscreen && !keyboardShown);
1294
- QV('deskkeybutton2b', fullscreen && keyboardShown);
1295
- }, 100);
1296
- }
1297
-
1298
- function exitButton() {
1299
- if (xxdialogMode) return;
1300
- QV('deskButtonMenu', false);
1301
- QV('termButtonMenu', false);
1302
- if (fullscreenzoom == 1) {
1303
- deskToggleFull();
1304
- } else {
1305
- deskChangeFullscreenZoom();
1306
- setTimeout(deskToggleFull, 10);
1307
- }
1308
- }
1309
-
1310
- function deskMenuButton(x) {
1311
- toggleMenu(true);
1312
- deskSendKeys(x);
1313
- }
1314
-
1315
-
1316
- //
1317
- // Desktop Shortcut Keys
1318
- //
1319
-
1320
- function updateDeskShortcutKeys() {
1321
- var x = ''; //'<div class="menuButton" onclick="deskMenuButton(-1)">' + "Customize" + '</div>';
1322
- for (var i in deskKeyboardShortcuts) { x += '<div class="menuButton" onclick="deskMenuButton(' + deskKeyboardShortcuts[i] + ')">' + keyShortcutTotext(deskKeyboardShortcuts[i]) + '</div>'; }
1323
- QH('deskButtonMenu', x);
1324
- }
1325
-
1326
- var keyStrings = { 8: "BackSpace", 9: "Tab", 13: "Enter", 27: "Escape", 44: "Print Screen", 45: "Insert", 46: "Del", 36: "Home", 35: "End", 33: "Page Up", 34: "Page Down", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 0: "None" }
1327
-
1328
- function keyShortcutTotext(n) {
1329
- var x = [];
1330
- if (n & 0x010000) { x.push("Shift"); }
1331
- if (n & 0x020000) { x.push("Alt"); }
1332
- if (n & 0x080000) { x.push("Ctrl"); }
1333
- if (n & 0x100000) { x.push("Win"); }
1334
- n = (n & 0xFFFF);
1335
- if ((n >= 112) && (n <= 123)) { x.push('F' + (n - 111)); } // Fx keys
1336
- else if ((n != 0) && (keyStrings[n])) { x.push(keyStrings[n]); }
1337
- else { if (n != 0) { x.push(String.fromCharCode(n)); } }
1338
- return x.join(' + ');
1339
- }
1340
-
1341
- // Customize keyboard shortcuts
1342
- function deskCustomizeKeys() {
1343
- if (xxdialogMode) return;
1344
- var x = '<div id=d2shortcuts style="width:100%;height:180px;padding:4px;overflow-y:auto;border:1px solid gray"></div><div style=width:100%;padding:5px>';
1345
- x += '<label><input id=d1kshift type=checkbox /> ' + "Shift" + '</label><label> <input id=d1kalt type=checkbox /> ' + "Alt" + '</label><label> <input id=d1kctrl type=checkbox /> ' + "Ctrl" + '</label> <input id=d1kwin type=checkbox /> ' + "Win" + '</label>';
1346
- x += ' <select id=d2keySelect>';
1347
- for (var i in keyStrings) { x += '<option value=' + i + '>' + keyStrings[i] + '</option>'; }
1348
- for (var i = 1; i <= 12; i++) { x += '<option value=' + (i + 111) + '>F' + i + '</option>'; }
1349
- for (var i = 0; i < 10; i++) { x += '<option value=' + (i + 48) + '>' + i + '</option>'; }
1350
- for (var i = 0; i < 26; i++) { x += '<option value=' + (i + 65) + '>' + String.fromCharCode(i + 65) + '</option>'; }
1351
- x += '</select> <input type=button value=' + "Add" + ' onclick=addDeskCustomizeKey() /></div>';
1352
- QH('p10dialog2', x);
1353
- xxdialogMode = 2;
1354
- QV('p10dialog', true);
1355
- deskUpdateShortcutList();
1356
- }
1357
-
1358
- function deskCustomizeKeysEx() {
1359
- QV('p10dialog', false);
1360
- xxdialogMode = 0;
1361
- //putstore('deskKeyShortcuts', deskKeyboardShortcuts.join(','));
1362
- updateDeskShortcutKeys();
1363
- }
1364
-
1365
- function deskUpdateShortcutList() {
1366
- var x = '';
1367
- for (var i in deskKeyboardShortcuts) {
1368
- var kt = keyShortcutTotext(deskKeyboardShortcuts[i]), orderButtons = '';
1369
- if (i != (deskKeyboardShortcuts.length - 1)) { orderButtons += '<img width=8 height=8 style=float:right;cursor:pointer;padding:3px src="images/c2.png" onclick=deskCustomizeKeyDown(' + deskKeyboardShortcuts[i] + ')>'; }
1370
- if (i != 0) { orderButtons += '<img width=8 height=8 style=float:right;cursor:pointer;padding:3px src="images/c3.png" onclick=deskCustomizeKeyUp(' + deskKeyboardShortcuts[i] + ')>'; }
1371
- x += '<div style="width:100%;background-color:#AAA;border-radius:4px;margin-bottom:4px;padding:4px;text-align:left;box-sizing:border-box" value=' + deskKeyboardShortcuts[i] + '>' + kt + '<img width=10 height=10 style=float:right;cursor:pointer;padding:2px;margin-left:8px src="images/trash.png" onclick=removeDeskCustomizeKey(' + deskKeyboardShortcuts[i] + ')>' + orderButtons + '</div>';
1372
- }
1373
- if (x == '') { x = '<i>' + "No keyboard shortcuts defined" + '</i>'; }
1374
- QH('d2shortcuts', x);
1375
- }
1376
-
1377
- function deskCustomizeKeyDown(k) {
1378
- var i = deskKeyboardShortcuts.indexOf(k), x = deskKeyboardShortcuts[i + 1];
1379
- deskKeyboardShortcuts[i + 1] = deskKeyboardShortcuts[i];
1380
- deskKeyboardShortcuts[i] = x;
1381
- deskUpdateShortcutList();
1382
- }
1383
-
1384
- function deskCustomizeKeyUp(k) {
1385
- var i = deskKeyboardShortcuts.indexOf(k), x = deskKeyboardShortcuts[i];
1386
- deskKeyboardShortcuts[i] = deskKeyboardShortcuts[i - 1];
1387
- deskKeyboardShortcuts[i - 1] = x;
1388
- deskUpdateShortcutList();
1389
- }
1390
-
1391
- function removeDeskCustomizeKey(k) {
1392
- var na = [];
1393
- for (var i in deskKeyboardShortcuts) { if (deskKeyboardShortcuts[i] != k) { na.push(deskKeyboardShortcuts[i]); } }
1394
- deskKeyboardShortcuts = na;
1395
- deskUpdateShortcutList();
1396
- }
1397
-
1398
- function addDeskCustomizeKey() {
1399
- var k = parseInt(Q('d2keySelect').value);
1400
- if (Q('d1kshift').checked) { k |= 0x010000; }
1401
- if (Q('d1kalt').checked) { k |= 0x020000; }
1402
- if (Q('d1kctrl').checked) { k |= 0x080000; }
1403
- if (Q('d1kwin').checked) { k |= 0x100000; }
1404
- if ((k > 0) && (deskKeyboardShortcuts.indexOf(k) == -1)) { deskKeyboardShortcuts.push(k); deskUpdateShortcutList(); }
1405
- }
1406
-
1407
- // Remote desktop special key combos for Windows
1408
- function deskSendKeys(ks) {
1409
- if (xxdialogMode || desktop == null || desktop.State != 3) return;
1410
-
1411
- // Construct the key command
1412
- if (ks == -1) { deskCustomizeKeys(); return; } // Customize
1413
- if (ks == 0x0A002E) { desktop.m.sendcad(); return; } // CTRL-ALT-DEL
1414
- //if ((desktop.contype == 1) && (ks == 0x10004C)) { desktop.sendCtrlMsg('{"action":"lock"}'); return; } // Lock desktop, WIN + L
1415
-
1416
- var flags = (ks & 0xFF0000) >> 16, key = (ks & 0xFFFF), keyArray = [], keyArray2 = [];
1417
- var amtTranslate = {
1418
- 8: 0xff08, // BackSpace
1419
- 9: 0xff09, // Tab
1420
- 13: 0xff0d, // Return or Enter
1421
- 27: 0xff1b, // Escape
1422
- 45: 0xff63, // Insert
1423
- 46: 0xffff, // Delete
1424
- 36: 0xff50, // Home
1425
- 35: 0xff57, // End
1426
- 33: 0xff55, // Page Up
1427
- 34: 0xff56, // Page Down
1428
- 37: 0xff51, // Left arrow
1429
- 38: 0xff52, // Up arrow
1430
- 39: 0xff53, // Right arrow
1431
- 40: 0xff54, // Down arrow
1432
- 112: 0xffbe, // F1
1433
- 113: 0xffbf, // F2
1434
- 114: 0xffc0, // F3
1435
- 115: 0xffc1, // F4
1436
- 116: 0xffc2, // F5
1437
- 117: 0xffc3, // F6
1438
- 118: 0xffc4, // F7
1439
- 119: 0xffc5, // F8
1440
- 120: 0xffc6, // F9
1441
- 121: 0xffc7, // F10
1442
- 122: 0xffc8, // F11
1443
- 123: 0xffc9 // F12
1444
- }
1445
-
1446
- // 0x010000 = Shift
1447
- // 0x020000 = Left-Alt
1448
- // 0x080000 = Ctrl
1449
- // 0x100000 = Window
1450
-
1451
- if (desktop.contype == 2) {
1452
- // Intel AMT
1453
- if (flags & 1) { keyArray.push([0xffe1, 1]); keyArray2.push([0xffe1, 0]); } // Shift
1454
- if (flags & 2) { keyArray.push([0xffe9, 1]); keyArray2.push([0xffe9, 0]); } // Left-alt
1455
- if (flags & 8) { keyArray.push([0xffe3, 1]); keyArray2.push([0xffe3, 0]); } // Ctrl
1456
- if (flags & 16) { keyArray.push([0xffe7, 1]); keyArray2.push([0xffe7, 0]); } // Windows key
1457
- if (amtTranslate[key]) { key = amtTranslate[key]; }
1458
- if ((key >= 65) && (key <= 90)) { key += 32; }
1459
- if (key != 0) { keyArray.push([key, 1]); keyArray2.push([key, 0]); }
1460
- keyArray2.reverse();
1461
- for (var i = 0; i < keyArray2.length; i++) { keyArray.push(keyArray2[i]); }
1462
- desktop.m.sendkey(keyArray);
1463
- } else {
1464
- // Agent desktop
1465
- if (flags & 1) { keyArray.push([desktop.m.KeyAction.DOWN, 16]); keyArray2.push([desktop.m.KeyAction.UP, 16]); } // Shift
1466
- if (flags & 2) { keyArray.push([desktop.m.KeyAction.EXDOWN, 18]); keyArray2.push([desktop.m.KeyAction.EXUP, 18]); } // Left-alt
1467
- if (flags & 8) { keyArray.push([desktop.m.KeyAction.EXDOWN, 17]); keyArray2.push([desktop.m.KeyAction.EXUP, 17]); } // Ctrl
1468
- if (flags & 16) { keyArray.push([desktop.m.KeyAction.EXDOWN, 0x5B]); keyArray2.push([desktop.m.KeyAction.EXUP, 0x5B]); } // Windows key
1469
- if (key != 0) { keyArray.push([desktop.m.KeyAction.DOWN, key]); keyArray2.push([desktop.m.KeyAction.UP, key]); }
1470
- keyArray2.reverse();
1471
- for (var i = 0; i < keyArray2.length; i++) { keyArray.push(keyArray2[i]); }
1472
- desktop.m.SendKeyMsgKC(keyArray);
1473
- }
1474
- }
1475
-
1476
-
1477
- //
1478
- // Terminal
1479
- //
1480
-
1481
- function setupTerminal() {
1482
- // Setup the terminal
1483
- if (terminal != null) { terminal.Stop(); terminal = null; }
1484
- updateTerminalButtons();
1485
-
1486
- // Terminal special keys
1487
- var x = '';
1488
- for (var c = 1; c < 27; c++) x += '<option value=\'' + c + '\'>' + "Ctrl" + '-' + String.fromCharCode(64 + c) + ' (' + c + ')</option>';
1489
- QH('specialkeylist', x);
1490
- }
1491
-
1492
- // Show and enable the right buttons
1493
- function updateTerminalButtons() {
1494
- var termState = ((terminal != null) && (terminal.state != 0));
1495
-
1496
- // Show the right buttons
1497
- QV('disconnectbutton2span', termState == true);
1498
- QV('connectbutton2span', termState == false);
1499
- //QV('terminalSizeDropDown', termState == false);
1500
-
1501
- // Enable buttons
1502
- QE('connectbutton2', true);
1503
-
1504
- // Key buttons
1505
- QE('ctrlcbutton', termState);
1506
- QE('ctrlxbutton', termState);
1507
- QE('escbutton', termState);
1508
- QE('bsbutton', termState);
1509
- QE('pastebutton', termState);
1510
- QE('specialkeylist', termState);
1511
- QE('specialkeylistinput', termState);
1512
-
1513
- // Terminal settings
1514
- QV('terminalSettingsButtons', (terminal) && (terminal.contype == 2));
1515
- if (terminal) {
1516
- Q('id_ttypebutton').value = terminalEmulations[terminal.m.terminalEmulation];
1517
- Q('id_tfxkeysbutton').value = fxEmulations[terminal.m.fxEmulation];
1518
- Q('id_tcrbutton').value = (terminal.m.lineFeed == '\r\n') ? "CR+LF" : "LF";
1519
- }
1520
-
1521
- // Display extra buttons on legacy terminal
1522
- var xtermActive = true;
1523
- QV('termarea3xdiv', xtermActive);
1524
- QV('bsbutton', !xtermActive);
1525
- QV('pastebutton', !xtermActive);
1526
- QV('devListToolbarViewIcons2', xtermActive);
1527
- QE('termSizeList', terminal == null);
1528
- }
1529
-
1530
- // Called when the terminal state changes
1531
- function onTerminalStateChange(xterminal, state) {
1532
- var xstate = state;
1533
- if ((xstate == 3) && (xterminal.contype == 2)) { xstate++; }
1534
- var str = StatusStrs[xstate];
1535
- if (terminal.webRtcActive == true) { str += ", WebRTC"; }
1536
- QH('termstatus', str);
1537
- switch (state) {
1538
- case 0:
1539
- // Disconnected, clear the terminal
1540
- QH('termtitle', '');
1541
- QV('termRecordIcon', false);
1542
- if (xterm == null) {
1543
- xterminal.m.TermResetScreen();
1544
- xterminal.m.TermDraw();
1545
- } else {
1546
- xterm.dispose();
1547
- xterm = xtermfit = null;
1548
- }
1549
- if (terminal != null) { terminal.Stop(); terminal = null; }
1550
- break;
1551
- case 3:
1552
- if (xterminal && (xterminal.serverIsRecording == true)) { QV('termRecordIcon', true); }
1553
- terminal.startTime = new Date();
1554
- if (updateSessionTimer == null) { updateSessionTimer = setInterval(updateSessionTime, 1000); }
1555
- if (xterm != null) { xterm.focus(); }
1556
- break;
1557
- default:
1558
- //console.log('Unhandled onTerminalStateChange state', state);
1559
- break;
1560
- }
1561
- updateTerminalButtons();
1562
- }
1563
-
1564
- function updateSessionTime() {
1565
- // Terminal
1566
- var latencyStr = '', seconds = 0;
1567
- if (terminal && terminal.startTime) {
1568
- if (terminal.latency && (terminal.latency.current >= 0)) { latencyStr = format('{0} ms, ', terminal.latency.current); }
1569
- seconds = Math.floor((new Date() - terminal.startTime) / 1000);
1570
- QH('TermTimer', latencyStr + zeroPad(Math.floor(seconds / 3600), 2) + ':' + zeroPad((Math.floor(seconds / 60) % 60), 2) + ':' + zeroPad((seconds % 60), 2));
1571
- } else {
1572
- QH('TermTimer', '');
1573
- }
1574
-
1575
- if (terminal == null) { clearInterval(updateSessionTimer); updateSessionTimer = null; }
1576
- }
1577
-
1578
- // DEBUG
1579
- var autoConnectTerminalTimer = null;
1580
- function autoConnectTerminal(e) { if (autoConnectTerminalTimer == null) { autoConnectTerminalTimer = setInterval(connectTerminal, 100); } else { clearInterval(autoConnectTerminalTimer); autoConnectTerminalTimer = null; } }
1581
-
1582
- // Handles a tunnel to a remote shell
1583
- function CreateRemoteTunnel(onTunnelUpdate, options) {
1584
- var obj = { protocol: 1 };
1585
- if ((options != null) && (typeof options.protocol == 'number')) { obj.protocol = options.protocol; }
1586
- obj.onTunnelUpdate = onTunnelUpdate;
1587
- obj.xxStateChange = function (state) { }
1588
- obj.ProcessBinaryData = function (data) { obj.onTunnelUpdate(data); }
1589
- obj.ProcessData = function (data) { obj.onTunnelUpdate(data); }
1590
- obj.terminalEmulation = 1;
1591
- obj.fxEmulation = 0;
1592
- obj.lineFeed = '\r\n';
1593
- return obj;
1594
- }
1595
-
1596
- function tunnelUpdate(data) { if (typeof data == 'string') { xterm.writeUtf8(data); } else { xterm.writeUtf8(new Uint8Array(data)); } }
1597
-
1598
- // Send the new terminal size to the agent
1599
- function xTermSendResize() {
1600
- xtermResizeTimer = null;
1601
- if ((xterm != null) && (terminal != null) && (terminal.sendCtrlMsg != null)) { terminal.sendCtrlMsg(JSON.stringify({ ctrlChannel: '102938', type: 'termsize', cols: xterm.cols, rows: xterm.rows })); }
1602
- }
1603
-
1604
- // Used to translate incoming agent console messages
1605
- var agentConsoleMessages = ['', "Waiting for user to grant access...", "Denied", "Failed to start remote terminal session, {0} ({1})", "Timeout", "Received invalid network data"];
1606
- function formatAgentConsoleMessage(msg, msgid, msgargs) {
1607
- var r;
1608
- if (msgargs == null) { msgargs = []; }
1609
- while (msgargs.length < 3) { msgargs.push(''); } // We need to call the format function in a way that works with older browsers and minifier, can't use apply() or ...
1610
- if (msgid && (msgid < agentConsoleMessages.length)) { r = EscapeHtml(format(agentConsoleMessages[msgid], (msgargs[0]), (msgargs[1]), (msgargs[2]))); } else { r = EscapeHtml(msg); }
1611
- return r.split('\n').join('<br />') + '<br /><br />';
1612
- }
1613
-
1614
- function connectTerminal(e, contype, options) {
1615
- p12clearConsoleMsg();
1616
- if (!terminal) {
1617
- // Terminal setup
1618
- var termoptions = { protocol: ((options != null) && (typeof options.protocol == 'number')) ? options.protocol : 1 };
1619
- if (options && options.requireLogin) { termoptions.requireLogin = true; }
1620
- /*
1621
- if ([1, 2, 3, 4, 21, 22].indexOf(currentNode.agent.id) == -1) {
1622
- if (Q('termSizeList').value == 1) { termoptions.cols = 80; termoptions.rows = 25; termoptions.xterm = true; }
1623
- else if (Q('termSizeList').value == 2) { termoptions.cols = 100; termoptions.rows = 30; termoptions.xterm = true; }
1624
- else if (Q('termSizeList').value == 3) {
1625
- // TODO: Try to improve terminal auto-size.
1626
- termoptions.cols = Math.floor((Q('column_l').clientWidth - 60) / 10);
1627
- termoptions.rows = Math.floor((Q('column_l').clientHeight - 120) / 20);
1628
- termoptions.xterm = true;
1629
- }
1630
- }
1631
- */
1632
-
1633
- /*
1634
- // If shift is pressed
1635
- if ((e && (e.shiftKey == true))) {
1636
- if (currentNode.agent.id > 4) {
1637
- if (termoptions.protocol == 1) { termoptions.protocol = 7; } // Switch to user shell
1638
- } else {
1639
- if (termoptions.protocol == 1) { termoptions.protocol = 6; } // Switch to Powershell
1640
- }
1641
- }
1642
- */
1643
-
1644
- // Setup a mesh agent xterm terminal
1645
- QV('termarea3xdiv', true);
1646
-
1647
- // Setup the terminal with auto-fit
1648
- if (xterm != null) { xterm.dispose(); }
1649
- xtermfit = new FitAddon.FitAddon();
1650
- xterm = new Terminal();
1651
- if (xtermfit) { xterm.loadAddon(xtermfit); }
1652
- xterm.open(Q('termarea3xdiv')); // termarea3x
1653
- xterm.onData(function (data) { if (terminal != null) { terminal.sendText(data); } })
1654
- if (xtermfit) { xtermfit.fit(); }
1655
- xterm.onTitleChange(function (title) { QH('termtitle', ' - ' + EscapeHtml(title)); });
1656
- xterm.onResize(function (size) {
1657
- // Despam resize
1658
- if (xtermResizeTimer) clearTimeout(xtermResizeTimer);
1659
- xtermResizeTimer = setTimeout(xTermSendResize, 200);
1660
- });
1661
-
1662
- // Setup a terminal tunnel to the agent
1663
- terminal = CreateAgentRedirect(null, CreateRemoteTunnel(tunnelUpdate, options), serverPublicNamePort, authCookie, null, domainUrl);
1664
- terminal.debugmode = debugmode;
1665
- terminal.m.debugmode = debugmode;
1666
- terminal.options = { cols: xterm.cols, rows: xterm.rows };
1667
- if (options && options.requireLogin) { terminal.options.requireLogin = true; }
1668
- terminal.Start(null);
1669
- terminal.onStateChanged = onTerminalStateChange;
1670
- terminal.contype = 1;
1671
- terminal.attemptWebRTC = false; // Never do WebRTC on terminal, because of a race condition we can't do it.
1672
- terminal.onConsoleMessageChange = function (server, msg) {
1673
- if (terminal.consoleMessage) {
1674
- Q('p12TermConsoleMsg').innerHTML += formatAgentConsoleMessage(terminal.consoleMessage, terminal.consoleMessageId, terminal.consoleMessageArgs);
1675
- QV('p12TermConsoleMsg', true);
1676
- if (p12TermConsoleMsgTimer != null) { clearTimeout(p12TermConsoleMsgTimer); }
1677
- if (terminal.consoleMessageTimeout) { p12TermConsoleMsgTimer = setTimeout(p12clearConsoleMsg, terminal.consoleMessageTimeout * 1000); }
1678
- } else {
1679
- p12clearConsoleMsg();
1680
- }
1681
- };
1682
- } else {
1683
- terminal.Stop();
1684
- terminal = null;
1685
- }
1686
- Q('connectbutton2').blur(); // Deselect the connect button so the button does not get key presses.
1687
- }
1688
-
1689
- var terminalEmulations = ["UTF8 Terminal", "Extended ASCII", "Intel ASCII"];
1690
- function termToggleType() {
1691
- if (!terminal || xxdialogMode) return;
1692
- terminal.m.terminalEmulation = (terminal.m.terminalEmulation + 1) % 3;
1693
- Q('id_ttypebutton').value = terminalEmulations[terminal.m.terminalEmulation];
1694
- Q('id_ttypebutton').blur(); // Deselect the connect button so the button does not get key presses.
1695
- }
1696
-
1697
- var fxEmulations = ["Intel (F10 = ESC+[OM)", "Alternate (F10 = ESC+0)", "VT100+ (F10 = ESC+[OY)"];
1698
- function termToggleFx() {
1699
- if (!terminal || xxdialogMode) return;
1700
- terminal.m.fxEmulation = (terminal.m.fxEmulation + 1) % 3;
1701
- Q('id_tfxkeysbutton').value = fxEmulations[terminal.m.fxEmulation];
1702
- Q('id_tfxkeysbutton').blur(); // Deselect the connect button so the button does not get key presses.
1703
- }
1704
-
1705
- function termToggleCr() {
1706
- if (!terminal || xxdialogMode) return;
1707
- if (terminal.m.lineFeed == '\n') { terminal.m.lineFeed = '\r\n'; } else { terminal.m.lineFeed = '\n'; }
1708
- Q('id_tcrbutton').value = (terminal.m.lineFeed == '\r\n') ? "CR+LF" : "LF";
1709
- }
1710
-
1711
- function termSendKey(key, id) {
1712
- if (!terminal || xxdialogMode) return;
1713
- if (xterm != null) {
1714
- if (terminal.sendText) {
1715
- // MeshAgent
1716
- terminal.sendText(String.fromCharCode(key));
1717
- } else {
1718
- // CIRA
1719
- terminal.send(String.fromCharCode(key));
1720
- }
1721
- xterm.focus();
1722
- } else if (terminal != null) {
1723
- terminal.m.TermSendKey(key);
1724
- Q(id).blur(); // Deselect the connect button so the button does not get key presses.
1725
- }
1726
- }
1727
-
1728
- function showTermPasteDialog() {
1729
- if (!terminal || xxdialogMode) return;
1730
- Q('pastebutton').blur();
1731
- setDialogMode(2, "Paste", 3, showTermPasteDialogEx, '<textarea id=d2pasteText style="width:100%;height:184px;resize:none"></textarea>');
1732
- Q('d2pasteText').focus();
1733
- }
1734
-
1735
- function showTermPasteDialogEx() {
1736
- if (!terminal) return;
1737
- terminal.m.TermSendKeys(Q('d2pasteText').value);
1738
- }
1739
-
1740
- // Send special key
1741
- function sendSpecialKey() {
1742
- if (xterm != null) {
1743
- terminal.sendText(String.fromCharCode(Q('specialkeylist').value));
1744
- xterm.focus();
1745
- } else if (terminal != null) {
1746
- terminal.m.TermSendKey(Q('specialkeylist').value);
1747
- Q('specialkeylist').blur();
1748
- Q('specialkeylistinput').blur();
1749
- }
1750
- }
1751
-
1752
- function p12clearConsoleMsg() { QH('p12TermConsoleMsg', ''); QV('p12TermConsoleMsg', false); if (p12TermConsoleMsgTimer) { clearTimeout(p12TermConsoleMsgTimer); p12TermConsoleMsgTimer = null; } }
1753
-
1754
-
1755
-
1756
- //
1757
- // Files
1758
- //
1759
-
1760
- function setupFiles() {
1761
- // Setup the files tab
1762
- if (files != null) { files.Stop(); files = null; }
1763
- }
1764
-
1765
- function onFilesStateChange(xfiles, state) {
1766
- p13Connect.value = (state == 0) ? "Connect" : "Disconnect";
1767
- var str = StatusStrs[state];
1768
- if (files.webRtcActive == true) { str += ", WebRTC"; }
1769
- Q('p13Status').textContent = str;
1770
- switch (state) {
1771
- case 0:
1772
- // Disconnected, clear the files
1773
- QH('p13files', '');
1774
- p13filetree = null;
1775
- p13filetreelocation = [];
1776
- QH('p13currentpath', '');
1777
- QE('p13FolderUp', false);
1778
- QV('filesRecordIcon', false);
1779
- p13setActions();
1780
- if (files != null) { files.Stop(); files = null; }
1781
- if (xxdialogTag == 'fileMsgDialog') { setDialogMode(0); }
1782
- break;
1783
- case 3:
1784
- p13targetpath = '';
1785
- if (files) {
1786
- files.sendText({ action: 'ls', reqid: 1, path: '' });
1787
- if (files.serverIsRecording == true) { QV('filesRecordIcon', true); }
1788
- }
1789
- break;
1790
- default:
1791
- //console.log('Unknown onFilesStateChange state', state);
1792
- break;
1793
- }
1794
- }
1795
-
1796
- function CreateRemoteFiles(onFileUpdate) {
1797
- var obj = { protocol: 5 };
1798
- obj.onFileUpdate = onFileUpdate;
1799
- obj.xxStateChange = function (state) { }
1800
- obj.ProcessData = function (data) { obj.onFileUpdate(data); }
1801
- return obj;
1802
- }
1803
-
1804
- function connectFiles(e) {
1805
- p13clearConsoleMsg();
1806
- if (!files) {
1807
- // Setup a mesh agent files
1808
- files = CreateAgentRedirect(null, CreateRemoteFiles(p13gotFiles), serverPublicNamePort, authCookie, null, domainUrl);
1809
- files.attemptWebRTC = attemptWebRTC;
1810
- files.onStateChanged = onFilesStateChange;
1811
- files.onConsoleMessageChange = function () {
1812
- if (files.consoleMessage) {
1813
- Q('p13FilesConsoleMsg').innerHTML += formatAgentConsoleMessage(files.consoleMessage, files.consoleMessageId, files.consoleMessageArgs);
1814
- QV('p13FilesConsoleMsg', true);
1815
- if (p13FilesConsoleMsgTimer != null) { clearTimeout(p13FilesConsoleMsgTimer); }
1816
- if (files.consoleMessageTimeout) { p13FilesConsoleMsgTimer = setTimeout(p13clearConsoleMsg, files.consoleMessageTimeout * 1000); }
1817
- } else {
1818
- p13clearConsoleMsg();
1819
- }
1820
- }
1821
- files.Start(null);
1822
- } else {
1823
- //QH('Term', '');
1824
- files.Stop();
1825
- files = null;
1826
- }
1827
- p13clipboard = p13clipboardFolder = null;
1828
- p13clipboardCut = 0;
1829
- p13updateClipview();
1830
- }
1831
-
1832
- var p13filetree = null;
1833
- var p13targetpath = null;
1834
- var p13filetreelocation = [];
1835
-
1836
- function p13fileOperationDialogEx(b) { if ((b == 0) && (files != null)) { files.sendText({ action: 'cancel' }); } }
1837
-
1838
- function p13gotFiles(data) {
1839
- if ((data.length > 0) && (data.charCodeAt(0) != 123)) { p13gotDownloadBinaryData(data); return; } // This is ok because 4 first bytes is a control value.
1840
- //console.log('p13gotFiles', data);
1841
- try { data = JSON.parse(decode_utf8(data)); } catch (ex) { data = JSON.parse(data); }
1842
- if (data.action == 'download') { p13gotDownloadCommand(data); return; }
1843
-
1844
- // Find file result
1845
- if (data.action == 'findfile') {
1846
- if (xxdialogTag == data.reqid) {
1847
- if (data.r == null) {
1848
- QE('d2findFilter', true);
1849
- QE('filefind_dlgOkButton', true);
1850
- xxdialogTag = null;
1851
- if (Q('d2findResults').innerHTML == '') { QH('d2findResults', '<div style=text-align:center;margin:10px><i>' + "No files found" + '</i></div>'); }
1852
- } else {
1853
- QA('d2findResults', '<div style=white-space:nowrap>' + EscapeHtml(data.r) + '</div>');
1854
- }
1855
- }
1856
- return;
1857
- }
1858
-
1859
- // Process file upload commands
1860
- if ((data.action != null) && (data.action.startsWith('upload'))) { p13gotUploadData(data); return; }
1861
-
1862
- // Display a dialog message
1863
- if (data.action == 'dialogmessage') {
1864
- if ((data.msg == null) && (xxdialogTag == 'fileMsgDialog')) {
1865
- setDialogMode(0); // Close the dialog box
1866
- } else if ((data.msg == 'zipping') && ((!xxdialogMode) || (xxdialogTag == 'fileMsgDialog'))) {
1867
- // Show the dialog box message
1868
- setDialogMode(2, "File Operation", 10, p13fileOperationDialogEx, '<div style=margin:10px>' + "Compressing files..." + '<div>', 'fileMsgDialog');
1869
- } else if ((data.msg == 'zippingFile') && ((!xxdialogMode) || (xxdialogTag == 'fileMsgDialog'))) {
1870
- // Show the dialog box message
1871
- setDialogMode(2, "File Operation", 10, p13fileOperationDialogEx, '<div style=margin:10px>' + EscapeHtml(data.file) + '<div><br /><progress value=' + EscapeHtml(data.progress) + ' style=width:100% max=100 />', 'fileMsgDialog');
1872
- }
1873
- return;
1874
- }
1875
-
1876
- // Refresh file folder
1877
- if (data.action == 'refresh') { p13folderup(9999); return; }
1878
-
1879
- if (data.path != null) {
1880
- data.path = data.path.replace(/\//g, '\\');
1881
- if ((p13filetree != null) && (data.path == p13filetree.path)) {
1882
- // This is an update to the same folder
1883
- var checkedNames = p13getCheckedNames();
1884
- p13filetree = data;
1885
- p13updateFiles(checkedNames);
1886
- } else {
1887
- // Make both paths use the same seperator not start with /
1888
- var x1 = data.path.replace(/\//g, '\\'), x2 = p13targetpath.replace(/\//g, '\\');
1889
- while ((x1.length > 0) && (x1[0] == '\\')) { x1 = x1.substring(1); }
1890
- while ((x2.length > 0) && (x2[0] == '\\')) { x2 = x2.substring(1); }
1891
- if ((x1 == x2) || ((data.path == '\\') && (p13targetpath == ''))) {
1892
- // This is a different folder
1893
- p13filetree = data;
1894
- p13updateFiles();
1895
- }
1896
- }
1897
- }
1898
- }
1899
-
1900
- function p13getCheckedNames() {
1901
- // Save all existing checked boxes
1902
- var checkedNames = [], checkboxes = document.getElementsByName('fd');
1903
- for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { checkedNames.push(p13filetree.dir[checkboxes[i].value].n) }; }
1904
- return checkedNames;
1905
- }
1906
-
1907
- function p13updateFiles(checkedNames) {
1908
- var html1 = '', html2 = '', displayPath = '<a href=# style=cursor:pointer onclick="return p13folderup(0)">' + "Root" + '</a>', fullPath = 'Root';
1909
-
1910
- // Work on parsing the file path
1911
- var x = p13filetree.path.split('\\');
1912
- p13filetreelocation = [];
1913
- for (var i in x) { if (x[i] != '') { p13filetreelocation.push(x[i]); } } // Remove empty spaces
1914
- for (var i in p13filetreelocation) { displayPath += ' / <a href=# style=cursor:pointer onclick="return p13folderup(' + (parseInt(i) + 1) + ')">' + EscapeHtml(p13filetreelocation[i]) + '</a>' } // Setup the path we display
1915
- var newlinkpath = p13filetreelocation.join('/');
1916
-
1917
- // Sort the files
1918
- var filetreexx = p13sort_files(p13filetree.dir);
1919
-
1920
- // Display all files and folders at this location
1921
- for (var i in filetreexx) {
1922
- // Figure out the name and shortname
1923
- var f = filetreexx[i], name = f.n, shortname;
1924
- shortname = name;
1925
- if (name.length > 70) { shortname = '<span title="' + EscapeHtml(name) + '">' + EscapeHtml(name.substring(0, 70)) + ("..." + '</span>'); } else { shortname = EscapeHtml(name); }
1926
- name = EscapeHtml(name);
1927
-
1928
- // Figure out the date
1929
- var fdatestr = '';
1930
- if (f.d != null) {
1931
- var fdate = new Date(f.d);
1932
- if (typeof f.d == 'number') { fdate = new Date(f.d * 1000); }
1933
- var fdatestr = printDateTime(fdate) + ' ';
1934
- }
1935
-
1936
- // Figure out the size
1937
- var fsize = '';
1938
- if (f.s != null) { fsize = getFileSizeStr(f.s); }
1939
-
1940
- var h = '';
1941
- if (f.t < 3) {
1942
- var right = '', title = '';
1943
- h = '<div class=filelist file=999><input file=999 style=float:left name=fd class=fcb type=checkbox onchange=p13setActions() value=\'' + f.nx + '\'> <span style=float:right title="' + title + '">' + right + '</span><span><div class=fileIcon' + f.t + ' onclick=p13folderset("' + encodeURIComponentEx(f.nx) + '")></div><a href=# style=cursor:pointer onclick=\'return p13folderset("' + encodeURIComponentEx(f.nx) + '")\'>' + shortname + '</a></span></div>';
1944
- } else {
1945
- var link = shortname;
1946
- if (f.s > 0) {
1947
- // Local link
1948
- //link = '<a href=# style=cursor:pointer onclick="return p13downloadfile(\'' + encodeURIComponentEx(newlinkpath + '/' + name) + '\',\'' + encodeURIComponentEx(name) + '\',' + f.s + ')">' + shortname + '</a>';
1949
- // Server link
1950
- //link = '<a href="devicefile.ashx?c=' + authCookie + '&m=' + currentNode.meshid.split('/')[2] + '&n=' + currentNode._id.split('/')[2] + '&f=' + encodeURIComponentEx(newlinkpath + '/' + name) + '" download="' + name + '" style=cursor:pointer>' + shortname + '</a>';
1951
- // Server link
1952
- //link = '<a onclick=downloadFile("devicefile.ashx?c=' + authCookie + '&m=' + currentNode.meshid.split('/')[2] + '&n=' + currentNode._id.split('/')[2] + '&f=' + encodeURIComponentEx(newlinkpath + '/' + name) + '","' + encodeURIComponentEx(name) + '") style=cursor:pointer>' + shortname + '</a>';
1953
- link = '<a onclick=downloadFile("devicefile.ashx?c=' + authCookie + '&f=' + encodeURIComponentEx(newlinkpath + '/' + name) + '","' + encodeURIComponentEx(name) + '") style=cursor:pointer>' + shortname + '</a>';
1954
- }
1955
- h = '<div id=fileEntry cmenu=filesContextMenu fileIndex=' + i + ' class=filelist file=3><input file=3 style=float:left name=fd class=fcb type=checkbox onchange=p13setActions() value=\'' + f.nx + '\'> <span class=fsize>' + fdatestr + '</span><span style=float:right>' + EscapeHtml(fsize) + '</span><span><div class=fileIcon' + f.t + '></div>' + link + '</span></div>';
1956
- }
1957
-
1958
- if (f.t < 3) { html1 += h; } else { html2 += h; }
1959
- }
1960
-
1961
- // Display the files and path
1962
- QH('p13files', html1 + html2);
1963
- QH('p13currentpath', displayPath);
1964
- QE('p13FolderUp', p13filetreelocation.length != 0);
1965
-
1966
- // Re-check all boxes if needed using names
1967
- if (checkedNames != null) { var checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkedNames.indexOf(p13filetree.dir[checkboxes[i].value].n) >= 0) { checkboxes[i].checked = true; } } }
1968
-
1969
- // Update the actions buttons
1970
- p13setActions();
1971
- }
1972
-
1973
- function p13folderset(x) {
1974
- p13targetpath = joinPaths(p13filetree.path, p13filetree.dir[x].n).split('\\').join('/');
1975
- files.sendText({ action: 'ls', reqid: 1, path: p13targetpath });
1976
- }
1977
-
1978
- function p13folderup(x) {
1979
- if (x == null) { p13filetreelocation.pop(); } else { while (p13filetreelocation.length > x) { p13filetreelocation.pop(); } }
1980
- p13targetpath = p13filetreelocation.join('/');
1981
- files.sendText({ action: 'ls', reqid: 1, path: p13targetpath });
1982
- return false;
1983
- }
1984
-
1985
- function p13findfile() {
1986
- if (xxdialogMode) return;
1987
- var x = addHtmlValue("Filter", '<input id=d2findFilter style="width:230px" onkeyup=p13findfileValidate() onkeydown=p13findfileDown(event) placeholder="*.txt"></input>');
1988
- x += '<div id=d2findResults style="width:100%;height:184px;background-color:white;border:1px solid black;padding:3px;overflow:scroll;margin-top:8px"></div>';
1989
- x += '<div style=margin-top:8px><input id=filefind_dlgCancelButton type=button value=' + "Close" + ' style=float:right;width:80px;margin-left:5px onclick=p13findfileCancel()>';
1990
- x += '<input id=filefind_dlgOkButton type=submit value=' + "Search" + ' style=float:right;width:80px onclick=p13findfileEx()><br /><br /></div>';
1991
- setDialogMode(2, "Find Files", 0, null, x);
1992
- p13findfileValidate();
1993
- Q('d2findFilter').focus();
1994
- }
1995
-
1996
- function p13findfileDown(e) { if (e.code == "Enter") { p13findfileEx(); } }
1997
- function p13findfileValidate() { QE('filefind_dlgOkButton', Q('d2findFilter').value.length > 0); }
1998
- function p13findfileCancel() { if (xxdialogTag != null) { files.sendText({ action: 'cancelfindfile', reqid: xxdialogTag }); } dialogclose(0) }
1999
-
2000
- function p13findfileEx(b, t) {
2001
- if (Q('d2findFilter').value.length == 0) return;
2002
- var winagent = true;//((currentNode.agent.id > 0) && (currentNode.agent.id < 5));
2003
- var slash = winagent ? '\\' : '/';
2004
- var path = p13filetreelocation.join(slash) + slash;
2005
- if (!winagent) { path = slash + path; }
2006
- xxdialogTag = 'find:' + Math.random();
2007
- files.sendText({ action: 'findfile', reqid: xxdialogTag, path: path, filter: Q('d2findFilter').value });
2008
- QH('d2findResults', '');
2009
- QE('d2findFilter', false);
2010
- QE('filefind_dlgOkButton', false);
2011
- }
2012
-
2013
- var p13sortorder;
2014
- function p13sort_filename(a, b) { if (a.ln > b.ln) return (1 * p13sortorder); if (a.ln < b.ln) return (-1 * p13sortorder); return 0; }
2015
- function p13sort_timestamp(a, b) { if (a.d > b.d) return (1 * p13sortorder); if (a.d < b.d) return (-1 * p13sortorder); return 0; }
2016
- function p13sort_bysize(a, b) { if (a.s == b.s) return p13sort_filename(a, b); return (((a.s - b.s)) * p13sortorder); }
2017
-
2018
- function p13sort_files(files) {
2019
- var r = [], sortselection = Q('p13sortdropdown').value;
2020
- for (var i in files) { files[i].nx = i; if (files[i].s == null) { files[i].s = 0; } if (files[i].n == null) { files[i].n = i; } files[i].ln = files[i].n.toLowerCase(); r.push(files[i]); }
2021
- p13sortorder = 1;
2022
- if (sortselection > 3) { p13sortorder = -1; sortselection -= 3; }
2023
- if (sortselection == 1) { r.sort(p13sort_filename); }
2024
- else if (sortselection == 2) { r.sort(p13sort_bysize); }
2025
- else if (sortselection == 3) { r.sort(p13sort_timestamp); }
2026
- return r;
2027
- }
2028
-
2029
- function p13setActions() {
2030
- var advancedFeatures = true; //(currentNode.agent.id != 14); // Reduct file feature on some devices.
2031
- if (p13filetree == null) {
2032
- QE('p13DeleteFileButton', false);
2033
- QE('p13NewFolderButton', false);
2034
- QE('p13UploadButton', false);
2035
- QE('p13RenameFileButton', false);
2036
- QE('p13ViewFileButton', false);
2037
- QE('p13SelectAllButton', false);
2038
- Q('p13SelectAllButton').value = "Select All";
2039
- QE('p13RefreshButton', false);
2040
- QE('p13FindButton', false);
2041
- QE('p13CutButton', false);
2042
- QE('p13CopyButton', false);
2043
- QE('p13ZipButton', false);
2044
- QE('p13PasteButton', false);
2045
- } else {
2046
- var cc = p13getFileSelCount(), tc = p13getFileCount(), sfc = p13getFileSelCount(false); // In order: number of entires selected, number of total entries, number of selected entires that are files (not folders)
2047
- var winAgent = true; //((currentNode.agent.id > 0) && (currentNode.agent.id < 5)) || (currentNode.agent.id == 14);
2048
- QE('p13DeleteFileButton', (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false)));
2049
- QE('p13NewFolderButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false)));
2050
- QE('p13UploadButton', ((p13filetreelocation.length > 0) || (winAgent == false) /*|| (currentNode.agent.id == 14)*/));
2051
- QE('p13RenameFileButton', advancedFeatures && (cc == 1) && ((p13filetreelocation.length > 0) || (winAgent == false)));
2052
- QE('p13ViewFileButton', advancedFeatures && (cc == 1) && (sfc == 1) && ((p13filetreelocation.length > 0) || (winAgent == false)));
2053
- QE('p13SelectAllButton', tc > 0);
2054
- Q('p13SelectAllButton').value = (cc > 0 ? "Select None" : "Select All");
2055
- QE('p13RefreshButton', true);
2056
- QE('p13FindButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false)));
2057
- QE('p13CutButton', advancedFeatures && (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false)));
2058
- QE('p13CopyButton', advancedFeatures && (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false)));
2059
- QE('p13ZipButton', advancedFeatures && (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false)));
2060
- QE('p13PasteButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false)) && ((p13clipboard != null) && (p13clipboard.length > 0)));
2061
- }
2062
- }
2063
-
2064
- function p13getFileSelCount(includeDirs) { var cc = 0; var checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && ((includeDirs != false) || (checkboxes[i].attributes.file.value == '3'))) cc++; } return cc; }
2065
- function p13getFileSelDirCount() { var cc = 0, checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && (checkboxes[i].attributes.file.value == '999')) cc++; } return cc; }
2066
- function p13getFileCount() { var cc = 0; var checkboxes = document.getElementsByName('fd'); return checkboxes.length; }
2067
- function p13selectallfile() { var nv = (p13getFileSelCount() == 0), checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].checked = nv; } p13setActions(); }
2068
- function p13createfolder() { setDialogMode(2, "New Folder", 3, p13createfolderEx, '<input type=text id=p13renameinput maxlength=64 onkeyup=p13fileNameCheck(event) style=width:100% />'); focusTextBox('p13renameinput'); p13fileNameCheck(); }
2069
- function p13createfolderEx() { files.sendText({ action: 'mkdir', reqid: 1, path: p13filetreelocation.join('/') + '/' + Q('p13renameinput').value }); p13folderup(999); }
2070
- function p13deletefile() { var cc = p13getFileSelCount(), rec = (p13getFileSelDirCount() > 0) ? '<br /><br /><label><input type=checkbox id=p13recdeleteinput>' + "Recursive delete" + '</label><br>' : '<input type=checkbox id=p13recdeleteinput style=\'display:none\'>'; setDialogMode(2, "Delete", 3, p13deletefileEx, (cc > 1) ? (format("Delete {0} selected items?", cc) + rec) : ("Delete selected item?" + rec)); }
2071
- function p13deletefileEx() { var delfiles = [], checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { delfiles.push(p13filetree.dir[checkboxes[i].value].n); } } files.sendText({ action: 'rm', reqid: 1, path: p13filetreelocation.join('/'), delfiles: delfiles, rec: Q('p13recdeleteinput').checked }); p13folderup(999); }
2072
- function p13renamefile() { var renamefile, checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { renamefile = p13filetree.dir[checkboxes[i].value].n; } } setDialogMode(2, "Rename", 3, p13renamefileEx, '<input type=text id=p13renameinput maxlength=64 onkeyup=p13fileNameCheck(event) style=width:100% value="' + renamefile + '" />', { action: 'rename', path: p13filetreelocation.join('/'), oldname: renamefile }); focusTextBox('p13renameinput'); p13fileNameCheck(); }
2073
- function p13renamefileEx(b, t) { t.newname = Q('p13renameinput').value; files.sendText(t); p13folderup(999); }
2074
- function p13fileNameCheck(e) { var x = isFilenameValid(Q('p13renameinput').value); QE('idx_dlgOkButton', x); if ((x == true) && (e != null) && (e.keyCode == 13)) { dialogclose(1); } }
2075
- function p13uploadFile() { setDialogMode(2, "Upload File", 3, p13uploadFileEx, '<input type=file name=files id=p13uploadinput style=width:100% multiple=multiple onchange="updateUploadDialogOk(\'p13uploadinput\')" />'); updateUploadDialogOk('p13uploadinput'); }
2076
- function updateUploadDialogOk(x) { QE('idx_dlgOkButton', Q('p13uploadinput').files.length > 0); }
2077
- function p13uploadFileEx() { p13doUploadFiles(Q('p13uploadinput').files); }
2078
- function p13viewfile() {
2079
- var checkboxes = document.getElementsByName('fd');
2080
- for (var i = 0; i < checkboxes.length; i++) {
2081
- if (checkboxes[i].checked) {
2082
- if (p13filetree.dir[checkboxes[i].value].s <= 204800) {
2083
- p13downloadfile(encodeURIComponentEx(p13filetreelocation.join('/') + '/' + p13filetree.dir[checkboxes[i].value].n), encodeURIComponentEx(p13filetree.dir[checkboxes[i].value].n), p13filetree.dir[checkboxes[i].value].s, 'viewer');
2084
- } else { messagebox("File Editor", "Only files less than 200k can be edited."); }
2085
- break;
2086
- }
2087
- }
2088
- }
2089
-
2090
- function p13zipFiles() {
2091
- var inputFiles = [], checkboxes = document.getElementsByName('fd');
2092
- for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { inputFiles.push(p13filetree.dir[checkboxes[i].value].n); } }
2093
- setDialogMode(2, "Zip Filename", 3, p13zipFilesEx, '<input type=text id=p13renameinput maxlength=64 onkeyup=p13fileNameCheck(event) style=width:100% value="" />', { action: 'zip', path: p13filetreelocation.join('/'), files: inputFiles });
2094
- focusTextBox('p13renameinput');
2095
- p13fileNameCheck();
2096
- }
2097
-
2098
- function p13zipFilesEx(b, tag) {
2099
- tag.output = Q('p13renameinput').value;
2100
- if (!tag.output.toLowerCase().endsWith('.zip')) { tag.output += '.zip'; }
2101
- files.sendText(tag);
2102
- }
2103
-
2104
- var p13clipboard = null, p13clipboardFolder = null, p13clipboardCut = 0;
2105
- function p13copyFile(cut) { var checkboxes = document.getElementsByName('fd'); p13clipboard = []; p13clipboardCut = cut, p13clipboardFolder = p13targetpath; for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && (checkboxes[i].attributes.file.value == '3')) { p13clipboard.push(p13filetree.dir[checkboxes[i].value].n); } } p13updateClipview(); }
2106
- function p13pasteFile() {
2107
- var x = '';
2108
- if ((p13clipboard != null) && (p13clipboard.length > 0)) {
2109
- if (p13clipboardCut == 0) {
2110
- if (p13clipboard.length > 1) { x = format("Confirm copy of {0} entries to this location?", p13clipboard.length); } else { x = format("Confirm copy of 1 entrie to this location?"); }
2111
- } else {
2112
- if (p13clipboard.length > 1) { x = format("Confirm move of {0} entries to this location?", p13clipboard.length); } else { x = format("Confirm move of 1 entrie to this location?"); }
2113
- }
2114
- }
2115
- setDialogMode(2, "Paste", 3, p13pasteFileEx, x);
2116
- }
2117
- function p13pasteFileEx() { files.sendText({ action: (p13clipboardCut == 0 ? 'copy' : 'move'), reqid: 1, scpath: p13clipboardFolder, dspath: p13targetpath, names: p13clipboard }); p13folderup(999); if (p13clipboardCut == 1) { p13clipboard = null, p13clipboardFolder = null, p13clipboardCut = 0; p13updateClipview(); } }
2118
- function p13updateClipview() {
2119
- var x = '';
2120
- if ((p13clipboard != null) && (p13clipboard.length > 0)) {
2121
- if (p13clipboardCut == 0) {
2122
- if (p13clipboard.length > 1) {
2123
- x = format("Holding {0} entries for copy" + ', <a href=# onclick="return p13clearClip()" style=cursor:pointer>' + "Clear" + '</a>.', p13clipboard.length);
2124
- } else {
2125
- x = format("Holding 1 entrie for copy" + ', <a href=# onclick="return p13clearClip()" style=cursor:pointer>' + "Clear" + '</a>.');
2126
- }
2127
- } else {
2128
- if (p13clipboard.length > 1) {
2129
- x = format("Holding {0} entries for move" + ', <a href=# onclick="return p13clearClip()" style=cursor:pointer>' + "Clear" + '</a>.', p13clipboard.length);
2130
- } else {
2131
- x = format("Holding 1 entrie for move" + ', <a href=# onclick="return p13clearClip()" style=cursor:pointer>' + "Clear" + '</a>.');
2132
- }
2133
- }
2134
- }
2135
- QH('p13bottomstatus', x);
2136
- p13setActions();
2137
- }
2138
- function p13clearClip() { p13clipboard = null; p13clipboardFolder = null; p13clipboardCut = 0; p13updateClipview(); return false; }
2139
-
2140
- function p13fileDragDrop(e) {
2141
- haltEvent(e);
2142
- QV('p13bigfail', false);
2143
- QV('p13bigok', false);
2144
- if ((e.dataTransfer == null) || (e.dataTransfer.files.length == 0) || (p13filetree == null)) return;
2145
-
2146
- // Check if these are files we can upload, remove all folders.
2147
- var files = [];
2148
- for (var i in e.dataTransfer.files) { if ((e.dataTransfer.files[i].size != null) && (e.dataTransfer.files[i].size != 0)) { files.push(e.dataTransfer.files[i]); } }
2149
- if (files.length == 0) return;
2150
-
2151
- p13doUploadFiles(files);
2152
- }
2153
-
2154
- var p13dragtimer = null;
2155
- function p13fileDragOver(e) {
2156
- haltEvent(e);
2157
- if (p13dragtimer != null) { clearTimeout(p13dragtimer); p13dragtimer = null; }
2158
- var ac = (p13filetree != null); // Set to true if we can accept the file
2159
- QV('p13bigok', ac);
2160
- QV('p13bigfail', !ac);
2161
- }
2162
-
2163
- function p13fileDragLeave(e) {
2164
- haltEvent(e);
2165
- if (e.target.id != 'p13filetable') {
2166
- QV('p13bigfail', false);
2167
- QV('p13bigok', false);
2168
- } else {
2169
- p13dragtimer = setTimeout(function () { QV('p13bigfail', false); QV('p13bigok', false); p13dragtimer = null; }, 10);
2170
- }
2171
- }
2172
-
2173
- //
2174
- // FILES DOWNLOAD
2175
- //
2176
-
2177
- var gdownloadFile; // Global state for file download
2178
-
2179
- // Called by the html page to start a download, arguments are: path, file name and file size.
2180
- function p13downloadfile(x, y, z, tag) {
2181
- if (xxdialogMode || !files) return;
2182
- gdownloadFile = { path: decodeURIComponent(x), file: decodeURIComponent(y), size: z, tsize: 0, data: '', state: 0, id: Math.random(), tag: tag }
2183
- //console.log('p13downloadFileCancel', gdownloadFile);
2184
- files.sendText({ action: 'download', sub: 'start', id: gdownloadFile.id, path: gdownloadFile.path });
2185
- setDialogMode(2, "Download File", 10, p13downloadFileCancel, '<div>' + gdownloadFile.file + '</div><br /><progress id=d2progressBar style=width:100% value=0 max=' + z + ' />');
2186
- }
2187
-
2188
- // Called by the html page to cancel the download
2189
- function p13downloadFileCancel() { setDialogMode(0); files.sendText({ action: 'download', sub: 'cancel', id: gdownloadFile.id }); gdownloadFile = null; }
2190
-
2191
- // Called by the transport when download control command is received
2192
- function p13gotDownloadCommand(cmd) {
2193
- //console.log('p13gotDownloadCommand', cmd);
2194
- if ((gdownloadFile == null) || (cmd.id != gdownloadFile.id)) return;
2195
- if (cmd.sub == 'start') { gdownloadFile.state = 1; files.sendText({ action: 'download', sub: 'startack', id: gdownloadFile.id }); }
2196
- else if (cmd.sub == 'cancel') { gdownloadFile = null; setDialogMode(0); }
2197
- }
2198
-
2199
- // Called by the transport when binary data is received
2200
- function p13gotDownloadBinaryData(data) {
2201
- if (!gdownloadFile || gdownloadFile.state == 0) return;
2202
- if (data.length > 4) {
2203
- gdownloadFile.tsize += (data.length - 4); // Add to the total bytes received
2204
- gdownloadFile.data += data.substring(4); // Append the data
2205
- Q('d2progressBar').value = gdownloadFile.tsize; // Change the progress bar
2206
- }
2207
- if ((ReadInt(data, 0) & 1) != 0) { // Check end flag
2208
- if (gdownloadFile.tag == 'viewer') {
2209
- // View the file in the dialog box
2210
- setDialogMode(4, EscapeHtml(gdownloadFile.file), 3, p13editSaveBack, null, gdownloadFile.file);
2211
- QS('dialog').width = 'auto';
2212
- QS('dialog').bottom = '80px';
2213
- QS('dialog').top = QS('dialog').left = QS('dialog').right = '100px';
2214
- Q('d4editorarea').value = gdownloadFile.data;
2215
- gdownloadFile = null;
2216
- } else {
2217
- // Save the file to disk
2218
- saveAs(data2blob(gdownloadFile.data), gdownloadFile.file); gdownloadFile = null; setDialogMode(0); // Save the file
2219
- }
2220
- } else {
2221
- files.sendText({ action: 'download', sub: 'ack', id: gdownloadFile.id }); // Send the ACK
2222
- }
2223
- }
2224
-
2225
- var d4EditWrapVal = 0;
2226
- var d4EditSizeVal = 0;
2227
- function d4ToggleWrap(update) {
2228
- if (!update) { d4EditWrapVal = ++d4EditWrapVal % 2; }
2229
- Q('d4WrapButton').value = ["Wrap: ON", "Wrap: OFF"][d4EditWrapVal];
2230
- QS('d4editorarea').overflow = (d4EditWrapVal == 0) ? 'auto' : 'scroll';
2231
- QS('d4editorarea')['white-space'] = (d4EditWrapVal == 0) ? null : 'pre';
2232
- putstore('editorWrap', d4EditWrapVal);
2233
- }
2234
-
2235
- function d4ToggleSize(update) {
2236
- if (!update) { d4EditSizeVal = ++d4EditSizeVal % 4; }
2237
- QS('d4editorarea')['font-size'] = ['100%', '125%', '150%', '200%'][d4EditSizeVal];
2238
- Q('d4SizeButton').value = ["Size: 100%", "Size: 125%", "Size: 150%", "Size: 200%"][d4EditSizeVal];
2239
- putstore('editorSize', d4EditSizeVal);
2240
- }
2241
-
2242
- function p13editSaveBack(b, tag) {
2243
- var data = new TextEncoder().encode(Q('d4editorarea').value);
2244
- p13uploadFileContinue(1, [{ name: tag, size: data.byteLength, type: 'text/plain', xdata: data }]);
2245
- }
2246
-
2247
- //
2248
- // FILES UPLOAD
2249
- //
2250
-
2251
- var uploadFile;
2252
- function p13doUploadFiles(files) {
2253
- if (xxdialogMode) return;
2254
-
2255
- // Check if we are going to overwrite any files
2256
- var winAgent = true;//((currentNode.agent.id > 0) && (currentNode.agent.id < 5));
2257
- var targetFiles = [], overWriteCount = 0;
2258
- for (var i in p13filetree.dir) { if (winAgent) { targetFiles.push(p13filetree.dir[i].n.toLowerCase()); } else { targetFiles.push(p13filetree.dir[i].n); } }
2259
- for (var i = 0; i < files.length; i++) {
2260
- if (winAgent) {
2261
- if (targetFiles.indexOf(files[i].name.toLowerCase()) >= 0) { overWriteCount++; }
2262
- } else {
2263
- if (targetFiles.indexOf(files[i].name) >= 0) { overWriteCount++; }
2264
- }
2265
- }
2266
-
2267
- if (overWriteCount == 0) {
2268
- // If no overwrite, go ahead with upload
2269
- p13uploadFileContinue(1, files);
2270
- } else {
2271
- // Otherwise, prompt for confirmation
2272
- setDialogMode(2, "Upload File", 3, p13uploadFileContinue, format((overWriteCount == 1) ? "Upload will overwrite 1 file. Continue?" : "Upload will overwrite {0} files. Continue?", overWriteCount), files);
2273
- }
2274
- }
2275
-
2276
- function p13uploadFileContinue(b, files) {
2277
- uploadFile = {};
2278
- uploadFile.xpath = p13filetreelocation.join('/');
2279
- uploadFile.xfiles = files;
2280
- uploadFile.xfilePtr = -1;
2281
- setDialogMode(2, "Upload File", 10, p13uploadFileCancel, '<div id=p13dfileName>' + "Connecting..." + '</div><br /><progress id=d2progressBar style=width:100% value=0 max=0 />');
2282
- p13uploadNextFile();
2283
- }
2284
-
2285
- // Perform SHA-384 hashing
2286
- const byteToHex = [];
2287
- for (var n = 0; n <= 0xff; ++n) { var hexOctet = n.toString(16).padStart(2, '0'); byteToHex.push(hexOctet); }
2288
- function arrayBufferToHex(arrayBuffer) { return Array.prototype.map.call(new Uint8Array(arrayBuffer), n => byteToHex[n]).join(''); }
2289
- function performHash(data, f) { window.crypto.subtle.digest('SHA-384', data).then(function (v) { f(arrayBufferToHex(v)); }, function () { f(null); }); }
2290
-
2291
- // Push the next file
2292
- function p13uploadNextFile() {
2293
- uploadFile.xfilePtr++;
2294
- if (uploadFile.xfiles.length > uploadFile.xfilePtr) {
2295
- uploadFile.xptr = 0;
2296
- var file = uploadFile.xfiles[uploadFile.xfilePtr];
2297
- QH('p13dfileName', file.name);
2298
- Q('d2progressBar').max = file.size;
2299
- Q('d2progressBar').value = 0;
2300
- if (file.xdata == null) {
2301
- // Load the data
2302
- uploadFile.xreader = new FileReader();
2303
- uploadFile.xreader.onload = function () {
2304
- uploadFile.xdata = uploadFile.xreader.result;
2305
-
2306
- // If the remote file already exists and is smaller then our file, see if we can resume the trasfer
2307
- var f = null;
2308
- for (var i in p13filetree.dir) { if (p13filetree.dir[i].n == file.name) { f = p13filetree.dir[i]; } }
2309
- if ((f != null) && (f.s <= uploadFile.xreader.result.byteLength)) {
2310
- performHash(uploadFile.xreader.result.slice(0, f.s), function (hash) {
2311
- files.sendText(JSON.stringify({ action: 'uploadhash', reqid: uploadFile.xfilePtr, path: uploadFile.xpath, name: file.name, tag: { h: hash.toUpperCase(), s: f.s, skip: f.s == uploadFile.xreader.result.byteLength } }));
2312
- });
2313
- } else {
2314
- files.sendText(JSON.stringify({ action: 'upload', reqid: uploadFile.xfilePtr, path: uploadFile.xpath, name: file.name, size: uploadFile.xdata.byteLength }));
2315
- }
2316
- };
2317
- uploadFile.xreader.readAsArrayBuffer(file);
2318
- } else {
2319
- // Data already loaded
2320
- uploadFile.xdata = file.xdata;
2321
- files.sendText(JSON.stringify({ action: 'upload', reqid: uploadFile.xfilePtr, path: uploadFile.xpath, name: file.name, size: uploadFile.xdata.byteLength }));
2322
- }
2323
- } else {
2324
- p13uploadFileTransferDone();
2325
- }
2326
- }
2327
-
2328
- // Used to cancel the entire transfer.
2329
- function p13uploadFileCancel(button, tag) {
2330
- if (uploadFile != null) { files.sendText(JSON.stringify({ action: 'uploadcancel', reqid: uploadFile.xfilePtr })); uploadFile = null; }
2331
- p13uploadFileTransferDone();
2332
- }
2333
-
2334
- // Used to cancel the entire transfer.
2335
- function p13uploadFileTransferDone() {
2336
- uploadFile = null; // No more files to upload, clean up.
2337
- setDialogMode(0); // Close the dialog box
2338
- p13folderup(9999); // Refresh the current folder
2339
- }
2340
-
2341
- // Receive upload ack from the mesh agent, use this to keep sending more data
2342
- function p13gotUploadData(cmd) {
2343
- if ((uploadFile == null) || (parseInt(uploadFile.xfilePtr) != parseInt(cmd.reqid))) { return; }
2344
- switch (cmd.action) {
2345
- case 'uploadstart': { p13uploadNextPart(false); for (var i = 0; i < 8; i++) { p13uploadNextPart(true); } break; } // Send 8 more blocks of 16k to fill the websocket.
2346
- case 'uploadack': { p13uploadNextPart(false); break; }
2347
- case 'uploaddone': { if (uploadFile.xfiles.length > uploadFile.xfilePtr + 1) { p13uploadNextFile(); } else { p13uploadFileTransferDone(); } break; }
2348
- case 'uploaderror': { p13uploadFileCancel(); break; }
2349
- case 'uploadhash': {
2350
- var file = uploadFile.xfiles[uploadFile.xfilePtr];
2351
- if (file) {
2352
- if (cmd.tag.h === cmd.hash) {
2353
- if (cmd.tag.skip) {
2354
- p13uploadNextFile();
2355
- } else {
2356
- uploadFile.xptr = cmd.tag.s;
2357
- files.sendText(JSON.stringify({ action: 'upload', reqid: uploadFile.xfilePtr, path: uploadFile.xpath, name: file.name, size: uploadFile.xdata.byteLength, append: true }));
2358
- }
2359
- } else {
2360
- files.sendText(JSON.stringify({ action: 'upload', reqid: uploadFile.xfilePtr, path: uploadFile.xpath, name: file.name, size: uploadFile.xdata.byteLength, append: false }));
2361
- }
2362
- }
2363
- break;
2364
- }
2365
- }
2366
- }
2367
-
2368
- // Push the next part of the file into the websocket. If dataPriming is true, push more data only if it's not the last block of the file.
2369
- function p13uploadNextPart(dataPriming) {
2370
- var data = uploadFile.xdata, start = uploadFile.xptr;
2371
- if (start >= data.byteLength) {
2372
- files.sendText(JSON.stringify({ action: 'uploaddone', reqid: uploadFile.xfilePtr }));
2373
- } else {
2374
- var end = uploadFile.xptr + 16384;
2375
- if (end > data.byteLength) { if (dataPriming == true) { return; } end = data.byteLength; }
2376
- var dataslice = new Uint8Array(data.slice(start, end))
2377
- if ((dataslice[0] == 123) || (dataslice[0] == 0)) {
2378
- var datapart = new Uint8Array(end - start + 1);
2379
- datapart.set(dataslice, 1); // Add a zero char at the start of the send, this will indicate that it's not a JSON command.
2380
- files.send(datapart);
2381
- } else {
2382
- files.send(dataslice); // The data does not start with 0 or 123 "{" so it can't be confused for JSON.
2383
- }
2384
- uploadFile.xptr = end;
2385
- Q('d2progressBar').value = end;
2386
- }
2387
- }
2388
-
2389
-
2390
-
2391
- //
2392
- // POPUP DIALOG
2393
- //
2394
-
2395
- // null = Hidden, 1 = Generic Message
2396
- var xxdialogMode;
2397
- var xxdialogFunc;
2398
- var xxdialogButtons;
2399
- var xxdialogTag;
2400
- var xxcurrentView = -1;
2401
-
2402
- // Display a dialog box
2403
- // Parameters: Dialog Mode (0 = none), Dialog Title, Buttons (1 = OK, 2 = Cancel, 3 = OK & Cancel), Call back function(0 = Cancel, 1 = OK), Dialog Content (Mode 2 only)
2404
- function setDialogMode(x, y, b, f, c, tag) {
2405
- xxdialogMode = x;
2406
- xxdialogFunc = f;
2407
- xxdialogButtons = b;
2408
- xxdialogTag = tag;
2409
- QE('idx_dlgOkButton', true);
2410
- QV('idx_dlgOkButton', b & 1);
2411
- QV('idx_dlgCancelButton', b & 2);
2412
- QV('id_dialogclose', (b & 2) || (b & 8));
2413
- QV('idx_dlgDeleteButton', b & 4);
2414
- QV('idx_dlgButtonBar', b & 7);
2415
- if (y) QH('id_dialogtitle', y);
2416
- for (var i = 1; i < 8; i++) { QV('dialog' + i, i == x); } // Edit this line when more dialogs are added
2417
- QV('dialog', x);
2418
- if (c) { if (x == 2) { QH('id_dialogOptions', c); } else { QH('id_dialogMessage', c); } }
2419
- }
2420
-
2421
- function dialogclose(x) {
2422
- var f = xxdialogFunc, b = xxdialogButtons, t = xxdialogTag;
2423
- setDialogMode();
2424
- if (((b & 8) || x) && f) f(x, t);
2425
- }
2426
-
2427
- function go(x) {
2428
- if (xxdialogMode) return;
2429
- QV('p11', x == 11);
2430
- QV('p12', x == 12);
2431
- QV('p13', x == 13);
2432
- xxcurrentView = x;
2433
- setupDeviceMenu();
2434
- }
2435
-
2436
- function setupDeviceMenu() {
2437
- var menus = [];
2438
- if (features & 2) { menus.push({ n: "Desktop", f: 'go(11)', s: (xxcurrentView == 11) }); }
2439
- if (features & 1) { menus.push({ n: "Terminal", f: 'go(12)', s: (xxcurrentView == 12) }); }
2440
- if (features & 4) { menus.push({ n: "Files", f: 'go(13)', s: (xxcurrentView == 13) }); }
2441
- updateFooterMenu(menus);
2442
- }
2443
-
2444
- function updateFooterMenu(options) {
2445
- while (options != null && options.length < 3) { options.push({ n: '' }); }
2446
- var x = '', prev = '';
2447
- if (options != null) { for (var i in options) { x += '<td style="cursor:pointer' + ((prev == '') ? '' : ';border-left:solid 1px white') + (options[i].s ? ';background-color:#487099' : '') + '" onclick="' + options[i].f + '">' + options[i].n; prev = options[i].n; } }
2448
- QH('xfooterMenu', '<tr>' + x);
2449
- }
2450
-
2451
- function center() { if (xtermfit) xtermfit.fit(); QS('dialog').left = ((((getDocWidth() - 300) / 2)) + 'px'); deskAdjust(); }
2452
- function getDocWidth() { if (window.innerWidth) return window.innerWidth; if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientWidth != 0) return document.documentElement.clientWidth; return document.getElementsByTagName('body')[0].clientWidth; }
2453
- function messagebox(t, m) { setSessionActivity(); QH('id_dialogMessage', m); setDialogMode(1, t, 1); }
2454
- function statusbox(t, m) { setSessionActivity(); QH('id_dialogMessage', m); setDialogMode(1, t); }
2455
- function haltEvent(e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
2456
- function pad2(num) { var s = '00' + num; return s.substr(s.length - 2); }
2457
- function format(format) { var args = Array.prototype.slice.call(arguments, 1); return format.replace(/{(\d+)}/g, function (match, number) { return typeof args[number] != 'undefined' ? args[number] : match; }); };
2458
- function setSessionActivity() { sessionActivity = Date.now(); /*QH('idleTimeoutNotify', '');*/ }
2459
- function printDate(d) { return d.toLocaleDateString(urlargs.locale); }
2460
- function printTime(d) { return d.toLocaleTimeString(urlargs.locale); }
2461
- function printDateTime(d) { return d.toLocaleString(urlargs.locale); }
2462
- function printFlexDateTime(d) { if (printDate(new Date()) == printDate(d)) { return format("Expires at {0}", printTime(d)); } else { return format("Expires {0}", printDateTime(d)); } }
2463
- function getFileSizeStr(size) { if (typeof size != 'number') { size = 0; } if (size == 1) return "1 byte"; return format("{0} bytes", size); }
2464
- function encodeURIComponentEx(txt) { return encodeURIComponent(txt).replace(/'/g, '%27'); };
2465
- function joinPaths() { var x = []; for (var i in arguments) { var w = arguments[i]; if ((w != null) && (w != '')) { while (w.endsWith('/') || w.endsWith('\\')) { w = w.substring(0, w.length - 1); } while (w.startsWith('/') || w.startsWith('\\')) { w = w.substring(1); } x.push(w); } } return x.join('/'); }
2466
- function focusTextBox(x) { setTimeout(function () { Q(x).selectionStart = Q(x).selectionEnd = 65535; Q(x).focus(); }, 0); }
2467
- var isFilenameValid = (function () { var x1 = /^[^\\/:\*\?"<>\|]+$/, x2 = /^\./, x3 = /^(nul|prn|con|lpt[0-9]|com[0-9])(\.|$)/i; return function isFilenameValid(fname) { return x1.test(fname) && !x2.test(fname) && !x3.test(fname) && (fname[0] != '.'); } })();
2468
-
2469
- // Webkit seems to have a problem with "download" tag causing "network error", but openning the download in a hidden frame fixes it.
2470
- // So we do that for all browsers except FireFox
2471
- function downloadFile(link, name, closeDialog) {
2472
- var element = document.createElement('a');
2473
- element.setAttribute('href', link);
2474
- element.setAttribute('rel', 'noreferrer noopener');
2475
- element.setAttribute('target', 'fileDownloadFrame');
2476
- if (navigator.userAgent.indexOf('Firefox') >= 0) { element.setAttribute('download', decodeURIComponent(name ? name : '')); }
2477
- document.body.appendChild(element);
2478
- element.click();
2479
- document.body.removeChild(element);
2480
- if (closeDialog) { setDialogMode(0); }
2481
- }
2482
-
2483
- start();
2484
- </script>
2485
-</body>
2486
-</html>
\ No newline at end of file
views/sharing-mobile.handlebars
+45
-203
@@ -459,19 +459,9 @@
459
<div id=p10 style=display:none;position:absolute;bottom:0;top:0;width:100%;overflow:hidden>
460
<table id=p10deskTopTable cellspacing=0 style="margin:0;padding:0;border-spacing:0;border:0;position:absolute;top:0">
461
<tr style=padding:0>
462
- <td style="padding:0;color:#c8c8c8;text-align:center;cursor:pointer" width=60px valign=top onclick=goBack()>
463
- <div style="padding:0;background-color:#036;width:10px;height:10px;float:right;border:0">
464
- <div class="menucurve"></div>
465
- </div>
466
- <div style="padding:0;font-size:25px;background-color:#036;width:50px;border-radius:0 0 10px 0;height:36px">◀</div>
467
- </td>
468
- <td>
469
- <a id=MainComputerImage style=cursor:pointer onclick=p10showiconselector()></a>
470
- </td>
462
<td>
472
- <div style=margin-left:5px>
473
- <strong><span id=p10deviceName></span></strong><br />
474
- <span id=MainComputerState></span>
463
+ <div style="margin-left:10px;margin-top:14px;font-size:20px">
464
+ <strong><span id=p10deviceName></span></strong>
465
</div>
466
</td>
467
</tr>
@@ -522,15 +512,10 @@
512
<div id=deskarea4 style="position:absolute;bottom:0px;width:100%;height:32px">
513
<div style=padding-top:2px;padding-bottom:2px;background:#C0C0C0>
514
<div style=float:right;text-align:right>
525
- <span id=DeskChatButton><img src='images/icon-chat.png' onclick=deviceChat(event) height=16 width=16 style=padding-top:5px;cursor:pointer /></span>
526
- <span id=DeskToastButton><img src='images/icon-notify.png' onclick=deviceToastFunction() height=16 width=16 style=padding-top:5px;cursor:pointer /></span>
515
<!--<input id=DeskToolsButton type=button value=Tools onkeypress="return false" onkeydown="return false" onclick="toggleDeskTools()"> -->
516
</div>
517
<div>
530
- <input id="deskActionsBtn" type=button style="margin-left:3px;height:28px" onkeypress="return false" onkeydown="return false" value=Actions onclick=deviceActionFunction() />
518
<input type="button" value="Settings" onkeypress="return false" onkeydown="return false" onclick="showDesktopSettings()" style="height:28px">
532
- <input type="button" onkeypress="return false" onkeydown="return false" value="Power Actions..." onclick="showPowerActionDlg()" style="display:none;height:28px">
533
- <!--<input type="button" id="DeskSpecialKeys" value="Keys" onkeypress="return false" onkeydown="return false" onclick="sendSpecialKeys()" style="height:28px">-->
519
<input type="button" id="DeskScreens" value="Screens" onkeypress="return false" onkeydown="return false" onclick="deskSelectScreens()" style="display:none;height:28px">
520
<label><span id="DeskControlSpan" style="display:none"><input id="DeskControl" type="checkbox" onkeypress="return false" onkeydown="return false">Input</span></label>
521
</div>
@@ -562,7 +547,6 @@
547
<div class="areaFoot">
548
<div class="toright2"></div>
549
<div style="height:28px">
565
- <input id="termActionsBtn" style="margin-left:3px;height:28px" type=button title="Perform power actions on the device" onkeypress="return false" onkeydown="return false" value=Actions onclick=deviceActionFunction() />
550
</div>
551
</div>
552
</div>
@@ -574,7 +558,6 @@
558
<tr>
559
<td style="background-color:#C0C0C0;border-bottom:2px solid black;padding:2px;line-height:24px">
560
<div style="float:right;text-align:right">
577
- <input id="filesActionsBtn" type=button onkeypress="return false" onkeydown="return false" value=Actions onclick=deviceActionFunction() style=margin-right:2px />
561
<div id="filesCustomUpperRight" style="float:left;margin-right:6px"></div>
562
</div>
563
<div style="margin-left:2px">
@@ -755,13 +738,14 @@
738
<script>
739
'use strict';
740
var args = parseUriArgs();
741
+ var urlargs = args;
742
var sessionTime = parseInt('{{{sessiontime}}}');
743
var sessionRefreshTimer = null;
744
var domain = '{{{domain}}}';
745
var domainUrl = '{{{domainurl}}}';
746
var authCookie = '{{{authCookie}}}';
747
var authRelayCookie = '{{{authRelayCookie}}}';
764
- var viewOnly = parseInt('{{{viewOnly}}}');
748
+ var viewOnly = (parseInt('{{{viewOnly}}}') == 1);
749
var authCookieRenewTimer = null;
750
var serverPublicNamePort = '{{{serverDnsName}}}:{{{serverPublicPort}}}';
751
var debugmode = false;
@@ -777,6 +761,7 @@
761
var xtermResizeTimer = null;
762
var features = parseInt('{{{features}}}');
763
var features2 = parseInt('{{{features2}}}');
764
+ var nodeName = decodeURIComponent('{{{nodeName}}}');
765
766
// Console Message Display Timers
767
var p11DeskConsoleMsgTimer = null;
@@ -788,6 +773,7 @@
773
check_webp_feature('lossy', function (f, x) { webpSupport = x; });
774
775
function startup() {
776
+ QH('p10deviceName', nodeName);
777
if ((features & 32) == 0) {
778
// Guard against other site's top frames (web bugs).
779
var loc = null;
@@ -800,6 +786,9 @@
786
center();
787
go(10);
788
789
+ // Set the document title
790
+ if (nodeName.length > 0) { document.title += ' - ' + nodeName; }
791
+
792
// Document keys
793
document.onkeypress = ondeskkeypress;
794
document.onkeydown = ondeskkeydown;
@@ -820,6 +809,8 @@
809
for (var i in deskKeyboardShortcutsStr) { deskKeyboardShortcuts.push(parseInt(deskKeyboardShortcutsStr[i])); }
810
updateDeskShortcutKeys();
811
updateTermShortcutKeys();
812
+ updateDesktopButtons();
813
+ updateTerminalButtons();
814
815
if (features & 2) { currentDevicePanel = 1; } // Goto desktop
816
else if (features & 1) { currentDevicePanel = 5; } // Goto terminal
@@ -853,13 +844,7 @@
844
gotKeyPressEvent = true;
845
Q('softKeyboard').value = '';
846
// Check what keys we are allows to send
856
- if (currentNode != null) {
857
- var meshrights = GetMeshRights(currentNode.meshid);
858
- var inputAllowed = ((features2 & 0x2000) == 0) && ((meshrights == 0xFFFFFFFF) || (((meshrights & 8) != 0) && ((meshrights & 256) == 0)));
859
- if (inputAllowed == false) return false;
860
- var limitedInputAllowed = ((meshrights != 0xFFFFFFFF) && (((meshrights & 8) != 0) && ((meshrights & 256) == 0) && ((meshrights & 4096) != 0)));
861
- if (limitedInputAllowed == true) { if ((e.altKey == true) || (e.ctrlKey == true) || ((e.keyCode < 32) && (e.keyCode != 8) && (e.keyCode != 13)) || (e.keyCode > 90)) return false; }
862
- }
847
+ if (viewOnly) return false;
848
return desktop.m.handleKeys(e);
849
}
850
if (terminal && !xxdialogMode && (xxcurrentView == 10) && (currentDevicePanel == 5) && (t !== 1)) {
@@ -887,13 +872,7 @@
872
gotKeyPressEvent = false;
873
Q('softKeyboard').value = '';
874
// Check what keys we are allows to send
890
- if (currentNode != null) {
891
- var meshrights = GetMeshRights(currentNode.meshid);
892
- var inputAllowed = ((features2 & 0x2000) == 0) && ((meshrights == 0xFFFFFFFF) || (((meshrights & 8) != 0) && ((meshrights & 256) == 0)));
893
- if (inputAllowed == false) return false;
894
- var limitedInputAllowed = ((meshrights != 0xFFFFFFFF) && (((meshrights & 8) != 0) && ((meshrights & 256) == 0) && ((meshrights & 4096) != 0)));
895
- if (limitedInputAllowed == true) { if ((e.altKey == true) || (e.ctrlKey == true) || ((e.keyCode < 32) && (e.keyCode != 8) && (e.keyCode != 13)) || (e.keyCode > 90)) return false; }
896
- }
875
+ if (viewOnly) return false;
876
return desktop.m.handleKeyDown(e);
877
}
878
if (terminal && !xxdialogMode && (xxcurrentView == 10) && (currentDevicePanel == 5) && (t !== 1)) {
@@ -922,13 +901,7 @@
901
var inputStr = Q('softKeyboard').value;
902
Q('softKeyboard').value = '';
903
// Check what keys we are allows to send
925
- if (currentNode != null) {
926
- var meshrights = GetMeshRights(currentNode.meshid);
927
- var inputAllowed = ((features2 & 0x2000) == 0) && ((meshrights == 0xFFFFFFFF) || (((meshrights & 8) != 0) && ((meshrights & 256) == 0)));
928
- if (inputAllowed == false) return false;
929
- var limitedInputAllowed = ((meshrights != 0xFFFFFFFF) && (((meshrights & 8) != 0) && ((meshrights & 256) == 0) && ((meshrights & 4096) != 0)));
930
- if (limitedInputAllowed == true) { if ((e.altKey == true) || (e.ctrlKey == true) || ((e.keyCode < 32) && (e.keyCode != 8) && (e.keyCode != 13)) || (e.keyCode > 90)) return false; }
931
- }
904
+ if (viewOnly) return;
905
if ((gotKeyPressEvent == false) && (inputStr.length > 0) && desktop.m.SendKeyUnicode) {
906
// This is a mobile keyboard, we need to send that is in the input control.
907
var inputchar = inputStr[inputStr.length - 1].charCodeAt(0);
@@ -1035,15 +1008,15 @@
1008
1009
// Show and enable the right buttons
1010
function updateDesktopButtons() {
1038
- var mesh = meshes[currentNode.meshid];
1011
var deskState = 0;
1012
if (desktop != null) { deskState = desktop.State; }
1041
- var meshrights = GetNodeRights(currentNode);
1013
1014
// Show the right buttons
1015
QV('disconnectbutton1', (deskState != 0));
1016
QE('deskFullScreen', (deskState != 0));
1046
- QV('connectbutton1', (deskState == 0) && ((meshrights & 8) || (meshrights & 256)) && (currentNode.agent != null) && (currentNode.agent.caps & 1));
1017
+ QV('connectbutton1', (deskState == 0));
1018
+ QV('connectbutton1h', false);
1019
+ /*
1020
QV('connectbutton1h',
1021
(deskState == 0) &&
1022
(meshrights & 8) &&
@@ -1056,29 +1029,15 @@
1029
((currentNode.intelamt.sku & 8) != 0))))
1030
)
1031
);
1032
+ */
1033
1034
// Show the right settings
1061
- QV('d7amtkvm', (currentNode.intelamt != null && ((currentNode.intelamt.ver != null) || (currentNode.agent == null))) && ((deskState == 0) || (desktop.contype == 2)));
1062
- QV('d7meshkvm', ((currentNode.agent != null) && (currentNode.agent.caps & 1) && ((deskState == false) || (desktop.contype == 1))));
1035
+ QV('d7amtkvm', false);
1036
+ QV('d7meshkvm', true);
1037
1038
// Enable buttons
1065
- var online = ((currentNode.conn & 1) != 0); // If Agent (1) connected, enable remote desktop
1066
- QE('connectbutton1', online);
1067
- var hwonline = ((currentNode.conn & 6) != 0); // If CIRA (2) or AMT (4) connected, enable hardware terminal
1068
- QE('connectbutton1h', hwonline);
1069
- //QE('deskSaveBtn', deskState == 3);
1070
- //QV('DeskCAD', meshrights & 8);
1071
- //QE('DeskCAD', deskState == 3);
1072
- //QV('DeskWD', (currentNode.agent) && (currentNode.agent.id < 5));
1073
- //QE('DeskWD', deskState == 3);
1074
- //QV('deskkeys', (currentNode.agent) && (currentNode.agent.id < 5));
1075
- //QE('deskkeys', deskState == 3);
1076
- //QE('DeskToolsButton', online);
1077
- QV('DeskToastButton', ((meshrights & 16384) != 0) && (currentNode.agent) && (currentNode.agent.id < 5) && (meshrights & 8));
1078
- //QE('DeskToastButton', online);
1079
- QV('deskActionsBtn', meshrights & 8);
1080
- Q('DeskControl').checked = ((meshrights & 8) != 0);
1081
- if (online == false) QV('DeskTools', false);
1039
+ QE('connectbutton1', true);
1040
+ QE('connectbutton1h', false);
1041
}
1042
1043
// Used to translate incoming agent console messages
@@ -1096,7 +1055,6 @@
1055
QV('p11DeskSessionSelector', false);
1056
p11clearConsoleMsg();
1057
if (desktop == null) {
1099
- desktopNode = currentNode;
1058
if (contype == 2) {
1059
// Setup the Intel AMT remote desktop
1060
if ((desktopNode.intelamt.user == null) || (desktopNode.intelamt.user == '')) { editDeviceAmtSettings(desktopNode._id, connectDesktop); return; }
@@ -1109,9 +1067,9 @@
1067
desktop.m.onScreenSizeChange = function (o, x, y) { if (fullscreen) { QS('deskarea3').width = (x * fullscreenzoom) + 'px'; QS('deskarea3').height = (y * fullscreenzoom) + 'px'; } deskAdjust(); }
1068
desktop.Start(desktopNode._id, 16994, '*', '*', 0);
1069
desktop.contype = 2;
1112
- } else if ((contype == null) || (contype == 1) || ((contype == 3) && (currentNode.agent.id > 4))) {
1070
+ } else if ((contype == null) || (contype == 1) || ((contype == 3))) {
1071
// Setup the Mesh Agent remote desktop
1114
- desktop = CreateAgentRedirect(meshserver, CreateAgentRemoteDesktop('Desk'), serverPublicNamePort, authCookie, authRelayCookie, domainUrl);
1072
+ desktop = CreateAgentRedirect(null, CreateAgentRemoteDesktop('Desk'), serverPublicNamePort, authCookie, null, domainUrl);
1073
desktop.debugmode = debugmode;
1074
desktop.m.debugmode = debugmode;
1075
desktop.attemptWebRTC = attemptWebRTC;
@@ -1137,11 +1095,11 @@
1095
desktop.m.FrameRateTimer = desktopsettings.framerate;
1096
desktop.m.onDisplayinfo = deskDisplayInfo;
1097
desktop.m.onScreenSizeChange = function (o, x, y) { if (fullscreen) { QS('deskarea3').width = (x * fullscreenzoom) + 'px'; QS('deskarea3').height = (y * fullscreenzoom) + 'px'; } deskAdjust(); }
1140
- desktop.Start(desktopNode._id);
1098
+ desktop.Start(null);
1099
desktop.contype = 1;
1100
} else if (contype == 3) {
1101
// Ask for user sessions
1144
- meshserver.send({ action: 'msg', type: 'userSessions', nodeid: currentNode._id, tag: consent });
1102
+ //meshserver.send({ action: 'msg', type: 'userSessions', nodeid: currentNode._id, tag: consent });
1103
}
1104
} else {
1105
// Disconnect and clean up the remote desktop
@@ -1483,9 +1441,7 @@
1441
QV('deskarea4', !fullscreen);
1442
QV('termarea1', !fullscreen);
1443
QV('termarea4', !fullscreen);
1486
-
1487
- var rights = GetNodeRights(currentNode);
1488
- var inputAllowed = ((features2 & 0x2000) == 0) && (currentNode.agent.id != 14) && ((rights == 0xFFFFFFFF) || (((rights & 8) != 0) && ((rights & 256) == 0) && ((rights & 4096) == 0)));
1444
+ var inputAllowed = !viewOnly;
1445
1446
// Show full screen buttons if needed
1447
QV('deskkeybutton1', fullscreen);
@@ -1570,7 +1526,7 @@
1526
QS('termarea3')['padding-right'] = null;
1527
QS('termarea3')['height'] = 'calc(100% - 60px)';
1528
}
1573
- QS('body')['background-color'] = nightMode ? '#000' : '#FFF';
1529
+ QS('body')['background-color'] = '#FFF';
1530
QS('p10')['background-color'] = null;
1531
}
1532
if (currentDevicePanel == 1) { deskAdjust(); }
@@ -1664,40 +1620,15 @@
1620
1621
// Show and enable the right buttons
1622
function updateTerminalButtons() {
1667
- var mtype = (currentNode.agent == 1) ? 1 : 2;
1623
var termState = ((terminal != null) && (terminal.state != 0));
1624
QE('termFullScreen', (termState != 0));
1625
1671
- // If we are looking at a local non-windows device, enable terminal and files capability.
1672
- if ((terminalNode.mtype == 3) && (terminalNode.agent != null) && (terminalNode.agent.id > 4) && (features2 & 0x00000200)) { terminalNode.agent.caps = 6; }
1673
-
1626
// Show the right buttons
1675
- QV('disconnectbutton2span', (termState == true));
1676
- QV('connectbutton2span', (termState == false) && (currentNode.agent != null) && (currentNode.agent.caps & 2));
1627
+ QV('disconnectbutton2span', termState == true);
1628
+ QV('connectbutton2span', termState == false);
1629
1630
// Enable buttons
1679
- var online = ((terminalNode.conn & 1) != 0) || (terminalNode.mtype == 3); // If Agent (1) connected, enable Terminal
1680
- QE('connectbutton2', online);
1681
-
1682
- // Enable action button if mesh type is not "local devices"
1683
- QV('termActionsBtn', terminalNode.mtype != 3);
1684
- if (terminalNode.mtype != 3) {
1685
- QH('terminalCustomUpperRight', '');
1686
- } else {
1687
- QH('terminalCustomUpperRight', '<a style=cursor:pointer onclick=cmsshportaction(1,event)>' + format("SSH Port {0}", (terminalNode.sshport ? terminalNode.sshport : 22)) + '</a>');
1688
- }
1689
- }
1690
-
1691
- function cmsshportaction(action) {
1692
- if (xxdialogMode) return;
1693
- var x = "SSH remote connection port:" + '<br /><br /><input type=text placeholder="22" inputmode="numeric" pattern="[0-9]*" onkeypress="return (event.keyCode == 8) || (event.charCode >= 48 && event.charCode <= 57)" maxlength=5 id=d10sshport type=text>';
1694
- setDialogMode(2, "SSH Connection", 3, function () {
1695
- // Save the new SSH port to the server
1696
- var sshport = ((Q('d10sshport').value.length > 0) ? parseInt(Q('d10sshport').value) : 22);
1697
- meshserver.send({ action: 'changedevice', nodeid: currentNode._id, sshport: sshport });
1698
- }, x, currentNode);
1699
- Q('d10sshport').focus();
1700
- if (currentNode.sshport != null) { Q('d10sshport').value = currentNode.sshport; }
1631
+ QE('connectbutton2', true);
1632
}
1633
1634
// Called when the terminal state changes
@@ -1878,14 +1809,13 @@
1809
document.getElementsByClassName('xterm-viewport')[0].style.overflow = 'hidden';
1810
1811
// Setup a terminal tunnel to the agent
1881
- terminal = CreateAgentRedirect(meshserver, CreateRemoteTunnel((currentNode.mtype == 3) ? sshTunnelUpdate : tunnelUpdate, termoptions), serverPublicNamePort, authCookie, authRelayCookie, domainUrl);
1882
- if (currentNode.mtype == 3) { terminal.urlname = 'sshterminalrelay.ashx'; } // If this is a SSH session, change the URL to the SSH application relay.
1812
+ terminal = CreateAgentRedirect(null, CreateRemoteTunnel(tunnelUpdate, options), serverPublicNamePort, authCookie, null, domainUrl);
1813
terminal.debugmode = debugmode;
1814
terminal.m.debugmode = debugmode;
1815
terminal.options = termoptions;
1816
terminal.options = { cols: xterm.cols, rows: xterm.rows };
1817
if (termoptions.requireLogin) { terminal.options.requireLogin = true; }
1888
- terminal.Start(terminalNode._id);
1818
+ terminal.Start(null);
1819
terminal.onStateChanged = onTerminalStateChange;
1820
terminal.contype = 1;
1821
terminal.attemptWebRTC = false; // Never do WebRTC on terminal, because of a race condition we can't do it.
@@ -1924,14 +1854,9 @@
1854
// FILES
1855
//
1856
1927
- var filesNode;
1857
function setupFiles() {
1858
// Setup the files tab
1930
- var samenode = (filesNode == currentNode);
1931
- filesNode = currentNode;
1932
- var online = ((filesNode.conn & 1) != 0) || (filesNode.mtype == 3); // If Agent (1) connected, enable Terminal
1933
- QE('p13Connect', online);
1934
- if (((samenode == false) || (online == false)) && files) { files.Stop(); files = null; }
1859
+ QE('p13Connect', true);
1860
p13setActions();
1861
}
1862
@@ -1957,9 +1882,6 @@
1882
p13filetreelocation = [];
1883
p13targetpath = '';
1884
if (files) {
1960
- var filepaths = [];
1961
- try { filepaths = JSON.parse(getstore('_devFilePaths', '[]')); } catch (ex) { }
1962
- for (var i = 0; i < filepaths.length; i++) { if (filepaths[i].n == currentNode._id) { p13targetpath = filepaths[i].p; } }
1885
p13filetreelocation = p13targetpath.split('/');
1886
files.sendText({ action: 'ls', reqid: 1, path: p13targetpath });
1887
//if (files.serverIsRecording == true) { QV('filesRecordIcon', true); }
@@ -1987,8 +1909,7 @@
1909
p13clearConsoleMsg();
1910
if (!files) {
1911
// Setup a mesh agent files
1990
- files = CreateAgentRedirect(meshserver, CreateRemoteFiles(p13gotFiles), serverPublicNamePort, authCookie, authRelayCookie, domainUrl);
1991
- if (filesNode.mtype == 3) { files.urlname = 'sshfilesrelay.ashx'; } // If this is a SSH session, change the URL to the SSH application relay.
1912
+ files = CreateAgentRedirect(null, CreateRemoteFiles(p13gotFiles), serverPublicNamePort, authCookie, null, domainUrl);
1913
files.attemptWebRTC = attemptWebRTC;
1914
files.onStateChanged = onFilesStateChange;
1915
files.onConsoleMessageChange = function () {
@@ -2001,7 +1922,7 @@
1922
p13clearConsoleMsg();
1923
}
1924
}
2004
- files.Start(filesNode._id);
1925
+ files.Start(null);
1926
} else {
1927
//QH('Term', '');
1928
files.Stop();
@@ -2148,7 +2069,6 @@
2069
function p13folderset(x) {
2070
p13targetpath = joinPaths(p13filetree.path, p13filetree.dir[x].n).split('\\').join('/');
2071
if (files) {
2151
- p13storeCurrentPath(p13targetpath);
2072
files.sendText({ action: 'ls', reqid: 1, path: p13targetpath });
2073
}
2074
}
@@ -2157,23 +2077,10 @@
2077
if (x == null) { p13filetreelocation.pop(); } else { while (p13filetreelocation.length > x) { p13filetreelocation.pop(); } }
2078
p13targetpath = p13filetreelocation.join('/');
2079
if (files) {
2160
- p13storeCurrentPath(p13targetpath);
2080
files.sendText({ action: 'ls', reqid: 1, path: p13targetpath });
2081
}
2082
}
2083
2165
- // Store the current path for a given node as browser state.
2166
- // This is so, when reconnecting to a device, you go back to the same path.
2167
- function p13storeCurrentPath(path) {
2168
- var filepaths = [], j = -1;
2169
- try { filepaths = JSON.parse(getstore('_devFilePaths', '[]')); } catch (ex) { }
2170
- for (var i = 0; i < filepaths.length; i++) { if (filepaths[i].n == currentNode._id) { j = i; } }
2171
- if (j >= 0) { filepaths.splice(j, 1); }
2172
- filepaths.push({ n: currentNode._id, p: path });
2173
- while (filepaths.length > 40) { filepaths.shift(); } // Keep only 40 devices worth of paths.
2174
- putstore('_devFilePaths', JSON.stringify(filepaths));
2175
- }
2176
-
2084
var p13sortorder;
2085
function p13sort_filename(a, b) { if (a.ln > b.ln) return (1 * p13sortorder); if (a.ln < b.ln) return (-1 * p13sortorder); return 0; }
2086
function p13sort_timestamp(a, b) { if (a.d > b.d) return (1 * p13sortorder); if (a.d < b.d) return (-1 * p13sortorder); return 0; }
@@ -2191,7 +2098,7 @@
2098
}
2099
2100
function p13setActions() {
2194
- var advancedFeatures = ((currentNode.agent) && (currentNode.agent.id != 14)); // Reduct file feature on some devices.
2101
+ var advancedFeatures = true; //((currentNode.agent) && (currentNode.agent.id != 14)); // Reduct file feature on some devices.
2102
if (p13filetree == null) {
2103
QE('p13DeleteFileButton', false);
2104
QE('p13NewFolderButton', false);
@@ -2205,7 +2112,7 @@
2112
QE('p13PasteButton', false);
2113
} else {
2114
var cc = p13getFileSelCount(), tc = p13getFileCount(), sfc = p13getFileSelCount(false); // In order: number of entires selected, number of total entries, number of selected entires that are files (not folders)
2208
- var winAgent = ((currentNode.agent.id > 0) && (currentNode.agent.id < 5)) || (currentNode.agent.id == 14) || (currentNode.agent.id == 34);
2115
+ var winAgent = true; //((currentNode.agent.id > 0) && (currentNode.agent.id < 5)) || (currentNode.agent.id == 14) || (currentNode.agent.id == 34);
2116
QE('p13DeleteFileButton', advancedFeatures && (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false)));
2117
QE('p13NewFolderButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false)));
2118
QE('p13UploadButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false)));
@@ -2213,16 +2120,12 @@
2120
QE('p13SelectAllButton', tc > 0);
2121
Q('p13SelectAllButton').value = (cc > 0 ? "None" : "All");
2122
QE('p13RefreshButton', true);
2216
- QE('p13CutButton', advancedFeatures && (cc > 0) && (cc == sfc) && (currentNode.mtype != 3) && ((p13filetreelocation.length > 0) || (winAgent == false)));
2217
- QE('p13CopyButton', advancedFeatures && (cc > 0) && (cc == sfc) && (currentNode.mtype != 3) && ((p13filetreelocation.length > 0) || (winAgent == false)));
2218
- QE('p13PasteButton', advancedFeatures && (currentNode.mtype != 3) && ((p13filetreelocation.length > 0) || (winAgent == false)) && ((p13clipboard != null) && (p13clipboard.length > 0)));
2123
+ //QE('p13FindButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false)));
2124
+ QE('p13CutButton', advancedFeatures && (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false)));
2125
+ QE('p13CopyButton', advancedFeatures && (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false)));
2126
+ //QE('p13ZipButton', advancedFeatures && (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false)));
2127
+ QE('p13PasteButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false)) && ((p13clipboard != null) && (p13clipboard.length > 0)));
2128
}
2220
- if (filesNode.mtype != 3) {
2221
- QH('filesCustomUpperRight', '');
2222
- } else {
2223
- QH('filesCustomUpperRight', '<a style=cursor:pointer onclick=cmsshportaction(1,event)>' + format("SSH Port {0}", (filesNode.sshport ? filesNode.sshport : 22)) + '</a>');
2224
- }
2225
- QV('filesActionsBtn', filesNode.mtype != 3);
2129
}
2130
2131
function p13getFileSelCount(includeDirs) { var cc = 0; var checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && ((includeDirs != false) || (checkboxes[i].attributes.file.value == '3'))) cc++; } return cc; }
@@ -2329,67 +2232,6 @@
2232
}
2233
}
2234
2332
- /*
2333
- var downloadFile; // Global state for file download
2334
-
2335
- // Called by the html page to start a download, arguments are: path, file name and file size.
2336
- function p13downloadfile(x, y, z) {
2337
- if (xxdialogMode) return;
2338
- downloadFile = CreateAgentRedirect(meshserver, CreateRemoteFiles(p13gotDownloadData), serverPublicNamePort, authCookie, authRelayCookie, domainUrl); // Create our websocket file transport
2339
- downloadFile.ctrlMsgAllowed = false;
2340
- downloadFile.onStateChanged = onFileDownloadStateChange;
2341
- downloadFile.xpath = decodeURIComponent(x);
2342
- downloadFile.xfile = decodeURIComponent(y);
2343
- downloadFile.xsize = z;
2344
- downloadFile.xtsize = 0;
2345
- downloadFile.xstate = 0;
2346
- downloadFile.Start(filesNode._id);
2347
- setDialogMode(2, "Download File", 10, p13downloadFileCancel, '<div>' + downloadFile.xfile + '</div><br /><progress id=d2progressBar style=width:100% value=0 max=' + z + ' />');
2348
- }
2349
-
2350
- // Called by the html page to cancel the download
2351
- function p13downloadFileCancel(button, tag) {
2352
- //console.log('p13downloadFileCancel');
2353
- downloadFile.Stop();
2354
- delete downloadFile;
2355
- downloadFile = null;
2356
- }
2357
-
2358
- // Called by the file transport to indicate when the transport connection state has changed
2359
- function onFileDownloadStateChange(xdownloadFile, state) {
2360
- switch (state) {
2361
- case 0: // Transport as disconnected. If this is not part of an abort, we need to save the file
2362
- setDialogMode(0); // Close any dialog boxes if present
2363
- if ((downloadFile != null) && (downloadFile.xstate == 1)) { saveAs(data2blob(downloadFile.xdata), downloadFile.xfile); } // Save the file
2364
- break;
2365
- case 3: // Transport as connected, send a command to indicate we want to start a file download
2366
- downloadFile.send(JSON.stringify({ action: 'download', reqid: 1, path: downloadFile.xpath }));
2367
- break;
2368
- default:
2369
- console.log('Unknown onFileDownloadStateChange state', state);
2370
- break;
2371
- }
2372
- }
2373
-
2374
- // Called by the transport when data is received
2375
- function p13gotDownloadData(data) {
2376
- if (downloadFile.xstate == 0) { // If state is 0, this is a command confirming if the file will be transfered.
2377
- var cmd = JSON.parse(data);
2378
- if (cmd.action == 'downloadstart') { // Yes, the file is about to start
2379
- downloadFile.xstate = 1; // Switch to state 1, we will start receiving the file data
2380
- downloadFile.xdata = ''; // Start with empty data
2381
- downloadFile.send('a'); // Send the first ACK
2382
- } else if (cmd.action == 'downloaderror') { // Problem opening this file, cancel
2383
- p13downloadFileCancel();
2384
- }
2385
- } else { // We are in the process of receiving the file
2386
- downloadFile.xtsize += (data.length); // Add to the total bytes received
2387
- downloadFile.xdata += data; // Append the data
2388
- Q('d2progressBar').value = downloadFile.xtsize; // Change the progress bar
2389
- downloadFile.send('a'); // Send the ACK
2390
- }
2391
- }
2392
- */
2235
2236
//
2237
// FILES UPLOAD
@@ -2400,7 +2242,7 @@
2242
if (xxdialogMode) return;
2243
2244
// Check if we are going to overwrite any files
2403
- var winAgent = ((currentNode.agent.id > 0) && (currentNode.agent.id < 5)) || (currentNode.agent.id == 14) || (currentNode.agent.id == 34);
2245
+ var winAgent = true; //((currentNode.agent.id > 0) && (currentNode.agent.id < 5)) || (currentNode.agent.id == 14) || (currentNode.agent.id == 34);
2246
var targetFiles = [], overWriteCount = 0;
2247
for (var i in p13filetree.dir) { if (winAgent) { targetFiles.push(p13filetree.dir[i].n.toLowerCase()); } else { targetFiles.push(p13filetree.dir[i].n); } }
2248
for (var i = 0; i < files.length; i++) {
@@ -2602,7 +2444,7 @@
2444
//
2445
2446
function getNodeAmtVersion(node) { if ((node == null) || (node.intelamt == null) || (typeof node.intelamt.ver != 'string')) return 0; var verSplit = node.intelamt.ver.split('.'); if (verSplit.length < 2) return 0; return parseInt(verSplit[0]) + (parseInt(verSplit[1]) / 100); }
2605
- function putstore(name, val) { try { if ((typeof (localStorage) === 'undefined') || (localStorage.getItem(name) == val)) return; if (val == null) { localStorage.removeItem(name); } else { localStorage.setItem(name, val); } } catch (e) { } if (name[0] != '_') { var s = {}; for (var i = 0, len = localStorage.length; i < len; ++i) { var k = localStorage.key(i); if (k[0] != '_') { s[k] = localStorage.getItem(k); } } meshserver.send({ action: 'userWebState', state: JSON.stringify(s) }); } }
2447
+ function putstore(name, val) { try { if ((typeof (localStorage) === 'undefined') || (localStorage.getItem(name) == val)) return; if (val == null) { localStorage.removeItem(name); } else { localStorage.setItem(name, val); } } catch (e) { } if (name[0] != '_') { var s = {}; for (var i = 0, len = localStorage.length; i < len; ++i) { var k = localStorage.key(i); if (k[0] != '_') { s[k] = localStorage.getItem(k); } } } }
2448
function getstore(name, val) { try { if (typeof (localStorage) === 'undefined') return val; var v = localStorage.getItem(name); if ((v == null) || (v == null)) return val; return v; } catch (e) { return val; } }
2449
function center() { if (xtermfit) xtermfit.fit(); QS('dialog').left = ((((getDocWidth() - 300) / 2)) + 'px'); deskAdjust(); }
2450
function messagebox(t, m) { QH('id_dialogMessage', m); setDialogMode(1, t, 1); }