]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - html/cgi-bin/fwhosts.cgi
Forward Firewall: Portfw now working and firewall closed correctly
[people/teissler/ipfire-2.x.git] / html / cgi-bin / fwhosts.cgi
index 6b6a5ec23c4208e42b548eda625e1854e7b44fb8..face57b32c642d9ef840ec7290a59b68602d1138 100755 (executable)
@@ -108,7 +108,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,11 +116,15 @@ 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')
 {
@@ -151,13 +154,41 @@ 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'}     = '';
@@ -169,7 +200,6 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice')
                $fwhostsettings{'updatesrv'}= 'on';
        }
        if($needrules eq 'on'){
-               $errormessage="reread!";
                &rules;
        }
        &addservice;
@@ -459,7 +489,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'}='';
@@ -717,7 +746,7 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
                {
                        if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
                        {
-                               $count=$customservicegrp{$key}[5];
+                               $count=$customservicegrp{$key}[3];
                                last;
                        }
                }
@@ -1246,7 +1275,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 {$a <=> $b}  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>";
        }
@@ -1334,8 +1363,9 @@ END
                        }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]' />
@@ -1367,18 +1397,18 @@ 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 { 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>";}
@@ -1410,12 +1440,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>";
                
@@ -1578,7 +1609,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) {
@@ -1590,14 +1620,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
@@ -1725,7 +1751,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;}
        }
@@ -1733,7 +1759,6 @@ sub plausicheck
        if (!&checkip(\%customhost,2))
        {
                $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'};
-               
        }