Forward Firewall: added SNAT multiport support
authorAlexander Marx <amarx@ipfire.org>
Thu, 11 Apr 2013 15:33:22 +0000 (17:33 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Aug 2013 12:12:40 +0000 (14:12 +0200)
config/forwardfw/rules.pl
html/cgi-bin/forwardfw.cgi

index 917e061eb97e8be11891a89d7b905f7b6a0cd829..1cbbee7a58b77e4358cfaf74253c0ceda8cb09b9 100755 (executable)
@@ -182,7 +182,7 @@ sub buildrules
                next if ($$hash{$key}[6] eq 'RED' && $conexists eq 'off' );
                if ($$hash{$key}[28] eq 'ON'){
                        $command='iptables -t nat -A';
                next if ($$hash{$key}[6] eq 'RED' && $conexists eq 'off' );
                if ($$hash{$key}[28] eq 'ON'){
                        $command='iptables -t nat -A';
-                       $natip=&get_nat_ip($$hash{$key}[29]);
+                       $natip=&get_nat_ip($$hash{$key}[29],$$hash{$key}[31]);
                        if($$hash{$key}[31] eq 'dnat'){
                                $nat='DNAT';
                                if ($$hash{$key}[30] =~ /\|/){
                        if($$hash{$key}[31] eq 'dnat'){
                                $nat='DNAT';
                                if ($$hash{$key}[30] =~ /\|/){
@@ -308,8 +308,8 @@ sub buildrules
                                                                                        }
                                                                                }
                                                                                print "iptables -A PORTFWACCESS $PROT -i $con $STAG $sourcehash{$a}[0] -d $ip $fwaccessdport $TIME -j $$hash{$key}[0]\n";
                                                                                        }
                                                                                }
                                                                                print "iptables -A PORTFWACCESS $PROT -i $con $STAG $sourcehash{$a}[0] -d $ip $fwaccessdport $TIME -j $$hash{$key}[0]\n";
-                                                                       }elsif($$hash{$key}[28] eq 'ON' && $$hash{$key}[32] eq 'snat'){
-                                                                               print "$command $$hash{$key}[1] $PROT $STAG $sourcehash{$a}[0] $SPORT -d $targethash{$b}[0] $DPORT $TIME -j $nat --to $natip$fireport\n";
+                                                                       }elsif($$hash{$key}[28] eq 'ON' && $$hash{$key}[31] eq 'snat'){
+                                                                               print "$command $$hash{$key}[1] $PROT $STAG $sourcehash{$a}[0] $SPORT -d $targethash{$b}[0] $DPORT $TIME -j $nat --to $natip\n";
                                                                        }
                                                                }                               
                                                        }
                                                                        }
                                                                }                               
                                                        }
@@ -382,17 +382,22 @@ sub buildrules
 sub get_nat_ip
 {
        my $val=shift;
 sub get_nat_ip
 {
        my $val=shift;
+       my $type=shift;
        my $result;
        if($val eq 'RED' || $val eq 'GREEN' || $val eq 'ORANGE' || $val eq 'BLUE'){
                $result=$defaultNetworks{$val.'_ADDRESS'};
        }elsif($val eq 'ALL'){
                $result='-i '.$con;
        my $result;
        if($val eq 'RED' || $val eq 'GREEN' || $val eq 'ORANGE' || $val eq 'BLUE'){
                $result=$defaultNetworks{$val.'_ADDRESS'};
        }elsif($val eq 'ALL'){
                $result='-i '.$con;
-       }elsif($val eq 'Default IP'){
+       }elsif($val eq 'Default IP' && $type eq 'dnat'){
                $result='-d '.$redip;
                $result='-d '.$redip;
+       }elsif($val eq 'Default IP' && $type eq 'snat'){
+               $result=$redip;
        }else{
                foreach my $al (sort keys %aliases){
        }else{
                foreach my $al (sort keys %aliases){
-                       if($val eq $al){
+                       if($val eq $al && $type eq 'dnat'){
                                $result='-d '.$aliases{$al}{'IPT'};
                                $result='-d '.$aliases{$al}{'IPT'};
+                       }elsif($val eq $al && $type eq 'snat'){
+                               $result=$aliases{$al}{'IPT'};
                        }
                }
        }
                        }
                }
        }
index 72771e8cf4693683d15bd3bc076e8513c61d71e6..7bd3fa52f6ddf2db7cf02c010140262fe67b37ae 100755 (executable)
@@ -77,7 +77,7 @@ my %aliases=();
 my %optionsfw=();
 my %ifaces=();
 
 my %optionsfw=();
 my %ifaces=();
 
-my $VERSION='0.9.9.3';
+my $VERSION='0.9.9.4';
 my $color;
 my $confignet          = "${General::swroot}/fwhosts/customnetworks";
 my $confighost         = "${General::swroot}/fwhosts/customhosts";
 my $color;
 my $confignet          = "${General::swroot}/fwhosts/customnetworks";
 my $confighost         = "${General::swroot}/fwhosts/customhosts";
@@ -838,7 +838,7 @@ sub checktarget
                if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
                        if ($fwdfwsettings{'TGT_PROT'} eq 'TCP' || $fwdfwsettings{'TGT_PROT'} eq 'UDP'){
                                if ($fwdfwsettings{'TGT_PORT'} ne ''){
                if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
                        if ($fwdfwsettings{'TGT_PROT'} eq 'TCP' || $fwdfwsettings{'TGT_PROT'} eq 'UDP'){
                                if ($fwdfwsettings{'TGT_PORT'} ne ''){
-                                       if ($fwdfwsettings{'TGT_PORT'} =~ "," && $fwdfwsettings{'USE_NAT'}) {
+                                       if ($fwdfwsettings{'TGT_PORT'} =~ "," && $fwdfwsettings{'USE_NAT'} && $fwdfwsettings{'nat'} eq 'dnat') {
                                                $errormessage=$Lang::tr{'fwdfw dnat porterr'}."<br>";
                                        }
                                        my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
                                                $errormessage=$Lang::tr{'fwdfw dnat porterr'}."<br>";
                                        }
                                        my @parts=split(",",$fwdfwsettings{'TGT_PORT'});