Adapt to gnugen's LDAP tree structure
We will eventually support both unipoly and gnugen.
This commit is contained in:
parent
3a66832fac
commit
ad221c1d33
2 changed files with 18 additions and 9 deletions
|
@ -13,6 +13,9 @@ password = "secret"
|
||||||
[ldap.lists]
|
[ldap.lists]
|
||||||
basetree = "ou=Lists,dc=unipoly,dc=epfl,dc=ch"
|
basetree = "ou=Lists,dc=unipoly,dc=epfl,dc=ch"
|
||||||
|
|
||||||
|
[ldap.users]
|
||||||
|
basetree = "ou=Users,dc=unipoly,dc=epfl,dc=ch"
|
||||||
|
|
||||||
[mlmmj]
|
[mlmmj]
|
||||||
basepath = "/var/spool/mlmmj"
|
basepath = "/var/spool/mlmmj"
|
||||||
list_binary = "/usr/bin/mlmmj-list"
|
list_binary = "/usr/bin/mlmmj-list"
|
||||||
|
|
|
@ -108,16 +108,21 @@ def remove_subscriber_from(list_name, list, addr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_list(list_name, ldap_group_entry)
|
def sync_list(list_name, ldap_group_entry, user_basetree)
|
||||||
mlmmj_basepath = @configuration['mlmmj']['basepath']
|
mlmmj_basepath = @configuration['mlmmj']['basepath']
|
||||||
list = "#{mlmmj_basepath}/#{list_name}@#{@configuration['domain']}"
|
list = "#{mlmmj_basepath}/#{list_name}@#{@configuration['domain']}"
|
||||||
|
|
||||||
# Members are formatted as
|
ldap_members = ldap_group_entry.memberuid.map do |uid|
|
||||||
# 'mail=user@domain.tld,ou=Users,dc=unipoly,dc=epfl,dc=ch': we extract the
|
filter = Net::LDAP::Filter.eq('uid', uid)
|
||||||
# mail address.
|
matched_ldap_users = conn.search(base: user_basetree, filter: filter)
|
||||||
ldap_members = ldap_group_entry.uniquemember.map do |dn|
|
if matched_ldap_users.nil? || matched_ldap_users.empty?
|
||||||
/mail=([^,]+),/.match(dn).values_at(1).first.downcase
|
""
|
||||||
|
else
|
||||||
|
matched_ldap_users.first.mail
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ldap_members.select! {|e| not e.empty? }
|
||||||
puts "Found #{ldap_group_entry.dn} with #{ldap_members.size} members"
|
puts "Found #{ldap_group_entry.dn} with #{ldap_members.size} members"
|
||||||
|
|
||||||
# Extract mail addresses from Mlmmj
|
# Extract mail addresses from Mlmmj
|
||||||
|
@ -147,7 +152,8 @@ def main
|
||||||
conn = connect_ldap
|
conn = connect_ldap
|
||||||
|
|
||||||
domain = @configuration['domain']
|
domain = @configuration['domain']
|
||||||
basetree = @configuration['ldap']['lists']['basetree']
|
user_basetree = @configuration['ldap']['user']['basetree']
|
||||||
|
list_basetree = @configuration['ldap']['lists']['basetree']
|
||||||
lists = (@configuration['lists_add'] + @configuration['lists_remove']).uniq
|
lists = (@configuration['lists_add'] + @configuration['lists_remove']).uniq
|
||||||
|
|
||||||
# Sync Mlmmj lists with LDAP groups
|
# Sync Mlmmj lists with LDAP groups
|
||||||
|
@ -156,14 +162,14 @@ def main
|
||||||
print 'Searching LDAP... '
|
print 'Searching LDAP... '
|
||||||
|
|
||||||
filter = Net::LDAP::Filter.eq('cn', list_name)
|
filter = Net::LDAP::Filter.eq('cn', list_name)
|
||||||
matched_ldap_groups = conn.search(base: basetree, filter: filter)
|
matched_ldap_groups = conn.search(base: list_basetree, filter: filter)
|
||||||
if matched_ldap_groups.nil? || matched_ldap_groups.empty?
|
if matched_ldap_groups.nil? || matched_ldap_groups.empty?
|
||||||
# Could not find matching LDAP group
|
# Could not find matching LDAP group
|
||||||
puts 'NOT FOUND'
|
puts 'NOT FOUND'
|
||||||
else
|
else
|
||||||
puts 'OK'
|
puts 'OK'
|
||||||
ldap_group_entry = matched_ldap_groups.first
|
ldap_group_entry = matched_ldap_groups.first
|
||||||
sync_list(list_name, ldap_group_entry)
|
sync_list(list_name, ldap_group_entry, user_basetree)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue