From 1c8eb141543d231410b3c83c3213816d74f97f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Sun, 7 Oct 2018 22:15:19 +0200 Subject: [PATCH] Separate the add and remove operations on lists --- conf.example.toml | 3 ++- unipoly-mlmmj-ldap-sync | 39 ++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/conf.example.toml b/conf.example.toml index 9c6a834..a90278b 100644 --- a/conf.example.toml +++ b/conf.example.toml @@ -1,5 +1,6 @@ domain = "unipoly.ch" -lists = [ "membres"] +lists_add = ["membres"] +lists_remove = ["membres"] [ldap] host = "ldap.gnugen.ch" diff --git a/unipoly-mlmmj-ldap-sync b/unipoly-mlmmj-ldap-sync index 6daf202..37c3ba7 100755 --- a/unipoly-mlmmj-ldap-sync +++ b/unipoly-mlmmj-ldap-sync @@ -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"