Nouveau systme de destruction d'objets.

darcs-hash:20040911232457-41617-acc80a0d56d11a346497d0aef68fd4b5c0b13a00.gz
This commit is contained in:
pauget 2004-09-12 01:24:57 +02:00
parent 6020d212db
commit d0ba7705d9
4 changed files with 114 additions and 50 deletions

View file

@ -1,14 +1,14 @@
#! /usr/bin/env python
# -*- coding: iso-8859-15 -*-
import sys, signal, os, commands, getopt, smtplib
import sys, signal, os, commands, getopt, smtplib, shutil
sys.path.append('/usr/scripts/gestion')
from ldap_crans import crans_ldap, crans, ann_scol, smtpserv
from lock import *
from affich_tools import anim, cprint, OK, ERREUR, WARNING
from time import localtime
from time import localtime, strftime
import config
# On vérifie que l'on es root
@ -24,7 +24,7 @@ make_lock('auto_generate')
##### Options fournies ?
try :
if len(sys.argv) > 1 :
options, arg = getopt.getopt(sys.argv[1:], '', ['quiet', 'home=', 'mail_bienvenue=', 'ML-ENS=', 'droits', 'switch=' , 'dhcp', 'dns', 'firewall', 'conf_wifi', 'bornes_wifi=' ])
options, arg = getopt.getopt(sys.argv[1:], '', ['quiet', 'home=', 'mail_bienvenue=', 'ML-ENS=', 'droits', 'switch=' , 'dhcp', 'dns', 'firewall', 'conf_wifi', 'bornes_wifi=' , 'del_user='])
else :
options, arg = ( [],'')
except getopt.error, msg :
@ -51,8 +51,46 @@ else :
from socket import gethostname
inst = []
if gethostname().split(".")[0] == 'zamok':
inst = []
if 'del_user' in to_do.keys() :
if auto : db.services_to_restart('-del_user')
cprint('Archivage fichiers utilisateur','gras')
for args in to_do['del_user'] :
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-%H:%M_') + 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 debug :
sys.stderr.write(warn)
except :
print ERREUR
# On devra le refaire la prochaine fois
if auto : db.services_to_restart('del_user',[args])
if debug :
import traceback
traceback.print_exc()
if 'home' in to_do.keys() :
if auto : db.services_to_restart('-home')
cprint('Création home','gras')
@ -60,17 +98,29 @@ if gethostname().split(".")[0] == 'zamok':
anim('\t' + args)
try :
home, uid, login = args.split(',')
try :
### Home
if not os.path.exists(home) :
# Le home n'existe pas
os.mkdir(home, 0755)
except :
pass
os.chown(home, int(uid) ,config.gid)
try :
os.chown(home, int(uid) ,config.gid)
elif os.path.isdir(home) :
# Il y un répertoire existant
# Bon UID ?
stat = os.stat(home)
if stat[4] != int(uid) or stat[5] != config.gid :
# Le home n'est pas à la bonne personne
raise OSError('home existant')
### Mail
try :
os.mkdir(home + '/Mail', 0700)
os.chown(home + '/Mail', int(uid) ,config.gid)
except :
# Pas grave
pass
os.chown(home + '/Mail', int(uid) ,config.gid)
status, output = commands.getstatusoutput('/usr/sbin/edquota -p pauget %s' % login )
### Quota
status, output = commands.getstatusoutput('/usr/sbin/edquota -p pauget %s' % login )
if status :
print WARNING
if debug :
@ -84,6 +134,7 @@ if gethostname().split(".")[0] == 'zamok':
if debug :
import traceback
traceback.print_exc()
if 'mail_bienvenue' in to_do.keys() :
if auto : db.services_to_restart('-mail_bienvenue')
cprint('Envoi mail de bienvenue','gras')