Add and remove users from the mailing lists
This commit is contained in:
parent
1b926fdbcc
commit
cc21e41d4a
2 changed files with 52 additions and 19 deletions
|
@ -15,4 +15,6 @@ basetree = "ou=Lists,dc=unipoly,dc=epfl,dc=ch"
|
|||
[mlmmj]
|
||||
basepath = "/var/spool/mlmmj"
|
||||
list_binary = "/usr/bin/mlmmj-list"
|
||||
sub_binary = "/usr/bin/mlmmj-sub"
|
||||
unsub_binary = "/usr/bin/mlmmj-unsub"
|
||||
|
||||
|
|
|
@ -41,40 +41,71 @@ def main
|
|||
domain = conf["domain"]
|
||||
basetree = conf["ldap"]["lists"]["basetree"]
|
||||
conf["lists"].each do |cn|
|
||||
puts ">> Processing list #{cn}@#{domain}"
|
||||
|
||||
filter = Net::LDAP::Filter.eq("cn", cn)
|
||||
|
||||
print "Searching LDAP... "
|
||||
match = conn.search(:base => basetree, :filter => filter)
|
||||
unless (match.size < 1)
|
||||
if (match.size > 0)
|
||||
entry = match.first
|
||||
members = entry.uniquemember.map { |dn| /mail=([^,]+),/.match(dn).values_at(1).first }
|
||||
puts "Found: #{entry.dn} with #{members.size} entries"
|
||||
members = entry.uniquemember.map do |dn|
|
||||
/mail=([^,]+),/.match(dn).values_at(1).first
|
||||
end
|
||||
|
||||
mlmmj_list_binary = conf["mlmmj"]["list_binary"]
|
||||
mlmmj_basepath = conf["mlmmj"]["basepath"]
|
||||
puts "OK"
|
||||
puts "Found #{entry.dn} with #{members.size} members"
|
||||
|
||||
print "Searchin mlmmj... "
|
||||
if (File.executable?(mlmmj_list_binary))
|
||||
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}"
|
||||
mlmmj_list_binary = conf["mlmmj"]["list_binary"]
|
||||
mlmmj_basepath = conf["mlmmj"]["basepath"]
|
||||
list = "#{mlmmj_basepath}/#{cn}@#{domain}"
|
||||
raw = %x(#{mlmmj_list_binary} -L #{list} -s)
|
||||
|
||||
members.each do |member|
|
||||
if (subscribers.include?(member))
|
||||
subscribers.delete(member)
|
||||
if ($?.exitstatus == 0)
|
||||
purs "OK"
|
||||
subscribers = raw.split("\n")
|
||||
puts "Found #{cn}@#{domain} with #{subscribers.size} subscribers"
|
||||
print "\n"
|
||||
|
||||
# Add to the subscribers any missing entry
|
||||
# Remove successful matches
|
||||
members.each do |m|
|
||||
if (subscribers.include?(m))
|
||||
subscribers.delete(m)
|
||||
else
|
||||
puts "#{member} is to be added to #{cn}"
|
||||
puts "Adding #{m}... "
|
||||
mlmmj_sub_binary = conf["mlmmj"]["sub_binary"]
|
||||
%x(#{mlmmj_sub_binary} -L #{list} -a #{m} -q -f -s)
|
||||
if ($?.exitstatus == 0)
|
||||
puts "OK"
|
||||
else
|
||||
puts "Failed"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Remove remaining "subcribers" (= they did not match with members)
|
||||
subscribers.each do |s|
|
||||
puts "Removing #{s}... "
|
||||
mlmmj_unsub_binary = conf["mlmmj"]["unsub_binary"]
|
||||
%x(#{mlmmj_unsub_binary} -L #{list} -a #{m} -q -s)
|
||||
if ($?.exitstatus == 0)
|
||||
puts "OK"
|
||||
else
|
||||
puts "Failed"
|
||||
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}"
|
||||
puts "FAIL"
|
||||
end
|
||||
else
|
||||
puts "Could not execute #{mlmmj_list_binary}"
|
||||
puts "could not execute #{mlmmj_list_binary}"
|
||||
end
|
||||
else
|
||||
dn = "cn=#{cn},#{basetree}"
|
||||
puts "Unable to find list: #{dn}"
|
||||
puts "FAIL"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue