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