Files
cloudron-box/src/views/activity.js

455 lines
19 KiB
JavaScript
Raw Normal View History

2018-01-22 13:01:38 -08:00
'use strict';
/* global angular:false */
/* global $:false */
2018-01-22 13:01:38 -08:00
angular.module('Application').controller('ActivityController', ['$scope', '$location', 'Client', function ($scope, $location, Client) {
2020-02-24 12:56:13 +01:00
Client.onReady(function () { if (!Client.getUserInfo().isAtLeastAdmin) $location.path('/'); });
2018-01-22 13:01:38 -08:00
$scope.config = Client.getConfig();
$scope.busy = false;
$scope.eventLogs = [];
$scope.activeEventLog = null;
2018-01-22 13:01:38 -08:00
// TODO sync this with the eventlog filter
$scope.actions = [
2018-02-20 11:13:51 -08:00
{ name: '-- All app events --', value: 'app.' },
{ name: '-- All user events --', value: 'user.' },
2018-01-22 13:01:38 -08:00
{ name: 'app.configure', value: 'app.configure' },
{ name: 'app.install', value: 'app.install' },
{ name: 'app.restore', value: 'app.restore' },
{ name: 'app.uninstall', value: 'app.uninstall' },
{ name: 'app.update', value: 'app.update' },
2019-09-26 20:13:24 -07:00
{ name: 'app.update.finish', value: 'app.update.finish' },
2018-01-22 13:01:38 -08:00
{ name: 'app.login', value: 'app.login' },
2019-01-17 15:49:53 +01:00
{ name: 'app.oom', value: 'app.oom' },
2019-02-11 12:34:06 -08:00
{ name: 'app.down', value: 'app.down' },
2019-02-11 13:03:12 -08:00
{ name: 'app.up', value: 'app.up' },
2020-03-19 17:05:50 -07:00
{ name: 'app.start', value: 'app.start' },
{ name: 'app.stop', value: 'app.stop' },
{ name: 'app.restart', value: 'app.restart' },
2019-01-19 15:53:49 +01:00
{ name: 'Apptask Crash', value: 'app.task.crash' },
2019-01-14 09:29:00 -08:00
{ name: 'backup.cleanup', value: 'backup.cleanup.start' },
{ name: 'backup.cleanup.finish', value: 'backup.cleanup.finish' },
2018-01-22 13:01:38 -08:00
{ name: 'backup.finish', value: 'backup.finish' },
{ name: 'backup.start', value: 'backup.start' },
2018-11-14 20:37:58 -08:00
{ name: 'certificate.new', value: 'certificate.new' },
2018-01-22 13:01:38 -08:00
{ name: 'certificate.renew', value: 'certificate.renew' },
2018-02-20 11:13:51 -08:00
{ name: 'cloudron.activate', value: 'cloudron.activate' },
2018-11-10 01:34:50 -08:00
{ name: 'cloudron.provision', value: 'cloudron.provision' },
{ name: 'cloudron.restore', value: 'cloudron.restore' },
2018-01-22 13:01:38 -08:00
{ name: 'cloudron.start', value: 'cloudron.start' },
{ name: 'cloudron.update', value: 'cloudron.update' },
2019-09-26 20:13:24 -07:00
{ name: 'cloudron.update.finish', value: 'cloudron.update.finish' },
2019-02-04 20:24:23 -08:00
{ name: 'dashboard.domain.update', value: 'dashboard.domain.update' },
2019-01-14 09:29:00 -08:00
{ name: 'dyndns.update', value: 'dyndns.update' },
2018-11-10 01:09:06 -08:00
{ name: 'domain.add', value: 'domain.add' },
{ name: 'domain.update', value: 'domain.update' },
{ name: 'domain.remove', value: 'domain.remove' },
2020-09-09 22:31:57 -07:00
{ name: 'mail.location', value: 'mail.location' },
2018-11-10 00:32:37 -08:00
{ name: 'mail.enabled', value: 'mail.enabled' },
{ name: 'mail.box.add', value: 'mail.box.add' },
{ name: 'mail.box.update', value: 'mail.box.update' },
2018-11-10 00:32:37 -08:00
{ name: 'mail.box.remove', value: 'mail.box.remove' },
{ name: 'mail.list.add', value: 'mail.list.add' },
{ name: 'mail.list.update', value: 'mail.list.update' },
2018-11-10 00:32:37 -08:00
{ name: 'mail.list.remove', value: 'mail.list.remove' },
2019-12-16 14:12:59 -08:00
{ name: 'support.ticket', value: 'support.ticket' },
{ name: 'support.ssh', value: 'support.ssh' },
2018-01-22 13:01:38 -08:00
{ name: 'user.add', value: 'user.add' },
{ name: 'user.login', value: 'user.login' },
{ name: 'user.remove', value: 'user.remove' },
2018-07-05 13:54:05 -07:00
{ name: 'user.transfer', value: 'user.transfer' },
2019-01-19 15:53:49 +01:00
{ name: 'user.update', value: 'user.update' },
{ name: 'System Crash', value: 'system.crash' }
2018-01-22 13:01:38 -08:00
];
$scope.pageItemCount = [
{ name: 'Show 20 per page', value: 20 },
{ name: 'Show 50 per page', value: 50 },
{ name: 'Show 100 per page', value: 100 }
];
$scope.currentPage = 1;
$scope.pageItems = $scope.pageItemCount[0];
$scope.action = '';
$scope.selectedActions = [];
2018-01-22 13:01:38 -08:00
$scope.search = '';
function eventLogDetails(eventLog) {
var ACTION_ACTIVATE = 'cloudron.activate';
var ACTION_PROVISION = 'cloudron.provision';
var ACTION_RESTORE = 'cloudron.restore';
2019-09-26 21:36:11 -07:00
var ACTION_APP_CLONE = 'app.clone';
2019-09-26 21:36:11 -07:00
var ACTION_APP_REPAIR = 'app.repair';
var ACTION_APP_CONFIGURE = 'app.configure';
var ACTION_APP_INSTALL = 'app.install';
var ACTION_APP_RESTORE = 'app.restore';
var ACTION_APP_UNINSTALL = 'app.uninstall';
var ACTION_APP_UPDATE = 'app.update';
var ACTION_APP_UPDATE_FINISH = 'app.update.finish';
var ACTION_APP_LOGIN = 'app.login';
var ACTION_APP_OOM = 'app.oom';
var ACTION_APP_UP = 'app.up';
var ACTION_APP_DOWN = 'app.down';
2020-03-19 17:05:50 -07:00
var ACTION_APP_START = 'app.start';
var ACTION_APP_STOP = 'app.stop';
var ACTION_APP_RESTART = 'app.restart';
var ACTION_BACKUP_FINISH = 'backup.finish';
var ACTION_BACKUP_START = 'backup.start';
var ACTION_BACKUP_CLEANUP_START = 'backup.cleanup.start';
var ACTION_BACKUP_CLEANUP_FINISH = 'backup.cleanup.finish';
var ACTION_CERTIFICATE_NEW = 'certificate.new';
var ACTION_CERTIFICATE_RENEWAL = 'certificate.renew';
var ACTION_DASHBOARD_DOMAIN_UPDATE = 'dashboard.domain.update';
var ACTION_DOMAIN_ADD = 'domain.add';
var ACTION_DOMAIN_UPDATE = 'domain.update';
var ACTION_DOMAIN_REMOVE = 'domain.remove';
var ACTION_START = 'cloudron.start';
var ACTION_UPDATE = 'cloudron.update';
var ACTION_UPDATE_FINISH = 'cloudron.update.finish';
var ACTION_USER_ADD = 'user.add';
var ACTION_USER_LOGIN = 'user.login';
var ACTION_USER_REMOVE = 'user.remove';
var ACTION_USER_UPDATE = 'user.update';
var ACTION_USER_TRANSFER = 'user.transfer';
2020-09-09 22:31:57 -07:00
var ACTION_MAIL_LOCATION = 'mail.location';
var ACTION_MAIL_ENABLED = 'mail.enabled';
var ACTION_MAIL_DISABLED = 'mail.disabled';
var ACTION_MAIL_MAILBOX_ADD = 'mail.box.add';
var ACTION_MAIL_MAILBOX_UPDATE = 'mail.box.update';
var ACTION_MAIL_MAILBOX_REMOVE = 'mail.box.remove';
var ACTION_MAIL_LIST_ADD = 'mail.list.add';
var ACTION_MAIL_LIST_UPDATE = 'mail.list.update';
var ACTION_MAIL_LIST_REMOVE = 'mail.list.remove';
2019-12-16 14:12:59 -08:00
var ACTION_SUPPORT_TICKET = 'support.ticket';
var ACTION_SUPPORT_SSH = 'support.ssh';
var ACTION_DYNDNS_UPDATE = 'dyndns.update';
var ACTION_SYSTEM_CRASH = 'system.crash';
var data = eventLog.data;
var errorMessage = data.errorMessage;
2020-03-19 17:05:50 -07:00
var details, app;
function appName(app) {
return (app.label || app.fqdn || app.location) + ' (' + app.manifest.title + ')';
}
switch (eventLog.action) {
case ACTION_ACTIVATE:
return 'Cloudron was activated';
case ACTION_PROVISION:
return 'Cloudron was setup';
case ACTION_RESTORE:
return 'Cloudron was restored using backup ' + data.backupId;
2020-03-19 17:05:50 -07:00
case ACTION_APP_CONFIGURE: {
if (!data.app) return '';
2020-03-19 17:05:50 -07:00
app = data.app;
var q = function (x) {
return '"' + x + '"';
};
if ('accessRestriction' in data) { // since it can be null
2020-03-19 17:05:50 -07:00
return 'Access restriction of ' + appName(app) + ' was changed';
} else if (data.label) {
2020-03-19 17:05:50 -07:00
return 'Label of ' + appName(app) + ' was set to ' + q(data.label);
} else if (data.tags) {
2020-03-19 17:05:50 -07:00
return 'Tags of ' + appName(app) + ' was set to ' + q(data.tags.join(','));
} else if (data.icon) {
2020-03-19 17:05:50 -07:00
return 'Icon of ' + appName(app) + ' was changed';
} else if (data.memoryLimit) {
2020-03-19 17:05:50 -07:00
return 'Memory limit of ' + appName(app) + ' was set to ' + data.memoryLimit;
2020-03-19 17:11:51 -07:00
} else if (data.cpuShares) {
2020-03-19 17:15:08 -07:00
return 'CPU shares of ' + appName(app) + ' was set to ' + Math.round((data.cpuShares * 100)/1024) + '%';
} else if (data.env) {
2020-03-19 17:05:50 -07:00
return 'Env vars of ' + appName(app) + ' was changed';
} else if ('debugMode' in data) { // since it can be null
if (data.debugMode) {
2020-03-19 17:05:50 -07:00
return appName(app) + ' was placed in repair mode';
} else {
2020-03-19 17:05:50 -07:00
return appName(app) + ' was taken out of repair mode';
}
} else if ('enableBackup' in data) {
2020-03-19 17:05:50 -07:00
return 'Automatic backups of ' + appName(app) + ' was ' + (data.enableBackup ? 'enabled' : 'disabled');
} else if ('enableAutomaticUpdate' in data) {
2020-03-19 17:05:50 -07:00
return 'Automatic updates of ' + appName(app) + ' was ' + (data.enableAutomaticUpdate ? 'enabled' : 'disabled');
2019-10-14 15:20:48 -07:00
} else if ('reverseProxyConfig' in data) {
2020-03-19 17:05:50 -07:00
return 'Reverse proxy configuration of ' + appName(app) + ' was updated';
} else if ('cert' in data) {
if (data.cert) {
2020-03-19 17:05:50 -07:00
return 'Custom certificate was set for ' + appName(app);
} else {
2020-03-19 17:05:50 -07:00
return 'Certificate of ' + appName(app) + ' was reset';
}
} else if (data.location) {
2019-09-27 12:58:26 -07:00
if (data.fqdn !== data.app.fqdn) {
2020-03-19 17:05:50 -07:00
return 'Location of ' + appName(app) + ' was changed to ' + data.fqdn;
} else if (!angular.equals(data.alternateDomains, data.app.alternateDomains)) {
2019-09-27 12:58:26 -07:00
var altFqdns = data.alternateDomains.map(function (a) { return a.fqdn; });
2020-03-19 17:05:50 -07:00
return 'Alternate domains of ' + appName(app) + ' was ' + (altFqdns.length ? 'set to ' + altFqdns.join(', ') : 'reset');
} else if (!angular.equals(data.portBindings, data.app.portBindings)) {
2020-03-19 17:05:50 -07:00
return 'Port bindings of ' + appName(app) + ' was changed';
}
} else if ('dataDir' in data) {
if (data.dataDir) {
2020-03-19 17:05:50 -07:00
return 'Data directory of ' + appName(app) + ' was set ' + data.dataDir;
} else {
2020-03-19 17:05:50 -07:00
return 'Data directory of ' + appName(app) + ' was reset';
}
2019-09-27 13:44:57 -07:00
} else if ('icon' in data) {
if (data.icon) {
2020-03-19 17:05:50 -07:00
return 'Icon of ' + appName(app) + ' was set';
2019-09-27 13:44:57 -07:00
} else {
2020-03-19 17:05:50 -07:00
return 'Icon of ' + appName(app) + ' was reset';
2019-09-27 13:44:57 -07:00
}
} else if (('mailboxName' in data) && data.mailboxName !== data.app.mailboxName) {
if (data.mailboxName) {
2020-03-19 17:05:50 -07:00
return 'Mailbox of ' + appName(app) + ' was set to ' + q(data.mailboxName);
} else {
2020-03-19 17:05:50 -07:00
return 'Mailbox of ' + appName(app) + ' was reset';
}
}
2020-03-19 17:05:50 -07:00
return appName(app) + ' was re-configured';
}
case ACTION_APP_INSTALL:
if (!data.app) return '';
return data.app.manifest.title + ' (package v' + data.app.manifest.version + ') was installed at ' + (data.app.fqdn || data.app.location);
case ACTION_APP_RESTORE:
if (!data.app) return '';
details = data.app.manifest.title + ' was restored at ' + (data.app.fqdn || data.app.location);
// older versions (<3.5) did not have these fields
if (data.fromManifest) details += ' from version ' + data.fromManifest.version;
if (data.toManifest) details += ' to version ' + data.toManifest.version;
if (data.backupId) details += ' using backup ' + data.backupId;
return details;
case ACTION_APP_UNINSTALL:
if (!data.app) return '';
return data.app.manifest.title + ' (package v' + data.app.manifest.version + ') was uninstalled at ' + (data.app.fqdn || data.app.location);
case ACTION_APP_UPDATE:
if (!data.app) return '';
return 'Update of ' + data.app.manifest.title + ' at ' + (data.app.fqdn || data.app.location) + ' started from v' + data.fromManifest.version + ' to v' + data.toManifest.version;
case ACTION_APP_UPDATE_FINISH:
if (!data.app) return '';
return data.app.manifest.title + ' at ' + (data.app.fqdn || data.app.location) + ' was updated to v' + data.app.manifest.version;
case ACTION_APP_CLONE:
return data.newApp.manifest.title + ' at ' + (data.newApp.fqdn || data.newApp.location) + ' was cloned from ' + (data.oldApp.fqdn || data.oldApp.location) + ' using backup ' + data.backupId + ' with v' + data.oldApp.manifest.version;
2019-09-26 21:36:11 -07:00
case ACTION_APP_REPAIR:
2020-09-09 22:36:57 -07:00
return 'App ' + appName(data.app) + ' was re-configured'; // re-configure of email apps is more common?
2019-09-26 21:36:11 -07:00
2020-03-19 17:05:50 -07:00
case ACTION_APP_LOGIN: {
app = Client.getCachedAppSync(data.appId);
2020-03-04 15:07:35 -08:00
if (!app) return '';
2019-09-26 21:36:11 -07:00
return 'App ' + app.fqdn + ' logged in';
2020-03-19 17:05:50 -07:00
}
case ACTION_APP_OOM:
2020-03-04 15:07:35 -08:00
if (!data.app) return '';
2020-03-19 17:05:50 -07:00
return appName(data.app) + ' ran out of memory';
case ACTION_APP_DOWN:
2020-03-04 15:07:35 -08:00
if (!data.app) return '';
2020-03-19 17:05:50 -07:00
return appName(data.app) + ' is down';
case ACTION_APP_UP:
2020-03-04 15:07:35 -08:00
if (!data.app) return '';
2020-03-19 17:05:50 -07:00
return appName(data.app) + ' is back online';
case ACTION_APP_START:
if (!data.app) return '';
return appName(data.app) + ' was started';
case ACTION_APP_STOP:
if (!data.app) return '';
return appName(data.app) + ' was stopped';
case ACTION_APP_RESTART:
if (!data.app) return '';
return appName(data.app) + ' was restarted';
case ACTION_BACKUP_START:
return 'Backup started';
case ACTION_BACKUP_FINISH:
if (!errorMessage) {
2019-09-27 09:29:07 -07:00
return 'Cloudron backup created with Id ' + data.backupId;
} else {
2019-09-27 09:29:07 -07:00
return 'Cloudron backup errored with error: ' + errorMessage;
}
case ACTION_BACKUP_CLEANUP_START:
return 'Backup cleaner started';
case ACTION_BACKUP_CLEANUP_FINISH:
2020-07-06 14:53:52 +02:00
return data.errorMessage ? 'Backup cleaner errored: ' + data.errorMessage : 'Backup cleaner removed ' + (data.removedBoxBackups ? data.removedBoxBackups.length : '0') + ' backups';
case ACTION_CERTIFICATE_NEW:
return 'Certificate install for ' + data.domain + (errorMessage ? ' failed' : ' succeeded');
case ACTION_CERTIFICATE_RENEWAL:
return 'Certificate renewal for ' + data.domain + (errorMessage ? ' failed' : ' succeeded');
case ACTION_DASHBOARD_DOMAIN_UPDATE:
return 'Dashboard domain set to ' + data.fqdn;
case ACTION_DOMAIN_ADD:
return 'Domain ' + data.domain + ' with ' + data.provider + ' provider was added';
case ACTION_DOMAIN_UPDATE:
return 'Domain ' + data.domain + ' with ' + data.provider + ' provider was updated';
case ACTION_DOMAIN_REMOVE:
return 'Domain ' + data.domain + ' was removed';
2020-09-09 22:31:57 -07:00
case ACTION_MAIL_LOCATION:
return 'Mail server location was changed to ' + data.subdomain + (data.subdomain ? '.' : '') + data.domain;
case ACTION_MAIL_ENABLED:
2020-09-09 22:31:57 -07:00
return 'Mail was enabled for domain ' + data.domain;
case ACTION_MAIL_DISABLED:
2020-09-09 22:31:57 -07:00
return 'Mail was disabled for domain ' + data.domain;
case ACTION_MAIL_MAILBOX_ADD:
return 'Mailbox with name ' + data.name + ' was added in domain ' + data.domain;
case ACTION_MAIL_MAILBOX_UPDATE:
return 'Mailbox with name ' + data.name + ' was updated in domain ' + data.domain;
case ACTION_MAIL_MAILBOX_REMOVE:
return 'Mailbox with name ' + data.name + ' was removed in domain ' + data.domain;
case ACTION_MAIL_LIST_ADD:
return 'Mail list with name ' + data.name + ' was added in domain ' + data.domain;
case ACTION_MAIL_LIST_UPDATE:
return 'Mail list with name ' + data.name + ' was updated in domain ' + data.domain;
case ACTION_MAIL_LIST_REMOVE:
2019-12-11 10:00:00 -08:00
return 'Mail list with name ' + data.name + ' was removed in domain ' + data.domain;
case ACTION_START:
return 'Cloudron started with version ' + data.version;
case ACTION_UPDATE:
return 'Cloudron update to version ' + data.boxUpdateInfo.version + ' was started';
case ACTION_UPDATE_FINISH:
2020-05-15 21:37:27 -07:00
if (data.errorMessage) {
return 'Cloudron update errored. Error: ' + data.errorMessage;
} else {
return 'Cloudron updated to version ' + data.newVersion;
}
case ACTION_USER_ADD:
return data.email + (data.user.username ? ' (' + data.user.username + ')' : '') + ' was added';
case ACTION_USER_UPDATE:
return (data.user ? (data.user.email + (data.user.username ? ' (' + data.user.username + ')' : '')) : data.userId) + ' was updated';
case ACTION_USER_REMOVE:
return (data.user ? (data.user.email + (data.user.username ? ' (' + data.user.username + ')' : '')) : data.userId) + ' was removed';
case ACTION_USER_TRANSFER:
return 'Apps of ' + data.oldOwnerId + ' was transferred to ' + data.newOwnerId;
case ACTION_USER_LOGIN:
2019-09-27 15:07:37 -07:00
return (data.user ? data.user.username : data.userId) + ' logged in';
case ACTION_DYNDNS_UPDATE:
return 'DNS was updated from ' + data.fromIp + ' to ' + data.toIp;
2019-12-16 14:12:59 -08:00
case ACTION_SUPPORT_SSH:
return 'Remote Support was ' + (data.enable ? 'enabled' : 'disabled');
case ACTION_SUPPORT_TICKET:
return 'Support ticket was created';
case ACTION_SYSTEM_CRASH:
return 'A system process crashed';
default: return eventLog.action;
}
}
function eventLogSource(eventLog) {
var source = eventLog.source;
var line = '';
2019-09-27 15:07:37 -07:00
line = source.username || source.userId || source.mailboxId || source.authType || 'system';
if (source.appId) {
var app = Client.getCachedAppSync(source.appId);
line += ' - ' + (app ? app.fqdn : source.appId);
} else if (source.ip) {
line += ' - ' + source.ip;
}
return line;
2020-01-24 17:17:58 -08:00
}
2018-01-22 13:01:38 -08:00
function fetchEventLogs() {
$scope.busy = true;
var actions = $scope.selectedActions.map(function (a) { return a.value; }).join(', ');
2018-01-22 13:01:38 -08:00
Client.getEventLogs(actions, $scope.search || null, $scope.currentPage, $scope.pageItems.value, function (error, result) {
2018-01-22 13:01:38 -08:00
$scope.busy = false;
if (error) return console.error(error);
$scope.eventLogs = [];
result.forEach(function (e) {
$scope.eventLogs.push({ raw: e, details: eventLogDetails(e), source: eventLogSource(e) });
});
2018-01-22 13:01:38 -08:00
});
}
$scope.showNextPage = function () {
$scope.currentPage++;
fetchEventLogs();
};
$scope.showPrevPage = function () {
if ($scope.currentPage > 1) $scope.currentPage--;
else $scope.currentPage = 1;
fetchEventLogs();
};
$scope.updateFilter = function (fresh) {
if (fresh) $scope.currentPage = 1;
fetchEventLogs();
};
$scope.showEventLogDetails = function (eventLog) {
if ($scope.activeEventLog === eventLog) $scope.activeEventLog = null;
else $scope.activeEventLog = eventLog;
};
2018-01-22 13:01:38 -08:00
Client.onReady(function () {
fetchEventLogs();
});
$('.modal-backdrop').remove();
}]);