]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - Utils.js
2 Ext
. ns ( 'Proxmox.Setup' );
4 if (! Ext
. isDefined ( Proxmox
. Setup
. auth_cookie_name
)) {
5 throw "Proxmox library not initialized" ;
8 // avoid errors related to Accessible Rich Internet Applications
9 // (access for people with disabilities)
10 // TODO reenable after all components are upgraded
11 Ext
. enableAria
= false ;
12 Ext
. enableAriaButtons
= false ;
13 Ext
. enableAriaPanels
= false ;
15 // avoid errors when running without development tools
16 if (! Ext
. isDefined ( Ext
. global
. console
)) {
28 Ext
. global
. console
= console
;
31 Ext
. Ajax
. defaultHeaders
= {
32 'Accept' : 'application/json' ,
35 Ext
. Ajax
. on ( 'beforerequest' , function ( conn
, options
) {
36 if ( Proxmox
. CSRFPreventionToken
) {
37 if (! options
. headers
) {
40 options
. headers
. CSRFPreventionToken
= Proxmox
. CSRFPreventionToken
;
44 Ext
. define ( 'Proxmox.Utils' , { // a singleton
47 yesText
: gettext ( 'Yes' ),
48 noText
: gettext ( 'No' ),
49 enabledText
: gettext ( 'Enabled' ),
50 disabledText
: gettext ( 'Disabled' ),
51 noneText
: gettext ( 'none' ),
52 NoneText
: gettext ( 'None' ),
53 errorText
: gettext ( 'Error' ),
54 unknownText
: gettext ( 'Unknown' ),
55 defaultText
: gettext ( 'Default' ),
56 daysText
: gettext ( 'days' ),
57 dayText
: gettext ( 'day' ),
58 runningText
: gettext ( 'running' ),
59 stoppedText
: gettext ( 'stopped' ),
60 neverText
: gettext ( 'never' ),
61 totalText
: gettext ( 'Total' ),
62 usedText
: gettext ( 'Used' ),
63 directoryText
: gettext ( 'Directory' ),
64 stateText
: gettext ( 'State' ),
65 groupText
: gettext ( 'Group' ),
74 eu
: 'Euskera (Basque)' ,
75 fa
: 'Persian (Farsi)' ,
80 nb
: 'Norwegian (Bokmal)' ,
81 nn
: 'Norwegian (Nynorsk)' ,
83 pt_BR
: 'Portuguese (Brazil)' ,
88 zh_CN
: 'Chinese (Simplified)' ,
89 zh_TW
: 'Chinese (Traditional)' ,
92 render_language : function ( value
) {
94 return Proxmox
. Utils
. defaultText
+ ' (English)' ;
96 var text
= Proxmox
. Utils
. language_map
[ value
];
98 return text
+ ' (' + value
+ ')' ;
103 language_array : function () {
104 var data
= [[ '__default__' , Proxmox
. Utils
. render_language ( '' )]];
105 Ext
. Object
. each ( Proxmox
. Utils
. language_map
, function ( key
, value
) {
106 data
. push ([ key
, Proxmox
. Utils
. render_language ( value
)]);
112 bond_mode_gettext_map
: {
113 '802.3ad' : 'LACP (802.3ad)' ,
114 'lacp-balance-slb' : 'LACP (balance-slb)' ,
115 'lacp-balance-tcp' : 'LACP (balance-tcp)' ,
118 render_bond_mode
: value
=> Proxmox
. Utils
. bond_mode_gettext_map
[ value
] || value
|| '' ,
120 bond_mode_array : function ( modes
) {
121 return modes
. map ( mode
=> [ mode
, Proxmox
. Utils
. render_bond_mode ( mode
)]);
124 getNoSubKeyHtml : function ( url
) {
125 // url http://www.proxmox.com/products/proxmox-ve/subscription-service-plans
126 return Ext
. String
. format ( 'You do not have a valid subscription for this server. Please visit <a target="_blank" href="{0}">www.proxmox.com</a> to get a list of available options.' , url
|| 'https://www.proxmox.com' );
129 format_boolean_with_default : function ( value
) {
130 if ( Ext
. isDefined ( value
) && value
!== '__default__' ) {
131 return value
? Proxmox
. Utils
. yesText
: Proxmox
. Utils
. noText
;
133 return Proxmox
. Utils
. defaultText
;
136 format_boolean : function ( value
) {
137 return value
? Proxmox
. Utils
. yesText
: Proxmox
. Utils
. noText
;
140 format_neg_boolean : function ( value
) {
141 return ! value
? Proxmox
. Utils
. yesText
: Proxmox
. Utils
. noText
;
144 format_enabled_toggle : function ( value
) {
145 return value
? Proxmox
. Utils
. enabledText
: Proxmox
. Utils
. disabledText
;
148 format_expire : function ( date
) {
150 return Proxmox
. Utils
. neverText
;
152 return Ext
. Date
. format ( date
, "Y-m-d" );
155 // somewhat like a human would tell durations, omit zero values and do not
156 // give seconds precision if we talk days already
157 format_duration_human : function ( ut
) {
158 let seconds
= 0 , minutes
= 0 , hours
= 0 , days
= 0 ;
165 seconds
= Number (( remaining
% 60 ). toFixed ( 1 ));
166 remaining
= Math
. trunc ( remaining
/ 60 );
168 minutes
= remaining
% 60 ;
169 remaining
= Math
. trunc ( remaining
/ 60 );
171 hours
= remaining
% 24 ;
172 remaining
= Math
. trunc ( remaining
/ 24 );
180 let add
= ( t
, unit
) => {
181 if ( t
> 0 ) res
. push ( t
+ unit
);
185 let addSeconds
= ! add ( days
, 'd' );
191 return res
. join ( ' ' );
194 format_duration_long : function ( ut
) {
195 var days
= Math
. floor ( ut
/ 86400 );
197 var hours
= Math
. floor ( ut
/ 3600 );
199 var mins
= Math
. floor ( ut
/ 60 );
202 var hours_str
= '00' + hours
. toString ();
203 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
204 var mins_str
= "00" + mins
. toString ();
205 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
206 var ut_str
= "00" + ut
. toString ();
207 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
210 var ds
= days
> 1 ? Proxmox
. Utils
. daysText
: Proxmox
. Utils
. dayText
;
211 return days
. toString () + ' ' + ds
+ ' ' +
212 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
214 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
218 format_subscription_level : function ( level
) {
221 } else if ( level
=== 'b' ) {
223 } else if ( level
=== 's' ) {
225 } else if ( level
=== 'p' ) {
228 return Proxmox
. Utils
. noneText
;
232 compute_min_label_width : function ( text
, width
) {
233 if ( width
=== undefined ) { width
= 100 ; }
235 var tm
= new Ext
. util
. TextMetrics ();
236 var min
= tm
. getWidth ( text
+ ':' );
238 return min
< width
? width
: min
;
241 setAuthData : function ( data
) {
242 Proxmox
. CSRFPreventionToken
= data
. CSRFPreventionToken
;
243 Proxmox
. UserName
= data
. username
;
244 Proxmox
. LoggedOut
= data
. LoggedOut
;
245 // creates a session cookie (expire = null)
246 // that way the cookie gets deleted after the browser window is closed
247 Ext
. util
. Cookies
. set ( Proxmox
. Setup
. auth_cookie_name
, data
. ticket
, null , '/' , null , true );
251 if ( Proxmox
. LoggedOut
) {
254 let cookie
= Ext
. util
. Cookies
. get ( Proxmox
. Setup
. auth_cookie_name
);
255 if ( Proxmox
. UserName
!== '' && cookie
&& ! cookie
. startsWith ( "PVE:tfa!" )) {
262 authClear : function () {
263 if ( Proxmox
. LoggedOut
) {
266 Ext
. util
. Cookies
. clear ( Proxmox
. Setup
. auth_cookie_name
);
269 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
270 // use el.mask() instead
271 setErrorMask : function ( comp
, msg
) {
278 } else if ( msg
=== true ) {
279 el
. mask ( gettext ( "Loading..." ));
285 getResponseErrorMessage
: ( err
) => {
286 if (! err
. statusText
) {
287 return gettext ( 'Connection error' );
289 let msg
= [ ` ${err.statusText} ( ${err.status} )` ];
290 if ( err
. response
&& err
. response
. responseText
) {
291 let txt
= err
. response
. responseText
;
293 let res
= JSON
. parse ( txt
);
294 if ( res
. errors
&& typeof res
. errors
=== 'object' ) {
295 for ( let [ key
, value
] of Object
. entries ( res
. errors
)) {
296 msg
. push ( Ext
. String
. htmlEncode ( ` ${key} : ${value} ` ));
300 // fallback to string
301 msg
. push ( Ext
. String
. htmlEncode ( txt
));
304 return msg
. join ( '<br>' );
307 monStoreErrors : function ( component
, store
, clearMaskBeforeLoad
) {
308 if ( clearMaskBeforeLoad
) {
309 component
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
310 Proxmox
. Utils
. setErrorMask ( component
, false );
313 component
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
314 if (! component
. loadCount
) {
315 component
. loadCount
= 0 ; // make sure it is nucomponent.ic
316 Proxmox
. Utils
. setErrorMask ( component
, true );
321 // only works with 'proxmox' proxy
322 component
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
323 component
. loadCount
++;
326 Proxmox
. Utils
. setErrorMask ( component
, false );
330 let error
= request
. _operation
. getError ();
331 let msg
= Proxmox
. Utils
. getResponseErrorMessage ( error
);
332 Proxmox
. Utils
. setErrorMask ( component
, msg
);
336 extractRequestError : function ( result
, verbose
) {
337 var msg
= gettext ( 'Successful' );
339 if (! result
. success
) {
340 msg
= gettext ( "Unknown error" );
341 if ( result
. message
) {
342 msg
= result
. message
;
344 msg
+= ' (' + result
. status
+ ')' ;
347 if ( verbose
&& Ext
. isObject ( result
. errors
)) {
349 Ext
. Object
. each ( result
. errors
, function ( prop
, desc
) {
350 msg
+= "<br><b>" + Ext
. htmlEncode ( prop
) + "</b>: " +
351 Ext
. htmlEncode ( desc
);
360 API2Request : function ( reqOpts
) {
361 var newopts
= Ext
. apply ({
362 waitMsg
: gettext ( 'Please wait...' ),
365 if (! newopts
. url
. match ( /^\/api2/ )) {
366 newopts
. url
= '/api2/extjs' + newopts
. url
;
368 delete newopts
. callback
;
370 var createWrapper = function ( successFn
, callbackFn
, failureFn
) {
372 success : function ( response
, options
) {
373 if ( options
. waitMsgTarget
) {
374 if ( Proxmox
. Utils
. toolkit
=== 'touch' ) {
375 options
. waitMsgTarget
. setMasked ( false );
377 options
. waitMsgTarget
. setLoading ( false );
380 var result
= Ext
. decode ( response
. responseText
);
381 response
. result
= result
;
382 if (! result
. success
) {
383 response
. htmlStatus
= Proxmox
. Utils
. extractRequestError ( result
, true );
384 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
385 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
388 Ext
. callback ( callbackFn
, options
. scope
, [ options
, true , response
]);
389 Ext
. callback ( successFn
, options
. scope
, [ response
, options
]);
391 failure : function ( response
, options
) {
392 if ( options
. waitMsgTarget
) {
393 if ( Proxmox
. Utils
. toolkit
=== 'touch' ) {
394 options
. waitMsgTarget
. setMasked ( false );
396 options
. waitMsgTarget
. setLoading ( false );
399 response
. result
= {};
401 response
. result
= Ext
. decode ( response
. responseText
);
405 var msg
= gettext ( 'Connection error' ) + ' - server offline?' ;
406 if ( response
. aborted
) {
407 msg
= gettext ( 'Connection error' ) + ' - aborted.' ;
408 } else if ( response
. timedout
) {
409 msg
= gettext ( 'Connection error' ) + ' - Timeout.' ;
410 } else if ( response
. status
&& response
. statusText
) {
411 msg
= gettext ( 'Connection error' ) + ' ' + response
. status
+ ': ' + response
. statusText
;
413 response
. htmlStatus
= msg
;
414 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
415 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
420 createWrapper ( reqOpts
. success
, reqOpts
. callback
, reqOpts
. failure
);
422 var target
= newopts
. waitMsgTarget
;
424 if ( Proxmox
. Utils
. toolkit
=== 'touch' ) {
425 target
. setMasked ({ xtype
: 'loadmask' , message
: newopts
. waitMsg
});
427 // Note: ExtJS bug - this does not work when component is not rendered
428 target
. setLoading ( newopts
. waitMsg
);
431 Ext
. Ajax
. request ( newopts
);
434 checked_command : function ( orig_cmd
) {
435 Proxmox
. Utils
. API2Request ({
436 url
: '/nodes/localhost/subscription' ,
438 failure : function ( response
, opts
) {
439 Ext
. Msg
. alert ( gettext ( 'Error' ), response
. htmlStatus
);
441 success : function ( response
, opts
) {
442 let data
= response
. result
. data
;
443 if ( data
. status
!== 'Active' ) {
445 title
: gettext ( 'No valid subscription' ),
446 icon
: Ext
. Msg
. WARNING
,
447 message
: Proxmox
. Utils
. getNoSubKeyHtml ( data
. url
),
449 callback : function ( btn
) {
463 assemble_field_data : function ( values
, data
) {
464 if (! Ext
. isObject ( data
)) {
467 Ext
. Object
. each ( data
, function ( name
, val
) {
468 if ( Object
. prototype . hasOwnProperty
. call ( values
, name
)) {
469 let bucket
= values
[ name
];
470 if (! Ext
. isArray ( bucket
)) {
471 bucket
= values
[ name
] = [ bucket
];
473 if ( Ext
. isArray ( val
)) {
474 values
[ name
] = bucket
. concat ( val
);
484 updateColumnWidth : function ( container
) {
485 let mode
= Ext
. state
. Manager
. get ( 'summarycolumns' ) || 'auto' ;
487 if ( mode
!== 'auto' ) {
488 factor
= parseInt ( mode
, 10 );
489 if ( Number
. isNaN ( factor
)) {
493 factor
= container
. getSize (). width
< 1600 ? 1 : 2 ;
496 if ( container
. oldFactor
=== factor
) {
500 let items
= container
. query ( '>' ); // direct childs
501 factor
= Math
. min ( factor
, items
. length
);
502 container
. oldFactor
= factor
;
504 items
. forEach (( item
) => {
505 item
. columnWidth
= 1 / factor
;
508 // we have to update the layout twice, since the first layout change
509 // can trigger the scrollbar which reduces the amount of space left
510 container
. updateLayout ();
511 container
. updateLayout ();
514 dialog_title : function ( subject
, create
, isAdd
) {
517 return gettext ( 'Add' ) + ': ' + subject
;
519 return gettext ( 'Create' ) + ': ' + subject
;
522 return gettext ( 'Edit' ) + ': ' + subject
;
526 network_iface_types
: {
527 eth
: gettext ( "Network Device" ),
528 bridge
: 'Linux Bridge' ,
531 OVSBridge
: 'OVS Bridge' ,
534 OVSIntPort
: 'OVS IntPort' ,
537 render_network_iface_type : function ( value
) {
538 return Proxmox
. Utils
. network_iface_types
[ value
] ||
539 Proxmox
. Utils
. unknownText
;
543 acmenewcert
: [ 'SRV' , gettext ( 'Order Certificate' )],
544 acmeregister
: [ 'ACME Account' , gettext ( 'Register' )],
545 acmedeactivate
: [ 'ACME Account' , gettext ( 'Deactivate' )],
546 acmeupdate
: [ 'ACME Account' , gettext ( 'Update' )],
547 acmerefresh
: [ 'ACME Account' , gettext ( 'Refresh' )],
548 acmerenew
: [ 'SRV' , gettext ( 'Renew Certificate' )],
549 acmerevoke
: [ 'SRV' , gettext ( 'Revoke Certificate' )],
550 'auth-realm-sync' : [ gettext ( 'Realm' ), gettext ( 'Sync' )],
551 'auth-realm-sync-test' : [ gettext ( 'Realm' ), gettext ( 'Sync Preview' )],
552 'move_volume' : [ 'CT' , gettext ( 'Move Volume' )],
553 clustercreate
: [ '' , gettext ( 'Create Cluster' )],
554 clusterjoin
: [ '' , gettext ( 'Join Cluster' )],
555 diskinit
: [ 'Disk' , gettext ( 'Initialize Disk with GPT' )],
556 vncproxy
: [ 'VM/CT' , gettext ( 'Console' )],
557 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
558 vncshell
: [ '' , gettext ( 'Shell' )],
559 spiceshell
: [ '' , gettext ( 'Shell' ) + ' (Spice)' ],
560 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' )],
561 qmrollback
: [ 'VM' , gettext ( 'Rollback' )],
562 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' )],
563 qmcreate
: [ 'VM' , gettext ( 'Create' )],
564 qmrestore
: [ 'VM' , gettext ( 'Restore' )],
565 qmdestroy
: [ 'VM' , gettext ( 'Destroy' )],
566 qmigrate
: [ 'VM' , gettext ( 'Migrate' )],
567 qmclone
: [ 'VM' , gettext ( 'Clone' )],
568 qmmove
: [ 'VM' , gettext ( 'Move disk' )],
569 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' )],
570 qmstart
: [ 'VM' , gettext ( 'Start' )],
571 qmstop
: [ 'VM' , gettext ( 'Stop' )],
572 qmreset
: [ 'VM' , gettext ( 'Reset' )],
573 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' )],
574 qmreboot
: [ 'VM' , gettext ( 'Reboot' )],
575 qmsuspend
: [ 'VM' , gettext ( 'Hibernate' )],
576 qmpause
: [ 'VM' , gettext ( 'Pause' )],
577 qmresume
: [ 'VM' , gettext ( 'Resume' )],
578 qmconfig
: [ 'VM' , gettext ( 'Configure' )],
579 vzsnapshot
: [ 'CT' , gettext ( 'Snapshot' )],
580 vzrollback
: [ 'CT' , gettext ( 'Rollback' )],
581 vzdelsnapshot
: [ 'CT' , gettext ( 'Delete Snapshot' )],
582 vzcreate
: [ 'CT' , gettext ( 'Create' )],
583 vzrestore
: [ 'CT' , gettext ( 'Restore' )],
584 vzdestroy
: [ 'CT' , gettext ( 'Destroy' )],
585 vzmigrate
: [ 'CT' , gettext ( 'Migrate' )],
586 vzclone
: [ 'CT' , gettext ( 'Clone' )],
587 vztemplate
: [ 'CT' , gettext ( 'Convert to template' )],
588 vzstart
: [ 'CT' , gettext ( 'Start' )],
589 vzstop
: [ 'CT' , gettext ( 'Stop' )],
590 vzmount
: [ 'CT' , gettext ( 'Mount' )],
591 vzumount
: [ 'CT' , gettext ( 'Unmount' )],
592 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' )],
593 vzreboot
: [ 'CT' , gettext ( 'Reboot' )],
594 vzsuspend
: [ 'CT' , gettext ( 'Suspend' )],
595 vzresume
: [ 'CT' , gettext ( 'Resume' )],
596 push_file
: [ 'CT' , gettext ( 'Push file' )],
597 pull_file
: [ 'CT' , gettext ( 'Pull file' )],
598 hamigrate
: [ 'HA' , gettext ( 'Migrate' )],
599 hastart
: [ 'HA' , gettext ( 'Start' )],
600 hastop
: [ 'HA' , gettext ( 'Stop' )],
601 hashutdown
: [ 'HA' , gettext ( 'Shutdown' )],
602 srvstart
: [ 'SRV' , gettext ( 'Start' )],
603 srvstop
: [ 'SRV' , gettext ( 'Stop' )],
604 srvrestart
: [ 'SRV' , gettext ( 'Restart' )],
605 srvreload
: [ 'SRV' , gettext ( 'Reload' )],
606 cephcreatemgr
: [ 'Ceph Manager' , gettext ( 'Create' )],
607 cephdestroymgr
: [ 'Ceph Manager' , gettext ( 'Destroy' )],
608 cephcreatemon
: [ 'Ceph Monitor' , gettext ( 'Create' )],
609 cephdestroymon
: [ 'Ceph Monitor' , gettext ( 'Destroy' )],
610 cephcreateosd
: [ 'Ceph OSD' , gettext ( 'Create' )],
611 cephdestroyosd
: [ 'Ceph OSD' , gettext ( 'Destroy' )],
612 cephcreatepool
: [ 'Ceph Pool' , gettext ( 'Create' )],
613 cephdestroypool
: [ 'Ceph Pool' , gettext ( 'Destroy' )],
614 cephfscreate
: [ 'CephFS' , gettext ( 'Create' )],
615 cephcreatemds
: [ 'Ceph Metadata Server' , gettext ( 'Create' )],
616 cephdestroymds
: [ 'Ceph Metadata Server' , gettext ( 'Destroy' )],
617 imgcopy
: [ '' , gettext ( 'Copy data' )],
618 imgdel
: [ '' , gettext ( 'Erase data' )],
619 unknownimgdel
: [ '' , gettext ( 'Destroy image from unknown guest' )],
620 download
: [ '' , gettext ( 'Download' )],
621 vzdump
: ( type
, id
) => id
? `VM/CT ${id} - ${gettext('Backup')} ` : gettext ( 'Backup Job' ),
622 aptupdate
: [ '' , gettext ( 'Update package database' )],
623 startall
: [ '' , gettext ( 'Start all VMs and Containers' )],
624 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' )],
625 migrateall
: [ '' , gettext ( 'Migrate all VMs and Containers' )],
626 dircreate
: [ gettext ( 'Directory Storage' ), gettext ( 'Create' )],
627 lvmcreate
: [ gettext ( 'LVM Storage' ), gettext ( 'Create' )],
628 lvmthincreate
: [ gettext ( 'LVM-Thin Storage' ), gettext ( 'Create' )],
629 zfscreate
: [ gettext ( 'ZFS Storage' ), gettext ( 'Create' )],
632 // to add or change existing for product specific ones
633 override_task_descriptions : function ( extra
) {
634 for ( const [ key
, value
] of Object
. entries ( extra
)) {
635 Proxmox
. Utils
. task_desc_table
[ key
] = value
;
639 format_task_description : function ( type
, id
) {
640 let farray
= Proxmox
. Utils
. task_desc_table
[ type
];
648 } else if ( Ext
. isFunction ( farray
)) {
649 return farray ( type
, id
);
651 let prefix
= farray
[ 0 ];
653 if ( prefix
&& id
!== undefined ) {
654 return prefix
+ ' ' + id
+ ' - ' + text
;
659 format_size : function ( size
) {
660 /*jslint confusion: true */
662 var units
= [ '' , 'Ki' , 'Mi' , 'Gi' , 'Ti' , 'Pi' , 'Ei' , 'Zi' , 'Yi' ];
665 while ( size
>= 1024 && num
++ <= units
. length
) {
669 return size
. toFixed ( num
> 0 ? 2 : 0 ) + " " + units
[ num
] + "B" ;
672 render_upid : function ( value
, metaData
, record
) {
673 let task
= record
. data
;
674 let type
= task
. type
|| task
. worker_type
;
675 let id
= task
. id
|| task
. worker_id
;
677 return Proxmox
. Utils
. format_task_description ( type
, id
);
680 render_uptime : function ( value
) {
683 if ( uptime
=== undefined ) {
691 return Proxmox
. Utils
. format_duration_long ( uptime
);
694 parse_task_upid : function ( upid
) {
697 var res
= upid
. match ( /^UPID:([^\s:]+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8,9}):(([0-9A-Fa-f]{8,16}):)?([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/ );
699 throw "unable to parse upid '" + upid
+ "'" ;
702 task
. pid
= parseInt ( res
[ 2 ], 16 );
703 task
. pstart
= parseInt ( res
[ 3 ], 16 );
704 if ( res
[ 5 ] !== undefined ) {
705 task
. task_id
= parseInt ( res
[ 5 ], 16 );
707 task
. starttime
= parseInt ( res
[ 6 ], 16 );
712 task
. desc
= Proxmox
. Utils
. format_task_description ( task
. type
, task
. id
);
717 render_duration : function ( value
) {
718 if ( value
=== undefined ) {
721 return Proxmox
. Utils
. format_duration_human ( value
);
724 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
725 var servertime
= new Date ( value
* 1000 );
726 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
729 get_help_info : function ( section
) {
731 if ( typeof proxmoxOnlineHelpInfo
!== 'undefined' ) {
732 helpMap
= proxmoxOnlineHelpInfo
; // eslint-disable-line no-undef
733 } else if ( typeof pveOnlineHelpInfo
!== 'undefined' ) {
734 // be backward compatible with older pve-doc-generators
735 helpMap
= pveOnlineHelpInfo
; // eslint-disable-line no-undef
737 throw "no global OnlineHelpInfo map declared" ;
740 return helpMap
[ section
];
743 get_help_link : function ( section
) {
744 var info
= Proxmox
. Utils
. get_help_info ( section
);
748 return window
. location
. origin
+ info
. link
;
751 openXtermJsViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
752 var url
= Ext
. Object
. toQueryString ({
753 console
: vmtype
, // kvm, lxc, upgrade or shell
761 var nw
= window
. open ( "?" + url
, '_blank' , 'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=800,height=420' );
770 constructor : function () {
772 Ext
. apply ( me
, me
. utilities
);
774 var IPV4_OCTET
= "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])" ;
775 var IPV4_REGEXP
= "(?:(?:" + IPV4_OCTET
+ " \\ .){3}" + IPV4_OCTET
+ ")" ;
776 var IPV6_H16
= "(?:[0-9a-fA-F]{1,4})" ;
777 var IPV6_LS32
= "(?:(?:" + IPV6_H16
+ ":" + IPV6_H16
+ ")|" + IPV4_REGEXP
+ ")" ;
778 var IPV4_CIDR_MASK
= "([0-9]{1,2})" ;
779 var IPV6_CIDR_MASK
= "([0-9]{1,3})" ;
782 me
. IP4_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")$" );
783 me
. IP4_cidr_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")/" + IPV4_CIDR_MASK
+ "$" );
785 /* eslint-disable no-useless-concat,no-multi-spaces */
786 var IPV6_REGEXP
= "(?:" +
787 "(?:(?:" + "(?:" + IPV6_H16
+ ":){6})" + IPV6_LS32
+ ")|" +
788 "(?:(?:" + "::" + "(?:" + IPV6_H16
+ ":){5})" + IPV6_LS32
+ ")|" +
789 "(?:(?:(?:" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){4})" + IPV6_LS32
+ ")|" +
790 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,1}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){3})" + IPV6_LS32
+ ")|" +
791 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,2}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){2})" + IPV6_LS32
+ ")|" +
792 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,3}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){1})" + IPV6_LS32
+ ")|" +
793 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,4}" + IPV6_H16
+ ")?::" + ")" + IPV6_LS32
+ ")|" +
794 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,5}" + IPV6_H16
+ ")?::" + ")" + IPV6_H16
+ ")|" +
795 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,7}" + IPV6_H16
+ ")?::" + ")" + ")" +
797 /* eslint-enable no-useless-concat,no-multi-spaces */
799 me
. IP6_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")$" );
800 me
. IP6_cidr_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")/" + IPV6_CIDR_MASK
+ "$" );
801 me
. IP6_bracket_match
= new RegExp ( "^ \\ [(" + IPV6_REGEXP
+ ") \\ ]" );
803 me
. IP64_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ ")$" );
804 me
. IP64_cidr_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ "/" + IPV6_CIDR_MASK
+ ")|(?:" + IPV4_REGEXP
+ "/" + IPV4_CIDR_MASK
+ ")$" );
806 var DnsName_REGEXP
= "(?:(([a-zA-Z0-9]([a-zA-Z0-9 \\ -]*[a-zA-Z0-9])?) \\ .)*([A-Za-z0-9]([A-Za-z0-9 \\ -]*[A-Za-z0-9])?))" ;
807 me
. DnsName_match
= new RegExp ( "^" + DnsName_REGEXP
+ "$" );
809 me
. HostPort_match
= new RegExp ( "^(" + IPV4_REGEXP
+ "|" + DnsName_REGEXP
+ ")(: \\ d+)?$" );
810 me
. HostPortBrackets_match
= new RegExp ( "^ \\ [(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ "|" + DnsName_REGEXP
+ ") \\ ](: \\ d+)?$" );
811 me
. IP6_dotnotation_match
= new RegExp ( "^" + IPV6_REGEXP
+ "( \\ . \\ d+)?$" );
812 me
. Vlan_match
= /^vlan(\\d+)/ ;
813 me
. VlanInterface_match
= /(\\w+)\\.(\\d+)/ ;