]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/Utils.js
remove reference to PVE.ConsoleWorkspace
[pve-manager.git] / www / manager6 / Utils.js
CommitLineData
b0a6d326
EK
1Ext.ns('PVE');
2
63b9faae
EK
3// avoid errors related to Accessible Rich Internet Applications
4// (access for people with disabilities)
0be88ae1 5// TODO reenable after all components are upgraded
63b9faae
EK
6Ext.enableAria = false;
7Ext.enableAriaButtons = false;
8Ext.enableAriaPanels = false;
9
b0a6d326 10// avoid errors when running without development tools
0be88ae1
DC
11if (!Ext.isDefined(Ext.global.console)) {
12 var console = {
13 dir: function() {},
14 log: function() {}
b0a6d326
EK
15 };
16}
0be88ae1 17console.log("Starting PVE Manager");
b0a6d326
EK
18
19Ext.Ajax.defaultHeaders = {
20 'Accept': 'application/json'
21};
22
23Ext.Ajax.on('beforerequest', function(conn, options) {
24 if (PVE.CSRFPreventionToken) {
0be88ae1 25 if (!options.headers) {
b0a6d326
EK
26 options.headers = {};
27 }
28 options.headers.CSRFPreventionToken = PVE.CSRFPreventionToken;
29 }
30});
31
9fa2e36d 32Ext.define('PVE.Utils', { utilities: {
b0a6d326 33
9fa2e36d 34 // this singleton contains miscellaneous utilities
b0a6d326 35
0be88ae1 36 toolkit: undefined, // (extjs|touch), set inside Toolkit.js
b0a6d326 37
98a01af2
EK
38 bus_match: /^(ide|sata|virtio|scsi)\d+$/,
39
b0a6d326
EK
40 log_severity_hash: {
41 0: "panic",
42 1: "alert",
43 2: "critical",
44 3: "error",
45 4: "warning",
46 5: "notice",
47 6: "info",
48 7: "debug"
49 },
50
51 support_level_hash: {
52 'c': gettext('Community'),
53 'b': gettext('Basic'),
54 's': gettext('Standard'),
55 'p': gettext('Premium')
56 },
57
58 noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit <a target="_blank" href="http://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.',
59
60 kvm_ostypes: {
61 other: gettext('Other OS types'),
62 wxp: 'Microsoft Windows XP/2003',
63 w2k: 'Microsoft Windows 2000',
64 w2k8: 'Microsoft Windows Vista/2008',
65 win7: 'Microsoft Windows 7/2008r2',
2b9e8828
EK
66 win8: 'Microsoft Windows 8.x/2012/2012r2',
67 win10: 'Microsoft Windows 10/2016',
b0a6d326 68 l24: 'Linux 2.4 Kernel',
5a4ba3c2 69 l26: 'Linux 4.X/3.X/2.6 Kernel',
b0a6d326
EK
70 solaris: 'Solaris Kernel'
71 },
72
428bc4a2
DC
73 get_health_icon: function(state, circle) {
74 if (circle === undefined) {
75 circle = false;
76 }
77
78 if (state === undefined) {
79 state = 'uknown';
80 }
81
82 var icon = 'faded fa-question';
83 switch(state) {
84 case 'good':
85 icon = 'good fa-check';
86 break;
87 case 'warning':
88 icon = 'warning fa-exclamation';
89 break;
90 case 'critical':
91 icon = 'critical fa-times';
92 break;
93 default: break;
94 }
95
96 if (circle) {
97 icon += '-circle';
98 }
99
100 return icon;
101 },
102
046e640c
DC
103 map_ceph_health: {
104 'HEALTH_OK':'good',
105 'HEALTH_WARN':'warning',
106 'HEALTH_ERR':'critical'
107 },
108
109 render_ceph_health: function(record) {
110 var state = {
111 iconCls: PVE.Utils.get_health_icon(),
112 text: ''
113 };
114
115 if (!record || !record.data) {
116 return state;
117 }
118
119 var health = PVE.Utils.map_ceph_health[record.data.health.overall_status];
120
121 state.iconCls = PVE.Utils.get_health_icon(health, true);
122 state.text = record.data.health.overall_status;
123
124 return state;
125 },
126
b0a6d326
EK
127 render_kvm_ostype: function (value) {
128 if (!value) {
129 return gettext('Other OS types');
130 }
131 var text = PVE.Utils.kvm_ostypes[value];
132 if (text) {
b7159d8b 133 return text;
b0a6d326
EK
134 }
135 return value;
136 },
137
138 render_hotplug_features: function (value) {
23d3881a 139 var fa = [];
b0a6d326
EK
140
141 if (!value || (value === '0')) {
142 return gettext('disabled');
143 }
144
4dcca8a4
DC
145 if (value === '1') {
146 value = 'disk,network,usb';
147 }
148
b0a6d326
EK
149 Ext.each(value.split(','), function(el) {
150 if (el === 'disk') {
151 fa.push(gettext('Disk'));
152 } else if (el === 'network') {
153 fa.push(gettext('Network'));
154 } else if (el === 'usb') {
155 fa.push(gettext('USB'));
156 } else if (el === 'memory') {
157 fa.push(gettext('Memory'));
158 } else if (el === 'cpu') {
159 fa.push(gettext('CPU'));
160 } else {
161 fa.push(el);
162 }
163 });
164
165 return fa.join(', ');
166 },
167
168 network_iface_types: {
169 eth: gettext("Network Device"),
170 bridge: 'Linux Bridge',
171 bond: 'Linux Bond',
172 OVSBridge: 'OVS Bridge',
173 OVSBond: 'OVS Bond',
174 OVSPort: 'OVS Port',
175 OVSIntPort: 'OVS IntPort'
176 },
177
178 render_network_iface_type: function(value) {
0be88ae1 179 return PVE.Utils.network_iface_types[value] ||
b0a6d326
EK
180 PVE.Utils.unknownText;
181 },
182
17c71f27
DC
183 render_qemu_bios: function(value) {
184 if (!value) {
185 return PVE.Utils.defaultText + ' (SeaBIOS)';
186 } else if (value === 'seabios') {
187 return "SeaBIOS";
188 } else if (value === 'ovmf') {
189 return "OVMF (UEFI)";
190 } else {
191 return value;
192 }
193 },
194
b0a6d326
EK
195 render_scsihw: function(value) {
196 if (!value) {
197 return PVE.Utils.defaultText + ' (LSI 53C895A)';
198 } else if (value === 'lsi') {
199 return 'LSI 53C895A';
200 } else if (value === 'lsi53c810') {
201 return 'LSI 53C810';
202 } else if (value === 'megasas') {
203 return 'MegaRAID SAS 8708EM2';
204 } else if (value === 'virtio-scsi-pci') {
49f5d1ab
EK
205 return 'VirtIO SCSI';
206 } else if (value === 'virtio-scsi-single') {
207 return 'VirtIO SCSI single';
b0a6d326
EK
208 } else if (value === 'pvscsi') {
209 return 'VMware PVSCSI';
210 } else {
211 return value;
212 }
213 },
214
215 // fixme: auto-generate this
216 // for now, please keep in sync with PVE::Tools::kvmkeymaps
217 kvm_keymaps: {
218 //ar: 'Arabic',
219 da: 'Danish',
0be88ae1
DC
220 de: 'German',
221 'de-ch': 'German (Swiss)',
222 'en-gb': 'English (UK)',
0a5b8747 223 'en-us': 'English (USA)',
b0a6d326
EK
224 es: 'Spanish',
225 //et: 'Estonia',
226 fi: 'Finnish',
0be88ae1
DC
227 //fo: 'Faroe Islands',
228 fr: 'French',
229 'fr-be': 'French (Belgium)',
b0a6d326
EK
230 'fr-ca': 'French (Canada)',
231 'fr-ch': 'French (Swiss)',
232 //hr: 'Croatia',
233 hu: 'Hungarian',
234 is: 'Icelandic',
0be88ae1 235 it: 'Italian',
b0a6d326
EK
236 ja: 'Japanese',
237 lt: 'Lithuanian',
238 //lv: 'Latvian',
0be88ae1 239 mk: 'Macedonian',
b0a6d326
EK
240 nl: 'Dutch',
241 //'nl-be': 'Dutch (Belgium)',
0be88ae1 242 no: 'Norwegian',
b0a6d326
EK
243 pl: 'Polish',
244 pt: 'Portuguese',
245 'pt-br': 'Portuguese (Brazil)',
246 //ru: 'Russian',
247 sl: 'Slovenian',
248 sv: 'Swedish',
249 //th: 'Thai',
250 tr: 'Turkish'
251 },
252
253 kvm_vga_drivers: {
254 std: gettext('Standard VGA'),
5ca366f2 255 vmware: gettext('VMware compatible'),
b0a6d326
EK
256 cirrus: 'Cirrus Logic GD5446',
257 qxl: 'SPICE',
258 qxl2: 'SPICE dual monitor',
259 qxl3: 'SPICE three monitors',
260 qxl4: 'SPICE four monitors',
261 serial0: gettext('Serial terminal') + ' 0',
262 serial1: gettext('Serial terminal') + ' 1',
263 serial2: gettext('Serial terminal') + ' 2',
264 serial3: gettext('Serial terminal') + ' 3'
265 },
266
267 render_kvm_language: function (value) {
268 if (!value) {
269 return PVE.Utils.defaultText;
270 }
271 var text = PVE.Utils.kvm_keymaps[value];
272 if (text) {
273 return text + ' (' + value + ')';
274 }
275 return value;
276 },
277
278 kvm_keymap_array: function() {
f2782813 279 var data = [['__default__', PVE.Utils.render_kvm_language('')]];
b0a6d326
EK
280 Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) {
281 data.push([key, PVE.Utils.render_kvm_language(value)]);
282 });
283
284 return data;
285 },
286
287 render_console_viewer: function(value) {
f2782813 288 if (!value || value === '__default__') {
b0a6d326 289 return PVE.Utils.defaultText + ' (HTML5)';
b0a6d326
EK
290 } else if (value === 'vv') {
291 return 'SPICE (remote-viewer)';
292 } else if (value === 'html5') {
293 return 'HTML5 (noVNC)';
294 } else {
295 return value;
296 }
297 },
298
299 language_map: {
300 zh_CN: 'Chinese',
301 ca: 'Catalan',
302 da: 'Danish',
303 en: 'English',
304 eu: 'Euskera (Basque)',
305 fr: 'French',
306 de: 'German',
307 it: 'Italian',
308 ja: 'Japanese',
309 nb: 'Norwegian (Bokmal)',
310 nn: 'Norwegian (Nynorsk)',
311 fa: 'Persian (Farsi)',
312 pl: 'Polish',
313 pt_BR: 'Portuguese (Brazil)',
314 ru: 'Russian',
315 sl: 'Slovenian',
316 es: 'Spanish',
317 sv: 'Swedish',
318 tr: 'Turkish'
319 },
320
321 render_language: function (value) {
322 if (!value) {
323 return PVE.Utils.defaultText + ' (English)';
324 }
325 var text = PVE.Utils.language_map[value];
326 if (text) {
327 return text + ' (' + value + ')';
328 }
329 return value;
330 },
331
332 language_array: function() {
d98a2c3c 333 var data = [['__default__', PVE.Utils.render_language('')]];
b0a6d326
EK
334 Ext.Object.each(PVE.Utils.language_map, function(key, value) {
335 data.push([key, PVE.Utils.render_language(value)]);
336 });
337
338 return data;
339 },
340
341 render_kvm_vga_driver: function (value) {
342 if (!value) {
343 return PVE.Utils.defaultText;
344 }
345 var text = PVE.Utils.kvm_vga_drivers[value];
0be88ae1 346 if (text) {
b0a6d326
EK
347 return text + ' (' + value + ')';
348 }
349 return value;
350 },
351
352 kvm_vga_driver_array: function() {
f2782813 353 var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]];
b0a6d326
EK
354 Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) {
355 data.push([key, PVE.Utils.render_kvm_vga_driver(value)]);
356 });
357
358 return data;
359 },
360
361 render_kvm_startup: function(value) {
362 var startup = PVE.Parser.parseStartup(value);
363
364 var res = 'order=';
365 if (startup.order === undefined) {
366 res += 'any';
367 } else {
368 res += startup.order;
369 }
370 if (startup.up !== undefined) {
371 res += ',up=' + startup.up;
372 }
373 if (startup.down !== undefined) {
374 res += ',down=' + startup.down;
375 }
376
377 return res;
378 },
379
380 authOK: function() {
381 return Ext.util.Cookies.get('PVEAuthCookie');
382 },
383
384 authClear: function() {
385 Ext.util.Cookies.clear("PVEAuthCookie");
386 },
387
388 // fixme: remove - not needed?
389 gridLineHeigh: function() {
390 return 21;
0be88ae1 391
b0a6d326
EK
392 //if (Ext.isGecko)
393 //return 23;
394 //return 21;
395 },
396
397 extractRequestError: function(result, verbose) {
398 var msg = gettext('Successful');
399
400 if (!result.success) {
401 msg = gettext("Unknown error");
402 if (result.message) {
403 msg = result.message;
404 if (result.status) {
405 msg += ' (' + result.status + ')';
406 }
407 }
408 if (verbose && Ext.isObject(result.errors)) {
409 msg += "<br>";
410 Ext.Object.each(result.errors, function(prop, desc) {
0be88ae1 411 msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " +
b0a6d326
EK
412 Ext.htmlEncode(desc);
413 });
0be88ae1 414 }
b0a6d326
EK
415 }
416
417 return msg;
418 },
419
420 extractFormActionError: function(action) {
421 var msg;
422 switch (action.failureType) {
423 case Ext.form.action.Action.CLIENT_INVALID:
424 msg = gettext('Form fields may not be submitted with invalid values');
425 break;
426 case Ext.form.action.Action.CONNECT_FAILURE:
427 msg = gettext('Connection error');
428 var resp = action.response;
429 if (resp.status && resp.statusText) {
430 msg += " " + resp.status + ": " + resp.statusText;
431 }
432 break;
433 case Ext.form.action.Action.LOAD_FAILURE:
434 case Ext.form.action.Action.SERVER_INVALID:
435 msg = PVE.Utils.extractRequestError(action.result, true);
436 break;
437 }
438 return msg;
439 },
440
441 // Ext.Ajax.request
442 API2Request: function(reqOpts) {
443
444 var newopts = Ext.apply({
445 waitMsg: gettext('Please wait...')
446 }, reqOpts);
447
448 if (!newopts.url.match(/^\/api2/)) {
449 newopts.url = '/api2/extjs' + newopts.url;
450 }
451 delete newopts.callback;
452
453 var createWrapper = function(successFn, callbackFn, failureFn) {
454 Ext.apply(newopts, {
455 success: function(response, options) {
456 if (options.waitMsgTarget) {
457 if (PVE.Utils.toolkit === 'touch') {
458 options.waitMsgTarget.setMasked(false);
459 } else {
460 options.waitMsgTarget.setLoading(false);
461 }
462 }
463 var result = Ext.decode(response.responseText);
464 response.result = result;
465 if (!result.success) {
466 response.htmlStatus = PVE.Utils.extractRequestError(result, true);
467 Ext.callback(callbackFn, options.scope, [options, false, response]);
468 Ext.callback(failureFn, options.scope, [response, options]);
469 return;
470 }
471 Ext.callback(callbackFn, options.scope, [options, true, response]);
472 Ext.callback(successFn, options.scope, [response, options]);
473 },
474 failure: function(response, options) {
475 if (options.waitMsgTarget) {
476 if (PVE.Utils.toolkit === 'touch') {
477 options.waitMsgTarget.setMasked(false);
478 } else {
479 options.waitMsgTarget.setLoading(false);
480 }
481 }
482 response.result = {};
483 try {
484 response.result = Ext.decode(response.responseText);
485 } catch(e) {}
486 var msg = gettext('Connection error') + ' - server offline?';
487 if (response.aborted) {
488 msg = gettext('Connection error') + ' - aborted.';
489 } else if (response.timedout) {
490 msg = gettext('Connection error') + ' - Timeout.';
491 } else if (response.status && response.statusText) {
492 msg = gettext('Connection error') + ' ' + response.status + ': ' + response.statusText;
493 }
494 response.htmlStatus = msg;
495 Ext.callback(callbackFn, options.scope, [options, false, response]);
496 Ext.callback(failureFn, options.scope, [response, options]);
497 }
498 });
499 };
500
501 createWrapper(reqOpts.success, reqOpts.callback, reqOpts.failure);
502
503 var target = newopts.waitMsgTarget;
504 if (target) {
505 if (PVE.Utils.toolkit === 'touch') {
506 target.setMasked({ xtype: 'loadmask', message: newopts.waitMsg} );
507 } else {
508 // Note: ExtJS bug - this does not work when component is not rendered
509 target.setLoading(newopts.waitMsg);
510 }
511 }
512 Ext.Ajax.request(newopts);
513 },
514
515 assemble_field_data: function(values, data) {
516 if (Ext.isObject(data)) {
517 Ext.Object.each(data, function(name, val) {
518 if (values.hasOwnProperty(name)) {
519 var bucket = values[name];
520 if (!Ext.isArray(bucket)) {
521 bucket = values[name] = [bucket];
522 }
523 if (Ext.isArray(val)) {
524 values[name] = bucket.concat(val);
525 } else {
526 bucket.push(val);
527 }
528 } else {
529 values[name] = val;
530 }
531 });
532 }
533 },
534
535 checked_command: function(orig_cmd) {
536 PVE.Utils.API2Request({
537 url: '/nodes/localhost/subscription',
538 method: 'GET',
539 //waitMsgTarget: me,
540 failure: function(response, opts) {
541 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
542 },
543 success: function(response, opts) {
544 var data = response.result.data;
545
546 if (data.status !== 'Active') {
547 Ext.Msg.show({
548 title: gettext('No valid subscription'),
549 icon: Ext.Msg.WARNING,
550 msg: PVE.Utils.noSubKeyHtml,
551 buttons: Ext.Msg.OK,
552 callback: function(btn) {
553 if (btn !== 'ok') {
554 return;
555 }
556 orig_cmd();
557 }
558 });
559 } else {
560 orig_cmd();
561 }
562 }
563 });
564 },
565
566 task_desc_table: {
a36deac4 567 diskinit: [ 'Disk', gettext('Initialize GPT') ],
b0a6d326
EK
568 vncproxy: [ 'VM/CT', gettext('Console') ],
569 spiceproxy: [ 'VM/CT', gettext('Console') + ' (Spice)' ],
570 vncshell: [ '', gettext('Shell') ],
571 spiceshell: [ '', gettext('Shell') + ' (Spice)' ],
572 qmsnapshot: [ 'VM', gettext('Snapshot') ],
573 qmrollback: [ 'VM', gettext('Rollback') ],
574 qmdelsnapshot: [ 'VM', gettext('Delete Snapshot') ],
575 qmcreate: [ 'VM', gettext('Create') ],
576 qmrestore: [ 'VM', gettext('Restore') ],
577 qmdestroy: [ 'VM', gettext('Destroy') ],
578 qmigrate: [ 'VM', gettext('Migrate') ],
579 qmclone: [ 'VM', gettext('Clone') ],
580 qmmove: [ 'VM', gettext('Move disk') ],
581 qmtemplate: [ 'VM', gettext('Convert to template') ],
582 qmstart: [ 'VM', gettext('Start') ],
583 qmstop: [ 'VM', gettext('Stop') ],
584 qmreset: [ 'VM', gettext('Reset') ],
585 qmshutdown: [ 'VM', gettext('Shutdown') ],
586 qmsuspend: [ 'VM', gettext('Suspend') ],
587 qmresume: [ 'VM', gettext('Resume') ],
588 qmconfig: [ 'VM', gettext('Configure') ],
16152937
DM
589 vzsnapshot: [ 'CT', gettext('Snapshot') ],
590 vzrollback: [ 'CT', gettext('Rollback') ],
591 vzdelsnapshot: [ 'CT', gettext('Delete Snapshot') ],
b0a6d326
EK
592 vzcreate: ['CT', gettext('Create') ],
593 vzrestore: ['CT', gettext('Restore') ],
594 vzdestroy: ['CT', gettext('Destroy') ],
595 vzmigrate: [ 'CT', gettext('Migrate') ],
bfade4b4
DM
596 vzclone: [ 'CT', gettext('Clone') ],
597 vztemplate: [ 'CT', gettext('Convert to template') ],
b0a6d326
EK
598 vzstart: ['CT', gettext('Start') ],
599 vzstop: ['CT', gettext('Stop') ],
600 vzmount: ['CT', gettext('Mount') ],
601 vzumount: ['CT', gettext('Unmount') ],
602 vzshutdown: ['CT', gettext('Shutdown') ],
603 vzsuspend: [ 'CT', gettext('Suspend') ],
604 vzresume: [ 'CT', gettext('Resume') ],
605 hamigrate: [ 'HA', gettext('Migrate') ],
606 hastart: [ 'HA', gettext('Start') ],
607 hastop: [ 'HA', gettext('Stop') ],
608 srvstart: ['SRV', gettext('Start') ],
609 srvstop: ['SRV', gettext('Stop') ],
610 srvrestart: ['SRV', gettext('Restart') ],
611 srvreload: ['SRV', gettext('Reload') ],
612 cephcreatemon: ['Ceph Monitor', gettext('Create') ],
613 cephdestroymon: ['Ceph Monitor', gettext('Destroy') ],
614 cephcreateosd: ['Ceph OSD', gettext('Create') ],
615 cephdestroyosd: ['Ceph OSD', gettext('Destroy') ],
616 imgcopy: ['', gettext('Copy data') ],
617 imgdel: ['', gettext('Erase data') ],
618 download: ['', gettext('Download') ],
619 vzdump: ['', gettext('Backup') ],
620 aptupdate: ['', gettext('Update package database') ],
621 startall: [ '', gettext('Start all VMs and Containers') ],
622 stopall: [ '', gettext('Stop all VMs and Containers') ],
623 migrateall: [ '', gettext('Migrate all VMs and Containers') ]
624 },
625
0be88ae1 626 format_task_description: function(type, id) {
b0a6d326
EK
627 var farray = PVE.Utils.task_desc_table[type];
628 if (!farray) {
629 return type;
630 }
631 var prefix = farray[0];
632 var text = farray[1];
633 if (prefix) {
0be88ae1 634 return prefix + ' ' + id + ' - ' + text;
b0a6d326
EK
635 }
636 return text;
637 },
638
639 parse_task_upid: function(upid) {
640 var task = {};
641
642 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]+):$/);
643 if (!res) {
644 throw "unable to parse upid '" + upid + "'";
645 }
646 task.node = res[1];
647 task.pid = parseInt(res[2], 16);
648 task.pstart = parseInt(res[3], 16);
649 task.starttime = parseInt(res[4], 16);
650 task.type = res[5];
651 task.id = res[6];
652 task.user = res[7];
653
654 task.desc = PVE.Utils.format_task_description(task.type, task.id);
655
656 return task;
657 },
658
659 format_size: function(size) {
660 /*jslint confusion: true */
661
02f47fe8
DC
662 var units = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'];
663 var num = 0;
b0a6d326 664
02f47fe8
DC
665 while (size >= 1024 && ((num++)+1) < units.length) {
666 size = size / 1024;
b0a6d326
EK
667 }
668
02f47fe8 669 return size.toFixed((num > 0)?2:0) + " " + units[num] + "B";
b0a6d326
EK
670 },
671
672 format_html_bar: function(per, text) {
673
674 return "<div class='pve-bar-wrap'>" + text + "<div class='pve-bar-border'>" +
675 "<div class='pve-bar-inner' style='width:" + per + "%;'></div>" +
676 "</div></div>";
0be88ae1 677
b0a6d326
EK
678 },
679
680 format_cpu_bar: function(per1, per2, text) {
681
682 return "<div class='pve-bar-border'>" +
683 "<div class='pve-bar-inner' style='width:" + per1 + "%;'></div>" +
684 "<div class='pve-bar-inner2' style='width:" + per2 + "%;'></div>" +
0be88ae1 685 "<div class='pve-bar-text'>" + text + "</div>" +
b0a6d326
EK
686 "</div>";
687 },
688
689 format_large_bar: function(per, text) {
690
691 if (!text) {
692 text = per.toFixed(1) + "%";
693 }
694
695 return "<div class='pve-largebar-border'>" +
696 "<div class='pve-largebar-inner' style='width:" + per + "%;'></div>" +
0be88ae1 697 "<div class='pve-largebar-text'>" + text + "</div>" +
b0a6d326
EK
698 "</div>";
699 },
700
701 format_duration_long: function(ut) {
702
703 var days = Math.floor(ut / 86400);
704 ut -= days*86400;
705 var hours = Math.floor(ut / 3600);
706 ut -= hours*3600;
707 var mins = Math.floor(ut / 60);
708 ut -= mins*60;
709
710 var hours_str = '00' + hours.toString();
711 hours_str = hours_str.substr(hours_str.length - 2);
712 var mins_str = "00" + mins.toString();
713 mins_str = mins_str.substr(mins_str.length - 2);
714 var ut_str = "00" + ut.toString();
715 ut_str = ut_str.substr(ut_str.length - 2);
716
717 if (days) {
718 var ds = days > 1 ? PVE.Utils.daysText : PVE.Utils.dayText;
0be88ae1 719 return days.toString() + ' ' + ds + ' ' +
b0a6d326
EK
720 hours_str + ':' + mins_str + ':' + ut_str;
721 } else {
722 return hours_str + ':' + mins_str + ':' + ut_str;
723 }
724 },
725
726 format_duration_short: function(ut) {
0be88ae1 727
b0a6d326
EK
728 if (ut < 60) {
729 return ut.toString() + 's';
730 }
731
732 if (ut < 3600) {
733 var mins = ut / 60;
734 return mins.toFixed(0) + 'm';
735 }
736
737 if (ut < 86400) {
738 var hours = ut / 3600;
739 return hours.toFixed(0) + 'h';
740 }
741
742 var days = ut / 86400;
0be88ae1 743 return days.toFixed(0) + 'd';
b0a6d326
EK
744 },
745
746 yesText: gettext('Yes'),
747 noText: gettext('No'),
748 noneText: gettext('none'),
749 errorText: gettext('Error'),
750 unknownText: gettext('Unknown'),
751 defaultText: gettext('Default'),
752 daysText: gettext('days'),
753 dayText: gettext('day'),
754 runningText: gettext('running'),
755 stoppedText: gettext('stopped'),
756 neverText: gettext('never'),
757 totalText: gettext('Total'),
758 usedText: gettext('Used'),
759 directoryText: gettext('Directory'),
760 imagesText: gettext('Disk image'),
761 backupFileText: gettext('VZDump backup file'),
2c554952 762 vztmplText: gettext('Container template'),
b0a6d326 763 isoImageText: gettext('ISO image'),
2c554952 764 containersText: gettext('Container'),
45ab85bb
DM
765 stateText: gettext('State'),
766 groupText: gettext('Group'),
b0a6d326
EK
767
768 format_expire: function(date) {
769 if (!date) {
770 return PVE.Utils.neverText;
771 }
772 return Ext.Date.format(date, "Y-m-d");
773 },
774
775 format_storage_type: function(value) {
776 if (value === 'dir') {
777 return PVE.Utils.directoryText;
778 } else if (value === 'nfs') {
779 return 'NFS';
780 } else if (value === 'glusterfs') {
781 return 'GlusterFS';
782 } else if (value === 'lvm') {
783 return 'LVM';
ffd96a3b
DM
784 } else if (value === 'lvmthin') {
785 return 'LVM-Thin';
b0a6d326
EK
786 } else if (value === 'iscsi') {
787 return 'iSCSI';
788 } else if (value === 'rbd') {
789 return 'RBD';
790 } else if (value === 'sheepdog') {
791 return 'Sheepdog';
792 } else if (value === 'zfs') {
793 return 'ZFS over iSCSI';
794 } else if (value === 'zfspool') {
795 return 'ZFS';
796 } else if (value === 'iscsidirect') {
797 return 'iSCSIDirect';
ffd96a3b
DM
798 } else if (value === 'drbd') {
799 return 'DRBD';
b0a6d326
EK
800 } else {
801 return PVE.Utils.unknownText;
802 }
803 },
804
805 format_boolean_with_default: function(value) {
f2782813 806 if (Ext.isDefined(value) && value !== '__default__') {
b0a6d326
EK
807 return value ? PVE.Utils.yesText : PVE.Utils.noText;
808 }
809 return PVE.Utils.defaultText;
810 },
811
812 format_boolean: function(value) {
813 return value ? PVE.Utils.yesText : PVE.Utils.noText;
814 },
815
816 format_neg_boolean: function(value) {
817 return !value ? PVE.Utils.yesText : PVE.Utils.noText;
818 },
819
ced1677b
TL
820 format_ha: function(value) {
821 var text = PVE.Utils.format_boolean(value.managed);
822
823 if (value.managed) {
45ab85bb 824 text += ', ' + PVE.Utils.stateText + ': ';
f25d7c4a 825 text += value.state || PVE.Utils.noneText;
ced1677b 826
45ab85bb 827 text += ', ' + PVE.Utils.groupText + ': ';
f25d7c4a 828 text += value.group || PVE.Utils.noneText;
ced1677b
TL
829 }
830
831 return text;
832 },
833
b0a6d326
EK
834 format_content_types: function(value) {
835 var cta = [];
836
837 Ext.each(value.split(',').sort(), function(ct) {
838 if (ct === 'images') {
839 cta.push(PVE.Utils.imagesText);
840 } else if (ct === 'backup') {
841 cta.push(PVE.Utils.backupFileText);
842 } else if (ct === 'vztmpl') {
843 cta.push(PVE.Utils.vztmplText);
844 } else if (ct === 'iso') {
845 cta.push(PVE.Utils.isoImageText);
846 } else if (ct === 'rootdir') {
847 cta.push(PVE.Utils.containersText);
848 }
849 });
850
851 return cta.join(', ');
852 },
853
854 render_storage_content: function(value, metaData, record) {
855 var data = record.data;
856 if (Ext.isNumber(data.channel) &&
857 Ext.isNumber(data.id) &&
858 Ext.isNumber(data.lun)) {
0be88ae1
DC
859 return "CH " +
860 Ext.String.leftPad(data.channel,2, '0') +
b0a6d326
EK
861 " ID " + data.id + " LUN " + data.lun;
862 }
863 return data.volid.replace(/^.*:(.*\/)?/,'');
864 },
865
866 render_serverity: function (value) {
867 return PVE.Utils.log_severity_hash[value] || value;
868 },
869
870 render_cpu: function(value, metaData, record, rowIndex, colIndex, store) {
871
872 if (!(record.data.uptime && Ext.isNumeric(value))) {
873 return '';
874 }
875
876 var maxcpu = record.data.maxcpu || 1;
877
878 if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
879 return '';
880 }
0be88ae1 881
b0a6d326
EK
882 var per = value * 100;
883
884 return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
885 },
886
887 render_size: function(value, metaData, record, rowIndex, colIndex, store) {
888 /*jslint confusion: true */
889
890 if (!Ext.isNumeric(value)) {
891 return '';
892 }
893
894 return PVE.Utils.format_size(value);
895 },
896
946730cd
DC
897 render_bandwidth: function(value) {
898 if (!Ext.isNumeric(value)) {
899 return '';
900 }
901
902 return PVE.Utils.format_size(value) + '/s';
903 },
904
b0a6d326
EK
905 render_timestamp: function(value, metaData, record, rowIndex, colIndex, store) {
906 var servertime = new Date(value * 1000);
907 return Ext.Date.format(servertime, 'Y-m-d H:i:s');
908 },
909
0bfc799f
DC
910 calculate_mem_usage: function(data) {
911 if (!Ext.isNumeric(data.mem) ||
912 data.maxmem === 0 ||
913 data.uptime < 1) {
914 return -1;
915 }
916
917 return (data.mem / data.maxmem);
918 },
919
920 render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
921 if (!Ext.isNumeric(value) || value === -1) {
922 return '';
923 }
924 if (value > 1 ) {
925 // we got no percentage but bytes
926 var mem = value;
927 var maxmem = record.data.maxmem;
928 if (!record.data.uptime ||
929 maxmem === 0 ||
930 !Ext.isNumeric(mem)) {
931 return '';
932 }
933
934 return ((mem*100)/maxmem).toFixed(1) + " %";
935 }
936 return (value*100).toFixed(1) + " %";
937 },
938
b0a6d326
EK
939 render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
940
941 var mem = value;
942 var maxmem = record.data.maxmem;
0be88ae1 943
b0a6d326
EK
944 if (!record.data.uptime) {
945 return '';
946 }
947
948 if (!(Ext.isNumeric(mem) && maxmem)) {
949 return '';
950 }
951
728f1b97 952 return PVE.Utils.render_size(value);
b0a6d326
EK
953 },
954
0bfc799f
DC
955 calculate_disk_usage: function(data) {
956
957 if (!Ext.isNumeric(data.disk) ||
958 data.type === 'qemu' ||
959 (data.type === 'lxc' && data.uptime === 0) ||
960 data.maxdisk === 0) {
961 return -1;
962 }
963
964 return (data.disk / data.maxdisk);
965 },
966
967 render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
968 if (!Ext.isNumeric(value) || value === -1) {
969 return '';
970 }
971
972 return (value * 100).toFixed(1) + " %";
973 },
974
b0a6d326
EK
975 render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) {
976
977 var disk = value;
978 var maxdisk = record.data.maxdisk;
728f1b97 979 var type = record.data.type;
b0a6d326 980
728f1b97
DC
981 if (!Ext.isNumeric(disk) ||
982 type === 'qemu' ||
983 maxdisk === 0 ||
984 (type === 'lxc' && record.data.uptime === 0)) {
b0a6d326
EK
985 return '';
986 }
987
728f1b97 988 return PVE.Utils.render_size(value);
b0a6d326
EK
989 },
990
991 render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
992
b1d8e73d
DC
993 var icon = '';
994 var gridcls = '';
995
996 switch (value) {
997 case 'lxc': icon = 'cube';
998 gridcls = '-stopped';
999 break;
1000 case 'qemu': icon = 'desktop';
1001 gridcls = '-stopped';
1002 break;
1003 case 'node': icon = 'building';
1004 gridcls = '-offline';
1005 break;
1006 case 'storage': icon = 'database'; break;
1007 case 'pool': icon = 'tags'; break;
1008 default: icon = 'file';
1009 }
1010
1011 if (value === 'lxc' || value === 'qemu') {
1012 if (record.data.running && record.data.status !== 'paused') {
1013 gridcls = '-running';
1014 } else if (record.data.running) {
1015 gridcls = '-paused';
1016 }
1017 if (record.data.template) {
1018 icon = 'file-o';
1019 gridcls = '-template-' + value;
1020 }
1021 } else if (value === 'node') {
1022 if (record.data.running) {
a764c5f7 1023 gridcls = '-online';
b1d8e73d 1024 }
b0a6d326
EK
1025 }
1026
2b2fe160
DC
1027 // overwrite anything else
1028 if (record.data.hastate === 'error') {
1029 gridcls = '-offline';
1030 }
1031
a764c5f7 1032 var fa = '<i class="fa fa-fw x-fa-grid' + gridcls + ' fa-' + icon + '"></i> ';
b1d8e73d 1033 return fa + value;
b0a6d326
EK
1034 },
1035
1036 render_uptime: function(value, metaData, record, rowIndex, colIndex, store) {
1037
1038 var uptime = value;
1039
1040 if (uptime === undefined) {
1041 return '';
1042 }
0be88ae1 1043
b0a6d326
EK
1044 if (uptime <= 0) {
1045 return '-';
1046 }
1047
1048 return PVE.Utils.format_duration_long(uptime);
1049 },
1050
1051 render_support_level: function(value, metaData, record) {
1052 return PVE.Utils.support_level_hash[value] || '-';
1053 },
1054
0be88ae1 1055 render_upid: function(value, metaData, record) {
b0a6d326
EK
1056 var type = record.data.type;
1057 var id = record.data.id;
1058
1059 return PVE.Utils.format_task_description(type, id);
1060 },
1061
054ac1b8
DC
1062 /* render functions for new status panel */
1063
1064 render_usage: function(val) {
1065 return (val*100).toFixed(2) + '%';
1066 },
1067
1068 render_cpu_usage: function(val, max) {
1069 return Ext.String.format(gettext('{0}% of {1}') +
1070 ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max);
1071 },
1072
1073 render_size_usage: function(val, max) {
bab64974
DC
1074 if (max === 0) {
1075 return gettext('N/A');
1076 }
054ac1b8
DC
1077 return (val*100/max).toFixed(2) + '% '+ '(' +
1078 Ext.String.format(gettext('{0} of {1}'),
1079 PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')';
1080 },
1081
1082 /* this is different for nodes */
1083 render_node_cpu_usage: function(value, record) {
1084 return PVE.Utils.render_cpu_usage(value, record.cpus);
1085 },
1086
1087 /* this is different for nodes */
1088 render_node_size_usage: function(record) {
1089 return PVE.Utils.render_size_usage(record.used, record.total);
1090 },
1091
b0a6d326
EK
1092 dialog_title: function(subject, create, isAdd) {
1093 if (create) {
1094 if (isAdd) {
1095 return gettext('Add') + ': ' + subject;
1096 } else {
1097 return gettext('Create') + ': ' + subject;
1098 }
1099 } else {
1100 return gettext('Edit') + ': ' + subject;
1101 }
1102 },
aa0819a8
WB
1103
1104 windowHostname: function() {
c15c61d3 1105 return window.location.hostname.replace(PVE.Utils.IP6_bracket_match,
aa0819a8
WB
1106 function(m, addr, offset, original) { return addr; });
1107 },
0be88ae1 1108
b0a6d326
EK
1109 openDefaultConsoleWindow: function(allowSpice, vmtype, vmid, nodename, vmname) {
1110 var dv = PVE.Utils.defaultViewer(allowSpice);
1111 PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname);
1112 },
1113
1114 openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname) {
9e361643 1115 // kvm, lxc, shell, upgrade
b0a6d326 1116
9e361643 1117 if (vmid == undefined && (vmtype === 'kvm' || vmtype === 'lxc')) {
b0a6d326
EK
1118 throw "missing vmid";
1119 }
1120
1121 if (!nodename) {
1122 throw "no nodename specified";
1123 }
1124
c7218ab3
DC
1125 if (viewer === 'html5') {
1126 PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname);
b0a6d326
EK
1127 } else if (viewer === 'vv') {
1128 var url;
aa0819a8 1129 var params = { proxy: PVE.Utils.windowHostname() };
b0a6d326
EK
1130 if (vmtype === 'kvm') {
1131 url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy';
1132 PVE.Utils.openSpiceViewer(url, params);
9e361643
DM
1133 } else if (vmtype === 'lxc') {
1134 url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy';
b0a6d326
EK
1135 PVE.Utils.openSpiceViewer(url, params);
1136 } else if (vmtype === 'shell') {
1137 url = '/nodes/' + nodename + '/spiceshell';
1138 PVE.Utils.openSpiceViewer(url, params);
1139 } else if (vmtype === 'upgrade') {
1140 url = '/nodes/' + nodename + '/spiceshell';
1141 params.upgrade = 1;
1142 PVE.Utils.openSpiceViewer(url, params);
1143 }
1144 } else {
1145 throw "unknown viewer type";
1146 }
1147 },
1148
1149 defaultViewer: function(allowSpice) {
1150 var vncdefault = 'html5';
1151 var dv = PVE.VersionInfo.console || vncdefault;
1152 if (dv === 'vv' && !allowSpice) {
1153 dv = vncdefault;
1154 }
1155
1156 return dv;
1157 },
1158
c7218ab3 1159 openVNCViewer: function(vmtype, vmid, nodename, vmname) {
b0a6d326 1160 var url = Ext.urlEncode({
9e361643 1161 console: vmtype, // kvm, lxc, upgrade or shell
c7218ab3 1162 novnc: 1,
b0a6d326
EK
1163 vmid: vmid,
1164 vmname: vmname,
1165 node: nodename
1166 });
1167 var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
1168 nw.focus();
1169 },
1170
1171 openSpiceViewer: function(url, params){
1172
1173 var downloadWithName = function(uri, name) {
1174 var link = Ext.DomHelper.append(document.body, {
1175 tag: 'a',
1176 href: uri,
1177 css : 'display:none;visibility:hidden;height:0px;'
1178 });
1179
1180 // Note: we need to tell android the correct file name extension
1181 // but we do not set 'download' tag for other environments, because
1182 // It can have strange side effects (additional user prompt on firefox)
1183 var andriod = navigator.userAgent.match(/Android/i) ? true : false;
1184 if (andriod) {
1185 link.download = name;
1186 }
1187
1188 if (link.fireEvent) {
1189 link.fireEvent('onclick');
1190 } else {
1191 var evt = document.createEvent("MouseEvents");
1192 evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
1193 link.dispatchEvent(evt);
1194 }
1195 };
1196
1197 PVE.Utils.API2Request({
1198 url: url,
1199 params: params,
1200 method: 'POST',
1201 failure: function(response, opts){
1202 Ext.Msg.alert('Error', response.htmlStatus);
1203 },
1204 success: function(response, opts){
1205 var raw = "[virt-viewer]\n";
1206 Ext.Object.each(response.result.data, function(k, v) {
1207 raw += k + "=" + v + "\n";
1208 });
1209 var url = 'data:application/x-virt-viewer;charset=UTF-8,' +
1210 encodeURIComponent(raw);
0be88ae1 1211
b0a6d326
EK
1212 downloadWithName(url, "pve-spice.vv");
1213 }
1214 });
1215 },
1216
0be88ae1 1217 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
b0a6d326
EK
1218 // use el.mask() instead
1219 setErrorMask: function(comp, msg) {
1220 var el = comp.el;
1221 if (!el) {
1222 return;
1223 }
1224 if (!msg) {
1225 el.unmask();
1226 } else {
1227 if (msg === true) {
1228 el.mask(gettext("Loading..."));
1229 } else {
1230 el.mask(msg);
1231 }
1232 }
1233 },
1234
1235 monStoreErrors: function(me, store) {
1236 me.mon(store, 'beforeload', function(s, operation, eOpts) {
1237 if (!me.loadCount) {
1238 me.loadCount = 0; // make sure it is numeric
1239 PVE.Utils.setErrorMask(me, true);
1240 }
1241 });
1242
1243 // only works with 'pve' proxy
1244 me.mon(store.proxy, 'afterload', function(proxy, request, success) {
1245 me.loadCount++;
1246
1247 if (success) {
1248 PVE.Utils.setErrorMask(me, false);
1249 return;
1250 }
1251
1252 var msg;
23d3881a 1253 /*jslint nomen: true */
86826854 1254 var operation = request._operation;
b0a6d326
EK
1255 var error = operation.getError();
1256 if (error.statusText) {
1257 msg = error.statusText + ' (' + error.status + ')';
1258 } else {
1259 msg = gettext('Connection error');
1260 }
1261 PVE.Utils.setErrorMask(me, msg);
1262 });
685b7aa4 1263 },
b0a6d326 1264
e3129443
DC
1265 openTreeConsole: function(tree, record, item, index, e) {
1266 e.stopEvent();
1267 var nodename = record.data.node;
1268 var vmid = record.data.vmid;
1269 var vmname = record.data.name;
1270 if (record.data.type === 'qemu' && !record.data.template) {
1271 PVE.Utils.API2Request({
1272 url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current',
1273 failure: function(response, opts) {
1274 Ext.Msg.alert('Error', response.htmlStatus);
1275 },
1276 success: function(response, opts) {
1277 var allowSpice = response.result.data.spice;
1278 PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname);
1279 }
1280 });
1281 } else if (record.data.type === 'lxc' && !record.data.template) {
1282 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
1283 }
1284 },
1285
fbd60cfd
DM
1286 // test automation helper
1287 call_menu_handler: function(menu, text) {
1288
1289 var list = menu.query('menuitem');
1290
1291 Ext.Array.each(list, function(item) {
1292 if (item.text === text) {
1293 if (item.handler) {
1294 item.handler();
1295 return 1;
1296 } else {
1297 return undefined;
1298 }
1299 }
1300 });
1301 },
1302
685b7aa4
DC
1303 createCmdMenu: function(v, record, item, index, event) {
1304 event.stopEvent();
cc1a91be
DC
1305 if (!(v instanceof Ext.tree.View)) {
1306 v.select(record);
1307 }
685b7aa4
DC
1308 var menu;
1309
1310 if (record.data.type === 'qemu' && !record.data.template) {
1311 menu = Ext.create('PVE.qemu.CmdMenu', {
1312 pveSelNode: record
1313 });
1314 } else if (record.data.type === 'qemu' && record.data.template) {
1315 menu = Ext.create('PVE.qemu.TemplateMenu', {
1316 pveSelNode: record
1317 });
1318 } else if (record.data.type === 'lxc' && !record.data.template) {
1319 menu = Ext.create('PVE.lxc.CmdMenu', {
1320 pveSelNode: record
1321 });
1322 } else if (record.data.type === 'lxc' && record.data.template) {
1323 /* since clone does not work reliably, disable for now
1324 menu = Ext.create('PVE.lxc.TemplateMenu', {
1325 pveSelNode: record
1326 });
1327 */
1328 return;
1329 } else {
1330 return;
1331 }
1332
1333 menu.showAt(event.getXY());
9fa2e36d
EK
1334 }},
1335
fe4f00ad
TL
1336 // helper for deleting field which are set to there default values
1337 delete_if_default: function(values, fieldname, default_val, create) {
1338 if (values[fieldname] === '' || values[fieldname] === default_val) {
1339 if (!create) {
1340 if (values['delete']) {
1341 values['delete'] += ',' + fieldname;
1342 } else {
1343 values['delete'] = fieldname;
1344 }
1345 }
1346
1347 delete values[fieldname];
1348 }
1349 },
1350
9fa2e36d
EK
1351 singleton: true,
1352 constructor: function() {
1353 var me = this;
1354 Ext.apply(me, me.utilities);
c15c61d3
EK
1355
1356 var IPV4_OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
1357 var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")";
1358 var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})";
1359 var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
1360
1361
1362 me.IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
1363 me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
1364
1365 var IPV6_REGEXP = "(?:" +
1366 "(?:(?:" + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
1367 "(?:(?:" + "::" + "(?:" + IPV6_H16 + ":){5})" + IPV6_LS32 + ")|" +
1368 "(?:(?:(?:" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){4})" + IPV6_LS32 + ")|" +
1369 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,1}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){3})" + IPV6_LS32 + ")|" +
1370 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,2}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){2})" + IPV6_LS32 + ")|" +
1371 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,3}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){1})" + IPV6_LS32 + ")|" +
1372 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,4}" + IPV6_H16 + ")?::" + ")" + IPV6_LS32 + ")|" +
1373 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,5}" + IPV6_H16 + ")?::" + ")" + IPV6_H16 + ")|" +
1374 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,7}" + IPV6_H16 + ")?::" + ")" + ")" +
1375 ")";
1376
1377 me.IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
1378 me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
1379 me.IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
1380
1381 me.IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
1382
1383 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])?))";
1384 me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");
1385
1386 me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$");
1387 me.HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$");
1388 me.IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$");
685b7aa4 1389 }
9fa2e36d 1390});
b0a6d326 1391