]> git.proxmox.com Git - proxmox-backup.git/blob - www/Utils.js
ui: fix crypt mode caluclation
[proxmox-backup.git] / www / Utils.js
1 /*global Proxmox */
2 Ext.ns('PBS');
3
4 console.log("Starting Backup Server GUI");
5
6 Ext.define('PBS.Utils', {
7 singleton: true,
8
9 updateLoginData: function(data) {
10
11 Proxmox.Utils.setAuthData(data);
12 },
13
14 dataStorePrefix: 'DataStore-',
15
16 cryptmap: [
17 'none',
18 'mixed',
19 'sign-only',
20 'encrypt',
21 ],
22
23 cryptText: [
24 Proxmox.Utils.noText,
25 gettext('Mixed'),
26 gettext('Signed'),
27 gettext('Encrypted'),
28 ],
29
30 cryptIconCls: [
31 '',
32 '',
33 'certificate',
34 'lock',
35 ],
36
37 calculateCryptMode: function(data) {
38 let mixed = data.mixed;
39 let encrypted = data.encrypt;
40 let signed = data['sign-only'];
41 let files = data.count;
42 if (mixed > 0) {
43 return PBS.Utils.cryptmap.indexOf('mixed');
44 } else if (files === encrypted) {
45 return PBS.Utils.cryptmap.indexOf('encrypt');
46 } else if (files === signed) {
47 return PBS.Utils.cryptmap.indexOf('sign-only');
48 } else if ((signed+encrypted) === 0) {
49 return PBS.Utils.cryptmap.indexOf('none');
50 } else {
51 return PBS.Utils.cryptmap.indexOf('mixed');
52 }
53 },
54
55 getDataStoreFromPath: function(path) {
56 return path.slice(PBS.Utils.dataStorePrefix.length);
57 },
58
59 isDataStorePath: function(path) {
60 return path.indexOf(PBS.Utils.dataStorePrefix) === 0;
61 },
62
63 render_datetime_utc: function(datetime) {
64 let pad = (number) => number < 10 ? '0' + number : number;
65 return datetime.getUTCFullYear() +
66 '-' + pad(datetime.getUTCMonth() + 1) +
67 '-' + pad(datetime.getUTCDate()) +
68 'T' + pad(datetime.getUTCHours()) +
69 ':' + pad(datetime.getUTCMinutes()) +
70 ':' + pad(datetime.getUTCSeconds()) +
71 'Z';
72 },
73
74 render_datastore_worker_id: function(id, what) {
75 const res = id.match(/^(\S+?)_(\S+?)_(\S+?)(_(.+))?$/);
76 if (res) {
77 let datastore = res[1], type = res[2], id = res[3];
78 if (res[4] !== undefined) {
79 let datetime = Ext.Date.parse(parseInt(res[5], 16), 'U');
80 let utctime = PBS.Utils.render_datetime_utc(datetime);
81 return `Datastore ${datastore} ${what} ${type}/${id}/${utctime}`;
82 } else {
83 return `Datastore ${datastore} ${what} ${type}/${id}`;
84 }
85 }
86 return `Datastore ${what} ${id}`;
87 },
88
89 constructor: function() {
90 var me = this;
91
92 // do whatever you want here
93 Proxmox.Utils.override_task_descriptions({
94 garbage_collection: ['Datastore', gettext('Garbage collect') ],
95 sync: ['Datastore', gettext('Remote Sync') ],
96 syncjob: [gettext('Sync Job'), gettext('Remote Sync') ],
97 prune: (type, id) => {
98 return PBS.Utils.render_datastore_worker_id(id, gettext('Prune'));
99 },
100 verify: (type, id) => {
101 return PBS.Utils.render_datastore_worker_id(id, gettext('Verify'));
102 },
103 backup: (type, id) => {
104 return PBS.Utils.render_datastore_worker_id(id, gettext('Backup'));
105 },
106 reader: (type, id) => {
107 return PBS.Utils.render_datastore_worker_id(id, gettext('Read objects'));
108 },
109 });
110 }
111 });