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