]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - html/cgi-bin/firewall.cgi
Firewall: BUG 10526 (missing RED iface in SNAT Dropdown)
[people/teissler/ipfire-2.x.git] / html / cgi-bin / firewall.cgi
index 6f4e10b02256ea6d4c4f56ed571eae1d397fc80e..ff950c449a56e8e0e962e260b04ee7c81ef1bda0 100644 (file)
 
 use strict;
 use Sort::Naturally;
+use utf8;
+use feature 'unicode_strings';
+
 no warnings 'uninitialized';
+
 # enable only the following on debugging purpose
 #use warnings;
 #use CGI::Carp 'fatalsToBrowser';
@@ -29,7 +33,7 @@ no warnings 'uninitialized';
 require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
-require "${General::swroot}/firewall/bin/firewall-lib.pl";
+require "/usr/lib/firewall/firewall-lib.pl";
 
 unless (-d "${General::swroot}/firewall")                      { system("mkdir ${General::swroot}/firewall"); }
 unless (-e "${General::swroot}/firewall/settings")     { system("touch ${General::swroot}/firewall/settings"); }
@@ -97,7 +101,7 @@ my @protocols;
 &General::readhasharray("$configipsec", \%ipsecconf);
 &Header::showhttpheaders();
 &Header::getcgihash(\%fwdfwsettings);
-&Header::openpage($Lang::tr{'fwdfw menu'}, 1, '');
+&Header::openpage($Lang::tr{'firewall rules'}, 1, '');
 &Header::openbigbox('100%', 'center',$errormessage);
 #### JAVA SCRIPT ####
 print<<END;
@@ -194,6 +198,7 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule')
        $errormessage=&checksource;
        if(!$errormessage){&checktarget;}
        if(!$errormessage){&checkrule;}
+
        #check if manual ip (source) is orange network
        if ($fwdfwsettings{'grp1'} eq 'src_addr'){
                my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
@@ -220,16 +225,17 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule')
                                if (   "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
                                        eq "$configinputfw{$key}[0],$configinputfw{$key}[2],$configinputfw{$key}[3],$configinputfw{$key}[4],$configinputfw{$key}[5],$configinputfw{$key}[6],$configinputfw{$key}[7],$configinputfw{$key}[8],$configinputfw{$key}[9],$configinputfw{$key}[10],$configinputfw{$key}[11],$configinputfw{$key}[12],$configinputfw{$key}[13],$configinputfw{$key}[14],$configinputfw{$key}[15],$configinputfw{$key}[17],$configinputfw{$key}[18],$configinputfw{$key}[19],$configinputfw{$key}[20],$configinputfw{$key}[21],$configinputfw{$key}[22],$configinputfw{$key}[23],$configinputfw{$key}[24],$configinputfw{$key}[25],$configinputfw{$key}[26],$configinputfw{$key}[27],$configinputfw{$key}[28],$configinputfw{$key}[29],$configinputfw{$key}[30],$configinputfw{$key}[31]"){
                                                $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
-                                               if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on'){
-                                                       $errormessage='';
-                                               }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
+                                               if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
                                                        $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
                                                }
+                                               if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && &validremark($fwdfwsettings{'ruleremark'})){
+                                                       $errormessage='';
+                                               }
                                                if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
                                                        $fwdfwsettings{'nosave'} = 'on';
                                                }
-                               }       
-                       }       
+                               }
+                       }
                }
                #check Rulepos on new Rule
                if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
@@ -263,11 +269,12 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule')
                                if (   "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
                                        eq "$configoutgoingfw{$key}[0],$configoutgoingfw{$key}[2],$configoutgoingfw{$key}[3],$configoutgoingfw{$key}[4],$configoutgoingfw{$key}[5],$configoutgoingfw{$key}[6],$configoutgoingfw{$key}[7],$configoutgoingfw{$key}[8],$configoutgoingfw{$key}[9],$configoutgoingfw{$key}[10],$configoutgoingfw{$key}[11],$configoutgoingfw{$key}[12],$configoutgoingfw{$key}[13],$configoutgoingfw{$key}[14],$configoutgoingfw{$key}[15],$configoutgoingfw{$key}[17],$configoutgoingfw{$key}[18],$configoutgoingfw{$key}[19],$configoutgoingfw{$key}[20],$configoutgoingfw{$key}[21],$configoutgoingfw{$key}[22],$configoutgoingfw{$key}[23],$configoutgoingfw{$key}[24],$configoutgoingfw{$key}[25],$configoutgoingfw{$key}[26],$configoutgoingfw{$key}[27],$configoutgoingfw{$key}[28],$configoutgoingfw{$key}[29],$configoutgoingfw{$key}[30],$configoutgoingfw{$key}[31]"){
                                                $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
-                                               if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on'){
-                                                       $errormessage='';
-                                               }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
+                                               if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
                                                        $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
                                                }
+                                               if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && &validremark($fwdfwsettings{'ruleremark'})){
+                                                       $errormessage='';
+                                               }
                                                if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
                                                        $fwdfwsettings{'nosave'} = 'on';
                                                }
@@ -276,7 +283,6 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule')
                }
                #check Rulepos on new Rule
                if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
-                       print"CHECK OUTGOING DOPPELTE REGEL<br>";
                        $fwdfwsettings{'oldrulenumber'}=$maxkey;
                        foreach my $key (sort keys %configoutgoingfw){
                                if (   "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
@@ -309,17 +315,18 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule')
                                if (   "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
                                        eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[18],$configfwdfw{$key}[19],$configfwdfw{$key}[20],$configfwdfw{$key}[21],$configfwdfw{$key}[22],$configfwdfw{$key}[23],$configfwdfw{$key}[24],$configfwdfw{$key}[25],$configfwdfw{$key}[26],$configfwdfw{$key}[27],$configfwdfw{$key}[28],$configfwdfw{$key}[29],$configfwdfw{$key}[30],$configfwdfw{$key}[31]"){
                                                $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
-                                               if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' ){
-                                                       $errormessage='';
-                                               }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
+                                               if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
                                                        $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
                                                }
+                                               if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && &validremark($fwdfwsettings{'ruleremark'})){
+                                                       $errormessage='';
+                                               }
                                                if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
                                                        $fwdfwsettings{'nosave'} = 'on';
                                                }
-                               }               
+                               }
                        }
-               }       
+               }
                #check Rulepos on new Rule
                if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
                        $fwdfwsettings{'oldrulenumber'}=$maxkey;
@@ -327,7 +334,7 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule')
                                if (   "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
                                        eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[18],$configfwdfw{$key}[19],$configfwdfw{$key}[20],$configfwdfw{$key}[21],$configfwdfw{$key}[22],$configfwdfw{$key}[23],$configfwdfw{$key}[24],$configfwdfw{$key}[25],$configfwdfw{$key}[26],$configfwdfw{$key}[27],$configfwdfw{$key}[28],$configfwdfw{$key}[29],$configfwdfw{$key}[30],$configfwdfw{$key}[31]"){
                                                $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
-                               }               
+                               }
                        }
                }
                #check if we just close a rule
@@ -505,8 +512,8 @@ sub checksource
                        return $errormessage;
                }
        }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
-               $errormessage.=$Lang::tr{'fwdfw err nosrcip'};
-               return $errormessage;
+               $fwdfwsettings{'grp1'}='std_net_src';
+               $fwdfwsettings{$fwdfwsettings{'grp1'}} = 'ALL';
        }
 
        #check empty fields
@@ -577,8 +584,10 @@ sub checktarget
                                }
                        }
                }else{
-                       $errormessage=$Lang::tr{'fwdfw dnat error'}."<br>";
-                       return $errormessage;
+                       if ($fwdfwsettings{'grp2'} ne 'ipfire'){
+                               $errormessage=$Lang::tr{'fwdfw dnat error'}."<br>";
+                               return $errormessage;
+                       }
                }
        }
        if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
@@ -606,8 +615,8 @@ sub checktarget
                        return $errormessage;
                }
        }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
-               $errormessage.=$Lang::tr{'fwdfw err notgtip'};
-               return $errormessage;
+               $fwdfwsettings{'grp2'}='std_net_tgt';
+               $fwdfwsettings{$fwdfwsettings{'grp2'}} = 'ALL';
        }
        #check for mac in targetgroup
        if ($fwdfwsettings{'grp2'} eq 'cust_grp_tgt'){
@@ -982,6 +991,12 @@ sub deleterule
                &base;
        }
 }
+sub del_double
+{
+       my %all=();
+       @all{@_}=1;
+       return (keys %all);
+}
 sub disable_rule
 {
        my $key1=shift;
@@ -1245,10 +1260,8 @@ sub get_serviceports
        my $name=shift;
        &General::readhasharray("$configsrv", \%customservice);
        &General::readhasharray("$configsrvgrp", \%customservicegrp);
-       my $tcp;
-       my $udp;
-       my $icmp;
        @protocols=();
+       my @specprot=("IPIP","IPV6","IGMP","GRE","AH","ESP");
        if($type eq 'service'){
                foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
                        if ($customservice{$key}[0] eq $name){
@@ -1258,33 +1271,23 @@ sub get_serviceports
        }elsif($type eq 'group'){
                foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
                        if ($customservicegrp{$key}[0] eq $name){
-                               foreach my $key1 (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
-                                       if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
-                                               if($customservice{$key1}[2] eq 'TCP'){
-                                                       $tcp='TCP';
-                                               }elsif($customservice{$key1}[2] eq 'ICMP'){
-                                                       $icmp='ICMP';
-                                               }elsif($customservice{$key1}[2] eq 'UDP'){
-                                                       $udp='UDP';
+                               if ($customservicegrp{$key}[2] ~~ @specprot){
+                                       push (@protocols," ".$customservicegrp{$key}[2]);
+                               }else{
+                                       foreach my $key1 (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
+                                               if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
+                                                       if (!grep(/$customservice{$key1}[2]/, @protocols)){
+                                                               push (@protocols,$customservice{$key1}[2]);}
                                                }
                                        }
                                }
                        }
                }
        }
-       if($tcp && $udp && $icmp){
-               push (@protocols,"TCP,UDP, <br>ICMP");
-               return @protocols;
-       }
-       if($tcp){
-               push (@protocols,"TCP");
-       }
-       if($udp){
-               push (@protocols,"UDP");
-       }
-       if($icmp){
-               push (@protocols,"ICMP");
-       }
+
+       # Sort protocols alphabetically.
+       @protocols = sort(@protocols);
+
        return @protocols;
 }
 sub getcolor
@@ -1293,6 +1296,12 @@ sub getcolor
        my $val=shift;
        my $hash=shift;
        if($optionsfw{'SHOWCOLORS'} eq 'on'){
+               # Don't colourise MAC addresses
+               if (&General::validmac($val)) {
+                       $tdcolor = "";
+                       return;
+               }
+
                #custom Hosts
                if ($nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
                        foreach my $key (sort keys %$hash){
@@ -1380,11 +1389,13 @@ sub getcolor
                        }
                        #Check if IP is part of a IPsec N2N network
                        foreach my $key (sort keys %ipsecconf){
-                               my ($a,$b) = split("/",$ipsecconf{$key}[11]);
-                               $b=&General::iporsubtodec($b);
-                               if (&General::IpInSubnet($c,$a,$b)){
-                                       $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
-                                       return;
+                               if ($ipsecconf{$key}[11]){
+                                       my ($a,$b) = split("/",$ipsecconf{$key}[11]);
+                                       $b=&General::iporsubtodec($b);
+                                       if (&General::IpInSubnet($c,$a,$b)){
+                                               $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
+                                               return;
+                                       }
                                }
                        }
                }
@@ -1527,6 +1538,8 @@ sub newrule
                                $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}}                 = 'selected';
                                $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
                                $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
+                               $selected{'dnat'}{$fwdfwsettings{'dnat'}}                               ='selected';
+                               $selected{'snat'}{$fwdfwsettings{'snat'}}                               ='selected';
                        }
                }
                $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
@@ -1572,7 +1585,7 @@ sub newrule
        my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
        if ($scidr eq '32'){$fwdfwsettings{$fwdfwsettings{'grp1'}}=$sip;}
        my ($dip,$dcidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp2'}});
-       if ($scidr eq '32'){$fwdfwsettings{$fwdfwsettings{'grp2'}}=$dip;}
+       if ($dcidr eq '32'){$fwdfwsettings{$fwdfwsettings{'grp2'}}=$dip;}
        &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'});
        #------SOURCE-------------------------------------------------------
        print "<form method='post'>";
@@ -1589,7 +1602,7 @@ END
                if (! -z "${General::swroot}/ethernet/aliases"){
                        foreach my $alias (sort keys %aliases)
                        {
-                               print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
+                               print "<option value='$alias' $selected{'ipfire_src'}{$alias}>$alias</option>";
                        }
                }
                print<<END;
@@ -1619,25 +1632,28 @@ END
                                                </td>
 END
 
-               if (%aliases) {
-                       print <<END;
+       print <<END;
                                                <td width='25%' align='right'>$Lang::tr{'dnat address'}:</td>
                                                <td width='30%'>
                                                        <select name='dnat' style='width: 100%;'>
-                                                               <option value='Default IP' $selected{'dnat'}{'Default IP'}>$Lang::tr{'default ip'} ($netsettings{'RED_ADDRESS'})</option>
+                                                               <option value='AUTO' $selected{'dnat'}{'AUTO'}>- $Lang::tr{'automatic'} -</option>
+                                                               <option value='Default IP' $selected{'dnat'}{'Default IP'}>$Lang::tr{'red1'} ($redip)</option>
 END
+               if (%aliases) {
                        foreach my $alias (sort keys %aliases) {
                                print "<option value='$alias' $selected{'dnat'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
                        }
-
-                       print "</select>";
-               } else {
-                       print <<END;
-                                               <td colspan="2" width='55%'>
-                                                       <input type='hidden' name='dnat' value='Default IP'>
-                                               </td>
-END
                }
+               #DNAT Dropdown
+               foreach my $network (sort keys %defaultNetworks)
+               {
+                       if ($defaultNetworks{$network}{'NAME'} eq 'BLUE'||$defaultNetworks{$network}{'NAME'} eq 'GREEN' ||$defaultNetworks{$network}{'NAME'} eq 'ORANGE'){
+                               print "<option value='$defaultNetworks{$network}{'NAME'}'";
+                               print " selected='selected'" if ($fwdfwsettings{'dnat'} eq $defaultNetworks{$network}{'NAME'});
+                               print ">$network ($defaultNetworks{$network}{'NET'})</option>";
+                       }
+               }
+               print "</select>";
                print "</tr>";
 
                #SNAT
@@ -1658,19 +1674,14 @@ END
                foreach my $alias (sort keys %aliases) {
                        print "<option value='$alias' $selected{'snat'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
                }
-
-               # XXX this is composed in a very ugly fashion
+               # SNAT Dropdown
                foreach my $network (sort keys %defaultNetworks) {
-                       next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
-                       next if($defaultNetworks{$network}{'NAME'} eq "ALL");
-                       next if($defaultNetworks{$network}{'NAME'} =~ /OpenVPN/i);
-                       next if($defaultNetworks{$network}{'NAME'} =~ /IPsec/i);
-
-                       print "<option value='$defaultNetworks{$network}{'NAME'}'";
-                       print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'nat'}} eq $defaultNetworks{$network}{'NAME'});
-                       print ">$network ($defaultNetworks{$network}{'NET'})</option>";
+                       if ($defaultNetworks{$network}{'NAME'} eq 'BLUE'||$defaultNetworks{$network}{'NAME'} eq 'GREEN' ||$defaultNetworks{$network}{'NAME'} eq 'ORANGE'){
+                               print "<option value='$defaultNetworks{$network}{'NAME'}'";
+                               print " selected='selected'" if ($fwdfwsettings{'snat'} eq $defaultNetworks{$network}{'NAME'});
+                               print ">$network ($defaultNetworks{$network}{'NET'})</option>";
+                       }
                }
-
                print <<END;
                                                        </select>
                                                </td>
@@ -2132,6 +2143,9 @@ sub saverule
                        &changerule($configfwdfw);
                        #print"6";
                }
+               $fwdfwsettings{'ruleremark'}=~ s/,/;/g;
+               utf8::decode($fwdfwsettings{'ruleremark'});
+               $fwdfwsettings{'ruleremark'}=&Header::escape($fwdfwsettings{'ruleremark'});
                if ($fwdfwsettings{'updatefwrule'} ne 'on'){
                        my $key = &General::findhasharraykey ($hash);
                        $$hash{$key}[0]  = $fwdfwsettings{'RULE_ACTION'};
@@ -2267,30 +2281,27 @@ sub saverule
 sub validremark
 {
        # Checks a hostname against RFC1035
-        my $remark = $_[0];
-
-       # Each part should be at least two characters in length
-       # but no more than 63 characters
-       if (length ($remark) < 1 || length ($remark) > 255) {
-               return 0;}
-       # Only valid characters are a-z, A-Z, 0-9 and -
-       if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
-               return 0;}
-       # First character can only be a letter or a digit
-       if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9(]*$/) {
-               return 0;}
-       # Last character can only be a letter or a digit
-       if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
-               return 0;}
-       return 1;
+       my $remark = $_[0];
+
+       # Try to decode $remark into UTF-8. If this doesn't work,
+       # we assume that the string it not sane.
+       if (!utf8::decode($remark)) {
+               return 0;
+       }
+
+       # Check if the string only contains of printable characters.
+       if ($remark =~ /^[[:print:]]*$/) {
+               return 1;
+       }
+       return 0;
 }
 sub viewtablerule
 {
        &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
 
        &viewtablenew(\%configfwdfw, $configfwdfw, $Lang::tr{'firewall rules'});
-       &viewtablenew(\%configinputfw, $configinput, $Lang::tr{'external access'});
-       &viewtablenew(\%configoutgoingfw, $configoutgoing, $Lang::tr{'outgoing firewall'});
+       &viewtablenew(\%configinputfw, $configinput, $Lang::tr{'incoming firewall access'});
+       &viewtablenew(\%configoutgoingfw, $configoutgoing, $Lang::tr{'outgoing firewall access'});
 }
 sub viewtablenew
 {
@@ -2362,26 +2373,18 @@ END
                                if($$hash{$key}[3] eq  'ipsec_net_src'){
                                        if(&fwlib::get_ipsec_net_ip($host,11) eq ''){
                                                $coloryellow='on';
-                                               &disable_rule($key);
-                                               $$hash{$key}[2]='';
                                        }
                                }elsif($$hash{$key}[3] eq  'ovpn_net_src'){
                                        if(&fwlib::get_ovpn_net_ip($host,1) eq ''){
                                                $coloryellow='on';
-                                               &disable_rule($key);
-                                               $$hash{$key}[2]='';
                                        }
                                }elsif($$hash{$key}[3] eq  'ovpn_n2n_src'){
                                        if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){
                                                $coloryellow='on';
-                                               &disable_rule($key);
-                                               $$hash{$key}[2]='';
                                        }
                                }elsif($$hash{$key}[3] eq  'ovpn_host_src'){
                                        if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
                                                $coloryellow='on';
-                                               &disable_rule($key);
-                                               $$hash{$key}[2]='';
                                        }
                                }
                        }
@@ -2389,26 +2392,18 @@ END
                                if($$hash{$key}[5] eq 'ipsec_net_tgt'){
                                        if(&fwlib::get_ipsec_net_ip($host,11) eq ''){
                                                $coloryellow='on';
-                                               &disable_rule($key);
-                                               $$hash{$key}[2]='';
                                        }
                                }elsif($$hash{$key}[5] eq 'ovpn_net_tgt'){
                                        if(&fwlib::get_ovpn_net_ip($host,1) eq ''){
                                                $coloryellow='on';
-                                               &disable_rule($key);
-                                               $$hash{$key}[2]='';
                                        }
                                }elsif($$hash{$key}[5] eq 'ovpn_n2n_tgt'){
                                        if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){
                                                $coloryellow='on';
-                                               &disable_rule($key);
-                                               $$hash{$key}[2]='';
                                        }
                                }elsif($$hash{$key}[5] eq 'ovpn_host_tgt'){
                                        if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
                                                $coloryellow='on';
-                                               &disable_rule($key);
-                                               $$hash{$key}[2]='';
                                        }
                                }
                        }
@@ -2416,15 +2411,11 @@ END
                        foreach my $netgroup (sort keys %customgrp){
                                if(($$hash{$key}[4] eq $customgrp{$netgroup}[0] || $$hash{$key}[6] eq $customgrp{$netgroup}[0]) && $customgrp{$netgroup}[2] eq 'none'){
                                        $coloryellow='on';
-                                       &disable_rule($key);
-                                       $$hash{$key}[2]='';
                                }
                        }
                        foreach my $srvgroup (sort keys %customservicegrp){
                                if($$hash{$key}[15] eq $customservicegrp{$srvgroup}[0] && $customservicegrp{$srvgroup}[2] eq 'none'){
                                        $coloryellow='on';
-                                       &disable_rule($key);
-                                       $$hash{$key}[2]='';
                                }
                        }
                        $$hash{'ACTIVE'}=$$hash{$key}[2];
@@ -2484,7 +2475,7 @@ END
                                push (@protocols,$Lang::tr{'all'});
                        }
 
-                       my $protz=join(",",@protocols);
+                       my $protz=join(", ",@protocols);
                        if($protz eq 'ICMP' && $$hash{$key}[9] ne 'All ICMP-Types' && $$hash{$key}[14] ne 'cust_srvgrp'){
                                &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
                                foreach my $keyicmp (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
@@ -2493,6 +2484,8 @@ END
                                                last;
                                        }
                                }
+                       }elsif($#protocols gt '3'){
+                               print"<td align='center'><span title='$protz'>$Lang::tr{'fwdfw many'}</span></td>";
                        }else{
                                print"<td align='center'>$protz</td>";
                        }
@@ -2559,8 +2552,21 @@ END
                                        <td align='center' $tdcolor>
 END
                        #Is this a DNAT rule?
+                       my $natstring;
                        if ($$hash{$key}[31] eq 'dnat' && $$hash{$key}[28] eq 'ON'){
-                               print "Firewall ($$hash{$key}[29])";
+                               if ($$hash{$key}[29] eq 'Default IP'){$$hash{$key}[29]=$Lang::tr{'red1'};}
+                               if ($$hash{$key}[29] eq 'AUTO'){
+                                       my @src_addresses=&fwlib::get_addresses(\%$hash,$key,'src');
+                                       my @nat_ifaces;
+                                       foreach my $val (@src_addresses){
+                                               push (@nat_ifaces,&fwlib::get_nat_address($$hash{$key}[29],$val));
+                                       }
+                                       @nat_ifaces=&del_double(@nat_ifaces);
+                                       $natstring = join(', ', @nat_ifaces);
+                               }else{
+                                       $natstring = $$hash{$key}[29];
+                               }
+                               print "$Lang::tr{'firewall'} ($natstring)";
                                if($$hash{$key}[30] ne ''){
                                        $$hash{$key}[30]=~ tr/|/,/;
                                        print": $$hash{$key}[30]";
@@ -2716,7 +2722,7 @@ END
                                <td colspan='13'>&nbsp;</td>
                        </tr>
                        <tr>
-                               <td colspan='13' style="padding-left:0px;">
+                               <td colspan='13' style="padding-left:0px;padding-right:0px">
                                        <table width="100%" border='1' rules="cols" cellspacing='0'>
 END
 
@@ -2799,14 +2805,16 @@ END
                                                <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
                                                ($Lang::tr{'fwdfw pol block'})
                                        </td>
+END
+                       }
+
+                       print <<END;
                                        <td align='center'>
                                                <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
                                                ($Lang::tr{'fwdfw pol block'})
                                        </td>
+                               </tr>
 END
-                       }
-
-                       print"</tr>";
                }
 
                print <<END;