]>
Commit | Line | Data |
---|---|---|
0bb29d35 DM |
1 | Ext.ns('Proxmox'); |
2 | Ext.ns('Proxmox.Setup'); | |
3 | ||
757cc58a DM |
4 | if (!Ext.isDefined(Proxmox.Setup.auth_cookie_name)) { |
5 | throw "Proxmox library not initialized"; | |
0bb29d35 DM |
6 | } |
7 | ||
8 | // avoid errors related to Accessible Rich Internet Applications | |
9 | // (access for people with disabilities) | |
10 | // TODO reenable after all components are upgraded | |
11 | Ext.enableAria = false; | |
12 | Ext.enableAriaButtons = false; | |
13 | Ext.enableAriaPanels = false; | |
14 | ||
15 | // avoid errors when running without development tools | |
16 | if (!Ext.isDefined(Ext.global.console)) { | |
17 | var console = { | |
18 | dir: function() {}, | |
19 | log: function() {} | |
20 | }; | |
21 | } | |
22 | ||
23 | Ext.Ajax.defaultHeaders = { | |
24 | 'Accept': 'application/json' | |
25 | }; | |
26 | ||
27 | Ext.Ajax.on('beforerequest', function(conn, options) { | |
28 | if (Proxmox.CSRFPreventionToken) { | |
29 | if (!options.headers) { | |
30 | options.headers = {}; | |
31 | } | |
32 | options.headers.CSRFPreventionToken = Proxmox.CSRFPreventionToken; | |
33 | } | |
34 | }); | |
35 | ||
36 | Ext.define('Proxmox.Utils', { utilities: { | |
37 | ||
38 | // this singleton contains miscellaneous utilities | |
39 | ||
30f885cb DM |
40 | yesText: gettext('Yes'), |
41 | noText: gettext('No'), | |
42 | enabledText: gettext('Enabled'), | |
43 | disabledText: gettext('Disabled'), | |
44 | noneText: gettext('none'), | |
45 | errorText: gettext('Error'), | |
a58001dd | 46 | unknownText: gettext('Unknown'), |
30f885cb DM |
47 | defaultText: gettext('Default'), |
48 | daysText: gettext('days'), | |
49 | dayText: gettext('day'), | |
50 | runningText: gettext('running'), | |
51 | stoppedText: gettext('stopped'), | |
52 | neverText: gettext('never'), | |
53 | totalText: gettext('Total'), | |
54 | usedText: gettext('Used'), | |
55 | directoryText: gettext('Directory'), | |
56 | stateText: gettext('State'), | |
57 | groupText: gettext('Group'), | |
58 | ||
f6f0066a | 59 | language_map: { |
0247a07a TL |
60 | zh_CN: 'Chinese (Simplified)', |
61 | zh_TW: 'Chinese (Traditional)', | |
f97a2a34 DC |
62 | ca: 'Catalan', |
63 | da: 'Danish', | |
f6f0066a | 64 | en: 'English', |
f97a2a34 | 65 | eu: 'Euskera (Basque)', |
f6f0066a DM |
66 | fr: 'French', |
67 | de: 'German', | |
68 | it: 'Italian', | |
f97a2a34 DC |
69 | es: 'Spanish', |
70 | ja: 'Japanese', | |
71 | nb: 'Norwegian (Bokmal)', | |
72 | nn: 'Norwegian (Nynorsk)', | |
73 | fa: 'Persian (Farsi)', | |
74 | pl: 'Polish', | |
75 | pt_BR: 'Portuguese (Brazil)', | |
76 | ru: 'Russian', | |
77 | sl: 'Slovenian', | |
78 | sv: 'Swedish', | |
79 | tr: 'Turkish' | |
f6f0066a DM |
80 | }, |
81 | ||
82 | render_language: function (value) { | |
83 | if (!value) { | |
84 | return Proxmox.Utils.defaultText + ' (English)'; | |
85 | } | |
86 | var text = Proxmox.Utils.language_map[value]; | |
87 | if (text) { | |
88 | return text + ' (' + value + ')'; | |
89 | } | |
90 | return value; | |
91 | }, | |
92 | ||
93 | language_array: function() { | |
94 | var data = [['__default__', Proxmox.Utils.render_language('')]]; | |
95 | Ext.Object.each(Proxmox.Utils.language_map, function(key, value) { | |
96 | data.push([key, Proxmox.Utils.render_language(value)]); | |
97 | }); | |
98 | ||
99 | return data; | |
100 | }, | |
101 | ||
8311c0b1 DC |
102 | bond_mode_gettext_map: { |
103 | '802.3ad': 'LACP (802.3ad)', | |
104 | 'lacp-balance-slb': 'LACP (balance-slb)', | |
105 | 'lacp-balance-tcp': 'LACP (balance-tcp)', | |
106 | }, | |
107 | ||
227fb07f | 108 | render_bond_mode: value => Proxmox.Utils.bond_mode_gettext_map[value] || value || '', |
8311c0b1 DC |
109 | |
110 | bond_mode_array: function(modes) { | |
61e428c2 | 111 | return modes.map(mode => [mode, Proxmox.Utils.render_bond_mode(mode)]); |
8311c0b1 DC |
112 | }, |
113 | ||
5f93e010 DM |
114 | getNoSubKeyHtml: function(url) { |
115 | // url http://www.proxmox.com/products/proxmox-ve/subscription-service-plans | |
3154bb78 | 116 | return Ext.String.format('You do not have a valid subscription for this server. Please visit <a target="_blank" href="{0}">www.proxmox.com</a> to get a list of available options.', url || 'https://www.proxmox.com'); |
5f93e010 DM |
117 | }, |
118 | ||
b0d9b5d1 DM |
119 | format_boolean_with_default: function(value) { |
120 | if (Ext.isDefined(value) && value !== '__default__') { | |
121 | return value ? Proxmox.Utils.yesText : Proxmox.Utils.noText; | |
122 | } | |
123 | return Proxmox.Utils.defaultText; | |
124 | }, | |
125 | ||
126 | format_boolean: function(value) { | |
127 | return value ? Proxmox.Utils.yesText : Proxmox.Utils.noText; | |
128 | }, | |
129 | ||
130 | format_neg_boolean: function(value) { | |
131 | return !value ? Proxmox.Utils.yesText : Proxmox.Utils.noText; | |
132 | }, | |
a58001dd | 133 | |
0e49da6d DM |
134 | format_enabled_toggle: function(value) { |
135 | return value ? Proxmox.Utils.enabledText : Proxmox.Utils.disabledText; | |
136 | }, | |
137 | ||
2d0153a5 DM |
138 | format_expire: function(date) { |
139 | if (!date) { | |
140 | return Proxmox.Utils.neverText; | |
141 | } | |
142 | return Ext.Date.format(date, "Y-m-d"); | |
143 | }, | |
144 | ||
452892df DM |
145 | format_duration_long: function(ut) { |
146 | ||
147 | var days = Math.floor(ut / 86400); | |
148 | ut -= days*86400; | |
149 | var hours = Math.floor(ut / 3600); | |
150 | ut -= hours*3600; | |
151 | var mins = Math.floor(ut / 60); | |
152 | ut -= mins*60; | |
153 | ||
154 | var hours_str = '00' + hours.toString(); | |
155 | hours_str = hours_str.substr(hours_str.length - 2); | |
156 | var mins_str = "00" + mins.toString(); | |
157 | mins_str = mins_str.substr(mins_str.length - 2); | |
158 | var ut_str = "00" + ut.toString(); | |
159 | ut_str = ut_str.substr(ut_str.length - 2); | |
160 | ||
161 | if (days) { | |
162 | var ds = days > 1 ? Proxmox.Utils.daysText : Proxmox.Utils.dayText; | |
163 | return days.toString() + ' ' + ds + ' ' + | |
164 | hours_str + ':' + mins_str + ':' + ut_str; | |
165 | } else { | |
166 | return hours_str + ':' + mins_str + ':' + ut_str; | |
167 | } | |
168 | }, | |
169 | ||
02ef30c9 DM |
170 | format_subscription_level: function(level) { |
171 | if (level === 'c') { | |
8f5a1a08 | 172 | return 'Community'; |
02ef30c9 | 173 | } else if (level === 'b') { |
8f5a1a08 | 174 | return 'Basic'; |
02ef30c9 | 175 | } else if (level === 's') { |
8f5a1a08 | 176 | return 'Standard'; |
02ef30c9 | 177 | } else if (level === 'p') { |
8f5a1a08 | 178 | return 'Premium'; |
02ef30c9 DM |
179 | } else { |
180 | return Proxmox.Utils.noneText; | |
181 | } | |
182 | }, | |
183 | ||
28e54f37 DM |
184 | compute_min_label_width: function(text, width) { |
185 | ||
186 | if (width === undefined) { width = 100; } | |
187 | ||
188 | var tm = new Ext.util.TextMetrics(); | |
189 | var min = tm.getWidth(text + ':'); | |
190 | ||
191 | return min < width ? width : min; | |
192 | }, | |
193 | ||
c2e25a21 WB |
194 | setAuthData: function(data) { |
195 | Proxmox.CSRFPreventionToken = data.CSRFPreventionToken; | |
196 | Proxmox.UserName = data.username; | |
197 | Proxmox.LoggedOut = data.LoggedOut; | |
198 | // creates a session cookie (expire = null) | |
199 | // that way the cookie gets deleted after the browser window is closed | |
200 | Ext.util.Cookies.set(Proxmox.Setup.auth_cookie_name, data.ticket, null, '/', null, true); | |
201 | }, | |
202 | ||
0bb29d35 | 203 | authOK: function() { |
c2e25a21 WB |
204 | if (Proxmox.LoggedOut) { |
205 | return undefined; | |
206 | } | |
0bb29d35 DM |
207 | return (Proxmox.UserName !== '') && Ext.util.Cookies.get(Proxmox.Setup.auth_cookie_name); |
208 | }, | |
209 | ||
210 | authClear: function() { | |
c2e25a21 WB |
211 | if (Proxmox.LoggedOut) { |
212 | return undefined; | |
213 | } | |
0bb29d35 DM |
214 | Ext.util.Cookies.clear(Proxmox.Setup.auth_cookie_name); |
215 | }, | |
216 | ||
217 | // comp.setLoading() is buggy in ExtJS 4.0.7, so we | |
218 | // use el.mask() instead | |
219 | setErrorMask: function(comp, msg) { | |
220 | var el = comp.el; | |
221 | if (!el) { | |
222 | return; | |
223 | } | |
224 | if (!msg) { | |
225 | el.unmask(); | |
226 | } else { | |
227 | if (msg === true) { | |
228 | el.mask(gettext("Loading...")); | |
229 | } else { | |
230 | el.mask(msg); | |
231 | } | |
232 | } | |
233 | }, | |
234 | ||
5b4b3ffd DM |
235 | monStoreErrors: function(me, store, clearMaskBeforeLoad) { |
236 | if (clearMaskBeforeLoad) { | |
237 | me.mon(store, 'beforeload', function(s, operation, eOpts) { | |
238 | Proxmox.Utils.setErrorMask(me, false); | |
e94c0767 | 239 | }); |
5b4b3ffd DM |
240 | } else { |
241 | me.mon(store, 'beforeload', function(s, operation, eOpts) { | |
242 | if (!me.loadCount) { | |
243 | me.loadCount = 0; // make sure it is numeric | |
244 | Proxmox.Utils.setErrorMask(me, true); | |
245 | } | |
246 | }); | |
247 | } | |
0bb29d35 DM |
248 | |
249 | // only works with 'proxmox' proxy | |
250 | me.mon(store.proxy, 'afterload', function(proxy, request, success) { | |
251 | me.loadCount++; | |
252 | ||
253 | if (success) { | |
254 | Proxmox.Utils.setErrorMask(me, false); | |
255 | return; | |
256 | } | |
257 | ||
258 | var msg; | |
259 | /*jslint nomen: true */ | |
260 | var operation = request._operation; | |
261 | var error = operation.getError(); | |
262 | if (error.statusText) { | |
263 | msg = error.statusText + ' (' + error.status + ')'; | |
264 | } else { | |
265 | msg = gettext('Connection error'); | |
266 | } | |
267 | Proxmox.Utils.setErrorMask(me, msg); | |
268 | }); | |
269 | }, | |
270 | ||
271 | extractRequestError: function(result, verbose) { | |
272 | var msg = gettext('Successful'); | |
273 | ||
274 | if (!result.success) { | |
275 | msg = gettext("Unknown error"); | |
276 | if (result.message) { | |
277 | msg = result.message; | |
278 | if (result.status) { | |
279 | msg += ' (' + result.status + ')'; | |
280 | } | |
281 | } | |
282 | if (verbose && Ext.isObject(result.errors)) { | |
283 | msg += "<br>"; | |
284 | Ext.Object.each(result.errors, function(prop, desc) { | |
285 | msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " + | |
286 | Ext.htmlEncode(desc); | |
287 | }); | |
288 | } | |
289 | } | |
290 | ||
291 | return msg; | |
292 | }, | |
293 | ||
294 | // Ext.Ajax.request | |
295 | API2Request: function(reqOpts) { | |
296 | ||
297 | var newopts = Ext.apply({ | |
298 | waitMsg: gettext('Please wait...') | |
299 | }, reqOpts); | |
300 | ||
301 | if (!newopts.url.match(/^\/api2/)) { | |
302 | newopts.url = '/api2/extjs' + newopts.url; | |
303 | } | |
304 | delete newopts.callback; | |
305 | ||
306 | var createWrapper = function(successFn, callbackFn, failureFn) { | |
307 | Ext.apply(newopts, { | |
308 | success: function(response, options) { | |
309 | if (options.waitMsgTarget) { | |
5812914c DC |
310 | if (Proxmox.Utils.toolkit === 'touch') { |
311 | options.waitMsgTarget.setMasked(false); | |
312 | } else { | |
313 | options.waitMsgTarget.setLoading(false); | |
314 | } | |
0bb29d35 DM |
315 | } |
316 | var result = Ext.decode(response.responseText); | |
317 | response.result = result; | |
318 | if (!result.success) { | |
319 | response.htmlStatus = Proxmox.Utils.extractRequestError(result, true); | |
320 | Ext.callback(callbackFn, options.scope, [options, false, response]); | |
321 | Ext.callback(failureFn, options.scope, [response, options]); | |
322 | return; | |
323 | } | |
324 | Ext.callback(callbackFn, options.scope, [options, true, response]); | |
325 | Ext.callback(successFn, options.scope, [response, options]); | |
326 | }, | |
327 | failure: function(response, options) { | |
328 | if (options.waitMsgTarget) { | |
5812914c DC |
329 | if (Proxmox.Utils.toolkit === 'touch') { |
330 | options.waitMsgTarget.setMasked(false); | |
331 | } else { | |
332 | options.waitMsgTarget.setLoading(false); | |
333 | } | |
0bb29d35 DM |
334 | } |
335 | response.result = {}; | |
336 | try { | |
337 | response.result = Ext.decode(response.responseText); | |
338 | } catch(e) {} | |
339 | var msg = gettext('Connection error') + ' - server offline?'; | |
340 | if (response.aborted) { | |
341 | msg = gettext('Connection error') + ' - aborted.'; | |
342 | } else if (response.timedout) { | |
343 | msg = gettext('Connection error') + ' - Timeout.'; | |
344 | } else if (response.status && response.statusText) { | |
345 | msg = gettext('Connection error') + ' ' + response.status + ': ' + response.statusText; | |
346 | } | |
347 | response.htmlStatus = msg; | |
348 | Ext.callback(callbackFn, options.scope, [options, false, response]); | |
349 | Ext.callback(failureFn, options.scope, [response, options]); | |
350 | } | |
351 | }); | |
352 | }; | |
353 | ||
354 | createWrapper(reqOpts.success, reqOpts.callback, reqOpts.failure); | |
355 | ||
356 | var target = newopts.waitMsgTarget; | |
357 | if (target) { | |
5812914c DC |
358 | if (Proxmox.Utils.toolkit === 'touch') { |
359 | target.setMasked({ xtype: 'loadmask', message: newopts.waitMsg} ); | |
360 | } else { | |
361 | // Note: ExtJS bug - this does not work when component is not rendered | |
362 | target.setLoading(newopts.waitMsg); | |
363 | } | |
0bb29d35 DM |
364 | } |
365 | Ext.Ajax.request(newopts); | |
366 | }, | |
367 | ||
5f93e010 DM |
368 | checked_command: function(orig_cmd) { |
369 | Proxmox.Utils.API2Request({ | |
370 | url: '/nodes/localhost/subscription', | |
371 | method: 'GET', | |
372 | //waitMsgTarget: me, | |
373 | failure: function(response, opts) { | |
374 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
375 | }, | |
376 | success: function(response, opts) { | |
377 | var data = response.result.data; | |
378 | ||
379 | if (data.status !== 'Active') { | |
380 | Ext.Msg.show({ | |
381 | title: gettext('No valid subscription'), | |
382 | icon: Ext.Msg.WARNING, | |
383 | msg: Proxmox.Utils.getNoSubKeyHtml(data.url), | |
384 | buttons: Ext.Msg.OK, | |
385 | callback: function(btn) { | |
386 | if (btn !== 'ok') { | |
387 | return; | |
388 | } | |
389 | orig_cmd(); | |
390 | } | |
391 | }); | |
392 | } else { | |
393 | orig_cmd(); | |
394 | } | |
395 | } | |
396 | }); | |
397 | }, | |
398 | ||
06694509 DM |
399 | assemble_field_data: function(values, data) { |
400 | if (Ext.isObject(data)) { | |
401 | Ext.Object.each(data, function(name, val) { | |
402 | if (values.hasOwnProperty(name)) { | |
403 | var bucket = values[name]; | |
404 | if (!Ext.isArray(bucket)) { | |
405 | bucket = values[name] = [bucket]; | |
406 | } | |
407 | if (Ext.isArray(val)) { | |
408 | values[name] = bucket.concat(val); | |
409 | } else { | |
410 | bucket.push(val); | |
411 | } | |
412 | } else { | |
413 | values[name] = val; | |
414 | } | |
415 | }); | |
416 | } | |
417 | }, | |
418 | ||
419 | dialog_title: function(subject, create, isAdd) { | |
420 | if (create) { | |
421 | if (isAdd) { | |
422 | return gettext('Add') + ': ' + subject; | |
423 | } else { | |
424 | return gettext('Create') + ': ' + subject; | |
425 | } | |
426 | } else { | |
427 | return gettext('Edit') + ': ' + subject; | |
428 | } | |
429 | }, | |
430 | ||
a58001dd DM |
431 | network_iface_types: { |
432 | eth: gettext("Network Device"), | |
433 | bridge: 'Linux Bridge', | |
434 | bond: 'Linux Bond', | |
8cb1ec17 | 435 | vlan: 'Linux VLAN', |
a58001dd DM |
436 | OVSBridge: 'OVS Bridge', |
437 | OVSBond: 'OVS Bond', | |
438 | OVSPort: 'OVS Port', | |
439 | OVSIntPort: 'OVS IntPort' | |
440 | }, | |
441 | ||
442 | render_network_iface_type: function(value) { | |
443 | return Proxmox.Utils.network_iface_types[value] || | |
444 | Proxmox.Utils.unknownText; | |
445 | }, | |
446 | ||
ab7fac0b | 447 | task_desc_table: { |
18ffbaef DC |
448 | acmenewcert: [ 'SRV', gettext('Order Certificate') ], |
449 | acmeregister: [ 'ACME Account', gettext('Register') ], | |
450 | acmedeactivate: [ 'ACME Account', gettext('Deactivate') ], | |
451 | acmeupdate: [ 'ACME Account', gettext('Update') ], | |
452 | acmerefresh: [ 'ACME Account', gettext('Refresh') ], | |
453 | acmerenew: [ 'SRV', gettext('Renew Certificate') ], | |
454 | acmerevoke: [ 'SRV', gettext('Revoke Certificate') ], | |
455 | 'move_volume': [ 'CT', gettext('Move Volume') ], | |
456 | clustercreate: [ '', gettext('Create Cluster') ], | |
457 | clusterjoin: [ '', gettext('Join Cluster') ], | |
ab7fac0b DC |
458 | diskinit: [ 'Disk', gettext('Initialize Disk with GPT') ], |
459 | vncproxy: [ 'VM/CT', gettext('Console') ], | |
460 | spiceproxy: [ 'VM/CT', gettext('Console') + ' (Spice)' ], | |
461 | vncshell: [ '', gettext('Shell') ], | |
462 | spiceshell: [ '', gettext('Shell') + ' (Spice)' ], | |
463 | qmsnapshot: [ 'VM', gettext('Snapshot') ], | |
464 | qmrollback: [ 'VM', gettext('Rollback') ], | |
465 | qmdelsnapshot: [ 'VM', gettext('Delete Snapshot') ], | |
466 | qmcreate: [ 'VM', gettext('Create') ], | |
467 | qmrestore: [ 'VM', gettext('Restore') ], | |
468 | qmdestroy: [ 'VM', gettext('Destroy') ], | |
469 | qmigrate: [ 'VM', gettext('Migrate') ], | |
470 | qmclone: [ 'VM', gettext('Clone') ], | |
471 | qmmove: [ 'VM', gettext('Move disk') ], | |
472 | qmtemplate: [ 'VM', gettext('Convert to template') ], | |
473 | qmstart: [ 'VM', gettext('Start') ], | |
474 | qmstop: [ 'VM', gettext('Stop') ], | |
475 | qmreset: [ 'VM', gettext('Reset') ], | |
476 | qmshutdown: [ 'VM', gettext('Shutdown') ], | |
b7d94d3e DC |
477 | qmsuspend: [ 'VM', gettext('Hibernate') ], |
478 | qmpause: [ 'VM', gettext('Pause') ], | |
ab7fac0b DC |
479 | qmresume: [ 'VM', gettext('Resume') ], |
480 | qmconfig: [ 'VM', gettext('Configure') ], | |
481 | vzsnapshot: [ 'CT', gettext('Snapshot') ], | |
482 | vzrollback: [ 'CT', gettext('Rollback') ], | |
483 | vzdelsnapshot: [ 'CT', gettext('Delete Snapshot') ], | |
484 | vzcreate: ['CT', gettext('Create') ], | |
485 | vzrestore: ['CT', gettext('Restore') ], | |
486 | vzdestroy: ['CT', gettext('Destroy') ], | |
487 | vzmigrate: [ 'CT', gettext('Migrate') ], | |
488 | vzclone: [ 'CT', gettext('Clone') ], | |
489 | vztemplate: [ 'CT', gettext('Convert to template') ], | |
490 | vzstart: ['CT', gettext('Start') ], | |
491 | vzstop: ['CT', gettext('Stop') ], | |
492 | vzmount: ['CT', gettext('Mount') ], | |
493 | vzumount: ['CT', gettext('Unmount') ], | |
494 | vzshutdown: ['CT', gettext('Shutdown') ], | |
495 | vzsuspend: [ 'CT', gettext('Suspend') ], | |
496 | vzresume: [ 'CT', gettext('Resume') ], | |
497 | hamigrate: [ 'HA', gettext('Migrate') ], | |
498 | hastart: [ 'HA', gettext('Start') ], | |
499 | hastop: [ 'HA', gettext('Stop') ], | |
500 | srvstart: ['SRV', gettext('Start') ], | |
501 | srvstop: ['SRV', gettext('Stop') ], | |
502 | srvrestart: ['SRV', gettext('Restart') ], | |
503 | srvreload: ['SRV', gettext('Reload') ], | |
18ffbaef DC |
504 | cephcreatemgr: ['Ceph Manager', gettext('Create') ], |
505 | cephdestroymgr: ['Ceph Manager', gettext('Destroy') ], | |
ab7fac0b DC |
506 | cephcreatemon: ['Ceph Monitor', gettext('Create') ], |
507 | cephdestroymon: ['Ceph Monitor', gettext('Destroy') ], | |
508 | cephcreateosd: ['Ceph OSD', gettext('Create') ], | |
509 | cephdestroyosd: ['Ceph OSD', gettext('Destroy') ], | |
510 | cephcreatepool: ['Ceph Pool', gettext('Create') ], | |
511 | cephdestroypool: ['Ceph Pool', gettext('Destroy') ], | |
9367da29 TL |
512 | cephfscreate: ['CephFS', gettext('Create') ], |
513 | cephcreatemds: ['Ceph Metadata Server', gettext('Create') ], | |
514 | cephdestroymds: ['Ceph Metadata Server', gettext('Destroy') ], | |
ab7fac0b DC |
515 | imgcopy: ['', gettext('Copy data') ], |
516 | imgdel: ['', gettext('Erase data') ], | |
99a5979b | 517 | unknownimgdel: ['', gettext('Destroy image from unknown guest') ], |
ab7fac0b | 518 | download: ['', gettext('Download') ], |
9138244f | 519 | vzdump: ['VM/CT', gettext('Backup') ], |
ab7fac0b DC |
520 | aptupdate: ['', gettext('Update package database') ], |
521 | startall: [ '', gettext('Start all VMs and Containers') ], | |
522 | stopall: [ '', gettext('Stop all VMs and Containers') ], | |
0908d830 DC |
523 | migrateall: [ '', gettext('Migrate all VMs and Containers') ], |
524 | dircreate: [ gettext('Directory Storage'), gettext('Create') ], | |
525 | lvmcreate: [ gettext('LVM Storage'), gettext('Create') ], | |
526 | lvmthincreate: [ gettext('LVM-Thin Storage'), gettext('Create') ], | |
527 | zfscreate: [ gettext('ZFS Storage'), gettext('Create') ] | |
ab7fac0b DC |
528 | }, |
529 | ||
53ac9bca | 530 | format_task_description: function(type, id) { |
ab7fac0b | 531 | var farray = Proxmox.Utils.task_desc_table[type]; |
c5aaa502 | 532 | var text; |
ab7fac0b | 533 | if (!farray) { |
c5aaa502 | 534 | text = type; |
ab7fac0b DC |
535 | if (id) { |
536 | type += ' ' + id; | |
537 | } | |
538 | return text; | |
539 | } | |
540 | var prefix = farray[0]; | |
c5aaa502 | 541 | text = farray[1]; |
ab7fac0b DC |
542 | if (prefix) { |
543 | return prefix + ' ' + id + ' - ' + text; | |
544 | } | |
545 | return text; | |
53ac9bca DM |
546 | }, |
547 | ||
b91c7ce2 DC |
548 | format_size: function(size) { |
549 | /*jslint confusion: true */ | |
550 | ||
551 | var units = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi']; | |
552 | var num = 0; | |
553 | ||
554 | while (size >= 1024 && ((num++)+1) < units.length) { | |
555 | size = size / 1024; | |
556 | } | |
557 | ||
558 | return size.toFixed((num > 0)?2:0) + " " + units[num] + "B"; | |
559 | }, | |
560 | ||
53ac9bca DM |
561 | render_upid: function(value, metaData, record) { |
562 | var type = record.data.type; | |
563 | var id = record.data.id; | |
564 | ||
565 | return Proxmox.Utils.format_task_description(type, id); | |
566 | }, | |
567 | ||
452892df DM |
568 | render_uptime: function(value) { |
569 | ||
570 | var uptime = value; | |
571 | ||
572 | if (uptime === undefined) { | |
573 | return ''; | |
574 | } | |
575 | ||
576 | if (uptime <= 0) { | |
577 | return '-'; | |
578 | } | |
579 | ||
580 | return Proxmox.Utils.format_duration_long(uptime); | |
581 | }, | |
582 | ||
06694509 DM |
583 | parse_task_upid: function(upid) { |
584 | var task = {}; | |
585 | ||
586 | var res = upid.match(/^UPID:(\S+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8,9}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/); | |
587 | if (!res) { | |
588 | throw "unable to parse upid '" + upid + "'"; | |
589 | } | |
590 | task.node = res[1]; | |
591 | task.pid = parseInt(res[2], 16); | |
592 | task.pstart = parseInt(res[3], 16); | |
593 | task.starttime = parseInt(res[4], 16); | |
594 | task.type = res[5]; | |
595 | task.id = res[6]; | |
596 | task.user = res[7]; | |
597 | ||
53ac9bca DM |
598 | task.desc = Proxmox.Utils.format_task_description(task.type, task.id); |
599 | ||
06694509 DM |
600 | return task; |
601 | }, | |
602 | ||
603 | render_timestamp: function(value, metaData, record, rowIndex, colIndex, store) { | |
604 | var servertime = new Date(value * 1000); | |
605 | return Ext.Date.format(servertime, 'Y-m-d H:i:s'); | |
881c9c0c DC |
606 | }, |
607 | ||
1098bee4 DC |
608 | get_help_info: function(section) { |
609 | var helpMap; | |
610 | if (typeof proxmoxOnlineHelpInfo !== 'undefined') { | |
611 | helpMap = proxmoxOnlineHelpInfo; | |
612 | } else if (typeof pveOnlineHelpInfo !== 'undefined') { | |
613 | // be backward compatible with older pve-doc-generators | |
614 | helpMap = pveOnlineHelpInfo; | |
615 | } else { | |
616 | throw "no global OnlineHelpInfo map declared"; | |
617 | } | |
618 | ||
619 | return helpMap[section]; | |
620 | }, | |
621 | ||
622 | get_help_link: function(section) { | |
623 | var info = Proxmox.Utils.get_help_info(section); | |
624 | if (!info) { | |
625 | return; | |
626 | } | |
627 | ||
628 | return window.location.origin + info.link; | |
629 | }, | |
630 | ||
f80f1f94 TM |
631 | openXtermJsViewer: function(vmtype, vmid, nodename, vmname, cmd) { |
632 | var url = Ext.Object.toQueryString({ | |
881c9c0c DC |
633 | console: vmtype, // kvm, lxc, upgrade or shell |
634 | xtermjs: 1, | |
635 | vmid: vmid, | |
636 | vmname: vmname, | |
f80f1f94 TM |
637 | node: nodename, |
638 | cmd: cmd, | |
639 | ||
881c9c0c DC |
640 | }); |
641 | var nw = window.open("?" + url, '_blank', 'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=800,height=420'); | |
9bf01f76 DC |
642 | if (nw) { |
643 | nw.focus(); | |
644 | } | |
e94c0767 | 645 | } |
06694509 | 646 | |
881c9c0c | 647 | }, |
5ffef550 | 648 | |
0bb29d35 DM |
649 | singleton: true, |
650 | constructor: function() { | |
651 | var me = this; | |
652 | Ext.apply(me, me.utilities); | |
653 | ||
654 | var IPV4_OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])"; | |
655 | var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")"; | |
656 | var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})"; | |
657 | var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")"; | |
577b6c75 ML |
658 | var IPV4_CIDR_MASK = "([0-9]{1,2})"; |
659 | var IPV6_CIDR_MASK = "([0-9]{1,3})"; | |
0bb29d35 DM |
660 | |
661 | ||
662 | me.IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$"); | |
577b6c75 | 663 | me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/" + IPV4_CIDR_MASK + "$"); |
0bb29d35 DM |
664 | |
665 | var IPV6_REGEXP = "(?:" + | |
666 | "(?:(?:" + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" + | |
667 | "(?:(?:" + "::" + "(?:" + IPV6_H16 + ":){5})" + IPV6_LS32 + ")|" + | |
668 | "(?:(?:(?:" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){4})" + IPV6_LS32 + ")|" + | |
669 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,1}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){3})" + IPV6_LS32 + ")|" + | |
670 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,2}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){2})" + IPV6_LS32 + ")|" + | |
671 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,3}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){1})" + IPV6_LS32 + ")|" + | |
672 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,4}" + IPV6_H16 + ")?::" + ")" + IPV6_LS32 + ")|" + | |
673 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,5}" + IPV6_H16 + ")?::" + ")" + IPV6_H16 + ")|" + | |
674 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,7}" + IPV6_H16 + ")?::" + ")" + ")" + | |
675 | ")"; | |
676 | ||
677 | me.IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$"); | |
577b6c75 | 678 | me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/" + IPV6_CIDR_MASK + "$"); |
0bb29d35 DM |
679 | me.IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]"); |
680 | ||
681 | me.IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$"); | |
577b6c75 | 682 | me.IP64_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + "\/" + IPV6_CIDR_MASK + ")|(?:" + IPV4_REGEXP + "\/" + IPV4_CIDR_MASK + ")$"); |
0bb29d35 DM |
683 | |
684 | var DnsName_REGEXP = "(?:(([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)\\.)*([A-Za-z0-9]([A-Za-z0-9\\-]*[A-Za-z0-9])?))"; | |
685 | me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$"); | |
686 | ||
687 | me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$"); | |
688 | me.HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$"); | |
689 | me.IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$"); | |
690 | } | |
691 | }); |