]>
Commit | Line | Data |
---|---|---|
787ae72a DM |
1 | /* |
2 | * Workspace base class | |
3 | * | |
4 | * popup login window when auth fails (call onLogin handler) | |
5 | * update (re-login) ticket every 15 minutes | |
6 | * | |
7 | */ | |
8 | ||
9 | Ext.define('PVE.Workspace', { | |
10 | extend: 'Ext.container.Viewport', | |
11 | ||
12 | title: 'Proxmox Virtual Environment', | |
13 | ||
14 | loginData: null, // Data from last login call | |
15 | ||
16 | onLogin: function(loginData) {}, | |
17 | ||
18 | // private | |
19 | updateLoginData: function(loginData) { | |
20 | var me = this; | |
21 | me.loginData = loginData; | |
22 | PVE.CSRFPreventionToken = loginData.CSRFPreventionToken; | |
23 | PVE.UserName = loginData.username; | |
24 | ||
25 | if (loginData.cap) { | |
26 | Ext.state.Manager.set('GuiCap', loginData.cap); | |
27 | } | |
28 | ||
29 | // creates a session cookie (expire = null) | |
30 | // that way the cookie gets deleted after browser window close | |
31 | Ext.util.Cookies.set('PVEAuthCookie', loginData.ticket, null, '/', null, true); | |
32 | me.onLogin(loginData); | |
33 | }, | |
34 | ||
35 | // private | |
36 | showLogin: function() { | |
37 | var me = this; | |
38 | ||
39 | PVE.Utils.authClear(); | |
40 | PVE.UserName = null; | |
41 | me.loginData = null; | |
42 | ||
43 | if (!me.login) { | |
44 | me.login = Ext.create('PVE.window.LoginWindow', { | |
45 | handler: function(data) { | |
46 | me.login = null; | |
47 | me.updateLoginData(data); | |
48 | PVE.Utils.checked_command(function() {}); // display subscription status | |
49 | } | |
50 | }); | |
51 | } | |
52 | me.onLogin(null); | |
53 | me.login.show(); | |
54 | }, | |
55 | ||
56 | initComponent : function() { | |
57 | var me = this; | |
58 | ||
59 | Ext.tip.QuickTipManager.init(); | |
60 | ||
61 | // fixme: what about other errors | |
62 | Ext.Ajax.on('requestexception', function(conn, response, options) { | |
63 | if (response.status == 401) { // auth failure | |
64 | me.showLogin(); | |
65 | } | |
66 | }); | |
67 | ||
787ae72a DM |
68 | me.callParent(); |
69 | ||
70 | if (!PVE.Utils.authOK()) { | |
71 | me.showLogin(); | |
72 | } else { | |
73 | if (me.loginData) { | |
74 | me.onLogin(me.loginData); | |
75 | } | |
76 | } | |
77 | ||
78 | Ext.TaskManager.start({ | |
79 | run: function() { | |
80 | var ticket = PVE.Utils.authOK(); | |
81 | if (!ticket || !PVE.UserName) { | |
82 | return; | |
83 | } | |
84 | ||
85 | Ext.Ajax.request({ | |
86 | params: { | |
87 | username: PVE.UserName, | |
88 | password: ticket | |
89 | }, | |
90 | url: '/api2/json/access/ticket', | |
91 | method: 'POST', | |
92 | success: function(response, opts) { | |
93 | var obj = Ext.decode(response.responseText); | |
94 | me.updateLoginData(obj.data); | |
95 | } | |
96 | }); | |
97 | }, | |
98 | interval: 15*60*1000 | |
99 | }); | |
100 | ||
101 | } | |
102 | }); | |
103 | ||
104 | Ext.define('PVE.ConsoleWorkspace', { | |
105 | extend: 'PVE.Workspace', | |
106 | ||
107 | alias: ['widget.pveConsoleWorkspace'], | |
108 | ||
109 | title: gettext('Console'), | |
110 | ||
111 | initComponent : function() { | |
ec0bd652 DC |
112 | // novnc is a string in param |
113 | // but a boolean in content | |
114 | /*jslint confusion: true*/ | |
787ae72a DM |
115 | var me = this; |
116 | ||
117 | var param = Ext.Object.fromQueryString(window.location.search); | |
118 | var consoleType = me.consoleType || param.console; | |
119 | ||
120 | param.novnc = (param.novnc === '1') ? true : false; | |
121 | ||
122 | var content; | |
123 | if (consoleType === 'kvm') { | |
124 | me.title = "VM " + param.vmid; | |
125 | if (param.vmname) { | |
126 | me.title += " ('" + param.vmname + "')"; | |
127 | } | |
128 | content = { | |
129 | xtype: 'pveKVMConsole', | |
130 | novnc: param.novnc, | |
131 | vmid: param.vmid, | |
132 | nodename: param.node, | |
133 | vmname: param.vmname, | |
134 | toplevel: true | |
135 | }; | |
136 | } else if (consoleType === 'lxc') { | |
137 | me.title = "CT " + param.vmid; | |
138 | if (param.vmname) { | |
139 | me.title += " ('" + param.vmname + "')"; | |
140 | } | |
141 | content = { | |
142 | xtype: 'pveLxcConsole', | |
143 | novnc: param.novnc, | |
144 | vmid: param.vmid, | |
145 | nodename: param.node, | |
146 | vmname: param.vmname, | |
147 | toplevel: true | |
148 | }; | |
149 | } else if (consoleType === 'shell') { | |
150 | me.title = "node '" + param.node + "'"; | |
151 | content = { | |
152 | xtype: 'pveShell', | |
153 | novnc: param.novnc, | |
154 | nodename: param.node, | |
155 | toplevel: true | |
156 | }; | |
157 | } else if (consoleType === 'upgrade') { | |
158 | me.title = Ext.String.format(gettext('System upgrade on node {0}'), "'" + param.node + "'"); | |
159 | content = { | |
160 | xtype: 'pveShell', | |
161 | novnc: param.novnc, | |
162 | nodename: param.node, | |
163 | ugradeSystem: true, | |
164 | toplevel: true | |
165 | }; | |
166 | } else { | |
167 | content = { | |
168 | border: false, | |
169 | bodyPadding: 10, | |
170 | html: gettext('Error') + ': No such console type' | |
171 | }; | |
172 | } | |
173 | ||
174 | Ext.apply(me, { | |
175 | layout: { type: 'fit' }, | |
176 | border: false, | |
177 | items: [ content ] | |
178 | }); | |
179 | ||
180 | me.callParent(); | |
181 | } | |
182 | }); | |
183 | ||
184 | Ext.define('PVE.StdWorkspace', { | |
185 | extend: 'PVE.Workspace', | |
186 | ||
187 | alias: ['widget.pveStdWorkspace'], | |
188 | ||
189 | // private | |
190 | setContent: function(comp) { | |
191 | var me = this; | |
192 | ||
193 | var cont = me.child('#content'); | |
834ba9e4 DC |
194 | |
195 | var lay = cont.getLayout(); | |
196 | ||
197 | var cur = lay.getActiveItem(); | |
787ae72a DM |
198 | |
199 | if (comp) { | |
200 | PVE.Utils.setErrorMask(cont, false); | |
201 | comp.border = false; | |
202 | cont.add(comp); | |
834ba9e4 DC |
203 | if (cur !== null && lay.getNext()) { |
204 | lay.next(); | |
205 | var task = Ext.create('Ext.util.DelayedTask', function(){ | |
206 | cont.remove(cur); | |
207 | }); | |
208 | task.delay(10); | |
209 | } | |
210 | } | |
de7eeaac EK |
211 | else { |
212 | // helper for cleaning the content when logging out | |
213 | cont.removeAll(); | |
214 | } | |
787ae72a DM |
215 | }, |
216 | ||
217 | selectById: function(nodeid) { | |
218 | var me = this; | |
219 | var tree = me.down('pveResourceTree'); | |
220 | tree.selectById(nodeid); | |
221 | }, | |
222 | ||
223 | checkVmMigration: function(record) { | |
224 | var me = this; | |
225 | var tree = me.down('pveResourceTree'); | |
226 | tree.checkVmMigration(record); | |
227 | }, | |
228 | ||
229 | onLogin: function(loginData) { | |
230 | var me = this; | |
231 | ||
232 | me.updateUserInfo(); | |
233 | ||
234 | if (loginData) { | |
235 | PVE.data.ResourceStore.startUpdate(); | |
236 | ||
237 | PVE.Utils.API2Request({ | |
238 | url: '/version', | |
239 | method: 'GET', | |
240 | success: function(response) { | |
241 | PVE.VersionInfo = response.result.data; | |
242 | me.updateVersionInfo(); | |
243 | } | |
244 | }); | |
245 | } | |
246 | }, | |
247 | ||
248 | updateUserInfo: function() { | |
249 | var me = this; | |
250 | ||
251 | var ui = me.query('#userinfo')[0]; | |
252 | ||
253 | if (PVE.UserName) { | |
254 | var msg = Ext.String.format(gettext("You are logged in as {0}"), "'" + PVE.UserName + "'"); | |
255 | ui.update('<div class="x-unselectable" style="white-space:nowrap;">' + msg + '</div>'); | |
256 | } else { | |
257 | ui.update(''); | |
258 | } | |
6a71fe01 | 259 | ui.updateLayout(); |
787ae72a DM |
260 | }, |
261 | ||
262 | updateVersionInfo: function() { | |
263 | var me = this; | |
264 | ||
265 | var ui = me.query('#versioninfo')[0]; | |
266 | ||
267 | if (PVE.VersionInfo) { | |
268 | var version = PVE.VersionInfo.version + '-' + PVE.VersionInfo.release + '/' + | |
269 | PVE.VersionInfo.repoid; | |
55d727ca | 270 | ui.update('Virtual Environment ' + version); |
787ae72a | 271 | } else { |
55d727ca | 272 | ui.update('Virtual Environment'); |
787ae72a | 273 | } |
6a71fe01 | 274 | ui.updateLayout(); |
787ae72a DM |
275 | }, |
276 | ||
277 | initComponent : function() { | |
278 | var me = this; | |
279 | ||
280 | Ext.History.init(); | |
281 | ||
282 | var sprovider = Ext.create('PVE.StateProvider'); | |
283 | Ext.state.Manager.setProvider(sprovider); | |
284 | ||
aeb5e2f6 | 285 | var selview = Ext.create('PVE.form.ViewSelector'); |
787ae72a DM |
286 | |
287 | var rtree = Ext.createWidget('pveResourceTree', { | |
288 | viewFilter: selview.getViewFilter(), | |
289 | flex: 1, | |
aeb5e2f6 EK |
290 | selModel: { |
291 | selType: 'treemodel', | |
787ae72a DM |
292 | listeners: { |
293 | selectionchange: function(sm, selected) { | |
787ae72a DM |
294 | if (selected.length > 0) { |
295 | var n = selected[0]; | |
f184350f EK |
296 | var tlckup = { |
297 | root: 'PVE.dc.Config', | |
298 | node: 'PVE.node.Config', | |
299 | qemu: 'PVE.qemu.Config', | |
300 | lxc: 'PVE.lxc.Config', | |
301 | storage: 'PVE.storage.Browser', | |
302 | pool: 'pvePoolConfig' | |
303 | }; | |
304 | var comp = { | |
787ae72a DM |
305 | xtype: tlckup[n.data.type || 'root'] || |
306 | 'pvePanelConfig', | |
787ae72a DM |
307 | showSearch: (n.data.id === 'root') || |
308 | Ext.isDefined(n.data.groupbyid), | |
309 | pveSelNode: n, | |
310 | workspace: me, | |
311 | viewFilter: selview.getViewFilter() | |
312 | }; | |
313 | PVE.curSelectedNode = n; | |
f184350f | 314 | me.setContent(comp); |
787ae72a | 315 | } |
787ae72a DM |
316 | } |
317 | } | |
aeb5e2f6 | 318 | } |
787ae72a DM |
319 | }); |
320 | ||
321 | selview.on('select', function(combo, records) { | |
fb387756 | 322 | if (records) { |
787ae72a DM |
323 | var view = combo.getViewFilter(); |
324 | rtree.setViewFilter(view); | |
325 | } | |
326 | }); | |
327 | ||
328 | var caps = sprovider.get('GuiCap'); | |
329 | ||
330 | var createVM = Ext.createWidget('button', { | |
331 | pack: 'end', | |
f01259ee | 332 | margin: '3 5 0 0', |
787ae72a | 333 | baseCls: 'x-btn', |
d1f155b8 | 334 | iconCls: 'fa fa-desktop', |
787ae72a DM |
335 | text: gettext("Create VM"), |
336 | disabled: !caps.vms['VM.Allocate'], | |
337 | handler: function() { | |
338 | var wiz = Ext.create('PVE.qemu.CreateWizard', {}); | |
339 | wiz.show(); | |
340 | } | |
341 | }); | |
342 | ||
343 | var createCT = Ext.createWidget('button', { | |
344 | pack: 'end', | |
f01259ee | 345 | margin: '3 5 0 0', |
787ae72a | 346 | baseCls: 'x-btn', |
d1f155b8 | 347 | iconCls: 'fa fa-cube', |
787ae72a DM |
348 | text: gettext("Create CT"), |
349 | disabled: !caps.vms['VM.Allocate'], | |
350 | handler: function() { | |
351 | var wiz = Ext.create('PVE.lxc.CreateWizard', {}); | |
352 | wiz.show(); | |
353 | } | |
354 | }); | |
355 | ||
356 | sprovider.on('statechange', function(sp, key, value) { | |
357 | if (key === 'GuiCap' && value) { | |
358 | caps = value; | |
359 | createVM.setDisabled(!caps.vms['VM.Allocate']); | |
360 | createCT.setDisabled(!caps.vms['VM.Allocate']); | |
361 | } | |
362 | }); | |
363 | ||
364 | Ext.apply(me, { | |
365 | layout: { type: 'border' }, | |
366 | border: false, | |
367 | items: [ | |
368 | { | |
369 | region: 'north', | |
787ae72a DM |
370 | layout: { |
371 | type: 'hbox', | |
f76884fd | 372 | align: 'middle' |
787ae72a DM |
373 | }, |
374 | baseCls: 'x-plain', | |
375 | defaults: { | |
376 | baseCls: 'x-plain' | |
377 | }, | |
378 | border: false, | |
f76884fd | 379 | margin: '2 0 2 5', |
787ae72a DM |
380 | items: [ |
381 | { | |
787ae72a | 382 | html: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' + |
55d727ca | 383 | '<img style="padding-top:4px;padding-right:5px" src="/pve2/images/proxmox_logo.png"/></a>' |
787ae72a DM |
384 | }, |
385 | { | |
386 | minWidth: 200, | |
787ae72a | 387 | id: 'versioninfo', |
55d727ca | 388 | html: 'Virtual Environment' |
787ae72a | 389 | }, |
839eed58 DC |
390 | { |
391 | xtype: 'pveGlobalSearchField', | |
392 | tree: rtree | |
393 | }, | |
394 | { | |
395 | flex: 1 | |
396 | }, | |
787ae72a DM |
397 | { |
398 | pack: 'end', | |
787ae72a DM |
399 | id: 'userinfo', |
400 | stateful: false | |
401 | }, | |
ce11a8af DC |
402 | { |
403 | xtype: 'button', | |
d0cbdb2b DC |
404 | margin: '0 10 0 3', |
405 | iconCls: 'fa black fa-gear', | |
406 | handler: function() { | |
407 | var win = Ext.create('PVE.window.Settings'); | |
408 | win.show(); | |
ce11a8af DC |
409 | } |
410 | }, | |
3ef58611 DC |
411 | { |
412 | xtype: 'pveHelpButton', | |
413 | hidden: false, | |
414 | iconCls: 'fa fa-info-circle x-btn-icon-el-default-toolbar-small ', | |
415 | listenToGlobalEvent: false, | |
c8802a60 | 416 | onlineHelp: 'pve_documentation_index', |
3ef58611 DC |
417 | margin: '0 5 0 0' |
418 | }, | |
6a7465ae EK |
419 | createVM, |
420 | createCT, | |
787ae72a DM |
421 | { |
422 | pack: 'end', | |
f76884fd | 423 | margin: '0 5 0 0', |
787ae72a DM |
424 | xtype: 'button', |
425 | baseCls: 'x-btn', | |
d1f155b8 | 426 | iconCls: 'fa fa-sign-out', |
787ae72a DM |
427 | text: gettext("Logout"), |
428 | handler: function() { | |
de7eeaac | 429 | PVE.data.ResourceStore.loadData([], false); |
787ae72a | 430 | me.showLogin(); |
de7eeaac | 431 | me.setContent(null); |
787ae72a DM |
432 | var rt = me.down('pveResourceTree'); |
433 | rt.clearTree(); | |
de7eeaac EK |
434 | |
435 | // empty the stores of the StatusPanel child items | |
436 | var statusPanels = Ext.ComponentQuery.query('pveStatusPanel grid'); | |
437 | Ext.Array.forEach(statusPanels, function(comp) { | |
438 | if (comp.getStore()) { | |
439 | comp.getStore().loadData([], false); | |
440 | } | |
441 | }); | |
787ae72a | 442 | } |
6a7465ae | 443 | } |
787ae72a DM |
444 | ] |
445 | }, | |
446 | { | |
447 | region: 'center', | |
29aedb75 DC |
448 | stateful: true, |
449 | stateId: 'pvecenter', | |
450 | minWidth: 100, | |
451 | minHeight: 100, | |
787ae72a DM |
452 | id: 'content', |
453 | xtype: 'container', | |
834ba9e4 | 454 | layout: { type: 'card' }, |
787ae72a | 455 | border: false, |
f01259ee | 456 | margin: '0 5 0 0', |
787ae72a DM |
457 | items: [] |
458 | }, | |
459 | { | |
460 | region: 'west', | |
29aedb75 DC |
461 | stateful: true, |
462 | stateId: 'pvewest', | |
463 | itemId: 'west', | |
787ae72a DM |
464 | xtype: 'container', |
465 | border: false, | |
466 | layout: { type: 'vbox', align: 'stretch' }, | |
f01259ee | 467 | margin: '0 0 0 5', |
787ae72a DM |
468 | split: true, |
469 | width: 200, | |
29aedb75 DC |
470 | items: [ selview, rtree ], |
471 | listeners: { | |
472 | resize: function(panel, width, height) { | |
473 | var viewWidth = me.getSize().width; | |
474 | if (width > viewWidth - 100) { | |
475 | panel.setWidth(viewWidth - 100); | |
476 | } | |
477 | } | |
478 | } | |
787ae72a DM |
479 | }, |
480 | { | |
80e8b725 | 481 | xtype: 'pveStatusPanel', |
29aedb75 DC |
482 | stateful: true, |
483 | stateId: 'pvesouth', | |
484 | itemId: 'south', | |
787ae72a | 485 | region: 'south', |
f01259ee | 486 | margin:'0 5 5 5', |
6a87871f DC |
487 | title: gettext('Logs'), |
488 | collapsible: true, | |
489 | header: false, | |
29aedb75 DC |
490 | height: 200, |
491 | split:true, | |
492 | listeners: { | |
493 | resize: function(panel, width, height) { | |
29aedb75 DC |
494 | var viewHeight = me.getSize().height; |
495 | if (height > (viewHeight - 150)) { | |
496 | panel.setHeight(viewHeight - 150); | |
497 | } | |
498 | } | |
499 | } | |
787ae72a DM |
500 | } |
501 | ] | |
502 | }); | |
503 | ||
504 | me.callParent(); | |
505 | ||
506 | me.updateUserInfo(); | |
6c18be66 DC |
507 | |
508 | // on resize, center all modal windows | |
509 | Ext.on('resize', function(){ | |
510 | var wins = Ext.ComponentQuery.query('window[modal]'); | |
511 | if (wins.length > 0) { | |
512 | wins.forEach(function(win){ | |
513 | win.alignTo(me, 'c-c'); | |
514 | }); | |
515 | } | |
516 | }); | |
787ae72a DM |
517 | } |
518 | }); | |
519 |