]>
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
: 'PBSInputPanel' ,
673 ipanel
: 'VlanInputPanel' ,
678 ipanel
: 'QinQInputPanel' ,
683 ipanel
: 'VxlanInputPanel' ,
688 ipanel
: 'EvpnInputPanel' ,
693 sdncontrollerSchema
: {
700 ipanel
: 'EvpnInputPanel' ,
705 format_sdnvnet_type : function ( value
, md
, record
) {
706 var schema
= PVE
. Utils
. sdnvnetSchema
[ value
];
710 return Proxmox
. Utils
. unknownText
;
713 format_sdnzone_type : function ( value
, md
, record
) {
714 var schema
= PVE
. Utils
. sdnzoneSchema
[ value
];
718 return Proxmox
. Utils
. unknownText
;
721 format_sdncontroller_type : function ( value
, md
, record
) {
722 var schema
= PVE
. Utils
. sdncontrollerSchema
[ value
];
726 return Proxmox
. Utils
. unknownText
;
729 format_storage_type : function ( value
, md
, record
) {
730 if ( value
=== 'rbd' ) {
731 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
732 } else if ( value
=== 'cephfs' ) {
733 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
736 var schema
= PVE
. Utils
. storageSchema
[ value
];
740 return Proxmox
. Utils
. unknownText
;
743 format_ha : function ( value
) {
744 var text
= Proxmox
. Utils
. noneText
;
747 text
= value
. state
|| Proxmox
. Utils
. noneText
;
749 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
750 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
756 format_content_types : function ( value
) {
757 return value
. split ( ',' ). sort (). map ( function ( ct
) {
758 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
762 render_storage_content : function ( value
, metaData
, record
) {
763 var data
= record
. data
;
764 if ( Ext
. isNumber ( data
. channel
) &&
765 Ext
. isNumber ( data
. id
) &&
766 Ext
. isNumber ( data
. lun
)) {
768 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
769 " ID " + data
. id
+ " LUN " + data
. lun
;
771 return data
. volid
. replace ( /^.*?:(.*?\/)?/ , '' );
774 render_serverity : function ( value
) {
775 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
778 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
780 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
784 var maxcpu
= record
. data
. maxcpu
|| 1 ;
786 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
790 var per
= value
* 100 ;
792 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
795 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
797 if (! Ext
. isNumeric ( value
)) {
801 return Proxmox
. Utils
. format_size ( value
);
804 render_bandwidth : function ( value
) {
805 if (! Ext
. isNumeric ( value
)) {
809 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
812 render_timestamp_human_readable : function ( value
) {
813 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
816 calculate_mem_usage : function ( data
) {
817 if (! Ext
. isNumeric ( data
. mem
) ||
823 return ( data
. mem
/ data
. maxmem
);
826 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
827 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
831 // we got no percentage but bytes
833 var maxmem
= record
. data
. maxmem
;
834 if (! record
. data
. uptime
||
836 ! Ext
. isNumeric ( mem
)) {
840 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
842 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
845 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
848 var maxmem
= record
. data
. maxmem
;
850 if (! record
. data
. uptime
) {
854 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
858 return PVE
. Utils
. render_size ( value
);
861 calculate_disk_usage : function ( data
) {
863 if (! Ext
. isNumeric ( data
. disk
) ||
864 data
. type
=== 'qemu' ||
865 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
866 data
. maxdisk
=== 0 ) {
870 return ( data
. disk
/ data
. maxdisk
);
873 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
874 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
878 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
881 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
884 var maxdisk
= record
. data
. maxdisk
;
885 var type
= record
. data
. type
;
887 if (! Ext
. isNumeric ( disk
) ||
890 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
894 return PVE
. Utils
. render_size ( value
);
897 get_object_icon_class : function ( type
, record
) {
901 if ( type
=== 'type' ) {
903 objType
= record
. groupbyid
;
904 } else if ( record
. template
) {
906 objType
= 'template' ;
910 status
= record
. status
+ ' ha-' + record
. hastate
;
914 status
+= ' locked lock-' + record
. lock
;
917 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
918 if ( defaults
&& defaults
. iconCls
) {
919 var retVal
= defaults
. iconCls
+ ' ' + status
;
926 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
928 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
930 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
934 render_support_level : function ( value
, metaData
, record
) {
935 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
938 render_upid : function ( value
, metaData
, record
) {
939 var type
= record
. data
. type
;
940 var id
= record
. data
. id
;
942 return Proxmox
. Utils
. format_task_description ( type
, id
);
945 /* render functions for new status panel */
947 render_usage : function ( val
) {
948 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
951 render_cpu_usage : function ( val
, max
) {
952 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
953 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
956 render_size_usage : function ( val
, max
) {
958 return gettext ( 'N/A' );
960 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
961 Ext
. String
. format ( gettext ( '{0} of {1}' ),
962 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
965 /* this is different for nodes */
966 render_node_cpu_usage : function ( value
, record
) {
967 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
970 /* this is different for nodes */
971 render_node_size_usage : function ( record
) {
972 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
975 render_optional_url : function ( value
) {
977 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
978 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
983 render_san : function ( value
) {
985 if ( Ext
. isArray ( value
)) {
986 value
. forEach ( function ( val
) {
987 if (! Ext
. isNumber ( val
)) {
991 return names
. join ( '<br>' );
996 render_full_name : function ( firstname
, metaData
, record
) {
997 var first
= firstname
|| '' ;
998 var last
= record
. data
. lastname
|| '' ;
999 return Ext
. htmlEncode ( first
+ " " + last
);
1002 render_u2f_error : function ( error
) {
1004 '1' : gettext ( 'Other Error' ),
1005 '2' : gettext ( 'Bad Request' ),
1006 '3' : gettext ( 'Configuration Unsupported' ),
1007 '4' : gettext ( 'Device Ineligible' ),
1008 '5' : gettext ( 'Timeout' )
1010 return "U2F Error: " + ErrorNames
[ error
] || Proxmox
. Utils
. unknownText
;
1013 windowHostname : function () {
1014 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
1015 function ( m
, addr
, offset
, original
) { return addr
; });
1018 openDefaultConsoleWindow : function ( consoles
, consoleType
, vmid
, nodename
, vmname
, cmd
) {
1019 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
1020 PVE
. Utils
. openConsoleWindow ( dv
, consoleType
, vmid
, nodename
, vmname
, cmd
);
1023 openConsoleWindow : function ( viewer
, consoleType
, vmid
, nodename
, vmname
, cmd
) {
1024 if ( vmid
== undefined && ( consoleType
=== 'kvm' || consoleType
=== 'lxc' )) {
1025 throw "missing vmid" ;
1028 throw "no nodename specified" ;
1031 if ( viewer
=== 'html5' ) {
1032 PVE
. Utils
. openVNCViewer ( consoleType
, vmid
, nodename
, vmname
, cmd
);
1033 } else if ( viewer
=== 'xtermjs' ) {
1034 Proxmox
. Utils
. openXtermJsViewer ( consoleType
, vmid
, nodename
, vmname
, cmd
);
1035 } else if ( viewer
=== 'vv' ) {
1036 let url
= '/nodes/' + nodename
+ '/spiceshell' ;
1038 proxy
: PVE
. Utils
. windowHostname (),
1040 if ( consoleType
=== 'kvm' ) {
1041 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
1042 } else if ( consoleType
=== 'lxc' ) {
1043 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
1044 } else if ( consoleType
=== 'upgrade' ) {
1045 params
. cmd
= 'upgrade' ;
1046 } else if ( consoleType
=== 'cmd' ) {
1048 } else if ( consoleType
!== 'shell' ) {
1049 throw `unknown spice viewer type ' ${consoleType} '` ;
1051 PVE
. Utils
. openSpiceViewer ( url
, params
);
1053 throw `unknown viewer type ' ${viewer} '` ;
1057 defaultViewer : function ( consoles
) {
1059 var allowSpice
, allowXtermjs
;
1061 if ( consoles
=== true ) {
1063 allowXtermjs
= true ;
1064 } else if ( typeof consoles
=== 'object' ) {
1065 allowSpice
= consoles
. spice
;
1066 allowXtermjs
= !! consoles
. xtermjs
;
1068 var dv
= PVE
. VersionInfo
. console
|| 'xtermjs' ;
1069 if ( dv
=== 'vv' && ! allowSpice
) {
1070 dv
= ( allowXtermjs
) ? 'xtermjs' : 'html5' ;
1071 } else if ( dv
=== 'xtermjs' && ! allowXtermjs
) {
1072 dv
= ( allowSpice
) ? 'vv' : 'html5' ;
1078 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
1079 let scaling
= 'off' ;
1080 if ( Proxmox
. Utils
. toolkit
!== 'touch' ) {
1081 var sp
= Ext
. state
. Manager
. getProvider ();
1082 scaling
= sp
. get ( 'novnc-scaling' , 'off' );
1084 var url
= Ext
. Object
. toQueryString ({
1085 console
: vmtype
, // kvm, lxc, upgrade or shell
1093 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1099 openSpiceViewer : function ( url
, params
){
1101 var downloadWithName = function ( uri
, name
) {
1102 var link
= Ext
. DomHelper
. append ( document
. body
, {
1105 css
: 'display:none;visibility:hidden;height:0px;'
1108 // Note: we need to tell android the correct file name extension
1109 // but we do not set 'download' tag for other environments, because
1110 // It can have strange side effects (additional user prompt on firefox)
1111 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1113 link
. download
= name
;
1116 if ( link
. fireEvent
) {
1117 link
. fireEvent ( 'onclick' );
1119 let evt
= document
. createEvent ( "MouseEvents" );
1120 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1121 link
. dispatchEvent ( evt
);
1125 Proxmox
. Utils
. API2Request ({
1129 failure : function ( response
, opts
){
1130 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1132 success : function ( response
, opts
){
1133 var raw
= "[virt-viewer] \n " ;
1134 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1135 raw
+= k
+ "=" + v
+ " \n " ;
1137 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1138 encodeURIComponent ( raw
);
1140 downloadWithName ( url
, "pve-spice.vv" );
1145 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1147 var nodename
= record
. data
. node
;
1148 var vmid
= record
. data
. vmid
;
1149 var vmname
= record
. data
. name
;
1150 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1151 Proxmox
. Utils
. API2Request ({
1152 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1153 failure : function ( response
, opts
) {
1154 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1156 success : function ( response
, opts
) {
1157 let conf
= response
. result
. data
;
1159 spice
: !! conf
. spice
,
1160 xtermjs
: !! conf
. serial
,
1162 PVE
. Utils
. openDefaultConsoleWindow ( consoles
, 'kvm' , vmid
, nodename
, vmname
);
1165 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1166 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1170 // test automation helper
1171 call_menu_handler : function ( menu
, text
) {
1173 var list
= menu
. query ( 'menuitem' );
1175 Ext
. Array
. each ( list
, function ( item
) {
1176 if ( item
. text
=== text
) {
1187 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1189 if (!( v
instanceof Ext
. tree
. View
)) {
1193 var template
= !! record
. data
. template
;
1194 var type
= record
. data
. type
;
1197 if ( type
=== 'qemu' || type
== 'lxc' ) {
1198 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
1202 } else if ( type
=== 'qemu' ||
1205 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
1207 nodename
: record
. data
. node
1213 menu
. showAt ( event
. getXY ());
1217 // helper for deleting field which are set to there default values
1218 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1219 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1221 if ( values
[ 'delete' ]) {
1222 if ( Ext
. isArray ( values
[ 'delete' ])) {
1223 values
[ 'delete' ]. push ( fieldname
);
1225 values
[ 'delete' ] += ',' + fieldname
;
1228 values
[ 'delete' ] = fieldname
;
1232 delete values
[ fieldname
];
1236 loadSSHKeyFromFile : function ( file
, callback
) {
1237 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1238 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1239 // assume: 740*8 for max. 32kbit (5920 byte file)
1240 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1241 if ( file
. size
> 8192 ) {
1242 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1248 var reader
= new FileReader ();
1249 reader
. onload = function ( evt
) {
1250 callback ( evt
. target
. result
);
1252 reader
. readAsText ( file
);
1255 diskControllerMaxIDs
: {
1262 // types is either undefined (all busses), an array of busses, or a single bus
1263 forEachBus : function ( types
, func
) {
1264 var busses
= Object
. keys ( PVE
. Utils
. diskControllerMaxIDs
);
1265 var i
, j
, count
, cont
;
1267 if ( Ext
. isArray ( types
)) {
1269 } else if ( Ext
. isDefined ( types
)) {
1273 // check if we only have valid busses
1274 for ( i
= 0 ; i
< busses
. length
; i
++) {
1275 if (! PVE
. Utils
. diskControllerMaxIDs
[ busses
[ i
]]) {
1276 throw "invalid bus: '" + busses
[ i
] + "'" ;
1280 for ( i
= 0 ; i
< busses
. length
; i
++) {
1281 count
= PVE
. Utils
. diskControllerMaxIDs
[ busses
[ i
]];
1282 for ( j
= 0 ; j
< count
; j
++) {
1283 cont
= func ( busses
[ i
], j
);
1284 if (! cont
&& cont
!== undefined ) {
1291 mp_counts
: { mps
: 256 , unused
: 256 },
1293 forEachMP : function ( func
, includeUnused
) {
1295 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1296 cont
= func ( 'mp' , i
);
1297 if (! cont
&& cont
!== undefined ) {
1302 if (! includeUnused
) {
1306 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1307 cont
= func ( 'unused' , i
);
1308 if (! cont
&& cont
!== undefined ) {
1314 hardware_counts
: { net
: 32 , usb
: 5 , hostpci
: 16 , audio
: 1 , efidisk
: 1 , serial
: 4 , rng
: 1 },
1316 cleanEmptyObjectKeys : function ( obj
) {
1318 for ( propName
in obj
) {
1319 if ( obj
. hasOwnProperty ( propName
)) {
1320 if ( obj
[ propName
] === null || obj
[ propName
] === undefined ) {
1321 delete obj
[ propName
];
1327 acmedomain_count
: 5 ,
1329 add_domain_to_acme : function ( acme
, domain
) {
1330 if ( acme
. domains
=== undefined ) {
1331 acme
. domains
= [ domain
];
1333 acme
. domains
. push ( domain
);
1334 acme
. domains
= acme
. domains
. filter (( value
, index
, self
) => {
1335 return self
. indexOf ( value
) === index
;
1341 remove_domain_from_acme : function ( acme
, domain
) {
1342 if ( acme
. domains
!== undefined ) {
1343 acme
. domains
= acme
. domains
. filter (( value
, index
, self
) => {
1344 return self
. indexOf ( value
) === index
&& value
!== domain
;
1350 handleStoreErrorOrMask : function ( me
, store
, regex
, callback
) {
1352 me
. mon ( store
, 'load' , function ( proxy
, response
, success
, operation
) {
1355 Proxmox
. Utils
. setErrorMask ( me
, false );
1360 if ( operation
. error
. statusText
) {
1361 if ( operation
. error
. statusText
. match ( regex
)) {
1362 callback ( me
, operation
. error
);
1365 msg
= operation
. error
. statusText
+ ' (' + operation
. error
. status
+ ')' ;
1368 msg
= gettext ( 'Connection error' );
1370 Proxmox
. Utils
. setErrorMask ( me
, msg
);
1374 showCephInstallOrMask : function ( container
, msg
, nodename
, callback
){
1375 var regex
= new RegExp ( "not (installed|initialized)" , "i" );
1376 if ( msg
. match ( regex
)) {
1377 if ( Proxmox
. UserName
=== 'root@pam' ) {
1378 container
. el
. mask ();
1379 if (! container
. down ( 'pveCephInstallWindow' )){
1380 var isInstalled
= msg
. match ( /not initialized/i ) ? true : false ;
1381 var win
= Ext
. create ( 'PVE.ceph.Install' , {
1384 win
. getViewModel (). set ( 'isInstalled' , isInstalled
);
1390 container
. mask ( Ext
. String
. format ( gettext ( '{0} not installed.' ) +
1391 ' ' + gettext ( 'Log in as root to install.' ), 'Ceph' ), [ 'pve-static-mask' ]);
1399 propertyStringSet : function ( target
, source
, name
, value
) {
1401 if ( value
=== undefined ) {
1402 target
[ name
] = source
;
1404 target
[ name
] = value
;
1407 delete target
[ name
];
1411 updateColumns : function ( container
) {
1412 let mode
= Ext
. state
. Manager
. get ( 'summarycolumns' ) || 'auto' ;
1414 if ( mode
!== 'auto' ) {
1415 factor
= parseInt ( mode
, 10 );
1416 if ( Number
. isNaN ( factor
)) {
1420 factor
= container
. getSize (). width
< 1400 ? 1 : 2 ;
1423 if ( container
. oldFactor
=== factor
) {
1427 let items
= container
. query ( '>' ); // direct childs
1428 factor
= Math
. min ( factor
, items
. length
);
1429 container
. oldFactor
= factor
;
1431 items
. forEach (( item
) => {
1432 item
. columnWidth
= 1 / factor
;
1435 // we have to update the layout twice, since the first layout change
1436 // can trigger the scrollbar which reduces the amount of space left
1437 container
. updateLayout ();
1438 container
. updateLayout ();
1441 forEachCorosyncLink : function ( nodeinfo
, cb
) {
1442 let re
= /(?:ring|link)(\d+)_addr/ ;
1443 Ext
. iterate ( nodeinfo
, ( prop
, val
) => {
1444 let match
= re
. exec ( prop
);
1446 cb ( Number ( match
[ 1 ]), val
);
1453 'AuthenticAMD' : 'AMD' ,
1454 'GenuineIntel' : 'Intel'
1462 "_default_" : 5 , // includes custom models
1467 constructor : function () {
1469 Ext
. apply ( me
, me
. utilities
);