]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/forwardfw.cgi
ee46e37dd090aa1fe4684a1545474ff5827ac5a4
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
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. #
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. #
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/>. #
20 ###############################################################################
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. #
27 # Now that the ccd extension is ready i am able to develop the main request. #
28 # Any feedback is appreciated. #
31 ###############################################################################
35 no warnings
'uninitialized';
36 # enable only the following on debugging purpose
38 #use CGI::Carp 'fatalsToBrowser';
40 require '/var/ipfire/general-functions.pl';
41 require "${General::swroot}/lang.pl";
42 require "${General::swroot}/header.pl";
43 require "${General::swroot}/forward/bin/firewall-lib.pl";
45 unless (-d
"${General::swroot}/forward") { system("mkdir ${General::swroot}/forward"); }
46 unless (-e
"${General::swroot}/forward/settings") { system("touch ${General::swroot}/forward/settings"); }
47 unless (-e
"${General::swroot}/forward/config") { system("touch ${General::swroot}/forward/config"); }
48 unless (-e
"${General::swroot}/forward/input") { system("touch ${General::swroot}/forward/input"); }
49 unless (-e
"${General::swroot}/forward/outgoing") { system("touch ${General::swroot}/forward/outgoing"); }
50 unless (-e
"${General::swroot}/forward/nat") { system("touch ${General::swroot}/forward/nat"); }
54 my %defaultNetworks=();
58 my %customnetworks=();
60 my %customservicegrp=();
66 my %configoutgoingfw=();
79 my $VERSION='0.9.9.8';
81 my $confignet = "${General::swroot}/fwhosts/customnetworks";
82 my $confighost = "${General::swroot}/fwhosts/customhosts";
83 my $configgrp = "${General::swroot}/fwhosts/customgroups";
84 my $configsrv = "${General::swroot}/fwhosts/customservices";
85 my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
86 my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
87 my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
88 my $configipsec = "${General::swroot}/vpn/config";
89 my $configipsecrw = "${General::swroot}/vpn/settings";
90 my $configfwdfw = "${General::swroot}/forward/config";
91 my $configinput = "${General::swroot}/forward/input";
92 my $configoutgoing = "${General::swroot}/forward/outgoing";
93 my $confignat = "${General::swroot}/forward/nat";
94 my $configovpn = "${General::swroot}/ovpn/settings";
95 my $fwoptions = "${General::swroot}/optionsfw/settings";
96 my $ifacesettings = "${General::swroot}/ethernet/settings";
99 my $ipgrp="${General::swroot}/outgoing/groups";
103 &General
::readhash
("${General::swroot}/forward/settings", \
%fwdfwsettings);
104 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
105 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
106 &General
::readhash
($fwoptions, \
%optionsfw);
107 &General
::readhash
($ifacesettings, \
%ifaces);
108 &General
::readhash
("$configovpn", \
%ovpnsettings);
109 &General
::readhash
("$configipsecrw", \
%ipsecsettings);
110 &General
::readhasharray
("$configipsec", \
%ipsecconf);
111 &Header
::showhttpheaders
();
112 &Header
::getcgihash
(\
%fwdfwsettings);
113 &Header
::openpage
($Lang::tr
{'fwdfw menu'}, 1, '');
114 &Header
::openbigbox
('100%', 'center',$errormessage);
117 if ($fwdfwsettings{'ACTION'} eq 'saverule')
119 &General
::readhasharray
("$configfwdfw", \
%configfwdfw);
120 &General
::readhasharray
("$configinput", \
%configinputfw);
121 &General
::readhasharray
("$configoutgoing", \
%configoutgoingfw);
122 &General
::readhasharray
("$confignat", \
%confignatfw);
123 $errormessage=&checksource
;
124 if(!$errormessage){&checktarget
;}
125 if(!$errormessage){&checkrule
;}
127 #check if manual ip (source) is orange network
128 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
129 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
130 if ( &General
::IpInSubnet
($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
135 if( ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' || $checkorange eq 'on') && $fwdfwsettings{'grp2'} eq 'ipfire'){
136 $errormessage.=$Lang::tr
{'fwdfw useless rule'}."<br>";
138 #check if we try to break rules
139 if( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'grp2'} eq 'ipfire'){
140 $errormessage.=$Lang::tr
{'fwdfw err same'};
143 if ($fwdfwsettings{'USE_NAT'} eq 'ON'){
144 $fwdfwsettings{'config'}=$confignat;
145 if ($fwdfwsettings{'nat'} eq 'dnat'){
146 $fwdfwsettings{'chain'} = 'NAT_DESTINATION';
148 $fwdfwsettings{'chain'} = 'NAT_SOURCE';
150 my $maxkey=&General
::findhasharraykey
(\
%confignatfw);
151 #check if we have an identical rule already
152 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
153 foreach my $key (sort keys %confignatfw){
154 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]"
155 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'}"){
156 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
157 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' ){
159 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark
($fwdfwsettings{'ruleremark'})){
160 $errormessage=$Lang::tr
{'fwdfw err remark'}."<br>";
162 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
163 $fwdfwsettings{'nosave'} = 'on';
169 #check Rulepos on new Rule
170 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
171 $fwdfwsettings{'oldrulenumber'}=$maxkey;
172 foreach my $key (sort keys %confignatfw){
173 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'}"
174 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]"){
175 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
179 #check if we just close a rule
180 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'}) {
181 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
183 $fwdfwsettings{'nosave2'} = 'on';
186 &checkcounter
($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
187 if ($fwdfwsettings{'nobase'} ne 'on'){
188 &checkcounter
($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
190 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
191 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
192 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
193 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
194 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
195 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
197 if($fwdfwsettings{'nosave2'} ne 'on'){
198 &saverule
(\
%confignatfw,$confignat);
201 }elsif($fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ORANGE'){
202 $fwdfwsettings{'config'}=$configinput;
203 $fwdfwsettings{'chain'} = 'INPUTFW';
204 my $maxkey=&General
::findhasharraykey
(\
%configinputfw);
205 #check if we have an identical rule already
206 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
207 foreach my $key (sort keys %configinputfw){
208 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'}"
209 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]"){
210 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
211 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on'){
213 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark
($fwdfwsettings{'ruleremark'})){
214 $errormessage=$Lang::tr
{'fwdfw err remark'}."<br>";
216 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
217 $fwdfwsettings{'nosave'} = 'on';
222 #check Rulepos on new Rule
223 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
224 $fwdfwsettings{'oldrulenumber'}=$maxkey;
225 foreach my $key (sort keys %configinputfw){
226 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'}"
227 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]"){
228 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
232 #check if we just close a rule
233 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'}) {
234 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
236 $fwdfwsettings{'nosave2'} = 'on';
239 &checkcounter
($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
240 if ($fwdfwsettings{'nobase'} ne 'on'){
241 &checkcounter
($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
243 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
244 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
245 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
246 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
247 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
248 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
250 if($fwdfwsettings{'nosave2'} ne 'on'){
251 &saverule
(\
%configinputfw,$configinput);
253 }elsif($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' ){
255 $fwdfwsettings{'config'}=$configoutgoing;
256 $fwdfwsettings{'chain'} = 'OUTGOINGFW';
257 my $maxkey=&General
::findhasharraykey
(\
%configoutgoingfw);
258 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
259 foreach my $key (sort keys %configoutgoingfw){
260 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'}"
261 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]"){
262 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
263 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on'){
265 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark
($fwdfwsettings{'ruleremark'})){
266 $errormessage=$Lang::tr
{'fwdfw err remark'}."<br>";
268 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
269 $fwdfwsettings{'nosave'} = 'on';
274 #check Rulepos on new Rule
275 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
276 print"CHECK OUTGOING DOPPELTE REGEL<br>";
277 $fwdfwsettings{'oldrulenumber'}=$maxkey;
278 foreach my $key (sort keys %configoutgoingfw){
279 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'}"
280 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]"){
281 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
285 #check if we just close a rule
286 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'}) {
287 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
288 $fwdfwsettings{'nosave2'} = 'on';
293 &checkcounter
($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
294 &checkcounter
($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
295 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
296 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
297 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
298 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
299 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
300 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
302 if ($fwdfwsettings{'nobase'} eq 'on'){
303 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
305 if ($fwdfwsettings{'nosave2'} ne 'on'){
306 &saverule
(\
%configoutgoingfw,$configoutgoing);
310 $fwdfwsettings{'config'}=$configfwdfw;
311 $fwdfwsettings{'chain'} = 'FORWARDFW';
312 my $maxkey=&General
::findhasharraykey
(\
%configfwdfw);
313 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
314 #check if we have an identical rule already
315 foreach my $key (sort keys %configfwdfw){
316 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'}"
317 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]"){
318 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
319 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' ){
321 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark
($fwdfwsettings{'ruleremark'})){
322 $errormessage=$Lang::tr
{'fwdfw err remark'}."<br>";
324 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
325 $fwdfwsettings{'nosave'} = 'on';
330 #check Rulepos on new Rule
331 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
332 $fwdfwsettings{'oldrulenumber'}=$maxkey;
333 foreach my $key (sort keys %configfwdfw){
334 if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}"
335 eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[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]"){
336 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
340 #check if we just close a rule
341 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'}) {
342 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
343 $fwdfwsettings{'nosave2'} = 'on';
348 &checkcounter
($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
349 &checkcounter
($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
350 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
351 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
352 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
353 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
354 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
355 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
357 if ($fwdfwsettings{'nobase'} eq 'on'){
358 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
360 if ($fwdfwsettings{'nosave2'} ne 'on'){
361 &saverule
(\
%configfwdfw,$configfwdfw);
367 if($fwdfwsettings{'nosave2'} ne 'on'){
373 if ($fwdfwsettings{'ACTION'} eq $Lang::tr
{'fwdfw newrule'})
377 if ($fwdfwsettings{'ACTION'} eq $Lang::tr
{'fwdfw toggle'})
380 &General
::readhasharray
($fwdfwsettings{'config'}, \
%togglehash);
381 foreach my $key (sort keys %togglehash){
382 if ($key eq $fwdfwsettings{'key'}){
383 if ($togglehash{$key}[2] eq 'ON'){$togglehash{$key}[2]='';}else{$togglehash{$key}[2]='ON';}
386 &General
::writehasharray
($fwdfwsettings{'config'}, \
%togglehash);
390 if ($fwdfwsettings{'ACTION'} eq $Lang::tr
{'fwdfw togglelog'})
393 &General
::readhasharray
($fwdfwsettings{'config'}, \
%togglehash);
394 foreach my $key (sort keys %togglehash){
395 if ($key eq $fwdfwsettings{'key'}){
396 if ($togglehash{$key}[17] eq 'ON'){$togglehash{$key}[17]='';}else{$togglehash{$key}[17]='ON';}
399 &General
::writehasharray
($fwdfwsettings{'config'}, \
%togglehash);
403 if ($fwdfwsettings{'ACTION'} eq $Lang::tr
{'fwdfw reread'})
408 if ($fwdfwsettings{'ACTION'} eq 'editrule')
410 $fwdfwsettings{'updatefwrule'}='on';
413 if ($fwdfwsettings{'ACTION'} eq 'deleterule')
417 if ($fwdfwsettings{'ACTION'} eq 'moveup')
422 if ($fwdfwsettings{'ACTION'} eq 'movedown')
427 if ($fwdfwsettings{'ACTION'} eq 'copyrule')
429 $fwdfwsettings{'copyfwrule'}='on';
432 if ($fwdfwsettings{'ACTION'} eq '')
440 if (-f
"${General::swroot}/forward/reread"){
441 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;'>    $Lang::tr{'fwhost reread'}</div</td></tr></table></form><hr><br>";
443 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw menu'});
444 print "<form method='post'>";
445 print "<table border='0'>";
446 print "<tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'></td>";
447 print"</tr></table></form><hr>";
456 print "<br><br><div align='right'><font size='1' color='grey'>Version: $VERSION</font></div>";
461 $fwdfwsettings{'updatefwrule'}='';
462 $fwdfwsettings{'config'}=$oldchain;
463 $fwdfwsettings{'nobase'}='on';
465 &checkcounter
(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
466 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
471 #check ip-address if manual
472 if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){
473 #check if ip with subnet
474 if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?
)$/) {
475 ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'});
476 $subnet = &General
::iporsubtocidr
($subnet);
477 $fwdfwsettings{'isip'}='on';
480 if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
481 $ip=$fwdfwsettings{'src_addr'};
483 $fwdfwsettings{'isip'}='on';
486 if ($fwdfwsettings{'isip'} ne 'on'){
487 if (&General
::validmac
($fwdfwsettings{'src_addr'})){$fwdfwsettings{'ismac'}='on';}
489 if ($fwdfwsettings{'isip'} eq 'on'){
490 ##check if ip is valid
491 if (! &General
::validip
($ip)){
492 $errormessage.=$Lang::tr
{'fwdfw err src_addr'}."<br>";
493 return $errormessage;
495 #check and form valid IP
496 $ip=&General
::ip2dec
($ip);
497 $ip=&General
::dec2ip
($ip);
498 #check if net or broadcast
499 my @tmp= split (/\./,$ip);
500 if (($tmp[3] eq "0") || ($tmp[3] eq "255"))
502 $errormessage=$Lang::tr
{'fwhost err hostip'}."<br>";
503 return $errormessage;
505 $fwdfwsettings{'src_addr'}="$ip/$subnet";
506 if(!&General
::validipandmask
($fwdfwsettings{'src_addr'})){
507 $errormessage.=$Lang::tr
{'fwdfw err src_addr'}."<br>";
508 return $errormessage;
511 if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){
512 $errormessage.=$Lang::tr
{'fwdfw err src_addr'}."<br>";
513 return $errormessage;
515 }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
516 $errormessage.=$Lang::tr
{'fwdfw err nosrcip'};
517 return $errormessage;
521 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr
{'fwdfw err nosrc'}."<br>";}
523 if ($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ICMP'){
524 $fwdfwsettings{'SRC_PORT'}='';
525 &General
::readhasharray
("${General::swroot}/fwhosts/icmp-types", \
%icmptypes);
526 foreach my $key (keys %icmptypes){
527 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){
528 $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]";
531 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'GRE'){
532 $fwdfwsettings{'SRC_PORT'}='';
533 $fwdfwsettings{'ICMP_TYPES'}='';
534 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ESP'){
535 $fwdfwsettings{'SRC_PORT'}='';
536 $fwdfwsettings{'ICMP_TYPES'}='';
537 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'AH'){
538 $fwdfwsettings{'SRC_PORT'}='';
539 $fwdfwsettings{'ICMP_TYPES'}='';
540 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} ne 'ICMP'){
541 $fwdfwsettings{'ICMP_TYPES'}='';
543 $fwdfwsettings{'ICMP_TYPES'}='';
544 $fwdfwsettings{'SRC_PORT'}='';
545 $fwdfwsettings{'PROT'}='';
548 if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){
549 my @parts=split(",",$fwdfwsettings{'SRC_PORT'});
553 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
555 #change dashes with :
558 push(@values,"1:65535");
561 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
562 push(@values,"1:$2");
565 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/ ) {
566 push(@values,"$1:65535");
569 $errormessage .= &General
::validportrange
($_, 'destination');
574 if (&General
::validport
($_)){
581 $fwdfwsettings{'SRC_PORT'}=join("|",@values);
583 return $errormessage;
588 &General
::readhasharray
("$configsrv", \
%customservice);
589 #check DNAT settings (has to be single Host and single Port or portrange)
590 if ($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat'){
591 if($fwdfwsettings{'grp2'} eq 'tgt_addr' || $fwdfwsettings{'grp2'} eq 'cust_host_tgt' || $fwdfwsettings{'grp2'} eq 'ovpn_host_tgt'){
592 if ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'dnatport'} eq ''){
593 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
594 return $errormessage;
596 #check if manual ip is a single Host (if set)
597 if ($fwdfwsettings{'grp2'} eq 'tgt_addr'){
598 my @tmp= split (/\./,$fwdfwsettings{$fwdfwsettings{'grp2'}});
599 my @tmp1= split ("/",$tmp[3]);
600 if (($tmp1[0] eq "0") || ($tmp1[0] eq "255"))
602 $errormessage=$Lang::tr
{'fwdfw dnat error'}."<br>";
603 return $errormessage;
606 #check if Port is a single Port or portrange
607 if ($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
608 if(($fwdfwsettings{'TGT_PROT'} ne 'TCP'|| $fwdfwsettings{'TGT_PROT'} ne 'UDP') && $fwdfwsettings{'TGT_PORT'} eq ''){
609 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
610 return $errormessage;
612 if (($fwdfwsettings{'TGT_PROT'} eq 'TCP'|| $fwdfwsettings{'TGT_PROT'} eq 'UDP') && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport
($fwdfwsettings{'TGT_PORT'})){
613 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
614 return $errormessage;
618 $errormessage=$Lang::tr
{'fwdfw dnat error'}."<br>";
619 return $errormessage;
622 if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
623 #check if ip with subnet
624 if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?
)$/) {
625 ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
626 $subnet = &General
::iporsubtocidr
($subnet);
629 if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
630 $ip=$fwdfwsettings{'tgt_addr'};
633 #check if ip is valid
634 if (! &General
::validip
($ip)){
635 $errormessage.=$Lang::tr
{'fwdfw err tgt_addr'}."<br>";
636 return $errormessage;
638 #check and form valid IP
639 $ip=&General
::ip2dec
($ip);
640 $ip=&General
::dec2ip
($ip);
641 $fwdfwsettings{'tgt_addr'}="$ip/$subnet";
642 if(!&General
::validipandmask
($fwdfwsettings{'tgt_addr'})){
643 $errormessage.=$Lang::tr
{'fwdfw err tgt_addr'}."<br>";
644 return $errormessage;
646 }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
647 $errormessage.=$Lang::tr
{'fwdfw err notgtip'};
648 return $errormessage;
651 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr
{'fwdfw err notgt'}."<br>";}
653 if ($fwdfwsettings{'USESRV'} eq 'ON'){
654 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
655 $fwdfwsettings{'TGT_PROT'}='';
656 $fwdfwsettings{'ICMP_TGT'}='';
658 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
659 $fwdfwsettings{'TGT_PROT'}='';
660 $fwdfwsettings{'ICMP_TGT'}='';
661 #check target service
662 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){
663 $errormessage.=$Lang::tr
{'fwdfw err tgt_grp'};
666 if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
667 if ($fwdfwsettings{'TGT_PROT'} eq 'TCP' || $fwdfwsettings{'TGT_PROT'} eq 'UDP'){
668 if ($fwdfwsettings{'TGT_PORT'} ne ''){
669 if ($fwdfwsettings{'TGT_PORT'} =~ "," && $fwdfwsettings{'USE_NAT'} && $fwdfwsettings{'nat'} eq 'dnat') {
670 $errormessage=$Lang::tr
{'fwdfw dnat porterr'}."<br>";
671 return $errormessage;
673 my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
677 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
679 #change dashes with :
682 push(@values,"1:65535");
685 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
686 push(@values,"1:$2");
689 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
690 push(@values,"$1:65535");
693 $errormessage .= &General
::validportrange
($_, 'destination');
698 if (&General
::validport
($_)){
705 $fwdfwsettings{'TGT_PORT'}=join("|",@values);
707 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'GRE'){
708 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
709 $fwdfwsettings{'TGT_PORT'} = '';
710 $fwdfwsettings{'ICMP_TGT'} = '';
711 }elsif($fwdfwsettings{'TGT_PROT'} eq 'ESP'){
712 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
713 $fwdfwsettings{'TGT_PORT'} = '';
714 $fwdfwsettings{'ICMP_TGT'}='';
715 }elsif($fwdfwsettings{'TGT_PROT'} eq 'AH'){
716 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
717 $fwdfwsettings{'TGT_PORT'} = '';
718 $fwdfwsettings{'ICMP_TGT'}='';
719 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'ICMP'){
720 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
721 $fwdfwsettings{'TGT_PORT'} = '';
722 &General
::readhasharray
("${General::swroot}/fwhosts/icmp-types", \
%icmptypes);
723 foreach my $key (keys %icmptypes){
725 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwdfwsettings{'ICMP_TGT'}){
726 $fwdfwsettings{'ICMP_TGT'}=$icmptypes{$key}[0];
733 if ($fwdfwsettings{'USESRV'} ne 'ON'){
734 $fwdfwsettings{'grp3'}='';
735 $fwdfwsettings{$fwdfwsettings{'grp3'}}='';
736 $fwdfwsettings{'ICMP_TGT'}='';
739 if($fwdfwsettings{'TIME'} eq 'ON'){
740 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 ''){
741 $errormessage=$Lang::tr
{'fwdfw err time'};
742 return $errormessage;
745 return $errormessage;
750 if($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
751 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\-(\d+)$/) {
752 $fwdfwsettings{'dnatport'} =~ tr/-/:/;
753 if ($fwdfwsettings{'dnatport'} eq "*") {
754 $fwdfwsettings{'dnatport'}="1:65535";
756 if ($fwdfwsettings{'dnatport'} =~ /^(\D)\:(\d+)$/) {
757 $fwdfwsettings{'dnatport'} = "1:$2";
759 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\:(\D)$/) {
760 $fwdfwsettings{'dnatport'} ="$1:65535";
765 if ($val =~ "," || $val>65536 || $val<0){
772 #check valid port for NAT
773 if($fwdfwsettings{'USE_NAT'} eq 'ON'){
774 #if no port is given in nat area, take target host port
775 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$fwdfwsettings{'TGT_PORT'};}
776 #check if port given in nat area is a single valid port or portrange
777 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport
($fwdfwsettings{'dnatport'})){
778 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
779 }elsif($fwdfwsettings{'USESRV'} eq 'ON' && $fwdfwsettings{'grp3'} eq 'cust_srv'){
781 #get servcie Protocol and Port
782 foreach my $key (sort keys %customservice){
783 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]){
784 if ($customservice{$key}[2] ne 'TCP' && $customservice{$key}[2] ne 'UDP'){
785 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
787 $custsrvport= $customservice{$key}[1];
790 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$custsrvport;}
792 #check if DNAT port is multiple
793 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
794 my @parts=split(",",$fwdfwsettings{'dnatport'});
798 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
800 #change dashes with :
803 push(@values,"1:65535");
806 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
807 push(@values,"1:$2");
810 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
811 push(@values,"$1:65535");
814 $errormessage .= &General
::validportrange
($_, 'destination');
819 if (&General
::validport
($_)){
826 $fwdfwsettings{'dnatport'}=join("|",@values);
830 if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark
($fwdfwsettings{'ruleremark'})){
831 $errormessage.=$Lang::tr
{'fwdfw err remark'}."<br>";
833 #check if source and target identical
834 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL'){
835 $errormessage.=$Lang::tr
{'fwdfw err same'};
836 return $errormessage;
838 #get source and targetip address if possible
839 my ($sip,$scidr,$tip,$tcidr);
840 ($sip,$scidr)=&get_ip
("src","grp1");
841 ($tip,$tcidr)=&get_ip
("tgt","grp2");
842 #check same iprange in source and target
843 if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){
844 my $networkip1=&General
::getnetworkip
($sip,$scidr);
845 my $networkip2=&General
::getnetworkip
($tip,$tcidr);
846 if ($scidr gt $tcidr){
847 if ( &General
::IpInSubnet
($networkip1,$tip,&General
::iporsubtodec
($tcidr))){
848 $errormessage.=$Lang::tr
{'fwdfw err samesub'};
850 }elsif($scidr eq $tcidr && $scidr eq '32'){
851 my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1);
852 my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2);
853 if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){
854 $hint=$Lang::tr
{'fwdfw hint ip1'}."<br>";
855 $hint.=$Lang::tr
{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>";
858 if ( &General
::IpInSubnet
($networkip2,$sip,&General
::iporsubtodec
($scidr)) ){
859 $errormessage.=$Lang::tr
{'fwdfw err samesub'};
863 #check source and destination protocol if manual
864 if( $fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'USESRV'} eq 'ON'){
865 if($fwdfwsettings{'PROT'} ne $fwdfwsettings{'TGT_PROT'} && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
866 $errormessage.=$Lang::tr
{'fwdfw err prot'};
868 #check source and destination protocol if source manual and dest servicegrp
869 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
870 foreach my $key (sort keys %customservice){
871 if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){
872 if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){
873 $errormessage.=$Lang::tr
{'fwdfw err prot'};
883 my ($base1,$val1,$base2,$val2) = @_;
885 if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){
886 &dec_counter
($confignet,\
%customnetwork,$val1);
887 }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){
888 &dec_counter
($confighost,\
%customhost,$val1);
889 }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){
890 &dec_counter
($configgrp,\
%customgrp,$val1);
891 }elsif($base1 eq 'cust_srv'){
892 &dec_counter
($configsrv,\
%customservice,$val1);
893 }elsif($base1 eq 'cust_srvgrp'){
894 &dec_counter
($configsrvgrp,\
%customservicegrp,$val1);
897 if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){
898 &inc_counter
($confignet,\
%customnetwork,$val2);
899 }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){
900 &inc_counter
($confighost,\
%customhost,$val2);
901 }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){
902 &inc_counter
($configgrp,\
%customgrp,$val2);
903 }elsif($base2 eq 'cust_srv'){
904 &inc_counter
($configsrv,\
%customservice,$val2);
905 }elsif($base2 eq 'cust_srvgrp'){
906 &inc_counter
($configsrvgrp,\
%customservicegrp,$val2);
912 #Test if manual IP is part of static OpenVPN networks
913 &General
::readhasharray
("$configccdnet", \
%ccdnet);
914 foreach my $key (sort keys %ccdnet){
915 my ($vpnip,$vpnsubnet) = split ("/",$ccdnet{$key}[1]);
916 my $sub=&General
::iporsubtodec
($vpnsubnet);
917 if (&General
::IpInSubnet
($ip,$vpnip,$sub)){
921 # A Test if manual ip is part of dynamic openvpn subnet is made in getcolor
922 # because if one creates a custom host with the ip, we need to check the color there!
923 # It does not make sense to check this here
925 # Test if manual IP is part of an OpenVPN N2N subnet does also not make sense here
926 # Is also checked in getcolor
928 # Test if manual ip is part of an IPsec Network is also checked in getcolor
938 &General
::readhasharray
($fwdfwsettings{'config'}, \
%delhash);
939 foreach my $key (sort {$a <=> $b} keys %delhash){
940 if ($key == $fwdfwsettings{'key'}){
941 #check hosts/net and groups
942 &checkcounter
($delhash{$key}[3],$delhash{$key}[4],,);
943 &checkcounter
($delhash{$key}[5],$delhash{$key}[6],,);
944 #check services and groups
945 if ($delhash{$key}[11] eq 'ON'){
946 &checkcounter
($delhash{$key}[14],$delhash{$key}[15],,);
949 if ($key >= $fwdfwsettings{'key'}) {
951 if (exists $delhash{$next}) {
952 foreach my $i (0 .. $#{$delhash{$next}}) {
953 $delhash{$key}[$i] = $delhash{$next}[$i];
958 # Remove the very last entry.
959 my $last_key = (sort {$a <=> $b} keys %delhash)[-1];
960 delete $delhash{$last_key};
962 &General
::writehasharray
($fwdfwsettings{'config'}, \
%delhash);
965 if($fwdfwsettings{'nobase'} ne 'on'){
972 &General
::readhasharray
("$configfwdfw", \
%configfwdfw);
973 foreach my $key (sort keys %configfwdfw){
975 if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';}
978 &General
::writehasharray
("$configfwdfw", \
%configfwdfw);
987 &General
::readhasharray
($config, \
%hash);
988 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
989 if($hash{$key}[0] eq $val){
990 $pos=$#{$hash{$key}};
991 $hash{$key}[$pos] = $hash{$key}[$pos]-1;
994 &General
::writehasharray
($config, \
%hash);
999 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
1000 print "<class name='base'>$errormessage\n";
1001 print " </class>\n";
1002 &Header
::closebox
();
1008 my %hash=%{(shift)};
1011 foreach my $key (sort { ncmp
($hash{$a}[0],$hash{$b}[0]) } keys %hash){
1012 if($hash{$key}[0] eq $val){
1013 print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>";
1015 print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>";
1025 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1026 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1027 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1028 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1029 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1030 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1031 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1032 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1033 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1034 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1035 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1036 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1037 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1038 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1039 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1040 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1041 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1042 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1044 <table width='100%' border='0'>
1045 <tr><td width='50%' valign='top'>
1046 <table width='100%' border='0'>
1047 <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;'>
1049 foreach my $network (sort keys %defaultNetworks)
1051 next if($defaultNetworks{$network}{'NAME'} eq "RED" && $srctgt eq 'src');
1052 next if($defaultNetworks{$network}{'NAME'} eq "IPFire" && $srctgt eq 'tgt');
1053 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1054 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $defaultNetworks{$network}{'NAME'});
1055 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
1056 $ifaces{$defnet} = '0.0.0.0' if ($defaultNetworks{$network}{'NAME'} eq 'ALL');
1057 $defnet = "RED_ADDRESS" if ($defaultNetworks{$network}{'NAME'} eq 'IPFire');
1058 print ">$network $ifaces{$defnet} </option>";
1060 print"</select></td></tr>";
1062 if (! -z
$confignet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1063 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;'>";
1064 &fillselect
(\
%customnetwork,$fwdfwsettings{$fwdfwsettings{$grp}});
1065 print"</select></td>";
1068 if (! -z
$confighost || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1069 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;'>";
1070 &fillselect
(\
%customhost,$fwdfwsettings{$fwdfwsettings{$grp}});
1071 print"</select></td>";
1074 if (! -z
$configgrp || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1075 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;'>";
1076 foreach my $key (sort { ncmp
($customgrp{$a}[0],$customgrp{$b}[0]) } keys %customgrp) {
1077 if($helper ne $customgrp{$key}[0]){
1079 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $customgrp{$key}[0]);
1080 print ">$customgrp{$key}[0]</option>";
1082 $helper=$customgrp{$key}[0];
1084 print"</select></td>";
1086 #End left table. start right table (vpn)
1087 print"</tr></table></td><td valign='top'><table width='100%' border='0'><tr>";
1089 if( ! -z
$configccdnet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1090 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;'>";
1091 &fillselect
(\
%ccdnet,$fwdfwsettings{$fwdfwsettings{$grp}});
1092 print"</select></td></tr>";
1095 foreach my $key (sort { ncmp
($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost){
1096 if ($ccdhost{$key}[33] ne '' ){
1097 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 '');
1099 print "<option value='$ccdhost{$key}[1]'";
1100 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1101 print ">$ccdhost{$key}[1]</option>";
1104 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1105 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>" ;
1107 if ($show eq '1'){$show='';print"</select></td></tr>";}
1109 foreach my $key (sort { ncmp
($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost){
1110 if ($ccdhost{$key}[3] eq 'net'){
1111 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 '');
1113 print "<option value='$ccdhost{$key}[1]'";
1114 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1115 print ">$ccdhost{$key}[1]</option>";
1118 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1119 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>" ;
1121 if ($show eq '1'){$show='';print"</select></td></tr>";}
1123 foreach my $key (sort { ncmp
($ipsecconf{$a}[1],$ipsecconf{$b}[1]) } keys %ipsecconf) {
1124 if ($ipsecconf{$key}[3] eq 'net' || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1125 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 '');
1128 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ipsecconf{$key}[1]);
1129 print ">$ipsecconf{$key}[1]</option>";
1132 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1133 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>";
1135 if ($show eq '1'){$show='';print"</select></td></tr>";}
1137 print"</tr></table>";
1138 print"</td></tr></table><br>";
1146 &General
::readhash
("/var/ipfire/ethernet/settings", \
%netsettings);
1147 if ($fwdfwsettings{$grp} ne $Lang::tr
{'fwhost any'}){
1148 if ($fwdfwsettings{$grp} eq $val.'_addr'){
1149 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
1150 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
1151 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
1152 $a=$netsettings{'GREEN_NETADDRESS'};
1153 $b=&General
::iporsubtocidr
($netsettings{'GREEN_NETMASK'});
1154 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
1155 $a=$netsettings{'ORANGE_NETADDRESS'};
1156 $b=&General
::iporsubtocidr
($netsettings{'ORANGE_NETMASK'});
1157 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
1158 $a=$netsettings{'BLUE_NETADDRESS'};
1159 $b=&General
::iporsubtocidr
($netsettings{'BLUE_NETMASK'});
1160 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
1161 &General
::readhash
("$configovpn",\
%ovpnsettings);
1162 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
1163 $b=&General
::iporsubtocidr
($b);
1165 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
1166 &General
::readhasharray
("$confignet", \
%customnetwork);
1167 foreach my $key (keys %customnetwork){
1168 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1169 $a=$customnetwork{$key}[1];
1170 $b=&General
::iporsubtocidr
($customnetwork{$key}[2]);
1173 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
1174 &General
::readhasharray
("$confighost", \
%customhost);
1175 foreach my $key (keys %customhost){
1176 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1177 if ($customhost{$key}[1] eq 'ip'){
1178 ($a,$b)=split (/\//,$customhost{$key}[2]);
1179 $b=&General
::iporsubtocidr
($b);
1181 if ($grp eq 'grp2'){
1182 $errormessage=$Lang::tr
{'fwdfw err tgt_mac'};
1194 &General
::setup_default_networks
(\
%defaultNetworks);
1195 foreach my $network (sort keys %defaultNetworks)
1197 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1202 my %hash=%{(shift)};
1204 if($hash{$key}[7] eq 'ON' && $hash{$key}[8] ne '' && $hash{$key}[10]){
1205 $hash{$key}[10]=~ s/\|/,/g;
1206 print": $hash{$key}[10]";
1207 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
1208 print": <br>$hash{$key}[9] ";
1213 my %hash=%{(shift)};
1217 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1218 if($hash{$key}[14] eq 'cust_srv'){
1219 &General
::readhasharray
("$configsrv", \
%customservice);
1220 foreach my $i (sort keys %customservice){
1221 if($customservice{$i}[0] eq $hash{$key}[15]){
1222 $service = $customservice{$i}[0];
1225 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
1226 $service=$hash{$key}[15];
1227 }elsif($hash{$key}[14] eq 'TGT_PORT'){
1228 $hash{$key}[15]=~ s/\|/,/g;
1229 $service=$hash{$key}[15];
1234 }elsif($hash{$key}[11] eq 'ON' && $hash{$key}[12] eq 'ICMP'){
1235 print":<br>$hash{$key}[13]";
1238 sub get_serviceports
1242 &General
::readhasharray
("$configsrv", \
%customservice);
1243 &General
::readhasharray
("$configsrvgrp", \
%customservicegrp);
1248 if($type eq 'service'){
1249 foreach my $key (sort { ncmp
($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1250 if ($customservice{$key}[0] eq $name){
1251 push (@protocols,$customservice{$key}[2]);
1254 }elsif($type eq 'group'){
1255 foreach my $key (sort { ncmp
($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1256 if ($customservicegrp{$key}[0] eq $name){
1257 foreach my $key1 (sort { ncmp
($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1258 if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
1259 if($customservice{$key1}[2] eq 'TCP'){
1261 }elsif($customservice{$key1}[2] eq 'ICMP'){
1263 }elsif($customservice{$key1}[2] eq 'UDP'){
1271 if($tcp && $udp && $icmp){
1272 push (@protocols,"All");
1276 push (@protocols,"TCP");
1279 push (@protocols,"UDP");
1282 push (@protocols,"ICMP");
1291 if($optionsfw{'SHOWCOLORS'} eq 'on'){
1293 if ($val eq 'GREEN'){
1294 $tdcolor="style='border: 1px solid $Header::colourgreen;'";
1296 }elsif ($val eq 'ORANGE'){
1297 $tdcolor="style='border: 1px solid $Header::colourorange;'";
1299 }elsif ($val eq 'BLUE'){
1300 $tdcolor="style='border: 1px solid $Header::colourblue;'";
1302 }elsif ($val eq 'RED' ||$val eq 'RED1' ){
1303 $tdcolor="style='border: 1px solid $Header::colourred;'";
1305 }elsif ($val eq 'IPFire' ){
1306 $tdcolor="style='border: 1px solid $Header::colourred;'";
1308 }elsif($val =~ /^(.*?)\/(.*?
)$/){
1309 my ($sip,$scidr) = split ("/",$val);
1310 if ( &General
::IpInSubnet
($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1311 $tdcolor="style='border: 1px solid $Header::colourorange;'";
1314 if ( &General
::IpInSubnet
($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1315 $tdcolor="style='border: 1px solid $Header::colourgreen;'";
1318 if ( &General
::IpInSubnet
($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
1319 $tdcolor="style='border: 1px solid $Header::colourblue;'";
1322 }elsif ($val eq 'Default IP'){
1323 $tdcolor="style='border: 1px solid $Header::colourred;'";
1326 #Check if a manual IP is part of a VPN
1327 if ($nettype eq 'src_addr' || $nettype eq 'tgt_addr'){
1328 #Check if IP is part of OpenVPN dynamic subnet
1329 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
1330 my ($c,$d) = split("/",$val);
1331 if (&General
::IpInSubnet
($c,$a,$b)){
1332 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1335 #Check if IP is part of OpenVPN static subnet
1336 foreach my $key (sort keys %ccdnet){
1337 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1338 $b =&General
::iporsubtodec
($b);
1339 if (&General
::IpInSubnet
($c,$a,$b)){
1340 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1344 #Check if IP is part of OpenVPN N2N subnet
1345 foreach my $key (sort keys %ccdhost){
1346 if ($ccdhost{$key}[3] eq 'net'){
1347 my ($a,$b) = split("/",$ccdhost{$key}[11]);
1348 if (&General
::IpInSubnet
($c,$a,$b)){
1349 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1354 #Check if IP is part of IPsec RW network
1355 if ($ipsecsettings{'RW_NET'} ne ''){
1356 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1357 $b=&General
::iporsubtodec
($b);
1358 if (&General
::IpInSubnet
($c,$a,$b)){
1359 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1363 #Check if IP is part of a IPsec N2N network
1364 foreach my $key (sort keys %ipsecconf){
1365 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1366 if (&General
::IpInSubnet
($c,$a,$b)){
1367 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1373 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'){
1374 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1377 if ($nettype eq 'ipsec_net_src' || $nettype eq 'ipsec_net_tgt'){
1378 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1382 if ($nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1383 foreach my $key (sort keys %$hash){
1384 if ($$hash{$key}[0] eq $val){
1385 $val=$$hash{$key}[2];
1390 foreach my $alias (sort keys %aliases)
1392 if ($val eq $alias){
1393 $tdcolor="style='border: 1px solid $Header::colourred;'";
1404 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwhost hint'});
1405 print "<class name='base'>$hint\n";
1406 print " </class>\n";
1407 &Header
::closebox
();
1414 my %hash=%{(shift)};
1418 &General
::readhasharray
($config, \
%hash);
1419 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
1420 if($hash{$key}[0] eq $val){
1421 $pos=$#{$hash{$key}};
1422 $hash{$key}[$pos] = $hash{$key}[$pos]+1;
1425 &General
::writehasharray
($config, \
%hash);
1430 &General
::setup_default_networks
(\
%defaultNetworks);
1431 &General
::readhash
("/var/ipfire/ethernet/settings", \
%netsettings);
1432 #read all configfiles
1433 &General
::readhasharray
("$configccdnet", \
%ccdnet);
1434 &General
::readhasharray
("$confignet", \
%customnetwork);
1435 &General
::readhasharray
("$configccdhost", \
%ccdhost);
1436 &General
::readhasharray
("$confighost", \
%customhost);
1437 &General
::readhasharray
("$configccdhost", \
%ccdhost);
1438 &General
::readhasharray
("$configgrp", \
%customgrp);
1439 &General
::readhasharray
("$configipsec", \
%ipsecconf);
1440 &General
::get_aliases
(\
%aliases);
1444 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
1445 my $config=$fwdfwsettings{'config'};
1447 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1448 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1449 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1450 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1451 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1452 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1453 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1454 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1455 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1456 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1457 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1458 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1459 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1460 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1461 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1462 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1463 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1464 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1465 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1466 #check if update and get values
1467 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
1468 &General
::readhasharray
("$config", \
%hash);
1469 foreach my $key (sort keys %hash){
1471 if ($key eq $fwdfwsettings{'key'}){
1472 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
1473 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
1474 $fwdfwsettings{'chain'} = $hash{$key}[1];
1475 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1476 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1477 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1478 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1479 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1480 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1481 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1482 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1483 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1484 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1485 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1486 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1487 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1488 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1489 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1490 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1491 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1492 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1493 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1494 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1495 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1496 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1497 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1498 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1499 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1500 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
1501 $fwdfwsettings{'USE_NAT'} = $hash{$key}[28];
1502 $fwdfwsettings{'nat'} = $hash{$key}[31]; #changed order
1503 $fwdfwsettings{$fwdfwsettings{'nat'}} = $hash{$key}[29];
1504 $fwdfwsettings{'dnatport'} = $hash{$key}[30];
1505 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1506 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1507 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1508 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1509 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1510 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1511 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1512 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1513 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1514 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1515 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1516 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1517 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1518 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1519 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1520 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1521 $checked{'nat'}{$fwdfwsettings{'nat'}} = 'CHECKED';
1522 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1523 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1524 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1525 $selected{'dnat'}{$fwdfwsettings{$fwdfwsettings{'nat'}}} ='selected';
1526 $selected{'snat'}{$fwdfwsettings{$fwdfwsettings{'nat'}}} ='selected';
1529 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1530 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1531 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1532 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1533 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1534 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1535 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1536 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1537 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1538 $fwdfwsettings{'oldruletype'}=$fwdfwsettings{'chain'};
1539 #check if manual ip (source) is orange network
1540 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1541 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1542 if ( &General
::IpInSubnet
($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1543 $fwdfwsettings{'oldorange'} ='on';
1547 $fwdfwsettings{'ACTIVE'}='ON';
1548 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1549 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1550 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1551 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1552 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1553 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1554 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1555 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1556 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1557 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1558 #check if manual ip (source) is orange network
1559 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1560 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1561 if ( &General
::IpInSubnet
($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1562 $fwdfwsettings{'oldorange'} ='on';
1566 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw addrule'});
1567 print "<form method='post'>";
1568 &Header
::closebox
();
1569 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw source'});
1570 #------SOURCE-------------------------------------------------------
1572 <table width='100%' border='0'>
1573 <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>
1574 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr>
1577 &gen_dd_block
('src','grp1');
1579 <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
1580 <table width='100%' border='0'>
1581 <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>
1582 <td width='15%' nowrap='nowrap'>$Lang::tr{'fwdfw man port'}</td><td><select name='PROT'>
1584 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
1586 if ($_ eq $fwdfwsettings{'PROT'})
1588 print"<option selected>$_</option>";
1590 print"<option>$_</option>";
1593 $fwdfwsettings{'SRC_PORT'}=~ s/\|/,/g;
1595 </select></td><td align='right'><input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18' ></td></tr>
1596 <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;'>
1598 &General
::readhasharray
("${General::swroot}/fwhosts/icmp-types", \
%icmptypes);
1599 print"<option>All ICMP-Types</option>";
1600 foreach my $key (sort { ncmp
($icmptypes{$a}[0],$icmptypes{$b}[0]) } keys %icmptypes){
1601 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1602 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1604 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1608 </select></td></tr></table><br><hr>
1610 &Header
::closebox
();
1612 #---TARGET------------------------------------------------------
1613 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw target'});
1615 <table width='100%' border='0'>
1616 <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>Firewall</b></td>
1618 print"<td align='right'><select name='ipfire' style='width:200px;'>";
1619 print "<option value='ALL' $selected{'ipfire'}{'ALL'}>$Lang::tr{'all'} 0.0.0.0</option>";
1620 print "<option value='GREEN' $selected{'ipfire'}{'GREEN'}>$Lang::tr{'green'} $ifaces{'GREEN_ADDRESS'}</option>" if $ifaces{'GREEN_ADDRESS'};
1621 print "<option value='ORANGE' $selected{'ipfire'}{'ORANGE'}>$Lang::tr{'orange'} $ifaces{'ORANGE_ADDRESS'}</option>" if $ifaces{'ORANGE_ADDRESS'};
1622 print "<option value='BLUE' $selected{'ipfire'}{'BLUE'}>$Lang::tr{'blue'} $ifaces{'BLUE_ADDRESS'}</option>" if $ifaces{'BLUE_ADDRESS'};
1623 print "<option value='RED1' $selected{'ipfire'}{'RED1'}>$Lang::tr{'red1'} $ifaces{'RED_ADDRESS'}</option>" if $ifaces{'RED_ADDRESS'};
1625 if (! -z
"${General::swroot}/ethernet/aliases"){
1626 foreach my $alias (sort keys %aliases)
1628 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1633 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
1635 &gen_dd_block
('tgt','grp2');
1637 <b>$Lang::tr{'fwhost attention'}:</b><br>
1638 $Lang::tr{'fwhost macwarn'}<br><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; '></hr><br>
1639 <table width='100%' border='0'>
1640 <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;' >
1642 &General
::readhasharray
("$configsrv", \
%customservice);
1643 foreach my $key (sort { ncmp
($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1645 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1646 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1650 <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;' >
1652 &General
::readhasharray
("$configsrvgrp", \
%customservicegrp);
1654 foreach my $key (sort { ncmp
($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1655 if ($helper ne $customservicegrp{$key}[0]){
1657 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1658 print">$customservicegrp{$key}[0]</option>";
1660 $helper=$customservicegrp{$key}[0];
1664 <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'>
1666 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
1668 if ($_ eq $fwdfwsettings{'TGT_PROT'})
1670 print"<option selected>$_</option>";
1672 print"<option>$_</option>";
1675 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
1677 </select></td><td align='right'><input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18' ></td></tr>
1678 <tr><td colspan='2'></td><td></td><td>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TGT' style='min-width:230px;'>
1680 &General
::readhasharray
("${General::swroot}/fwhosts/icmp-types", \
%icmptypes);
1681 print"<option>All ICMP-Types</option>";
1682 foreach my $key (sort { ncmp
($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
1683 if($fwdfwsettings{'ICMP_TGT'} eq "$icmptypes{$key}[0]"){
1684 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1686 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1695 #---SNAT / DNAT ------------------------------------------------
1696 &Header
::openbox
('100%', 'left', 'NAT');
1698 <table width='100%' border='0'>
1699 <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>
1700 <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>
1702 print"<td width='8%'>IPFire: </td><td width='20%' align='right'><select name='dnat' style='width:140px;'>";
1703 print "<option value='ALL' $selected{'dnat'}{$Lang::tr{'all'}}>$Lang::tr{'all'}</option>";
1704 print "<option value='Default IP' $selected{'dnat'}{'Default IP'}>Default IP</option>";
1705 foreach my $alias (sort keys %aliases)
1707 print "<option value='$alias' $selected{'dnat'}{$alias}>$alias</option>";
1710 $fwdfwsettings{'dnatport'}=~ tr/|/,/;
1711 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>";
1712 print"<tr><td colspan='8'><br></td></tr>";
1714 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>";
1715 print"<td width='8%'>IPFire: </td><td width='20%' align='right'><select name='snat' style='width:140px;'>";
1716 print "<option value='Default IP' $selected{'snat'}{'Default IP'}>Default IP</option>";
1717 foreach my $alias (sort keys %aliases)
1719 print "<option value='$alias' $selected{'snat'}{$alias}>$alias</option>";
1721 foreach my $network (sort keys %defaultNetworks)
1723 next if($defaultNetworks{$network}{'NAME'} eq "RED");
1724 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1725 next if($defaultNetworks{$network}{'NAME'} eq "ALL");
1726 next if($defaultNetworks{$network}{'NAME'} =~ /OpenVPN/i);
1727 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1728 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'nat'}} eq $defaultNetworks{$network}{'NAME'});
1729 print ">$network</option>";
1733 &Header
::closebox
();
1734 #---Activate/logging/remark-------------------------------------
1735 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw additional'});
1737 <table width='100%' border='0'>
1738 <tr><td nowrap>$Lang::tr{'fwdfw rule action'}</td><td><select name='RULE_ACTION'>
1740 foreach ("ACCEPT","DROP","REJECT")
1742 if($fwdfwsettings{'updatefwrule'} eq 'on'){
1743 print"<option value='$_'";
1744 print "selected='selected'" if ($fwdfwsettings{'RULE_ACTION'} eq $_);
1745 print">$Lang::tr{'fwdfw '.$_}</option>";
1747 if($fwdfwsettings{'POLICY'} eq 'MODE2'){
1748 $fwdfwsettings{'RULE_ACTION'} = 'DROP';
1750 if ($_ eq $fwdfwsettings{'RULE_ACTION'})
1752 print"<option value='$_' selected>$Lang::tr{'fwdfw '.$_}</option>";
1754 print"<option value='$_'>$Lang::tr{'fwdfw '.$_}</option>";
1758 print"</select></td></tr>";
1759 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>";
1760 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
1761 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
1762 for (my $count =1; $count <= $sum; $count++){
1763 print"<option value='$count' ";
1764 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
1765 print">$count</option>";
1767 print"</select></td></tr>";
1769 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
1773 </table><table width='100%'>
1774 <tr><td width='1%'><input type='checkbox' name='ACTIVE' value='ON' $checked{'ACTIVE'}{'ON'}></td><td>$Lang::tr{'fwdfw rule activate'}</td></tr>
1775 <tr><td width='1%'><input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'} ></td><td>$Lang::tr{'fwdfw log rule'}</td></tr>
1778 &Header
::closebox
();
1779 #---ADD TIMEFRAME-----------------------------------------------
1780 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw timeframe'});
1782 <table width='70%' border='0'>
1783 <tr><td width='1%'><input type='checkbox' name='TIME' value='ON' $checked{'TIME'}{'ON'}></td><td colspan='4'>$Lang::tr{'fwdfw timeframe'}</td></tr>
1784 <tr><td colspan='7'> </td></tr>
1786 <td align='left'>$Lang::tr{'time'}:</td>
1787 <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>
1788 <td width='15%' align='left'>$Lang::tr{'advproxy from'}</td>
1789 <td width='15%' align='left'>$Lang::tr{'advproxy to'}</td>
1792 <td align='right'></td>
1793 <td width='30%' align='left'>
1794 <input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} />
1795 <input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} />
1796 <input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} />
1797 <input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} />
1798 <input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} />
1799 <input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} />
1800 <input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} />
1802 <td><select name='TIME_FROM'>
1804 for (my $i=0;$i<=23;$i++) {
1805 $i = sprintf("%02s",$i);
1806 for (my $j=0;$j<=45;$j+=15) {
1807 $j = sprintf("%02s",$j);
1808 my $time = $i.":".$j;
1809 print "\t\t\t\t\t<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
1814 <td><select name='TIME_TO'>
1816 for (my $i=0;$i<=23;$i++) {
1817 $i = sprintf("%02s",$i);
1818 for (my $j=0;$j<=45;$j+=15) {
1819 $j = sprintf("%02s",$j);
1820 my $time = $i.":".$j;
1821 print "\t\t\t\t\t<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
1828 #---ACTION------------------------------------------------------
1829 if($fwdfwsettings{'updatefwrule'} ne 'on'){
1831 <table border='0' width='100%'>
1832 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
1833 <input type='hidden' name='config' value='$config' >
1834 <input type='hidden' name='ACTION' value='saverule' >
1835 </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>
1840 <table border='0' width='100%'>
1841 <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'}'>
1842 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
1843 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
1844 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
1845 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
1846 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
1847 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
1848 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
1849 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
1850 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
1851 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
1852 <input type='hidden' name='oldorange' value='$fwdfwsettings{'oldorange'}' />
1853 <input type='hidden' name='oldnat' value='$fwdfwsettings{'oldnat'}' />
1854 <input type='hidden' name='oldruletype' value='$fwdfwsettings{'oldruletype'}' />
1855 <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>
1859 &Header
::closebox
();
1865 &General
::readhasharray
($fwdfwsettings{'config'}, \
%uphash);
1866 foreach my $key (sort keys %uphash){
1867 if ($key eq $fwdfwsettings{'key'}) {
1869 if (exists $uphash{$last}){
1871 foreach my $y (0 .. $#{$uphash{$last}}) {
1872 $tmp{0}[$y] = $uphash{$last}[$y];
1874 #copy active rule to last
1875 foreach my $i (0 .. $#{$uphash{$last}}) {
1876 $uphash{$last}[$i] = $uphash{$key}[$i];
1878 #copy saved rule to actual position
1879 foreach my $x (0 .. $#{$tmp{0}}) {
1880 $uphash{$key}[$x] = $tmp{0}[$x];
1885 &General
::writehasharray
($fwdfwsettings{'config'}, \
%uphash);
1892 &General
::readhasharray
($fwdfwsettings{'config'}, \
%downhash);
1893 foreach my $key (sort keys %downhash){
1894 if ($key eq $fwdfwsettings{'key'}) {
1895 my $next = $key + 1;
1896 if (exists $downhash{$next}){
1898 foreach my $y (0 .. $#{$downhash{$next}}) {
1899 $tmp{0}[$y] = $downhash{$next}[$y];
1901 #copy active rule to next
1902 foreach my $i (0 .. $#{$downhash{$next}}) {
1903 $downhash{$next}[$i] = $downhash{$key}[$i];
1905 #copy saved rule to actual position
1906 foreach my $x (0 .. $#{$tmp{0}}) {
1907 $downhash{$key}[$x] = $tmp{0}[$x];
1912 &General
::writehasharray
($fwdfwsettings{'config'}, \
%downhash);
1917 if (!-f
"${General::swroot}/forward/reread"){
1918 system("touch ${General::swroot}/forward/reread");
1919 system("touch ${General::swroot}/fwhosts/reread");
1924 system("/usr/local/bin/forwardfwctrl");
1925 if ( -f
"${General::swroot}/forward/reread"){
1926 system("rm ${General::swroot}/forward/reread");
1927 system("rm ${General::swroot}/fwhosts/reread");
1934 &General
::readhasharray
("$config", $hash);
1935 if (!$errormessage){
1936 #check if we change a NAT to a FORWARD
1937 if(($fwdfwsettings{'oldruletype'} eq 'NAT_SOURCE' || $fwdfwsettings{'oldruletype'} eq 'NAT_DESTINATION') && $fwdfwsettings{'chain'} eq 'FORWARDFW'){
1938 &changerule
($confignat);
1941 #check if we change a NAT to a INPUT (external access)
1942 elsif(($fwdfwsettings{'oldruletype'} eq 'NAT_SOURCE' || $fwdfwsettings{'oldruletype'} eq 'NAT_DESTINATION') && $fwdfwsettings{'chain'} eq 'INPUTFW'){
1943 &changerule
($confignat);
1946 #check if we change a NAT to a OUTGOING
1947 elsif(($fwdfwsettings{'oldruletype'} eq 'NAT_SOURCE' || $fwdfwsettings{'oldruletype'} eq 'NAT_DESTINATION') && $fwdfwsettings{'chain'} eq 'OUTGOINGFW'){
1948 &changerule
($confignat);
1951 ################################################################
1952 #check if we change an INPUT rule to a NAT
1953 elsif($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && ($fwdfwsettings{'chain'} eq 'NAT_SOURCE' || $fwdfwsettings{'chain'} eq 'NAT_DESTINATION')){
1954 &changerule
($configinput);
1957 #check if we change an INPUT rule to a OUTGOING
1958 elsif($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW' ){
1959 &changerule
($configinput);
1962 #check if we change an INPUT rule to a FORWARD
1963 elsif($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
1964 &changerule
($configinput);
1967 ################################################################
1968 #check if we change an OUTGOING rule to an INPUT
1969 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'INPUTFW' ){
1970 &changerule
($configoutgoing);
1973 #check if we change an OUTGOING rule to a FORWARD
1974 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
1975 &changerule
($configoutgoing);
1978 #check if we change an OUTGOING rule to a NAT
1979 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && ($fwdfwsettings{'chain'} eq 'NAT_SOURCE' || $fwdfwsettings{'chain'} eq 'NAT_DESTINATION')){
1980 &changerule
($configoutgoing);
1983 ################################################################
1984 #check if we change a FORWARD rule to an INPUT
1985 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'INPUTFW'){
1986 &changerule
($configfwdfw);
1989 #check if we change a FORWARD rule to an OUTGOING
1990 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW'){
1991 &changerule
($configfwdfw);
1994 #check if we change a FORWARD rule to an NAT
1995 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && ($fwdfwsettings{'chain'} eq 'NAT_SOURCE' || $fwdfwsettings{'chain'} eq 'NAT_DESTINATION')){
1996 &changerule
($configfwdfw);
1999 if ($fwdfwsettings{'updatefwrule'} ne 'on'){
2000 my $key = &General
::findhasharraykey
($hash);
2001 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
2002 $$hash{$key}[1] = $fwdfwsettings{'chain'};
2003 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
2004 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
2005 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
2006 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
2007 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
2008 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
2009 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
2010 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
2011 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
2012 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
2013 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
2014 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
2015 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
2016 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
2017 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
2018 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
2019 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
2020 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
2021 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
2022 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
2023 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
2024 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
2025 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
2026 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
2027 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
2028 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
2029 if($fwdfwsettings{'USE_NAT'} eq 'ON'){
2030 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
2031 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
2032 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
2033 $$hash{$key}[31] = $fwdfwsettings{'nat'};
2035 &General
::writehasharray
("$config", $hash);
2037 foreach my $key (sort {$a <=> $b} keys %$hash){
2038 if($key eq $fwdfwsettings{'key'}){
2039 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
2040 $$hash{$key}[1] = $fwdfwsettings{'chain'};
2041 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
2042 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
2043 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
2044 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
2045 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
2046 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
2047 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
2048 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
2049 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
2050 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
2051 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
2052 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
2053 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
2054 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
2055 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
2056 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
2057 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
2058 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
2059 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
2060 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
2061 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
2062 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
2063 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
2064 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
2065 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
2066 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
2067 if($fwdfwsettings{'USE_NAT'} eq 'ON'){
2068 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
2069 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
2070 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
2071 $$hash{$key}[31] = $fwdfwsettings{'nat'};
2077 &General
::writehasharray
("$config", $hash);
2078 if($fwdfwsettings{'oldrulenumber'} > $fwdfwsettings{'rulepos'}){
2080 my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'};
2081 for (my $z=0;$z<$val;$z++){
2082 foreach my $key (sort {$a <=> $b} keys %$hash){
2083 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2085 if (exists $$hash{$last}){
2087 foreach my $y (0 .. $#{$$hash{$last}}) {
2088 $tmp{0}[$y] = $$hash{$last}[$y];
2090 #copy active rule to last
2091 foreach my $i (0 .. $#{$$hash{$last}}) {
2092 $$hash{$last}[$i] = $$hash{$key}[$i];
2094 #copy saved rule to actual position
2095 foreach my $x (0 .. $#{$tmp{0}}) {
2096 $$hash{$key}[$x] = $tmp{0}[$x];
2101 $fwdfwsettings{'oldrulenumber'}--;
2103 &General
::writehasharray
("$config", $hash);
2105 }elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
2107 my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
2108 for (my $z=0;$z<$val;$z++){
2109 foreach my $key (sort {$a <=> $b} keys %$hash){
2110 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2111 my $next = $key + 1;
2112 if (exists $$hash{$next}){
2114 foreach my $y (0 .. $#{$$hash{$next}}) {
2115 $tmp{0}[$y] = $$hash{$next}[$y];
2117 #copy active rule to next
2118 foreach my $i (0 .. $#{$$hash{$next}}) {
2119 $$hash{$next}[$i] = $$hash{$key}[$i];
2121 #copy saved rule to actual position
2122 foreach my $x (0 .. $#{$tmp{0}}) {
2123 $$hash{$key}[$x] = $tmp{0}[$x];
2128 $fwdfwsettings{'oldrulenumber'}++;
2130 &General
::writehasharray
("$config", $hash);
2137 # Checks a hostname against RFC1035
2140 # Each part should be at least two characters in length
2141 # but no more than 63 characters
2142 if (length ($remark) < 1 || length ($remark) > 255) {
2144 # Only valid characters are a-z, A-Z, 0-9 and -
2145 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s
]*$/) {
2147 # First character can only be a letter or a digit
2148 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
2150 # Last character can only be a letter or a digit
2151 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
2157 &General
::readhash
("/var/ipfire/ethernet/settings", \
%netsettings);
2158 &viewtablenew
(\
%confignatfw,$confignat,"$Lang::tr{'fwdfw rules'}","Portforward / SNAT" );
2159 &viewtablenew
(\
%configfwdfw,$configfwdfw,"","Forward" );
2160 &viewtablenew
(\
%configoutgoingfw,$configoutgoing,"","Outgoing" );
2161 &viewtablenew
(\
%configinputfw,$configinput,"",$Lang::tr
{'fwdfw xt access'} );
2170 &General
::get_aliases
(\
%aliases);
2171 &General
::readhasharray
("$confighost", \
%customhost);
2172 &General
::readhasharray
("$config", $hash);
2173 &General
::readhasharray
("$configccdnet", \
%ccdnet);
2174 &General
::readhasharray
("$configccdhost", \
%ccdhost);
2176 &Header
::openbox
('100%', 'left',$title);
2184 print"<b>$title1</b><br>";
2185 print"<table width='100%' cellspacing='0' cellpadding='0' border='0'>";
2186 print"<tr><td align='center'><b>#</td><td ></td><td align='center'><b>$Lang::tr{'fwdfw source'}</td><td width='1%'><b>Log</td><td align='center'><b>$Lang::tr{'fwdfw target'}</td><td align='center' width='25'></td><td align='center' colspan='6' width='1%'><b>$Lang::tr{'fwdfw action'}</td></tr>";#<td align='center'><b>$Lang::tr{'fwdfw time'}</td><b>$Lang::tr{'protocol'}</b>
2187 foreach my $key (sort {$a <=> $b} keys %$hash){
2190 #check if vpn hosts/nets have been deleted
2191 if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){
2192 push (@tmpsrc,$$hash{$key}[4]);
2194 if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){
2195 push (@tmpsrc,$$hash{$key}[6]);
2197 foreach my $host (@tmpsrc){
2198 if($$hash{$key}[3] eq 'ipsec_net_src' || $$hash{$key}[5] eq 'ipsec_net_tgt'){
2199 if(&fwlib
::get_ipsec_net_ip
($host,11) eq ''){
2201 &disable_rule
($key);
2204 }elsif($$hash{$key}[3] eq 'ovpn_net_src' || $$hash{$key}[5] eq 'ovpn_net_tgt'){
2205 if(&fwlib
::get_ovpn_net_ip
($host,1) eq ''){
2207 &disable_rule
($key);
2210 }elsif($$hash{$key}[3] eq 'ovpn_n2n_src' || $$hash{$key}[5] eq 'ovpn_n2n_tgt'){
2211 if(&fwlib
::get_ovpn_n2n_ip
($host,27) eq ''){
2213 &disable_rule
($key);
2216 }elsif($$hash{$key}[3] eq 'ovpn_host_src' || $$hash{$key}[5] eq 'ovpn_host_tgt'){
2217 if(&fwlib
::get_ovpn_host_ip
($host,33) eq ''){
2219 &disable_rule
($key);
2224 $$hash{'ACTIVE'}=$$hash{$key}[2];
2226 if($coloryellow eq 'on'){
2227 print"<tr bgcolor='$color{'color14'}' >";
2229 }elsif($coloryellow eq ''){
2231 $color="$color{'color22'}";
2234 $color="$color{'color20'}";
2237 print"<tr bgcolor='$color' >";
2239 <td align='right' width='18'><b>$key  </b></td>
2241 if ($$hash{$key}[0] eq 'ACCEPT'){
2244 $rulecolor=$color{'color17'};
2245 }elsif($$hash{$key}[0] eq 'DROP'){
2248 $rulecolor=$color{'color25'};
2249 }elsif($$hash{$key}[0] eq 'REJECT'){
2252 $rulecolor=$color{'color16'};
2254 print"<td bgcolor='$rulecolor' align='center' width='10'><span title='$tooltip'><b>$ruletype</b></span></td>";
2255 &getcolor
($$hash{$key}[3],$$hash{$key}[4],\
%customhost);
2256 print"<td align='center' width='160' $tdcolor>";
2257 if ($$hash{$key}[3] eq 'std_net_src'){
2258 print &get_name
($$hash{$key}[4]);
2260 print $$hash{$key}[4];
2263 &getsrcport
(\
%$hash,$key);
2264 #Is this a SNAT rule?
2265 if ($$hash{$key}[31] eq 'snat'){
2266 print"<br>-> $$hash{$key}[29]";
2267 if ($$hash{$key}[30] ne ''){
2268 print": $$hash{$key}[30]";
2271 if ($$hash{$key}[17] eq 'ON'){
2272 $log="/images/on.gif";
2274 $log="/images/off.gif";
2278 <form method='post'>
2279 <td align='left' width='25'><input type='image' img src='$log' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw togglelog'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;'/>
2280 <input type='hidden' name='key' value='$key' />
2281 <input type='hidden' name='config' value='$config' />
2282 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw togglelog'}' />
2285 &getcolor
($$hash{$key}[5],$$hash{$key}[6],\
%customhost);
2287 <td align='center' width='160' $tdcolor>
2289 #Is this a DNAT rule?
2290 if ($$hash{$key}[31] eq 'dnat'){
2291 print "IPFire ($$hash{$key}[29])";
2292 if($$hash{$key}[30] ne ''){
2293 $$hash{$key}[30]=~ tr/|/,/;
2294 print": $$hash{$key}[30]";
2298 if ($$hash{$key}[5] eq 'std_net_tgt' || $$hash{$key}[5] eq 'ipfire' && $$hash{$key}[6] eq 'RED' || $$hash{$key}[6] eq 'RED1' || $$hash{$key}[6] eq 'GREEN' || $$hash{$key}[6] eq 'ORANGE' || $$hash{$key}[6] eq 'BLUE' ){
2299 if ($$hash{$key}[6] eq 'RED1')
2301 print $Lang::tr
{'red1'};
2303 print &get_name
($$hash{$key}[6]);
2306 print $$hash{$key}[6];
2309 &gettgtport
(\
%$hash,$key);
2313 if ($$hash{$key}[8] && $$hash{$key}[7] eq 'ON'){#source prot if manual
2314 push (@protocols,$$hash{$key}[8]);
2315 }elsif ($$hash{$key}[12]){ #target prot if manual
2316 push (@protocols,$$hash{$key}[12]);
2317 }elsif($$hash{$key}[14] eq 'cust_srv'){
2318 &get_serviceports
("service",$$hash{$key}[15]);
2319 }elsif($$hash{$key}[14] eq 'cust_srvgrp'){
2320 &get_serviceports
("group",$$hash{$key}[15]);
2322 push (@protocols,$Lang::tr
{'all'});
2324 my $protz=join(",",@protocols);
2325 print"<td align='center'>$protz</td>";
2328 if($$hash{$key}[2] eq 'ON'){
2329 $gif="/images/on.gif"
2332 $gif="/images/off.gif"
2335 <form method='post'>
2336 <td width='25'><input type='image' img src='$gif' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw toggle'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2337 <input type='hidden' name='key' value='$key' />
2338 <input type='hidden' name='config' value='$config' />
2339 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw toggle'}' />
2341 <form method='post'>
2342 <td width='25' ><input type='image' img src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'fwdfw edit'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2343 <input type='hidden' name='key' value='$key' />
2344 <input type='hidden' name='config' value='$config' />
2345 <input type='hidden' name='ACTION' value='editrule' />
2347 <form method='post'>
2348 <td width='25'><input type='image' img src='/images/addblue.gif' alt='$Lang::tr{'fwdfw copy'}' title='$Lang::tr{'fwdfw copy'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2349 <input type='hidden' name='key' value='$key' />
2350 <input type='hidden' name='config' value='$config' />
2351 <input type='hidden' name='ACTION' value='copyrule' />
2353 <form method='post'>
2354 <td width='25' ><input type='image' img src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'fwdfw delete'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2355 <input type='hidden' name='key' value='$key' />
2356 <input type='hidden' name='config' value='$config' />
2357 <input type='hidden' name='ACTION' value='deleterule' />
2360 if (exists $$hash{$key-1}){
2362 <form method='post'>
2363 <td width='25'><input type='image' img src='/images/up.gif' alt='$Lang::tr{'fwdfw moveup'}' title='$Lang::tr{'fwdfw moveup'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2364 <input type='hidden' name='key' value='$key' />
2365 <input type='hidden' name='config' value='$config' />
2366 <input type='hidden' name='ACTION' value='moveup' />
2370 print"<td width='25'><input type='image' img src='/images/up.gif' style='visibility:hidden;'></td>";
2372 if (exists $$hash{$key+1}){
2374 <form method='post'>
2375 <td width='25' ><input type='image' img src='/images/down.gif' alt='$Lang::tr{'fwdfw movedown'}' title='$Lang::tr{'fwdfw movedown'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2376 <input type='hidden' name='key' value='$key' />
2377 <input type='hidden' name='config' value='$config' />
2378 <input type='hidden' name='ACTION' value='movedown' />
2379 </td></form></td></tr>
2382 print"<td width='25'><input type='image' img src='/images/down.gif' style='visibility:hidden;'></td></tr>";
2385 if ($optionsfw{'SHOWREMARK'} eq 'on' && $$hash{$key}[16] ne ''){
2386 print"<tr bgcolor='$color'>";
2387 print"<td> </td><td bgcolor='$rulecolor'></td><td colspan='10'>  $$hash{$key}[16]</td></tr>";
2389 if ($$hash{$key}[18] eq 'ON'){
2391 if ($$hash{$key}[18] eq 'ON'){
2393 if($$hash{$key}[19] ne ''){push (@days,$Lang::tr
{'fwdfw wd_mon'});}
2394 if($$hash{$key}[20] ne ''){push (@days,$Lang::tr
{'fwdfw wd_tue'});}
2395 if($$hash{$key}[21] ne ''){push (@days,$Lang::tr
{'fwdfw wd_wed'});}
2396 if($$hash{$key}[22] ne ''){push (@days,$Lang::tr
{'fwdfw wd_thu'});}
2397 if($$hash{$key}[23] ne ''){push (@days,$Lang::tr
{'fwdfw wd_fri'});}
2398 if($$hash{$key}[24] ne ''){push (@days,$Lang::tr
{'fwdfw wd_sat'});}
2399 if($$hash{$key}[25] ne ''){push (@days,$Lang::tr
{'fwdfw wd_sun'});}
2400 my $weekdays=join(",",@days);
2402 print"<tr bgcolor='$color'>";
2403 print"<td> </td><td bgcolor='$rulecolor'></td><td align='left' colspan='10'>$weekdays   $$hash{$key}[26] - $$hash{$key}[27] </td></tr>";
2407 print"<tr bgcolor='FFFFFF'><td colspan='13' height='1'></td></tr>";
2410 &Header
::closebox
();
2414 if ($optionsfw{'SHOWTABLES'} eq 'on'){
2415 print "<b>$title1</b><br>";
2416 print"<table width='100%' border='0' rules='none'><tr><td height='30' bgcolor=$color{'color22'} align='center'>$Lang::tr{'fwhost empty'}</td></tr></table><br><br>";
2420 &Header
::closebigbox
();
2421 &Header
::closepage
();