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