]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - html/cgi-bin/fwhosts.cgi
firewall: Fix colouring when IPsec VPN subnets are denoted in CIDR.
[people/teissler/ipfire-2.x.git] / html / cgi-bin / fwhosts.cgi
index 7f4b63c9043ccf689525e2cd9d5827ecf6154a35..3e59a9d9dbf6d4161d14990a0b76c70f5342b23e 100755 (executable)
@@ -46,6 +46,7 @@ my %ownnet=();
 my %ipsecsettings=();
 my %fwfwd=();
 my %fwinp=();
+my %fwout=();
 my %ovpnsettings=();
 
 
@@ -62,6 +63,7 @@ my $configsrv         = "${General::swroot}/fwhosts/customservices";
 my $configsrvgrp       = "${General::swroot}/fwhosts/customservicegrp";
 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";
@@ -109,6 +111,12 @@ print<<END;
                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");
+                       \$('#' + id).prop("checked", true);
+               });
        });
 </script>
 END
@@ -166,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;
@@ -194,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'}){
@@ -216,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){
@@ -240,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'};
@@ -247,7 +266,6 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice')
                $fwhostsettings{'ICMP'}         = $fwhostsettings{'oldsrvicmp'};
                $fwhostsettings{'updatesrv'}= 'on';
        }
-       $fwhostsettings{'updatesrv'} = '';
        if($needrules eq 'on'){
                &General::firewall_config_changed();
        }
@@ -256,7 +274,6 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice')
 # 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
@@ -330,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;
                }                       
@@ -341,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;
                                                }
@@ -351,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'}){
@@ -391,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
@@ -399,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;
@@ -423,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';
@@ -471,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'){
@@ -480,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'}){
@@ -525,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'){
@@ -536,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'}='';
@@ -559,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;
@@ -569,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'};
@@ -673,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");
@@ -691,36 +690,21 @@ 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 )
                {
                        &General::firewall_config_changed();
                }
@@ -731,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);
@@ -741,7 +726,11 @@ if ($fwhostsettings{'ACTION'} eq 'saveservice')
                }
        }
        if($ICMP eq ''){$ICMP=$fwhostsettings{'ICMP_TYPES'};}
-       if ($fwhostsettings{'PROT'} ne 'ICMP'){$ICMP='';}
+       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] = "";}
@@ -749,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'}='';
@@ -793,6 +781,10 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
        if ($fwhostsettings{'SRVGRP_REMARK'} ne '' && !&validremark($fwhostsettings{'SRVGRP_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
                if ($fwhostsettings{'CUST_SRV'} eq ''){
@@ -815,34 +807,14 @@ 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';
        }
@@ -993,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;
@@ -1027,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){
@@ -1129,6 +1100,52 @@ if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark')
        &addservicegrp;
        &viewtableservicegrp;
 }
+if ($fwhostsettings{'ACTION'} eq 'changesrvgrpname')
+{
+       &General::readhasharray("$configsrvgrp", \%customservicegrp );
+       if ($fwhostsettings{'oldsrvgrpname'} ne $fwhostsettings{'srvgrp'}){
+               #Check new groupname
+               if (!&validhostname($fwhostsettings{'srvgrp'})){
+                       $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
+               }
+               if (!$errormessage){
+                       #Rename group in customservicegroup
+                       foreach my $key (keys %customservicegrp) {
+                               if($customservicegrp{$key}[0] eq $fwhostsettings{'oldsrvgrpname'}){
+                                       $customservicegrp{$key}[0]=$fwhostsettings{'srvgrp'};
+                               }
+                       }
+                       &General::writehasharray("$configsrvgrp", \%customservicegrp );
+                       #change name in FW Rules
+                       &changenameinfw($fwhostsettings{'oldsrvgrpname'},$fwhostsettings{'srvgrp'},15);
+               }
+       }
+       &addservicegrp;
+       &viewtableservicegrp;
+}
+if ($fwhostsettings{'ACTION'} eq 'changegrpname')
+{
+       &General::readhasharray("$configgrp", \%customgrp );
+       if ($fwhostsettings{'oldgrpname'} ne $fwhostsettings{'grp'}){
+               #Check new groupname
+               if (!&validhostname($fwhostsettings{'grp'})){
+                       $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
+               }
+               if (!$errormessage){
+                       #Rename group in customservicegroup
+                       foreach my $key (keys %customgrp) {
+                               if($customgrp{$key}[0] eq $fwhostsettings{'oldgrpname'}){
+                                       $customgrp{$key}[0]=$fwhostsettings{'grp'};
+                               }
+                       }
+                       &General::writehasharray("$configgrp", \%customgrp );
+                       #change name in FW Rules
+                       &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},6);
+               }
+       }
+       &addgrp;
+       &viewtablegrp;
+}
 ###  VIEW  ###
 if($fwhostsettings{'ACTION'} eq '')
 {
@@ -1216,6 +1233,7 @@ sub addgrp
        $checked{'check1'}{'on'} = '';
        $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED';
        $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'};
+       $fwhostsettings{'oldgrpname'}=$fwhostsettings{'grp_name'};
        my $grp=$fwhostsettings{'grp_name'};
        my $rem=$fwhostsettings{'remark'};
                if ($fwhostsettings{'update'} eq ''){   
@@ -1228,8 +1246,8 @@ END
                }else{
                        print<<END;
                        <table width='100%' border='0'><form method='post' style='display:inline'>
-                       <tr><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='TEXT' name='grp'  value='$fwhostsettings{'grp_name'}' readonly ></td><td></td></tr>
-                       <tr><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='newrem' size='45' value='$fwhostsettings{'remark'}' style='width:98%'></td><td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='ACTION' value='changegrpremark' ></td></tr></table></form>
+                       <tr><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost addgrpname'}</td><td width='20%'><input type='TEXT' name='grp'  value='$fwhostsettings{'grp_name'}' ></td><td><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldgrpname' value='$fwhostsettings{'oldgrpname'}'><input type='hidden' name='ACTION' value='changegrpname'></td><td></td></form></tr>
+                       <tr><form method='post' style='display:inline'><td>$Lang::tr{'remark'}:</td><td colspan='2'><input type='TEXT' name='newrem' size='45' value='$fwhostsettings{'remark'}' style='width:98%'></td><td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='ACTION' value='changegrpremark' ></td></tr></table></form>
                        <hr>
 END
                }
@@ -1393,6 +1411,7 @@ sub addservicegrp
        &showmenu;
        &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservicegrp'});
        $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'};
+       $fwhostsettings{'oldsrvgrpname'}=$fwhostsettings{'SRVGRP_NAME'};
        if ($fwhostsettings{'updatesrvgrp'} eq ''){
                print<<END;
                <table width='100%' border='0'><form method='post'>
@@ -1404,9 +1423,9 @@ END
        }else{
                print<<END;
                <table width='100%' border='0'><form method='post' style='display:inline'>
-               <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='text' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}' readonly  size='14'></td><td width='3%'></td></tr>
-               <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='text' name='newsrvrem'  value='$fwhostsettings{'SRVGRP_REMARK'}' style='width:98%;'></td><td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldsrvrem' value='$fwhostsettings{'oldsrvgrpremark'}'><input type='hidden' name='ACTION' value='changesrvgrpremark' ></td></tr>
-               <tr><td colspan='3'><br><hr></td></td></tr>
+               <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td width='20%'><input type='text' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}' size='14'></td><td align='left'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldsrvgrpname' value='$fwhostsettings{'oldsrvgrpname'}'><input type='hidden' name='ACTION' value='changesrvgrpname'></td><td width='3%'></td></form></tr>
+               <tr><form method='post'><td width='10%'>$Lang::tr{'remark'}:</td><td colspan='2'><input type='text' name='newsrvrem'  value='$fwhostsettings{'SRVGRP_REMARK'}' style='width:98%;'></td><td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldsrvrem' value='$fwhostsettings{'oldsrvgrpremark'}'><input type='hidden' name='ACTION' value='changesrvgrpremark' ></td></tr>
+               <tr><td colspan='4'><br><hr></td></td></tr>
                </table></form>
 END
        }
@@ -1451,6 +1470,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>"; 
@@ -1472,7 +1495,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'>
@@ -1482,7 +1506,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{
@@ -1550,6 +1574,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>"; 
@@ -1567,7 +1595,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' />
@@ -1577,7 +1607,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{
@@ -1599,6 +1629,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;
@@ -1607,7 +1640,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){
@@ -1630,8 +1663,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>";
                                }
@@ -1661,7 +1695,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>";
@@ -1678,10 +1712,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>
@@ -1695,17 +1734,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
+                       #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{
@@ -1725,14 +1766,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]) } 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])
@@ -1753,8 +1800,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>";
                                }
@@ -1792,9 +1839,9 @@ sub viewtableservicegrp
                        }
                        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],$customservicegrp{$key}[3]'></form></td></tr>";
+                               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,$customservicegrp{$key}[3]'></form></td></tr>";
+                               print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$protocol'></form></td></tr>";
                        }
                        $helper=$customservicegrp{$key}[0];
                }
@@ -1816,10 +1863,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;
                }
        }
@@ -1907,6 +1965,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;
@@ -2165,6 +2331,36 @@ sub decreaseservice
        &General::writehasharray("$configsrv", \%customservice);
        
 }
+sub changenameinfw
+{
+       my $old=shift;
+       my $new=shift;
+       my $fld=shift;
+       &General::readhasharray("$fwconfigfwd", \%fwfwd);
+       &General::readhasharray("$fwconfiginp", \%fwinp);
+       &General::readhasharray("$fwconfigout", \%fwout);
+       #Rename group in Firewall-CONFIG
+       foreach my $key1 (keys %fwfwd) {
+               if($fwfwd{$key1}[$fld] eq $old){
+                       $fwfwd{$key1}[$fld]=$new;
+               }
+       }
+       &General::writehasharray("$fwconfigfwd", \%fwfwd );
+       #Rename group in Firewall-INPUT
+       foreach my $key2 (keys %fwinp) {
+               if($fwinp{$key2}[$fld] eq $old){
+                       $fwinp{$key2}[$fld]=$new;
+               }
+       }
+       &General::writehasharray("$fwconfiginp", \%fwinp );
+       #Rename group in Firewall-OUTGOING
+       foreach my $key3 (keys %fwout) {
+               if($fwout{$key3}[$fld] eq $old){
+                       $fwout{$key3}[$fld]=$new;
+               }
+       }
+       &General::writehasharray("$fwconfigout", \%fwout );
+}
 sub checkports
 {