]> git.proxmox.com Git - novnc-pve.git/blob - debian/patches/pveui.patch
fix height on resize
[novnc-pve.git] / debian / patches / pveui.patch
1 From 280c1f8b3c07fde35282cd46d965bc1bc8f5649d Mon Sep 17 00:00:00 2001
2 From: Alexandre Derumier <aderumier@odiso.com>
3 Date: Thu, 25 Jun 2015 02:50:03 +0200
4 Subject: [PATCH] pveui : add promox code
5
6 Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
7 ---
8 pveui.js | 724 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
9 1 file changed, 675 insertions(+), 49 deletions(-)
10
11 diff --git a/pveui.js b/pveui.js
12 index cb5717c..ceaa4fc 100644
13 --- a/pveui.js
14 +++ b/pveui.js
15 @@ -39,10 +39,17 @@ var UI;
16 isTouchDevice: false,
17 rememberedClipSetting: null,
18
19 + pveAllowMigratedVMTest: false, // set to true after a succesful conection
20 + pveCommandsOpen: false,
21 + consoletype: undefined,
22 + vmid: undefined,
23 + vmname: undefined,
24 + nodename: undefined,
25 + resize: undefined,
26 // Setup rfb object, load settings from browser storage, then call
27 // UI.init to setup the UI/menus
28 load: function (callback) {
29 - WebUtil.initSettings(UI.start, callback);
30 + WebUtil.initSettings(UI.pve_start, callback);
31 },
32
33 // Render default UI and initialize settings menu
34 @@ -54,13 +61,13 @@ var UI;
35 var sheets = WebUtil.getStylesheets();
36 var i;
37 for (i = 0; i < sheets.length; i += 1) {
38 - UI.addOption($D('noVNC_stylesheet'),sheets[i].title, sheets[i].title);
39 + //UI.addOption($D('noVNC_stylesheet'),sheets[i].title, sheets[i].title);
40 }
41
42 // Logging selection dropdown
43 var llevels = ['error', 'warn', 'info', 'debug'];
44 for (i = 0; i < llevels.length; i += 1) {
45 - UI.addOption($D('noVNC_logging'),llevels[i], llevels[i]);
46 + //UI.addOption($D('noVNC_logging'),llevels[i], llevels[i]);
47 }
48
49 // Settings with immediate effects
50 @@ -84,20 +91,10 @@ var UI;
51 }
52 }
53
54 - /* Populate the controls if defaults are provided in the URL */
55 - UI.initSetting('host', window.location.hostname);
56 - UI.initSetting('port', port);
57 - UI.initSetting('password', '');
58 - UI.initSetting('encrypt', (window.location.protocol === "https:"));
59 - UI.initSetting('true_color', true);
60 - UI.initSetting('cursor', !UI.isTouchDevice);
61 - UI.initSetting('resize', 'off');
62 - UI.initSetting('shared', true);
63 - UI.initSetting('view_only', false);
64 - UI.initSetting('path', 'websockify');
65 +
66 UI.initSetting('repeaterID', '');
67
68 - var autoconnect = WebUtil.getQueryVar('autoconnect', false);
69 + var autoconnect = true;
70 if (autoconnect === 'true' || autoconnect == '1') {
71 autoconnect = true;
72 UI.connect();
73 @@ -140,7 +137,9 @@ var UI;
74 (document.documentElement.requestFullscreen ||
75 document.documentElement.mozRequestFullScreen ||
76 document.documentElement.webkitRequestFullscreen ||
77 - document.body.msRequestFullscreen)) {
78 + document.body.msRequestFullscreen)
79 + && UI.getSetting('resize') === 'scale'
80 + ) {
81 $D('fullscreenButton').style.display = "inline";
82 Util.addEvent(window, 'fullscreenchange', UI.updateFullscreenButton);
83 Util.addEvent(window, 'mozfullscreenchange', UI.updateFullscreenButton);
84 @@ -177,13 +176,16 @@ var UI;
85
86 initRFB: function () {
87 try {
88 + var scaleType = UI.getSetting('resize');
89 +
90 UI.rfb = new RFB({'target': $D('noVNC_canvas'),
91 'onUpdateState': UI.updateState,
92 'onXvpInit': UI.updateXvpVisualState,
93 'onClipboard': UI.clipReceive,
94 'onFBUComplete': UI.FBUComplete,
95 - 'onFBResize': UI.updateViewDrag,
96 - 'onDesktopName': UI.updateDocumentTitle});
97 + 'onFBResize': (typeof scaleType !== 'undefined') ? UI.updateFBSize : UI.updateViewDrag
98 + // 'onDesktopName': UI.updateDocumentTitle
99 + });
100 return true;
101 } catch (exc) {
102 UI.updateState(null, 'fatal', null, 'Unable to create RFB client -- ' + exc);
103 @@ -211,31 +213,34 @@ var UI;
104 $D("sendEscButton").onclick = UI.sendEsc;
105
106 $D("sendCtrlAltDelButton").onclick = UI.sendCtrlAltDel;
107 - $D("xvpShutdownButton").onclick = UI.xvpShutdown;
108 - $D("xvpRebootButton").onclick = UI.xvpReboot;
109 - $D("xvpResetButton").onclick = UI.xvpReset;
110 - $D("noVNC_status").onclick = UI.togglePopupStatus;
111 + //$D("xvpShutdownButton").onclick = UI.xvpShutdown;
112 + //$D("xvpRebootButton").onclick = UI.xvpReboot;
113 + //$D("xvpResetButton").onclick = UI.xvpReset;
114 + //$D("noVNC_status").onclick = UI.togglePopupStatus;
115 $D("noVNC_popup_status").onclick = UI.togglePopupStatus;
116 - $D("xvpButton").onclick = UI.toggleXvpPanel;
117 + //$D("xvpButton").onclick = UI.toggleXvpPanel;
118 $D("clipboardButton").onclick = UI.toggleClipboardPanel;
119 $D("fullscreenButton").onclick = UI.toggleFullscreen;
120 - $D("settingsButton").onclick = UI.toggleSettingsPanel;
121 - $D("connectButton").onclick = UI.toggleConnectPanel;
122 - $D("disconnectButton").onclick = UI.disconnect;
123 - $D("descriptionButton").onclick = UI.toggleConnectPanel;
124 + //$D("settingsButton").onclick = UI.toggleSettingsPanel;
125 + //$D("connectButton").onclick = UI.toggleConnectPanel;
126 + //$D("disconnectButton").onclick = UI.disconnect;
127 + //$D("descriptionButton").onclick = UI.toggleConnectPanel;
128
129 $D("noVNC_clipboard_text").onfocus = UI.displayBlur;
130 $D("noVNC_clipboard_text").onblur = UI.displayFocus;
131 $D("noVNC_clipboard_text").onchange = UI.clipSend;
132 $D("noVNC_clipboard_clear_button").onclick = UI.clipClear;
133
134 - $D("noVNC_settings_menu").onmouseover = UI.displayBlur;
135 - $D("noVNC_settings_menu").onmouseover = UI.displayFocus;
136 - $D("noVNC_apply").onclick = UI.settingsApply;
137 + //$D("noVNC_settings_menu").onmouseover = UI.displayBlur;
138 + //$D("noVNC_settings_menu").onmouseover = UI.displayFocus;
139 + //$D("noVNC_apply").onclick = UI.settingsApply;
140
141 - $D("noVNC_connect_button").onclick = UI.connect;
142 + //$D("noVNC_connect_button").onclick = UI.connect;
143
144 $D("noVNC_resize").onchange = UI.enableDisableViewClip;
145 +
146 + $D("pveCommandsButton").onclick = UI.togglePVECommandPanel;
147 + $D("showSendKeysButton").onclick = UI.togglePVESendKeysPanel;
148 },
149
150 onresize: function (callback) {
151 @@ -398,6 +403,9 @@ var UI;
152 toggleXvpPanel: function() {
153 // Close the description panel
154 $D('noVNC_description').style.display = "none";
155 + if (UI.pveCommandsOpen === true) {
156 + UI.togglePVECommandPanel();
157 + }
158 // Close settings if open
159 if (UI.settingsOpen === true) {
160 UI.settingsApply();
161 @@ -413,12 +421,12 @@ var UI;
162 }
163 // Toggle XVP panel
164 if (UI.xvpOpen === true) {
165 - $D('noVNC_xvp').style.display = "none";
166 - $D('xvpButton').className = "noVNC_status_button";
167 + //$D('noVNC_xvp').style.display = "none";
168 + //$D('xvpButton').className = "noVNC_status_button";
169 UI.xvpOpen = false;
170 } else {
171 - $D('noVNC_xvp').style.display = "block";
172 - $D('xvpButton').className = "noVNC_status_button_selected";
173 + //$D('noVNC_xvp').style.display = "block";
174 + //$D('xvpButton').className = "noVNC_status_button_selected";
175 UI.xvpOpen = true;
176 }
177 },
178 @@ -427,6 +435,12 @@ var UI;
179 toggleClipboardPanel: function() {
180 // Close the description panel
181 $D('noVNC_description').style.display = "none";
182 + if (UI.pveCommandsOpen === true) {
183 + UI.togglePVECommandPanel();
184 + }
185 + if (UI.sendKeysVisible === true) {
186 + UI.togglePVESendKeysPanel();
187 + }
188 // Close settings if open
189 if (UI.settingsOpen === true) {
190 UI.settingsApply();
191 @@ -497,6 +511,9 @@ var UI;
192 toggleConnectPanel: function() {
193 // Close the description panel
194 $D('noVNC_description').style.display = "none";
195 + if (UI.pveCommandsOpen === true) {
196 + UI.togglePVECommandPanel();
197 + }
198 // Close connection settings if open
199 if (UI.settingsOpen === true) {
200 UI.settingsApply();
201 @@ -515,14 +532,14 @@ var UI;
202 // Toggle Connection Panel
203 if (UI.connSettingsOpen === true) {
204 $D('noVNC_controls').style.display = "none";
205 - $D('connectButton').className = "noVNC_status_button";
206 + //$D('connectButton').className = "noVNC_status_button";
207 UI.connSettingsOpen = false;
208 UI.saveSetting('host');
209 UI.saveSetting('port');
210 //UI.saveSetting('password');
211 } else {
212 $D('noVNC_controls').style.display = "block";
213 - $D('connectButton').className = "noVNC_status_button_selected";
214 + //$D('connectButton').className = "noVNC_status_button_selected";
215 UI.connSettingsOpen = true;
216 $D('noVNC_host').focus();
217 }
218 @@ -576,14 +593,14 @@ var UI;
219 UI.toggleXvpPanel();
220 }
221 $D('noVNC_settings').style.display = "block";
222 - $D('settingsButton').className = "noVNC_status_button_selected";
223 + //$D('settingsButton').className = "noVNC_status_button_selected";
224 UI.settingsOpen = true;
225 },
226
227 // Close menu (without applying settings)
228 closeSettingsMenu: function() {
229 $D('noVNC_settings').style.display = "none";
230 - $D('settingsButton').className = "noVNC_status_button";
231 + //$D('settingsButton').className = "noVNC_status_button";
232 UI.settingsOpen = false;
233 },
234
235 @@ -676,10 +693,15 @@ var UI;
236 break;
237 case 'normal':
238 klass = "noVNC_status_normal";
239 + UI.pveAllowMigratedVMTest = true;
240 break;
241 case 'disconnected':
242 $D('noVNC_logo').style.display = "block";
243 $D('noVNC_container').style.display = "none";
244 + if (UI.pveAllowMigratedVMTest) {
245 + UI.pveAllowMigratedVMTest = false;
246 + UI.pve_detect_migrated_vm();
247 + }
248 /* falls through */
249 case 'loaded':
250 klass = "noVNC_status_normal";
251 @@ -730,7 +752,7 @@ var UI;
252 if (connected) {
253 UI.setViewClip();
254 UI.setMouseButton(1);
255 - $D('clipboardButton').style.display = "inline";
256 + $D('clipboardButton').style.display = (UI.consoletype !== 'kvm') ? "inline" : "none";
257 $D('showKeyboard').style.display = "inline";
258 $D('noVNC_extra_keys').style.display = "";
259 $D('sendCtrlAltDelButton').style.display = "inline";
260 @@ -751,18 +773,18 @@ var UI;
261 case 'fatal':
262 case 'failed':
263 case 'disconnected':
264 - $D('connectButton').style.display = "";
265 - $D('disconnectButton').style.display = "none";
266 + //$D('connectButton').style.display = "";
267 + //$D('disconnectButton').style.display = "none";
268 UI.connSettingsOpen = false;
269 UI.toggleConnectPanel();
270 break;
271 case 'loaded':
272 - $D('connectButton').style.display = "";
273 - $D('disconnectButton').style.display = "none";
274 + //$D('connectButton').style.display = "";
275 + //$D('disconnectButton').style.display = "none";
276 break;
277 default:
278 - $D('connectButton').style.display = "none";
279 - $D('disconnectButton').style.display = "";
280 + //$D('connectButton').style.display = "none";
281 + //$D('disconnectButton').style.display = "";
282 break;
283 }
284
285 @@ -772,9 +794,9 @@ var UI;
286 // Disable/enable XVP button
287 updateXvpVisualState: function(ver) {
288 if (ver >= 1) {
289 - $D('xvpButton').style.display = 'inline';
290 + //$D('xvpButton').style.display = 'inline';
291 } else {
292 - $D('xvpButton').style.display = 'none';
293 + //$D('xvpButton').style.display = 'none';
294 // Close XVP panel if open
295 if (UI.xvpOpen === true) {
296 UI.toggleXvpPanel();
297 @@ -1200,7 +1222,611 @@ var UI;
298
299 var vncwidth = $D('noVNC_screen').style.offsetWidth;
300 $D('noVNC-control-bar').style.width = vncwidth + 'px';
301 - }
302 + },
303 + // Proxmox VE related code
304 +
305 + urlEncode: function(object) {
306 + var i,value, params = [];
307 +
308 + for (i in object) {
309 + if (object.hasOwnProperty(i)) {
310 + value = object[i];
311 + if (value === undefined) value = '';
312 + params.push(encodeURIComponent(i) + '=' + encodeURIComponent(String(value)));
313 + }
314 + }
315 +
316 + return params.join('&');
317 + },
318 +
319 + API2Request: function(reqOpts) {
320 +
321 + reqOpts.method = reqOpts.method || 'GET';
322 +
323 + var xhr = new XMLHttpRequest();
324 +
325 + xhr.onload = function() {
326 + var scope = reqOpts.scope || this;
327 + var result;
328 + var errmsg;
329 +
330 + if (xhr.readyState === 4) {
331 + var ctype = xhr.getResponseHeader('Content-Type');
332 + if (xhr.status === 200) {
333 + if (ctype.match(/application\/json;/)) {
334 + result = JSON.parse(xhr.responseText);
335 + } else {
336 + errmsg = 'got unexpected content type ' + ctype;
337 + }
338 + } else {
339 + errmsg = 'Error ' + xhr.status + ': ' + xhr.statusText;
340 + }
341 + } else {
342 + errmsg = 'Connection error - server offline?';
343 + }
344 +
345 + if (errmsg !== undefined) {
346 + if (reqOpts.failure) {
347 + reqOpts.failure.call(scope, errmsg);
348 + }
349 + } else {
350 + if (reqOpts.success) {
351 + reqOpts.success.call(scope, result);
352 + }
353 + }
354 + if (reqOpts.callback) {
355 + reqOpts.callback.call(scope, errmsg === undefined);
356 + }
357 + }
358 +
359 + var data = UI.urlEncode(reqOpts.params || {});
360 +
361 + if (reqOpts.method === 'GET') {
362 + xhr.open(reqOpts.method, "/api2/json" + reqOpts.url + '?' + data);
363 + } else {
364 + xhr.open(reqOpts.method, "/api2/json" + reqOpts.url);
365 + }
366 + xhr.setRequestHeader('Cache-Control', 'no-cache');
367 + if (reqOpts.method === 'POST' || reqOpts.method === 'PUT') {
368 + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
369 + xhr.setRequestHeader('CSRFPreventionToken', PVE.CSRFPreventionToken);
370 + xhr.send(data);
371 + } else if (reqOpts.method === 'GET') {
372 + xhr.send();
373 + } else {
374 + throw "unknown method";
375 + }
376 +
377 +
378 + },
379 +
380 + // show msg for 5 seconds
381 + pve_show_msg: function(klass, msg, permanant) {
382 + var oldklass = $D('noVNC-control-bar').getAttribute("class");
383 + $D('noVNC-control-bar').setAttribute("class", klass);
384 + var oldmsg = $D('noVNC_status').innerHTML;
385 + $D('noVNC_status').innerHTML = msg;
386 + if (typeof permanent !== 'undefined' && permanent) return;
387 +
388 + setTimeout(function() {
389 + var curmsg = $D('noVNC_status').innerHTML;
390 + if (curmsg === msg) {
391 + $D('noVNC_status').innerHTML = oldmsg;
392 + }
393 + var curklass = $D('noVNC-control-bar').getAttribute("class");
394 + if (curklass === klass) {
395 + $D('noVNC-control-bar').setAttribute("class", oldklass);
396 + }
397 + }, 5000);
398 + },
399 +
400 + pve_detect_migrated_vm: function() {
401 + if (!(UI.consoletype === 'kvm' || UI.consoletype === 'lxc')) {
402 + return;
403 + }
404 +
405 + // try to detect migrated VM
406 + UI.API2Request({
407 + url: '/cluster/resources',
408 + method: 'GET',
409 + success: function(result) {
410 + var list = result.data;
411 + list.every(function(item) {
412 + if ((item.type === 'qemu' || item.type === 'lxc') &&
413 + (item.vmid == UI.vmid)) {
414 + var url = "?" + UI.urlEncode({
415 + console: UI.consoletype,
416 + novnc: 1,
417 + vmid: UI.vmid,
418 + vmname: UI.vmname,
419 + node: item.node,
420 + resize: UI.resize
421 + });
422 + location.href = url;
423 + return false; // break
424 + }
425 + return true;
426 + });
427 + }
428 + });
429 + },
430 +
431 + pve_vm_command: function(cmd, params, reload) {
432 + var baseUrl;
433 +
434 + if (UI.consoletype === 'kvm') {
435 + baseUrl = '/nodes/' + UI.nodename + '/qemu/' + UI.vmid;
436 + } else if (UI.consoletype === 'lxc') {
437 + baseUrl = '/nodes/' + UI.nodename + '/lxc/' + UI.vmid;
438 + } else {
439 + throw "unknown VM type";
440 + }
441 +
442 + UI.API2Request({
443 + params: params,
444 + url: baseUrl + "/status/" + cmd,
445 + method: 'POST',
446 + failure: function(msg) {
447 + UI.pve_show_msg('noVNC_status_warn', msg);
448 + },
449 + success: function() {
450 + UI.pve_show_msg('noVNC_status_normall', "VM command '" + cmd +"' successful");
451 + if (reload) {
452 + setTimeout(function() {
453 + UI.pveReload();
454 + }, 1000);
455 + };
456 + }
457 + });
458 + },
459 +
460 + pveCmdStart: function() {
461 + if (UI.pveCommandsOpen === true) {
462 + UI.togglePVECommandPanel();
463 + }
464 + UI.pve_vm_command('start', {}, true);
465 + },
466 +
467 + pveCmdShutdown: function() {
468 + if (UI.pveCommandsOpen === true) {
469 + UI.togglePVECommandPanel();
470 + }
471 + var msg = gettext("Do you really want to shutdown VM {0}?");
472 + msg = msg.replace(/\{0\}/, UI.vmid);
473 +
474 + if (confirm(msg) === true) {
475 + UI.pve_vm_command('shutdown');
476 + }
477 + },
478 +
479 + pveCmdStop: function() {
480 + if (UI.pveCommandsOpen === true) {
481 + UI.togglePVECommandPanel();
482 + }
483 +
484 + var msg = gettext("Do you really want to stop VM {0}?");
485 + msg = msg.replace(/\{0\}/, UI.vmid);
486 +
487 + if (confirm(msg) === true) {
488 + UI.pve_vm_command('stop');
489 + }
490 + },
491 +
492 + pveCmdReset: function() {
493 + if (UI.pveCommandsOpen === true) {
494 + UI.togglePVECommandPanel();
495 + }
496 + var msg = gettext("Do you really want to reset VM {0}?");
497 + msg = msg.replace(/\{0\}/, UI.vmid);
498 +
499 + if (confirm(msg) === true) {
500 + UI.pve_vm_command('reset');
501 + }
502 + },
503 +
504 + pveCmdSuspend: function() {
505 + if (UI.pveCommandsOpen === true) {
506 + UI.togglePVECommandPanel();
507 + }
508 + var msg = gettext("Do you really want to suspend VM {0}?");
509 + msg = msg.replace(/\{0\}/, UI.vmid);
510 +
511 + if (confirm(msg) === true) {
512 + UI.pve_vm_command('suspend');
513 + }
514 + },
515 +
516 + pveCmdResume: function() {
517 + if (UI.pveCommandsOpen === true) {
518 + UI.togglePVECommandPanel();
519 + }
520 + UI.pve_vm_command('resume');
521 + },
522 +
523 + pveCmdReload: function() {
524 + if (UI.pveCommandsOpen === true) {
525 + UI.togglePVECommandPanel();
526 + }
527 + UI.pveReload();
528 + },
529 +
530 + pveReload: function() {
531 + location.reload();
532 + },
533 +
534 + pve_send_key: function(keyname) {
535 + var baseUrl;
536 +
537 + if (UI.consoletype === 'kvm') {
538 + baseUrl = '/nodes/' + UI.nodename + '/qemu/' + UI.vmid;
539 + } else {
540 + throw "send key not implemented";
541 + }
542 +
543 + UI.API2Request({
544 + params: { key: keyname },
545 + url: baseUrl + '/sendkey',
546 + method: 'PUT',
547 + failure: function(msg) {
548 + UI.pve_show_msg('noVNC_status_warn', msg);
549 + }
550 + });
551 + },
552 +
553 + pve_start: function(callback) {
554 + UI.consoletype = WebUtil.getQueryVar('console');
555 + UI.vmid = WebUtil.getQueryVar('vmid');
556 + UI.vmname = WebUtil.getQueryVar('vmname');
557 + UI.nodename = WebUtil.getQueryVar('node');
558 + UI.resize = WebUtil.getQueryVar('resize');
559 +
560 + var url;
561 + var wsurl;
562 + var params = { websocket: 1 };
563 + var btn;
564 +
565 + // add pve command buttons
566 + var cmdpanel = $D('noVNC_pve_command_menu');
567 + var buttonlist = [
568 + {
569 + text: gettext('Start'),
570 + handler: UI.pveCmdStart,
571 + enable: { kvm: 1, lxc: 1 }
572 + },
573 + {
574 + text: gettext('Shutdown'),
575 + handler: UI.pveCmdShutdown,
576 + enable: { kvm: 1, lxc: 1 }
577 + },
578 + {
579 + text: gettext('Stop'),
580 + handler: UI.pveCmdStop,
581 + enable: { kvm: 1, lxc: 1 }
582 + },
583 + {
584 + text: gettext('Reset'),
585 + handler: UI.pveCmdReset,
586 + enable: { kvm: 1 }
587 + },
588 + {
589 + text: gettext('Suspend'),
590 + handler: UI.pveCmdSuspend,
591 + enable: { kvm: 1 }
592 + },
593 + {
594 + text: gettext('Resume'),
595 + handler: UI.pveCmdResume,
596 + enable: { kvm: 1 }
597 + },
598 + {
599 + text: gettext('Reload'),
600 + handler: UI.pveCmdReload,
601 + enable: { any: 1 }
602 + }
603 + ];
604 + buttonlist.forEach(function(btn) {
605 + if (btn.enable.any || btn.enable[UI.consoletype]) {
606 + var el = document.createElement('input');
607 + el.setAttribute('type', 'button');
608 + el.setAttribute('value', btn.text);
609 + el.onclick = btn.handler;
610 + el.style.display = "block";
611 + el.style.width = "100%";
612 + el.style.minWidth = "150px";
613 + cmdpanel.appendChild(el);
614 + }
615 + });
616 +
617 + // add sendKeys buttons
618 + var skpanel = $D('noVNC_send_keys_panel');
619 +
620 + buttonlist = [
621 + {
622 + text: 'Tab', handler: function() {
623 + UI.pve_send_key('tab');
624 + }
625 + },
626 + {
627 + text: 'Ctrl-Alt-Delete', handler: function() {
628 + UI.pve_send_key('ctrl-alt-delete');
629 + }
630 + },
631 + {
632 + text: 'Ctrl-Alt-Backspace', handler: function() {
633 + UI.pve_send_key('ctrl-alt-backspace');
634 + }
635 + },
636 + {
637 + text: 'Ctrl-Alt-F1', handler: function() {
638 + UI.pve_send_key('ctrl-alt-f1');
639 + }
640 + },
641 + {
642 + text: 'Ctrl-Alt-F2', handler: function() {
643 + UI.pve_send_key('ctrl-alt-f2');
644 + }
645 + },
646 + {
647 + text: 'Ctrl-Alt-F3', handler: function() {
648 + UI.pve_send_key('ctrl-alt-f3');
649 + }
650 + },
651 + {
652 + text: 'Ctrl-Alt-F4', handler: function() {
653 + UI.pve_send_key('ctrl-alt-f4');
654 + }
655 + },
656 + {
657 + text: 'Ctrl-Alt-F5', handler: function() {
658 + UI.pve_send_key('ctrl-alt-f5');
659 + }
660 + },
661 + {
662 + text: 'Ctrl-Alt-F6', handler: function() {
663 + UI.pve_send_key('ctrl-alt-f6');
664 + }
665 + },
666 + {
667 + text: 'Ctrl-Alt-F7', handler: function() {
668 + UI.pve_send_key('ctrl-alt-f7');
669 + }
670 + },
671 + {
672 + text: 'Ctrl-Alt-F8', handler: function() {
673 + UI.pve_send_key('ctrl-alt-f8');
674 + }
675 + },
676 + {
677 + text: 'Ctrl-Alt-F9', handler: function() {
678 + UI.pve_send_key('ctrl-alt-f9');
679 + }
680 + },
681 + {
682 + text: 'Ctrl-Alt-F10', handler: function() {
683 + UI.pve_send_key('ctrl-alt-f10');
684 + }
685 + },
686 + {
687 + text: 'Ctrl-Alt-F11', handler: function() {
688 + UI.pve_send_key('ctrl-alt-f11');
689 + }
690 + },
691 + {
692 + text: 'Ctrl-Alt-F12', handler: function() {
693 + UI.pve_send_key('ctrl-alt-f12');
694 + }
695 + }
696 + ];
697 +
698 + buttonlist.forEach(function(btn) {
699 + var el = document.createElement('input');
700 + el.setAttribute('type', 'button');
701 + el.setAttribute('value', btn.text);
702 + el.onclick = function(handler) {
703 + return function() {
704 + if (UI.sendKeysVisible === true) {
705 + UI.togglePVESendKeysPanel();
706 + }
707 +
708 + handler.call(this);
709 + };
710 + }(btn.handler);
711 + el.style.display = "block";
712 + el.style.width = "100%";
713 + el.style.minWidth = "150px";
714 + skpanel.appendChild(el);
715 + });
716 +
717 + var title;
718 +
719 + if (UI.consoletype === 'kvm') {
720 + var baseUrl = '/nodes/' + UI.nodename + '/qemu/' + UI.vmid;
721 + url = baseUrl + '/vncproxy';
722 + wsurl = baseUrl + '/vncwebsocket';
723 + title = "VM " + UI.vmid;
724 + if (UI.vmname) {
725 + title += " ('" + UI.vmname + "')";
726 + }
727 + } else if (UI.consoletype === 'lxc') {
728 + var baseUrl = '/nodes/' + UI.nodename + '/lxc/' + UI.vmid;
729 + url = baseUrl + '/vncproxy';
730 + wsurl = baseUrl + '/vncwebsocket';
731 + title = "CT " + UI.vmid;
732 + if (UI.vmname) {
733 + title += " ('" + UI.vmname + "')";
734 + }
735 + } else if (UI.consoletype === 'shell') {
736 + var baseUrl = '/nodes/' + UI.nodename;
737 + url = baseUrl + '/vncshell';
738 + wsurl = baseUrl + '/vncwebsocket';
739 + title = "node '" + UI.nodename + "'";
740 + } else if (UI.consoletype === 'upgrade') {
741 + var baseUrl = '/nodes/' + UI.nodename;
742 + url = baseUrl + '/vncshell';
743 + wsurl = baseUrl + '/vncwebsocket';
744 + params.upgrade = 1;
745 + title = gettext('System upgrade on node {0}');
746 + title = title.replace(/\{0\}/, UI.nodename);
747 + } else {
748 + throw "implement me";
749 + }
750 +
751 + document.title = title;
752 +
753 + var start_vnc_viewer = function(param) {
754 + var wsparams = UI.urlEncode({
755 + port: param.port,
756 + vncticket: param.ticket
757 + });
758 +
759 + UI.updateSetting('host', window.location.hostname);
760 + UI.updateSetting('port', window.location.port || 443);
761 + UI.updateSetting('password', param.ticket);
762 + UI.updateSetting('encrypt', true);
763 + UI.updateSetting('true_color', true);
764 + UI.updateSetting('cursor', !UI.isTouchDevice);
765 + UI.updateSetting('shared', true);
766 + UI.updateSetting('view_only', false);
767 + UI.updateSetting('resize', UI.resize);
768 +
769 + UI.updateSetting('path', 'api2/json' + wsurl + "?" + wsparams);
770 +
771 + UI.start(callback);
772 + };
773 +
774 + UI.API2Request({
775 + url: url,
776 + method: 'POST',
777 + params: params,
778 + success: function(result) {
779 + start_vnc_viewer(result.data);
780 + },
781 + failure: function(msg) {
782 + UI.pve_show_msg('noVNC_status_error', msg, 1);
783 + }
784 + });
785 + },
786 +
787 + lastFBWidth: undefined,
788 + lastFBHeight: undefined,
789 + sizeUpdateTimer: undefined,
790 +
791 + updateFBSize: function(rfb, width, height) {
792 + try {
793 + // Note1: CSS Canvas size is wrong by a few pixels in Chrome
794 + // Note2: window size must be even number for firefox
795 + UI.lastFBWidth = Math.floor((width + 1)/2)*2;;
796 + UI.lastFBHeight = Math.floor((height + 1)/2)*2;
797 +
798 + if (UI.sizeUpdateTimer !== undefined) {
799 + clearInterval(UI.sizeUpdateTimer);
800 + }
801 + if (UI.getSetting('clip')) return;
802 +
803 + var update_size = function() {
804 + var oh;
805 + var ow;
806 +
807 + if (window.innerHeight) {
808 + oh = window.innerHeight;
809 + ow = window.innerWidth;
810 + } else if (document.documentElement &&
811 + document.documentElement.clientHeight) {
812 + oh = document.documentElement.clientHeight;
813 + ow = document.documentElement.clientWidth;
814 + } else if (document.body) {
815 + oh = document.body.clientHeight;
816 + ow = document.body.clientWidth;
817 + } else {
818 + throw "can't get window size";
819 + }
820 +
821 + // see base.css/noVNC_screen_pad
822 + var toolbar_height = 36;
823 +
824 + var offsetw = UI.lastFBWidth - ow;
825 + var offseth = UI.lastFBHeight + toolbar_height - oh;
826 + if (offsetw !== 0 || offseth !== 0) {
827 + //console.log("try resize by " + offsetw + " " + offseth);
828 + window.resizeBy(offsetw, offseth);
829 + }
830 + };
831 +
832 + update_size();
833 + UI.sizeUpdateTimer = setInterval(update_size, 1000);
834 +
835 + } catch(e) {
836 + console.log(e);
837 + }
838 + },
839 + // Open/close PVE commandand menu
840 + togglePVECommandPanel: function() {
841 + // Close the description panel
842 + $D('noVNC_description').style.display = "none";
843 + if (UI.sendKeysVisible === true) {
844 + UI.togglePVESendKeysPanel();
845 + }
846 + // Close clipboard panel if open
847 + if (UI.clipboardOpen === true) {
848 + UI.toggleClipboardPanel();
849 + }
850 + // Close connection settings if open
851 + if (UI.connSettingsOpen === true) {
852 + UI.toggleConnectPanel();
853 + }
854 + // Close popup status panel if open
855 + if (UI.popupStatusOpen === true) {
856 + UI.togglePopupStatusPanel();
857 + }
858 + // Close XVP panel if open
859 + if (UI.xvpOpen === true) {
860 + UI.toggleXvpPanel();
861 + }
862 + if (UI.pveCommandsOpen) {
863 + $D('noVNC_pve_commands').style.display = "none";
864 + $D('pveCommandsButton').className = "noVNC_status_button";
865 + UI.pveCommandsOpen = false;
866 + } else {
867 + $D('noVNC_pve_commands').style.display = "block";
868 + $D('pveCommandsButton').className = "noVNC_status_button_selected";
869 + UI.pveCommandsOpen = true;
870 + }
871 + },
872 +
873 + // Open/close PVE SendKeys menu
874 + togglePVESendKeysPanel: function() {
875 + // Close the description panel
876 + $D('noVNC_description').style.display = "none";
877 + if (UI.pveCommandsOpen === true) {
878 + UI.togglePVECommandPanel();
879 + }
880 + // Close clipboard panel if open
881 + if (UI.clipboardOpen === true) {
882 + UI.toggleClipboardPanel();
883 + }
884 + // Close connection settings if open
885 + if (UI.connSettingsOpen === true) {
886 + UI.toggleConnectPanel();
887 + }
888 + // Close popup status panel if open
889 + if (UI.popupStatusOpen === true) {
890 + UI.togglePopupStatusPanel();
891 + }
892 + // Close XVP panel if open
893 + if (UI.xvpOpen === true) {
894 + UI.toggleXvpPanel();
895 + }
896 + if (UI.sendKeysVisible) {
897 + $D('noVNC_send_keys').style.display = "none";
898 + $D('showSendKeysButton').className = "noVNC_status_button";
899 + UI.sendKeysVisible = false;
900 + } else {
901 + $D('noVNC_send_keys').style.display = "block";
902 + $D('showSendKeysButton').className = "noVNC_status_button_selected";
903 + UI.sendKeysVisible = true;
904 + }
905 + }
906 +
907
908 };
909 })();
910 --
911 2.1.4
912