Added User Web State control on config.json.

This commit is contained in:
Ylian Saint-Hilaire 2020-02-27 18:05:18 -08:00
parent 84964bead4
commit dadb3ae1d4
5 changed files with 18 additions and 19 deletions

View File

@ -541,7 +541,7 @@ function CreateMeshCentralServer(config, args) {
// Lower case all keys in the config file // Lower case all keys in the config file
try { try {
require('./common.js').objKeysToLower(config2, ["ldapoptions"]); require('./common.js').objKeysToLower(config2, ['ldapoptions', 'defaultuserwebstate', 'forceduserwebstate']);
} catch (ex) { } catch (ex) {
console.log('CRITICAL ERROR: Unable to access the file \"./common.js\".\r\nCheck folder & file permissions.'); console.log('CRITICAL ERROR: Unable to access the file \"./common.js\".\r\nCheck folder & file permissions.');
process.exit(); process.exit();
@ -830,7 +830,7 @@ function CreateMeshCentralServer(config, args) {
// Lower case all keys in the config file // Lower case all keys in the config file
try { try {
require('./common.js').objKeysToLower(config2, ['ldapoptions']); require('./common.js').objKeysToLower(config2, ['ldapoptions', 'defaultuserwebstate', 'forceduserwebstate']);
} catch (ex) { } catch (ex) {
console.log("CRITICAL ERROR: Unable to access the file \"./common.js\".\r\nCheck folder & file permissions."); console.log("CRITICAL ERROR: Unable to access the file \"./common.js\".\r\nCheck folder & file permissions.");
process.exit(); process.exit();
@ -2266,7 +2266,7 @@ function getConfig(createSampleConfig) {
// Lower case all keys in the config file // Lower case all keys in the config file
try { try {
require('./common.js').objKeysToLower(config, ["ldapoptions"]); require('./common.js').objKeysToLower(config, ['ldapoptions', 'defaultuserwebstate', 'forceduserwebstate']);
} catch (ex) { } catch (ex) {
console.log('CRITICAL ERROR: Unable to access the file \"./common.js\".\r\nCheck folder & file permissions.'); console.log('CRITICAL ERROR: Unable to access the file \"./common.js\".\r\nCheck folder & file permissions.');
process.exit(); process.exit();

View File

@ -1,6 +1,6 @@
{ {
"name": "meshcentral", "name": "meshcentral",
"version": "0.4.9-m", "version": "0.4.9-n",
"keywords": [ "keywords": [
"Remote Management", "Remote Management",
"Intel AMT", "Intel AMT",

View File

@ -3636,7 +3636,7 @@
"pt": "Erro de chamada", "pt": "Erro de chamada",
"ru": "Ошибка вызова", "ru": "Ошибка вызова",
"xloc": [ "xloc": [
"default.handlebars->27->1480" "default.handlebars->27->1477"
] ]
}, },
{ {
@ -8824,10 +8824,7 @@
}, },
{ {
"en": "Illegal invocation", "en": "Illegal invocation",
"nl": "Ongeldige aanroep", "nl": "Ongeldige aanroep"
"xloc": [
"default.handlebars->27->1478"
]
}, },
{ {
"cs": "Kódovaní obrazu", "cs": "Kódovaní obrazu",
@ -10393,7 +10390,7 @@
"pt": "Menos", "pt": "Menos",
"ru": "Меньше", "ru": "Меньше",
"xloc": [ "xloc": [
"default.handlebars->27->1482" "default.handlebars->27->1479"
] ]
}, },
{ {
@ -12016,7 +12013,7 @@
"pt": "Mais", "pt": "Mais",
"ru": "Еще", "ru": "Еще",
"xloc": [ "xloc": [
"default.handlebars->27->1481" "default.handlebars->27->1478"
] ]
}, },
{ {
@ -20615,10 +20612,7 @@
}, },
{ {
"en": "encoding", "en": "encoding",
"nl": "codering", "nl": "codering"
"xloc": [
"default.handlebars->27->1477"
]
}, },
{ {
"cs": "eventslist.csv", "cs": "eventslist.csv",
@ -21001,10 +20995,7 @@
}, },
{ {
"en": "undefined", "en": "undefined",
"nl": "onbepaald", "nl": "onbepaald"
"xloc": [
"default.handlebars->27->1479"
]
}, },
{ {
"cs": "uživatel:", "cs": "uživatel:",

View File

@ -1128,6 +1128,7 @@
var webState = '{{{webstate}}}'; var webState = '{{{webstate}}}';
if (webState != '') { webState = JSON.parse(decodeURIComponent(webState)); } if (webState != '') { webState = JSON.parse(decodeURIComponent(webState)); }
for (var i in webState) { localStorage.setItem(i, webState[i]); } for (var i in webState) { localStorage.setItem(i, webState[i]); }
if (webState.deviceView != null) { localStorage.setItem('_deviceView', webState.deviceView); }
if (!webState.loctag) { try { delete localStorage.removeItem('loctag'); } catch (ex) { } } if (!webState.loctag) { try { delete localStorage.removeItem('loctag'); } catch (ex) { } }
var args, urlargs; var args, urlargs;

View File

@ -1590,6 +1590,13 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
parent.debug('web', 'handleRootRequestEx: success.'); parent.debug('web', 'handleRootRequestEx: success.');
obj.db.Get('ws' + user._id, function (err, states) { obj.db.Get('ws' + user._id, function (err, states) {
var webstate = (states.length == 1) ? obj.filterUserWebState(states[0].state) : ''; var webstate = (states.length == 1) ? obj.filterUserWebState(states[0].state) : '';
if ((webstate == '') && (typeof domain.defaultuserwebstate == 'object')) { webstate = JSON.stringify(domain.defaultuserwebstate); } // User has no web state, use defaults.
if (typeof domain.forceduserwebstate == 'object') { // Forces initial user web state is present, use it.
var webstate2 = {};
try { if (webstate != '') { webstate2 = JSON.parse(webstate); } } catch (ex) { }
for (var i in domain.forceduserwebstate) { webstate2[i] = domain.forceduserwebstate[i]; }
webstate = JSON.stringify(webstate2);
}
render(req, res, getRenderPage('default', req), getRenderArgs({ authCookie: authCookie, authRelayCookie: authRelayCookie, viewmode: viewmode, currentNode: currentNode, logoutControls: JSON.stringify(logoutcontrols), domain: domain.id, debuglevel: parent.debugLevel, serverDnsName: obj.getWebServerName(domain), serverRedirPort: args.redirport, serverPublicPort: httpsPort, noServerBackup: (args.noserverbackup == 1 ? 1 : 0), features: features, sessiontime: args.sessiontime, mpspass: args.mpspass, passRequirements: passRequirements, webcerthash: Buffer.from(obj.webCertificateFullHashs[domain.id], 'binary').toString('base64').replace(/\+/g, '@').replace(/\//g, '$'), footer: (domain.footer == null) ? '' : domain.footer, webstate: encodeURIComponent(webstate), pluginHandler: (parent.pluginHandler == null) ? 'null' : parent.pluginHandler.prepExports(), StartGeoLocation: StartGeoLocation, EndGeoLocation: EndGeoLocation, StartGeoLocationJS: StartGeoLocationJS, EndGeoLocationJS: EndGeoLocationJS }, domain)); render(req, res, getRenderPage('default', req), getRenderArgs({ authCookie: authCookie, authRelayCookie: authRelayCookie, viewmode: viewmode, currentNode: currentNode, logoutControls: JSON.stringify(logoutcontrols), domain: domain.id, debuglevel: parent.debugLevel, serverDnsName: obj.getWebServerName(domain), serverRedirPort: args.redirport, serverPublicPort: httpsPort, noServerBackup: (args.noserverbackup == 1 ? 1 : 0), features: features, sessiontime: args.sessiontime, mpspass: args.mpspass, passRequirements: passRequirements, webcerthash: Buffer.from(obj.webCertificateFullHashs[domain.id], 'binary').toString('base64').replace(/\+/g, '@').replace(/\//g, '$'), footer: (domain.footer == null) ? '' : domain.footer, webstate: encodeURIComponent(webstate), pluginHandler: (parent.pluginHandler == null) ? 'null' : parent.pluginHandler.prepExports(), StartGeoLocation: StartGeoLocation, EndGeoLocation: EndGeoLocation, StartGeoLocationJS: StartGeoLocationJS, EndGeoLocationJS: EndGeoLocationJS }, domain));
}); });
} else { } else {