From 1b6abf4f92d98345887f34e9efd78c6150362f84 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Sun, 29 Sep 2013 14:40:30 +0200 Subject: [PATCH] =?utf8?q?Pratique=20pour=20br=C3=BBler=20les=20gens=20sui?= =?utf8?q?te=20aux=20rapppels=20de=20mdp=20de=20Mailman?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- mailman_bad_guys.py | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 mailman_bad_guys.py diff --git a/mailman_bad_guys.py b/mailman_bad_guys.py new file mode 100755 index 0000000..eba0821 --- /dev/null +++ b/mailman_bad_guys.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- + +"""Pour trouver dans quelle(s) ML(s) est quelqu'un et l'en virer. + + À exécuter sur redisdead. + """ + +from __future__ import print_function + +import socket +if socket.gethostname() != "redisdead": + print("Not on redisdead, might not work") + +import sys + +sys.path.append("/var/lib/mailman/bin") + +import paths +#from Mailman import mm_cfg +from Mailman import MailList +from Mailman import Utils + +def list_lists(): + """Donne la liste des MLs""" + return [unicode(n) for n in Utils.list_names()] + +def list_members(ml): + """Donne la liste des membres de ``ml``. + Deals with fucking unicode problems.""" + ml = MailList.MailList(ml, lock=False) + rmembers = ml.getRegularMemberKeys() + dmembers = ml.getDigestMemberKeys() + l = rmembers + dmembers + l = [s if isinstance(s, unicode) else s.decode("utf-8") for s in l] + return l + +def get_all(): + """Retourne un dico nom_de_ml -> membres""" + return {n: list_members(n) for n in list_lists()} + +def get_mls_from_mail(mail, all=None): + """Retourne la liste des mls auxquelles est abonné ``mail``. + Calcule le dico ``all`` si on ne lui donne pas.""" + if all == None: + all = get_all() + return [n for (n, members) in all.iteritems() if mail in members] + +def exterminate(mail, ml): + """Désabonne ``mail`` de ``ml``. + Pas de notification à mail, mais à l'admin.""" + l = MailList.MailList(ml.encode(), lock=True) + l.DeleteMember(mail.encode(), admin_notif="prout", userack=False) + l.Save() + l.Unlock() + +if __name__ == "__main__": + bad_guy = sys.argv[1].decode("utf-8").lower() + mls = get_mls_from_mail(bad_guy) + mls.sort() + if mls: + print("Exterminating %s from %s" % (bad_guy, ", ".join(mls))) + answer = raw_input("[y/n] ?") + if answer.lower() == "y": + for n in mls: + exterminate(bad_guy, n) + else: + print("No mailing list found") -- 2.39.2