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