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