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