Separate the add and remove operations on lists

This commit is contained in:
Timothée Floure 2018-10-07 22:15:19 +02:00
parent 165e01269d
commit 1c8eb14154
2 changed files with 24 additions and 18 deletions

View file

@ -1,5 +1,6 @@
domain = "unipoly.ch"
lists = [ "membres"]
lists_add = ["membres"]
lists_remove = ["membres"]
[ldap]
host = "ldap.gnugen.ch"

View file

@ -40,7 +40,8 @@ def main
domain = conf["domain"]
basetree = conf["ldap"]["lists"]["basetree"]
conf["lists"].each do |cn|
lists = (conf["lists_add"] + conf["lists_remove"]).uniq
lists.each do |cn|
puts ">> Processing list #{cn}@#{domain}"
filter = Net::LDAP::Filter.eq("cn", cn)
@ -75,26 +76,30 @@ def main
if (subscribers.include?(m))
subscribers.delete(m)
else
print "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
if (conf["lists_add"].include?(cn))
print "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
end
# Remove remaining "subcribers" (= they did not match with members)
subscribers.each do |s|
print "Removing #{s}... "
mlmmj_unsub_binary = conf["mlmmj"]["unsub_binary"]
%x(#{mlmmj_unsub_binary} -L #{list} -a #{s} -q -s)
if ($?.exitstatus == 0)
puts "OK"
else
puts "Failed"
if (conf["lists_remove"].include?(cn))
subscribers.each do |s|
print "Removing #{s}... "
mlmmj_unsub_binary = conf["mlmmj"]["unsub_binary"]
%x(#{mlmmj_unsub_binary} -L #{list} -a #{s} -q -s)
if ($?.exitstatus == 0)
puts "OK"
else
puts "Failed"
end
end
end
print "\n"