Merge pull request #3232 from michael-dev/develop

Make APIKEY and SESSIONKEY file customizable
This commit is contained in:
John McLear 2018-04-03 13:34:49 +01:00 committed by GitHub
commit d393bf4dd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View File

@ -24,17 +24,19 @@ var fs = require("fs");
var api = require("../db/API");
var padManager = require("../db/PadManager");
var randomString = require("../utils/randomstring");
var argv = require('../utils/Cli').argv;
//ensure we have an apikey
var apikey = null;
var apikeyFilename = argv.apikey || "./APIKEY.txt";
try
{
apikey = fs.readFileSync("./APIKEY.txt","utf8");
apikey = fs.readFileSync(apikeyFilename,"utf8");
}
catch(e)
{
apikey = randomString(32);
fs.writeFileSync("./APIKEY.txt",apikey,"utf8");
fs.writeFileSync(apikeyFilename,apikey,"utf8");
}
//a list of all functions

View File

@ -39,5 +39,15 @@ for ( var i = 0; i < argv.length; i++ ) {
exports.argv.credentials = arg;
}
// Override location of settings.json file
if ( prevArg == '--sessionkey' || prevArg == '-k' ) {
exports.argv.sessionkey = arg;
}
// Override location of settings.json file
if ( prevArg == '--apikey' || prevArg == '-k' ) {
exports.argv.apikey = arg;
}
prevArg = arg;
}

View File

@ -476,11 +476,12 @@ exports.reloadSettings = function reloadSettings() {
}
if (!exports.sessionKey) {
var sessionkeyFilename = argv.sessionkey || "./SESSIONKEY.txt";
try {
exports.sessionKey = fs.readFileSync("./SESSIONKEY.txt","utf8");
exports.sessionKey = fs.readFileSync(sessionkeyFilename,"utf8");
} catch(e) {
exports.sessionKey = randomString(32);
fs.writeFileSync("./SESSIONKEY.txt",exports.sessionKey,"utf8");
fs.writeFileSync(sessionkeyFilename,exports.sessionKey,"utf8");
}
} else {
console.warn("Declaring the sessionKey in the settings.json is deprecated. This value is auto-generated now. Please remove the setting from the file.");