Added automatic password generation on first run.

This commit is contained in:
empathicqubit 2018-05-29 00:30:22 -04:00
parent 5e9516cb0c
commit c4a2ef6ac3
7 changed files with 64 additions and 12 deletions

View file

@ -1,2 +1 @@
AUDIO_FILES_ARRAY=["24Tracks2.ogg", "24TracksShouldBeEnoughForAnybody.ogg", "DesmillahHi-VariousVocalEffects-Guitar-AnyoneCanSee.ogg", "Guitar-VocalEffects-Accents.ogg", "HgInt-Desmillah-Etc-Guitar-Hi.ogg", "HgIntHi-GottaGetOut-VariousVocalEffects-Guitar-NothingMatters.ogg", "HgOpenYourEyesIDontWannaDie-Skaramoush-Drums-NoNoNo.ogg", "HgWhatever.ogg", "HiVocalEffects.ogg", "Mix-5.ogg", "Mix-6.ogg", "Mix-Bass.ogg", "Mix-DrumKit.ogg", "Mix-Harmonizing.ogg", "Mix-Piano.ogg"]
ADMIN_PASSWORD=3L6rsLFeTTRDPo1hpCHi0rjq9lBSBTie

View file

@ -1,4 +1,3 @@
module.exports = {
files: JSON.parse(process.env.AUDIO_FILES_ARRAY),
password: process.env.ADMIN_PASSWORD,
};

View file

@ -65,8 +65,8 @@ function getProps (render) {
sources: [],
realPosition: 0,
clientId: 0,
x: 0,
y: 0,
x: Math.floor(Math.random() * 400),
y: Math.floor(Math.random() * 400),
onDrag: (evt, data) => {
updateX(data.x);
updateY(data.y);

View file

@ -181,10 +181,13 @@ class Admin extends React.Component {
<p>
This interface allows you to control the state of connected clients; which tracks are playing as well as the pan and gain for each track.
</p>
<p>
The password for this interface is echoed to the command line. Look for the text &quot;ADMIN PASSWORD&quot; surrounded by equals signs.
</p>
{!this.state.passwordSubmitted
? (
<div className="password-input">
Enter password: <input type="text" value={this.state.password} onChange={ (evt) => this.changePassword(evt.target.value) } />
Enter admin password: <input type="text" value={this.state.password} onChange={ (evt) => this.changePassword(evt.target.value) } />
<button onClick={ () => this.submitPassword() }>
Submit
</button>

View file

@ -7,7 +7,6 @@
"debug": "npm-run-all --parallel debug-frontend debug-server",
"debug-server": "nodemon --inspect-brk=0.0.0.0:9229 ./index.js",
"debug-frontend": "cd ./frontend && yarn install && yarn run start",
"start": "npm-run-all --parallel frontend server",
"frontend": "cd ./frontend && yarn install && yarn run build && npx static-html-server -p 3000 -r ./build -f index.html",
"server": "node ./index.js"
@ -21,6 +20,7 @@
"music-metadata": "^1.1.0",
"node-storage": "^0.0.7",
"npm-run-all": "^4.1.2",
"password-generator": "^2.2.0",
"q": "^1.5.1",
"serve": "^6.5.7",
"ws": "^4.0.0"

49
ws.js
View file

@ -6,19 +6,21 @@ const fs = require('fs');
const cors = require('cors');
const execFile = q.denodeify(require('child_process').execFile);
const path = require('path');
const statSync = require('fs').statSync;
const lowdb = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
const readFile = q.denodeify(fs.readFile);
const passwordGenerator = require('password-generator');
let PASSWORD = require('./config').password;
const storagePath = path.join(__dirname, 'storage.json');
let storage = lowdb(new FileSync(path.join(__dirname, 'storage.json')));
let storage = lowdb(new FileSync(storagePath));
let _savedSources = storage.get('savedSources').value();
const savedSources = (set) => {
if(set) {
_savedSources = set
_savedSources = set;
storage.set('savedSources', _savedSources).write();
}
@ -27,6 +29,34 @@ const savedSources = (set) => {
_savedSources = _savedSources || savedSources({});
let _adminPassword = storage.get('adminPassword').value();
const adminPassword = (set) => {
if(set) {
_adminPassword = set;
storage.set('adminPassword', _adminPassword).write();
}
return _adminPassword;
};
_adminPassword = _adminPassword || adminPassword(passwordGenerator(32));
const logAdminPassword = () => {
let adminLogLine = 'ADMIN PASSWORD: ' + adminPassword();
let formatLine = Array(adminLogLine.length).join('=');
console.log();
console.log(formatLine);
console.log();
console.log(adminLogLine);
console.log();
console.log(formatLine);
console.log();
}
let adminPasswordRepeated = false;
let poller;
let startTime;
let audioLength;
@ -110,6 +140,12 @@ const initServer = () => {
});
wsServer.on('connection', (client, req) => {
// Only repeat the password once.
if(!adminPasswordRepeated) {
logAdminPassword();
adminPasswordRepeated = true;
}
client.admin = false;
client.sources = [];
client.id = Math.floor(Math.random() * 1000000);
@ -148,11 +184,15 @@ const initServer = () => {
}
else if(data.type == 'hello_admin') {
// Gecting the password wrong shouldn't cause a disconnect.
if(data.password == PASSWORD) {
if(data.password == adminPassword()) {
wsSend(client, data);
client.hello = client.admin = true;
}
else {
console.log();
console.log('An invalid password was entered!');
}
}
else if(!client.hello) {
client.close();
@ -270,7 +310,6 @@ module.exports = {
savedSources(_savedSources);
}
if(!wsServer) {
initServer();
}

View file

@ -280,7 +280,7 @@ camelcase@^1.0.2:
version "1.2.1"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39"
camelcase@^4.0.0:
camelcase@^4.0.0, camelcase@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd"
@ -1733,6 +1733,12 @@ parseurl@~1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.2.tgz#fc289d4ed8993119460c156253262cdc8de65bf3"
password-generator@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/password-generator/-/password-generator-2.2.0.tgz#fc75cff795110923e054a5a71623433240bf5e49"
dependencies:
yargs-parser "^8.0.0"
path-is-absolute@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
@ -2544,6 +2550,12 @@ yallist@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
yargs-parser@^8.0.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-8.1.0.tgz#f1376a33b6629a5d063782944da732631e966950"
dependencies:
camelcase "^4.1.0"
yargs@~3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1"