ui: adapt for new sign-only crypt mode

we can now show 'none', 'encprypted', 'signed' or 'mixed' for
the crypt mode

also adds a different icon for signed files, and adds a hint that
signatures cannot be verified on the server

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-07-08 13:32:20 +02:00 committed by Dietmar Maurer
parent 4459ffe30e
commit 2774566b03
3 changed files with 78 additions and 37 deletions

View File

@ -12,26 +12,28 @@ Ext.define('pbs-data-store-snapshots', {
'owner', 'owner',
{ name: 'size', type: 'int', allowNull: true, }, { name: 'size', type: 'int', allowNull: true, },
{ {
name: 'encrypted', name: 'crypt-mode',
type: 'boolean', type: 'boolean',
calculate: function(data) { calculate: function(data) {
let encrypted = 0; let encrypted = 0;
let crypt = {
none: 0,
mixed: 0,
'sign-only': 0,
encrypt: 0,
};
let signed = 0;
let files = 0; let files = 0;
data.files.forEach(file => { data.files.forEach(file => {
if (file.filename === 'index.json.blob') return; // is never encrypted if (file.filename === 'index.json.blob') return; // is never encrypted
if (file.encrypted) { let mode = PBS.Utils.cryptmap.indexOf(file['crypt-mode']);
encrypted++; if (mode !== -1) {
crypt[file['crypt-mode']]++;
} }
files++; files++;
}); });
if (encrypted === 0) { return PBS.Utils.calculateCryptMode(crypt['sign-only'], crypt.encrypt, files);
return 0;
} else if (encrypted < files) {
return 1;
} else {
return 2;
}
} }
} }
] ]
@ -149,11 +151,14 @@ Ext.define('PBS.DataStoreContent', {
let children = []; let children = [];
for (const [_key, group] of Object.entries(groups)) { for (const [_key, group] of Object.entries(groups)) {
let last_backup = 0; let last_backup = 0;
let encrypted = 0; let crypt = {
none: 0,
mixed: 0,
'sign-only': 0,
encrypt: 0
};
for (const item of group.children) { for (const item of group.children) {
if (item.encrypted > 0) { crypt[PBS.Utils.cryptmap[item['crypt-mode']]]++;
encrypted++;
}
if (item["backup-time"] > last_backup && item.size !== null) { if (item["backup-time"] > last_backup && item.size !== null) {
last_backup = item["backup-time"]; last_backup = item["backup-time"];
group["backup-time"] = last_backup; group["backup-time"] = last_backup;
@ -163,14 +168,8 @@ Ext.define('PBS.DataStoreContent', {
} }
} }
if (encrypted === 0) {
group.encrypted = 0;
} else if (encrypted < group.children.length) {
group.encrypted = 1;
} else {
group.encrypted = 2;
}
group.count = group.children.length; group.count = group.children.length;
group['crypt-mode'] = PBS.Utils.calculateCryptMode(crypt['sign-only'], crypt.encrypt, group.count);
children.push(group); children.push(group);
} }
@ -296,7 +295,7 @@ Ext.define('PBS.DataStoreContent', {
let encrypted = false; let encrypted = false;
data.files.forEach(file => { data.files.forEach(file => {
if (file.filename === 'catalog.pcat1.didx' && file.encrypted) { if (file.filename === 'catalog.pcat1.didx' && file['crypt-mode'] === 'encrypt') {
encrypted = true; encrypted = true;
} }
}); });
@ -365,15 +364,8 @@ Ext.define('PBS.DataStoreContent', {
}, },
{ {
header: gettext('Encrypted'), header: gettext('Encrypted'),
dataIndex: 'encrypted', dataIndex: 'crypt-mode',
renderer: function(value) { renderer: value => PBS.Utils.cryptText[value] || Proxmox.Utils.unknownText,
switch (value) {
case 0: return Proxmox.Utils.noText;
case 1: return gettext('Mixed');
case 2: return Proxmox.Utils.yesText;
default: Proxmox.Utils.unknownText;
}
}
}, },
{ {
header: gettext("Files"), header: gettext("Files"),
@ -383,8 +375,10 @@ Ext.define('PBS.DataStoreContent', {
return files.map((file) => { return files.map((file) => {
let icon = ''; let icon = '';
let size = ''; let size = '';
if (file.encrypted) { let mode = PBS.Utils.cryptmap.indexOf(file['crypt-mode']);
icon = '<i class="fa fa-lock"></i> '; let iconCls = PBS.Utils.cryptIconCls[mode] || '';
if (iconCls !== '') {
icon = `<i class="fa fa-${iconCls}"></i> `;
} }
if (file.size) { if (file.size) {
size = ` (${Proxmox.Utils.format_size(file.size)})`; size = ` (${Proxmox.Utils.format_size(file.size)})`;

View File

@ -13,6 +13,39 @@ Ext.define('PBS.Utils', {
dataStorePrefix: 'DataStore-', dataStorePrefix: 'DataStore-',
cryptmap: [
'none',
'mixed',
'sign-only',
'encrypt',
],
cryptText: [
Proxmox.Utils.noText,
gettext('Mixed'),
gettext('Signed'),
gettext('Encrypted'),
],
cryptIconCls: [
'',
'',
'certificate',
'lock',
],
calculateCryptMode: function(signed, encrypted, files) {
if (files === encrypted) {
return PBS.Utils.cryptmap.indexOf('encrypt');
} else if (files === signed) {
return PBS.Utils.cryptmap.indexOf('sign-only');
} else if ((signed+encrypted) === 0) {
return PBS.Utils.cryptmap.indexOf('none');
} else {
return PBS.Utils.cryptmap.indexOf('mixed');
}
},
getDataStoreFromPath: function(path) { getDataStoreFromPath: function(path) {
return path.slice(PBS.Utils.dataStorePrefix.length); return path.slice(PBS.Utils.dataStorePrefix.length);
}, },

View File

@ -46,8 +46,9 @@ Ext.define('PBS.window.BackupFileDownloader', {
let me = this; let me = this;
let combo = me.lookup('file'); let combo = me.lookup('file');
let rec = combo.getStore().findRecord('filename', value, 0, false, true, true); let rec = combo.getStore().findRecord('filename', value, 0, false, true, true);
let canDownload = !rec.data.encrypted; let canDownload = rec.data['crypt-mode'] !== 'encrypt';
me.lookup('encryptedHint').setVisible(!canDownload); me.lookup('encryptedHint').setVisible(!canDownload);
me.lookup('signedHint').setVisible(rec.data['crypt-mode'] === 'sign-only');
me.lookup('downloadBtn').setDisabled(!canDownload); me.lookup('downloadBtn').setDisabled(!canDownload);
}, },
@ -88,7 +89,7 @@ Ext.define('PBS.window.BackupFileDownloader', {
emptyText: gettext('No file selected'), emptyText: gettext('No file selected'),
fieldLabel: gettext('File'), fieldLabel: gettext('File'),
store: { store: {
fields: ['filename', 'size', 'encrypted',], fields: ['filename', 'size', 'crypt-mode',],
idProperty: ['filename'], idProperty: ['filename'],
}, },
listConfig: { listConfig: {
@ -107,12 +108,25 @@ Ext.define('PBS.window.BackupFileDownloader', {
}, },
{ {
text: gettext('Encrypted'), text: gettext('Encrypted'),
dataIndex: 'encrypted', dataIndex: 'crypt-mode',
renderer: Proxmox.Utils.format_boolean, renderer: function(value) {
let mode = -1;
if (value !== undefined) {
mode = PBS.Utils.cryptmap.indexOf(value);
}
return PBS.Utils.cryptText[mode] || Proxmox.Utils.unknownText;
}
}, },
], ],
}, },
}, },
{
xtype: 'displayfield',
userCls: 'pmx-hint',
reference: 'signedHint',
hidden: true,
value: gettext('Note: Signatures of signed files will not be verified on the server. Please use the client to do this.'),
},
{ {
xtype: 'displayfield', xtype: 'displayfield',
userCls: 'pmx-hint', userCls: 'pmx-hint',