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