Detabification massive.
darcs-hash:20051018083823-d1718-09c2df38cfb707d3c3679188b9b9a812009f4f7c.gz
This commit is contained in:
parent
3c54fb2904
commit
37b21339a6
40 changed files with 1473 additions and 1473 deletions
|
@ -80,12 +80,12 @@ class home:
|
|||
sys.stderr.write(output+'\n')
|
||||
else :
|
||||
print OK
|
||||
|
||||
### Mail
|
||||
os.mkdir(home + '/Mail', 0700)
|
||||
os.chown(home + '/Mail', int(uid) ,config.gid)
|
||||
os.mkdir('/var/mail/' + login,0770)
|
||||
os.chown('/var/mail/' + login, int(uid) ,8)
|
||||
|
||||
### Mail
|
||||
os.mkdir(home + '/Mail', 0700)
|
||||
os.chown(home + '/Mail', int(uid) ,config.gid)
|
||||
os.mkdir('/var/mail/' + login,0770)
|
||||
os.chown('/var/mail/' + login, int(uid) ,8)
|
||||
|
||||
except :
|
||||
print ERREUR
|
||||
|
|
|
@ -19,11 +19,11 @@ except:
|
|||
|
||||
class droits(gen_config) :
|
||||
def restart(s) :
|
||||
# Rien à faire
|
||||
pass
|
||||
# Rien à faire
|
||||
pass
|
||||
|
||||
def __str__(s):
|
||||
return "droits"
|
||||
return "droits"
|
||||
|
||||
class droits_ldap(crans_ldap,droits) :
|
||||
####### Les groupes
|
||||
|
@ -32,9 +32,9 @@ class droits_ldap(crans_ldap,droits) :
|
|||
# Quels droits donnent l'appartenacne à quel groupe ?
|
||||
groupes = { 'adm' : [ u'Nounou' ] ,
|
||||
'respbats' : [ u'Câbleur' , u'Déconnecteur', u'Nounou' ] ,
|
||||
'moderateurs' : [ u'Modérateur' ] ,
|
||||
'disconnect' : [ u'Déconnecteur' ] ,
|
||||
'webcvs' : [ u'CVSWeb'] }
|
||||
'moderateurs' : [ u'Modérateur' ] ,
|
||||
'disconnect' : [ u'Déconnecteur' ] ,
|
||||
'webcvs' : [ u'CVSWeb'] }
|
||||
|
||||
####### Les ML
|
||||
# Le + devant un nom de ML indique une synchronisqtion
|
||||
|
@ -42,96 +42,96 @@ class droits_ldap(crans_ldap,droits) :
|
|||
# des abonnés si le droit est retiré
|
||||
mailing_listes = { 'roots' : [ u'Nounou', u'Apprenti' ],
|
||||
'+nounou' : [ u'Nounou', u'Apprenti' ],
|
||||
'respbats' : [ u'Câbleur', u'Nounou' ],
|
||||
'+moderateurs' : [ u'Modérateur' ],
|
||||
'+disconnect' : [ u'Déconnecteur' ] }
|
||||
|
||||
'respbats' : [ u'Câbleur', u'Nounou' ],
|
||||
'+moderateurs' : [ u'Modérateur' ],
|
||||
'+disconnect' : [ u'Déconnecteur' ] }
|
||||
|
||||
def build_group(self) :
|
||||
""" Reconstruit les groupes dans la base LDAP """
|
||||
self.anim.iter = len( self.groupes.keys() )
|
||||
for group, fonctions in self.groupes.items() :
|
||||
self.anim.cycle()
|
||||
# Qui doit être dans ce groupe ?
|
||||
res = []
|
||||
for f in fonctions :
|
||||
res += self.search('droits=%s' % f)['adherent']
|
||||
""" Reconstruit les groupes dans la base LDAP """
|
||||
self.anim.iter = len( self.groupes.keys() )
|
||||
for group, fonctions in self.groupes.items() :
|
||||
self.anim.cycle()
|
||||
# Qui doit être dans ce groupe ?
|
||||
res = []
|
||||
for f in fonctions :
|
||||
res += self.search('droits=%s' % f)['adherent']
|
||||
|
||||
# Récupération de la constitution du groupe actuel
|
||||
dn = 'cn=%s,%s' % (group, self.base_group_dn)
|
||||
data = self.conn.search_s(dn ,0,'objectClass=posixGroup')[0][1]
|
||||
init_data = data.copy()
|
||||
|
||||
# Supression de tout les membres
|
||||
data['memberUid'] = []
|
||||
|
||||
# Ajout des bonnes personnes
|
||||
for adher in res :
|
||||
uid = preattr(adher.compte())[1]
|
||||
if uid and uid not in data['memberUid'] :
|
||||
data['memberUid'].append(uid)
|
||||
|
||||
# Sauvegarde
|
||||
# Récupération de la constitution du groupe actuel
|
||||
dn = 'cn=%s,%s' % (group, self.base_group_dn)
|
||||
data = self.conn.search_s(dn ,0,'objectClass=posixGroup')[0][1]
|
||||
init_data = data.copy()
|
||||
|
||||
# Supression de tout les membres
|
||||
data['memberUid'] = []
|
||||
|
||||
# Ajout des bonnes personnes
|
||||
for adher in res :
|
||||
uid = preattr(adher.compte())[1]
|
||||
if uid and uid not in data['memberUid'] :
|
||||
data['memberUid'].append(uid)
|
||||
|
||||
# Sauvegarde
|
||||
modlist = ldap.modlist.modifyModlist(init_data,data)
|
||||
self.conn.modify_s(dn,modlist)
|
||||
self.conn.modify_s(dn,modlist)
|
||||
|
||||
def print_liste(self,poste) :
|
||||
""" Donne la liste des membres actifs """
|
||||
for adh in self.search('droits=%s&chbre!=EXT' % poste)['adherent'] :
|
||||
print "%s %s" % (adh.nom(), adh.prenom())
|
||||
|
||||
""" Donne la liste des membres actifs """
|
||||
for adh in self.search('droits=%s&chbre!=EXT' % poste)['adherent'] :
|
||||
print "%s %s" % (adh.nom(), adh.prenom())
|
||||
|
||||
def sync_ML(self) :
|
||||
self.anim.iter = len( self.mailing_listes.keys() )
|
||||
for ML, fonctions in self.mailing_listes.items() :
|
||||
self.anim.cycle()
|
||||
if ML[0] == '+' :
|
||||
ML = ML[1:]
|
||||
only_add = 1
|
||||
else :
|
||||
only_add = 0
|
||||
|
||||
# Instance correspondant à la ML
|
||||
mlist = MailList.MailList(ML)
|
||||
self.mlist_to_unlock = mlist
|
||||
|
||||
# Qui doit être dans cette ML ?
|
||||
res = []
|
||||
for f in fonctions :
|
||||
res += self.search('droits=%s' % f)['adherent']
|
||||
|
||||
# Liste des personnes déja inscrites
|
||||
deja_inscrits = {} # { email en miniscules : email avec case n'importe comment }
|
||||
for addr in mlist.getMemberCPAddresses(mlist.getMembers()):
|
||||
deja_inscrits[addr.lower()] = addr
|
||||
|
||||
# Mails à ajouter
|
||||
to_add = []
|
||||
mail_traite = []
|
||||
for adher in res :
|
||||
mail = adher.mail().lower()
|
||||
if mail in mail_traite : continue
|
||||
mail_traite.append(mail)
|
||||
if mail.find('@') == -1 : mail += '@crans.org'
|
||||
if mail not in deja_inscrits.keys() :
|
||||
# Visiblement pas inscrit
|
||||
to_add.append([ mail, adher.Nom() ])
|
||||
else :
|
||||
# L'adhérent est déja inscrit
|
||||
deja_inscrits.pop(mail)
|
||||
|
||||
# Ajout
|
||||
for mail, nom in to_add :
|
||||
pw = Utils.MakeRandomPassword()
|
||||
userdesc = UserDesc( mail, nom, pw)
|
||||
mlist.ApprovedAddMember(userdesc)
|
||||
if not only_add :
|
||||
# Supression des personnes inscritees en trop
|
||||
for mail in deja_inscrits.values() :
|
||||
mlist.ApprovedDeleteMember(mail)
|
||||
|
||||
mlist.Save()
|
||||
mlist.Unlock()
|
||||
self.mlist_to_unlock = None
|
||||
|
||||
self.anim.iter = len( self.mailing_listes.keys() )
|
||||
for ML, fonctions in self.mailing_listes.items() :
|
||||
self.anim.cycle()
|
||||
if ML[0] == '+' :
|
||||
ML = ML[1:]
|
||||
only_add = 1
|
||||
else :
|
||||
only_add = 0
|
||||
|
||||
# Instance correspondant à la ML
|
||||
mlist = MailList.MailList(ML)
|
||||
self.mlist_to_unlock = mlist
|
||||
|
||||
# Qui doit être dans cette ML ?
|
||||
res = []
|
||||
for f in fonctions :
|
||||
res += self.search('droits=%s' % f)['adherent']
|
||||
|
||||
# Liste des personnes déja inscrites
|
||||
deja_inscrits = {} # { email en miniscules : email avec case n'importe comment }
|
||||
for addr in mlist.getMemberCPAddresses(mlist.getMembers()):
|
||||
deja_inscrits[addr.lower()] = addr
|
||||
|
||||
# Mails à ajouter
|
||||
to_add = []
|
||||
mail_traite = []
|
||||
for adher in res :
|
||||
mail = adher.mail().lower()
|
||||
if mail in mail_traite : continue
|
||||
mail_traite.append(mail)
|
||||
if mail.find('@') == -1 : mail += '@crans.org'
|
||||
if mail not in deja_inscrits.keys() :
|
||||
# Visiblement pas inscrit
|
||||
to_add.append([ mail, adher.Nom() ])
|
||||
else :
|
||||
# L'adhérent est déja inscrit
|
||||
deja_inscrits.pop(mail)
|
||||
|
||||
# Ajout
|
||||
for mail, nom in to_add :
|
||||
pw = Utils.MakeRandomPassword()
|
||||
userdesc = UserDesc( mail, nom, pw)
|
||||
mlist.ApprovedAddMember(userdesc)
|
||||
if not only_add :
|
||||
# Supression des personnes inscritees en trop
|
||||
for mail in deja_inscrits.values() :
|
||||
mlist.ApprovedDeleteMember(mail)
|
||||
|
||||
mlist.Save()
|
||||
mlist.Unlock()
|
||||
self.mlist_to_unlock = None
|
||||
|
||||
def gen_conf(self) :
|
||||
self.anim = anim('\tconfiguration groupes')
|
||||
try:
|
||||
|
@ -170,10 +170,10 @@ class droits_openbsd(droits) :
|
|||
"""
|
||||
master = ""
|
||||
group = "wheel:*:0:root"
|
||||
self.anim.iter = 2
|
||||
self.anim.iter = 2
|
||||
for fonction in ("Nounou", "Apprenti"):
|
||||
self.anim.cycle()
|
||||
# Qui doit être dans ce groupe ?
|
||||
self.anim.cycle()
|
||||
# Qui doit être dans ce groupe ?
|
||||
res = crans_ldap().search('droits=%s' % fonction)['adherent']
|
||||
for a in res:
|
||||
if fonction == "Nounou":
|
||||
|
@ -234,13 +234,13 @@ class droits_openbsd(droits) :
|
|||
|
||||
if __name__ == '__main__' :
|
||||
if '-h' in sys.argv or '--help' in sys.argv or len(sys.argv) == 1 :
|
||||
print "%s <switch>" % sys.argv[0].split('/')[-1].split('.')[0]
|
||||
print "Génération de la liste des personnes avec le(s) droit(s) donné(s)."
|
||||
sys.exit(255)
|
||||
|
||||
print "%s <switch>" % sys.argv[0].split('/')[-1].split('.')[0]
|
||||
print "Génération de la liste des personnes avec le(s) droit(s) donné(s)."
|
||||
sys.exit(255)
|
||||
|
||||
cl = droits()
|
||||
for arg in sys.argv[1:] :
|
||||
titre = "%s : " % arg
|
||||
print titre
|
||||
print "-" * len (titre)
|
||||
cl.print_liste(unicode(arg,'iso-8859-1'))
|
||||
for arg in sys.argv[1:] :
|
||||
titre = "%s : " % arg
|
||||
print titre
|
||||
print "-" * len (titre)
|
||||
cl.print_liste(unicode(arg,'iso-8859-1'))
|
||||
|
|
|
@ -25,25 +25,25 @@ class exemptions(gen_config) :
|
|||
restart_cmd = ""
|
||||
|
||||
def __str__ (self) :
|
||||
return "exemptions"
|
||||
return "exemptions"
|
||||
|
||||
def _gen (self) :
|
||||
|
||||
machines = crans_ldap().search('exempt=*')['machine']
|
||||
|
||||
pgsql = PgSQL.connect(host='/var/run/postgresql', database='filtrage', user='crans')
|
||||
curseur = pgsql.cursor()
|
||||
|
||||
requete="DELETE FROM exemptes"
|
||||
curseur.execute(requete)
|
||||
|
||||
for couple in self.base :
|
||||
requete="INSERT INTO exemptes (ip_crans,ip_dest) VALUES ('%s','%s')" % (couple[0],couple[1])
|
||||
curseur.execute(requete)
|
||||
|
||||
for machine in machines :
|
||||
for destination in machine.exempt() :
|
||||
requete="INSERT INTO exemptes (ip_crans,ip_dest) VALUES ('%s','%s')" % (machine.ip(),destination)
|
||||
curseur.execute(requete)
|
||||
|
||||
pgsql.commit()
|
||||
|
||||
machines = crans_ldap().search('exempt=*')['machine']
|
||||
|
||||
pgsql = PgSQL.connect(host='/var/run/postgresql', database='filtrage', user='crans')
|
||||
curseur = pgsql.cursor()
|
||||
|
||||
requete="DELETE FROM exemptes"
|
||||
curseur.execute(requete)
|
||||
|
||||
for couple in self.base :
|
||||
requete="INSERT INTO exemptes (ip_crans,ip_dest) VALUES ('%s','%s')" % (couple[0],couple[1])
|
||||
curseur.execute(requete)
|
||||
|
||||
for machine in machines :
|
||||
for destination in machine.exempt() :
|
||||
requete="INSERT INTO exemptes (ip_crans,ip_dest) VALUES ('%s','%s')" % (machine.ip(),destination)
|
||||
curseur.execute(requete)
|
||||
|
||||
pgsql.commit()
|
||||
|
|
|
@ -44,23 +44,23 @@ class base_reconfigure :
|
|||
if not to_do :
|
||||
if debug : print 'Lecture services à redémarrer dans la base LDAP'
|
||||
auto = 1
|
||||
to_do = {}
|
||||
to_do = {}
|
||||
# Création de la liste de ce qu'il y a à faire
|
||||
for serv in db.services_to_restart() :
|
||||
# Services spéciaux portant sur plusieurs machines
|
||||
to_add = self.__service_develop.get(serv.nom,[])
|
||||
if to_add :
|
||||
for nom in to_add :
|
||||
for t in serv.start :
|
||||
db.services_to_restart(nom,serv.args,t)
|
||||
if time() > t :
|
||||
to_do[nom] = serv.args
|
||||
for t in serv.start :
|
||||
db.services_to_restart(nom,serv.args,t)
|
||||
if time() > t :
|
||||
to_do[nom] = serv.args
|
||||
db.services_to_restart('-' + serv.nom)
|
||||
else :
|
||||
for t in serv.start :
|
||||
if time() > t :
|
||||
to_do[serv.nom] = serv.args
|
||||
break
|
||||
else :
|
||||
for t in serv.start :
|
||||
if time() > t :
|
||||
to_do[serv.nom] = serv.args
|
||||
break
|
||||
else :
|
||||
auto = 0
|
||||
if debug : print 'Services à redémarrer imposés (non lecture de la base LDAP)'
|
||||
|
@ -87,8 +87,8 @@ class base_reconfigure :
|
|||
reste = db.services_to_restart()
|
||||
if reste :
|
||||
print "Reste à faire :"
|
||||
for s in reste :
|
||||
print '\t%s' % s
|
||||
for s in reste :
|
||||
print '\t%s' % s
|
||||
else :
|
||||
print "Plus rien à faire"
|
||||
|
||||
|
@ -116,7 +116,7 @@ class rouge(base_reconfigure) :
|
|||
def dns(self) :
|
||||
from gen_confs.bind import dns
|
||||
self._do(dns(),self._machines())
|
||||
|
||||
|
||||
def dhcp(self) :
|
||||
from gen_confs.dhcpd import dhcp
|
||||
self._do(dhcp(),self._machines())
|
||||
|
@ -134,14 +134,14 @@ class rouge(base_reconfigure) :
|
|||
l'affichage des résultats formera le corps du mail """
|
||||
from supervison import mail
|
||||
self._do(mail(trucs))
|
||||
|
||||
|
||||
def switch(self,chambres) :
|
||||
from gen_confs.switchs import switch
|
||||
self._do(switch(chambres))
|
||||
|
||||
def exemptions(self) :
|
||||
from exemptions import exemptions
|
||||
self._do(exemptions())
|
||||
self._do(exemptions())
|
||||
|
||||
class zamok(base_reconfigure) :
|
||||
# Tout est dans le parent
|
||||
|
@ -243,7 +243,7 @@ class vert(base_reconfigure) :
|
|||
def del_user(self,args) :
|
||||
from adherents import del_user
|
||||
self._do(del_user(args))
|
||||
|
||||
|
||||
def mail_bienvenue(self,mails) :
|
||||
from adherents import mail_bienvenue
|
||||
self._do(mail_bienvenue(mails))
|
||||
|
@ -290,7 +290,7 @@ if __name__ == '__main__' :
|
|||
elif opt == '--list' :
|
||||
print 'Services à redémarrer :'
|
||||
for s in db.services_to_restart() :
|
||||
print '\t%s' % s
|
||||
print '\t%s' % s
|
||||
sys.exit(0)
|
||||
|
||||
elif opt == '--reconnect' :
|
||||
|
|
|
@ -15,32 +15,32 @@ class squid(gen_config) :
|
|||
restart_cmd = '/etc/init.d/squid reload'
|
||||
|
||||
def __str__(self) :
|
||||
return str(self.__class__).replace('_','-').split('.')[2]
|
||||
return str(self.__class__).replace('_','-').split('.')[2]
|
||||
|
||||
def _gen(self) :
|
||||
self._mklist()
|
||||
self._mklist()
|
||||
|
||||
def _mklist(self) :
|
||||
fic = self._open_conf(self.FICHIER)
|
||||
# recherche_bl :
|
||||
# 1 : search sur champ blacklist et clubs compris
|
||||
# 0 : search plus général et clubs exclus
|
||||
if self.recherche_bl==1:
|
||||
liste = self.db.search("paiement=ok&blacklist=*%s*"%self.chaine)
|
||||
l_proprio = liste["adherent"]+liste["club"]
|
||||
else:
|
||||
l_proprio = self.db.search('paiement=ok&' + self.chaine)["adherent"]
|
||||
self.anim.iter=len(l_proprio)
|
||||
for proprio in l_proprio :
|
||||
self.anim.cycle()
|
||||
if self.recherche_bl==0 or self.chaine in proprio.blacklist_actif():
|
||||
# Pas la peine de renvoyer les machines complètement bloqués
|
||||
for m in proprio.machines():
|
||||
if not 'bloq' in m.blacklist_actif():
|
||||
fic.write(m.Nom()+'\n')
|
||||
fic.close()
|
||||
fic = self._open_conf(self.FICHIER)
|
||||
# recherche_bl :
|
||||
# 1 : search sur champ blacklist et clubs compris
|
||||
# 0 : search plus général et clubs exclus
|
||||
if self.recherche_bl==1:
|
||||
liste = self.db.search("paiement=ok&blacklist=*%s*"%self.chaine)
|
||||
l_proprio = liste["adherent"]+liste["club"]
|
||||
else:
|
||||
l_proprio = self.db.search('paiement=ok&' + self.chaine)["adherent"]
|
||||
self.anim.iter=len(l_proprio)
|
||||
for proprio in l_proprio :
|
||||
self.anim.cycle()
|
||||
if self.recherche_bl==0 or self.chaine in proprio.blacklist_actif():
|
||||
# Pas la peine de renvoyer les machines complètement bloqués
|
||||
for m in proprio.machines():
|
||||
if not 'bloq' in m.blacklist_actif():
|
||||
fic.write(m.Nom()+'\n')
|
||||
fic.close()
|
||||
|
||||
|
||||
|
||||
class squid_upload(squid) :
|
||||
""" Genère le fichier blacklist-upload pour squid """
|
||||
FICHIER = "/etc/squid/blacklist_upload"
|
||||
|
@ -66,17 +66,17 @@ class squid_carte(squid) :
|
|||
recherche_bl = 0
|
||||
|
||||
if not bl_carte_et_actif :
|
||||
# Inutile de relancer squid si la blacklist n'est pas activée
|
||||
restart_cmd = ''
|
||||
# Inutile de relancer squid si la blacklist n'est pas activée
|
||||
restart_cmd = ''
|
||||
|
||||
def _gen(self) :
|
||||
# Liste vide si la blacklist n'est pas activée
|
||||
if not bl_carte_et_actif :
|
||||
fic = self._open_conf(self.FICHIER)
|
||||
# on vide la blackliste
|
||||
fic.close()
|
||||
return
|
||||
self._mklist()
|
||||
# Liste vide si la blacklist n'est pas activée
|
||||
if not bl_carte_et_actif :
|
||||
fic = self._open_conf(self.FICHIER)
|
||||
# on vide la blackliste
|
||||
fic.close()
|
||||
return
|
||||
self._mklist()
|
||||
|
||||
class squid_chbre(squid) :
|
||||
""" Genère le fichier blacklist-chbre pour squid """
|
||||
|
|
|
@ -170,164 +170,164 @@ class autostatus(gen_config) :
|
|||
# FIN DE LA CONFIGURATION
|
||||
|
||||
def __str__ (self) :
|
||||
return "autostatus"
|
||||
return "autostatus"
|
||||
|
||||
def make_config (self, dico ) :
|
||||
"""
|
||||
Transforme le dico en suite lignes de configuration
|
||||
"""
|
||||
liste = dico.keys()
|
||||
liste.sort()
|
||||
append = ""
|
||||
for i in liste :
|
||||
append = append + " ".join( dico[i] ) + "\n"
|
||||
return append.encode('iso-8859-15')
|
||||
"""
|
||||
Transforme le dico en suite lignes de configuration
|
||||
"""
|
||||
liste = dico.keys()
|
||||
liste.sort()
|
||||
append = ""
|
||||
for i in liste :
|
||||
append = append + " ".join( dico[i] ) + "\n"
|
||||
return append.encode('iso-8859-15')
|
||||
|
||||
def mail_contact (self, nom) :
|
||||
# retourne le mail à qui envoyer les avis pour un serveur
|
||||
if nom in self.contact.keys() :
|
||||
return self.contact[nom]
|
||||
else :
|
||||
return 'nobody'
|
||||
|
||||
# retourne le mail à qui envoyer les avis pour un serveur
|
||||
if nom in self.contact.keys() :
|
||||
return self.contact[nom]
|
||||
else :
|
||||
return 'nobody'
|
||||
|
||||
def _gen (self) :
|
||||
|
||||
# machines crans
|
||||
################
|
||||
|
||||
machines = crans().machines()
|
||||
|
||||
# tri des machines par type
|
||||
bornes = {}
|
||||
switchs = {}
|
||||
serveurs = {}
|
||||
ferme = {}
|
||||
# machines crans
|
||||
################
|
||||
|
||||
machines = crans().machines()
|
||||
|
||||
# tri des machines par type
|
||||
bornes = {}
|
||||
switchs = {}
|
||||
serveurs = {}
|
||||
ferme = {}
|
||||
|
||||
# tri des machines
|
||||
for m in machines :
|
||||
# tri des machines
|
||||
for m in machines :
|
||||
|
||||
# machine exclue
|
||||
if m.nom() in self.exclude :
|
||||
continue
|
||||
|
||||
# les bornes
|
||||
if m.canal() :
|
||||
# C'est une borne
|
||||
if m.info() :
|
||||
# on regarde si c'est une borne de batiment
|
||||
if ( m.info()[0][0:3] == "Au " ) and ( len(m.info()[0]) == 5 ) :
|
||||
bornes[ "1-" + m.info()[0][4]+m.info()[0][3] + "-" + m.nom() ] = [ m.nom().split(".")[0] , m.nom() , 'none' , self.mail_contact(m.nom()) , m.info()[0] ]
|
||||
else :
|
||||
bornes[ "2-" + m.info()[0] + m.nom() ] = [ m.nom().split(".")[0] , m.nom() , 'none' , self.mail_contact(m.nom()) , m.info()[0] ]
|
||||
else :
|
||||
# on met les bornes non définies à la fin (ordre alphabétique)
|
||||
bornes[ "3-" + m.nom() ] = [ m.nom().split(".")[0] , m.nom() , 'none' , self.mail_contact(m.nom()) , 'Inutilise' ]
|
||||
# machine exclue
|
||||
if m.nom() in self.exclude :
|
||||
continue
|
||||
|
||||
# les bornes
|
||||
if m.canal() :
|
||||
# C'est une borne
|
||||
if m.info() :
|
||||
# on regarde si c'est une borne de batiment
|
||||
if ( m.info()[0][0:3] == "Au " ) and ( len(m.info()[0]) == 5 ) :
|
||||
bornes[ "1-" + m.info()[0][4]+m.info()[0][3] + "-" + m.nom() ] = [ m.nom().split(".")[0] , m.nom() , 'none' , self.mail_contact(m.nom()) , m.info()[0] ]
|
||||
else :
|
||||
bornes[ "2-" + m.info()[0] + m.nom() ] = [ m.nom().split(".")[0] , m.nom() , 'none' , self.mail_contact(m.nom()) , m.info()[0] ]
|
||||
else :
|
||||
# on met les bornes non définies à la fin (ordre alphabétique)
|
||||
bornes[ "3-" + m.nom() ] = [ m.nom().split(".")[0] , m.nom() , 'none' , self.mail_contact(m.nom()) , 'Inutilise' ]
|
||||
|
||||
# les switchs
|
||||
elif m.info() and 'switch' in m.info()[0].lower() :
|
||||
# les switchs
|
||||
elif m.info() and 'switch' in m.info()[0].lower() :
|
||||
|
||||
# est ce que c'est un batiment
|
||||
if 'bat' == m.nom()[0:3] :
|
||||
index = '1-' + m.nom().split(".")[0]
|
||||
else :
|
||||
index = '0-' + m.nom().split(".")[0]
|
||||
|
||||
# on ajoute au dictionnaire
|
||||
switchs[ index ] = [ m.nom().split(".")[0] , m.nom() , 'none' , self.mail_contact(m.nom()) , m.info()[0] ]
|
||||
# est ce que c'est un batiment
|
||||
if 'bat' == m.nom()[0:3] :
|
||||
index = '1-' + m.nom().split(".")[0]
|
||||
else :
|
||||
index = '0-' + m.nom().split(".")[0]
|
||||
|
||||
# on ajoute au dictionnaire
|
||||
switchs[ index ] = [ m.nom().split(".")[0] , m.nom() , 'none' , self.mail_contact(m.nom()) , m.info()[0] ]
|
||||
|
||||
# la ferme
|
||||
elif '.ferme.crans.org' in m.nom() :
|
||||
nom = ".".join(m.nom().split(".")[0:2])
|
||||
if m.info() :
|
||||
ferme[ nom ] = [ nom , m.nom() , 'none' , self.mail_contact(m.nom()) , m.info()[0] ]
|
||||
else :
|
||||
ferme[ nom ] = [ nom , m.nom() , 'none' , self.mail_contact(m.nom()) , 'Infos non disponibles' ]
|
||||
|
||||
# les serveurs
|
||||
else :
|
||||
if ".wifi.crans.org" in m.nom() :
|
||||
nom = m.nom().split(".")[0] + ".wifi"
|
||||
else :
|
||||
nom = m.nom().split(".")[0]
|
||||
if m.info() :
|
||||
serveurs[ nom ] = [ nom , m.nom() , 'none' , self.mail_contact(m.nom()) , m.info()[0] ]
|
||||
else :
|
||||
serveurs[ nom ] = [ nom , m.nom() , 'none' , self.mail_contact(m.nom()) , 'Infos non disponibles' ]
|
||||
|
||||
# route vers l'extérieur
|
||||
########################
|
||||
|
||||
# on récupère la route vers l'extérieur
|
||||
traceroute = commands.getoutput("/usr/bin/traceroute www.free.fr 2> /dev/null | sed 's/\*//g' | sed 's/ */ /g' | sed 's/^ //g' | sed 's/[(,)]//g' | cut -d ' ' -f 2,3").split("\n")
|
||||
|
||||
# initialisation des variables
|
||||
in_renater = 0
|
||||
route_to_ext = ''
|
||||
depends_to_ext = ''
|
||||
|
||||
for routeur in traceroute :
|
||||
|
||||
# on commence à rentrer dans la chaine des routeurs renater
|
||||
if 'renater.fr' in routeur :
|
||||
in_renater = 1
|
||||
|
||||
# on est plus dans les routeurs renater donc on arrête
|
||||
if in_renater and not 'renater.fr' in routeur :
|
||||
continue
|
||||
|
||||
# ajout du routeur
|
||||
|
||||
# ip
|
||||
tmp_ip = routeur.split(' ')[1]
|
||||
|
||||
# nom & desciption
|
||||
if routeur.split(' ')[1] in self.infos_routeurs.keys() :
|
||||
tmp_name = self.infos_routeurs[tmp_ip][0]
|
||||
tmp_desc = self.infos_routeurs[tmp_ip][1]
|
||||
else :
|
||||
tmp_name = routeur.split(' ')[0].split('.')[0]
|
||||
tmp_desc = 'Pas de description'
|
||||
|
||||
# dépendances
|
||||
if not depends_to_ext :
|
||||
tmp_depends = 'none'
|
||||
depends_to_ext = tmp_name
|
||||
else :
|
||||
tmp_depends = depends_to_ext
|
||||
depends_to_ext += ',' + tmp_name
|
||||
|
||||
# on l'ajoute à la route
|
||||
if route_to_ext :
|
||||
route_to_ext += '\n'
|
||||
route_to_ext += '%s %s %s %s %s' % (tmp_name, tmp_ip, tmp_depends,self.mail_contact(tmp_name),tmp_desc)
|
||||
# la ferme
|
||||
elif '.ferme.crans.org' in m.nom() :
|
||||
nom = ".".join(m.nom().split(".")[0:2])
|
||||
if m.info() :
|
||||
ferme[ nom ] = [ nom , m.nom() , 'none' , self.mail_contact(m.nom()) , m.info()[0] ]
|
||||
else :
|
||||
ferme[ nom ] = [ nom , m.nom() , 'none' , self.mail_contact(m.nom()) , 'Infos non disponibles' ]
|
||||
|
||||
# les serveurs
|
||||
else :
|
||||
if ".wifi.crans.org" in m.nom() :
|
||||
nom = m.nom().split(".")[0] + ".wifi"
|
||||
else :
|
||||
nom = m.nom().split(".")[0]
|
||||
if m.info() :
|
||||
serveurs[ nom ] = [ nom , m.nom() , 'none' , self.mail_contact(m.nom()) , m.info()[0] ]
|
||||
else :
|
||||
serveurs[ nom ] = [ nom , m.nom() , 'none' , self.mail_contact(m.nom()) , 'Infos non disponibles' ]
|
||||
|
||||
# route vers l'extérieur
|
||||
########################
|
||||
|
||||
# on récupère la route vers l'extérieur
|
||||
traceroute = commands.getoutput("/usr/bin/traceroute www.free.fr 2> /dev/null | sed 's/\*//g' | sed 's/ */ /g' | sed 's/^ //g' | sed 's/[(,)]//g' | cut -d ' ' -f 2,3").split("\n")
|
||||
|
||||
# initialisation des variables
|
||||
in_renater = 0
|
||||
route_to_ext = ''
|
||||
depends_to_ext = ''
|
||||
|
||||
for routeur in traceroute :
|
||||
|
||||
# on commence à rentrer dans la chaine des routeurs renater
|
||||
if 'renater.fr' in routeur :
|
||||
in_renater = 1
|
||||
|
||||
# on est plus dans les routeurs renater donc on arrête
|
||||
if in_renater and not 'renater.fr' in routeur :
|
||||
continue
|
||||
|
||||
# ajout du routeur
|
||||
|
||||
# ip
|
||||
tmp_ip = routeur.split(' ')[1]
|
||||
|
||||
# nom & desciption
|
||||
if routeur.split(' ')[1] in self.infos_routeurs.keys() :
|
||||
tmp_name = self.infos_routeurs[tmp_ip][0]
|
||||
tmp_desc = self.infos_routeurs[tmp_ip][1]
|
||||
else :
|
||||
tmp_name = routeur.split(' ')[0].split('.')[0]
|
||||
tmp_desc = 'Pas de description'
|
||||
|
||||
# dépendances
|
||||
if not depends_to_ext :
|
||||
tmp_depends = 'none'
|
||||
depends_to_ext = tmp_name
|
||||
else :
|
||||
tmp_depends = depends_to_ext
|
||||
depends_to_ext += ',' + tmp_name
|
||||
|
||||
# on l'ajoute à la route
|
||||
if route_to_ext :
|
||||
route_to_ext += '\n'
|
||||
route_to_ext += '%s %s %s %s %s' % (tmp_name, tmp_ip, tmp_depends,self.mail_contact(tmp_name),tmp_desc)
|
||||
|
||||
# services extérieurs
|
||||
#####################
|
||||
|
||||
services_exterieurs = {}
|
||||
for key in self.services_exterieurs.keys() :
|
||||
s = self.services_exterieurs[key]
|
||||
if s[2] :
|
||||
services_exterieurs[ key ] = [ s[0] + ':' + str(s[2]), s[1] , depends_to_ext, s[4] , s[3] ]
|
||||
else :
|
||||
services_exterieurs[ key ] = [ s[0] , s[1] , depends_to_ext, s[4] , s[3] ]
|
||||
# services extérieurs
|
||||
#####################
|
||||
|
||||
services_exterieurs = {}
|
||||
for key in self.services_exterieurs.keys() :
|
||||
s = self.services_exterieurs[key]
|
||||
if s[2] :
|
||||
services_exterieurs[ key ] = [ s[0] + ':' + str(s[2]), s[1] , depends_to_ext, s[4] , s[3] ]
|
||||
else :
|
||||
services_exterieurs[ key ] = [ s[0] , s[1] , depends_to_ext, s[4] , s[3] ]
|
||||
|
||||
# génération du fichier
|
||||
#######################
|
||||
|
||||
file = self._open_conf(self.CONFFILE, "#")
|
||||
|
||||
# génère le dictionnaire pour les modifications
|
||||
dico = {}
|
||||
dico['switchs'] = self.make_config(switchs)
|
||||
dico['bornes'] = self.make_config(bornes)
|
||||
dico['serveurs'] = self.make_config(serveurs)
|
||||
dico['ferme'] = self.make_config(ferme)
|
||||
dico['route'] = route_to_ext.encode('iso-8859-15')
|
||||
dico['exterieur'] = self.make_config(services_exterieurs)
|
||||
|
||||
# on écrit dans le fichier de configuration
|
||||
file.write( self.matrice % dico )
|
||||
|
||||
# on ferme le fichier
|
||||
file.close()
|
||||
# génération du fichier
|
||||
#######################
|
||||
|
||||
file = self._open_conf(self.CONFFILE, "#")
|
||||
|
||||
# génère le dictionnaire pour les modifications
|
||||
dico = {}
|
||||
dico['switchs'] = self.make_config(switchs)
|
||||
dico['bornes'] = self.make_config(bornes)
|
||||
dico['serveurs'] = self.make_config(serveurs)
|
||||
dico['ferme'] = self.make_config(ferme)
|
||||
dico['route'] = route_to_ext.encode('iso-8859-15')
|
||||
dico['exterieur'] = self.make_config(services_exterieurs)
|
||||
|
||||
# on écrit dans le fichier de configuration
|
||||
file.write( self.matrice % dico )
|
||||
|
||||
# on ferme le fichier
|
||||
file.close()
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
argument : nom du switch
|
||||
|
||||
procédure de configuration initiale :
|
||||
* mot de passe admin (password manager user-name <username>)
|
||||
* upgrade firmware (copy tftp flash 138.231.136.7 <file>)
|
||||
* reboot (boot)
|
||||
* génération clef ssh (crypto key generate ssh)
|
||||
* copie fichier de conf (copy tftp startup-config 138.231.136.7 <file>)
|
||||
* faire le stacking et le snmpv3 à la main
|
||||
* mot de passe admin (password manager user-name <username>)
|
||||
* upgrade firmware (copy tftp flash 138.231.136.7 <file>)
|
||||
* reboot (boot)
|
||||
* génération clef ssh (crypto key generate ssh)
|
||||
* copie fichier de conf (copy tftp startup-config 138.231.136.7 <file>)
|
||||
* faire le stacking et le snmpv3 à la main
|
||||
pour les reconfiguration juste copier le fichier de conf
|
||||
"""
|
||||
|
||||
|
@ -116,153 +116,153 @@ exit
|
|||
rad_template = "radius-server host %s\n"
|
||||
|
||||
def __init__(self,truc):
|
||||
""" truc est soit :
|
||||
* une _liste_ de chambres => reconfig de ces chambres
|
||||
* un _tulpe_ de noms de switch => reconfig de ces swiths"""
|
||||
self.db = crans_ldap() # connexion LDAP
|
||||
if type(truc) == list :
|
||||
# On enlève les chambres "CRA", "????" et EXT qui n'ont pas besion de config
|
||||
self.chbres = [ch for ch in truc if (ch not in [ "CRA", "????", "EXT" ]) ]
|
||||
self.switch = None
|
||||
else :
|
||||
self.chbres = None
|
||||
self.switch = truc
|
||||
|
||||
""" truc est soit :
|
||||
* une _liste_ de chambres => reconfig de ces chambres
|
||||
* un _tulpe_ de noms de switch => reconfig de ces swiths"""
|
||||
self.db = crans_ldap() # connexion LDAP
|
||||
if type(truc) == list :
|
||||
# On enlève les chambres "CRA", "????" et EXT qui n'ont pas besion de config
|
||||
self.chbres = [ch for ch in truc if (ch not in [ "CRA", "????", "EXT" ]) ]
|
||||
self.switch = None
|
||||
else :
|
||||
self.chbres = None
|
||||
self.switch = truc
|
||||
|
||||
def __str__(self) :
|
||||
return 'switchs'
|
||||
return 'switchs'
|
||||
|
||||
def restart(self) :
|
||||
if self.chbre :
|
||||
# Tout est déja fait
|
||||
return
|
||||
####### Vu qu'il n'y a pas de serveur tftp ici
|
||||
# on excécute pas le truc en dessous
|
||||
#for switch in self.switch :
|
||||
# self.aff = anim('\treboot de %s' % switch)
|
||||
# sw = hptools.switch(switch)
|
||||
# sw.update()
|
||||
if self.chbre :
|
||||
# Tout est déja fait
|
||||
return
|
||||
####### Vu qu'il n'y a pas de serveur tftp ici
|
||||
# on excécute pas le truc en dessous
|
||||
#for switch in self.switch :
|
||||
# self.aff = anim('\treboot de %s' % switch)
|
||||
# sw = hptools.switch(switch)
|
||||
# sw.update()
|
||||
|
||||
def gen_conf(self) :
|
||||
if self.chbres :
|
||||
self.chbres.sort()
|
||||
for chbre in self.chbres :
|
||||
self.configure_chbre(chbre)
|
||||
elif self.switch :
|
||||
for switch in self.switch :
|
||||
self.configure_switch(switch)
|
||||
|
||||
if self.chbres :
|
||||
self.chbres.sort()
|
||||
for chbre in self.chbres :
|
||||
self.configure_chbre(chbre)
|
||||
elif self.switch :
|
||||
for switch in self.switch :
|
||||
self.configure_switch(switch)
|
||||
|
||||
def configure_chbre(self,chbre) :
|
||||
""" Recontigure la chambre fournie chambre """
|
||||
try :
|
||||
bat = chbre[0].lower()
|
||||
if bat in bat_switchs :
|
||||
prise = sw_chbre(chbre)
|
||||
prise.reconfigure() # Vitesse et nom (juste au cas ou ca aurait changé)
|
||||
elif bat in bat_manuels :
|
||||
class prise_non_manageable :
|
||||
def __init__(self,chbre) :
|
||||
self.chbre = chbre
|
||||
|
||||
def __mail(self,sujet) :
|
||||
To = "clef%s@crans.org" % self.chbre[0].lower()
|
||||
From = To
|
||||
conn=smtplib.SMTP('localhost')
|
||||
txt_mail = "From: Crans scripts <%(From)s>\n"
|
||||
txt_mail+= "To: %(To)s\n"
|
||||
txt_mail+= "Subject: (CRANS) %s\n\nMerci." % sujet
|
||||
conn.sendmail(From, To , txt_mail % { 'From' : From, 'To' : To })
|
||||
conn.quit()
|
||||
|
||||
def disable(self) :
|
||||
self.__mail("Chambre %s à débrancher." % self.chbre)
|
||||
def enable(self) :
|
||||
self.__mail("Chambre %s à brancher." % self.chbre)
|
||||
|
||||
prise=prise_non_manageable(chbre)
|
||||
|
||||
else :
|
||||
# Rien a faire
|
||||
print OK
|
||||
return True
|
||||
|
||||
""" Recontigure la chambre fournie chambre """
|
||||
try :
|
||||
bat = chbre[0].lower()
|
||||
if bat in bat_switchs :
|
||||
prise = sw_chbre(chbre)
|
||||
prise.reconfigure() # Vitesse et nom (juste au cas ou ca aurait changé)
|
||||
elif bat in bat_manuels :
|
||||
class prise_non_manageable :
|
||||
def __init__(self,chbre) :
|
||||
self.chbre = chbre
|
||||
|
||||
def __mail(self,sujet) :
|
||||
To = "clef%s@crans.org" % self.chbre[0].lower()
|
||||
From = To
|
||||
conn=smtplib.SMTP('localhost')
|
||||
txt_mail = "From: Crans scripts <%(From)s>\n"
|
||||
txt_mail+= "To: %(To)s\n"
|
||||
txt_mail+= "Subject: (CRANS) %s\n\nMerci." % sujet
|
||||
conn.sendmail(From, To , txt_mail % { 'From' : From, 'To' : To })
|
||||
conn.quit()
|
||||
|
||||
def disable(self) :
|
||||
self.__mail("Chambre %s à débrancher." % self.chbre)
|
||||
def enable(self) :
|
||||
self.__mail("Chambre %s à brancher." % self.chbre)
|
||||
|
||||
prise=prise_non_manageable(chbre)
|
||||
|
||||
else :
|
||||
# Rien a faire
|
||||
print OK
|
||||
return True
|
||||
|
||||
|
||||
a = self.db.search('chbre=%s&paiement=ok' % chbre)
|
||||
a = a['adherent'] + a['club']
|
||||
if a and 'bloq' not in a[0].blacklist_actif() :
|
||||
# Il faut activer la prise
|
||||
anim('\tactivation chbre %s' % chbre)
|
||||
prise.enable()
|
||||
else :
|
||||
# Il faut désactiver la prise
|
||||
anim('\tdésactivation chbre %s' % chbre)
|
||||
prise.disable()
|
||||
|
||||
print OK
|
||||
except :
|
||||
print ERREUR
|
||||
if self.debug :
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
return True
|
||||
a = self.db.search('chbre=%s&paiement=ok' % chbre)
|
||||
a = a['adherent'] + a['club']
|
||||
if a and 'bloq' not in a[0].blacklist_actif() :
|
||||
# Il faut activer la prise
|
||||
anim('\tactivation chbre %s' % chbre)
|
||||
prise.enable()
|
||||
else :
|
||||
# Il faut désactiver la prise
|
||||
anim('\tdésactivation chbre %s' % chbre)
|
||||
prise.disable()
|
||||
|
||||
print OK
|
||||
except :
|
||||
print ERREUR
|
||||
if self.debug :
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def configure_switch(self,switch) :
|
||||
self.aff = anim('\tconfiguration de %s' % switch)
|
||||
try:
|
||||
warn = self.__configure_switch(switch)
|
||||
self.aff.reinit()
|
||||
if warn :
|
||||
print WARNING
|
||||
if self.debug :
|
||||
sys.stderr.write(warn)
|
||||
else :
|
||||
print OK
|
||||
except :
|
||||
self.aff.reinit()
|
||||
print ERREUR
|
||||
self._restore()
|
||||
return 1
|
||||
self.aff = anim('\tconfiguration de %s' % switch)
|
||||
try:
|
||||
warn = self.__configure_switch(switch)
|
||||
self.aff.reinit()
|
||||
if warn :
|
||||
print WARNING
|
||||
if self.debug :
|
||||
sys.stderr.write(warn)
|
||||
else :
|
||||
print OK
|
||||
except :
|
||||
self.aff.reinit()
|
||||
print ERREUR
|
||||
self._restore()
|
||||
return 1
|
||||
|
||||
def __configure_switch(self,switch) :
|
||||
""" Génère le fichier de conf du switch donné """
|
||||
conn = hpswitch(switch)
|
||||
### Récupération données du switch
|
||||
# Batiment et num-Aéro du switch-b
|
||||
bat = switch[3].lower()
|
||||
""" Génère le fichier de conf du switch donné """
|
||||
conn = hpswitch(switch)
|
||||
### Récupération données du switch
|
||||
# Batiment et num-Aéro du switch-b
|
||||
bat = switch[3].lower()
|
||||
sw_num = int(switch[5])
|
||||
|
||||
# Conf radius
|
||||
from secrets import radius_key
|
||||
shuffle(self.rad_servs)
|
||||
from secrets import radius_key
|
||||
shuffle(self.rad_servs)
|
||||
rad = self.rad_template * len(self.rad_servs)
|
||||
params = { 'switch' : switch, 'bat' : bat.upper() ,
|
||||
'radius_key' : radius_key ,
|
||||
'radius-serveurs' : rad[:-1] % tuple(self.rad_servs)}
|
||||
params = { 'switch' : switch, 'bat' : bat.upper() ,
|
||||
'radius_key' : radius_key ,
|
||||
'radius-serveurs' : rad[:-1] % tuple(self.rad_servs)}
|
||||
|
||||
# Nombre de prises et modèle
|
||||
nb_prises = conn.nb_prises()
|
||||
modele = conn.version()
|
||||
if not nb_prises or not modele :
|
||||
raise RuntimeError("Erreur : impossible de déterminer les caractéristiques du switch.")
|
||||
params['modele'] = modele.split()[1]
|
||||
|
||||
# IP
|
||||
params['ip'] = commands.getoutput("host %s" % switch).split()[-1]
|
||||
|
||||
### Configuration prises
|
||||
params['INTERFACES_CONF'] = ''
|
||||
|
||||
# Dictionnaire prise -> chambre
|
||||
prise_chbres = reverse(bat)
|
||||
|
||||
# Prises occupées par des machines du Cr@ns
|
||||
crans_prises={}
|
||||
for m in self.db.search('prise=%s%i*' % (bat.upper(), sw_num))['machine'] :
|
||||
try: crans_prises[m.prise()].append(m)
|
||||
except: crans_prises[m.prise()] = [ m ]
|
||||
# Nombre de prises et modèle
|
||||
nb_prises = conn.nb_prises()
|
||||
modele = conn.version()
|
||||
if not nb_prises or not modele :
|
||||
raise RuntimeError("Erreur : impossible de déterminer les caractéristiques du switch.")
|
||||
params['modele'] = modele.split()[1]
|
||||
|
||||
# IP
|
||||
params['ip'] = commands.getoutput("host %s" % switch).split()[-1]
|
||||
|
||||
### Configuration prises
|
||||
params['INTERFACES_CONF'] = ''
|
||||
|
||||
# Dictionnaire prise -> chambre
|
||||
prise_chbres = reverse(bat)
|
||||
|
||||
# Prises occupées par des machines du Cr@ns
|
||||
crans_prises={}
|
||||
for m in self.db.search('prise=%s%i*' % (bat.upper(), sw_num))['machine'] :
|
||||
try: crans_prises[m.prise()].append(m)
|
||||
except: crans_prises[m.prise()] = [ m ]
|
||||
|
||||
self.aff.iter = nb_prises+1
|
||||
self.aff.iter = nb_prises+1
|
||||
|
||||
# Param-Aètres à affecter-b
|
||||
for key in ( 'uplinks', 'non_uplinks', 'prises_filtrage_mac' ) :
|
||||
|
@ -273,17 +273,17 @@ exit
|
|||
'default_tagged' : [] , 'default_untagged' : [] }
|
||||
|
||||
# G-Aénération de la conf de chaque prise-b
|
||||
for prise in range(1,nb_prises+1):
|
||||
self.aff.cycle()
|
||||
for prise in range(1,nb_prises+1):
|
||||
self.aff.cycle()
|
||||
|
||||
# Conf par d-Aéfaut : activée, autonégociation-b
|
||||
prise_params = { 'prise' : prise , 'speed' : '', 'etat' : '' }
|
||||
annu_prise = '%i%02i' % (sw_num, prise) # prise telle que notée dans l'annuaire
|
||||
|
||||
if uplink_prises[bat].has_key(int(annu_prise)) :
|
||||
### Prise d'uplink
|
||||
prise_params['nom'] = uplink_prises[bat][int(annu_prise)]
|
||||
params['uplinks'].append(prise)
|
||||
# Conf par d-Aéfaut : activée, autonégociation-b
|
||||
prise_params = { 'prise' : prise , 'speed' : '', 'etat' : '' }
|
||||
annu_prise = '%i%02i' % (sw_num, prise) # prise telle que notée dans l'annuaire
|
||||
|
||||
if uplink_prises[bat].has_key(int(annu_prise)) :
|
||||
### Prise d'uplink
|
||||
prise_params['nom'] = uplink_prises[bat][int(annu_prise)]
|
||||
params['uplinks'].append(prise)
|
||||
vlans['default_untagged'].append(prise)
|
||||
vlans['adm_tagged'].append(prise)
|
||||
vlans['wifi_tagged'].append(prise)
|
||||
|
@ -292,31 +292,31 @@ exit
|
|||
|
||||
params['non_uplinks'].append(prise)
|
||||
|
||||
if crans_prises.has_key("%s%s" % (bat.upper(), annu_prise)) :
|
||||
### Prise réservée à l'association
|
||||
wifi=0
|
||||
adm=0
|
||||
autres=0
|
||||
for m in crans_prises["%s%s" % (bat.upper(), annu_prise)] :
|
||||
if m.canal() : wifi+=1
|
||||
if crans_prises.has_key("%s%s" % (bat.upper(), annu_prise)) :
|
||||
### Prise réservée à l'association
|
||||
wifi=0
|
||||
adm=0
|
||||
autres=0
|
||||
for m in crans_prises["%s%s" % (bat.upper(), annu_prise)] :
|
||||
if m.canal() : wifi+=1
|
||||
elif m.Nom().find('.adm.crans.org')!=-1 : adm+=1
|
||||
else : autres+=1
|
||||
if autres==0 and adm==0 :
|
||||
# Vlan wifi uniquement
|
||||
else : autres+=1
|
||||
if autres==0 and adm==0 :
|
||||
# Vlan wifi uniquement
|
||||
if wifi == 1 :
|
||||
prise_params['nom'] = "Wifi_%s" % m.nom().split(".")[0]
|
||||
else :
|
||||
prise_params['nom'] = "Wifi"
|
||||
vlans['wifi_untagged'].append(prise)
|
||||
elif wifi==0 and autres==0 :
|
||||
# Vlan adm uniquement
|
||||
vlans['wifi_untagged'].append(prise)
|
||||
elif wifi==0 and autres==0 :
|
||||
# Vlan adm uniquement
|
||||
if amd == 1 :
|
||||
prise_params['nom'] = m.nom().split(".")[0]
|
||||
else :
|
||||
prise_params['nom'] = "Uplink_adm"
|
||||
vlans['adm_untagged'].append(prise)
|
||||
else :
|
||||
# Tous les vlans
|
||||
else :
|
||||
# Tous les vlans
|
||||
prise_params['nom'] = "Prise_crans"
|
||||
vlans['default_untagged'].append(prise)
|
||||
vlans['adm_tagged'].append(prise)
|
||||
|
@ -337,7 +337,7 @@ exit
|
|||
# Prise non référencée dans l'annuaire
|
||||
prise_params['nom'] = "Pas_dans_l'annuaire"
|
||||
prise_params['etat']='\n disable'
|
||||
params['INTERFACES_CONF'] += self.interface_template % prise_params
|
||||
params['INTERFACES_CONF'] += self.interface_template % prise_params
|
||||
continue
|
||||
|
||||
params['prises_filtrage_mac'].append(prise)
|
||||
|
@ -348,9 +348,9 @@ exit
|
|||
if len(chbres) > 1 : prise_params['nom'] += 's'
|
||||
for chbre in chbres :
|
||||
prise_params['nom'] += '_%s%s' % (bat.upper(), chbre)
|
||||
|
||||
|
||||
# Besoin d'activer la prise ?
|
||||
prise_params['etat']='\n disable'
|
||||
prise_params['etat']='\n disable'
|
||||
for chbre in chbres :
|
||||
res = self.db.search('chbre=%s%s&paiement=ok' % (bat.upper(), chbre) )
|
||||
for res in res['adherent'] + res['club'] :
|
||||
|
@ -358,48 +358,48 @@ exit
|
|||
prise_params['etat']=''
|
||||
break
|
||||
|
||||
params['INTERFACES_CONF'] += self.interface_template % prise_params
|
||||
params['INTERFACES_CONF'] += self.interface_template % prise_params
|
||||
|
||||
# Petite verif
|
||||
if not params['uplinks'] or not params['non_uplinks'] :
|
||||
raise RuntimeError('Switch sans uplink ou sans prise adhérent.')
|
||||
|
||||
def mk_list(liste_prise) :
|
||||
"""
|
||||
transforme une liste de prises en une chaine pour le switch
|
||||
exemple : 1, 3, 4, 5, 6, 7, 9, 10, 11, 12 => 1,3-7,9-12
|
||||
"""
|
||||
# Petite verif
|
||||
if not params['uplinks'] or not params['non_uplinks'] :
|
||||
raise RuntimeError('Switch sans uplink ou sans prise adhérent.')
|
||||
|
||||
def mk_list(liste_prise) :
|
||||
"""
|
||||
transforme une liste de prises en une chaine pour le switch
|
||||
exemple : 1, 3, 4, 5, 6, 7, 9, 10, 11, 12 => 1,3-7,9-12
|
||||
"""
|
||||
if not liste_prise : return ''
|
||||
liste_prise.sort()
|
||||
liste_prise.sort()
|
||||
|
||||
# initialisation
|
||||
i = liste_prise.pop(0)
|
||||
groupe = [ i, i ]
|
||||
result = []
|
||||
|
||||
liste_prise.append(9999) # apparaitra jamais dans la liste
|
||||
|
||||
while liste_prise :
|
||||
nouveau = liste_prise.pop(0)
|
||||
if nouveau == groupe[1] + 1 :
|
||||
groupe[1] += 1
|
||||
else :
|
||||
# Ajout du groupe au résultat
|
||||
if groupe[0] == groupe[1] :
|
||||
result.append(str(groupe[0]))
|
||||
else :
|
||||
result.append('-'.join(map(str,groupe)))
|
||||
# Réinit de groupe
|
||||
groupe = [ nouveau, nouveau ]
|
||||
|
||||
return ','.join(result)
|
||||
# initialisation
|
||||
i = liste_prise.pop(0)
|
||||
groupe = [ i, i ]
|
||||
result = []
|
||||
|
||||
liste_prise.append(9999) # apparaitra jamais dans la liste
|
||||
|
||||
while liste_prise :
|
||||
nouveau = liste_prise.pop(0)
|
||||
if nouveau == groupe[1] + 1 :
|
||||
groupe[1] += 1
|
||||
else :
|
||||
# Ajout du groupe au résultat
|
||||
if groupe[0] == groupe[1] :
|
||||
result.append(str(groupe[0]))
|
||||
else :
|
||||
result.append('-'.join(map(str,groupe)))
|
||||
# Réinit de groupe
|
||||
groupe = [ nouveau, nouveau ]
|
||||
|
||||
return ','.join(result)
|
||||
|
||||
# Saut de ligne parasite
|
||||
params['INTERFACES_CONF'] = params['INTERFACES_CONF'][:-1]
|
||||
|
||||
# Conversion des listes
|
||||
for key in [ 'prises_filtrage_mac', 'uplinks', 'non_uplinks' ] :
|
||||
params[key] = mk_list(params[key])
|
||||
|
||||
# Conversion des listes
|
||||
for key in [ 'prises_filtrage_mac', 'uplinks', 'non_uplinks' ] :
|
||||
params[key] = mk_list(params[key])
|
||||
for key, prises in vlans.items() :
|
||||
vlans[key]=mk_list(prises)
|
||||
|
||||
|
@ -414,19 +414,19 @@ exit
|
|||
|
||||
# Ecriture
|
||||
fd = self._open_conf(self.CONF_REP + switch + '.conf')
|
||||
fd.write(self.config % params)
|
||||
fd.close()
|
||||
|
||||
fd.write(self.config % params)
|
||||
fd.close()
|
||||
|
||||
if __name__ == '__main__' :
|
||||
if '-h' in sys.argv or '--help' in sys.argv or len(sys.argv) == 1 :
|
||||
print "%s <switch>" % sys.argv[0].split('/')[-1].split('.')[0]
|
||||
print "Génération du fichier de configuration des switchs donnés."
|
||||
sys.exit(255)
|
||||
print "%s <switch>" % sys.argv[0].split('/')[-1].split('.')[0]
|
||||
print "Génération du fichier de configuration des switchs donnés."
|
||||
sys.exit(255)
|
||||
|
||||
if sys.argv[1] == 'all' :
|
||||
switchs = all_switchs()
|
||||
switchs = all_switchs()
|
||||
else :
|
||||
switchs = tuple(sys.argv[1:])
|
||||
switchs = tuple(sys.argv[1:])
|
||||
sw = switch(switchs)
|
||||
sw.debug = 1
|
||||
sw.reconfigure()
|
||||
|
|
|
@ -48,12 +48,12 @@ class conf_wifi_ng(gen_config) :
|
|||
clients = self.db.search('host=*.wifi.crans.org&paiement=ok')['machine'] + \
|
||||
invite().machines()
|
||||
bornes = self.db.search('host=*.wifi.crans.org&ipsec!=*')['machine']
|
||||
|
||||
print OK
|
||||
|
||||
print OK
|
||||
self.gen_isakmpd(clients)
|
||||
self.gen_macip(clients, bornes)
|
||||
self.gen_bornes(bornes)
|
||||
self.anim=anim('\tfin reconfigurations')
|
||||
self.anim=anim('\tfin reconfigurations')
|
||||
|
||||
def gen_bornes(self, bornes):
|
||||
"""Génération de la configuration des bornes"""
|
||||
|
@ -64,7 +64,7 @@ class conf_wifi_ng(gen_config) :
|
|||
COMMON = "%s/common" % ROOT
|
||||
DEFAULT = "%s/default" % ROOT
|
||||
for borne in bornes:
|
||||
self.anim=anim('\treconfiguration de %s' % borne.nom())
|
||||
self.anim=anim('\treconfiguration de %s' % borne.nom())
|
||||
# Il s'agit de faire l'union du répertoire common et du
|
||||
# répertoire propre (s'il existe) ou alors du répertoire default
|
||||
# On supprime le répertoire de travail
|
||||
|
@ -134,7 +134,7 @@ NVRAM_wl0_radio=%(ON)d
|
|||
self.anim.cycle()
|
||||
if 'bloq' in machine.blacklist_actif() : continue
|
||||
fd.write("%s %s\n" % (machine.mac(), machine.ip()))
|
||||
self.anim.reinit()
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
||||
def gen_isakmpd(self, clients):
|
||||
|
@ -240,5 +240,5 @@ Netmask= 0.0.0.0
|
|||
fd.write(blocs)
|
||||
fd.write(net_crans)
|
||||
fd.close()
|
||||
self.anim.reinit()
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue