diff --git a/dashboard/gulpfile.js b/dashboard/gulpfile.js index afcc32232..2e9d9d590 100644 --- a/dashboard/gulpfile.js +++ b/dashboard/gulpfile.js @@ -98,15 +98,6 @@ gulp.task('js-index', function () { .pipe(gulp.dest('dist/js')); }); -gulp.task('js-logs', function () { - return gulp.src(['src/js/logs.js', 'src/js/client.js', 'src/js/utils.js']) - .pipe(ejs({ apiOrigin: apiOrigin, revision: revision, appstore: appstore }, {}, { ext: '.js' })) - .pipe(sourcemaps.init()) - .pipe(concat('logs.js', { newLine: ';' })) - .pipe(sourcemaps.write()) - .pipe(gulp.dest('dist/js')); -}); - gulp.task('js-filemanager', function () { return gulp.src(['src/js/filemanager.js', 'src/js/client.js', 'src/js/utils.js', 'src/components/*.js']) .pipe(ejs({ apiOrigin: apiOrigin, revision: revision, appstore: appstore }, {}, { ext: '.js' })) @@ -161,7 +152,7 @@ gulp.task('js-restore', function () { .pipe(gulp.dest('dist/js')); }); -gulp.task('js', gulp.series([ 'js-index', 'js-logs', 'js-filemanager', 'js-passwordreset', 'js-setupaccount', 'js-setup', 'js-setupdns', 'js-restore' ])); +gulp.task('js', gulp.series([ 'js-index', 'js-filemanager', 'js-passwordreset', 'js-setupaccount', 'js-setup', 'js-setupdns', 'js-restore' ])); // -------------- // HTML @@ -236,7 +227,6 @@ gulp.task('watch', function (done) { gulp.watch(['src/js/setup.js', 'src/js/client.js', 'src/js/utils.js'], gulp.series(['js-setup'])); gulp.watch(['src/js/setupdns.js', 'src/js/client.js', 'src/js/utils.js'], gulp.series(['js-setupdns'])); gulp.watch(['src/js/restore.js', 'src/js/client.js', 'src/js/utils.js'], gulp.series(['js-restore'])); - gulp.watch(['src/js/logs.js', 'src/js/client.js', 'src/js/utils.js'], gulp.series(['js-logs'])); gulp.watch(['src/js/filemanager.js', 'src/js/client.js', 'src/js/utils.js', 'src/components/*.js'], gulp.series(['js-filemanager'])); gulp.watch(['src/js/passwordreset.js', 'src/js/utils.js'], gulp.series(['js-passwordreset'])); gulp.watch(['src/js/setupaccount.js', 'src/js/utils.js'], gulp.series(['js-setupaccount'])); diff --git a/dashboard/src/js/client.js b/dashboard/src/js/client.js index 23f427c5b..509def688 100644 --- a/dashboard/src/js/client.js +++ b/dashboard/src/js/client.js @@ -748,14 +748,6 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout return token; }; - Client.prototype.makeURL = function (url) { - if (url.indexOf('?') === -1) { - return this.apiOrigin + url + '?access_token=' + token; - } else { - return this.apiOrigin + url + '&access_token=' + token; - } - }; - /* * Rest API wrappers */ @@ -1415,21 +1407,6 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; - Client.prototype.getTaskLogs = function (taskId, follow, lines, callback) { - if (follow) { - var eventSource = new EventSource(client.apiOrigin + '/api/v1/tasks/' + taskId + '/logstream?lines=' + lines + '&access_token=' + token); - eventSource.onerror = callback; - eventSource.onopen = function () { callback(null, eventSource); }; - } else { - get('/api/v1/services/' + taskId + '/logs?lines=' + lines, null, function (error, data, status) { - if (error) return callback(error); - if (status !== 200) return callback(new ClientError(status, data)); - - callback(null, data); - }); - } - }; - Client.prototype.editBackup = function (backupId, label, preserveSecs, callback) { post('/api/v1/backups/' + backupId, { label: label, preserveSecs: preserveSecs }, null, function (error, data, status) { if (error) return callback(error); @@ -1553,36 +1530,6 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; - Client.prototype.getPlatformLogs = function (unit, follow, lines, callback) { - if (follow) { - var eventSource = new EventSource(client.apiOrigin + '/api/v1/cloudron/logstream/' + unit + '?lines=' + lines + '&access_token=' + token); - eventSource.onerror = callback; - eventSource.onopen = function () { callback(null, eventSource); }; - } else { - get('/api/v1/cloudron/logs/' + unit + '?lines=' + lines, null, function (error, data, status) { - if (error) return callback(error); - if (status !== 200) return callback(new ClientError(status, data)); - - callback(null, data); - }); - } - }; - - Client.prototype.getServiceLogs = function (serviceName, follow, lines, callback) { - if (follow) { - var eventSource = new EventSource(client.apiOrigin + '/api/v1/services/' + serviceName + '/logstream?lines=' + lines + '&access_token=' + token); - eventSource.onerror = callback; - eventSource.onopen = function () { callback(null, eventSource); }; - } else { - get('/api/v1/services/' + serviceName + '/logs?lines=' + lines, null, function (error, data, status) { - if (error) return callback(error); - if (status !== 200) return callback(new ClientError(status, data)); - - callback(null, data); - }); - } - }; - Client.prototype.getApps = function (callback) { var that = this; @@ -1599,21 +1546,6 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; - Client.prototype.getAppLogs = function (appId, follow, lines, callback) { - if (follow) { - var eventSource = new EventSource(client.apiOrigin + '/api/v1/apps/' + appId + '/logstream?lines=' + lines + '&access_token=' + token); - eventSource.onerror = callback; - eventSource.onopen = function () { callback(null, eventSource); }; - } else { - get('/api/v1/apps/' + appId + '/logs', null, function (error, data, status) { - if (error) return callback(error); - if (status !== 200) return callback(new ClientError(status, data)); - - callback(null, data); - }); - } - }; - Client.prototype.getAppBackups = function (appId, callback) { var page = 1; var perPage = 100; diff --git a/dashboard/src/js/logs.js b/dashboard/src/js/logs.js deleted file mode 100644 index 7555f2f1c..000000000 --- a/dashboard/src/js/logs.js +++ /dev/null @@ -1,209 +0,0 @@ -'use strict'; - -/* global angular */ -/* global moment */ -/* global $ */ - -// create main application module -var app = angular.module('Application', ['pascalprecht.translate', 'ngCookies', 'angular-md5', 'ui-notification']); - -app.controller('LogsController', ['$scope', '$translate', 'Client', function ($scope, $translate, Client) { - var search = decodeURIComponent(window.location.search).slice(1).split('&').map(function (item) { return item.split('='); }).reduce(function (o, k) { o[k[0]] = k[1]; return o; }, {}); - - $scope.initialized = false; - $scope.client = Client; - $scope.selected = ''; - $scope.activeEventSource = null; - $scope.lines = 100; - $scope.selectedAppInfo = null; - $scope.selectedTaskInfo = null; - $scope.error = null; - - function ab2str(buf) { - return String.fromCharCode.apply(null, new Uint16Array(buf)); - } - - $scope.clear = function () { - var logViewer = $('.logs-container'); - logViewer.empty(); - }; - - // https://github.com/janl/mustache.js/blob/master/mustache.js#L60 - var entityMap = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''', - '/': '/', - '`': '`', - '=': '=' - }; - - function escapeHtml(string) { - return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) { - return entityMap[s]; - }); - } - - function showLogs() { - if (!$scope.selected) return; - - var func; - if ($scope.selected.type === 'platform') func = Client.getPlatformLogs; - else if ($scope.selected.type === 'service') func = Client.getServiceLogs; - else if ($scope.selected.type === 'task') func = Client.getTaskLogs; - else if ($scope.selected.type === 'app') func = Client.getAppLogs; - - func($scope.selected.value, true /* follow */, $scope.lines, function (error, result) { - if (error) { - $scope.$apply(function () { $scope.error = { logsGone: true }; }); - return console.error('Error subscribing to logstream.', error); - } - - $scope.activeEventSource = result; - result.onmessage = function handleMessage(message) { - var data; - - try { - data = JSON.parse(message.data); - } catch (e) { - return console.error(e); - } - - // check if we want to auto scroll (this is before the appending, as that skews the check) - var tmp = $('.logs-container'); - var autoScroll = tmp[0].scrollTop > (tmp[0].scrollHeight - tmp.innerHeight() - 24); - - var logLine = $('
'); - // realtimeTimestamp is 0 if line is blank or some parse error - var timeString = data.realtimeTimestamp ? moment(data.realtimeTimestamp/1000).format('MMM DD HH:mm:ss') : ''; - logLine.html('' + timeString + ' ' + window.ansiToHTML(escapeHtml(typeof data.message === 'string' ? data.message : ab2str(data.message)))); - tmp.append(logLine); - - if (autoScroll) tmp[0].lastChild.scrollIntoView({ behavior: 'instant', block: 'end' }); - }; - }); - } - - function select(ids, callback) { - if (ids.id && ids.id.indexOf('redis:') === 0) { - $scope.selected = { - name: 'Redis', - type: 'service', - value: ids.id, - url: Client.makeURL('/api/v1/services/' + ids.id + '/logs') - }; - callback(); - } else if (ids.id) { - var BUILT_IN_LOGS = [ - { name: 'Box', type: 'platform', value: 'box', url: Client.makeURL('/api/v1/cloudron/logs/box') }, - { name: 'Graphite', type: 'service', value: 'graphite', url: Client.makeURL('/api/v1/services/graphite/logs') }, - { name: 'MongoDB', type: 'service', value: 'mongodb', url: Client.makeURL('/api/v1/services/mongodb/logs') }, - { name: 'MySQL', type: 'service', value: 'mysql', url: Client.makeURL('/api/v1/services/mysql/logs') }, - { name: 'PostgreSQL', type: 'service', value: 'postgresql', url: Client.makeURL('/api/v1/services/postgresql/logs') }, - { name: 'Mail', type: 'service', value: 'mail', url: Client.makeURL('/api/v1/services/mail/logs') }, - { name: 'Docker', type: 'service', value: 'docker', url: Client.makeURL('/api/v1/services/docker/logs') }, - { name: 'Nginx', type: 'service', value: 'nginx', url: Client.makeURL('/api/v1/services/nginx/logs') }, - { name: 'Unbound', type: 'service', value: 'unbound', url: Client.makeURL('/api/v1/services/unbound/logs') }, - { name: 'SFTP', type: 'service', value: 'sftp', url: Client.makeURL('/api/v1/services/sftp/logs') }, - { name: 'TURN/STUN', type: 'service', value: 'turn', url: Client.makeURL('/api/v1/services/turn/logs') }, - ]; - - $scope.selected = BUILT_IN_LOGS.find(function (e) { return e.value === ids.id; }); - callback(); - } else if (ids.crashId) { - $scope.selected = { - type: 'platform', - value: 'crash-' + ids.crashId, - name: 'Crash', - url: Client.makeURL('/api/v1/cloudron/logs/crash-' + ids.crashId) - }; - - callback(); - } else if (ids.appId) { - Client.getApp(ids.appId, function (error, app) { - if (error) return callback(error); - - $scope.selectedAppInfo = app; - - $scope.selected = { - type: 'app', - value: app.id, - name: app.fqdn + ' (' + app.manifest.title + ')', - url: Client.makeURL('/api/v1/apps/' + app.id + '/logs'), - addons: app.manifest.addons - }; - - callback(); - }); - } else if (ids.taskId) { - Client.getTask(ids.taskId, function (error, task) { - if (error) return callback(error); - - $scope.selectedTaskInfo = task; - - $scope.selected = { - type: 'task', - value: task.id, - name: task.type, - url: Client.makeURL('/api/v1/tasks/' + task.id + '/logs') - }; - - callback(); - }); - } - } - - function init() { - - Client.getStatus(function (error, status) { - if (error) return Client.initError(error, init); - - if (!status.activated) { - console.log('Not activated yet, redirecting', status); - window.location.href = '/'; - return; - } - - // check version and force reload if needed - if (!localStorage.version) { - localStorage.version = status.version; - } else if (localStorage.version !== status.version) { - localStorage.version = status.version; - window.location.reload(true); - } - - console.log('Running log version ', localStorage.version); - - // get user profile as the first thing. this populates the "scope" and affects subsequent API calls - Client.refreshUserInfo(function (error) { - if (error) return Client.initError(error, init); - - Client.refreshConfig(function (error) { - if (error) return Client.initError(error, init); - - select({ id: search.id, taskId: search.taskId, appId: search.appId, crashId: search.crashId }, function (error) { - $scope.initialized = true; - - if (error) { - $scope.error = { notFound: true }; - return console.error('Not found.', error); - } - - // now mark the Client to be ready - Client.setReady(); - - showLogs(); - }); - }); - }); - }); - } - - init(); - - $translate([ 'logs.title' ]).then(function (tr) { - if (tr['logs.title'] !== 'logs.title') window.document.title = tr['logs.title']; - }); -}]); diff --git a/dashboard/src/logs.html b/dashboard/src/logs.html deleted file mode 100644 index 7f52795b5..000000000 --- a/dashboard/src/logs.html +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - - Cloudron Logs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {{ 'main.offline' | tr }} - -
-
{{ 'logs.notFoundError' | tr }}
-
{{ 'logs.logsGoneError' | tr }}
- - -
-
- - -