From 156b902059dec03be58098a7ded07730d51dca73 Mon Sep 17 00:00:00 2001 From: Progfou Date: Fri, 1 Mar 2013 15:53:00 -0500 Subject: [PATCH] =?utf8?q?Outil=20d'affichage=20des=20tailles=20limites=20de?= =?utf8?q?s=20courriels=20=C3=A0=20l'AuF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- outils/auf-estmp-sizes | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 outils/auf-estmp-sizes diff --git a/outils/auf-estmp-sizes b/outils/auf-estmp-sizes new file mode 100755 index 0000000..e8f02a4 --- /dev/null +++ b/outils/auf-estmp-sizes @@ -0,0 +1,83 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +""" +auf-esmtp-sizes — Vérification des tailles de messages ESMTP acceptées + +Copyright : Agence universitaire de la Francophonie — www.auf.org +Licence : GNU General Public Licence, version 3 +Auteur : Jean Christophe André +Date de création : 1 mars 2013 + +Dépendance Debian : python-dnspython +""" +import sys +import time +import smtplib +import aufrefer +import dns.resolver + +SMTP_TIMEOUT = 60 # 5 suffit pour la moitié, 30 ne suffit pas pour tout le monde + +moinmoin = (len(sys.argv) > 1) and (sys.argv[1] == '--moinmoin') + +# on cherche le meilleur MX, ou sinon le domaine lui-même +def get_mail_exchanger(domain): + mx_hostname = domain + mx_preference = 1000 + for rdata in dns.resolver.query(domain + '.', 'MX'): + if rdata.preference < mx_preference: + mx_hostname = rdata.exchange.to_text() + mx_preference = rdata.preference + return mx_hostname + +# on contacte le MX en ESMTP pour obtenir sa taille limite +def get_mx_size(mx): + try: + smtp = smtplib.SMTP(mx, timeout=SMTP_TIMEOUT) + smtp.ehlo_or_helo_if_needed() + except: + raise Exception("non joignable") + if not smtp.does_esmtp: + raise Exception("non compatible ESMTP ?!?") + try: + size = int(smtp.esmtp_features['size']) + except: + raise Exception("sans taille valide") + smtp.quit() + return size + +# liste des domaines internes de communication à l'AuF +domains = [u['redir'].split('@')[1] for u in aufrefer.get('annuaire.json')] +domains = [d for d in set(domains)] +domains.sort() + +if moinmoin: + today = time.strftime('%d/%m/%Y') + print u"== Tailles acceptées pour les courriels au %s ==" % today + print u"||'''Domaine'''||'''Taille acceptée'''||" + +# pour chaque domaine, vérifier la taille sur le MX principal +for domain in domains: + mx = get_mail_exchanger(domain) + #print "Test de '%s'..." % mx + try: + size = get_mx_size(mx) + except Exception, e: + if moinmoin: + print "||%s||''%s''||" % (domain, e.message) + else: + print "Domaine '%s' %s." % (domain, e.message) + continue + if moinmoin: + if size <= 0: + color = '#ff0000' + elif size <= 3*1024*1024: + color = '#00ff00' + elif size <= 10*1024*1024: + color = '#ffff00' + else: + color = '#ff0000' + print "||%s||<)%s>%s||" % (domain, color, size) + else: + print "Taille pour le domaine '%s' : %s" % (domain, size) + -- 1.7.10.4