]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - html/cgi-bin/fwhosts.cgi
Forward Firewall: added "apply" button to groupmanagement. Now the user can make...
[people/teissler/ipfire-2.x.git] / html / cgi-bin / fwhosts.cgi
index 89b2a9321f91d124304c3835dfd13230076f2ee6..636cf65e43b02c7878de1bdb9e585c6c03d60639 100755 (executable)
@@ -80,6 +80,11 @@ unless (-e $configsrvgrp) { system("touch $configsrvgrp"); }
 &Header::openbigbox('100%', 'center');
 
 ## ACTION ####
+if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
+{
+       &reread_rules;
+       &showmenu;
+}
 # Update
 if ($fwhostsettings{'ACTION'} eq 'updatenet' )
 {
@@ -108,7 +113,6 @@ if ($fwhostsettings{'ACTION'} eq 'updatehost')
        {
                if($customhost{$key}[0] eq $fwhostsettings{'orgname'})
                {
-                       $fwhostsettings{'orgname'} = $customhost{$key}[0];
                        if ($customhost{$key}[1] eq 'ip'){
                                ($ip,$subnet) = split (/\//,$customhost{$key}[2]);
                        }else{
@@ -117,21 +121,21 @@ if ($fwhostsettings{'ACTION'} eq 'updatehost')
                        $fwhostsettings{'orgip'} = $ip;
                        $fwhostsettings{'count'} = $customhost{$key}[3];
                        delete $customhost{$key};
+                       &General::writehasharray("$confighost", \%customhost);
                }
        }
-       &General::writehasharray("$confighost", \%customhost);
-       
-       
-       
        $fwhostsettings{'actualize'} = 'on';
+       if($fwhostsettings{'orgip'}){
        $fwhostsettings{'ACTION'} = 'savehost';
+       }else{
+               $fwhostsettings{'ACTION'} = $Lang::tr{'fwhost newhost'};
+       }
 }
 if ($fwhostsettings{'ACTION'} eq 'updateservice')
 {
        my $count=0;
        my $needrules=0;
        $errormessage=&checkports(\%customservice);
-       
        if (!$errormessage){
                &General::readhasharray("$configsrv", \%customservice);
                foreach my $key (keys %customservice)
@@ -155,30 +159,54 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice')
                $customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'};
                $customservice{$key1}[4] = $count;
                &General::writehasharray("$configsrv", \%customservice);
-               if($fwhostsettings{'updatesrv'} eq 'on'){
-                       if($count gt 0 && $fwhostsettings{'oldsrvport'} ne $fwhostsettings{'SRV_PORT'} ){
-                               $needrules='on';
+               #check if we need to update firewallrules
+               if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){
+                       if ( ! -z $fwconfigfwd ){
+                               &General::readhasharray("$fwconfigfwd", \%fwfwd);
+                               foreach my $key (sort keys %fwfwd){
+                                       if ($fwfwd{$key}[15] eq $fwhostsettings{'oldsrvname'}){
+                                               $fwfwd{$key}[15] = $fwhostsettings{'SRV_NAME'};
+                                       }
+                               }
+                               &General::writehasharray("$fwconfigfwd", \%fwfwd);
                        }
-                       if($count gt 0 && $fwhostsettings{'oldsrvprot'} ne $fwhostsettings{'PROT'} ){
-                               $needrules='on';
+                       if ( ! -z $fwconfiginp ){
+                               &General::readhasharray("$fwconfiginp", \%fwinp);
+                               foreach my $line (sort keys %fwinp){
+                                       if ($fwfwd{$line}[15] eq $fwhostsettings{'oldsrvname'}){
+                                               $fwfwd{$line}[15] = $fwhostsettings{'SRV_NAME'};
+                                       }
+                               }
+                               &General::writehasharray("$fwconfiginp", \%fwinp);
+                       }
+                       #check if we need to update groups
+                       &General::readhasharray("$configsrvgrp", \%customservicegrp);
+                       foreach my $key (sort keys %customservicegrp){
+                               if($customservicegrp{$key}[2] eq $fwhostsettings{'oldsrvname'}){
+                                       $customservicegrp{$key}[2] = $fwhostsettings{'SRV_NAME'};
+                               }
                        }
+                       &General::writehasharray("$configsrvgrp", \%customservicegrp);
+                       $needrules='on';
+               }
+               if($count gt 0 && $fwhostsettings{'oldsrvport'} ne $fwhostsettings{'SRV_PORT'} ){
+                       $needrules='on';
+               }
+               if($count gt 0 && $fwhostsettings{'oldsrvprot'} ne $fwhostsettings{'PROT'} ){
+                       $needrules='on';
                }
                $fwhostsettings{'SRV_NAME'}     = '';
                $fwhostsettings{'SRV_PORT'}     = '';
                $fwhostsettings{'PROT'}         = '';
-               
        }else{
                $fwhostsettings{'SRV_NAME'}     = $fwhostsettings{'oldsrvname'};
                $fwhostsettings{'SRV_PORT'}     = $fwhostsettings{'oldsrvport'};
                $fwhostsettings{'PROT'}         = $fwhostsettings{'oldsrvprot'};
                $fwhostsettings{'updatesrv'}= 'on';
        }
-       
        if($needrules eq 'on'){
-               $errormessage="reread!";
                &rules;
        }
-       
        &addservice;
 }
 # save
@@ -187,7 +215,6 @@ 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
        if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
        {
@@ -207,7 +234,6 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                if(&General::iporsubtocidr($fwhostsettings{'SUBNET'}) eq '32')
                {
                        $errormessage=$errormessage.$Lang::tr{'fwhost err sub32'};
-                       
                }
                if($fwhostsettings{'error'} ne 'on'){
                        #check if we use one of ipfire's networks (green,orange,blue)
@@ -240,14 +266,12 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                if (!$errormessage){
                        &plausicheck("editnet");
                }
-               
                #check if network ip is part of an already used one 
                if(&checksubnet(\%customnetwork))
                {
                        $errormessage=$errormessage.$Lang::tr{'fwhost err partofnet'};
                        $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
                }                               
-               
                if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage)
                {
                        $fwhostsettings{'actualize'} = '';
@@ -260,7 +284,6 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                        &General::writehasharray("$confignet", \%customnetwork);
                        undef %customnetwork;
                }                       
-                                               
                if (!$errormessage){
                        &General::readhasharray("$confignet", \%customnetwork);
                        if ($fwhostsettings{'ACTION'} eq 'updatenet'){
@@ -345,23 +368,19 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                        &viewtablenet;
                }
        }
-       
 }
 if ($fwhostsettings{'ACTION'} eq 'savehost')
 {
        my $count=0;
        my $needrules=0;
        if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
-       
        $fwhostsettings{'SUBNET'}='32';
-               
        #check if all fields are set
        if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
        {
                $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
                $fwhostsettings{'ACTION'} = 'edithost';
        }else{
-       
                if($fwhostsettings{'type'} eq 'ip' && $fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){
                        $fwhostsettings{'type'} = 'mac';
                }elsif($fwhostsettings{'type'} eq 'mac' && $fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
@@ -374,13 +393,11 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                        $fwhostsettings{'type'} = '';
                        $errormessage=$Lang::tr{'fwhost err ipmac'};
                }
-               
                if($fwhostsettings{'type'} eq 'mac' )
                {
                        if ($fwhostsettings{'IP'}!~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/ )
                        {
                                $errormessage=$Lang::tr{'fwhost err mac'};
-                               
                        }
                }
                #CHECK IP-PART
@@ -392,7 +409,6 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                                                $errormessage.=$errormessage.$Lang::tr{'fwhost err ip'};
                                                $fwhostsettings{'error'}='on';
                                        }
-                               
                        }elsif(rindex($fwhostsettings{'IP'},'/') ne '-1' ){
                                $errormessage=$errormessage.$Lang::tr{'fwhost err ipwithsub'};
                                $fwhostsettings{'error'}='on';
@@ -403,14 +419,10 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                                $errormessage=$Lang::tr{'fwhost err hostip'};
                        }
                }
-                       
-               
-               
                #only check plausi when no error till now
                if (!$errormessage){    
                        &plausicheck("edithost");
                }
-                               
                if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){
                        $fwhostsettings{'actualize'} = '';
                        my $key = &General::findhasharraykey (\%customhost);
@@ -425,9 +437,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                        $customhost{$key}[3] = $fwhostsettings{'count'};
                        &General::writehasharray("$confighost", \%customhost);
                        undef %customhost;
-                               
                } 
-               
                if (!$errormessage){
                        #get count if host was edited
                        if($fwhostsettings{'actualize'} eq 'on'){
@@ -484,8 +494,6 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                        if($fwhostsettings{'newhost'} eq 'on'){$count=0;}
                        $customhost{$key}[3] = $count;
                        &General::writehasharray("$confighost", \%customhost);
-                       
-                       #$fwhostsettings{'IP'} = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
                        undef %customhost;
                        $fwhostsettings{'HOSTNAME'}='';
                        $fwhostsettings{'IP'}='';
@@ -500,9 +508,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                        &addhost;
                        &viewtablehost;
                }
-       
        }
-
 }
 if ($fwhostsettings{'ACTION'} eq 'savegrp')
 {
@@ -517,9 +523,7 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
        &General::readhasharray("$confignet", \%customnetwork);
        &General::readhasharray("$confighost", \%customhost);
        $grp=$fwhostsettings{'grp_name'};
-       
-       if (!&General::validhostname($grp)){$errormessage=$errormessage.$Lang::tr{'fwhost err name'};}
-       
+       if (!&validhostname($grp)){$errormessage=$errormessage.$Lang::tr{'fwhost err name'};}
        ###check standard networks
        if ($fwhostsettings{'grp2'} eq 'std_net'){
                @target=$fwhostsettings{'DEFAULT_SRC_ADR'};
@@ -570,7 +574,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
                $fwhostsettings{'grp_name'}='';
                $fwhostsettings{'remark'}='';
        }
-       
        #get address from IPSEC HOST
        if ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} ne ''){
                @target=$fwhostsettings{'IPSEC_HOST'};
@@ -589,7 +592,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
                $fwhostsettings{'grp_name'}='';
                $fwhostsettings{'remark'}='';
        }
-       
        #check if host/net exists in grp
        my $test="$grp,$fwhostsettings{'oldremark'},@target";
        foreach my $key (keys %customgrp) {
@@ -599,7 +601,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
                        $fwhostsettings{'update'} = 'on';
                }
        }
-               
        if (!$errormessage){
                #on first save, we have an empty @target, so fill it with nothing
                my $targetvalues=@target;
@@ -607,7 +608,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
                        @target=$Lang::tr{'fwhost empty'};
                }
                #on update, we have to delete the dummy entry
-               
                foreach my $key (keys %customgrp){
                        if ($customgrp{$key}[0] eq $grp && $customgrp{$key}[2] eq $Lang::tr{'fwhost empty'}){
                                delete $customgrp{$key};
@@ -616,21 +616,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
                }
                &General::writehasharray("$configgrp", \%customgrp);
                &General::readhasharray("$configgrp", \%customgrp);
-               
-               
-               
-               #check if remark has also changed
-               if ($fwhostsettings{'remark'} ne $fwhostsettings{'oldremark'} && $fwhostsettings{'update'} eq 'on')
-               {
-                       foreach my $key (keys %customgrp)
-                       {
-                               if($customgrp{$key}[0] eq $grp && $customgrp{$key}[1] eq $fwhostsettings{'oldremark'})
-                               {
-                                       $customgrp{$key}[1]='';
-                                       $customgrp{$key}[1]=$rem;
-                               }       
-                       }
-               }
                #get count used
                foreach my $key (keys %customgrp)
                {
@@ -658,7 +643,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
                        $customgrp{$key}[4] = $count;
                }
                &General::writehasharray("$configgrp", \%customgrp);
-               
                #update counter in Host/Net
                if($updcounter eq 'net'){
                        foreach my $key (keys %customnetwork) {
@@ -676,13 +660,11 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
                        }
                        &General::writehasharray("$confighost", \%customhost);
                }
-               
                $fwhostsettings{'update'}='on';
-               
        }
-               if ($fwhostsettings{'remark'} ne $fwhostsettings{'oldremark'} && $errormessage)
+               if ($fwhostsettings{'remark'} ne $fwhostsettings{'oldremark'} )
                {
-                       foreach my $key (keys %customgrp)
+                       foreach my $key (sort keys %customgrp)
                        {
                                if($customgrp{$key}[0] eq $grp && $customgrp{$key}[1] eq $fwhostsettings{'oldremark'})
                                {
@@ -690,9 +672,8 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
                                        $customgrp{$key}[1]=$rem;
                                }       
                        }
-                       &General::writehasharray("$configsrvgrp", \%customservicegrp);
+                       &General::writehasharray("$configgrp", \%customgrp);
                        $errormessage='';
-                       $hint=$Lang::tr{'fwhost changeremark'};
                        $fwhostsettings{'update'}='on';
                }
                #check if ruleupdate is needed
@@ -702,15 +683,12 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
                }
                &addgrp;
                &viewtablegrp;
-       
 }
 if ($fwhostsettings{'ACTION'} eq 'saveservice')
 {
        my $ICMP;
-       
        &General::readhasharray("$configsrv", \%customservice );
        $errormessage=&checkports(\%customservice);
-       
        if ($fwhostsettings{'PROT'} eq 'ICMP'){
                &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
                foreach my $key (keys %icmptypes){
@@ -721,7 +699,6 @@ if ($fwhostsettings{'ACTION'} eq 'saveservice')
        }
        if($ICMP eq ''){$ICMP='BLANK';}
        if (!$errormessage){
-               
                my $key = &General::findhasharraykey (\%customservice);
                foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";}
                $customservice{$key}[0] = $fwhostsettings{'SRV_NAME'};
@@ -735,11 +712,8 @@ if ($fwhostsettings{'ACTION'} eq 'saveservice')
                $fwhostsettings{'SRV_PORT'}='';
                $fwhostsettings{'PROT'}='';
                $fwhostsettings{'ICMP_TYPES'}='';
-               
        }
-       
        &addservice;
-       
 }
 if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
 {
@@ -748,13 +722,10 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
        my $count=0;
        &General::readhasharray("$configsrvgrp", \%customservicegrp );
        &General::readhasharray("$configsrv", \%customservice );
-       
        $errormessage=&checkservicegroup;
-       
        if (!$errormessage){
                #on first save, we have to enter a dummy value
                if ($fwhostsettings{'CUST_SRV'} eq ''){$fwhostsettings{'CUST_SRV'}=$Lang::tr{'fwhost empty'};}
-               
                #on update, we have to delete the dummy entry
                foreach my $key (keys %customservicegrp){
                        if ($customservicegrp{$key}[2] eq $Lang::tr{'fwhost empty'}){
@@ -780,7 +751,7 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
                {
                        if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
                        {
-                               $count=$customservicegrp{$key}[5];
+                               $count=$customservicegrp{$key}[3];
                                last;
                        }
                }
@@ -794,15 +765,12 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
                        }
                }
                &General::writehasharray("$configsrv", \%customservice );
-               
                my $key = &General::findhasharraykey (\%customservicegrp);
                foreach my $i (0 .. 3) { $customservice{$key}[$i] = "";}
                $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'};
                $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'};
                $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'};
-               $customservicegrp{$key}[3] = $port;
-               $customservicegrp{$key}[4] = $prot;
-               $customservicegrp{$key}[5] = $count;
+               $customservicegrp{$key}[3] = $count;
                &General::writehasharray("$configsrvgrp", \%customservicegrp );
                $fwhostsettings{'updatesrvgrp'}='on';
        }
@@ -895,7 +863,6 @@ if ($fwhostsettings{'ACTION'} eq 'delhost')
        }
        &addhost;
        &viewtablehost;
-       
 }
 if ($fwhostsettings{'ACTION'} eq 'deletegrphost')
 {
@@ -1041,9 +1008,15 @@ sub showmenu
        <table border='0' width='100%'><form method='post'>
        <tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newnet'}' /><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newhost'}' /><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newgrp'}' /></td>
        <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newservice'}' /><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newservicegrp'}' /></td></tr>
-       <tr><td colspan='6'><hr></hr></td></tr></table></form>
+       <tr><td colspan='6'><hr></hr></td>
 END
        
+               
+       if (-f "${General::swroot}/fwhosts/reread"){
+               print "</tr><tr><td colspan='6'><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}'>$Lang::tr{'fwhost reread'}</td>";
+       }
+               print"</tr></table></form>";    
+
        &Header::closebox();
        
 }
@@ -1313,7 +1286,7 @@ END
        <tr><td width='1%' nowrap='nowrap'>$Lang::tr{'fwhost cust service'}</td><td><select name='CUST_SRV' style='min-width:185px;'>
 END
        &General::readhasharray("$configsrv", \%customservice);
-       foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) }  keys %customservice)
+       foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0])||  $a <=> $b } keys %customservice)
        {
                print "<option>$customservice{$key}[0]</option>";
        }
@@ -1359,7 +1332,7 @@ END
                                print" <tr bgcolor='$color{'color20'}'>";
                        }
                        print<<END;
-                       <td width='40%'><form method='post'>$customnetwork{$key}[0]</td><td width=25%'>$customnetwork{$key}[1]</td><td width='25%'>$customnetwork{$key}[2]</td><td align='center'>$customnetwork{$key}[3] x</td>
+                       <td width='40%'><form method='post'>$customnetwork{$key}[0]</td><td width=25%'>$customnetwork{$key}[1]</td><td width='25%'>$customnetwork{$key}[2]</td><td align='center'>$customnetwork{$key}[3]x</td>
                        <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'>
                        <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' />
@@ -1395,14 +1368,15 @@ sub viewtablehost
 END
        }
                my $count=0;
-               foreach my $key (sort {$a <=> $b} keys %customhost) {
+               foreach my $key (sort { uc($customhost{$a}[0]) cmp uc($customhost{$b}[0])||  $a <=> $b } keys %customhost) {
                        if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) {
                                print" <tr bgcolor='${Header::colouryellow}'>";
                        }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";}
                        else{            print" <tr bgcolor='$color{'color20'}'>";}
                        my ($ip,$sub)=split(/\//,$customhost{$key}[2]);
+                       $customhost{$key}[3]=~s/\s+//g;
                        print<<END;
-                       <td width='40%'><form method='post'>$customhost{$key}[0]</td><td width='50%'>$customhost{$key}[2]</td><td align='center'>$customhost{$key}[3] x</td>
+                       <td width='40%'><form method='post'>$customhost{$key}[0]</td><td width='50%'>$ip</td><td align='center'>$customhost{$key}[3]x</td>
                        <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='edithost' />
                        <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' />
@@ -1434,24 +1408,24 @@ sub viewtablegrp
        &General::readhasharray("$confignet", \%customnetwork);
        my @grp=();
        my $helper='';
-       my $count=0;
+       my $count=1;
        my $grpname;
        my $remark;
-       my $number=keys %customgrp;
+       my $number;
        if (!keys %customgrp) 
        { 
                print "<center><b>$Lang::tr{'fwhost empty'}</b>"; 
        }else{
-               foreach my $key (sort {$a <=> $b} keys %customgrp){
-                       
+               foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } sort { uc($customgrp{$a}[2]) cmp uc($customgrp{$b}[2]) } keys %customgrp){
                        $count++;
                        if ($helper ne $customgrp{$key}[0]){
+                               $number=1;
                                $grpname=$customgrp{$key}[0];
                                $remark=$customgrp{$key}[1];
                                if($count >=2){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";
+                               print "<b>$Lang::tr{'used'}:</b> $customgrp{$key}[4]x";
                                if($customgrp{$key}[4] == '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>";
@@ -1477,12 +1451,13 @@ sub viewtablegrp
                        }else{
                                print"<td>$ip</td><td>$customgrp{$key}[3]</td><td width='1%'><form method='post'>";
                        }
-                       if ($number gt '1' && $ip ne ''){
+                       if ($number > 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='delhost' value='$grpname,$remark,$customgrp{$key}[2],$customgrp{$key}[3]'></form></td></tr>";
                        
                        $helper=$customgrp{$key}[0];
+                       $number++;
                }
                print"</table>";
                
@@ -1502,7 +1477,7 @@ sub viewtableservice
                        <table width='100%' border='0'>
                        <tr><td align='center'><b>$Lang::tr{'fwhost srv_name'}</td><td align='center'><b>$Lang::tr{'fwhost prot'}</td><td align='center'><b>$Lang::tr{'fwhost port'}</td><td align='center'><b>ICMP</td><td align='center'><b>$Lang::tr{'fwhost used'}</td><td></td><td width='3%'></td></tr>
 END
-               foreach my $key (sort {$a <=> $b} keys %customservice)
+               foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0])||  $a <=> $b } keys %customservice)
                {
                        $count++;
                        if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) {
@@ -1537,12 +1512,14 @@ sub viewtableservicegrp
        my $grpname;
        my $remark;
        my $helper;
+       my $port;
+       my $protocol;
        if (! -z $configsrvgrp){
-       
                &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'});
                &General::readhasharray("$configsrvgrp", \%customservicegrp);
+               &General::readhasharray("$configsrv", \%customservice);
                my $number= keys %customservicegrp;
-               foreach my $key (sort {$a <=> $b} keys %customservicegrp){
+               foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0])||  $a <=> $b } keys %customservicegrp){
                        $count++;
                        if ($helper ne $customservicegrp{$key}[0]){
                                $grpname=$customservicegrp{$key}[0];
@@ -1550,8 +1527,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}[5] x";
-                               if($customservicegrp{$key}[5] == '0')
+                               print "&nbsp <b>$Lang::tr{'used'}:</b> $customservicegrp{$key}[3]x";
+                               if($customservicegrp{$key}[3] == '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>";
                                }
@@ -1560,14 +1537,26 @@ sub viewtableservicegrp
                        }
                        if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) {
                                print" <tr bgcolor='${Header::colouryellow}'>";
-                               }elsif ($count %2 == 0){print"<tr bgcolor='$color{'color22'}'>";}else{print"<tr bgcolor='$color{'color20'}'>";}
-                               print "<td width='39%'>$customservicegrp{$key}[2]</td>";
-                               print"<td align='center'>$customservicegrp{$key}[3]</td><td align='center'>$customservicegrp{$key}[4]</td><td width='1%'><form method='post'>";
-                               if ($number gt '1'){
-                                       print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
+                       }
+                       if ($count %2 == 0){
+                               print"<tr bgcolor='$color{'color22'}'>";
+                       }else{
+                               print"<tr bgcolor='$color{'color20'}'>";
+                       }
+                       print "<td width='39%'>$customservicegrp{$key}[2]</td>";
+                       foreach my $srv (sort keys %customservice){
+                               if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){
+                                       $protocol=$customservice{$srv}[2];
+                                       $port=$customservice{$srv}[1];
+                                       last;
                                }
-                               print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2],$customservicegrp{$key}[3]'></form></td></tr>";
-                               $helper=$customservicegrp{$key}[0];
+                       }
+                       print"<td align='center'>$port</td><td align='center'>$protocol</td><td width='1%'><form method='post'>";
+                       if ($number 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='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2],$customservicegrp{$key}[3]'></form></td></tr>";
+                       $helper=$customservicegrp{$key}[0];
                }
                print"</table>";
                &Header::closebox();
@@ -1616,7 +1605,7 @@ sub checkservicegroup
        
        
        #check name
-       if ( ! &General::validhostname($fwhostsettings{'SRVGRP_NAME'}))
+       if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'}))
        {
                $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
                return $errormessage;
@@ -1631,7 +1620,6 @@ sub checkservicegroup
        {
                $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>";
        }
-       
        #check if name already exists
        if ($fwhostsettings{'updatesrvgrp'} ne 'on'){
                foreach my $key (keys %customservicegrp) {
@@ -1643,14 +1631,10 @@ sub checkservicegroup
        }
        #check if service already exists in group
        foreach my $key (keys %customservicegrp) {
-                       if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){
-                               $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>";
-                       
-                       }
+               if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){
+                       $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>";
                }
-       
-       
-       
+       }
        return $errormessage;
 }
 sub error
@@ -1778,7 +1762,7 @@ sub plausicheck
        &General::readhasharray("$confighost", \%customhost);
        if (!&checkname(\%customhost))
        {
-               $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err hostexist'};
+               $errormessage.="<br>".$Lang::tr{'fwhost err hostexist'};
                $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
                if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
        }
@@ -1786,7 +1770,6 @@ sub plausicheck
        if (!&checkip(\%customhost,2))
        {
                $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'};
-               
        }
                
        
@@ -1904,10 +1887,20 @@ sub getipforgroup
        }
 }
 sub rules
+{
+       if (!-f "${General::swroot}/fwhosts/reread"){
+               system("touch ${General::swroot}/fwhosts/reread");
+       }
+}
+sub reread_rules
 {
        system ("/usr/local/bin/forwardfwctrl");
-       system("rm ${General::swroot}/forward/reread");
+       if ( -f "${General::swroot}/fwhosts/reread"){
+               system("rm ${General::swroot}/fwhosts/reread");
+       }
+       
 }
+
 sub decrease
 {
        my $grp=$_[0];
@@ -1966,7 +1959,7 @@ sub checkports
                $errormessage=$Lang::tr{'fwhost err port'};
        }
        #check valid name
-       if (! &General::validhostname($fwhostsettings{'SRV_NAME'})){
+       if (! &validhostname($fwhostsettings{'SRV_NAME'})){
                $errormessage="<br>".$Lang::tr{'fwhost err name'};
        }
        #change dashes with :
@@ -2003,13 +1996,13 @@ sub validhostname
        if (length ($hostname) < 1 || length ($hostname) > 63) {
                return 0;}
        # Only valid characters are a-z, A-Z, 0-9 and -
-       if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-\s]*$/) {
+       if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-_()\/\s]*$/) {
                return 0;}
        # First character can only be a letter or a digit
        if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
                return 0;}
        # Last character can only be a letter or a digit
-       if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
+       if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9()]*$/) {
                return 0;}
        return 1;
 }