]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - html/cgi-bin/forwardfw.cgi
Forward Firewall: Try to implement a timeconverter for Rules. New function timeconver...
[people/teissler/ipfire-2.x.git] / html / cgi-bin / forwardfw.cgi
index 55f61eb2d22e207a58621ea727399d807ba2d87f..1caa34869cbdd5edb89f38b73004f6f7d16e2927 100755 (executable)
@@ -74,7 +74,7 @@ my %ipsecsettings=();
 my %aliases=();
 my %optionsfw=();
 
-my $VERSION='0.9.7.9';
+my $VERSION='0.9.8.3';
 my $color;
 my $confignet          = "${General::swroot}/fwhosts/customnetworks";
 my $confighost         = "${General::swroot}/fwhosts/customhosts";
@@ -96,7 +96,7 @@ my $hint='';
 my $ipgrp="${General::swroot}/outgoing/groups";
 my $tdcolor='';
 my $checkorange='';
-
+my @protocols;
 &General::readhash("${General::swroot}/forward/settings", \%fwdfwsettings);
 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
@@ -143,6 +143,12 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule')
        if(     $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'grp2'} eq 'ipfire'){
                $errormessage.=$Lang::tr{'fwdfw err same'};
        }
+       #Konvert timeframe if defined
+       if ($fwdfwsettings{'TIME'} eq 'ON'){
+               $fwdfwsettings{'TIME_FROM'} = &timeconvert($fwdfwsettings{'TIME_FROM'},'2utc');
+               $fwdfwsettings{'TIME_TO'}   = &timeconvert($fwdfwsettings{'TIME_TO'},'2utc');
+               print "NACHHER: $fwdfwsettings{'TIME_FROM'} - $fwdfwsettings{'TIME_TO'}<br>";
+       }
        #DMZ-Part
        if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' || $checkorange eq 'on'){
                $fwdfwsettings{'config'}=$configdmz;
@@ -575,9 +581,8 @@ END
        print "$Lang::tr{'outgoing firewall reset'}: <input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /><input type='hidden' name='poltype' value='outgoing' /></tr>";
        print "</table></form>";
        &Header::closebox();
-       print "<br><br><div align='right'><font size='1' color='grey'>Version: $VERSION</div>";
+       print "<br><br><div align='right'><font size='1' color='grey'>Version: $VERSION</font></div>";
 }
-
 sub changerule
 {
        my $oldchain=shift;
@@ -1223,13 +1228,14 @@ sub get_serviceports
        my $name=shift;
        &General::readhasharray("$configsrv", \%customservice);
        &General::readhasharray("$configsrvgrp", \%customservicegrp);
-       my $protocols;
        my $tcp;
        my $udp;
+       my $icmp;
+       @protocols=();
        if($type eq 'service'){
                foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
                        if ($customservice{$key}[0] eq $name){
-                               $protocols=$customservice{$key}[2];
+                               push (@protocols,$customservice{$key}[2]);
                        }
                }
        }elsif($type eq 'group'){
@@ -1237,16 +1243,32 @@ sub get_serviceports
                        if ($customservicegrp{$key}[0] eq $name){
                                foreach my $key1 (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
                                        if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
-                                               if($customservice{$key1}[2] eq 'TCP'){$tcp='TCP';}else{$udp='UDP';}
+                                               if($customservice{$key1}[2] eq 'TCP'){
+                                                       $tcp='TCP';
+                                               }elsif($customservice{$key1}[2] eq 'ICMP'){
+                                                       $icmp='ICMP';
+                                               }elsif($customservice{$key1}[2] eq 'UDP'){
+                                                       $udp='UDP';
+                                               }
                                        }
                                }
                        }
                }
        }
-       if($tcp && $udp){$protocols="TCP,UDP";
-       }elsif($tcp){$protocols.="TCP";
-       }elsif($udp){$protocols.="UDP";}
-       return $protocols;
+       if($tcp && $udp && $icmp){
+               push (@protocols,"All");
+               return @protocols;
+       }
+       if($tcp){
+               push (@protocols,"TCP");
+       }
+       if($udp){
+               push (@protocols,"UDP");
+       }
+       if($icmp){
+               push (@protocols,"ICMP");
+       }
+       return @protocols;
 }
 sub getcolor
 {
@@ -1369,6 +1391,8 @@ sub newrule
        $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}}                = 'CHECKED';
        $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}}                = 'CHECKED';
        $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}}                = 'CHECKED';
+       $fwdfwsettings{'TIME_FROM'} = &timeconvert($fwdfwsettings{'TIME_FROM'},'');
+       $fwdfwsettings{'TIME_TO'} = &timeconvert($fwdfwsettings{'TIME_TO'},'');
        $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}}             = 'selected';
        $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}}                 = 'selected';
        $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
@@ -1461,7 +1485,8 @@ sub newrule
                }       
        }
        &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
-
+       $fwdfwsettings{'TIME_FROM'} = &timeconvert($fwdfwsettings{'TIME_FROM'},'');
+       $fwdfwsettings{'TIME_TO'} = &timeconvert($fwdfwsettings{'TIME_TO'},'');
 print <<END;
        <form method="post">
        <table border='0'>
@@ -1973,6 +1998,49 @@ sub saverule
                }
        }
 }
+sub timeconvert
+{
+       my $orgtime=shift;
+       my $type=shift;
+       my $newtime;
+       my ($hour,$min) = split (":", $orgtime);
+       my @locar = localtime(time);
+       my @gmtar = gmtime();
+       my $oldtime = $hour*60 + $min;
+       my $gmt = $gmtar[2]*60 + $gmtar[1];
+       my $loc = $locar[2]*60 + $locar[1];
+       my $diff;
+       my $newtime;
+       if ($gmt > $loc)
+       {
+               $diff = $gmt - $loc;
+               if ($type eq '2utc')
+               {
+                       print"umrechnen nach UTC<br>";
+                       $newtime = $oldtime + $diff;
+               }else{
+                       $newtime = $oldtime - $diff;
+               }
+       }else{
+               $diff = $loc - $gmt;
+               if ($type eq '2utc')
+               {
+                       $newtime = $oldtime - $diff;
+               }else{
+                       $newtime = $oldtime + $diff;
+               }
+       }
+       if ($newtime < 0 ){
+               $newtime += 1440;
+       }
+       if ($newtime >= 1440){
+               $newtime -= 1440;
+       }
+       my $newhour =sprintf"%02d", $newtime/60;
+       my $newmin  = sprintf"%02d",$newtime % 60;
+       $newtime = "$newhour:$newmin";
+       return $newtime;
+}
 sub validremark
 {
        # Checks a hostname against RFC1035
@@ -2059,8 +2127,6 @@ sub viewtablenew
                                                $$hash{$key}[2]='';
                                        }
                                }
-                               #$$hash{$key}[3]='';
-                               #$$hash{$key}[5]='';
                        }
                        $$hash{'ACTIVE'}=$$hash{$key}[2];
                        $count++;
@@ -2131,17 +2197,19 @@ END
                        #Get Protocol
                        my $prot;
                        if ($$hash{$key}[12]){                  #target prot if manual
-                               $prot=$$hash{$key}[12];
+                               push (@protocols,$$hash{$key}[12]);
                        }elsif($$hash{$key}[8]){                #source prot if manual
-                               $prot=$$hash{$key}[8];
+                               push (@protocols,$$hash{$key}[8]);
                        }elsif($$hash{$key}[14] eq 'cust_srv'){ 
-                               $prot=&get_serviceports("service",$$hash{$key}[15]);
+                               &get_serviceports("service",$$hash{$key}[15]);
                        }elsif($$hash{$key}[14] eq 'cust_srvgrp'){
-                               $prot=&get_serviceports("group",$$hash{$key}[15]);
+                               &get_serviceports("group",$$hash{$key}[15]);
                        }else{
-                               $prot=$Lang::tr{'all'};
+                               push (@protocols,$Lang::tr{'all'});
                        }
-                       print"<td align='center'>$prot</td>";
+                       my $protz=join(",",@protocols);
+                       print"<td align='center'>$protz</td>";
+                       @protocols=();
                        if ($$hash{$key}[18] eq 'ON'){
                                my @days=();
                                if($$hash{$key}[19] ne ''){push (@days,$Lang::tr{'fwdfw wd_mon'});}
@@ -2153,7 +2221,10 @@ END
                                if($$hash{$key}[25] ne ''){push (@days,$Lang::tr{'fwdfw wd_sun'});}
                                my $weekdays=join(",",@days);
                                if (@days){
-                                       print"<td align='center' width='100'>$weekdays &nbsp $$hash{$key}[26] - $$hash{$key}[27]</td>";
+                                       my $from = &timeconvert($$hash{$key}[26],'2loc');
+                                       my $to = &timeconvert($$hash{$key}[27],'2loc');;
+                                       
+                                       print"<td align='center' width='100'>$weekdays &nbsp $from - $to</td>";
                                }
                        }else{
                                        print"<td align='center'>24/7</td>";