1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

ldapUserName and ldapUserRealname can now be set to for example: {{{givenName}}} {{{sn}}} (#4276)

This commit is contained in:
Ylian Saint-Hilaire 2022-07-20 00:50:32 -07:00
parent 58cd5e3bea
commit b7bc172c40
2 changed files with 86 additions and 66 deletions

View file

@ -453,7 +453,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
// Work on getting the userid for this LDAP user
var shortname = null;
var username = xxuser['displayName'];
if (domain.ldapusername) { username = xxuser[domain.ldapusername]; }
if (typeof domain.ldapusername == 'string') {
if (domain.ldapusername.indexOf('{{{') >= 0) { username = assembleStringFromObject(domain.ldapusername, xxuser); } else { username = xxuser[domain.ldapusername]; }
}
if (domain.ldapuserbinarykey) {
// Use a binary key as the userid
if (xxuser[domain.ldapuserbinarykey]) { shortname = Buffer.from(xxuser[domain.ldapuserbinarykey], 'binary').toString('hex').toLowerCase(); }
@ -474,12 +476,14 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
// Get the email address for this LDAP user
var email = null;
if (domain.ldapuseremail) { email = xxuser[domain.ldapuseremail]; } else if (xxuser.mail) { email = xxuser.mail; } // Use given feild name or default
if ('[object Array]' == Object.prototype.toString.call(email)) { email = email[0]; } // Mail may be multivalued in LDAP in which case, answer is an array. Use the 1st value.
if (Array.isArray(email)) { email = email[0]; } // Mail may be multivalued in LDAP in which case, answer is an array. Use the 1st value.
if (email) { email = email.toLowerCase(); } // it seems some code elsewhere also lowercase the emailaddress, so let's be consistant.
// Get the real name for this LDAP user
var realname = null;
if (domain.ldapuserrealname) { realname = xxuser[domain.ldapuserrealname]; }
if (typeof domain.ldapuserrealname == 'string') {
if (domain.ldapuserrealname.indexOf('{{{') >= 0) { realname = assembleStringFromObject(domain.ldapuserrealname, xxuser); } else { realname = xxuser[domain.ldapuserrealname]; }
}
else { if (typeof xxuser['name'] == 'string') { realname = xxuser['name']; } }
// Get the phone number for this LDAP user
@ -500,6 +504,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
// Display user information extracted from LDAP data
/*
console.log('shortname', shortname);
console.log('username', username);
console.log('email', email);
console.log('realname', realname);
console.log('phonenumber', phonenumber);
@ -8537,5 +8542,14 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
return require('ipcheck').match(cookieip, ip + '/24'); // 'lax' - IP address need to be in the some range
}
// Takes a formating string like "this {{{a}}} is an {{{b}}} example" and fills the a and b with input o.a and o.b
function assembleStringFromObject(format, o) {
var r = '', i = format.indexOf('{{{');
if (i > 0) { r = format.substring(0, i); format = format.substring(i); }
const cmd = format.split('{{{');
for (var j in cmd) { if (j == 0) continue; i = cmd[j].indexOf('}}}'); r += o[cmd[j].substring(0, i)] + cmd[j].substring(i + 3); }
return r;
}
return obj;
};