]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/VNCConsole.js
1 Ext
.define('PVE.noVncConsole', {
2 extend
: 'Ext.panel.Panel',
3 alias
: 'widget.pveNoVncConsole',
9 consoleType
: undefined, // lxc or kvm
11 initComponent : function() {
15 throw "no node name specified";
18 if (!me
.consoleType
) {
19 throw "no console type specified";
22 if (!me
.vmid
&& me
.consoleType
!== 'shell') {
23 throw "no VM ID specified";
26 // always use same iframe, to avoid running several noVnc clients
27 // at same time (to avoid performance problems)
28 var box
= Ext
.create('widget.uxiframe', { id
: "vncconsole" });
31 layout
: { type
: 'fit' },
36 var url
= '/?console=' + me
.consoleType
+ '&novnc=1&node=' + me
.nodename
+ '&resize=scale';
38 url
+= '&vmid='+ me
.vmid
;
49 PVE_vnc_console_event = function(appletid
, action
, err
) {
50 //console.log("TESTINIT param1 " + appletid + " action " + action);
52 if (action
=== "error") {
53 var compid
= appletid
.replace("-vncapp", "");
54 var comp
= Ext
.getCmp(compid
);
56 if (!comp
|| !comp
.vmid
|| !comp
.toplevel
) {
60 comp
.detectMigratedVM();
66 Ext
.define('PVE.VNCConsole', {
67 extend
: 'Ext.panel.Panel',
68 alias
: ['widget.pveVNCConsole'],
72 last_novnc_state
: undefined,
73 last_novnc_msg
: undefined,
75 detectMigratedVM: function() {
82 // try to detect migrated VM
83 PVE
.Utils
.API2Request({
84 url
: '/cluster/resources',
86 success: function(response
) {
87 var list
= response
.result
.data
;
88 Ext
.Array
.each(list
, function(item
) {
89 if (item
.type
=== 'qemu' && item
.vmid
== me
.vmid
) {
90 if (item
.node
!== me
.nodename
) {
91 me
.nodename
= item
.node
;
92 me
.url
= "/nodes/" + me
.nodename
+ "/" + item
.type
+ "/" + me
.vmid
+ "/vncproxy";
93 me
.wsurl
= "/nodes/" + me
.nodename
+ "/" + item
.type
+ "/" + me
.vmid
+ "/vncwebsocket";
96 return false; // break
103 initComponent : function() {
107 throw "no url specified";
110 var myid
= me
.id
+ "-vncapp";
118 throw "no web socket url specified";
120 box
= Ext
.create('widget.uxiframe', { id
: myid
});
122 box
= Ext
.create('Ext.Component', { border
: false, html
: "" });
125 var resize_window = function() {
126 //console.log("resize");
133 var novnciframe
= box
.getFrame();
135 var innerDoc
= novnciframe
.contentDocument
|| novnciframe
.contentWindow
.document
;
136 aw
= innerDoc
.getElementById('noVNC_canvas').width
;
137 ah
= innerDoc
.getElementById('noVNC_canvas').height
+ 8;
139 var novnc_state
= innerDoc
.getElementById('noVNC_status_state').innerHTML
;
140 var novnc_msg
= innerDoc
.getElementById('noVNC_status_msg').innerHTML
;
142 if (novnc_state
!== me
.last_novnc_state
|| novnc_msg
!== me
.last_novnc_msg
) {
143 me
.last_novnc_state
= novnc_state
;
144 me
.last_novnc_msg
= novnc_msg
;
146 if (novnc_state
!== 'normal') {
147 PVE
.Utils
.setErrorMask(box
, novnc_msg
|| 'unknown');
149 PVE
.Utils
.setErrorMask(box
); // clear mask
152 if (novnc_state
=== 'disconnected') {
153 me
.detectMigratedVM();
158 applet
= Ext
.getDom(myid
);
160 // try again when dom element is available
161 if (!(applet
&& Ext
.isFunction(applet
.getPreferredSize
))) {
162 return Ext
.Function
.defer(resize_window
, 1000);
165 var ps
= applet
.getPreferredSize();
170 if (aw
< 640) { aw
= 640; }
171 if (ah
< 400) { ah
= 400; }
173 var tbar
= me
.getDockedItems("[dock=top]")[0];
174 var tbh
= tbar
? tbar
.getHeight() : 0;
179 //console.log("size0 " + aw + " " + ah + " tbh " + tbh);
181 if (window
.innerHeight
) {
182 oh
= window
.innerHeight
;
183 ow
= window
.innerWidth
;
184 } else if (document
.documentElement
&&
185 document
.documentElement
.clientHeight
) {
186 oh
= document
.documentElement
.clientHeight
;
187 ow
= document
.documentElement
.clientWidth
;
188 } else if (document
.body
) {
189 oh
= document
.body
.clientHeight
;
190 ow
= document
.body
.clientWidth
;
192 throw "can't get window size";
196 Ext
.fly(applet
).setSize(aw
, ah
+ tbh
);
199 var offsetw
= aw
- ow
;
200 var offseth
= ah
+ tbh
- oh
;
202 if (offsetw
!== 0 || offseth
!== 0) {
203 //console.log("try resize by " + offsetw + " " + offseth);
204 try { window
.resizeBy(offsetw
, offseth
); } catch (e
) {}
207 Ext
.Function
.defer(resize_window
, 1000);
210 var resize_box = function() {
212 throw "implement me";
214 var applet
= Ext
.getDom(myid
);
216 if ((applet
&& Ext
.isFunction(applet
.getPreferredSize
))) {
217 var ps
= applet
.getPreferredSize();
218 Ext
.fly(applet
).setSize(ps
.width
, ps
.height
);
222 Ext
.Function
.defer(resize_box
, 1000);
225 var start_vnc_viewer = function(param
) {
229 var pveparams
= Ext
.urlEncode({
231 vncticket
: param
.ticket
234 var urlparams
= Ext
.urlEncode({
236 path
: "api2/json" + me
.wsurl
+ "?" + pveparams
,
237 password
: param
.ticket
239 box
.load('/novnc/vnc_pve.html?' + urlparams
);
243 var cert
= param
.cert
;
244 cert
= cert
.replace(/\n/g, "|");
250 code
: 'com.tigervnc.vncviewer.VncViewer',
251 archive
: '/vncterm/VncViewer.jar',
252 // NOTE: set size to '100%' - else resize does not work
256 {tag
: 'param', name
: 'id', value
: myid
},
257 {tag
: 'param', name
: 'PORT', value
: param
.port
},
258 {tag
: 'param', name
: 'PASSWORD', value
: param
.ticket
},
259 {tag
: 'param', name
: 'USERNAME', value
: param
.user
},
260 {tag
: 'param', name
: 'Show Controls', value
: 'No'},
261 {tag
: 'param', name
: 'Offer Relogin', value
: 'No'},
262 {tag
: 'param', name
: 'PVECert', value
: cert
}
268 Ext
.Function
.defer(resize_window
, 1000);
270 Ext
.Function
.defer(resize_box
, 1000);
277 autoScroll
: me
.toplevel
? false : true,
279 reloadApplet: function() {
280 var params
= Ext
.apply({}, me
.params
);
282 params
.websocket
= 1;
284 PVE
.Utils
.API2Request({
287 method
: me
.method
|| 'POST',
288 failure: function(response
, opts
) {
289 box
.update(gettext('Error') + ' ' + response
.htmlStatus
);
291 success: function(response
, opts
) {
292 start_vnc_viewer(response
.result
.data
);
301 me
.on("render", me
.reloadApplet
);
303 me
.on("show", me
.reloadApplet
);
304 me
.on("hide", function() { box
.update(""); });
309 Ext
.define('PVE.KVMConsole', {
310 extend
: 'PVE.VNCConsole',
311 alias
: ['widget.pveKVMConsole'],
313 initComponent : function() {
317 throw "no node name specified";
321 throw "no VM ID specified";
324 var baseUrl
= "/nodes/" + me
.nodename
+ "/qemu/" + me
.vmid
;
326 var vm_command = function(cmd
, params
, reload_applet
) {
327 PVE
.Utils
.API2Request({
329 url
: baseUrl
+ "/status/" + cmd
,
332 failure: function(response
, opts
) {
333 Ext
.Msg
.alert('Error', response
.htmlStatus
);
335 success: function() {
337 Ext
.Function
.defer(me
.reloadApplet
, 1000, me
);
345 text
: gettext('Start'),
346 handler: function() {
347 vm_command("start", {}, 1);
351 text
: gettext('Shutdown'),
352 handler: function() {
353 var msg
= Ext
.String
.format(gettext("Do you really want to shutdown VM {0}?"), me
.vmid
);
354 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
358 vm_command('shutdown');
363 text
: gettext('Stop'),
364 handler: function() {
365 var msg
= Ext
.String
.format(gettext("Do you really want to stop VM {0}?"), me
.vmid
);
366 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
375 xtype
: 'pveQemuSendKeyMenu',
376 nodename
: me
.nodename
,
380 text
: gettext('Reset'),
381 handler: function() {
382 var msg
= Ext
.String
.format(gettext("Do you really want to reset VM {0}?"), me
.vmid
);
383 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
392 text
: gettext('Suspend'),
393 handler: function() {
394 var msg
= Ext
.String
.format(gettext("Do you really want to suspend VM {0}?"), me
.vmid
);
395 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
399 vm_command("suspend");
404 text
: gettext('Resume'),
405 handler: function() {
406 vm_command("resume");
409 // Note: no migrate here, because we can't display migrate log
411 text
: gettext('Console'),
412 handler: function() {
413 PVE
.Utils
.openVNCViewer('kvm', me
.vmid
, me
.nodename
, me
.vmname
, me
.novnc
);
418 text
: gettext('Refresh'),
419 hidden
: me
.novnc
? true : false,
420 handler: function() {
421 var applet
= Ext
.getDom(me
.appletID
);
422 applet
.sendRefreshRequest();
426 text
: gettext('Reload'),
427 handler: function () {
436 url
: baseUrl
+ "/vncproxy",
437 wsurl
: baseUrl
+ "/vncwebsocket"
444 Ext
.define('PVE.LxcConsole', {
445 extend
: 'PVE.VNCConsole',
446 alias
: ['widget.pveLxcConsole'],
448 initComponent : function() {
452 throw "no node name specified";
456 throw "no VM ID specified";
459 var baseUrl
= "/nodes/" + me
.nodename
+ "/lxc/" + me
.vmid
;
461 var vm_command = function(cmd
, params
, reload_applet
) {
462 PVE
.Utils
.API2Request({
464 url
: baseUrl
+ "/status/" + cmd
,
467 failure: function(response
, opts
) {
468 Ext
.Msg
.alert('Error', response
.htmlStatus
);
470 success: function() {
472 Ext
.Function
.defer(me
.reloadApplet
, 1000, me
);
480 text
: gettext('Start'),
481 handler: function() {
486 text
: gettext('Shutdown'),
487 handler: function() {
488 var msg
= Ext
.String
.format(gettext("Do you really want to shutdown VM {0}?"), me
.vmid
);
489 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
493 vm_command("shutdown");
498 text
: gettext('Stop'),
499 handler: function() {
500 var msg
= Ext
.String
.format(gettext("Do you really want to stop VM {0}?"), me
.vmid
);
501 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
509 // Note: no migrate here, because we can't display migrate log
512 text
: gettext('Refresh'),
513 hidden
: me
.novnc
? true : false,
514 handler: function() {
515 var applet
= Ext
.getDom(me
.appletID
);
516 applet
.sendRefreshRequest();
520 text
: gettext('Reload'),
521 handler: function () {
529 url
: baseUrl
+ "/vncproxy",
530 wsurl
: baseUrl
+ "/vncwebsocket"
537 Ext
.define('PVE.Shell', {
538 extend
: 'PVE.VNCConsole',
539 alias
: ['widget.pveShell'],
541 ugradeSystem
: false, // set to true to run "apt-get dist-upgrade"
543 initComponent : function() {
547 throw "no node name specified";
554 text
: gettext('Refresh'),
555 handler: function() {
556 var applet
= Ext
.getDom(me
.appletID
);
557 applet
.sendRefreshRequest();
562 if (!me
.ugradeSystem
) {
563 // we dont want to restart the upgrade script
565 text
: gettext('Reload'),
566 handler: function () { me
.reloadApplet(); }
571 text
: gettext('Shell'),
572 handler: function() {
573 PVE
.Utils
.openVNCViewer('shell', undefined, me
.nodename
, undefined, me
.novnc
);
577 var baseUrl
= "/nodes/" + me
.nodename
;
581 url
: baseUrl
+ "/vncshell",
582 wsurl
: baseUrl
+ "/vncwebsocket"
585 if (me
.ugradeSystem
) {
586 me
.params
= { upgrade
: 1 };