Lorsque l'on supprimait une machine, l'ip n'tait plus dans la base ldap,
donc il tait impossible de retrouver l'adhrent et de construire class_id Donc on recherche plutot la rgle iptables avec l'ip donne en entre et on retravaille la rgle pour rcuprer les lments pour la suppression. darcs-hash:20060425072920-72cb0-8996b3ea9eec6ae66d0fc8514588afbe56590202.gz
This commit is contained in:
parent
e3a6cbd9ff
commit
7faa5714e5
1 changed files with 23 additions and 28 deletions
|
@ -613,21 +613,6 @@ class firewall_komaz(firewall_crans) :
|
||||||
print OK + ' (rien à faire)'
|
print OK + ' (rien à faire)'
|
||||||
return
|
return
|
||||||
|
|
||||||
maj = {}
|
|
||||||
for ip in ip_list :
|
|
||||||
machine = db.search('ip=%s'% ip)['machine']
|
|
||||||
if not machine :
|
|
||||||
# Suppression de la règle associée à la machine
|
|
||||||
maj[machine[0]] = '-'
|
|
||||||
|
|
||||||
elif len(machine) == 1 :
|
|
||||||
# Ajout de la machine
|
|
||||||
maj[machine[0]] = '+'
|
|
||||||
else :
|
|
||||||
print WARNING
|
|
||||||
if debug :
|
|
||||||
sys.stderr.write("Plusieurs machines avec l'IP %s\n" % ip)
|
|
||||||
|
|
||||||
print OK
|
print OK
|
||||||
|
|
||||||
## Traitement
|
## Traitement
|
||||||
|
@ -636,17 +621,27 @@ class firewall_komaz(firewall_crans) :
|
||||||
self.anim = anim('\tMise à jour des classes p2p')
|
self.anim = anim('\tMise à jour des classes p2p')
|
||||||
warn = ''
|
warn = ''
|
||||||
try :
|
try :
|
||||||
for machine in maj.keys() :
|
for ip in ip_list :
|
||||||
|
recherche = db.search('ip=%s'% ip)['machine']
|
||||||
|
if not recherche :
|
||||||
|
# Il faut supprimer cette entrée
|
||||||
|
option = '-D'
|
||||||
|
subnet = ip.split('.')[2]
|
||||||
|
regles = iptables("-t mangle -L SUBNET-%s_24 -n | grep %s" % (subnet, ip)).split('\n')
|
||||||
|
# On sélectionne la première qui doit contenir ce que l'on veut
|
||||||
|
regle = regles[0].split()
|
||||||
|
mark = regle[7]
|
||||||
|
class_id = regle[10].split(':')[1]
|
||||||
|
elif len(recherche) == 1 :
|
||||||
|
# Il faut ajouter cette entrée
|
||||||
|
option = '-A'
|
||||||
|
machine = recherche[0]
|
||||||
adherent = machine.proprietaire()
|
adherent = machine.proprietaire()
|
||||||
ip = machine.ip()
|
ip = machine.ip()
|
||||||
subnet = ip.split('.')[2]
|
subnet = ip.split('.')[2]
|
||||||
class_id = int(adherent.id())+1 # On ne peut pas reprendre le numéro 1
|
class_id = int(adherent.id())+1 # On ne peut pas reprendre le numéro 1
|
||||||
if maj[machine] == '+' :
|
|
||||||
# Il faut ajouter cette entrée
|
|
||||||
option = '-A'
|
|
||||||
else :
|
else :
|
||||||
# Il faut supprimer cette entrée
|
warn += "Plusieurs machines avec l'IP %s\n" % ip
|
||||||
option = '-D'
|
|
||||||
iptables("-t mangle %s SUBNET-%s_24 -o ens -s %s -m mark " % (option, subnet, ip) +
|
iptables("-t mangle %s SUBNET-%s_24 -o ens -s %s -m mark " % (option, subnet, ip) +
|
||||||
"--mark %s -j CLASSIFY --set-class 1:%s" % (conf_fw.mark['bittorrent'], class_id))
|
"--mark %s -j CLASSIFY --set-class 1:%s" % (conf_fw.mark['bittorrent'], class_id))
|
||||||
iptables("-t mangle %s SUBNET-%s_24 -o crans -d %s -m mark " % (option, subnet, ip) +
|
iptables("-t mangle %s SUBNET-%s_24 -o crans -d %s -m mark " % (option, subnet, ip) +
|
||||||
|
@ -844,7 +839,7 @@ class firewall_komaz(firewall_crans) :
|
||||||
|
|
||||||
# Recherche sur le champ ablacklist (clubs compris)
|
# Recherche sur le champ ablacklist (clubs compris)
|
||||||
search = db.search('ablacklist=*&paiement=%s' % ann_scol)
|
search = db.search('ablacklist=*&paiement=%s' % ann_scol)
|
||||||
self.anim = anim("\tBlackliste machines", len(search['adherent']+search['club']))
|
self.anim = anim("\tBlackliste adhérents+clubs", len(search['adherent']+search['club']))
|
||||||
for entite in search['adherent'] + search['club']:
|
for entite in search['adherent'] + search['club']:
|
||||||
self.anim.cycle()
|
self.anim.cycle()
|
||||||
sanctions = entite.blacklist_actif()
|
sanctions = entite.blacklist_actif()
|
||||||
|
@ -857,7 +852,7 @@ class firewall_komaz(firewall_crans) :
|
||||||
|
|
||||||
# Recherche sur le champ mblacklist
|
# Recherche sur le champ mblacklist
|
||||||
search = db.search('mblacklist=*&paiement=%s' % ann_scol)
|
search = db.search('mblacklist=*&paiement=%s' % ann_scol)
|
||||||
self.anim = anim("\tBlackliste adhérents", len(search['machine']))
|
self.anim = anim("\tBlackliste machines", len(search['machine']))
|
||||||
for entite in search['machine']:
|
for entite in search['machine']:
|
||||||
self.anim.cycle()
|
self.anim.cycle()
|
||||||
sanctions = entite.blacklist_actif()
|
sanctions = entite.blacklist_actif()
|
||||||
|
@ -1090,7 +1085,7 @@ if __name__ == '__main__' :
|
||||||
fw = eval('firewall_%s()' % hostname)
|
fw = eval('firewall_%s()' % hostname)
|
||||||
chaines = []
|
chaines = []
|
||||||
for nom in dir(fw) :
|
for nom in dir(fw) :
|
||||||
if nom in [ 'log_chaines' , 'test_virus_flood', 'reseaux_non_routables', 'test_mac_ip' , 'blacklist' , 'ext_vers_serveurs' , 'serveurs_vers_ext', 'ext_vers_crans', 'crans_vers_ext' , 'filtre_p2p', 'admin_vlan' , 'serv_out_adm', 'mangle_table' ] :
|
if nom in [ 'log_chaines' , 'test_virus_flood', 'reseaux_non_routables', 'test_mac_ip' , 'blacklist' , 'ext_vers_serveurs' , 'serveurs_vers_ext', 'ext_vers_crans', 'crans_vers_ext' , 'filtre_p2p', 'admin_vlan' , 'serv_out_adm', 'mangle_table', 'classes_p2p_maj' ] :
|
||||||
chaines.append(nom)
|
chaines.append(nom)
|
||||||
|
|
||||||
def __usage(txt=None) :
|
def __usage(txt=None) :
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue