]>
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
15 initComponent : function() {
19 throw "no node name specified";
22 if (!me
.consoleType
) {
23 throw "no console type specified";
26 if (!me
.vmid
&& me
.consoleType
!== 'shell') {
27 throw "no VM ID specified";
30 // always use same iframe, to avoid running several noVnc clients
31 // at same time (to avoid performance problems)
32 var box
= Ext
.create('Ext.ux.IFrame', { itemid
: "vncconsole" });
37 activate: function() {
38 var url
= '/?console=' + me
.consoleType
+ '&novnc=1&node=' + me
.nodename
+ '&resize=scale';
40 url
+= '&vmid='+ me
.vmid
;
51 Ext
.define('PVE.VNCConsole', {
52 extend
: 'Ext.panel.Panel',
53 alias
: 'widget.pveVNCConsole',
55 last_novnc_state
: undefined,
56 last_novnc_msg
: undefined,
61 detectMigratedVM: function() {
68 // try to detect migrated VM
69 PVE
.Utils
.API2Request({
70 url
: '/cluster/resources',
72 success: function(response
) {
73 var list
= response
.result
.data
;
74 Ext
.Array
.each(list
, function(item
) {
75 if (item
.type
=== 'qemu' && item
.vmid
== me
.vmid
) {
76 if (item
.node
!== me
.nodename
) {
77 me
.nodename
= item
.node
;
78 me
.url
= "/nodes/" + me
.nodename
+ "/" + item
.type
+ "/" + me
.vmid
+ "/vncproxy";
79 me
.wsurl
= "/nodes/" + me
.nodename
+ "/" + item
.type
+ "/" + me
.vmid
+ "/vncwebsocket";
82 return false; // break
89 initComponent : function() {
93 throw "no url specified";
96 var myid
= me
.id
+ "-vncapp";
103 throw "no web socket url specified";
105 box
= Ext
.create('Ext.ux.IFrame', { id
: myid
});
107 var resize_window = function() {
108 //console.log("resize");
113 var novnciframe
= box
.getFrame();
115 var innerDoc
= novnciframe
.contentDocument
|| novnciframe
.contentWindow
.document
;
116 aw
= innerDoc
.getElementById('noVNC_canvas').width
;
117 ah
= innerDoc
.getElementById('noVNC_canvas').height
+ 8;
119 var novnc_state
= innerDoc
.getElementById('noVNC_status_state').innerHTML
;
120 var novnc_msg
= innerDoc
.getElementById('noVNC_status_msg').innerHTML
;
122 if (novnc_state
!== me
.last_novnc_state
|| novnc_msg
!== me
.last_novnc_msg
) {
123 me
.last_novnc_state
= novnc_state
;
124 me
.last_novnc_msg
= novnc_msg
;
126 if (novnc_state
!== 'normal') {
127 PVE
.Utils
.setErrorMask(box
, novnc_msg
|| 'unknown');
129 PVE
.Utils
.setErrorMask(box
); // clear mask
132 if (novnc_state
=== 'disconnected') {
133 me
.detectMigratedVM();
137 if (aw
< 640) { aw
= 640; }
138 if (ah
< 400) { ah
= 400; }
140 var tbar
= me
.getDockedItems("[dock=top]")[0];
141 var tbh
= tbar
? tbar
.getHeight() : 0;
146 //console.log("size0 " + aw + " " + ah + " tbh " + tbh);
148 if (window
.innerHeight
) {
149 oh
= window
.innerHeight
;
150 ow
= window
.innerWidth
;
151 } else if (document
.documentElement
&&
152 document
.documentElement
.clientHeight
) {
153 oh
= document
.documentElement
.clientHeight
;
154 ow
= document
.documentElement
.clientWidth
;
155 } else if (document
.body
) {
156 oh
= document
.body
.clientHeight
;
157 ow
= document
.body
.clientWidth
;
159 throw "can't get window size";
162 var offsetw
= aw
- ow
;
163 var offseth
= ah
+ tbh
- oh
;
165 if (offsetw
!== 0 || offseth
!== 0) {
166 //console.log("try resize by " + offsetw + " " + offseth);
167 try { window
.resizeBy(offsetw
, offseth
); } catch (e
) {}
170 Ext
.Function
.defer(resize_window
, 1000);
173 var start_vnc_viewer = function(param
) {
174 var pveparams
= Ext
.urlEncode({
176 vncticket
: param
.ticket
179 var urlparams
= Ext
.urlEncode({
181 path
: "api2/json" + me
.wsurl
+ "?" + pveparams
,
182 password
: param
.ticket
184 box
.load('/novnc/vnc_pve.html?' + urlparams
);
186 Ext
.Function
.defer(resize_window
, 1000);
190 scrollable
: me
.toplevel
? false : true,
192 reloadApplet: function() {
193 var params
= Ext
.apply({}, me
.params
);
194 params
.websocket
= 1;
195 PVE
.Utils
.API2Request({
198 method
: me
.method
|| 'POST',
199 failure: function(response
, opts
) {
200 box
.update(gettext('Error') + ' ' + response
.htmlStatus
);
202 success: function(response
, opts
) {
203 start_vnc_viewer(response
.result
.data
);
212 me
.on("render", me
.reloadApplet
);
214 me
.on("activate", me
.reloadApplet
);
215 me
.on("hide", function() { box
.update(""); });
220 Ext
.define('PVE.KVMConsole', {
221 extend
: 'PVE.VNCConsole',
222 alias
: 'widget.pveKVMConsole',
224 initComponent : function() {
228 throw "no node name specified";
232 throw "no VM ID specified";
235 var baseUrl
= "/nodes/" + me
.nodename
+ "/qemu/" + me
.vmid
;
237 var vm_command = function(cmd
, params
, reload_applet
) {
238 PVE
.Utils
.API2Request({
240 url
: baseUrl
+ "/status/" + cmd
,
243 failure: function(response
, opts
) {
244 Ext
.Msg
.alert('Error', response
.htmlStatus
);
246 success: function() {
248 Ext
.Function
.defer(me
.reloadApplet
, 1000, me
);
256 text
: gettext('Start'),
257 handler: function() {
258 vm_command("start", {}, 1);
262 text
: gettext('Shutdown'),
263 handler: function() {
264 var msg
= PVE
.Utils
.format_task_description('qmshutdown', me
.vmid
);
265 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
269 vm_command('shutdown');
274 text
: gettext('Stop'),
275 handler: function() {
276 var msg
= PVE
.Utils
.format_task_description('qmstop', me
.vmid
);
277 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
286 xtype
: 'pveQemuSendKeyMenu',
287 nodename
: me
.nodename
,
291 text
: gettext('Reset'),
292 handler: function() {
293 var msg
= PVE
.Utils
.format_task_description('qmreset', me
.vmid
);
294 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
303 text
: gettext('Suspend'),
304 handler: function() {
305 var msg
= PVE
.Utils
.format_task_description('qmsuspend', me
.vmid
);
306 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
310 vm_command("suspend");
315 text
: gettext('Resume'),
316 handler: function() {
317 vm_command("resume");
320 // Note: no migrate here, because we can't display migrate log
322 text
: gettext('Console'),
323 handler: function() {
324 PVE
.Utils
.openVNCViewer('kvm', me
.vmid
, me
.nodename
, me
.vmname
);
329 text
: gettext('Reload'),
330 handler: function () {
338 url
: baseUrl
+ "/vncproxy",
339 wsurl
: baseUrl
+ "/vncwebsocket"
346 Ext
.define('PVE.LxcConsole', {
347 extend
: 'PVE.VNCConsole',
348 alias
: 'widget.pveLxcConsole',
350 initComponent : function() {
354 throw "no node name specified";
358 throw "no VM ID specified";
361 var baseUrl
= "/nodes/" + me
.nodename
+ "/lxc/" + me
.vmid
;
363 var vm_command = function(cmd
, params
, reload_applet
) {
364 PVE
.Utils
.API2Request({
366 url
: baseUrl
+ "/status/" + cmd
,
369 failure: function(response
, opts
) {
370 Ext
.Msg
.alert('Error', response
.htmlStatus
);
372 success: function() {
374 Ext
.Function
.defer(me
.reloadApplet
, 1000, me
);
382 text
: gettext('Start'),
383 handler: function() {
388 text
: gettext('Shutdown'),
389 handler: function() {
390 var msg
= PVE
.Utils
.format_task_description('vzshutdown', me
.vmid
);
391 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
395 vm_command("shutdown");
400 text
: gettext('Stop'),
401 handler: function() {
402 var msg
= PVE
.Utils
.format_task_description('vzstop', me
.vmid
);
403 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
411 // Note: no migrate here, because we can't display migrate log
414 text
: gettext('Reload'),
415 handler: function () {
423 url
: baseUrl
+ "/vncproxy",
424 wsurl
: baseUrl
+ "/vncwebsocket"
431 Ext
.define('PVE.Shell', {
432 extend
: 'PVE.VNCConsole',
433 alias
: 'widget.pveShell',
435 ugradeSystem
: false, // set to true to run "apt-get dist-upgrade"
437 initComponent : function() {
441 throw "no node name specified";
446 if (!me
.ugradeSystem
) {
447 // we dont want to restart the upgrade script
449 text
: gettext('Reload'),
450 handler: function () { me
.reloadApplet(); }
455 text
: gettext('Shell'),
456 handler: function() {
457 PVE
.Utils
.openVNCViewer('shell', undefined, me
.nodename
, undefined);
461 var baseUrl
= "/nodes/" + me
.nodename
;
465 url
: baseUrl
+ "/vncshell",
466 wsurl
: baseUrl
+ "/vncwebsocket"
469 if (me
.ugradeSystem
) {
470 me
.params
= { upgrade
: 1 };