From 85d7ced6052499cb3fa56563d3a09b098bfce4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Tabarra?= Date: Sun, 30 Jun 2019 10:22:55 -0300 Subject: [PATCH 1/2] check packages and node version --- README.md | 2 +- src/extras/testUtils.js | 56 +++++++++++++++++++++++++++++++++++++++++ src/index.js | 14 ++++++----- 3 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 src/extras/testUtils.js diff --git a/README.md b/README.md index ad2bfc7eb..6ff3f0301 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ If you have any problems with `package-lock.json`, just delete it and try again. - [ ] Write version bumper script - [ ] Write resource injector - [ ] Add custom commands to the config file -- [ ] Config tester check for the modules inside `package.json` (require.resolve?) +- [x] Config tester check for the modules inside `package.json` (require.resolve?) - [ ] Config tester kill spawned fxserver after 5 seconds - [ ] Investigate the "fxserver has stopped working" not disappearing when autorestarter kills the server (probably windows detaches it? in that case we would need to PID map and then kill them one by one?) diff --git a/src/extras/testUtils.js b/src/extras/testUtils.js new file mode 100644 index 000000000..c91ee2350 --- /dev/null +++ b/src/extras/testUtils.js @@ -0,0 +1,56 @@ +//Requires +const fs = require('fs'); +const { dir, log, logOk, logWarn, logError, cleanTerminal } = require('./console'); +const context = 'TestUtils'; + + +//================================================================ +/** + * Check if running on NodeJS v10 LTS + */ +function nodeVersionChecker(){ + if(!process.version.startsWith('v10.')){ + cleanTerminal(); + logError(`FATAL ERROR: txAdmin doesn't support NodeJS ${process.version}, please install NodeJS v10 LTS!`, 'NodeVersionChecker'); + process.exit(); + } +} + + +//================================================================ +/** + * Check if the packages in package.json were installed + */ +function moduleInstallChecker() { + let errorOut; + try { + let rawFile = fs.readFileSync('package.json'); + let parsedFile = JSON.parse(rawFile); + let packages = Object.keys(parsedFile.dependencies) + let missing = []; + packages.forEach(package => { + try { + require.resolve(package); + } catch (error) { + missing.push(package); + } + }); + if(missing.length){ + errorOut = `The following packages are missing, make sure you executed 'npm i':\n` + missing.join(', '); + } + } catch (error) { + errorOut = `Error reading or parsing package.json: ${error.message}`; + } + + if(errorOut){ + logError(errorOut, 'PackageChecker'); + process.exit(); + } +} + + + +module.exports = { + nodeVersionChecker, + moduleInstallChecker, +} diff --git a/src/index.js b/src/index.js index 10919c5fe..cd996db9a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,7 @@ //Requires const { dir, log, logOk, logWarn, logError, cleanTerminal } = require('./extras/console'); +const testUtils = require('./extras/testUtils'); -//NOTE: temp node version checker -if(!process.version.startsWith('v10.')){ - cleanTerminal(); - logError(`FATAL ERROR: txAdmin doesn't support NodeJS ${process.version}, please install NodeJS v10 LTS!`); - process.exit(); -} //============================================================== //FIXME: I should be using dependency injection or something @@ -28,6 +23,7 @@ globals = { resourceNotFound: null //FIXME: temp hack } + //============================================================== class txAdmin { constructor(){ @@ -40,6 +36,10 @@ class txAdmin { console.log(motd); log(">>Starting txAdmin"); + //Check node version and packages + testUtils.nodeVersionChecker(); + testUtils.moduleInstallChecker(); + //Prepare settings let localConfig = require('./extras/config'); globals.config = localConfig.global; @@ -140,9 +140,11 @@ function HandleFatalError(err, context){ process.exit(); } + process.stdin.on('error', (data) => {}); process.stdout.on('error', (data) => {}); process.stderr.on('error', (data) => {}); + process.on('unhandledRejection', (err) => { logError(">>Ohh nooooo - unhandledRejection") logError(err.message) From aabfa67b9ba36f5598b80a219cba48dad73c33c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Tabarra?= Date: Sun, 30 Jun 2019 16:12:03 -0300 Subject: [PATCH 2/2] Hotfix for the login problems. Node version checker --- plan.md | 73 ++++++++++++++++++++------------- src/components/authenticator.js | 2 +- src/extras/testUtils.js | 2 +- version.json | 6 ++- 4 files changed, 52 insertions(+), 31 deletions(-) diff --git a/plan.md b/plan.md index e7a100c75..4ad96cb6e 100644 --- a/plan.md +++ b/plan.md @@ -1,35 +1,52 @@ +## Instructions +```bash +# Install +$ git clone https://github.com/tabarra/txAdmin && cd txAdmin +$ npm i -//FIXME: change config.json name, cant be both named the same - -data/ - config.json (web port, admins) - example/ - config.json - messages.json - commands.json - data/ - players.json - admin.log - FXServer.log - txAdmin_errors.log -extensions/ ? -setup.js -start.js -start.bat - - -setup.js: - checkup node version - check packages +# Add admin +$ node src/scripts/admin-add.js + +# Setup default server +$ node src/scripts/setup.js default + +# Start default server +$ node src/index.js default +``` + +## TODO: +- [x] adapt admin-add +- [ ] adapt config-tester +- [ ] adapt main +- [ ] xxx +- [ ] xxx + + +## Folder Structure + data/ + admins.json + example/ + config.json + messages.json + commands.json + data/ + players.json + admin.log + FXServer.log + txAdmin_errors.log + extensions/ (?) + start_default.bat + + + +## setup.js + check node version & packages + check for existing settings and --overwrite start setup webpage asking for: - login/password - first server config (paths & etc) + basic server config (paths & etc) check if the configs are correct save data/config.json with password save the server config as data/default -start.js: - checkup node version - check packages - start txadmin with the 'default' server config (or argv) + diff --git a/src/components/authenticator.js b/src/components/authenticator.js index 76d8ab32e..f8ee080cb 100644 --- a/src/components/authenticator.js +++ b/src/components/authenticator.js @@ -29,7 +29,7 @@ module.exports = class Authenticator { checkAuth(uname, pwd){ let username = uname.toLowerCase(); let admin = this.admins.find((user) => { - return (username === user.name && bcrypt.compareSync(pwd, user.password_hash)) + return (username === user.name.toLowerCase() && bcrypt.compareSync(pwd, user.password_hash)) }); return (admin)? admin : false; } diff --git a/src/extras/testUtils.js b/src/extras/testUtils.js index c91ee2350..931a0e671 100644 --- a/src/extras/testUtils.js +++ b/src/extras/testUtils.js @@ -36,7 +36,7 @@ function moduleInstallChecker() { } }); if(missing.length){ - errorOut = `The following packages are missing, make sure you executed 'npm i':\n` + missing.join(', '); + errorOut = `Make sure you executed 'npm i'. The following packages are missing:\n` + missing.join(', '); } } catch (error) { errorOut = `Error reading or parsing package.json: ${error.message}`; diff --git a/version.json b/version.json index 0ea47f85e..103339be0 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "1.0.4", + "version": "1.0.5", "changelog": "New Interface and too many new features to list here. Please Update.", "allVersions": [ { @@ -21,6 +21,10 @@ { "version": "1.0.4", "changelog": "Fixed crashing on fxserver restart." + }, + { + "version": "1.0.5", + "changelog": "Hotfix for the login problems. Node version checker" } ] }