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