Repasse en ISO
darcs-hash:20050815071649-d1718-56af0b205962422ace3997b3fb3a7ffb3f69272e.gz
This commit is contained in:
parent
36877b6969
commit
65c95a51cd
1 changed files with 25 additions and 25 deletions
|
@ -1,7 +1,7 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: iso-8859-15 -*-
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -42,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 :
|
||||||
|
@ -55,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)
|
||||||
|
@ -78,14 +78,14 @@ 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' """
|
||||||
return db.all_machines(graphic=True)
|
return db.all_machines(graphic=True)
|
||||||
|
|
||||||
def _do(self,service,machines=None) :
|
def _do(self,service,machines=None) :
|
||||||
|
@ -97,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) :
|
||||||
|
@ -138,7 +138,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) :
|
||||||
|
@ -172,7 +172,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) :
|
||||||
|
@ -207,8 +207,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))
|
||||||
|
|
||||||
|
@ -239,7 +239,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 :
|
||||||
|
@ -257,7 +257,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 :
|
||||||
|
@ -271,12 +271,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)
|
||||||
|
@ -292,7 +292,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)
|
||||||
|
@ -312,5 +312,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