From f6082bd197ad26cb14d3d8bb76a1df57b265efc1 Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Fri, 25 Jan 2013 13:02:53 +0100 Subject: [PATCH] fixed the way how are flushed out the iptables rules --- lib/Monitorix.pm | 59 +++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/lib/Monitorix.pm b/lib/Monitorix.pm index 18896bc..d2a1b01 100644 --- a/lib/Monitorix.pm +++ b/lib/Monitorix.pm @@ -166,41 +166,38 @@ sub flush_accounting_rules { my $num = 0; logger("Flushing out iptables rules.") if $debug; - if(open(IN, "iptables -nxvL INPUT --line-numbers |")) { - my @rules; + { my @names; - while() { - my ($rule, undef, undef, $name) = split(' ', $_); - if($name =~ /monitorix_IN/ || /monitorix_nginx_IN/) { - push(@rules, $rule); - push(@names, $name); + if(open(IN, "iptables -nxvL INPUT --line-numbers |")) { + my @rules; + while() { + my ($rule, undef, undef, $name) = split(' ', $_); + if($name =~ /monitorix_IN/ || /monitorix_OUT/ || /monitorix_nginx_IN/) { + push(@rules, $rule); + push(@names, $name); + } + } + close(IN); + @rules = reverse(@rules); + foreach(@rules) { + system("iptables -D INPUT $_"); + $num++; } } - close(IN); - @rules = reverse(@rules); - foreach(@rules) { - system("iptables -D INPUT $_"); - $num++; - } - foreach(@names) { - system("iptables -X $_"); - } - } - if(open(IN, "iptables -nxvL OUTPUT --line-numbers |")) { - my @rules; - my @names; - while() { - my ($rule, undef, undef, $name) = split(' ', $_); - if($name =~ /monitorix_OUT/ || /monitorix_nginx_OUT/) { - push(@rules, $rule); - push(@names, $name); + if(open(IN, "iptables -nxvL OUTPUT --line-numbers |")) { + my @rules; + while() { + my ($rule, undef, undef, $name) = split(' ', $_); + if($name =~ /monitorix_IN/ || /monitorix_OUT/ || /monitorix_nginx_IN/) { + push(@rules, $rule); + } + } + close(IN); + @rules = reverse(@rules); + foreach(@rules) { + system("iptables -D OUTPUT $_"); + $num++; } - } - close(IN); - @rules = reverse(@rules); - foreach(@rules) { - system("iptables -D OUTPUT $_"); - $num++; } foreach(@names) { system("iptables -X $_");