Extract users to be added or removed from a given list
This commit is contained in:
parent
b26a4ba565
commit
1b926fdbcc
1 changed files with 17 additions and 8 deletions
|
@ -34,10 +34,6 @@ def connect_ldap(conf)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ldap_connect(ldap)
|
|
||||||
ldap.bind
|
|
||||||
end
|
|
||||||
|
|
||||||
def main
|
def main
|
||||||
conf = read_configuration(@configuration_file)
|
conf = read_configuration(@configuration_file)
|
||||||
conn = connect_ldap(conf)
|
conn = connect_ldap(conf)
|
||||||
|
@ -49,14 +45,27 @@ def main
|
||||||
match = conn.search(:base => basetree, :filter => filter)
|
match = conn.search(:base => basetree, :filter => filter)
|
||||||
unless (match.size < 1)
|
unless (match.size < 1)
|
||||||
entry = match.first
|
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_list_binary = conf["mlmmj"]["list_binary"]
|
||||||
mlmmj_basepath = conf["mlmmj"]["basepath"]
|
mlmmj_basepath = conf["mlmmj"]["basepath"]
|
||||||
if (File.executable?(mlmmj_list_binary))
|
if (File.executable?(mlmmj_list_binary))
|
||||||
subscribers = %x(#{mlmmj_list_binary} -L #{mlmmj_basepath}/#{cn}@#{domain} -s)
|
raw = %x(#{mlmmj_list_binary} -L #{mlmmj_basepath}/#{cn}@#{domain} -s)
|
||||||
unless ($?.exitstatus == 0)
|
if ($?.exitstatus == 0)
|
||||||
puts "Got #{subscribers.split("\n").size} subscribers from mlmmj".
|
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
|
else
|
||||||
puts "Failed to get the subscribers of #{cn}@#{domain}"
|
puts "Failed to get the subscribers of #{cn}@#{domain}"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue