Modification du systme de mise jour de la correspondance MAC-IP :
destruction des rgles grace leur description et non grace leur numro. darcs-hash:20041215105530-41617-74aeff1d8d22e161060923972d35082de63828f5.gz
This commit is contained in:
parent
66fb4cee44
commit
301abf1dd3
1 changed files with 38 additions and 22 deletions
|
@ -467,10 +467,14 @@ class firewall_komaz :
|
|||
""" Mise à jour de la correspondance MAC-IP pour les ip fournies """
|
||||
## Que faut-il faire ?
|
||||
self.anim = anim(' Analyse travail à effectuer')
|
||||
if ip_list == [''] :
|
||||
print OK + ' (rien à faire)'
|
||||
return
|
||||
|
||||
mac_ip_maj = {}
|
||||
serveur_maj = False
|
||||
for ip in ip_list :
|
||||
machine = crans_ldap().search('ip=%s'% ip)['machine']
|
||||
machine = crans_ldap().search('paiement=ok&ip=%s'% ip)['machine']
|
||||
if not machine :
|
||||
# Destruction des occurences
|
||||
if AddrInNet(ip,self.zone_serveur) :
|
||||
|
@ -499,35 +503,47 @@ class firewall_komaz :
|
|||
|
||||
# Correspondance MAC-IP
|
||||
if mac_ip_maj :
|
||||
to_del = []
|
||||
to_add = []
|
||||
def procedure() :
|
||||
warn = ''
|
||||
self.anim = anim(' Actualisation TEST_MAC-IP')
|
||||
for regle in iptables("-t nat -L TEST_MAC-IP -n --line-numbers").split('\n')[2:] :
|
||||
for regle in iptables("-t nat -L TEST_MAC-IP -n").split('\n')[2:] :
|
||||
regle = regle.split()
|
||||
num = regle[0]
|
||||
ip = regle[4]
|
||||
mac = regle[7].lower()
|
||||
ip = regle[3]
|
||||
mac = regle[6].lower()
|
||||
if ip in mac_ip_maj.keys() :
|
||||
machine = mac_ip_maj.pop(ip)
|
||||
if not machine :
|
||||
to_del.append(num)
|
||||
elif ( machine.ipsec() and mac!=self.mac_wifi ) or \
|
||||
( not machine.ipsec() and mac != machine.mac() ) :
|
||||
to_del.append(num)
|
||||
to_add.append(machine)
|
||||
# La règle correspond à une ip à mettre à jour
|
||||
machine = mac_ip_maj[ip]
|
||||
try :
|
||||
if not machine :
|
||||
# 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))
|
||||
else :
|
||||
if ( machine.ipsec() and mac!=self.mac_wifi ) \
|
||||
or ( not machine.ipsec() and mac != machine.mac() ) :
|
||||
# La correspondance MAC-IP est fausse => on ajoute la bonne règle
|
||||
self.__test_mac_ip(machine)
|
||||
# Supression de l'ancienne ligne
|
||||
iptables("-t nat -D TEST_MAC-IP -s %s -m mac --mac-source %s -j ACCEPT" % (ip, mac))
|
||||
|
||||
to_del.sort()
|
||||
to_del.reverse()
|
||||
for i in to_del :
|
||||
iptables('-t nat -D TEST_MAC-IP %s' % i )
|
||||
for machine in ( to_add + mac_ip_maj.values() ) :
|
||||
if machine :
|
||||
# Toutes les autres occurences devront être détruites
|
||||
mac_ip_maj[ip]=None
|
||||
|
||||
|
||||
except IptablesError, c :
|
||||
warn += c
|
||||
|
||||
# Ajout des machines qui n'étaient pas dans le firewall
|
||||
for machine in mac_ip_maj.values() :
|
||||
if machine :
|
||||
self.__test_mac_ip(machine)
|
||||
print OK
|
||||
|
||||
if warn :
|
||||
print WARNING
|
||||
sys.stdout.write(warn)
|
||||
else :
|
||||
print OK
|
||||
|
||||
self.__exception_catcher(procedure)
|
||||
|
||||
|
||||
if __name__ == '__main__' :
|
||||
# Chaines pouvant être recontruites
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue