From e6d57aa39427a05ab173e9ffc3a7d81d4ff78a3b Mon Sep 17 00:00:00 2001 From: pauget Date: Sat, 11 Jun 2005 19:23:01 +0200 Subject: [PATCH] Ce fichier aussi dans le cvs darcs-hash:20050611172301-41617-b9321a1119f3f67c2656e1925493da98995c5b32.gz --- gestion/gen_confs/adherents.py | 135 +++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100755 gestion/gen_confs/adherents.py diff --git a/gestion/gen_confs/adherents.py b/gestion/gen_confs/adherents.py new file mode 100755 index 00000000..360a16b0 --- /dev/null +++ b/gestion/gen_confs/adherents.py @@ -0,0 +1,135 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (C) Fr-bédéric Pauget-A +# Licence : GPLv2 + +import smtplib, sys, commands, shutil, os +sys.path.append('/usr/scripts/gestion') +from affich_tools import cprint, anim, OK, WARNING, ERREUR +import config +from time import strftime + +class del_user : + debug = True + def __init__(self,args) : + self.args=args + def reconfigure(self) : + cprint('Archivage fichiers utilisateur','gras') + for args in self.args : + anim('\t' + args) + try: + login, home = args.split(',') + if not login or not home : + raise ValueError('Argument invalide') + warn = '' + f = config.cimetiere + '/files/' + strftime('%Y-%m-%d-%Hh%Mm_') + login + '.tar.bz2' + status, output = commands.getstatusoutput("tar cjf '%s' '%s' /var/spool/mail/%s" % ( f,home,login) ) + if ( status != 512 and status!=0 ) or not os.path.isfile(f) : + # La 512 est si un des paths n'exite pas. + raise OSError(output) + if os.path.isdir(home) and os.stat(home)[4] >= 500 : + shutil.rmtree(home) + else : + warn += '%s incorrect\n' % home + if os.path.isfile('/var/spool/mail/' + login ) : + os.unlink('/var/spool/mail/' + login) + else : + warn += '/var/spool/mail/%s incorrect\n' % login + + if warn : + print WARNING + if self.debug : + sys.stderr.write(warn) + else : + print OK + except : + print ERREUR + if self.debug : + import traceback + traceback.print_exc() + +class home: + debug = True + def __init__(self,args) : + self.args = args + def reconfigure(self) : + cprint('Création home','gras') + for args in self.args : + anim('\t' + args) + try: + home, uid, login = args.split(',') + ### Home + if not os.path.exists(home) : + # Le home n'existe pas + os.mkdir(home, 0755) + os.chown(home, int(uid) ,config.gid) + elif os.path.isdir(home) : + # Il y un r-bépertoire existant-A + # Bon UID ? + stat = os.stat(home) + if stat[4] != int(uid) or stat[5] != config.gid : + # Le home n'est pas -bà la bonne personne-A + raise OSError('home existant') + + ### Mail + try: + os.mkdir(home + '/Mail', 0700) + os.chown(home + '/Mail', int(uid) ,config.gid) + except : + # Pas grave + pass + + ### Quota + status, output = commands.getstatusoutput('/usr/sbin/edquota -p pauget %s' % login ) + if status : + print WARNING + if self.debug : + sys.stderr.write(output+'\n') + else : + print OK + except : + print ERREUR + if self.debug : + import traceback + traceback.print_exc() + +class mail_bienvenue : + debug = True + def __init__(self,mails) : + self.mails = mails + + def reconfigure(self) : + cprint('Envoi mail de bienvenue','gras') + for mail in self.mails : + anim('\t' + mail) + try: + From = "respbats@crans.org" + To = mail + if To.find('@') == -1 : To += '@crans.org' + conn=smtplib.SMTP('localhost') + conn.sendmail(From, To , config.txt_mail_bienvenue % { 'From' : From, 'To' : To }) + conn.quit() + print OK + except Exception, c: + print ERREUR + if self.debug : + import traceback + traceback.print_exc() + +class ML_ens : + debug = True + def __init__(self,mails) : + self.mails = mails + + def reconfigure(self) : + cprint('Inscription ML-ENS','gras') + for mail in self.mails : + anim('\t'+mail) + status, output = commands.getstatusoutput("echo '%s' | /usr/sbin/add_members -r - com-ens >/dev/null 2>&1" % mail) + if status : + print ERREUR + if self.debug : + sys.stderr.write(output+'\n') + else : + print OK