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