From c634e03cb553e21158fddc6d4221a54aa799de79 Mon Sep 17 00:00:00 2001 From: marzavec Date: Mon, 18 Mar 2019 23:36:21 -0700 Subject: refactoring 1 of 2 --- server/src/scripts/setupSchema/Banner.js | 28 +++++++++++++++ server/src/scripts/setupSchema/Footer.js | 7 ++++ server/src/scripts/setupSchema/Questions.js | 55 +++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 server/src/scripts/setupSchema/Banner.js create mode 100644 server/src/scripts/setupSchema/Footer.js create mode 100644 server/src/scripts/setupSchema/Questions.js (limited to 'server/src/scripts/setupSchema') diff --git a/server/src/scripts/setupSchema/Banner.js b/server/src/scripts/setupSchema/Banner.js new file mode 100644 index 0000000..823f0fe --- /dev/null +++ b/server/src/scripts/setupSchema/Banner.js @@ -0,0 +1,28 @@ +/** + * This script will be run before the package starts asking for the config data, + * used to output a simple guide for the coming questions, or to spam some sexy + * ascii art at the user. + * + */ + +const stripIndents = require('common-tags').stripIndents; +const chalk = require('chalk'); + +// gotta have that sexy console +console.log(stripIndents` + ${chalk.magenta('°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸°º¤ø,¸¸,ø¤º°`°º¤ø')} + ${chalk.gray('--------------(') + chalk.white(' HackChat Setup Wizard v2.0 ') + chalk.gray(')--------------')} + ${chalk.magenta('°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸°º¤ø,¸¸,ø¤º°`°º¤ø')} + + For advanced setup, see the documentation at: + ${chalk.green('https://github.com/hack-chat/main/tree/master/documentation')} + + ${chalk.white('Note:')} ${chalk.green('npm/yarn run config')} will re-run this utility. + + You will now be asked for the following: + - ${chalk.magenta(' Salt')}, the salt for username trip + - ${chalk.magenta('Admin Name')}, the initial admin username + - ${chalk.magenta('Admin Pass')}, the initial admin password + - ${chalk.magenta(' Port')}, the port for the websocket + \u200b +`); diff --git a/server/src/scripts/setupSchema/Footer.js b/server/src/scripts/setupSchema/Footer.js new file mode 100644 index 0000000..d2ee14f --- /dev/null +++ b/server/src/scripts/setupSchema/Footer.js @@ -0,0 +1,7 @@ +/** + * This script will be run once all questions have finished and no errors have + * occured. You can congratulate the user on their fine choice in software usage + * + */ + +console.log('Config generated! You may now start the server normally.'); diff --git a/server/src/scripts/setupSchema/Questions.js b/server/src/scripts/setupSchema/Questions.js new file mode 100644 index 0000000..f84d32f --- /dev/null +++ b/server/src/scripts/setupSchema/Questions.js @@ -0,0 +1,55 @@ +/** + * This object contains Prompt ( https://www.npmjs.com/package/prompt ) style + * questions that the SetupWizard will require an answer to. Questions are asked + * in the order they are specified here. + * + * The resulting config.json file will be used by the server, accessed by the + * name specified. IE, a valid use is; config.adminName + * + */ + +const Questions = { + properties: { + tripSalt: { + description: 'Salt (leave as default)', + type: 'string', + hidden: true, + replace: '*', + before: value => { + salt = value; + return value; + } + }, + + adminName: { + description: 'Admin Nickname', + pattern: /^"?[a-zA-Z0-9_]+"?$/, + type: 'string', + message: 'Nicks can only contain letters, numbers and underscores', + before: value => value.replace(/"/g, '') + }, + + adminTrip: { + type: 'string', + hidden: true, + replace: '*', + description: 'Admin Password', + message: 'You must enter or re-enter a password', + before: value => { + const crypto = require('crypto'); + let sha = crypto.createHash('sha256'); + sha.update(value + salt); + return sha.digest('base64').substr(0, 6); + } + }, + + websocketPort: { + type: 'integer', + message: 'The port may only be a number!', + description: 'Websocket Port', + default: '6060' + } + } +} + +module.exports = Questions; -- cgit v1.2.1