diff --git a/gestion/classe_firewall.py b/gestion/classe_firewall.py index 8b3d36ee..1e8d6697 100755 --- a/gestion/classe_firewall.py +++ b/gestion/classe_firewall.py @@ -100,7 +100,9 @@ class firewall: """ Détruit une entrée dans le firewall Note: Il faut *os.systemer lourdement* cette fonction. - """ + Ce serait pas mal de factoriser par ici, mais de toute façon la + méthode ne me plaît pas du tout. + """ try: os.system("iptables -L -n > /tmp/firewall") except: @@ -110,14 +112,30 @@ class firewall: count=0 for line in fileinput.input('/tmp/firewall'): count=count+1 - if "Chain" in line: + if "Chain" in line: tmp=line.split(' ') chaine=tmp[1] count=0 - if ip in line: - os.system("iptables -L") - test("iptables -D %s %i"%(chaine,count)) + if ip in line: count=count-1 + test("iptables -D %s %i"%(chaine,count)) + os.system("rm -f /tmp/firewall") + try: + os.system("iptables -t nat -L -n > /tmp/firewall") + except: + print "Impossible de créer le fichier d'états /tmp/firewall" + exit() + chaines=[] + count=0 + for line in fileinput.input('/tmp/firewall'): + count=count+1 + if "Chain" in line: + tmp=line.split(' ') + chaine=tmp[1] + count=0 + if ip in line: + count=count-1 + test("iptables -t nat -D %s %i"%(chaine,count)) os.system("rm -f /tmp/firewall") def paire_macip(self,ip,mac):