Forward Firewall: cleanup unused code
[people/teissler/ipfire-2.x.git] / html / cgi-bin / forwardfw.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 #
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 ###############################################################################
21 # #
22 # Hi folks! I hope this code is useful for all. I needed something to handle #
23 # my VPN Connections in a comfortable way. As a prerequisite i needed #
24 # something that makes sure the vpn roadwarrior are able to have a fixed #
25 # ip-address. So i developed the ccd extension for the vpn server. #
26 # #
27 # Now that the ccd extension is ready i am able to develop the main request. #
28 # Any feedback is appreciated. #
29 # #
30 #Copymaster #
31 ###############################################################################
32
33 use strict;
34 use Sort::Naturally;
35 no warnings 'uninitialized';
36 # enable only the following on debugging purpose
37 #use warnings;
38 #use CGI::Carp 'fatalsToBrowser';
39
40 require '/var/ipfire/general-functions.pl';
41 require "${General::swroot}/lang.pl";
42 require "${General::swroot}/header.pl";
43 require "${General::swroot}/forward/bin/firewall-lib.pl";
44
45 unless (-d "${General::swroot}/forward") { system("mkdir ${General::swroot}/forward"); }
46 unless (-e "${General::swroot}/forward/settings") { system("touch ${General::swroot}/forward/settings"); }
47 unless (-e "${General::swroot}/forward/config") { system("touch ${General::swroot}/forward/config"); }
48 unless (-e "${General::swroot}/forward/input") { system("touch ${General::swroot}/forward/input"); }
49 unless (-e "${General::swroot}/forward/outgoing") { system("touch ${General::swroot}/forward/outgoing"); }
50 unless (-e "${General::swroot}/forward/dmz") { system("touch ${General::swroot}/forward/dmz"); }
51 unless (-e "${General::swroot}/forward/nat") { system("touch ${General::swroot}/forward/nat"); }
52
53 my %fwdfwsettings=();
54 my %selected=() ;
55 my %defaultNetworks=();
56 my %netsettings=();
57 my %customhost=();
58 my %customgrp=();
59 my %customnetworks=();
60 my %customservice=();
61 my %customservicegrp=();
62 my %ccdnet=();
63 my %customnetwork=();
64 my %ccdhost=();
65 my %configfwdfw=();
66 my %configinputfw=();
67 my %configoutgoingfw=();
68 my %configdmzfw=();
69 my %confignatfw=();
70 my %ipsecconf=();
71 my %color=();
72 my %mainsettings=();
73 my %checked=();
74 my %icmptypes=();
75 my %ovpnsettings=();
76 my %ipsecsettings=();
77 my %aliases=();
78 my %optionsfw=();
79 my %ifaces=();
80
81 my $VERSION='0.9.9.8';
82 my $color;
83 my $confignet = "${General::swroot}/fwhosts/customnetworks";
84 my $confighost = "${General::swroot}/fwhosts/customhosts";
85 my $configgrp = "${General::swroot}/fwhosts/customgroups";
86 my $configsrv = "${General::swroot}/fwhosts/customservices";
87 my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
88 my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
89 my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
90 my $configipsec = "${General::swroot}/vpn/config";
91 my $configipsecrw = "${General::swroot}/vpn/settings";
92 my $configfwdfw = "${General::swroot}/forward/config";
93 my $configinput = "${General::swroot}/forward/input";
94 my $configoutgoing = "${General::swroot}/forward/outgoing";
95 my $configdmz = "${General::swroot}/forward/dmz";
96 my $confignat = "${General::swroot}/forward/nat";
97 my $configovpn = "${General::swroot}/ovpn/settings";
98 my $fwoptions = "${General::swroot}/optionsfw/settings";
99 my $ifacesettings = "${General::swroot}/ethernet/settings";
100 my $errormessage='';
101 my $hint='';
102 my $ipgrp="${General::swroot}/outgoing/groups";
103 my $tdcolor='';
104 my $checkorange='';
105 my @protocols;
106 &General::readhash("${General::swroot}/forward/settings", \%fwdfwsettings);
107 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
108 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
109 &General::readhash($fwoptions, \%optionsfw);
110 &General::readhash($ifacesettings, \%ifaces);
111 &General::readhash("$configovpn", \%ovpnsettings);
112 &General::readhash("$configipsecrw", \%ipsecsettings);
113 &General::readhasharray("$configipsec", \%ipsecconf);
114 &Header::showhttpheaders();
115 &Header::getcgihash(\%fwdfwsettings);
116 &Header::openpage($Lang::tr{'fwdfw menu'}, 1, '');
117 &Header::openbigbox('100%', 'center',$errormessage);
118 #### ACTION #####
119
120 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'save'})
121 {
122 my $MODE = $fwdfwsettings{'POLICY'};
123 my $MODE1 = $fwdfwsettings{'POLICY1'};
124 %fwdfwsettings = ();
125 $fwdfwsettings{'POLICY'} = "$MODE";
126 $fwdfwsettings{'POLICY1'} = "$MODE1";
127 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
128 &reread_rules;
129 }
130 if ($fwdfwsettings{'ACTION'} eq 'saverule')
131 {
132 &General::readhasharray("$configfwdfw", \%configfwdfw);
133 &General::readhasharray("$configinput", \%configinputfw);
134 &General::readhasharray("$configoutgoing", \%configoutgoingfw);
135 &General::readhasharray("$confignat", \%confignatfw);
136 $errormessage=&checksource;
137 if(!$errormessage){&checktarget;}
138 if(!$errormessage){&checkrule;}
139
140 #check if manual ip (source) is orange network
141 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
142 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
143 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
144 $checkorange='on';
145 }
146 }
147 #check useless rules
148 if( ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' || $checkorange eq 'on') && $fwdfwsettings{'grp2'} eq 'ipfire'){
149 $errormessage.=$Lang::tr{'fwdfw useless rule'}."<br>";
150 }
151 #check if we try to break rules
152 if( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'grp2'} eq 'ipfire'){
153 $errormessage.=$Lang::tr{'fwdfw err same'};
154 }
155 #NAT-Part
156 if ($fwdfwsettings{'USE_NAT'} eq 'ON'){
157 $fwdfwsettings{'config'}=$confignat;
158 if ($fwdfwsettings{'nat'} eq 'dnat'){
159 $fwdfwsettings{'chain'} = 'NAT_DESTINATION';
160 }else{
161 $fwdfwsettings{'chain'} = 'NAT_SOURCE';
162 }
163 my $maxkey=&General::findhasharraykey(\%confignatfw);
164 #check if we have an identical rule already
165 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
166 foreach my $key (sort keys %confignatfw){
167 if ("$confignatfw{$key}[0],$confignatfw{$key}[1],$confignatfw{$key}[2],$confignatfw{$key}[3],$confignatfw{$key}[4],$confignatfw{$key}[5],$confignatfw{$key}[6],$confignatfw{$key}[11],$confignatfw{$key}[12],$confignatfw{$key}[14],$confignatfw{$key}[15],$confignatfw{$key}[28],$confignatfw{$key}[29],$confignatfw{$key}[30],$confignatfw{$key}[31]"
168 eq "$fwdfwsettings{'RULE_ACTION'},NAT_DESTINATION,$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"){
169 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
170 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' ){
171 $errormessage='';
172 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
173 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
174 }
175 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
176 $fwdfwsettings{'nosave'} = 'on';
177 }
178 }
179 }
180 }
181
182 #check Rulepos on new Rule
183 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
184 $fwdfwsettings{'oldrulenumber'}=$maxkey;
185 foreach my $key (sort keys %confignatfw){
186 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{'snatport'},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
187 eq "$confignatfw{$key}[0],$confignatfw{$key}[2],$confignatfw{$key}[3],$confignatfw{$key}[4],$confignatfw{$key}[5],$confignatfw{$key}[6],$confignatfw{$key}[7],$confignatfw{$key}[8],$confignatfw{$key}[9],$confignatfw{$key}[10],$confignatfw{$key}[11],$confignatfw{$key}[12],$confignatfw{$key}[13],$confignatfw{$key}[14],$confignatfw{$key}[15],$confignatfw{$key}[17],$confignatfw{$key}[19],$confignatfw{$key}[20],$confignatfw{$key}[21],$confignatfw{$key}[22],$confignatfw{$key}[23],$confignatfw{$key}[24],$confignatfw{$key}[25],$confignatfw{$key}[26],$confignatfw{$key}[27],$confignatfw{$key}[28],$confignatfw{$key}[29],$confignatfw{$key}[30],$confignatfw{$key}[31],$confignatfw{$key}[32]"){
188 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
189 }
190 }
191 }
192 #check if we just close a rule
193 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'}) {
194 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
195 $errormessage='';
196 $fwdfwsettings{'nosave2'} = 'on';
197 }
198 }
199 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
200 if ($fwdfwsettings{'nobase'} ne 'on'){
201 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
202 }
203 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
204 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
205 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
206 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
207 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
208 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
209 }
210 if($fwdfwsettings{'nosave2'} ne 'on'){
211 &saverule(\%confignatfw,$confignat);
212 }
213 #DMZ-Part
214 }elsif ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' || $checkorange eq 'on'){
215 $fwdfwsettings{'config'}=$configdmz;
216 $fwdfwsettings{'chain'} = 'FORWARDFW';
217 my $maxkey=&General::findhasharraykey(\%configdmzfw);
218 #check if we have an identical rule already
219 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
220 foreach my $key (sort keys %configdmzfw){
221 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'}"
222 eq "$configdmzfw{$key}[0],$configdmzfw{$key}[2],$configdmzfw{$key}[3],$configdmzfw{$key}[4],$configdmzfw{$key}[5],$configdmzfw{$key}[6],$configdmzfw{$key}[7],$configdmzfw{$key}[8],$configdmzfw{$key}[9],$configdmzfw{$key}[10],$configdmzfw{$key}[11],$configdmzfw{$key}[12],$configdmzfw{$key}[13],$configdmzfw{$key}[14],$configdmzfw{$key}[15],$configdmzfw{$key}[17],$configdmzfw{$key}[18],$configdmzfw{$key}[19],$configdmzfw{$key}[20],$configdmzfw{$key}[21],$configdmzfw{$key}[22],$configdmzfw{$key}[23],$configdmzfw{$key}[24],$configdmzfw{$key}[25],$configdmzfw{$key}[26],$configdmzfw{$key}[27]"){
223 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
224 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' ){
225 $errormessage='';
226 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
227 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
228 }
229 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
230 $fwdfwsettings{'nosave'} = 'on';
231 }
232 }
233 }
234 }
235 #check Rulepos on new Rule
236 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
237 $fwdfwsettings{'oldrulenumber'}=$maxkey;
238 foreach my $key (sort keys %configdmzfw){
239 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'}"
240 eq "$configdmzfw{$key}[0],$configdmzfw{$key}[2],$configdmzfw{$key}[3],$configdmzfw{$key}[4],$configdmzfw{$key}[5],$configdmzfw{$key}[6],$configdmzfw{$key}[7],$configdmzfw{$key}[8],$configdmzfw{$key}[9],$configdmzfw{$key}[10],$configdmzfw{$key}[11],$configdmzfw{$key}[12],$configdmzfw{$key}[13],$configdmzfw{$key}[14],$configdmzfw{$key}[15],$configdmzfw{$key}[17],$configdmzfw{$key}[18],$configdmzfw{$key}[19],$configdmzfw{$key}[20],$configdmzfw{$key}[21],$configdmzfw{$key}[22],$configdmzfw{$key}[23],$configdmzfw{$key}[24],$configdmzfw{$key}[25],$configdmzfw{$key}[26],$configdmzfw{$key}[27]"){
241 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
242 }
243 }
244 }
245 #check if we just close a rule
246 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'}) {
247 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
248 $errormessage='';
249 $fwdfwsettings{'nosave2'} = 'on';
250 }
251 }
252 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
253 if ($fwdfwsettings{'nobase'} ne 'on'){
254 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
255 }
256 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
257 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
258 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
259 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
260 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
261 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
262 }
263 if($fwdfwsettings{'nosave2'} ne 'on'){
264 &saverule(\%configdmzfw,$configdmz);
265 }
266 #INPUT part
267 }elsif($fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ORANGE'){
268 $fwdfwsettings{'config'}=$configinput;
269 $fwdfwsettings{'chain'} = 'INPUTFW';
270 my $maxkey=&General::findhasharraykey(\%configinputfw);
271 #check if we have an identical rule already
272 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
273 foreach my $key (sort keys %configinputfw){
274 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'}"
275 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]"){
276 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
277 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on'){
278 $errormessage='';
279 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
280 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
281 }
282 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
283 $fwdfwsettings{'nosave'} = 'on';
284 }
285 }
286 }
287 }
288 #check Rulepos on new Rule
289 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
290 $fwdfwsettings{'oldrulenumber'}=$maxkey;
291 foreach my $key (sort keys %configinputfw){
292 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'}"
293 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]"){
294 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
295 }
296 }
297 }
298 #check if we just close a rule
299 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'}) {
300 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
301 $errormessage='';
302 $fwdfwsettings{'nosave2'} = 'on';
303 }
304 }
305 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
306 if ($fwdfwsettings{'nobase'} ne 'on'){
307 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
308 }
309 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
310 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
311 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
312 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
313 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
314 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
315 }
316 if($fwdfwsettings{'nosave2'} ne 'on'){
317 &saverule(\%configinputfw,$configinput);
318 }
319 }elsif($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' ){
320 # OUTGOING PART
321 $fwdfwsettings{'config'}=$configoutgoing;
322 $fwdfwsettings{'chain'} = 'OUTGOINGFW';
323 my $maxkey=&General::findhasharraykey(\%configoutgoingfw);
324 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
325 foreach my $key (sort keys %configoutgoingfw){
326 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'}"
327 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]"){
328 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
329 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on'){
330 $errormessage='';
331 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
332 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
333 }
334 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
335 $fwdfwsettings{'nosave'} = 'on';
336 }
337 }
338 }
339 }
340 #check Rulepos on new Rule
341 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
342 print"CHECK OUTGOING DOPPELTE REGEL<br>";
343 $fwdfwsettings{'oldrulenumber'}=$maxkey;
344 foreach my $key (sort keys %configoutgoingfw){
345 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'}"
346 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]"){
347 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
348 }
349 }
350 }
351 #check if we just close a rule
352 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'}) {
353 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
354 $fwdfwsettings{'nosave2'} = 'on';
355 $errormessage='';
356 }
357 }
358 #increase counters
359 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
360 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
361 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
362 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
363 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
364 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
365 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
366 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
367 }
368 if ($fwdfwsettings{'nobase'} eq 'on'){
369 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
370 }
371 if ($fwdfwsettings{'nosave2'} ne 'on'){
372 &saverule(\%configoutgoingfw,$configoutgoing);
373 }
374 }else{
375 #FORWARD PART
376 $fwdfwsettings{'config'}=$configfwdfw;
377 $fwdfwsettings{'chain'} = 'FORWARDFW';
378 my $maxkey=&General::findhasharraykey(\%configfwdfw);
379 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
380 #check if we have an identical rule already
381 foreach my $key (sort keys %configfwdfw){
382 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'}"
383 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}[17],$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]"){
384 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
385 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' ){
386 $errormessage='';
387 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
388 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
389 }
390 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
391 $fwdfwsettings{'nosave'} = 'on';
392 }
393 }
394 }
395 }
396 #check Rulepos on new Rule
397 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
398 $fwdfwsettings{'oldrulenumber'}=$maxkey;
399 foreach my $key (sort keys %configfwdfw){
400 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'}"
401 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}[17],$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]"){
402 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
403 }
404 }
405 }
406 #check if we just close a rule
407 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'} ) {
408 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
409 $fwdfwsettings{'nosave2'} = 'on';
410 $errormessage='';
411 }
412 }
413 #increase counters
414 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
415 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
416 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
417 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
418 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
419 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
420 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
421 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
422 }
423 if ($fwdfwsettings{'nobase'} eq 'on'){
424 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
425 }
426 if ($fwdfwsettings{'nosave2'} ne 'on'){
427 &saverule(\%configfwdfw,$configfwdfw);
428 }
429 }
430 if ($errormessage){
431 &newrule;
432 }else{
433 if($fwdfwsettings{'nosave2'} ne 'on'){
434 &rules;
435 }
436 &base;
437 }
438 }
439 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'reset'})
440 {
441 if($fwdfwsettings{'poltype'} eq 'forward'){
442 &General::readhasharray("$configfwdfw", \%configfwdfw);
443 foreach my $key (sort keys %configfwdfw){
444 &checkcounter($configfwdfw{$key}[3],$configfwdfw{$key}[4],,);
445 &checkcounter($configfwdfw{$key}[5],$configfwdfw{$key}[6],,);
446 &checkcounter($configfwdfw{$key}[14],$configfwdfw{$key}[15],,);
447 }
448 system("rm ${General::swroot}/forward/config");
449 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
450 unless (-e "${General::swroot}/forward/config") { system("touch ${General::swroot}/forward/config"); }
451 my $MODE1=$fwdfwsettings{'POLICY1'};
452 %fwdfwsettings = ();
453 $fwdfwsettings{'POLICY'}='MODE2';
454 $fwdfwsettings{'POLICY1'}=$MODE1;
455 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
456 &reread_rules;
457 }else{
458 &General::readhasharray("$configoutgoing", \%configoutgoingfw);
459 foreach my $key (sort keys %configoutgoingfw){
460 &checkcounter($configoutgoingfw{$key}[3],$configoutgoingfw{$key}[4],,);
461 &checkcounter($configoutgoingfw{$key}[5],$configoutgoingfw{$key}[6],,);
462 &checkcounter($configoutgoingfw{$key}[14],$configoutgoingfw{$key}[15],,);
463 }
464 system("rm ${General::swroot}/forward/outgoing");
465 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
466 unless (-e "${General::swroot}/forward/outgoing") { system("touch ${General::swroot}/forward/outgoing"); }
467 my $MODE=$fwdfwsettings{'POLICY'};
468 %fwdfwsettings = ();
469 $fwdfwsettings{'POLICY'}=$MODE;
470 $fwdfwsettings{'POLICY1'}='MODE2';
471 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
472 &reread_rules;
473 }
474 }
475 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw newrule'})
476 {
477 &newrule;
478 }
479 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw toggle'})
480 {
481 my %togglehash=();
482 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
483 foreach my $key (sort keys %togglehash){
484 if ($key eq $fwdfwsettings{'key'}){
485 if ($togglehash{$key}[2] eq 'ON'){$togglehash{$key}[2]='';}else{$togglehash{$key}[2]='ON';}
486 }
487 }
488 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
489 &rules;
490 &base;
491 }
492 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw togglelog'})
493 {
494 my %togglehash=();
495 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
496 foreach my $key (sort keys %togglehash){
497 if ($key eq $fwdfwsettings{'key'}){
498 if ($togglehash{$key}[17] eq 'ON'){$togglehash{$key}[17]='';}else{$togglehash{$key}[17]='ON';}
499 }
500 }
501 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
502 &rules;
503 &base;
504 }
505 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
506 {
507 &reread_rules;
508 &base;
509 }
510 if ($fwdfwsettings{'ACTION'} eq 'editrule')
511 {
512 $fwdfwsettings{'updatefwrule'}='on';
513 &newrule;
514 }
515 if ($fwdfwsettings{'ACTION'} eq 'deleterule')
516 {
517 &deleterule;
518 }
519 if ($fwdfwsettings{'ACTION'} eq 'moveup')
520 {
521 &pos_up;
522 &base;
523 }
524 if ($fwdfwsettings{'ACTION'} eq 'movedown')
525 {
526 &pos_down;
527 &base;
528 }
529 if ($fwdfwsettings{'ACTION'} eq 'copyrule')
530 {
531 $fwdfwsettings{'copyfwrule'}='on';
532 &newrule;
533 }
534 if ($fwdfwsettings{'ACTION'} eq '')
535 {
536 &base;
537 }
538 ### Functions ####
539 sub addrule
540 {
541 &error;
542 if (-f "${General::swroot}/forward/reread"){
543 print "<table border='0'><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: red; font-weight: bold; font-size: 14pt;'>&nbsp &nbsp $Lang::tr{'fwhost reread'}</div</td></tr></table></form><hr><br>";
544 }
545 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw menu'});
546 print "<form method='post'>";
547 print "<table border='0'>";
548 print "<tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'></td>";
549 print"</tr></table></form><hr>";
550 &Header::closebox();
551 &viewtablerule;
552 }
553 sub base
554 {
555 if ($fwdfwsettings{'POLICY'} eq 'MODE1'){ $selected{'POLICY'}{'MODE1'} = 'selected'; } else { $selected{'POLICY'}{'MODE1'} = ''; }
556 if ($fwdfwsettings{'POLICY'} eq 'MODE2'){ $selected{'POLICY'}{'MODE2'} = 'selected'; } else { $selected{'POLICY'}{'MODE2'} = ''; }
557 if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){ $selected{'POLICY1'}{'MODE1'} = 'selected'; } else { $selected{'POLICY1'}{'MODE1'} = ''; }
558 if ($fwdfwsettings{'POLICY1'} eq 'MODE2'){ $selected{'POLICY1'}{'MODE2'} = 'selected'; } else { $selected{'POLICY1'}{'MODE2'} = ''; }
559 &hint;
560 &addrule;
561 print "<br><br>";
562 &Header::openbox('100%', 'center', $Lang::tr{'fwdfw pol title'});
563 print <<END;
564 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
565 <table width='100%' border='0'>
566 <tr><td colspan='3' style='font-weight:bold;color:red;' align='left'>FORWARD </td></tr>
567 <tr><td colspan='3' align='left'>$Lang::tr{'fwdfw pol text'}</td></tr>
568 <tr><td colspan='3'><hr /></td></tr>
569 <tr><td width='15%' align='left'> <select name='POLICY' style="width: 100px">
570 <option value='MODE1' $selected{'POLICY'}{'MODE1'}>$Lang::tr{'fwdfw pol block'}</option>
571 <option value='MODE2' $selected{'POLICY'}{'MODE2'}>$Lang::tr{'fwdfw pol allow'}</option></select>
572 <input type='submit' name='ACTION' value=$Lang::tr{'save'} /></td><td width='45%' align='right'>
573
574 END
575 print "$Lang::tr{'outgoing firewall reset'}: <input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /><input type='hidden' name='poltype' value='forward' /></td></tr>";
576 print "</table></form>";
577 print"<br><br>";
578 print <<END;
579 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
580 <table width='100%' border='0'>
581 <tr><td colspan='3' style='font-weight:bold;color:red;' align='left'>OUTGOING </td></tr>
582 <tr><td colspan='3' align='left'>$Lang::tr{'fwdfw pol text1'}</td></tr>
583 <tr><td colspan='3'><hr /></td></tr>
584 <tr><td width='15%' align='left'> <select name='POLICY1' style="width: 100px">
585 <option value='MODE1' $selected{'POLICY1'}{'MODE1'}>$Lang::tr{'fwdfw pol block'}</option>
586 <option value='MODE2' $selected{'POLICY1'}{'MODE2'}>$Lang::tr{'fwdfw pol allow'}</option></select>
587 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td><td width='45%' align='right'>
588
589 END
590 print "$Lang::tr{'outgoing firewall reset'}: <input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /><input type='hidden' name='poltype' value='outgoing' /></tr>";
591 print "</table></form>";
592 &Header::closebox();
593 print "<br><br><div align='right'><font size='1' color='grey'>Version: $VERSION</font></div>";
594 }
595 sub changerule
596 {
597 my $oldchain=shift;
598 $fwdfwsettings{'updatefwrule'}='';
599 $fwdfwsettings{'config'}=$oldchain;
600 $fwdfwsettings{'nobase'}='on';
601 &deleterule;
602 &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
603 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
604 }
605 sub checksource
606 {
607 my ($ip,$subnet);
608 #check ip-address if manual
609 if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){
610 #check if ip with subnet
611 if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?)$/) {
612 ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'});
613 $subnet = &General::iporsubtocidr($subnet);
614 $fwdfwsettings{'isip'}='on';
615 }
616 #check if only ip
617 if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
618 $ip=$fwdfwsettings{'src_addr'};
619 $subnet = '32';
620 $fwdfwsettings{'isip'}='on';
621 }
622
623 if ($fwdfwsettings{'isip'} ne 'on'){
624 if (&General::validmac($fwdfwsettings{'src_addr'})){$fwdfwsettings{'ismac'}='on';}
625 }
626 if ($fwdfwsettings{'isip'} eq 'on'){
627 ##check if ip is valid
628 if (! &General::validip($ip)){
629 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
630 return $errormessage;
631 }
632 #check and form valid IP
633 $ip=&General::ip2dec($ip);
634 $ip=&General::dec2ip($ip);
635 #check if net or broadcast
636 my @tmp= split (/\./,$ip);
637 if (($tmp[3] eq "0") || ($tmp[3] eq "255"))
638 {
639 $errormessage=$Lang::tr{'fwhost err hostip'}."<br>";
640 return $errormessage;
641 }
642 $fwdfwsettings{'src_addr'}="$ip/$subnet";
643 if(!&General::validipandmask($fwdfwsettings{'src_addr'})){
644 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
645 return $errormessage;
646 }
647 }
648 if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){
649 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
650 return $errormessage;
651 }
652 }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
653 $errormessage.=$Lang::tr{'fwdfw err nosrcip'};
654 return $errormessage;
655 }
656
657 #check empty fields
658 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err nosrc'}."<br>";}
659 #check icmp source
660 if ($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ICMP'){
661 $fwdfwsettings{'SRC_PORT'}='';
662 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
663 foreach my $key (keys %icmptypes){
664 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){
665 $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]";
666 }
667 }
668 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'GRE'){
669 $fwdfwsettings{'SRC_PORT'}='';
670 $fwdfwsettings{'ICMP_TYPES'}='';
671 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ESP'){
672 $fwdfwsettings{'SRC_PORT'}='';
673 $fwdfwsettings{'ICMP_TYPES'}='';
674 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'AH'){
675 $fwdfwsettings{'SRC_PORT'}='';
676 $fwdfwsettings{'ICMP_TYPES'}='';
677 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} ne 'ICMP'){
678 $fwdfwsettings{'ICMP_TYPES'}='';
679 }else{
680 $fwdfwsettings{'ICMP_TYPES'}='';
681 $fwdfwsettings{'SRC_PORT'}='';
682 $fwdfwsettings{'PROT'}='';
683 }
684
685 if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){
686 my @parts=split(",",$fwdfwsettings{'SRC_PORT'});
687 my @values=();
688 foreach (@parts){
689 chomp($_);
690 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
691 my $check;
692 #change dashes with :
693 $_=~ tr/-/:/;
694 if ($_ eq "*") {
695 push(@values,"1:65535");
696 $check='on';
697 }
698 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
699 push(@values,"1:$2");
700 $check='on';
701 }
702 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/ ) {
703 push(@values,"$1:65535");
704 $check='on'
705 }
706 $errormessage .= &General::validportrange($_, 'destination');
707 if(!$check){
708 push (@values,$_);
709 }
710 }else{
711 if (&General::validport($_)){
712 push (@values,$_);
713 }else{
714
715 }
716 }
717 }
718 $fwdfwsettings{'SRC_PORT'}=join("|",@values);
719 }
720 return $errormessage;
721 }
722 sub checktarget
723 {
724 my ($ip,$subnet);
725 &General::readhasharray("$configsrv", \%customservice);
726 #check DNAT settings (has to be single Host and single Port or portrange)
727 if ($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat'){
728 if($fwdfwsettings{'grp2'} eq 'tgt_addr' || $fwdfwsettings{'grp2'} eq 'cust_host_tgt' || $fwdfwsettings{'grp2'} eq 'ovpn_host_tgt'){
729 if ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'dnatport'} eq ''){
730 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
731 return $errormessage;
732 }
733 #check if manual ip is a single Host (if set)
734 if ($fwdfwsettings{'grp2'} eq 'tgt_addr'){
735 my @tmp= split (/\./,$fwdfwsettings{$fwdfwsettings{'grp2'}});
736 my @tmp1= split ("/",$tmp[3]);
737 if (($tmp1[0] eq "0") || ($tmp1[0] eq "255"))
738 {
739 $errormessage=$Lang::tr{'fwdfw dnat error'}."<br>";
740 return $errormessage;
741 }
742 }
743 #check if Port is a single Port or portrange
744 if ($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
745 if(($fwdfwsettings{'TGT_PROT'} ne 'TCP'|| $fwdfwsettings{'TGT_PROT'} ne 'UDP') && $fwdfwsettings{'TGT_PORT'} eq ''){
746 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
747 return $errormessage;
748 }
749 if (($fwdfwsettings{'TGT_PROT'} eq 'TCP'|| $fwdfwsettings{'TGT_PROT'} eq 'UDP') && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport($fwdfwsettings{'TGT_PORT'})){
750 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
751 return $errormessage;
752 }
753 }
754 }else{
755 $errormessage=$Lang::tr{'fwdfw dnat error'}."<br>";
756 return $errormessage;
757 }
758 }
759 if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
760 #check if ip with subnet
761 if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?)$/) {
762 ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
763 $subnet = &General::iporsubtocidr($subnet);
764 }
765 #check if only ip
766 if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
767 $ip=$fwdfwsettings{'tgt_addr'};
768 $subnet='32';
769 }
770 #check if ip is valid
771 if (! &General::validip($ip)){
772 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
773 return $errormessage;
774 }
775 #check and form valid IP
776 $ip=&General::ip2dec($ip);
777 $ip=&General::dec2ip($ip);
778 $fwdfwsettings{'tgt_addr'}="$ip/$subnet";
779 if(!&General::validipandmask($fwdfwsettings{'tgt_addr'})){
780 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
781 return $errormessage;
782 }
783 }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
784 $errormessage.=$Lang::tr{'fwdfw err notgtip'};
785 return $errormessage;
786 }
787 #check empty fields
788 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err notgt'}."<br>";}
789 #check tgt services
790 if ($fwdfwsettings{'USESRV'} eq 'ON'){
791 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
792 $fwdfwsettings{'TGT_PROT'}='';
793 $fwdfwsettings{'ICMP_TGT'}='';
794 }
795 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
796 $fwdfwsettings{'TGT_PROT'}='';
797 $fwdfwsettings{'ICMP_TGT'}='';
798 #check target service
799 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){
800 $errormessage.=$Lang::tr{'fwdfw err tgt_grp'};
801 }
802 }
803 if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
804 if ($fwdfwsettings{'TGT_PROT'} eq 'TCP' || $fwdfwsettings{'TGT_PROT'} eq 'UDP'){
805 if ($fwdfwsettings{'TGT_PORT'} ne ''){
806 if ($fwdfwsettings{'TGT_PORT'} =~ "," && $fwdfwsettings{'USE_NAT'} && $fwdfwsettings{'nat'} eq 'dnat') {
807 $errormessage=$Lang::tr{'fwdfw dnat porterr'}."<br>";
808 return $errormessage;
809 }
810 my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
811 my @values=();
812 foreach (@parts){
813 chomp($_);
814 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
815 my $check;
816 #change dashes with :
817 $_=~ tr/-/:/;
818 if ($_ eq "*") {
819 push(@values,"1:65535");
820 $check='on';
821 }
822 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
823 push(@values,"1:$2");
824 $check='on';
825 }
826 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
827 push(@values,"$1:65535");
828 $check='on'
829 }
830 $errormessage .= &General::validportrange($_, 'destination');
831 if(!$check){
832 push (@values,$_);
833 }
834 }else{
835 if (&General::validport($_)){
836 push (@values,$_);
837 }else{
838
839 }
840 }
841 }
842 $fwdfwsettings{'TGT_PORT'}=join("|",@values);
843 }
844 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'GRE'){
845 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
846 $fwdfwsettings{'TGT_PORT'} = '';
847 $fwdfwsettings{'ICMP_TGT'} = '';
848 }elsif($fwdfwsettings{'TGT_PROT'} eq 'ESP'){
849 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
850 $fwdfwsettings{'TGT_PORT'} = '';
851 $fwdfwsettings{'ICMP_TGT'}='';
852 }elsif($fwdfwsettings{'TGT_PROT'} eq 'AH'){
853 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
854 $fwdfwsettings{'TGT_PORT'} = '';
855 $fwdfwsettings{'ICMP_TGT'}='';
856 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'ICMP'){
857 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
858 $fwdfwsettings{'TGT_PORT'} = '';
859 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
860 foreach my $key (keys %icmptypes){
861
862 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwdfwsettings{'ICMP_TGT'}){
863 $fwdfwsettings{'ICMP_TGT'}=$icmptypes{$key}[0];
864 }
865 }
866 }
867 }
868 }
869 #check targetport
870 if ($fwdfwsettings{'USESRV'} ne 'ON'){
871 $fwdfwsettings{'grp3'}='';
872 $fwdfwsettings{$fwdfwsettings{'grp3'}}='';
873 $fwdfwsettings{'ICMP_TGT'}='';
874 }
875 #check timeframe
876 if($fwdfwsettings{'TIME'} eq 'ON'){
877 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 ''){
878 $errormessage=$Lang::tr{'fwdfw err time'};
879 return $errormessage;
880 }
881 }
882 return $errormessage;
883 }
884 sub check_natport
885 {
886 my $val=shift;
887 if($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
888 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\-(\d+)$/) {
889 $fwdfwsettings{'dnatport'} =~ tr/-/:/;
890 if ($fwdfwsettings{'dnatport'} eq "*") {
891 $fwdfwsettings{'dnatport'}="1:65535";
892 }
893 if ($fwdfwsettings{'dnatport'} =~ /^(\D)\:(\d+)$/) {
894 $fwdfwsettings{'dnatport'} = "1:$2";
895 }
896 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\:(\D)$/) {
897 $fwdfwsettings{'dnatport'} ="$1:65535";
898 }
899 }
900 return 1;
901 }
902 if ($val =~ "," || $val>65536 || $val<0){
903 return 0;
904 }
905 return 1;
906 }
907 sub checkrule
908 {
909 #check valid port for NAT
910 if($fwdfwsettings{'USE_NAT'} eq 'ON'){
911 #if no port is given in nat area, take target host port
912 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$fwdfwsettings{'TGT_PORT'};}
913 #check if port given in nat area is a single valid port or portrange
914 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport($fwdfwsettings{'dnatport'})){
915 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
916 }elsif($fwdfwsettings{'USESRV'} eq 'ON' && $fwdfwsettings{'grp3'} eq 'cust_srv'){
917 my $custsrvport;
918 #get servcie Protocol and Port
919 foreach my $key (sort keys %customservice){
920 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]){
921 if ($customservice{$key}[2] ne 'TCP' && $customservice{$key}[2] ne 'UDP'){
922 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
923 }
924 $custsrvport= $customservice{$key}[1];
925 }
926 }
927 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$custsrvport;}
928 }
929 #check if DNAT port is multiple
930 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
931 my @parts=split(",",$fwdfwsettings{'dnatport'});
932 my @values=();
933 foreach (@parts){
934 chomp($_);
935 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
936 my $check;
937 #change dashes with :
938 $_=~ tr/-/:/;
939 if ($_ eq "*") {
940 push(@values,"1:65535");
941 $check='on';
942 }
943 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
944 push(@values,"1:$2");
945 $check='on';
946 }
947 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
948 push(@values,"$1:65535");
949 $check='on'
950 }
951 $errormessage .= &General::validportrange($_, 'destination');
952 if(!$check){
953 push (@values,$_);
954 }
955 }else{
956 if (&General::validport($_)){
957 push (@values,$_);
958 }else{
959
960 }
961 }
962 }
963 $fwdfwsettings{'dnatport'}=join("|",@values);
964 }
965 }
966 #check valid remark
967 if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
968 $errormessage.=$Lang::tr{'fwdfw err remark'}."<br>";
969 }
970 #check if source and target identical
971 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL'){
972 $errormessage.=$Lang::tr{'fwdfw err same'};
973 return $errormessage;
974 }
975 #get source and targetip address if possible
976 my ($sip,$scidr,$tip,$tcidr);
977 ($sip,$scidr)=&get_ip("src","grp1");
978 ($tip,$tcidr)=&get_ip("tgt","grp2");
979 #check same iprange in source and target
980 if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){
981 my $networkip1=&General::getnetworkip($sip,$scidr);
982 my $networkip2=&General::getnetworkip($tip,$tcidr);
983 if ($scidr gt $tcidr){
984 if ( &General::IpInSubnet($networkip1,$tip,&General::iporsubtodec($tcidr))){
985 $errormessage.=$Lang::tr{'fwdfw err samesub'};
986 }
987 }elsif($scidr eq $tcidr && $scidr eq '32'){
988 my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1);
989 my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2);
990 if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){
991 $hint=$Lang::tr{'fwdfw hint ip1'}."<br>";
992 $hint.=$Lang::tr{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>";
993 }
994 }else{
995 if ( &General::IpInSubnet($networkip2,$sip,&General::iporsubtodec($scidr)) ){
996 $errormessage.=$Lang::tr{'fwdfw err samesub'};
997 }
998 }
999 }
1000 #check source and destination protocol if manual
1001 if( $fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'USESRV'} eq 'ON'){
1002 if($fwdfwsettings{'PROT'} ne $fwdfwsettings{'TGT_PROT'} && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
1003 $errormessage.=$Lang::tr{'fwdfw err prot'};
1004 }
1005 #check source and destination protocol if source manual and dest servicegrp
1006 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
1007 foreach my $key (sort keys %customservice){
1008 if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){
1009 if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){
1010 $errormessage.=$Lang::tr{'fwdfw err prot'};
1011 last;
1012 }
1013 }
1014 }
1015 }
1016 }
1017 }
1018 sub checkcounter
1019 {
1020 my ($base1,$val1,$base2,$val2) = @_;
1021
1022 if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){
1023 &dec_counter($confignet,\%customnetwork,$val1);
1024 }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){
1025 &dec_counter($confighost,\%customhost,$val1);
1026 }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){
1027 &dec_counter($configgrp,\%customgrp,$val1);
1028 }elsif($base1 eq 'cust_srv'){
1029 &dec_counter($configsrv,\%customservice,$val1);
1030 }elsif($base1 eq 'cust_srvgrp'){
1031 &dec_counter($configsrvgrp,\%customservicegrp,$val1);
1032 }
1033
1034 if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){
1035 &inc_counter($confignet,\%customnetwork,$val2);
1036 }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){
1037 &inc_counter($confighost,\%customhost,$val2);
1038 }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){
1039 &inc_counter($configgrp,\%customgrp,$val2);
1040 }elsif($base2 eq 'cust_srv'){
1041 &inc_counter($configsrv,\%customservice,$val2);
1042 }elsif($base2 eq 'cust_srvgrp'){
1043 &inc_counter($configsrvgrp,\%customservicegrp,$val2);
1044 }
1045 }
1046 sub checkvpn
1047 {
1048 my $ip=shift;
1049 #Test if manual IP is part of static OpenVPN networks
1050 &General::readhasharray("$configccdnet", \%ccdnet);
1051 foreach my $key (sort keys %ccdnet){
1052 my ($vpnip,$vpnsubnet) = split ("/",$ccdnet{$key}[1]);
1053 my $sub=&General::iporsubtodec($vpnsubnet);
1054 if (&General::IpInSubnet($ip,$vpnip,$sub)){
1055 return 0;
1056 }
1057 }
1058 # A Test if manual ip is part of dynamic openvpn subnet is made in getcolor
1059 # because if one creates a custom host with the ip, we need to check the color there!
1060 # It does not make sense to check this here
1061
1062 # Test if manual IP is part of an OpenVPN N2N subnet does also not make sense here
1063 # Is also checked in getcolor
1064
1065 # Test if manual ip is part of an IPsec Network is also checked in getcolor
1066 return 1;
1067 }
1068 sub checkvpncolor
1069 {
1070
1071 }
1072 sub deleterule
1073 {
1074 my %delhash=();
1075 &General::readhasharray($fwdfwsettings{'config'}, \%delhash);
1076 foreach my $key (sort {$a <=> $b} keys %delhash){
1077 if ($key == $fwdfwsettings{'key'}){
1078 #check hosts/net and groups
1079 &checkcounter($delhash{$key}[3],$delhash{$key}[4],,);
1080 &checkcounter($delhash{$key}[5],$delhash{$key}[6],,);
1081 #check services and groups
1082 if ($delhash{$key}[11] eq 'ON'){
1083 &checkcounter($delhash{$key}[14],$delhash{$key}[15],,);
1084 }
1085 }
1086 if ($key >= $fwdfwsettings{'key'}) {
1087 my $next = $key + 1;
1088 if (exists $delhash{$next}) {
1089 foreach my $i (0 .. $#{$delhash{$next}}) {
1090 $delhash{$key}[$i] = $delhash{$next}[$i];
1091 }
1092 }
1093 }
1094 }
1095 # Remove the very last entry.
1096 my $last_key = (sort {$a <=> $b} keys %delhash)[-1];
1097 delete $delhash{$last_key};
1098
1099 &General::writehasharray($fwdfwsettings{'config'}, \%delhash);
1100 &rules;
1101
1102 if($fwdfwsettings{'nobase'} ne 'on'){
1103 &base;
1104 }
1105 }
1106 sub disable_rule
1107 {
1108 my $key1=shift;
1109 &General::readhasharray("$configfwdfw", \%configfwdfw);
1110 foreach my $key (sort keys %configfwdfw){
1111 if ($key eq $key1 ){
1112 if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';}
1113 }
1114 }
1115 &General::writehasharray("$configfwdfw", \%configfwdfw);
1116 &rules;
1117 }
1118 sub dec_counter
1119 {
1120 my $config=shift;
1121 my %hash=%{(shift)};
1122 my $val=shift;
1123 my $pos;
1124 &General::readhasharray($config, \%hash);
1125 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
1126 if($hash{$key}[0] eq $val){
1127 $pos=$#{$hash{$key}};
1128 $hash{$key}[$pos] = $hash{$key}[$pos]-1;
1129 }
1130 }
1131 &General::writehasharray($config, \%hash);
1132 }
1133 sub error
1134 {
1135 if ($errormessage) {
1136 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1137 print "<class name='base'>$errormessage\n";
1138 print "&nbsp;</class>\n";
1139 &Header::closebox();
1140 print"<hr>";
1141 }
1142 }
1143 sub fillselect
1144 {
1145 my %hash=%{(shift)};
1146 my $val=shift;
1147 my $key;
1148 foreach my $key (sort { ncmp($hash{$a}[0],$hash{$b}[0]) } keys %hash){
1149 if($hash{$key}[0] eq $val){
1150 print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>";
1151 }else{
1152 print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>";
1153 }
1154 }
1155 }
1156 sub gen_dd_block
1157 {
1158 my $srctgt = shift;
1159 my $grp=shift;
1160 my $helper='';
1161 my $show='';
1162 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1163 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1164 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1165 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1166 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1167 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1168 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1169 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1170 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1171 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1172 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1173 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1174 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1175 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1176 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1177 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1178 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1179 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1180 print<<END;
1181 <table width='100%' border='0'>
1182 <tr><td width='50%' valign='top'>
1183 <table width='100%' border='0'>
1184 <tr><td width='1%'><input type='radio' name='$grp' 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;'>
1185 END
1186 foreach my $network (sort keys %defaultNetworks)
1187 {
1188 next if($defaultNetworks{$network}{'NAME'} eq "RED" && $srctgt eq 'src');
1189 next if($defaultNetworks{$network}{'NAME'} eq "IPFire" && $srctgt eq 'tgt');
1190 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1191 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $defaultNetworks{$network}{'NAME'});
1192 print ">$network</option>";
1193 }
1194 print"</select></td></tr>";
1195 #custom networks
1196 if (! -z $confignet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1197 print"<tr><td><input type='radio' name='$grp' 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;'>";
1198 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{$grp}});
1199 print"</select></td>";
1200 }
1201 #custom hosts
1202 if (! -z $confighost || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1203 print"<tr><td><input type='radio' name='$grp' 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;'>";
1204 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{$grp}});
1205 print"</select></td>";
1206 }
1207 #custom groups
1208 if (! -z $configgrp || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1209 print"<tr><td valign='top'><input type='radio' name='$grp' 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;'>";
1210 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } keys %customgrp) {
1211 if($helper ne $customgrp{$key}[0]){
1212 print"<option ";
1213 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $customgrp{$key}[0]);
1214 print ">$customgrp{$key}[0]</option>";
1215 }
1216 $helper=$customgrp{$key}[0];
1217 }
1218 print"</select></td>";
1219 }
1220 #End left table. start right table (vpn)
1221 print"</tr></table></td><td valign='top'><table width='100%' border='0'><tr>";
1222 # CCD networks
1223 if( ! -z $configccdnet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1224 print"<td width='1%'><input type='radio' name='$grp' 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;'>";
1225 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{$grp}});
1226 print"</select></td></tr>";
1227 }
1228 #OVPN CCD Hosts
1229 foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost){
1230 if ($ccdhost{$key}[33] ne '' ){
1231 print"<tr><td width='1%'><input type='radio' name='$grp' 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 '');
1232 $show='1';
1233 print "<option value='$ccdhost{$key}[1]'";
1234 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1235 print ">$ccdhost{$key}[1]</option>";
1236 }
1237 }
1238 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1239 print"<tr><td width='1%'><input type='radio' name='$grp' 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>" ;
1240 }
1241 if ($show eq '1'){$show='';print"</select></td></tr>";}
1242 #OVPN N2N
1243 foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost){
1244 if ($ccdhost{$key}[3] eq 'net'){
1245 print"<tr><td width='1%'><input type='radio' name='$grp' 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 '');
1246 $show='1';
1247 print "<option value='$ccdhost{$key}[1]'";
1248 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1249 print ">$ccdhost{$key}[1]</option>";
1250 }
1251 }
1252 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1253 print"<tr><td width='1%'><input type='radio' name='$grp' 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>" ;
1254 }
1255 if ($show eq '1'){$show='';print"</select></td></tr>";}
1256 #IPsec netze
1257 foreach my $key (sort { ncmp($ipsecconf{$a}[1],$ipsecconf{$b}[1]) } keys %ipsecconf) {
1258 if ($ipsecconf{$key}[3] eq 'net' || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1259 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 '');
1260 $show='1';
1261 print "<option ";
1262 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ipsecconf{$key}[1]);
1263 print ">$ipsecconf{$key}[1]</option>";
1264 }
1265 }
1266 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1267 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;'><select></td></tr>";
1268 }
1269 if ($show eq '1'){$show='';print"</select></td></tr>";}
1270
1271 print"</tr></table>";
1272 print"</td></tr></table><br>";
1273 }
1274 sub get_ip
1275 {
1276 my $val=shift;
1277 my $grp =shift;
1278 my $a;
1279 my $b;
1280 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1281 if ($fwdfwsettings{$grp} ne $Lang::tr{'fwhost any'}){
1282 if ($fwdfwsettings{$grp} eq $val.'_addr'){
1283 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
1284 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
1285 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
1286 $a=$netsettings{'GREEN_NETADDRESS'};
1287 $b=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'});
1288 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
1289 $a=$netsettings{'ORANGE_NETADDRESS'};
1290 $b=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'});
1291 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
1292 $a=$netsettings{'BLUE_NETADDRESS'};
1293 $b=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'});
1294 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
1295 &General::readhash("$configovpn",\%ovpnsettings);
1296 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
1297 $b=&General::iporsubtocidr($b);
1298 }
1299 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
1300 &General::readhasharray("$confignet", \%customnetwork);
1301 foreach my $key (keys %customnetwork){
1302 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1303 $a=$customnetwork{$key}[1];
1304 $b=&General::iporsubtocidr($customnetwork{$key}[2]);
1305 }
1306 }
1307 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
1308 &General::readhasharray("$confighost", \%customhost);
1309 foreach my $key (keys %customhost){
1310 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1311 if ($customhost{$key}[1] eq 'ip'){
1312 ($a,$b)=split (/\//,$customhost{$key}[2]);
1313 $b=&General::iporsubtocidr($b);
1314 }else{
1315 if ($grp eq 'grp2'){
1316 $errormessage=$Lang::tr{'fwdfw err tgt_mac'};
1317 }
1318 }
1319 }
1320 }
1321 }
1322 }
1323 return $a,$b;
1324 }
1325 sub get_name
1326 {
1327 my $val=shift;
1328 &General::setup_default_networks(\%defaultNetworks);
1329 foreach my $network (sort keys %defaultNetworks)
1330 {
1331 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1332 }
1333 }
1334 sub getsrcport
1335 {
1336 my %hash=%{(shift)};
1337 my $key=shift;
1338 if($hash{$key}[7] eq 'ON' && $hash{$key}[8] ne '' && $hash{$key}[10]){
1339 $hash{$key}[10]=~ s/\|/,/g;
1340 print": $hash{$key}[10]";
1341 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
1342 print": <br>$hash{$key}[9] ";
1343 }
1344 }
1345 sub gettgtport
1346 {
1347 my %hash=%{(shift)};
1348 my $key=shift;
1349 my $service;
1350 my $prot;
1351 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1352 if($hash{$key}[14] eq 'cust_srv'){
1353 &General::readhasharray("$configsrv", \%customservice);
1354 foreach my $i (sort keys %customservice){
1355 if($customservice{$i}[0] eq $hash{$key}[15]){
1356 $service = $customservice{$i}[0];
1357 }
1358 }
1359 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
1360 $service=$hash{$key}[15];
1361 }elsif($hash{$key}[14] eq 'TGT_PORT'){
1362 $hash{$key}[15]=~ s/\|/,/g;
1363 $service=$hash{$key}[15];
1364 }
1365 if($service){
1366 print": $service";
1367 }
1368 }elsif($hash{$key}[11] eq 'ON' && $hash{$key}[12] eq 'ICMP'){
1369 print":<br>$hash{$key}[13]";
1370 }
1371 }
1372 sub get_serviceports
1373 {
1374 my $type=shift;
1375 my $name=shift;
1376 &General::readhasharray("$configsrv", \%customservice);
1377 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1378 my $tcp;
1379 my $udp;
1380 my $icmp;
1381 @protocols=();
1382 if($type eq 'service'){
1383 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1384 if ($customservice{$key}[0] eq $name){
1385 push (@protocols,$customservice{$key}[2]);
1386 }
1387 }
1388 }elsif($type eq 'group'){
1389 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1390 if ($customservicegrp{$key}[0] eq $name){
1391 foreach my $key1 (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1392 if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
1393 if($customservice{$key1}[2] eq 'TCP'){
1394 $tcp='TCP';
1395 }elsif($customservice{$key1}[2] eq 'ICMP'){
1396 $icmp='ICMP';
1397 }elsif($customservice{$key1}[2] eq 'UDP'){
1398 $udp='UDP';
1399 }
1400 }
1401 }
1402 }
1403 }
1404 }
1405 if($tcp && $udp && $icmp){
1406 push (@protocols,"All");
1407 return @protocols;
1408 }
1409 if($tcp){
1410 push (@protocols,"TCP");
1411 }
1412 if($udp){
1413 push (@protocols,"UDP");
1414 }
1415 if($icmp){
1416 push (@protocols,"ICMP");
1417 }
1418 return @protocols;
1419 }
1420 sub getcolor
1421 {
1422 my $nettype=shift;
1423 my $val=shift;
1424 my $hash=shift;
1425 if($optionsfw{'SHOWCOLORS'} eq 'on'){
1426 #standard networks
1427 if ($val eq 'GREEN'){
1428 $tdcolor="style='border: 1px solid $Header::colourgreen;'";
1429 return;
1430 }elsif ($val eq 'ORANGE'){
1431 $tdcolor="style='border: 1px solid $Header::colourorange;'";
1432 return;
1433 }elsif ($val eq 'BLUE'){
1434 $tdcolor="style='border: 1px solid $Header::colourblue;'";
1435 return;
1436 }elsif ($val eq 'RED' ||$val eq 'RED1' ){
1437 $tdcolor="style='border: 1px solid $Header::colourred;'";
1438 return;
1439 }elsif ($val eq 'IPFire' ){
1440 $tdcolor="style='border: 1px solid $Header::colourred;'";
1441 return;
1442 }elsif($val =~ /^(.*?)\/(.*?)$/){
1443 my ($sip,$scidr) = split ("/",$val);
1444 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1445 $tdcolor="style='border: 1px solid $Header::colourorange;'";
1446 return;
1447 }
1448 if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1449 $tdcolor="style='border: 1px solid $Header::colourgreen;'";
1450 return;
1451 }
1452 if ( &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
1453 $tdcolor="style='border: 1px solid $Header::colourblue;'";
1454 return;
1455 }
1456 }elsif ($val eq 'Default IP'){
1457 $tdcolor="style='border: 1px solid $Header::colourred;'";
1458 return;
1459 }
1460 #Check if a manual IP is part of a VPN
1461 if ($nettype eq 'src_addr' || $nettype eq 'tgt_addr'){
1462 #Check if IP is part of OpenVPN dynamic subnet
1463 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
1464 my ($c,$d) = split("/",$val);
1465 if (&General::IpInSubnet($c,$a,$b)){
1466 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1467 return;
1468 }
1469 #Check if IP is part of OpenVPN static subnet
1470 foreach my $key (sort keys %ccdnet){
1471 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1472 $b =&General::iporsubtodec($b);
1473 if (&General::IpInSubnet($c,$a,$b)){
1474 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1475 return;
1476 }
1477 }
1478 #Check if IP is part of OpenVPN N2N subnet
1479 foreach my $key (sort keys %ccdhost){
1480 if ($ccdhost{$key}[3] eq 'net'){
1481 my ($a,$b) = split("/",$ccdhost{$key}[11]);
1482 if (&General::IpInSubnet($c,$a,$b)){
1483 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1484 return;
1485 }
1486 }
1487 }
1488 #Check if IP is part of IPsec RW network
1489 if ($ipsecsettings{'RW_NET'} ne ''){
1490 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1491 $b=&General::iporsubtodec($b);
1492 if (&General::IpInSubnet($c,$a,$b)){
1493 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1494 return;
1495 }
1496 }
1497 #Check if IP is part of a IPsec N2N network
1498 foreach my $key (sort keys %ipsecconf){
1499 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1500 if (&General::IpInSubnet($c,$a,$b)){
1501 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1502 return;
1503 }
1504 }
1505 }
1506 #VPN networks
1507 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'){
1508 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1509 return;
1510 }
1511 if ($nettype eq 'ipsec_net_src' || $nettype eq 'ipsec_net_tgt'){
1512 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1513 return;
1514 }
1515 #custom Hosts
1516 if ($nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1517 foreach my $key (sort keys %$hash){
1518 if ($$hash{$key}[0] eq $val){
1519 $val=$$hash{$key}[2];
1520 }
1521 }
1522 }
1523 #ALIASE
1524 foreach my $alias (sort keys %aliases)
1525 {
1526 if ($val eq $alias){
1527 $tdcolor="style='border: 1px solid $Header::colourred;'";
1528 return;
1529 }
1530 }
1531 }
1532 $tdcolor='';
1533 return;
1534 }
1535 sub hint
1536 {
1537 if ($hint) {
1538 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1539 print "<class name='base'>$hint\n";
1540 print "&nbsp;</class>\n";
1541 &Header::closebox();
1542 print"<hr>";
1543 }
1544 }
1545 sub inc_counter
1546 {
1547 my $config=shift;
1548 my %hash=%{(shift)};
1549 my $val=shift;
1550 my $pos;
1551
1552 &General::readhasharray($config, \%hash);
1553 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
1554 if($hash{$key}[0] eq $val){
1555 $pos=$#{$hash{$key}};
1556 $hash{$key}[$pos] = $hash{$key}[$pos]+1;
1557 }
1558 }
1559 &General::writehasharray($config, \%hash);
1560 }
1561 sub newrule
1562 {
1563 &error;
1564 &General::setup_default_networks(\%defaultNetworks);
1565 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1566 #read all configfiles
1567 &General::readhasharray("$configccdnet", \%ccdnet);
1568 &General::readhasharray("$confignet", \%customnetwork);
1569 &General::readhasharray("$configccdhost", \%ccdhost);
1570 &General::readhasharray("$confighost", \%customhost);
1571 &General::readhasharray("$configccdhost", \%ccdhost);
1572 &General::readhasharray("$configgrp", \%customgrp);
1573 &General::readhasharray("$configipsec", \%ipsecconf);
1574 &General::get_aliases(\%aliases);
1575 my %checked=();
1576 my $helper;
1577 my $sum=0;
1578 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
1579 my $config=$fwdfwsettings{'config'};
1580 my %hash=();
1581 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1582 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1583 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1584 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1585 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1586 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1587 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1588 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1589 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1590 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1591 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1592 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1593 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1594 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1595 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1596 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1597 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1598 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1599 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1600 #check if update and get values
1601 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
1602 &General::readhasharray("$config", \%hash);
1603 foreach my $key (sort keys %hash){
1604 $sum++;
1605 if ($key eq $fwdfwsettings{'key'}){
1606 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
1607 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
1608 $fwdfwsettings{'chain'} = $hash{$key}[1];
1609 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1610 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1611 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1612 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1613 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1614 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1615 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1616 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1617 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1618 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1619 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1620 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1621 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1622 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1623 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1624 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1625 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1626 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1627 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1628 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1629 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1630 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1631 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1632 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1633 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1634 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
1635 $fwdfwsettings{'USE_NAT'} = $hash{$key}[28];
1636 $fwdfwsettings{'nat'} = $hash{$key}[31]; #changed order
1637 $fwdfwsettings{$fwdfwsettings{'nat'}} = $hash{$key}[29];
1638 $fwdfwsettings{'dnatport'} = $hash{$key}[30];
1639 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1640 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1641 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1642 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1643 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1644 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1645 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1646 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1647 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1648 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1649 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1650 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1651 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1652 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1653 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1654 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1655 $checked{'nat'}{$fwdfwsettings{'nat'}} = 'CHECKED';
1656 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1657 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1658 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1659 $selected{'dnat'}{$fwdfwsettings{$fwdfwsettings{'nat'}}} ='selected';
1660 $selected{'snat'}{$fwdfwsettings{$fwdfwsettings{'nat'}}} ='selected';
1661 }
1662 }
1663 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1664 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1665 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1666 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1667 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1668 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1669 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1670 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1671 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1672 if ($fwdfwsettings{'config'} eq "${General::swroot}/forward/dmz"){
1673 $fwdfwsettings{'oldruletype'}='DMZ';
1674 }else{
1675 $fwdfwsettings{'oldruletype'}=$fwdfwsettings{'chain'};
1676 }
1677 #check if manual ip (source) is orange network
1678 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1679 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1680 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1681 $fwdfwsettings{'oldorange'} ='on';
1682 }
1683 }
1684 }else{
1685 $fwdfwsettings{'ACTIVE'}='ON';
1686 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1687 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1688 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1689 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1690 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1691 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1692 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1693 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1694 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1695 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1696 #check if manual ip (source) is orange network
1697 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1698 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1699 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1700 $fwdfwsettings{'oldorange'} ='on';
1701 }
1702 }
1703 }
1704 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
1705 print "<form method='post'>";
1706 &Header::closebox();
1707 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'});
1708 #------SOURCE-------------------------------------------------------
1709 print<<END;
1710 <table width='100%' border='0'>
1711 <tr><td width='1%'><input type='radio' name='grp1' value='src_addr' checked></td><td colspan='5'>$Lang::tr{'fwdfw sourceip'}<input type='TEXT' name='src_addr' value='$fwdfwsettings{'src_addr'}' size='16' maxlength='17'></td></tr>
1712 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr>
1713 </table>
1714 END
1715 &gen_dd_block('src','grp1');
1716 print<<END;
1717 <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
1718 <table width='100%' border='0'>
1719 <tr><td width='1%'><input type='checkbox' name='USE_SRC_PORT' value='ON' $checked{'USE_SRC_PORT'}{'ON'}></td><td width='51%' colspan='3'>$Lang::tr{'fwdfw use srcport'}</td>
1720 <td width='15%' nowrap='nowrap'>$Lang::tr{'fwdfw man port'}</td><td><select name='PROT'>
1721 END
1722 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
1723 {
1724 if ($_ eq $fwdfwsettings{'PROT'})
1725 {
1726 print"<option selected>$_</option>";
1727 }else{
1728 print"<option>$_</option>";
1729 }
1730 }
1731 $fwdfwsettings{'SRC_PORT'}=~ s/\|/,/g;
1732 print<<END;
1733 </select></td><td align='right'><input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18' ></td></tr>
1734 <tr><td></td><td></td><td></td><td></td><td nowrap='nowrap'>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TYPES' style='width:230px;'>
1735 END
1736 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1737 print"<option>All ICMP-Types</option>";
1738 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) } keys %icmptypes){
1739 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1740 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1741 }else{
1742 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1743 }
1744 }
1745 print<<END;
1746 </select></td></tr></table><br><hr>
1747 END
1748 &Header::closebox();
1749
1750 #---TARGET------------------------------------------------------
1751 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw target'});
1752 print<<END;
1753 <table width='100%' border='0'>
1754 <tr><td width='1%'><input type='radio' name='grp2' value='tgt_addr' checked></td><td width='57%' nowrap='nowrap'>$Lang::tr{'fwdfw targetip'}<input type='TEXT' name='tgt_addr' value='$fwdfwsettings{'tgt_addr'}' size='16' maxlength='17'><td width='1%'><input type='radio' name='grp2' value='ipfire' $checked{'grp2'}{'ipfire'}></td><td><b>IPFire</b></td>
1755 END
1756 print"<td align='right'><select name='ipfire' style='width:200px;'>";
1757 print "<option value='ALL' $selected{'ipfire'}{'ALL'}>$Lang::tr{'all'}</option>";
1758 print "<option value='GREEN' $selected{'ipfire'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
1759 print "<option value='ORANGE' $selected{'ipfire'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if $ifaces{'ORANGE_ADDRESS'};
1760 print "<option value='BLUE' $selected{'ipfire'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>" if $ifaces{'BLUE_ADDRESS'};
1761 print "<option value='RED1' $selected{'ipfire'}{'RED1'}>$Lang::tr{'red1'} (Default IP)</option>" if $ifaces{'RED_ADDRESS'};
1762
1763 if (! -z "${General::swroot}/ethernet/aliases"){
1764 foreach my $alias (sort keys %aliases)
1765 {
1766 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1767 }
1768 }
1769 print<<END;
1770 </td></tr>
1771 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
1772 END
1773 &gen_dd_block('tgt','grp2');
1774 print<<END;
1775 <b>$Lang::tr{'fwhost attention'}:</b><br>
1776 $Lang::tr{'fwhost macwarn'}<br><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; '></hr><br>
1777 <table width='100%' border='0'>
1778 <tr><td width='1%'><input type='checkbox' name='USESRV' value='ON' $checked{'USESRV'}{'ON'} ></td><td width='48%'>$Lang::tr{'fwdfw use srv'}</td><td width='1%'><input type='radio' name='grp3' value='cust_srv' checked></td><td nowrap='nowrap'>$Lang::tr{'fwhost cust service'}</td><td width='1%' colspan='2'><select name='cust_srv'style='min-width:230px;' >
1779 END
1780 &General::readhasharray("$configsrv", \%customservice);
1781 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1782 print"<option ";
1783 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1784 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1785 }
1786 print<<END;
1787 </select></td></tr>
1788 <tr><td colspan='2'></td><td><input type='radio' name='grp3' value='cust_srvgrp' $checked{'grp3'}{'cust_srvgrp'}></td><td nowrap='nowrap'>$Lang::tr{'fwhost cust srvgrp'}:</td><td colspan='2'><select name='cust_srvgrp' style='min-width:230px;' >
1789 END
1790 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1791 my $helper;
1792 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1793 if ($helper ne $customservicegrp{$key}[0]){
1794 print"<option ";
1795 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1796 print">$customservicegrp{$key}[0]</option>";
1797 }
1798 $helper=$customservicegrp{$key}[0];
1799 }
1800 print<<END;
1801 </select></td></tr>
1802 <tr><td colspan='2'></td><td><input type='radio' name='grp3' value='TGT_PORT' $checked{'grp3'}{'TGT_PORT'}></td><td>$Lang::tr{'fwdfw man port'}</td><td><select name='TGT_PROT'>
1803 END
1804 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
1805 {
1806 if ($_ eq $fwdfwsettings{'TGT_PROT'})
1807 {
1808 print"<option selected>$_</option>";
1809 }else{
1810 print"<option>$_</option>";
1811 }
1812 }
1813 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
1814 print<<END;
1815 </select></td><td align='right'><input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18' ></td></tr>
1816 <tr><td colspan='2'></td><td></td><td>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TGT' style='min-width:230px;'>
1817 END
1818 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1819 print"<option>All ICMP-Types</option>";
1820 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
1821 if($fwdfwsettings{'ICMP_TGT'} eq "$icmptypes{$key}[0]"){
1822 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1823 }else{
1824 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1825 }
1826 }
1827 print<<END;
1828 </select></td></tr>
1829 </table><br><hr>
1830
1831 END
1832 &Header::closebox;
1833 #---SNAT / DNAT ------------------------------------------------
1834 &Header::openbox('100%', 'left', 'NAT');
1835 print<<END;
1836 <table width='100%' border='0'>
1837 <tr><td width='1%'><input type='checkbox' name='USE_NAT' value='ON' $checked{'USE_NAT'}{'ON'}></td><td width='15%'>$Lang::tr{'fwdfw use nat'}</td><td colspan='5'></td></tr>
1838 <tr><td colspan='2'></td><td width='1%'><input type='radio' name='nat' value='dnat' checked ></td><td width='50%'>$Lang::tr{'fwdfw dnat'}</td>
1839 END
1840 print"<td width='8%'>IPFire: </td><td width='20%' align='right'><select name='dnat' style='width:140px;'>";
1841 print "<option value='ALL' $selected{'dnat'}{$Lang::tr{'all'}}>$Lang::tr{'all'}</option>";
1842 print "<option value='Default IP' $selected{'dnat'}{'Default IP'}>Default IP</option>";
1843 foreach my $alias (sort keys %aliases)
1844 {
1845 print "<option value='$alias' $selected{'dnat'}{$alias}>$alias</option>";
1846 }
1847 print"</td></tr>";
1848 $fwdfwsettings{'dnatport'}=~ tr/|/,/;
1849 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>";
1850 print"<tr><td colspan='8'><br></td></tr>";
1851 #SNAT
1852 print"<tr><td colspan='2'></td><td width='1%'><input type='radio' name='nat' value='snat' $checked{'nat'}{'snat'}></td><td width='20%'>$Lang::tr{'fwdfw snat'}</td>";
1853 print"<td width='8%'>IPFire: </td><td width='20%' align='right'><select name='snat' style='width:140px;'>";
1854 print "<option value='Default IP' $selected{'snat'}{'Default IP'}>Default IP</option>";
1855 foreach my $alias (sort keys %aliases)
1856 {
1857 print "<option value='$alias' $selected{'snat'}{$alias}>$alias</option>";
1858 }
1859 foreach my $network (sort keys %defaultNetworks)
1860 {
1861 next if($defaultNetworks{$network}{'NAME'} eq "RED");
1862 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1863 next if($defaultNetworks{$network}{'NAME'} eq "ALL");
1864 next if($defaultNetworks{$network}{'NAME'} =~ /OpenVPN/i);
1865 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1866 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'nat'}} eq $defaultNetworks{$network}{'NAME'});
1867 print ">$network</option>";
1868 }
1869 print"</table>";
1870 print"<hr>";
1871 &Header::closebox();
1872 #---Activate/logging/remark-------------------------------------
1873 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw additional'});
1874 print<<END;
1875 <table width='100%' border='0'>
1876 <tr><td nowrap>$Lang::tr{'fwdfw rule action'}</td><td><select name='RULE_ACTION'>
1877 END
1878 foreach ("ACCEPT","DROP","REJECT")
1879 {
1880 if($fwdfwsettings{'updatefwrule'} eq 'on'){
1881 print"<option value='$_'";
1882 print "selected='selected'" if ($fwdfwsettings{'RULE_ACTION'} eq $_);
1883 print">$Lang::tr{'fwdfw '.$_}</option>";
1884 }else{
1885 if($fwdfwsettings{'POLICY'} eq 'MODE2'){
1886 $fwdfwsettings{'RULE_ACTION'} = 'DROP';
1887 }
1888 if ($_ eq $fwdfwsettings{'RULE_ACTION'})
1889 {
1890 print"<option value='$_' selected>$Lang::tr{'fwdfw '.$_}</option>";
1891 }else{
1892 print"<option value='$_'>$Lang::tr{'fwdfw '.$_}</option>";
1893 }
1894 }
1895 }
1896 print"</select></td></tr>";
1897 print"<tr><td width='12%'>$Lang::tr{'remark'}:</td><td align='left'><input type='text' name='ruleremark' size='40' maxlength='255' value='$fwdfwsettings{'ruleremark'}'></td></tr>";
1898 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
1899 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
1900 for (my $count =1; $count <= $sum; $count++){
1901 print"<option value='$count' ";
1902 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
1903 print">$count</option>";
1904 }
1905 print"</select></td></tr>";
1906 }else{
1907 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
1908 }
1909
1910 print<<END;
1911 </table><table width='100%'>
1912 <tr><td width='1%'><input type='checkbox' name='ACTIVE' value='ON' $checked{'ACTIVE'}{'ON'}></td><td>$Lang::tr{'fwdfw rule activate'}</td></tr>
1913 <tr><td width='1%'><input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'} ></td><td>$Lang::tr{'fwdfw log rule'}</td></tr>
1914 </table><br><hr>
1915 END
1916 &Header::closebox();
1917 #---ADD TIMEFRAME-----------------------------------------------
1918 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw timeframe'});
1919 print<<END;
1920 <table width='70%' border='0'>
1921 <tr><td width='1%'><input type='checkbox' name='TIME' value='ON' $checked{'TIME'}{'ON'}></td><td colspan='4'>$Lang::tr{'fwdfw timeframe'}</td></tr>
1922 <tr><td colspan='7'>&nbsp</td></tr>
1923 <tr>
1924 <td align='left'>$Lang::tr{'time'}:</td>
1925 <td width='30%' align='left'>$Lang::tr{'advproxy monday'} $Lang::tr{'advproxy tuesday'} $Lang::tr{'advproxy wednesday'} $Lang::tr{'advproxy thursday'} $Lang::tr{'advproxy friday'} $Lang::tr{'advproxy saturday'} $Lang::tr{'advproxy sunday'}</td>
1926 <td width='15%' align='left'>$Lang::tr{'advproxy from'}</td>
1927 <td width='15%' align='left'>$Lang::tr{'advproxy to'}</td>
1928 </tr>
1929 <tr>
1930 <td align='right'></td>
1931 <td width='30%' align='left'>
1932 <input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} />
1933 <input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} />
1934 <input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} />
1935 <input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} />
1936 <input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} />
1937 <input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} />
1938 <input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} />
1939 </td>
1940 <td><select name='TIME_FROM'>
1941 END
1942 for (my $i=0;$i<=23;$i++) {
1943 $i = sprintf("%02s",$i);
1944 for (my $j=0;$j<=45;$j+=15) {
1945 $j = sprintf("%02s",$j);
1946 my $time = $i.":".$j;
1947 print "\t\t\t\t\t<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
1948 }
1949 }
1950 print<<END;
1951 </select></td>
1952 <td><select name='TIME_TO'>
1953 END
1954 for (my $i=0;$i<=23;$i++) {
1955 $i = sprintf("%02s",$i);
1956 for (my $j=0;$j<=45;$j+=15) {
1957 $j = sprintf("%02s",$j);
1958 my $time = $i.":".$j;
1959 print "\t\t\t\t\t<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
1960 }
1961 }
1962 print<<END;
1963 </select></td></tr>
1964 </table><br><hr>
1965 END
1966 #---ACTION------------------------------------------------------
1967 if($fwdfwsettings{'updatefwrule'} ne 'on'){
1968 print<<END;
1969 <table border='0' width='100%'>
1970 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
1971 <input type='hidden' name='config' value='$config' >
1972 <input type='hidden' name='ACTION' value='saverule' >
1973 </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>
1974 </table></form>
1975 END
1976 }else{
1977 print<<END;
1978 <table border='0' width='100%'>
1979 <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'}'>
1980 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
1981 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
1982 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
1983 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
1984 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
1985 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
1986 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
1987 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
1988 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
1989 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
1990 <input type='hidden' name='oldorange' value='$fwdfwsettings{'oldorange'}' />
1991 <input type='hidden' name='oldnat' value='$fwdfwsettings{'oldnat'}' />
1992 <input type='hidden' name='oldruletype' value='$fwdfwsettings{'oldruletype'}' />
1993 <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>
1994 </table></form>
1995 END
1996 }
1997 &Header::closebox();
1998 }
1999 sub pos_up
2000 {
2001 my %uphash=();
2002 my %tmp=();
2003 &General::readhasharray($fwdfwsettings{'config'}, \%uphash);
2004 foreach my $key (sort keys %uphash){
2005 if ($key eq $fwdfwsettings{'key'}) {
2006 my $last = $key -1;
2007 if (exists $uphash{$last}){
2008 #save rule last
2009 foreach my $y (0 .. $#{$uphash{$last}}) {
2010 $tmp{0}[$y] = $uphash{$last}[$y];
2011 }
2012 #copy active rule to last
2013 foreach my $i (0 .. $#{$uphash{$last}}) {
2014 $uphash{$last}[$i] = $uphash{$key}[$i];
2015 }
2016 #copy saved rule to actual position
2017 foreach my $x (0 .. $#{$tmp{0}}) {
2018 $uphash{$key}[$x] = $tmp{0}[$x];
2019 }
2020 }
2021 }
2022 }
2023 &General::writehasharray($fwdfwsettings{'config'}, \%uphash);
2024 &rules;
2025 }
2026 sub pos_down
2027 {
2028 my %downhash=();
2029 my %tmp=();
2030 &General::readhasharray($fwdfwsettings{'config'}, \%downhash);
2031 foreach my $key (sort keys %downhash){
2032 if ($key eq $fwdfwsettings{'key'}) {
2033 my $next = $key + 1;
2034 if (exists $downhash{$next}){
2035 #save rule next
2036 foreach my $y (0 .. $#{$downhash{$next}}) {
2037 $tmp{0}[$y] = $downhash{$next}[$y];
2038 }
2039 #copy active rule to next
2040 foreach my $i (0 .. $#{$downhash{$next}}) {
2041 $downhash{$next}[$i] = $downhash{$key}[$i];
2042 }
2043 #copy saved rule to actual position
2044 foreach my $x (0 .. $#{$tmp{0}}) {
2045