mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-02-24 20:09:11 -05:00
Factor logincookie, changelang
This commit is contained in:
parent
bb81de62db
commit
8bf0112423
73
meshuser.js
73
meshuser.js
@ -656,14 +656,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
|
|
||||||
// TODO: Send the message of user sessions connected to other servers.
|
// TODO: Send the message of user sessions connected to other servers.
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'logincookie':
|
|
||||||
{
|
|
||||||
// If allowed, return a login cookie
|
|
||||||
if (parent.parent.config.settings.allowlogintoken === true) {
|
|
||||||
try { ws.send(JSON.stringify({ action: 'logincookie', cookie: parent.parent.encodeCookie({ u: user._id, a: 3 }, parent.parent.loginCookieEncryptionKey) })); } catch (ex) { }
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'servertimelinestats':
|
case 'servertimelinestats':
|
||||||
@ -1041,35 +1033,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'changelang':
|
|
||||||
{
|
|
||||||
// Do not allow this command when logged in using a login token
|
|
||||||
if (req.session.loginToken != null) break;
|
|
||||||
|
|
||||||
// If this account is settings locked, return here.
|
|
||||||
if ((user.siteadmin != 0xFFFFFFFF) && ((user.siteadmin & 1024) != 0)) return;
|
|
||||||
|
|
||||||
if (common.validateString(command.lang, 1, 6) == false) return;
|
|
||||||
|
|
||||||
// Always lowercase the language
|
|
||||||
command.lang = command.lang.toLowerCase();
|
|
||||||
|
|
||||||
// Update the user's language
|
|
||||||
var oldlang = user.lang;
|
|
||||||
if (command.lang == '*') { delete user.lang; } else { user.lang = command.lang; }
|
|
||||||
parent.db.SetUser(user);
|
|
||||||
|
|
||||||
// Event the change
|
|
||||||
var message = { etype: 'user', userid: user._id, username: user.name, account: parent.CloneSafeUser(user), action: 'accountchange', domain: domain.id, msgid: 2, msgArgs: [(oldlang ? oldlang : 'default'), (user.lang ? user.lang : 'default')] };
|
|
||||||
if (db.changeStream) { message.noact = 1; } // If DB change stream is active, don't use this event to change the user. Another event will come.
|
|
||||||
message.msg = 'Changed language from ' + (oldlang ? oldlang : 'default') + ' to ' + (user.lang ? user.lang : 'default');
|
|
||||||
|
|
||||||
var targets = ['*', 'server-users', user._id];
|
|
||||||
if (user.groups) { for (var i in user.groups) { targets.push('server-users:' + i); } }
|
|
||||||
parent.parent.DispatchEvent(targets, obj, message);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'changeemail':
|
case 'changeemail':
|
||||||
{
|
{
|
||||||
// Do not allow this command when logged in using a login token
|
// Do not allow this command when logged in using a login token
|
||||||
@ -5454,12 +5417,14 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
'adduserbatch': serverCommandAddUserBatch,
|
'adduserbatch': serverCommandAddUserBatch,
|
||||||
'addusertousergroup': serverCommandAddUserToUserGroup,
|
'addusertousergroup': serverCommandAddUserToUserGroup,
|
||||||
'authcookie': serverCommandAuthCookie,
|
'authcookie': serverCommandAuthCookie,
|
||||||
|
'changelang': serverCommandChangeLang,
|
||||||
'files': serverCommandFiles,
|
'files': serverCommandFiles,
|
||||||
'getnetworkinfo': serverCommandGetNetworkInfo,
|
'getnetworkinfo': serverCommandGetNetworkInfo,
|
||||||
'getsysinfo': serverCommandGetSysInfo,
|
'getsysinfo': serverCommandGetSysInfo,
|
||||||
'intersession': serverCommandInterSession,
|
'intersession': serverCommandInterSession,
|
||||||
'lastconnect': serverCommandLastConnect,
|
'lastconnect': serverCommandLastConnect,
|
||||||
'lastconnects': serverCommandLastConnects,
|
'lastconnects': serverCommandLastConnects,
|
||||||
|
'logincookie': serverCommandLoginCookie,
|
||||||
'meshes': serverCommandMeshes,
|
'meshes': serverCommandMeshes,
|
||||||
'ping': serverCommandPing,
|
'ping': serverCommandPing,
|
||||||
'pong': serverCommandPong,
|
'pong': serverCommandPong,
|
||||||
@ -5828,6 +5793,33 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
} catch (ex) { }
|
} catch (ex) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function serverCommandChangeLang(command) {
|
||||||
|
// Do not allow this command when logged in using a login token
|
||||||
|
if (req.session.loginToken != null) return;
|
||||||
|
|
||||||
|
// If this account is settings locked, return here.
|
||||||
|
if ((user.siteadmin != 0xFFFFFFFF) && ((user.siteadmin & 1024) != 0)) return;
|
||||||
|
|
||||||
|
if (common.validateString(command.lang, 1, 6) == false) return;
|
||||||
|
|
||||||
|
// Always lowercase the language
|
||||||
|
command.lang = command.lang.toLowerCase();
|
||||||
|
|
||||||
|
// Update the user's language
|
||||||
|
var oldlang = user.lang;
|
||||||
|
if (command.lang == '*') { delete user.lang; } else { user.lang = command.lang; }
|
||||||
|
parent.db.SetUser(user);
|
||||||
|
|
||||||
|
// Event the change
|
||||||
|
var message = { etype: 'user', userid: user._id, username: user.name, account: parent.CloneSafeUser(user), action: 'accountchange', domain: domain.id, msgid: 2, msgArgs: [(oldlang ? oldlang : 'default'), (user.lang ? user.lang : 'default')] };
|
||||||
|
if (db.changeStream) { message.noact = 1; } // If DB change stream is active, don't use this event to change the user. Another event will come.
|
||||||
|
message.msg = 'Changed language from ' + (oldlang ? oldlang : 'default') + ' to ' + (user.lang ? user.lang : 'default');
|
||||||
|
|
||||||
|
var targets = ['*', 'server-users', user._id];
|
||||||
|
if (user.groups) { for (var i in user.groups) { targets.push('server-users:' + i); } }
|
||||||
|
parent.parent.DispatchEvent(targets, obj, message);
|
||||||
|
}
|
||||||
|
|
||||||
function serverCommandFiles(command) {
|
function serverCommandFiles(command) {
|
||||||
// Send the full list of server files to the browser app
|
// Send the full list of server files to the browser app
|
||||||
updateUserFiles(user, ws, domain);
|
updateUserFiles(user, ws, domain);
|
||||||
@ -5932,6 +5924,13 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function serverCommandLoginCookie(command) {
|
||||||
|
// If allowed, return a login cookie
|
||||||
|
if (parent.parent.config.settings.allowlogintoken === true) {
|
||||||
|
try { ws.send(JSON.stringify({ action: 'logincookie', cookie: parent.parent.encodeCookie({ u: user._id, a: 3 }, parent.parent.loginCookieEncryptionKey) })); } catch (ex) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function serverCommandMeshes(command) {
|
function serverCommandMeshes(command) {
|
||||||
// Request a list of all meshes this user as rights to
|
// Request a list of all meshes this user as rights to
|
||||||
try { ws.send(JSON.stringify({ action: 'meshes', meshes: parent.GetAllMeshWithRights(user).map(parent.CloneSafeMesh), tag: command.tag })); } catch (ex) { }
|
try { ws.send(JSON.stringify({ action: 'meshes', meshes: parent.GetAllMeshWithRights(user).map(parent.CloneSafeMesh), tag: command.tag })); } catch (ex) { }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user