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]
|
[mlmmj]
|
||||||
basepath = "/var/spool/mlmmj"
|
basepath = "/var/spool/mlmmj"
|
||||||
list_binary = "/usr/bin/mlmmj-list"
|
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"]
|
domain = conf["domain"]
|
||||||
basetree = conf["ldap"]["lists"]["basetree"]
|
basetree = conf["ldap"]["lists"]["basetree"]
|
||||||
conf["lists"].each do |cn|
|
conf["lists"].each do |cn|
|
||||||
filter = Net::LDAP::Filter.eq("cn", cn)
|
puts ">> Processing list #{cn}@#{domain}"
|
||||||
match = conn.search(:base => basetree, :filter => filter)
|
|
||||||
unless (match.size < 1)
|
|
||||||
entry = match.first
|
|
||||||
members = entry.uniquemember.map { |dn| /mail=([^,]+),/.match(dn).values_at(1).first }
|
|
||||||
puts "Found: #{entry.dn} with #{members.size} entries"
|
|
||||||
|
|
||||||
|
filter = Net::LDAP::Filter.eq("cn", cn)
|
||||||
|
|
||||||
|
print "Searching LDAP... "
|
||||||
|
match = conn.search(:base => basetree, :filter => filter)
|
||||||
|
if (match.size > 0)
|
||||||
|
entry = match.first
|
||||||
|
members = entry.uniquemember.map do |dn|
|
||||||
|
/mail=([^,]+),/.match(dn).values_at(1).first
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "OK"
|
||||||
|
puts "Found #{entry.dn} with #{members.size} members"
|
||||||
|
|
||||||
|
print "Searchin mlmmj... "
|
||||||
|
if (File.executable?(mlmmj_list_binary))
|
||||||
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))
|
list = "#{mlmmj_basepath}/#{cn}@#{domain}"
|
||||||
raw = %x(#{mlmmj_list_binary} -L #{mlmmj_basepath}/#{cn}@#{domain} -s)
|
raw = %x(#{mlmmj_list_binary} -L #{list} -s)
|
||||||
if ($?.exitstatus == 0)
|
|
||||||
subscribers = raw.split("\n")
|
|
||||||
puts "Got #{subscribers.size} subscribers from mlmmj for #{cn}@#{domain}"
|
|
||||||
|
|
||||||
members.each do |member|
|
if ($?.exitstatus == 0)
|
||||||
if (subscribers.include?(member))
|
purs "OK"
|
||||||
subscribers.delete(member)
|
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
|
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
|
||||||
end
|
end
|
||||||
print "There are #{subscribers.size} addesses to remove:"
|
|
||||||
subscribers.each { |s| print " " + s}
|
|
||||||
print "\n"
|
print "\n"
|
||||||
else
|
else
|
||||||
puts "Failed to get the subscribers of #{cn}@#{domain}"
|
puts "FAIL"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
puts "Could not execute #{mlmmj_list_binary}"
|
puts "could not execute #{mlmmj_list_binary}"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
dn = "cn=#{cn},#{basetree}"
|
puts "FAIL"
|
||||||
puts "Unable to find list: #{dn}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue