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