]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/forwardfw.cgi
4fc74aab70568746a621f454293321d6780da2df
[people/teissler/ipfire-2.x.git] / html / cgi-bin / forwardfw.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21 # #
22 # Hi folks! I hope this code is useful for all. I needed something to handle #
23 # my VPN Connections in a comfortable way. As a prerequisite i needed #
24 # something that makes sure the vpn roadwarrior are able to have a fixed #
25 # ip-address. So i developed the ccd extension for the vpn server. #
26 # #
27 # Now that the ccd extension is ready i am able to develop the main request. #
28 # Any feedback is appreciated. #
29 # #
30 # #
31 ###############################################################################
32
33 use strict;
34 no warnings 'uninitialized';
35 # enable only the following on debugging purpose
36 #use warnings;
37 #use CGI::Carp 'fatalsToBrowser';
38
39 require '/var/ipfire/general-functions.pl';
40 require "${General::swroot}/lang.pl";
41 require "${General::swroot}/header.pl";
42 require "${General::swroot}/forward/bin/firewall-lib.pl";
43
44 unless (-d "${General::swroot}/forward") { system("mkdir ${General::swroot}/forward"); }
45 unless (-e "${General::swroot}/forward/settings") { system("touch ${General::swroot}/forward/settings"); }
46 unless (-e "${General::swroot}/forward/config") { system("touch ${General::swroot}/forward/config"); }
47 unless (-e "${General::swroot}/forward/input") { system("touch ${General::swroot}/forward/input"); }
48
49 my %fwdfwsettings=();
50 my %selected=() ;
51 my %defaultNetworks=();
52 my %netsettings=();
53 my %customhost=();
54 my %customgrp=();
55 my %customnetworks=();
56 my %customservice=();
57 my %customservicegrp=();
58 my %ccdnet=();
59 my %customnetwork=();
60 my %ccdhost=();
61 my %configfwdfw=();
62 my %configinputfw=();
63 my %ipsecconf=();
64 my %color=();
65 my %mainsettings=();
66 my %checked=();
67 my %icmptypes=();
68 my %ovpnsettings=();
69 my %ipsecsettings=();
70 my %aliases=();
71 my @p2ps = ();
72 my $color;
73 my $confignet = "${General::swroot}/fwhosts/customnetworks";
74 my $confighost = "${General::swroot}/fwhosts/customhosts";
75 my $configgrp = "${General::swroot}/fwhosts/customgroups";
76 my $configsrv = "${General::swroot}/fwhosts/customservices";
77 my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
78 my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
79 my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
80 my $configipsec = "${General::swroot}/vpn/config";
81 my $configipsecrw = "${General::swroot}/vpn/settings";
82 my $configfwdfw = "${General::swroot}/forward/config";
83 my $configinput = "${General::swroot}/forward/input";
84 my $configovpn = "${General::swroot}/ovpn/settings";
85 my $p2pfile = "${General::swroot}/forward/p2protocols";
86 my $errormessage='';
87 my $hint='';
88 my $ipgrp="${General::swroot}/outgoing/groups";
89
90
91 &General::readhash("${General::swroot}/forward/settings", \%fwdfwsettings);
92 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
93 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
94
95 &Header::showhttpheaders();
96 &Header::getcgihash(\%fwdfwsettings);
97 &Header::openpage($Lang::tr{'fwdfw menu'}, 1, '');
98 &Header::openbigbox('100%', 'center',$errormessage);
99 #### ACTION #####
100
101 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'save'})
102 {
103 my $MODE = $fwdfwsettings{'POLICY'};
104 %fwdfwsettings = ();
105 $fwdfwsettings{'POLICY'} = "$MODE";
106 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
107 &reread_rules;
108 }
109 if ($fwdfwsettings{'ACTION'} eq 'saverule')
110 {
111 &General::readhasharray("$configfwdfw", \%configfwdfw);
112 &General::readhasharray("$configinput", \%configinputfw);
113 $errormessage=&checksource;
114 if(!$errormessage){&checktarget;}
115 if(!$errormessage){&checkrule;}
116 #check if we change an forward rule to an external access
117 if( $fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{'oldgrp2a'} ne 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
118 $fwdfwsettings{'updatefwrule'}='';
119 $fwdfwsettings{'config'}=$configfwdfw;
120 $fwdfwsettings{'nobase'}='on';
121 &deleterule;
122 &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
123 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
124 }
125 #check if we change an external access rule to an forward
126 if( $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'oldgrp2a'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
127 $fwdfwsettings{'updatefwrule'}='';
128 $fwdfwsettings{'config'}=$configinput;
129 $fwdfwsettings{'nobase'}='on';
130 &deleterule;
131 &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
132 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
133 }
134 #INPUT part
135 if($fwdfwsettings{'grp2'} eq 'ipfire'){
136 $fwdfwsettings{'chain'} = 'INPUTFW';
137 my $maxkey=&General::findhasharraykey(\%configinputfw);
138 #check if we have an identical rule already
139 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
140 foreach my $key (sort keys %configinputfw){
141 if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}"
142 eq "$configinputfw{$key}[0],$configinputfw{$key}[2],$configinputfw{$key}[3],$configinputfw{$key}[4],$configinputfw{$key}[5],$configinputfw{$key}[6],$configinputfw{$key}[7],$configinputfw{$key}[8],$configinputfw{$key}[9],$configinputfw{$key}[10],$configinputfw{$key}[11],$configinputfw{$key}[12],$configinputfw{$key}[13],$configinputfw{$key}[14],$configinputfw{$key}[15],$configinputfw{$key}[17],$configinputfw{$key}[18],$configinputfw{$key}[19],$configinputfw{$key}[20],$configinputfw{$key}[21],$configinputfw{$key}[22],$configinputfw{$key}[23],$configinputfw{$key}[24],$configinputfw{$key}[25],$configinputfw{$key}[26],$configinputfw{$key}[27]"){
143 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
144 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && &validremark($fwdfwsettings{'ruleremark'})){
145 $errormessage='';
146 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && !&validremark($fwdfwsettings{'ruleremark'})){
147 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
148 }
149 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
150 $fwdfwsettings{'nosave'} = 'on';
151 }
152 }
153 }
154 }
155 #check Rulepos on new Rule
156 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
157 $fwdfwsettings{'oldrulenumber'}=$maxkey;
158 foreach my $key (sort keys %configinputfw){
159 if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}"
160 eq "$configinputfw{$key}[0],$configinputfw{$key}[2],$configinputfw{$key}[3],$configinputfw{$key}[4],$configinputfw{$key}[5],$configinputfw{$key}[6],$configinputfw{$key}[7],$configinputfw{$key}[8],$configinputfw{$key}[9],$configinputfw{$key}[10],$configinputfw{$key}[11],$configinputfw{$key}[12],$configinputfw{$key}[13],$configinputfw{$key}[14],$configinputfw{$key}[15],$configinputfw{$key}[17],$configinputfw{$key}[18],$configinputfw{$key}[19],$configinputfw{$key}[20],$configinputfw{$key}[21],$configinputfw{$key}[22],$configinputfw{$key}[23],$configinputfw{$key}[24],$configinputfw{$key}[25],$configinputfw{$key}[26],$configinputfw{$key}[27]"){
161 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
162 }
163 }
164 }
165 #check if we just close a rule
166 if( $fwdfwsettings{'oldgrp1a'} eq $fwdfwsettings{'grp1'} && $fwdfwsettings{'oldgrp1b'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'oldgrp2a'} eq $fwdfwsettings{'grp2'} && $fwdfwsettings{'oldgrp2b'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'oldgrp3a'} eq $fwdfwsettings{'grp3'} && $fwdfwsettings{'oldgrp3b'} eq $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} ) {
167 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
168 $errormessage='';
169 $fwdfwsettings{'nosave2'} = 'on';
170 }
171 }
172 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
173 if ($fwdfwsettings{'nobase'} ne 'on'){
174 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
175 }
176 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
177 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
178 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
179 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
180 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
181 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
182 }
183 if($fwdfwsettings{'nosave2'} ne 'on'){
184 &saverule(\%configinputfw,$configinput);
185 }
186 #print "Source: $fwdfwsettings{'grp1'} -> $fwdfwsettings{$fwdfwsettings{'grp1'}}<br>";
187 #print "Sourceport: $fwdfwsettings{'USE_SRC_PORT'}, $fwdfwsettings{'PROT'}, $fwdfwsettings{'ICMP_TYPES'}, $fwdfwsettings{'SRC_PORT'}<br>";
188 #print "Target: $fwdfwsettings{'grp2'} -> $fwdfwsettings{$fwdfwsettings{'grp2'}}<br>";
189 #print "Dienst: $fwdfwsettings{'USESRV'}, $fwdfwsettings{'grp3'} -> $fwdfwsettings{$fwdfwsettings{'grp3'}}<br>";
190 #print "BEMERKUNG: $fwdfwsettings{'ruleremark'}<br>";
191 #print " Regel AKTIV: $fwdfwsettings{'ACTIVE'}<br>";
192 #print " Regel LOG: $fwdfwsettings{'LOG'}<br>";
193 #print " ZEITRAHMEN: $fwdfwsettings{'TIME'}<br>";
194 #print " MO: $fwdfwsettings{'TIME_MON'}<br>";
195 #print " DI: $fwdfwsettings{'TIME_TUE'}<br>";
196 #print " MI: $fwdfwsettings{'TIME_WED'}<br>";
197 #print " DO: $fwdfwsettings{'TIME_THU'}<br>";
198 #print " FR: $fwdfwsettings{'TIME_FRI'}<br>";
199 #print " SA: $fwdfwsettings{'TIME_SAT'}<br>";
200 #print " SO: $fwdfwsettings{'TIME_SUN'}<br>";
201 #print " VON: $fwdfwsettings{'TIME_FROM'} bis $fwdfwsettings{'TIME_TO'}<br>";
202 #print "<br>";
203 #print"ALT: $fwdfwsettings{'oldgrp1a'} $fwdfwsettings{'oldgrp1b'} NEU: $fwdfwsettings{'grp1'} $fwdfwsettings{$fwdfwsettings{'grp1'}}<br>";
204 #print"ALT: $fwdfwsettings{'oldgrp2a'} $fwdfwsettings{'oldgrp2b'} NEU: $fwdfwsettings{'grp2'} $fwdfwsettings{$fwdfwsettings{'grp2'}}<br>";
205 #print"ALT: $fwdfwsettings{'oldgrp3a'} $fwdfwsettings{'oldgrp3b'} NEU: $fwdfwsettings{'grp3'} $fwdfwsettings{$fwdfwsettings{'grp3'}}<br>";
206 #print"DIENSTE Checkalt:$fwdfwsettings{'oldusesrv'} DIENSTE Checkneu:$fwdfwsettings{'USESRV'} DIENST ALT:$fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'} DIENST NEU:$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}<br>";
207 }else{
208 #FORWARD PART
209 $fwdfwsettings{'chain'} = 'FORWARDFW';
210 my $maxkey=&General::findhasharraykey(\%configfwdfw);
211 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
212 #check if we have an identical rule already
213 foreach my $key (sort keys %configfwdfw){
214 if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}"
215 eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[17],$configfwdfw{$key}[18],$configfwdfw{$key}[19],$configfwdfw{$key}[20],$configfwdfw{$key}[21],$configfwdfw{$key}[22],$configfwdfw{$key}[23],$configfwdfw{$key}[24],$configfwdfw{$key}[25],$configfwdfw{$key}[26],$configfwdfw{$key}[27]"){
216 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
217 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && &validremark($fwdfwsettings{'ruleremark'})){
218 $errormessage='';
219 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && !&validremark($fwdfwsettings{'ruleremark'})){
220 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
221 }
222 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
223 $fwdfwsettings{'nosave'} = 'on';
224 }
225 }
226 }
227 }
228 #check Rulepos on new Rule
229 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
230 $fwdfwsettings{'oldrulenumber'}=$maxkey;
231 foreach my $key (sort keys %configfwdfw){
232 if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}"
233 eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[17],$configfwdfw{$key}[18],$configfwdfw{$key}[19],$configfwdfw{$key}[20],$configfwdfw{$key}[21],$configfwdfw{$key}[22],$configfwdfw{$key}[23],$configfwdfw{$key}[24],$configfwdfw{$key}[25],$configfwdfw{$key}[26],$configfwdfw{$key}[27]"){
234 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
235 }
236 }
237 }
238 #check if we just close a rule
239 if( $fwdfwsettings{'oldgrp1a'} eq $fwdfwsettings{'grp1'} && $fwdfwsettings{'oldgrp1b'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'oldgrp2a'} eq $fwdfwsettings{'grp2'} && $fwdfwsettings{'oldgrp2b'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'oldgrp3a'} eq $fwdfwsettings{'grp3'} && $fwdfwsettings{'oldgrp3b'} eq $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'} ) {
240 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
241 $fwdfwsettings{'nosave2'} = 'on';
242 $errormessage='';
243 }
244 }
245 #increase counters
246 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
247 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
248 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
249 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
250 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
251 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
252 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
253 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
254 }
255 if ($fwdfwsettings{'nobase'} eq 'on'){
256 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
257 }
258 if ($fwdfwsettings{'nosave2'} ne 'on'){
259 &saverule(\%configfwdfw,$configfwdfw);
260 }
261 #print "Source: $fwdfwsettings{'grp1'} -> $fwdfwsettings{$fwdfwsettings{'grp1'}}<br>";
262 #print "Sourceport: $fwdfwsettings{'USE_SRC_PORT'}, $fwdfwsettings{'PROT'}, $fwdfwsettings{'ICMP_TYPES'}, $fwdfwsettings{'SRC_PORT'}<br>";
263 #print "Target: $fwdfwsettings{'grp2'} -> $fwdfwsettings{$fwdfwsettings{'grp2'}}<br>";
264 #print "Dienst: $fwdfwsettings{'USESRV'}, $fwdfwsettings{'grp3'} -> $fwdfwsettings{$fwdfwsettings{'grp3'}}<br>";
265 #print "BEMERKUNG: $fwdfwsettings{'ruleremark'}<br>";
266 #print " Regel AKTIV: $fwdfwsettings{'ACTIVE'}<br>";
267 #print " Regel LOG: $fwdfwsettings{'LOG'}<br>";
268 #print " ZEITRAHMEN: $fwdfwsettings{'TIME'}<br>";
269 #print " MO: $fwdfwsettings{'TIME_MON'}<br>";
270 #print " DI: $fwdfwsettings{'TIME_TUE'}<br>";
271 #print " MI: $fwdfwsettings{'TIME_WED'}<br>";
272 #print " DO: $fwdfwsettings{'TIME_THU'}<br>";
273 #print " FR: $fwdfwsettings{'TIME_FRI'}<br>";
274 #print " SA: $fwdfwsettings{'TIME_SAT'}<br>";
275 #print " SO: $fwdfwsettings{'TIME_SUN'}<br>";
276 #print " VON: $fwdfwsettings{'TIME_FROM'} bis $fwdfwsettings{'TIME_TO'}<br>";
277 #print "<br>";
278 #print"ALT: $fwdfwsettings{'oldgrp1a'} $fwdfwsettings{'oldgrp1b'} NEU: $fwdfwsettings{'grp1'} $fwdfwsettings{$fwdfwsettings{'grp1'}}<br>";
279 #print"ALT: $fwdfwsettings{'oldgrp2a'} $fwdfwsettings{'oldgrp2b'} NEU: $fwdfwsettings{'grp2'} $fwdfwsettings{$fwdfwsettings{'grp2'}}<br>";
280 #print"ALT: $fwdfwsettings{'oldgrp3a'} $fwdfwsettings{'oldgrp3b'} NEU: $fwdfwsettings{'grp3'} $fwdfwsettings{$fwdfwsettings{'grp3'}}<br>";
281 #print"DIENSTE Checkalt:$fwdfwsettings{'oldusesrv'} DIENSTE Checkneu:$fwdfwsettings{'USESRV'} DIENST ALT:$fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'} DIENST NEU:$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}<br>";
282 }
283 if ($errormessage){
284 &newrule;
285 }else{
286 if($fwdfwsettings{'nosave2'} ne 'on'){
287 &rules;
288 }
289 &base;
290 }
291 }
292 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'reset'})
293 {
294 &General::readhasharray("$configfwdfw", \%configfwdfw);
295 foreach my $key (sort keys %configfwdfw){
296 &checkcounter($configfwdfw{$key}[3],$configfwdfw{$key}[4],,);
297 &checkcounter($configfwdfw{$key}[5],$configfwdfw{$key}[6],,);
298 &checkcounter($configfwdfw{$key}[14],$configfwdfw{$key}[15],,);
299 }
300 &General::readhasharray("$configinput", \%configinputfw);
301 foreach my $key (sort keys %configinputfw){
302 &checkcounter($configinputfw{$key}[3],$configinputfw{$key}[4],,);
303 &checkcounter($configinputfw{$key}[5],$configinputfw{$key}[6],,);
304 &checkcounter($configinputfw{$key}[14],$configinputfw{$key}[15],,);
305 }
306 $fwdfwsettings{'POLICY'}='MODE0';
307 system("rm ${General::swroot}/forward/config");
308 system("rm ${General::swroot}/forward/input");
309 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
310 unless (-e "${General::swroot}/forward/config") { system("touch ${General::swroot}/forward/config"); }
311 unless (-e "${General::swroot}/forward/input") { system("touch ${General::swroot}/forward/input"); }
312 %fwdfwsettings = ();
313 &reread_rules;
314
315 }
316 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw newrule'})
317 {
318 &newrule;
319 }
320 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw toggle'})
321 {
322 my %togglehash=();
323 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
324 foreach my $key (sort keys %togglehash){
325 if ($key eq $fwdfwsettings{'key'}){
326 if ($togglehash{$key}[2] eq 'ON'){$togglehash{$key}[2]='';}else{$togglehash{$key}[2]='ON';}
327 }
328 }
329 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
330 &rules;
331 &base;
332 }
333 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw togglelog'})
334 {
335 my %togglehash=();
336 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
337 foreach my $key (sort keys %togglehash){
338 if ($key eq $fwdfwsettings{'key'}){
339 if ($togglehash{$key}[17] eq 'ON'){$togglehash{$key}[17]='';}else{$togglehash{$key}[17]='ON';}
340 }
341 }
342 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
343 &rules;
344 &base;
345 }
346 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
347 {
348 &reread_rules;
349 &base;
350 }
351 if ($fwdfwsettings{'ACTION'} eq 'editrule')
352 {
353 $fwdfwsettings{'updatefwrule'}='on';
354 &newrule;
355 }
356 if ($fwdfwsettings{'ACTION'} eq 'deleterule')
357 {
358 &deleterule;
359 }
360 if ($fwdfwsettings{'ACTION'} eq 'moveup')
361 {
362 &pos_up;
363 &base;
364 }
365 if ($fwdfwsettings{'ACTION'} eq 'movedown')
366 {
367 &pos_down;
368 &base;
369 }
370 if ($fwdfwsettings{'ACTION'} eq 'copyrule')
371 {
372 $fwdfwsettings{'copyfwrule'}='on';
373 #$fwdfwsettings{'updatefwrule'}='on';
374 &newrule;
375 }
376 if ($fwdfwsettings{'ACTION'} eq 'togglep2p')
377 {
378 #$errormessage="Toggle $fwdfwsettings{'P2PROT'}<br>";
379 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
380 @p2ps = <FILE>;
381 close FILE;
382 open( FILE, "> $p2pfile" ) or die "Unable to write $p2pfile";
383 foreach my $p2pentry (sort @p2ps)
384 {
385 my @p2pline = split( /\;/, $p2pentry );
386 if ($p2pline[1] eq $fwdfwsettings{'P2PROT'}) {
387 if($p2pline[2] eq 'on'){
388 $p2pline[2]='off';
389 }else{
390 $p2pline[2]='on';
391 }
392 }
393 print FILE "$p2pline[0];$p2pline[1];$p2pline[2];\n";
394 }
395 close FILE;
396 &rules;
397 &base;
398 }
399 if ($fwdfwsettings{'ACTION'} eq '')
400 {
401 &base;
402 }
403 ### Functions ####
404 sub pos_up
405 {
406 my %uphash=();
407 my %tmp=();
408 &General::readhasharray($fwdfwsettings{'config'}, \%uphash);
409 foreach my $key (sort keys %uphash){
410 if ($key eq $fwdfwsettings{'key'}) {
411 my $last = $key -1;
412 if (exists $uphash{$last}){
413 #save rule last
414 foreach my $y (0 .. $#{$uphash{$last}}) {
415 $tmp{0}[$y] = $uphash{$last}[$y];
416 }
417 #copy active rule to last
418 foreach my $i (0 .. $#{$uphash{$last}}) {
419 $uphash{$last}[$i] = $uphash{$key}[$i];
420 }
421 #copy saved rule to actual position
422 foreach my $x (0 .. $#{$tmp{0}}) {
423 $uphash{$key}[$x] = $tmp{0}[$x];
424 }
425 }
426 }
427 }
428 &General::writehasharray($fwdfwsettings{'config'}, \%uphash);
429 &rules;
430 }
431 sub pos_down
432 {
433 my %downhash=();
434 my %tmp=();
435 &General::readhasharray($fwdfwsettings{'config'}, \%downhash);
436 foreach my $key (sort keys %downhash){
437 if ($key eq $fwdfwsettings{'key'}) {
438 my $next = $key + 1;
439 if (exists $downhash{$next}){
440 #save rule next
441 foreach my $y (0 .. $#{$downhash{$next}}) {
442 $tmp{0}[$y] = $downhash{$next}[$y];
443 }
444 #copy active rule to next
445 foreach my $i (0 .. $#{$downhash{$next}}) {
446 $downhash{$next}[$i] = $downhash{$key}[$i];
447 }
448 #copy saved rule to actual position
449 foreach my $x (0 .. $#{$tmp{0}}) {
450 $downhash{$key}[$x] = $tmp{0}[$x];
451 }
452 }
453 }
454 }
455 &General::writehasharray($fwdfwsettings{'config'}, \%downhash);
456 &rules;
457 }
458 sub checkcounter
459 {
460 my ($base1,$val1,$base2,$val2) = @_;
461
462 if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){
463 &dec_counter($confignet,\%customnetwork,$val1);
464 }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){
465 &dec_counter($confighost,\%customhost,$val1);
466 }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){
467 &dec_counter($configgrp,\%customgrp,$val1);
468 }elsif($base1 eq 'cust_srv'){
469 &dec_counter($configsrv,\%customservice,$val1);
470 }elsif($base1 eq 'cust_srvgrp'){
471 &dec_counter($configsrvgrp,\%customservicegrp,$val1);
472 }
473
474 if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){
475 &inc_counter($confignet,\%customnetwork,$val2);
476 }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){
477 &inc_counter($confighost,\%customhost,$val2);
478 }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){
479 &inc_counter($configgrp,\%customgrp,$val2);
480 }elsif($base2 eq 'cust_srv'){
481 &inc_counter($configsrv,\%customservice,$val2);
482 }elsif($base2 eq 'cust_srvgrp'){
483 &inc_counter($configsrvgrp,\%customservicegrp,$val2);
484 }
485 }
486 sub inc_counter
487 {
488 my $config=shift;
489 my %hash=%{(shift)};
490 my $val=shift;
491 my $pos;
492
493 &General::readhasharray($config, \%hash);
494 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
495 if($hash{$key}[0] eq $val){
496 $pos=$#{$hash{$key}};
497 $hash{$key}[$pos] = $hash{$key}[$pos]+1;
498 }
499 }
500 &General::writehasharray($config, \%hash);
501 }
502 sub dec_counter
503 {
504 my $config=shift;
505 my %hash=%{(shift)};
506 my $val=shift;
507 my $pos;
508 #$errormessage.="ALT:config: $config , verringert wird $val <br>";
509 &General::readhasharray($config, \%hash);
510 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
511 if($hash{$key}[0] eq $val){
512 $pos=$#{$hash{$key}};
513 $hash{$key}[$pos] = $hash{$key}[$pos]-1;
514 }
515 }
516 &General::writehasharray($config, \%hash);
517 }
518 sub base
519 {
520 if ($fwdfwsettings{'POLICY'} eq 'MODE0'){ $selected{'POLICY'}{'MODE0'} = 'selected'; } else { $selected{'POLICY'}{'MODE0'} = ''; }
521 if ($fwdfwsettings{'POLICY'} eq 'MODE1'){ $selected{'POLICY'}{'MODE1'} = 'selected'; } else { $selected{'POLICY'}{'MODE1'} = ''; }
522 if ($fwdfwsettings{'POLICY'} eq 'MODE2'){ $selected{'POLICY'}{'MODE2'} = 'selected'; } else { $selected{'POLICY'}{'MODE2'} = ''; }
523
524 &hint;
525 if ($fwdfwsettings{'POLICY'} ne 'MODE0' && $fwdfwsettings{'POLICY'} ne '') {
526 &addrule;
527 }
528
529 #print"<table width='100' border='1'><tr>";
530 #foreach (0 .. 40){
531 #my $i="color".$_;
532 #print"<td bgcolor='$color{$i}'>$_</td>";
533 #}
534 #print"</tr></table>";
535 if ($fwdfwsettings{'POLICY'} eq 'MODE1' || $fwdfwsettings{'POLICY'} eq 'MODE2' ) {
536 &p2pblock;
537 }
538 &Header::openbox('100%', 'center', 'Policy');
539 print <<END;
540 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
541 <table width='100%'>
542 <tr><td width='10%' align='left'><b>$Lang::tr{'mode'} 0:</b><td width='90%' align='left' colspan='2'>$Lang::tr{'outgoing firewall mode0'}</td></tr>
543 <tr><td width='10%' align='left'><b>$Lang::tr{'mode'} 1:</b><td width='90%' align='left' colspan='2'>$Lang::tr{'outgoing firewall mode1'}</td></tr>
544 <tr><td width='10%' align='left'><b>$Lang::tr{'mode'} 2:</b><td width='90%' align='left' colspan='2'>$Lang::tr{'outgoing firewall mode2'}</td></tr>
545 <tr><td colspan='3'><hr /></td></tr>
546 <tr><td width='10%' align='left'> <select name='POLICY' style="width: 85px"><option value='MODE0' $selected{'POLICY'}{'MODE0'}>$Lang::tr{'mode'} 0</option><option value='MODE1' $selected{'POLICY'}{'MODE1'}>$Lang::tr{'mode'} 1</option><option value='MODE2' $selected{'POLICY'}{'MODE2'}>$Lang::tr{'mode'} 2</option></select>
547 <td width='45%' align='left'><input type='submit' name='ACTION' value=$Lang::tr{'save'} />
548 <td width='45%' align='left'>
549 END
550 if ($fwdfwsettings{'POLICY'} ne 'MODE0'&& $fwdfwsettings{'POLICY'} ne '' ) {
551 print "$Lang::tr{'outgoing firewall reset'}: <input type='submit' name='ACTION' value='$Lang::tr{'reset'}' />";
552 }
553 print "</table></form>";
554 &Header::closebox();
555 }
556 sub addrule
557 {
558 &error;
559 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
560
561 print "<form method='post'>";
562 print "<table border='0'>";
563 print "<tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'></td>";
564 if (-f "${General::swroot}/forward/reread"){
565 print "<td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}'></td>";
566 }
567 print"</tr></table></form><hr>";
568
569 &Header::closebox();
570 &viewtablerule;
571 }
572 sub deleterule
573 {
574 my %delhash=();
575 &General::readhasharray($fwdfwsettings{'config'}, \%delhash);
576 foreach my $key (sort {$a <=> $b} keys %delhash){
577 if ($key == $fwdfwsettings{'key'}){
578 #check hosts/net and groups
579 &checkcounter($delhash{$key}[3],$delhash{$key}[4],,);
580 &checkcounter($delhash{$key}[5],$delhash{$key}[6],,);
581 #check services and groups
582 if ($delhash{$key}[11] eq 'ON'){
583 &checkcounter($delhash{$key}[14],$delhash{$key}[15],,);
584 }
585 }
586 if ($key >= $fwdfwsettings{'key'}) {
587 my $next = $key + 1;
588 if (exists $delhash{$next}) {
589 foreach my $i (0 .. $#{$delhash{$next}}) {
590 $delhash{$key}[$i] = $delhash{$next}[$i];
591 }
592 }
593 }
594 }
595 # Remove the very last entry.
596 my $last_key = (sort {$a <=> $b} keys %delhash)[-1];
597 delete $delhash{$last_key};
598
599 &General::writehasharray($fwdfwsettings{'config'}, \%delhash);
600 &rules;
601
602 if($fwdfwsettings{'nobase'} ne 'on'){
603 &base;
604 }
605 }
606 sub disable_rule
607 {
608 my $key1=shift;
609 &General::readhasharray("$configfwdfw", \%configfwdfw);
610 foreach my $key (sort keys %configfwdfw){
611 if ($key eq $key1 ){
612 if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';}
613 }
614 }
615 &General::writehasharray("$configfwdfw", \%configfwdfw);
616 &rules;
617 }
618 sub checksource
619 {
620 my ($ip,$subnet);
621
622 #check ip-address if manual
623 if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){
624 #check if ip with subnet
625 if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?)$/) {
626 ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'});
627 $subnet = &General::iporsubtocidr($subnet);
628 $fwdfwsettings{'isip'}='on';
629 }
630 #check if only ip
631 if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
632 $ip=$fwdfwsettings{'src_addr'};
633 $subnet = '32';
634 $fwdfwsettings{'isip'}='on';
635 }
636
637 if ($fwdfwsettings{'isip'} ne 'on'){
638 if (&General::validmac($fwdfwsettings{'src_addr'})){$fwdfwsettings{'ismac'}='on';}
639 }
640 if ($fwdfwsettings{'isip'} eq 'on'){
641 #check and form valid IP
642 $ip=&General::ip2dec($ip);
643 $ip=&General::dec2ip($ip);
644 #check if net or broadcast
645 my @tmp= split (/\./,$ip);
646 if (($tmp[3] eq "0") || ($tmp[3] eq "255"))
647 {
648 $errormessage=$Lang::tr{'fwhost err hostip'}."<br>";
649 }
650 $fwdfwsettings{'src_addr'}="$ip/$subnet";
651
652 if(!&General::validipandmask($fwdfwsettings{'src_addr'})){
653 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
654 }
655 }
656 if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){
657 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
658 }
659 }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
660 $errormessage.=$Lang::tr{'fwdfw err nosrcip'};
661 return $errormessage;
662 }
663
664 #check empty fields
665 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err nosrc'}."<br>";}
666 #check icmp source
667 if ($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ICMP'){
668 $fwdfwsettings{'SRC_PORT'}='';
669 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
670 foreach my $key (keys %icmptypes){
671 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){
672 $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]";
673 }
674 }
675 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'GRE'){
676 $fwdfwsettings{'SRC_PORT'}='';
677 $fwdfwsettings{'ICMP_TYPES'}='';
678 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ESP'){
679 $fwdfwsettings{'SRC_PORT'}='';
680 $fwdfwsettings{'ICMP_TYPES'}='';
681 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'AH'){
682 $fwdfwsettings{'SRC_PORT'}='';
683 $fwdfwsettings{'ICMP_TYPES'}='';
684 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} ne 'ICMP'){
685 $fwdfwsettings{'ICMP_TYPES'}='';
686 }else{
687 $fwdfwsettings{'ICMP_TYPES'}='';
688 $fwdfwsettings{'SRC_PORT'}='';
689 $fwdfwsettings{'PROT'}='';
690 }
691
692 if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){
693 my @parts=split(",",$fwdfwsettings{'SRC_PORT'});
694 my @values=();
695 foreach (@parts){
696 chomp($_);
697 if ($_ =~ /^(\d+)\:(\d+)$/) {
698 my $check;
699 #change dashes with :
700 $_=~ tr/-/:/;
701 if ($_ eq "*") {
702 push(@values,"1:65535");
703 $check='on';
704 }
705 if ($_ =~ /^(\D)\:(\d+)$/) {
706 push(@values,"1:$2");
707 $check='on';
708 }
709 if ($_ =~ /^(\d+)\:(\D)$/) {
710 push(@values,"$1:65535");
711 $check='on'
712 }
713 $errormessage .= &General::validportrange($_, 'destination');
714 if(!$check){
715 push (@values,$_);
716 }
717 }else{
718 if (&General::validport($_)){
719 push (@values,$_);
720 }else{
721
722 }
723 }
724 }
725 $fwdfwsettings{'SRC_PORT'}=join("|",@values);
726 return $errormessage;
727 }
728 }
729 sub checktarget
730 {
731 my ($ip,$subnet);
732
733 if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
734 #check if ip with subnet
735 if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?)$/) {
736 ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
737 $subnet = &General::iporsubtocidr($subnet);
738 }
739 #check if only ip
740 if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
741 $ip=$fwdfwsettings{'tgt_addr'};
742 $subnet='32';
743 }
744 #check and form valid IP
745 $ip=&General::ip2dec($ip);
746 $ip=&General::dec2ip($ip);
747
748 #check if net or broadcast
749 my @tmp= split (/\./,$ip);
750 if (($tmp[3] eq "0") || ($tmp[3] eq "255"))
751 {
752 $errormessage=$Lang::tr{'fwhost err hostip'}."<br>";
753 }
754 $fwdfwsettings{'tgt_addr'}="$ip/$subnet";
755
756 if(!&General::validipandmask($fwdfwsettings{'tgt_addr'})){
757 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
758 }
759
760 }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
761 $errormessage.=$Lang::tr{'fwdfw err notgtip'};
762 return $errormessage;
763 }
764
765 #check empty fields
766 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err notgt'}."<br>";}
767
768 #check tgt services
769 if ($fwdfwsettings{'USESRV'} eq 'ON'){
770 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
771 $fwdfwsettings{'TGT_PROT'}='';
772 $fwdfwsettings{'ICMP_TGT'}='';
773 }
774 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
775 $fwdfwsettings{'TGT_PROT'}='';
776 $fwdfwsettings{'ICMP_TGT'}='';
777 #check target service
778 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){
779 $errormessage.=$Lang::tr{'fwdfw err tgt_grp'};
780 }
781 }
782 if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
783 if ($fwdfwsettings{'TGT_PROT'} eq 'TCP' || $fwdfwsettings{'TGT_PROT'} eq 'UDP'){
784 if ($fwdfwsettings{'TGT_PORT'} ne ''){
785 my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
786 my @values=();
787 foreach (@parts){
788 chomp($_);
789 if ($_ =~ /^(\d+)\:(\d+)$/) {
790 my $check;
791 #change dashes with :
792 $_=~ tr/-/:/;
793 if ($_ eq "*") {
794 push(@values,"1:65535");
795 $check='on';
796 }
797 if ($_ =~ /^(\D)\:(\d+)$/) {
798 push(@values,"1:$2");
799 $check='on';
800 }
801 if ($_ =~ /^(\d+)\:(\D)$/) {
802 push(@values,"$1:65535");
803 $check='on'
804 }
805 $errormessage .= &General::validportrange($_, 'destination');
806 if(!$check){
807 push (@values,$_);
808 }
809 }else{
810 if (&General::validport($_)){
811 push (@values,$_);
812 }else{
813
814 }
815 }
816 }
817 $fwdfwsettings{'TGT_PORT'}=join("|",@values);
818 }
819 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'GRE'){
820 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
821 $fwdfwsettings{'TGT_PORT'} = '';
822 $fwdfwsettings{'ICMP_TGT'} = '';
823 }elsif($fwdfwsettings{'TGT_PROT'} eq 'ESP'){
824 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
825 $fwdfwsettings{'TGT_PORT'} = '';
826 $fwdfwsettings{'ICMP_TGT'}='';
827 }elsif($fwdfwsettings{'TGT_PROT'} eq 'AH'){
828 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
829 $fwdfwsettings{'TGT_PORT'} = '';
830 $fwdfwsettings{'ICMP_TGT'}='';
831 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'ICMP'){
832 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
833 $fwdfwsettings{'TGT_PORT'} = '';
834 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
835 foreach my $key (keys %icmptypes){
836
837 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwdfwsettings{'ICMP_TGT'}){
838 $fwdfwsettings{'ICMP_TGT'}=$icmptypes{$key}[0];
839 }
840 }
841 }
842 }
843 }
844
845 #check targetport
846 if ($fwdfwsettings{'USESRV'} ne 'ON'){
847 $fwdfwsettings{'grp3'}='';
848 $fwdfwsettings{$fwdfwsettings{'grp3'}}='';
849 $fwdfwsettings{'TGT_PROT'}='';
850 $fwdfwsettings{'ICMP_TGT'}='';
851 }
852 #check timeframe
853 if($fwdfwsettings{'TIME'} eq 'ON'){
854 if($fwdfwsettings{'TIME_MON'} eq '' && $fwdfwsettings{'TIME_TUE'} eq '' && $fwdfwsettings{'TIME_WED'} eq '' && $fwdfwsettings{'TIME_THU'} eq '' && $fwdfwsettings{'TIME_FRI'} eq '' && $fwdfwsettings{'TIME_SAT'} eq '' && $fwdfwsettings{'TIME_SUN'} eq ''){
855 $errormessage=$Lang::tr{'fwdfw err time'};
856 }
857 }
858 return $errormessage;
859 }
860 sub checkrule
861 {
862 #check valid remark
863 if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
864 $errormessage.=$Lang::tr{'fwdfw err remark'}."<br>";
865 }
866 #check if source and target identical
867 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL'){
868 $errormessage.=$Lang::tr{'fwdfw err same'};
869 return $errormessage;
870 }
871
872 #get source and targetip address if possible
873 my ($sip,$scidr,$tip,$tcidr);
874 ($sip,$scidr)=&get_ip("src","grp1");
875 ($tip,$tcidr)=&get_ip("tgt","grp2");
876
877 #check same iprange in source and target
878 if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){
879 my $networkip1=&General::getnetworkip($sip,$scidr);
880 my $networkip2=&General::getnetworkip($tip,$tcidr);
881 if ($scidr gt $tcidr){
882 if ( &General::IpInSubnet($networkip1,$tip,&General::iporsubtodec($tcidr)) ){
883 $errormessage.=$Lang::tr{'fwdfw err samesub'};
884 }
885 }elsif($scidr eq $tcidr && $scidr eq '32'){
886 my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1);
887 my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2);
888 if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){
889 $hint=$Lang::tr{'fwdfw hint ip1'}."<br>";
890 $hint.=$Lang::tr{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>";
891 }
892 }else{
893 if ( &General::IpInSubnet($networkip2,$sip,&General::iporsubtodec($scidr)) ){
894 $errormessage.=$Lang::tr{'fwdfw err samesub'};
895 }
896 }
897 }
898
899 #check source and destination protocol if manual
900 if( $fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'USESRV'} eq 'ON'){
901
902
903 if($fwdfwsettings{'PROT'} ne $fwdfwsettings{'TGT_PROT'} && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
904 $errormessage.=$Lang::tr{'fwdfw err prot'};
905 }
906 #check source and destination protocol if source manual and dest servicegrp
907 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
908 &General::readhasharray("$configsrv", \%customservice);
909 foreach my $key (sort keys %customservice){
910 if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){
911 if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){
912 $errormessage.=$Lang::tr{'fwdfw err prot'};
913 last;
914 }
915 }
916 }
917 }
918 }
919 }
920 sub get_ip
921 {
922 my $val=shift;
923 my $grp =shift;
924 my $a;
925 my $b;
926 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
927 if ($fwdfwsettings{$grp} ne $Lang::tr{'fwhost any'}){
928 if ($fwdfwsettings{$grp} eq $val.'_addr'){
929 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
930 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
931 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
932 $a=$netsettings{'GREEN_NETADDRESS'};
933 $b=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'});
934 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
935 $a=$netsettings{'ORANGE_NETADDRESS'};
936 $b=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'});
937 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
938 $a=$netsettings{'BLUE_NETADDRESS'};
939 $b=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'});
940 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
941 &General::readhash("$configovpn",\%ovpnsettings);
942 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
943 $b=&General::iporsubtocidr($b);
944 }
945 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
946 &General::readhasharray("$confignet", \%customnetwork);
947 foreach my $key (keys %customnetwork){
948 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
949 $a=$customnetwork{$key}[1];
950 $b=&General::iporsubtocidr($customnetwork{$key}[2]);
951 }
952 }
953 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
954 &General::readhasharray("$confighost", \%customhost);
955 foreach my $key (keys %customhost){
956 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
957 if ($customhost{$key}[1] eq 'ip'){
958 ($a,$b)=split (/\//,$customhost{$key}[2]);
959 $b=&General::iporsubtocidr($b);
960 }else{
961 if ($grp eq 'grp2'){
962 $errormessage=$Lang::tr{'fwdfw err tgt_mac'};
963 }
964 }
965 }
966 }
967 }
968 }
969 return $a,$b;
970 }
971 sub newrule
972 {
973 &error;
974 &General::setup_default_networks(\%defaultNetworks);
975 #read all configfiles
976 &General::readhasharray("$configccdnet", \%ccdnet);
977 &General::readhasharray("$confignet", \%customnetwork);
978 &General::readhasharray("$configccdhost", \%ccdhost);
979 &General::readhasharray("$confighost", \%customhost);
980 &General::readhasharray("$configccdhost", \%ccdhost);
981 &General::readhasharray("$configgrp", \%customgrp);
982 &General::readhasharray("$configipsec", \%ipsecconf);
983 &General::get_aliases(\%aliases);
984 my %checked=();
985 my $helper;
986 my $sum=0;
987 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
988 my $config=$fwdfwsettings{'config'};
989 my %hash=();
990 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
991 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
992 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
993 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
994 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
995 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
996 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
997 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
998 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
999 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1000 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1001 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1002 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1003 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1004 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1005 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1006 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1007 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1008 #check if update and get values
1009 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
1010 &General::readhasharray("$config", \%hash);
1011 foreach my $key (sort keys %hash){
1012 $sum++;
1013 if ($key eq $fwdfwsettings{'key'}){
1014 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
1015 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
1016 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1017 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1018 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1019 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1020 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1021 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1022 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1023 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1024 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1025 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1026 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1027 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1028 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1029 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1030 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1031 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1032 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1033 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1034 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1035 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1036 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1037 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1038 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1039 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1040 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1041 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
1042 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1043 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1044 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1045 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1046 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1047 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1048 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1049 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1050 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1051 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1052 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1053 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1054 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1055 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1056 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1057 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1058 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1059 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1060 }
1061 }
1062 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1063 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1064 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1065 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1066 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1067 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1068 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1069 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1070 }else{
1071 $fwdfwsettings{'ACTIVE'}='ON';
1072 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1073 }
1074
1075 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
1076
1077 print <<END;
1078 <form method="post">
1079 <table border='0'>
1080 <tr><td nowrap>$Lang::tr{'fwdfw rule action'}</td><td><select name='RULE_ACTION'>
1081 END
1082 foreach ("ACCEPT","DROP","REJECT")
1083 {
1084 if($fwdfwsettings{'updatefwrule'} eq 'on'){
1085 print"<option ";
1086 print "selected='selected'" if ($fwdfwsettings{'RULE_ACTION'} eq $_);
1087 print">$_</option>";
1088 }else{
1089 if($fwdfwsettings{'POLICY'} eq 'MODE2'){
1090 $fwdfwsettings{'RULE_ACTION'} = 'DROP';
1091 }
1092
1093 if ($_ eq $fwdfwsettings{'RULE_ACTION'})
1094 {
1095 print"<option selected>$_</option>";
1096 }else{
1097 print"<option>$_</option>";
1098 }
1099 }
1100 }
1101 print"</select></td></tr></table><hr>";
1102
1103 &Header::closebox();
1104 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'});
1105 #------SOURCE-------------------------------------------------------
1106 print<<END;
1107 <table width='100%' border='0'>
1108 <tr><td width='1%'><input type='radio' name='grp1' value='src_addr' checked></td><td colspan='5'>$Lang::tr{'fwdfw sourceip'}<input type='TEXT' name='src_addr' value='$fwdfwsettings{'src_addr'}' ></td></tr>
1109 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr>
1110 <tr><td width='1%'><input type='radio' name='grp1' value='std_net_src' $checked{'grp1'}{'std_net_src'}></td><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost stdnet'}</td><td width='13%'><select name='std_net_src' style='min-width:185px;'>
1111 END
1112 foreach my $network (sort keys %defaultNetworks)
1113 {
1114 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
1115 next if($defaultNetworks{$network}{'NAME'} eq "RED");
1116 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1117 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $defaultNetworks{$network}{'NAME'});
1118 print ">$network</option>";
1119 }
1120 print<<END;
1121 </select></td><td width='1%'><input type='radio' name='grp1' value='ovpn_net_src' $checked{'grp1'}{'ovpn_net_src'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_net_src' style='min-width:185px;'>
1122 END
1123 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{'grp1'}});
1124 print<<END;
1125 </select></td></tr>
1126 <tr><td><input type='radio' name='grp1' value='cust_net_src' $checked{'grp1'}{'cust_net_src'}></td><td>$Lang::tr{'fwhost cust net'}</td><td><select name='cust_net_src' style='min-width:185px;'>
1127 END
1128 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{'grp1'}});
1129 print<<END;
1130 </select></td><td width='1%'><input type='radio' name='grp1' value='ovpn_host_src' $checked{'grp1'}{'ovpn_host_src'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_host_src' style='min-width:185px;'>
1131 END
1132 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost)
1133 {
1134 if ($ccdhost{$key}[33] ne ''){
1135
1136 print "<option value='$ccdhost{$key}[1]'";
1137 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ccdhost{$key}[1]);
1138 print ">$ccdhost{$key}[1]</option>";
1139 }
1140 }
1141 print<<END;
1142 </select></td></tr>
1143 <tr><td valign='top'><input type='radio' name='grp1' value='cust_host_src' $checked{'grp1'}{'cust_host_src'}></td><td>$Lang::tr{'fwhost cust addr'}</td><td><select name='cust_host_src' style='min-width:185px;'>
1144 END
1145 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{'grp1'}});
1146 print<<END;
1147 </select></td><td width='1%'><input type='radio' name='grp1' value='ovpn_n2n_src' $checked{'grp1'}{'ovpn_n2n_src'}></td><td >$Lang::tr{'fwhost ovpn_n2n'}</td><td colspan='3'><select name='ovpn_n2n_src' style='min-width:185px;'>
1148 END
1149 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) {
1150 if($ccdhost{$key}[3] eq 'net'){
1151 print"<option ";
1152 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ccdhost{$key}[1]);
1153 print ">$ccdhost{$key}[1]</option>";
1154 }
1155 }
1156 print<<END;
1157 </select></td></tr>
1158
1159 <tr><td valign='top'><input type='radio' name='grp1' value='cust_grp_src' $checked{'grp1'}{'cust_grp_src'}></td><td >$Lang::tr{'fwhost cust grp'}</td><td><select name='cust_grp_src' style='min-width:185px;'>
1160 END
1161 foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } keys %customgrp) {
1162 if($helper ne $customgrp{$key}[0]){
1163 print"<option ";
1164 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $customgrp{$key}[0]);
1165 print ">$customgrp{$key}[0]</option>";
1166 }
1167 $helper=$customgrp{$key}[0];
1168 }
1169 print<<END;
1170 </select></td>
1171 <td valign='top'><input type='radio' name='grp1' value='ipsec_net_src' $checked{'grp1'}{'ipsec_net_src'}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td><select name='ipsec_net_src' style='min-width:185px;'>
1172 END
1173 foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1174 if ($ipsecconf{$key}[3] eq 'net'){
1175 print "<option ";
1176 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ipsecconf{$key}[1]);
1177 print ">$ipsecconf{$key}[1]</option>";
1178 }
1179 }
1180 #sourceport
1181 print<<END;
1182 </select></td></tr>
1183 END
1184
1185 # <td valign='top'><input type='radio' name='grp1' value='ipsec_host_src' $checked{'grp1'}{'ipsec_host_src'}></td><td >$Lang::tr{'fwhost ipsec host'}</td><td><select name='ipsec_host_src' style='min-width:185px;'>
1186 #END
1187 # foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1188 # if ($ipsecconf{$key}[3] eq 'host'){
1189 # print "<option ";
1190 # print "selected='selected'" if($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ipsecconf{$key}[1]);
1191 # print ">$ipsecconf{$key}[1]</option>";
1192 # }
1193 # }
1194 print<<END;
1195 <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
1196 <table width='100%' border='0'>
1197 <tr><td width='1%'><input type='checkbox' name='USE_SRC_PORT' value='ON' $checked{'USE_SRC_PORT'}{'ON'}></td><td width='51%' colspan='3'>$Lang::tr{'fwdfw use srcport'}</td>
1198 <td width='15%' nowrap='nowrap'>$Lang::tr{'fwdfw man port'}</td><td><select name='PROT'>
1199 END
1200 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
1201 {
1202 if ($_ eq $fwdfwsettings{'PROT'})
1203 {
1204 print"<option selected>$_</option>";
1205 }else{
1206 print"<option>$_</option>";
1207 }
1208 }
1209 $fwdfwsettings{'SRC_PORT'}=~ s/\|/,/g;
1210 print<<END;
1211 </select></td><td align='right'><input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18' ></td></tr>
1212 <tr><td></td><td></td><td></td><td></td><td nowrap='nowrap'>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TYPES'>
1213 END
1214 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1215 print"<option>All ICMP-Types</option>";
1216 foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) } keys %icmptypes){
1217 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1218 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1219 }else{
1220 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1221 }
1222 }
1223 print<<END;
1224 </select></td></tr></table><hr>
1225 END
1226 &Header::closebox();
1227
1228 #---TARGET------------------------------------------------------
1229 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw target'});
1230 print<<END;
1231 <table width='100%' border='0'>
1232 <tr><td width='1%'><input type='radio' name='grp2' value='tgt_addr' checked></td><td colspan='2'>$Lang::tr{'fwdfw targetip'}<input type='TEXT' name='tgt_addr' value='$fwdfwsettings{'tgt_addr'}' size='16'><td><input type='radio' name='grp2' value='ipfire' $checked{'grp2'}{'ipfire'}></td><td><b>IPFire ($Lang::tr{'external access'})</b></td><td><select name='ipfire' style='min-width:185px;'>
1233 END
1234 print "<option value='Default IP' $selected{'ipfire'}{'Default IP'}>Default IP</option>";
1235
1236 foreach my $alias (sort keys %aliases)
1237 {
1238 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1239 }
1240
1241 print<<END;
1242 </td></tr>
1243 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr>
1244 <tr><td width='1%'><input type='radio' name='grp2' value='std_net_tgt' $checked{'grp2'}{'std_net_tgt'}></td><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost stdnet'}</td><td width='13%'><select name='std_net_tgt' style='min-width:185px;'>
1245 END
1246 foreach my $network (sort keys %defaultNetworks)
1247 {
1248 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1249 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $defaultNetworks{$network}{'NAME'});
1250 print ">$network</option>";
1251 }
1252 print<<END;
1253 </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_net_tgt' $checked{'grp2'}{'ovpn_net_tgt'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_net_tgt' style='min-width:185px;'>
1254 END
1255 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{'grp2'}});
1256 print<<END;
1257 </select></td></tr>
1258 <tr><td><input type='radio' name='grp2' value='cust_net_tgt' $checked{'grp2'}{'cust_net_tgt'}></td><td>$Lang::tr{'fwhost cust net'}</td><td><select name='cust_net_tgt' style='min-width:185px;'>
1259 END
1260 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{'grp2'}});
1261 print<<END;
1262 </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_host_tgt' $checked{'grp2'}{'ovpn_host_tgt'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_host_tgt' style='min-width:185px;'>
1263 END
1264 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost)
1265 {
1266 if ($ccdhost{$key}[33] ne ''){
1267 print "<option value='$ccdhost{$key}[1]' ";
1268 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ccdhost{$key}[33]);
1269 print ">$ccdhost{$key}[1]</option>";
1270 }
1271 }
1272 print<<END;
1273 </select></td></tr>
1274 <tr><td valign='top'><input type='radio' name='grp2' value='cust_host_tgt' $checked{'grp2'}{'cust_host_tgt'}></td><td>$Lang::tr{'fwhost cust addr'}</td><td><select name='cust_host_tgt' style='min-width:185px;'>
1275 END
1276 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{'grp2'}});
1277 print<<END;
1278 </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_n2n_tgt' $checked{'grp2'}{'ovpn_n2n_tgt'}></td><td >$Lang::tr{'fwhost ovpn_n2n'}</td><td colspan='3'><select name='ovpn_n2n_tgt' style='min-width:185px;'>
1279 END
1280 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) {
1281 if($ccdhost{$key}[3] eq 'net'){
1282 print "<option ";
1283 print "selected='selected'" if($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ccdhost{$key}[1]);
1284 print ">$ccdhost{$key}[1]</option>";
1285 }
1286 }
1287 print<<END;
1288 </select></td></tr>
1289 <tr><td valign='top'><input type='radio' name='grp2' value='cust_grp_tgt' $checked{'grp2'}{'cust_grp_tgt'}></td><td >$Lang::tr{'fwhost cust grp'}</td><td><select name='cust_grp_tgt' style='min-width:185px;'>
1290 END
1291 $helper='';
1292 foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } keys %customgrp) {
1293 if($helper ne $customgrp{$key}[0]){
1294 print"<option ";
1295 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $customgrp{$key}[0]);
1296 print">$customgrp{$key}[0]</option>";
1297 }
1298 $helper=$customgrp{$key}[0];
1299 }
1300 print<<END;
1301 </select></td>
1302 <td valign='top'><input type='radio' name='grp2' value='ipsec_net_tgt' $checked{'grp2'}{'ipsec_net_tgt'}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td><select name='ipsec_net_tgt' style='min-width:185px;'>
1303 END
1304 foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1305 if ($ipsecconf{$key}[3] eq 'net'){
1306 print"<option ";
1307 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ipsecconf{$key}[1]);
1308 print">$ipsecconf{$key}[1]</option>";
1309 }
1310 }
1311 print<<END;
1312 </select></td></tr>
1313 END
1314 # <td valign='top'><input type='radio' name='grp2' value='ipsec_host_tgt' $checked{'grp2'}{'ipsec_host_tgt'}></td><td >$Lang::tr{'fwhost ipsec host'}</td><td><select name='ipsec_host_tgt' style='min-width:185px;'>
1315 #END
1316 # foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1317 # if ($ipsecconf{$key}[3] eq 'host'){
1318 # print"<option ";
1319 # print"selected='Selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ipsecconf{$key}[1]);
1320 # print">$ipsecconf{$key}[1]</option>";
1321 # }
1322 # }
1323 print<<END;
1324 </table>
1325 <b>$Lang::tr{'fwhost attention'}:</b><br>
1326 $Lang::tr{'fwhost macwarn'}<br><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; '></hr><br>
1327
1328 <table width='100%' border='0'>
1329 <tr><td width='1%'><input type='checkbox' name='USESRV' value='ON' $checked{'USESRV'}{'ON'} ></td><td width='48%'>$Lang::tr{'fwdfw use srv'}</td><td width='1%'><input type='radio' name='grp3' value='cust_srv' checked></td><td nowrap='nowrap'>$Lang::tr{'fwhost cust service'}</td><td width='1%' colspan='2'><select name='cust_srv'style='min-width:230px;' >
1330 END
1331 &General::readhasharray("$configsrv", \%customservice);
1332 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
1333 print"<option ";
1334 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1335 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1336 }
1337 print<<END;
1338 </select></td></tr>
1339 <tr><td colspan='2'></td><td><input type='radio' name='grp3' value='cust_srvgrp' $checked{'grp3'}{'cust_srvgrp'}></td><td nowrap='nowrap'>$Lang::tr{'fwhost cust srvgrp'}:</td><td colspan='2'><select name='cust_srvgrp'style='min-width:230px;' >
1340 END
1341 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1342 my $helper;
1343 foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){
1344 if ($helper ne $customservicegrp{$key}[0]){
1345 print"<option ";
1346 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1347 print">$customservicegrp{$key}[0]</option>";
1348 }
1349 $helper=$customservicegrp{$key}[0];
1350 }
1351 print<<END;
1352 </select></td></tr>
1353 <tr><td colspan='2'></td><td><input type='radio' name='grp3' value='TGT_PORT' $checked{'grp3'}{'TGT_PORT'}></td><td>$Lang::tr{'fwdfw man port'}</td><td><select name='TGT_PROT'>
1354 END
1355 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
1356 {
1357 if ($_ eq $fwdfwsettings{'TGT_PROT'})
1358 {
1359 print"<option selected>$_</option>";
1360 }else{
1361 print"<option>$_</option>";
1362 }
1363 }
1364 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
1365 print<<END;
1366 </select></td><td align='right'><input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18' ></td></tr>
1367 <tr><td colspan='2'></td><td></td><td>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TGT'>
1368 END
1369 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1370 print"<option>All ICMP-Types</option>";
1371 foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) }keys %icmptypes){
1372 if($fwdfwsettings{'ICMP_TGT'} eq "$icmptypes{$key}[0]"){
1373 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1374 }else{
1375 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1376 }
1377 }
1378 print<<END;
1379 </select></td></tr>
1380 </table><hr><br><br>
1381
1382 END
1383 #---Activate/logging/remark-------------------------------------
1384 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw additional'});
1385 print<<END;
1386 <table width='100%' border='0'>
1387 <tr><td width='12%'>$Lang::tr{'remark'}:</td><td align='left'><input type='text' name='ruleremark' size='40' maxlength='255' value='$fwdfwsettings{'ruleremark'}'></td></tr>
1388 END
1389 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
1390 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
1391 for (my $count =1; $count <= $sum; $count++){
1392 print"<option value='$count' ";
1393 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
1394 print">$count</option>";
1395 }
1396 print"</select></td></tr>";
1397 }else{
1398 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
1399 }
1400
1401 print<<END;
1402 </table><table width='100%'>
1403 <tr><td width='1%'><input type='checkbox' name='ACTIVE' value='ON' $checked{'ACTIVE'}{'ON'}></td><td>$Lang::tr{'fwdfw rule activate'}</td></tr>
1404 <tr><td width='1%'><input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'} ></td><td>$Lang::tr{'fwdfw log rule'}</td></tr>
1405 </table><hr><br>
1406 END
1407 &Header::closebox();
1408 #---ADD TIMEFRAME-----------------------------------------------
1409 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw timeframe'});
1410 print<<END;
1411 <table width='70%' border='0'>
1412 <tr><td width='1%'><input type='checkbox' name='TIME' value='ON' $checked{'TIME'}{'ON'}></td><td colspan='4'>$Lang::tr{'fwdfw timeframe'}</td></tr>
1413 <tr><td colspan='7'>&nbsp</td></tr>
1414 <tr>
1415 <td align='left'>$Lang::tr{'time'}:</td>
1416 <td width='30%' align='left'>$Lang::tr{'advproxy monday'} $Lang::tr{'advproxy tuesday'} $Lang::tr{'advproxy wednesday'} $Lang::tr{'advproxy thursday'} $Lang::tr{'advproxy friday'} $Lang::tr{'advproxy saturday'} $Lang::tr{'advproxy sunday'}</td>
1417 <td width='15%' align='left'>$Lang::tr{'advproxy from'}</td>
1418 <td width='15%' align='left'>$Lang::tr{'advproxy to'}</td>
1419 </tr>
1420 <tr>
1421 <td align='right'></td>
1422 <td width='30%' align='left'>
1423 <input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} />
1424 <input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} />
1425 <input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} />
1426 <input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} />
1427 <input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} />
1428 <input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} />
1429 <input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} />
1430 </td>
1431 <td><select name='TIME_FROM'>
1432 END
1433 for (my $i=0;$i<=23;$i++) {
1434 $i = sprintf("%02s",$i);
1435 for (my $j=0;$j<=45;$j+=15) {
1436 $j = sprintf("%02s",$j);
1437 my $time = $i.":".$j;
1438 print "\t\t\t\t\t<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
1439 }
1440 }
1441 print<<END;
1442 </select></td>
1443 <td><select name='TIME_TO'>
1444 END
1445 for (my $i=0;$i<=23;$i++) {
1446 $i = sprintf("%02s",$i);
1447 for (my $j=0;$j<=45;$j+=15) {
1448 $j = sprintf("%02s",$j);
1449 my $time = $i.":".$j;
1450 print "\t\t\t\t\t<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
1451 }
1452 }
1453 print<<END;
1454 </select></td></tr>
1455 </table><hr>
1456 END
1457 &Header::closebox();
1458 #---ACTION------------------------------------------------------
1459 if($fwdfwsettings{'updatefwrule'} ne 'on'){
1460 print<<END;
1461 <table border='0' width='100%'>
1462 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
1463 <input type='hidden' name='config' value='$config' >
1464 <input type='hidden' name='ACTION' value='saverule' >
1465 </form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'><input type='hidden' name='ACTION' value'reset'></td></td>
1466 </table></form>
1467 END
1468 }else{
1469 print<<END;
1470 <table border='0' width='100%'>
1471 <tr><td align='right'><input type='submit' value='$Lang::tr{'fwdfw change'}' style='min-width:100px;' /><input type='hidden' name='updatefwrule' value='$fwdfwsettings{'updatefwrule'}'><input type='hidden' name='key' value='$fwdfwsettings{'key'}'>
1472 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
1473 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
1474 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
1475 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
1476 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
1477 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
1478 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
1479 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
1480 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
1481 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
1482 <input type='hidden' name='ACTION' value='saverule' ></form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'><input type='hidden' name='ACTION' value'reset'></td></td>
1483 </table></form>
1484 END
1485 }
1486 &Header::closebox();
1487 }
1488 sub saverule
1489 {
1490 my $hash=shift;
1491 my $config=shift;
1492 &General::readhasharray("$config", $hash);
1493 if (!$errormessage){
1494 if ($fwdfwsettings{'updatefwrule'} ne 'on'){
1495 my $key = &General::findhasharraykey ($hash);
1496 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1497 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1498 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1499 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1500 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1501 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1502 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1503 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1504 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1505 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1506 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1507 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1508 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1509 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1510 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1511 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1512 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1513 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1514 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1515 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1516 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1517 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1518 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1519 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1520 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1521 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1522 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1523 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
1524 &General::writehasharray("$config", $hash);
1525 }else{
1526 foreach my $key (sort {$a <=> $b} keys %$hash){
1527 if($key eq $fwdfwsettings{'key'}){
1528 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1529 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1530 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1531 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1532 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1533 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1534 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1535 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1536 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1537 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1538 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1539 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1540 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1541 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1542 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1543 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1544 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1545 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1546 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1547 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1548 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1549 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1550 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1551 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1552 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1553 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1554 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1555 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
1556 last;
1557 }
1558 }
1559 }
1560 &General::writehasharray("$config", $hash);
1561 if($fwdfwsettings{'oldrulenumber'} gt $fwdfwsettings{'rulepos'}){
1562 my %tmp=();
1563 my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'};
1564 for (my $z=0;$z<$val;$z++){
1565 foreach my $key (sort {$a <=> $b} keys %$hash){
1566 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
1567 my $last = $key -1;
1568 if (exists $$hash{$last}){
1569 #save rule last
1570 foreach my $y (0 .. $#{$$hash{$last}}) {
1571 $tmp{0}[$y] = $$hash{$last}[$y];
1572 }
1573 #copy active rule to last
1574 foreach my $i (0 .. $#{$$hash{$last}}) {
1575 $$hash{$last}[$i] = $$hash{$key}[$i];
1576 }
1577 #copy saved rule to actual position
1578 foreach my $x (0 .. $#{$tmp{0}}) {
1579 $$hash{$key}[$x] = $tmp{0}[$x];
1580 }
1581 }
1582 }
1583 }
1584 $fwdfwsettings{'oldrulenumber'}--;
1585 }
1586 &General::writehasharray("$config", $hash);
1587 &rules;
1588 }elsif($fwdfwsettings{'rulepos'} gt $fwdfwsettings{'oldrulenumber'}){
1589 my %tmp=();
1590 my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
1591 for (my $z=0;$z<$val;$z++){
1592 foreach my $key (sort {$a <=> $b} keys %$hash){
1593 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
1594 my $next = $key + 1;
1595 if (exists $$hash{$next}){
1596 #save rule next
1597 foreach my $y (0 .. $#{$$hash{$next}}) {
1598 $tmp{0}[$y] = $$hash{$next}[$y];
1599 }
1600 #copy active rule to next
1601 foreach my $i (0 .. $#{$$hash{$next}}) {
1602 $$hash{$next}[$i] = $$hash{$key}[$i];
1603 }
1604 #copy saved rule to actual position
1605 foreach my $x (0 .. $#{$tmp{0}}) {
1606 $$hash{$key}[$x] = $tmp{0}[$x];
1607 }
1608 }
1609 }
1610 }
1611 $fwdfwsettings{'oldrulenumber'}++;
1612 }
1613 &General::writehasharray("$config", $hash);
1614 &rules;
1615 }
1616 }
1617 }
1618 sub error
1619 {
1620 if ($errormessage) {
1621 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1622 print "<class name='base'>$errormessage\n";
1623 print "&nbsp;</class>\n";
1624 &Header::closebox();
1625 print"<hr>";
1626 }
1627 }
1628 sub hint
1629 {
1630 if ($hint) {
1631 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1632 print "<class name='base'>$hint\n";
1633 print "&nbsp;</class>\n";
1634 &Header::closebox();
1635 print"<hr>";
1636 }
1637 }
1638 sub get_name
1639 {
1640 my $val=shift;
1641 &General::setup_default_networks(\%defaultNetworks);
1642 foreach my $network (sort keys %defaultNetworks)
1643 {
1644 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1645 }
1646 }
1647 sub validremark
1648 {
1649 # Checks a hostname against RFC1035
1650 my $remark = $_[0];
1651
1652 # Each part should be at least two characters in length
1653 # but no more than 63 characters
1654 if (length ($remark) < 1 || length ($remark) > 255) {
1655 return 0;}
1656 # Only valid characters are a-z, A-Z, 0-9 and -
1657 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:_\/\s]*$/) {
1658 return 0;}
1659 # First character can only be a letter or a digit
1660 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
1661 return 0;}
1662 # Last character can only be a letter or a digit
1663 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.]*$/) {
1664 return 0;}
1665 return 1;
1666 }
1667 sub getsrcport
1668 {
1669 my %hash=%{(shift)};
1670 my $key=shift;
1671 if($hash{$key}[7] eq 'ON' && $hash{$key}[8] ne '' && $hash{$key}[10]){
1672 $hash{$key}[10]=~ s/\|/,/g;
1673 print": $hash{$key}[10]";
1674 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
1675 print": <br>$hash{$key}[9] ";
1676 }
1677 }
1678 sub gettgtport
1679 {
1680 my %hash=%{(shift)};
1681 my $key=shift;
1682 my $service;
1683 my $prot;
1684 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1685 if($hash{$key}[14] eq 'cust_srv'){
1686 &General::readhasharray("$configsrv", \%customservice);
1687 foreach my $i (sort keys %customservice){
1688 if($customservice{$i}[0] eq $hash{$key}[15]){
1689 $service = $customservice{$i}[0];
1690 }
1691 }
1692 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
1693 $service=$hash{$key}[15];
1694 }elsif($hash{$key}[14] eq 'TGT_PORT'){
1695 $hash{$key}[15]=~ s/\|/,/g;
1696 $service=$hash{$key}[15];
1697 }
1698 if($service){
1699 print": $service";
1700 }
1701 }elsif($hash{$key}[11] eq 'ON' && $hash{$key}[12] eq 'ICMP'){
1702 print":<br>$hash{$key}[13]";
1703 }
1704 }
1705 sub get_serviceports
1706 {
1707 my $type=shift;
1708 my $name=shift;
1709 &General::readhasharray("$configsrv", \%customservice);
1710 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1711 my $protocols;
1712 my $tcp;
1713 my $udp;
1714 if($type eq 'service'){
1715 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
1716 if ($customservice{$key}[0] eq $name){
1717 $protocols=$customservice{$key}[2];
1718 }
1719 }
1720
1721 }elsif($type eq 'group'){
1722 foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){
1723 if ($customservicegrp{$key}[0] eq $name){
1724 if($customservicegrp{$key}[4] eq 'TCP'){$tcp='TCP';}else{$udp='UDP';}
1725 }
1726 }
1727 }
1728 if($tcp){$protocols.="TCP";}
1729 if($udp){$protocols.=",UDP";}
1730 return $protocols;
1731 }
1732 sub viewtablerule
1733 {
1734 &viewtablenew(\%configfwdfw,$configfwdfw,$Lang::tr{'fwdfw rules'},"Forward" );
1735 &viewtablenew(\%configinputfw,$configinput,"",$Lang::tr{'external access'} );
1736 }
1737 sub viewtablenew
1738 {
1739 my $hash=shift;
1740 my $config=shift;
1741 my $title=shift;
1742 my $title1=shift;
1743
1744 if ( ! -z "$config"){
1745 &Header::openbox('100%', 'left',$title);
1746 my $count=0;
1747 my ($gif,$log);
1748 my $ruletype;
1749 my $rulecolor;
1750 my $tooltip;
1751 my @tmpsrc=();
1752 my $coloryellow='';
1753 &General::readhasharray("$config", $hash);
1754 print"<b>$title1</b><br>";
1755 print"<table width='100%' border='0' cellspacing='1' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;'>";
1756 print"<tr><td align='center' width='1%'><b>#</td><td width='1%'></td><td align='center' ><b>$Lang::tr{'fwdfw source'}</td><td width='1%'><b>Log</td><td align='center' width='20%'><b>$Lang::tr{'fwdfw target'}</td><td align='center'><b>$Lang::tr{'protocol'}</b></td><td align='center' width='70%'><b>$Lang::tr{'remark'}</td><td align='center' colspan='3' width='1%'><b>$Lang::tr{'fwdfw action'}</td></tr>";
1757 foreach my $key (sort {$a <=> $b} keys %$hash){
1758 @tmpsrc=();
1759 #check if vpn hosts/nets have been deleted
1760 if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){
1761 push (@tmpsrc,$$hash{$key}[4]);
1762 }
1763 if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){
1764 push (@tmpsrc,$$hash{$key}[6]);
1765 }
1766 foreach my $host (@tmpsrc){
1767 if($$hash{$key}[3] eq 'ipsec_net_src' || $$hash{$key}[5] eq 'ipsec_net_tgt'){
1768 if(&fwlib::get_ipsec_net_ip($host,11) eq ''){
1769 $coloryellow='on';
1770 &disable_rule($key);
1771 $$hash{$key}[2]='';
1772 }
1773 }elsif($$hash{$key}[3] eq 'ovpn_net_src' || $$hash{$key}[5] eq 'ovpn_net_tgt'){
1774 if(&fwlib::get_ovpn_net_ip($host,1) eq ''){
1775 $coloryellow='on';
1776 &disable_rule($key);
1777 $$hash{$key}[2]='';
1778 }
1779 }elsif($$hash{$key}[3] eq 'ovpn_n2n_src' || $$hash{$key}[5] eq 'ovpn_n2n_tgt'){
1780 if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){
1781 $coloryellow='on';
1782 &disable_rule($key);
1783 $$hash{$key}[2]='';
1784 }
1785 }elsif($$hash{$key}[3] eq 'ovpn_host_src' || $$hash{$key}[5] eq 'ovpn_host_tgt'){
1786 if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
1787 $coloryellow='on';
1788 &disable_rule($key);
1789 $$hash{$key}[2]='';
1790 }
1791 }
1792 $$hash{$key}[3]='';
1793 $$hash{$key}[5]='';
1794 }
1795 $$hash{'ACTIVE'}=$$hash{$key}[2];
1796 $count++;
1797 if($coloryellow eq 'on'){
1798 print"<tr bgcolor='$color{'color14'}' >";
1799 $coloryellow='';
1800 }elsif($coloryellow eq ''){
1801 if ($count % 2){
1802 print"<tr bgcolor='$color{'color22'}' >";
1803 }
1804 else{
1805 print"<tr bgcolor='$color{'color20'}' >";
1806 }
1807 }
1808 print<<END;
1809 <td align='right'>$key</td>
1810 END
1811 if ($$hash{$key}[0] eq 'ACCEPT'){
1812 $ruletype='A';
1813 $tooltip='ACCEPT';
1814 $rulecolor=$color{'color17'};
1815 }elsif($$hash{$key}[0] eq 'DROP'){
1816 $ruletype='D';
1817 $tooltip='DROP';
1818 $rulecolor=$color{'color25'};
1819 }elsif($$hash{$key}[0] eq 'REJECT'){
1820 $ruletype='R';
1821 $tooltip='REJECT';
1822 $rulecolor=$color{'color16'};
1823 }
1824 print"<td bgcolor='$rulecolor' width='2%' align='center'><span title='$tooltip'><b>$ruletype</b></span></td>";
1825 print"<td align='center' nowrap='nowrap'>";
1826 if ($$hash{$key}[3] eq 'std_net_src'){
1827 print &get_name($$hash{$key}[4]);
1828 }else{
1829 print $$hash{$key}[4];
1830 }
1831 &getsrcport(\%$hash,$key);
1832 if ($$hash{$key}[17] eq 'ON'){
1833 $log="/images/on.gif";
1834 }else{
1835 $log="/images/off.gif";
1836 }
1837 print<<END;
1838 </td>
1839 <form method='post'>
1840 <td width='1%' align='left'><input type='image' img src='$log' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw togglelog'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;'/>
1841 <input type='hidden' name='key' value='$key' />
1842 <input type='hidden' name='config' value='$config' />
1843 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw togglelog'}' />
1844 </td></form>
1845 END
1846
1847 print<<END;
1848 <td align='center' nowrap='nowrap'>
1849 END
1850 if ($$hash{$key}[5] eq 'std_net_tgt'){
1851 print &get_name($$hash{$key}[6]);
1852 }else{
1853 print $$hash{$key}[6];
1854 }
1855 &gettgtport(\%$hash,$key);
1856 ################################################################################
1857 print"</td>";
1858 #Get Protocol
1859 my $prot;
1860 if ($$hash{$key}[12]){ #target prot if manual
1861 $prot=$$hash{$key}[12];
1862 }elsif($$hash{$key}[8]){ #source prot if manual
1863 $prot=$$hash{$key}[8];
1864 }elsif($$hash{$key}[14] eq 'cust_srv'){
1865 $prot=&get_serviceports("service",$$hash{$key}[15]);
1866 }elsif($$hash{$key}[14] eq 'cust_srvgrp'){
1867 $prot=&get_serviceports("group",$$hash{$key}[15]);
1868 }else{
1869 $prot=$Lang::tr{'all'};
1870 }
1871 print"<td align='center'>$prot</td>";
1872
1873 print"<td width='20%'>$$hash{$key}[16]</td>";
1874
1875 if($$hash{$key}[2] eq 'ON'){
1876 $gif="/images/on.gif"
1877
1878 }else{
1879 $gif="/images/off.gif"
1880 }
1881 print<<END;
1882 <form method='post'>
1883 <td width='1%'><input type='image' img src='$gif' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw toggle'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
1884 <input type='hidden' name='key' value='$key' />
1885 <input type='hidden' name='config' value='$config' />
1886 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw toggle'}' />
1887 </td></form>
1888 <form method='post'>
1889 <td width='1%' ><input type='image' img src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'fwdfw edit'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
1890 <input type='hidden' name='key' value='$key' />
1891 <input type='hidden' name='config' value='$config' />
1892 <input type='hidden' name='ACTION' value='editrule' />
1893 </td></form></td>
1894 <form method='post'>
1895 <td width='1%'><input type='image' img src='/images/addblue.gif' alt='$Lang::tr{'fwdfw copy'}' title='$Lang::tr{'fwdfw copy'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
1896 <input type='hidden' name='key' value='$key' />
1897 <input type='hidden' name='config' value='$config' />
1898 <input type='hidden' name='ACTION' value='copyrule' />
1899 </td></form></td>
1900 <form method='post'>
1901 <td width='1%' ><input type='image' img src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'fwdfw delete'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
1902 <input type='hidden' name='key' value='$key' />
1903 <input type='hidden' name='config' value='$config' />
1904 <input type='hidden' name='ACTION' value='deleterule' />
1905 </td></form></td>
1906 END
1907 if (exists $$hash{$key-1}){
1908 print<<END;
1909 <form method='post'>
1910 <td width='1%'><input type='image' img src='/images/up.gif' alt='$Lang::tr{'fwdfw moveup'}' title='$Lang::tr{'fwdfw moveup'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
1911 <input type='hidden' name='key' value='$key' />
1912 <input type='hidden' name='config' value='$config' />
1913 <input type='hidden' name='ACTION' value='moveup' />
1914 </td></form></td>
1915 END
1916 }else{
1917 print"<td></td>";
1918 }
1919 if (exists $$hash{$key+1}){
1920 print<<END;
1921 <form method='post'>
1922 <td width='1%' ><input type='image' img src='/images/down.gif' alt='$Lang::tr{'fwdfw movedown'}' title='$Lang::tr{'fwdfw movedown'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
1923 <input type='hidden' name='key' value='$key' />
1924 <input type='hidden' name='config' value='$config' />
1925 <input type='hidden' name='ACTION' value='movedown' />
1926 </td></form></td></tr>
1927 END
1928 }else{
1929 print"<td></td></tr>";
1930 }
1931 #if timeframe set, print new line in table
1932 if ($$hash{$key}[18] eq 'ON'){
1933 my @days=();
1934 if($$hash{$key}[19] ne ''){push (@days,$Lang::tr{'fwdfw wd_mon'});}
1935 if($$hash{$key}[20] ne ''){push (@days,$Lang::tr{'fwdfw wd_tue'});}
1936 if($$hash{$key}[21] ne ''){push (@days,$Lang::tr{'fwdfw wd_wed'});}
1937 if($$hash{$key}[22] ne ''){push (@days,$Lang::tr{'fwdfw wd_thu'});}
1938 if($$hash{$key}[23] ne ''){push (@days,$Lang::tr{'fwdfw wd_fri'});}
1939 if($$hash{$key}[24] ne ''){push (@days,$Lang::tr{'fwdfw wd_sat'});}
1940 if($$hash{$key}[25] ne ''){push (@days,$Lang::tr{'fwdfw wd_sun'});}
1941 my $weekdays=join(",",@days);
1942 if (@days){
1943 print"<tr bgcolor='#FFE4B5'><td colspan='6'>$Lang::tr{'fwdfw time'} ";
1944 print"$weekdays";
1945 print "&nbsp $Lang::tr{'fwdfw from'} $$hash{$key}[26] &nbsp $Lang::tr{'fwdfw till'} $$hash{$key}[27]</td><td colspan='8'></d></tr>";
1946 }
1947 }
1948 }
1949 print"</table>";
1950 &Header::closebox();
1951 }
1952 }
1953 sub p2pblock
1954 {
1955 my $gif;
1956 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
1957 @p2ps = <FILE>;
1958 close FILE;
1959 &Header::openbox('100%', 'center', 'P2P-Block');
1960 print <<END;
1961 <table width='35%' border='0'>
1962 <tr bgcolor='$color{'color22'}'><td align=center colspan='2' ><b>$Lang::tr{'protocol'}</b></td><td align='center'><b>$Lang::tr{'status'}</b></td></tr>
1963 END
1964 foreach my $p2pentry (sort @p2ps)
1965 {
1966 my @p2pline = split( /\;/, $p2pentry );
1967 if($p2pline[2] eq 'on'){
1968 $gif="/images/on.gif"
1969 }else{
1970 $gif="/images/off.gif"
1971 }
1972 print <<END;
1973 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1974 <tr bgcolor='$color{'color20'}'>
1975 <td align='center' colspan='2' >$p2pline[0]:</td><td align='center'><input type='hidden' name='P2PROT' value='$p2pline[1]' /><input type='image' img src='$gif' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw toggle'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' ><input type='hidden' name='ACTION' value='togglep2p'></td></tr></form>
1976 END
1977 }
1978 print"<tr><td><img src='/images/on.gif'></td><td align='left'>$Lang::tr{'outgoing firewall p2p allow'}</td></tr>";
1979 print"<tr><td><img src='/images/off.gif'></td><td align='left'>$Lang::tr{'outgoing firewall p2p deny'}</td></tr></table>";
1980 &Header::closebox();
1981 }
1982 sub fillselect
1983 {
1984 my %hash=%{(shift)};
1985 my $val=shift;
1986 my $key;
1987 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
1988 if($hash{$key}[0] eq $val){
1989 print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>";
1990 }else{
1991 print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>";
1992 }
1993 }
1994 }
1995 sub rules
1996 {
1997 if (!-f "${General::swroot}/forward/reread"){
1998 system("touch ${General::swroot}/forward/reread");
1999 }
2000 }
2001 sub reread_rules
2002 {
2003 system("/usr/local/bin/forwardfwctrl");
2004 system("rm ${General::swroot}/forward/reread");
2005 }
2006 &Header::closebigbox();
2007 &Header::closepage();