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