]>
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 /*jslint confusion: true */
23 Ext
. define ( 'PVE.Utils' , { utilities
: {
25 // this singleton contains miscellaneous utilities
27 toolkit
: undefined , // (extjs|touch), set inside Toolkit.js
29 bus_match
: /^(ide|sata|virtio|scsi)\d+$/ ,
43 'c' : gettext ( 'Community' ),
44 'b' : gettext ( 'Basic' ),
45 's' : gettext ( 'Standard' ),
46 'p' : gettext ( 'Premium' )
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.' ,
53 { desc
: '5.x - 2.6 Kernel' , val
: 'l26' },
54 { desc
: '2.4 Kernel' , val
: 'l24' }
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' }
65 { desc
: '-' , val
: 'solaris' }
68 { desc
: '-' , val
: 'other' }
72 get_health_icon : function ( state
, circle
) {
73 if ( circle
=== undefined ) {
77 if ( state
=== undefined ) {
81 var icon
= 'faded fa-question' ;
84 icon
= 'good fa-check' ;
87 icon
= 'warning fa-upload' ;
90 icon
= 'warning fa-refresh' ;
93 icon
= 'warning fa-exclamation' ;
96 icon
= 'critical fa-times' ;
108 parse_ceph_version : function ( service
) {
109 if ( service
. ceph_version_short
) {
110 return service
. ceph_version_short
;
113 if ( service
. ceph_version
) {
114 var match
= service
. ceph_version
. match ( /version (\d+(\.\d+)*)/ );
123 compare_ceph_versions : function ( a
, b
) {
131 if ( Ext
. isArray ( a
)) {
132 avers
= a
. slice (); // copy array
134 avers
= a
. toString (). split ( '.' );
137 if ( Ext
. isArray ( b
)) {
138 bvers
= b
. slice (); // copy array
140 bvers
= b
. toString (). split ( '.' );
144 let av
= avers
. shift ();
145 let bv
= bvers
. shift ();
147 if ( av
=== undefined && bv
=== undefined ) {
149 } else if ( av
=== undefined ) {
151 } else if ( bv
=== undefined ) {
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
162 get_ceph_icon_html : function ( health
, fw
) {
163 var state
= PVE
. Utils
. map_ceph_health
[ health
];
164 var cls
= PVE
. Utils
. get_health_icon ( state
);
168 return "<i class='fa " + cls
+ "'></i> " ;
173 'HEALTH_UPGRADE' : 'upgrade' ,
175 'HEALTH_WARN' : 'warning' ,
176 'HEALTH_ERR' : 'critical'
179 render_ceph_health : function ( healthObj
) {
181 iconCls
: PVE
. Utils
. get_health_icon (),
185 if (! healthObj
|| ! healthObj
. status
) {
189 var health
= PVE
. Utils
. map_ceph_health
[ healthObj
. status
];
191 state
. iconCls
= PVE
. Utils
. get_health_icon ( health
, true );
192 state
. text
= healthObj
. status
;
197 render_zfs_health : function ( value
) {
198 if ( typeof value
== 'undefined' ){
201 var iconCls
= 'question-circle' ;
205 iconCls
= 'check-circle good' ;
209 iconCls
= 'exclamation-circle warning' ;
214 iconCls
= 'times-circle critical' ;
219 return '<i class="fa fa-' + iconCls
+ '"></i> ' + value
;
223 get_kvm_osinfo : function ( value
) {
224 var info
= { base
: 'Other' }; // default
226 Ext
. each ( Object
. keys ( PVE
. Utils
. kvm_ostypes
), function ( k
) {
227 Ext
. each ( PVE
. Utils
. kvm_ostypes
[ k
], function ( e
) {
228 if ( e
. val
=== value
) {
229 info
= { desc
: e
. desc
, base
: k
};
237 render_kvm_ostype : function ( value
) {
238 var osinfo
= PVE
. Utils
. get_kvm_osinfo ( value
);
239 if ( osinfo
. desc
&& osinfo
. desc
!== '-' ) {
240 return osinfo
. base
+ ' ' + osinfo
. desc
;
246 render_hotplug_features : function ( value
) {
249 if (! value
|| ( value
=== '0' )) {
250 return gettext ( 'Disabled' );
254 value
= 'disk,network,usb' ;
257 Ext
. each ( value
. split ( ',' ), function ( el
) {
259 fa
. push ( gettext ( 'Disk' ));
260 } else if ( el
=== 'network' ) {
261 fa
. push ( gettext ( 'Network' ));
262 } else if ( el
=== 'usb' ) {
264 } else if ( el
=== 'memory' ) {
265 fa
. push ( gettext ( 'Memory' ));
266 } else if ( el
=== 'cpu' ) {
267 fa
. push ( gettext ( 'CPU' ));
273 return fa
. join ( ', ' );
276 render_qga_features : function ( value
) {
278 return Proxmox
. Utils
. defaultText
+ ' (' + Proxmox
. Utils
. disabledText
+ ')' ;
280 var props
= PVE
. Parser
. parsePropertyString ( value
, 'enabled' );
281 if (! PVE
. Parser
. parseBoolean ( props
. enabled
)) {
282 return Proxmox
. Utils
. disabledText
;
285 delete props
. enabled
;
286 var agentstring
= Proxmox
. Utils
. enabledText
;
288 Ext
. Object
. each ( props
, function ( key
, value
) {
290 agentstring
+= ', ' + key
+ ': ' ;
292 if ( key
=== 'type' ) {
297 agentstring
+= map
[ value
] || Proxmox
. Utils
. unknownText
;
299 if ( PVE
. Parser
. parseBoolean ( value
)) {
300 agentstring
+= Proxmox
. Utils
. enabledText
;
302 agentstring
+= Proxmox
. Utils
. disabledText
;
310 render_qemu_machine : function ( value
) {
311 return value
|| ( Proxmox
. Utils
. defaultText
+ ' (i440fx)' );
314 render_qemu_bios : function ( value
) {
316 return Proxmox
. Utils
. defaultText
+ ' (SeaBIOS)' ;
317 } else if ( value
=== 'seabios' ) {
319 } else if ( value
=== 'ovmf' ) {
320 return "OVMF (UEFI)" ;
326 render_dc_ha_opts : function ( value
) {
328 return Proxmox
. Utils
. defaultText
;
330 return PVE
. Parser
. printPropertyString ( value
);
333 render_as_property_string : function ( value
) {
334 return (! value
) ? Proxmox
. Utils
. defaultText
335 : PVE
. Parser
. printPropertyString ( value
);
338 render_scsihw : function ( value
) {
340 return Proxmox
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
341 } else if ( value
=== 'lsi' ) {
342 return 'LSI 53C895A' ;
343 } else if ( value
=== 'lsi53c810' ) {
345 } else if ( value
=== 'megasas' ) {
346 return 'MegaRAID SAS 8708EM2' ;
347 } else if ( value
=== 'virtio-scsi-pci' ) {
348 return 'VirtIO SCSI' ;
349 } else if ( value
=== 'virtio-scsi-single' ) {
350 return 'VirtIO SCSI single' ;
351 } else if ( value
=== 'pvscsi' ) {
352 return 'VMware PVSCSI' ;
358 render_spice_enhancements : function ( values
) {
359 let props
= PVE
. Parser
. parsePropertyString ( values
);
360 if ( Ext
. Object
. isEmpty ( props
)) {
361 return Proxmox
. Utils
. noneText
;
365 if ( PVE
. Parser
. parseBoolean ( props
. foldersharing
)) {
366 output
. push ( 'Folder Sharing: ' + gettext ( 'Enabled' ));
368 if ( props
. videostreaming
=== 'all' || props
. videostreaming
=== 'filter' ) {
369 output
. push ( 'Video Streaming: ' + props
. videostreaming
);
371 return output
. join ( ', ' );
374 // fixme: auto-generate this
375 // for now, please keep in sync with PVE::Tools::kvmkeymaps
380 'de-ch' : 'German (Swiss)' ,
381 'en-gb' : 'English (UK)' ,
382 'en-us' : 'English (USA)' ,
386 //fo: 'Faroe Islands',
388 'fr-be' : 'French (Belgium)' ,
389 'fr-ca' : 'French (Canada)' ,
390 'fr-ch' : 'French (Swiss)' ,
400 //'nl-be': 'Dutch (Belgium)',
404 'pt-br' : 'Portuguese (Brazil)' ,
413 std
: gettext ( 'Standard VGA' ),
414 vmware
: gettext ( 'VMware compatible' ),
416 qxl2
: 'SPICE dual monitor' ,
417 qxl3
: 'SPICE three monitors' ,
418 qxl4
: 'SPICE four monitors' ,
419 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
420 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
421 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
422 serial3
: gettext ( 'Serial terminal' ) + ' 3' ,
423 virtio
: 'VirtIO-GPU' ,
424 none
: Proxmox
. Utils
. noneText
427 render_kvm_language : function ( value
) {
428 if (! value
|| value
=== '__default__' ) {
429 return Proxmox
. Utils
. defaultText
;
431 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
433 return text
+ ' (' + value
+ ')' ;
438 kvm_keymap_array : function () {
439 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
440 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
441 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
448 '__default__' : Proxmox
. Utils
. defaultText
+ ' (xterm.js)' ,
449 'vv' : 'SPICE (remote-viewer)' ,
450 'html5' : 'HTML5 (noVNC)' ,
451 'xtermjs' : 'xterm.js'
454 render_console_viewer : function ( value
) {
455 value
= value
|| '__default__' ;
456 if ( PVE
. Utils
. console_map
[ value
]) {
457 return PVE
. Utils
. console_map
[ value
];
462 console_viewer_array : function () {
463 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
464 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
468 render_kvm_vga_driver : function ( value
) {
470 return Proxmox
. Utils
. defaultText
;
472 var vga
= PVE
. Parser
. parsePropertyString ( value
, 'type' );
473 var text
= PVE
. Utils
. kvm_vga_drivers
[ vga
. type
];
475 text
= Proxmox
. Utils
. defaultText
;
478 return text
+ ' (' + value
+ ')' ;
483 kvm_vga_driver_array : function () {
484 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
485 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
486 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
492 render_kvm_startup : function ( value
) {
493 var startup
= PVE
. Parser
. parseStartup ( value
);
496 if ( startup
. order
=== undefined ) {
499 res
+= startup
. order
;
501 if ( startup
. up
!== undefined ) {
502 res
+= ',up=' + startup
. up
;
504 if ( startup
. down
!== undefined ) {
505 res
+= ',down=' + startup
. down
;
511 extractFormActionError : function ( action
) {
513 switch ( action
. failureType
) {
514 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
515 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
517 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
518 msg
= gettext ( 'Connection error' );
519 var resp
= action
. response
;
520 if ( resp
. status
&& resp
. statusText
) {
521 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
524 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
525 case Ext
. form
. action
. Action
. SERVER_INVALID
:
526 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
532 format_duration_short : function ( ut
) {
535 return ut
. toFixed ( 1 ) + 's' ;
540 return mins
. toFixed ( 1 ) + 'm' ;
544 var hours
= ut
/ 3600 ;
545 return hours
. toFixed ( 1 ) + 'h' ;
548 var days
= ut
/ 86400 ;
549 return days
. toFixed ( 1 ) + 'd' ;
553 'images' : gettext ( 'Disk image' ),
554 'backup' : gettext ( 'VZDump backup file' ),
555 'vztmpl' : gettext ( 'Container template' ),
556 'iso' : gettext ( 'ISO image' ),
557 'rootdir' : gettext ( 'Container' ),
558 'snippets' : gettext ( 'Snippets' )
561 volume_is_qemu_backup : function ( volid
, format
) {
562 return format
=== 'pbs-vm' || volid
. match ( ':backup/vzdump-qemu-' );
565 volume_is_lxc_backup : function ( volid
, format
) {
566 return format
=== 'pbs-ct' || volid
. match ( ':backup/vzdump-(lxc|openvz)-' );
571 name
: gettext ( 'Active Directory Server' ),
572 ipanel
: 'pveAuthADPanel' ,
573 syncipanel
: 'pveAuthLDAPSyncPanel' ,
577 name
: gettext ( 'LDAP Server' ),
578 ipanel
: 'pveAuthLDAPPanel' ,
579 syncipanel
: 'pveAuthLDAPSyncPanel' ,
584 ipanel
: 'pveAuthBasePanel' ,
588 name
: 'Proxmox VE authentication server' ,
589 ipanel
: 'pveAuthBasePanel' ,
596 name
: Proxmox
. Utils
. directoryText
,
597 ipanel
: 'DirInputPanel' ,
602 ipanel
: 'LVMInputPanel' ,
607 ipanel
: 'LvmThinInputPanel' ,
612 ipanel
: 'NFSInputPanel' ,
617 ipanel
: 'CIFSInputPanel' ,
622 ipanel
: 'GlusterFsInputPanel' ,
627 ipanel
: 'IScsiInputPanel' ,
632 ipanel
: 'CephFSInputPanel' ,
636 name
: 'CephFS (PVE)' ,
637 ipanel
: 'CephFSInputPanel' ,
643 ipanel
: 'RBDInputPanel' ,
648 ipanel
: 'RBDInputPanel' ,
653 name
: 'ZFS over iSCSI' ,
654 ipanel
: 'ZFSInputPanel' ,
659 ipanel
: 'ZFSPoolInputPanel' ,
663 name
: 'Proxmox Backup Server' ,
664 //ipanel: '', // TODO
688 ipanel
: 'VlanInputPanel' ,
693 ipanel
: 'QinQInputPanel' ,
698 ipanel
: 'VxlanInputPanel' ,
703 ipanel
: 'EvpnInputPanel' ,
708 sdncontrollerSchema
: {
715 ipanel
: 'EvpnInputPanel' ,
720 format_sdnvnet_type : function ( value
, md
, record
) {
721 var schema
= PVE
. Utils
. sdnvnetSchema
[ value
];
725 return Proxmox
. Utils
. unknownText
;
728 format_sdnzone_type : function ( value
, md
, record
) {
729 var schema
= PVE
. Utils
. sdnzoneSchema
[ value
];
731 return schema
. name
. toUpperCase ();
733 return Proxmox
. Utils
. unknownText
;
736 format_sdncontroller_type : function ( value
, md
, record
) {
737 var schema
= PVE
. Utils
. sdncontrollerSchema
[ value
];
741 return Proxmox
. Utils
. unknownText
;
744 format_storage_type : function ( value
, md
, record
) {
745 if ( value
=== 'rbd' ) {
746 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
747 } else if ( value
=== 'cephfs' ) {
748 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
751 var schema
= PVE
. Utils
. storageSchema
[ value
];
755 return Proxmox
. Utils
. unknownText
;
758 format_ha : function ( value
) {
759 var text
= Proxmox
. Utils
. noneText
;
762 text
= value
. state
|| Proxmox
. Utils
. noneText
;
764 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
765 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
771 format_content_types : function ( value
) {
772 return value
. split ( ',' ). sort (). map ( function ( ct
) {
773 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
777 render_storage_content : function ( value
, metaData
, record
) {
778 var data
= record
. data
;
779 if ( Ext
. isNumber ( data
. channel
) &&
780 Ext
. isNumber ( data
. id
) &&
781 Ext
. isNumber ( data
. lun
)) {
783 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
784 " ID " + data
. id
+ " LUN " + data
. lun
;
786 return data
. volid
. replace ( /^.*?:(.*?\/)?/ , '' );
789 render_serverity : function ( value
) {
790 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
793 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
795 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
799 var maxcpu
= record
. data
. maxcpu
|| 1 ;
801 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
805 var per
= value
* 100 ;
807 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
810 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
811 /*jslint confusion: true */
813 if (! Ext
. isNumeric ( value
)) {
817 return Proxmox
. Utils
. format_size ( value
);
820 render_bandwidth : function ( value
) {
821 if (! Ext
. isNumeric ( value
)) {
825 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
828 render_timestamp_human_readable : function ( value
) {
829 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
832 render_duration : function ( value
) {
833 if ( value
=== undefined ) {
836 return PVE
. Utils
. format_duration_short ( value
);
839 calculate_mem_usage : function ( data
) {
840 if (! Ext
. isNumeric ( data
. mem
) ||
846 return ( data
. mem
/ data
. maxmem
);
849 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
850 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
854 // we got no percentage but bytes
856 var maxmem
= record
. data
. maxmem
;
857 if (! record
. data
. uptime
||
859 ! Ext
. isNumeric ( mem
)) {
863 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
865 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
868 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
871 var maxmem
= record
. data
. maxmem
;
873 if (! record
. data
. uptime
) {
877 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
881 return PVE
. Utils
. render_size ( value
);
884 calculate_disk_usage : function ( data
) {
886 if (! Ext
. isNumeric ( data
. disk
) ||
887 data
. type
=== 'qemu' ||
888 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
889 data
. maxdisk
=== 0 ) {
893 return ( data
. disk
/ data
. maxdisk
);
896 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
897 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
901 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
904 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
907 var maxdisk
= record
. data
. maxdisk
;
908 var type
= record
. data
. type
;
910 if (! Ext
. isNumeric ( disk
) ||
913 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
917 return PVE
. Utils
. render_size ( value
);
920 get_object_icon_class : function ( type
, record
) {
924 if ( type
=== 'type' ) {
926 objType
= record
. groupbyid
;
927 } else if ( record
. template
) {
929 objType
= 'template' ;
933 status
= record
. status
+ ' ha-' + record
. hastate
;
937 status
+= ' locked lock-' + record
. lock
;
940 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
941 if ( defaults
&& defaults
. iconCls
) {
942 var retVal
= defaults
. iconCls
+ ' ' + status
;
949 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
951 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
953 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
957 render_support_level : function ( value
, metaData
, record
) {
958 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
961 render_upid : function ( value
, metaData
, record
) {
962 var type
= record
. data
. type
;
963 var id
= record
. data
. id
;
965 return Proxmox
. Utils
. format_task_description ( type
, id
);
968 /* render functions for new status panel */
970 render_usage : function ( val
) {
971 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
974 render_cpu_usage : function ( val
, max
) {
975 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
976 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
979 render_size_usage : function ( val
, max
) {
981 return gettext ( 'N/A' );
983 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
984 Ext
. String
. format ( gettext ( '{0} of {1}' ),
985 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
988 /* this is different for nodes */
989 render_node_cpu_usage : function ( value
, record
) {
990 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
993 /* this is different for nodes */
994 render_node_size_usage : function ( record
) {
995 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
998 render_optional_url : function ( value
) {
1000 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
1001 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
1006 render_san : function ( value
) {
1008 if ( Ext
. isArray ( value
)) {
1009 value
. forEach ( function ( val
) {
1010 if (! Ext
. isNumber ( val
)) {
1014 return names
. join ( '<br>' );
1019 render_full_name : function ( firstname
, metaData
, record
) {
1020 var first
= firstname
|| '' ;
1021 var last
= record
. data
. lastname
|| '' ;
1022 return Ext
. htmlEncode ( first
+ " " + last
);
1025 render_u2f_error : function ( error
) {
1027 '1' : gettext ( 'Other Error' ),
1028 '2' : gettext ( 'Bad Request' ),
1029 '3' : gettext ( 'Configuration Unsupported' ),
1030 '4' : gettext ( 'Device Ineligible' ),
1031 '5' : gettext ( 'Timeout' )
1033 return "U2F Error: " + ErrorNames
[ error
] || Proxmox
. Utils
. unknownText
;
1036 windowHostname : function () {
1037 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
1038 function ( m
, addr
, offset
, original
) { return addr
; });
1041 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
1042 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
1043 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
, cmd
);
1046 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
1047 // kvm, lxc, shell, upgrade
1049 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
1050 throw "missing vmid" ;
1054 throw "no nodename specified" ;
1057 if ( viewer
=== 'html5' ) {
1058 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
1059 } else if ( viewer
=== 'xtermjs' ) {
1060 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
1061 } else if ( viewer
=== 'vv' ) {
1063 var params
= { proxy
: PVE
. Utils
. windowHostname () };
1064 if ( vmtype
=== 'kvm' ) {
1065 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
1066 PVE
. Utils
. openSpiceViewer ( url
, params
);
1067 } else if ( vmtype
=== 'lxc' ) {
1068 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
1069 PVE
. Utils
. openSpiceViewer ( url
, params
);
1070 } else if ( vmtype
=== 'shell' ) {
1071 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1072 PVE
. Utils
. openSpiceViewer ( url
, params
);
1073 } else if ( vmtype
=== 'upgrade' ) {
1074 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1076 PVE
. Utils
. openSpiceViewer ( url
, params
);
1077 } else if ( vmtype
=== 'cmd' ) {
1078 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1080 PVE
. Utils
. openSpiceViewer ( url
, params
);
1083 throw "unknown viewer type" ;
1087 defaultViewer : function ( consoles
) {
1089 var allowSpice
, allowXtermjs
;
1091 if ( consoles
=== true ) {
1093 allowXtermjs
= true ;
1094 } else if ( typeof consoles
=== 'object' ) {
1095 allowSpice
= consoles
. spice
;
1096 allowXtermjs
= !! consoles
. xtermjs
;
1098 var dv
= PVE
. VersionInfo
. console
|| 'xtermjs' ;
1099 if ( dv
=== 'vv' && ! allowSpice
) {
1100 dv
= ( allowXtermjs
) ? 'xtermjs' : 'html5' ;
1101 } else if ( dv
=== 'xtermjs' && ! allowXtermjs
) {
1102 dv
= ( allowSpice
) ? 'vv' : 'html5' ;
1108 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
1109 let scaling
= 'off' ;
1110 if ( Proxmox
. Utils
. toolkit
!== 'touch' ) {
1111 var sp
= Ext
. state
. Manager
. getProvider ();
1112 scaling
= sp
. get ( 'novnc-scaling' , 'off' );
1114 var url
= Ext
. Object
. toQueryString ({
1115 console
: vmtype
, // kvm, lxc, upgrade or shell
1123 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1129 openSpiceViewer : function ( url
, params
){
1131 var downloadWithName = function ( uri
, name
) {
1132 var link
= Ext
. DomHelper
. append ( document
. body
, {
1135 css
: 'display:none;visibility:hidden;height:0px;'
1138 // Note: we need to tell android the correct file name extension
1139 // but we do not set 'download' tag for other environments, because
1140 // It can have strange side effects (additional user prompt on firefox)
1141 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1143 link
. download
= name
;
1146 if ( link
. fireEvent
) {
1147 link
. fireEvent ( 'onclick' );
1149 var evt
= document
. createEvent ( "MouseEvents" );
1150 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1151 link
. dispatchEvent ( evt
);
1155 Proxmox
. Utils
. API2Request ({
1159 failure : function ( response
, opts
){
1160 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1162 success : function ( response
, opts
){
1163 var raw
= "[virt-viewer] \n " ;
1164 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1165 raw
+= k
+ "=" + v
+ " \n " ;
1167 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1168 encodeURIComponent ( raw
);
1170 downloadWithName ( url
, "pve-spice.vv" );
1175 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1177 var nodename
= record
. data
. node
;
1178 var vmid
= record
. data
. vmid
;
1179 var vmname
= record
. data
. name
;
1180 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1181 Proxmox
. Utils
. API2Request ({
1182 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1183 failure : function ( response
, opts
) {
1184 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1186 success : function ( response
, opts
) {
1187 let conf
= response
. result
. data
;
1189 spice
: !! conf
. spice
,
1190 xtermjs
: !! conf
. serial
,
1192 PVE
. Utils
. openDefaultConsoleWindow ( consoles
, 'kvm' , vmid
, nodename
, vmname
);
1195 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1196 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1200 // test automation helper
1201 call_menu_handler : function ( menu
, text
) {
1203 var list
= menu
. query ( 'menuitem' );
1205 Ext
. Array
. each ( list
, function ( item
) {
1206 if ( item
. text
=== text
) {
1217 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1219 if (!( v
instanceof Ext
. tree
. View
)) {
1223 var template
= !! record
. data
. template
;
1224 var type
= record
. data
. type
;
1227 if ( type
=== 'qemu' || type
== 'lxc' ) {
1228 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
1232 } else if ( type
=== 'qemu' ||
1235 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
1237 nodename
: record
. data
. node
1243 menu
. showAt ( event
. getXY ());
1247 // helper for deleting field which are set to there default values
1248 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1249 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1251 if ( values
[ 'delete' ]) {
1252 if ( Ext
. isArray ( values
[ 'delete' ])) {
1253 values
[ 'delete' ]. push ( fieldname
);
1255 values
[ 'delete' ] += ',' + fieldname
;
1258 values
[ 'delete' ] = fieldname
;
1262 delete values
[ fieldname
];
1266 loadSSHKeyFromFile : function ( file
, callback
) {
1267 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1268 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1269 // assume: 740*8 for max. 32kbit (5920 byte file)
1270 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1271 if ( file
. size
> 8192 ) {
1272 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1278 var reader
= new FileReader ();
1279 reader
. onload = function ( evt
) {
1280 callback ( evt
. target
. result
);
1282 reader
. readAsText ( file
);
1285 diskControllerMaxIDs
: {
1292 // types is either undefined (all busses), an array of busses, or a single bus
1293 forEachBus : function ( types
, func
) {
1294 var busses
= Object
. keys ( PVE
. Utils
. diskControllerMaxIDs
);
1295 var i
, j
, count
, cont
;
1297 if ( Ext
. isArray ( types
)) {
1299 } else if ( Ext
. isDefined ( types
)) {
1303 // check if we only have valid busses
1304 for ( i
= 0 ; i
< busses
. length
; i
++) {
1305 if (! PVE
. Utils
. diskControllerMaxIDs
[ busses
[ i
]]) {
1306 throw "invalid bus: '" + busses
[ i
] + "'" ;
1310 for ( i
= 0 ; i
< busses
. length
; i
++) {
1311 count
= PVE
. Utils
. diskControllerMaxIDs
[ busses
[ i
]];
1312 for ( j
= 0 ; j
< count
; j
++) {
1313 cont
= func ( busses
[ i
], j
);
1314 if (! cont
&& cont
!== undefined ) {
1321 mp_counts
: { mps
: 256 , unused
: 256 },
1323 forEachMP : function ( func
, includeUnused
) {
1325 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1326 cont
= func ( 'mp' , i
);
1327 if (! cont
&& cont
!== undefined ) {
1332 if (! includeUnused
) {
1336 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1337 cont
= func ( 'unused' , i
);
1338 if (! cont
&& cont
!== undefined ) {
1344 hardware_counts
: { net
: 32 , usb
: 5 , hostpci
: 16 , audio
: 1 , efidisk
: 1 , serial
: 4 , rng
: 1 },
1346 cleanEmptyObjectKeys : function ( obj
) {
1348 for ( propName
in obj
) {
1349 if ( obj
. hasOwnProperty ( propName
)) {
1350 if ( obj
[ propName
] === null || obj
[ propName
] === undefined ) {
1351 delete obj
[ propName
];
1357 handleStoreErrorOrMask : function ( me
, store
, regex
, callback
) {
1359 me
. mon ( store
, 'load' , function ( proxy
, response
, success
, operation
) {
1362 Proxmox
. Utils
. setErrorMask ( me
, false );
1367 if ( operation
. error
. statusText
) {
1368 if ( operation
. error
. statusText
. match ( regex
)) {
1369 callback ( me
, operation
. error
);
1372 msg
= operation
. error
. statusText
+ ' (' + operation
. error
. status
+ ')' ;
1375 msg
= gettext ( 'Connection error' );
1377 Proxmox
. Utils
. setErrorMask ( me
, msg
);
1381 showCephInstallOrMask : function ( container
, msg
, nodename
, callback
){
1382 var regex
= new RegExp ( "not (installed|initialized)" , "i" );
1383 if ( msg
. match ( regex
)) {
1384 if ( Proxmox
. UserName
=== 'root@pam' ) {
1385 container
. el
. mask ();
1386 if (! container
. down ( 'pveCephInstallWindow' )){
1387 var isInstalled
= msg
. match ( /not initialized/i ) ? true : false ;
1388 var win
= Ext
. create ( 'PVE.ceph.Install' , {
1391 win
. getViewModel (). set ( 'isInstalled' , isInstalled
);
1397 container
. mask ( Ext
. String
. format ( gettext ( '{0} not installed.' ) +
1398 ' ' + gettext ( 'Log in as root to install.' ), 'Ceph' ), [ 'pve-static-mask' ]);
1406 propertyStringSet : function ( target
, source
, name
, value
) {
1408 if ( value
=== undefined ) {
1409 target
[ name
] = source
;
1411 target
[ name
] = value
;
1414 delete target
[ name
];
1418 updateColumns : function ( container
) {
1419 let mode
= Ext
. state
. Manager
. get ( 'summarycolumns' ) || 'auto' ;
1421 if ( mode
!== 'auto' ) {
1422 factor
= parseInt ( mode
, 10 );
1423 if ( Number
. isNaN ( factor
)) {
1427 factor
= container
. getSize (). width
< 1400 ? 1 : 2 ;
1430 if ( container
. oldFactor
=== factor
) {
1434 let items
= container
. query ( '>' ); // direct childs
1435 factor
= Math
. min ( factor
, items
. length
);
1436 container
. oldFactor
= factor
;
1438 items
. forEach (( item
) => {
1439 item
. columnWidth
= 1 / factor
;
1442 // we have to update the layout twice, since the first layout change
1443 // can trigger the scrollbar which reduces the amount of space left
1444 container
. updateLayout ();
1445 container
. updateLayout ();
1448 forEachCorosyncLink : function ( nodeinfo
, cb
) {
1449 let re
= /(?:ring|link)(\d+)_addr/ ;
1450 Ext
. iterate ( nodeinfo
, ( prop
, val
) => {
1451 let match
= re
. exec ( prop
);
1453 cb ( Number ( match
[ 1 ]), val
);
1460 constructor : function () {
1462 Ext
. apply ( me
, me
. utilities
);