]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/Utils.js
ui: dc: add AuthEditOpenId panel
[pve-manager.git] / www / manager6 / Utils.js
1 Ext.ns('PVE');
2
3 // avoid errors related to Accessible Rich Internet Applications
4 // (access for people with disabilities)
5 // TODO reenable after all components are upgraded
6 Ext.enableAria = false;
7 Ext.enableAriaButtons = false;
8 Ext.enableAriaPanels = false;
9
10 console.log("Starting Proxmox VE Manager");
11
12 Ext.Ajax.defaultHeaders = {
13 'Accept': 'application/json',
14 };
15
16 Ext.define('PVE.Utils', {
17 utilities: {
18
19 // this singleton contains miscellaneous utilities
20
21 toolkit: undefined, // (extjs|touch), set inside Toolkit.js
22
23 bus_match: /^(ide|sata|virtio|scsi)\d+$/,
24
25 log_severity_hash: {
26 0: "panic",
27 1: "alert",
28 2: "critical",
29 3: "error",
30 4: "warning",
31 5: "notice",
32 6: "info",
33 7: "debug",
34 },
35
36 support_level_hash: {
37 'c': gettext('Community'),
38 'b': gettext('Basic'),
39 's': gettext('Standard'),
40 'p': gettext('Premium'),
41 },
42
43 noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit '
44 +'<a target="_blank" href="https://www.proxmox.com/products/proxmox-ve/subscription-service-plans">'
45 +'www.proxmox.com</a> to get a list of available options.',
46
47 kvm_ostypes: {
48 'Linux': [
49 { desc: '5.x - 2.6 Kernel', val: 'l26' },
50 { desc: '2.4 Kernel', val: 'l24' },
51 ],
52 'Microsoft Windows': [
53 { desc: '10/2016/2019', val: 'win10' },
54 { desc: '8.x/2012/2012r2', val: 'win8' },
55 { desc: '7/2008r2', val: 'win7' },
56 { desc: 'Vista/2008', val: 'w2k8' },
57 { desc: 'XP/2003', val: 'wxp' },
58 { desc: '2000', val: 'w2k' },
59 ],
60 'Solaris Kernel': [
61 { desc: '-', val: 'solaris' },
62 ],
63 'Other': [
64 { desc: '-', val: 'other' },
65 ],
66 },
67
68 is_windows: function(ostype) {
69 for (let entry of PVE.Utils.kvm_ostypes['Microsoft Windows']) {
70 if (entry.val === ostype) {
71 return true;
72 }
73 }
74 return false;
75 },
76
77 get_health_icon: function(state, circle) {
78 if (circle === undefined) {
79 circle = false;
80 }
81
82 if (state === undefined) {
83 state = 'uknown';
84 }
85
86 var icon = 'faded fa-question';
87 switch (state) {
88 case 'good':
89 icon = 'good fa-check';
90 break;
91 case 'upgrade':
92 icon = 'warning fa-upload';
93 break;
94 case 'old':
95 icon = 'warning fa-refresh';
96 break;
97 case 'warning':
98 icon = 'warning fa-exclamation';
99 break;
100 case 'critical':
101 icon = 'critical fa-times';
102 break;
103 default: break;
104 }
105
106 if (circle) {
107 icon += '-circle';
108 }
109
110 return icon;
111 },
112
113 parse_ceph_version: function(service) {
114 if (service.ceph_version_short) {
115 return service.ceph_version_short;
116 }
117
118 if (service.ceph_version) {
119 var match = service.ceph_version.match(/version (\d+(\.\d+)*)/);
120 if (match) {
121 return match[1];
122 }
123 }
124
125 return undefined;
126 },
127
128 compare_ceph_versions: function(a, b) {
129 let avers = [];
130 let bvers = [];
131
132 if (a === b) {
133 return 0;
134 }
135
136 if (Ext.isArray(a)) {
137 avers = a.slice(); // copy array
138 } else {
139 avers = a.toString().split('.');
140 }
141
142 if (Ext.isArray(b)) {
143 bvers = b.slice(); // copy array
144 } else {
145 bvers = b.toString().split('.');
146 }
147
148 for (;;) {
149 let av = avers.shift();
150 let bv = bvers.shift();
151
152 if (av === undefined && bv === undefined) {
153 return 0;
154 } else if (av === undefined) {
155 return -1;
156 } else if (bv === undefined) {
157 return 1;
158 } else {
159 let diff = parseInt(av, 10) - parseInt(bv, 10);
160 if (diff !== 0) return diff;
161 // else we need to look at the next parts
162 }
163 }
164 },
165
166 get_ceph_icon_html: function(health, fw) {
167 var state = PVE.Utils.map_ceph_health[health];
168 var cls = PVE.Utils.get_health_icon(state);
169 if (fw) {
170 cls += ' fa-fw';
171 }
172 return "<i class='fa " + cls + "'></i> ";
173 },
174
175 map_ceph_health: {
176 'HEALTH_OK': 'good',
177 'HEALTH_UPGRADE': 'upgrade',
178 'HEALTH_OLD': 'old',
179 'HEALTH_WARN': 'warning',
180 'HEALTH_ERR': 'critical',
181 },
182
183 render_sdn_pending: function(rec, value, key, index) {
184 if (rec.data.state === undefined || rec.data.state === null) {
185 return value;
186 }
187
188 if (rec.data.state === 'deleted') {
189 if (value === undefined) {
190 return ' ';
191 } else {
192 return '<div style="text-decoration: line-through;">'+ value +'</div>';
193 }
194 } else if (rec.data.pending[key] !== undefined && rec.data.pending[key] !== null) {
195 if (rec.data.pending[key] === 'deleted') {
196 return ' ';
197 } else {
198 return rec.data.pending[key];
199 }
200 }
201 return value;
202 },
203
204 render_sdn_pending_state: function(rec, value) {
205 if (value === undefined || value === null) {
206 return ' ';
207 }
208
209 let icon = `<i class="fa fa-fw fa-refresh warning"></i>`;
210
211 if (value === 'deleted') {
212 return '<span>' + icon + value + '</span>';
213 }
214
215 let tip = gettext('Pending Changes') + ': <br>';
216
217 for (const [key, keyvalue] of Object.entries(rec.data.pending)) {
218 if ((rec.data[key] !== undefined && rec.data.pending[key] !== rec.data[key]) ||
219 rec.data[key] === undefined
220 ) {
221 tip += `${key}: ${keyvalue} <br>`;
222 }
223 }
224 return '<span data-qtip="' + tip + '">'+ icon + value + '</span>';
225 },
226
227 render_ceph_health: function(healthObj) {
228 var state = {
229 iconCls: PVE.Utils.get_health_icon(),
230 text: '',
231 };
232
233 if (!healthObj || !healthObj.status) {
234 return state;
235 }
236
237 var health = PVE.Utils.map_ceph_health[healthObj.status];
238
239 state.iconCls = PVE.Utils.get_health_icon(health, true);
240 state.text = healthObj.status;
241
242 return state;
243 },
244
245 render_zfs_health: function(value) {
246 if (typeof value === 'undefined') {
247 return "";
248 }
249 var iconCls = 'question-circle';
250 switch (value) {
251 case 'AVAIL':
252 case 'ONLINE':
253 iconCls = 'check-circle good';
254 break;
255 case 'REMOVED':
256 case 'DEGRADED':
257 iconCls = 'exclamation-circle warning';
258 break;
259 case 'UNAVAIL':
260 case 'FAULTED':
261 case 'OFFLINE':
262 iconCls = 'times-circle critical';
263 break;
264 default: //unknown
265 }
266
267 return '<i class="fa fa-' + iconCls + '"></i> ' + value;
268 },
269
270 render_pbs_fingerprint: fp => fp.substring(0, 23),
271
272 render_backup_encryption: function(v, meta, record) {
273 if (!v) {
274 return gettext('No');
275 }
276
277 let tip = '';
278 if (v.match(/^[a-fA-F0-9]{2}:/)) { // fingerprint
279 tip = `Key fingerprint ${PVE.Utils.render_pbs_fingerprint(v)}`;
280 }
281 let icon = `<i class="fa fa-fw fa-lock good"></i>`;
282 return `<span data-qtip="${tip}">${icon} ${gettext('Encrypted')}</span>`;
283 },
284
285 render_backup_verification: function(v, meta, record) {
286 let i = (cls, txt) => `<i class="fa fa-fw fa-${cls}"></i> ${txt}`;
287 if (v === undefined || v === null) {
288 return i('question-circle-o warning', gettext('None'));
289 }
290 let tip = "";
291 let txt = gettext('Failed');
292 let iconCls = 'times critical';
293 if (v.state === 'ok') {
294 txt = gettext('OK');
295 iconCls = 'check good';
296 let now = Date.now() / 1000;
297 let task = Proxmox.Utils.parse_task_upid(v.upid);
298 let verify_time = Proxmox.Utils.render_timestamp(task.starttime);
299 tip = `Last verify task started on ${verify_time}`;
300 if (now - v.starttime > 30 * 24 * 60 * 60) {
301 tip = `Last verify task over 30 days ago: ${verify_time}`;
302 iconCls = 'check warning';
303 }
304 }
305 return `<span data-qtip="${tip}"> ${i(iconCls, txt)} </span>`;
306 },
307
308 render_backup_status: function(value, meta, record) {
309 if (typeof value === 'undefined') {
310 return "";
311 }
312
313 let iconCls = 'check-circle good';
314 let text = gettext('Yes');
315
316 if (!PVE.Parser.parseBoolean(value.toString())) {
317 iconCls = 'times-circle critical';
318
319 text = gettext('No');
320
321 let reason = record.get('reason');
322 if (typeof reason !== 'undefined') {
323 if (reason in PVE.Utils.backup_reasons_table) {
324 reason = PVE.Utils.backup_reasons_table[record.get('reason')];
325 }
326 text = `${text} - ${reason}`;
327 }
328 }
329
330 return `<i class="fa fa-${iconCls}"></i> ${text}`;
331 },
332
333 render_backup_days_of_week: function(val) {
334 var dows = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
335 var selected = [];
336 var cur = -1;
337 val.split(',').forEach(function(day) {
338 cur++;
339 var dow = (dows.indexOf(day)+6)%7;
340 if (cur === dow) {
341 if (selected.length === 0 || selected[selected.length-1] === 0) {
342 selected.push(1);
343 } else {
344 selected[selected.length-1]++;
345 }
346 } else {
347 while (cur < dow) {
348 cur++;
349 selected.push(0);
350 }
351 selected.push(1);
352 }
353 });
354
355 cur = -1;
356 var days = [];
357 selected.forEach(function(item) {
358 cur++;
359 if (item > 2) {
360 days.push(Ext.Date.dayNames[cur+1] + '-' + Ext.Date.dayNames[(cur+item)%7]);
361 cur += item-1;
362 } else if (item === 2) {
363 days.push(Ext.Date.dayNames[cur+1]);
364 days.push(Ext.Date.dayNames[(cur+2)%7]);
365 cur++;
366 } else if (item === 1) {
367 days.push(Ext.Date.dayNames[(cur+1)%7]);
368 }
369 });
370 return days.join(', ');
371 },
372
373 render_backup_selection: function(value, metaData, record) {
374 let allExceptText = gettext('All except {0}');
375 let allText = '-- ' + gettext('All') + ' --';
376 if (record.data.all) {
377 if (record.data.exclude) {
378 return Ext.String.format(allExceptText, record.data.exclude);
379 }
380 return allText;
381 }
382 if (record.data.vmid) {
383 return record.data.vmid;
384 }
385
386 if (record.data.pool) {
387 return "Pool '"+ record.data.pool + "'";
388 }
389
390 return "-";
391 },
392
393 backup_reasons_table: {
394 'backup=yes': gettext('Enabled'),
395 'backup=no': gettext('Disabled'),
396 'enabled': gettext('Enabled'),
397 'disabled': gettext('Disabled'),
398 'not a volume': gettext('Not a volume'),
399 'efidisk but no OMVF BIOS': gettext('EFI Disk without OMVF BIOS'),
400 },
401
402 get_kvm_osinfo: function(value) {
403 var info = { base: 'Other' }; // default
404 if (value) {
405 Ext.each(Object.keys(PVE.Utils.kvm_ostypes), function(k) {
406 Ext.each(PVE.Utils.kvm_ostypes[k], function(e) {
407 if (e.val === value) {
408 info = { desc: e.desc, base: k };
409 }
410 });
411 });
412 }
413 return info;
414 },
415
416 render_kvm_ostype: function(value) {
417 var osinfo = PVE.Utils.get_kvm_osinfo(value);
418 if (osinfo.desc && osinfo.desc !== '-') {
419 return osinfo.base + ' ' + osinfo.desc;
420 } else {
421 return osinfo.base;
422 }
423 },
424
425 render_hotplug_features: function(value) {
426 var fa = [];
427
428 if (!value || value === '0') {
429 return gettext('Disabled');
430 }
431
432 if (value === '1') {
433 value = 'disk,network,usb';
434 }
435
436 Ext.each(value.split(','), function(el) {
437 if (el === 'disk') {
438 fa.push(gettext('Disk'));
439 } else if (el === 'network') {
440 fa.push(gettext('Network'));
441 } else if (el === 'usb') {
442 fa.push('USB');
443 } else if (el === 'memory') {
444 fa.push(gettext('Memory'));
445 } else if (el === 'cpu') {
446 fa.push(gettext('CPU'));
447 } else {
448 fa.push(el);
449 }
450 });
451
452 return fa.join(', ');
453 },
454
455 render_localtime: function(value) {
456 if (value === '__default__') {
457 return Proxmox.Utils.defaultText + ' (' + gettext('Enabled for Windows') + ')';
458 }
459 return Proxmox.Utils.format_boolean(value);
460 },
461
462 render_qga_features: function(config) {
463 if (!config) {
464 return Proxmox.Utils.defaultText + ' (' + Proxmox.Utils.disabledText + ')';
465 }
466 let qga = PVE.Parser.parsePropertyString(config, 'enabled');
467 if (!PVE.Parser.parseBoolean(qga.enabled)) {
468 return Proxmox.Utils.disabledText;
469 }
470 delete qga.enabled;
471
472 let agentstring = Proxmox.Utils.enabledText;
473
474 for (const [key, value] of Object.entries(qga)) {
475 let displayText = Proxmox.Utils.disabledText;
476 if (key === 'type') {
477 let map = {
478 isa: "ISA",
479 virtio: "VirtIO",
480 };
481 displayText = map[value] || Proxmox.Utils.unknownText;
482 } else if (PVE.Parser.parseBoolean(value)) {
483 displayText = Proxmox.Utils.enabledText;
484 }
485 agentstring += `, ${key}: ${displayText}`;
486 }
487
488 return agentstring;
489 },
490
491 render_qemu_machine: function(value) {
492 return value || Proxmox.Utils.defaultText + ' (i440fx)';
493 },
494
495 render_qemu_bios: function(value) {
496 if (!value) {
497 return Proxmox.Utils.defaultText + ' (SeaBIOS)';
498 } else if (value === 'seabios') {
499 return "SeaBIOS";
500 } else if (value === 'ovmf') {
501 return "OVMF (UEFI)";
502 } else {
503 return value;
504 }
505 },
506
507 render_dc_ha_opts: function(value) {
508 if (!value) {
509 return Proxmox.Utils.defaultText;
510 } else {
511 return PVE.Parser.printPropertyString(value);
512 }
513 },
514 render_as_property_string: function(value) {
515 return !value ? Proxmox.Utils.defaultText
516 : PVE.Parser.printPropertyString(value);
517 },
518
519 render_scsihw: function(value) {
520 if (!value) {
521 return Proxmox.Utils.defaultText + ' (LSI 53C895A)';
522 } else if (value === 'lsi') {
523 return 'LSI 53C895A';
524 } else if (value === 'lsi53c810') {
525 return 'LSI 53C810';
526 } else if (value === 'megasas') {
527 return 'MegaRAID SAS 8708EM2';
528 } else if (value === 'virtio-scsi-pci') {
529 return 'VirtIO SCSI';
530 } else if (value === 'virtio-scsi-single') {
531 return 'VirtIO SCSI single';
532 } else if (value === 'pvscsi') {
533 return 'VMware PVSCSI';
534 } else {
535 return value;
536 }
537 },
538
539 render_spice_enhancements: function(values) {
540 let props = PVE.Parser.parsePropertyString(values);
541 if (Ext.Object.isEmpty(props)) {
542 return Proxmox.Utils.noneText;
543 }
544
545 let output = [];
546 if (PVE.Parser.parseBoolean(props.foldersharing)) {
547 output.push('Folder Sharing: ' + gettext('Enabled'));
548 }
549 if (props.videostreaming === 'all' || props.videostreaming === 'filter') {
550 output.push('Video Streaming: ' + props.videostreaming);
551 }
552 return output.join(', ');
553 },
554
555 // fixme: auto-generate this
556 // for now, please keep in sync with PVE::Tools::kvmkeymaps
557 kvm_keymaps: {
558 //ar: 'Arabic',
559 da: 'Danish',
560 de: 'German',
561 'de-ch': 'German (Swiss)',
562 'en-gb': 'English (UK)',
563 'en-us': 'English (USA)',
564 es: 'Spanish',
565 //et: 'Estonia',
566 fi: 'Finnish',
567 //fo: 'Faroe Islands',
568 fr: 'French',
569 'fr-be': 'French (Belgium)',
570 'fr-ca': 'French (Canada)',
571 'fr-ch': 'French (Swiss)',
572 //hr: 'Croatia',
573 hu: 'Hungarian',
574 is: 'Icelandic',
575 it: 'Italian',
576 ja: 'Japanese',
577 lt: 'Lithuanian',
578 //lv: 'Latvian',
579 mk: 'Macedonian',
580 nl: 'Dutch',
581 //'nl-be': 'Dutch (Belgium)',
582 no: 'Norwegian',
583 pl: 'Polish',
584 pt: 'Portuguese',
585 'pt-br': 'Portuguese (Brazil)',
586 //ru: 'Russian',
587 sl: 'Slovenian',
588 sv: 'Swedish',
589 //th: 'Thai',
590 tr: 'Turkish',
591 },
592
593 kvm_vga_drivers: {
594 std: gettext('Standard VGA'),
595 vmware: gettext('VMware compatible'),
596 qxl: 'SPICE',
597 qxl2: 'SPICE dual monitor',
598 qxl3: 'SPICE three monitors',
599 qxl4: 'SPICE four monitors',
600 serial0: gettext('Serial terminal') + ' 0',
601 serial1: gettext('Serial terminal') + ' 1',
602 serial2: gettext('Serial terminal') + ' 2',
603 serial3: gettext('Serial terminal') + ' 3',
604 virtio: 'VirtIO-GPU',
605 none: Proxmox.Utils.noneText,
606 },
607
608 render_kvm_language: function(value) {
609 if (!value || value === '__default__') {
610 return Proxmox.Utils.defaultText;
611 }
612 var text = PVE.Utils.kvm_keymaps[value];
613 if (text) {
614 return text + ' (' + value + ')';
615 }
616 return value;
617 },
618
619 kvm_keymap_array: function() {
620 var data = [['__default__', PVE.Utils.render_kvm_language('')]];
621 Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) {
622 data.push([key, PVE.Utils.render_kvm_language(value)]);
623 });
624
625 return data;
626 },
627
628 console_map: {
629 '__default__': Proxmox.Utils.defaultText + ' (xterm.js)',
630 'vv': 'SPICE (remote-viewer)',
631 'html5': 'HTML5 (noVNC)',
632 'xtermjs': 'xterm.js',
633 },
634
635 render_console_viewer: function(value) {
636 value = value || '__default__';
637 if (PVE.Utils.console_map[value]) {
638 return PVE.Utils.console_map[value];
639 }
640 return value;
641 },
642
643 console_viewer_array: function() {
644 return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) {
645 return [v, PVE.Utils.render_console_viewer(v)];
646 });
647 },
648
649 render_kvm_vga_driver: function(value) {
650 if (!value) {
651 return Proxmox.Utils.defaultText;
652 }
653 var vga = PVE.Parser.parsePropertyString(value, 'type');
654 var text = PVE.Utils.kvm_vga_drivers[vga.type];
655 if (!vga.type) {
656 text = Proxmox.Utils.defaultText;
657 }
658 if (text) {
659 return text + ' (' + value + ')';
660 }
661 return value;
662 },
663
664 kvm_vga_driver_array: function() {
665 var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]];
666 Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) {
667 data.push([key, PVE.Utils.render_kvm_vga_driver(value)]);
668 });
669
670 return data;
671 },
672
673 render_kvm_startup: function(value) {
674 var startup = PVE.Parser.parseStartup(value);
675
676 var res = 'order=';
677 if (startup.order === undefined) {
678 res += 'any';
679 } else {
680 res += startup.order;
681 }
682 if (startup.up !== undefined) {
683 res += ',up=' + startup.up;
684 }
685 if (startup.down !== undefined) {
686 res += ',down=' + startup.down;
687 }
688
689 return res;
690 },
691
692 extractFormActionError: function(action) {
693 var msg;
694 switch (action.failureType) {
695 case Ext.form.action.Action.CLIENT_INVALID:
696 msg = gettext('Form fields may not be submitted with invalid values');
697 break;
698 case Ext.form.action.Action.CONNECT_FAILURE:
699 msg = gettext('Connection error');
700 var resp = action.response;
701 if (resp.status && resp.statusText) {
702 msg += " " + resp.status + ": " + resp.statusText;
703 }
704 break;
705 case Ext.form.action.Action.LOAD_FAILURE:
706 case Ext.form.action.Action.SERVER_INVALID:
707 msg = Proxmox.Utils.extractRequestError(action.result, true);
708 break;
709 }
710 return msg;
711 },
712
713 contentTypes: {
714 'images': gettext('Disk image'),
715 'backup': gettext('VZDump backup file'),
716 'vztmpl': gettext('Container template'),
717 'iso': gettext('ISO image'),
718 'rootdir': gettext('Container'),
719 'snippets': gettext('Snippets'),
720 },
721
722 volume_is_qemu_backup: function(volid, format) {
723 return format === 'pbs-vm' || volid.match(':backup/vzdump-qemu-');
724 },
725
726 volume_is_lxc_backup: function(volid, format) {
727 return format === 'pbs-ct' || volid.match(':backup/vzdump-(lxc|openvz)-');
728 },
729
730 authSchema: {
731 ad: {
732 name: gettext('Active Directory Server'),
733 ipanel: 'pveAuthADPanel',
734 syncipanel: 'pveAuthLDAPSyncPanel',
735 add: true,
736 tfa: true,
737 },
738 ldap: {
739 name: gettext('LDAP Server'),
740 ipanel: 'pveAuthLDAPPanel',
741 syncipanel: 'pveAuthLDAPSyncPanel',
742 add: true,
743 tfa: true,
744 },
745 openid: {
746 name: gettext('OpenID Server'),
747 ipanel: 'pveAuthOpenIDPanel',
748 add: true,
749 tfa: false,
750 },
751 pam: {
752 name: 'Linux PAM',
753 ipanel: 'pveAuthBasePanel',
754 add: false,
755 tfa: true,
756 },
757 pve: {
758 name: 'Proxmox VE authentication server',
759 ipanel: 'pveAuthBasePanel',
760 add: false,
761 },
762 },
763
764 storageSchema: {
765 dir: {
766 name: Proxmox.Utils.directoryText,
767 ipanel: 'DirInputPanel',
768 faIcon: 'folder',
769 backups: true,
770 },
771 lvm: {
772 name: 'LVM',
773 ipanel: 'LVMInputPanel',
774 faIcon: 'folder',
775 backups: false,
776 },
777 lvmthin: {
778 name: 'LVM-Thin',
779 ipanel: 'LvmThinInputPanel',
780 faIcon: 'folder',
781 backups: false,
782 },
783 btrfs: {
784 name: 'BTRFS',
785 ipanel: 'BTRFSInputPanel',
786 faIcon: 'folder',
787 backups: true,
788 },
789 nfs: {
790 name: 'NFS',
791 ipanel: 'NFSInputPanel',
792 faIcon: 'building',
793 backups: true,
794 },
795 cifs: {
796 name: 'CIFS',
797 ipanel: 'CIFSInputPanel',
798 faIcon: 'building',
799 backups: true,
800 },
801 glusterfs: {
802 name: 'GlusterFS',
803 ipanel: 'GlusterFsInputPanel',
804 faIcon: 'building',
805 backups: true,
806 },
807 iscsi: {
808 name: 'iSCSI',
809 ipanel: 'IScsiInputPanel',
810 faIcon: 'building',
811 backups: false,
812 },
813 cephfs: {
814 name: 'CephFS',
815 ipanel: 'CephFSInputPanel',
816 faIcon: 'building',
817 backups: true,
818 },
819 pvecephfs: {
820 name: 'CephFS (PVE)',
821 ipanel: 'CephFSInputPanel',
822 hideAdd: true,
823 faIcon: 'building',
824 backups: true,
825 },
826 rbd: {
827 name: 'RBD',
828 ipanel: 'RBDInputPanel',
829 faIcon: 'building',
830 backups: false,
831 },
832 pveceph: {
833 name: 'RBD (PVE)',
834 ipanel: 'RBDInputPanel',
835 hideAdd: true,
836 faIcon: 'building',
837 backups: false,
838 },
839 zfs: {
840 name: 'ZFS over iSCSI',
841 ipanel: 'ZFSInputPanel',
842 faIcon: 'building',
843 backups: false,
844 },
845 zfspool: {
846 name: 'ZFS',
847 ipanel: 'ZFSPoolInputPanel',
848 faIcon: 'folder',
849 backups: false,
850 },
851 pbs: {
852 name: 'Proxmox Backup Server',
853 ipanel: 'PBSInputPanel',
854 faIcon: 'floppy-o',
855 backups: true,
856 },
857 drbd: {
858 name: 'DRBD',
859 hideAdd: true,
860 backups: false,
861 },
862 },
863
864 sdnvnetSchema: {
865 vnet: {
866 name: 'vnet',
867 faIcon: 'folder',
868 },
869 },
870
871 sdnzoneSchema: {
872 zone: {
873 name: 'zone',
874 hideAdd: true,
875 },
876 simple: {
877 name: 'Simple',
878 ipanel: 'SimpleInputPanel',
879 faIcon: 'th',
880 },
881 vlan: {
882 name: 'VLAN',
883 ipanel: 'VlanInputPanel',
884 faIcon: 'th',
885 },
886 qinq: {
887 name: 'QinQ',
888 ipanel: 'QinQInputPanel',
889 faIcon: 'th',
890 },
891 vxlan: {
892 name: 'VXLAN',
893 ipanel: 'VxlanInputPanel',
894 faIcon: 'th',
895 },
896 evpn: {
897 name: 'EVPN',
898 ipanel: 'EvpnInputPanel',
899 faIcon: 'th',
900 },
901 },
902
903 sdncontrollerSchema: {
904 controller: {
905 name: 'controller',
906 hideAdd: true,
907 },
908 evpn: {
909 name: 'evpn',
910 ipanel: 'EvpnInputPanel',
911 faIcon: 'crosshairs',
912 },
913 bgp: {
914 name: 'bgp',
915 ipanel: 'BgpInputPanel',
916 faIcon: 'crosshairs',
917 },
918 },
919
920 sdnipamSchema: {
921 ipam: {
922 name: 'ipam',
923 hideAdd: true,
924 },
925 pve: {
926 name: 'PVE',
927 ipanel: 'PVEIpamInputPanel',
928 faIcon: 'th',
929 hideAdd: true,
930 },
931 netbox: {
932 name: 'Netbox',
933 ipanel: 'NetboxInputPanel',
934 faIcon: 'th',
935 },
936 phpipam: {
937 name: 'PhpIpam',
938 ipanel: 'PhpIpamInputPanel',
939 faIcon: 'th',
940 },
941 },
942
943 sdndnsSchema: {
944 dns: {
945 name: 'dns',
946 hideAdd: true,
947 },
948 powerdns: {
949 name: 'powerdns',
950 ipanel: 'PowerdnsInputPanel',
951 faIcon: 'th',
952 },
953 },
954
955 format_sdnvnet_type: function(value, md, record) {
956 var schema = PVE.Utils.sdnvnetSchema[value];
957 if (schema) {
958 return schema.name;
959 }
960 return Proxmox.Utils.unknownText;
961 },
962
963 format_sdnzone_type: function(value, md, record) {
964 var schema = PVE.Utils.sdnzoneSchema[value];
965 if (schema) {
966 return schema.name;
967 }
968 return Proxmox.Utils.unknownText;
969 },
970
971 format_sdncontroller_type: function(value, md, record) {
972 var schema = PVE.Utils.sdncontrollerSchema[value];
973 if (schema) {
974 return schema.name;
975 }
976 return Proxmox.Utils.unknownText;
977 },
978
979 format_sdnipam_type: function(value, md, record) {
980 var schema = PVE.Utils.sdnipamSchema[value];
981 if (schema) {
982 return schema.name;
983 }
984 return Proxmox.Utils.unknownText;
985 },
986
987 format_sdndns_type: function(value, md, record) {
988 var schema = PVE.Utils.sdndnsSchema[value];
989 if (schema) {
990 return schema.name;
991 }
992 return Proxmox.Utils.unknownText;
993 },
994
995 format_storage_type: function(value, md, record) {
996 if (value === 'rbd') {
997 value = !record || record.get('monhost') ? 'rbd' : 'pveceph';
998 } else if (value === 'cephfs') {
999 value = !record || record.get('monhost') ? 'cephfs' : 'pvecephfs';
1000 }
1001
1002 var schema = PVE.Utils.storageSchema[value];
1003 if (schema) {
1004 return schema.name;
1005 }
1006 return Proxmox.Utils.unknownText;
1007 },
1008
1009 format_ha: function(value) {
1010 var text = Proxmox.Utils.noneText;
1011
1012 if (value.managed) {
1013 text = value.state || Proxmox.Utils.noneText;
1014
1015 text += ', ' + Proxmox.Utils.groupText + ': ';
1016 text += value.group || Proxmox.Utils.noneText;
1017 }
1018
1019 return text;
1020 },
1021
1022 format_content_types: function(value) {
1023 return value.split(',').sort().map(function(ct) {
1024 return PVE.Utils.contentTypes[ct] || ct;
1025 }).join(', ');
1026 },
1027
1028 render_storage_content: function(value, metaData, record) {
1029 var data = record.data;
1030 if (Ext.isNumber(data.channel) &&
1031 Ext.isNumber(data.id) &&
1032 Ext.isNumber(data.lun)) {
1033 return "CH " +
1034 Ext.String.leftPad(data.channel, 2, '0') +
1035 " ID " + data.id + " LUN " + data.lun;
1036 }
1037 return data.volid.replace(/^.*?:(.*?\/)?/, '');
1038 },
1039
1040 render_serverity: function(value) {
1041 return PVE.Utils.log_severity_hash[value] || value;
1042 },
1043
1044 calculate_hostcpu: function(data) {
1045 if (!(data.uptime && Ext.isNumeric(data.cpu))) {
1046 return -1;
1047 }
1048
1049 if (data.type !== 'qemu' && data.type !== 'lxc') {
1050 return -1;
1051 }
1052
1053 var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node);
1054 var node = PVE.data.ResourceStore.getAt(index);
1055 if (!Ext.isDefined(node) || node === null) {
1056 return -1;
1057 }
1058 var maxcpu = node.data.maxcpu || 1;
1059
1060 if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
1061 return -1;
1062 }
1063
1064 return (data.cpu/maxcpu) * data.maxcpu;
1065 },
1066
1067 render_hostcpu: function(value, metaData, record, rowIndex, colIndex, store) {
1068 if (!(record.data.uptime && Ext.isNumeric(record.data.cpu))) {
1069 return '';
1070 }
1071
1072 if (record.data.type !== 'qemu' && record.data.type !== 'lxc') {
1073 return '';
1074 }
1075
1076 var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node);
1077 var node = PVE.data.ResourceStore.getAt(index);
1078 if (!Ext.isDefined(node) || node === null) {
1079 return '';
1080 }
1081 var maxcpu = node.data.maxcpu || 1;
1082
1083 if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
1084 return '';
1085 }
1086
1087 var per = (record.data.cpu/maxcpu) * record.data.maxcpu * 100;
1088
1089 return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
1090 },
1091
1092 render_bandwidth: function(value) {
1093 if (!Ext.isNumeric(value)) {
1094 return '';
1095 }
1096
1097 return Proxmox.Utils.format_size(value) + '/s';
1098 },
1099
1100 render_timestamp_human_readable: function(value) {
1101 return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s');
1102 },
1103
1104 calculate_mem_usage: function(data) {
1105 if (!Ext.isNumeric(data.mem) ||
1106 data.maxmem === 0 ||
1107 data.uptime < 1) {
1108 return -1;
1109 }
1110
1111 return data.mem / data.maxmem;
1112 },
1113
1114 calculate_hostmem_usage: function(data) {
1115 if (data.type !== 'qemu' && data.type !== 'lxc') {
1116 return -1;
1117 }
1118
1119 var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node);
1120 var node = PVE.data.ResourceStore.getAt(index);
1121
1122 if (!Ext.isDefined(node) || node === null) {
1123 return -1;
1124 }
1125 var maxmem = node.data.maxmem || 0;
1126
1127 if (!Ext.isNumeric(data.mem) ||
1128 maxmem === 0 ||
1129 data.uptime < 1) {
1130 return -1;
1131 }
1132
1133 return data.mem / maxmem;
1134 },
1135
1136 render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
1137 if (!Ext.isNumeric(value) || value === -1) {
1138 return '';
1139 }
1140 if (value > 1) {
1141 // we got no percentage but bytes
1142 var mem = value;
1143 var maxmem = record.data.maxmem;
1144 if (!record.data.uptime ||
1145 maxmem === 0 ||
1146 !Ext.isNumeric(mem)) {
1147 return '';
1148 }
1149
1150 return (mem*100/maxmem).toFixed(1) + " %";
1151 }
1152 return (value*100).toFixed(1) + " %";
1153 },
1154
1155 render_hostmem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
1156 if (!Ext.isNumeric(record.data.mem) || value === -1) {
1157 return '';
1158 }
1159
1160 if (record.data.type !== 'qemu' && record.data.type !== 'lxc') {
1161 return '';
1162 }
1163
1164 var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node);
1165 var node = PVE.data.ResourceStore.getAt(index);
1166 var maxmem = node.data.maxmem || 0;
1167
1168 if (record.data.mem > 1) {
1169 // we got no percentage but bytes
1170 var mem = record.data.mem;
1171 if (!record.data.uptime ||
1172 maxmem === 0 ||
1173 !Ext.isNumeric(mem)) {
1174 return '';
1175 }
1176
1177 return ((mem*100)/maxmem).toFixed(1) + " %";
1178 }
1179 return (value*100).toFixed(1) + " %";
1180 },
1181
1182 render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
1183 var mem = value;
1184 var maxmem = record.data.maxmem;
1185
1186 if (!record.data.uptime) {
1187 return '';
1188 }
1189
1190 if (!(Ext.isNumeric(mem) && maxmem)) {
1191 return '';
1192 }
1193
1194 return Proxmox.Utils.render_size(value);
1195 },
1196
1197 calculate_disk_usage: function(data) {
1198 if (!Ext.isNumeric(data.disk) ||
1199 ((data.type === 'qemu' || data.type === 'lxc') && data.uptime === 0) ||
1200 data.maxdisk === 0
1201 ) {
1202 return -1;
1203 }
1204
1205 return data.disk / data.maxdisk;
1206 },
1207
1208 render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
1209 if (!Ext.isNumeric(value) || value === -1) {
1210 return '';
1211 }
1212
1213 return (value * 100).toFixed(1) + " %";
1214 },
1215
1216 render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) {
1217 var disk = value;
1218 var maxdisk = record.data.maxdisk;
1219 var type = record.data.type;
1220
1221 if (!Ext.isNumeric(disk) ||
1222 maxdisk === 0 ||
1223 ((type === 'qemu' || type === 'lxc') && record.data.uptime === 0)
1224 ) {
1225 return '';
1226 }
1227
1228 return Proxmox.Utils.render_size(value);
1229 },
1230
1231 get_object_icon_class: function(type, record) {
1232 var status = '';
1233 var objType = type;
1234
1235 if (type === 'type') {
1236 // for folder view
1237 objType = record.groupbyid;
1238 } else if (record.template) {
1239 // templates
1240 objType = 'template';
1241 status = type;
1242 } else {
1243 // everything else
1244 status = record.status + ' ha-' + record.hastate;
1245 }
1246
1247 if (record.lock) {
1248 status += ' locked lock-' + record.lock;
1249 }
1250
1251 var defaults = PVE.tree.ResourceTree.typeDefaults[objType];
1252 if (defaults && defaults.iconCls) {
1253 var retVal = defaults.iconCls + ' ' + status;
1254 return retVal;
1255 }
1256
1257 return '';
1258 },
1259
1260 render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
1261 var cls = PVE.Utils.get_object_icon_class(value, record.data);
1262
1263 var fa = '<i class="fa-fw x-grid-icon-custom ' + cls + '"></i> ';
1264 return fa + value;
1265 },
1266
1267 render_support_level: function(value, metaData, record) {
1268 return PVE.Utils.support_level_hash[value] || '-';
1269 },
1270
1271 render_upid: function(value, metaData, record) {
1272 var type = record.data.type;
1273 var id = record.data.id;
1274
1275 return Proxmox.Utils.format_task_description(type, id);
1276 },
1277
1278 render_optional_url: function(value) {
1279 if (value && value.match(/^https?:\/\//)) {
1280 return '<a target="_blank" href="' + value + '">' + value + '</a>';
1281 }
1282 return value;
1283 },
1284
1285 render_san: function(value) {
1286 var names = [];
1287 if (Ext.isArray(value)) {
1288 value.forEach(function(val) {
1289 if (!Ext.isNumber(val)) {
1290 names.push(val);
1291 }
1292 });
1293 return names.join('<br>');
1294 }
1295 return value;
1296 },
1297
1298 render_full_name: function(firstname, metaData, record) {
1299 var first = firstname || '';
1300 var last = record.data.lastname || '';
1301 return Ext.htmlEncode(first + " " + last);
1302 },
1303
1304 render_u2f_error: function(error) {
1305 var ErrorNames = {
1306 '1': gettext('Other Error'),
1307 '2': gettext('Bad Request'),
1308 '3': gettext('Configuration Unsupported'),
1309 '4': gettext('Device Ineligible'),
1310 '5': gettext('Timeout'),
1311 };
1312 return "U2F Error: " + ErrorNames[error] || Proxmox.Utils.unknownText;
1313 },
1314
1315 windowHostname: function() {
1316 return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
1317 function(m, addr, offset, original) { return addr; });
1318 },
1319
1320 openDefaultConsoleWindow: function(consoles, consoleType, vmid, nodename, vmname, cmd) {
1321 var dv = PVE.Utils.defaultViewer(consoles, consoleType);
1322 PVE.Utils.openConsoleWindow(dv, consoleType, vmid, nodename, vmname, cmd);
1323 },
1324
1325 openConsoleWindow: function(viewer, consoleType, vmid, nodename, vmname, cmd) {
1326 if (vmid === undefined && (consoleType === 'kvm' || consoleType === 'lxc')) {
1327 throw "missing vmid";
1328 }
1329 if (!nodename) {
1330 throw "no nodename specified";
1331 }
1332
1333 if (viewer === 'html5') {
1334 PVE.Utils.openVNCViewer(consoleType, vmid, nodename, vmname, cmd);
1335 } else if (viewer === 'xtermjs') {
1336 Proxmox.Utils.openXtermJsViewer(consoleType, vmid, nodename, vmname, cmd);
1337 } else if (viewer === 'vv') {
1338 let url = '/nodes/' + nodename + '/spiceshell';
1339 let params = {
1340 proxy: PVE.Utils.windowHostname(),
1341 };
1342 if (consoleType === 'kvm') {
1343 url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy';
1344 } else if (consoleType === 'lxc') {
1345 url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy';
1346 } else if (consoleType === 'upgrade') {
1347 params.cmd = 'upgrade';
1348 } else if (consoleType === 'cmd') {
1349 params.cmd = cmd;
1350 } else if (consoleType !== 'shell') {
1351 throw `unknown spice viewer type '${consoleType}'`;
1352 }
1353 PVE.Utils.openSpiceViewer(url, params);
1354 } else {
1355 throw `unknown viewer type '${viewer}'`;
1356 }
1357 },
1358
1359 defaultViewer: function(consoles, type) {
1360 var allowSpice, allowXtermjs;
1361
1362 if (consoles === true) {
1363 allowSpice = true;
1364 allowXtermjs = true;
1365 } else if (typeof consoles === 'object') {
1366 allowSpice = consoles.spice;
1367 allowXtermjs = !!consoles.xtermjs;
1368 }
1369 let dv = PVE.VersionInfo.console || (type === 'kvm' ? 'vv' : 'xtermjs');
1370 if (dv === 'vv' && !allowSpice) {
1371 dv = allowXtermjs ? 'xtermjs' : 'html5';
1372 } else if (dv === 'xtermjs' && !allowXtermjs) {
1373 dv = allowSpice ? 'vv' : 'html5';
1374 }
1375
1376 return dv;
1377 },
1378
1379 openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) {
1380 let scaling = 'off';
1381 if (Proxmox.Utils.toolkit !== 'touch') {
1382 var sp = Ext.state.Manager.getProvider();
1383 scaling = sp.get('novnc-scaling', 'off');
1384 }
1385 var url = Ext.Object.toQueryString({
1386 console: vmtype, // kvm, lxc, upgrade or shell
1387 novnc: 1,
1388 vmid: vmid,
1389 vmname: vmname,
1390 node: nodename,
1391 resize: scaling,
1392 cmd: cmd,
1393 });
1394 var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
1395 if (nw) {
1396 nw.focus();
1397 }
1398 },
1399
1400 openSpiceViewer: function(url, params) {
1401 var downloadWithName = function(uri, name) {
1402 var link = Ext.DomHelper.append(document.body, {
1403 tag: 'a',
1404 href: uri,
1405 css: 'display:none;visibility:hidden;height:0px;',
1406 });
1407
1408 // Note: we need to tell Android and Chrome the correct file name extension
1409 // but we do not set 'download' tag for other environments, because
1410 // It can have strange side effects (additional user prompt on firefox)
1411 if (navigator.userAgent.match(/Android|Chrome/i)) {
1412 link.download = name;
1413 }
1414
1415 if (link.fireEvent) {
1416 link.fireEvent('onclick');
1417 } else {
1418 let evt = document.createEvent("MouseEvents");
1419 evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
1420 link.dispatchEvent(evt);
1421 }
1422 };
1423
1424 Proxmox.Utils.API2Request({
1425 url: url,
1426 params: params,
1427 method: 'POST',
1428 failure: function(response, opts) {
1429 Ext.Msg.alert('Error', response.htmlStatus);
1430 },
1431 success: function(response, opts) {
1432 let cfg = response.result.data;
1433 let raw = Object.entries(cfg).reduce((acc, [k, v]) => acc + `${k}=${v}\n`, "[virt-viewer]\n");
1434 let spiceDownload = 'data:application/x-virt-viewer;charset=UTF-8,' + encodeURIComponent(raw);
1435 downloadWithName(spiceDownload, "pve-spice.vv");
1436 },
1437 });
1438 },
1439
1440 openTreeConsole: function(tree, record, item, index, e) {
1441 e.stopEvent();
1442 let nodename = record.data.node;
1443 let vmid = record.data.vmid;
1444 let vmname = record.data.name;
1445 if (record.data.type === 'qemu' && !record.data.template) {
1446 Proxmox.Utils.API2Request({
1447 url: `/nodes/${nodename}/qemu/${vmid}/status/current`,
1448 failure: response => Ext.Msg.alert('Error', response.htmlStatus),
1449 success: function(response, opts) {
1450 let conf = response.result.data;
1451 let consoles = {
1452 spice: !!conf.spice,
1453 xtermjs: !!conf.serial,
1454 };
1455 PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname);
1456 },
1457 });
1458 } else if (record.data.type === 'lxc' && !record.data.template) {
1459 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
1460 }
1461 },
1462
1463 // test automation helper
1464 call_menu_handler: function(menu, text) {
1465 let item = menu.query('menuitem').find(el => el.text === text);
1466 if (item && item.handler) {
1467 item.handler();
1468 }
1469 },
1470
1471 createCmdMenu: function(v, record, item, index, event) {
1472 event.stopEvent();
1473 if (!(v instanceof Ext.tree.View)) {
1474 v.select(record);
1475 }
1476 let menu;
1477 let type = record.data.type;
1478
1479 if (record.data.template) {
1480 if (type === 'qemu' || type === 'lxc') {
1481 menu = Ext.create('PVE.menu.TemplateMenu', {
1482 pveSelNode: record,
1483 });
1484 }
1485 } else if (type === 'qemu' || type === 'lxc' || type === 'node') {
1486 menu = Ext.create('PVE.' + type + '.CmdMenu', {
1487 pveSelNode: record,
1488 nodename: record.data.node,
1489 });
1490 } else {
1491 return undefined;
1492 }
1493
1494 menu.showAt(event.getXY());
1495 return menu;
1496 },
1497
1498 // helper for deleting field which are set to there default values
1499 delete_if_default: function(values, fieldname, default_val, create) {
1500 if (values[fieldname] === '' || values[fieldname] === default_val) {
1501 if (!create) {
1502 if (values.delete) {
1503 if (Ext.isArray(values.delete)) {
1504 values.delete.push(fieldname);
1505 } else {
1506 values.delete += ',' + fieldname;
1507 }
1508 } else {
1509 values.delete = fieldname;
1510 }
1511 }
1512
1513 delete values[fieldname];
1514 }
1515 },
1516
1517 loadSSHKeyFromFile: function(file, callback) {
1518 // ssh-keygen produces ~ 740 bytes for a 4096 bit RSA key, current max is 16 kbit, so assume:
1519 // 740 * 8 for max. 32kbit (5920 bytes), round upwards to 8192 bytes, leaves lots of comment space
1520 PVE.Utils.loadFile(file, callback, 8192);
1521 },
1522
1523 loadFile: function(file, callback, maxSize) {
1524 maxSize = maxSize || 32 * 1024;
1525 if (file.size > maxSize) {
1526 Ext.Msg.alert(gettext('Error'), `${gettext("Invalid file size")}: ${file.size} > ${maxSize}`);
1527 return;
1528 }
1529 let reader = new FileReader();
1530 reader.onload = evt => callback(evt.target.result);
1531 reader.readAsText(file);
1532 },
1533
1534 loadTextFromFile: function(file, callback, maxBytes) {
1535 let maxSize = maxBytes || 8192;
1536 if (file.size > maxSize) {
1537 Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
1538 return;
1539 }
1540 let reader = new FileReader();
1541 reader.onload = evt => callback(evt.target.result);
1542 reader.readAsText(file);
1543 },
1544
1545 diskControllerMaxIDs: {
1546 ide: 4,
1547 sata: 6,
1548 scsi: 31,
1549 virtio: 16,
1550 },
1551
1552 // types is either undefined (all busses), an array of busses, or a single bus
1553 forEachBus: function(types, func) {
1554 let busses = Object.keys(PVE.Utils.diskControllerMaxIDs);
1555
1556 if (Ext.isArray(types)) {
1557 busses = types;
1558 } else if (Ext.isDefined(types)) {
1559 busses = [types];
1560 }
1561
1562 // check if we only have valid busses
1563 for (let i = 0; i < busses.length; i++) {
1564 if (!PVE.Utils.diskControllerMaxIDs[busses[i]]) {
1565 throw "invalid bus: '" + busses[i] + "'";
1566 }
1567 }
1568
1569 for (let i = 0; i < busses.length; i++) {
1570 let count = PVE.Utils.diskControllerMaxIDs[busses[i]];
1571 for (let j = 0; j < count; j++) {
1572 let cont = func(busses[i], j);
1573 if (!cont && cont !== undefined) {
1574 return;
1575 }
1576 }
1577 }
1578 },
1579
1580 mp_counts: {
1581 mps: 256,
1582 unused: 256,
1583 },
1584
1585 forEachMP: function(func, includeUnused) {
1586 for (let i = 0; i < PVE.Utils.mp_counts.mps; i++) {
1587 let cont = func('mp', i);
1588 if (!cont && cont !== undefined) {
1589 return;
1590 }
1591 }
1592
1593 if (!includeUnused) {
1594 return;
1595 }
1596
1597 for (let i = 0; i < PVE.Utils.mp_counts.unused; i++) {
1598 let cont = func('unused', i);
1599 if (!cont && cont !== undefined) {
1600 return;
1601 }
1602 }
1603 },
1604
1605 hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1 },
1606
1607 cleanEmptyObjectKeys: function(obj) {
1608 for (const propName of Object.keys(obj)) {
1609 if (obj[propName] === null || obj[propName] === undefined) {
1610 delete obj[propName];
1611 }
1612 }
1613 },
1614
1615 acmedomain_count: 5,
1616
1617 add_domain_to_acme: function(acme, domain) {
1618 if (acme.domains === undefined) {
1619 acme.domains = [domain];
1620 } else {
1621 acme.domains.push(domain);
1622 acme.domains = acme.domains.filter((value, index, self) => self.indexOf(value) === index);
1623 }
1624 return acme;
1625 },
1626
1627 remove_domain_from_acme: function(acme, domain) {
1628 if (acme.domains !== undefined) {
1629 acme.domains = acme
1630 .domains
1631 .filter((value, index, self) => self.indexOf(value) === index && value !== domain);
1632 }
1633 return acme;
1634 },
1635
1636 handleStoreErrorOrMask: function(view, store, regex, callback) {
1637 view.mon(store, 'load', function(proxy, response, success, operation) {
1638 if (success) {
1639 Proxmox.Utils.setErrorMask(view, false);
1640 return;
1641 }
1642 let msg;
1643 if (operation.error.statusText) {
1644 if (operation.error.statusText.match(regex)) {
1645 callback(view, operation.error);
1646 return;
1647 } else {
1648 msg = operation.error.statusText + ' (' + operation.error.status + ')';
1649 }
1650 } else {
1651 msg = gettext('Connection error');
1652 }
1653 Proxmox.Utils.setErrorMask(view, msg);
1654 });
1655 },
1656
1657 showCephInstallOrMask: function(container, msg, nodename, callback) {
1658 if (msg.match(/not (installed|initialized)/i)) {
1659 if (Proxmox.UserName === 'root@pam') {
1660 container.el.mask();
1661 if (!container.down('pveCephInstallWindow')) {
1662 var isInstalled = !!msg.match(/not initialized/i);
1663 var win = Ext.create('PVE.ceph.Install', {
1664 nodename: nodename,
1665 });
1666 win.getViewModel().set('isInstalled', isInstalled);
1667 container.add(win);
1668 win.show();
1669 callback(win);
1670 }
1671 } else {
1672 container.mask(Ext.String.format(gettext('{0} not installed.') +
1673 ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']);
1674 }
1675 return true;
1676 } else {
1677 return false;
1678 }
1679 },
1680
1681 monitor_ceph_installed: function(view, rstore, nodename, maskOwnerCt) {
1682 PVE.Utils.handleStoreErrorOrMask(
1683 view,
1684 rstore,
1685 /not (installed|initialized)/i,
1686 (_, error) => {
1687 nodename = nodename || 'localhost';
1688 let maskTarget = maskOwnerCt ? view.ownerCt : view;
1689 rstore.stopUpdate();
1690 PVE.Utils.showCephInstallOrMask(maskTarget, error.statusText, nodename, win => {
1691 view.mon(win, 'cephInstallWindowClosed', () => rstore.startUpdate());
1692 });
1693 },
1694 );
1695 },
1696
1697
1698 propertyStringSet: function(target, source, name, value) {
1699 if (source) {
1700 if (value === undefined) {
1701 target[name] = source;
1702 } else {
1703 target[name] = value;
1704 }
1705 } else {
1706 delete target[name];
1707 }
1708 },
1709
1710 forEachCorosyncLink: function(nodeinfo, cb) {
1711 let re = /(?:ring|link)(\d+)_addr/;
1712 Ext.iterate(nodeinfo, (prop, val) => {
1713 let match = re.exec(prop);
1714 if (match) {
1715 cb(Number(match[1]), val);
1716 }
1717 });
1718 },
1719
1720 cpu_vendor_map: {
1721 'default': 'QEMU',
1722 'AuthenticAMD': 'AMD',
1723 'GenuineIntel': 'Intel',
1724 },
1725
1726 cpu_vendor_order: {
1727 "AMD": 1,
1728 "Intel": 2,
1729 "QEMU": 3,
1730 "Host": 4,
1731 "_default_": 5, // includes custom models
1732 },
1733
1734 verify_ip64_address_list: function(value, with_suffix) {
1735 for (let addr of value.split(/[ ,;]+/)) {
1736 if (addr === '') {
1737 continue;
1738 }
1739
1740 if (with_suffix) {
1741 let parts = addr.split('%');
1742 addr = parts[0];
1743
1744 if (parts.length > 2) {
1745 return false;
1746 }
1747
1748 if (parts.length > 1 && !addr.startsWith('fe80:')) {
1749 return false;
1750 }
1751 }
1752
1753 if (!Proxmox.Utils.IP64_match.test(addr)) {
1754 return false;
1755 }
1756 }
1757
1758 return true;
1759 },
1760 },
1761
1762 singleton: true,
1763 constructor: function() {
1764 var me = this;
1765 Ext.apply(me, me.utilities);
1766
1767 Proxmox.Utils.override_task_descriptions({
1768 acmedeactivate: ['ACME Account', gettext('Deactivate')],
1769 acmenewcert: ['SRV', gettext('Order Certificate')],
1770 acmerefresh: ['ACME Account', gettext('Refresh')],
1771 acmeregister: ['ACME Account', gettext('Register')],
1772 acmerenew: ['SRV', gettext('Renew Certificate')],
1773 acmerevoke: ['SRV', gettext('Revoke Certificate')],
1774 acmeupdate: ['ACME Account', gettext('Update')],
1775 'auth-realm-sync': [gettext('Realm'), gettext('Sync')],
1776 'auth-realm-sync-test': [gettext('Realm'), gettext('Sync Preview')],
1777 cephcreatemds: ['Ceph Metadata Server', gettext('Create')],
1778 cephcreatemgr: ['Ceph Manager', gettext('Create')],
1779 cephcreatemon: ['Ceph Monitor', gettext('Create')],
1780 cephcreateosd: ['Ceph OSD', gettext('Create')],
1781 cephcreatepool: ['Ceph Pool', gettext('Create')],
1782 cephdestroymds: ['Ceph Metadata Server', gettext('Destroy')],
1783 cephdestroymgr: ['Ceph Manager', gettext('Destroy')],
1784 cephdestroymon: ['Ceph Monitor', gettext('Destroy')],
1785 cephdestroyosd: ['Ceph OSD', gettext('Destroy')],
1786 cephdestroypool: ['Ceph Pool', gettext('Destroy')],
1787 cephfscreate: ['CephFS', gettext('Create')],
1788 cephsetpool: ['Ceph Pool', gettext('Edit')],
1789 cephsetflags: ['', gettext('Change global Ceph flags')],
1790 clustercreate: ['', gettext('Create Cluster')],
1791 clusterjoin: ['', gettext('Join Cluster')],
1792 dircreate: [gettext('Directory Storage'), gettext('Create')],
1793 dirremove: [gettext('Directory'), gettext('Remove')],
1794 download: ['', gettext('Download')],
1795 hamigrate: ['HA', gettext('Migrate')],
1796 hashutdown: ['HA', gettext('Shutdown')],
1797 hastart: ['HA', gettext('Start')],
1798 hastop: ['HA', gettext('Stop')],
1799 imgcopy: ['', gettext('Copy data')],
1800 imgdel: ['', gettext('Erase data')],
1801 lvmcreate: [gettext('LVM Storage'), gettext('Create')],
1802 lvmthincreate: [gettext('LVM-Thin Storage'), gettext('Create')],
1803 migrateall: ['', gettext('Migrate all VMs and Containers')],
1804 'move_volume': ['CT', gettext('Move Volume')],
1805 'pbs-download': ['VM/CT', gettext('File Restore Download')],
1806 pull_file: ['CT', gettext('Pull file')],
1807 push_file: ['CT', gettext('Push file')],
1808 qmclone: ['VM', gettext('Clone')],
1809 qmconfig: ['VM', gettext('Configure')],
1810 qmcreate: ['VM', gettext('Create')],
1811 qmdelsnapshot: ['VM', gettext('Delete Snapshot')],
1812 qmdestroy: ['VM', gettext('Destroy')],
1813 qmigrate: ['VM', gettext('Migrate')],
1814 qmmove: ['VM', gettext('Move disk')],
1815 qmpause: ['VM', gettext('Pause')],
1816 qmreboot: ['VM', gettext('Reboot')],
1817 qmreset: ['VM', gettext('Reset')],
1818 qmrestore: ['VM', gettext('Restore')],
1819 qmresume: ['VM', gettext('Resume')],
1820 qmrollback: ['VM', gettext('Rollback')],
1821 qmshutdown: ['VM', gettext('Shutdown')],
1822 qmsnapshot: ['VM', gettext('Snapshot')],
1823 qmstart: ['VM', gettext('Start')],
1824 qmstop: ['VM', gettext('Stop')],
1825 qmsuspend: ['VM', gettext('Hibernate')],
1826 qmtemplate: ['VM', gettext('Convert to template')],
1827 spiceproxy: ['VM/CT', gettext('Console') + ' (Spice)'],
1828 spiceshell: ['', gettext('Shell') + ' (Spice)'],
1829 startall: ['', gettext('Start all VMs and Containers')],
1830 stopall: ['', gettext('Stop all VMs and Containers')],
1831 unknownimgdel: ['', gettext('Destroy image from unknown guest')],
1832 wipedisk: ['Device', gettext('Wipe Disk')],
1833 vncproxy: ['VM/CT', gettext('Console')],
1834 vncshell: ['', gettext('Shell')],
1835 vzclone: ['CT', gettext('Clone')],
1836 vzcreate: ['CT', gettext('Create')],
1837 vzdelsnapshot: ['CT', gettext('Delete Snapshot')],
1838 vzdestroy: ['CT', gettext('Destroy')],
1839 vzdump: (type, id) => id ? `VM/CT ${id} - ${gettext('Backup')}` : gettext('Backup Job'),
1840 vzmigrate: ['CT', gettext('Migrate')],
1841 vzmount: ['CT', gettext('Mount')],
1842 vzreboot: ['CT', gettext('Reboot')],
1843 vzrestore: ['CT', gettext('Restore')],
1844 vzresume: ['CT', gettext('Resume')],
1845 vzrollback: ['CT', gettext('Rollback')],
1846 vzshutdown: ['CT', gettext('Shutdown')],
1847 vzsnapshot: ['CT', gettext('Snapshot')],
1848 vzstart: ['CT', gettext('Start')],
1849 vzstop: ['CT', gettext('Stop')],
1850 vzsuspend: ['CT', gettext('Suspend')],
1851 vztemplate: ['CT', gettext('Convert to template')],
1852 vzumount: ['CT', gettext('Unmount')],
1853 zfscreate: [gettext('ZFS Storage'), gettext('Create')],
1854 });
1855 },
1856
1857 });