-
-
Save elliottwilliams/a91b310c4fd8a142c2d0 to your computer and use it in GitHub Desktop.
Detecting collisions in OpenMRS ID LDAP email addresses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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