diff --git a/meshcentral.js b/meshcentral.js index dcff8ab8..eae34229 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -79,7 +79,7 @@ function CreateMeshCentralServer(config, args) { try { require('./pass').hash('test', function () { }); } catch (e) { console.log('Old version of node, must upgrade.'); return; } // TODO: Not sure if this test works or not. // Check for invalid arguments - var validArguments = ['_', 'notls', 'user', 'port', 'aliasport', 'mpsport', 'mpsaliasport', 'redirport', 'cert', 'mpscert', 'deletedomain', 'deletedefaultdomain', 'showall', 'showusers', 'shownodes', 'showmeshes', 'showevents', 'showpower', 'clearpower', 'showiplocations', 'help', 'exactports', 'install', 'uninstall', 'start', 'stop', 'restart', 'debug', 'filespath', 'datapath', 'noagentupdate', 'launch', 'noserverbackup', 'mongodb', 'mongodbcol', 'wanonly', 'lanonly', 'nousers', 'mpsdebug', 'mpspass', 'ciralocalfqdn', 'dbexport', 'dbimport', 'selfupdate', 'tlsoffload', 'userallowedip', 'fastcert', 'swarmport', 'swarmdebug', 'logintoken', 'logintokenkey', 'logintokengen', 'logintokengen', 'mailtokengen', 'admin', 'unadmin']; + var validArguments = ['_', 'notls', 'user', 'port', 'aliasport', 'mpsport', 'mpsaliasport', 'redirport', 'cert', 'mpscert', 'deletedomain', 'deletedefaultdomain', 'showall', 'showusers', 'shownodes', 'showmeshes', 'showevents', 'showpower', 'clearpower', 'showiplocations', 'help', 'exactports', 'install', 'uninstall', 'start', 'stop', 'restart', 'debug', 'filespath', 'datapath', 'noagentupdate', 'launch', 'noserverbackup', 'mongodb', 'mongodbcol', 'wanonly', 'lanonly', 'nousers', 'mpsdebug', 'mpspass', 'ciralocalfqdn', 'dbexport', 'dbimport', 'selfupdate', 'tlsoffload', 'userallowedip', 'fastcert', 'swarmport', 'swarmdebug', 'logintoken', 'logintokenkey', 'logintokengen', 'logintokengen', 'mailtokengen', 'admin', 'unadmin', 'sessionkey', 'sessiontime']; for (var arg in obj.args) { obj.args[arg.toLocaleLowerCase()] = obj.args[arg]; if (validArguments.indexOf(arg.toLocaleLowerCase()) == -1) { console.log('Invalid argument "' + arg + '", use --help.'); return; } } if (obj.args.mongodb == true) { console.log('Must specify: --mongodb [connectionstring] \r\nSee https://docs.mongodb.com/manual/reference/connection-string/ for MongoDB connection string.'); return; } for (var i in obj.config.settings) { obj.args[i] = obj.config.settings[i]; } // Place all settings into arguments, arguments have already been placed into settings so arguments take precedence. @@ -419,13 +419,12 @@ function CreateMeshCentralServer(config, args) { // If the server is set to "nousers", allow only loopback unless IP filter is set if ((obj.args.nousers == true) && (obj.args.userallowedip == null)) { obj.args.userallowedip = "::1,127.0.0.1"; } - if (obj.args.secret) { - // This secret is used to encrypt HTTP session information, if specified, user it. - obj.webserver = require('./webserver.js').CreateWebServer(obj, obj.db, obj.args, obj.args.secret, obj.certificates); - } else { - // If the secret is not specified, generate a random number. - obj.webserver = require('./webserver.js').CreateWebServer(obj, obj.db, obj.args, buf.toString('hex').toUpperCase(), obj.certificates); - } + // Set the session length to 60 minutes if not set and set a random key if needed + if ((obj.args.sessiontime == null) || (typeof obj.args.sessiontime != 'number') || (obj.args.sessiontime < 1)) { obj.args.sessiontime = 60; } + if (!obj.args.sessionkey) { obj.args.sessionkey = buf.toString('hex').toUpperCase(); } + + // Start eh web server and if needed, the redirection web server. + obj.webserver = require('./webserver.js').CreateWebServer(obj, obj.db, obj.args, obj.certificates); if (obj.redirserver != null) { obj.redirserver.hookMainWebServer(obj.certificates); } // Setup the Intel AMT event handler diff --git a/package.json b/package.json index b7f74bf3..2575bfaf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.1.9-k", + "version": "0.1.9-m", "keywords": [ "Remote Management", "Intel AMT", @@ -30,6 +30,7 @@ "body-parser": "^1.18.2", "compression": "^1.7.1", "connect-redis": "^3.3.3", + "cookie-session": "^2.0.0-beta.3", "express": "^4.16.2", "express-handlebars": "^3.0.0", "express-session": "^1.15.6", @@ -43,7 +44,7 @@ "xmldom": "^0.1.27", "yauzl": "^2.9.1" }, - "devDependencies": { }, + "devDependencies": {}, "repository": { "type": "git", "url": "https://github.com/Ylianst/MeshCentral.git" diff --git a/sample-config.json b/sample-config.json index fa94978d..77fae33b 100644 --- a/sample-config.json +++ b/sample-config.json @@ -5,6 +5,8 @@ "_MongoDbCol": "meshcentral", "_WANonly": true, "_LANonly": true, + "_SessionTime": 30, + "_SessionKey": "MyReallySecretPassword", "_Port": 443, "_RedirPort": 80, "_AllowLoginToken": true, diff --git a/views/default.handlebars b/views/default.handlebars index dd616097..7d6da388 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -5174,7 +5174,7 @@ if (maxUsers > 0) { if (addHeader) { x += '
Username: | +Username: | |
Email: | +Email: | |
Password: | +Password: | |
Password: | +Password: | |
Password Hint: | +Password Hint: | |
Creation Token: | +Creation Token: | |