Dplacement de la mthode ipsec.
Il ne faut plus utiliser m.ipsec() pour dterminer si m est une machine wifi. darcs-hash:20060313161212-68412-c18bb0100a5d2bc06988d8a19302616405364aca.gz
This commit is contained in:
parent
9cc6478e4e
commit
858702f0b2
4 changed files with 62 additions and 59 deletions
|
@ -28,7 +28,8 @@ sys.path.append('/usr/scripts/gestion')
|
||||||
import syslog
|
import syslog
|
||||||
import pwd
|
import pwd
|
||||||
from lock import *
|
from lock import *
|
||||||
from ldap_crans import crans_ldap, ann_scol, Machine, crans, invite, hostname
|
from ldap_crans import crans_ldap, ann_scol, crans, invite, hostname
|
||||||
|
from ldap_crans import Machine, MachineWifi
|
||||||
from affich_tools import *
|
from affich_tools import *
|
||||||
from commands import getstatusoutput
|
from commands import getstatusoutput
|
||||||
from iptools import AddrInNet
|
from iptools import AddrInNet
|
||||||
|
@ -223,10 +224,10 @@ class firewall_crans :
|
||||||
insert = '-I'
|
insert = '-I'
|
||||||
else:
|
else:
|
||||||
insert = '-A'
|
insert = '-A'
|
||||||
if machine.ipsec():
|
if isinstance(machine, MachineWifi):
|
||||||
# Machine wifi, c'est la mac de Nectaris
|
# Machine wifi, c'est la mac de Nectaris
|
||||||
iptables("-t nat %s TEST_MAC-IP -s "%(insert)+\
|
iptables("-t nat %s TEST_MAC-IP -s "%(insert)+\
|
||||||
"%s -m mac --mac-source %s -j ACCEPT"%(ip,self.mac_wifi))
|
"%s -m mac --mac-source %s -j ACCEPT"%(ip, self.mac_wifi))
|
||||||
else:
|
else:
|
||||||
# Machine fixe
|
# Machine fixe
|
||||||
iptables("-t nat %s TEST_MAC-IP -s "%(insert)+\
|
iptables("-t nat %s TEST_MAC-IP -s "%(insert)+\
|
||||||
|
@ -322,8 +323,8 @@ class firewall_crans :
|
||||||
# Il faut détruire cette entrée
|
# Il faut détruire cette entrée
|
||||||
iptables("-t nat -D TEST_MAC-IP -s %s -m mac --mac-source %s -j ACCEPT" % (ip, mac))
|
iptables("-t nat -D TEST_MAC-IP -s %s -m mac --mac-source %s -j ACCEPT" % (ip, mac))
|
||||||
else :
|
else :
|
||||||
if ( machine.ipsec() and mac!=self.mac_wifi ) \
|
if (isinstance(machine, MachineWifi) and mac != self.mac_wifi) \
|
||||||
or ( not machine.ipsec() and mac != machine.mac() ) :
|
or (not isinstance(machine, MachineWifi) and mac != machine.mac()):
|
||||||
# La correspondance MAC-IP est fausse => on ajoute la bonne rčgle
|
# La correspondance MAC-IP est fausse => on ajoute la bonne rčgle
|
||||||
self.__test_mac_ip(machine)
|
self.__test_mac_ip(machine)
|
||||||
# Supression de l'ancienne ligne
|
# Supression de l'ancienne ligne
|
||||||
|
|
|
@ -723,6 +723,8 @@ class crans_ldap:
|
||||||
# Croisement
|
# Croisement
|
||||||
bons_dn = [] # liste des dn d'adhérents qui correspondent aux critères
|
bons_dn = [] # liste des dn d'adhérents qui correspondent aux critères
|
||||||
for i in 'adherent', 'club':
|
for i in 'adherent', 'club':
|
||||||
|
if r[i] == None:
|
||||||
|
continue
|
||||||
for a in r[i]:
|
for a in r[i]:
|
||||||
if a[0] in mach_adh and not a[0] in bons_dn:
|
if a[0] in mach_adh and not a[0] in bons_dn:
|
||||||
bons_dn.append(a[0])
|
bons_dn.append(a[0])
|
||||||
|
@ -731,6 +733,8 @@ class crans_ldap:
|
||||||
# Maintenant c'est au tour des bonnes machines
|
# Maintenant c'est au tour des bonnes machines
|
||||||
bons_dn2 = []
|
bons_dn2 = []
|
||||||
for i in 'machineFixe', 'machineWifi':
|
for i in 'machineFixe', 'machineWifi':
|
||||||
|
if r[i] == None:
|
||||||
|
continue
|
||||||
for a in r[i]:
|
for a in r[i]:
|
||||||
dn = string.join(a[0].split(',')[-4:], ',')
|
dn = string.join(a[0].split(',')[-4:], ',')
|
||||||
if dn in bons_dn and not a[0] in bons_dn2:
|
if dn in bons_dn and not a[0] in bons_dn2:
|
||||||
|
@ -1270,27 +1274,24 @@ class base_proprietaire(base_classes_crans):
|
||||||
|
|
||||||
def machines(self):
|
def machines(self):
|
||||||
""" Retourne les machines (instances) appartenant à la classe """
|
""" Retourne les machines (instances) appartenant à la classe """
|
||||||
if self.id():
|
res = []
|
||||||
res = []
|
for r in self.conn.search_s('%s=%s,%s' % (self.idn, self.id(), self.base_dn), 1, Machine.filtre_idn):
|
||||||
try:
|
res.append(self.make(r, self._modifiable))
|
||||||
for r in self.conn.search_s('%s=%s,%s' % ( self.idn,self.id() , self.base_dn ),1,'objectClass=machine'):
|
return res
|
||||||
if r[1].has_key('puissance'):
|
|
||||||
res.append(BorneWifi(r, self._modifiable, self.conn))
|
|
||||||
else:
|
|
||||||
res.append(Machine(r, self._modifiable, self.conn))
|
|
||||||
return res
|
|
||||||
except:
|
|
||||||
return []
|
|
||||||
else:
|
|
||||||
return []
|
|
||||||
|
|
||||||
def machines_fixes(self):
|
def machines_fixes(self):
|
||||||
""" Retourne les machines fixes appartenant à l'instance """
|
""" Retourne les machines fixes appartenant à l'instance """
|
||||||
return filter(lambda x: not x.ipsec(), self.machines())
|
res = []
|
||||||
|
for r in self.conn.search_s('%s=%s,%s' % (self.idn, self.id(), self.base_dn), 1, 'objectClass=machineFixe'):
|
||||||
|
res.append(self.make(r, self._modifiable))
|
||||||
|
return res
|
||||||
|
|
||||||
def machines_wifi(self):
|
def machines_wifi(self):
|
||||||
""" Retourne les machines wifi appartenant à l'instance """
|
""" Retourne les machines wifi appartenant à l'instance """
|
||||||
return filter(lambda x: x.ipsec(), self.machines())
|
res = []
|
||||||
|
for r in self.conn.search_s('%s=%s,%s' % (self.idn, self.id(), self.base_dn), 1, 'objectClass=machineWifi'):
|
||||||
|
res.append(self.make(r, self._modifiable))
|
||||||
|
return res
|
||||||
|
|
||||||
def solde(self, operation=None, comment=None):
|
def solde(self, operation=None, comment=None):
|
||||||
""" Retourne ou modifie le solde d'un propriétaire
|
""" Retourne ou modifie le solde d'un propriétaire
|
||||||
|
@ -1426,16 +1427,14 @@ class base_proprietaire(base_classes_crans):
|
||||||
"""
|
"""
|
||||||
# Note: un peu trop de fonctions pour un club mais ce n'est pas génant
|
# Note: un peu trop de fonctions pour un club mais ce n'est pas génant
|
||||||
|
|
||||||
ret =''
|
ret = ''
|
||||||
if self._init_data:
|
if self._init_data:
|
||||||
nouveau =0
|
nouveau = 0
|
||||||
# Reconfiguration switch si changement de chambre et si machine fixe
|
# Reconfiguration switch si changement de chambre et si machine fixe
|
||||||
if 'chbre' in self.modifs:
|
if 'chbre' in self.modifs:
|
||||||
for m in self.machines():
|
if self.machines_fixe():
|
||||||
if not m.ipsec():
|
self.services_to_restart('switch', [self._data['chbre'][0]])
|
||||||
self.services_to_restart('switch',[self._data['chbre'][0]])
|
self.services_to_restart('switch', [self._init_data.get('chbre', '')[0]])
|
||||||
self.services_to_restart('switch',[self._init_data.get('chbre','')[0]])
|
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
nouveau = 1
|
nouveau = 1
|
||||||
|
|
||||||
|
@ -1466,7 +1465,7 @@ class base_proprietaire(base_classes_crans):
|
||||||
for m in self.machines():
|
for m in self.machines():
|
||||||
self.services_to_restart('macip',[m.ip()] )
|
self.services_to_restart('macip',[m.ip()] )
|
||||||
self.services_to_restart('dns')
|
self.services_to_restart('dns')
|
||||||
if m.ipsec():
|
if isinstance(m, MachineWifi):
|
||||||
self.services_to_restart('conf_wifi_ng')
|
self.services_to_restart('conf_wifi_ng')
|
||||||
self.services_to_restart('ragnarok-dhcp')
|
self.services_to_restart('ragnarok-dhcp')
|
||||||
else:
|
else:
|
||||||
|
@ -1478,7 +1477,7 @@ class base_proprietaire(base_classes_crans):
|
||||||
# Verif si machines avec bonnes ip
|
# Verif si machines avec bonnes ip
|
||||||
err = 0
|
err = 0
|
||||||
for m in self.machines():
|
for m in self.machines():
|
||||||
if m.ipsec():
|
if isinstance(m, MachineWifi):
|
||||||
# Machine Wifi
|
# Machine Wifi
|
||||||
continue
|
continue
|
||||||
# Machine fixe
|
# Machine fixe
|
||||||
|
@ -1621,7 +1620,7 @@ class adherent(base_proprietaire):
|
||||||
# N'est pas ou plus sur le campus
|
# N'est pas ou plus sur le campus
|
||||||
# Machine fixe ?
|
# Machine fixe ?
|
||||||
# for m in self.machines():
|
# for m in self.machines():
|
||||||
# if not m.ipsec():
|
# if not isinstance(m, MachineWifi):
|
||||||
# raise ValueError(u'Un adhérent en dehors du campus ne doit pas avoir de machine fixe.')
|
# raise ValueError(u'Un adhérent en dehors du campus ne doit pas avoir de machine fixe.')
|
||||||
|
|
||||||
self._set('chbre',['EXT'])
|
self._set('chbre',['EXT'])
|
||||||
|
@ -2179,7 +2178,7 @@ class Machine(base_classes_crans):
|
||||||
|
|
||||||
if typ == 'wifi':
|
if typ == 'wifi':
|
||||||
# Génération de la clef IPsec
|
# Génération de la clef IPsec
|
||||||
self.ipsec(1)
|
self.ipsec(True)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise TypeError(u'Arguments invalides')
|
raise TypeError(u'Arguments invalides')
|
||||||
|
@ -2493,26 +2492,6 @@ class Machine(base_classes_crans):
|
||||||
|
|
||||||
return self.__proprietaire
|
return self.__proprietaire
|
||||||
|
|
||||||
def ipsec(self, clef=0):
|
|
||||||
""" Génération (clef=1) ou affichage de la clef IPsec de la machine
|
|
||||||
Si clef!=1: prend la clef fournie.
|
|
||||||
"""
|
|
||||||
if self.__typ != 'wifi': return None
|
|
||||||
|
|
||||||
if not clef:
|
|
||||||
return decode(self._data.get('ipsec',[''])[0])
|
|
||||||
|
|
||||||
if clef == 1:
|
|
||||||
# Génération
|
|
||||||
clef = ''
|
|
||||||
for i in range(22):
|
|
||||||
clef += random.choice(filter(lambda x: x != 'l' and x != 'o', string.lowercase) +
|
|
||||||
filter(lambda x: x != '1' and x != '0', string.digits))
|
|
||||||
|
|
||||||
self._set('ipsec',[clef])
|
|
||||||
|
|
||||||
return clef
|
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""
|
"""
|
||||||
Enregistre la machine courante dans la base LDAP
|
Enregistre la machine courante dans la base LDAP
|
||||||
|
@ -2542,7 +2521,7 @@ class Machine(base_classes_crans):
|
||||||
|
|
||||||
# Clef IPsec
|
# Clef IPsec
|
||||||
if 'ipsec' in self.modifs:
|
if 'ipsec' in self.modifs:
|
||||||
ret += coul(u'Clef IPsec de la machine : %s\n' % self.ipsec(),'cyan')
|
ret += coul(u'Clef IPsec de la machine : %s\n' % self.ipsec(), 'cyan')
|
||||||
self.services_to_restart('conf_wifi_ng')
|
self.services_to_restart('conf_wifi_ng')
|
||||||
|
|
||||||
# Reconfiguration firewalls et dhcps
|
# Reconfiguration firewalls et dhcps
|
||||||
|
@ -2654,6 +2633,7 @@ class MachineFixe(Machine):
|
||||||
def __init__(self, parent_or_tuple, typ='fixe', conn=None):
|
def __init__(self, parent_or_tuple, typ='fixe', conn=None):
|
||||||
Machine.__init__(self, parent_or_tuple, typ, conn)
|
Machine.__init__(self, parent_or_tuple, typ, conn)
|
||||||
|
|
||||||
|
|
||||||
class MachineWifi(Machine):
|
class MachineWifi(Machine):
|
||||||
""" Classe de définition d'une machine wifi """
|
""" Classe de définition d'une machine wifi """
|
||||||
objectClass = "machineWifi"
|
objectClass = "machineWifi"
|
||||||
|
@ -2661,6 +2641,26 @@ class MachineWifi(Machine):
|
||||||
def __init__(self, parent_or_tuple, typ='wifi', conn=None):
|
def __init__(self, parent_or_tuple, typ='wifi', conn=None):
|
||||||
Machine.__init__(self, parent_or_tuple, typ, conn)
|
Machine.__init__(self, parent_or_tuple, typ, conn)
|
||||||
|
|
||||||
|
def ipsec(self, clef=None):
|
||||||
|
"""
|
||||||
|
Affichage (clef=None), génération (clef=True) ou définition de la clef IPsec
|
||||||
|
de la machine. Si clef différent de True et None: prend la clef fournie.
|
||||||
|
"""
|
||||||
|
if clef == None:
|
||||||
|
return decode(self._data.get('ipsec', [''])[0])
|
||||||
|
|
||||||
|
if clef == True:
|
||||||
|
# Génération
|
||||||
|
clef = ''
|
||||||
|
for i in range(22):
|
||||||
|
clef += random.choice(filter(lambda x: x != 'l' and x != 'o', string.lowercase) +
|
||||||
|
filter(lambda x: x != '1' and x != '0', string.digits))
|
||||||
|
|
||||||
|
self._set('ipsec', [clef])
|
||||||
|
|
||||||
|
return clef
|
||||||
|
|
||||||
|
|
||||||
class MachineCrans(Machine):
|
class MachineCrans(Machine):
|
||||||
""" Classe de définition d'une machine du Crans """
|
""" Classe de définition d'une machine du Crans """
|
||||||
objectClass = "machineCrans"
|
objectClass = "machineCrans"
|
||||||
|
|
|
@ -48,7 +48,8 @@ except:
|
||||||
|
|
||||||
base = None
|
base = None
|
||||||
|
|
||||||
from ldap_crans import is_actif, crans_ldap, ann_scol, crans, hostname, BorneWifi
|
from ldap_crans import is_actif, crans_ldap, ann_scol, crans, hostname
|
||||||
|
from ldap_crans import MachineWifi, BorneWifi
|
||||||
from affich_tools import *
|
from affich_tools import *
|
||||||
import user_tests
|
import user_tests
|
||||||
import popen2, commands
|
import popen2, commands
|
||||||
|
@ -132,7 +133,7 @@ def adhers_brief(adhers) :
|
||||||
for machine in a.machines() :
|
for machine in a.machines() :
|
||||||
nom = machine.nom().split('.')[0]
|
nom = machine.nom().split('.')[0]
|
||||||
if machine.blacklist_actif() : k = 'rouge'
|
if machine.blacklist_actif() : k = 'rouge'
|
||||||
elif machine.ipsec() : k = 'cyan'
|
elif isinstance(machine, MachineWifi): k = 'cyan'
|
||||||
else : k= ''
|
else : k= ''
|
||||||
if machines : machines += ', ' + coul(nom,k)
|
if machines : machines += ', ' + coul(nom,k)
|
||||||
else : machines = coul(nom,k)
|
else : machines = coul(nom,k)
|
||||||
|
@ -454,7 +455,7 @@ def machine_details(machine) :
|
||||||
f+= coul(u'mid=%s ' % machine.id(),'bleu')
|
f+= coul(u'mid=%s ' % machine.id(),'bleu')
|
||||||
|
|
||||||
# Type de machine
|
# Type de machine
|
||||||
if machine.ipsec(): a = 'Machine wifi'
|
if isinstance(machine, MachineWifi): a = 'Machine wifi'
|
||||||
elif isinstance(machine, BorneWifi): a = 'Borne wifi'
|
elif isinstance(machine, BorneWifi): a = 'Borne wifi'
|
||||||
else: a = 'Machine fixe'
|
else: a = 'Machine fixe'
|
||||||
f += coul(a + ' : ', 'gras')
|
f += coul(a + ' : ', 'gras')
|
||||||
|
@ -546,7 +547,7 @@ def machine_details(machine) :
|
||||||
f += '\n'
|
f += '\n'
|
||||||
|
|
||||||
|
|
||||||
if aff_ipsec and machine.ipsec() :
|
if aff_ipsec and isinstance(machine, MachineWifi):
|
||||||
f += coul(u'Clef IPsec : ','gras') + machine.ipsec()
|
f += coul(u'Clef IPsec : ','gras') + machine.ipsec()
|
||||||
f += '\n'
|
f += '\n'
|
||||||
|
|
||||||
|
@ -688,8 +689,8 @@ def _hist(clas) :
|
||||||
def __bases_machines(m) :
|
def __bases_machines(m) :
|
||||||
""" Retourne [ type de la machines, blacklist ] """
|
""" Retourne [ type de la machines, blacklist ] """
|
||||||
#Type
|
#Type
|
||||||
if m.ipsec() : t='wifi'
|
if isinstance(m, MachineWifi): t = 'wifi'
|
||||||
elif isinstance(m, BorneWifi): t='born'
|
elif isinstance(m, BorneWifi): t = 'born'
|
||||||
else : t='fixe'
|
else : t='fixe'
|
||||||
|
|
||||||
# Déconnectée ?
|
# Déconnectée ?
|
||||||
|
|
|
@ -23,6 +23,7 @@ sys.path.append('/usr/scripts/gestion')
|
||||||
from config import upload, virus, p2p, NETs
|
from config import upload, virus, p2p, NETs
|
||||||
import smtplib
|
import smtplib
|
||||||
from ldap_crans import crans_ldap, crans, invite, base_classes_crans
|
from ldap_crans import crans_ldap, crans, invite, base_classes_crans
|
||||||
|
from ldap_crans import MachineWifi
|
||||||
from time import *
|
from time import *
|
||||||
import locale
|
import locale
|
||||||
locale.setlocale(locale.LC_TIME,'fr_FR')
|
locale.setlocale(locale.LC_TIME,'fr_FR')
|
||||||
|
@ -36,7 +37,7 @@ def machine_online(machine) :
|
||||||
Retourne True si la machine est connectée au réseau et False si elle ne l'est pas
|
Retourne True si la machine est connectée au réseau et False si elle ne l'est pas
|
||||||
"""
|
"""
|
||||||
# Les machines wifi sont toujours online
|
# Les machines wifi sont toujours online
|
||||||
if machine.ipsec() :
|
if isinstance(machine, MachineWifi):
|
||||||
return True
|
return True
|
||||||
# Arping pour les fixes
|
# Arping pour les fixes
|
||||||
return not commands.getstatusoutput('/usr/sbin/arping -c 3 %s' % machine.mac())[0]
|
return not commands.getstatusoutput('/usr/sbin/arping -c 3 %s' % machine.mac())[0]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue