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