]>
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', { id
: "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
= Ext
.String
.format(gettext("Do you really want to shutdown VM {0}?"), 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
= Ext
.String
.format(gettext("Do you really want to stop VM {0}?"), 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
= Ext
.String
.format(gettext("Do you really want to reset VM {0}?"), me
.vmid
);
294 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
303 text
: gettext('Suspend'),
304 handler: function() {
305 var msg
= Ext
.String
.format(gettext("Do you really want to suspend VM {0}?"), 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 () {
339 url
: baseUrl
+ "/vncproxy",
340 wsurl
: baseUrl
+ "/vncwebsocket"
347 Ext
.define('PVE.LxcConsole', {
348 extend
: 'PVE.VNCConsole',
349 alias
: ['widget.pveLxcConsole'],
351 initComponent : function() {
355 throw "no node name specified";
359 throw "no VM ID specified";
362 var baseUrl
= "/nodes/" + me
.nodename
+ "/lxc/" + me
.vmid
;
364 var vm_command = function(cmd
, params
, reload_applet
) {
365 PVE
.Utils
.API2Request({
367 url
: baseUrl
+ "/status/" + cmd
,
370 failure: function(response
, opts
) {
371 Ext
.Msg
.alert('Error', response
.htmlStatus
);
373 success: function() {
375 Ext
.Function
.defer(me
.reloadApplet
, 1000, me
);
383 text
: gettext('Start'),
384 handler: function() {
389 text
: gettext('Shutdown'),
390 handler: function() {
391 var msg
= Ext
.String
.format(gettext("Do you really want to shutdown VM {0}?"), me
.vmid
);
392 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
396 vm_command("shutdown");
401 text
: gettext('Stop'),
402 handler: function() {
403 var msg
= Ext
.String
.format(gettext("Do you really want to stop VM {0}?"), me
.vmid
);
404 Ext
.Msg
.confirm(gettext('Confirm'), msg
, function(btn
) {
412 // Note: no migrate here, because we can't display migrate log
415 text
: gettext('Reload'),
416 handler: function () {
424 url
: baseUrl
+ "/vncproxy",
425 wsurl
: baseUrl
+ "/vncwebsocket"
432 Ext
.define('PVE.Shell', {
433 extend
: 'PVE.VNCConsole',
434 alias
: ['widget.pveShell'],
436 ugradeSystem
: false, // set to true to run "apt-get dist-upgrade"
438 initComponent : function() {
442 throw "no node name specified";
447 if (!me
.ugradeSystem
) {
448 // we dont want to restart the upgrade script
450 text
: gettext('Reload'),
451 handler: function () { me
.reloadApplet(); }
456 text
: gettext('Shell'),
457 handler: function() {
458 PVE
.Utils
.openVNCViewer('shell', undefined, me
.nodename
, undefined);
462 var baseUrl
= "/nodes/" + me
.nodename
;
466 url
: baseUrl
+ "/vncshell",
467 wsurl
: baseUrl
+ "/vncwebsocket"
470 if (me
.ugradeSystem
) {
471 me
.params
= { upgrade
: 1 };