Déplacement de la construction de la liste des machines autorisées
dans crans_ldap. darcs-hash:20050722095945-d1718-311250cb58e94806a636fef95a153e87e2fcfae8.gz
This commit is contained in:
parent
fab7e1e2e6
commit
11b8e5ea76
1 changed files with 25 additions and 47 deletions
|
@ -1,7 +1,7 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (C) Frédéric Pauget
|
# Copyright (C) Frédéric Pauget
|
||||||
# Licence : GPLv2
|
# Licence : GPLv2
|
||||||
|
|
||||||
"""Ce script permet de lancer la reconfiguration des divers services
|
"""Ce script permet de lancer la reconfiguration des divers services
|
||||||
|
@ -9,8 +9,8 @@
|
||||||
Usage: %(prog)s options
|
Usage: %(prog)s options
|
||||||
Les options possibles sont :
|
Les options possibles sont :
|
||||||
\t%(options)s
|
\t%(options)s
|
||||||
Les options avec = doivent être suivies d'un argument. Plusieurs
|
Les options avec = doivent être suivies d'un argument. Plusieurs
|
||||||
arguments peuvent être founis pour une même option, les séparer par &
|
arguments peuvent être founis pour une même option, les séparer par &
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, signal, os, getopt
|
import sys, signal, os, getopt
|
||||||
|
@ -24,9 +24,9 @@ from time import localtime, strftime, time, sleep
|
||||||
import config
|
import config
|
||||||
from inspect import getargspec
|
from inspect import getargspec
|
||||||
|
|
||||||
# On vérifie que l'on est root
|
# On vérifie que l'on est root
|
||||||
if os.getuid() != 0:
|
if os.getuid() != 0:
|
||||||
sys.stderr.write("Il faut être root\n")
|
sys.stderr.write("Il faut être root\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
signal.signal(signal.SIGINT,signal.SIG_IGN) # Pas de Ctrl-C
|
signal.signal(signal.SIGINT,signal.SIG_IGN) # Pas de Ctrl-C
|
||||||
|
@ -35,7 +35,6 @@ db = crans_ldap()
|
||||||
make_lock('auto_generate','Big lock',nowait=1)
|
make_lock('auto_generate','Big lock',nowait=1)
|
||||||
|
|
||||||
class base_reconfigure :
|
class base_reconfigure :
|
||||||
__machines = ()
|
|
||||||
__service_develop = {
|
__service_develop = {
|
||||||
'macip' : [ 'rouge-macip', 'bleu-macip', 'sila-macip' , 'komaz-macip', 'zamok-macip' ] ,
|
'macip' : [ 'rouge-macip', 'bleu-macip', 'sila-macip' , 'komaz-macip', 'zamok-macip' ] ,
|
||||||
'droits': [ 'zamok-droits', 'nectaris-droits' ] ,
|
'droits': [ 'zamok-droits', 'nectaris-droits' ] ,
|
||||||
|
@ -43,12 +42,12 @@ class base_reconfigure :
|
||||||
|
|
||||||
def __init__(self,to_do=[]) :
|
def __init__(self,to_do=[]) :
|
||||||
if not to_do :
|
if not to_do :
|
||||||
if debug : print 'Lecture services à redémarrer dans la base LDAP'
|
if debug : print 'Lecture services à redémarrer dans la base LDAP'
|
||||||
to_do = db.services_to_restart()
|
to_do = db.services_to_restart()
|
||||||
auto = 1
|
auto = 1
|
||||||
# Développements nécessaires
|
# Développements nécessaires
|
||||||
for service,args in to_do.items() :
|
for service,args in to_do.items() :
|
||||||
# Services spéciaux portant sur plusieurs machines
|
# Services spéciaux portant sur plusieurs machines
|
||||||
to_add = self.__service_develop.get(service,[])
|
to_add = self.__service_develop.get(service,[])
|
||||||
if to_add :
|
if to_add :
|
||||||
for s in to_add :
|
for s in to_add :
|
||||||
|
@ -56,13 +55,13 @@ class base_reconfigure :
|
||||||
db.services_to_restart('-' + service)
|
db.services_to_restart('-' + service)
|
||||||
else :
|
else :
|
||||||
auto = 0
|
auto = 0
|
||||||
if debug : print 'Services à redémarrer imposés (non lecture de la base LDAP)'
|
if debug : print 'Services à redémarrer imposés (non lecture de la base LDAP)'
|
||||||
|
|
||||||
for serv,args in to_do.items() :
|
for serv,args in to_do.items() :
|
||||||
# Au cas ou le service porte sur plusieurs machines
|
# Au cas ou le service porte sur plusieurs machines
|
||||||
service = serv.replace('%s-'%hostname,'')
|
service = serv.replace('%s-'%hostname,'')
|
||||||
if hasattr(self,service) :
|
if hasattr(self,service) :
|
||||||
# Le service est à reconfigurer sur cette machine
|
# Le service est à reconfigurer sur cette machine
|
||||||
db.services_to_restart('-%s' % serv)
|
db.services_to_restart('-%s' % serv)
|
||||||
try:
|
try:
|
||||||
m = getattr(self,service)
|
m = getattr(self,service)
|
||||||
|
@ -79,36 +78,15 @@ class base_reconfigure :
|
||||||
if debug :
|
if debug :
|
||||||
reste = db.services_to_restart()
|
reste = db.services_to_restart()
|
||||||
if reste :
|
if reste :
|
||||||
print "Reste à faire :"
|
print "Reste à faire :"
|
||||||
for item in reste.items() :
|
for item in reste.items() :
|
||||||
print '\t%s(%s)' % item
|
print '\t%s(%s)' % item
|
||||||
else :
|
else :
|
||||||
print "Plus rien à faire"
|
print "Plus rien à faire"
|
||||||
|
|
||||||
def _machines(self) :
|
def _machines(self) :
|
||||||
""" Retourne les machines de la base étant 'à jour' """
|
""" Retourne les machines de la base étant 'à jour' """
|
||||||
if not self.__machines :
|
return db.all_machines(graphic=True)
|
||||||
# Récolte des données
|
|
||||||
cprint('Lecture base LDAP','gras')
|
|
||||||
# Machines de l'assoce
|
|
||||||
self.__machines = crans(db.conn).machines()
|
|
||||||
# Machines des invités
|
|
||||||
self.__machines += invite(db.conn).machines()
|
|
||||||
# Machines des adhérents et clubs de l'année en cours
|
|
||||||
base = db.search('paiement=ok')
|
|
||||||
base = base['adherent'] + base['club']
|
|
||||||
a = anim('\ttri machines',len(base))
|
|
||||||
for adh in base :
|
|
||||||
a.cycle()
|
|
||||||
# Adhérent ayant payé l'année en cours
|
|
||||||
if 'bloq' in adh.blacklist_actif() :
|
|
||||||
# Adhérent ignoré
|
|
||||||
continue
|
|
||||||
self.__machines += adh.machines()
|
|
||||||
a.reinit()
|
|
||||||
print OK
|
|
||||||
|
|
||||||
return self.__machines
|
|
||||||
|
|
||||||
def _do(self,service,machines=None) :
|
def _do(self,service,machines=None) :
|
||||||
# Reconfiguration des services
|
# Reconfiguration des services
|
||||||
|
@ -119,7 +97,7 @@ class base_reconfigure :
|
||||||
|
|
||||||
def macip(self,ips) :
|
def macip(self,ips) :
|
||||||
import firewall
|
import firewall
|
||||||
cprint("Mise à jour correspondance MAC-IP",'gras')
|
cprint("Mise à jour correspondance MAC-IP",'gras')
|
||||||
eval("firewall.firewall_%s()" % hostname).mac_ip_maj(ips)
|
eval("firewall.firewall_%s()" % hostname).mac_ip_maj(ips)
|
||||||
|
|
||||||
class rouge(base_reconfigure) :
|
class rouge(base_reconfigure) :
|
||||||
|
@ -148,7 +126,7 @@ class komaz(base_reconfigure) :
|
||||||
return self.__real_fw
|
return self.__real_fw
|
||||||
|
|
||||||
def macip(self,ips) :
|
def macip(self,ips) :
|
||||||
cprint("Mise à jour correspondance MAC-IP",'gras')
|
cprint("Mise à jour correspondance MAC-IP",'gras')
|
||||||
self.__fw().mac_ip_maj(ips)
|
self.__fw().mac_ip_maj(ips)
|
||||||
|
|
||||||
def ports(self,ips) :
|
def ports(self,ips) :
|
||||||
|
@ -182,7 +160,7 @@ class nectaris(base_reconfigure) :
|
||||||
__restart_wifi_update = False
|
__restart_wifi_update = False
|
||||||
|
|
||||||
def macip(self) :
|
def macip(self) :
|
||||||
# Surcharge car rien à faire ici
|
# Surcharge car rien à faire ici
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __wifi(self) :
|
def __wifi(self) :
|
||||||
|
@ -217,8 +195,8 @@ class nectaris(base_reconfigure) :
|
||||||
|
|
||||||
class zamok(base_reconfigure) :
|
class zamok(base_reconfigure) :
|
||||||
def mail_modif(self,trucs) :
|
def mail_modif(self,trucs) :
|
||||||
""" trucs est une liste de recherches à effectuer dans la base
|
""" trucs est une liste de recherches à effectuer dans la base
|
||||||
l'affichage des résultats formera le corps du mail """
|
l'affichage des résultats formera le corps du mail """
|
||||||
from supervison import mail
|
from supervison import mail
|
||||||
self._do(mail(trucs))
|
self._do(mail(trucs))
|
||||||
|
|
||||||
|
@ -265,7 +243,7 @@ if __name__ == '__main__' :
|
||||||
classe = eval(hostname)
|
classe = eval(hostname)
|
||||||
|
|
||||||
args_autorises = ['quiet', 'remove=', 'add=', 'list' ,'help', 'reconnect']
|
args_autorises = ['quiet', 'remove=', 'add=', 'list' ,'help', 'reconnect']
|
||||||
# Ajout aussi des arguments spécifiques à la machine
|
# Ajout aussi des arguments spécifiques à la machine
|
||||||
for nom in dir(classe) :
|
for nom in dir(classe) :
|
||||||
if nom[0]!='_' :
|
if nom[0]!='_' :
|
||||||
if len(getargspec(getattr(classe,nom))[0])>1 :
|
if len(getargspec(getattr(classe,nom))[0])>1 :
|
||||||
|
@ -283,7 +261,7 @@ if __name__ == '__main__' :
|
||||||
sys.stderr.write('%s\n' % msg)
|
sys.stderr.write('%s\n' % msg)
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
|
|
||||||
debug = 1 # défaut
|
debug = 1 # défaut
|
||||||
to_do = {}
|
to_do = {}
|
||||||
|
|
||||||
for opt, val in options :
|
for opt, val in options :
|
||||||
|
@ -297,12 +275,12 @@ if __name__ == '__main__' :
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
elif opt == '--list' :
|
elif opt == '--list' :
|
||||||
print 'Services à redémarrer :'
|
print 'Services à redémarrer :'
|
||||||
print db.services_to_restart()
|
print db.services_to_restart()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
elif opt == '--reconnect' :
|
elif opt == '--reconnect' :
|
||||||
# Personnes à reconnecter
|
# Personnes à reconnecter
|
||||||
print 'Recheche personnes en fin de sanction.'
|
print 'Recheche personnes en fin de sanction.'
|
||||||
hier = strftime('%d/%m/%Y %H:%M'.split()[0],localtime(time()-60*60*24))
|
hier = strftime('%d/%m/%Y %H:%M'.split()[0],localtime(time()-60*60*24))
|
||||||
c = db.search('blacklist=*,%s*' % hier)
|
c = db.search('blacklist=*,%s*' % hier)
|
||||||
|
@ -318,7 +296,7 @@ if __name__ == '__main__' :
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
elif opt=='--add' :
|
elif opt=='--add' :
|
||||||
# Ajout d'un item dans les services à redémarrer
|
# Ajout d'un item dans les services à redémarrer
|
||||||
for serv in val.split('&') :
|
for serv in val.split('&') :
|
||||||
if serv.find(',')!=-1 :
|
if serv.find(',')!=-1 :
|
||||||
serv, arg = serv.split(',',1)
|
serv, arg = serv.split(',',1)
|
||||||
|
@ -338,5 +316,5 @@ if __name__ == '__main__' :
|
||||||
to_do[opt[2:]] = val.split('&')
|
to_do[opt[2:]] = val.split('&')
|
||||||
|
|
||||||
|
|
||||||
# On fait ce qu'il y a à faire
|
# On fait ce qu'il y a à faire
|
||||||
classe(to_do)
|
classe(to_do)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue