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