From b1239e1291c421485893afe85fe105d34235ef31 Mon Sep 17 00:00:00 2001 From: Michel Blockelet Date: Thu, 18 Mar 2010 02:40:02 +0100 Subject: [PATCH] [admin/mail_invalide,gestion/] Modification du systeme de mail_invalide Maintenant tout est gere par des blacklistes mail_invalide, ce qui est beaucoup plus simple ... (Le champ mailInvalide de la base LDAP peut maintenant etre supprime ...) darcs-hash:20100318014002-ddb99-d7e616f0b5040fba54c55d49fcaad25dc55a5665.gz --- admin/mail_invalide/mail_invalide.py | 9 +++-- gestion/gen_confs/adherents.py | 39 ------------------ gestion/gen_confs/generate.py | 8 ---- gestion/gen_confs/squid.py | 2 +- gestion/ldap_crans.py | 59 +++++++++++++++++----------- 5 files changed, 42 insertions(+), 75 deletions(-) diff --git a/admin/mail_invalide/mail_invalide.py b/admin/mail_invalide/mail_invalide.py index ee93d39c..808c30dd 100755 --- a/admin/mail_invalide/mail_invalide.py +++ b/admin/mail_invalide/mail_invalide.py @@ -95,11 +95,14 @@ if __name__ == "__main__": print adh.Nom() a_verifier.append(adresse) else: - print "Génération de la fiche pour %s :" % res[0].Nom().encode('utf-8') - fiche = generate_ps(res[0]) + adherent = res[0] + print "Génération de la fiche pour %s :" % adherent.Nom().encode('utf-8') + fiche = generate_ps(adherent) print fiche a_imprimer.append(fiche) - db.services_to_restart('mail_invalide_expire', ['%s$%s' % (res[0].id(), res[0].mail())], time.time()+14*86400) + adherent.blacklist([time.time() + 14 * 24 * 3600, + '-', 'mail_invalide', "Mail invalide"]) + adherent.save() if len(a_verifier) + len(a_imprimer) > 0: print '' diff --git a/gestion/gen_confs/adherents.py b/gestion/gen_confs/adherents.py index c6a48a23..9c1b1032 100644 --- a/gestion/gen_confs/adherents.py +++ b/gestion/gen_confs/adherents.py @@ -199,26 +199,6 @@ class mail_ajout_droits: traceback.print_exc() -class mail_invalide_expire: - # Passage d'un mail en invalide 2 semaines après notification - debug = True - - def __init__(self, args): - self.args = args - - def reconfigure(self): - cprint(u'Passage en mail invalide', 'gras') - db = crans_ldap() - for arg in self.args: - aid, old_mail = arg.split('$') - adhl = db.search("aid=%s" % aid, 'w')['adherent'] - if len(adhl) > 0: - adh = adhl[0] - if adh.mail() == old_mail: - adh.mail_invalide(True) - adh.save() - - class ML_ens: debug = True @@ -242,22 +222,3 @@ class ML_ens: print OK mlist.Save() mlist.Unlock() - -class mail_valide: - debug = True - - def __init__(self,aids): - self.aids = aids - - def reconfigure(self): - db = crans_ldap() - cprint(u'Validation d\'adresses', 'gras') - for aid in self.aids: - adh = db.search(("aid=%s" %aid), 'w')['adherent'][0] - if not adh._modifiable: - db.services_to_restart('mail_valide',aid) - print "echec pour le mail de %s" %adh.nom() - else: - adh.mail_invalide(False) - adh.save() - print "mail de %s marque valide" % adh.nom() diff --git a/gestion/gen_confs/generate.py b/gestion/gen_confs/generate.py index 1fe89926..72d17dc5 100644 --- a/gestion/gen_confs/generate.py +++ b/gestion/gen_confs/generate.py @@ -166,14 +166,6 @@ class rouge(base_reconfigure): from adherents import del_user self._do(del_user(args)) - def mail_valide(self, args): - from adherents import mail_valide - self._do(mail_valide(args)) - - def mail_invalide_expire(self, args): - from adherents import mail_invalide_expire - self._do(mail_invalide_expire(args)) - def mail_ajout_droits(self, args): from adherents import mail_ajout_droits self._do(mail_ajout_droits(args)) diff --git a/gestion/gen_confs/squid.py b/gestion/gen_confs/squid.py index 6a36a18b..fa70637b 100644 --- a/gestion/gen_confs/squid.py +++ b/gestion/gen_confs/squid.py @@ -111,4 +111,4 @@ class squid_chbre(squid) : class squid_mail(squid) : """ Génère le fichier blacklist-mail pour squid """ FICHIER = "/etc/squid3/blacklist_mail" - chaine = "mailInvalide=TRUE&uid!=*" + chaine = "mail_invalide" diff --git a/gestion/ldap_crans.py b/gestion/ldap_crans.py index f37b757c..293c87ff 100644 --- a/gestion/ldap_crans.py +++ b/gestion/ldap_crans.py @@ -97,7 +97,9 @@ blacklist_items = { u'bloq': u'Bloquage total de tous les services', u'autodisc_virus': u'Autodisconnect pour virus', u'autodisc_upload': u'Autodisconnect pour upload', u'autodisc_p2p': u'Autodisconnect pour P2P', - u'ipv6_ra': u'Isolement pour RA' } + u'ipv6_ra': u'Isolement pour RA', + u'mail_invalide': u'Bloquage sur squid', + } ################################################################################## ### Droits possibles @@ -306,7 +308,7 @@ class CransLdap: ['etudes', 'paiement', 'carteEtudiant', 'aid', 'postalAddress', 'historique', 'blacklist', 'droits', 'uidNumber', 'uid', 'info', 'solde', 'controle', 'contourneGreylist', 'rewriteMailHeaders', - 'ablacklist', 'homepageAlias', 'mailInvalide', 'charteMA', + 'ablacklist', 'homepageAlias', 'charteMA', 'adherentPayant'], \ 'club': \ ['cid', 'responsable', 'paiement', 'historique', 'blacklist', @@ -1999,27 +2001,27 @@ class Adherent(BaseProprietaire): # Les tests : # exactement un @ - # 2 ou 3 caractères après le . final + # 2 à 4 caractères après le . final # @ pas en premier ni juste avant le dernier . if new.count('@') != 1 \ - or not ( l-b == 4 or l-b == 3) \ - or a<1 or b-a<2: + or not ( l-b >= 2 and l-b <= 4) \ + or a < 1 or b-a < 2: raise ValueError(u"Adresse mail incorrecte.") # Pas de caractèrs bizarres for l in new[:]: if not l in (string.lowercase + string.digits + '-_.@'): - raise ValueError(u"Caractère interdits dans l'adresse mail (%s)." % l) + raise ValueError(u"Caractère interdit dans l'adresse mail (%s)." % l) # Pour les vicieux if re.match('.*crans.(org|ens-cachan.fr)$', new): - raise ValueError(u"Adresse mail @crans interdite ici") + raise ValueError(u"Adresse mail @crans interdite ici !") # Il ne doit pas y avoir de compte self.supprimer_compte() self._set('mail', [new]) - # L'adresse est supposée valide avant l'envoi du mail de bienvenue + # On enlève les blacklistes mail_invalide self.mail_invalide(False) # on renvoie le mail de bienvenue @@ -2042,23 +2044,32 @@ class Adherent(BaseProprietaire): def mail_invalide(self, valeur=None): u""" L'adresse est invalide. - Au niveau de la base, on considère l'absence ou la présence - de mailInvalide=TRUE. + Au niveau de la base, on considère l'absence ou la présence d'une + blackliste mail_invalide. """ - - # tente de modifier la valeur - if valeur == True: - self._set('mailInvalide', ['TRUE']) - elif valeur == False: - self._set('mailInvalide', []) - elif valeur != None: - raise ValueError, u"mail_invalide prend un booléen comme argument" - - # on met à jour la blackliste sur sable - self.services_to_restart('bl_mail_invalide') - - # renvoie la valeur trouvée dans la base - return bool(self._data.get('mailInvalide', [])) + if valeur == False: + # On enlève les blacklistes + bl_mail_list = [x for x in self.blacklist() if 'mail_invalide' in x] + now = time.time() + for bl_mail in bl_mail_list: + bl_data = bl_mail.split('$') + if int(bl_data[0]) <= now and bl_data[1] == '-': + self.blacklist((self.blacklist().index(bl_mail), + [bl_data[0], 'now', 'mail_invalide', bl_data[3]])) + elif int(bl_data[0]) >= now: + self.blacklist((self.blacklist().index(bl_mail), + [str(now-2), str(now-1), 'mail_invalide', bl_data[3]])) + elif valeur == None: + # On retourne l'existence d'une blackliste active ou future + bl_mail_list = [x for x in self.blacklist() if 'mail_invalide' in x] + now = time.time() + for bl_mail in bl_mail_list: + bl_data = bl_mail.split('$') + if (int(bl_data[0]) <= now and bl_data[1] == '-') or int(bl_data[0]) >= now: + return True + return False + else: + raise ValueError, u'mail_invalide ne peut prendre que None ou False en argument' def charteMA(self, valeur=None): u"""