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