From cffd04446eb4dfa7959cb83a00e931c0d0525dfc Mon Sep 17 00:00:00 2001 From: Stefan Date: Mon, 1 Jun 2020 18:57:53 +0200 Subject: [PATCH] admin: Add etherpad update check This update check notifies admin on startup (via console) or in /admin UI that they need to update Etherpad. --- src/node/hooks/express/adminplugins.js | 4 ++- src/node/server.js | 6 +++- src/node/utils/UpdateCheck.js | 44 ++++++++++++++++++++++++++ src/templates/admin/plugins-info.html | 1 + 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/node/utils/UpdateCheck.js diff --git a/src/node/hooks/express/adminplugins.js b/src/node/hooks/express/adminplugins.js index 7cfb160b9..983d29ea6 100644 --- a/src/node/hooks/express/adminplugins.js +++ b/src/node/hooks/express/adminplugins.js @@ -4,6 +4,7 @@ var installer = require('ep_etherpad-lite/static/js/pluginfw/installer'); var plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins'); var _ = require('underscore'); var semver = require('semver'); +const UpdateCheck = require('ep_etherpad-lite/node/utils/UpdateCheck'); exports.expressCreateServer = function(hook_name, args, cb) { args.app.get('/admin/plugins', function(req, res) { @@ -23,7 +24,8 @@ exports.expressCreateServer = function(hook_name, args, cb) { res.send(eejs.require("ep_etherpad-lite/templates/admin/plugins-info.html", { gitCommit: gitCommit, - epVersion: epVersion + epVersion: epVersion, + latestVersion: UpdateCheck.getLatestVersion() })); }); } diff --git a/src/node/server.js b/src/node/server.js index d98767225..be595173a 100755 --- a/src/node/server.js +++ b/src/node/server.js @@ -21,8 +21,9 @@ * limitations under the License. */ -var log4js = require('log4js') +const log4js = require('log4js') , NodeVersion = require('./utils/NodeVersion') + , UpdateCheck = require('./utils/UpdateCheck') ; log4js.replaceConsole(); @@ -38,6 +39,9 @@ NodeVersion.enforceMinNodeVersion('10.13.0'); */ NodeVersion.checkDeprecationStatus('10.13.0', '1.8.3'); +// Check if Etherpad version is up-to-date +UpdateCheck.check(); + /* * start up stats counting system */ diff --git a/src/node/utils/UpdateCheck.js b/src/node/utils/UpdateCheck.js new file mode 100644 index 000000000..0181f1ea2 --- /dev/null +++ b/src/node/utils/UpdateCheck.js @@ -0,0 +1,44 @@ +const semver = require('semver'); +const settings = require('./Settings'); +const request = require('request'); + +let infos; + +function loadEtherpadInformations() { + return new Promise(function(resolve, reject) { + request('https://static.etherpad.org/info.json', function (er, response, body) { + if (er) return reject(er); + + try { + infos = JSON.parse(body); + return resolve(infos); + } catch (err) { + return reject(err); + } + }); + }) +} + +exports.getLatestVersion = function() { + exports.needsUpdate(); + return infos.latestVersion; +} + +exports.needsUpdate = function(cb) { + loadEtherpadInformations().then(function(info) { + if (semver.gt(info.latestVersion, settings.getEpVersion())) { + if (cb) return cb(true); + } + }).catch(function (err) { + console.error('Can not perform Etherpad update check: ' + err) + if (cb) return cb(false); + }) +} + +exports.check = function() { + exports.needsUpdate(function (needsUpdate) { + if (needsUpdate) { + console.warn('Update available: Download the actual version ' + infos.latestVersion) + } + }) +} \ No newline at end of file diff --git a/src/templates/admin/plugins-info.html b/src/templates/admin/plugins-info.html index 8c259ac20..fe0f69f7b 100644 --- a/src/templates/admin/plugins-info.html +++ b/src/templates/admin/plugins-info.html @@ -24,6 +24,7 @@

Etherpad version

Version number: <%= epVersion %>

+

Latest available version: <%= latestVersion %>

Git sha: <%= gitCommit %>

Installed plugins