]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/firewall.cgi
Merge branch 'master' of ssh://git.ipfire.org/pub/git/ipfire-2.x into seventeen-geoip
[ipfire-2.x.git] / html / cgi-bin / firewall.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 Alexander Marx <amarx@ipfire.org> #
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 use strict;
23 use Sort::Naturally;
24 use utf8;
25 use feature 'unicode_strings';
26
27 no warnings 'uninitialized';
28
29 # enable only the following on debugging purpose
30 #use warnings;
31 #use CGI::Carp 'fatalsToBrowser';
32
33 require '/var/ipfire/general-functions.pl';
34 require "${General::swroot}/lang.pl";
35 require "${General::swroot}/header.pl";
36 require "${General::swroot}/geoip-functions.pl";
37 require "/usr/lib/firewall/firewall-lib.pl";
38
39 unless (-d "${General::swroot}/firewall") { system("mkdir ${General::swroot}/firewall"); }
40 unless (-e "${General::swroot}/firewall/settings") { system("touch ${General::swroot}/firewall/settings"); }
41 unless (-e "${General::swroot}/firewall/config") { system("touch ${General::swroot}/firewall/config"); }
42 unless (-e "${General::swroot}/firewall/input") { system("touch ${General::swroot}/firewall/input"); }
43 unless (-e "${General::swroot}/firewall/outgoing") { system("touch ${General::swroot}/firewall/outgoing"); }
44
45 my %fwdfwsettings=();
46 my %selected=() ;
47 my %defaultNetworks=();
48 my %netsettings=();
49 my %customhost=();
50 my %customgrp=();
51 my %customgeoipgrp=();
52 my %customnetworks=();
53 my %customservice=();
54 my %customservicegrp=();
55 my %ccdnet=();
56 my %customnetwork=();
57 my %ccdhost=();
58 my %configfwdfw=();
59 my %configinputfw=();
60 my %configoutgoingfw=();
61 my %ipsecconf=();
62 my %color=();
63 my %mainsettings=();
64 my %checked=();
65 my %icmptypes=();
66 my %ovpnsettings=();
67 my %ipsecsettings=();
68 my %aliases=();
69 my %optionsfw=();
70 my %ifaces=();
71
72 my @PROTOCOLS = ("TCP", "UDP", "ICMP", "IGMP", "AH", "ESP", "GRE","IPv6","IPIP");
73
74 my $color;
75 my $confignet = "${General::swroot}/fwhosts/customnetworks";
76 my $confighost = "${General::swroot}/fwhosts/customhosts";
77 my $configgrp = "${General::swroot}/fwhosts/customgroups";
78 my $configgeoipgrp = "${General::swroot}/fwhosts/customgeoipgrp";
79 my $configsrv = "${General::swroot}/fwhosts/customservices";
80 my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
81 my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
82 my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
83 my $configipsec = "${General::swroot}/vpn/config";
84 my $configipsecrw = "${General::swroot}/vpn/settings";
85 my $configfwdfw = "${General::swroot}/firewall/config";
86 my $configinput = "${General::swroot}/firewall/input";
87 my $configoutgoing = "${General::swroot}/firewall/outgoing";
88 my $configovpn = "${General::swroot}/ovpn/settings";
89 my $fwoptions = "${General::swroot}/optionsfw/settings";
90 my $ifacesettings = "${General::swroot}/ethernet/settings";
91 my $errormessage='';
92 my $hint='';
93 my $ipgrp="${General::swroot}/outgoing/groups";
94 my $tdcolor='';
95 my $checkorange='';
96 my @protocols;
97 &General::readhash("${General::swroot}/firewall/settings", \%fwdfwsettings);
98 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
99 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
100 &General::readhash($fwoptions, \%optionsfw);
101 &General::readhash($ifacesettings, \%ifaces);
102 &General::readhash("$configovpn", \%ovpnsettings);
103 &General::readhash("$configipsecrw", \%ipsecsettings);
104 &General::readhasharray("$configipsec", \%ipsecconf);
105 &Header::showhttpheaders();
106 &Header::getcgihash(\%fwdfwsettings);
107 &Header::openpage($Lang::tr{'firewall rules'}, 1, '');
108 &Header::openbigbox('100%', 'center',$errormessage);
109 #### JAVA SCRIPT ####
110 print<<END;
111 <script>
112 var PROTOCOLS_WITH_PORTS = ["TCP", "UDP"];
113
114 var update_protocol = function() {
115 var protocol = \$("#protocol").val();
116
117 if (protocol === undefined)
118 return;
119
120 // Check if a template is/should be used.
121 if (protocol === "template") {
122 \$("#PROTOCOL_TEMPLATE").show();
123 } else {
124 \$("#PROTOCOL_TEMPLATE").hide();
125 }
126
127 // Check if we are dealing with a protocol, that knows ports.
128 if (\$.inArray(protocol, PROTOCOLS_WITH_PORTS) >= 0) {
129 \$("#PROTOCOL_PORTS").show();
130 } else {
131 \$("#PROTOCOL_PORTS").hide();
132 }
133
134 // Handle ICMP.
135 if (protocol === "ICMP") {
136 \$("#PROTOCOL_ICMP_TYPES").show();
137 } else {
138 \$("#PROTOCOL_ICMP_TYPES").hide();
139 }
140 };
141
142 \$(document).ready(function() {
143 \$("#protocol").change(update_protocol);
144 update_protocol();
145
146 // Show/Hide elements when NAT checkbox is checked.
147 if (\$("#USE_NAT").attr("checked")) {
148 \$("#actions").hide();
149 } else {
150 \$(".NAT").hide();
151 }
152
153 // Show NAT area when "use nat" checkbox is clicked
154 \$("#USE_NAT").change(function() {
155 \$(".NAT").toggle();
156 \$("#actions").toggle();
157 });
158
159 // Time constraints
160 if(!\$("#USE_TIME_CONSTRAINTS").attr("checked")) {
161 \$("#TIME_CONSTRAINTS").hide();
162 }
163 \$("#USE_TIME_CONSTRAINTS").change(function() {
164 \$("#TIME_CONSTRAINTS").toggle();
165 });
166
167 // Limit concurrent connections per ip
168 if(!\$("#USE_LIMIT_CONCURRENT_CONNECTIONS_PER_IP").attr("checked")) {
169 \$("#LIMIT_CON").hide();
170 }
171 \$("#USE_LIMIT_CONCURRENT_CONNECTIONS_PER_IP").change(function() {
172 \$("#LIMIT_CON").toggle();
173 });
174
175 // Rate-limit new connections
176 if(!\$("#USE_RATELIMIT").attr("checked")) {
177 \$("#RATELIMIT").hide();
178 }
179 \$("#USE_RATELIMIT").change(function() {
180 \$("#RATELIMIT").toggle();
181 });
182
183 // Automatically select radio buttons when corresponding
184 // dropdown menu changes.
185 \$("select").change(function() {
186 var id = \$(this).attr("name");
187 \$('#' + id).prop("checked", true);
188 });
189 });
190 </script>
191 END
192
193 #### ACTION #####
194
195 if ($fwdfwsettings{'ACTION'} eq 'saverule')
196 {
197 &General::readhasharray("$configfwdfw", \%configfwdfw);
198 &General::readhasharray("$configinput", \%configinputfw);
199 &General::readhasharray("$configoutgoing", \%configoutgoingfw);
200 #Set Variables according to the JQuery code in protocol section
201 if ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP')
202 {
203 if ($fwdfwsettings{'SRC_PORT'} ne '')
204 {
205 $fwdfwsettings{'USE_SRC_PORT'} = 'ON';
206 }
207 if ($fwdfwsettings{'TGT_PORT'} ne '')
208 {
209 $fwdfwsettings{'USESRV'} = 'ON';
210 $fwdfwsettings{'grp3'} = 'TGT_PORT';
211 }
212 }
213 if ($fwdfwsettings{'PROT'} eq 'template')
214 {
215 $fwdfwsettings{'USESRV'} = 'ON';
216 }
217 $errormessage=&checksource;
218 if(!$errormessage){&checktarget;}
219 if(!$errormessage){&checkrule;}
220
221 #check if manual ip (source) is orange network
222 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
223 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
224 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
225 $checkorange='on';
226 }
227 }
228 #check useless rules
229 if( ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' || $checkorange eq 'on') && $fwdfwsettings{'grp2'} eq 'ipfire'){
230 $errormessage.=$Lang::tr{'fwdfw useless rule'}."<br>";
231 }
232 #check if we try to break rules
233 if( $fwdfwsettings{'grp1'} eq 'ipfire_src' && $fwdfwsettings{'grp2'} eq 'ipfire'){
234 $errormessage=$Lang::tr{'fwdfw err same'};
235 }
236 #INPUT part
237 if($fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ORANGE'){
238 $fwdfwsettings{'config'}=$configinput;
239 $fwdfwsettings{'chain'} = 'INPUTFW';
240 my $maxkey=&General::findhasharraykey(\%configinputfw);
241 #check if we have an identical rule already
242 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
243 foreach my $key (sort keys %configinputfw){
244 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'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'},$fwdfwsettings{'LIMIT_CON_CON'},$fwdfwsettings{'concon'},$fwdfwsettings{'RATE_LIMIT'},$fwdfwsettings{'ratecon'},$fwdfwsettings{'RATETIME'}"
245 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],$configinputfw{$key}[28],$configinputfw{$key}[29],$configinputfw{$key}[30],$configinputfw{$key}[31],$configinputfw{$key}[32],$configinputfw{$key}[33],$configinputfw{$key}[34],$configinputfw{$key}[35],$configinputfw{$key}[36]"){
246 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
247 if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
248 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
249 }
250 if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && &validremark($fwdfwsettings{'ruleremark'})){
251 $errormessage='';
252 }
253 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
254 $fwdfwsettings{'nosave'} = 'on';
255 }
256 }
257 }
258 }
259 #check Rulepos on new Rule
260 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
261 $fwdfwsettings{'oldrulenumber'}=$maxkey;
262 foreach my $key (sort keys %configinputfw){
263 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'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'},$fwdfwsettings{'LIMIT_CON_CON'},$fwdfwsettings{'concon'},$fwdfwsettings{'RATE_LIMIT'},$fwdfwsettings{'ratecon'},$fwdfwsettings{'RATETIME'}"
264 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],$configinputfw{$key}[28],$configinputfw{$key}[29],$configinputfw{$key}[30],$configinputfw{$key}[31],$configinputfw{$key}[32],$configinputfw{$key}[33],$configinputfw{$key}[34],$configinputfw{$key}[35],$configinputfw{$key}[36]"){
265 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
266 }
267 }
268 }
269 #check if we just close a rule
270 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'} && $fwdfwsettings{'oldruletype'} eq $fwdfwsettings{'chain'} ) {
271 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
272 $errormessage='';
273 $fwdfwsettings{'nosave2'} = 'on';
274 }
275 }
276 if (!$errormessage){
277 if($fwdfwsettings{'nosave2'} ne 'on'){
278 &saverule(\%configinputfw,$configinput);
279 }
280 }
281 }elsif($fwdfwsettings{'grp1'} eq 'ipfire_src' ){
282 # OUTGOING PART
283 $fwdfwsettings{'config'}=$configoutgoing;
284 $fwdfwsettings{'chain'} = 'OUTGOINGFW';
285 my $maxkey=&General::findhasharraykey(\%configoutgoingfw);
286 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
287 foreach my $key (sort keys %configoutgoingfw){
288 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'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'},$fwdfwsettings{'LIMIT_CON_CON'},$fwdfwsettings{'concon'},$fwdfwsettings{'RATE_LIMIT'},$fwdfwsettings{'ratecon'},$fwdfwsettings{'RATETIME'}"
289 eq "$configoutgoingfw{$key}[0],$configoutgoingfw{$key}[2],$configoutgoingfw{$key}[3],$configoutgoingfw{$key}[4],$configoutgoingfw{$key}[5],$configoutgoingfw{$key}[6],$configoutgoingfw{$key}[7],$configoutgoingfw{$key}[8],$configoutgoingfw{$key}[9],$configoutgoingfw{$key}[10],$configoutgoingfw{$key}[11],$configoutgoingfw{$key}[12],$configoutgoingfw{$key}[13],$configoutgoingfw{$key}[14],$configoutgoingfw{$key}[15],$configoutgoingfw{$key}[17],$configoutgoingfw{$key}[18],$configoutgoingfw{$key}[19],$configoutgoingfw{$key}[20],$configoutgoingfw{$key}[21],$configoutgoingfw{$key}[22],$configoutgoingfw{$key}[23],$configoutgoingfw{$key}[24],$configoutgoingfw{$key}[25],$configoutgoingfw{$key}[26],$configoutgoingfw{$key}[27],$configoutgoingfw{$key}[28],$configoutgoingfw{$key}[29],$configoutgoingfw{$key}[30],$configoutgoingfw{$key}[31],$configoutgoingfw{$key}[32],$configoutgoingfw{$key}[33],$configoutgoingfw{$key}[34],$configoutgoingfw{$key}[35],$configoutgoingfw{$key}[36]"){
290 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
291 if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
292 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
293 }
294 if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && &validremark($fwdfwsettings{'ruleremark'})){
295 $errormessage='';
296 }
297 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
298 $fwdfwsettings{'nosave'} = 'on';
299 }
300 }
301 }
302 }
303 #check Rulepos on new Rule
304 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
305 $fwdfwsettings{'oldrulenumber'}=$maxkey;
306 foreach my $key (sort keys %configoutgoingfw){
307 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'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'},$fwdfwsettings{'LIMIT_CON_CON'},$fwdfwsettings{'concon'},$fwdfwsettings{'RATE_LIMIT'},$fwdfwsettings{'ratecon'},$fwdfwsettings{'RATETIME'}"
308 eq "$configoutgoingfw{$key}[0],$configoutgoingfw{$key}[2],$configoutgoingfw{$key}[3],$configoutgoingfw{$key}[4],$configoutgoingfw{$key}[5],$configoutgoingfw{$key}[6],$configoutgoingfw{$key}[7],$configoutgoingfw{$key}[8],$configoutgoingfw{$key}[9],$configoutgoingfw{$key}[10],$configoutgoingfw{$key}[11],$configoutgoingfw{$key}[12],$configoutgoingfw{$key}[13],$configoutgoingfw{$key}[14],$configoutgoingfw{$key}[15],$configoutgoingfw{$key}[17],$configoutgoingfw{$key}[18],$configoutgoingfw{$key}[19],$configoutgoingfw{$key}[20],$configoutgoingfw{$key}[21],$configoutgoingfw{$key}[22],$configoutgoingfw{$key}[23],$configoutgoingfw{$key}[24],$configoutgoingfw{$key}[25],$configoutgoingfw{$key}[26],$configoutgoingfw{$key}[27],$configoutgoingfw{$key}[28],$configoutgoingfw{$key}[29],$configoutgoingfw{$key}[30],$configoutgoingfw{$key}[31],$configoutgoingfw{$key}[32],$configoutgoingfw{$key}[33],$configoutgoingfw{$key}[34],$configoutgoingfw{$key}[35],$configoutgoingfw{$key}[36]"){
309 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
310 }
311 }
312 }
313 #check if we just close a rule
314 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'} && $fwdfwsettings{'oldruletype'} eq $fwdfwsettings{'chain'} ) {
315 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
316 $fwdfwsettings{'nosave2'} = 'on';
317 $errormessage='';
318 }
319 }
320 #increase counters
321 if (!$errormessage){
322 if ($fwdfwsettings{'nosave2'} ne 'on'){
323 &saverule(\%configoutgoingfw,$configoutgoing);
324 }
325 }
326 }else{
327 #FORWARD PART
328 $fwdfwsettings{'config'}=$configfwdfw;
329 $fwdfwsettings{'chain'} = 'FORWARDFW';
330 my $maxkey=&General::findhasharraykey(\%configfwdfw);
331 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
332 #check if we have an identical rule already
333 foreach my $key (sort keys %configfwdfw){
334 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{'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'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'},$fwdfwsettings{'LIMIT_CON_CON'},$fwdfwsettings{'concon'},$fwdfwsettings{'RATE_LIMIT'},$fwdfwsettings{'ratecon'},$fwdfwsettings{'RATETIME'}"
335 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}[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],$configfwdfw{$key}[28],$configfwdfw{$key}[29],$configfwdfw{$key}[30],$configfwdfw{$key}[31],$configfwdfw{$key}[32],$configfwdfw{$key}[33],$configfwdfw{$key}[34],$configfwdfw{$key}[35],$configfwdfw{$key}[36]"){
336 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
337 if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
338 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
339 }
340 if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && &validremark($fwdfwsettings{'ruleremark'})){
341 $errormessage='';
342 }
343 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
344 $fwdfwsettings{'nosave'} = 'on';
345 }
346 }
347 }
348 }
349 #check Rulepos on new Rule
350 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
351 $fwdfwsettings{'oldrulenumber'}=$maxkey;
352 foreach my $key (sort keys %configfwdfw){
353 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{'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'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'},$fwdfwsettings{'LIMIT_CON_CON'},$fwdfwsettings{'concon'},$fwdfwsettings{'RATE_LIMIT'},$fwdfwsettings{'ratecon'},$fwdfwsettings{'RATETIME'}"
354 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}[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],$configfwdfw{$key}[28],$configfwdfw{$key}[29],$configfwdfw{$key}[30],$configfwdfw{$key}[31],$configfwdfw{$key}[32],$configfwdfw{$key}[33],$configfwdfw{$key}[34],$configfwdfw{$key}[35],$configfwdfw{$key}[36]"){
355 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
356 }
357 }
358 }
359 #check if we just close a rule
360 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'} && $fwdfwsettings{'oldruletype'} eq $fwdfwsettings{'chain'}){
361 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
362 $fwdfwsettings{'nosave2'} = 'on';
363 $errormessage='';
364 }
365 }
366 #check max concurrent connections per ip address
367 if ($fwdfwsettings{'LIMIT_CON_CON'} eq 'ON'){
368 if (!($fwdfwsettings{'concon'} =~ /^(\d+)$/)) {
369 $errormessage.=$Lang::tr{'fwdfw err concon'};
370 }
371 }else{
372 $fwdfwsettings{'concon'}='';
373 }
374 #check ratelimit value
375 if ($fwdfwsettings{'RATE_LIMIT'} eq 'ON'){
376 if (!($fwdfwsettings{'ratecon'} =~ /^(\d+)$/)) {
377 $errormessage.=$Lang::tr{'fwdfw err ratecon'};
378 }
379 }else{
380 $fwdfwsettings{'ratecon'}='';
381 }
382 #increase counters
383 if (!$errormessage){
384 if ($fwdfwsettings{'nosave2'} ne 'on'){
385 &saverule(\%configfwdfw,$configfwdfw);
386 }
387 }
388 }
389 if ($errormessage){
390 &newrule;
391 }else{
392 if($fwdfwsettings{'nosave2'} ne 'on'){
393 &General::firewall_config_changed();
394 }
395 &base;
396 }
397 }
398 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw newrule'})
399 {
400 &newrule;
401 }
402 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw toggle'})
403 {
404 my %togglehash=();
405 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
406 foreach my $key (sort keys %togglehash){
407 if ($key eq $fwdfwsettings{'key'}){
408 if ($togglehash{$key}[2] eq 'ON'){$togglehash{$key}[2]='';}else{$togglehash{$key}[2]='ON';}
409 }
410 }
411 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
412 &General::firewall_config_changed();
413 &base;
414 }
415 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw togglelog'})
416 {
417 my %togglehash=();
418 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
419 foreach my $key (sort keys %togglehash){
420 if ($key eq $fwdfwsettings{'key'}){
421 if ($togglehash{$key}[17] eq 'ON'){$togglehash{$key}[17]='';}else{$togglehash{$key}[17]='ON';}
422 }
423 }
424 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
425 &General::firewall_config_changed();
426 &base;
427 }
428 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
429 {
430 &General::firewall_reload();
431 &base;
432 }
433 if ($fwdfwsettings{'ACTION'} eq 'editrule')
434 {
435 $fwdfwsettings{'updatefwrule'}='on';
436 &newrule;
437 }
438 if ($fwdfwsettings{'ACTION'} eq 'deleterule')
439 {
440 &deleterule;
441 }
442 if ($fwdfwsettings{'ACTION'} eq 'moveup')
443 {
444 &pos_up;
445 &base;
446 }
447 if ($fwdfwsettings{'ACTION'} eq 'movedown')
448 {
449 &pos_down;
450 &base;
451 }
452 if ($fwdfwsettings{'ACTION'} eq 'copyrule')
453 {
454 $fwdfwsettings{'copyfwrule'}='on';
455 &newrule;
456 }
457 if ($fwdfwsettings{'ACTION'} eq '' or $fwdfwsettings{'ACTION'} eq 'reset')
458 {
459 &base;
460 }
461 ### Functions ####
462 sub addrule
463 {
464 &error;
465
466 &Header::openbox('100%', 'left', "");
467 print <<END;
468 <form method="POST" action="">
469 <table border='0' width="100%">
470 <tr>
471 <td align='center'>
472 <input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'>
473 END
474
475 if (&General::firewall_needs_reload()) {
476 print <<END;
477 <input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-weight: bold; color: green;'>
478 END
479 }
480
481 print <<END;
482 </td>
483 </tr>
484 </table>
485 </form>
486
487 <br>
488 END
489
490 &Header::closebox();
491 &viewtablerule;
492 }
493 sub base
494 {
495 &hint;
496 &addrule;
497 }
498 sub changerule
499 {
500 my $oldchain=shift;
501 $fwdfwsettings{'updatefwrule'}='';
502 $fwdfwsettings{'config'}=$oldchain;
503 $fwdfwsettings{'nobase'}='on';
504 &deleterule;
505 }
506 sub checksource
507 {
508 my ($ip,$subnet);
509 #check ip-address if manual
510 if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){
511 #check if ip with subnet
512 if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?)$/) {
513 ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'});
514 $subnet = &General::iporsubtocidr($subnet);
515 $fwdfwsettings{'isip'}='on';
516 }
517 #check if only ip
518 if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
519 $ip=$fwdfwsettings{'src_addr'};
520 $subnet = '32';
521 $fwdfwsettings{'isip'}='on';
522 }
523
524 if ($fwdfwsettings{'isip'} ne 'on'){
525 if (&General::validmac($fwdfwsettings{'src_addr'})){
526 $fwdfwsettings{'ismac'}='on';
527 }
528 }
529 if ($fwdfwsettings{'isip'} eq 'on'){
530 ##check if ip is valid
531 if (! &General::validip($ip)){
532 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
533 return $errormessage;
534 }
535 #check and form valid IP
536 $ip=&General::ip2dec($ip);
537 $ip=&General::dec2ip($ip);
538 #check if net or broadcast
539 $fwdfwsettings{'src_addr'}="$ip/$subnet";
540 if(!&General::validipandmask($fwdfwsettings{'src_addr'})){
541 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
542 return $errormessage;
543 }
544 }
545 if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){
546 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
547 return $errormessage;
548 }
549 }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
550 $fwdfwsettings{'grp1'}='std_net_src';
551 $fwdfwsettings{$fwdfwsettings{'grp1'}} = 'ALL';
552 }
553
554 #check empty fields
555 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err nosrc'}."<br>";}
556 if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){
557 my @parts=split(",",$fwdfwsettings{'SRC_PORT'});
558 my @values=();
559 foreach (@parts){
560 chomp($_);
561 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
562 my $check;
563 #change dashes with :
564 $_=~ tr/-/:/;
565 if ($_ eq "*") {
566 push(@values,"1:65535");
567 $check='on';
568 }
569 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
570 push(@values,"1:$2");
571 $check='on';
572 }
573 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/ ) {
574 push(@values,"$1:65535");
575 $check='on'
576 }
577 $errormessage .= &General::validportrange($_, 'destination');
578 if(!$check){
579 push (@values,$_);
580 }
581 }else{
582 if (&General::validport($_)){
583 push (@values,$_);
584 }else{
585
586 }
587 }
588 }
589 $fwdfwsettings{'SRC_PORT'}=join("|",@values);
590 }
591 return $errormessage;
592 }
593 sub checktarget
594 {
595 my ($ip,$subnet);
596 &General::readhasharray("$configsrv", \%customservice);
597 #check DNAT settings (has to be single Host and single Port or portrange)
598 if ($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat'){
599 if($fwdfwsettings{'grp2'} eq 'tgt_addr' || $fwdfwsettings{'grp2'} eq 'cust_host_tgt' || $fwdfwsettings{'grp2'} eq 'ovpn_host_tgt'){
600 #check if manual ip is a single Host (if set)
601 if ($fwdfwsettings{'grp2'} eq 'tgt_addr'){
602 my @tmp= split (/\./,$fwdfwsettings{$fwdfwsettings{'grp2'}});
603 my @tmp1= split ("/",$tmp[3]);
604 if (($tmp1[0] eq "0") || ($tmp1[0] eq "255"))
605 {
606 $errormessage=$Lang::tr{'fwdfw dnat error'}."<br>";
607 return $errormessage;
608 }
609 }
610 #check if Port is a single Port or portrange
611 if ($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
612 if(($fwdfwsettings{'PROT'} ne 'TCP'|| $fwdfwsettings{'PROT'} ne 'UDP') && $fwdfwsettings{'TGT_PORT'} eq ''){
613 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
614 return $errormessage;
615 }
616 if (($fwdfwsettings{'PROT'} eq 'TCP'|| $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport($fwdfwsettings{'TGT_PORT'})){
617 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
618 return $errormessage;
619 }
620 }
621 }else{
622 if ($fwdfwsettings{'grp2'} ne 'ipfire'){
623 $errormessage=$Lang::tr{'fwdfw dnat error'}."<br>";
624 return $errormessage;
625 }
626 }
627 }
628 if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
629 #check if ip with subnet
630 if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?)$/) {
631 ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
632 $subnet = &General::iporsubtocidr($subnet);
633 }
634 #check if only ip
635 if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
636 $ip=$fwdfwsettings{'tgt_addr'};
637 $subnet='32';
638 }
639 #check if ip is valid
640 if (! &General::validip($ip)){
641 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
642 return $errormessage;
643 }
644 #check and form valid IP
645 $ip=&General::ip2dec($ip);
646 $ip=&General::dec2ip($ip);
647 $fwdfwsettings{'tgt_addr'}="$ip/$subnet";
648 if(!&General::validipandmask($fwdfwsettings{'tgt_addr'})){
649 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
650 return $errormessage;
651 }
652 }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
653 $fwdfwsettings{'grp2'}='std_net_tgt';
654 $fwdfwsettings{$fwdfwsettings{'grp2'}} = 'ALL';
655 }
656 #check for mac in targetgroup
657 if ($fwdfwsettings{'grp2'} eq 'cust_grp_tgt'){
658 &General::readhasharray("$configgrp", \%customgrp);
659 &General::readhasharray("$confighost", \%customhost);
660 foreach my $grpkey (sort keys %customgrp){
661 foreach my $hostkey (sort keys %customhost){
662 if ($customgrp{$grpkey}[2] eq $customhost{$hostkey}[0] && $customhost{$hostkey}[1] eq 'mac'){
663 $hint=$Lang::tr{'fwdfw hint mac'};
664 return $hint;
665 }
666 }
667 }
668 }
669 #check empty fields
670 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err notgt'}."<br>";}
671 #check tgt services
672 if ($fwdfwsettings{'USESRV'} eq 'ON'){
673 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
674 $fwdfwsettings{'TGT_PROT'}='';
675 $fwdfwsettings{'ICMP_TGT'}='';
676 $fwdfwsettings{'TGT_PORT'}='';
677 }
678 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
679 $fwdfwsettings{'TGT_PROT'}='';
680 $fwdfwsettings{'ICMP_TGT'}='';
681 $fwdfwsettings{'TGT_PORT'}='';
682 #check target service
683 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){
684 $errormessage.=$Lang::tr{'fwdfw err tgt_grp'};
685 }
686 }
687 if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
688 if ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP'){
689 if ($fwdfwsettings{'TGT_PORT'} ne ''){
690 if ($fwdfwsettings{'TGT_PORT'} =~ "," && $fwdfwsettings{'USE_NAT'} && $fwdfwsettings{'nat'} eq 'dnat') {
691 $errormessage=$Lang::tr{'fwdfw dnat porterr'}."<br>";
692 return $errormessage;
693 }
694 my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
695 my @values=();
696 foreach (@parts){
697 chomp($_);
698 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
699 my $check;
700 #change dashes with :
701 $_=~ tr/-/:/;
702 if ($_ eq "*") {
703 push(@values,"1:65535");
704 $check='on';
705 }
706 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
707 push(@values,"1:$2");
708 $check='on';
709 }
710 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
711 push(@values,"$1:65535");
712 $check='on'
713 }
714 $errormessage .= &General::validportrange($_, 'destination');
715 if(!$check){
716 push (@values,$_);
717 }
718 }else{
719 if (&General::validport($_)){
720 push (@values,$_);
721 }else{
722 $errormessage=$Lang::tr{'fwdfw err tgt_port'};
723 return $errormessage;
724 }
725 }
726 }
727 $fwdfwsettings{'TGT_PORT'}=join("|",@values);
728 }
729 }elsif ($fwdfwsettings{'PROT'} eq 'GRE'){
730 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
731 $fwdfwsettings{'TGT_PORT'} = '';
732 $fwdfwsettings{'ICMP_TGT'} = '';
733 }elsif ($fwdfwsettings{'PROT'} eq 'ESP'){
734 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
735 $fwdfwsettings{'TGT_PORT'} = '';
736 $fwdfwsettings{'ICMP_TGT'}='';
737 }elsif ($fwdfwsettings{'PROT'} eq 'AH'){
738 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
739 $fwdfwsettings{'TGT_PORT'} = '';
740 $fwdfwsettings{'ICMP_TGT'}='';
741 }elsif ($fwdfwsettings{'PROT'} eq 'ICMP'){
742 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
743 $fwdfwsettings{'TGT_PORT'} = '';
744 }
745 }
746 }
747 #check targetport
748 if ($fwdfwsettings{'USESRV'} ne 'ON'){
749 $fwdfwsettings{'grp3'}='';
750 $fwdfwsettings{$fwdfwsettings{'grp3'}}='';
751 $fwdfwsettings{'ICMP_TGT'}='';
752 }
753 #check timeframe
754 if($fwdfwsettings{'TIME'} eq 'ON'){
755 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 ''){
756 $errormessage=$Lang::tr{'fwdfw err time'};
757 return $errormessage;
758 }
759 }
760 return $errormessage;
761 }
762 sub check_natport
763 {
764 my $val=shift;
765 if($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
766 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\-(\d+)$/) {
767 $fwdfwsettings{'dnatport'} =~ tr/-/:/;
768 if ($fwdfwsettings{'dnatport'} eq "*") {
769 $fwdfwsettings{'dnatport'}="1:65535";
770 }
771 if ($fwdfwsettings{'dnatport'} =~ /^(\D)\:(\d+)$/) {
772 $fwdfwsettings{'dnatport'} = "1:$2";
773 }
774 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\:(\D)$/) {
775 $fwdfwsettings{'dnatport'} ="$1:65535";
776 }
777 }
778 return 1;
779 }
780 if ($val =~ "," || $val>65536 || $val<0){
781 return 0;
782 }
783 return 1;
784 }
785 sub checkrule
786 {
787 #check valid port for NAT
788 if($fwdfwsettings{'USE_NAT'} eq 'ON'){
789 #RULE_ACTION must be ACCEPT if we use NAT
790 $fwdfwsettings{'RULE_ACTION'} = 'ACCEPT';
791
792 #if no dnat or snat selected errormessage
793 if ($fwdfwsettings{'nat'} eq ''){
794 $errormessage=$Lang::tr{'fwdfw dnat nochoice'};
795 return;
796 }
797
798 #if using snat, the external port has to be empty
799 if ($fwdfwsettings{'nat'} eq 'snat' && $fwdfwsettings{'dnatport'} ne ''){
800 $errormessage=$Lang::tr{'fwdfw dnat extport'};
801 return;
802 }
803 #if no dest port is given in nat area, take target host port
804 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$fwdfwsettings{'TGT_PORT'};}
805 if($fwdfwsettings{'TGT_PORT'} eq '' && $fwdfwsettings{'dnatport'} ne '' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP')){
806 $errormessage=$Lang::tr{'fwdfw dnat porterr2'};
807 return;
808 }
809 #check if port given in nat area is a single valid port or portrange
810 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport($fwdfwsettings{'dnatport'})){
811 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
812 }elsif($fwdfwsettings{'USESRV'} eq 'ON' && $fwdfwsettings{'grp3'} eq 'cust_srv'){
813 my $custsrvport;
814 #get service Protocol and Port
815 foreach my $key (sort keys %customservice){
816 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]){
817 if ($customservice{$key}[2] ne 'TCP' && $customservice{$key}[2] ne 'UDP'){
818 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
819 }
820 $custsrvport= $customservice{$key}[1];
821 }
822 }
823 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$custsrvport;}
824 }
825 #check if DNAT port is multiple
826 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
827 my @parts=split(",",$fwdfwsettings{'dnatport'});
828 my @values=();
829 foreach (@parts){
830 chomp($_);
831 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
832 my $check;
833 #change dashes with :
834 $_=~ tr/-/:/;
835 if ($_ eq "*") {
836 push(@values,"1:65535");
837 $check='on';
838 }
839 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
840 push(@values,"1:$2");
841 $check='on';
842 }
843 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
844 push(@values,"$1:65535");
845 $check='on'
846 }
847 $errormessage .= &General::validportrange($_, 'destination');
848 if(!$check){
849 push (@values,$_);
850 }
851 }else{
852 if (&General::validport($_)){
853 push (@values,$_);
854 }else{
855
856 }
857 }
858 }
859 $fwdfwsettings{'dnatport'}=join("|",@values);
860 }
861 #check if a rule with prot tcp or udp and ports is edited and now prot is "all", then delete all ports
862 if($fwdfwsettings{'PROT'} eq ''){
863 $fwdfwsettings{'dnatport'}='';
864 }
865 }
866 #check valid remark
867 if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
868 $errormessage.=$Lang::tr{'fwdfw err remark'}."<br>";
869 }
870 #check if source and target identical
871 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL'){
872 $errormessage=$Lang::tr{'fwdfw err same'};
873 return $errormessage;
874 }
875 #get source and targetip address if possible
876 my ($sip,$scidr,$tip,$tcidr);
877 ($sip,$scidr)=&get_ip("src","grp1");
878 ($tip,$tcidr)=&get_ip("tgt","grp2");
879 #check same iprange in source and target
880 if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){
881 my $networkip1=&General::getnetworkip($sip,$scidr);
882 my $networkip2=&General::getnetworkip($tip,$tcidr);
883 if ($scidr gt $tcidr){
884 if ( &General::IpInSubnet($networkip1,$tip,&General::iporsubtodec($tcidr))){
885 $errormessage.=$Lang::tr{'fwdfw err samesub'};
886 }
887 }elsif($scidr eq $tcidr && $scidr eq '32'){
888 my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1);
889 my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2);
890 if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){
891 $hint=$Lang::tr{'fwdfw hint ip1'}."<br>";
892 $hint.=$Lang::tr{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>";
893 }
894 }else{
895 if ( &General::IpInSubnet($networkip2,$sip,&General::iporsubtodec($scidr)) ){
896 $errormessage.=$Lang::tr{'fwdfw err samesub'};
897 }
898 }
899 }
900 #when icmp selected, no source and targetport allowed
901 if (($fwdfwsettings{'PROT'} ne '' && $fwdfwsettings{'PROT'} ne 'TCP' && $fwdfwsettings{'PROT'} ne 'UDP' && $fwdfwsettings{'PROT'} ne 'template') && ($fwdfwsettings{'USESRV'} eq 'ON' || $fwdfwsettings{'USE_SRC_PORT'} eq 'ON')){
902 $errormessage.=$Lang::tr{'fwdfw err prot_port'};
903 return;
904 }
905 #change protocol if prot not equal dest single service
906 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
907 foreach my $key (sort keys %customservice){
908 if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){
909 if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){
910 $fwdfwsettings{'PROT'} = $customservice{$key}[2];
911 last;
912 }
913 }
914 }
915 }
916 #check source and destination protocol if source manual and dest servicegroup
917 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
918 $fwdfwsettings{'PROT'} = '';
919 }
920 #ATTENTION: $fwdfwsetting{'TGT_PROT'} deprecated since 30.09.2013
921 $fwdfwsettings{'TGT_PROT'}=''; #Set field empty (deprecated)
922 #Check ICMP Types
923 if ($fwdfwsettings{'PROT'} eq 'ICMP'){
924 $fwdfwsettings{'USE_SRC_PORT'}='';
925 $fwdfwsettings{'SRC_PORT'}='';
926 #$fwdfwsettings{'USESRV'}='';
927 $fwdfwsettings{'TGT_PORT'}='';
928 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
929 foreach my $key (keys %icmptypes){
930 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){
931 $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]";
932 }
933 }
934 }elsif($fwdfwsettings{'PROT'} eq 'GRE'){
935 $fwdfwsettings{'USE_SRC_PORT'}='';
936 $fwdfwsettings{'SRC_PORT'}='';
937 $fwdfwsettings{'ICMP_TYPES'}='';
938 $fwdfwsettings{'USESRV'}='';
939 $fwdfwsettings{'TGT_PORT'}='';
940 }elsif($fwdfwsettings{'PROT'} eq 'ESP'){
941 $fwdfwsettings{'USE_SRC_PORT'}='';
942 $fwdfwsettings{'SRC_PORT'}='';
943 $fwdfwsettings{'ICMP_TYPES'}='';
944 $fwdfwsettings{'USESRV'}='';
945 $fwdfwsettings{'TGT_PORT'}='';
946 }elsif($fwdfwsettings{'PROT'} eq 'AH'){
947 $fwdfwsettings{'USE_SRC_PORT'}='';
948 $fwdfwsettings{'SRC_PORT'}='';
949 $fwdfwsettings{'ICMP_TYPES'}='';
950 $fwdfwsettings{'USESRV'}='';
951 $fwdfwsettings{'TGT_PORT'}='';
952 }elsif($fwdfwsettings{'PROT'} eq 'IGMP'){
953 $fwdfwsettings{'USE_SRC_PORT'}='';
954 $fwdfwsettings{'SRC_PORT'}='';
955 $fwdfwsettings{'ICMP_TYPES'}='';
956 $fwdfwsettings{'USESRV'}='';
957 $fwdfwsettings{'TGT_PORT'}='';
958 }elsif($fwdfwsettings{'PROT'} eq 'IPv6'){
959 $fwdfwsettings{'USE_SRC_PORT'}='';
960 $fwdfwsettings{'SRC_PORT'}='';
961 $fwdfwsettings{'ICMP_TYPES'}='';
962 $fwdfwsettings{'USESRV'}='';
963 $fwdfwsettings{'TGT_PORT'}='';
964 }elsif($fwdfwsettings{'PROT'} eq 'IPIP'){
965 $fwdfwsettings{'USE_SRC_PORT'}='';
966 $fwdfwsettings{'SRC_PORT'}='';
967 $fwdfwsettings{'ICMP_TYPES'}='';
968 $fwdfwsettings{'USESRV'}='';
969 $fwdfwsettings{'TGT_PORT'}='';
970 }elsif($fwdfwsettings{'PROT'} ne 'TCP' && $fwdfwsettings{'PROT'} ne 'UDP'){
971 $fwdfwsettings{'ICMP_TYPES'}='';
972 $fwdfwsettings{'SRC_PORT'}='';
973 $fwdfwsettings{'TGT_PORT'}='';
974 }elsif($fwdfwsettings{'PROT'} ne 'ICMP'){
975 $fwdfwsettings{'ICMP_TYPES'}='';
976 }
977 }
978 sub checkvpn
979 {
980 my $ip=shift;
981 #Test if manual IP is part of static OpenVPN networks
982 &General::readhasharray("$configccdnet", \%ccdnet);
983 foreach my $key (sort keys %ccdnet){
984 my ($vpnip,$vpnsubnet) = split ("/",$ccdnet{$key}[1]);
985 my $sub=&General::iporsubtodec($vpnsubnet);
986 if (&General::IpInSubnet($ip,$vpnip,$sub)){
987 return 0;
988 }
989 }
990 # A Test if manual ip is part of dynamic openvpn subnet is made in getcolor
991 # because if one creates a custom host with the ip, we need to check the color there!
992 # It does not make sense to check this here
993
994 # Test if manual IP is part of an OpenVPN N2N subnet does also not make sense here
995 # Is also checked in getcolor
996
997 # Test if manual ip is part of an IPsec Network is also checked in getcolor
998 return 1;
999 }
1000 sub checkvpncolor
1001 {
1002
1003 }
1004 sub deleterule
1005 {
1006 my %delhash=();
1007 &General::readhasharray($fwdfwsettings{'config'}, \%delhash);
1008 foreach my $key (sort {$a <=> $b} keys %delhash){
1009 if ($key >= $fwdfwsettings{'key'}) {
1010 my $next = $key + 1;
1011 if (exists $delhash{$next}) {
1012 foreach my $i (0 .. $#{$delhash{$next}}) {
1013 $delhash{$key}[$i] = $delhash{$next}[$i];
1014 }
1015 }
1016 }
1017 }
1018 # Remove the very last entry.
1019 my $last_key = (sort {$a <=> $b} keys %delhash)[-1];
1020 delete $delhash{$last_key};
1021
1022 &General::writehasharray($fwdfwsettings{'config'}, \%delhash);
1023 &General::firewall_config_changed();
1024
1025 if($fwdfwsettings{'nobase'} ne 'on'){
1026 &base;
1027 }
1028 }
1029 sub del_double
1030 {
1031 my %all=();
1032 @all{@_}=1;
1033 return (keys %all);
1034 }
1035 sub disable_rule
1036 {
1037 my $key1=shift;
1038 &General::readhasharray("$configfwdfw", \%configfwdfw);
1039 foreach my $key (sort keys %configfwdfw){
1040 if ($key eq $key1 ){
1041 if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';}
1042 }
1043 }
1044 &General::writehasharray("$configfwdfw", \%configfwdfw);
1045 &General::firewall_config_changed();
1046 }
1047 sub error
1048 {
1049 if ($errormessage) {
1050 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1051 print "<class name='base'>$errormessage\n";
1052 print "&nbsp;</class>\n";
1053 &Header::closebox();
1054 }
1055 }
1056 sub fillselect
1057 {
1058 my %hash=%{(shift)};
1059 my $val=shift;
1060 my $key;
1061 foreach my $key (sort { ncmp($hash{$a}[0],$hash{$b}[0]) } keys %hash){
1062 if($hash{$key}[0] eq $val){
1063 print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>";
1064 }else{
1065 print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>";
1066 }
1067 }
1068 }
1069 sub gen_dd_block
1070 {
1071 my $srctgt = shift;
1072 my $grp=shift;
1073 my $helper='';
1074 my $show='';
1075 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1076 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1077 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1078 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1079 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1080 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1081 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1082 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1083 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1084 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1085 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1086 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1087 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1088 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1089 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1090 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1091 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1092 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
1093 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1094 print<<END;
1095 <table width='100%' border='0'>
1096 <tr><td width='50%' valign='top'>
1097 <table width='95%' border='0'>
1098 <tr><td width='1%'><input type='radio' name='$grp' id='std_net_$srctgt' value='std_net_$srctgt' $checked{$grp}{'std_net_'.$srctgt}></td><td>$Lang::tr{'fwhost stdnet'}</td><td align='right'><select name='std_net_$srctgt' style='width:200px;'>
1099 END
1100 foreach my $network (sort keys %defaultNetworks)
1101 {
1102 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1103 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1104 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $defaultNetworks{$network}{'NAME'});
1105 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
1106 my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK";
1107 my $defsub1=&General::subtocidr($ifaces{$defsub});
1108 $ifaces{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED');
1109 if ($ifaces{$defnet}){
1110 print ">$network ($ifaces{$defnet}/$defsub1)</option>";
1111 }else{
1112 print ">$network</option>";
1113 }
1114 }
1115 print"</select></td></tr>";
1116 #custom networks
1117 if (! -z $confignet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1118 print"<tr><td><input type='radio' name='$grp' id='cust_net_$srctgt' value='cust_net_$srctgt' $checked{$grp}{'cust_net_'.$srctgt}></td><td>$Lang::tr{'fwhost cust net'}</td><td align='right'><select name='cust_net_$srctgt' style='width:200px;'>";
1119 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{$grp}});
1120 print"</select></td>";
1121 }
1122 #custom hosts
1123 if (! -z $confighost || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1124 print"<tr><td><input type='radio' name='$grp' id='cust_host_$srctgt' value='cust_host_$srctgt' $checked{$grp}{'cust_host_'.$srctgt}></td><td>$Lang::tr{'fwhost cust addr'}</td><td align='right'><select name='cust_host_$srctgt' style='width:200px;'>";
1125 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{$grp}});
1126 print"</select></td>";
1127 }
1128 #custom groups
1129 if (! -z $configgrp || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1130 print"<tr><td valign='top'><input type='radio' name='$grp' id='cust_grp_$srctgt' value='cust_grp_$srctgt' $checked{$grp}{'cust_grp_'.$srctgt}></td><td >$Lang::tr{'fwhost cust grp'}</td><td align='right'><select name='cust_grp_$srctgt' style='width:200px;'>";
1131 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } keys %customgrp) {
1132 if($helper ne $customgrp{$key}[0] && $customgrp{$key}[2] ne 'none'){
1133 print"<option ";
1134 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $customgrp{$key}[0]);
1135 print ">$customgrp{$key}[0]</option>";
1136 }
1137 $helper=$customgrp{$key}[0];
1138 }
1139 print"</select></td>";
1140 }
1141 # geoip locations / groups.
1142 my @geoip_locations = &fwlib::get_geoip_locations();
1143
1144 print "<tr>\n";
1145 print "<td valign='top'><input type='radio' name='$grp' id='cust_geoip_$srctgt' value='cust_geoip_$srctgt' $checked{$grp}{'cust_geoip_'.$srctgt}></td>\n";
1146 print "<td>$Lang::tr{'geoip'}</td>\n";
1147 print "<td align='right'><select name='cust_geoip_$srctgt' style='width:200px;'>\n";
1148
1149 # Add GeoIP groups to dropdown.
1150 if (!-z $configgeoipgrp) {
1151 print "<optgroup label='$Lang::tr{'fwhost cust geoipgroup'}'>\n";
1152 foreach my $key (sort { ncmp($customgeoipgrp{$a}[0],$customgeoipgrp{$b}[0]) } keys %customgeoipgrp) {
1153 my $selected;
1154
1155 # Generate stored value for select detection.
1156 my $stored = join(':', "group",$customgeoipgrp{$key}[0]);
1157
1158 # Only show a group once and group with elements.
1159 if($helper ne $customgeoipgrp{$key}[0] && $customgeoipgrp{$key}[2] ne 'none') {
1160 # Mark current entry as selected.
1161 if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $stored) {
1162 $selected = "selected='selected'";
1163 }
1164 print"<option $selected value='group:$customgeoipgrp{$key}[0]'>$customgeoipgrp{$key}[0]</option>\n";
1165 }
1166 $helper=$customgeoipgrp{$key}[0];
1167 }
1168 print "</optgroup>\n";
1169 }
1170
1171 # Add locations.
1172 print "<optgroup label='$Lang::tr{'fwhost cust geoiplocation'}'>\n";
1173 foreach my $location (@geoip_locations) {
1174 # Get country name.
1175 my $country_name = &GeoIP::get_full_country_name($location);
1176
1177 # Mark current entry as selected.
1178 my $selected;
1179 if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $location) {
1180 $selected = "selected='selected'";
1181 }
1182 print "<option $selected value='$location'>$location - $country_name</option>\n";
1183 }
1184 print "</optgroup>\n";
1185
1186 # Close GeoIP dropdown.
1187 print "</select></td>\n";
1188
1189 #End left table. start right table (vpn)
1190 print"</tr></table></td><td valign='top'><table width='95%' border='0' align='right'><tr>";
1191 # CCD networks
1192 if( ! -z $configccdnet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1193 print"<td width='1%'><input type='radio' name='$grp' id='ovpn_net_$srctgt' value='ovpn_net_$srctgt' $checked{$grp}{'ovpn_net_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_net_$srctgt' style='width:200px;'>";
1194 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{$grp}});
1195 print"</select></td></tr>";
1196 }
1197 #OVPN CCD Hosts
1198 foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost){
1199 if ($ccdhost{$key}[33] ne '' ){
1200 print"<tr><td width='1%'><input type='radio' name='$grp' id='ovpn_host_$srctgt' value='ovpn_host_$srctgt' $checked{$grp}{'ovpn_host_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_host_$srctgt' style='width:200px;'>" if ($show eq '');
1201 $show='1';
1202 print "<option value='$ccdhost{$key}[1]'";
1203 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1204 print ">$ccdhost{$key}[1]</option>";
1205 }
1206 }
1207 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1208 print"<tr><td width='1%'><input type='radio' name='$grp' id='ovpn_host_$srctgt' value='ovpn_host_$srctgt' $checked{$grp}{'ovpn_host_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_host_$srctgt' style='width:200px;'></select></td></tr>" ;
1209 }
1210 if ($show eq '1'){$show='';print"</select></td></tr>";}
1211 #OVPN N2N
1212 foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost){
1213 if ($ccdhost{$key}[3] eq 'net'){
1214 print"<tr><td width='1%'><input type='radio' name='$grp' id='ovpn_n2n_$srctgt' value='ovpn_n2n_$srctgt' $checked{$grp}{'ovpn_n2n_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ovpn_n2n'}:</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_n2n_$srctgt' style='width:200px;'>" if ($show eq '');
1215 $show='1';
1216 print "<option value='$ccdhost{$key}[1]'";
1217 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1218 print ">$ccdhost{$key}[1]</option>";
1219 }
1220 }
1221 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1222 print"<tr><td width='1%'><input type='radio' name='$grp' id='ovpn_n2n_$srctgt' value='ovpn_n2n_$srctgt' $checked{$grp}{'ovpn_n2n_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ovpn_n2n'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_n2n_$srctgt' style='width:200px;'></select></td></tr>" ;
1223 }
1224 if ($show eq '1'){$show='';print"</select></td></tr>";}
1225 #IPsec netze
1226 foreach my $key (sort { ncmp($ipsecconf{$a}[1],$ipsecconf{$b}[1]) } keys %ipsecconf) {
1227 if ($ipsecconf{$key}[3] eq 'net' || ($optionsfw{'SHOWDROPDOWN'} eq 'on' && $ipsecconf{$key}[3] ne 'host')){
1228 print"<tr><td valign='top'><input type='radio' name='$grp' value='ipsec_net_$srctgt' $checked{$grp}{'ipsec_net_'.$srctgt}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td align='right'><select name='ipsec_net_$srctgt' style='width:200px;'>" if ($show eq '');
1229 $show='1';
1230 print "<option ";
1231 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ipsecconf{$key}[1]);
1232 print ">$ipsecconf{$key}[1]</option>";
1233 }
1234 }
1235 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1236 print"<tr><td valign='top'><input type='radio' name='$grp' id='ipsec_net_$srctgt' value='ipsec_net_$srctgt' $checked{$grp}{'ipsec_net_'.$srctgt}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td align='right'><select name='ipsec_net_$srctgt' style='width:200px;'><select></td></tr>";
1237 }
1238 if ($show eq '1'){$show='';print"</select></td></tr>";}
1239
1240 print"</table>";
1241 print"</td></tr></table><br>";
1242 }
1243 sub get_ip
1244 {
1245 my $val=shift;
1246 my $grp =shift;
1247 my $a;
1248 my $b;
1249 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1250 if ($fwdfwsettings{$grp} ne $Lang::tr{'fwhost any'}){
1251 if ($fwdfwsettings{$grp} eq $val.'_addr'){
1252 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
1253 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
1254 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
1255 $a=$netsettings{'GREEN_NETADDRESS'};
1256 $b=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'});
1257 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
1258 $a=$netsettings{'ORANGE_NETADDRESS'};
1259 $b=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'});
1260 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
1261 $a=$netsettings{'BLUE_NETADDRESS'};
1262 $b=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'});
1263 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
1264 &General::readhash("$configovpn",\%ovpnsettings);
1265 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
1266 $b=&General::iporsubtocidr($b);
1267 }
1268 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
1269 &General::readhasharray("$confignet", \%customnetwork);
1270 foreach my $key (keys %customnetwork){
1271 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1272 $a=$customnetwork{$key}[1];
1273 $b=&General::iporsubtocidr($customnetwork{$key}[2]);
1274 }
1275 }
1276 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
1277 &General::readhasharray("$confighost", \%customhost);
1278 foreach my $key (keys %customhost){
1279 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1280 if ($customhost{$key}[1] eq 'ip'){
1281 ($a,$b)=split (/\//,$customhost{$key}[2]);
1282 $b=&General::iporsubtocidr($b);
1283 }else{
1284 if ($grp eq 'grp2'){
1285 $errormessage=$Lang::tr{'fwdfw err tgt_mac'};
1286 }
1287 }
1288 }
1289 }
1290 }
1291 }
1292 return $a,$b;
1293 }
1294 sub get_name
1295 {
1296 my $val=shift;
1297 &General::setup_default_networks(\%defaultNetworks);
1298 foreach my $network (sort keys %defaultNetworks)
1299 {
1300 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1301 }
1302 }
1303 sub getsrcport
1304 {
1305 my %hash=%{(shift)};
1306 my $key=shift;
1307 if($hash{$key}[7] eq 'ON' && $hash{$key}[10]){
1308 $hash{$key}[10]=~ s/\|/,/g;
1309 print": $hash{$key}[10]";
1310 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
1311 print": <br>$hash{$key}[9] ";
1312 }
1313 }
1314 sub gettgtport
1315 {
1316 my %hash=%{(shift)};
1317 my $key=shift;
1318 my $service;
1319 my $prot;
1320 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1321 if($hash{$key}[14] eq 'cust_srv'){
1322 &General::readhasharray("$configsrv", \%customservice);
1323 foreach my $i (sort keys %customservice){
1324 if($customservice{$i}[0] eq $hash{$key}[15]){
1325 $service = $customservice{$i}[0];
1326 }
1327 }
1328 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
1329 $service=$hash{$key}[15];
1330 }elsif($hash{$key}[14] eq 'TGT_PORT'){
1331 $hash{$key}[15]=~ s/\|/,/g;
1332 $service=$hash{$key}[15];
1333 }
1334 if($service){
1335 print": $service";
1336 }
1337 }
1338 }
1339 sub get_serviceports
1340 {
1341 my $type=shift;
1342 my $name=shift;
1343 &General::readhasharray("$configsrv", \%customservice);
1344 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1345 @protocols=();
1346 my @specprot=("IPIP","IPV6","IGMP","GRE","AH","ESP");
1347 if($type eq 'service'){
1348 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1349 if ($customservice{$key}[0] eq $name){
1350 push (@protocols,$customservice{$key}[2]);
1351 }
1352 }
1353 }elsif($type eq 'group'){
1354 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1355 if ($customservicegrp{$key}[0] eq $name){
1356 if ($customservicegrp{$key}[2] ~~ @specprot){
1357 push (@protocols," ".$customservicegrp{$key}[2]);
1358 }else{
1359 foreach my $key1 (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1360 if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
1361 if (!grep(/$customservice{$key1}[2]/, @protocols)){
1362 push (@protocols,$customservice{$key1}[2]);}
1363 }
1364 }
1365 }
1366 }
1367 }
1368 }
1369
1370 # Sort protocols alphabetically.
1371 @protocols = sort(@protocols);
1372
1373 return @protocols;
1374 }
1375 sub getcolor
1376 {
1377 my $nettype=shift;
1378 my $val=shift;
1379 my $hash=shift;
1380 if($optionsfw{'SHOWCOLORS'} eq 'on'){
1381 # Don't colourise MAC addresses
1382 if (&General::validmac($val)) {
1383 $tdcolor = "";
1384 return;
1385 }
1386
1387 #custom Hosts
1388 if ($nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1389 foreach my $key (sort keys %$hash){
1390 if ($$hash{$key}[0] eq $val){
1391 $val=$$hash{$key}[2];
1392 }
1393 }
1394 }
1395 #standard networks
1396 if ($val eq 'GREEN'){
1397 $tdcolor="style='background-color: $Header::colourgreen;color:white;'";
1398 return;
1399 }elsif ($val eq 'ORANGE'){
1400 $tdcolor="style='background-color: $Header::colourorange;color:white;'";
1401 return;
1402 }elsif ($val eq 'BLUE'){
1403 $tdcolor="style='background-color: $Header::colourblue;color:white;'";
1404 return;
1405 }elsif ($val eq 'RED' ||$val eq 'RED1' ){
1406 $tdcolor="style='background-color: $Header::colourred;color:white;'";
1407 return;
1408 }elsif ($val eq 'IPFire' ){
1409 $tdcolor="style='background-color: $Header::colourred;color:white;'";
1410 return;
1411 }elsif ($val eq 'OpenVPN-Dyn' ){
1412 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1413 return;
1414 }elsif ($val eq 'IPsec RW' ){
1415 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1416 return;
1417 }elsif($val =~ /^(.*?)\/(.*?)$/){
1418 my ($sip,$scidr) = split ("/",$val);
1419 if ( &Header::orange_used() && &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1420 $tdcolor="style='background-color: $Header::colourorange;color:white;'";
1421 return;
1422 }
1423 if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1424 $tdcolor="style='background-color: $Header::colourgreen;color:white;'";
1425 return;
1426 }
1427 if ( &Header::blue_used() && &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
1428 $tdcolor="style='background-color: $Header::colourblue;color:white;'";
1429 return;
1430 }
1431 }elsif ($val eq 'Default IP'){
1432 $tdcolor="style='background-color: $Header::colourred;color:white;'";
1433 return;
1434 }
1435 #Check if a manual IP or custom host is part of a VPN
1436 if ($nettype eq 'src_addr' || $nettype eq 'tgt_addr' || $nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1437 #Check if IP is part of OpenVPN dynamic subnet
1438 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
1439 my ($c,$d) = split("/",$val);
1440 if (&General::IpInSubnet($c,$a,$b)){
1441 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1442 return;
1443 }
1444 #Check if IP is part of OpenVPN static subnet
1445 foreach my $key (sort keys %ccdnet){
1446 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1447 $b =&General::iporsubtodec($b);
1448 if (&General::IpInSubnet($c,$a,$b)){
1449 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1450 return;
1451 }
1452 }
1453 #Check if IP is part of OpenVPN N2N subnet
1454 foreach my $key (sort keys %ccdhost){
1455 if ($ccdhost{$key}[3] eq 'net'){
1456 my ($a,$b) = split("/",$ccdhost{$key}[11]);
1457 if (&General::IpInSubnet($c,$a,$b)){
1458 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1459 return;
1460 }
1461 }
1462 }
1463 #Check if IP is part of IPsec RW network
1464 if ($ipsecsettings{'RW_NET'} ne ''){
1465 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1466 $b=&General::iporsubtodec($b);
1467 if (&General::IpInSubnet($c,$a,$b)){
1468 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1469 return;
1470 }
1471 }
1472 #Check if IP is part of a IPsec N2N network
1473 foreach my $key (sort keys %ipsecconf){
1474 if ($ipsecconf{$key}[11]){
1475 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1476 $b=&General::iporsubtodec($b);
1477 if (&General::IpInSubnet($c,$a,$b)){
1478 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1479 return;
1480 }
1481 }
1482 }
1483 }
1484 #VPN networks
1485 if ($nettype eq 'ovpn_n2n_src' || $nettype eq 'ovpn_n2n_tgt' || $nettype eq 'ovpn_net_src' || $nettype eq 'ovpn_net_tgt'|| $nettype eq 'ovpn_host_src' || $nettype eq 'ovpn_host_tgt'){
1486 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1487 return;
1488 }
1489 if ($nettype eq 'ipsec_net_src' || $nettype eq 'ipsec_net_tgt'){
1490 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1491 return;
1492 }
1493 #ALIASE
1494 foreach my $alias (sort keys %aliases)
1495 {
1496 if ($val eq $alias){
1497 $tdcolor="style='background-color:$Header::colourred;color:white;'";
1498 return;
1499 }
1500 }
1501 }
1502 $tdcolor='';
1503 return;
1504 }
1505 sub hint
1506 {
1507 if ($hint) {
1508 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1509 print "<class name='base'>$hint\n";
1510 print "&nbsp;</class>\n";
1511 &Header::closebox();
1512 }
1513 }
1514 sub newrule
1515 {
1516 &error;
1517 &General::setup_default_networks(\%defaultNetworks);
1518 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1519 #read all configfiles
1520 &General::readhasharray("$configccdnet", \%ccdnet);
1521 &General::readhasharray("$confignet", \%customnetwork);
1522 &General::readhasharray("$configccdhost", \%ccdhost);
1523 &General::readhasharray("$confighost", \%customhost);
1524 &General::readhasharray("$configccdhost", \%ccdhost);
1525 &General::readhasharray("$configgrp", \%customgrp);
1526 &General::readhasharray("$configgeoipgrp", \%customgeoipgrp);
1527 &General::readhasharray("$configipsec", \%ipsecconf);
1528 &General::get_aliases(\%aliases);
1529 my %checked=();
1530 my $helper;
1531 my $sum=0;
1532 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
1533 my $config=$fwdfwsettings{'config'};
1534 my %hash=();
1535 #Get Red IP-ADDRESS
1536 open (CONN1,"/var/ipfire/red/local-ipaddress");
1537 my $redip = <CONN1>;
1538 close(CONN1);
1539 if (! $fwdfwsettings{'RULE_ACTION'} && $fwdfwsettings{'POLICY'} eq 'MODE2'){
1540 $fwdfwsettings{'RULE_ACTION'}='DROP';
1541 }elsif(! $fwdfwsettings{'RULE_ACTION'} && $fwdfwsettings{'POLICY'} eq 'MODE1'){
1542 $fwdfwsettings{'RULE_ACTION'}='ACCEPT';
1543 }
1544 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1545 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1546 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1547 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1548 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1549 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1550 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1551 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1552 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1553 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1554 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1555 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1556 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1557 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1558 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1559 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1560 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1561 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1562 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1563 $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
1564 #check if update and get values
1565 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
1566 &General::readhasharray("$config", \%hash);
1567 foreach my $key (sort keys %hash){
1568 $sum++;
1569 if ($key eq $fwdfwsettings{'key'}){
1570 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
1571 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
1572 $fwdfwsettings{'chain'} = $hash{$key}[1];
1573 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1574 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1575 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1576 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1577 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1578 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1579 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1580 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1581 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1582 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1583 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1584 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1585 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1586 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1587 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1588 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1589 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1590 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1591 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1592 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1593 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1594 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1595 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1596 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1597 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1598 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
1599 $fwdfwsettings{'USE_NAT'} = $hash{$key}[28];
1600 $fwdfwsettings{'nat'} = $hash{$key}[31]; #changed order
1601 $fwdfwsettings{$fwdfwsettings{'nat'}} = $hash{$key}[29];
1602 $fwdfwsettings{'dnatport'} = $hash{$key}[30];
1603 $fwdfwsettings{'LIMIT_CON_CON'} = $hash{$key}[32];
1604 $fwdfwsettings{'concon'} = $hash{$key}[33];
1605 $fwdfwsettings{'RATE_LIMIT'} = $hash{$key}[34];
1606 $fwdfwsettings{'ratecon'} = $hash{$key}[35];
1607 $fwdfwsettings{'RATETIME'} = $hash{$key}[36];
1608 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1609 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1610 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1611 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1612 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1613 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1614 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1615 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1616 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1617 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1618 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1619 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1620 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1621 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1622 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1623 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1624 $checked{'nat'}{$fwdfwsettings{'nat'}} = 'CHECKED';
1625 $checked{'LIMIT_CON_CON'}{$fwdfwsettings{'LIMIT_CON_CON'}} = 'CHECKED';
1626 $checked{'RATE_LIMIT'}{$fwdfwsettings{'RATE_LIMIT'}} = 'CHECKED';
1627 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1628 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1629 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1630 $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
1631 $selected{'dnat'}{$fwdfwsettings{'dnat'}} ='selected';
1632 $selected{'snat'}{$fwdfwsettings{'snat'}} ='selected';
1633 $selected{'RATETIME'}{$fwdfwsettings{'RATETIME'}} ='selected';
1634 }
1635 }
1636 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1637 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1638 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1639 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1640 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1641 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1642 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1643 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1644 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1645 $fwdfwsettings{'oldruletype'}=$fwdfwsettings{'chain'};
1646 $fwdfwsettings{'oldconcon'}=$fwdfwsettings{'LIMIT_CON_CON'};
1647 $fwdfwsettings{'olduseratelimit'}=$fwdfwsettings{'RATE_LIMIT'};
1648 $fwdfwsettings{'olduseratelimitamount'}=$fwdfwsettings{'ratecon'};
1649 $fwdfwsettings{'oldratelimittime'}=$fwdfwsettings{'RATETIME'};
1650
1651 #check if manual ip (source) is orange network
1652 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1653 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1654 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1655 $fwdfwsettings{'oldorange'} ='on';
1656 }
1657 }
1658 }else{
1659 $fwdfwsettings{'ACTIVE'}='ON';
1660 $fwdfwsettings{'nat'} = 'dnat';
1661 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1662 $checked{'nat'}{$fwdfwsettings{'nat'}} = 'CHECKED';
1663 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1664 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1665 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1666 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1667 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1668 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1669 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1670 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1671 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1672 $fwdfwsettings{'oldconcon'}=$fwdfwsettings{'LIMIT_CON_CON'};
1673 #check if manual ip (source) is orange network
1674 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1675 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1676 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1677 $fwdfwsettings{'oldorange'} ='on';
1678 }
1679 }
1680 }
1681 # Split manual source and target address and delete the subnet
1682 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1683 if ($scidr eq '32'){$fwdfwsettings{$fwdfwsettings{'grp1'}}=$sip;}
1684 my ($dip,$dcidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp2'}});
1685 if ($dcidr eq '32'){$fwdfwsettings{$fwdfwsettings{'grp2'}}=$dip;}
1686 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'});
1687 #------SOURCE-------------------------------------------------------
1688 print "<form method='post'>";
1689 print<<END;
1690 <table width='100%' border='0'>
1691 <tr><td width='1%'><input type='radio' name='grp1' value='src_addr' checked></td><td width='60%'>$Lang::tr{'fwdfw sourceip'}<input type='TEXT' name='src_addr' value='$fwdfwsettings{'src_addr'}' size='16' maxlength='18' ></td><td width='1%'><input type='radio' name='grp1' id='ipfire_src' value='ipfire_src' $checked{'grp1'}{'ipfire_src'}></td><td><b>Firewall</b></td>
1692 END
1693 print"<td align='right'><select name='ipfire_src' style='width:200px;'>";
1694 print "<option value='ALL' $selected{'ipfire_src'}{'ALL'}>$Lang::tr{'all'}</option>";
1695 print "<option value='GREEN' $selected{'ipfire_src'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
1696 print "<option value='ORANGE' $selected{'ipfire_src'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if (&Header::orange_used());
1697 print "<option value='BLUE' $selected{'ipfire_src'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>" if (&Header::blue_used());
1698 print "<option value='RED1' $selected{'ipfire_src'}{'RED1'}>$Lang::tr{'red1'} ($redip)" if ($redip);
1699 if (! -z "${General::swroot}/ethernet/aliases"){
1700 foreach my $alias (sort keys %aliases)
1701 {
1702 print "<option value='$alias' $selected{'ipfire_src'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
1703 }
1704 }
1705 print<<END;
1706 </select></td></tr>
1707 <tr><td><br></td></tr>
1708 </table>
1709 END
1710 &gen_dd_block('src','grp1');
1711 &Header::closebox();
1712
1713 #---SNAT / DNAT ------------------------------------------------
1714 &Header::openbox('100%', 'left', 'NAT');
1715 print<<END;
1716 <label>
1717 <input type='checkbox' name='USE_NAT' id='USE_NAT' value="ON" $checked{'USE_NAT'}{'ON'}>
1718 $Lang::tr{'fwdfw use nat'}
1719 </label>
1720 <div class="NAT">
1721 <table width='100%' border='0'>
1722 <tr>
1723 <td width='5%'></td>
1724 <td width='40%'>
1725 <label>
1726 <input type='radio' name='nat' value='dnat' $checked{'nat'}{'dnat'}>
1727 $Lang::tr{'fwdfw dnat'}
1728 </label>
1729 </td>
1730 END
1731
1732 print <<END;
1733 <td width='25%' align='right'>$Lang::tr{'dnat address'}:</td>
1734 <td width='30%'>
1735 <select name='dnat' style='width: 100%;'>
1736 <option value='AUTO' $selected{'dnat'}{'AUTO'}>- $Lang::tr{'automatic'} -</option>
1737 <option value='Default IP' $selected{'dnat'}{'Default IP'}>$Lang::tr{'red1'} ($redip)</option>
1738 END
1739 if (%aliases) {
1740 foreach my $alias (sort keys %aliases) {
1741 print "<option value='$alias' $selected{'dnat'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
1742 }
1743 }
1744 #DNAT Dropdown
1745 foreach my $network (sort keys %defaultNetworks)
1746 {
1747 if ($defaultNetworks{$network}{'NAME'} eq 'BLUE'||$defaultNetworks{$network}{'NAME'} eq 'GREEN' ||$defaultNetworks{$network}{'NAME'} eq 'ORANGE'){
1748 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1749 print " selected='selected'" if ($fwdfwsettings{'dnat'} eq $defaultNetworks{$network}{'NAME'});
1750 print ">$network ($defaultNetworks{$network}{'NET'})</option>";
1751 }
1752 }
1753 print "</select>";
1754 print "</tr>";
1755
1756 #SNAT
1757 print <<END;
1758 <tr>
1759 <td width='5%'></td>
1760 <td width='40%'>
1761 <label>
1762 <input type='radio' name='nat' value='snat' $checked{'nat'}{'snat'}>
1763 $Lang::tr{'fwdfw snat'}
1764 </label>
1765 </td>
1766 <td width='25%' align='right'>$Lang::tr{'snat new source ip address'}:</td>
1767 <td width='30%'>
1768 <select name='snat' style='width: 100%;'>
1769 END
1770
1771 foreach my $alias (sort keys %aliases) {
1772 print "<option value='$alias' $selected{'snat'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
1773 }
1774 # SNAT Dropdown
1775 foreach my $network (sort keys %defaultNetworks) {
1776 if ($defaultNetworks{$network}{'NAME'} eq 'BLUE'||$defaultNetworks{$network}{'NAME'} eq 'GREEN' ||$defaultNetworks{$network}{'NAME'} eq 'ORANGE'){
1777 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1778 print " selected='selected'" if ($fwdfwsettings{'snat'} eq $defaultNetworks{$network}{'NAME'});
1779 print ">$network ($defaultNetworks{$network}{'NET'})</option>";
1780 }
1781 }
1782 print <<END;
1783 </select>
1784 </td>
1785 </tr>
1786 </table>
1787 </div>
1788 END
1789 &Header::closebox();
1790
1791 #---TARGET------------------------------------------------------
1792 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw target'});
1793 print<<END;
1794 <table width='100%' border='0'>
1795 <tr><td width='1%'><input type='radio' name='grp2' value='tgt_addr' checked></td><td width='60%' nowrap='nowrap'>$Lang::tr{'fwdfw targetip'}<input type='TEXT' name='tgt_addr' value='$fwdfwsettings{'tgt_addr'}' size='16' maxlength='18'><td width='1%'><input type='radio' name='grp2' id='ipfire' value='ipfire' $checked{'grp2'}{'ipfire'}></td><td><b>Firewall</b></td>
1796 END
1797 print"<td align='right'><select name='ipfire' style='width:200px;'>";
1798 print "<option value='ALL' $selected{'ipfire'}{'ALL'}>$Lang::tr{'all'}</option>";
1799 print "<option value='GREEN' $selected{'ipfire'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
1800 print "<option value='ORANGE' $selected{'ipfire'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if (&Header::orange_used());
1801 print "<option value='BLUE' $selected{'ipfire'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>"if (&Header::blue_used());
1802 print "<option value='RED1' $selected{'ipfire'}{'RED1'}>$Lang::tr{'red1'} ($redip)" if ($redip);
1803 if (! -z "${General::swroot}/ethernet/aliases"){
1804 foreach my $alias (sort keys %aliases)
1805 {
1806 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
1807 }
1808 }
1809 print<<END;
1810 </select></td></tr>
1811 <tr><td><br></td></tr></table>
1812 END
1813 &gen_dd_block('tgt','grp2');
1814 &Header::closebox;
1815 #---PROTOCOL------------------------------------------------------
1816 $fwdfwsettings{'SRC_PORT'} =~ s/\|/,/g;
1817 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
1818 $fwdfwsettings{'dnatport'} =~ tr/|/,/;
1819
1820 # The dnatport may be empty, if it matches TGT_PORT
1821 if ($fwdfwsettings{'dnatport'} eq $fwdfwsettings{'TGT_PORT'}) {
1822 $fwdfwsettings{'dnatport'} = "";
1823 }
1824
1825 &Header::openbox('100%', 'left', $Lang::tr{'fwhost prot'});
1826 #Fix Protocol for JQuery
1827 if ($fwdfwsettings{'grp3'} eq 'cust_srv' || $fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
1828 $fwdfwsettings{'PROT'} = 'template';
1829 }
1830 print<<END;
1831 <table width='100%' border='0'>
1832 <tr>
1833 <td width="25%">
1834 <select name='PROT' id='protocol' style="width: 95px;">
1835 END
1836 print "<option value=\"\"";
1837 if ($fwdfwsettings{'PROT'} eq '') {
1838 print " selected=\"selected\"";
1839 }
1840 print ">$Lang::tr{'all'}</option>";
1841
1842 print "<option value=\"template\"";
1843 print " selected=\"selected\"" if ($fwdfwsettings{'grp3'} eq 'cust_srv' || $fwdfwsettings{'grp3'} eq 'cust_srvgrp');
1844 print ">- $Lang::tr{'template'} -</option>";
1845
1846 foreach (@PROTOCOLS) {
1847 print"<option value=\"$_\"";
1848 if ($_ eq $fwdfwsettings{'PROT'}) {
1849 print " selected=\"selected\"";
1850 }
1851 if($_ eq "IPv6"){
1852 print ">$Lang::tr{'fwdfw prot41'}</option>";
1853 }else{
1854 print ">$_</option>";
1855 }
1856 }
1857
1858 print<<END;
1859 </select>
1860 </td>
1861 <td width="75%">
1862 <table width='100%' border='0' id="PROTOCOL_ICMP_TYPES">
1863 <tr>
1864 <td width='20%'>$Lang::tr{'fwhost icmptype'}</td>
1865 <td colspan='2'>
1866 <select name='ICMP_TYPES' style='min-width:230px;'>
1867 END
1868 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1869 print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>";
1870 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
1871 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1872 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1873 }else{
1874 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1875 }
1876 }
1877
1878 print <<END;
1879 </select>
1880 </td>
1881 </tr>
1882 </table>
1883
1884 <table width="100%" border="0" id="PROTOCOL_PORTS">
1885 <tr>
1886 <!-- #SOURCEPORT -->
1887 <td>
1888 $Lang::tr{'fwdfw use srcport'}
1889 </td>
1890 <td>
1891 <input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18'>
1892 </td>
1893 <td width='10%'>
1894 </td>
1895
1896 <!-- #TARGETPORT -->
1897 <td>
1898 $Lang::tr{'fwdfw use srv'}
1899 </td>
1900
1901 <td>
1902 <input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18'>
1903 </td>
1904 </tr>
1905 <tr class="NAT">
1906 <td colspan='3'></td>
1907 <td>$Lang::tr{'fwdfw external port nat'}:</td>
1908 <td>
1909 <input type='text' name='dnatport' value=\"$fwdfwsettings{'dnatport'}\" maxlength='20' size='18'>
1910 </td>
1911 </tr>
1912 </table>
1913
1914 <table width="100%" border="0" id="PROTOCOL_TEMPLATE">
1915 <tr>
1916 <td>
1917 <input type='radio' name='grp3' id='cust_srv' value='cust_srv' checked>
1918 $Lang::tr{'fwhost cust service'}
1919 </td>
1920 <td>
1921 <select name='cust_srv' style='min-width: 230px;'>
1922 END
1923
1924 &General::readhasharray("$configsrv", \%customservice);
1925 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1926 print"<option ";
1927 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1928 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1929 }
1930
1931 print <<END;
1932 </select>
1933 </td>
1934 </tr>
1935 <tr>
1936 <td>
1937 <input type='radio' name='grp3' id='cust_srvgrp' value='cust_srvgrp' $checked{'grp3'}{'cust_srvgrp'}>
1938 $Lang::tr{'fwhost cust srvgrp'}
1939 </td>
1940 <td>
1941 <select name='cust_srvgrp' style='min-width:230px;'>
1942 END
1943
1944 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1945 my $helper;
1946 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1947 if ($helper ne $customservicegrp{$key}[0] && $customservicegrp{$key}[2] ne 'none'){
1948 print"<option ";
1949 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1950 print">$customservicegrp{$key}[0]</option>";
1951 }
1952 $helper=$customservicegrp{$key}[0];
1953 }
1954
1955 print<<END;
1956 </select>
1957 </td>
1958 </tr>
1959 </table>
1960 </td>
1961 </tr>
1962 </table>
1963 END
1964
1965 &Header::closebox;
1966 $checked{"RULE_ACTION"}{$fwdfwsettings{'RULE_ACTION'}} = 'CHECKED';
1967 print <<END;
1968 <center>
1969 <table width="80%" class='tbl' id='actions'>
1970 <tr>
1971 <td width="33%" align="center" bgcolor="$color{'color17'}">
1972 &nbsp;<br>&nbsp;
1973 </td>
1974 <td width="33%" align="center" bgcolor="$color{'color25'}">
1975 &nbsp;<br>&nbsp;
1976 </td>
1977 <td width="33%" align="center" bgcolor="$color{'color16'}">
1978 &nbsp;<br>&nbsp;
1979 </td>
1980 </tr>
1981 <tr>
1982 <td width="33%" align="center">
1983 <label>
1984 <input type="radio" name="RULE_ACTION" value="ACCEPT" $checked{"RULE_ACTION"}{"ACCEPT"}>
1985 <strong>$Lang::tr{'fwdfw ACCEPT'}</strong>
1986 </label>
1987 </td>
1988 <td width="33%" align="center">
1989 <label>
1990 <input type="radio" name="RULE_ACTION" value="DROP" $checked{"RULE_ACTION"}{"DROP"}>
1991 <strong>$Lang::tr{'fwdfw DROP'}</strong>
1992 </label>
1993 </td>
1994 <td width="33%" align="center">
1995 <label>
1996 <input type="radio" name="RULE_ACTION" value="REJECT" $checked{"RULE_ACTION"}{"REJECT"}>
1997 <strong>$Lang::tr{'fwdfw REJECT'}</strong>
1998 </label>
1999 </td>
2000 </tr>
2001 </table>
2002 </center>
2003
2004 <br>
2005 END
2006 #---Activate/logging/remark-------------------------------------
2007 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw additional'});
2008 print<<END;
2009 <table width='100%' border='0'>
2010 END
2011 print"<tr><td width='12%'>$Lang::tr{'remark'}:</td><td width='88%' align='left'><input type='text' name='ruleremark' maxlength='255' value='$fwdfwsettings{'ruleremark'}' style='width:99%;'></td></tr>";
2012 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
2013 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
2014 for (my $count =1; $count <= $sum; $count++){
2015 print"<option value='$count' ";
2016 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
2017 print">$count</option>";
2018 }
2019 print"</select></td></tr>";
2020 }else{
2021 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
2022 }
2023
2024 print<<END;
2025 </table>
2026 <table width='100%'>
2027 <tr>
2028 END
2029
2030 if ($fwdfwsettings{'updatefwrule'} eq 'on') {
2031 print <<END;
2032 <td>
2033 <input type='checkbox' name='ACTIVE' value="ON" $checked{'ACTIVE'}{'ON'}>
2034 </td>
2035 <td>$Lang::tr{'fwdfw rule activate'}</td>
2036 END
2037 } else {
2038 print <<END;
2039 <td colspan="2">
2040 <input type="hidden" name="ACTIVE" value="ON">
2041 </td>
2042 END
2043 }
2044
2045 print <<END;
2046 </tr>
2047 <tr>
2048 <td>
2049 <input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'}>
2050 </td>
2051 <td>$Lang::tr{'fwdfw log rule'}</td>
2052 </tr>
2053 <tr>
2054 <td width='1%'>
2055 <input type='checkbox' name='TIME' id="USE_TIME_CONSTRAINTS" value='ON' $checked{'TIME'}{'ON'}>
2056 </td>
2057 <td>$Lang::tr{'fwdfw timeframe'}</td>
2058 </tr>
2059 <tr id="TIME_CONSTRAINTS">
2060 <td colspan="2">
2061 <table width="66%" border="0">
2062 <tr>
2063 <td width="8em">&nbsp;</td>
2064 <td align="center">$Lang::tr{'advproxy monday'}</td>
2065 <td align="center">$Lang::tr{'advproxy tuesday'}</td>
2066 <td align="center">$Lang::tr{'advproxy wednesday'}</td>
2067 <td align="center">$Lang::tr{'advproxy thursday'}</td>
2068 <td align="center">$Lang::tr{'advproxy friday'}</td>
2069 <td align="center">$Lang::tr{'advproxy saturday'}</td>
2070 <td align="center">$Lang::tr{'advproxy sunday'}</td>
2071 <td>&nbsp;</td>
2072 </tr>
2073 <tr>
2074 <td width="8em">&nbsp;</td>
2075 <td align="center"><input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} ></td>
2076 <td align="center"><input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} ></td>
2077 <td align="center"><input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} ></td>
2078 <td align="center"><input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} ></td>
2079 <td align="center"><input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} ></td>
2080 <td align="center"><input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} ></td>
2081 <td align="center"><input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} ></td>
2082 <td>
2083 <select name='TIME_FROM'>
2084 END
2085 for (my $i=0;$i<=23;$i++) {
2086 $i = sprintf("%02s",$i);
2087 for (my $j=0;$j<=45;$j+=15) {
2088 $j = sprintf("%02s",$j);
2089 my $time = $i.":".$j;
2090 print "<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
2091 }
2092 }
2093 print<<END;
2094 </select> &dash;
2095 <select name='TIME_TO'>
2096 END
2097 for (my $i=0;$i<=23;$i++) {
2098 $i = sprintf("%02s",$i);
2099 for (my $j=0;$j<=45;$j+=15) {
2100 $j = sprintf("%02s",$j);
2101 my $time = $i.":".$j;
2102 print "<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
2103 }
2104 }
2105 print<<END;
2106 </select>
2107 </td>
2108 </tr>
2109 </table>
2110 </td>
2111 </tr>
2112 <tr>
2113 <td width='1%'>
2114 <input type='checkbox' name='LIMIT_CON_CON' id="USE_LIMIT_CONCURRENT_CONNECTIONS_PER_IP" value='ON' $checked{'LIMIT_CON_CON'}{'ON'}>
2115 </td>
2116 <td>$Lang::tr{'fwdfw limitconcon'}</td>
2117 </tr>
2118 <tr id="LIMIT_CON">
2119 <td colspan='2'>
2120 <table width='66%' border='0'>
2121 <tr>
2122 <td width="20em">&nbsp;</td>
2123 <td>$Lang::tr{'fwdfw maxconcon'}: <input type='text' name='concon' size='2' value="$fwdfwsettings{'concon'}"></td>
2124 </tr>
2125 </table>
2126 </td>
2127 </tr>
2128 <tr>
2129 <td width='1%'>
2130 <input type='checkbox' name='RATE_LIMIT' id="USE_RATELIMIT" value='ON' $checked{'RATE_LIMIT'}{'ON'}>
2131 </td>
2132 <td>$Lang::tr{'fwdfw ratelimit'}</td>
2133 </tr>
2134 <tr id="RATELIMIT">
2135 <td colspan='2'>
2136 <table width='66%' border='0'>
2137 <tr>
2138 <td width="20em">&nbsp;</td>
2139 <td>$Lang::tr{'fwdfw numcon'}: <input type='text' name='ratecon' size='2' value="$fwdfwsettings{'ratecon'}"> /
2140 <select name='RATETIME' style='width:100px;'>
2141 <option value='second' $selected{'RATETIME'}{'second'}>$Lang::tr{'age second'}</option>
2142 <option value='minute' $selected{'RATETIME'}{'minute'}>$Lang::tr{'minute'}</option>
2143 <option value='hour' $selected{'RATETIME'}{'hour'}>$Lang::tr{'hour'}</option>
2144 </select>
2145 </td>
2146 </tr>
2147 </table>
2148 </td>
2149 </tr>
2150 </table>
2151 <br>
2152 END
2153
2154 #---ACTION------------------------------------------------------
2155 if($fwdfwsettings{'updatefwrule'} ne 'on'){
2156 print<<END;
2157 <table border='0' width='100%'>
2158 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
2159 <input type='hidden' name='config' value='$config' >
2160 <input type='hidden' name='ACTION' value='saverule' ></form>
2161 <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'></form></td></tr>
2162 </table>
2163 <br>
2164 END
2165 }else{
2166 print<<END;
2167 <table border='0' width='100%'>
2168 <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'}'>
2169 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
2170 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
2171 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
2172 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
2173 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
2174 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
2175 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
2176 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
2177 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
2178 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
2179 <input type='hidden' name='oldorange' value='$fwdfwsettings{'oldorange'}' />
2180 <input type='hidden' name='oldnat' value='$fwdfwsettings{'oldnat'}' />
2181 <input type='hidden' name='oldruletype' value='$fwdfwsettings{'oldruletype'}' />
2182 <input type='hidden' name='oldconcon' value='$fwdfwsettings{'oldconcon'}' />
2183 <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>
2184 </table></form>
2185 END
2186 }
2187 &Header::closebox();
2188 }
2189 sub pos_up
2190 {
2191 my %uphash=();
2192 my %tmp=();
2193 &General::readhasharray($fwdfwsettings{'config'}, \%uphash);
2194 foreach my $key (sort keys %uphash){
2195 if ($key eq $fwdfwsettings{'key'}) {
2196 my $last = $key -1;
2197 if (exists $uphash{$last}){
2198 #save rule last
2199 foreach my $y (0 .. $#{$uphash{$last}}) {
2200 $tmp{0}[$y] = $uphash{$last}[$y];
2201 }
2202 #copy active rule to last
2203 foreach my $i (0 .. $#{$uphash{$last}}) {
2204 $uphash{$last}[$i] = $uphash{$key}[$i];
2205 }
2206 #copy saved rule to actual position
2207 foreach my $x (0 .. $#{$tmp{0}}) {
2208 $uphash{$key}[$x] = $tmp{0}[$x];
2209 }
2210 }
2211 }
2212 }
2213 &General::writehasharray($fwdfwsettings{'config'}, \%uphash);
2214 &General::firewall_config_changed();
2215 }
2216 sub pos_down
2217 {
2218 my %downhash=();
2219 my %tmp=();
2220 &General::readhasharray($fwdfwsettings{'config'}, \%downhash);
2221 foreach my $key (sort keys %downhash){
2222 if ($key eq $fwdfwsettings{'key'}) {
2223 my $next = $key + 1;
2224 if (exists $downhash{$next}){
2225 #save rule next
2226 foreach my $y (0 .. $#{$downhash{$next}}) {
2227 $tmp{0}[$y] = $downhash{$next}[$y];
2228 }
2229 #copy active rule to next
2230 foreach my $i (0 .. $#{$downhash{$next}}) {
2231 $downhash{$next}[$i] = $downhash{$key}[$i];
2232 }
2233 #copy saved rule to actual position
2234 foreach my $x (0 .. $#{$tmp{0}}) {
2235 $downhash{$key}[$x] = $tmp{0}[$x];
2236 }
2237 }
2238 }
2239 }
2240 &General::writehasharray($fwdfwsettings{'config'}, \%downhash);
2241 &General::firewall_config_changed();
2242 }
2243 sub saverule
2244 {
2245 my $hash=shift;
2246 my $config=shift;
2247 &General::readhasharray("$config", $hash);
2248 if (!$errormessage){
2249 ################################################################
2250 #check if we change an INPUT rule to a OUTGOING
2251 if($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW' ){
2252 &changerule($configinput);
2253 #print"1";
2254 }
2255 #check if we change an INPUT rule to a FORWARD
2256 elsif($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
2257 &changerule($configinput);
2258 #print"2";
2259 }
2260 ################################################################
2261 #check if we change an OUTGOING rule to an INPUT
2262 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'INPUTFW' ){
2263 &changerule($configoutgoing);
2264 #print"3";
2265 }
2266 #check if we change an OUTGOING rule to a FORWARD
2267 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
2268 &changerule($configoutgoing);
2269 #print"4";
2270 }
2271 ################################################################
2272 #check if we change a FORWARD rule to an INPUT
2273 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'INPUTFW'){
2274 &changerule($configfwdfw);
2275 #print"5";
2276 }
2277 #check if we change a FORWARD rule to an OUTGOING
2278 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW'){
2279 &changerule($configfwdfw);
2280 #print"6";
2281 }
2282 $fwdfwsettings{'ruleremark'}=~ s/,/;/g;
2283 utf8::decode($fwdfwsettings{'ruleremark'});
2284 $fwdfwsettings{'ruleremark'}=&Header::escape($fwdfwsettings{'ruleremark'});
2285 if ($fwdfwsettings{'updatefwrule'} ne 'on'){
2286 my $key = &General::findhasharraykey ($hash);
2287 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
2288 $$hash{$key}[1] = $fwdfwsettings{'chain'};
2289 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
2290 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
2291 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
2292 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
2293 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
2294 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
2295 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
2296 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
2297 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
2298 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
2299 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
2300 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
2301 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
2302 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
2303 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
2304 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
2305 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
2306 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
2307 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
2308 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
2309 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
2310 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
2311 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
2312 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
2313 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
2314 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
2315 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
2316 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
2317 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
2318 $$hash{$key}[31] = $fwdfwsettings{'nat'};
2319 $$hash{$key}[32] = $fwdfwsettings{'LIMIT_CON_CON'};
2320 $$hash{$key}[33] = $fwdfwsettings{'concon'};
2321 $$hash{$key}[34] = $fwdfwsettings{'RATE_LIMIT'};
2322 $$hash{$key}[35] = $fwdfwsettings{'ratecon'};
2323 $$hash{$key}[36] = $fwdfwsettings{'RATETIME'};
2324 &General::writehasharray("$config", $hash);
2325 }else{
2326 foreach my $key (sort {$a <=> $b} keys %$hash){
2327 if($key eq $fwdfwsettings{'key'}){
2328 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
2329 $$hash{$key}[1] = $fwdfwsettings{'chain'};
2330 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
2331 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
2332 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
2333 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
2334 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
2335 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
2336 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
2337 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
2338 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
2339 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
2340 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
2341 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
2342 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
2343 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
2344 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
2345 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
2346 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
2347 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
2348 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
2349 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
2350 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
2351 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
2352 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
2353 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
2354 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
2355 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
2356 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
2357 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
2358 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
2359 $$hash{$key}[31] = $fwdfwsettings{'nat'};
2360 $$hash{$key}[32] = $fwdfwsettings{'LIMIT_CON_CON'};
2361 $$hash{$key}[33] = $fwdfwsettings{'concon'};
2362 $$hash{$key}[34] = $fwdfwsettings{'RATE_LIMIT'};
2363 $$hash{$key}[35] = $fwdfwsettings{'ratecon'};
2364 $$hash{$key}[36] = $fwdfwsettings{'RATETIME'};
2365 last;
2366 }
2367 }
2368 }
2369 &General::writehasharray("$config", $hash);
2370 if($fwdfwsettings{'oldrulenumber'} > $fwdfwsettings{'rulepos'}){
2371 my %tmp=();
2372 my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'};
2373 for (my $z=0;$z<$val;$z++){
2374 foreach my $key (sort {$a <=> $b} keys %$hash){
2375 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2376 my $last = $key -1;
2377 if (exists $$hash{$last}){
2378 #save rule last
2379 foreach my $y (0 .. $#{$$hash{$last}}) {
2380 $tmp{0}[$y] = $$hash{$last}[$y];
2381 }
2382 #copy active rule to last
2383 foreach my $i (0 .. $#{$$hash{$last}}) {
2384 $$hash{$last}[$i] = $$hash{$key}[$i];
2385 }
2386 #copy saved rule to actual position
2387 foreach my $x (0 .. $#{$tmp{0}}) {
2388 $$hash{$key}[$x] = $tmp{0}[$x];
2389 }
2390 }
2391 }
2392 }
2393 $fwdfwsettings{'oldrulenumber'}--;
2394 }
2395 &General::writehasharray("$config", $hash);
2396 &General::firewall_config_changed();
2397 }elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
2398 my %tmp=();
2399 my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
2400 for (my $z=0;$z<$val;$z++){
2401 foreach my $key (sort {$a <=> $b} keys %$hash){
2402 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2403 my $next = $key + 1;
2404 if (exists $$hash{$next}){
2405 #save rule next
2406 foreach my $y (0 .. $#{$$hash{$next}}) {
2407 $tmp{0}[$y] = $$hash{$next}[$y];
2408 }
2409 #copy active rule to next
2410 foreach my $i (0 .. $#{$$hash{$next}}) {
2411 $$hash{$next}[$i] = $$hash{$key}[$i];
2412 }
2413 #copy saved rule to actual position
2414 foreach my $x (0 .. $#{$tmp{0}}) {
2415 $$hash{$key}[$x] = $tmp{0}[$x];
2416 }
2417 }
2418 }
2419 }
2420 $fwdfwsettings{'oldrulenumber'}++;
2421 }
2422 &General::writehasharray("$config", $hash);
2423 &General::firewall_config_changed();
2424 }
2425 }
2426 }
2427 sub validremark
2428 {
2429 # Checks a hostname against RFC1035
2430 my $remark = $_[0];
2431
2432 # Try to decode $remark into UTF-8. If this doesn't work,
2433 # we assume that the string it not sane.
2434 if (!utf8::decode($remark)) {
2435 return 0;
2436 }
2437
2438 # Check if the string only contains of printable characters.
2439 if ($remark =~ /^[[:print:]]*$/) {
2440 return 1;
2441 }
2442 return 0;
2443 }
2444 sub viewtablerule
2445 {
2446 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
2447
2448 &viewtablenew(\%configfwdfw, $configfwdfw, $Lang::tr{'firewall rules'});
2449 &viewtablenew(\%configinputfw, $configinput, $Lang::tr{'incoming firewall access'});
2450 &viewtablenew(\%configoutgoingfw, $configoutgoing, $Lang::tr{'outgoing firewall access'});
2451 }
2452 sub viewtablenew
2453 {
2454 my $hash=shift;
2455 my $config=shift;
2456 my $title=shift;
2457 my $go='';
2458
2459 my $show_box = (! -z $config) || ($optionsfw{'SHOWTABLES'} eq 'on');
2460 return if (!$show_box);
2461
2462 &General::get_aliases(\%aliases);
2463 &General::readhasharray("$confighost", \%customhost);
2464 &General::readhasharray("$config", $hash);
2465 &General::readhasharray("$configccdnet", \%ccdnet);
2466 &General::readhasharray("$configccdhost", \%ccdhost);
2467 &General::readhasharray("$configgrp", \%customgrp);
2468 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2469
2470 &Header::openbox('100%', 'left', $title);
2471 print "<table width='100%' cellspacing='0' class='tbl'>";
2472
2473 if (! -z $config) {
2474 my $count=0;
2475 my ($gif,$log);
2476 my $ruletype;
2477 my $rulecolor;
2478 my $tooltip;
2479 my @tmpsrc=();
2480 my @tmptgt=();
2481 my $coloryellow='';
2482
2483 print <<END;
2484 <tr>
2485 <th align='right' width='3%'>
2486 #
2487 </th>
2488 <th width='2%'></th>
2489 <th align='center'>
2490 <b>$Lang::tr{'protocol'}</b>
2491 </th>
2492 <th align='center' width='30%'>
2493 <b>$Lang::tr{'fwdfw source'}</b>
2494 </th>
2495 <th align='center'>
2496 <b>$Lang::tr{'fwdfw log'}</b>
2497 </th>
2498 <th align='center' width='30%'>
2499 <b>$Lang::tr{'fwdfw target'}</b>
2500 </th>
2501 <th align='center' colspan='6' width='18%'>
2502 <b>$Lang::tr{'fwdfw action'}</b>
2503 </th>
2504 </tr>
2505 END
2506
2507 foreach my $key (sort {$a <=> $b} keys %$hash){
2508 $tdcolor='';
2509 @tmpsrc=();
2510 @tmptgt=();
2511 #check if vpn hosts/nets have been deleted
2512 if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){
2513 push (@tmpsrc,$$hash{$key}[4]);
2514 }
2515 if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){
2516 push (@tmptgt,$$hash{$key}[6]);
2517 }
2518 foreach my $host (@tmpsrc){
2519 if($$hash{$key}[3] eq 'ipsec_net_src'){
2520 if(&fwlib::get_ipsec_net_ip($host,11) eq ''){
2521 $coloryellow='on';
2522 }
2523 }elsif($$hash{$key}[3] eq 'ovpn_net_src'){
2524 if(&fwlib::get_ovpn_net_ip($host,1) eq ''){
2525 $coloryellow='on';
2526 }
2527 }elsif($$hash{$key}[3] eq 'ovpn_n2n_src'){
2528 if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){
2529 $coloryellow='on';
2530 }
2531 }elsif($$hash{$key}[3] eq 'ovpn_host_src'){
2532 if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
2533 $coloryellow='on';
2534 }
2535 }
2536 }
2537 foreach my $host (@tmptgt){
2538 if($$hash{$key}[5] eq 'ipsec_net_tgt'){
2539 if(&fwlib::get_ipsec_net_ip($host,11) eq ''){
2540 $coloryellow='on';
2541 }
2542 }elsif($$hash{$key}[5] eq 'ovpn_net_tgt'){
2543 if(&fwlib::get_ovpn_net_ip($host,1) eq ''){
2544 $coloryellow='on';
2545 }
2546 }elsif($$hash{$key}[5] eq 'ovpn_n2n_tgt'){
2547 if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){
2548 $coloryellow='on';
2549 }
2550 }elsif($$hash{$key}[5] eq 'ovpn_host_tgt'){
2551 if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
2552 $coloryellow='on';
2553 }
2554 }
2555 }
2556 #check if networkgroups or servicegroups are empty
2557 foreach my $netgroup (sort keys %customgrp){
2558 if(($$hash{$key}[4] eq $customgrp{$netgroup}[0] || $$hash{$key}[6] eq $customgrp{$netgroup}[0]) && $customgrp{$netgroup}[2] eq 'none'){
2559 $coloryellow='on';
2560 }
2561 }
2562 foreach my $srvgroup (sort keys %customservicegrp){
2563 if($$hash{$key}[15] eq $customservicegrp{$srvgroup}[0] && $customservicegrp{$srvgroup}[2] eq 'none'){
2564 $coloryellow='on';
2565 }
2566 }
2567 $$hash{'ACTIVE'}=$$hash{$key}[2];
2568 $count++;
2569 if($coloryellow eq 'on'){
2570 $color="$color{'color14'}";
2571 $coloryellow='';
2572 }elsif($coloryellow eq ''){
2573 if ($count % 2){
2574 $color="$color{'color22'}";
2575 }
2576 else{
2577 $color="$color{'color20'}";
2578 }
2579 }
2580 print<<END;
2581 <tr bgcolor='$color'>
2582 <td align='right' width='3%'>
2583 <b>$key&nbsp;</b>
2584 </td>
2585 END
2586
2587 #RULETYPE (A,R,D)
2588 if ($$hash{$key}[0] eq 'ACCEPT'){
2589 $ruletype='A';
2590 $tooltip='ACCEPT';
2591 $rulecolor=$color{'color17'};
2592 }elsif($$hash{$key}[0] eq 'DROP'){
2593 $ruletype='D';
2594 $tooltip='DROP';
2595 $rulecolor=$color{'color25'};
2596 }elsif($$hash{$key}[0] eq 'REJECT'){
2597 $ruletype='R';
2598 $tooltip='REJECT';
2599 $rulecolor=$color{'color16'};
2600 }
2601
2602 print <<END;
2603 <td bgcolor='$rulecolor' align='center' width='2%'>
2604 <span title='$tooltip'>&nbsp;&nbsp;</span>
2605 </td>
2606 END
2607
2608 #Get Protocol
2609 my $prot;
2610 if ($$hash{$key}[8]){
2611 if ($$hash{$key}[8] eq "IPv6"){
2612 push (@protocols,$Lang::tr{'fwdfw prot41 short'})
2613 }else{
2614 push (@protocols,$$hash{$key}[8]);
2615 }
2616 }elsif($$hash{$key}[14] eq 'cust_srv'){
2617 &get_serviceports("service",$$hash{$key}[15]);
2618 }elsif($$hash{$key}[14] eq 'cust_srvgrp'){
2619 &get_serviceports("group",$$hash{$key}[15]);
2620 }else{
2621 push (@protocols,$Lang::tr{'all'});
2622 }
2623
2624 my $protz=join(", ",@protocols);
2625 if($protz eq 'ICMP' && $$hash{$key}[9] ne 'All ICMP-Types' && $$hash{$key}[14] ne 'cust_srvgrp'){
2626 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
2627 foreach my $keyicmp (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
2628 if($$hash{$key}[9] eq "$icmptypes{$keyicmp}[0]"){
2629 print "<td align='center'><span title='$icmptypes{$keyicmp}[0]'><b>$protz ($icmptypes{$keyicmp}[1])</b></span></td>";
2630 last;
2631 }
2632 }
2633 }elsif($#protocols gt '3'){
2634 print"<td align='center'><span title='$protz'>$Lang::tr{'fwdfw many'}</span></td>";
2635 }else{
2636 print"<td align='center'>$protz</td>";
2637 }
2638 @protocols=();
2639 #SOURCE
2640 my $ipfireiface;
2641 &getcolor($$hash{$key}[3],$$hash{$key}[4],\%customhost);
2642 print"<td align='center' width='30%' $tdcolor>";
2643 if ($$hash{$key}[3] eq 'ipfire_src'){
2644 $ipfireiface=$Lang::tr{'fwdfw iface'};
2645 }
2646 if ($$hash{$key}[3] eq 'std_net_src'){
2647 print &get_name($$hash{$key}[4]);
2648 }elsif ($$hash{$key}[3] eq 'src_addr'){
2649 my ($split1,$split2) = split("/",$$hash{$key}[4]);
2650 if ($split2 eq '32'){
2651 print $split1;
2652 }else{
2653 print $$hash{$key}[4];
2654 }
2655 }elsif ($$hash{$key}[3] eq 'cust_geoip_src') {
2656 my ($split1,$split2) = split(":", $$hash{$key}[4]);
2657 if ($split2) {
2658 print "$split2\n";
2659 }else{
2660 print "$Lang::tr{'geoip'}: $$hash{$key}[4]\n";
2661 }
2662 }elsif ($$hash{$key}[4] eq 'RED1'){
2663 print "$ipfireiface $Lang::tr{'fwdfw red'}";
2664 }elsif ($$hash{$key}[4] eq 'ALL'){
2665 print "$ipfireiface $Lang::tr{'all'}";
2666 }else{
2667 if ($$hash{$key}[4] eq 'GREEN' || $$hash{$key}[4] eq 'ORANGE' || $$hash{$key}[4] eq 'BLUE' || $$hash{$key}[4] eq 'RED'){
2668 print "$ipfireiface $Lang::tr{lc($$hash{$key}[4])}";
2669 }else{
2670 print "$ipfireiface $$hash{$key}[4]";
2671 }
2672 }
2673 $tdcolor='';
2674 #SOURCEPORT
2675 &getsrcport(\%$hash,$key);
2676 #Is this a SNAT rule?
2677 if ($$hash{$key}[31] eq 'snat' && $$hash{$key}[28] eq 'ON'){
2678 my $net=&get_name($$hash{$key}[29]);
2679 if ( ! $net){ $net=$$hash{$key}[29];}
2680 print"<br>->$net";
2681 if ($$hash{$key}[30] ne ''){
2682 print": $$hash{$key}[30]";
2683 }
2684 }
2685 if ($$hash{$key}[17] eq 'ON'){
2686 $log="/images/on.gif";
2687 }else{
2688 $log="/images/off.gif";
2689 }
2690 #LOGGING
2691 print<<END;
2692 </td>
2693 <td align='center'>
2694 <form method='POST' action=''>
2695 <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 ;'/>
2696 <input type='hidden' name='key' value='$key' />
2697 <input type='hidden' name='config' value='$config' />
2698 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw togglelog'}' />
2699 </form>
2700 </td>
2701 END
2702 #TARGET
2703 &getcolor($$hash{$key}[5],$$hash{$key}[6],\%customhost);
2704 print<<END;
2705 <td align='center' $tdcolor>
2706 END
2707 #Is this a DNAT rule?
2708 my $natstring;
2709 if ($$hash{$key}[31] eq 'dnat' && $$hash{$key}[28] eq 'ON'){
2710 if ($$hash{$key}[29] eq 'Default IP'){$$hash{$key}[29]=$Lang::tr{'red1'};}
2711 if ($$hash{$key}[29] eq 'AUTO'){
2712 my @src_addresses=&fwlib::get_addresses(\%$hash,$key,'src');
2713 my @nat_ifaces;
2714 foreach my $val (@src_addresses){
2715 push (@nat_ifaces,&fwlib::get_nat_address($$hash{$key}[29],$val));
2716 }
2717 @nat_ifaces=&del_double(@nat_ifaces);
2718 $natstring = "";
2719 }else{
2720 $natstring = "($$hash{$key}[29])";
2721 }
2722 print "$Lang::tr{'firewall'} $natstring";
2723 if($$hash{$key}[30] ne ''){
2724 $$hash{$key}[30]=~ tr/|/,/;
2725 print": $$hash{$key}[30]";
2726 }
2727 print"<br>-&gt;";
2728 }
2729 if ($$hash{$key}[5] eq 'std_net_tgt' || $$hash{$key}[5] eq 'ipfire'){
2730 if ($$hash{$key}[6] eq 'RED1'){
2731 print "$Lang::tr{'red1'}";
2732 }elsif ($$hash{$key}[6] eq 'GREEN' || $$hash{$key}[6] eq 'ORANGE' || $$hash{$key}[6] eq 'BLUE'|| $$hash{$key}[6] eq 'ALL' || $$hash{$key}[6] eq 'RED')
2733 {
2734 print &get_name($$hash{$key}[6]);
2735 }else{
2736 print $$hash{$key}[6];
2737 }
2738 }elsif ($$hash{$key}[5] eq 'cust_geoip_tgt') {
2739 my ($split1,$split2) = split(":", $$hash{$key}[6]);
2740 if ($split2) {
2741 print "$split2\n";
2742 }else{
2743 print "$Lang::tr{'geoip'}: $$hash{$key}[6]\n";
2744 }
2745 }elsif ($$hash{$key}[5] eq 'tgt_addr'){
2746 my ($split1,$split2) = split("/",$$hash{$key}[6]);
2747 if ($split2 eq '32'){
2748 print $split1;
2749 }else{
2750 print $$hash{$key}[6];
2751 }
2752 }else{
2753 print "$$hash{$key}[6]";
2754 }
2755 $tdcolor='';
2756 #TARGETPORT
2757 &gettgtport(\%$hash,$key);
2758 print"</td>";
2759 #RULE ACTIVE
2760 if($$hash{$key}[2] eq 'ON'){
2761 $gif="/images/on.gif"
2762 }else{
2763 $gif="/images/off.gif"
2764 }
2765 print<<END;
2766 <td width='3%' align='center'>
2767 <form method='POST' action=''>
2768 <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;' />
2769 <input type='hidden' name='key' value='$key' />
2770 <input type='hidden' name='config' value='$config' />
2771 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw toggle'}' />
2772 </form>
2773 </td>
2774 <td width='3%' align='center'>
2775 <form method='POST' action=''>
2776 <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;' />
2777 <input type='hidden' name='key' value='$key' />
2778 <input type='hidden' name='config' value='$config' />
2779 <input type='hidden' name='ACTION' value='editrule' />
2780 </form>
2781 </td>
2782 <td width='3%' align='center'>
2783 <form method='POST' action=''>
2784 <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;' />
2785 <input type='hidden' name='key' value='$key' />
2786 <input type='hidden' name='config' value='$config' />
2787 <input type='hidden' name='ACTION' value='copyrule' />
2788 </form>
2789 </td>
2790 <td width='3%' align='center'>
2791 <form method='POST' action=''>
2792 <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;' />
2793 <input type='hidden' name='key' value='$key' />
2794 <input type='hidden' name='config' value='$config' />
2795 <input type='hidden' name='ACTION' value='deleterule' />
2796 </form>
2797 </td>
2798 END
2799 if (exists $$hash{$key-1}){
2800 print<<END;
2801 <td width='3%' align='center'>
2802 <form method='POST' action=''>
2803 <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;' />
2804 <input type='hidden' name='key' value='$key' />
2805 <input type='hidden' name='config' value='$config' />
2806 <input type='hidden' name='ACTION' value='moveup' />
2807 </form>
2808 </td>
2809 END
2810 }else{
2811 print"<td width='3%'></td>";
2812 }
2813
2814 if (exists $$hash{$key+1}){
2815 print<<END;
2816 <td width='3%' align='center'>
2817 <form method='POST' action=''>
2818 <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;' />
2819 <input type='hidden' name='key' value='$key' />
2820 <input type='hidden' name='config' value='$config' />
2821 <input type='hidden' name='ACTION' value='movedown' />
2822 </form>
2823 </td>
2824 </tr>
2825 END
2826 }else{
2827 print"<td width='3%'></td></tr>";
2828 }
2829 #REMARK
2830 if ($optionsfw{'SHOWREMARK'} eq 'on' && $$hash{$key}[16] ne ''){
2831 print <<END;
2832 <tr bgcolor='$color'>
2833 <td>&nbsp;</td>
2834 <td bgcolor='$rulecolor'></td>
2835 <td colspan='10'>
2836 &nbsp; <em>$$hash{$key}[16]</em>
2837 </td>
2838 </tr>
2839 END
2840 }
2841
2842 if ($$hash{$key}[18] eq 'ON'){
2843 #TIMEFRAME
2844 if ($$hash{$key}[18] eq 'ON'){
2845 my @days=();
2846 if($$hash{$key}[19] ne ''){push (@days,$Lang::tr{'fwdfw wd_mon'});}
2847 if($$hash{$key}[20] ne ''){push (@days,$Lang::tr{'fwdfw wd_tue'});}
2848 if($$hash{$key}[21] ne ''){push (@days,$Lang::tr{'fwdfw wd_wed'});}
2849 if($$hash{$key}[22] ne ''){push (@days,$Lang::tr{'fwdfw wd_thu'});}
2850 if($$hash{$key}[23] ne ''){push (@days,$Lang::tr{'fwdfw wd_fri'});}
2851 if($$hash{$key}[24] ne ''){push (@days,$Lang::tr{'fwdfw wd_sat'});}
2852 if($$hash{$key}[25] ne ''){push (@days,$Lang::tr{'fwdfw wd_sun'});}
2853 my $weekdays=join(",",@days);
2854 if (@days){
2855 print"<tr bgcolor='$color'>";
2856 print"<td>&nbsp;</td><td bgcolor='$rulecolor'></td><td align='left' colspan='10'>&nbsp; $weekdays &nbsp; $$hash{$key}[26] - $$hash{$key}[27]</td></tr>";
2857 }
2858 }
2859 }
2860 print"<tr bgcolor='FFFFFF'><td colspan='13' height='1'></td></tr>";
2861 }
2862 } elsif ($optionsfw{'SHOWTABLES'} eq 'on') {
2863 print <<END;
2864 <tr>
2865 <td colspan='7' height='30' bgcolor=$color{'color22'} align='center'>$Lang::tr{'fwhost empty'}</td>
2866 </tr>
2867 END
2868 }
2869
2870 #SHOW FINAL RULE
2871 my $policy = 'fwdfw ' . $fwdfwsettings{'POLICY'};
2872 my $colour = "bgcolor='green'";
2873 if ($fwdfwsettings{'POLICY'} eq 'MODE1') {
2874 $colour = "bgcolor='darkred'";
2875 }
2876
2877 my $message;
2878 if (($config eq '/var/ipfire/firewall/config') && ($fwdfwsettings{'POLICY'} ne 'MODE1')) {
2879 print <<END;
2880 <tr>
2881 <td colspan='13'>&nbsp;</td>
2882 </tr>
2883 <tr>
2884 <td colspan='13' style="padding-left:0px;padding-right:0px">
2885 <table width="100%" border='1' rules="cols" cellspacing='0'>
2886 END
2887
2888 # GREEN
2889 print <<END;
2890 <tr>
2891 <td align='center'>
2892 <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
2893 </td>
2894 <td align='center'>
2895 <font color="$Header::colourred">$Lang::tr{'red'}</font>
2896 ($Lang::tr{'fwdfw pol allow'})
2897 </td>
2898 END
2899
2900 if (&Header::orange_used()) {
2901 print <<END;
2902 <td align='center'>
2903 <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
2904 ($Lang::tr{'fwdfw pol allow'})
2905 </td>
2906 END
2907 }
2908
2909 if (&Header::blue_used()) {
2910 print <<END;
2911 <td align='center'>
2912 <font color="$Header::colourblue">$Lang::tr{'blue'}</font>
2913 ($Lang::tr{'fwdfw pol allow'})
2914 </td>
2915 END
2916 }
2917
2918 print"</tr>";
2919
2920 # ORANGE
2921 if (&Header::orange_used()) {
2922 print <<END;
2923 <tr>
2924 <td align='center' width='20%'>
2925 <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
2926 </td>
2927 <td align='center'>
2928 <font color="$Header::colourred">$Lang::tr{'red'}</font>
2929 ($Lang::tr{'fwdfw pol allow'})
2930 </td>
2931 <td align='center'>
2932 <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
2933 ($Lang::tr{'fwdfw pol block'})
2934 </td>
2935 END
2936
2937 if (&Header::blue_used()) {
2938 print <<END;
2939 <td align='center'>
2940 <font color="$Header::colourblue">$Lang::tr{'blue'}</font>
2941 ($Lang::tr{'fwdfw pol block'})
2942 </td>
2943 END
2944 }
2945
2946 print"</tr>";
2947 }
2948
2949 if (&Header::blue_used()) {
2950 print <<END;
2951 <tr>
2952 <td align='center'>
2953 <font color="$Header::colourblue">$Lang::tr{'blue'}</font>
2954 </td>
2955 <td align='center'>
2956 <font color="$Header::colourred">$Lang::tr{'red'}</font>
2957 ($Lang::tr{'fwdfw pol allow'})
2958 </td>
2959 END
2960
2961 if (&Header::orange_used()) {
2962 print <<END;
2963 <td align='center'>
2964 <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
2965 ($Lang::tr{'fwdfw pol block'})
2966 </td>
2967 END
2968 }
2969
2970 print <<END;
2971 <td align='center'>
2972 <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
2973 ($Lang::tr{'fwdfw pol block'})
2974 </td>
2975 </tr>
2976 END
2977 }
2978
2979 print <<END;
2980 </table>
2981 </td>
2982 </tr>
2983 END
2984
2985 $message = $Lang::tr{'fwdfw pol allow'};
2986
2987 } elsif ($config eq '/var/ipfire/firewall/outgoing' && ($fwdfwsettings{'POLICY1'} ne 'MODE1')) {
2988 $message = $Lang::tr{'fwdfw pol allow'};
2989 $colour = "bgcolor='green'";
2990 } else {
2991 $message = $Lang::tr{'fwdfw pol block'};
2992 $colour = "bgcolor='darkred'";
2993 }
2994
2995 if ($message) {
2996 print <<END;
2997 <tr>
2998 <td $colour align='center' colspan='13'>
2999 <font color='#FFFFFF'>$Lang::tr{'policy'}: $message</font>
3000 </td>
3001 </tr>
3002 END
3003 }
3004
3005 print "</table>";
3006 print "<br>";
3007
3008 &Header::closebox();
3009 }
3010
3011 &Header::closebigbox();
3012 &Header::closepage();