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