Skip to content

Instantly share code, notes, and snippets.

@Finkregh
Created December 6, 2013 11:15
Show Gist options
  • Save Finkregh/7822145 to your computer and use it in GitHub Desktop.
Save Finkregh/7822145 to your computer and use it in GitHub Desktop.
add groups from Active Directory / ldap to prosody
#!/bin/bash
#/usr/local/bin/create-prosody-groups.sh
tmpfile=/tmp/sharedgroups.txt
for org in group1 group2 ; do echo "[${org}]" ; ldapsearch -x -h ldap.corp.org -D "ldap-bind-user" -w "ldap-bind-pw" -LLL -b "ou=${org},dc=corp,dc=org" "(&(objectClass=user)(mail=*))" | grep -E "^cn: |sAMAccountName: "; done > ${tmpfile}
while read line ; do
if echo ${line} | grep -qE "^\[" ; then
echo ""
echo $line
else
if echo ${line} | grep -qE "^cn" ; then
fullname=$(echo ${line} | cut -d ' ' -f 2-)
elif echo ${line} | grep -qE "^sAMAccountName" ; then
uid=$(echo ${line} | cut -d ' ' -f 2 | tr '[:upper:]' '[:lower:]')
echo "${uid}@xmpp.corp.org=${fullname}"
fi
fi
done < ${tmpfile}
0 0 * * * root /usr/local/bin/create-prosody-groups.sh > /var/lib/prosody/sharedgroups.txt ; chown prosody.prosody /var/lib/prosody/sharedgroups.txt ; service prosody reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment