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