diff --git a/dashboard/src/utils.js b/dashboard/src/utils.js index 22114f112..040c3a800 100644 --- a/dashboard/src/utils.js +++ b/dashboard/src/utils.js @@ -75,7 +75,9 @@ function eventlogDetails(eventLog, app = null, appIdContext = '') { const ACTION_BACKUP_CLEANUP_START = 'backup.cleanup.start'; const ACTION_BACKUP_CLEANUP_FINISH = 'backup.cleanup.finish'; - const ACTION_BACKUPTARGET_ADD = 'backuptarget.add'; + const ACTION_BACKUP_SITE_ADD = 'backupsite.add'; + const ACTION_BACKUP_SITE_REMOVE = 'backupsite.remove'; + const ACTION_BACKUP_SITE_UPDATE = 'backupsite.update'; const ACTION_BRANDING_AVATAR = 'branding.avatar'; const ACTION_BRANDING_NAME = 'branding.name'; @@ -316,11 +318,11 @@ function eventlogDetails(eventLog, app = null, appIdContext = '') { return 'Backup ' + data.backupId + ' deleted from archive'; case ACTION_BACKUP_START: - return 'Backup started'; + return `Backup started at ${data.siteName}`; case ACTION_BACKUP_FINISH: - if (!errorMessage) return 'Cloudron backup created at ' + data.remotePath; - else return 'Cloudron backup errored with error: ' + errorMessage; + if (!errorMessage) return `Cloudron backup created at site ${data.siteName} . Path(s): ${JSON.stringify(data.result)}`; + else return `Cloudron backup at site ${data.siteName} errored with error: ${errorMessage}`; case ACTION_BACKUP_CLEANUP_START: return 'Backup cleaner started'; @@ -328,8 +330,30 @@ function eventlogDetails(eventLog, app = null, appIdContext = '') { case ACTION_BACKUP_CLEANUP_FINISH: return data.errorMessage ? 'Backup cleaner errored: ' + data.errorMessage : 'Backup cleaner removed ' + (data.removedBoxBackupPaths ? data.removedBoxBackupPaths.length : '0') + ' backups'; - case ACTION_BACKUPTARGET_ADD: - return `New backup ${data.name} site added`; + case ACTION_BACKUP_SITE_ADD: + return `New backup site ${data.name} added with provider ${data.provider} and format ${data.format}`; + + case ACTION_BACKUP_SITE_UPDATE: + if (data.schedule) { + return `Backup site ${data.name} schedule was updated to ${data.schedule}`; + } else if (data.limits) { + return `Backup site ${data.name} limits were updated`; + } else if (data.retention) { + return `Backup site ${data.name} retention was updated`; + } else if (data.contents) { + return `Backup site ${data.name} contents were updated`; + } else if (data.encryption) { + return `Backup site ${data.name} encryption was ${data.encryption ? 'enabled' : 'disabled'}`; + } else if (data.config) { + return `Backup site ${data.name} credentials were updated`; + } else if (data.oldName) { + return `Backup site was renamed from ${data.oldName} to ${data.name}`; + } else { + return `Backup site ${data.name} was updated`; + } + + case ACTION_BACKUP_SITE_REMOVE: + return `Backup site ${data.name} removed`; case ACTION_BRANDING_AVATAR: return 'Cloudron Avatar Changed'; diff --git a/src/backupsites.js b/src/backupsites.js index fcaafc98d..2c0611275 100644 --- a/src/backupsites.js +++ b/src/backupsites.js @@ -262,7 +262,7 @@ async function setSchedule(backupSite, schedule, auditSource) { await update(backupSite, { schedule }); await cron.handleBackupScheduleChanged(Object.assign({}, backupSite, { schedule })); - await eventlog.add(eventlog.ACTION_BACKUP_TARGET_UPDATE, auditSource, { backupSite: removePrivateFields(backupSite), schedule }); + await eventlog.add(eventlog.ACTION_BACKUP_SITE_UPDATE, auditSource, { name: backupSite.name, schedule }); } async function setLimits(backupSite, limits, auditSource) { @@ -271,7 +271,7 @@ async function setLimits(backupSite, limits, auditSource) { assert.strictEqual(typeof auditSource, 'object'); await update(backupSite, { limits }); - await eventlog.add(eventlog.ACTION_BACKUP_TARGET_UPDATE, auditSource, { backupSite: removePrivateFields(backupSite), limits }); + await eventlog.add(eventlog.ACTION_BACKUP_SITE_UPDATE, auditSource, { name: backupSite.name, limits }); } async function setRetention(backupSite, retention, auditSource) { @@ -283,7 +283,7 @@ async function setRetention(backupSite, retention, auditSource) { if (error) throw error; await update(backupSite, { retention }); - await eventlog.add(eventlog.ACTION_BACKUP_TARGET_UPDATE, auditSource, { backupSite: removePrivateFields(backupSite), retention }); + await eventlog.add(eventlog.ACTION_BACKUP_SITE_UPDATE, auditSource, { name: backupSite.name, retention }); } async function setEnabledForUpdates(backupSite, enableForUpdates, auditSource) { @@ -292,7 +292,7 @@ async function setEnabledForUpdates(backupSite, enableForUpdates, auditSource) { assert.strictEqual(typeof auditSource, 'object'); await update(backupSite, { enableForUpdates }); - await eventlog.add(eventlog.ACTION_BACKUP_TARGET_UPDATE, auditSource, { backupSite: removePrivateFields(backupSite), enableForUpdates }); + await eventlog.add(eventlog.ACTION_BACKUP_SITE_UPDATE, auditSource, { name: backupSite.name, enableForUpdates }); } async function setEncryption(backupSite, data, auditSource) { @@ -319,7 +319,7 @@ async function setEncryption(backupSite, data, auditSource) { if (error) throw error; if (result[1].affectedRows !== 1) throw new BoxError(BoxError.NOT_FOUND, 'Target not found'); - await eventlog.add(eventlog.ACTION_BACKUP_TARGET_UPDATE, auditSource, { backupSite: removePrivateFields(backupSite), encryption: !!encryption }); + await eventlog.add(eventlog.ACTION_BACKUP_SITE_UPDATE, auditSource, { name: backupSite.name, encryption: !!encryption }); } async function setName(backupSite, name, auditSource) { @@ -331,7 +331,7 @@ async function setName(backupSite, name, auditSource) { if (nameError) throw nameError; await update(backupSite, { name }); - await eventlog.add(eventlog.ACTION_BACKUP_TARGET_UPDATE, auditSource, { backupSite: removePrivateFields(backupSite), name }); + await eventlog.add(eventlog.ACTION_BACKUP_SITE_UPDATE, auditSource, { name, oldName: backupSite.name }); } async function setContents(backupSite, contents, auditSource) { @@ -343,7 +343,7 @@ async function setContents(backupSite, contents, auditSource) { if (contentsError) throw contentsError; await update(backupSite, { contents }); - await eventlog.add(eventlog.ACTION_BACKUP_TARGET_UPDATE, auditSource, { backupSite: removePrivateFields(backupSite), contents }); + await eventlog.add(eventlog.ACTION_BACKUP_SITE_UPDATE, auditSource, { name: backupSite.name, contents }); } async function del(backupSite, auditSource) { @@ -362,7 +362,7 @@ async function del(backupSite, auditSource) { if (error && error.sqlCode === 'ER_NO_REFERENCED_ROW_2') throw new BoxError(BoxError.NOT_FOUND, error); if (error) throw error; if (result[2].affectedRows !== 1) throw new BoxError(BoxError.NOT_FOUND, 'Target not found'); - await eventlog.add(eventlog.ACTION_BACKUP_TARGET_REMOVE, auditSource, { backupSite: removePrivateFields(backupSite) }); + await eventlog.add(eventlog.ACTION_BACKUP_SITE_REMOVE, auditSource, { name: backupSite.name, backupSite: removePrivateFields(backupSite) }); backupSite.schedule = constants.CRON_PATTERN_NEVER; await cron.handleBackupScheduleChanged(backupSite); @@ -507,7 +507,7 @@ async function setConfig(backupSite, newConfig, auditSource) { debug('setConfig: setting up new storage configuration'); await storageApi(backupSite).setup(sanitizedConfig); - await eventlog.add(eventlog.ACTION_BACKUP_TARGET_UPDATE, auditSource, { backupSite: removePrivateFields(backupSite), newConfig }); + await eventlog.add(eventlog.ACTION_BACKUP_SITE_UPDATE, auditSource, { name: backupSite.name, config: storageApi(backupSite).removePrivateFields(newConfig) }); } async function add(data, auditSource) { @@ -558,7 +558,7 @@ async function add(data, auditSource) { debug('add: setting up new storage configuration'); await storageApi({ provider }).setup(sanitizedConfig); - await eventlog.add(eventlog.ACTION_BACKUP_TARGET_ADD, auditSource, { id, name, provider, contents, schedule, format }); + await eventlog.add(eventlog.ACTION_BACKUP_SITE_ADD, auditSource, { id, name, provider, contents, schedule, format }); return id; } diff --git a/src/eventlog.js b/src/eventlog.js index 9d32d0ce9..91b76bf45 100644 --- a/src/eventlog.js +++ b/src/eventlog.js @@ -38,9 +38,9 @@ exports = module.exports = { ACTION_BACKUP_CLEANUP_START: 'backup.cleanup.start', // obsolete ACTION_BACKUP_CLEANUP_FINISH: 'backup.cleanup.finish', - ACTION_BACKUP_TARGET_ADD: 'backuptarget.add', - ACTION_BACKUP_TARGET_REMOVE: 'backuptarget.remove', - ACTION_BACKUP_TARGET_UPDATE: 'backuptarget.update', + ACTION_BACKUP_SITE_ADD: 'backupsite.add', + ACTION_BACKUP_SITE_REMOVE: 'backupsite.remove', + ACTION_BACKUP_SITE_UPDATE: 'backupsite.update', ACTION_BRANDING_NAME: 'branding.name', ACTION_BRANDING_FOOTER: 'branding.footer',