Nouveau systme de destruction d'objets.
darcs-hash:20040911232457-41617-acc80a0d56d11a346497d0aef68fd4b5c0b13a00.gz
This commit is contained in:
parent
6020d212db
commit
d0ba7705d9
4 changed files with 114 additions and 50 deletions
|
@ -25,9 +25,8 @@ dat = localtime()
|
||||||
if dat[1]<9 : ann_scol = dat[0]-1
|
if dat[1]<9 : ann_scol = dat[0]-1
|
||||||
else : ann_scol = dat[0]
|
else : ann_scol = dat[0]
|
||||||
|
|
||||||
## Quelques fichiers
|
## Répertoire de stoquage des objets détruits
|
||||||
# Log des destructions de machines ou d'adhérents
|
cimetiere = '/home/cimetiere'
|
||||||
delete_log = '/tmp/delete.log'
|
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
## Paramètres des machines ##
|
## Paramètres des machines ##
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
# -*- coding: iso-8859-15 -*-
|
# -*- 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')
|
sys.path.append('/usr/scripts/gestion')
|
||||||
|
|
||||||
from ldap_crans import crans_ldap, crans, ann_scol, smtpserv
|
from ldap_crans import crans_ldap, crans, ann_scol, smtpserv
|
||||||
from lock import *
|
from lock import *
|
||||||
from affich_tools import anim, cprint, OK, ERREUR, WARNING
|
from affich_tools import anim, cprint, OK, ERREUR, WARNING
|
||||||
from time import localtime
|
from time import localtime, strftime
|
||||||
import config
|
import config
|
||||||
|
|
||||||
# On vérifie que l'on es root
|
# On vérifie que l'on es root
|
||||||
|
@ -24,7 +24,7 @@ make_lock('auto_generate')
|
||||||
##### Options fournies ?
|
##### Options fournies ?
|
||||||
try :
|
try :
|
||||||
if len(sys.argv) > 1 :
|
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 :
|
else :
|
||||||
options, arg = ( [],'')
|
options, arg = ( [],'')
|
||||||
except getopt.error, msg :
|
except getopt.error, msg :
|
||||||
|
@ -51,8 +51,46 @@ else :
|
||||||
|
|
||||||
from socket import gethostname
|
from socket import gethostname
|
||||||
|
|
||||||
|
inst = []
|
||||||
|
|
||||||
if gethostname().split(".")[0] == 'zamok':
|
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 'home' in to_do.keys() :
|
||||||
if auto : db.services_to_restart('-home')
|
if auto : db.services_to_restart('-home')
|
||||||
cprint('Création home','gras')
|
cprint('Création home','gras')
|
||||||
|
@ -60,17 +98,29 @@ if gethostname().split(".")[0] == 'zamok':
|
||||||
anim('\t' + args)
|
anim('\t' + args)
|
||||||
try :
|
try :
|
||||||
home, uid, login = args.split(',')
|
home, uid, login = args.split(',')
|
||||||
try :
|
### Home
|
||||||
|
if not os.path.exists(home) :
|
||||||
|
# Le home n'existe pas
|
||||||
os.mkdir(home, 0755)
|
os.mkdir(home, 0755)
|
||||||
except :
|
os.chown(home, int(uid) ,config.gid)
|
||||||
pass
|
elif os.path.isdir(home) :
|
||||||
os.chown(home, int(uid) ,config.gid)
|
# Il y un répertoire existant
|
||||||
try :
|
# 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.mkdir(home + '/Mail', 0700)
|
||||||
|
os.chown(home + '/Mail', int(uid) ,config.gid)
|
||||||
except :
|
except :
|
||||||
|
# Pas grave
|
||||||
pass
|
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 :
|
if status :
|
||||||
print WARNING
|
print WARNING
|
||||||
if debug :
|
if debug :
|
||||||
|
@ -84,6 +134,7 @@ if gethostname().split(".")[0] == 'zamok':
|
||||||
if debug :
|
if debug :
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
if 'mail_bienvenue' in to_do.keys() :
|
if 'mail_bienvenue' in to_do.keys() :
|
||||||
if auto : db.services_to_restart('-mail_bienvenue')
|
if auto : db.services_to_restart('-mail_bienvenue')
|
||||||
cprint('Envoi mail de bienvenue','gras')
|
cprint('Envoi mail de bienvenue','gras')
|
||||||
|
|
|
@ -25,7 +25,7 @@ smtpserv = "localhost"
|
||||||
import smtplib, sre, os, random, string, time, sys
|
import smtplib, sre, os, random, string, time, sys
|
||||||
import ldap, ldap.modlist
|
import ldap, ldap.modlist
|
||||||
|
|
||||||
import config, annuaires, iptools, chgpass, user_tests
|
import config, annuaires, iptools, chgpass, user_tests, cPickle
|
||||||
from chgpass import chgpass
|
from chgpass import chgpass
|
||||||
from affich_tools import coul, prompt
|
from affich_tools import coul, prompt
|
||||||
from time import sleep,localtime
|
from time import sleep,localtime
|
||||||
|
@ -41,8 +41,8 @@ random.seed() # On initialise le g
|
||||||
##################################################################################
|
##################################################################################
|
||||||
### Items de la blackliste
|
### Items de la blackliste
|
||||||
blacklist_items = { u'bloq' : u'Bloquage total de tout services' ,
|
blacklist_items = { u'bloq' : u'Bloquage total de tout services' ,
|
||||||
u'bl_virus' : u'Bloquage sur squid',
|
u'virus' : u'Bloquage sur squid',
|
||||||
u'bl_upload' : u'Bloquage total accès extérieur' }
|
u'upload' : u'Bloquage total accès extérieur' }
|
||||||
|
|
||||||
##################################################################################
|
##################################################################################
|
||||||
### Droits possibles
|
### Droits possibles
|
||||||
|
@ -750,7 +750,6 @@ class base_classes_crans(crans_ldap) :
|
||||||
champ = c.args[0]['info'].split(':')[0]
|
champ = c.args[0]['info'].split(':')[0]
|
||||||
raise RuntimeError(u'Entrée en double dans le champ %s' % champ)
|
raise RuntimeError(u'Entrée en double dans le champ %s' % champ)
|
||||||
|
|
||||||
|
|
||||||
### Génération de la liste de services à redémarrer
|
### Génération de la liste de services à redémarrer
|
||||||
|
|
||||||
# Correspondance modif de la base -> service ayant besoin d'être redémarré
|
# Correspondance modif de la base -> service ayant besoin d'être redémarré
|
||||||
|
@ -762,21 +761,16 @@ class base_classes_crans(crans_ldap) :
|
||||||
'ipsec' : [ 'conf_wifi' ],
|
'ipsec' : [ 'conf_wifi' ],
|
||||||
'hostAlias' : [ 'dns' ] ,
|
'hostAlias' : [ 'dns' ] ,
|
||||||
'droits' : [ 'droits' ] ,
|
'droits' : [ 'droits' ] ,
|
||||||
'ports' : [ 'firewall-komaz' ]
|
'ports' : [ 'firewall-komaz' ] ,
|
||||||
|
'blacklist' : [ 'blacklistes' ] ,
|
||||||
}
|
}
|
||||||
|
|
||||||
serv = []
|
serv = []
|
||||||
for m in self.modifs :
|
for m in self.modifs :
|
||||||
for s in annuaire_modif_service.get(m,[]) :
|
for s in annuaire_modif_service.get(m,[]) :
|
||||||
if s not in serv :
|
if s not in serv :
|
||||||
serv.append(s)
|
serv.append(s)
|
||||||
|
|
||||||
# Regénération blackliste nécessaire ?
|
|
||||||
bl = self.blacklist_actif()
|
|
||||||
if bl and ( 'host' in self.modifs or 'blacklist' in self.modifs ):
|
|
||||||
for s in bl :
|
|
||||||
if s not in serv :
|
|
||||||
serv.append(s)
|
|
||||||
|
|
||||||
# Reinitialisation
|
# Reinitialisation
|
||||||
self._init_data = self._data.copy()
|
self._init_data = self._data.copy()
|
||||||
|
|
||||||
|
@ -785,20 +779,29 @@ class base_classes_crans(crans_ldap) :
|
||||||
|
|
||||||
def _delete(self,dn,comment='') :
|
def _delete(self,dn,comment='') :
|
||||||
""" Sauvegarde puis destruction du dn (et des sous-dn) fourni """
|
""" Sauvegarde puis destruction du dn (et des sous-dn) fourni """
|
||||||
if not self.conn : self.connect()
|
# Commentaires
|
||||||
|
self.modifs.append('destruction (%s)' % comment)
|
||||||
|
self._save()
|
||||||
|
|
||||||
|
# Sauvegarde
|
||||||
|
t = str(self.__class__).split('.')[-1]
|
||||||
|
fd = open('%s/%s/%s_%s' % (config.cimetiere, t, time.strftime('%Y-%m-%d-%H:%M'), self.nom()),'wb')
|
||||||
|
self.conn = None # Fermeture de la connexion à la base sinon cPickle ne marchera pas
|
||||||
|
cPickle.dump(self,fd,2)
|
||||||
|
fd.close()
|
||||||
|
index = "%s, %s : %s %s # %s\n" % (time.strftime(date_format), script_utilisateur, t, self.Nom() , comment)
|
||||||
|
|
||||||
|
# Destruction
|
||||||
|
self.connect()
|
||||||
data = self.conn.search_s(dn,2)
|
data = self.conn.search_s(dn,2)
|
||||||
txt = "%s # Destruction le %s par %s" % (data, time.strftime(date_format), script_utilisateur)
|
|
||||||
if comment :
|
|
||||||
txt += ' (%s)' % comment
|
|
||||||
txt += '\n'
|
|
||||||
|
|
||||||
data.reverse() # Necessaire pour détruire d'abord les sous-dn
|
data.reverse() # Necessaire pour détruire d'abord les sous-dn
|
||||||
for r in data :
|
for r in data :
|
||||||
self.conn.delete_s(r[0])
|
self.conn.delete_s(r[0])
|
||||||
|
|
||||||
try :
|
try :
|
||||||
log = open(config.delete_log,'a')
|
log = open(config.cimetiere + '/index','a')
|
||||||
log.write(txt)
|
log.write(index)
|
||||||
log.close()
|
log.close()
|
||||||
except :
|
except :
|
||||||
pass
|
pass
|
||||||
|
@ -895,18 +898,16 @@ class base_proprietaire(base_classes_crans) :
|
||||||
"""Destruction du proprietaire"""
|
"""Destruction du proprietaire"""
|
||||||
done = 0
|
done = 0
|
||||||
for m in self.machines() :
|
for m in self.machines() :
|
||||||
if m.ipsec() :
|
# Destruction machines
|
||||||
self.services_to_restart('conf_wifi')
|
m.delete(comment)
|
||||||
elif not done :
|
|
||||||
done = 1
|
|
||||||
self.services_to_restart('switch',[self.chbre()])
|
|
||||||
if self.machines() :
|
|
||||||
self.services_to_restart('dhcp')
|
|
||||||
self.services_to_restart('dns')
|
|
||||||
self.services_to_restart('firewall',[ self.nom() ])
|
|
||||||
|
|
||||||
self._delete(self.dn,comment)
|
self._delete(self.dn,comment)
|
||||||
|
|
||||||
|
if self.compte() :
|
||||||
|
args = self._data['uid'][0] + ','
|
||||||
|
args+= self._data['homeDirectory'][0]
|
||||||
|
self.services_to_restart('del_user',[ args ] )
|
||||||
|
|
||||||
def save(self) :
|
def save(self) :
|
||||||
"""
|
"""
|
||||||
Enregistre l'adhérent ou le club courant dans la base LDAP
|
Enregistre l'adhérent ou le club courant dans la base LDAP
|
||||||
|
@ -1877,6 +1878,12 @@ class machine(base_classes_crans) :
|
||||||
# Reconfiguration clients wifi necessaire
|
# Reconfiguration clients wifi necessaire
|
||||||
self.services_to_restart('conf_wifi')
|
self.services_to_restart('conf_wifi')
|
||||||
|
|
||||||
|
# Regénération blackliste nécessaire ?
|
||||||
|
bl = self.blacklist_actif()
|
||||||
|
if bl and ( 'ipHostNumber' in self.modifs or 'host' in self.modifs ):
|
||||||
|
for s in bl :
|
||||||
|
self.services_to_restart(s,[ self.ip() ] )
|
||||||
|
|
||||||
# Remise à zéro
|
# Remise à zéro
|
||||||
self.modifs=[]
|
self.modifs=[]
|
||||||
|
|
||||||
|
@ -1895,6 +1902,8 @@ class machine(base_classes_crans) :
|
||||||
elif self.__typ == 'fixe' :
|
elif self.__typ == 'fixe' :
|
||||||
self.services_to_restart('switch',[ self.proprietaire().chbre() ])
|
self.services_to_restart('switch',[ self.proprietaire().chbre() ])
|
||||||
|
|
||||||
|
self.proprio = self.__proprietaire.Nom() # On met dans un coin le nom du proprio
|
||||||
|
self.__proprietaire = None # On oublie le propriétaire
|
||||||
self._delete(self.dn,comment)
|
self._delete(self.dn,comment)
|
||||||
|
|
||||||
self.services_to_restart('dhcp')
|
self.services_to_restart('dhcp')
|
||||||
|
|
|
@ -384,12 +384,17 @@ def machine_details(machine) :
|
||||||
f+= coul(u'MAC : ','gras') + "%s\n" %machine.mac()
|
f+= coul(u'MAC : ','gras') + "%s\n" %machine.mac()
|
||||||
|
|
||||||
# Propriétaire
|
# Propriétaire
|
||||||
a = machine.proprietaire()
|
|
||||||
f+= coul(u'Propriétaire : ','gras')
|
f+= coul(u'Propriétaire : ','gras')
|
||||||
f += "%s" % a.Nom()
|
try :
|
||||||
if a.chbre() : f += " (%s)" % a.chbre()
|
f += machine.proprio + coul(' (adhérent détruit)', 'jaune')
|
||||||
|
a = crans()
|
||||||
|
except :
|
||||||
|
a = machine.proprietaire()
|
||||||
|
f += "%s" % a.Nom()
|
||||||
|
if a.chbre() : f += " (%s)" % a.chbre()
|
||||||
f+= '\n'
|
f+= '\n'
|
||||||
|
|
||||||
|
|
||||||
# Adhérent blacklisté ?
|
# Adhérent blacklisté ?
|
||||||
bl = a.blacklist_actif()
|
bl = a.blacklist_actif()
|
||||||
if bl :
|
if bl :
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue