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