]> gitweb.pimeys.fr Git - scripts-20-100.git/blobdiff - mailman_bad_guys.py
[update_myconfig] Refresh de la liste
[scripts-20-100.git] / mailman_bad_guys.py
index ba2942be7f9b48da3a5127934effc4964ead40f4..71d9ea84f1ca2e75682c0394b45c1a969b5c58e5 100755 (executable)
@@ -13,6 +13,7 @@ import socket
 if socket.gethostname() != "redisdead":
     print("Not on redisdead, might not work")
 
+import re
 import sys
 
 sys.path.append("/var/lib/mailman/bin")
@@ -38,15 +39,17 @@ def list_members(ml):
     moderators = [i for i in ml.moderator]
     return [members, admins, moderators]
 
-def get_all():
+def get_all(dico=None):
     """Retourne un dico nom_de_ml -> [membres, admins, moderateurs]"""
+    if dico:
+        return dico
     return {n: list_members(n) for n in list_lists()}
 
 def get_field_from_mail(mail, fieldno, all=None):
     """Retourne la liste des mls dont mail est :
-        * membre si ``fieldno`` = 1
-        *
-        *
+        * membre si ``fieldno`` = 0
+        * admin si ``fieldno`` = 1
+        * modérateur si ``fieldno`` = 2
        Calcule le dico ``all`` si on ne lui donne pas."""
     if all == None:
         all = get_all()
@@ -85,6 +88,20 @@ def exterminate_this_guy(bad_guy, dico=None):
     else:
         print("No mailing list found")
 
+def find_modadmin_domain(domain, dico=None):
+    """Retourne un dico ``mail`` -> ``[liste de MLs dont mail est admin, liste de MLs dont mail est modéro]``
+       où mail est un mail dont la partie domaine matche la regexp domain."""
+    all = get_all(dico)
+    # On récupère toutes les adresses d'admins et de modéros dans le même panier
+    suspects = sum([ml[1] + ml[2] for ml in all.values()], [])
+    suspects = list(set(suspects))
+    # On matche
+    regexp = re.compile(".*@%s" % domain)
+    coupables = [mail for mail in suspects if regexp.match(mail)]
+    # On retrouve les MLs correspondantes
+    coupables = {mail : [get_admins_from_mail(mail, all), get_moderators_from_mail(mail, all)] for mail in coupables}
+    return coupables
+
 if __name__ == "__main__":
     bad_guy = sys.argv[1].decode("utf-8").lower()
     exterminate_this_guy(bad_guy)