]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - html/cgi-bin/firewall.cgi
Firewall: Bugfix - when using addressgroups with mac addresses in source, the mac...
[people/teissler/ipfire-2.x.git] / html / cgi-bin / firewall.cgi
old mode 100755 (executable)
new mode 100644 (file)
index e5a6eee..86cba60
@@ -136,14 +136,17 @@ print<<END;
                \$("#protocol").change(update_protocol);
                update_protocol();
 
-               // When nat not used, hide it
-               if (! \$("#USE_NAT").attr("checked")) {
+               // Show/Hide elements when NAT checkbox is checked.
+               if (\$("#USE_NAT").attr("checked")) {
+                       \$("#actions").hide();
+               } else {
                        \$(".NAT").hide();
                }
 
                // Show NAT area when "use nat" checkbox is clicked
                \$("#USE_NAT").change(function() {
                        \$(".NAT").toggle();
+                       \$("#actions").toggle();
                });
 
                // Time constraints
@@ -158,11 +161,6 @@ print<<END;
                // dropdown menu changes.
                \$("select").change(function() {
                        var id = \$(this).attr("name");
-
-                       // When using SNAT or DNAT, check "USE NAT" Checkbox
-                       if (id === 'snat' || id === 'dnat') {
-                               \$('#USE_NAT').prop('checked', true);
-                       }
                        \$('#' + id).prop("checked", true);
                });
        });
@@ -251,17 +249,6 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule')
                        }
                }
                if (!$errormessage){
-                       &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
-                       if ($fwdfwsettings{'nobase'} ne 'on'){
-                               &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
-                       }
-                       if($fwdfwsettings{'oldusesrv'} eq '' &&  $fwdfwsettings{'USESRV'} eq 'ON'){
-                               &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
-                       }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
-                               &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
-                       }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
-                               &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
-                       }
                        if($fwdfwsettings{'nosave2'} ne 'on'){
                                &saverule(\%configinputfw,$configinput);
                        }
@@ -307,18 +294,6 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule')
                }
                #increase counters
                if (!$errormessage){
-                &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
-                &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
-                       if($fwdfwsettings{'oldusesrv'} eq '' &&  $fwdfwsettings{'USESRV'} eq 'ON'){
-                               &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
-                       }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
-                               &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
-                       }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
-                               &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
-                       }
-                       if ($fwdfwsettings{'nobase'} eq 'on'){
-                               &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
-                       }
                        if ($fwdfwsettings{'nosave2'} ne 'on'){
                                &saverule(\%configoutgoingfw,$configoutgoing);
                        }
@@ -364,18 +339,6 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule')
                }
                #increase counters
                if (!$errormessage){
-                       &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
-                       &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
-                       if($fwdfwsettings{'oldusesrv'} eq '' &&  $fwdfwsettings{'USESRV'} eq 'ON'){
-                               &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
-                       }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
-                               &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
-                       }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
-                               &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
-                       }
-                       if ($fwdfwsettings{'nobase'} eq 'on'){
-                               &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
-                       }
                        if ($fwdfwsettings{'nosave2'} ne 'on'){
                                &saverule(\%configfwdfw,$configfwdfw);
                        }
@@ -458,15 +421,13 @@ sub addrule
 {
        &error;
 
-       &Header::openbox('100%', 'left',  $Lang::tr{'fwdfw menu'});
+       &Header::openbox('100%', 'left', "");
        print <<END;
                <form method="POST" action="">
                        <table border='0' width="100%">
                                <tr>
-                                       <td>
+                                       <td align='center'>
                                                <input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'>
-                                       </td>
-                                       <td align="right">
 END
 
        if (&General::firewall_needs_reload()) {
@@ -481,8 +442,9 @@ END
                        </table>
                </form>
 
-               <hr>
+               <br>
 END
+
        &Header::closebox();
        &viewtablerule;
 }
@@ -498,8 +460,6 @@ sub changerule
        $fwdfwsettings{'config'}=$oldchain;
        $fwdfwsettings{'nobase'}='on';
        &deleterule;
-       &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
-       &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
 }
 sub checksource
 {
@@ -649,6 +609,19 @@ sub checktarget
                $errormessage.=$Lang::tr{'fwdfw err notgtip'};
                return $errormessage;
        }
+       #check for mac in targetgroup
+       if ($fwdfwsettings{'grp2'} eq 'cust_grp_tgt'){
+               &General::readhasharray("$configgrp", \%customgrp);
+               &General::readhasharray("$confighost", \%customhost);
+               foreach my $grpkey (sort keys %customgrp){
+                       foreach my $hostkey (sort keys %customhost){
+                               if ($customgrp{$grpkey}[2] eq $customhost{$hostkey}[0] && $customhost{$hostkey}[1] eq 'mac'){
+                                       $hint=$Lang::tr{'fwdfw hint mac'};
+                                       return $hint;
+                               }
+                       }
+               }
+       }
        #check empty fields
        if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err notgt'}."<br>";}
        #check tgt services
@@ -702,6 +675,8 @@ sub checktarget
                                                        if (&General::validport($_)){
                                                                push (@values,$_);
                                                        }else{
+                                                               $errormessage=$Lang::tr{'fwdfw err tgt_port'};
+                                                               return $errormessage;
                                                        }
                                                }
                                        }
@@ -767,14 +742,32 @@ sub checkrule
 {
        #check valid port for NAT
        if($fwdfwsettings{'USE_NAT'} eq 'ON'){
-               #if no port is given in nat area, take target host port
+               #RULE_ACTION must be ACCEPT if we use NAT
+               $fwdfwsettings{'RULE_ACTION'} = 'ACCEPT';
+
+               #if no dnat or snat selected errormessage
+               if ($fwdfwsettings{'nat'} eq ''){
+                       $errormessage=$Lang::tr{'fwdfw dnat nochoice'};
+                       return;
+               }
+
+               #if using snat, the external port has to be empty
+               if ($fwdfwsettings{'nat'} eq 'snat' && $fwdfwsettings{'dnatport'} ne ''){
+                       $errormessage=$Lang::tr{'fwdfw dnat extport'};
+                       return;
+               }
+               #if no dest port is given in nat area, take target host port
                if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$fwdfwsettings{'TGT_PORT'};}
+               if($fwdfwsettings{'TGT_PORT'} eq '' && $fwdfwsettings{'dnatport'} ne '' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP')){
+                       $errormessage=$Lang::tr{'fwdfw dnat porterr2'};
+                       return;
+               }
                #check if port given in nat area is a single valid port or portrange
                if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport($fwdfwsettings{'dnatport'})){
                        $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
                }elsif($fwdfwsettings{'USESRV'} eq 'ON' && $fwdfwsettings{'grp3'} eq 'cust_srv'){
                        my $custsrvport;
-                       #get servcie Protocol and Port
+                       #get service Protocol and Port
                        foreach my $key (sort keys %customservice){
                                if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]){
                                        if ($customservice{$key}[2] ne 'TCP' && $customservice{$key}[2] ne 'UDP'){
@@ -821,6 +814,10 @@ sub checkrule
                                        }
                                        $fwdfwsettings{'dnatport'}=join("|",@values);
                }
+               #check if a rule with prot tcp or udp and ports is edited and now prot is "all", then delete all ports
+               if($fwdfwsettings{'PROT'} eq ''){
+                       $fwdfwsettings{'dnatport'}='';
+               }
        }
        #check valid remark
        if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
@@ -856,12 +853,7 @@ sub checkrule
                        }
                }
        }
-       #When using source- or targetport, the protocol has to be TCP or UDP
-       if (($fwdfwsettings{'USESRV'} eq 'ON' || $fwdfwsettings{'USE_SRC_PORT'} eq 'ON') && ($fwdfwsettings{'SRC_PORT'} ne '' || $fwdfwsettings{'TGT_PORT'} ne '') && ($fwdfwsettings{'PROT'} ne 'TCP' && $fwdfwsettings{'PROT'} ne 'UDP')){
-               $errormessage.=$Lang::tr{'fwdfw err prot_port1'};
-               return;
-       }
-       #when icmp selected, no targetport allowed
+       #when icmp selected, no source and targetport allowed
        if (($fwdfwsettings{'PROT'} ne '' && $fwdfwsettings{'PROT'} ne 'TCP' && $fwdfwsettings{'PROT'} ne 'UDP' && $fwdfwsettings{'PROT'} ne 'template') && ($fwdfwsettings{'USESRV'} eq 'ON' || $fwdfwsettings{'USE_SRC_PORT'} eq 'ON')){
                $errormessage.=$Lang::tr{'fwdfw err prot_port'};
                return;
@@ -931,41 +923,14 @@ sub checkrule
                $fwdfwsettings{'ICMP_TYPES'}='';
                $fwdfwsettings{'USESRV'}='';
                $fwdfwsettings{'TGT_PORT'}='';
-       }elsif($fwdfwsettings{'PROT'} ne 'TCP' && $fwdfwsettings{'PROT'} ne 'UDP' && $fwdfwsettings{'PROT'} ne 'ICMP'){
+       }elsif($fwdfwsettings{'PROT'} ne 'TCP' && $fwdfwsettings{'PROT'} ne 'UDP'){
                $fwdfwsettings{'ICMP_TYPES'}='';
-               $fwdfwsettings{'PROT'} = '';
+               $fwdfwsettings{'SRC_PORT'}='';
+               $fwdfwsettings{'TGT_PORT'}='';
        }elsif($fwdfwsettings{'PROT'} ne 'ICMP'){
                $fwdfwsettings{'ICMP_TYPES'}='';
        }
 }
-sub checkcounter
-{
-       my ($base1,$val1,$base2,$val2) = @_;
-               
-       if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){
-               &dec_counter($confignet,\%customnetwork,$val1);
-       }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){
-               &dec_counter($confighost,\%customhost,$val1);
-       }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){
-               &dec_counter($configgrp,\%customgrp,$val1);
-       }elsif($base1 eq 'cust_srv'){
-               &dec_counter($configsrv,\%customservice,$val1);
-       }elsif($base1 eq 'cust_srvgrp'){
-               &dec_counter($configsrvgrp,\%customservicegrp,$val1);   
-       }
-
-       if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){
-               &inc_counter($confignet,\%customnetwork,$val2);
-       }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){
-               &inc_counter($confighost,\%customhost,$val2);
-       }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){
-               &inc_counter($configgrp,\%customgrp,$val2);
-       }elsif($base2 eq 'cust_srv'){
-               &inc_counter($configsrv,\%customservice,$val2);
-       }elsif($base2 eq 'cust_srvgrp'){
-               &inc_counter($configsrvgrp,\%customservicegrp,$val2);   
-       }
-}
 sub checkvpn
 {
        my $ip=shift;
@@ -997,15 +962,6 @@ sub deleterule
        my %delhash=();
        &General::readhasharray($fwdfwsettings{'config'}, \%delhash);
        foreach my $key (sort {$a <=> $b} keys %delhash){
-               if ($key == $fwdfwsettings{'key'}){
-                       #check hosts/net and groups
-                       &checkcounter($delhash{$key}[3],$delhash{$key}[4],,);
-                       &checkcounter($delhash{$key}[5],$delhash{$key}[6],,);
-                       #check services and groups
-                       if ($delhash{$key}[11] eq 'ON'){
-                               &checkcounter($delhash{$key}[14],$delhash{$key}[15],,);
-                       }
-               }
                if ($key >= $fwdfwsettings{'key'}) {
                        my $next = $key + 1;
                        if (exists $delhash{$next}) {
@@ -1038,21 +994,6 @@ sub disable_rule
        &General::writehasharray("$configfwdfw", \%configfwdfw);
        &General::firewall_config_changed();
 }
-sub dec_counter
-{
-       my $config=shift;
-       my %hash=%{(shift)};
-       my $val=shift;
-       my $pos;
-       &General::readhasharray($config, \%hash);
-       foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) }  keys %hash){
-               if($hash{$key}[0] eq $val){
-                       $pos=$#{$hash{$key}};
-                       $hash{$key}[$pos] = $hash{$key}[$pos]-1;
-               }
-       }
-       &General::writehasharray($config, \%hash);
-}
 sub error
 {
        if ($errormessage) {
@@ -1060,7 +1001,6 @@ sub error
                print "<class name='base'>$errormessage\n";
                print "&nbsp;</class>\n";
                &Header::closebox();
-               print"<hr>";
        }
 }
 sub fillselect
@@ -1104,7 +1044,7 @@ sub gen_dd_block
 print<<END;
                <table width='100%' border='0'>
                <tr><td width='50%' valign='top'>
-               <table width='100%' border='0'>
+               <table width='95%' border='0'>
                <tr><td width='1%'><input type='radio' name='$grp' id='std_net_$srctgt' value='std_net_$srctgt' $checked{$grp}{'std_net_'.$srctgt}></td><td>$Lang::tr{'fwhost stdnet'}</td><td align='right'><select name='std_net_$srctgt' style='width:200px;'>
 END
        foreach my $network (sort keys %defaultNetworks)
@@ -1140,7 +1080,7 @@ END
        if (! -z $configgrp || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
                print"<tr><td valign='top'><input type='radio' name='$grp' id='cust_grp_$srctgt' value='cust_grp_$srctgt' $checked{$grp}{'cust_grp_'.$srctgt}></td><td >$Lang::tr{'fwhost cust grp'}</td><td align='right'><select name='cust_grp_$srctgt' style='width:200px;'>";
                foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } keys %customgrp) {
-                       if($helper ne $customgrp{$key}[0]){
+                       if($helper ne $customgrp{$key}[0] && $customgrp{$key}[2] ne 'none'){
                                print"<option ";
                                print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $customgrp{$key}[0]);
                                print ">$customgrp{$key}[0]</option>";
@@ -1150,7 +1090,7 @@ END
                print"</select></td>";
        }
        #End left table. start right table (vpn)
-       print"</tr></table></td><td valign='top'><table width='100%' border='0'><tr>";
+       print"</tr></table></td><td valign='top'><table width='95%' border='0' align='right'><tr>";
        # CCD networks
        if( ! -z $configccdnet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
                print"<td width='1%'><input type='radio' name='$grp' id='ovpn_net_$srctgt' value='ovpn_net_$srctgt'  $checked{$grp}{'ovpn_net_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_net_$srctgt' style='width:200px;'>";
@@ -1187,7 +1127,7 @@ END
        if ($show eq '1'){$show='';print"</select></td></tr>";}
        #IPsec netze
        foreach my $key (sort { ncmp($ipsecconf{$a}[1],$ipsecconf{$b}[1]) } keys %ipsecconf) {
-               if ($ipsecconf{$key}[3] eq 'net' || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
+               if ($ipsecconf{$key}[3] eq 'net' || ($optionsfw{'SHOWDROPDOWN'} eq 'on' && $ipsecconf{$key}[3] ne 'host')){
                        print"<tr><td valign='top'><input type='radio' name='$grp' value='ipsec_net_$srctgt' $checked{$grp}{'ipsec_net_'.$srctgt}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td align='right'><select name='ipsec_net_$srctgt' style='width:200px;'>" if ($show eq '');
                        $show='1';
                        print "<option ";
@@ -1377,6 +1317,12 @@ sub getcolor
                }elsif ($val eq 'IPFire' ){
                        $tdcolor="style='background-color: $Header::colourred;color:white;'";
                        return;
+               }elsif ($val eq 'OpenVPN-Dyn' ){
+                       $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
+                       return;
+               }elsif ($val eq 'IPsec RW' ){
+                       $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
+                       return;
                }elsif($val =~ /^(.*?)\/(.*?)$/){
                        my ($sip,$scidr) = split ("/",$val);
                        if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
@@ -1435,6 +1381,7 @@ 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;
@@ -1469,25 +1416,8 @@ sub hint
                print "<class name='base'>$hint\n";
                print "&nbsp;</class>\n";
                &Header::closebox();
-               print"<hr>";
        }
 }
-sub inc_counter
-{
-       my $config=shift;
-       my %hash=%{(shift)};
-       my $val=shift;
-       my $pos;
-
-       &General::readhasharray($config, \%hash);
-       foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) }  keys %hash){
-               if($hash{$key}[0] eq $val){
-                       $pos=$#{$hash{$key}};
-                       $hash{$key}[$pos] = $hash{$key}[$pos]+1;
-               }
-       }
-       &General::writehasharray($config, \%hash);
-}
 sub newrule
 {
        &error;
@@ -1512,6 +1442,11 @@ sub newrule
        open (CONN1,"/var/ipfire/red/local-ipaddress");
        my $redip = <CONN1>;
        close(CONN1);
+       if (! $fwdfwsettings{'RULE_ACTION'} && $fwdfwsettings{'POLICY'} eq 'MODE2'){
+               $fwdfwsettings{'RULE_ACTION'}='DROP';
+       }elsif(! $fwdfwsettings{'RULE_ACTION'} && $fwdfwsettings{'POLICY'} eq 'MODE1'){
+               $fwdfwsettings{'RULE_ACTION'}='ACCEPT';
+       }
        $checked{'grp1'}{$fwdfwsettings{'grp1'}}                                = 'CHECKED';
        $checked{'grp2'}{$fwdfwsettings{'grp2'}}                                = 'CHECKED';
        $checked{'grp3'}{$fwdfwsettings{'grp3'}}                                = 'CHECKED';
@@ -1587,13 +1522,11 @@ sub newrule
                                $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}}                = 'CHECKED';
                                $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}}                = 'CHECKED';
                                $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}}                  = 'CHECKED';
-                               $checked{'nat'}{$fwdfwsettings{'nat'}}                                  = 'CHECKED';
+                               $checked{'nat'}{$fwdfwsettings{'nat'}}                                  = 'CHECKED';
                                $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}}             = 'selected';
                                $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}}                 = 'selected';
                                $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
                                $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
-                               $selected{'dnat'}{$fwdfwsettings{$fwdfwsettings{'nat'}}} ='selected';
-                               $selected{'snat'}{$fwdfwsettings{$fwdfwsettings{'nat'}}} ='selected';
                        }
                }
                $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
@@ -1615,7 +1548,9 @@ sub newrule
                }
        }else{
                $fwdfwsettings{'ACTIVE'}='ON';
+               $fwdfwsettings{'nat'} = 'dnat';
                $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
+               $checked{'nat'}{$fwdfwsettings{'nat'}} = 'CHECKED';
                $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
                $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
                $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
@@ -1633,8 +1568,11 @@ sub newrule
                        }
                }       
        }
-       &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
-       &Header::closebox();
+       # Split manual source and target address and delete the subnet
+       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;}
        &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'});
        #------SOURCE-------------------------------------------------------
        print "<form method='post'>";
@@ -1656,10 +1594,10 @@ END
                }
                print<<END;
                </select></td></tr>
-               <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
+               <tr><td><br></td></tr>
+               </table>
 END
                &gen_dd_block('src','grp1');
-               print"<hr>";
                &Header::closebox();
 
                #---SNAT / DNAT ------------------------------------------------
@@ -1675,7 +1613,7 @@ END
                                                <td width='5%'></td>
                                                <td width='40%'>
                                                        <label>
-                                                               <input type='radio' name='nat' id='dnat' value='dnat' checked>
+                                                               <input type='radio' name='nat'  value='dnat' $checked{'nat'}{'dnat'}>
                                                                $Lang::tr{'fwdfw dnat'}
                                                        </label>
                                                </td>
@@ -1686,10 +1624,10 @@ 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'}</option>
+                                                               <option value='Default IP' $selected{'dnat'}{'Default IP'}>$Lang::tr{'default ip'} ($netsettings{'RED_ADDRESS'})</option>
 END
                        foreach my $alias (sort keys %aliases) {
-                               print "<option value='$alias' $selected{'dnat'}{$alias}>$alias</option>";
+                               print "<option value='$alias' $selected{'dnat'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
                        }
 
                        print "</select>";
@@ -1708,7 +1646,7 @@ END
                                                <td width='5%'></td>
                                                <td width='40%'>
                                                        <label>
-                                                               <input type='radio' name='nat' id='snat' value='snat' $checked{'nat'}{'snat'}>
+                                                               <input type='radio' name='nat'  value='snat' $checked{'nat'}{'snat'}>
                                                                $Lang::tr{'fwdfw snat'}
                                                        </label>
                                                </td>
@@ -1718,7 +1656,7 @@ END
 END
 
                foreach my $alias (sort keys %aliases) {
-                       print "<option value='$alias' $selected{'snat'}{$alias}>$alias</option>";
+                       print "<option value='$alias' $selected{'snat'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
                }
 
                # XXX this is composed in a very ugly fashion
@@ -1726,10 +1664,11 @@ END
                        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</option>";
+                       print ">$network ($defaultNetworks{$network}{'NET'})</option>";
                }
 
                print <<END;
@@ -1761,10 +1700,9 @@ END
                }
                print<<END;
                </select></td></tr>
-               <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
+               <tr><td><br></td></tr></table>
 END
                &gen_dd_block('tgt','grp2');
-               print"<hr>";
                &Header::closebox;
                #---PROTOCOL------------------------------------------------------
                $fwdfwsettings{'SRC_PORT'} =~ s/\|/,/g;
@@ -1898,7 +1836,7 @@ END
                &General::readhasharray("$configsrvgrp", \%customservicegrp);
                my $helper;
                foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
-                       if ($helper ne $customservicegrp{$key}[0]){
+                       if ($helper ne $customservicegrp{$key}[0] && $customservicegrp{$key}[2] ne 'none'){
                                print"<option ";
                                print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
                                print">$customservicegrp{$key}[0]</option>";
@@ -1917,25 +1855,10 @@ END
 END
 
                &Header::closebox;
-
-               $checked{"RULE_ACTION"} = ();
-               foreach ("ACCEPT", "DROP", "REJECT") {
-                       $checked{"RULE_ACTION"}{$_} = "";
-               }
-
-               if($fwdfwsettings{'updatefwrule'} eq 'on') {
-                       $checked{"RULE_ACTION"}{$fwdfwsettings{'RULE_ACTION'}} = "checked";
-               } elsif ($fwdfwsettings{'POLICY'} eq 'MODE1') {
-                       $checked{"RULE_ACTION"}{"ACCEPT"} = "checked";
-               } elsif ($fwdfwsettings{'POLICY'} eq 'MODE2') {
-                       $checked{"RULE_ACTION"}{"DROP"} = "checked";
-               }
-
+               $checked{"RULE_ACTION"}{$fwdfwsettings{'RULE_ACTION'}}  = 'CHECKED';
                print <<END;
-                       <hr><br>
-
                        <center>
-                               <table width="80%" border="0">
+                               <table width="80%" class='tbl' id='actions'>
                                        <tr>
                                                <td width="33%" align="center" bgcolor="$color{'color17'}">
                                                        &nbsp;<br>&nbsp;
@@ -1972,7 +1895,6 @@ END
 
                        <br>
 END
-
                #---Activate/logging/remark-------------------------------------
                &Header::openbox('100%', 'left', $Lang::tr{'fwdfw additional'});
                print<<END;
@@ -2080,7 +2002,7 @@ END
                                </td>
                        </tr>
                </table>
-               <br><hr>
+               <br>
 END
 
                #---ACTION------------------------------------------------------
@@ -2355,7 +2277,7 @@ sub validremark
        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]*$/) {
+       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.:;_)]*$/) {
@@ -2365,36 +2287,43 @@ sub validremark
 sub viewtablerule
 {
        &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
-       &viewtablenew(\%configfwdfw,$configfwdfw,"","Forward" );
-       &viewtablenew(\%configinputfw,$configinput,"",$Lang::tr{'fwdfw xt access'} );
-       &viewtablenew(\%configoutgoingfw,$configoutgoing,"","Outgoing" );
+
+       &viewtablenew(\%configfwdfw, $configfwdfw, $Lang::tr{'firewall rules'});
+       &viewtablenew(\%configinputfw, $configinput, $Lang::tr{'external access'});
+       &viewtablenew(\%configoutgoingfw, $configoutgoing, $Lang::tr{'outgoing firewall'});
 }
 sub viewtablenew
 {
        my $hash=shift;
        my $config=shift;
        my $title=shift;
-       my $title1=shift;
        my $go='';
+
+       my $show_box = (! -z $config) || ($optionsfw{'SHOWTABLES'} eq 'on');
+       return if (!$show_box);
+
        &General::get_aliases(\%aliases);
        &General::readhasharray("$confighost", \%customhost);
        &General::readhasharray("$config", $hash);
        &General::readhasharray("$configccdnet", \%ccdnet);
        &General::readhasharray("$configccdhost", \%ccdhost);
-       if( ! -z $config){
-               &Header::openbox('100%', 'left',$title);
+       &General::readhasharray("$configgrp", \%customgrp);
+       &General::readhasharray("$configsrvgrp", \%customservicegrp);
+
+       &Header::openbox('100%', 'left', $title);
+       print "<table width='100%' cellspacing='0' class='tbl'>";
+
+       if (! -z $config) {
                my $count=0;
                my ($gif,$log);
                my $ruletype;
                my $rulecolor;
                my $tooltip;
                my @tmpsrc=();
+               my @tmptgt=();
                my $coloryellow='';
-               print <<END;
-                       <b>$title1</b>
-                       <br>
 
-                       <table width='100%' cellspacing='0' border='0'>
+               print <<END;
                                <tr>
                                        <th align='right' width='3%'>
                                                #
@@ -2421,33 +2350,34 @@ END
                foreach my $key (sort  {$a <=> $b} keys %$hash){
                        $tdcolor='';
                        @tmpsrc=();
+                       @tmptgt=();
                        #check if vpn hosts/nets have been deleted
                        if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){
                                push (@tmpsrc,$$hash{$key}[4]);
                        }
                        if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){
-                               push (@tmpsrc,$$hash{$key}[6]);
+                               push (@tmptgt,$$hash{$key}[6]);
                        }
                        foreach my $host (@tmpsrc){
-                               if($$hash{$key}[3] eq  'ipsec_net_src' || $$hash{$key}[5] eq 'ipsec_net_tgt'){
+                               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' || $$hash{$key}[5] eq 'ovpn_net_tgt'){
+                               }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' || $$hash{$key}[5] eq 'ovpn_n2n_tgt'){
+                               }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' || $$hash{$key}[5] eq 'ovpn_host_tgt'){
+                               }elsif($$hash{$key}[3] eq  'ovpn_host_src'){
                                        if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
                                                $coloryellow='on';
                                                &disable_rule($key);
@@ -2455,10 +2385,52 @@ END
                                        }
                                }
                        }
+                       foreach my $host (@tmptgt){
+                               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]='';
+                                       }
+                               }
+                       }
+                       #check if networkgroups or servicegroups are empty
+                       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];
                        $count++;
                        if($coloryellow eq 'on'){
-                               print"<tr bgcolor='$color{'color14'}' >";
+                               $color="$color{'color14'}";
                                $coloryellow='';
                        }elsif($coloryellow eq ''){
                                if ($count % 2){ 
@@ -2543,8 +2515,14 @@ END
                                }
                        }elsif ($$hash{$key}[4] eq 'RED1'){
                                print "$ipfireiface $Lang::tr{'fwdfw red'}";
+                       }elsif ($$hash{$key}[4] eq 'ALL'){
+                               print "$ipfireiface $Lang::tr{'all'}";
                        }else{
-                               print "$$hash{$key}[4]";
+                               if ($$hash{$key}[4] eq 'GREEN' || $$hash{$key}[4] eq 'ORANGE' || $$hash{$key}[4] eq 'BLUE' || $$hash{$key}[4] eq 'RED'){
+                                       print "$ipfireiface $Lang::tr{lc($$hash{$key}[4])}";
+                               }else{
+                                       print "$ipfireiface $$hash{$key}[4]";
+                               }
                        }
                        $tdcolor='';
                        #SOURCEPORT
@@ -2589,15 +2567,12 @@ END
                                }
                                print"<br>-&gt;";
                        }
-                       if ($$hash{$key}[5] eq 'ipfire'){
-                               $ipfireiface='Interface';
-                       }
-                       if ($$hash{$key}[5] eq 'std_net_tgt' || $$hash{$key}[5] eq 'ipfire'  || $$hash{$key}[6] eq 'RED1' || $$hash{$key}[6] eq 'GREEN' || $$hash{$key}[6] eq 'ORANGE' || $$hash{$key}[6] eq 'BLUE' ){
+                       if ($$hash{$key}[5] eq 'std_net_tgt' || $$hash{$key}[5] eq 'ipfire'){
                                if ($$hash{$key}[6] eq 'RED1'){
-                                       print "$ipfireiface $Lang::tr{'red1'}";
-                               }elsif ($$hash{$key}[6] eq 'GREEN' || $$hash{$key}[6] eq 'ORANGE' || $$hash{$key}[6] eq 'BLUE'|| $$hash{$key}[6] eq 'ALL')
+                                       print "$Lang::tr{'red1'}";
+                               }elsif ($$hash{$key}[6] eq 'GREEN' || $$hash{$key}[6] eq 'ORANGE' || $$hash{$key}[6] eq 'BLUE'|| $$hash{$key}[6] eq 'ALL' || $$hash{$key}[6] eq 'RED')
                                {
-                                       print "$ipfireiface ".&get_name($$hash{$key}[6]);
+                                       print &get_name($$hash{$key}[6]);
                                }else{
                                        print $$hash{$key}[6];
                                }
@@ -2719,97 +2694,152 @@ END
                        }
                        print"<tr bgcolor='FFFFFF'><td colspan='13' height='1'></td></tr>";
                }
-               print"</table>";
-               #SHOW FINAL RULE
-               print "<table width='100%'rules='cols' border='1'>";
-               my $col;
-               if ($config eq '/var/ipfire/firewall/config'){
-                       my $pol='fwdfw '.$fwdfwsettings{'POLICY'};
-                       if ($fwdfwsettings{'POLICY'} eq 'MODE1'){
-                               $col="bgcolor='darkred'";
-                       }else{
-                               $col="bgcolor='green'";
-                       }
-                       &show_defaultrules($col,$pol);
-               }elsif ($config eq '/var/ipfire/firewall/outgoing'){
-                       if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){
-                               $col="bgcolor='darkred'";
-                               print"<tr><td $col width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF' >$Lang::tr{'fwdfw pol block'}</font></td></tr>";
-                       }else{
-                               $col="bgcolor='green'";
-                               print"<tr><td $col width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF' >$Lang::tr{'fwdfw pol allow'}</font></td></tr>";
-                       }
-               }else{
-                       print"<tr><td bgcolor='darkred' width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td bgcolor='darkred' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol block'}</font></td></tr>";
+       } elsif ($optionsfw{'SHOWTABLES'} eq 'on') {
+               print <<END;
+                       <tr>
+                               <td colspan='7' height='30' bgcolor=$color{'color22'} align='center'>$Lang::tr{'fwhost empty'}</td>
+                       </tr>
+END
+       }
+
+       #SHOW FINAL RULE
+       my $policy = 'fwdfw ' . $fwdfwsettings{'POLICY'};
+       my $colour = "bgcolor='green'";
+       if ($fwdfwsettings{'POLICY'} eq 'MODE1') {
+               $colour = "bgcolor='darkred'";
+       }
+
+       my $message;
+       if (($config eq '/var/ipfire/firewall/config') && ($fwdfwsettings{'POLICY'} ne 'MODE1')) {
+               print <<END;
+                       <tr>
+                               <td colspan='13'>&nbsp;</td>
+                       </tr>
+                       <tr>
+                               <td colspan='13'>
+                                       <table width="100%" border='1' rules="cols" cellspacing='0'>
+END
+
+               # GREEN
+               print <<END;
+                       <tr>
+                               <td align='center'>
+                                       <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
+                               </td>
+                               <td align='center'>
+                                       <font color="$Header::colourred">$Lang::tr{'red'}</font>
+                                       ($Lang::tr{'fwdfw pol allow'})
+                               </td>
+END
+
+               if (&Header::orange_used()) {
+                       print <<END;
+                               <td align='center'>
+                                       <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
+                                       ($Lang::tr{'fwdfw pol allow'})
+                               </td>
+END
                }
-               print"</table>";
-               print "<hr>";
-               print "<br><br>";
-               &Header::closebox();
-       }else{
-               if ($optionsfw{'SHOWTABLES'} eq 'on'){
-                       print "<b>$title1</b><br>";
-                       print"<table width='100%' border='0' rules='none'><tr><td height='30' bgcolor=$color{'color22'} align='center'>$Lang::tr{'fwhost empty'}</td></tr></table>";
-                       my $col;
-                       if ($config eq '/var/ipfire/firewall/config'){
-                               my $pol='fwdfw '.$fwdfwsettings{'POLICY'};
-                               if ($fwdfwsettings{'POLICY'} eq 'MODE1'){
-                                       $col="bgcolor='darkred'";
-                               }else{
-                                       $col="bgcolor='green'";
-                               }
-                               &show_defaultrules($col,$pol);
-                       }elsif ($config eq '/var/ipfire/firewall/outgoing'){
-                               print "<table width='100%' rules='cols' border='1'>";
-                               my $pol='fwdfw '.$fwdfwsettings{'POLICY1'};
-                               if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){
-                                       $col="bgcolor='darkred'";
-                                       print"<tr><td $col align='center' width='20%'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol block'}</font></td></tr>";
-                               }else{
-                                       $col="bgcolor='green'";
-                                       print"<tr><td $col align='center' width='20%'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol allow'}</font></td></tr>";
-                               }
-                       }else{
-                               print "<table width='100%' rules='cols' border='1'>";
-                               print"<tr><td bgcolor='darkred' align='center' width='20%'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td align='center' bgcolor='darkred'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol block'}</font></td></tr>";
-                       }
-                       print"</table><br><br>";
+
+               if (&Header::blue_used()) {
+                       print <<END;
+                               <td align='center'>
+                                       <font color="$Header::colourblue">$Lang::tr{'blue'}</font>
+                                       ($Lang::tr{'fwdfw pol allow'})
+                               </td>
+END
                }
-       }
-}
-&Header::closebigbox();
-&Header::closepage();
 
-sub show_defaultrules
-{
-       my $col=shift;
-       my $pol=shift;
-       #STANDARD RULES (From WIKI)
-       print"</table>";
-       if ($col eq "bgcolor='green'"){
-               print "<br><table width='100%' rules='cols' border='1' >";
-               my $blue   = "<font color=$Header::colourblue>    $Lang::tr{'blue'}</font> ($Lang::tr{'fwdfw pol block'})" if (&Header::blue_used());
-               my $orange = "<font color=$Header::colourorange>  $Lang::tr{'orange'}</font> ($Lang::tr{'fwdfw pol block'})" if (&Header::orange_used());
-               my $blue1   = "<font color=$Header::colourblue>    $Lang::tr{'blue'}</font> ($Lang::tr{'fwdfw pol allow'})" if (&Header::blue_used());
-               my $orange1 = "<font color=$Header::colourorange>  $Lang::tr{'orange'}</font> ($Lang::tr{'fwdfw pol allow'})" if (&Header::orange_used());
-               print"<tr><td align='center'><font color='#000000'>$Lang::tr{'green'}</td><td align='center'> <font color=$Header::colourred>  $Lang::tr{'red'}</font> ($Lang::tr{'fwdfw pol allow'})</td>";
-               print"<td align='center'>$orange1</td>" if (&Header::orange_used());
-               print"<td align='center'>$blue1</td>" if (&Header::blue_used());
                print"</tr>";
-               if (&Header::orange_used()){
-                       print"<tr><td align='center' width='20%'><font color='#000000'>$Lang::tr{'orange'}</td><td align='center'> <font color=$Header::colourred>  $Lang::tr{'red'}</font> ($Lang::tr{'fwdfw pol allow'})</td><td align='center'><font color=$Header::colourgreen>  $Lang::tr{'green'}</font> ($Lang::tr{'fwdfw pol block'})</td>";
-                       print"<td align='center'>$blue</td>" if (&Header::blue_used());
+
+               # ORANGE
+               if (&Header::orange_used()) {
+                       print <<END;
+                               <tr>
+                                       <td align='center' width='20%'>
+                                               <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
+                                       </td>
+                                       <td align='center'>
+                                               <font color="$Header::colourred">$Lang::tr{'red'}</font>
+                                               ($Lang::tr{'fwdfw pol allow'})
+                                       </td>
+                                       <td align='center'>
+                                               <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
+                                               ($Lang::tr{'fwdfw pol block'})
+                                       </td>
+END
+
+                       if (&Header::blue_used()) {
+                               print <<END;
+                                       <td align='center'>
+                                               <font color="$Header::colourblue">$Lang::tr{'blue'}</font>
+                                               ($Lang::tr{'fwdfw pol block'})
+                                       </td>
+END
+                       }
+
                        print"</tr>";
                }
-               if (&Header::blue_used()){
-                       print"<tr><td align='center'><font color='#000000'>$Lang::tr{'blue'}</td><td align='center'> <font color=$Header::colourred>  $Lang::tr{'red'}</font> ($Lang::tr{'fwdfw pol allow'})</td>";
-                       print"<td align='center'>$orange</td>" if (&Header::orange_used());
-                       print"<td align='center'><font color=$Header::colourgreen>  $Lang::tr{'green'}</font> ($Lang::tr{'fwdfw pol block'})</td>";
+
+               if (&Header::blue_used()) {
+                       print <<END;
+                               <tr>
+                                       <td align='center'>
+                                               <font color="$Header::colourblue">$Lang::tr{'blue'}</font>
+                                       </td>
+                                       <td align='center'>
+                                               <font color="$Header::colourred">$Lang::tr{'red'}</font>
+                                               ($Lang::tr{'fwdfw pol allow'})
+                                       </td>
+END
+
+                       if (&Header::orange_used()) {
+                               print <<END;
+                                       <td align='center'>
+                                               <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
+                                               ($Lang::tr{'fwdfw pol block'})
+                                       </td>
+                                       <td align='center'>
+                                               <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
+                                               ($Lang::tr{'fwdfw pol block'})
+                                       </td>
+END
+                       }
+
                        print"</tr>";
                }
-               print"<tr><td $col align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'} </font></td><td $col colspan='3' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol allow'}</font></td></tr>";
-       }elsif($col eq "bgcolor='darkred'"){
-               print "<table width='100%' rules='cols' border='1' >";
-               print"<tr><td $col width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol block'}</font></td></tr>";
+
+               print <<END;
+                                       </table>
+                               </td>
+                       </tr>
+END
+
+               $message = $Lang::tr{'fwdfw pol allow'};
+
+       } elsif ($config eq '/var/ipfire/firewall/outgoing' && ($fwdfwsettings{'POLICY1'} ne 'MODE1')) {
+               $message = $Lang::tr{'fwdfw pol allow'};
+               $colour = "bgcolor='green'";
+       } else {
+               $message = $Lang::tr{'fwdfw pol block'};
+               $colour = "bgcolor='darkred'";
        }
+
+       if ($message) {
+               print <<END;
+                       <tr>
+                               <td $colour align='center' colspan='13'>
+                                       <font color='#FFFFFF'>$Lang::tr{'policy'}: $message</font>
+                               </td>
+                       </tr>
+END
+       }
+
+       print "</table>";
+       print "<br>";
+
+       &Header::closebox();
 }
+
+&Header::closebigbox();
+&Header::closepage();