diff --git a/gestion/gen_confs/droits.py b/gestion/gen_confs/droits.py index 9dd605cc..6abbc607 100755 --- a/gestion/gen_confs/droits.py +++ b/gestion/gen_confs/droits.py @@ -1,12 +1,13 @@ #! /usr/bin/env python # -*- coding: iso-8859-15 -*- -import sys, signal, os +import sys, signal, os, smtplib # Imports pour LDAP sys.path.append('/usr/scripts/gestion') from gen_confs import gen_config, anim, cprint, OK, ERREUR -from ldap_crans import crans_ldap, crans, preattr, ldap +from ldap_crans import crans_ldap, crans, preattr, ldap, smtpserv +from whos import adher_details from socket import gethostname @@ -37,7 +38,7 @@ class droits(crans_ldap,gen_config) : 'respbats' : [ u'Câbleur', u'Nounou' ], '+moderateurs' : [ u'Modérateur' ], '+disconnect' : [ u'Déconnecteur' ] } - + def restart(s) : # Rien à faire pass @@ -216,6 +217,19 @@ class droits(crans_ldap,gen_config) : if self.debug : import traceback traceback.print_exc() + + self.anim = anim('\tenvoi de mails à roots') + try : + self.mail(self.uids) + self.anim.reinit() + print OK + except : + self.anim.reinit() + print ERREUR + if self.debug : + import traceback + traceback.print_exc() + elif gethostname().split(".")[0] == 'nectaris': self.anim = anim('\tconfiguration master.passwd') try: @@ -228,7 +242,31 @@ class droits(crans_ldap,gen_config) : if self.debug : import traceback traceback.print_exc() - + + def mail (self, uids) : + """ Envoi un mail à roots pour dire que certains droits ont changé """ + + # base du mail + From = "roots@crans.org" + To = "roots@crans.org" + base_txt_mail = """From: %(From)s +To: %(To)s +Subject: Modifications des droits d'un adhérent + +%(Texte)s""" + + # boucle pour chaque adhérent modifié + for uid in uids : + try : + adh = self.search('uid=%s' % uid)['adherent'] + + if len(adh): + adh = adh[0] + conn=smtplib.SMTP(smtpserv) + conn.sendmail(From, To , base_txt_mail % { 'From' : From, 'To' : To, 'Texte' : adher_details(adh).encode('iso8859-15') }) + conn.quit() + except : + self.services_to_restart('droits',uid) if __name__ == '__main__' : if '-h' in sys.argv or '--help' in sys.argv or len(sys.argv) == 1 : diff --git a/gestion/gen_confs/generate.py b/gestion/gen_confs/generate.py index 5e6f3d7a..69ba0b13 100755 --- a/gestion/gen_confs/generate.py +++ b/gestion/gen_confs/generate.py @@ -242,10 +242,11 @@ if hostname == 'zamok': try: from gen_confs.droits import droits a = droits() + a.uids = to_do['droits'] a.debug = debug a.reconfigure() except: - if auto : db.services_to_restart('droits') + if auto : db.services_to_restart('droits',to_do['droits']) if 'blacklist_upload' in to_do.keys() : if auto : db.services_to_restart('-blacklist_upload') @@ -302,7 +303,7 @@ Subject: Modifications sur une machine du CR@NS if debug : import traceback traceback.print_exc() - + if 'autostatus' in to_do.keys() : if auto : db.services_to_restart('-autostatus') try: diff --git a/gestion/ldap_crans.py b/gestion/ldap_crans.py index a6921ff3..f162a9fc 100755 --- a/gestion/ldap_crans.py +++ b/gestion/ldap_crans.py @@ -197,7 +197,7 @@ class crans_ldap : 'club' : [ 'nom', 'chbre' ] } # Champs de recherche pour la recherche manuelle (en plus de la recherche auto) - non_auto_search_champs = { 'adherent' : [ 'etudes', 'paiement', 'carteEtudiant', 'aid' , 'postalAddress', 'historique' ,'blacklist', 'droits', 'uidNumber' ], \ + non_auto_search_champs = { 'adherent' : [ 'etudes', 'paiement', 'carteEtudiant', 'aid' , 'postalAddress', 'historique' ,'blacklist', 'droits', 'uidNumber', 'uid' ], \ 'machine' : [ 'mid' , 'ipsec', 'historique', 'blacklist' , 'puissance', 'canal', 'portTCPin', 'portTCPout', 'portUDPin', 'portUDPout' , 'prise' ] , 'club' : [ 'cid' , 'responsable', 'paiement', 'historique', 'blacklist'] } @@ -1183,7 +1183,7 @@ class base_proprietaire(base_classes_crans) : # Modif des droits ? if 'droits' in self.modifs : - self.services_to_restart('droits') + self.services_to_restart('droits',[self._data['uid']]) # Remise à zero self.modifs=[]