]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/Utils.js
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 ;
10 // avoid errors when running without development tools
11 if (! Ext
. isDefined ( Ext
. global
. console
)) {
16 console
. log ( "Starting PVE Manager" );
18 Ext
. Ajax
. defaultHeaders
= {
19 'Accept' : 'application/json'
22 Ext
. define ( 'PVE.Utils' , { utilities
: {
24 // this singleton contains miscellaneous utilities
26 toolkit
: undefined , // (extjs|touch), set inside Toolkit.js
28 bus_match
: /^(ide|sata|virtio|scsi)\d+$/ ,
42 'c' : gettext ( 'Community' ),
43 'b' : gettext ( 'Basic' ),
44 's' : gettext ( 'Standard' ),
45 'p' : gettext ( 'Premium' )
48 noSubKeyHtml
: 'You do not have a valid subscription for this server. Please visit <a target="_blank" href="https://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.' ,
52 { desc
: '5.x - 2.6 Kernel' , val
: 'l26' },
53 { desc
: '2.4 Kernel' , val
: 'l24' }
55 'Microsoft Windows' : [
56 { desc
: '10/2016/2019' , val
: 'win10' },
57 { desc
: '8.x/2012/2012r2' , val
: 'win8' },
58 { desc
: '7/2008r2' , val
: 'win7' },
59 { desc
: 'Vista/2008' , val
: 'w2k8' },
60 { desc
: 'XP/2003' , val
: 'wxp' },
61 { desc
: '2000' , val
: 'w2k' }
64 { desc
: '-' , val
: 'solaris' }
67 { desc
: '-' , val
: 'other' }
71 get_health_icon : function ( state
, circle
) {
72 if ( circle
=== undefined ) {
76 if ( state
=== undefined ) {
80 var icon
= 'faded fa-question' ;
83 icon
= 'good fa-check' ;
86 icon
= 'warning fa-upload' ;
89 icon
= 'warning fa-refresh' ;
92 icon
= 'warning fa-exclamation' ;
95 icon
= 'critical fa-times' ;
107 parse_ceph_version : function ( service
) {
108 if ( service
. ceph_version_short
) {
109 return service
. ceph_version_short
;
112 if ( service
. ceph_version
) {
113 var match
= service
. ceph_version
. match ( /version (\d+(\.\d+)*)/ );
122 compare_ceph_versions : function ( a
, b
) {
130 if ( Ext
. isArray ( a
)) {
131 avers
= a
. slice (); // copy array
133 avers
= a
. toString (). split ( '.' );
136 if ( Ext
. isArray ( b
)) {
137 bvers
= b
. slice (); // copy array
139 bvers
= b
. toString (). split ( '.' );
143 let av
= avers
. shift ();
144 let bv
= bvers
. shift ();
146 if ( av
=== undefined && bv
=== undefined ) {
148 } else if ( av
=== undefined ) {
150 } else if ( bv
=== undefined ) {
153 let diff
= parseInt ( av
, 10 ) - parseInt ( bv
, 10 );
154 if ( diff
!= 0 ) return diff
;
155 // else we need to look at the next parts
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
);
167 return "<i class='fa " + cls
+ "'></i> " ;
172 'HEALTH_UPGRADE' : 'upgrade' ,
174 'HEALTH_WARN' : 'warning' ,
175 'HEALTH_ERR' : 'critical'
178 render_ceph_health : function ( healthObj
) {
180 iconCls
: PVE
. Utils
. get_health_icon (),
184 if (! healthObj
|| ! healthObj
. status
) {
188 var health
= PVE
. Utils
. map_ceph_health
[ healthObj
. status
];
190 state
. iconCls
= PVE
. Utils
. get_health_icon ( health
, true );
191 state
. text
= healthObj
. status
;
196 render_zfs_health : function ( value
) {
197 if ( typeof value
== 'undefined' ){
200 var iconCls
= 'question-circle' ;
204 iconCls
= 'check-circle good' ;
208 iconCls
= 'exclamation-circle warning' ;
213 iconCls
= 'times-circle critical' ;
218 return '<i class="fa fa-' + iconCls
+ '"></i> ' + value
;
222 get_kvm_osinfo : function ( value
) {
223 var info
= { base
: 'Other' }; // default
225 Ext
. each ( Object
. keys ( PVE
. Utils
. kvm_ostypes
), function ( k
) {
226 Ext
. each ( PVE
. Utils
. kvm_ostypes
[ k
], function ( e
) {
227 if ( e
. val
=== value
) {
228 info
= { desc
: e
. desc
, base
: k
};
236 render_kvm_ostype : function ( value
) {
237 var osinfo
= PVE
. Utils
. get_kvm_osinfo ( value
);
238 if ( osinfo
. desc
&& osinfo
. desc
!== '-' ) {
239 return osinfo
. base
+ ' ' + osinfo
. desc
;
245 render_hotplug_features : function ( value
) {
248 if (! value
|| ( value
=== '0' )) {
249 return gettext ( 'Disabled' );
253 value
= 'disk,network,usb' ;
256 Ext
. each ( value
. split ( ',' ), function ( el
) {
258 fa
. push ( gettext ( 'Disk' ));
259 } else if ( el
=== 'network' ) {
260 fa
. push ( gettext ( 'Network' ));
261 } else if ( el
=== 'usb' ) {
263 } else if ( el
=== 'memory' ) {
264 fa
. push ( gettext ( 'Memory' ));
265 } else if ( el
=== 'cpu' ) {
266 fa
. push ( gettext ( 'CPU' ));
272 return fa
. join ( ', ' );
275 render_localtime : function ( value
) {
276 if ( value
=== '__default__' ) {
277 return Proxmox
. Utils
. defaultText
+ ' (' + gettext ( 'Enabled for Windows' ) + ')' ;
279 return Proxmox
. Utils
. format_boolean ( value
);
282 render_qga_features : function ( value
) {
284 return Proxmox
. Utils
. defaultText
+ ' (' + Proxmox
. Utils
. disabledText
+ ')' ;
286 var props
= PVE
. Parser
. parsePropertyString ( value
, 'enabled' );
287 if (! PVE
. Parser
. parseBoolean ( props
. enabled
)) {
288 return Proxmox
. Utils
. disabledText
;
291 delete props
. enabled
;
292 var agentstring
= Proxmox
. Utils
. enabledText
;
294 Ext
. Object
. each ( props
, function ( key
, value
) {
296 agentstring
+= ', ' + key
+ ': ' ;
298 if ( key
=== 'type' ) {
303 agentstring
+= map
[ value
] || Proxmox
. Utils
. unknownText
;
305 if ( PVE
. Parser
. parseBoolean ( value
)) {
306 agentstring
+= Proxmox
. Utils
. enabledText
;
308 agentstring
+= Proxmox
. Utils
. disabledText
;
316 render_qemu_machine : function ( value
) {
317 return value
|| ( Proxmox
. Utils
. defaultText
+ ' (i440fx)' );
320 render_qemu_bios : function ( value
) {
322 return Proxmox
. Utils
. defaultText
+ ' (SeaBIOS)' ;
323 } else if ( value
=== 'seabios' ) {
325 } else if ( value
=== 'ovmf' ) {
326 return "OVMF (UEFI)" ;
332 render_dc_ha_opts : function ( value
) {
334 return Proxmox
. Utils
. defaultText
;
336 return PVE
. Parser
. printPropertyString ( value
);
339 render_as_property_string : function ( value
) {
340 return (! value
) ? Proxmox
. Utils
. defaultText
341 : PVE
. Parser
. printPropertyString ( value
);
344 render_scsihw : function ( value
) {
346 return Proxmox
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
347 } else if ( value
=== 'lsi' ) {
348 return 'LSI 53C895A' ;
349 } else if ( value
=== 'lsi53c810' ) {
351 } else if ( value
=== 'megasas' ) {
352 return 'MegaRAID SAS 8708EM2' ;
353 } else if ( value
=== 'virtio-scsi-pci' ) {
354 return 'VirtIO SCSI' ;
355 } else if ( value
=== 'virtio-scsi-single' ) {
356 return 'VirtIO SCSI single' ;
357 } else if ( value
=== 'pvscsi' ) {
358 return 'VMware PVSCSI' ;
364 render_spice_enhancements : function ( values
) {
365 let props
= PVE
. Parser
. parsePropertyString ( values
);
366 if ( Ext
. Object
. isEmpty ( props
)) {
367 return Proxmox
. Utils
. noneText
;
371 if ( PVE
. Parser
. parseBoolean ( props
. foldersharing
)) {
372 output
. push ( 'Folder Sharing: ' + gettext ( 'Enabled' ));
374 if ( props
. videostreaming
=== 'all' || props
. videostreaming
=== 'filter' ) {
375 output
. push ( 'Video Streaming: ' + props
. videostreaming
);
377 return output
. join ( ', ' );
380 // fixme: auto-generate this
381 // for now, please keep in sync with PVE::Tools::kvmkeymaps
386 'de-ch' : 'German (Swiss)' ,
387 'en-gb' : 'English (UK)' ,
388 'en-us' : 'English (USA)' ,
392 //fo: 'Faroe Islands',
394 'fr-be' : 'French (Belgium)' ,
395 'fr-ca' : 'French (Canada)' ,
396 'fr-ch' : 'French (Swiss)' ,
406 //'nl-be': 'Dutch (Belgium)',
410 'pt-br' : 'Portuguese (Brazil)' ,
419 std
: gettext ( 'Standard VGA' ),
420 vmware
: gettext ( 'VMware compatible' ),
422 qxl2
: 'SPICE dual monitor' ,
423 qxl3
: 'SPICE three monitors' ,
424 qxl4
: 'SPICE four monitors' ,
425 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
426 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
427 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
428 serial3
: gettext ( 'Serial terminal' ) + ' 3' ,
429 virtio
: 'VirtIO-GPU' ,
430 none
: Proxmox
. Utils
. noneText
433 render_kvm_language : function ( value
) {
434 if (! value
|| value
=== '__default__' ) {
435 return Proxmox
. Utils
. defaultText
;
437 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
439 return text
+ ' (' + value
+ ')' ;
444 kvm_keymap_array : function () {
445 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
446 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
447 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
454 '__default__' : Proxmox
. Utils
. defaultText
+ ' (xterm.js)' ,
455 'vv' : 'SPICE (remote-viewer)' ,
456 'html5' : 'HTML5 (noVNC)' ,
457 'xtermjs' : 'xterm.js'
460 render_console_viewer : function ( value
) {
461 value
= value
|| '__default__' ;
462 if ( PVE
. Utils
. console_map
[ value
]) {
463 return PVE
. Utils
. console_map
[ value
];
468 console_viewer_array : function () {
469 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
470 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
474 render_kvm_vga_driver : function ( value
) {
476 return Proxmox
. Utils
. defaultText
;
478 var vga
= PVE
. Parser
. parsePropertyString ( value
, 'type' );
479 var text
= PVE
. Utils
. kvm_vga_drivers
[ vga
. type
];
481 text
= Proxmox
. Utils
. defaultText
;
484 return text
+ ' (' + value
+ ')' ;
489 kvm_vga_driver_array : function () {
490 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
491 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
492 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
498 render_kvm_startup : function ( value
) {
499 var startup
= PVE
. Parser
. parseStartup ( value
);
502 if ( startup
. order
=== undefined ) {
505 res
+= startup
. order
;
507 if ( startup
. up
!== undefined ) {
508 res
+= ',up=' + startup
. up
;
510 if ( startup
. down
!== undefined ) {
511 res
+= ',down=' + startup
. down
;
517 extractFormActionError : function ( action
) {
519 switch ( action
. failureType
) {
520 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
521 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
523 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
524 msg
= gettext ( 'Connection error' );
525 var resp
= action
. response
;
526 if ( resp
. status
&& resp
. statusText
) {
527 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
530 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
531 case Ext
. form
. action
. Action
. SERVER_INVALID
:
532 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
539 'images' : gettext ( 'Disk image' ),
540 'backup' : gettext ( 'VZDump backup file' ),
541 'vztmpl' : gettext ( 'Container template' ),
542 'iso' : gettext ( 'ISO image' ),
543 'rootdir' : gettext ( 'Container' ),
544 'snippets' : gettext ( 'Snippets' )
547 volume_is_qemu_backup : function ( volid
, format
) {
548 return format
=== 'pbs-vm' || volid
. match ( ':backup/vzdump-qemu-' );
551 volume_is_lxc_backup : function ( volid
, format
) {
552 return format
=== 'pbs-ct' || volid
. match ( ':backup/vzdump-(lxc|openvz)-' );
557 name
: gettext ( 'Active Directory Server' ),
558 ipanel
: 'pveAuthADPanel' ,
559 syncipanel
: 'pveAuthLDAPSyncPanel' ,
563 name
: gettext ( 'LDAP Server' ),
564 ipanel
: 'pveAuthLDAPPanel' ,
565 syncipanel
: 'pveAuthLDAPSyncPanel' ,
570 ipanel
: 'pveAuthBasePanel' ,
574 name
: 'Proxmox VE authentication server' ,
575 ipanel
: 'pveAuthBasePanel' ,
582 name
: Proxmox
. Utils
. directoryText
,
583 ipanel
: 'DirInputPanel' ,
588 ipanel
: 'LVMInputPanel' ,
593 ipanel
: 'LvmThinInputPanel' ,
598 ipanel
: 'NFSInputPanel' ,
603 ipanel
: 'CIFSInputPanel' ,
608 ipanel
: 'GlusterFsInputPanel' ,
613 ipanel
: 'IScsiInputPanel' ,
618 ipanel
: 'CephFSInputPanel' ,
622 name
: 'CephFS (PVE)' ,
623 ipanel
: 'CephFSInputPanel' ,
629 ipanel
: 'RBDInputPanel' ,
634 ipanel
: 'RBDInputPanel' ,
639 name
: 'ZFS over iSCSI' ,
640 ipanel
: 'ZFSInputPanel' ,
645 ipanel
: 'ZFSPoolInputPanel' ,
649 name
: 'Proxmox Backup Server' ,
650 //ipanel: '', // TODO
674 ipanel
: 'VlanInputPanel' ,
679 ipanel
: 'QinQInputPanel' ,
684 ipanel
: 'VxlanInputPanel' ,
689 ipanel
: 'EvpnInputPanel' ,
694 sdncontrollerSchema
: {
701 ipanel
: 'EvpnInputPanel' ,
706 format_sdnvnet_type : function ( value
, md
, record
) {
707 var schema
= PVE
. Utils
. sdnvnetSchema
[ value
];
711 return Proxmox
. Utils
. unknownText
;
714 format_sdnzone_type : function ( value
, md
, record
) {
715 var schema
= PVE
. Utils
. sdnzoneSchema
[ value
];
719 return Proxmox
. Utils
. unknownText
;
722 format_sdncontroller_type : function ( value
, md
, record
) {
723 var schema
= PVE
. Utils
. sdncontrollerSchema
[ value
];
727 return Proxmox
. Utils
. unknownText
;
730 format_storage_type : function ( value
, md
, record
) {
731 if ( value
=== 'rbd' ) {
732 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
733 } else if ( value
=== 'cephfs' ) {
734 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
737 var schema
= PVE
. Utils
. storageSchema
[ value
];
741 return Proxmox
. Utils
. unknownText
;
744 format_ha : function ( value
) {
745 var text
= Proxmox
. Utils
. noneText
;
748 text
= value
. state
|| Proxmox
. Utils
. noneText
;
750 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
751 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
757 format_content_types : function ( value
) {
758 return value
. split ( ',' ). sort (). map ( function ( ct
) {
759 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
763 render_storage_content : function ( value
, metaData
, record
) {
764 var data
= record
. data
;
765 if ( Ext
. isNumber ( data
. channel
) &&
766 Ext
. isNumber ( data
. id
) &&
767 Ext
. isNumber ( data
. lun
)) {
769 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
770 " ID " + data
. id
+ " LUN " + data
. lun
;
772 return data
. volid
. replace ( /^.*?:(.*?\/)?/ , '' );
775 render_serverity : function ( value
) {
776 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
779 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
781 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
785 var maxcpu
= record
. data
. maxcpu
|| 1 ;
787 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
791 var per
= value
* 100 ;
793 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
796 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
798 if (! Ext
. isNumeric ( value
)) {
802 return Proxmox
. Utils
. format_size ( value
);
805 render_bandwidth : function ( value
) {
806 if (! Ext
. isNumeric ( value
)) {
810 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
813 render_timestamp_human_readable : function ( value
) {
814 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
817 calculate_mem_usage : function ( data
) {
818 if (! Ext
. isNumeric ( data
. mem
) ||
824 return ( data
. mem
/ data
. maxmem
);
827 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
828 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
832 // we got no percentage but bytes
834 var maxmem
= record
. data
. maxmem
;
835 if (! record
. data
. uptime
||
837 ! Ext
. isNumeric ( mem
)) {
841 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
843 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
846 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
849 var maxmem
= record
. data
. maxmem
;
851 if (! record
. data
. uptime
) {
855 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
859 return PVE
. Utils
. render_size ( value
);
862 calculate_disk_usage : function ( data
) {
864 if (! Ext
. isNumeric ( data
. disk
) ||
865 data
. type
=== 'qemu' ||
866 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
867 data
. maxdisk
=== 0 ) {
871 return ( data
. disk
/ data
. maxdisk
);
874 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
875 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
879 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
882 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
885 var maxdisk
= record
. data
. maxdisk
;
886 var type
= record
. data
. type
;
888 if (! Ext
. isNumeric ( disk
) ||
891 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
895 return PVE
. Utils
. render_size ( value
);
898 get_object_icon_class : function ( type
, record
) {
902 if ( type
=== 'type' ) {
904 objType
= record
. groupbyid
;
905 } else if ( record
. template
) {
907 objType
= 'template' ;
911 status
= record
. status
+ ' ha-' + record
. hastate
;
915 status
+= ' locked lock-' + record
. lock
;
918 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
919 if ( defaults
&& defaults
. iconCls
) {
920 var retVal
= defaults
. iconCls
+ ' ' + status
;
927 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
929 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
931 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
935 render_support_level : function ( value
, metaData
, record
) {
936 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
939 render_upid : function ( value
, metaData
, record
) {
940 var type
= record
. data
. type
;
941 var id
= record
. data
. id
;
943 return Proxmox
. Utils
. format_task_description ( type
, id
);
946 /* render functions for new status panel */
948 render_usage : function ( val
) {
949 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
952 render_cpu_usage : function ( val
, max
) {
953 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
954 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
957 render_size_usage : function ( val
, max
) {
959 return gettext ( 'N/A' );
961 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
962 Ext
. String
. format ( gettext ( '{0} of {1}' ),
963 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
966 /* this is different for nodes */
967 render_node_cpu_usage : function ( value
, record
) {
968 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
971 /* this is different for nodes */
972 render_node_size_usage : function ( record
) {
973 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
976 render_optional_url : function ( value
) {
978 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
979 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
984 render_san : function ( value
) {
986 if ( Ext
. isArray ( value
)) {
987 value
. forEach ( function ( val
) {
988 if (! Ext
. isNumber ( val
)) {
992 return names
. join ( '<br>' );
997 render_full_name : function ( firstname
, metaData
, record
) {
998 var first
= firstname
|| '' ;
999 var last
= record
. data
. lastname
|| '' ;
1000 return Ext
. htmlEncode ( first
+ " " + last
);
1003 render_u2f_error : function ( error
) {
1005 '1' : gettext ( 'Other Error' ),
1006 '2' : gettext ( 'Bad Request' ),
1007 '3' : gettext ( 'Configuration Unsupported' ),
1008 '4' : gettext ( 'Device Ineligible' ),
1009 '5' : gettext ( 'Timeout' )
1011 return "U2F Error: " + ErrorNames
[ error
] || Proxmox
. Utils
. unknownText
;
1014 windowHostname : function () {
1015 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
1016 function ( m
, addr
, offset
, original
) { return addr
; });
1019 openDefaultConsoleWindow : function ( consoles
, consoleType
, vmid
, nodename
, vmname
, cmd
) {
1020 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
1021 PVE
. Utils
. openConsoleWindow ( dv
, consoleType
, vmid
, nodename
, vmname
, cmd
);
1024 openConsoleWindow : function ( viewer
, consoleType
, vmid
, nodename
, vmname
, cmd
) {
1025 if ( vmid
== undefined && ( consoleType
=== 'kvm' || consoleType
=== 'lxc' )) {
1026 throw "missing vmid" ;
1029 throw "no nodename specified" ;
1032 if ( viewer
=== 'html5' ) {
1033 PVE
. Utils
. openVNCViewer ( consoleType
, vmid
, nodename
, vmname
, cmd
);
1034 } else if ( viewer
=== 'xtermjs' ) {
1035 Proxmox
. Utils
. openXtermJsViewer ( consoleType
, vmid
, nodename
, vmname
, cmd
);
1036 } else if ( viewer
=== 'vv' ) {
1037 let url
= '/nodes/' + nodename
+ '/spiceshell' ;
1039 proxy
: PVE
. Utils
. windowHostname (),
1041 if ( consoleType
=== 'kvm' ) {
1042 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
1043 } else if ( consoleType
=== 'lxc' ) {
1044 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
1045 } else if ( consoleType
=== 'upgrade' ) {
1046 params
. cmd
= 'upgrade' ;
1047 } else if ( consoleType
=== 'cmd' ) {
1049 } else if ( consoleType
!== 'shell' ) {
1050 throw `unknown spice viewer type ' ${consoleType} '` ;
1052 PVE
. Utils
. openSpiceViewer ( url
, params
);
1054 throw `unknown viewer type ' ${viewer} '` ;
1058 defaultViewer : function ( consoles
) {
1060 var allowSpice
, allowXtermjs
;
1062 if ( consoles
=== true ) {
1064 allowXtermjs
= true ;
1065 } else if ( typeof consoles
=== 'object' ) {
1066 allowSpice
= consoles
. spice
;
1067 allowXtermjs
= !! consoles
. xtermjs
;
1069 var dv
= PVE
. VersionInfo
. console
|| 'xtermjs' ;
1070 if ( dv
=== 'vv' && ! allowSpice
) {
1071 dv
= ( allowXtermjs
) ? 'xtermjs' : 'html5' ;
1072 } else if ( dv
=== 'xtermjs' && ! allowXtermjs
) {
1073 dv
= ( allowSpice
) ? 'vv' : 'html5' ;
1079 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
1080 let scaling
= 'off' ;
1081 if ( Proxmox
. Utils
. toolkit
!== 'touch' ) {
1082 var sp
= Ext
. state
. Manager
. getProvider ();
1083 scaling
= sp
. get ( 'novnc-scaling' , 'off' );
1085 var url
= Ext
. Object
. toQueryString ({
1086 console
: vmtype
, // kvm, lxc, upgrade or shell
1094 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1100 openSpiceViewer : function ( url
, params
){
1102 var downloadWithName = function ( uri
, name
) {
1103 var link
= Ext
. DomHelper
. append ( document
. body
, {
1106 css
: 'display:none;visibility:hidden;height:0px;'
1109 // Note: we need to tell android the correct file name extension
1110 // but we do not set 'download' tag for other environments, because
1111 // It can have strange side effects (additional user prompt on firefox)
1112 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1114 link
. download
= name
;
1117 if ( link
. fireEvent
) {
1118 link
. fireEvent ( 'onclick' );
1120 let evt
= document
. createEvent ( "MouseEvents" );
1121 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1122 link
. dispatchEvent ( evt
);
1126 Proxmox
. Utils
. API2Request ({
1130 failure : function ( response
, opts
){
1131 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1133 success : function ( response
, opts
){
1134 var raw
= "[virt-viewer] \n " ;
1135 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1136 raw
+= k
+ "=" + v
+ " \n " ;
1138 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1139 encodeURIComponent ( raw
);
1141 downloadWithName ( url
, "pve-spice.vv" );
1146 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1148 var nodename
= record
. data
. node
;
1149 var vmid
= record
. data
. vmid
;
1150 var vmname
= record
. data
. name
;
1151 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1152 Proxmox
. Utils
. API2Request ({
1153 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1154 failure : function ( response
, opts
) {
1155 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1157 success : function ( response
, opts
) {
1158 let conf
= response
. result
. data
;
1160 spice
: !! conf
. spice
,
1161 xtermjs
: !! conf
. serial
,
1163 PVE
. Utils
. openDefaultConsoleWindow ( consoles
, 'kvm' , vmid
, nodename
, vmname
);
1166 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1167 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1171 // test automation helper
1172 call_menu_handler : function ( menu
, text
) {
1174 var list
= menu
. query ( 'menuitem' );
1176 Ext
. Array
. each ( list
, function ( item
) {
1177 if ( item
. text
=== text
) {
1188 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1190 if (!( v
instanceof Ext
. tree
. View
)) {
1194 var template
= !! record
. data
. template
;
1195 var type
= record
. data
. type
;
1198 if ( type
=== 'qemu' || type
== 'lxc' ) {
1199 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
1203 } else if ( type
=== 'qemu' ||
1206 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
1208 nodename
: record
. data
. node
1214 menu
. showAt ( event
. getXY ());
1218 // helper for deleting field which are set to there default values
1219 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1220 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1222 if ( values
[ 'delete' ]) {
1223 if ( Ext
. isArray ( values
[ 'delete' ])) {
1224 values
[ 'delete' ]. push ( fieldname
);
1226 values
[ 'delete' ] += ',' + fieldname
;
1229 values
[ 'delete' ] = fieldname
;
1233 delete values
[ fieldname
];
1237 loadSSHKeyFromFile : function ( file
, callback
) {
1238 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1239 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1240 // assume: 740*8 for max. 32kbit (5920 byte file)
1241 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1242 if ( file
. size
> 8192 ) {
1243 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1249 var reader
= new FileReader ();
1250 reader
. onload = function ( evt
) {
1251 callback ( evt
. target
. result
);
1253 reader
. readAsText ( file
);
1256 diskControllerMaxIDs
: {
1263 // types is either undefined (all busses), an array of busses, or a single bus
1264 forEachBus : function ( types
, func
) {
1265 var busses
= Object
. keys ( PVE
. Utils
. diskControllerMaxIDs
);
1266 var i
, j
, count
, cont
;
1268 if ( Ext
. isArray ( types
)) {
1270 } else if ( Ext
. isDefined ( types
)) {
1274 // check if we only have valid busses
1275 for ( i
= 0 ; i
< busses
. length
; i
++) {
1276 if (! PVE
. Utils
. diskControllerMaxIDs
[ busses
[ i
]]) {
1277 throw "invalid bus: '" + busses
[ i
] + "'" ;
1281 for ( i
= 0 ; i
< busses
. length
; i
++) {
1282 count
= PVE
. Utils
. diskControllerMaxIDs
[ busses
[ i
]];
1283 for ( j
= 0 ; j
< count
; j
++) {
1284 cont
= func ( busses
[ i
], j
);
1285 if (! cont
&& cont
!== undefined ) {
1292 mp_counts
: { mps
: 256 , unused
: 256 },
1294 forEachMP : function ( func
, includeUnused
) {
1296 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1297 cont
= func ( 'mp' , i
);
1298 if (! cont
&& cont
!== undefined ) {
1303 if (! includeUnused
) {
1307 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1308 cont
= func ( 'unused' , i
);
1309 if (! cont
&& cont
!== undefined ) {
1315 hardware_counts
: { net
: 32 , usb
: 5 , hostpci
: 16 , audio
: 1 , efidisk
: 1 , serial
: 4 , rng
: 1 },
1317 cleanEmptyObjectKeys : function ( obj
) {
1319 for ( propName
in obj
) {
1320 if ( obj
. hasOwnProperty ( propName
)) {
1321 if ( obj
[ propName
] === null || obj
[ propName
] === undefined ) {
1322 delete obj
[ propName
];
1328 acmedomain_count
: 5 ,
1330 add_domain_to_acme : function ( acme
, domain
) {
1331 if ( acme
. domains
=== undefined ) {
1332 acme
. domains
= [ domain
];
1334 acme
. domains
. push ( domain
);
1335 acme
. domains
= acme
. domains
. filter (( value
, index
, self
) => {
1336 return self
. indexOf ( value
) === index
;
1342 remove_domain_from_acme : function ( acme
, domain
) {
1343 if ( acme
. domains
!== undefined ) {
1344 acme
. domains
= acme
. domains
. filter (( value
, index
, self
) => {
1345 return self
. indexOf ( value
) === index
&& value
!== domain
;
1351 handleStoreErrorOrMask : function ( me
, store
, regex
, callback
) {
1353 me
. mon ( store
, 'load' , function ( proxy
, response
, success
, operation
) {
1356 Proxmox
. Utils
. setErrorMask ( me
, false );
1361 if ( operation
. error
. statusText
) {
1362 if ( operation
. error
. statusText
. match ( regex
)) {
1363 callback ( me
, operation
. error
);
1366 msg
= operation
. error
. statusText
+ ' (' + operation
. error
. status
+ ')' ;
1369 msg
= gettext ( 'Connection error' );
1371 Proxmox
. Utils
. setErrorMask ( me
, msg
);
1375 showCephInstallOrMask : function ( container
, msg
, nodename
, callback
){
1376 var regex
= new RegExp ( "not (installed|initialized)" , "i" );
1377 if ( msg
. match ( regex
)) {
1378 if ( Proxmox
. UserName
=== 'root@pam' ) {
1379 container
. el
. mask ();
1380 if (! container
. down ( 'pveCephInstallWindow' )){
1381 var isInstalled
= msg
. match ( /not initialized/i ) ? true : false ;
1382 var win
= Ext
. create ( 'PVE.ceph.Install' , {
1385 win
. getViewModel (). set ( 'isInstalled' , isInstalled
);
1391 container
. mask ( Ext
. String
. format ( gettext ( '{0} not installed.' ) +
1392 ' ' + gettext ( 'Log in as root to install.' ), 'Ceph' ), [ 'pve-static-mask' ]);
1400 propertyStringSet : function ( target
, source
, name
, value
) {
1402 if ( value
=== undefined ) {
1403 target
[ name
] = source
;
1405 target
[ name
] = value
;
1408 delete target
[ name
];
1412 updateColumns : function ( container
) {
1413 let mode
= Ext
. state
. Manager
. get ( 'summarycolumns' ) || 'auto' ;
1415 if ( mode
!== 'auto' ) {
1416 factor
= parseInt ( mode
, 10 );
1417 if ( Number
. isNaN ( factor
)) {
1421 factor
= container
. getSize (). width
< 1400 ? 1 : 2 ;
1424 if ( container
. oldFactor
=== factor
) {
1428 let items
= container
. query ( '>' ); // direct childs
1429 factor
= Math
. min ( factor
, items
. length
);
1430 container
. oldFactor
= factor
;
1432 items
. forEach (( item
) => {
1433 item
. columnWidth
= 1 / factor
;
1436 // we have to update the layout twice, since the first layout change
1437 // can trigger the scrollbar which reduces the amount of space left
1438 container
. updateLayout ();
1439 container
. updateLayout ();
1442 forEachCorosyncLink : function ( nodeinfo
, cb
) {
1443 let re
= /(?:ring|link)(\d+)_addr/ ;
1444 Ext
. iterate ( nodeinfo
, ( prop
, val
) => {
1445 let match
= re
. exec ( prop
);
1447 cb ( Number ( match
[ 1 ]), val
);
1454 'AuthenticAMD' : 'AMD' ,
1455 'GenuineIntel' : 'Intel'
1463 "_default_" : 5 , // includes custom models
1468 constructor : function () {
1470 Ext
. apply ( me
, me
. utilities
);