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