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