diff --git a/lib/api.js b/lib/api.js index 220e954d8..b3beddf3d 100644 --- a/lib/api.js +++ b/lib/api.js @@ -10,6 +10,7 @@ const nThen = require("nthen"); const Fs = require("fs"); const Path = require("path"); const Nacl = require("tweetnacl/nacl-fast"); +const Hash = require('./common-hash'); module.exports.create = function (Env) { var log = Env.Log; @@ -25,6 +26,39 @@ nThen(function (w) { console.error(err); } })); +}).nThen(function (w) { + let admins = Env.admins || []; + + // If we don't have any admin on this instance, print an onboarding link + if (Array.isArray(admins) && admins.length) { return; } + let token = Env.installToken; + let printLink = () => { + let url = `${Env.httpUnsafeOrigin}/install/#${token}`; + console.log('============================='); + console.log('Create your first admin account and customize your instance by visiting'); + console.log(url); + console.log('============================='); + + }; + + // If we already have a token, print it + if (token) { return void printLink(); } + + // Otherwise create a new token + let decreeName = Path.join(Env.paths.decree, 'decree.ndjson'); + token = Hash.createChannelId() + Hash.createChannelId(); + let decree = ["ADD_INSTALL_TOKEN",[token],"",+new Date()]; + Fs.appendFile(decreeName, JSON.stringify(decree) + '\n', w(function (err) { + if (err) { console.log(err); return; } + printLink(); + })); +}).nThen(function (w) { + if (!Env.admins.length) { + Env.Log.info('NO_ADMIN_CONFIGURED', { + message: `Your instance is not correctly configured for production usage. Review its checkup page for more information.`, + details: new URL('/checkup/', Env.httpUnsafeOrigin).href, + }); + } }).nThen(function (w) { // we assume the server has generated a secret used to validate JWT tokens if (typeof(Env.bearerSecret) === 'string') { return; } diff --git a/lib/common-hash.js b/lib/common-hash.js new file mode 100644 index 000000000..7a3beddab --- /dev/null +++ b/lib/common-hash.js @@ -0,0 +1,6 @@ +// SPDX-FileCopyrightText: 2023 XWiki CryptPad Team and contributors +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +module.exports = require("../www/common/common-hash"); + diff --git a/scripts/install.js b/scripts/install.js index 86a0d0b75..4fb06a4ed 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -40,5 +40,4 @@ nThen(function (w) { console.log(token); var url = config.httpUnsafeOrigin + '/install/'; console.log(`Please visit ${url} to create your first admin user`); - }); diff --git a/server.js b/server.js index f8e8ffd94..5326f0270 100644 --- a/server.js +++ b/server.js @@ -71,13 +71,6 @@ nThen(function (w) { Env.Log.info("WEBSERVER_LISTENING", { origin: url, }); - - if (!Env.admins.length) { - Env.Log.info('NO_ADMIN_CONFIGURED', { - message: `Your instance is not correctly configured for production usage. Review its checkup page for more information.`, - details: new URL('/checkup/', Env.httpUnsafeOrigin).href, - }); - } } catch (err) { Env.Log.error("INVALID_ORIGIN", { httpUnsafeOrigin: Env.httpUnsafeOrigin,