Extract users to be added or removed from a given list

This commit is contained in:
Timothée Floure 2018-06-28 17:23:42 +02:00
parent b26a4ba565
commit 1b926fdbcc

View file

@ -34,10 +34,6 @@ def connect_ldap(conf)
end
end
def ldap_connect(ldap)
ldap.bind
end
def main
conf = read_configuration(@configuration_file)
conn = connect_ldap(conf)
@ -49,14 +45,27 @@ def main
match = conn.search(:base => basetree, :filter => filter)
unless (match.size < 1)
entry = match.first
puts "Found: #{entry.dn} with #{entry.uniquemember.size} entries"
members = entry.uniquemember.map { |dn| /mail=([^,]+),/.match(dn).values_at(1).first }
puts "Found: #{entry.dn} with #{members.size} entries"
mlmmj_list_binary = conf["mlmmj"]["list_binary"]
mlmmj_basepath = conf["mlmmj"]["basepath"]
if (File.executable?(mlmmj_list_binary))
subscribers = %x(#{mlmmj_list_binary} -L #{mlmmj_basepath}/#{cn}@#{domain} -s)
unless ($?.exitstatus == 0)
puts "Got #{subscribers.split("\n").size} subscribers from mlmmj".
raw = %x(#{mlmmj_list_binary} -L #{mlmmj_basepath}/#{cn}@#{domain} -s)
if ($?.exitstatus == 0)
subscribers = raw.split("\n")
puts "Got #{subscribers.size} subscribers from mlmmj for #{cn}@#{domain}"
members.each do |member|
if (subscribers.include?(member))
subscribers.delete(member)
else
puts "#{member} is to be added to #{cn}"
end
end
print "There are #{subscribers.size} addesses to remove:"
subscribers.each { |s| print " " + s}
print "\n"
else
puts "Failed to get the subscribers of #{cn}@#{domain}"
end