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" domain = "unipoly.ch"
lists = [ "membres"] lists_add = ["membres"]
lists_remove = ["membres"]
[ldap] [ldap]
host = "ldap.gnugen.ch" host = "ldap.gnugen.ch"

View File

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