]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/fwhosts.cgi
Firewall: added JS to automatically select radiobuttons in fwhosts
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / fwhosts.cgi
index 9369c22d104976d1786b1bc2716c2dc8202a6357..330b0f72d4f410e36385410e05cbf2fe28454774 100755 (executable)
@@ -46,6 +46,7 @@ my %ownnet=();
 my %ipsecsettings=();
 my %fwfwd=();
 my %fwinp=();
+my %fwout=();
 my %ovpnsettings=();
 
 
@@ -60,8 +61,9 @@ my $configccdhost     = "${General::swroot}/ovpn/ovpnconfig";
 my $configipsec                = "${General::swroot}/vpn/config";
 my $configsrv          = "${General::swroot}/fwhosts/customservices";
 my $configsrvgrp       = "${General::swroot}/fwhosts/customservicegrp";
-my $fwconfigfwd                = "${General::swroot}/forward/config";
-my $fwconfiginp                = "${General::swroot}/forward/input";
+my $fwconfigfwd                = "${General::swroot}/firewall/config";
+my $fwconfiginp                = "${General::swroot}/firewall/input";
+my $fwconfigout                = "${General::swroot}/firewall/outgoing";
 my $configovpn         = "${General::swroot}/ovpn/settings";
 my $tdcolor='';
 my $configipsecrw      = "${General::swroot}/vpn/settings";
@@ -88,67 +90,38 @@ unless (-e $configsrvgrp) { system("touch $configsrvgrp"); }
 #### JAVA SCRIPT ####
 print<<END;
 <script>
+       var PROTOCOLS_WITH_PORTS = ["TCP", "UDP"];
+       var update_protocol = function() {
+               var protocol = \$("#protocol").val();
+
+               if (protocol === undefined)
+                       return;
+
+               // Check if we are dealing with a protocol, that knows ports.
+               if (\$.inArray(protocol, PROTOCOLS_WITH_PORTS) >= 0) {
+                       \$("#PORT").show();
+                       \$("#PROTOKOLL").hide();
+               } else {
+                       \$("#PORT").hide();
+                       \$("#PROTOKOLL").show();
+               }
+       };
+
        \$(document).ready(function() {
+               var protocol = \$("#protocol").val();
+               \$("#protocol").change(update_protocol);
+               update_protocol();
                // Automatically select radio buttons when corresponding
                // 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);
                });
-               // When protokol is not ICMP hide icmp-types
-               if ( \$("#PROT").val() === 'ICMP') {
-                       \$('PROTOKOLL').hide();
-               }
-               // When protocol dropdown is changed, check if we selected icmp - then show icmp-types
-               \$("#prt").change(function(){
-                       if ( \$("#PROT").val() === 'ICMP' ){
-                               \$('PROTOKOLL').show();
-                       }
-                       else{
-                               \$('PROTOKOLL').hide();
-                       }
-               });
        });
-function hide_elements(){
-       var elementNames = hide_elements.arguments;
-       for (var i=0; i<elementNames.length; i++)
-       {
-               var elementName = elementNames[i];
-               document.getElementById(elementName).style.display='none';
-       }
-}
-function getdropdown(){
-       d = document.getElementById("PROT").value;
-       if ( d == 'ICMP' )
-       {
-               document.getElementById('PROTOKOLL').style.display='block';
-       }
-       else
-       {
-               document.getElementById('PROTOKOLL').style.display='none';
-       }
-       if(document.getElementById('PROTOKOLL').style.display== "block" )
-       {
-               document.getElementById('PORT').style.display='none';
-       }
-       if(document.getElementById('PROTOKOLL').style.display== "none" )
-       {
-               document.getElementById('PORT').style.display='block';
-       }
-}
 </script>
 END
 
 ## ACTION ####
-if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
-{
-       &reread_rules;
-       &showmenu;
-}
 # Update
 if ($fwhostsettings{'ACTION'} eq 'updatenet' )
 {
@@ -201,13 +174,15 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice')
        my $count=0;
        my $needrules=0;
        $errormessage=&checkports(\%customservice);
+       if ($fwhostsettings{'oldsrvname'} ne $fwhostsettings{'SRV_NAME'} && !&checkgroup($fwhostsettings{'SRV_NAME'})){
+               $errormessage=$Lang::tr{'fwhost err grpexist'};
+       }
        if (!$errormessage){
                &General::readhasharray("$configsrv", \%customservice);
                foreach my $key (keys %customservice)
                {
                        if ($customservice{$key}[0] eq $fwhostsettings{'oldsrvname'})
                        {
-                               $count=$customservice{$key}[4];
                                delete $customservice{$key};
                                &General::writehasharray("$configsrv", \%customservice);
                                last;
@@ -229,7 +204,6 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice')
                $customservice{$key1}[1] = $fwhostsettings{'SRV_PORT'};
                $customservice{$key1}[2] = $fwhostsettings{'PROT'};
                $customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'};
-               $customservice{$key1}[4] = $count;
                &General::writehasharray("$configsrv", \%customservice);
                #check if we need to update firewallrules
                if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){
@@ -251,6 +225,15 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice')
                                }
                                &General::writehasharray("$fwconfiginp", \%fwinp);
                        }
+                       if ( ! -z $fwconfigout ){
+                               &General::readhasharray("$fwconfigout", \%fwout);
+                               foreach my $line (sort keys %fwout){
+                                       if ($fwout{$line}[15] eq $fwhostsettings{'oldsrvname'}){
+                                               $fwout{$line}[15] = $fwhostsettings{'SRV_NAME'};
+                                       }
+                               }
+                               &General::writehasharray("$fwconfigout", \%fwout);
+                       }
                        #check if we need to update groups
                        &General::readhasharray("$configsrvgrp", \%customservicegrp);
                        foreach my $key (sort keys %customservicegrp){
@@ -275,6 +258,7 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice')
                $fwhostsettings{'PROT'}         = '';
                $fwhostsettings{'ICMP'}         = '';
                $fwhostsettings{'oldsrvicmp'} = '';
+               $fwhostsettings{'updatesrv'} = '';
        }else{
                $fwhostsettings{'SRV_NAME'}     = $fwhostsettings{'oldsrvname'};
                $fwhostsettings{'SRV_PORT'}     = $fwhostsettings{'oldsrvport'};
@@ -282,16 +266,14 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice')
                $fwhostsettings{'ICMP'}         = $fwhostsettings{'oldsrvicmp'};
                $fwhostsettings{'updatesrv'}= 'on';
        }
-       $fwhostsettings{'updatesrv'} = '';
        if($needrules eq 'on'){
-               &rules;
+               &General::firewall_config_changed();
        }
        &addservice;
 }
 # save
 if ($fwhostsettings{'ACTION'} eq 'savenet' )
 {
-       my $count=0;
        my $needrules=0;
        if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
        #check if all fields are set
@@ -365,7 +347,6 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                        $customnetwork{$key}[1] = $fwhostsettings{'orgip'} ;
                        $customnetwork{$key}[2] = $fwhostsettings{'orgsub'};
                        $customnetwork{$key}[3] = $fwhostsettings{'orgnetremark'};
-                       $customnetwork{$key}[4] = $fwhostsettings{'count'};
                        &General::writehasharray("$confignet", \%customnetwork);
                        undef %customnetwork;
                }                       
@@ -376,7 +357,6 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                                if ($fwhostsettings{'update'} == '0'){
                                        foreach my $key (keys %customnetwork) {
                                                if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}){
-                                                       $count=$customnetwork{$key}[4];
                                                        delete $customnetwork{$key};
                                                        last;
                                                }
@@ -386,9 +366,8 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                        #get count if actualize is 'on'
                        if($fwhostsettings{'actualize'} eq 'on'){
                                $fwhostsettings{'actualize'} = '';
-                               $count=$fwhostsettings{'count'};
                                #check if we need to reload rules
-                               if($fwhostsettings{'orgip'}  ne $fwhostsettings{'IP'}  && $count gt '0'){
+                               if($fwhostsettings{'orgip'}  ne $fwhostsettings{'IP'}){
                                        $needrules='on';
                                }
                                if ($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
@@ -426,7 +405,7 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                                }
                        }                                       
                        my $key = &General::findhasharraykey (\%customnetwork);
-                       foreach my $i (0 .. 4) { $customnetwork{$key}[$i] = "";}
+                       foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
                        $fwhostsettings{'SUBNET'}       = &General::iporsubtocidr($fwhostsettings{'SUBNET'});
                        $customnetwork{$key}[0]         = $fwhostsettings{'HOSTNAME'};
                        #convert ip when leading '0' in byte
@@ -434,9 +413,7 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                        $fwhostsettings{'IP'}           =&General::dec2ip($fwhostsettings{'IP'});
                        $customnetwork{$key}[1]         = &General::getnetworkip($fwhostsettings{'IP'},$fwhostsettings{'SUBNET'}) ;
                        $customnetwork{$key}[2]         = &General::iporsubtodec($fwhostsettings{'SUBNET'}) ;
-                       if($fwhostsettings{'newnet'} eq 'on'){$count=0;}
                        $customnetwork{$key}[3]         = $fwhostsettings{'NETREMARK'};
-                       $customnetwork{$key}[4]         = $count;
                        &General::writehasharray("$confignet", \%customnetwork);
                        $fwhostsettings{'IP'}=$fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
                        undef %customnetwork;
@@ -446,7 +423,7 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                        $fwhostsettings{'NETREMARK'}='';
                        #check if an edited net affected groups and need to reload rules
                        if ($needrules eq 'on'){
-                               &rules;
+                               &General::firewall_config_changed();
                        }
                        &addnet;
                        &viewtablenet;
@@ -458,7 +435,6 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
 }
 if ($fwhostsettings{'ACTION'} eq 'savehost')
 {
-       my $count=0;
        my $needrules=0;
        if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
        $fwhostsettings{'SUBNET'}='32';
@@ -506,7 +482,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){
                        $fwhostsettings{'actualize'} = '';
                        my $key = &General::findhasharraykey (\%customhost);
-                       foreach my $i (0 .. 4) { $customhost{$key}[$i] = "";}
+                       foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";}
                        $customhost{$key}[0] = $fwhostsettings{'orgname'} ;
                        $customhost{$key}[1] = $fwhostsettings{'type'} ;
                        if($customhost{$key}[1] eq 'ip'){
@@ -515,15 +491,13 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                                $customhost{$key}[2] = $fwhostsettings{'orgip'};
                        }
                        $customhost{$key}[3] = $fwhostsettings{'orgremark'};
-                       $customhost{$key}[4] = $fwhostsettings{'count'};
                        &General::writehasharray("$confighost", \%customhost);
                        undef %customhost;
                } 
                if (!$errormessage){
                        #get count if host was edited
                        if($fwhostsettings{'actualize'} eq 'on'){
-                               $count=$fwhostsettings{'count'};
-                               if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'} && $count gt '0' ){
+                               if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){
                                        $needrules='on';
                                }
                                if($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
@@ -560,7 +534,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                                }
                        }
                        my $key = &General::findhasharraykey (\%customhost);
-                       foreach my $i (0 .. 4) { $customhost{$key}[$i] = "";}
+                       foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";}
                        $customhost{$key}[0] = $fwhostsettings{'HOSTNAME'} ;
                        $customhost{$key}[1] = $fwhostsettings{'type'} ;
                        if ($fwhostsettings{'type'} eq 'ip'){
@@ -571,9 +545,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                        }else{
                                $customhost{$key}[2] = $fwhostsettings{'IP'};
                        }
-                       if($fwhostsettings{'newhost'} eq 'on'){$count=0;}
                        $customhost{$key}[3] = $fwhostsettings{'HOSTREMARK'};
-                       $customhost{$key}[4] =$count;
                        &General::writehasharray("$confighost", \%customhost);
                        undef %customhost;
                        $fwhostsettings{'HOSTNAME'}='';
@@ -582,7 +554,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                         $fwhostsettings{'HOSTREMARK'}='';
                        #check if we need to update rules while host was edited
                        if($needrules eq 'on'){
-                               &rules;
+                               &General::firewall_config_changed();
                        }
                        &addhost;
                        &viewtablehost;
@@ -594,7 +566,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
 }
 if ($fwhostsettings{'ACTION'} eq 'savegrp')
 {
-       my $grp=$fwhostsettings{'grp_name'};;
+       my $grp=$fwhostsettings{'grp_name'};
        my $rem=$fwhostsettings{'remark'};
        my $count;
        my $type;
@@ -604,10 +576,13 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
        &General::readhasharray("$configgrp", \%customgrp);
        &General::readhasharray("$confignet", \%customnetwork);
        &General::readhasharray("$confighost", \%customhost);
+       &General::readhasharray("$fwconfigfwd", \%fwfwd);
+       &General::readhasharray("$fwconfiginp", \%fwinp);
+       &General::readhasharray("$fwconfigout", \%fwout);
        #check name
        if (!&validhostname($grp)){$errormessage.=$Lang::tr{'fwhost err name'};}
        #check existing name
-       if (!checkgroup(\%customgrp,$grp) && $fwhostsettings{'update'} ne 'on'){$errormessage.=$Lang::tr{'fwhost err grpexist'};}
+       if (!&checkgroup($grp) && $fwhostsettings{'update'} ne 'on'){$errormessage.=$Lang::tr{'fwhost err grpexist'};}
        #check remark
        if ($rem ne '' && !&validremark($rem) && $fwhostsettings{'update'} ne 'on'){
                $errormessage.=$Lang::tr{'fwhost err remark'};
@@ -708,17 +683,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
                }
                &General::writehasharray("$configgrp", \%customgrp);
                &General::readhasharray("$configgrp", \%customgrp);
-               #get count used
-               foreach my $key (keys %customgrp)
-               {
-                       if($customgrp{$key}[0] eq $grp)
-                       {
-                               $count=$customgrp{$key}[4];
-                               last;
-                       }
-               }
-               if ($count eq '' ){$count='0';}
-               
                #create array with new lines
                foreach my $line (@target){
                        push (@newgrp,"$grp,$rem,$line");
@@ -726,38 +690,23 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
                #append new entries
                my $key = &General::findhasharraykey (\%customgrp);
                foreach my $line (@newgrp){
-                       foreach my $i (0 .. 4) { $customgrp{$key}[$i] = "";}
+                       foreach my $i (0 .. 3) { $customgrp{$key}[$i] = "";}
                        my ($a,$b,$c,$d) = split (",",$line);
                        $customgrp{$key}[0] = $a;
                        $customgrp{$key}[1] = $b;
                        $customgrp{$key}[2] = $c;
                        $customgrp{$key}[3] = $type;
-                       $customgrp{$key}[4] = $count;
                }
                &General::writehasharray("$configgrp", \%customgrp);
                #update counter in Host/Net
-               if($updcounter eq 'net'){
-                       foreach my $key (keys %customnetwork) {
-                               if($customnetwork{$key}[0] eq $fwhostsettings{'CUST_SRC_NET'}){
-                                       $customnetwork{$key}[4] = $customnetwork{$key}[4]+1;
-                                       last;
-                               }
-                       }
-                       &General::writehasharray("$confignet", \%customnetwork);
-               }elsif($updcounter eq 'host'){
-                       foreach my $key (keys %customhost) {
-                               if ($customhost{$key}[0] eq $fwhostsettings{'CUST_SRC_HOST'}){
-                                       $customhost{$key}[4]=$customhost{$key}[4]+1;
-                               }
-                       }
-                       &General::writehasharray("$confighost", \%customhost);
-               }
                $fwhostsettings{'update'}='on';
        }
                #check if ruleupdate is needed
-               if($count > 0 )
+               my $netgrpcount=0;
+               $netgrpcount=&getnetcount($grp);
+               if($netgrpcount > 0 )
                {
-                       &rules;
+                       &General::firewall_config_changed();
                }
                &addgrp;
                &viewtablegrp;
@@ -766,6 +715,7 @@ if ($fwhostsettings{'ACTION'} eq 'saveservice')
 {
        my $ICMP;
        &General::readhasharray("$configsrv", \%customservice );
+       &General::readhasharray("$configgrp", \%customgrp);
        $errormessage=&checkports(\%customservice);
        if ($fwhostsettings{'PROT'} eq 'ICMP'){
                &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
@@ -775,7 +725,12 @@ if ($fwhostsettings{'ACTION'} eq 'saveservice')
                        }
                }
        }
-       if($ICMP eq ''){$ICMP='BLANK';}
+       if($ICMP eq ''){$ICMP=$fwhostsettings{'ICMP_TYPES'};}
+       if ($fwhostsettings{'PROT'} ne 'ICMP'){$ICMP='BLANK';}
+       #Check if a group with the same name already exists
+       if (!&checkgroup($fwhostsettings{'SRV_NAME'})){
+               $errormessage = $Lang::tr{'fwhost err grpexist'};
+       }
        if (!$errormessage){
                my $key = &General::findhasharraykey (\%customservice);
                foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";}
@@ -783,7 +738,6 @@ if ($fwhostsettings{'ACTION'} eq 'saveservice')
                $customservice{$key}[1] = $fwhostsettings{'SRV_PORT'};
                $customservice{$key}[2] = $fwhostsettings{'PROT'};
                $customservice{$key}[3] = $ICMP;
-               $customservice{$key}[4] = 0;
                &General::writehasharray("$configsrv", \%customservice );
                #reset fields
                $fwhostsettings{'SRV_NAME'}='';
@@ -798,12 +752,38 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
        my $prot;
        my $port;
        my $count=0;
+       my $tcpcounter=0;
+       my $udpcounter=0;
        &General::readhasharray("$configsrvgrp", \%customservicegrp );
        &General::readhasharray("$configsrv", \%customservice );
        $errormessage=&checkservicegroup;
+       #Check if we have more than 15 services from one Protocol in the group
+       #iptables can only handle 15 ports/portranges via multiport
+       foreach my $key (keys %customservicegrp){
+               if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){
+                       foreach my $key1 (keys %customservice){
+                               $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0];
+                               $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i;
+                               $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0];
+                               $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i;
+                       }
+               }
+       }
+       if ($tcpcounter > 15){
+               $errormessage=$Lang::tr{'fwhost err maxservicetcp'};
+       }
+       if ($udpcounter > 15){
+               $errormessage=$Lang::tr{'fwhost err maxserviceudp'};
+       }
+       $tcpcounter=0;
+       $udpcounter=0;
        #check remark
        if ($fwhostsettings{'SRVGRP_REMARK'} ne '' && !&validremark($fwhostsettings{'SRVGRP_REMARK'})){
-               $errormessage=$Lang::tr{'fwhost err remark'};
+               $errormessage .= $Lang::tr{'fwhost err remark'};
+       }
+       #Check if there is already a service with the same name
+       if(!&checkservice($fwhostsettings{'SRVGRP_NAME'})){
+               $errormessage .= $Lang::tr{'fwhost err srv exists'};
        }
        if (!$errormessage){
                #on first save, we have to enter a dummy value
@@ -827,39 +807,19 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
                                {
                                        $customservicegrp{$key}[1]='';
                                        $customservicegrp{$key}[1]=$fwhostsettings{'SRVGRP_REMARK'};
-                               }       
-                       }
-               }
-               #get count used
-               foreach my $key (keys %customservicegrp)
-               {
-                       if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
-                       {
-                               $count=$customservicegrp{$key}[3];
-                               last;
-                       }
-               }
-               if ($count eq '' ){$count='0';}
-                       
-               foreach my $key (sort keys %customservice){
-                       if($customservice{$key}[0] eq $fwhostsettings{'CUST_SRV'}){
-                               $port=$customservice{$key}[1];
-                               $prot=$customservice{$key}[2];
-                               $customservice{$key}[4]++;
+                               }
                        }
                }
-               &General::writehasharray("$configsrv", \%customservice );
                my $key = &General::findhasharraykey (\%customservicegrp);
-               foreach my $i (0 .. 3) { $customservice{$key}[$i] = "";}
+               foreach my $i (0 .. 2) { $customservice{$key}[$i] = "";}
                $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'};
                $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'};
                $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'};
-               $customservicegrp{$key}[3] = $count;
                &General::writehasharray("$configsrvgrp", \%customservicegrp );
                $fwhostsettings{'updatesrvgrp'}='on';
        }
        if ($count gt 0){
-               &rules;
+               &General::firewall_config_changed();
        }
        &addservicegrp;
        &viewtableservicegrp;
@@ -974,7 +934,9 @@ if ($fwhostsettings{'ACTION'} eq 'deletegrphost')
                }
        }
        &General::writehasharray("$configgrp", \%customgrp);
-       if ($fwhostsettings{'grpcnt'} > 0){&rules;}
+       if ($fwhostsettings{'grpcnt'} > 0){
+               &General::firewall_config_changed();
+       }
        if ($fwhostsettings{'update'} eq 'on'){
                $fwhostsettings{'remark'}= $grpremark;
                $fwhostsettings{'grp_name'}=$grpname;
@@ -1003,7 +965,6 @@ if ($fwhostsettings{'ACTION'} eq 'delservice')
        &General::readhasharray("$configsrv", \%customservice);
        foreach my $key (keys %customservice) {
                if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
-                       #&deletefromgrp($customhost{$key}[0],$configgrp);
                        delete $customservice{$key};
                        &General::writehasharray("$configsrv", \%customservice);
                        last;
@@ -1037,7 +998,7 @@ if ($fwhostsettings{'ACTION'} eq 'delgrpservice')
        &General::readhasharray("$configsrvgrp", \%customservicegrp);
        &General::readhasharray("$configsrv", \%customservice);
        foreach my $key (keys %customservicegrp){
-               if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2].",".$customservicegrp{$key}[3] eq $fwhostsettings{'delsrvfromgrp'})
+               if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2] eq $fwhostsettings{'delsrvfromgrp'})
                {
                        #decrease count from source service
                        foreach my $key1 (sort keys %customservice){
@@ -1046,14 +1007,14 @@ if ($fwhostsettings{'ACTION'} eq 'delgrpservice')
                                        last;
                                }
                        }
-                       &General::writehasharray("$configsrv", \%customservice);
                        $grpname=$customservicegrp{$key}[0];
                        $grpremark=$customservicegrp{$key}[1];
                        delete $customservicegrp{$key};
                }
        }
+       &General::writehasharray("$configsrv", \%customservice);
        &General::writehasharray("$configsrvgrp", \%customservicegrp);
-       &rules;
+       &General::firewall_config_changed();
        if ($fwhostsettings{'updatesrvgrp'} eq 'on'){
                $fwhostsettings{'SRVGRP_NAME'}=$grpname;
                $fwhostsettings{'SRVGRP_REMARK'}=$grpremark;
@@ -1126,6 +1087,9 @@ if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark')
                        &General::writehasharray("$configsrvgrp", \%customservicegrp);
                        $fwhostsettings{'updatesrvgrp'}='on';
                        $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'newsrvrem'};
+       }elsif($fwhostsettings{'oldsrvrem'} eq $fwhostsettings{'newsrvrem'}){
+               &addservicegrp;
+               &viewtableservicegrp;
        }else{
                $errormessage=$Lang::tr{'fwhost err remark'};
                $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'oldsrvrem'};
@@ -1142,11 +1106,7 @@ if($fwhostsettings{'ACTION'} eq '')
        &showmenu;
 }
 ###  FUNCTIONS  ###
-sub showmenu
-{
-       if (-f "${General::swroot}/forward/reread"){
-               print "<table border='1' rules='groups' bgcolor='lightgreen' width='100%'><form method='post'><td><div style='font-size:11pt; font-weight: bold;vertical-align: middle; '><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-face: Comic Sans MS; color: green; font-weight: bold; font-size: 14pt;'>&nbsp &nbsp $Lang::tr{'fwhost reread'}</td></tr></table></form><br>";
-       }
+sub showmenu {
        &Header::openbox('100%', 'left',$Lang::tr{'fwhost menu'});
        print "$Lang::tr{'fwhost welcome'}";
        print<<END;
@@ -1344,9 +1304,9 @@ sub addservice
                $fwhostsettings{'oldsrvicmp'} = $fwhostsettings{'ICMP'};
        }
        print<<END;
-       <div id='prt'><table width='100%' border='0'><form method='post'>
+       <table width='100%' border='0'><form method='post'>
        <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost srv_name'}:</td><td><input type='text' name='SRV_NAME' id='textbox1' value='$fwhostsettings{'SRV_NAME'}' size='24'><script>document.getElementById('textbox1').focus()</script></td></tr>
-       <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT' id='PROT' >
+       <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT' id='protocol' >
 END
        foreach ("TCP","UDP","ICMP")
        {
@@ -1358,11 +1318,11 @@ END
                }
        }
        print<<END;
-       </select></td></tr></table></div>
+       </select></td></tr></table>
        <div id='PROTOKOLL' class='noscript'><table width=100%' border='0'><tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost icmptype'}</td><td><select name='ICMP_TYPES'>
 END
        &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
-       print"<option>All ICMP-Types</option>";
+       print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>";
        foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
                if ($icmptypes{$key}[0] eq $fwhostsettings{'oldsrvicmp'}){
                        print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
@@ -1387,19 +1347,13 @@ END
                <input type='hidden' name='oldsrvicmp' value='$fwhostsettings{'oldsrvicmp'}'>
                </form>
 END
-               
-       }else{  
+       }else{
                print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>";
        }
        print<<END;
        <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr>
        </table></form>
-       
-       
 END
-       #if ($fwhostsettings{'PROT'} ne 'ICMP'){
-                       #print"<script language='JavaScript'>hide_elements('PROTOKOLL');</script>";
-               #}
        &Header::closebox();
        &viewtableservice;
 }
@@ -1430,13 +1384,24 @@ END
        if($fwhostsettings{'updatesrvgrp'} eq 'on'){
        print<<END;
        <form method='post'><input type='hidden' name='SRVGRP_REMARK' value='$fwhostsettings{'SRVGRP_REMARK'}'><input type='hidden' name='SRVGRP_NAME' value='$fwhostsettings{'SRVGRP_NAME'}'><table border='0' width='100%'>
-       <tr><td width='1%' nowrap='nowrap'>$Lang::tr{'fwhost cust service'}</td><td><select name='CUST_SRV' style='min-width:185px;'>
+       <tr><td width='1%' nowrap='nowrap'>$Lang::tr{'add'}</td><td><select name='CUST_SRV' style='min-width:185px;'>
 END
        &General::readhasharray("$configsrv", \%customservice);
+       #Protocols for use in servicegroups
+       print "<optgroup label='$Lang::tr{'fwhost cust service'}'>";
        foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice)
        {
                print "<option>$customservice{$key}[0]</option>";
        }
+       print "</optgroup>";
+       print "<optgroup label='$Lang::tr{'protocol'}'>";
+       print "<option>GRE</option>";
+       print "<option>AH</option>";
+       print "<option>ESP</option>";
+       print "<option>IGMP</option>";
+       print "<option>IPIP</option>";
+       print "<option value='IPV6'>IPv6 encap</option>";
+       print "</optgroup>";
        print<<END;
        </select></td></tr>
        <tr><td colspan='4'><br><br></td></tr>
@@ -1457,6 +1422,10 @@ sub viewtablenet
        if(! -z $confignet){
                &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'});
                &General::readhasharray("$confignet", \%customnetwork);
+               &General::readhasharray("$configgrp", \%customgrp);
+               &General::readhasharray("$fwconfigfwd", \%fwfwd);
+               &General::readhasharray("$fwconfiginp", \%fwinp);
+               &General::readhasharray("$fwconfigout", \%fwout);
                if (!keys %customnetwork) 
                { 
                        print "<center><b>$Lang::tr{'fwhost empty'}</b>"; 
@@ -1478,7 +1447,8 @@ END
                                print" <tr bgcolor='$color{'color20'}'>";
                        }
                        my $colnet="$customnetwork{$key}[1]/".&General::subtocidr($customnetwork{$key}[2]);
-                       print"<td width='20%'><form method='post'>$customnetwork{$key}[0]</td><td width='15%' align='center'>".&Header::colorize($colnet)."</td><td width='40%'>$customnetwork{$key}[3]</td><td align='center'>$customnetwork{$key}[4]x</td>";
+                       my $netcount=&getnetcount($customnetwork{$key}[0]);
+                       print"<td width='20%'><form method='post'>$customnetwork{$key}[0]</td><td width='15%' align='center'>".&Header::colorize($colnet)."</td><td width='40%'>$customnetwork{$key}[3]</td><td align='center'>$netcount x</td>";
                        print<<END;
                        <td width='1%'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} />
                        <input type='hidden' name='ACTION' value='editnet'>
@@ -1488,7 +1458,7 @@ END
                        <input type='hidden' name='NETREMARK' value='$customnetwork{$key}[3]' />
                        </td></form>
 END
-                       if($customnetwork{$key}[4] == '0')
+                       if($netcount == '0')
                        {
                                print"<td width='1%'><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} /><input type='hidden' name='ACTION' value='delnet' /><input type='hidden' name='key' value='$customnetwork{$key}[0]' /></td></form></tr>";
                        }else{
@@ -1556,6 +1526,10 @@ sub viewtablehost
                &General::readhasharray("$confighost", \%customhost);
                &General::readhasharray("$configccdnet", \%ccdnet);
                &General::readhasharray("$configccdhost", \%ccdhost);
+               &General::readhasharray("$fwconfigfwd", \%fwfwd);
+               &General::readhasharray("$fwconfiginp", \%fwinp);
+               &General::readhasharray("$fwconfigout", \%fwout);
+               &General::readhasharray("$configgrp", \%customgrp);
                if (!keys %customhost) 
                { 
                        print "<center><b>$Lang::tr{'fwhost empty'}</b>"; 
@@ -1573,7 +1547,9 @@ END
                        else{            print" <tr bgcolor='$color{'color20'}'>";}
                        my ($ip,$sub)=split(/\//,$customhost{$key}[2]);
                        $customhost{$key}[4]=~s/\s+//g;
-                       print"<td width='20%'>$customhost{$key}[0]</td><td width='20%' align='center' ".&getcolor($ip).">".&Header::colorize($ip)."</td><td width='50%' align='left'>$customhost{$key}[3]</td><td align='center'>$customhost{$key}[4]x</td>";
+                       my $hostcount=0;
+                       $hostcount=&gethostcount($customhost{$key}[0]);
+                       print"<td width='20%'>$customhost{$key}[0]</td><td width='20%' align='center' ".&getcolor($ip).">".&Header::colorize($ip)."</td><td width='50%' align='left'>$customhost{$key}[3]</td><td align='center'>$hostcount x</td>";
                        print<<END;
                        <td width='1%'><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} />
                        <input type='hidden' name='ACTION' value='edithost' />
@@ -1583,7 +1559,7 @@ END
                        <input type='hidden' name='HOSTREMARK' value='$customhost{$key}[3]' />
                        </form></td>
 END
-                       if($customhost{$key}[4] == '0')
+                       if($hostcount == '0')
                        {
                                print"<td width='1%'><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} /><input type='hidden' name='ACTION' value='delhost' /><input type='hidden' name='key' value='$customhost{$key}[0]' /></td></form></tr>";
                        }else{
@@ -1605,6 +1581,9 @@ sub viewtablegrp
        &General::readhasharray("$configccdnet", \%ccdnet);
        &General::readhasharray("$confighost", \%customhost);
        &General::readhasharray("$confignet", \%customnetwork);
+       &General::readhasharray("$fwconfigfwd", \%fwfwd);
+       &General::readhasharray("$fwconfiginp", \%fwinp);
+       &General::readhasharray("$fwconfigout", \%fwout);
        my @grp=();
        my $helper='';
        my $count=1;
@@ -1613,7 +1592,7 @@ sub viewtablegrp
        my $number;
        my $delflag;
        if (!keys %customgrp) 
-       { 
+       {
                print "<center><b>$Lang::tr{'fwhost err emptytable'}</b>";
        }else{
                foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
@@ -1636,8 +1615,9 @@ sub viewtablegrp
                                if($count gt 1){ print"</table>";}
                                print "<br><b><u>$grpname</u></b>&nbsp; &nbsp;";
                                print " <b>$Lang::tr{'remark'}:</b>&nbsp $remark &nbsp " if ($remark ne '');
-                               print "<b>$Lang::tr{'used'}:</b> $customgrp{$key}[4]x";
-                               if($customgrp{$key}[4] == '0')
+                               my $netgrpcount=&getnetcount($grpname);
+                               print "<b>$Lang::tr{'used'}:</b> $netgrpcount x";
+                               if($netgrpcount == '0')
                                {
                                        print"<form method='post' style='display:inline'><input type='image' src='/images/delete.gif' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} align='right' /><input type='hidden' name='grp_name' value='$grpname' ><input type='hidden' name='ACTION' value='delgrp'></form>";
                                }
@@ -1667,7 +1647,7 @@ sub viewtablegrp
                                $ip="$colip/".&General::subtocidr($colsub) if ($colsub);
                                print"<td align='center' ".&getcolor($colip).">".&Header::colorize($ip)."</td><td align='center'>$customgrp{$key}[3]</td><td width='1%'><form method='post'>";
                        }
-                       if ($delflag > '1' && $ip ne ''){
+                       if ($delflag > 1 && $ip ne ''){
                                print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
                        }
                        print"<input type='hidden' name='ACTION' value='deletegrphost'><input type='hidden' name='grpcnt' value='$customgrp{$key}[4]'><input type='hidden' name='update' value='$fwhostsettings{'update'}'><input type='hidden' name='delhost' value='$grpname,$remark,$customgrp{$key}[2],$customgrp{$key}[3]'></form></td></tr>";
@@ -1684,10 +1664,15 @@ sub viewtablegrp
 sub viewtableservice
 {
        my $count=0;
+       my $srvcount;
        if(! -z "$configsrv")
        {
                &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'});
                &General::readhasharray("$configsrv", \%customservice);
+               &General::readhasharray("$configsrvgrp", \%customservicegrp);
+               &General::readhasharray("$fwconfigfwd", \%fwfwd);
+               &General::readhasharray("$fwconfiginp", \%fwinp);
+               &General::readhasharray("$fwconfigout", \%fwout);
                print<<END;
                        <table width='100%' border='0' cellspacing='0'>
                        <tr><td align='center'><b>$Lang::tr{'fwhost srv_name'}</b></td><td align='center'><b>$Lang::tr{'fwhost prot'}</b></td><td align='center'><b>$Lang::tr{'fwhost port'}</b></td><td align='center'><b>ICMP</b></td><td align='center'><b>$Lang::tr{'fwhost used'}</b></td><td></td><td width='3%'></td></tr>
@@ -1701,17 +1686,19 @@ END
                        print<<END;
                        <td>$customservice{$key}[0]</td><td align='center'>$customservice{$key}[2]</td><td align='center'>$customservice{$key}[1]</td><td align='center'>
 END
-                       if($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
-               
+                       #Neuer count
+                       $srvcount=&getsrvcount($customservice{$key}[0]);
+                       if($customservice{$key}[3] eq 'All ICMP-Types'){print $Lang::tr{'fwdfw all icmp'};}
+                       elsif($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
                        print<<END;
-                       </td><td align='center'>$customservice{$key}[4]x</td>
+                       </td><td align='center'>$srvcount x</td>
                        <td width='1%'><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} /><input type='hidden' name='ACTION' value='editservice' />
                        <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' />
                        <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' />
                        <input type='hidden' name='PROT' value='$customservice{$key}[2]' />
                        <input type='hidden' name='ICMP' value='$customservice{$key}[3]' /></form></td>
 END
-                       if ($customservice{$key}[4] eq '0')
+                       if ($srvcount eq '0')
                        {
                                print"<td width='1%'><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} /><input type='hidden' name='ACTION' value='delservice' /><input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]'></td></tr></form>";
                        }else{
@@ -1731,14 +1718,20 @@ sub viewtableservicegrp
        my $port;
        my $protocol;
        my $delflag;
+       my $grpcount=0;
        if (! -z $configsrvgrp){
                &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'});
                &General::readhasharray("$configsrvgrp", \%customservicegrp);
                &General::readhasharray("$configsrv", \%customservice);
+               &General::readhasharray("$fwconfigfwd", \%fwfwd);
+               &General::readhasharray("$fwconfiginp", \%fwinp);
+               &General::readhasharray("$fwconfigout", \%fwout);
                my $number= keys %customservicegrp;
-               foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
+               foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){
                        $count++;
                        if ($helper ne $customservicegrp{$key}[0]){
+                               #Get used groupcounter
+                               $grpcount=&getsrvcount($customservicegrp{$key}[0]);
                                $delflag=0;
                                foreach my $key1 (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) } keys %customservicegrp){
                                        if ($customservicegrp{$key}[0] eq $customservicegrp{$key1}[0])
@@ -1759,8 +1752,8 @@ sub viewtableservicegrp
                                if($count >=2){print"</table>";}
                                print "<br><b><u>$grpname</u></b>&nbsp; &nbsp; ";
                                print "<b>$Lang::tr{'remark'}:</b>&nbsp; $remark " if ($remark ne '');
-                               print "&nbsp; <b>$Lang::tr{'used'}:</b> $customservicegrp{$key}[3]x";
-                               if($customservicegrp{$key}[3] == '0')
+                               print "&nbsp; <b>$Lang::tr{'used'}:</b> $grpcount x";
+                               if($grpcount == '0')
                                {
                                        print"<form method='post' style='display:inline'><input type='image' src='/images/delete.gif' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} align='right' /><input type='hidden' name='SRVGRP_NAME' value='$grpname' ><input type='hidden' name='ACTION' value='delservicegrp'></form>";
                                }
@@ -1774,6 +1767,16 @@ sub viewtableservicegrp
                        }else{
                                print"<tr bgcolor='$color{'color20'}'>";
                        }
+                       #Set fields if we use protocols in servicegroups
+                       if ($customservicegrp{$key}[2] ne 'TCP' || $customservicegrp{$key}[2] ne 'UDP' || $customservicegrp{$key}[2] ne 'ICMP'){
+                               $port='-';
+                       }
+                       if ($customservicegrp{$key}[2] eq 'GRE'){$protocol='GRE';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} GRE";}
+                       if ($customservicegrp{$key}[2] eq 'ESP'){$protocol='ESP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} ESP";}
+                       if ($customservicegrp{$key}[2] eq 'AH'){$protocol='AH';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} AH";}
+                       if ($customservicegrp{$key}[2] eq 'IGMP'){$protocol='IGMP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IGMP";}
+                       if ($customservicegrp{$key}[2] eq 'IPIP'){$protocol='IPIP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPIP";}
+                       if ($customservicegrp{$key}[2] eq 'IPV6'){$protocol='IPV6';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPv6 encapsulation";}
                        print "<td width='39%'>$customservicegrp{$key}[2]</td>";
                        foreach my $srv (sort keys %customservice){
                                if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){
@@ -1786,7 +1789,12 @@ sub viewtableservicegrp
                        if ($delflag gt '1'){
                                print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
                        }
-                       print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'><input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2],$customservicegrp{$key}[3]'></form></td></tr>";
+                       print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'>";
+                       if($protocol eq 'TCP' || $protocol eq 'UDP' || $protocol eq 'ICMP'){
+                               print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2]'></form></td></tr>";
+                       }else{
+                               print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$protocol'></form></td></tr>";
+                       }
                        $helper=$customservicegrp{$key}[0];
                }
                print"</table>";
@@ -1807,10 +1815,21 @@ sub checkname
 }
 sub checkgroup
 {
-       my %hash=%{(shift)};
+       &General::readhasharray("$configsrvgrp", \%customservicegrp );
        my $name=shift;
-       foreach my $key (keys %hash) {
-               if($hash{$key}[0] eq $name){
+       foreach my $key (keys %customservicegrp) {
+               if($customservicegrp{$key}[0] eq $name){
+                       return 0;
+               }
+       }
+       return 1;
+}
+sub checkservice
+{
+       &General::readhasharray("$configsrv", \%customservice );
+       my $name=shift;
+       foreach my $key (keys %customservice) {
+               if($customservice{$key}[0] eq $name){
                        return 0;
                }
        }
@@ -1843,8 +1862,6 @@ sub checksubnet
 sub checkservicegroup
 {
        &General::readhasharray("$configsrvgrp", \%customservicegrp);
-       
-       
        #check name
        if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'}))
        {
@@ -1900,7 +1917,114 @@ sub get_name
                return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
        }       
 }
-
+sub gethostcount
+{
+       my $searchstring=shift;
+       my $srvcounter=0;
+       #Count services used in servicegroups
+       foreach my $key (keys %customgrp) {
+               if($customgrp{$key}[2] eq $searchstring){
+                       $srvcounter++;
+               }
+       }
+       #Count services used in firewall - config
+       foreach my $key1 (keys %fwfwd) {
+               if($fwfwd{$key1}[4] eq $searchstring){
+                       $srvcounter++;
+               }
+               if($fwfwd{$key1}[6] eq $searchstring){
+                       $srvcounter++;
+               }
+       }
+       #Count services used in firewall - input
+       foreach my $key2 (keys %fwinp) {
+               if($fwinp{$key2}[4] eq $searchstring){
+                       $srvcounter++;
+               }
+               if($fwinp{$key2}[6] eq $searchstring){
+                       $srvcounter++;
+               }
+       }
+       #Count services used in firewall - outgoing
+       foreach my $key3 (keys %fwout) {
+               if($fwout{$key3}[4] eq $searchstring){
+                       $srvcounter++;
+               }
+               if($fwout{$key3}[6] eq $searchstring){
+                       $srvcounter++;
+               }
+       }
+       return $srvcounter;
+}
+sub getnetcount
+{
+       my $searchstring=shift;
+       my $srvcounter=0;
+       #Count services used in servicegroups
+       foreach my $key (keys %customgrp) {
+               if($customgrp{$key}[2] eq $searchstring){
+                       $srvcounter++;
+               }
+       }
+       #Count services used in firewall - config
+       foreach my $key1 (keys %fwfwd) {
+               if($fwfwd{$key1}[4] eq $searchstring){
+                       $srvcounter++;
+               }
+               if($fwfwd{$key1}[6] eq $searchstring){
+                       $srvcounter++;
+               }
+       }
+       #Count services used in firewall - input
+       foreach my $key2 (keys %fwinp) {
+               if($fwinp{$key2}[4] eq $searchstring){
+                       $srvcounter++;
+               }
+               if($fwinp{$key2}[6] eq $searchstring){
+                       $srvcounter++;
+               }
+       }
+       #Count services used in firewall - outgoing
+       foreach my $key3 (keys %fwout) {
+               if($fwout{$key3}[4] eq $searchstring){
+                       $srvcounter++;
+               }
+               if($fwout{$key3}[6] eq $searchstring){
+                       $srvcounter++;
+               }
+       }
+       return $srvcounter;
+}
+sub getsrvcount
+{
+       my $searchstring=shift;
+       my $srvcounter=0;
+       #Count services used in servicegroups
+       foreach my $key (keys %customservicegrp) {
+               if($customservicegrp{$key}[2] eq $searchstring){
+                       $srvcounter++;
+               }
+       }
+       #Count services used in firewall - config
+       foreach my $key1 (keys %fwfwd) {
+               if($fwfwd{$key1}[15] eq $searchstring){
+                       $srvcounter++;
+               }
+       }
+       #Count services used in firewall - input
+       foreach my $key2 (keys %fwinp) {
+               if($fwinp{$key2}[15] eq $searchstring){
+                       $srvcounter++;
+               }
+       }
+       #Count services used in firewall - outgoing
+       foreach my $key3 (keys %fwout) {
+               if($fwout{$key3}[15] eq $searchstring){
+                       $srvcounter++;
+               }
+       }
+       return $srvcounter;
+}
 sub deletefromgrp
 {
        my $target=shift;
@@ -1908,11 +2032,8 @@ sub deletefromgrp
        my %hash=();
        &General::readhasharray("$config",\%hash);
        foreach my $key (keys %hash) {
-               $errormessage.="lese $hash{$key}[2] und $target<br>";
                if($hash{$key}[2] eq $target){
-                       
                        delete $hash{$key};
-                       $errormessage.="Habe $target aus Gruppe gelöscht!<br>";
                }
        }
        &General::writehasharray("$config",\%hash);
@@ -2116,22 +2237,6 @@ sub getipforgroup
                }
        }
 }
-sub rules
-{
-       if (!-f "${General::swroot}/fwhosts/reread"){
-               system("touch ${General::swroot}/fwhosts/reread");
-               system("touch ${General::swroot}/forward/reread");
-       }
-}
-sub reread_rules
-{
-       system ("/usr/local/bin/forwardfwctrl");
-       if ( -f "${General::swroot}/fwhosts/reread"){
-               system("rm ${General::swroot}/fwhosts/reread");
-               system("rm ${General::swroot}/forward/reread");
-       }
-       
-}
 sub decrease
 {
        my $grp=$_[0];