]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - Utils.js
fix #2421: ComboGrid: correctly validate multiSelect variant
[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 errorText: gettext('Error'),
46 unknownText: gettext('Unknown'),
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
59 language_map: {
60 ca: 'Catalan',
61 da: 'Danish',
62 de: 'German',
63 en: 'English',
64 es: 'Spanish',
65 eu: 'Euskera (Basque)',
66 fa: 'Persian (Farsi)',
67 fr: 'French',
68 he: 'Hebrew',
69 it: 'Italian',
70 ja: 'Japanese',
71 nb: 'Norwegian (Bokmal)',
72 nn: 'Norwegian (Nynorsk)',
73 pl: 'Polish',
74 pt_BR: 'Portuguese (Brazil)',
75 ru: 'Russian',
76 sl: 'Slovenian',
77 sv: 'Swedish',
78 tr: 'Turkish',
79 zh_CN: 'Chinese (Simplified)',
80 zh_TW: 'Chinese (Traditional)',
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
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
109 render_bond_mode: value => Proxmox.Utils.bond_mode_gettext_map[value] || value || '',
110
111 bond_mode_array: function(modes) {
112 return modes.map(mode => [mode, Proxmox.Utils.render_bond_mode(mode)]);
113 },
114
115 getNoSubKeyHtml: function(url) {
116 // url http://www.proxmox.com/products/proxmox-ve/subscription-service-plans
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');
118 },
119
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 },
134
135 format_enabled_toggle: function(value) {
136 return value ? Proxmox.Utils.enabledText : Proxmox.Utils.disabledText;
137 },
138
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
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
171 format_subscription_level: function(level) {
172 if (level === 'c') {
173 return 'Community';
174 } else if (level === 'b') {
175 return 'Basic';
176 } else if (level === 's') {
177 return 'Standard';
178 } else if (level === 'p') {
179 return 'Premium';
180 } else {
181 return Proxmox.Utils.noneText;
182 }
183 },
184
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
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
204 authOK: function() {
205 if (Proxmox.LoggedOut) {
206 return undefined;
207 }
208 return (Proxmox.UserName !== '') && Ext.util.Cookies.get(Proxmox.Setup.auth_cookie_name);
209 },
210
211 authClear: function() {
212 if (Proxmox.LoggedOut) {
213 return undefined;
214 }
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
236 monStoreErrors: function(me, store, clearMaskBeforeLoad) {
237 if (clearMaskBeforeLoad) {
238 me.mon(store, 'beforeload', function(s, operation, eOpts) {
239 Proxmox.Utils.setErrorMask(me, false);
240 });
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 }
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) {
311 if (Proxmox.Utils.toolkit === 'touch') {
312 options.waitMsgTarget.setMasked(false);
313 } else {
314 options.waitMsgTarget.setLoading(false);
315 }
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) {
330 if (Proxmox.Utils.toolkit === 'touch') {
331 options.waitMsgTarget.setMasked(false);
332 } else {
333 options.waitMsgTarget.setLoading(false);
334 }
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) {
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 }
365 }
366 Ext.Ajax.request(newopts);
367 },
368
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,
384 msg: Proxmox.Utils.getNoSubKeyHtml(data.url),
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
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
432 network_iface_types: {
433 eth: gettext("Network Device"),
434 bridge: 'Linux Bridge',
435 bond: 'Linux Bond',
436 vlan: 'Linux VLAN',
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
448 task_desc_table: {
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') ],
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') ],
478 qmreboot: [ 'VM', gettext('Reboot') ],
479 qmsuspend: [ 'VM', gettext('Hibernate') ],
480 qmpause: [ 'VM', gettext('Pause') ],
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') ],
497 vzreboot: ['CT', gettext('Reboot') ],
498 vzsuspend: [ 'CT', gettext('Suspend') ],
499 vzresume: [ 'CT', gettext('Resume') ],
500 hamigrate: [ 'HA', gettext('Migrate') ],
501 hastart: [ 'HA', gettext('Start') ],
502 hastop: [ 'HA', gettext('Stop') ],
503 srvstart: ['SRV', gettext('Start') ],
504 srvstop: ['SRV', gettext('Stop') ],
505 srvrestart: ['SRV', gettext('Restart') ],
506 srvreload: ['SRV', gettext('Reload') ],
507 cephcreatemgr: ['Ceph Manager', gettext('Create') ],
508 cephdestroymgr: ['Ceph Manager', gettext('Destroy') ],
509 cephcreatemon: ['Ceph Monitor', gettext('Create') ],
510 cephdestroymon: ['Ceph Monitor', gettext('Destroy') ],
511 cephcreateosd: ['Ceph OSD', gettext('Create') ],
512 cephdestroyosd: ['Ceph OSD', gettext('Destroy') ],
513 cephcreatepool: ['Ceph Pool', gettext('Create') ],
514 cephdestroypool: ['Ceph Pool', gettext('Destroy') ],
515 cephfscreate: ['CephFS', gettext('Create') ],
516 cephcreatemds: ['Ceph Metadata Server', gettext('Create') ],
517 cephdestroymds: ['Ceph Metadata Server', gettext('Destroy') ],
518 imgcopy: ['', gettext('Copy data') ],
519 imgdel: ['', gettext('Erase data') ],
520 unknownimgdel: ['', gettext('Destroy image from unknown guest') ],
521 download: ['', gettext('Download') ],
522 vzdump: ['VM/CT', gettext('Backup') ],
523 aptupdate: ['', gettext('Update package database') ],
524 startall: [ '', gettext('Start all VMs and Containers') ],
525 stopall: [ '', gettext('Stop all VMs and Containers') ],
526 migrateall: [ '', gettext('Migrate all VMs and Containers') ],
527 dircreate: [ gettext('Directory Storage'), gettext('Create') ],
528 lvmcreate: [ gettext('LVM Storage'), gettext('Create') ],
529 lvmthincreate: [ gettext('LVM-Thin Storage'), gettext('Create') ],
530 zfscreate: [ gettext('ZFS Storage'), gettext('Create') ]
531 },
532
533 format_task_description: function(type, id) {
534 var farray = Proxmox.Utils.task_desc_table[type];
535 var text;
536 if (!farray) {
537 text = type;
538 if (id) {
539 type += ' ' + id;
540 }
541 return text;
542 }
543 var prefix = farray[0];
544 text = farray[1];
545 if (prefix) {
546 return prefix + ' ' + id + ' - ' + text;
547 }
548 return text;
549 },
550
551 format_size: function(size) {
552 /*jslint confusion: true */
553
554 var units = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'];
555 var num = 0;
556
557 while (size >= 1024 && ((num++)+1) < units.length) {
558 size = size / 1024;
559 }
560
561 return size.toFixed((num > 0)?2:0) + " " + units[num] + "B";
562 },
563
564 render_upid: function(value, metaData, record) {
565 var type = record.data.type;
566 var id = record.data.id;
567
568 return Proxmox.Utils.format_task_description(type, id);
569 },
570
571 render_uptime: function(value) {
572
573 var uptime = value;
574
575 if (uptime === undefined) {
576 return '';
577 }
578
579 if (uptime <= 0) {
580 return '-';
581 }
582
583 return Proxmox.Utils.format_duration_long(uptime);
584 },
585
586 parse_task_upid: function(upid) {
587 var task = {};
588
589 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]+):$/);
590 if (!res) {
591 throw "unable to parse upid '" + upid + "'";
592 }
593 task.node = res[1];
594 task.pid = parseInt(res[2], 16);
595 task.pstart = parseInt(res[3], 16);
596 task.starttime = parseInt(res[4], 16);
597 task.type = res[5];
598 task.id = res[6];
599 task.user = res[7];
600
601 task.desc = Proxmox.Utils.format_task_description(task.type, task.id);
602
603 return task;
604 },
605
606 render_timestamp: function(value, metaData, record, rowIndex, colIndex, store) {
607 var servertime = new Date(value * 1000);
608 return Ext.Date.format(servertime, 'Y-m-d H:i:s');
609 },
610
611 get_help_info: function(section) {
612 var helpMap;
613 if (typeof proxmoxOnlineHelpInfo !== 'undefined') {
614 helpMap = proxmoxOnlineHelpInfo;
615 } else if (typeof pveOnlineHelpInfo !== 'undefined') {
616 // be backward compatible with older pve-doc-generators
617 helpMap = pveOnlineHelpInfo;
618 } else {
619 throw "no global OnlineHelpInfo map declared";
620 }
621
622 return helpMap[section];
623 },
624
625 get_help_link: function(section) {
626 var info = Proxmox.Utils.get_help_info(section);
627 if (!info) {
628 return;
629 }
630
631 return window.location.origin + info.link;
632 },
633
634 openXtermJsViewer: function(vmtype, vmid, nodename, vmname, cmd) {
635 var url = Ext.Object.toQueryString({
636 console: vmtype, // kvm, lxc, upgrade or shell
637 xtermjs: 1,
638 vmid: vmid,
639 vmname: vmname,
640 node: nodename,
641 cmd: cmd,
642
643 });
644 var nw = window.open("?" + url, '_blank', 'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=800,height=420');
645 if (nw) {
646 nw.focus();
647 }
648 }
649
650 },
651
652 singleton: true,
653 constructor: function() {
654 var me = this;
655 Ext.apply(me, me.utilities);
656
657 var IPV4_OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
658 var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")";
659 var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})";
660 var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
661 var IPV4_CIDR_MASK = "([0-9]{1,2})";
662 var IPV6_CIDR_MASK = "([0-9]{1,3})";
663
664
665 me.IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
666 me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/" + IPV4_CIDR_MASK + "$");
667
668 var IPV6_REGEXP = "(?:" +
669 "(?:(?:" + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
670 "(?:(?:" + "::" + "(?:" + IPV6_H16 + ":){5})" + IPV6_LS32 + ")|" +
671 "(?:(?:(?:" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){4})" + IPV6_LS32 + ")|" +
672 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,1}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){3})" + IPV6_LS32 + ")|" +
673 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,2}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){2})" + IPV6_LS32 + ")|" +
674 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,3}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){1})" + IPV6_LS32 + ")|" +
675 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,4}" + IPV6_H16 + ")?::" + ")" + IPV6_LS32 + ")|" +
676 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,5}" + IPV6_H16 + ")?::" + ")" + IPV6_H16 + ")|" +
677 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,7}" + IPV6_H16 + ")?::" + ")" + ")" +
678 ")";
679
680 me.IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
681 me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/" + IPV6_CIDR_MASK + "$");
682 me.IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
683
684 me.IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
685 me.IP64_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + "\/" + IPV6_CIDR_MASK + ")|(?:" + IPV4_REGEXP + "\/" + IPV4_CIDR_MASK + ")$");
686
687 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])?))";
688 me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");
689
690 me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$");
691 me.HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$");
692 me.IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$");
693 }
694 });