Skip to content

Instantly share code, notes, and snippets.

@elliottwilliams
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliottwilliams/a91b310c4fd8a142c2d0 to your computer and use it in GitHub Desktop.
Save elliottwilliams/a91b310c4fd8a142c2d0 to your computer and use it in GitHub Desktop.
Detecting collisions in OpenMRS ID LDAP email addresses
var fs = require('fs');
var _ = require('lodash');
var xml2js = require('xml2js');
var async = require('async');
var emails = {};
var users = {};
var primary = fs.readFileSync('./primaryemails').toString();
var secondary = fs.readFileSync('./secondaryemails').toString();
var all = primary + '\n' + secondary;
var currentUser;
all.split('\n')
.forEach(function(line) {
if (line.indexOf('dn: ') === 0) {
currentUser = line.split('dn: ')[1];
users[currentUser] = users[currentUser] || [];
} else {
var m;
var write = false;
var type;
if (line.indexOf('mail: ') === 0) {
type = 'primary';
m = line.split('mail: ')[1];
write = true;
} else if (line.indexOf('otherMailbox: ') === 0) {
type = 'secondary';
m = line.split('otherMailbox: ')[1];
write = true;
}
if (write) {
emails[m] = emails[m] || [];
emails[m].push(currentUser);
}
}
});
emails = _.omit(emails, function(users) {
return users.length < 2;
});
var pairs = [];
_.forIn(emails, function(usersWithThisAddress, email) {
usersWithThisAddress.forEach(function(u) {
var uid = /^uid=(.+),ou=users,dc=openmrs,dc=org$/.exec(u)[1];
pairs.push([uid, email]);
});
});
// Write csv to stdout
process.stdout.write('Username,Email Address,JIRA profile,Confluence Profile\n');
pairs.forEach(function(p) {
p.push('https://issues.openmrs.org/secure/ViewProfile.jspa?name='+p[0]);
p.push('https://wiki.openmrs.org/display/~'+p[0]);
process.stdout.write(p.join(','));
process.stdout.write('\n');
});
return 0;
var users = require('./users.json');
var _ = require('lodash');
var arrayOfEmailList = _.pluck(users.objList, 'emailList');
var emails = _(arrayOfEmailList)
.flatten()
.compact()
.invoke('toLowerCase')
.sort()
.value();
var uniqEmails = _.uniq(emails);
_.reduce(emails, function(last, current) {
if (last === current) {
console.warn('duplicate address:', current);
}
return current;
});
#!/bin/sh
ldapsearch -x -W -D cn=admin,dc=openmrs,dc=org -b ou=users,dc=openmrs,dc=org "(mail=*)" -LLL mail modifyTimestamp > primaryemails
ldapsearch -x -W -D cn=admin,dc=openmrs,dc=org -b ou=users,dc=openmrs,dc=org "(otherMailbox=*)" -LLL otherMailbox > secondaryemails
Total:
6030 email addresses
130 email address duplicated
142 times.
128 of these are primary-only duplicates.
0 of these are secondary-only duplicates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment