]>
git.proxmox.com Git - proxmox-backup.git/blob - www/Utils.js
3 console
. log ( "Starting Backup Server GUI" );
5 Ext
. define ( 'PBS.Utils' , {
8 updateLoginData : function ( data
) {
9 Proxmox
. Utils
. setAuthData ( data
);
12 dataStorePrefix
: 'DataStore-' ,
35 calculateCryptMode : function ( data
) {
36 let mixed
= data
. mixed
;
37 let encrypted
= data
. encrypt
;
38 let signed
= data
[ 'sign-only' ];
39 let files
= data
. count
;
41 return PBS
. Utils
. cryptmap
. indexOf ( 'mixed' );
42 } else if ( files
=== encrypted
&& encrypted
> 0 ) {
43 return PBS
. Utils
. cryptmap
. indexOf ( 'encrypt' );
44 } else if ( files
=== signed
&& signed
> 0 ) {
45 return PBS
. Utils
. cryptmap
. indexOf ( 'sign-only' );
46 } else if (( signed
+ encrypted
) === 0 ) {
47 return PBS
. Utils
. cryptmap
. indexOf ( 'none' );
49 return PBS
. Utils
. cryptmap
. indexOf ( 'mixed' );
53 noSubKeyHtml
: 'You do not have a valid subscription for this server. Please visit <a target="_blank" href="https://www.proxmox.com/proxmox-backup-server/pricing">www.proxmox.com</a> to get a list of available options.' ,
55 getDataStoreFromPath : function ( path
) {
56 return path
. slice ( PBS
. Utils
. dataStorePrefix
. length
);
59 isDataStorePath : function ( path
) {
60 return path
. indexOf ( PBS
. Utils
. dataStorePrefix
) === 0 ;
63 parsePropertyString : function ( value
, defaultKey
) {
67 if ( typeof value
!== 'string' || value
=== '' ) {
71 Ext
. Array
. each ( value
. split ( ',' ), function ( p
) {
72 var kv
= p
. split ( '=' , 2 );
73 if ( Ext
. isDefined ( kv
[ 1 ])) {
75 } else if ( Ext
. isDefined ( defaultKey
)) {
76 if ( Ext
. isDefined ( res
[ defaultKey
])) {
77 error
= 'defaultKey may be only defined once in propertyString' ;
78 return false ; // break
80 res
[ defaultKey
] = kv
[ 0 ];
82 error
= 'invalid propertyString, not a key=value pair and no defaultKey defined' ;
83 return false ; // break
88 if ( error
!== undefined ) {
96 printPropertyString : function ( data
, defaultKey
) {
98 gotDefaultKeyVal
= false ,
101 Ext
. Object
. each ( data
, function ( key
, value
) {
102 if ( defaultKey
!== undefined && key
=== defaultKey
) {
103 gotDefaultKeyVal
= true ;
104 defaultKeyVal
= value
;
105 } else if ( value
!== '' && value
!== undefined ) {
106 stringparts
. push ( key
+ '=' + value
);
110 stringparts
= stringparts
. sort ();
111 if ( gotDefaultKeyVal
) {
112 stringparts
. unshift ( defaultKeyVal
);
115 return stringparts
. join ( ',' );
118 // helper for deleting field which are set to there default values
119 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
120 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
123 if ( Ext
. isArray ( values
. delete )) {
124 values
. delete . push ( fieldname
);
126 values
. delete += ',' + fieldname
;
129 values
. delete = [ fieldname
];
133 delete values
[ fieldname
];
138 render_datetime_utc : function ( datetime
) {
139 let pad
= ( number
) => number
< 10 ? '0' + number
: number
;
140 return datetime
. getUTCFullYear () +
141 '-' + pad ( datetime
. getUTCMonth () + 1 ) +
142 '-' + pad ( datetime
. getUTCDate ()) +
143 'T' + pad ( datetime
. getUTCHours ()) +
144 ':' + pad ( datetime
. getUTCMinutes ()) +
145 ':' + pad ( datetime
. getUTCSeconds ()) +
149 render_datastore_worker_id : function ( id
, what
) {
150 const res
= id
. match ( /^(\S+?):(\S+?)\/(\S+?)(\/(.+))?$/ );
152 let datastore
= res
[ 1 ], backupGroup
= ` ${res[2]} / ${res[3]} ` ;
153 if ( res
[ 4 ] !== undefined ) {
154 let datetime
= Ext
. Date
. parse ( parseInt ( res
[ 5 ], 16 ), 'U' );
155 let utctime
= PBS
. Utils
. render_datetime_utc ( datetime
);
156 return `Datastore ${datastore} ${what} ${backupGroup} / ${utctime} ` ;
158 return `Datastore ${datastore} ${what} ${backupGroup} ` ;
161 return `Datastore ${what} ${id} ` ;
164 // mimics Display trait in backend
165 renderKeyID : function ( fingerprint
) {
166 return fingerprint
. substring ( 0 , 23 );
169 parse_datastore_worker_id : function ( type
, id
) {
172 if ( type
. startsWith ( 'verif' )) {
173 res
= PBS
. Utils
. VERIFICATION_JOB_ID_RE
. exec ( id
);
177 } else if ( type
. startsWith ( 'sync' )) {
178 res
= PBS
. Utils
. SYNC_JOB_ID_RE
. exec ( id
);
182 } else if ( type
=== 'backup' ) {
183 res
= PBS
. Utils
. BACKUP_JOB_ID_RE
. exec ( id
);
187 } else if ( type
=== 'garbage_collection' ) {
189 } else if ( type
=== 'prune' ) {
197 extractTokenUser : function ( tokenid
) {
198 return tokenid
. match ( /^(.+)!([^!]+)$/ )[ 1 ];
201 extractTokenName : function ( tokenid
) {
202 return tokenid
. match ( /^(.+)!([^!]+)$/ )[ 2 ];
205 render_estimate : function ( value
) {
207 return gettext ( 'Not enough data' );
210 let now
= new Date ();
211 let estimate
= new Date ( value
* 1000 );
213 let timespan
= ( estimate
- now
)/ 1000 ;
215 if ( Number ( estimate
) <= Number ( now
) || isNaN ( timespan
)) {
216 return gettext ( 'Never' );
219 let duration
= Proxmox
. Utils
. format_duration_human ( timespan
);
220 return Ext
. String
. format ( gettext ( "in {0}" ), duration
);
223 render_size_usage : function ( val
, max
) {
225 return gettext ( 'N/A' );
227 return ( val
* 100 / max
). toFixed ( 2 ) + '% (' +
228 Ext
. String
. format ( gettext ( '{0} of {1}' ),
229 Proxmox
. Utils
. format_size ( val
), Proxmox
. Utils
. format_size ( max
)) + ')' ;
232 get_help_tool : function ( blockid
) {
233 let info
= Proxmox
. Utils
. get_help_info ( blockid
);
234 if ( info
=== undefined ) {
235 info
= Proxmox
. Utils
. get_help_info ( 'pbs_documentation_index' );
237 if ( info
=== undefined ) {
238 throw "get_help_info failed" ; // should not happen
241 let docsURI
= window
. location
. origin
+ info
. link
;
242 let title
= info
. title
;
244 title
+= ' - ' + info
. subtitle
;
249 handler : function () {
250 window
. open ( docsURI
);
255 calculate_dedup_factor : function ( gcstatus
) {
257 if ( gcstatus
[ 'disk-bytes' ] > 0 ) {
258 dedup
= ( gcstatus
[ 'index-data-bytes' ] || 0 )/ gcstatus
[ 'disk-bytes' ];
263 constructor : function () {
266 let PROXMOX_SAFE_ID_REGEX
= "([A-Za-z0-9_][A-Za-z0-9._-]*)" ;
267 // only anchored at beginning
268 // only parses datastore for now
269 me
. VERIFICATION_JOB_ID_RE
= new RegExp ( "^" + PROXMOX_SAFE_ID_REGEX
+ ':?' );
270 me
. SYNC_JOB_ID_RE
= new RegExp ( "^" + PROXMOX_SAFE_ID_REGEX
+ ':' +
271 PROXMOX_SAFE_ID_REGEX
+ ':' + PROXMOX_SAFE_ID_REGEX
+ ':' );
272 me
. BACKUP_JOB_ID_RE
= new RegExp ( "^" + PROXMOX_SAFE_ID_REGEX
+ ':' );
274 // do whatever you want here
275 Proxmox
. Utils
. override_task_descriptions ({
276 backup
: ( type
, id
) => PBS
. Utils
. render_datastore_worker_id ( id
, gettext ( 'Backup' )),
277 dircreate
: [ gettext ( 'Directory Storage' ), gettext ( 'Create' )],
278 dirremove
: [ gettext ( 'Directory' ), gettext ( 'Remove' )],
279 garbage_collection
: [ 'Datastore' , gettext ( 'Garbage collect' )],
280 logrotate
: [ null , gettext ( 'Log Rotation' )],
281 prune
: ( type
, id
) => PBS
. Utils
. render_datastore_worker_id ( id
, gettext ( 'Prune' )),
282 reader
: ( type
, id
) => PBS
. Utils
. render_datastore_worker_id ( id
, gettext ( 'Read objects' )),
283 sync
: [ 'Datastore' , gettext ( 'Remote Sync' )],
284 syncjob
: [ gettext ( 'Sync Job' ), gettext ( 'Remote Sync' )],
285 verify
: [ 'Datastore' , gettext ( 'Verification' )],
286 verify_group
: [ 'Group' , gettext ( 'Verification' )],
287 verify_snapshot
: [ 'Snapshot' , gettext ( 'Verification' )],
288 verificationjob
: [ gettext ( 'Verify Job' ), gettext ( 'Scheduled Verification' )],
289 zfscreate
: [ gettext ( 'ZFS Storage' ), gettext ( 'Create' )],