| 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 rel="manifest" href="{{{domainurl}}}manifest.json"> |
| 11 | <link rel="shortcut icon" href="{{{domainurl}}}favicon.ico" /> |
| 12 | <link rel="icon" type="image/png" sizes="16x16" href="{{{domainurl}}}favicon-16x16.png"> |
| 13 | <link rel="icon" type="image/png" sizes="32x32" href="{{{domainurl}}}favicon-32x32.png"> |
| 14 | <link rel="apple-touch-icon" href="/favicon-303x303.png" /> |
| 15 | <link type="text/css" href="styles/xterm.css" media="screen" rel="stylesheet" title="CSS" /> |
| 16 | {{{customCSSTags}}} |
| 17 | <meta name="apple-mobile-web-app-capable" content="yes"> |
| 18 | <meta name="apple-mobile-web-app-status-bar-style" content="#ffffff"> |
| 19 | <meta name="apple-mobile-web-app-title" content="{{{title}}}"> |
| 20 | <script type="text/javascript" src="scripts/common-0.0.1{{{min}}}.js"></script> |
| 21 | <script type="text/javascript" src="scripts/meshcentral{{{min}}}.js"></script> |
| 22 | <script type="text/javascript" src="scripts/agent-redir-ws-0.1.1{{{min}}}.js"></script> |
| 23 | <script type="text/javascript" src="scripts/agent-desktop-0.0.2{{{min}}}.js"></script> |
| 24 | <script type="text/javascript" src="scripts/amt-0.2.0{{{min}}}.js"></script> |
| 25 | <script type="text/javascript" src="scripts/amt-redir-ws-0.1.0{{{min}}}.js"></script> |
| 26 | <script type="text/javascript" src="scripts/amt-desktop-0.0.2{{{min}}}.js"></script> |
| 27 | <script type="text/javascript" src="scripts/xterm{{{min}}}.js"></script> |
| 28 | <script type="text/javascript" src="scripts/xterm-addon-fit{{{min}}}.js"></script> |
| 29 | <script type="text/javascript" src="scripts/xterm-addon-image{{{min}}}.js"></script> |
| 30 | <script type="text/javascript" src="scripts/zlib{{{min}}}.js"></script> |
| 31 | <script type="text/javascript" src="scripts/zlib-inflate{{{min}}}.js"></script> |
| 32 | <script type="text/javascript" src="scripts/zlib-adler32{{{min}}}.js"></script> |
| 33 | <script type="text/javascript" src="scripts/zlib-crc32{{{min}}}.js"></script> |
| 34 | <script keeplink=1 type="text/javascript" src="scripts/filesaver.min.js"></script> |
| 35 | {{{customJSTags}}} |
| 36 | <meta name="msapplication-TileColor" content="#00aba9"> |
| 37 | <meta name="theme-color" content="#ffffff"> |
| 38 | <title>{{{title}}}</title> |
| 39 | <style> |
| 40 | body { |
| 41 | background-color: white; |
| 42 | } |
| 43 | |
| 44 | .night body { |
| 45 | background-color: black; |
| 46 | } |
| 47 | |
| 48 | #MxMESH { |
| 49 | color: black; |
| 50 | } |
| 51 | |
| 52 | .night #MxMESH { |
| 53 | color: lightgray; |
| 54 | } |
| 55 | |
| 56 | .textOverGray { color: black; } |
| 57 | |
| 58 | #dialog { |
| 59 | z-index:1000; |
| 60 | background-color:#EEE; |
| 61 | box-shadow:0px 0px 15px #666; |
| 62 | font-family:Arial,Helvetica,sans-serif; |
| 63 | border-radius:5px; |
| 64 | position:fixed; |
| 65 | top:90px; |
| 66 | width:300px; |
| 67 | } |
| 68 | |
| 69 | .night #dialog { |
| 70 | color: black; |
| 71 | background-color:#AAA; |
| 72 | } |
| 73 | |
| 74 | :focus { |
| 75 | outline: 0; |
| 76 | } |
| 77 | |
| 78 | a { |
| 79 | color: #036; |
| 80 | text-decoration: underline; |
| 81 | } |
| 82 | |
| 83 | .night a { |
| 84 | color: #99F; |
| 85 | } |
| 86 | |
| 87 | #footer a { |
| 88 | color: #fff; |
| 89 | text-decoration: underline; |
| 90 | } |
| 91 | |
| 92 | #footer a:hover { |
| 93 | text-decoration: none; |
| 94 | } |
| 95 | |
| 96 | .night #footer { |
| 97 | color: gray; |
| 98 | } |
| 99 | |
| 100 | .i1 { |
| 101 | background: url(../images/icons50.png) 0px 0px; |
| 102 | background-image: image-set(url(../images/icons50.png) 1x, url(../images/icons100.png) 2x); |
| 103 | height: 50px; |
| 104 | width: 50px; |
| 105 | border: none; |
| 106 | } |
| 107 | |
| 108 | .i2 { |
| 109 | background: url(../images/icons50.png) -50px 0px; |
| 110 | background-image: image-set(url(../images/icons50.png) 1x, url(../images/icons100.png) 2x); |
| 111 | height: 50px; |
| 112 | width: 50px; |
| 113 | border: none; |
| 114 | } |
| 115 | |
| 116 | .i3 { |
| 117 | background: url(../images/icons50.png) -100px 0px; |
| 118 | background-image: image-set(url(../images/icons50.png) 1x, url(../images/icons100.png) 2x); |
| 119 | height: 50px; |
| 120 | width: 50px; |
| 121 | border: none; |
| 122 | } |
| 123 | |
| 124 | .i4 { |
| 125 | background: url(../images/icons50.png) -150px 0px; |
| 126 | background-image: image-set(url(../images/icons50.png) 1x, url(../images/icons100.png) 2x); |
| 127 | height: 50px; |
| 128 | width: 50px; |
| 129 | border: none; |
| 130 | } |
| 131 | |
| 132 | .i5 { |
| 133 | background: url(../images/icons50.png) -200px 0px; |
| 134 | background-image: image-set(url(../images/icons50.png) 1x, url(../images/icons100.png) 2x); |
| 135 | height: 50px; |
| 136 | width: 50px; |
| 137 | border: none; |
| 138 | } |
| 139 | |
| 140 | .i6 { |
| 141 | background: url(../images/icons50.png) -250px 0px; |
| 142 | background-image: image-set(url(../images/icons50.png) 1x, url(../images/icons100.png) 2x); |
| 143 | height: 50px; |
| 144 | width: 50px; |
| 145 | border: none; |
| 146 | } |
| 147 | |
| 148 | .i7 { |
| 149 | background: url(../images/icons50.png) -300px 0px; |
| 150 | background-image: image-set(url(../images/icons50.png) 1x, url(../images/icons100.png) 2x); |
| 151 | height: 50px; |
| 152 | width: 50px; |
| 153 | border: none; |
| 154 | } |
| 155 | |
| 156 | .i8 { |
| 157 | background: url(../images/icons50.png) -350px 0px; |
| 158 | background-image: image-set(url(../images/icons50.png) 1x, url(../images/icons100.png) 2x); |
| 159 | height: 50px; |
| 160 | width: 50px; |
| 161 | border: none; |
| 162 | } |
| 163 | |
| 164 | .m0 { |
| 165 | background: url(../images/images16.png) -32px 0px; |
| 166 | height: 16px; |
| 167 | width: 16px; |
| 168 | border: none; |
| 169 | float: left; |
| 170 | } |
| 171 | |
| 172 | .m1 { |
| 173 | background: url(../images/images16.png) -16px 0px; |
| 174 | height: 16px; |
| 175 | width: 16px; |
| 176 | border: none; |
| 177 | float: left; |
| 178 | } |
| 179 | |
| 180 | .m2 { |
| 181 | background: url(../images/images16.png) -96px 0px; |
| 182 | height: 16px; |
| 183 | width: 16px; |
| 184 | border: none; |
| 185 | float: left; |
| 186 | } |
| 187 | |
| 188 | .m3 { |
| 189 | background: url(../images/images16.png) -112px 0px; |
| 190 | height: 16px; |
| 191 | width: 16px; |
| 192 | border: none; |
| 193 | float: left; |
| 194 | } |
| 195 | |
| 196 | .m4 { |
| 197 | background: url(../images/images16.png) -128px 0px; |
| 198 | height: 16px; |
| 199 | width: 16px; |
| 200 | border: none; |
| 201 | float: left; |
| 202 | } |
| 203 | |
| 204 | .gray { |
| 205 | /*filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale");*/ /* Firefox 10+, Firefox on Android */ |
| 206 | filter: gray; /* IE6-9 */ |
| 207 | -webkit-filter: grayscale(100%) opacity(60%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */ |
| 208 | } |
| 209 | |
| 210 | .DevSt { |
| 211 | padding-left: 5px; |
| 212 | border-bottom-style: solid; |
| 213 | border-bottom-width: 1px; |
| 214 | border-bottom-color: #DDDDDD; |
| 215 | } |
| 216 | |
| 217 | .noselect { |
| 218 | -webkit-touch-callout: none; |
| 219 | -webkit-user-select: none; |
| 220 | -khtml-user-select: none; |
| 221 | -moz-user-select: none; |
| 222 | -ms-user-select: none; |
| 223 | user-select: none; |
| 224 | } |
| 225 | |
| 226 | .fileIcon1 { |
| 227 | background: url(data:image/gif;base64,R0lGODlhEAAQAJEDAPb49Y2Sj9LT2f///yH5BAEAAAMALAAAAAAQABAAAAImnI+py+1vhJwyUYAzHTL4D3qdlJWaIFJqmKod607sDKIiDUP63hQAOw==); |
| 228 | height: 16px; |
| 229 | width: 16px; |
| 230 | cursor: pointer; |
| 231 | border: none; |
| 232 | float: left; |
| 233 | margin-top: 1px; |
| 234 | } |
| 235 | |
| 236 | .fileIcon2 { |
| 237 | background: url(data:image/gif;base64,R0lGODlhEAAQAJEDAM2xV/Xur+XPgP///yH5BAEAAAMALAAAAAAQABAAAAJD3ISZIGHWUGihznesYDYATFVM+D2hJ4lgN1olxALAtAlmPCJvuMmJd6PJckDYwicrHhTD5o7plJmg0Uc0asNMkphHAQA7); |
| 238 | height: 16px; |
| 239 | width: 16px; |
| 240 | cursor: pointer; |
| 241 | border: none; |
| 242 | float: left; |
| 243 | margin-top: 1px; |
| 244 | } |
| 245 | |
| 246 | .fileIcon3 { |
| 247 | background: url(data:image/gif;base64,R0lGODlhEAAQAJEDAPb19IGBgbq6uv///yH5BAEAAAMALAAAAAAQABAAAAIy3ISpxgcPH2ouQgFEw1YmxnUXKEaaEZZnVWZk66JwzKpvuwZzwOgwb/C1gIOA8Yg8DgoAOw==); |
| 248 | height: 16px; |
| 249 | width: 16px; |
| 250 | cursor: pointer; |
| 251 | border: none; |
| 252 | float: left; |
| 253 | margin-top: 1px; |
| 254 | } |
| 255 | |
| 256 | .fileIcon4 { |
| 257 | background: url(../images/meshicon16.png); |
| 258 | height: 16px; |
| 259 | width: 16px; |
| 260 | cursor: pointer; |
| 261 | border: none; |
| 262 | float: left; |
| 263 | margin-top: 1px; |
| 264 | } |
| 265 | |
| 266 | .filelist { |
| 267 | -moz-user-select: none; |
| 268 | -khtml-user-select: none; |
| 269 | -webkit-user-select: none; |
| 270 | -o-user-select: none; |
| 271 | cursor: default; |
| 272 | -khtml-user-drag: element; |
| 273 | clear: both; |
| 274 | } |
| 275 | |
| 276 | .style10 { |
| 277 | background-color: #C9C9C9; |
| 278 | color: #000; |
| 279 | } |
| 280 | |
| 281 | .night .style10 { |
| 282 | background-color: #888; |
| 283 | } |
| 284 | |
| 285 | .meshList { |
| 286 | width:auto; |
| 287 | height:40px; |
| 288 | background-color:lightgray; |
| 289 | margin-top:5px; |
| 290 | margin-bottom:5px; |
| 291 | margin-left:60px; |
| 292 | padding-top:5px; |
| 293 | padding-bottom:5px; |
| 294 | border-radius:8px 0px 0px 8px; |
| 295 | } |
| 296 | |
| 297 | .night .meshList { |
| 298 | background-color: gray; |
| 299 | } |
| 300 | |
| 301 | .night .devList3 { |
| 302 | background-color: gray; |
| 303 | } |
| 304 | |
| 305 | .devList4 { |
| 306 | padding-left: 12px; |
| 307 | padding-top: 2px; |
| 308 | color: black; |
| 309 | } |
| 310 | |
| 311 | .devList5 { |
| 312 | padding-left: 12px; |
| 313 | padding-top: 3px; |
| 314 | color: #444 |
| 315 | } |
| 316 | |
| 317 | .night .devList5 { |
| 318 | color: black; |
| 319 | } |
| 320 | |
| 321 | .deskButton { |
| 322 | box-shadow: 0px 0px 10px #000; |
| 323 | border-radius:20px; |
| 324 | position:absolute; |
| 325 | right:10px; |
| 326 | top:10px; |
| 327 | cursor:pointer; |
| 328 | background-color:#AAA; |
| 329 | z-index:1000; |
| 330 | } |
| 331 | |
| 332 | .menuButton{ |
| 333 | box-shadow: 0px 0px 10px #000; |
| 334 | border-radius:10px; |
| 335 | display:inline-block; |
| 336 | width:120px; |
| 337 | background-color:#AAA; |
| 338 | text-align:center; |
| 339 | padding:8px; |
| 340 | cursor:pointer; |
| 341 | margin:10px; |
| 342 | z-index:1000; |
| 343 | } |
| 344 | |
| 345 | #p15statetext { |
| 346 | padding: 4px; |
| 347 | height: 15px; |
| 348 | } |
| 349 | |
| 350 | #p15agentConsole { |
| 351 | background: black; |
| 352 | margin: 0; |
| 353 | padding: 0; |
| 354 | color: lightgray; |
| 355 | width: 100%; |
| 356 | position: relative; |
| 357 | } |
| 358 | |
| 359 | #p15coreName { |
| 360 | padding: 4px; |
| 361 | display: inline-block; |
| 362 | } |
| 363 | |
| 364 | #p15agentConsoleText { |
| 365 | position:absolute; |
| 366 | margin: 0; |
| 367 | padding: 0; |
| 368 | top: 0; |
| 369 | bottom: 0; |
| 370 | left:0; |
| 371 | right: 0; |
| 372 | overflow-y: scroll; |
| 373 | overflow-x: auto; |
| 374 | } |
| 375 | |
| 376 | .areaHead { |
| 377 | padding-top: 2px; |
| 378 | padding-bottom: 2px; |
| 379 | background: #C0C0C0; |
| 380 | } |
| 381 | |
| 382 | .night .areaHead { |
| 383 | color: #CCC; |
| 384 | background: #333; |
| 385 | } |
| 386 | |
| 387 | .areaFoot { |
| 388 | padding-top: 2px; |
| 389 | padding-bottom: 2px; |
| 390 | background: #C0C0C0; |
| 391 | } |
| 392 | |
| 393 | .night .areaFoot { |
| 394 | color: #CCC; |
| 395 | background: #333; |
| 396 | } |
| 397 | |
| 398 | .toright2 { |
| 399 | float: right; |
| 400 | text-align: right; |
| 401 | } |
| 402 | |
| 403 | #consoleTable { |
| 404 | width: 100%; |
| 405 | height: 100%; |
| 406 | padding: 0px; |
| 407 | margin-top: 0px; |
| 408 | } |
| 409 | |
| 410 | .night #consoleTable { |
| 411 | color: black; |
| 412 | } |
| 413 | |
| 414 | #termTable { |
| 415 | width: 100%; |
| 416 | padding: 0px; |
| 417 | margin-top: 0px; |
| 418 | } |
| 419 | |
| 420 | .fulldesk #termTable { |
| 421 | position: absolute; |
| 422 | top: 0; |
| 423 | bottom: 0; |
| 424 | left: 0; |
| 425 | right: 0; |
| 426 | } |
| 427 | |
| 428 | #termarea3x { |
| 429 | background: black; |
| 430 | text-align: center; |
| 431 | height: 400px; |
| 432 | position: relative; |
| 433 | } |
| 434 | </style> |
| 435 | </head> |
| 436 | <body id="body" onload="if (typeof(startup) !== 'undefined') startup();" style="overflow-y:hidden;margin:0;padding:0;border:0;font-size:13px;font-family:\'Trebuchet MS\', Arial, Helvetica, sans-serif"> |
| 437 | <div id=container> |
| 438 | <div id="notifiyBox" class="notifiyBox" style="display:none"></div> |
| 439 | <div id=mastheadx></div> |
| 440 | <div id=masthead style="background:url(logo.png) 0px 0px;background-size:341px 50px;background-color:#036;background-repeat:no-repeat;height:50px;width:100%;overflow:hidden"> |
| 441 | <div style="width:calc(100% - 50px);overflow:hidden"> |
| 442 | <div style="float:left;height:66px;color:#c8c8c8;padding-left:10px;padding-top:6px"> |
| 443 | <strong><font style="font-size:36px;font-family:Arial,Helvetica,sans-serif">{{{title1}}}</font></strong> |
| 444 | </div> |
| 445 | <div style="float:left;height:66px;color:#c8c8c8;padding-left:5px;padding-top:10px"> |
| 446 | <strong><font style="font-size:12px;font-family:Arial,Helvetica,sans-serif">{{{title2}}}</font></strong> |
| 447 | </div> |
| 448 | </div> |
| 449 | </div> |
| 450 | <div id=page_content style="position:absolute;bottom:32px;top:50px;width:100%"> |
| 451 | <div id=column_l style="width:100%;padding:0;position:absolute;bottom:0px;top:0px"> |
| 452 | <div id=p0 style=display:none;width:100%;height:100%> |
| 453 | <div style="display:flex;align-items:center;width:100%;height:100%"> |
| 454 | <div id=p0message style=text-align:center;width:100%><span id="p0span">Server disconnected</span>, <href onclick=reload() style=cursor:pointer><u>click to reconnect</u></href>.</div> |
| 455 | </div> |
| 456 | </div> |
| 457 | <div id=p1 style=display:none;width:100%;height:100%> |
| 458 | <div style="display:flex;align-items:center;width:100%;height:100%"> |
| 459 | <div id=p1message style=text-align:center;width:100%></div> |
| 460 | </div> |
| 461 | </div> |
| 462 | <div id=p10 style=display:none;position:absolute;bottom:0;top:0;width:100%;overflow:hidden> |
| 463 | <table id=p10deskTopTable cellspacing=0 style="margin:0;padding:0;border-spacing:0;border:0;position:absolute;top:0"> |
| 464 | <tr style=padding:0> |
| 465 | <td> |
| 466 | <div style="margin-left:10px;margin-top:14px;font-size:20px"> |
| 467 | <strong><span id=p10deviceName></span></strong> |
| 468 | </div> |
| 469 | </td> |
| 470 | </tr> |
| 471 | </table> |
| 472 | <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"> |
| 473 | <div style="width:100%;background-color:#003366;color:#FFF;border-radius:5px 5px 0 0"> |
| 474 | <div style=padding:5px>Keyboard Shortcuts Customization</div> |
| 475 | <div style=width:100%;margin:6px></div> |
| 476 | </div> |
| 477 | <div style="margin-right:16px;margin-left:8px"><div id=p10dialog2 style="margin:auto;margin:3px"></div></div> |
| 478 | <div style="padding:10px;margin-bottom:20px"><input type="button" value="OK" style="float:right;width:80px" onclick="deskCustomizeKeysEx()"></div> |
| 479 | </div> |
| 480 | <img id="deskkeybutton1" src="images/mobile-desk-exit.png" class="deskButton" style="top:10px;display:none" onclick="exitButton()" /> |
| 481 | <img id="deskkeybutton3a" src="images/mobile-desk-menu-open.png" class="deskButton" style="top:60px;display:none" onclick="toggleMenu(false)" /> |
| 482 | <img id="deskkeybutton3b" src="images/mobile-desk-menu-close.png" class="deskButton" style="top:60px;display:none" onclick="toggleMenu(true)" /> |
| 483 | <img id="deskkeybutton4a" src="images/mobile-desk-mouse-left.png" class="deskButton" style="top:110px;display:none" onclick="deskChangeMouseButton(0)" /> |
| 484 | <img id="deskkeybutton4b" src="images/mobile-desk-mouse-right.png" class="deskButton" style="top:110px;display:none" onclick="deskChangeMouseButton(1)" /> |
| 485 | <img id="deskkeybutton5a" src="images/mobile-desk-scale-out.png" class="deskButton" style="top:160px;display:none" onclick="deskChangeFullscreenZoom()" /> |
| 486 | <img id="deskkeybutton5b" src="images/mobile-desk-scale-in.png" class="deskButton" style="top:160px;display:none" onclick="deskChangeFullscreenZoom()" /> |
| 487 | <img id="deskkeybutton2a" src="images/mobile-desk-keyboard-open.png" class="deskButton" style="top:210px;display:none" onclick="toggleKeyboard()" /> |
| 488 | <img id="deskkeybutton2b" src="images/mobile-desk-keyboard-close.png" class="deskButton" style="top:210px;display:none" onclick="toggleKeyboard()" /> |
| 489 | <div style="position:absolute;top:0;left:0;z-index:200;opacity:0;width:1px;height:1px"> |
| 490 | <input id="softKeyboard" autocapitalize="off" autocomplete="off" type="text" inputmode="text" spellcheck="false" style="z-index:200;opacity:0;width:1px;height:1px" onfocus="keyboardFocusChange()" onblur="keyboardFocusChange()" /> |
| 491 | </div> |
| 492 | <div id="deskButtonMenu" style="display:none;position:absolute;top:10px;left:10px;right:55px;bottom:10px;z-index:1000"></div> |
| 493 | <div id=p10desktop style="overflow:hidden;position:absolute;top:55px;bottom:0px;width:100%;display:none"> |
| 494 | <div id=deskarea1 style="position:absolute;top:0px;width:100%;height:32px"> |
| 495 | <div style="padding-top:2px;padding-bottom:2px;background:#C0C0C0;height:32px"> |
| 496 | <div style="float:right;text-align:right"> |
| 497 | <span id="p14power"></span> |
| 498 | <input type=button id=deskFullScreen value="Full Screen" onclick=deskToggleFull(event) onkeypress="return false" onkeydown="return false" disabled="disabled" style="height:28px;margin-right:3px;"> |
| 499 | </div> |
| 500 | <div style="margin-left:3px"> |
| 501 | <input type=button id=connectbutton1 value="Connect" onclick=connectDesktop(event,3) onkeypress="return false" onkeydown="return false" disabled="disabled" style="height:28px"> |
| 502 | <input type=button id=connectbutton1h value="HW Connect" onclick=connectDesktop(event,2) onkeypress="return false" onkeydown="return false" disabled="disabled" style="height:28px"> |
| 503 | <input type=button id=disconnectbutton1 value="Disconnect" onclick=connectDesktop(event,0) onkeypress="return false" onkeydown="return false" style="height:28px"> |
| 504 | <span id="deskstatus" style="color:black">Disconnected</span> |
| 505 | </div> |
| 506 | </div> |
| 507 | </div> |
| 508 | <div id=deskarea3 style="position:absolute;top:32px;width:100%;height:calc(100% - 64px);background-color:#000;text-align:center"> |
| 509 | <div id=DeskParent style="height:100%"> |
| 510 | <canvas id=Desk width=640 height=200 style="width:100%;-ms-touch-action:none;margin-left:0px" oncontextmenu="return false" onmousedown=dmousedown(event) onmouseup=dmouseup(event) onmousemove=dmousemove(event) onmousewheel=dmousewheel(event)></canvas> |
| 511 | </div> |
| 512 | <div id=p11DeskConsoleMsg style="display:none;cursor:pointer;position:absolute;left:30px;top:17px;color:yellow;background-color:rgba(0,0,0,0.6);padding:10px;border-radius:5px;text-align:left" onclick=p11clearConsoleMsg()></div> |
| 513 | <div id=p11DeskSessionSelector style="display:none;position:absolute;left:30px;top:17px;right:30px;bottom:17px;overflow-y:auto"></div> |
| 514 | </div> |
| 515 | <div id=deskarea4 style="position:absolute;bottom:0px;width:100%;height:32px"> |
| 516 | <div style=padding-top:2px;padding-bottom:2px;background:#C0C0C0> |
| 517 | <div style=float:right;text-align:right> |
| 518 | <!--<input id=DeskToolsButton type=button value=Tools onkeypress="return false" onkeydown="return false" onclick="toggleDeskTools()"> --> |
| 519 | </div> |
| 520 | <div> |
| 521 | <input type="button" value="Settings" onkeypress="return false" onkeydown="return false" onclick="showDesktopSettings()" style="height:28px"> |
| 522 | <input type="button" id="DeskScreens" value="Screens" onkeypress="return false" onkeydown="return false" onclick="deskSelectScreens()" style="display:none;height:28px"> |
| 523 | <label><span id="DeskControlSpan" style="display:none"><input id="DeskControl" type="checkbox" onkeypress="return false" onkeydown="return false">Input</span></label> |
| 524 | </div> |
| 525 | </div> |
| 526 | </div> |
| 527 | </div> |
| 528 | <div id="termButtonMenu" style="display:none;position:absolute;top:10px;left:10px;right:55px;bottom:10px;z-index:1000"></div> |
| 529 | <div id=p10terminal style="overflow:hidden;position:absolute;top:55px;bottom:0px;width:100%;display:none;background-color:#333"> |
| 530 | <div id=termTable style="position:absolute;top:0;bottom:0;left:0;right:0"> |
| 531 | <div id="termarea1"> |
| 532 | <div class="areaHead" style="line-height:24px"> |
| 533 | <div class="toright2"> |
| 534 | <input type=button id=termFullScreen value="Full Screen" onclick=deskToggleFull(event) onkeypress="return false" onkeydown="return false" disabled="disabled" style="height:28px;margin-right:3px;"> |
| 535 | <div id="terminalCustomUpperRight" style="float:left;margin-right:6px"></div> |
| 536 | </div> |
| 537 | <div> |
| 538 | <span id="connectbutton2span" style="margin-left:3px"><input type="button" id="connectbutton2" cmenu="termConnectButton" value="Connect" style="height:28px" onclick=connectTerminal(event,1) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span> |
| 539 | <span id="disconnectbutton2span" style="margin-left:3px"><input type="button" id="disconnectbutton2" value="Disconnect" style="height:28px" onclick=connectTerminal(event,0) onkeypress="return false" onkeydown="return false" /></span> |
| 540 | <span id="termstatus" style="line-height:22px">Disconnected</span><span id="termtitle"></span> |
| 541 | </div> |
| 542 | </div> |
| 543 | </div> |
| 544 | <div id="termarea3" style="width:100%;height: calc(100% - 60px);" cellpadding=0 cellspacing=0> |
| 545 | <div id="termarea3x" style="width:100%;height:100%"> |
| 546 | <div style="width:100%;height:100%" id="termarea3xdiv"></div> |
| 547 | </div> |
| 548 | </div> |
| 549 | <div id="termarea4" style="position:relative;height:32px;"> |
| 550 | <div class="areaFoot"> |
| 551 | <div class="toright2"></div> |
| 552 | <div style="height:28px"> |
| 553 | </div> |
| 554 | </div> |
| 555 | </div> |
| 556 | <div id=p12TermConsoleMsg style="display:none;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> |
| 557 | </div> |
| 558 | </div> |
| 559 | <div id=p10files style="position:absolute;top:55px;bottom:0px;width:100%;display:none"> |
| 560 | <table id="p13toolbar" style="width:100%;height:111px" cellpadding="0" cellspacing="0"> |
| 561 | <tr> |
| 562 | <td style="background-color:#C0C0C0;border-bottom:2px solid black;padding:2px;line-height:24px"> |
| 563 | <div style="float:right;text-align:right"> |
| 564 | <div id="filesCustomUpperRight" style="float:left;margin-right:6px"></div> |
| 565 | </div> |
| 566 | <div style="margin-left:2px"> |
| 567 | <input id=p13AutoConnect value="AutoConnect" onclick=autoConnectFiles(event) onkeypress="return false" onkeydown="return false" type="button" style="display:none"> |
| 568 | <input id=p13Connect value="Connect" onclick=connectFiles(event) onkeypress="return false" onkeydown="return false" type="button"> |
| 569 | <span class=textOverGray id=p13Status>Disconnected</span> |
| 570 | </div> |
| 571 | </td> |
| 572 | </tr> |
| 573 | <tr> |
| 574 | <td style="width:100%;background-color:#d3d9d6;text-align:left;padding:4px" valign=bottom> |
| 575 | <div style="width:100%;text-align:center"> |
| 576 | <input type=button style="width:calc(100%/5 - 5px)" id=p13FolderUp disabled="disabled" onclick="p13folderup()" value="Up" /> |
| 577 | <input type=button style="width:calc(100%/5 - 5px)" id=p13SelectAllButton disabled="disabled" onclick="p13selectallfile()" value="SelectAll" onkeypress="return false" onkeydown="return false" /> |
| 578 | <input type=button style="width:calc(100%/5 - 5px)" id=p13RenameFileButton disabled="disabled" value="Rename" onclick="p13renamefile()" onkeypress="return false" onkeydown="return false" /> |
| 579 | <input type=button style="width:calc(100%/5 - 5px)" id=p13DeleteFileButton disabled="disabled" value="Delete" onclick="p13deletefile()" onkeypress="return false" onkeydown="return false" /> |
| 580 | <input type=button style="width:calc(100%/5 - 5px)" id=p13NewFolderButton disabled="disabled" value="Folder" onclick="p13createfolder()" onkeypress="return false" onkeydown="return false" /> |
| 581 | </div> |
| 582 | <div style="width:100%;text-align:center"> |
| 583 | <input type=button style="width:calc(100%/5 - 5px)" id=p13UploadButton disabled="disabled" value="Upload" onclick="p13uploadFile()" onkeypress="return false" onkeydown="return false" /> |
| 584 | <input type=button style="width:calc(100%/5 - 5px)" id=p13CutButton disabled="disabled" value="Cut" onclick="p13copyFile(1)" onkeypress="return false" onkeydown="return false" /> |
| 585 | <input type=button style="width:calc(100%/5 - 5px)" id=p13CopyButton disabled="disabled" value="Copy" onclick="p13copyFile(0)" onkeypress="return false" onkeydown="return false" /> |
| 586 | <input type=button style="width:calc(100%/5 - 5px)" id=p13PasteButton disabled="disabled" value="Paste" onclick="p13pasteFile()" onkeypress="return false" onkeydown="return false" /> |
| 587 | <input type=button style="width:calc(100%/5 - 5px)" id=p13RefreshButton disabled="disabled" value="Refresh" onclick="p13folderup(9999)" onkeypress="return false" onkeydown="return false" /> |
| 588 | </div> |
| 589 | </td> |
| 590 | </tr> |
| 591 | <tr> |
| 592 | <td style="background-color:#E4E9E7;height:28px"> |
| 593 | <table style="width:100%"> |
| 594 | <tr> |
| 595 | <td id=p13currentpath style="overflow:hidden;padding-left:4px;padding-top:2px;color:black"></td> |
| 596 | <td style="text-align:right;padding-right:4px"> |
| 597 | <select id=p13sortdropdown onchange=p13updateFiles()> |
| 598 | <option value=1 selected="selected">Sort by name</option> |
| 599 | <option value=2>Sort by size</option> |
| 600 | <option value=3>Sort by date</option> |
| 601 | <option value=4>Descend by name</option> |
| 602 | <option value=5>Descend by size</option> |
| 603 | <option value=6>Descend by date</option> |
| 604 | </select> |
| 605 | </td> |
| 606 | </tr> |
| 607 | </table> |
| 608 | </td> |
| 609 | </tr> |
| 610 | </table> |
| 611 | <div id=p13FilesConsoleMsg style="display:none;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> |
| 612 | <div id="p13filetable" style="width:100%;height:calc(100% - 133px);overflow:auto;-webkit-user-select:none"> |
| 613 | <!-- |
| 614 | <div id="p13bigok" style="width:256px;overflow:hidden;position:absolute;left:337px;top:200px;text-align:center;font-size:1600%;color:#AAAAAA;display:none"><b>✓</b></div> |
| 615 | <div id="p13bigfail" style="width:256px;overflow:hidden;position:absolute;left:337px;top:200px;text-align:center;font-size:1600%;color:#AAAAAA;display:none"><b>✗</b></div> |
| 616 | --> |
| 617 | <span id="p13files"></span> |
| 618 | </div> |
| 619 | <table id="p13toolbarBottom" style="width:100%;height:22px;position:absolute;bottom:0px" cellpadding=0 cellspacing=0> |
| 620 | <tr><td style="text-align:left;padding:3px;text-align:center;background-color:#D3D9D6;color:black"> <span id="p13bottomstatus"></span></td></tr> |
| 621 | </table> |
| 622 | </div> |
| 623 | </div> |
| 624 | </div> |
| 625 | </div> |
| 626 | <div id=footer style="height:32px;width:100%;text-align:center;background-color:#113962;position:absolute;bottom:0px"> |
| 627 | <table id=footerMenu cellpadding=0 cellspacing=0 style="height:32px;width:100%;color:white;cursor:pointer;table-layout:fixed"></table> |
| 628 | </div> |
| 629 | </div> |
| 630 | <div id=dialog style="display:none"> |
| 631 | <div style="width:100%;background-color:#003366;color:#FFF;border-radius:5px 5px 0 0"> |
| 632 | <div id=id_dialogclose style=float:right;padding:5px;cursor:pointer onclick=setDialogMode()><b>X</b></div> |
| 633 | <div id=id_dialogtitle style=padding:5px></div> |
| 634 | <div style=width:100%;margin:6px></div> |
| 635 | </div> |
| 636 | <div style="margin-right:16px;margin-left:8px"> |
| 637 | <div id=dialog1 style="margin:auto;text-align:center;margin:3px"> |
| 638 | <div id=id_dialogMessage style="padding:10px"></div> |
| 639 | </div> |
| 640 | <div id=dialog2 style="margin:auto;margin:3px"> |
| 641 | <div id=id_dialogOptions></div> |
| 642 | </div> |
| 643 | <div id=dialog3 style="margin:auto;margin:3px"> |
| 644 | <select id="deskkeys" style="width:100%"> |
| 645 | <option value=10>Ctrl+Alt+Del</option> |
| 646 | <option value=11>Tab</option> |
| 647 | <option value=5>Win</option> |
| 648 | <option value=0>Win+Down</option> |
| 649 | <option value=1>Win+Up</option> |
| 650 | <option value=2>Win+L</option> |
| 651 | <option value=3>Win+M</option> |
| 652 | <option value=4>Shift+Win+M</option> |
| 653 | <option value=6>Win+R</option> |
| 654 | <option value=7>Alt-F4</option> |
| 655 | <option value=8>Ctrl-W</option> |
| 656 | <option value=9>Alt-Tab</option> |
| 657 | <option value=12>Shift-F10</option> |
| 658 | </select> |
| 659 | </div> |
| 660 | <div id=dialog7 style="margin:auto;margin:3px"> |
| 661 | <div id="d7meshkvm"> |
| 662 | <h4 style="width:100%;border-bottom:1px solid gray">Agent Remote Desktop</h4> |
| 663 | <table style="width:100%"> |
| 664 | <tr> |
| 665 | <td> |
| 666 | Quality |
| 667 | </td> |
| 668 | <td style="width:100px"> |
| 669 | <select id="d7bitmapquality" style="float:right;width:200px" dir="rtl"></select> |
| 670 | </td> |
| 671 | </tr> |
| 672 | <tr> |
| 673 | <td> |
| 674 | Scaling |
| 675 | </td> |
| 676 | <td style="width:100px"> |
| 677 | <select id="d7bitmapscaling" style="float:right;width:200px" dir="rtl"> |
| 678 | <option selected=selected value=1024>100%</option> |
| 679 | <option value=896>87.5%</option> |
| 680 | <option value=768>75%</option> |
| 681 | <option value=640>62.5%</option> |
| 682 | <option value=512>50%</option> |
| 683 | <option value=384>37.5%</option> |
| 684 | <option value=256>25%</option> |
| 685 | <option value=128>12.5%</option> |
| 686 | </select> |
| 687 | </td> |
| 688 | </tr> |
| 689 | <tr> |
| 690 | <td> |
| 691 | Rate |
| 692 | </td> |
| 693 | <td style="width:100px"> |
| 694 | <select id="d7framelimiter" style="float:right;width:200px" dir="rtl"> |
| 695 | <option selected=selected value=50>Fast</option> |
| 696 | <option value=100>Medium</option> |
| 697 | <option value=400>Slow</option> |
| 698 | <option value=1000>Very slow</option> |
| 699 | </select> |
| 700 | </td> |
| 701 | </tr> |
| 702 | <tr> |
| 703 | <td></td> |
| 704 | <td> |
| 705 | <label style="display:block" id="d7deskAutoLockLabel"><input type="checkbox" id="d7deskAutoLock" />Lock on Disconnect</label> |
| 706 | </td> |
| 707 | </tr> |
| 708 | </table> |
| 709 | </div> |
| 710 | <div id="d7amtkvm"> |
| 711 | <h4 style="width:100%;border-bottom:1px solid gray">Intel® AMT Hardware KVM</h4> |
| 712 | <table style="width:100%"> |
| 713 | <tr> |
| 714 | <td>Encoding</td> |
| 715 | <td style="width:100px"> |
| 716 | <select id="d7desktopmode" style="float:right;width:200px"> |
| 717 | <option value="1">RLE8, Fastest</option> |
| 718 | <option value="2">RLE16, Recommended</option> |
| 719 | <option value="3">RAW8, Slow</option> |
| 720 | <option value="4">RAW16, Very Slow</option> |
| 721 | </select> |
| 722 | </td> |
| 723 | </tr> |
| 724 | </table> |
| 725 | </div> |
| 726 | </div> |
| 727 | </div> |
| 728 | <div id="idx_dlgButtonBar" style="padding:10px;margin-bottom:20px"> |
| 729 | <input id="idx_dlgCancelButton" type="button" value="Cancel" style="float:right;width:80px;margin-left:5px" onclick="dialogclose(0)"> |
| 730 | <input id="idx_dlgOkButton" type="button" value="OK" style="float:right;width:80px" onclick="dialogclose(1)"> |
| 731 | <div><input id="idx_dlgDeleteButton" type="button" value="Delete" style="display:none" onclick="dialogclose(2)" /></div> |
| 732 | </div> |
| 733 | </div> |
| 734 | <div id=topMenu style="z-index:1000;background-color:#EEE;box-shadow:0px 0px 15px #666;font-family:Arial,Helvetica,sans-serif;border-radius:0px 0px 5px 5px;position:fixed;top:50px;right:5px;width:170px;display:none"> |
| 735 | <div style="padding:12px;border-top:1px solid gray;color:black;cursor:pointer" onclick=topMenu(2)>My Files</div> |
| 736 | <div style="padding:12px;border-top:1px solid gray;color:black;cursor:pointer" onclick=topMenu(1)>My Account</div> |
| 737 | <div id="logoutMenuOption"><a href=/logout><div style="padding:12px;border-top:1px solid gray;color:black;cursor:pointer">Logout</div></a></div> |
| 738 | </div> |
| 739 | <audio id="chimes"><source src="sounds/chimes.mp3" type="audio/mp3" /></audio> |
| 740 | <iframe name="fileUploadFrame" style=display:none></iframe> |
| 741 | <script> |
| 742 | 'use strict'; |
| 743 | var random = '{{{randomlength}}}' // Random length string for BREACH mitigation |
| 744 | var args = parseUriArgs(); |
| 745 | var urlargs = args; |
| 746 | var sessionTime = parseInt('{{{sessiontime}}}'); |
| 747 | var sessionRefreshTimer = null; |
| 748 | var domain = '{{{domain}}}'; |
| 749 | var domainUrl = '{{{domainurl}}}'; |
| 750 | var authCookie = '{{{authCookie}}}'; |
| 751 | var authRelayCookie = '{{{authRelayCookie}}}'; |
| 752 | var viewOnly = parseInt('{{{viewOnly}}}'); |
| 753 | var authCookieRenewTimer = null; |
| 754 | var serverPublicNamePort = '{{{serverDnsName}}}:{{{serverPublicPort}}}'; |
| 755 | var debugmode = false; |
| 756 | var attemptWebRTC = false; |
| 757 | var StatusStrs = ["Disconnected", "Connecting...", "Setup...", "Connected", "Intel® AMT Connected"]; |
| 758 | var files; |
| 759 | var terminal; |
| 760 | var sessionActivity = Date.now(); |
| 761 | var deskPinchZoom; |
| 762 | var deskKeyboardShortcuts = []; |
| 763 | var xterm = null; |
| 764 | var xtermfit = null; |
| 765 | var xtermimage = null; |
| 766 | var xtermResizeTimer = null; |
| 767 | var features = parseInt('{{{features}}}'); |
| 768 | var features2 = parseInt('{{{features2}}}'); |
| 769 | var features3 = parseInt('{{{features3}}}'); |
| 770 | var nodeName = decodeURIComponent('{{{nodeName}}}'); |
| 771 | |
| 772 | // Console Message Display Timers |
| 773 | var p11DeskConsoleMsgTimer = null; |
| 774 | var p12TermConsoleMsgTimer = null; |
| 775 | var p13FilesConsoleMsgTimer = null; |
| 776 | |
| 777 | // Check if WebP is supported |
| 778 | var webpSupport = false; |
| 779 | check_webp_feature('lossy', function (f, x) { webpSupport = x; }); |
| 780 | |
| 781 | function startup() { |
| 782 | QH('p10deviceName', nodeName); |
| 783 | if ((features & 32) == 0) { |
| 784 | // Guard against other site's top frames (web bugs). |
| 785 | var loc = null; |
| 786 | try { loc = top.location.toString().toLowerCase(); } catch (e) { } |
| 787 | if (top != self && (loc == null || top.active == false)) { top.location = self.location; return; } |
| 788 | } |
| 789 | if (!args.locale) { var x = getstore('loctag', 0); if ((x != null) && (x != '*')) { args.locale = x; } } |
| 790 | |
| 791 | window.onresize = center; |
| 792 | center(); |
| 793 | go(10); |
| 794 | |
| 795 | // Set the document title |
| 796 | if (nodeName.length > 0) { document.title += ' - ' + nodeName; } |
| 797 | |
| 798 | // Document keys |
| 799 | document.onkeypress = ondeskkeypress; |
| 800 | document.onkeydown = ondeskkeydown; |
| 801 | document.onkeyup = ondeskkeyup; |
| 802 | document.onclick = function (e) { if ((xxdialogMode == 999) && (e.target.id != 'topMenuIcon')) { QV('topMenu', false); xxdialogMode = 0; } } |
| 803 | |
| 804 | // Load desktop settings |
| 805 | var t = localStorage.getItem('desktopsettings'); |
| 806 | if (t != null) { desktopsettings = JSON.parse(t); } |
| 807 | applyDesktopSettings(); |
| 808 | |
| 809 | attemptWebRTC = false; // For now, default WebRTC off unless we set it in the URL. |
| 810 | if (args.webrtc != null) { attemptWebRTC = (args.webrtc == 1); } |
| 811 | |
| 812 | // Set the user's desktop shortcut keys |
| 813 | deskKeyboardShortcuts = []; |
| 814 | var deskKeyboardShortcutsStr = getstore('deskKeyShortcuts', '0x0A002E,0x100000,0x100028,0x100026,0x10004C,0x10004D,0x11004D,0x100052,0x020073,0x080057,0x020009,0x100025,0x100027').split(','); |
| 815 | for (var i in deskKeyboardShortcutsStr) { deskKeyboardShortcuts.push(parseInt(deskKeyboardShortcutsStr[i])); } |
| 816 | updateDeskShortcutKeys(); |
| 817 | updateTermShortcutKeys(); |
| 818 | updateDesktopButtons(); |
| 819 | updateTerminalButtons(); |
| 820 | |
| 821 | if (features & 2) { currentDevicePanel = 1; } // Goto desktop |
| 822 | else if (features & 1) { currentDevicePanel = 5; } // Goto terminal |
| 823 | else if (features & 4) { currentDevicePanel = 2; } // Goto files |
| 824 | setupDeviceMenu(currentDevicePanel); |
| 825 | } |
| 826 | |
| 827 | function setSessionActivity() { sessionActivity = Date.now(); } |
| 828 | function checkIdleSessionTimeout() { |
| 829 | var delta = (Date.now() - sessionActivity); |
| 830 | if (delta > serverinfo.timeout) { |
| 831 | if (desktop != null) { // Disconnect remote desktop |
| 832 | desktop.Stop(); |
| 833 | desktopNode = desktop = null; |
| 834 | } |
| 835 | if (terminal != null) { // Disconnect terminal |
| 836 | terminal.Stop(); |
| 837 | terminal = null; |
| 838 | } |
| 839 | if (files != null) { // Disconnect files |
| 840 | files.Stop(); |
| 841 | files = null; |
| 842 | } |
| 843 | if (serverinfo.logoutonidlesessiontimeout) { |
| 844 | window.location.href = 'logout'; |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | // |
| 850 | // Menu System |
| 851 | // |
| 852 | |
| 853 | function updateFooterMenu(options) { |
| 854 | while (options != null && options.length < 3) { options.push({ n: '' }); } |
| 855 | var x = '', prev = ''; |
| 856 | 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; } } |
| 857 | QH('footerMenu', '<tr>' + x); |
| 858 | } |
| 859 | |
| 860 | |
| 861 | // |
| 862 | // MY DEVICES |
| 863 | // |
| 864 | |
| 865 | var gotKeyPressEvent = false; |
| 866 | function ondeskkeypress(e, t) { |
| 867 | setSessionActivity(); |
| 868 | if (desktop && !xxdialogMode && (xxcurrentView == 10) && (currentDevicePanel == 1)) { |
| 869 | gotKeyPressEvent = true; |
| 870 | Q('softKeyboard').value = ''; |
| 871 | // Check what keys we are allows to send |
| 872 | if (viewOnly == 1) return false; |
| 873 | return desktop.m.handleKeys(e); |
| 874 | } |
| 875 | if (terminal && !xxdialogMode && (xxcurrentView == 10) && (currentDevicePanel == 5) && (t !== 1)) { |
| 876 | if (e.altKey == true) { return true; } |
| 877 | gotKeyPressEvent = true; |
| 878 | Q('softKeyboard').value = ''; |
| 879 | var k = 0; |
| 880 | if (e.charCode != 0) { k = e.charCode; } else if (e.keyCode != 0) { k = e.keyCode; } |
| 881 | if (k != 0) { |
| 882 | if (terminal.urlname == 'sshterminalrelay.ashx') { |
| 883 | // SSH |
| 884 | terminal.socket.send('~' + String.fromCharCode(k)); |
| 885 | } else { |
| 886 | // Agent |
| 887 | terminal.sendText(String.fromCharCode(k)); |
| 888 | } |
| 889 | } |
| 890 | return false; |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | function ondeskkeydown(e, t) { |
| 895 | setSessionActivity(); |
| 896 | if (desktop && !xxdialogMode && (xxcurrentView == 10) && (currentDevicePanel == 1)) { |
| 897 | gotKeyPressEvent = false; |
| 898 | Q('softKeyboard').value = ''; |
| 899 | // Check what keys we are allows to send |
| 900 | if (viewOnly == 1) return false; |
| 901 | return desktop.m.handleKeyDown(e); |
| 902 | } |
| 903 | if (terminal && !xxdialogMode && (xxcurrentView == 10) && (currentDevicePanel == 5) && (t !== 1)) { |
| 904 | if (e.altKey == true) { return true; } |
| 905 | Q('softKeyboard').value = ''; |
| 906 | gotKeyPressEvent = false; |
| 907 | var k = 0; |
| 908 | if (e.charCode != 0) { k = e.charCode; } else if (e.keyCode != 0) { k = e.keyCode; } |
| 909 | if (k == 8) { terminal.sendText(String.fromCharCode(k)); } // Enter and backspace |
| 910 | else if (e.ctrlKey && (k >= 64) && (k <= 95)) { |
| 911 | // Ctrl keys |
| 912 | if (terminal.urlname == 'sshterminalrelay.ashx') { |
| 913 | // SSH |
| 914 | terminal.socket.send('~' + String.fromCharCode(k - 64)); |
| 915 | } else { |
| 916 | // Agent |
| 917 | terminal.sendText(String.fromCharCode(k - 64)); |
| 918 | } |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | function ondeskkeyup(e, t) { |
| 924 | setSessionActivity(); |
| 925 | if (desktop && !xxdialogMode && (xxcurrentView == 10) && (currentDevicePanel == 1)) { |
| 926 | var inputStr = Q('softKeyboard').value; |
| 927 | Q('softKeyboard').value = ''; |
| 928 | // Check what keys we are allows to send |
| 929 | if (viewOnly == 1) return; |
| 930 | if ((gotKeyPressEvent == false) && (inputStr.length > 0) && desktop.m.SendKeyUnicode) { |
| 931 | // This is a mobile keyboard, we need to send that is in the input control. |
| 932 | var inputchar = inputStr[inputStr.length - 1].charCodeAt(0); |
| 933 | desktop.m.SendKeyUnicode(desktop.m.KeyAction.DOWN, inputchar); |
| 934 | desktop.m.SendKeyUnicode(desktop.m.KeyAction.UP, inputchar); |
| 935 | } else { |
| 936 | return desktop.m.handleKeyUp(e); |
| 937 | } |
| 938 | } |
| 939 | if (terminal && !xxdialogMode && (xxcurrentView == 10) && (currentDevicePanel == 5) && (gotKeyPressEvent == false) && (t !== 1)) { |
| 940 | if (e.altKey == true) { return true; } |
| 941 | var inputStr = Q('softKeyboard').value; |
| 942 | Q('softKeyboard').value = ''; |
| 943 | if (terminal.urlname == 'sshterminalrelay.ashx') { |
| 944 | // SSH |
| 945 | terminal.socket.send('~' + inputStr); |
| 946 | } else { |
| 947 | // Agent |
| 948 | if (inputStr) |
| 949 | terminal.sendText(inputStr); |
| 950 | } |
| 951 | return false; |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | |
| 956 | // |
| 957 | // MY DEVICE |
| 958 | // |
| 959 | |
| 960 | var currentDevicePanel = 0; |
| 961 | function setupDeviceMenu(op, obj) { |
| 962 | if (op != null) { currentDevicePanel = op; } |
| 963 | QV('p10desktop', currentDevicePanel == 1); // Show if we have remote control rights or desktop view only rights |
| 964 | QV('p10files', currentDevicePanel == 2); |
| 965 | QV('p10terminal', currentDevicePanel == 5); |
| 966 | var menus = []; |
| 967 | if (features & 2) { menus.push({ n: "Desktop", f: 'setupDeviceMenu(1)', s: (currentDevicePanel == 1) }); } |
| 968 | if (features & 1) { menus.push({ n: "Terminal", f: 'setupDeviceMenu(5)', s: (currentDevicePanel == 5) }); } |
| 969 | if (features & 4) { menus.push({ n: "Files", f: 'setupDeviceMenu(2)', s: (currentDevicePanel == 2) }); } |
| 970 | updateFooterMenu(menus); |
| 971 | if (currentDevicePanel == 1) { deskAdjust(); } |
| 972 | |
| 973 | /* |
| 974 | var meshrights = GetNodeRights(currentNode); |
| 975 | if (op != null) { currentDevicePanel = op; } |
| 976 | QV('p10general', currentDevicePanel == 0); |
| 977 | QV('p10desktop', currentDevicePanel == 1); // Show if we have remote control rights or desktop view only rights |
| 978 | QV('p10files', currentDevicePanel == 2); |
| 979 | QV('p10details', currentDevicePanel == 3); |
| 980 | QV('p10console', currentDevicePanel == 4); |
| 981 | QV('p10terminal', currentDevicePanel == 5); |
| 982 | var menus = []; |
| 983 | if (currentDevicePanel != 0) { menus.push({ n: "General", f: 'setupDeviceMenu(0)' }); } |
| 984 | |
| 985 | if ((currentDevicePanel != 1) && |
| 986 | (currentNode != null) && |
| 987 | ((meshrights & 8) || (meshrights & 256)) && ((meshrights == 0xFFFFFFFF) || ((meshrights & 65536) == 0)) && |
| 988 | (((currentNode.agent == null) && (currentNode.intelamt) && ((typeof currentNode.intelamt.sku !== 'number') || ((currentNode.intelamt.sku & 8) != 0))) || (currentNode.agent && (currentNode.agent.caps & 1))) |
| 989 | ) { menus.push({ n: "Desktop", f: 'setupDeviceMenu(1)' }); } |
| 990 | |
| 991 | if ((currentDevicePanel != 5) && |
| 992 | (currentNode != null) && |
| 993 | ((meshrights & 8) || (meshrights & 256)) && ((meshrights == 0xFFFFFFFF) || ((meshrights & 512) == 0)) && |
| 994 | (((currentNode.agent == null) && (currentNode.intelamt) && ((typeof currentNode.intelamt.sku !== 'number') || ((currentNode.intelamt.sku & 8) != 0))) || (currentNode.agent && (currentNode.agent.caps & 2))) |
| 995 | ) { menus.push({ n: "Terminal", f: 'setupDeviceMenu(5)' }); } |
| 996 | |
| 997 | if ((currentDevicePanel != 2) && (currentNode != null) && (meshrights & 8) && ((meshrights == 0xFFFFFFFF) || ((meshrights & 1024) == 0)) && ((currentNode.mtype != 1) && (currentNode.agent) && (currentNode.agent.caps & 4))) { menus.push({ n: "Files", f: 'setupDeviceMenu(2)' }); } |
| 998 | if ((currentDevicePanel != 3) && (currentNode != null) && (currentNode.mtype < 3) && ((meshrights & 1048576) != 0)) { menus.push({ n: "Details", f: 'setupDeviceMenu(3)' }); } |
| 999 | if ((currentDevicePanel != 4) && (currentNode != null) && (meshrights & 0x00000010) && (currentNode.mtype == 2)) { menus.push({ n: "Console", f: 'setupDeviceMenu(4)' }); } |
| 1000 | |
| 1001 | updateFooterMenu(menus); |
| 1002 | if (currentDevicePanel == 1) { deskAdjust(); } |
| 1003 | */ |
| 1004 | } |
| 1005 | |
| 1006 | |
| 1007 | // |
| 1008 | // DESKTOP |
| 1009 | // |
| 1010 | |
| 1011 | var desktop; |
| 1012 | var desktopNode; |
| 1013 | var desktopsettings = { encoding: 2, showfocus: false, showmouse: true, showcad: true, quality: 40, scaling: 1024, framerate: 50, autolock: false }; |
| 1014 | function setupDesktop() { |
| 1015 | // Setup the remote desktop |
| 1016 | if ((desktopNode != currentNode) && (desktop != null)) { desktop.Stop(); desktopNode = null; desktop = null; } |
| 1017 | |
| 1018 | // If the device desktop is already connected in multi-desktop, use that. |
| 1019 | if ((desktopNode != currentNode) || (desktop == null)) { |
| 1020 | // Device is not already connected, just setup a blank canvas |
| 1021 | //QH('DeskParent', '<canvas id=Desk width=640 height=200 style="width:100%;-ms-touch-action:none;margin-left:0px" oncontextmenu="return false" onmousedown=dmousedown(event) onmouseup=dmouseup(event) onmousemove=dmousemove(event)></canvas>'); |
| 1022 | desktopNode = currentNode; |
| 1023 | // Setup the mouse wheel |
| 1024 | Q('Desk').addEventListener('DOMMouseScroll', function (e) { return dmousewheel(e); }); |
| 1025 | Q('Desk').addEventListener('mousewheel', function (e) { return dmousewheel(e); }); |
| 1026 | } |
| 1027 | desktopNode = currentNode; |
| 1028 | updateDesktopButtons(); |
| 1029 | |
| 1030 | // On some browsers like IE, we can't save screen shots. Hide the scheenshot/capture buttons. |
| 1031 | if (!Q('Desk')['toBlob']) { QV('deskSaveBtn', false); } |
| 1032 | } |
| 1033 | |
| 1034 | // Show and enable the right buttons |
| 1035 | function updateDesktopButtons() { |
| 1036 | var deskState = 0; |
| 1037 | if (desktop != null) { deskState = desktop.State; } |
| 1038 | |
| 1039 | // Show the right buttons |
| 1040 | QV('disconnectbutton1', (deskState != 0)); |
| 1041 | QE('deskFullScreen', (deskState != 0)); |
| 1042 | QV('connectbutton1', (deskState == 0)); |
| 1043 | QV('connectbutton1h', false); |
| 1044 | /* |
| 1045 | QV('connectbutton1h', |
| 1046 | (deskState == 0) && |
| 1047 | (meshrights & 8) && |
| 1048 | ( |
| 1049 | ((currentNode.intelamt != null) && |
| 1050 | (currentNode.intelamt.state == 2) && |
| 1051 | (currentNode.intelamt.ver != null) && |
| 1052 | ((currentNode.intelamt.sku == null) || |
| 1053 | ((typeof currentNode.intelamt.sku == 'number') && |
| 1054 | ((currentNode.intelamt.sku & 8) != 0)))) |
| 1055 | ) |
| 1056 | ); |
| 1057 | */ |
| 1058 | |
| 1059 | // Show the right settings |
| 1060 | QV('d7amtkvm', false); |
| 1061 | QV('d7meshkvm', true); |
| 1062 | |
| 1063 | // Enable buttons |
| 1064 | QE('connectbutton1', true); |
| 1065 | QE('connectbutton1h', false); |
| 1066 | } |
| 1067 | |
| 1068 | // Used to translate incoming agent console messages |
| 1069 | var agentConsoleMessages = ['', "Waiting for user to grant access...", "Denied", "Failed to start remote terminal session, {0} ({1})", "Timeout", "Received invalid network data"]; |
| 1070 | function formatAgentConsoleMessage(msg, msgid, msgargs) { |
| 1071 | var r; |
| 1072 | if (msgargs == null) { msgargs = []; } |
| 1073 | 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 ... |
| 1074 | if (msgid && (msgid < agentConsoleMessages.length)) { r = EscapeHtml(format(agentConsoleMessages[msgid], (msgargs[0]), (msgargs[1]), (msgargs[2]))); } else { r = EscapeHtml(msg); } |
| 1075 | return r.split('\n').join('<br />') + '<br /><br />'; |
| 1076 | } |
| 1077 | |
| 1078 | function connectDesktop(e, contype, tsid, consent) { |
| 1079 | setSessionActivity(); |
| 1080 | QV('p11DeskSessionSelector', false); |
| 1081 | p11clearConsoleMsg(); |
| 1082 | if (desktop == null) { |
| 1083 | if (contype == 2) { |
| 1084 | // Setup the Intel AMT remote desktop |
| 1085 | if ((desktopNode.intelamt.user == null) || (desktopNode.intelamt.user == '')) { editDeviceAmtSettings(desktopNode._id, connectDesktop); return; } |
| 1086 | desktop = CreateAmtRedirect(CreateAmtRemoteDesktop('Desk'), authCookie); |
| 1087 | desktop.debugmode = debugmode; |
| 1088 | desktop.onStateChanged = onDesktopStateChange; |
| 1089 | desktop.m.stopInput = (viewOnly == 1); |
| 1090 | desktop.m.bpp = (desktopsettings.encoding == 1 || desktopsettings.encoding == 3) ? 1 : 2; |
| 1091 | desktop.m.useZRLE = (desktopsettings.encoding < 3); |
| 1092 | desktop.m.showmouse = true; |
| 1093 | desktop.m.onScreenSizeChange = function (o, x, y) { if (fullscreen) { QS('deskarea3').width = (x * fullscreenzoom) + 'px'; QS('deskarea3').height = (y * fullscreenzoom) + 'px'; } deskAdjust(); } |
| 1094 | desktop.Start(desktopNode._id, 16994, '*', '*', 0); |
| 1095 | desktop.contype = 2; |
| 1096 | } else if ((contype == null) || (contype == 1) || ((contype == 3))) { |
| 1097 | // Setup the Mesh Agent remote desktop |
| 1098 | desktop = CreateAgentRedirect(null, CreateAgentRemoteDesktop('Desk'), serverPublicNamePort, authCookie, null, domainUrl); |
| 1099 | desktop.m.stopInput = (viewOnly == 1); |
| 1100 | desktop.m.mouseCursorActive(true); |
| 1101 | desktop.debugmode = debugmode; |
| 1102 | desktop.m.debugmode = debugmode; |
| 1103 | desktop.attemptWebRTC = attemptWebRTC; |
| 1104 | desktop.options = {}; |
| 1105 | if (tsid != null) { desktop.options.tsid = tsid; } |
| 1106 | if (consent != null) { desktop.options.consent = consent; } |
| 1107 | if (desktopsettings.autolock == true) { desktop.options.autolock = true; } |
| 1108 | desktop.onStateChanged = onDesktopStateChange; |
| 1109 | if ((features2 & 0x2000) != 0) desktop.m.stopInput = true; |
| 1110 | desktop.onConsoleMessageChange = function () { |
| 1111 | if (desktop.consoleMessage) { |
| 1112 | Q('p11DeskConsoleMsg').innerHTML += formatAgentConsoleMessage(desktop.consoleMessage, desktop.consoleMessageId, desktop.consoleMessageArgs); |
| 1113 | QV('p11DeskConsoleMsg', true); |
| 1114 | if (p11DeskConsoleMsgTimer != null) { clearTimeout(p11DeskConsoleMsgTimer); } |
| 1115 | if (desktop.consoleMessageTimeout) { p11DeskConsoleMsgTimer = setTimeout(p11clearConsoleMsg, desktop.consoleMessageTimeout * 1000); } |
| 1116 | } else { |
| 1117 | p11clearConsoleMsg(); |
| 1118 | } |
| 1119 | } |
| 1120 | desktop.m.ImageType = webpSupport ? 4 : 1; // Send 4 if WebP is supported, otherwise send 1 for JPEG. |
| 1121 | desktop.m.CompressionLevel = desktopsettings.quality; // Number from 1 to 100. 50 or less is best. |
| 1122 | desktop.m.ScalingLevel = desktopsettings.scaling; |
| 1123 | desktop.m.FrameRateTimer = desktopsettings.framerate; |
| 1124 | desktop.m.onDisplayinfo = deskDisplayInfo; |
| 1125 | desktop.m.onScreenSizeChange = function (o, x, y) { if (fullscreen) { QS('deskarea3').width = (x * fullscreenzoom) + 'px'; QS('deskarea3').height = (y * fullscreenzoom) + 'px'; } deskAdjust(); } |
| 1126 | desktop.Start(null); |
| 1127 | desktop.contype = 1; |
| 1128 | } else if (contype == 3) { |
| 1129 | // Ask for user sessions |
| 1130 | //meshserver.send({ action: 'msg', type: 'userSessions', nodeid: currentNode._id, tag: consent }); |
| 1131 | } |
| 1132 | } else { |
| 1133 | // Disconnect and clean up the remote desktop |
| 1134 | desktop.Stop(); |
| 1135 | desktopNode = desktop = null; |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | function p11clearConsoleMsg() { QH('p11DeskConsoleMsg', ''); QV('p11DeskConsoleMsg', false); if (p11DeskConsoleMsgTimer) { clearTimeout(p11DeskConsoleMsgTimer); p11DeskConsoleMsgTimer = null; } } |
| 1140 | function p12clearConsoleMsg() { QH('p12TermConsoleMsg', ''); QV('p12TermConsoleMsg', false); if (p12TermConsoleMsgTimer) { clearTimeout(p12TermConsoleMsgTimer); p12TermConsoleMsgTimer = null; } } |
| 1141 | function p13clearConsoleMsg() { QH('p13FilesConsoleMsg', ''); QV('p13FilesConsoleMsg', false); if (p13FilesConsoleMsgTimer) { clearTimeout(p13FilesConsoleMsgTimer); p13FilesConsoleMsgTimer = null; } } |
| 1142 | |
| 1143 | function p12setConsoleMsg(msg, timeout) { |
| 1144 | if (msg) { |
| 1145 | Q('p12TermConsoleMsg').innerHTML += msg; |
| 1146 | QV('p12TermConsoleMsg', true); |
| 1147 | if (p12TermConsoleMsgTimer != null) { clearTimeout(p12TermConsoleMsgTimer); } |
| 1148 | if (timeout) { p12TermConsoleMsgTimer = setTimeout(p12clearConsoleMsg, timeout); } |
| 1149 | } else { |
| 1150 | p12clearConsoleMsg(); |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | function p13setConsoleMsg(msg, timeout) { |
| 1155 | if (msg) { |
| 1156 | Q('p13FilesConsoleMsg').innerHTML += msg; |
| 1157 | QV('p13FilesConsoleMsg', true); |
| 1158 | if (p13FilesConsoleMsgTimer != null) { clearTimeout(p13FilesConsoleMsgTimer); } |
| 1159 | if (timeout) { p13FilesConsoleMsgTimer = setTimeout(p13clearConsoleMsg, timeout); } |
| 1160 | } else { |
| 1161 | p13clearConsoleMsg(); |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | function onDesktopStateChange(xdesktop, state) { |
| 1166 | var xstate = state; |
| 1167 | if ((xstate == 3) && (xdesktop.contype == 2)) { xstate++; } |
| 1168 | var str = StatusStrs[xstate]; |
| 1169 | if ((desktop != null) && (desktop.webRtcActive == true)) { str += ", WebRTC"; } |
| 1170 | //if (desktop.m.stopInput == true) { str += ', Loopback'; } |
| 1171 | QH('deskstatus', str); |
| 1172 | switch (state) { |
| 1173 | case 0: |
| 1174 | // Disconnect and clean up the remote desktop |
| 1175 | desktop.Stop(); |
| 1176 | desktopNode = desktop = null; |
| 1177 | QV('DeskScreens', false); |
| 1178 | if (fullscreen == true) { deskToggleFull(); } |
| 1179 | break; |
| 1180 | case 2: |
| 1181 | break; |
| 1182 | default: |
| 1183 | //console.log('Unknown onDesktopStateChange state', state); |
| 1184 | break; |
| 1185 | } |
| 1186 | updateDesktopButtons(); |
| 1187 | deskAdjust(); |
| 1188 | setTimeout(deskAdjust, 50); |
| 1189 | } |
| 1190 | |
| 1191 | function showDesktopSettings() { |
| 1192 | if (xxdialogMode) return; |
| 1193 | applyDesktopSettings(); |
| 1194 | updateDesktopButtons(); |
| 1195 | setDialogMode(7, "Remote Desktop Settings", 3, showDesktopSettingsChanged); |
| 1196 | } |
| 1197 | |
| 1198 | function showDesktopSettingsChanged() { |
| 1199 | desktopsettings.encoding = d7desktopmode.value; |
| 1200 | desktopsettings.quality = d7bitmapquality.value; |
| 1201 | desktopsettings.scaling = d7bitmapscaling.value; |
| 1202 | desktopsettings.framerate = d7framelimiter.value; |
| 1203 | desktopsettings.autolock = d7deskAutoLock.checked; |
| 1204 | localStorage.setItem('desktopsettings', JSON.stringify(desktopsettings)); |
| 1205 | applyDesktopSettings(); |
| 1206 | if (desktop) { |
| 1207 | if (desktop.contype == 1) { |
| 1208 | if (desktop.State != 0) { desktop.m.SendCompressionLevel(webpSupport ? 4 : 1, desktopsettings.quality, desktopsettings.scaling, desktopsettings.framerate); } |
| 1209 | desktop.sendCtrlMsg('{"ctrlChannel":"102938","type":"autolock","value":' + desktopsettings.autolock + '}'); |
| 1210 | } |
| 1211 | if (desktop.contype == 2) { |
| 1212 | if (desktop.State != 0) { desktop.Stop(); setTimeout(function () { connectDesktop(null, 2); }, 50); } |
| 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | function applyDesktopSettings() { |
| 1218 | var r = '', ops = (features & 512) ? [100, 90, 70, 50, 40, 30, 20, 10, 5, 1] : [50, 40, 30, 20, 10, 5, 1]; |
| 1219 | for (var i in ops) { r += '<option value=' + ops[i] + '>' + ops[i] + '%</option>'; } |
| 1220 | QH('d7bitmapquality', r); |
| 1221 | d7desktopmode.value = desktopsettings.encoding; |
| 1222 | d7bitmapquality.value = 40; // Default value |
| 1223 | if (ops.indexOf(parseInt(desktopsettings.quality)) >= 0) { d7bitmapquality.value = desktopsettings.quality; } |
| 1224 | d7bitmapscaling.value = desktopsettings.scaling; |
| 1225 | if (desktopsettings.framerate) { d7framelimiter.value = desktopsettings.framerate; } |
| 1226 | if (desktopsettings.autolock != null) { d7deskAutoLock.checked = desktopsettings.autolock; } |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | var keyboardShown = false; |
| 1231 | var keyboardShownTimer = null; |
| 1232 | var fullScreenMode = false; |
| 1233 | function toggleKeyboard() { |
| 1234 | if (xxdialogMode) return; |
| 1235 | if (keyboardShownTimer != null) { clearTimeout(keyboardShownTimer); } |
| 1236 | if (keyboardShown) { Q('softKeyboard').blur(); keyboardShown = false; } else { Q('softKeyboard').focus(); keyboardShown = true; } |
| 1237 | QV('deskkeybutton2a', fullscreen && !keyboardShown); |
| 1238 | QV('deskkeybutton2b', fullscreen && keyboardShown); |
| 1239 | } |
| 1240 | |
| 1241 | function keyboardFocusChange() { |
| 1242 | keyboardShownTimer = setTimeout(function () { |
| 1243 | keyboardShownTimer = null; |
| 1244 | keyboardShown = (Q('softKeyboard') == document.activeElement); |
| 1245 | QV('deskkeybutton2a', fullscreen && !keyboardShown); |
| 1246 | QV('deskkeybutton2b', fullscreen && keyboardShown); |
| 1247 | }, 10); |
| 1248 | } |
| 1249 | |
| 1250 | function exitButton() { |
| 1251 | if (xxdialogMode) return; |
| 1252 | QV('deskButtonMenu', false); |
| 1253 | QV('termButtonMenu', false); |
| 1254 | deskToggleFull(); |
| 1255 | } |
| 1256 | |
| 1257 | function deskMenuButton(x) { |
| 1258 | toggleMenu(true); |
| 1259 | deskSendKeys(x); |
| 1260 | } |
| 1261 | |
| 1262 | // |
| 1263 | // Desktop Shortcut Keys |
| 1264 | // |
| 1265 | |
| 1266 | function updateDeskShortcutKeys() { |
| 1267 | var x = '<div class="menuButton" onclick="deskMenuButton(-1)">' + "Customize" + '</div>'; |
| 1268 | for (var i in deskKeyboardShortcuts) { x += '<div class="menuButton" onclick="deskMenuButton(' + deskKeyboardShortcuts[i] + ')">' + keyShortcutTotext(deskKeyboardShortcuts[i]) + '</div>'; } |
| 1269 | QH('deskButtonMenu', x); |
| 1270 | } |
| 1271 | |
| 1272 | 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" } |
| 1273 | |
| 1274 | function keyShortcutTotext(n) { |
| 1275 | var x = []; |
| 1276 | if (n & 0x010000) { x.push("Shift"); } |
| 1277 | if (n & 0x020000) { x.push("Alt"); } |
| 1278 | if (n & 0x080000) { x.push("Ctrl"); } |
| 1279 | if (n & 0x100000) { x.push("Win"); } |
| 1280 | n = (n & 0xFFFF); |
| 1281 | if ((n >= 112) && (n <= 123)) { x.push('F' + (n - 111)); } // Fx keys |
| 1282 | else if ((n != 0) && (keyStrings[n])) { x.push(keyStrings[n]); } |
| 1283 | else { if (n != 0) { x.push(String.fromCharCode(n)); } } |
| 1284 | return x.join(' + '); |
| 1285 | } |
| 1286 | |
| 1287 | // Customize keyboard shortcuts |
| 1288 | function deskCustomizeKeys() { |
| 1289 | if (xxdialogMode) return; |
| 1290 | 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>'; |
| 1291 | 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>'; |
| 1292 | x += ' <select id=d2keySelect>'; |
| 1293 | for (var i in keyStrings) { x += '<option value=' + i + '>' + keyStrings[i] + '</option>'; } |
| 1294 | for (var i = 1; i <= 12; i++) { x += '<option value=' + (i + 111) + '>F' + i + '</option>'; } |
| 1295 | for (var i = 0; i < 10; i++) { x += '<option value=' + (i + 48) + '>' + i + '</option>'; } |
| 1296 | for (var i = 0; i < 26; i++) { x += '<option value=' + (i + 65) + '>' + String.fromCharCode(i + 65) + '</option>'; } |
| 1297 | x += '</select> <input type=button value=' + "Add" + ' onclick=addDeskCustomizeKey() /></div>'; |
| 1298 | QH('p10dialog2', x); |
| 1299 | xxdialogMode = 2; |
| 1300 | QV('p10dialog', true); |
| 1301 | deskUpdateShortcutList(); |
| 1302 | } |
| 1303 | |
| 1304 | function deskCustomizeKeysEx() { |
| 1305 | QV('p10dialog', false); |
| 1306 | xxdialogMode = 0; |
| 1307 | putstore('deskKeyShortcuts', deskKeyboardShortcuts.join(',')); |
| 1308 | updateDeskShortcutKeys(); |
| 1309 | } |
| 1310 | |
| 1311 | function deskUpdateShortcutList() { |
| 1312 | var x = ''; |
| 1313 | for (var i in deskKeyboardShortcuts) { |
| 1314 | var kt = keyShortcutTotext(deskKeyboardShortcuts[i]), orderButtons = ''; |
| 1315 | 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] + ')>'; } |
| 1316 | if (i != 0) { orderButtons += '<img width=8 height=8 style=float:right;cursor:pointer;padding:3px src="images/c3.png" onclick=deskCustomizeKeyUp(' + deskKeyboardShortcuts[i] + ')>'; } |
| 1317 | 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>'; |
| 1318 | } |
| 1319 | if (x == '') { x = '<i>' + "No keyboard shortcuts defined" + '</i>'; } |
| 1320 | QH('d2shortcuts', x); |
| 1321 | } |
| 1322 | |
| 1323 | function deskCustomizeKeyDown(k) { |
| 1324 | var i = deskKeyboardShortcuts.indexOf(k), x = deskKeyboardShortcuts[i + 1]; |
| 1325 | deskKeyboardShortcuts[i + 1] = deskKeyboardShortcuts[i]; |
| 1326 | deskKeyboardShortcuts[i] = x; |
| 1327 | deskUpdateShortcutList(); |
| 1328 | } |
| 1329 | |
| 1330 | function deskCustomizeKeyUp(k) { |
| 1331 | var i = deskKeyboardShortcuts.indexOf(k), x = deskKeyboardShortcuts[i]; |
| 1332 | deskKeyboardShortcuts[i] = deskKeyboardShortcuts[i - 1]; |
| 1333 | deskKeyboardShortcuts[i - 1] = x; |
| 1334 | deskUpdateShortcutList(); |
| 1335 | } |
| 1336 | |
| 1337 | function removeDeskCustomizeKey(k) { |
| 1338 | var na = []; |
| 1339 | for (var i in deskKeyboardShortcuts) { if (deskKeyboardShortcuts[i] != k) { na.push(deskKeyboardShortcuts[i]); } } |
| 1340 | deskKeyboardShortcuts = na; |
| 1341 | deskUpdateShortcutList(); |
| 1342 | } |
| 1343 | |
| 1344 | function addDeskCustomizeKey() { |
| 1345 | var k = parseInt(Q('d2keySelect').value); |
| 1346 | if (Q('d1kshift').checked) { k |= 0x010000; } |
| 1347 | if (Q('d1kalt').checked) { k |= 0x020000; } |
| 1348 | if (Q('d1kctrl').checked) { k |= 0x080000; } |
| 1349 | if (Q('d1kwin').checked) { k |= 0x100000; } |
| 1350 | if ((k > 0) && (deskKeyboardShortcuts.indexOf(k) == -1)) { deskKeyboardShortcuts.push(k); deskUpdateShortcutList(); } |
| 1351 | } |
| 1352 | |
| 1353 | // Remote desktop special key combos for Windows |
| 1354 | function deskSendKeys(ks) { |
| 1355 | if (xxdialogMode || desktop == null || desktop.State != 3) return; |
| 1356 | |
| 1357 | // Construct the key command |
| 1358 | if (ks == -1) { deskCustomizeKeys(); return; } // Customize |
| 1359 | if (ks == 0x0A002E) { desktop.m.sendcad(); return; } // CTRL-ALT-DEL |
| 1360 | //if ((desktop.contype == 1) && (ks == 0x10004C)) { desktop.sendCtrlMsg('{"action":"lock"}'); return; } // Lock desktop, WIN + L |
| 1361 | |
| 1362 | var flags = (ks & 0xFF0000) >> 16, key = (ks & 0xFFFF), keyArray = [], keyArray2 = []; |
| 1363 | var amtTranslate = { |
| 1364 | 8: 0xff08, // BackSpace |
| 1365 | 9: 0xff09, // Tab |
| 1366 | 13: 0xff0d, // Return or Enter |
| 1367 | 27: 0xff1b, // Escape |
| 1368 | 45: 0xff63, // Insert |
| 1369 | 46: 0xffff, // Delete |
| 1370 | 36: 0xff50, // Home |
| 1371 | 35: 0xff57, // End |
| 1372 | 33: 0xff55, // Page Up |
| 1373 | 34: 0xff56, // Page Down |
| 1374 | 37: 0xff51, // Left arrow |
| 1375 | 38: 0xff52, // Up arrow |
| 1376 | 39: 0xff53, // Right arrow |
| 1377 | 40: 0xff54, // Down arrow |
| 1378 | 112: 0xffbe, // F1 |
| 1379 | 113: 0xffbf, // F2 |
| 1380 | 114: 0xffc0, // F3 |
| 1381 | 115: 0xffc1, // F4 |
| 1382 | 116: 0xffc2, // F5 |
| 1383 | 117: 0xffc3, // F6 |
| 1384 | 118: 0xffc4, // F7 |
| 1385 | 119: 0xffc5, // F8 |
| 1386 | 120: 0xffc6, // F9 |
| 1387 | 121: 0xffc7, // F10 |
| 1388 | 122: 0xffc8, // F11 |
| 1389 | 123: 0xffc9 // F12 |
| 1390 | } |
| 1391 | |
| 1392 | // 0x010000 = Shift |
| 1393 | // 0x020000 = Left-Alt |
| 1394 | // 0x080000 = Ctrl |
| 1395 | // 0x100000 = Window |
| 1396 | |
| 1397 | if (desktop.contype == 2) { |
| 1398 | // Intel AMT |
| 1399 | if (flags & 1) { keyArray.push([0xffe1, 1]); keyArray2.push([0xffe1, 0]); } // Shift |
| 1400 | if (flags & 2) { keyArray.push([0xffe9, 1]); keyArray2.push([0xffe9, 0]); } // Left-alt |
| 1401 | if (flags & 8) { keyArray.push([0xffe3, 1]); keyArray2.push([0xffe3, 0]); } // Ctrl |
| 1402 | if (flags & 16) { keyArray.push([0xffe7, 1]); keyArray2.push([0xffe7, 0]); } // Windows key |
| 1403 | if (amtTranslate[key]) { key = amtTranslate[key]; } |
| 1404 | if ((key >= 65) && (key <= 90)) { key += 32; } |
| 1405 | if (key != 0) { keyArray.push([key, 1]); keyArray2.push([key, 0]); } |
| 1406 | keyArray2.reverse(); |
| 1407 | for (var i = 0; i < keyArray2.length; i++) { keyArray.push(keyArray2[i]); } |
| 1408 | desktop.m.sendkey(keyArray); |
| 1409 | } else { |
| 1410 | // Agent desktop |
| 1411 | if (flags & 1) { keyArray.push([desktop.m.KeyAction.DOWN, 16]); keyArray2.push([desktop.m.KeyAction.UP, 16]); } // Shift |
| 1412 | if (flags & 2) { keyArray.push([desktop.m.KeyAction.EXDOWN, 18]); keyArray2.push([desktop.m.KeyAction.EXUP, 18]); } // Left-alt |
| 1413 | if (flags & 8) { keyArray.push([desktop.m.KeyAction.EXDOWN, 17]); keyArray2.push([desktop.m.KeyAction.EXUP, 17]); } // Ctrl |
| 1414 | if (flags & 16) { keyArray.push([desktop.m.KeyAction.EXDOWN, 0x5B]); keyArray2.push([desktop.m.KeyAction.EXUP, 0x5B]); } // Windows key |
| 1415 | if (key != 0) { keyArray.push([desktop.m.KeyAction.DOWN, key]); keyArray2.push([desktop.m.KeyAction.UP, key]); } |
| 1416 | keyArray2.reverse(); |
| 1417 | for (var i = 0; i < keyArray2.length; i++) { keyArray.push(keyArray2[i]); } |
| 1418 | desktop.m.SendKeyMsgKC(keyArray); |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | function toggleMenu(x) { |
| 1423 | if (xxdialogMode) return; |
| 1424 | QV('deskButtonMenu', fullscreen && !x && (currentDevicePanel == 1)); |
| 1425 | QV('termButtonMenu', fullscreen && !x && (currentDevicePanel == 5)); |
| 1426 | QV('deskkeybutton3a', fullscreen && x); |
| 1427 | QV('deskkeybutton3b', fullscreen && !x); |
| 1428 | } |
| 1429 | |
| 1430 | function deskChangeMouseButton(x) { |
| 1431 | if (xxdialogMode) return; |
| 1432 | if (desktop == null) return; |
| 1433 | desktop.m.SwapMouse = !desktop.m.SwapMouse; |
| 1434 | QV('deskkeybutton4a', fullscreen && (!desktop.m.SwapMouse)); |
| 1435 | QV('deskkeybutton4b', fullscreen && (desktop.m.SwapMouse)); |
| 1436 | } |
| 1437 | |
| 1438 | function deskChangeFullscreenZoom() { |
| 1439 | if (xxdialogMode) return; |
| 1440 | if (currentDevicePanel == 1) { |
| 1441 | if (desktop == null) return; |
| 1442 | if (fullscreenzoom == 1) { fullscreenzoom = 0.5; } else { fullscreenzoom = 1; } |
| 1443 | QV('deskkeybutton5a', fullscreen && (fullscreenzoom == 1)); |
| 1444 | QV('deskkeybutton5b', fullscreen && (fullscreenzoom != 1)); |
| 1445 | QS('deskarea3').width = (desktop.m.ScreenWidth * fullscreenzoom) + 'px'; |
| 1446 | QS('deskarea3').height = (desktop.m.ScreenHeight * fullscreenzoom) + 'px'; |
| 1447 | deskAdjust(); |
| 1448 | } |
| 1449 | if (currentDevicePanel == 5) { |
| 1450 | if (terminal == null) return; |
| 1451 | xterm.setOption('fontSize', (xterm.getOption('fontSize') == 15) ? 10 : 15) |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | var fullscreen = false; |
| 1456 | var fullscreenzoom = 1; |
| 1457 | function deskToggleFull() { |
| 1458 | fullscreen = !fullscreen; |
| 1459 | QV('mastheadx', !fullscreen); |
| 1460 | QV('masthead', !fullscreen); |
| 1461 | QV('topbar', !fullscreen); |
| 1462 | QV('p11deviceNameHeader', !fullscreen); |
| 1463 | QV('footer', !fullscreen); |
| 1464 | QV('column_l_bottomgap', !fullscreen); |
| 1465 | QV('idx_deskFullBtn2', fullscreen); |
| 1466 | QV('deskFullBtn', !fullscreen); |
| 1467 | QV('p10deskTopTable', !fullscreen); |
| 1468 | QV('deskarea1', !fullscreen); |
| 1469 | QV('deskarea4', !fullscreen); |
| 1470 | QV('termarea1', !fullscreen); |
| 1471 | QV('termarea4', !fullscreen); |
| 1472 | var inputAllowed = (viewOnly == 0); |
| 1473 | |
| 1474 | // Show full screen buttons if needed |
| 1475 | QV('deskkeybutton1', fullscreen); |
| 1476 | if (currentDevicePanel == 1) { // Desktop panel is being shown (1 = Desktop, 5 = Terminal) |
| 1477 | // Move shortcut key to desktop position |
| 1478 | QS('deskkeybutton2a').top = QS('deskkeybutton2b').top = '210px'; |
| 1479 | // Move the zoom button to normal or top position |
| 1480 | QS('deskkeybutton5a').top = QS('deskkeybutton5b').top = (inputAllowed) ? '160px' : '60px'; // Zoom |
| 1481 | QV('deskkeybutton2a', fullscreen && inputAllowed); |
| 1482 | QV('deskkeybutton2b', false); |
| 1483 | QV('deskkeybutton3a', fullscreen && inputAllowed); |
| 1484 | QV('deskkeybutton3b', false); |
| 1485 | QV('deskkeybutton4a', fullscreen && inputAllowed && (!desktop.m.SwapMouse)); |
| 1486 | QV('deskkeybutton4b', fullscreen && inputAllowed && (desktop.m.SwapMouse)); |
| 1487 | QV('deskkeybutton5a', fullscreen && (fullscreenzoom == 1)); |
| 1488 | QV('deskkeybutton5b', fullscreen && (fullscreenzoom != 1)); |
| 1489 | } |
| 1490 | if (currentDevicePanel == 5) { |
| 1491 | // Move right buttons to terminal position |
| 1492 | //QS('deskkeybutton3a').top = QS('deskkeybutton3b').top = '60px'; // Shortcuts |
| 1493 | //QS('deskkeybutton5a').top = QS('deskkeybutton5b').top = '110px'; // Zoom |
| 1494 | QS('deskkeybutton2a').top = QS('deskkeybutton2b').top = '110px'; // Keyboard |
| 1495 | QV('deskkeybutton2a', fullscreen); |
| 1496 | QV('deskkeybutton2b', false); |
| 1497 | QV('deskkeybutton3a', fullscreen); |
| 1498 | QV('deskkeybutton3b', false); |
| 1499 | QV('deskkeybutton4a', false); |
| 1500 | QV('deskkeybutton4b', false); |
| 1501 | QV('deskkeybutton5a', false); |
| 1502 | QV('deskkeybutton5a', false); |
| 1503 | //QV('deskkeybutton5a', xterm.getOption('fontSize') == 15); |
| 1504 | //QV('deskkeybutton5b', xterm.getOption('fontSize') != 15); |
| 1505 | } |
| 1506 | |
| 1507 | if (fullscreen) { |
| 1508 | QS('DeskParent').height = null; |
| 1509 | QS('page_content').top = '0px'; |
| 1510 | QS('page_content').bottom = '0px'; |
| 1511 | if (currentDevicePanel == 1) { |
| 1512 | QS('p10desktop').top = '0px'; |
| 1513 | QS('p10desktop').overflow = 'scroll'; |
| 1514 | QS('deskarea3').top = '0px'; |
| 1515 | QS('deskarea3').width = (desktop.m.ScreenWidth * fullscreenzoom) + 'px'; |
| 1516 | QS('deskarea3').height = (desktop.m.ScreenHeight * fullscreenzoom) + 'px'; |
| 1517 | QS('deskarea3')['padding-right'] = '55px'; |
| 1518 | } |
| 1519 | if (currentDevicePanel == 5) { |
| 1520 | QS('p10terminal').top = '0px'; |
| 1521 | QS('p10terminal').overflow = 'scroll'; |
| 1522 | QS('termarea3').top = '0px'; |
| 1523 | QS('termarea3').bottom = null; |
| 1524 | QS('termarea3').right = null; |
| 1525 | QS('termarea3')['padding-right'] = '55px'; |
| 1526 | QS('termarea3')['height'] = '100%'; |
| 1527 | } |
| 1528 | QS('body')['background-color'] = '#000'; |
| 1529 | QS('p10')['background-color'] = '#000'; |
| 1530 | } else { |
| 1531 | QS('DeskParent').height = '100%'; |
| 1532 | QS('page_content').top = '50px'; |
| 1533 | QS('page_content').bottom = '32px'; |
| 1534 | if (currentDevicePanel == 1) { |
| 1535 | QS('p10desktop').top = '55px'; |
| 1536 | QS('p10desktop').overflow = 'hidden'; |
| 1537 | QS('deskarea3').top = '32px'; |
| 1538 | QS('deskarea3').left = null; |
| 1539 | QS('deskarea3').width = '100%'; |
| 1540 | QS('deskarea3').height = 'calc(100% - 64px)'; |
| 1541 | QS('deskarea3')['padding-right'] = ''; |
| 1542 | QS('DeskParent')['margin-top'] = null; |
| 1543 | QS('DeskParent')['margin-left'] = null; |
| 1544 | } |
| 1545 | if (currentDevicePanel == 5) { |
| 1546 | //xterm.setOption('fontSize', 15) |
| 1547 | QS('p10terminal').top = '55px'; |
| 1548 | QS('p10terminal').overflow = 'hidden'; |
| 1549 | Q('p10terminal').scrollTop = 0; |
| 1550 | Q('p10terminal').scrollLeft = 0; |
| 1551 | QS('termarea3').top = '32px'; |
| 1552 | QS('termarea3').bottom = '32px'; |
| 1553 | //QS('termarea3').right = '0px'; |
| 1554 | QS('termarea3')['padding-right'] = null; |
| 1555 | QS('termarea3')['height'] = 'calc(100% - 60px)'; |
| 1556 | } |
| 1557 | QS('body')['background-color'] = '#FFF'; |
| 1558 | QS('p10')['background-color'] = null; |
| 1559 | } |
| 1560 | if (currentDevicePanel == 1) { deskAdjust(); } |
| 1561 | } |
| 1562 | |
| 1563 | function deskAdjust() { |
| 1564 | if (currentDevicePanel != 1) return; // If not on desktop tab, ignore this. |
| 1565 | if (fullscreen) { |
| 1566 | QS('Desk')['margin-top'] = null; |
| 1567 | QS('Desk')['margin-bottom'] = null; |
| 1568 | QS('Desk').width = '100%'; |
| 1569 | QS('Desk').height = '100%'; |
| 1570 | var parentH = Q('p10desktop').clientHeight, parentW = Q('p10desktop').clientWidth; |
| 1571 | var deskH = Q('deskarea3').clientHeight, deskW = Q('deskarea3').clientWidth - 55; |
| 1572 | if (parentH > deskH) { QS('deskarea3').top = ((parentH - deskH) / 2) + 'px'; } else { QS('deskarea3').top = null; } |
| 1573 | if (parentW > deskW) { QS('deskarea3').left = ((parentW - deskW) / 2) + 'px'; } else { QS('deskarea3').left = null; } |
| 1574 | } else { |
| 1575 | var parentH = Q('DeskParent').clientHeight, parentW = Q('DeskParent').clientWidth; |
| 1576 | var deskH = Q('Desk').height, deskW = Q('Desk').width; |
| 1577 | var webPageFullScreen = false; |
| 1578 | |
| 1579 | // Fixed aspect ratio |
| 1580 | if ((parentH / parentW) > (deskH / deskW)) { |
| 1581 | var hNew = ((deskH * parentW) / deskW) + 'px'; |
| 1582 | QS('Desk').height = hNew; |
| 1583 | QS('Desk').width = '100%'; |
| 1584 | } else { |
| 1585 | var wNew = ((deskW * parentH) / deskH) + 'px'; |
| 1586 | QS('Desk').width = wNew; |
| 1587 | QS('Desk').height = '100%'; |
| 1588 | } |
| 1589 | QS('DeskParent').overflow = 'hidden'; |
| 1590 | |
| 1591 | // Adjust top/bottom margins |
| 1592 | var x = (Q('DeskParent').clientHeight - Q('Desk').clientHeight) / 2; |
| 1593 | QS('Desk')['margin-top'] = x + 'px'; |
| 1594 | QS('Desk')['margin-bottom'] = x + 'px'; |
| 1595 | } |
| 1596 | } |
| 1597 | |
| 1598 | function sendSpecialKeys() { |
| 1599 | if (xxdialogMode || desktop == null || desktop.State != 3) return; |
| 1600 | setDialogMode(3, "Special Keys", 3, deskSendKeys); |
| 1601 | } |
| 1602 | |
| 1603 | // Save the desktop image to file |
| 1604 | function deskSaveImage() { |
| 1605 | setSessionActivity(); |
| 1606 | if (xxdialogMode || desktop == null || desktop.State != 3) return; |
| 1607 | var d = new Date(), n = 'Desktop-' + currentNode.name + '-' + d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2) + '-' + ('0' + d.getHours()).slice(-2) + '-' + ('0' + d.getMinutes()).slice(-2); |
| 1608 | Q('Desk')['toBlob'](function (blob) { saveAs(blob, n + '.png'); }); |
| 1609 | } |
| 1610 | |
| 1611 | function deskSelectScreens() { |
| 1612 | if (xxdialogMode || desktop == null || desktop.State != 3) return; |
| 1613 | var x = '', info = desktop.m.displays; |
| 1614 | for (var i in info) { x += '<option value=' + i + ' ' + ((desktop.m.selectedDisplay == i) ? ' selected' : '') + '>' + info[i] + '</option>'; } |
| 1615 | x = addHtmlValue4("Screen", '<select style=width:100% id=deskdisplays>' + x + '</select>'); |
| 1616 | setDialogMode(2, "Screen Selection", 3, deskSelectScreensEx, x); |
| 1617 | } |
| 1618 | |
| 1619 | function deskSelectScreensEx() { |
| 1620 | if (desktop == null || desktop.State != 3) return; |
| 1621 | desktop.m.SetDisplay(parseInt(Q('deskdisplays').value)); |
| 1622 | } |
| 1623 | |
| 1624 | function deskDisplayInfo(sender, info, selDisplay, selItem) { |
| 1625 | var displayCount = 0; |
| 1626 | for (var x in info) { displayCount++; } |
| 1627 | QV('DeskScreens', displayCount > 1); |
| 1628 | } |
| 1629 | |
| 1630 | function dmousedown(e) { setSessionActivity(); if ((!xxdialogMode && desktop != null)) { if (fullscreen) { e.addx = Q('p10desktop').scrollLeft * (1 / fullscreenzoom); e.addy = Q('p10desktop').scrollTop * (1 / fullscreenzoom); } desktop.m.mousedown(e); } } |
| 1631 | function dmouseup(e) { setSessionActivity(); if ((!xxdialogMode && desktop != null)) { if (fullscreen) { e.addx = Q('p10desktop').scrollLeft * (1 / fullscreenzoom); e.addy = Q('p10desktop').scrollTop * (1 / fullscreenzoom); } desktop.m.mouseup(e); } } |
| 1632 | function dmousemove(e) { setSessionActivity(); if ((!xxdialogMode && desktop != null)) { if (fullscreen) { e.addx = Q('p10desktop').scrollLeft * (1 / fullscreenzoom); e.addy = Q('p10desktop').scrollTop * (1 / fullscreenzoom); } desktop.m.mousemove(e); } } |
| 1633 | function dmousewheel(e) { setSessionActivity(); if ((!xxdialogMode && desktop != null) && desktop.m.mousewheel) { if (fullscreen) { e.addx = Q('p10desktop').scrollLeft * (1 / fullscreenzoom); e.addy = Q('p10desktop').scrollTop * (1 / fullscreenzoom); } desktop.m.mousewheel(e); haltEvent(e); return true; } return false; } |
| 1634 | function drotate(x) { if (!xxdialogMode && desktop != null) { desktop.m.setRotation(desktop.m.rotation + x); deskAdjust(); } } |
| 1635 | |
| 1636 | |
| 1637 | // |
| 1638 | // TERMINAL |
| 1639 | // |
| 1640 | |
| 1641 | var terminalNode; |
| 1642 | function setupTerminal() { |
| 1643 | // Setup the terminal |
| 1644 | if ((terminalNode != currentNode) && (terminal != null)) { terminal.Stop(); terminal = null; } |
| 1645 | terminalNode = currentNode; |
| 1646 | updateTerminalButtons(); |
| 1647 | } |
| 1648 | |
| 1649 | // Show and enable the right buttons |
| 1650 | function updateTerminalButtons() { |
| 1651 | var termState = ((terminal != null) && (terminal.state != 0)); |
| 1652 | QE('termFullScreen', (termState != 0)); |
| 1653 | |
| 1654 | // Show the right buttons |
| 1655 | QV('disconnectbutton2span', termState == true); |
| 1656 | QV('connectbutton2span', termState == false); |
| 1657 | |
| 1658 | // Enable buttons |
| 1659 | QE('connectbutton2', true); |
| 1660 | } |
| 1661 | |
| 1662 | // Called when the terminal state changes |
| 1663 | function onTerminalStateChange(xterminal, state) { |
| 1664 | var xstate = state; |
| 1665 | if ((xstate == 3) && (xterminal.contype == 2)) { xstate++; } |
| 1666 | var str = StatusStrs[xstate]; |
| 1667 | if (terminal.webRtcActive == true) { str += ", WebRTC"; } |
| 1668 | QH('termstatus', str); |
| 1669 | switch (state) { |
| 1670 | case 0: |
| 1671 | // Disconnected, clear the terminal |
| 1672 | xterm.dispose(); |
| 1673 | xterm = xtermfit = xtermimage = null; |
| 1674 | if (terminal != null) { terminal.Stop(); terminal = null; } |
| 1675 | break; |
| 1676 | case 3: |
| 1677 | xterm.focus(); |
| 1678 | break; |
| 1679 | default: |
| 1680 | //console.log('Unhandled onTerminalStateChange state', state); |
| 1681 | break; |
| 1682 | } |
| 1683 | updateTerminalButtons(); |
| 1684 | } |
| 1685 | |
| 1686 | // Handles a tunnel to a remote shell |
| 1687 | function CreateRemoteTunnel(onTunnelUpdate, options) { |
| 1688 | var obj = { protocol: 1 }; |
| 1689 | if ((options != null) && (typeof options.protocol == 'number')) { obj.protocol = options.protocol; } |
| 1690 | obj.onTunnelUpdate = onTunnelUpdate; |
| 1691 | obj.xxStateChange = function (state) { } |
| 1692 | obj.ProcessBinaryData = function (data) { obj.onTunnelUpdate(data); } |
| 1693 | obj.ProcessData = function (data) { obj.onTunnelUpdate(data); } |
| 1694 | obj.terminalEmulation = 1; |
| 1695 | obj.fxEmulation = 0; |
| 1696 | obj.lineFeed = '\r\n'; |
| 1697 | return obj; |
| 1698 | } |
| 1699 | |
| 1700 | function tunnelUpdate(data) { |
| 1701 | if (xterm.writeUtf8) { |
| 1702 | if (typeof data == 'string') { xterm.writeUtf8(data); } else { xterm.writeUtf8(new Uint8Array(data)); } |
| 1703 | } else { |
| 1704 | if (typeof data == 'string') { xterm.write(data); } else { xterm.write(new Uint8Array(data)); } |
| 1705 | } |
| 1706 | } |
| 1707 | |
| 1708 | function sshTunnelUpdate(data) { |
| 1709 | if (typeof data == 'string') { |
| 1710 | if (data[0] == '{') { |
| 1711 | var j = JSON.parse(data); |
| 1712 | switch (j.action) { |
| 1713 | case 'sshauth': { |
| 1714 | var x = ''; |
| 1715 | x += addHtmlValue("Authentication", '<select id=dp2authmethod style=width:150px onchange=sshAuthUpdate(event)><option value=1 selected>' + "Username & Password" + '</option><option value=2>' + "Username and Key" + '</option></select>') |
| 1716 | x += addHtmlValue("Username", '<input id=dp2user style=width:150px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />'); |
| 1717 | x += '<div id=d2passauth>'; |
| 1718 | x += addHtmlValue("Password", '<input type=password id=dp2pass style=width:150px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />'); |
| 1719 | x += '</div><div id=d2keyauth style=display:none>'; |
| 1720 | x += addHtmlValue("Key File", '<input type=file id=dp2key style=width:150px maxlength=64 autocomplete=off onchange=sshAuthUpdate(event) />'); |
| 1721 | x += addHtmlValue("Key Password", '<input type=password id=dp2keypass style=width:150px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />'); |
| 1722 | x += '</div>'; |
| 1723 | x += '<label><input id=dp2keep type=checkbox>' + "Remember credentials" + '</label>'; |
| 1724 | x += '<div id=d2keyauth2 style=font-size:x-small><br />' + "Key file must be in OpenSSH format." + '</div>'; |
| 1725 | setDialogMode(2, "Authentication", 11, sshConnectEx, x, 'ssh'); |
| 1726 | setTimeout(sshAuthUpdate, 50); |
| 1727 | break; |
| 1728 | } |
| 1729 | case 'sshautoauth': { |
| 1730 | terminal.socket.send(JSON.stringify({ action: 'sshautoauth', cols: xterm.cols, rows: xterm.rows, width: Q('termarea3xdiv').offsetWidth, height: Q('termarea3xdiv').offsetHeight })); |
| 1731 | break; |
| 1732 | } |
| 1733 | case 'autherror': { p12setConsoleMsg("Authentication Error", 5000); break; } |
| 1734 | case 'sessionerror': { p12setConsoleMsg("Session expired", 5000); break; } |
| 1735 | case 'sessiontimeout': { p12setConsoleMsg("Session timeout", 5000); break; } |
| 1736 | } |
| 1737 | } else if (data[0] == '~') { xterm.writeUtf8(data.substring(1)); } |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | function sshAuthUpdate(e) { |
| 1742 | QV('d2passauth', Q('dp2authmethod').value == 1); |
| 1743 | QV('d2keyauth', Q('dp2authmethod').value == 2); |
| 1744 | QV('d2keyauth2', Q('dp2authmethod').value == 2); |
| 1745 | if (Q('dp2authmethod').value == 1) { |
| 1746 | QE('idx_dlgOkButton', (Q('dp2user').value.length > 0) && (Q('dp2pass').value.length > 0)); |
| 1747 | } else { |
| 1748 | QE('idx_dlgOkButton', false); |
| 1749 | var ok = (Q('dp2user').value.length > 0) && (Q('dp2key').files != null) && (Q('dp2key').files.length == 1) && (Q('dp2key').files[0].size < 8000); |
| 1750 | if (ok == true) { |
| 1751 | var reader = new FileReader(); |
| 1752 | reader.onload = function (e) { |
| 1753 | var validkey = ((e.target.result.indexOf('-----BEGIN OPENSSH PRIVATE KEY-----') >= 0) && (e.target.result.indexOf('-----END OPENSSH PRIVATE KEY-----') >= 0)); |
| 1754 | QE('idx_dlgOkButton', validkey); |
| 1755 | } |
| 1756 | reader.readAsText(Q('dp2key').files[0]); |
| 1757 | } |
| 1758 | } |
| 1759 | } |
| 1760 | function sshConnectEx(b) { |
| 1761 | if (b == 0) { |
| 1762 | if (terminal != null) { connectTerminal(); } // Disconnect |
| 1763 | } else { |
| 1764 | if (Q('dp2authmethod').value == 1) { |
| 1765 | terminal.socket.send(JSON.stringify({ action: 'sshauth', username: Q('dp2user').value, password: Q('dp2pass').value, keep: Q('dp2keep').checked, cols: xterm.cols, rows: xterm.rows, width: Q('termarea3xdiv').offsetWidth, height: Q('termarea3xdiv').offsetHeight })); |
| 1766 | } else { |
| 1767 | var reader = new FileReader(), username = Q('dp2user').value, keypass = Q('dp2keypass').value, keep = Q('dp2keep').checked; |
| 1768 | reader.onload = function (e) { terminal.socket.send(JSON.stringify({ action: 'sshauth', username: username, keypass: keypass, key: e.target.result, keep: keep, cols: xterm.cols, rows: xterm.rows, width: Q('termarea3xdiv').offsetWidth, height: Q('termarea3xdiv').offsetHeight })); } |
| 1769 | reader.readAsText(Q('dp2key').files[0]); |
| 1770 | } |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | // Send the new terminal size to the agent |
| 1775 | function xTermSendResize() { |
| 1776 | xtermResizeTimer = null; |
| 1777 | if ((xterm != null) && (terminal != null) && (terminal.sendCtrlMsg != null)) { |
| 1778 | if (terminal.urlname == 'sshterminalrelay.ashx') { |
| 1779 | terminal.socket.send(JSON.stringify({ action: 'resize', cols: xterm.cols, rows: xterm.rows, width: Q('termarea3xdiv').offsetWidth, height: Q('termarea3xdiv').offsetHeight })); |
| 1780 | } else { |
| 1781 | terminal.sendCtrlMsg(JSON.stringify({ ctrlChannel: '102938', type: 'termsize', cols: xterm.cols, rows: xterm.rows })); |
| 1782 | } |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | function connectTerminal(e, contype, options) { |
| 1787 | p12clearConsoleMsg(); |
| 1788 | if (!terminal) { |
| 1789 | // Terminal setup |
| 1790 | var termoptions = { protocol: ((options != null) && (typeof options.protocol == 'number')) ? options.protocol : 1 }; |
| 1791 | if (options && options.requireLogin) { termoptions.requireLogin = true; } |
| 1792 | |
| 1793 | /* |
| 1794 | if ([1, 2, 3, 4, 21, 22].indexOf(currentNode.agent.id) == -1) { |
| 1795 | if (Q('termSizeList').value == 1) { termoptions.cols = 80; termoptions.rows = 25; termoptions.xterm = true; } |
| 1796 | else if (Q('termSizeList').value == 2) { termoptions.cols = 100; termoptions.rows = 30; termoptions.xterm = true; } |
| 1797 | else if (Q('termSizeList').value == 3) { |
| 1798 | // TODO: Try to improve terminal auto-size. |
| 1799 | termoptions.cols = Math.floor((Q('column_l').clientWidth - 60) / 10); |
| 1800 | termoptions.rows = Math.floor((Q('column_l').clientHeight - 120) / 20); |
| 1801 | termoptions.xterm = true; |
| 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | // If shift is pressed |
| 1806 | if ((e && (e.shiftKey == true))) { |
| 1807 | if (currentNode.agent.id > 4) { |
| 1808 | if (termoptions.protocol == 1) { termoptions.protocol = 7; } // Switch to user shell |
| 1809 | } else { |
| 1810 | if (termoptions.protocol == 1) { termoptions.protocol = 6; } // Switch to Powershell |
| 1811 | } |
| 1812 | } |
| 1813 | */ |
| 1814 | // If the server requires a shell type |
| 1815 | if ((serverinfo.linuxshell) != null && (currentNode.agent.id > 4)) { |
| 1816 | if (serverinfo.linuxshell == 'root') { termoptions.protocol = 1; delete termoptions.requireLogin; } |
| 1817 | if (serverinfo.linuxshell == 'user') { termoptions.protocol = 8; delete termoptions.requireLogin; } |
| 1818 | if (serverinfo.linuxshell == 'login') { termoptions.protocol = 1; termoptions.requireLogin = true; } |
| 1819 | } |
| 1820 | |
| 1821 | // Setup a mesh agent xterm terminal |
| 1822 | QV('termarea3xdiv', true); |
| 1823 | |
| 1824 | // Setup the terminal with auto-fit |
| 1825 | if (xterm != null) { xterm.dispose(); } |
| 1826 | xterm = new Terminal({ allowProposedApi: true }); |
| 1827 | xtermfit = new FitAddon.FitAddon(); |
| 1828 | xtermimage = new ImageAddon.ImageAddon(); |
| 1829 | if (xtermfit) { xterm.loadAddon(xtermfit); } |
| 1830 | xterm.loadAddon(xtermimage); |
| 1831 | xterm.setOption('scrollback', 0); |
| 1832 | //xterm.setOption('fontSize', 15); |
| 1833 | xterm.open(Q('termarea3xdiv')); |
| 1834 | xterm.onData(function (data) { if (terminal.urlname == 'sshterminalrelay.ashx') { terminal.socket.send('~' + data); } else { terminal.sendText(data); } }) |
| 1835 | if (xtermfit) { xtermfit.fit(); } |
| 1836 | xterm.onResize(function (size) { |
| 1837 | // Despam resize |
| 1838 | if (xtermResizeTimer) clearTimeout(xtermResizeTimer); |
| 1839 | xtermResizeTimer = setTimeout(xTermSendResize, 200); |
| 1840 | }); |
| 1841 | |
| 1842 | // Remove terminal textarea and scrollbar. |
| 1843 | document.getElementsByClassName('xterm-helper-textarea')[0].onfocus = () => { xterm.blur(); if (!fullscreen) toggleKeyboard(); }; |
| 1844 | document.getElementsByClassName('xterm-viewport')[0].style.overflow = 'hidden'; |
| 1845 | |
| 1846 | // Setup a terminal tunnel to the agent |
| 1847 | terminal = CreateAgentRedirect(null, CreateRemoteTunnel(tunnelUpdate, options), serverPublicNamePort, authCookie, null, domainUrl); |
| 1848 | terminal.debugmode = debugmode; |
| 1849 | terminal.m.debugmode = debugmode; |
| 1850 | terminal.options = termoptions; |
| 1851 | terminal.options = { cols: xterm.cols, rows: xterm.rows }; |
| 1852 | if (termoptions.requireLogin) { terminal.options.requireLogin = true; } |
| 1853 | terminal.Start(null); |
| 1854 | terminal.onStateChanged = onTerminalStateChange; |
| 1855 | terminal.contype = 1; |
| 1856 | terminal.attemptWebRTC = false; // Never do WebRTC on terminal, because of a race condition we can't do it. |
| 1857 | terminal.onConsoleMessageChange = function () { p12setConsoleMsg(terminal.consoleMessage ? formatAgentConsoleMessage(terminal.consoleMessage, terminal.consoleMessageId, terminal.consoleMessageArgs) : null, terminal.consoleMessageTimeout); } |
| 1858 | } else { |
| 1859 | terminal.Stop(); |
| 1860 | terminal = null; |
| 1861 | if (fullscreen) { deskToggleFull(); } |
| 1862 | } |
| 1863 | Q('connectbutton2').blur(); // Deselect the connect button so the button does not get key presses. |
| 1864 | } |
| 1865 | |
| 1866 | // |
| 1867 | // Terminal Shortcut Keys |
| 1868 | // |
| 1869 | |
| 1870 | function updateTermShortcutKeys() { |
| 1871 | var x = ''; |
| 1872 | for (var i = 64; i <= 95; i++) { x += '<div class="menuButton" style="width:70px" onclick="termMenuButton(' + i + ')">' + "Ctrl + " + String.fromCharCode(i) + '</div>'; } |
| 1873 | QH('termButtonMenu', x); |
| 1874 | } |
| 1875 | |
| 1876 | function termMenuButton(c) { |
| 1877 | toggleMenu(true); |
| 1878 | if (terminal.urlname == 'sshterminalrelay.ashx') { |
| 1879 | // SSH |
| 1880 | terminal.socket.send('~' + String.fromCharCode(c - 64)); |
| 1881 | } else { |
| 1882 | // Agent |
| 1883 | terminal.sendText(String.fromCharCode(c - 64)); |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | |
| 1888 | // |
| 1889 | // FILES |
| 1890 | // |
| 1891 | |
| 1892 | function setupFiles() { |
| 1893 | // Setup the files tab |
| 1894 | QE('p13Connect', true); |
| 1895 | p13setActions(); |
| 1896 | } |
| 1897 | |
| 1898 | function onFilesStateChange(xfiles, state) { |
| 1899 | setSessionActivity(); |
| 1900 | p13Connect.value = (state == 0) ? "Connect" : "Disconnect"; |
| 1901 | var str = StatusStrs[state]; |
| 1902 | if (files.webRtcActive == true) { str += ", WebRTC"; } |
| 1903 | Q('p13Status').textContent = str; |
| 1904 | switch (state) { |
| 1905 | case 0: |
| 1906 | // Disconnected, clear the files |
| 1907 | QH('p13files', ''); |
| 1908 | p13filetree = null; |
| 1909 | p13filetreelocation = []; |
| 1910 | QH('p13currentpath', ''); |
| 1911 | QE('p13FolderUp', false); |
| 1912 | p13setActions(); |
| 1913 | if (files != null) { files.Stop(); files = null; } |
| 1914 | if (uploadFile != null) { p13uploadFileTransferDone(); uploadFile = null; } |
| 1915 | break; |
| 1916 | case 3: |
| 1917 | p13filetreelocation = []; |
| 1918 | p13targetpath = ''; |
| 1919 | if (files) { |
| 1920 | p13filetreelocation = p13targetpath.split('/'); |
| 1921 | files.sendText({ action: 'ls', reqid: 1, path: p13targetpath }); |
| 1922 | //if (files.serverIsRecording == true) { QV('filesRecordIcon', true); } |
| 1923 | } |
| 1924 | break; |
| 1925 | default: |
| 1926 | //console.log('Unknown onFilesStateChange state', state); |
| 1927 | break; |
| 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | function CreateRemoteFiles(onFileUpdate) { |
| 1932 | var obj = { protocol: 5 }; |
| 1933 | obj.onFileUpdate = onFileUpdate; |
| 1934 | obj.xxStateChange = function (state) { } |
| 1935 | obj.ProcessData = function (data) { obj.onFileUpdate(data); } |
| 1936 | return obj; |
| 1937 | } |
| 1938 | |
| 1939 | // Debug Only |
| 1940 | var autoConnectFilesTimer = null; |
| 1941 | function autoConnectFiles(e) { if (autoConnectFilesTimer == null) { autoConnectFilesTimer = setInterval(connectFiles, 100); } else { clearInterval(autoConnectFilesTimer); autoConnectFilesTimer = null; } } |
| 1942 | |
| 1943 | function connectFiles(e) { |
| 1944 | p13clearConsoleMsg(); |
| 1945 | if (!files) { |
| 1946 | // Setup a mesh agent files |
| 1947 | files = CreateAgentRedirect(null, CreateRemoteFiles(p13gotFiles), serverPublicNamePort, authCookie, null, domainUrl); |
| 1948 | files.attemptWebRTC = attemptWebRTC; |
| 1949 | files.onStateChanged = onFilesStateChange; |
| 1950 | files.onConsoleMessageChange = function () { |
| 1951 | if (files.consoleMessage) { |
| 1952 | Q('p13FilesConsoleMsg').innerHTML += formatAgentConsoleMessage(files.consoleMessage, files.consoleMessageId, files.consoleMessageArgs); |
| 1953 | QV('p13FilesConsoleMsg', true); |
| 1954 | if (p13FilesConsoleMsgTimer != null) { clearTimeout(p13FilesConsoleMsgTimer); } |
| 1955 | if (files.consoleMessageTimeout) { p13FilesConsoleMsgTimer = setTimeout(p13clearConsoleMsg, files.consoleMessageTimeout * 1000); } |
| 1956 | } else { |
| 1957 | p13clearConsoleMsg(); |
| 1958 | } |
| 1959 | } |
| 1960 | files.Start(null); |
| 1961 | } else { |
| 1962 | //QH('Term', ''); |
| 1963 | files.Stop(); |
| 1964 | files = null; |
| 1965 | } |
| 1966 | p13clipboard = p13clipboardFolder = null; |
| 1967 | p13clipboardCut = 0; |
| 1968 | p13updateClipview(); |
| 1969 | } |
| 1970 | |
| 1971 | var p13filetree = null; |
| 1972 | var p13targetpath = null; |
| 1973 | var p13filetreelocation = []; |
| 1974 | |
| 1975 | function p13gotFiles(data) { |
| 1976 | if ((data.length > 0) && (data.charCodeAt(0) != 123)) { p13gotDownloadBinaryData(data); return; } // This is ok because 4 first bytes is a control value. |
| 1977 | //console.log('p13gotFiles', data); |
| 1978 | try { data = JSON.parse(decode_utf8(data)); } catch (ex) { data = JSON.parse(data); } |
| 1979 | if (data.action == 'download') { p13gotDownloadCommand(data); return; } |
| 1980 | |
| 1981 | // Process any SSH actions |
| 1982 | switch (data.action) { |
| 1983 | case 'sshauth': { |
| 1984 | var x = ''; |
| 1985 | x += addHtmlValue("Authentication", '<select id=dp2authmethod style=width:150px onchange=sshAuthUpdate(event)><option value=1 selected>' + "Username & Password" + '</option><option value=2>' + "Username and Key" + '</option></select>') |
| 1986 | x += addHtmlValue("Username", '<input id=dp2user style=width:150px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />'); |
| 1987 | x += '<div id=d2passauth>'; |
| 1988 | x += addHtmlValue("Password", '<input type=password id=dp2pass style=width:150px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />'); |
| 1989 | x += '</div><div id=d2keyauth style=display:none>'; |
| 1990 | x += addHtmlValue("Key File", '<input type=file id=dp2key style=width:150px maxlength=64 autocomplete=off onchange=sshAuthUpdate(event) />'); |
| 1991 | x += addHtmlValue("Key Password", '<input type=password id=dp2keypass style=width:150px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />'); |
| 1992 | x += '</div>'; |
| 1993 | x += '<label><input id=dp2keep type=checkbox>' + "Remember credentials" + '</label>'; |
| 1994 | x += '<div id=d2keyauth2 style=font-size:x-small><br />' + "Key file must be in OpenSSH format." + '</div>'; |
| 1995 | setDialogMode(2, "Authentication", 11, p13sshConnectEx, x, 'ssh'); |
| 1996 | setTimeout(sshAuthUpdate, 50); |
| 1997 | break; |
| 1998 | } |
| 1999 | case 'autherror': { p13setConsoleMsg("Authentication Error", 5000); return; } |
| 2000 | case 'connectionerror': { p13setConsoleMsg("Connection Error", 5000); return; } |
| 2001 | case 'sessionerror': { p13setConsoleMsg("Session expired", 5000); return; } |
| 2002 | case 'sessiontimeout': { p13setConsoleMsg("Session timeout", 5000); return; } |
| 2003 | } |
| 2004 | |
| 2005 | // Process file upload commands |
| 2006 | if ((data.action != null) && (data.action.startsWith('upload'))) { p13gotUploadData(data); return; } |
| 2007 | |
| 2008 | if (data.path != null) { |
| 2009 | if (data.dir == null) { |
| 2010 | if (p13targetpath != '') { p13folderup(); } |
| 2011 | } else { |
| 2012 | data.path = data.path.replace(/\//g, '\\'); |
| 2013 | if ((p13filetree != null) && (data.path == p13filetree.path)) { |
| 2014 | // This is an update to the same folder |
| 2015 | var checkedNames = p13getCheckedNames(); |
| 2016 | p13filetree = data; |
| 2017 | p13updateFiles(checkedNames); |
| 2018 | } else { |
| 2019 | // Make both paths use the same seperator not start with / |
| 2020 | var x1 = data.path.replace(/\//g, '\\'), x2 = p13targetpath.replace(/\//g, '\\'); |
| 2021 | while ((x1.length > 0) && (x1[0] == '\\')) { x1 = x1.substring(1); } |
| 2022 | while ((x2.length > 0) && (x2[0] == '\\')) { x2 = x2.substring(1); } |
| 2023 | if ((x1 == x2) || ((data.path == '\\') && (p13targetpath == ''))) { |
| 2024 | // This is a different folder |
| 2025 | p13filetree = data; |
| 2026 | p13updateFiles(); |
| 2027 | } |
| 2028 | } |
| 2029 | } |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | function p13sshConnectEx(b) { |
| 2034 | if (b == 0) { |
| 2035 | if (files != null) { connectFiles(); } // Disconnect |
| 2036 | } else { |
| 2037 | if (Q('dp2authmethod').value == 1) { |
| 2038 | files.socket.send(JSON.stringify({ action: 'sshauth', username: Q('dp2user').value, password: Q('dp2pass').value, keep: Q('dp2keep').checked })); |
| 2039 | } else { |
| 2040 | var reader = new FileReader(), username = Q('dp2user').value, keypass = Q('dp2keypass').value, keep = Q('dp2keep').checked; |
| 2041 | reader.onload = function (e) { files.socket.send(JSON.stringify({ action: 'sshauth', username: username, keypass: keypass, key: e.target.result, keep: keep })); } |
| 2042 | reader.readAsText(Q('dp2key').files[0]); |
| 2043 | } |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | function p13getCheckedNames() { |
| 2048 | // Save all existing checked boxes |
| 2049 | var checkedNames = [], checkboxes = document.getElementsByName('fd'); |
| 2050 | for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { checkedNames.push(p13filetree.dir[checkboxes[i].value].n) }; } |
| 2051 | return checkedNames; |
| 2052 | } |
| 2053 | |
| 2054 | function p13updateFiles(checkedNames) { |
| 2055 | var html1 = '', html2 = '', displayPath = '<a style=cursor:pointer;color:black onclick=p13folderup(0)>' + "Root" + '</a>', fullPath = 'Root'; |
| 2056 | |
| 2057 | // Work on parsing the file path |
| 2058 | var x = p13filetree.path.split('\\'); |
| 2059 | p13filetreelocation = []; |
| 2060 | for (var i in x) { if (x[i] != '') { p13filetreelocation.push(x[i]); } } // Remove empty spaces |
| 2061 | for (var i in p13filetreelocation) { displayPath += ' / <a style=cursor:pointer;color:black onclick=p13folderup(' + (parseInt(i) + 1) + ')>' + EscapeHtml(p13filetreelocation[i]) + '</a>' } // Setup the path we display |
| 2062 | var newlinkpath = p13filetreelocation.join('/'); |
| 2063 | |
| 2064 | // Sort the files |
| 2065 | var filetreexx = p13sort_files(p13filetree.dir); |
| 2066 | |
| 2067 | // Display all files and folders at this location |
| 2068 | for (var i in filetreexx) { |
| 2069 | // Figure out the name and shortname |
| 2070 | var f = filetreexx[i], name = f.n, shortname; |
| 2071 | // shortname = name; |
| 2072 | // if (name.length > 70) { shortname = EscapeHtml(name.substring(0, 70)) + "..."; } else { shortname = EscapeHtml(name); } |
| 2073 | // Removed redundant filename length check because we handle it in the CSS |
| 2074 | shortname = EscapeHtml(name); |
| 2075 | |
| 2076 | // Figure out the size |
| 2077 | var fsize = ''; |
| 2078 | if (f.s != null) { fsize = getFileSizeStr(f.s); } |
| 2079 | |
| 2080 | var h = ''; |
| 2081 | if (f.t < 3) { |
| 2082 | var right = ''; |
| 2083 | 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>' + right + '</span><span title="' + shortname + '"><div class=fileIcon' + f.t + '></div><a style=cursor:pointer onclick=p13folderset("' + encodeURIComponent(f.nx) + '")>' + shortname + '</a></span></div>'; |
| 2084 | } else { |
| 2085 | var link = shortname; |
| 2086 | if (f.s > 0) { link = '<a rel=\"noreferrer noopener\" target=\"_blank\" style=cursor:pointer onclick=\"p13downloadfile(\'' + encodeURIComponent(newlinkpath + '/' + name) + '\',\'' + encodeURIComponent(name) + '\',' + f.s + ')\">' + shortname + '</a>'; } |
| 2087 | h = '<div class=filelist file=3><input file=3 style=float:left name=fd class=fcb type=checkbox onchange=p13setActions() value=\'' + f.nx + '\'> <span style=float:right;padding-right:4px>' + fsize + '</span><span title="' + shortname + '"><div class=fileIcon' + f.t + '></div>' + link + '</span></div>'; |
| 2088 | } |
| 2089 | |
| 2090 | if (f.t < 3) { html1 += h; } else { html2 += h; } |
| 2091 | } |
| 2092 | |
| 2093 | // Display the files and path |
| 2094 | QH('p13files', html1 + html2); |
| 2095 | QH('p13currentpath', displayPath); |
| 2096 | QE('p13FolderUp', p13filetreelocation.length != 0); |
| 2097 | |
| 2098 | // Re-check all boxes if needed using names |
| 2099 | 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; } } } |
| 2100 | |
| 2101 | // Update the actions buttons |
| 2102 | p13setActions(); |
| 2103 | } |
| 2104 | |
| 2105 | function p13folderset(x) { |
| 2106 | p13targetpath = joinPaths(p13filetree.path, p13filetree.dir[x].n).split('\\').join('/'); |
| 2107 | if (files) { |
| 2108 | files.sendText({ action: 'ls', reqid: 1, path: p13targetpath }); |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | function p13folderup(x) { |
| 2113 | if (x == null) { p13filetreelocation.pop(); } else { while (p13filetreelocation.length > x) { p13filetreelocation.pop(); } } |
| 2114 | p13targetpath = p13filetreelocation.join('/'); |
| 2115 | if (files) { |
| 2116 | files.sendText({ action: 'ls', reqid: 1, path: p13targetpath }); |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | var p13sortorder; |
| 2121 | function p13sort_filename(a, b) { if (a.ln > b.ln) return (1 * p13sortorder); if (a.ln < b.ln) return (-1 * p13sortorder); return 0; } |
| 2122 | function p13sort_timestamp(a, b) { if (a.d > b.d) return (1 * p13sortorder); if (a.d < b.d) return (-1 * p13sortorder); return 0; } |
| 2123 | function p13sort_bysize(a, b) { if (a.s == b.s) return p13sort_filename(a, b); return (((a.s - b.s)) * p13sortorder); } |
| 2124 | |
| 2125 | function p13sort_files(files) { |
| 2126 | var r = [], sortselection = Q('p13sortdropdown').value; |
| 2127 | 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]); } |
| 2128 | p13sortorder = 1; |
| 2129 | if (sortselection > 3) { p13sortorder = -1; sortselection -= 3; } |
| 2130 | if (sortselection == 1) { r.sort(p13sort_filename); } |
| 2131 | else if (sortselection == 2) { r.sort(p13sort_bysize); } |
| 2132 | else if (sortselection == 3) { r.sort(p13sort_timestamp); } |
| 2133 | return r; |
| 2134 | } |
| 2135 | |
| 2136 | function p13setActions() { |
| 2137 | var advancedFeatures = true; //((currentNode.agent) && (currentNode.agent.id != 14)); // Reduct file feature on some devices. |
| 2138 | if (p13filetree == null) { |
| 2139 | QE('p13DeleteFileButton', false); |
| 2140 | QE('p13NewFolderButton', false); |
| 2141 | QE('p13UploadButton', false); |
| 2142 | QE('p13RenameFileButton', false); |
| 2143 | QE('p13SelectAllButton', false); |
| 2144 | Q('p13SelectAllButton').value = "All"; |
| 2145 | QE('p13RefreshButton', false); |
| 2146 | QE('p13CutButton', false); |
| 2147 | QE('p13CopyButton', false); |
| 2148 | QE('p13PasteButton', false); |
| 2149 | } else { |
| 2150 | 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) |
| 2151 | var winAgent = true; //((currentNode.agent.id > 0) && (currentNode.agent.id < 5)) || (currentNode.agent.id == 14) || (currentNode.agent.id == 34); |
| 2152 | QE('p13DeleteFileButton', advancedFeatures && (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false))); |
| 2153 | QE('p13NewFolderButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false))); |
| 2154 | QE('p13UploadButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false))); |
| 2155 | QE('p13RenameFileButton', advancedFeatures && (cc == 1) && ((p13filetreelocation.length > 0) || (winAgent == false))); |
| 2156 | QE('p13SelectAllButton', tc > 0); |
| 2157 | Q('p13SelectAllButton').value = (cc > 0 ? "None" : "All"); |
| 2158 | QE('p13RefreshButton', true); |
| 2159 | //QE('p13FindButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false))); |
| 2160 | QE('p13CutButton', advancedFeatures && (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false))); |
| 2161 | QE('p13CopyButton', advancedFeatures && (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false))); |
| 2162 | //QE('p13ZipButton', advancedFeatures && (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false))); |
| 2163 | QE('p13PasteButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false)) && ((p13clipboard != null) && (p13clipboard.length > 0))); |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | 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; } |
| 2168 | 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; } |
| 2169 | function p13getFileCount() { var cc = 0; var checkboxes = document.getElementsByName('fd'); return checkboxes.length; } |
| 2170 | function p13selectallfile() { var nv = (p13getFileSelCount() == 0), checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].checked = nv; } p13setActions(); } |
| 2171 | function p13createfolder() { setDialogMode(2, "New Folder", 3, p13createfolderEx, '<input type=text id=p13renameinput maxlength=64 onkeyup=p13fileNameCheck(event) style=width:100% />'); focusTextBox('p13renameinput'); p13fileNameCheck(); } |
| 2172 | function p13createfolderEx() { files.sendText({ action: 'mkdir', reqid: 1, path: p13filetreelocation.join('/') + '/' + Q('p13renameinput').value }); p13folderup(999); } |
| 2173 | 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)); } |
| 2174 | 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); } |
| 2175 | 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(); } |
| 2176 | function p13renamefileEx(b, t) { t.newname = Q('p13renameinput').value; files.sendText(t); p13folderup(999); } |
| 2177 | function p13fileNameCheck(e) { var x = isFilenameValid(Q('p13renameinput').value); QE('idx_dlgOkButton', x); if ((x == true) && (e != null) && (e.keyCode == 13)) { dialogclose(1); } } |
| 2178 | 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'); } |
| 2179 | function p13uploadFileEx() { p13doUploadFiles(Q('p13uploadinput').files); } |
| 2180 | function p13viewfile() { |
| 2181 | var checkboxes = document.getElementsByName('fd'); |
| 2182 | for (var i = 0; i < checkboxes.length; i++) { |
| 2183 | if (checkboxes[i].checked) { |
| 2184 | if (p13filetree.dir[checkboxes[i].value].s <= 204800) { |
| 2185 | p13downloadfile(encodeURIComponent(p13filetreelocation.join('/') + '/' + p13filetree.dir[checkboxes[i].value].n), encodeURIComponent(p13filetree.dir[checkboxes[i].value].n), p13filetree.dir[checkboxes[i].value].s, 'viewer'); |
| 2186 | } else { messagebox("File Editor", "Only files less than 200k can be edited."); } |
| 2187 | break; |
| 2188 | } |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | var p13clipboard = null, p13clipboardFolder = null, p13clipboardCut = 0; |
| 2193 | 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(); } |
| 2194 | function p13pasteFile() { |
| 2195 | var x = ''; |
| 2196 | if ((p13clipboard != null) && (p13clipboard.length > 0)) { |
| 2197 | if (p13clipboardCut == 0) { |
| 2198 | if (p13clipboard.length > 1) { x = format("Confirm copy of {0} entries's to this location?", p13clipboard.length); } else { x = format("Confirm copy of 1 entrie to this location?"); } |
| 2199 | } else { |
| 2200 | if (p13clipboard.length > 1) { x = format("Confirm move of {0} entries's to this location?", p13clipboard.length); } else { x = format("Confirm move of 1 entrie to this location?"); } |
| 2201 | } |
| 2202 | } |
| 2203 | setDialogMode(2, "Paste", 3, p13pasteFileEx, x); |
| 2204 | } |
| 2205 | 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(); } } |
| 2206 | function p13updateClipview() { |
| 2207 | var x = ''; |
| 2208 | if ((p13clipboard != null) && (p13clipboard.length > 0)) { |
| 2209 | if (p13clipboardCut == 0) { |
| 2210 | if (p13clipboard.length > 1) { |
| 2211 | x = format("Holding {0} entries for copy" + ', <a href=# onclick="return p13clearClip()" style=cursor:pointer>' + "Clear" + '</a>.', p13clipboard.length); |
| 2212 | } else { |
| 2213 | x = format("Holding 1 entrie for copy" + ', <a href=# onclick="return p13clearClip()" style=cursor:pointer>' + "Clear" + '</a>.'); |
| 2214 | } |
| 2215 | } else { |
| 2216 | if (p13clipboard.length > 1) { |
| 2217 | x = format("Holding {0} entries for move" + ', <a href=# onclick="return p13clearClip()" style=cursor:pointer>' + "Clear" + '</a>.', p13clipboard.length); |
| 2218 | } else { |
| 2219 | x = format("Holding 1 entrie for move" + ', <a href=# onclick="return p13clearClip()" style=cursor:pointer>' + "Clear" + '</a>.'); |
| 2220 | } |
| 2221 | } |
| 2222 | } |
| 2223 | QH('p13bottomstatus', x); |
| 2224 | p13setActions(); |
| 2225 | } |
| 2226 | function p13clearClip() { p13clipboard = null; p13clipboardFolder = null; p13clipboardCut = 0; p13updateClipview(); return false; } function updateUploadDialogOk(x) { QE('idx_dlgOkButton', Q(x).value != ''); } |
| 2227 | function getFileSelCount(includeDirs) { var cc = 0; var checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && ((includeDirs != false) || (checkboxes[i].attributes.file.value == "3"))) cc++; } return cc; } |
| 2228 | function getFileCount() { var cc = 0; var checkboxes = document.getElementsByName('fc'); return checkboxes.length; } |
| 2229 | |
| 2230 | // |
| 2231 | // FILES DOWNLOAD |
| 2232 | // |
| 2233 | |
| 2234 | var downloadFile; // Global state for file download |
| 2235 | |
| 2236 | // Called by the html page to start a download, arguments are: path, file name and file size. |
| 2237 | function p13downloadfile(x, y, z) { |
| 2238 | if (xxdialogMode || downloadFile || !files) return; |
| 2239 | downloadFile = { path: decodeURIComponent(x), file: decodeURIComponent(y), size: z, tsize: 0, data: '', state: 0, id: Math.random() } |
| 2240 | //console.log('p13downloadFileCancel', downloadFile); |
| 2241 | files.sendText({ action: 'download', sub: 'start', id: downloadFile.id, path: downloadFile.path }); |
| 2242 | setDialogMode(2, "Download File", 10, p13downloadFileCancel, '<div>' + downloadFile.file + '</div><br /><progress id=d2progressBar style=width:100% value=0 max=' + z + ' />'); |
| 2243 | } |
| 2244 | |
| 2245 | // Called by the html page to cancel the download |
| 2246 | function p13downloadFileCancel() { setDialogMode(0); files.sendText({ action: 'download', sub: 'cancel', id: downloadFile.id }); downloadFile = null; } |
| 2247 | |
| 2248 | // Called by the transport when download control command is received |
| 2249 | function p13gotDownloadCommand(cmd) { |
| 2250 | //console.log('p13gotDownloadCommand', cmd); |
| 2251 | if ((downloadFile == null) || (cmd.id != downloadFile.id)) return; |
| 2252 | if (cmd.sub == 'start') { downloadFile.state = 1; files.sendText({ action: 'download', sub: 'startack', id: downloadFile.id }); } |
| 2253 | else if (cmd.sub == 'cancel') { downloadFile = null; setDialogMode(0); } |
| 2254 | } |
| 2255 | |
| 2256 | // Called by the transport when binary data is received |
| 2257 | function p13gotDownloadBinaryData(data) { |
| 2258 | if (!downloadFile || downloadFile.state == 0) return; |
| 2259 | if (data.length > 4) { |
| 2260 | downloadFile.tsize += (data.length - 4); // Add to the total bytes received |
| 2261 | downloadFile.data += data.substring(4); // Append the data |
| 2262 | Q('d2progressBar').value = downloadFile.tsize; // Change the progress bar |
| 2263 | } |
| 2264 | if ((ReadInt(data, 0) & 1) != 0) { // Check end flag |
| 2265 | saveAs(data2blob(downloadFile.data), downloadFile.file); downloadFile = null; setDialogMode(0); // Save the file |
| 2266 | } else { |
| 2267 | files.sendText({ action: 'download', sub: 'ack', id: downloadFile.id }); // Send the ACK |
| 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | |
| 2272 | // |
| 2273 | // FILES UPLOAD |
| 2274 | // |
| 2275 | |
| 2276 | var uploadFile; |
| 2277 | function p13doUploadFiles(files) { |
| 2278 | if (xxdialogMode) return; |
| 2279 | |
| 2280 | // Check if we are going to overwrite any files |
| 2281 | var winAgent = true; //((currentNode.agent.id > 0) && (currentNode.agent.id < 5)) || (currentNode.agent.id == 14) || (currentNode.agent.id == 34); |
| 2282 | var targetFiles = [], overWriteCount = 0; |
| 2283 | for (var i in p13filetree.dir) { if (winAgent) { targetFiles.push(p13filetree.dir[i].n.toLowerCase()); } else { targetFiles.push(p13filetree.dir[i].n); } } |
| 2284 | for (var i = 0; i < files.length; i++) { |
| 2285 | if (winAgent) { |
| 2286 | if (targetFiles.indexOf(files[i].name.toLowerCase()) >= 0) { overWriteCount++; } |
| 2287 | } else { |
| 2288 | if (targetFiles.indexOf(files[i].name) >= 0) { overWriteCount++; } |
| 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | if (overWriteCount == 0) { |
| 2293 | // If no overwrite, go ahead with upload |
| 2294 | p13uploadFileContinue(1, files); |
| 2295 | } else { |
| 2296 | // Otherwise, prompt for confirmation |
| 2297 | setDialogMode(2, "Upload File", 3, p13uploadFileContinue, format((overWriteCount == 1) ? "Upload will overwrite 1 file. Continue?" : "Upload will overwrite {0} files. Continue?", overWriteCount), files); |
| 2298 | } |
| 2299 | } |
| 2300 | |
| 2301 | function p13uploadFileContinue(b, files) { |
| 2302 | uploadFile = {}; |
| 2303 | uploadFile.xpath = p13filetreelocation.join('/'); |
| 2304 | uploadFile.xfiles = files; |
| 2305 | uploadFile.xfilePtr = -1; |
| 2306 | setDialogMode(2, "Upload File", 10, p13uploadFileCancel, '<div id=p13dfileName>' + "Connecting..." + '</div><br /><progress id=d2progressBar style=width:100% value=0 max=0 />'); |
| 2307 | p13uploadNextFile(); |
| 2308 | } |
| 2309 | |
| 2310 | // Perform SHA-384 hashing |
| 2311 | const byteToHex = []; |
| 2312 | for (var n = 0; n <= 0xff; ++n) { var hexOctet = n.toString(16).padStart(2, '0'); byteToHex.push(hexOctet); } |
| 2313 | function arrayBufferToHex(arrayBuffer) { return Array.prototype.map.call(new Uint8Array(arrayBuffer), n => byteToHex[n]).join(''); } |
| 2314 | function performHash(data, f) { window.crypto.subtle.digest('SHA-384', data).then(function (v) { f(arrayBufferToHex(v)); }, function () { f(null); }); } |
| 2315 | function performHashOnFile(file, f) { |
| 2316 | // TODO: At some point, try to make this work for files of unlimited size using a digest stream |
| 2317 | var reader = new FileReader(); |
| 2318 | reader.onerror = function (err) { f(null); } |
| 2319 | reader.onload = function () { window.crypto.subtle.digest('SHA-384', reader.result).then(function (v) { f(arrayBufferToHex(v)); }, function () { f(null); }); }; |
| 2320 | reader.readAsArrayBuffer(file); |
| 2321 | } |
| 2322 | |
| 2323 | // Push the next file |
| 2324 | function p13uploadNextFile() { |
| 2325 | uploadFile.xfilePtr++; |
| 2326 | if (uploadFile.xfiles.length > uploadFile.xfilePtr) { |
| 2327 | uploadFile.xptr = 0; |
| 2328 | var file = uploadFile.xfiles[uploadFile.xfilePtr]; |
| 2329 | QH('p13dfileName', file.name); |
| 2330 | Q('d2progressBar').max = file.size; |
| 2331 | Q('d2progressBar').value = 0; |
| 2332 | if (file.xdata == null) { |
| 2333 | uploadFile.xfile = file; |
| 2334 | // If the remote file already exists and is smaller then our file, see if we can resume the trasfer |
| 2335 | var f = null; |
| 2336 | for (var i in p13filetree.dir) { if (p13filetree.dir[i].n == file.name) { f = p13filetree.dir[i]; } } |
| 2337 | if ((f != null) && (f.s <= uploadFile.xfile.size)) { |
| 2338 | performHashOnFile(uploadFile.xfile, function (hash) { 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.xfile.size } })); }); |
| 2339 | } else { |
| 2340 | files.sendText(JSON.stringify({ action: 'upload', reqid: uploadFile.xfilePtr, path: uploadFile.xpath, name: file.name, size: uploadFile.xfile.size })); |
| 2341 | } |
| 2342 | } else { |
| 2343 | // Data already loaded |
| 2344 | uploadFile.xdata = file.xdata; |
| 2345 | files.sendText(JSON.stringify({ action: 'upload', reqid: uploadFile.xfilePtr, path: uploadFile.xpath, name: file.name, size: uploadFile.xdata.byteLength })); |
| 2346 | } |
| 2347 | } else { |
| 2348 | p13uploadFileTransferDone(); |
| 2349 | } |
| 2350 | } |
| 2351 | |
| 2352 | // Used to cancel the entire transfer. |
| 2353 | function p13uploadFileCancel(button, tag) { |
| 2354 | if (uploadFile != null) { files.sendText(JSON.stringify({ action: 'uploadcancel', reqid: uploadFile.xfilePtr })); uploadFile = null; } |
| 2355 | p13uploadFileTransferDone(); |
| 2356 | } |
| 2357 | |
| 2358 | // Used to cancel the entire transfer. |
| 2359 | function p13uploadFileTransferDone() { |
| 2360 | uploadFile = null; // No more files to upload, clean up. |
| 2361 | setDialogMode(0); // Close the dialog box |
| 2362 | p13folderup(9999); // Refresh the current folder |
| 2363 | } |
| 2364 | |
| 2365 | // Receive upload ack from the mesh agent, use this to keep sending more data |
| 2366 | function p13gotUploadData(cmd) { |
| 2367 | if ((uploadFile == null) || (parseInt(uploadFile.xfilePtr) != parseInt(cmd.reqid))) { return; } |
| 2368 | switch (cmd.action) { |
| 2369 | case 'uploadstart': { uploadFile.xdataPriming = 8; p13uploadNextPart(false); break; } // Send 8 more blocks of 16k to fill the websocket. |
| 2370 | case 'uploadack': { p13uploadNextPart(false); break; } |
| 2371 | case 'uploaddone': { if (uploadFile.xfiles.length > uploadFile.xfilePtr + 1) { p13uploadNextFile(); } else { p13uploadFileTransferDone(); } break; } |
| 2372 | case 'uploaderror': { p13uploadFileCancel(); break; } |
| 2373 | case 'uploadhash': { |
| 2374 | var file = uploadFile.xfiles[uploadFile.xfilePtr]; |
| 2375 | if (file) { |
| 2376 | if (cmd.tag.h === cmd.hash) { |
| 2377 | if (cmd.tag.skip) { |
| 2378 | p13uploadNextFile(); |
| 2379 | } else { |
| 2380 | uploadFile.xptr = cmd.tag.s; |
| 2381 | files.sendText(JSON.stringify({ action: 'upload', reqid: uploadFile.xfilePtr, path: uploadFile.xpath, name: file.name, size: uploadFile.xfile.size, append: true })); |
| 2382 | } |
| 2383 | } else { |
| 2384 | files.sendText(JSON.stringify({ action: 'upload', reqid: uploadFile.xfilePtr, path: uploadFile.xpath, name: file.name, size: uploadFile.xfile.size, append: false })); |
| 2385 | } |
| 2386 | } |
| 2387 | break; |
| 2388 | } |
| 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | // 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. |
| 2393 | function p13uploadNextPart(dataPriming) { |
| 2394 | if (uploadFile.xreader != null) return; // Data reading already in process |
| 2395 | if (uploadFile.xptr >= uploadFile.xfile.size) return; |
| 2396 | var end = uploadFile.xptr + 65536; |
| 2397 | if (end > uploadFile.xfile.size) { if (dataPriming == true) { return; } end = uploadFile.xfile.size; } |
| 2398 | uploadFile.xreader = new FileReader(); |
| 2399 | uploadFile.xreader.onerror = function (err) { console.log(err); } |
| 2400 | uploadFile.xreader.onload = function () { |
| 2401 | var data = uploadFile.xreader.result; |
| 2402 | delete uploadFile.xreader; |
| 2403 | if (data == null) return; |
| 2404 | var dataslice = new Uint8Array(data) |
| 2405 | if ((dataslice[0] == 123) || (dataslice[0] == 0)) { |
| 2406 | var datapart = new Uint8Array(data.byteLength + 1); |
| 2407 | datapart.set(dataslice, 1); // Add a zero char at the start of the send, this will indicate that it's not a JSON command. |
| 2408 | files.send(datapart); |
| 2409 | } else { |
| 2410 | files.send(dataslice); // The data does not start with 0 or 123 "{" so it can't be confused for JSON. |
| 2411 | } |
| 2412 | uploadFile.xptr = end; |
| 2413 | Q('d2progressBar').value = end; |
| 2414 | if (uploadFile.xptr >= uploadFile.xfile.size) { |
| 2415 | files.sendText(JSON.stringify({ action: 'uploaddone', reqid: uploadFile.xfilePtr })); |
| 2416 | } else { |
| 2417 | if (uploadFile.xdataPriming > 0) { uploadFile.xdataPriming--; p13uploadNextPart(true); } |
| 2418 | } |
| 2419 | }; |
| 2420 | uploadFile.xreader.readAsArrayBuffer(uploadFile.xfile.slice(uploadFile.xptr, end)); |
| 2421 | } |
| 2422 | |
| 2423 | // |
| 2424 | // PANELS |
| 2425 | // |
| 2426 | |
| 2427 | var xxcurrentView = -1; |
| 2428 | function go(x) { |
| 2429 | setSessionActivity(); |
| 2430 | if (xxdialogMode || xxcurrentView == x) return; |
| 2431 | updateFooterMenu(); |
| 2432 | setDialogMode(0); |
| 2433 | // Edit this line when adding a new screen |
| 2434 | for (var i = 0; i < 32; i++) { QV('p' + i, i == x); } |
| 2435 | xxcurrentView = x; |
| 2436 | } |
| 2437 | |
| 2438 | // |
| 2439 | // POPUP DIALOG |
| 2440 | // |
| 2441 | |
| 2442 | // undefined = Hidden, 1 = Generic Message |
| 2443 | var xxdialogMode; |
| 2444 | var xxdialogFunc; |
| 2445 | var xxdialogButtons; |
| 2446 | var xxdialogTag; |
| 2447 | |
| 2448 | // Display a dialog box |
| 2449 | // 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) |
| 2450 | function setDialogMode(x, y, b, f, c, tag) { |
| 2451 | setSessionActivity(); |
| 2452 | xxdialogMode = x; |
| 2453 | xxdialogFunc = f; |
| 2454 | xxdialogButtons = b; |
| 2455 | xxdialogTag = tag; |
| 2456 | QE('idx_dlgOkButton', true); |
| 2457 | QV('idx_dlgOkButton', b & 1); |
| 2458 | QV('idx_dlgCancelButton', b & 2); |
| 2459 | QV('id_dialogclose', (b & 2) || (b & 8)); |
| 2460 | QV('idx_dlgDeleteButton', b & 4); |
| 2461 | QV('idx_dlgButtonBar', b & 7); |
| 2462 | if (y) QH('id_dialogtitle', y); |
| 2463 | for (var i = 1; i < 24; i++) { QV('dialog' + i, i == x); } // Edit this line when more dialogs are added |
| 2464 | QV('dialog', x); |
| 2465 | if (c) { if (x == 2) { QH('id_dialogOptions', c); } else { QH('id_dialogMessage', c); } } |
| 2466 | } |
| 2467 | |
| 2468 | function dialogclose(x) { |
| 2469 | setSessionActivity(); |
| 2470 | var f = xxdialogFunc; |
| 2471 | var b = xxdialogButtons; |
| 2472 | var t = xxdialogTag; |
| 2473 | setDialogMode(); |
| 2474 | if (((b & 8) || x) && f) f(x, t); |
| 2475 | } |
| 2476 | |
| 2477 | |
| 2478 | // |
| 2479 | // Generic Methods |
| 2480 | // |
| 2481 | |
| 2482 | 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); } |
| 2483 | 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); } } } } |
| 2484 | 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; } } |
| 2485 | function center() { if (xtermfit) xtermfit.fit(); QS('dialog').left = ((((getDocWidth() - 300) / 2)) + 'px'); deskAdjust(); } |
| 2486 | function messagebox(t, m) { QH('id_dialogMessage', m); setDialogMode(1, t, 1); } |
| 2487 | function statusbox(t, m) { QH('id_dialogMessage', m); setDialogMode(1, t); } |
| 2488 | 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; } |
| 2489 | function haltEvent(e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; } |
| 2490 | function haltReturn(e) { if (e.keyCode == 13) { haltEvent(e); } } |
| 2491 | function validateEmail(v) { var emailReg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return emailReg.test(v); } |
| 2492 | function reload() { window.location.href = window.location.href; } |
| 2493 | function getNodeFromId(id) { for (var i in nodes) { if (nodes[i]._id == id) return nodes[i]; } return null; } |
| 2494 | function addHtmlValue(t, v) { return '<table><td style=width:120px>' + t + '<td><b>' + v + '</b></table>'; } |
| 2495 | function addHtmlValue2(t, v) { return '<div><div style=display:inline-block;float:right>' + v + '</div><div style=display:inline-block>' + t + '</div></div>'; } |
| 2496 | function addHtmlValue4(t, v) { return '<table style=width:100%><td style=width:120px>' + t + '<td style=text-align:right><b>' + v + '</b></table>'; } |
| 2497 | function addLink(x, f) { return '<a style=cursor:pointer;text-decoration:none onclick=\'' + f + '\'>♦ ' + x + '</a>'; } |
| 2498 | function addLinkConditional(x, f, c) { if (c) return addLink(x, f); return x; } |
| 2499 | function passwordcheck(p) { var re = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()]).{8,}/; return re.test(p); } |
| 2500 | function getFileSizeStr(size) { if (typeof size != 'number') { size = 0; } if (size == 1) return "1 byte"; return format('{0} bytes', size); } |
| 2501 | function focusTextBox(x) { setTimeout(function () { Q(x).selectionStart = Q(x).selectionEnd = 65535; Q(x).focus(); }, 0); } |
| 2502 | 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] != '.'); } })(); |
| 2503 | function printDate(d) { return d.toLocaleDateString(args.locale); } |
| 2504 | function printTime(d) { return d.toLocaleTimeString(args.locale); } |
| 2505 | function printDateTime(d) { return d.toLocaleString(args.locale); } |
| 2506 | 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; }); }; |
| 2507 | function nobreak(x) { return x.split(' ').join(' '); } |
| 2508 | function getUserName(userid) { if (users && users[userid] != null) return users[userid].name; return userid.split('/')[2]; } |
| 2509 | function addDetailItem(title, value, state) { return '<table style=width:100%><td>' + nobreak(title) + '<td style=text-align:right>' + value + '</table>'; } |
| 2510 | function isPrivateIP(a) { return (a.startsWith('10.') || a.startsWith('172.16.') || a.startsWith('192.168.')); } |
| 2511 | function encodeURIComponentEx(txt) { return encodeURIComponent(txt).replace(/'/g, '%27'); }; |
| 2512 | function safeNewWindow(url, target) { var newWindow = window.open(url, target, 'noopener,noreferrer'); if (newWindow) { newWindow.opener = null; } } |
| 2513 | |
| 2514 | </script> |
| 2515 | </body> |
| 2516 | </html> |