fixed the way how are flushed out the iptables rules

This commit is contained in:
Jordi Sanfeliu 2013-01-25 13:02:53 +01:00
parent 08e9c9768a
commit f6082bd197
1 changed files with 28 additions and 31 deletions

View File

@ -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(<IN>) {
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(<IN>) {
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(<IN>) {
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(<IN>) {
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 $_");