]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/forwardfw.cgi
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 ###############################################################################
25 no warnings
'uninitialized';
26 # enable only the following on debugging purpose
28 #use CGI::Carp 'fatalsToBrowser';
30 require '/var/ipfire/general-functions.pl';
31 require "${General::swroot}/lang.pl";
32 require "${General::swroot}/header.pl";
33 require "${General::swroot}/forward/bin/firewall-lib.pl";
35 unless (-d
"${General::swroot}/forward") { system("mkdir ${General::swroot}/forward"); }
36 unless (-e
"${General::swroot}/forward/settings") { system("touch ${General::swroot}/forward/settings"); }
37 unless (-e
"${General::swroot}/forward/config") { system("touch ${General::swroot}/forward/config"); }
38 unless (-e
"${General::swroot}/forward/input") { system("touch ${General::swroot}/forward/input"); }
39 unless (-e
"${General::swroot}/forward/outgoing") { system("touch ${General::swroot}/forward/outgoing"); }
43 my %defaultNetworks=();
47 my %customnetworks=();
49 my %customservicegrp=();
55 my %configoutgoingfw=();
67 my $VERSION='0.9.9.10';
69 my $confignet = "${General::swroot}/fwhosts/customnetworks";
70 my $confighost = "${General::swroot}/fwhosts/customhosts";
71 my $configgrp = "${General::swroot}/fwhosts/customgroups";
72 my $configsrv = "${General::swroot}/fwhosts/customservices";
73 my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
74 my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
75 my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
76 my $configipsec = "${General::swroot}/vpn/config";
77 my $configipsecrw = "${General::swroot}/vpn/settings";
78 my $configfwdfw = "${General::swroot}/forward/config";
79 my $configinput = "${General::swroot}/forward/input";
80 my $configoutgoing = "${General::swroot}/forward/outgoing";
81 my $configovpn = "${General::swroot}/ovpn/settings";
82 my $fwoptions = "${General::swroot}/optionsfw/settings";
83 my $ifacesettings = "${General::swroot}/ethernet/settings";
86 my $ipgrp="${General::swroot}/outgoing/groups";
90 &General
::readhash
("${General::swroot}/forward/settings", \
%fwdfwsettings);
91 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
92 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
93 &General
::readhash
($fwoptions, \
%optionsfw);
94 &General
::readhash
($ifacesettings, \
%ifaces);
95 &General
::readhash
("$configovpn", \
%ovpnsettings);
96 &General
::readhash
("$configipsecrw", \
%ipsecsettings);
97 &General
::readhasharray
("$configipsec", \
%ipsecconf);
98 &Header
::showhttpheaders
();
99 &Header
::getcgihash
(\
%fwdfwsettings);
100 &Header
::openpage
($Lang::tr
{'fwdfw menu'}, 1, '');
101 &Header
::openbigbox
('100%', 'center',$errormessage);
104 if ($fwdfwsettings{'ACTION'} eq 'saverule')
106 &General
::readhasharray
("$configfwdfw", \
%configfwdfw);
107 &General
::readhasharray
("$configinput", \
%configinputfw);
108 &General
::readhasharray
("$configoutgoing", \
%configoutgoingfw);
109 $errormessage=&checksource
;
110 if(!$errormessage){&checktarget
;}
111 if(!$errormessage){&checkrule
;}
113 #check if manual ip (source) is orange network
114 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
115 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
116 if ( &General
::IpInSubnet
($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
121 if( ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' || $checkorange eq 'on') && $fwdfwsettings{'grp2'} eq 'ipfire'){
122 $errormessage.=$Lang::tr
{'fwdfw useless rule'}."<br>";
124 #check if we try to break rules
125 if( $fwdfwsettings{'grp1'} eq 'ipfire_src' && $fwdfwsettings{'grp2'} eq 'ipfire'){
126 $errormessage=$Lang::tr
{'fwdfw err same'};
129 if($fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ORANGE'){
130 $fwdfwsettings{'config'}=$configinput;
131 $fwdfwsettings{'chain'} = 'INPUTFW';
132 my $maxkey=&General
::findhasharraykey
(\
%configinputfw);
133 #check if we have an identical rule already
134 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
135 foreach my $key (sort keys %configinputfw){
136 if ( "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
137 eq "$configinputfw{$key}[0],$configinputfw{$key}[2],$configinputfw{$key}[3],$configinputfw{$key}[4],$configinputfw{$key}[5],$configinputfw{$key}[6],$configinputfw{$key}[7],$configinputfw{$key}[8],$configinputfw{$key}[9],$configinputfw{$key}[10],$configinputfw{$key}[11],$configinputfw{$key}[12],$configinputfw{$key}[13],$configinputfw{$key}[14],$configinputfw{$key}[15],$configinputfw{$key}[17],$configinputfw{$key}[18],$configinputfw{$key}[19],$configinputfw{$key}[20],$configinputfw{$key}[21],$configinputfw{$key}[22],$configinputfw{$key}[23],$configinputfw{$key}[24],$configinputfw{$key}[25],$configinputfw{$key}[26],$configinputfw{$key}[27],$configinputfw{$key}[28],$configinputfw{$key}[29],$configinputfw{$key}[30],$configinputfw{$key}[31]"){
138 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
139 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on'){
141 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark
($fwdfwsettings{'ruleremark'})){
142 $errormessage=$Lang::tr
{'fwdfw err remark'}."<br>";
144 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
145 $fwdfwsettings{'nosave'} = 'on';
150 #check Rulepos on new Rule
151 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
152 $fwdfwsettings{'oldrulenumber'}=$maxkey;
153 foreach my $key (sort keys %configinputfw){
154 if ( "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
155 eq "$configinputfw{$key}[0],$configinputfw{$key}[2],$configinputfw{$key}[3],$configinputfw{$key}[4],$configinputfw{$key}[5],$configinputfw{$key}[6],$configinputfw{$key}[7],$configinputfw{$key}[8],$configinputfw{$key}[9],$configinputfw{$key}[10],$configinputfw{$key}[11],$configinputfw{$key}[12],$configinputfw{$key}[13],$configinputfw{$key}[14],$configinputfw{$key}[15],$configinputfw{$key}[17],$configinputfw{$key}[18],$configinputfw{$key}[19],$configinputfw{$key}[20],$configinputfw{$key}[21],$configinputfw{$key}[22],$configinputfw{$key}[23],$configinputfw{$key}[24],$configinputfw{$key}[25],$configinputfw{$key}[26],$configinputfw{$key}[27],$configinputfw{$key}[28],$configinputfw{$key}[29],$configinputfw{$key}[30],$configinputfw{$key}[31]"){
156 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
160 #check if we just close a rule
161 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'}) {
162 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
164 $fwdfwsettings{'nosave2'} = 'on';
167 &checkcounter
($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
168 if ($fwdfwsettings{'nobase'} ne 'on'){
169 &checkcounter
($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
171 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
172 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
173 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
174 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
175 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
176 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
178 if($fwdfwsettings{'nosave2'} ne 'on'){
179 &saverule
(\
%configinputfw,$configinput);
181 }elsif($fwdfwsettings{'grp1'} eq 'ipfire_src' ){
183 $fwdfwsettings{'config'}=$configoutgoing;
184 $fwdfwsettings{'chain'} = 'OUTGOINGFW';
185 my $maxkey=&General
::findhasharraykey
(\
%configoutgoingfw);
186 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
187 foreach my $key (sort keys %configoutgoingfw){
188 if ( "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
189 eq "$configoutgoingfw{$key}[0],$configoutgoingfw{$key}[2],$configoutgoingfw{$key}[3],$configoutgoingfw{$key}[4],$configoutgoingfw{$key}[5],$configoutgoingfw{$key}[6],$configoutgoingfw{$key}[7],$configoutgoingfw{$key}[8],$configoutgoingfw{$key}[9],$configoutgoingfw{$key}[10],$configoutgoingfw{$key}[11],$configoutgoingfw{$key}[12],$configoutgoingfw{$key}[13],$configoutgoingfw{$key}[14],$configoutgoingfw{$key}[15],$configoutgoingfw{$key}[17],$configoutgoingfw{$key}[18],$configoutgoingfw{$key}[19],$configoutgoingfw{$key}[20],$configoutgoingfw{$key}[21],$configoutgoingfw{$key}[22],$configoutgoingfw{$key}[23],$configoutgoingfw{$key}[24],$configoutgoingfw{$key}[25],$configoutgoingfw{$key}[26],$configoutgoingfw{$key}[27],$configoutgoingfw{$key}[28],$configoutgoingfw{$key}[29],$configoutgoingfw{$key}[30],$configoutgoingfw{$key}[31]"){
190 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
191 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on'){
193 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark
($fwdfwsettings{'ruleremark'})){
194 $errormessage=$Lang::tr
{'fwdfw err remark'}."<br>";
196 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
197 $fwdfwsettings{'nosave'} = 'on';
202 #check Rulepos on new Rule
203 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
204 print"CHECK OUTGOING DOPPELTE REGEL<br>";
205 $fwdfwsettings{'oldrulenumber'}=$maxkey;
206 foreach my $key (sort keys %configoutgoingfw){
207 if ( "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
208 eq "$configoutgoingfw{$key}[0],$configoutgoingfw{$key}[2],$configoutgoingfw{$key}[3],$configoutgoingfw{$key}[4],$configoutgoingfw{$key}[5],$configoutgoingfw{$key}[6],$configoutgoingfw{$key}[7],$configoutgoingfw{$key}[8],$configoutgoingfw{$key}[9],$configoutgoingfw{$key}[10],$configoutgoingfw{$key}[11],$configoutgoingfw{$key}[12],$configoutgoingfw{$key}[13],$configoutgoingfw{$key}[14],$configoutgoingfw{$key}[15],$configoutgoingfw{$key}[17],$configoutgoingfw{$key}[18],$configoutgoingfw{$key}[19],$configoutgoingfw{$key}[20],$configoutgoingfw{$key}[21],$configoutgoingfw{$key}[22],$configoutgoingfw{$key}[23],$configoutgoingfw{$key}[24],$configoutgoingfw{$key}[25],$configoutgoingfw{$key}[26],$configoutgoingfw{$key}[27],$configoutgoingfw{$key}[28],$configoutgoingfw{$key}[29],$configoutgoingfw{$key}[30],$configoutgoingfw{$key}[31]"){
209 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
213 #check if we just close a rule
214 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'}) {
215 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
216 $fwdfwsettings{'nosave2'} = 'on';
221 &checkcounter
($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
222 &checkcounter
($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
223 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
224 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
225 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
226 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
227 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
228 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
230 if ($fwdfwsettings{'nobase'} eq 'on'){
231 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
233 if ($fwdfwsettings{'nosave2'} ne 'on'){
234 &saverule
(\
%configoutgoingfw,$configoutgoing);
238 $fwdfwsettings{'config'}=$configfwdfw;
239 $fwdfwsettings{'chain'} = 'FORWARDFW';
240 my $maxkey=&General
::findhasharraykey
(\
%configfwdfw);
241 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
242 #check if we have an identical rule already
243 foreach my $key (sort keys %configfwdfw){
244 if ( "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
245 eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[18],$configfwdfw{$key}[19],$configfwdfw{$key}[20],$configfwdfw{$key}[21],$configfwdfw{$key}[22],$configfwdfw{$key}[23],$configfwdfw{$key}[24],$configfwdfw{$key}[25],$configfwdfw{$key}[26],$configfwdfw{$key}[27],$configfwdfw{$key}[28],$configfwdfw{$key}[29],$configfwdfw{$key}[30],$configfwdfw{$key}[31]"){
246 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
247 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' ){
249 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark
($fwdfwsettings{'ruleremark'})){
250 $errormessage=$Lang::tr
{'fwdfw err remark'}."<br>";
252 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
253 $fwdfwsettings{'nosave'} = 'on';
258 #check Rulepos on new Rule
259 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
260 $fwdfwsettings{'oldrulenumber'}=$maxkey;
261 foreach my $key (sort keys %configfwdfw){
262 if ( "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
263 eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[18],$configfwdfw{$key}[19],$configfwdfw{$key}[20],$configfwdfw{$key}[21],$configfwdfw{$key}[22],$configfwdfw{$key}[23],$configfwdfw{$key}[24],$configfwdfw{$key}[25],$configfwdfw{$key}[26],$configfwdfw{$key}[27],$configfwdfw{$key}[28],$configfwdfw{$key}[29],$configfwdfw{$key}[30],$configfwdfw{$key}[31]"){
264 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
268 #check if we just close a rule
269 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'}) {
270 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
271 $fwdfwsettings{'nosave2'} = 'on';
276 &checkcounter
($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
277 &checkcounter
($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
278 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
279 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
280 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
281 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
282 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
283 &checkcounter
($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
285 if ($fwdfwsettings{'nobase'} eq 'on'){
286 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
288 if ($fwdfwsettings{'nosave2'} ne 'on'){
289 &saverule
(\
%configfwdfw,$configfwdfw);
295 if($fwdfwsettings{'nosave2'} ne 'on'){
301 if ($fwdfwsettings{'ACTION'} eq $Lang::tr
{'fwdfw newrule'})
305 if ($fwdfwsettings{'ACTION'} eq $Lang::tr
{'fwdfw toggle'})
308 &General
::readhasharray
($fwdfwsettings{'config'}, \
%togglehash);
309 foreach my $key (sort keys %togglehash){
310 if ($key eq $fwdfwsettings{'key'}){
311 if ($togglehash{$key}[2] eq 'ON'){$togglehash{$key}[2]='';}else{$togglehash{$key}[2]='ON';}
314 &General
::writehasharray
($fwdfwsettings{'config'}, \
%togglehash);
318 if ($fwdfwsettings{'ACTION'} eq $Lang::tr
{'fwdfw togglelog'})
321 &General
::readhasharray
($fwdfwsettings{'config'}, \
%togglehash);
322 foreach my $key (sort keys %togglehash){
323 if ($key eq $fwdfwsettings{'key'}){
324 if ($togglehash{$key}[17] eq 'ON'){$togglehash{$key}[17]='';}else{$togglehash{$key}[17]='ON';}
327 &General
::writehasharray
($fwdfwsettings{'config'}, \
%togglehash);
331 if ($fwdfwsettings{'ACTION'} eq $Lang::tr
{'fwdfw reread'})
336 if ($fwdfwsettings{'ACTION'} eq 'editrule')
338 $fwdfwsettings{'updatefwrule'}='on';
341 if ($fwdfwsettings{'ACTION'} eq 'deleterule')
345 if ($fwdfwsettings{'ACTION'} eq 'moveup')
350 if ($fwdfwsettings{'ACTION'} eq 'movedown')
355 if ($fwdfwsettings{'ACTION'} eq 'copyrule')
357 $fwdfwsettings{'copyfwrule'}='on';
360 if ($fwdfwsettings{'ACTION'} eq '')
368 if (-f
"${General::swroot}/forward/reread"){
369 print "<table border='1' rules='groups' bgcolor='lightgreen' width='100%'><form method='post'><td><div style='font-size:11pt; font-weight: bold;vertical-align: middle; '><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-face: Comic Sans MS; color: green; font-weight: bold; font-size: 14pt;'>    $Lang::tr{'fwhost reread'}</div</td></tr></table></form><br>";
371 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw menu'});
372 print "<form method='post'>";
373 print "<table border='0'>";
374 print "<tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'></td>";
375 print"</tr></table></form><hr>";
384 print "<br><br><div align='right'><font size='1' color='grey'>Version: $VERSION</font></div>";
389 $fwdfwsettings{'updatefwrule'}='';
390 $fwdfwsettings{'config'}=$oldchain;
391 $fwdfwsettings{'nobase'}='on';
393 &checkcounter
(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
394 &checkcounter
(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
399 #check ip-address if manual
400 if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){
401 #check if ip with subnet
402 if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?
)$/) {
403 ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'});
404 $subnet = &General
::iporsubtocidr
($subnet);
405 $fwdfwsettings{'isip'}='on';
408 if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
409 $ip=$fwdfwsettings{'src_addr'};
411 $fwdfwsettings{'isip'}='on';
414 if ($fwdfwsettings{'isip'} ne 'on'){
415 if (&General
::validmac
($fwdfwsettings{'src_addr'})){$fwdfwsettings{'ismac'}='on';}
417 if ($fwdfwsettings{'isip'} eq 'on'){
418 ##check if ip is valid
419 if (! &General
::validip
($ip)){
420 $errormessage.=$Lang::tr
{'fwdfw err src_addr'}."<br>";
421 return $errormessage;
423 #check and form valid IP
424 $ip=&General
::ip2dec
($ip);
425 $ip=&General
::dec2ip
($ip);
426 #check if net or broadcast
427 my @tmp= split (/\./,$ip);
428 if (($tmp[3] eq "0") || ($tmp[3] eq "255"))
430 $errormessage=$Lang::tr
{'fwhost err hostip'}."<br>";
431 return $errormessage;
433 $fwdfwsettings{'src_addr'}="$ip/$subnet";
434 if(!&General
::validipandmask
($fwdfwsettings{'src_addr'})){
435 $errormessage.=$Lang::tr
{'fwdfw err src_addr'}."<br>";
436 return $errormessage;
439 if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){
440 $errormessage.=$Lang::tr
{'fwdfw err src_addr'}."<br>";
441 return $errormessage;
443 }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
444 $errormessage.=$Lang::tr
{'fwdfw err nosrcip'};
445 return $errormessage;
449 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr
{'fwdfw err nosrc'}."<br>";}
451 if ($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ICMP'){
452 $fwdfwsettings{'SRC_PORT'}='';
453 &General
::readhasharray
("${General::swroot}/fwhosts/icmp-types", \
%icmptypes);
454 foreach my $key (keys %icmptypes){
455 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){
456 $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]";
459 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'GRE'){
460 $fwdfwsettings{'SRC_PORT'}='';
461 $fwdfwsettings{'ICMP_TYPES'}='';
462 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ESP'){
463 $fwdfwsettings{'SRC_PORT'}='';
464 $fwdfwsettings{'ICMP_TYPES'}='';
465 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'AH'){
466 $fwdfwsettings{'SRC_PORT'}='';
467 $fwdfwsettings{'ICMP_TYPES'}='';
468 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} ne 'ICMP'){
469 $fwdfwsettings{'ICMP_TYPES'}='';
471 $fwdfwsettings{'ICMP_TYPES'}='';
472 $fwdfwsettings{'SRC_PORT'}='';
473 $fwdfwsettings{'PROT'}='';
476 if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){
477 my @parts=split(",",$fwdfwsettings{'SRC_PORT'});
481 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
483 #change dashes with :
486 push(@values,"1:65535");
489 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
490 push(@values,"1:$2");
493 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/ ) {
494 push(@values,"$1:65535");
497 $errormessage .= &General
::validportrange
($_, 'destination');
502 if (&General
::validport
($_)){
509 $fwdfwsettings{'SRC_PORT'}=join("|",@values);
511 return $errormessage;
516 &General
::readhasharray
("$configsrv", \
%customservice);
517 #check DNAT settings (has to be single Host and single Port or portrange)
518 if ($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat'){
519 if($fwdfwsettings{'grp2'} eq 'tgt_addr' || $fwdfwsettings{'grp2'} eq 'cust_host_tgt' || $fwdfwsettings{'grp2'} eq 'ovpn_host_tgt'){
520 if ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'dnatport'} eq ''){
521 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
522 return $errormessage;
524 #check if manual ip is a single Host (if set)
525 if ($fwdfwsettings{'grp2'} eq 'tgt_addr'){
526 my @tmp= split (/\./,$fwdfwsettings{$fwdfwsettings{'grp2'}});
527 my @tmp1= split ("/",$tmp[3]);
528 if (($tmp1[0] eq "0") || ($tmp1[0] eq "255"))
530 $errormessage=$Lang::tr
{'fwdfw dnat error'}."<br>";
531 return $errormessage;
534 #check if Port is a single Port or portrange
535 if ($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
536 if(($fwdfwsettings{'TGT_PROT'} ne 'TCP'|| $fwdfwsettings{'TGT_PROT'} ne 'UDP') && $fwdfwsettings{'TGT_PORT'} eq ''){
537 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
538 return $errormessage;
540 if (($fwdfwsettings{'TGT_PROT'} eq 'TCP'|| $fwdfwsettings{'TGT_PROT'} eq 'UDP') && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport
($fwdfwsettings{'TGT_PORT'})){
541 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
542 return $errormessage;
546 $errormessage=$Lang::tr
{'fwdfw dnat error'}."<br>";
547 return $errormessage;
550 if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
551 #check if ip with subnet
552 if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?
)$/) {
553 ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
554 $subnet = &General
::iporsubtocidr
($subnet);
557 if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
558 $ip=$fwdfwsettings{'tgt_addr'};
561 #check if ip is valid
562 if (! &General
::validip
($ip)){
563 $errormessage.=$Lang::tr
{'fwdfw err tgt_addr'}."<br>";
564 return $errormessage;
566 #check and form valid IP
567 $ip=&General
::ip2dec
($ip);
568 $ip=&General
::dec2ip
($ip);
569 $fwdfwsettings{'tgt_addr'}="$ip/$subnet";
570 if(!&General
::validipandmask
($fwdfwsettings{'tgt_addr'})){
571 $errormessage.=$Lang::tr
{'fwdfw err tgt_addr'}."<br>";
572 return $errormessage;
574 }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
575 $errormessage.=$Lang::tr
{'fwdfw err notgtip'};
576 return $errormessage;
579 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr
{'fwdfw err notgt'}."<br>";}
581 if ($fwdfwsettings{'USESRV'} eq 'ON'){
582 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
583 $fwdfwsettings{'TGT_PROT'}='';
584 $fwdfwsettings{'ICMP_TGT'}='';
586 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
587 $fwdfwsettings{'TGT_PROT'}='';
588 $fwdfwsettings{'ICMP_TGT'}='';
589 #check target service
590 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){
591 $errormessage.=$Lang::tr
{'fwdfw err tgt_grp'};
594 if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
595 if ($fwdfwsettings{'TGT_PROT'} eq 'TCP' || $fwdfwsettings{'TGT_PROT'} eq 'UDP'){
596 if ($fwdfwsettings{'TGT_PORT'} ne ''){
597 if ($fwdfwsettings{'TGT_PORT'} =~ "," && $fwdfwsettings{'USE_NAT'} && $fwdfwsettings{'nat'} eq 'dnat') {
598 $errormessage=$Lang::tr
{'fwdfw dnat porterr'}."<br>";
599 return $errormessage;
601 my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
605 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
607 #change dashes with :
610 push(@values,"1:65535");
613 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
614 push(@values,"1:$2");
617 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
618 push(@values,"$1:65535");
621 $errormessage .= &General
::validportrange
($_, 'destination');
626 if (&General
::validport
($_)){
633 $fwdfwsettings{'TGT_PORT'}=join("|",@values);
635 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'GRE'){
636 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
637 $fwdfwsettings{'TGT_PORT'} = '';
638 $fwdfwsettings{'ICMP_TGT'} = '';
639 }elsif($fwdfwsettings{'TGT_PROT'} eq 'ESP'){
640 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
641 $fwdfwsettings{'TGT_PORT'} = '';
642 $fwdfwsettings{'ICMP_TGT'}='';
643 }elsif($fwdfwsettings{'TGT_PROT'} eq 'AH'){
644 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
645 $fwdfwsettings{'TGT_PORT'} = '';
646 $fwdfwsettings{'ICMP_TGT'}='';
647 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'ICMP'){
648 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
649 $fwdfwsettings{'TGT_PORT'} = '';
650 &General
::readhasharray
("${General::swroot}/fwhosts/icmp-types", \
%icmptypes);
651 foreach my $key (keys %icmptypes){
653 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwdfwsettings{'ICMP_TGT'}){
654 $fwdfwsettings{'ICMP_TGT'}=$icmptypes{$key}[0];
661 if ($fwdfwsettings{'USESRV'} ne 'ON'){
662 $fwdfwsettings{'grp3'}='';
663 $fwdfwsettings{$fwdfwsettings{'grp3'}}='';
664 $fwdfwsettings{'ICMP_TGT'}='';
667 if($fwdfwsettings{'TIME'} eq 'ON'){
668 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 ''){
669 $errormessage=$Lang::tr
{'fwdfw err time'};
670 return $errormessage;
673 return $errormessage;
678 if($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
679 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\-(\d+)$/) {
680 $fwdfwsettings{'dnatport'} =~ tr/-/:/;
681 if ($fwdfwsettings{'dnatport'} eq "*") {
682 $fwdfwsettings{'dnatport'}="1:65535";
684 if ($fwdfwsettings{'dnatport'} =~ /^(\D)\:(\d+)$/) {
685 $fwdfwsettings{'dnatport'} = "1:$2";
687 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\:(\D)$/) {
688 $fwdfwsettings{'dnatport'} ="$1:65535";
693 if ($val =~ "," || $val>65536 || $val<0){
700 #check valid port for NAT
701 if($fwdfwsettings{'USE_NAT'} eq 'ON'){
702 #if no port is given in nat area, take target host port
703 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$fwdfwsettings{'TGT_PORT'};}
704 #check if port given in nat area is a single valid port or portrange
705 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport
($fwdfwsettings{'dnatport'})){
706 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
707 }elsif($fwdfwsettings{'USESRV'} eq 'ON' && $fwdfwsettings{'grp3'} eq 'cust_srv'){
709 #get servcie Protocol and Port
710 foreach my $key (sort keys %customservice){
711 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]){
712 if ($customservice{$key}[2] ne 'TCP' && $customservice{$key}[2] ne 'UDP'){
713 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
715 $custsrvport= $customservice{$key}[1];
718 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$custsrvport;}
720 #check if DNAT port is multiple
721 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
722 my @parts=split(",",$fwdfwsettings{'dnatport'});
726 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
728 #change dashes with :
731 push(@values,"1:65535");
734 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
735 push(@values,"1:$2");
738 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
739 push(@values,"$1:65535");
742 $errormessage .= &General
::validportrange
($_, 'destination');
747 if (&General
::validport
($_)){
754 $fwdfwsettings{'dnatport'}=join("|",@values);
758 if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark
($fwdfwsettings{'ruleremark'})){
759 $errormessage.=$Lang::tr
{'fwdfw err remark'}."<br>";
761 #check if source and target identical
762 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL'){
763 $errormessage=$Lang::tr
{'fwdfw err same'};
764 return $errormessage;
766 #get source and targetip address if possible
767 my ($sip,$scidr,$tip,$tcidr);
768 ($sip,$scidr)=&get_ip
("src","grp1");
769 ($tip,$tcidr)=&get_ip
("tgt","grp2");
770 #check same iprange in source and target
771 if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){
772 my $networkip1=&General
::getnetworkip
($sip,$scidr);
773 my $networkip2=&General
::getnetworkip
($tip,$tcidr);
774 if ($scidr gt $tcidr){
775 if ( &General
::IpInSubnet
($networkip1,$tip,&General
::iporsubtodec
($tcidr))){
776 $errormessage.=$Lang::tr
{'fwdfw err samesub'};
778 }elsif($scidr eq $tcidr && $scidr eq '32'){
779 my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1);
780 my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2);
781 if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){
782 $hint=$Lang::tr
{'fwdfw hint ip1'}."<br>";
783 $hint.=$Lang::tr
{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>";
786 if ( &General
::IpInSubnet
($networkip2,$sip,&General
::iporsubtodec
($scidr)) ){
787 $errormessage.=$Lang::tr
{'fwdfw err samesub'};
791 #check source and destination protocol if manual
792 if( $fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'USESRV'} eq 'ON'){
793 if($fwdfwsettings{'PROT'} ne $fwdfwsettings{'TGT_PROT'} && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
794 $errormessage.=$Lang::tr
{'fwdfw err prot'};
796 #check source and destination protocol if source manual and dest servicegrp
797 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
798 foreach my $key (sort keys %customservice){
799 if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){
800 if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){
801 $errormessage.=$Lang::tr
{'fwdfw err prot'};
808 if( $fwdfwsettings{'USE_SRC_PORT'} ne 'ON' && $fwdfwsettings{'USESRV'} ne 'ON'){
809 $fwdfwsettings{'PROT'}='';
810 $fwdfwsettings{'TGT_PROT'}='';
815 my ($base1,$val1,$base2,$val2) = @_;
817 if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){
818 &dec_counter
($confignet,\
%customnetwork,$val1);
819 }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){
820 &dec_counter
($confighost,\
%customhost,$val1);
821 }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){
822 &dec_counter
($configgrp,\
%customgrp,$val1);
823 }elsif($base1 eq 'cust_srv'){
824 &dec_counter
($configsrv,\
%customservice,$val1);
825 }elsif($base1 eq 'cust_srvgrp'){
826 &dec_counter
($configsrvgrp,\
%customservicegrp,$val1);
829 if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){
830 &inc_counter
($confignet,\
%customnetwork,$val2);
831 }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){
832 &inc_counter
($confighost,\
%customhost,$val2);
833 }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){
834 &inc_counter
($configgrp,\
%customgrp,$val2);
835 }elsif($base2 eq 'cust_srv'){
836 &inc_counter
($configsrv,\
%customservice,$val2);
837 }elsif($base2 eq 'cust_srvgrp'){
838 &inc_counter
($configsrvgrp,\
%customservicegrp,$val2);
844 #Test if manual IP is part of static OpenVPN networks
845 &General
::readhasharray
("$configccdnet", \
%ccdnet);
846 foreach my $key (sort keys %ccdnet){
847 my ($vpnip,$vpnsubnet) = split ("/",$ccdnet{$key}[1]);
848 my $sub=&General
::iporsubtodec
($vpnsubnet);
849 if (&General
::IpInSubnet
($ip,$vpnip,$sub)){
853 # A Test if manual ip is part of dynamic openvpn subnet is made in getcolor
854 # because if one creates a custom host with the ip, we need to check the color there!
855 # It does not make sense to check this here
857 # Test if manual IP is part of an OpenVPN N2N subnet does also not make sense here
858 # Is also checked in getcolor
860 # Test if manual ip is part of an IPsec Network is also checked in getcolor
870 &General
::readhasharray
($fwdfwsettings{'config'}, \
%delhash);
871 foreach my $key (sort {$a <=> $b} keys %delhash){
872 if ($key == $fwdfwsettings{'key'}){
873 #check hosts/net and groups
874 &checkcounter
($delhash{$key}[3],$delhash{$key}[4],,);
875 &checkcounter
($delhash{$key}[5],$delhash{$key}[6],,);
876 #check services and groups
877 if ($delhash{$key}[11] eq 'ON'){
878 &checkcounter
($delhash{$key}[14],$delhash{$key}[15],,);
881 if ($key >= $fwdfwsettings{'key'}) {
883 if (exists $delhash{$next}) {
884 foreach my $i (0 .. $#{$delhash{$next}}) {
885 $delhash{$key}[$i] = $delhash{$next}[$i];
890 # Remove the very last entry.
891 my $last_key = (sort {$a <=> $b} keys %delhash)[-1];
892 delete $delhash{$last_key};
894 &General
::writehasharray
($fwdfwsettings{'config'}, \
%delhash);
897 if($fwdfwsettings{'nobase'} ne 'on'){
904 &General
::readhasharray
("$configfwdfw", \
%configfwdfw);
905 foreach my $key (sort keys %configfwdfw){
907 if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';}
910 &General
::writehasharray
("$configfwdfw", \
%configfwdfw);
919 &General
::readhasharray
($config, \
%hash);
920 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
921 if($hash{$key}[0] eq $val){
922 $pos=$#{$hash{$key}};
923 $hash{$key}[$pos] = $hash{$key}[$pos]-1;
926 &General
::writehasharray
($config, \
%hash);
931 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
932 print "<class name='base'>$errormessage\n";
933 print " </class>\n";
943 foreach my $key (sort { ncmp
($hash{$a}[0],$hash{$b}[0]) } keys %hash){
944 if($hash{$key}[0] eq $val){
945 print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>";
947 print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>";
957 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
958 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
959 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
960 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
961 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
962 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
963 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
964 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
965 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
966 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
967 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
968 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
969 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
970 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
971 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
972 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
973 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
974 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
975 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
977 <table width='100%' border='0'>
978 <tr><td width='50%' valign='top'>
979 <table width='100%' border='0'>
980 <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;'>
982 foreach my $network (sort keys %defaultNetworks)
984 next if($defaultNetworks{$network}{'NAME'} eq "RED" && $srctgt eq 'src');
985 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
986 print "<option value='$defaultNetworks{$network}{'NAME'}'";
987 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $defaultNetworks{$network}{'NAME'});
988 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
989 my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK";
990 my $defsub1=&General
::subtocidr
($ifaces{$defsub});
991 $ifaces{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED');
992 if ($ifaces{$defnet}){
993 print ">$network ($ifaces{$defnet}/$defsub1)</option>";
995 print ">$network</option>";
998 print"</select></td></tr>";
1000 if (! -z
$confignet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1001 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;'>";
1002 &fillselect
(\
%customnetwork,$fwdfwsettings{$fwdfwsettings{$grp}});
1003 print"</select></td>";
1006 if (! -z
$confighost || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1007 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;'>";
1008 &fillselect
(\
%customhost,$fwdfwsettings{$fwdfwsettings{$grp}});
1009 print"</select></td>";
1012 if (! -z
$configgrp || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1013 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;'>";
1014 foreach my $key (sort { ncmp
($customgrp{$a}[0],$customgrp{$b}[0]) } keys %customgrp) {
1015 if($helper ne $customgrp{$key}[0]){
1017 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $customgrp{$key}[0]);
1018 print ">$customgrp{$key}[0]</option>";
1020 $helper=$customgrp{$key}[0];
1022 print"</select></td>";
1024 #End left table. start right table (vpn)
1025 print"</tr></table></td><td valign='top'><table width='100%' border='0'><tr>";
1027 if( ! -z
$configccdnet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1028 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;'>";
1029 &fillselect
(\
%ccdnet,$fwdfwsettings{$fwdfwsettings{$grp}});
1030 print"</select></td></tr>";
1033 foreach my $key (sort { ncmp
($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost){
1034 if ($ccdhost{$key}[33] ne '' ){
1035 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 '');
1037 print "<option value='$ccdhost{$key}[1]'";
1038 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1039 print ">$ccdhost{$key}[1]</option>";
1042 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1043 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>" ;
1045 if ($show eq '1'){$show='';print"</select></td></tr>";}
1047 foreach my $key (sort { ncmp
($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost){
1048 if ($ccdhost{$key}[3] eq 'net'){
1049 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 '');
1051 print "<option value='$ccdhost{$key}[1]'";
1052 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1053 print ">$ccdhost{$key}[1]</option>";
1056 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1057 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>" ;
1059 if ($show eq '1'){$show='';print"</select></td></tr>";}
1061 foreach my $key (sort { ncmp
($ipsecconf{$a}[1],$ipsecconf{$b}[1]) } keys %ipsecconf) {
1062 if ($ipsecconf{$key}[3] eq 'net' || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1063 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 '');
1066 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ipsecconf{$key}[1]);
1067 print ">$ipsecconf{$key}[1]</option>";
1070 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1071 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>";
1073 if ($show eq '1'){$show='';print"</select></td></tr>";}
1075 print"</tr></table>";
1076 print"</td></tr></table><br>";
1084 &General
::readhash
("/var/ipfire/ethernet/settings", \
%netsettings);
1085 if ($fwdfwsettings{$grp} ne $Lang::tr
{'fwhost any'}){
1086 if ($fwdfwsettings{$grp} eq $val.'_addr'){
1087 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
1088 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
1089 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
1090 $a=$netsettings{'GREEN_NETADDRESS'};
1091 $b=&General
::iporsubtocidr
($netsettings{'GREEN_NETMASK'});
1092 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
1093 $a=$netsettings{'ORANGE_NETADDRESS'};
1094 $b=&General
::iporsubtocidr
($netsettings{'ORANGE_NETMASK'});
1095 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
1096 $a=$netsettings{'BLUE_NETADDRESS'};
1097 $b=&General
::iporsubtocidr
($netsettings{'BLUE_NETMASK'});
1098 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
1099 &General
::readhash
("$configovpn",\
%ovpnsettings);
1100 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
1101 $b=&General
::iporsubtocidr
($b);
1103 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
1104 &General
::readhasharray
("$confignet", \
%customnetwork);
1105 foreach my $key (keys %customnetwork){
1106 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1107 $a=$customnetwork{$key}[1];
1108 $b=&General
::iporsubtocidr
($customnetwork{$key}[2]);
1111 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
1112 &General
::readhasharray
("$confighost", \
%customhost);
1113 foreach my $key (keys %customhost){
1114 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1115 if ($customhost{$key}[1] eq 'ip'){
1116 ($a,$b)=split (/\//,$customhost{$key}[2]);
1117 $b=&General
::iporsubtocidr
($b);
1119 if ($grp eq 'grp2'){
1120 $errormessage=$Lang::tr
{'fwdfw err tgt_mac'};
1132 &General
::setup_default_networks
(\
%defaultNetworks);
1133 foreach my $network (sort keys %defaultNetworks)
1135 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1140 my %hash=%{(shift)};
1142 if($hash{$key}[7] eq 'ON' && $hash{$key}[8] ne '' && $hash{$key}[10]){
1143 $hash{$key}[10]=~ s/\|/,/g;
1144 print": $hash{$key}[10]";
1145 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
1146 print": <br>$hash{$key}[9] ";
1151 my %hash=%{(shift)};
1155 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1156 if($hash{$key}[14] eq 'cust_srv'){
1157 &General
::readhasharray
("$configsrv", \
%customservice);
1158 foreach my $i (sort keys %customservice){
1159 if($customservice{$i}[0] eq $hash{$key}[15]){
1160 $service = $customservice{$i}[0];
1163 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
1164 $service=$hash{$key}[15];
1165 }elsif($hash{$key}[14] eq 'TGT_PORT'){
1166 $hash{$key}[15]=~ s/\|/,/g;
1167 $service=$hash{$key}[15];
1172 }elsif($hash{$key}[11] eq 'ON' && $hash{$key}[12] eq 'ICMP'){
1173 print":<br>$hash{$key}[13]";
1176 sub get_serviceports
1180 &General
::readhasharray
("$configsrv", \
%customservice);
1181 &General
::readhasharray
("$configsrvgrp", \
%customservicegrp);
1186 if($type eq 'service'){
1187 foreach my $key (sort { ncmp
($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1188 if ($customservice{$key}[0] eq $name){
1189 push (@protocols,$customservice{$key}[2]);
1192 }elsif($type eq 'group'){
1193 foreach my $key (sort { ncmp
($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1194 if ($customservicegrp{$key}[0] eq $name){
1195 foreach my $key1 (sort { ncmp
($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1196 if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
1197 if($customservice{$key1}[2] eq 'TCP'){
1199 }elsif($customservice{$key1}[2] eq 'ICMP'){
1201 }elsif($customservice{$key1}[2] eq 'UDP'){
1209 if($tcp && $udp && $icmp){
1210 push (@protocols,"All");
1214 push (@protocols,"TCP");
1217 push (@protocols,"UDP");
1220 push (@protocols,"ICMP");
1229 if($optionsfw{'SHOWCOLORS'} eq 'on'){
1231 if ($val eq 'GREEN'){
1232 $tdcolor="style='border: 1px solid $Header::colourgreen;'";
1234 }elsif ($val eq 'ORANGE'){
1235 $tdcolor="style='border: 1px solid $Header::colourorange;'";
1237 }elsif ($val eq 'BLUE'){
1238 $tdcolor="style='border: 1px solid $Header::colourblue;'";
1240 }elsif ($val eq 'RED' ||$val eq 'RED1' ){
1241 $tdcolor="style='border: 1px solid $Header::colourred;'";
1243 }elsif ($val eq 'IPFire' ){
1244 $tdcolor="style='border: 1px solid $Header::colourred;'";
1246 }elsif($val =~ /^(.*?)\/(.*?
)$/){
1247 my ($sip,$scidr) = split ("/",$val);
1248 if ( &General
::IpInSubnet
($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1249 $tdcolor="style='border: 1px solid $Header::colourorange;'";
1252 if ( &General
::IpInSubnet
($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1253 $tdcolor="style='border: 1px solid $Header::colourgreen;'";
1256 if ( &General
::IpInSubnet
($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
1257 $tdcolor="style='border: 1px solid $Header::colourblue;'";
1260 }elsif ($val eq 'Default IP'){
1261 $tdcolor="style='border: 1px solid $Header::colourred;'";
1264 #Check if a manual IP is part of a VPN
1265 if ($nettype eq 'src_addr' || $nettype eq 'tgt_addr'){
1266 #Check if IP is part of OpenVPN dynamic subnet
1267 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
1268 my ($c,$d) = split("/",$val);
1269 if (&General
::IpInSubnet
($c,$a,$b)){
1270 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1273 #Check if IP is part of OpenVPN static subnet
1274 foreach my $key (sort keys %ccdnet){
1275 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1276 $b =&General
::iporsubtodec
($b);
1277 if (&General
::IpInSubnet
($c,$a,$b)){
1278 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1282 #Check if IP is part of OpenVPN N2N subnet
1283 foreach my $key (sort keys %ccdhost){
1284 if ($ccdhost{$key}[3] eq 'net'){
1285 my ($a,$b) = split("/",$ccdhost{$key}[11]);
1286 if (&General
::IpInSubnet
($c,$a,$b)){
1287 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1292 #Check if IP is part of IPsec RW network
1293 if ($ipsecsettings{'RW_NET'} ne ''){
1294 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1295 $b=&General
::iporsubtodec
($b);
1296 if (&General
::IpInSubnet
($c,$a,$b)){
1297 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1301 #Check if IP is part of a IPsec N2N network
1302 foreach my $key (sort keys %ipsecconf){
1303 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1304 if (&General
::IpInSubnet
($c,$a,$b)){
1305 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1311 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'){
1312 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1315 if ($nettype eq 'ipsec_net_src' || $nettype eq 'ipsec_net_tgt'){
1316 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1320 if ($nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1321 foreach my $key (sort keys %$hash){
1322 if ($$hash{$key}[0] eq $val){
1323 $val=$$hash{$key}[2];
1328 foreach my $alias (sort keys %aliases)
1330 if ($val eq $alias){
1331 $tdcolor="style='border: 1px solid $Header::colourred;'";
1342 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwhost hint'});
1343 print "<class name='base'>$hint\n";
1344 print " </class>\n";
1345 &Header
::closebox
();
1352 my %hash=%{(shift)};
1356 &General
::readhasharray
($config, \
%hash);
1357 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
1358 if($hash{$key}[0] eq $val){
1359 $pos=$#{$hash{$key}};
1360 $hash{$key}[$pos] = $hash{$key}[$pos]+1;
1363 &General
::writehasharray
($config, \
%hash);
1368 &General
::setup_default_networks
(\
%defaultNetworks);
1369 &General
::readhash
("/var/ipfire/ethernet/settings", \
%netsettings);
1370 #read all configfiles
1371 &General
::readhasharray
("$configccdnet", \
%ccdnet);
1372 &General
::readhasharray
("$confignet", \
%customnetwork);
1373 &General
::readhasharray
("$configccdhost", \
%ccdhost);
1374 &General
::readhasharray
("$confighost", \
%customhost);
1375 &General
::readhasharray
("$configccdhost", \
%ccdhost);
1376 &General
::readhasharray
("$configgrp", \
%customgrp);
1377 &General
::readhasharray
("$configipsec", \
%ipsecconf);
1378 &General
::get_aliases
(\
%aliases);
1382 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
1383 my $config=$fwdfwsettings{'config'};
1386 open (CONN1
,"/var/ipfire/red/local-ipaddress");
1387 my $redip = <CONN1
>;
1389 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1390 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1391 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1392 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1393 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1394 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1395 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1396 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1397 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1398 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1399 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1400 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1401 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1402 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1403 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1404 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1405 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1406 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1407 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1408 $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
1409 #check if update and get values
1410 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
1411 &General
::readhasharray
("$config", \
%hash);
1412 foreach my $key (sort keys %hash){
1414 if ($key eq $fwdfwsettings{'key'}){
1415 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
1416 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
1417 $fwdfwsettings{'chain'} = $hash{$key}[1];
1418 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1419 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1420 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1421 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1422 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1423 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1424 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1425 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1426 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1427 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1428 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1429 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1430 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1431 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1432 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1433 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1434 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1435 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1436 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1437 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1438 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1439 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1440 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1441 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1442 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1443 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
1444 $fwdfwsettings{'USE_NAT'} = $hash{$key}[28];
1445 $fwdfwsettings{'nat'} = $hash{$key}[31]; #changed order
1446 $fwdfwsettings{$fwdfwsettings{'nat'}} = $hash{$key}[29];
1447 $fwdfwsettings{'dnatport'} = $hash{$key}[30];
1448 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1449 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1450 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1451 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1452 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1453 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1454 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1455 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1456 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1457 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1458 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1459 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1460 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1461 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1462 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1463 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1464 $checked{'nat'}{$fwdfwsettings{'nat'}} = 'CHECKED';
1465 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1466 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1467 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1468 $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
1469 $selected{'dnat'}{$fwdfwsettings{$fwdfwsettings{'nat'}}} ='selected';
1470 $selected{'snat'}{$fwdfwsettings{$fwdfwsettings{'nat'}}} ='selected';
1473 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1474 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1475 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1476 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1477 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1478 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1479 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1480 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1481 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1482 $fwdfwsettings{'oldruletype'}=$fwdfwsettings{'chain'};
1483 #check if manual ip (source) is orange network
1484 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1485 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1486 if ( &General
::IpInSubnet
($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1487 $fwdfwsettings{'oldorange'} ='on';
1491 $fwdfwsettings{'ACTIVE'}='ON';
1492 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1493 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1494 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1495 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1496 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1497 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1498 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1499 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1500 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1501 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1502 #check if manual ip (source) is orange network
1503 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1504 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1505 if ( &General
::IpInSubnet
($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1506 $fwdfwsettings{'oldorange'} ='on';
1510 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw addrule'});
1511 print "<form method='post'>";
1512 &Header
::closebox
();
1513 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw source'});
1514 #------SOURCE-------------------------------------------------------
1516 <table width='100%' border='0'>
1517 <tr><td width='1%'><input type='radio' name='grp1' value='src_addr' checked></td><td width='60%'>$Lang::tr{'fwdfw sourceip'}<input type='TEXT' name='src_addr' value='$fwdfwsettings{'src_addr'}' size='16' maxlength='17'></td><td width='1%'><input type='radio' name='grp1' value='ipfire_src' $checked{'grp1'}{'ipfire_src'}></td><td><b>Firewall</b></td>
1519 print"<td align='right'><select name='ipfire_src' style='width:200px;'>";
1520 print "<option value='ALL' $selected{'ipfire_src'}{'ALL'}>$Lang::tr{'all'}</option>";
1521 print "<option value='GREEN' $selected{'ipfire_src'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
1522 print "<option value='ORANGE' $selected{'ipfire_src'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if $ifaces{'ORANGE_ADDRESS'};
1523 print "<option value='BLUE' $selected{'ipfire_src'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>" if $ifaces{'BLUE_ADDRESS'};
1524 print "<option value='RED1' $selected{'ipfire_src'}{'RED1'}>$Lang::tr{'red1'} ($redip)" if ($redip);
1526 if (! -z
"${General::swroot}/ethernet/aliases"){
1527 foreach my $alias (sort keys %aliases)
1529 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1534 <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
1536 &gen_dd_block
('src','grp1');
1538 <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
1539 <table width='100%' border='0'>
1540 <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>
1541 <td width='15%' nowrap='nowrap'>$Lang::tr{'fwdfw man port'}</td><td><select name='PROT'>
1543 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
1545 if ($_ eq $fwdfwsettings{'PROT'})
1547 print"<option selected>$_</option>";
1549 print"<option>$_</option>";
1552 $fwdfwsettings{'SRC_PORT'}=~ s/\|/,/g;
1554 </select></td><td align='right'><input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18' ></td></tr>
1555 <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;'>
1557 &General
::readhasharray
("${General::swroot}/fwhosts/icmp-types", \
%icmptypes);
1558 print"<option>All ICMP-Types</option>";
1559 foreach my $key (sort { ncmp
($icmptypes{$a}[0],$icmptypes{$b}[0]) } keys %icmptypes){
1560 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1561 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1563 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1567 </select></td></tr></table><br><hr>
1569 &Header
::closebox
();
1571 #---TARGET------------------------------------------------------
1572 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw target'});
1574 <table width='100%' border='0'>
1575 <tr><td width='1%'><input type='radio' name='grp2' value='tgt_addr' checked></td><td width='60%' nowrap='nowrap'>$Lang::tr{'fwdfw targetip'}<input type='TEXT' name='tgt_addr' value='$fwdfwsettings{'tgt_addr'}' size='16' maxlength='17'><td width='1%'><input type='radio' name='grp2' value='ipfire' $checked{'grp2'}{'ipfire'}></td><td><b>Firewall</b></td>
1577 print"<td align='right'><select name='ipfire' style='width:200px;'>";
1578 print "<option value='ALL' $selected{'ipfire'}{'ALL'}>$Lang::tr{'all'}</option>";
1579 print "<option value='GREEN' $selected{'ipfire'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
1580 print "<option value='ORANGE' $selected{'ipfire'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if $ifaces{'ORANGE_ADDRESS'};
1581 print "<option value='BLUE' $selected{'ipfire'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>" if $ifaces{'BLUE_ADDRESS'};
1582 print "<option value='RED1' $selected{'ipfire'}{'RED1'}>$Lang::tr{'red1'} ($redip)" if ($redip);
1583 if (! -z
"${General::swroot}/ethernet/aliases"){
1584 foreach my $alias (sort keys %aliases)
1586 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1591 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
1593 &gen_dd_block
('tgt','grp2');
1595 <hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; '></hr><br>
1596 <table width='100%' border='0'>
1597 <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;' >
1599 &General
::readhasharray
("$configsrv", \
%customservice);
1600 foreach my $key (sort { ncmp
($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1602 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1603 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1607 <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;' >
1609 &General
::readhasharray
("$configsrvgrp", \
%customservicegrp);
1611 foreach my $key (sort { ncmp
($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1612 if ($helper ne $customservicegrp{$key}[0]){
1614 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1615 print">$customservicegrp{$key}[0]</option>";
1617 $helper=$customservicegrp{$key}[0];
1621 <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'>
1623 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
1625 if ($_ eq $fwdfwsettings{'TGT_PROT'})
1627 print"<option selected>$_</option>";
1629 print"<option>$_</option>";
1632 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
1634 </select></td><td align='right'><input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18' ></td></tr>
1635 <tr><td colspan='2'></td><td></td><td>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TGT' style='min-width:230px;'>
1637 &General
::readhasharray
("${General::swroot}/fwhosts/icmp-types", \
%icmptypes);
1638 print"<option>All ICMP-Types</option>";
1639 foreach my $key (sort { ncmp
($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
1640 if($fwdfwsettings{'ICMP_TGT'} eq "$icmptypes{$key}[0]"){
1641 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1643 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1652 #---SNAT / DNAT ------------------------------------------------
1653 &Header
::openbox
('100%', 'left', 'NAT');
1655 <table width='100%' border='0'>
1656 <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>
1657 <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>
1659 print"<td width='8%'>IPFire: </td><td width='20%' align='right'><select name='dnat' style='width:140px;'>";
1660 print "<option value='ALL' $selected{'dnat'}{$Lang::tr{'all'}}>$Lang::tr{'all'}</option>";
1661 print "<option value='Default IP' $selected{'dnat'}{'Default IP'}>Default IP</option>";
1662 foreach my $alias (sort keys %aliases)
1664 print "<option value='$alias' $selected{'dnat'}{$alias}>$alias</option>";
1667 $fwdfwsettings{'dnatport'}=~ tr/|/,/;
1668 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>";
1669 print"<tr><td colspan='8'><br></td></tr>";
1671 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>";
1672 print"<td width='8%'>IPFire: </td><td width='20%' align='right'><select name='snat' style='width:140px;'>";
1673 foreach my $alias (sort keys %aliases)
1675 print "<option value='$alias' $selected{'snat'}{$alias}>$alias</option>";
1677 foreach my $network (sort keys %defaultNetworks)
1679 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1680 next if($defaultNetworks{$network}{'NAME'} eq "ALL");
1681 next if($defaultNetworks{$network}{'NAME'} =~ /OpenVPN/i);
1682 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1683 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'nat'}} eq $defaultNetworks{$network}{'NAME'});
1684 print ">$network</option>";
1688 &Header
::closebox
();
1689 #---Activate/logging/remark-------------------------------------
1690 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw additional'});
1692 <table width='100%' border='0'>
1693 <tr><td nowrap>$Lang::tr{'fwdfw rule action'}</td><td><select name='RULE_ACTION'>
1695 foreach ("ACCEPT","DROP","REJECT")
1697 if($fwdfwsettings{'updatefwrule'} eq 'on'){
1698 print"<option value='$_'";
1699 print "selected='selected'" if ($fwdfwsettings{'RULE_ACTION'} eq $_);
1700 print">$Lang::tr{'fwdfw '.$_}</option>";
1702 if($fwdfwsettings{'POLICY'} eq 'MODE2'){
1703 $fwdfwsettings{'RULE_ACTION'} = 'DROP';
1705 if ($_ eq $fwdfwsettings{'RULE_ACTION'})
1707 print"<option value='$_' selected>$Lang::tr{'fwdfw '.$_}</option>";
1709 print"<option value='$_'>$Lang::tr{'fwdfw '.$_}</option>";
1713 print"</select></td></tr>";
1714 print"<tr><td width='12%'>$Lang::tr{'remark'}:</td><td width='88%' align='left'><input type='text' name='ruleremark' maxlength='255' value='$fwdfwsettings{'ruleremark'}' style='width:99%':></td></tr>";
1715 #print"<tr><td width='100%'>$Lang::tr{'remark'}:</td><td align='left'><textarea name='ruleremark' cols='70' rows='3' value='$fwdfwsettings{'ruleremark'}'></textarea></td></tr>";
1716 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
1717 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
1718 for (my $count =1; $count <= $sum; $count++){
1719 print"<option value='$count' ";
1720 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
1721 print">$count</option>";
1723 print"</select></td></tr>";
1725 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
1729 </table><table width='100%'>
1730 <tr><td width='1%'><input type='checkbox' name='ACTIVE' value='ON' $checked{'ACTIVE'}{'ON'}></td><td>$Lang::tr{'fwdfw rule activate'}</td></tr>
1731 <tr><td width='1%'><input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'} ></td><td>$Lang::tr{'fwdfw log rule'}</td></tr>
1734 &Header
::closebox
();
1735 #---ADD TIMEFRAME-----------------------------------------------
1736 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw timeframe'});
1738 <table width='70%' border='0'>
1739 <tr><td width='1%'><input type='checkbox' name='TIME' value='ON' $checked{'TIME'}{'ON'}></td><td colspan='4'>$Lang::tr{'fwdfw timeframe'}</td></tr>
1740 <tr><td colspan='7'> </td></tr>
1742 <td align='left'>$Lang::tr{'time'}:</td>
1743 <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>
1744 <td width='15%' align='left'>$Lang::tr{'advproxy from'}</td>
1745 <td width='15%' align='left'>$Lang::tr{'advproxy to'}</td>
1748 <td align='right'></td>
1749 <td width='30%' align='left'>
1750 <input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} />
1751 <input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} />
1752 <input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} />
1753 <input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} />
1754 <input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} />
1755 <input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} />
1756 <input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} />
1758 <td><select name='TIME_FROM'>
1760 for (my $i=0;$i<=23;$i++) {
1761 $i = sprintf("%02s",$i);
1762 for (my $j=0;$j<=45;$j+=15) {
1763 $j = sprintf("%02s",$j);
1764 my $time = $i.":".$j;
1765 print "\t\t\t\t\t<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
1770 <td><select name='TIME_TO'>
1772 for (my $i=0;$i<=23;$i++) {
1773 $i = sprintf("%02s",$i);
1774 for (my $j=0;$j<=45;$j+=15) {
1775 $j = sprintf("%02s",$j);
1776 my $time = $i.":".$j;
1777 print "\t\t\t\t\t<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
1784 #---ACTION------------------------------------------------------
1785 if($fwdfwsettings{'updatefwrule'} ne 'on'){
1787 <table border='0' width='100%'>
1788 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
1789 <input type='hidden' name='config' value='$config' >
1790 <input type='hidden' name='ACTION' value='saverule' >
1791 </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>
1796 <table border='0' width='100%'>
1797 <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'}'>
1798 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
1799 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
1800 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
1801 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
1802 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
1803 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
1804 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
1805 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
1806 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
1807 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
1808 <input type='hidden' name='oldorange' value='$fwdfwsettings{'oldorange'}' />
1809 <input type='hidden' name='oldnat' value='$fwdfwsettings{'oldnat'}' />
1810 <input type='hidden' name='oldruletype' value='$fwdfwsettings{'oldruletype'}' />
1811 <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>
1815 &Header
::closebox
();
1821 &General
::readhasharray
($fwdfwsettings{'config'}, \
%uphash);
1822 foreach my $key (sort keys %uphash){
1823 if ($key eq $fwdfwsettings{'key'}) {
1825 if (exists $uphash{$last}){
1827 foreach my $y (0 .. $#{$uphash{$last}}) {
1828 $tmp{0}[$y] = $uphash{$last}[$y];
1830 #copy active rule to last
1831 foreach my $i (0 .. $#{$uphash{$last}}) {
1832 $uphash{$last}[$i] = $uphash{$key}[$i];
1834 #copy saved rule to actual position
1835 foreach my $x (0 .. $#{$tmp{0}}) {
1836 $uphash{$key}[$x] = $tmp{0}[$x];
1841 &General
::writehasharray
($fwdfwsettings{'config'}, \
%uphash);
1848 &General
::readhasharray
($fwdfwsettings{'config'}, \
%downhash);
1849 foreach my $key (sort keys %downhash){
1850 if ($key eq $fwdfwsettings{'key'}) {
1851 my $next = $key + 1;
1852 if (exists $downhash{$next}){
1854 foreach my $y (0 .. $#{$downhash{$next}}) {
1855 $tmp{0}[$y] = $downhash{$next}[$y];
1857 #copy active rule to next
1858 foreach my $i (0 .. $#{$downhash{$next}}) {
1859 $downhash{$next}[$i] = $downhash{$key}[$i];
1861 #copy saved rule to actual position
1862 foreach my $x (0 .. $#{$tmp{0}}) {
1863 $downhash{$key}[$x] = $tmp{0}[$x];
1868 &General
::writehasharray
($fwdfwsettings{'config'}, \
%downhash);
1873 if (!-f
"${General::swroot}/forward/reread"){
1874 system("touch ${General::swroot}/forward/reread");
1875 system("touch ${General::swroot}/fwhosts/reread");
1880 system("/usr/local/bin/forwardfwctrl");
1881 if ( -f
"${General::swroot}/forward/reread"){
1882 system("rm ${General::swroot}/forward/reread");
1883 system("rm ${General::swroot}/fwhosts/reread");
1890 &General
::readhasharray
("$config", $hash);
1891 if (!$errormessage){
1892 ################################################################
1893 #check if we change an INPUT rule to a OUTGOING
1894 if($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW' ){
1895 &changerule
($configinput);
1898 #check if we change an INPUT rule to a FORWARD
1899 elsif($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
1900 &changerule
($configinput);
1903 ################################################################
1904 #check if we change an OUTGOING rule to an INPUT
1905 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'INPUTFW' ){
1906 &changerule
($configoutgoing);
1909 #check if we change an OUTGOING rule to a FORWARD
1910 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
1911 &changerule
($configoutgoing);
1914 ################################################################
1915 #check if we change a FORWARD rule to an INPUT
1916 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'INPUTFW'){
1917 &changerule
($configfwdfw);
1920 #check if we change a FORWARD rule to an OUTGOING
1921 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW'){
1922 &changerule
($configfwdfw);
1925 if ($fwdfwsettings{'updatefwrule'} ne 'on'){
1926 my $key = &General
::findhasharraykey
($hash);
1927 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1928 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1929 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1930 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1931 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1932 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1933 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1934 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1935 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1936 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1937 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1938 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1939 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1940 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1941 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1942 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1943 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1944 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1945 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1946 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1947 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1948 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1949 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1950 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1951 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1952 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1953 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1954 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
1955 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
1956 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
1957 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
1958 $$hash{$key}[31] = $fwdfwsettings{'nat'};
1959 &General
::writehasharray
("$config", $hash);
1961 foreach my $key (sort {$a <=> $b} keys %$hash){
1962 if($key eq $fwdfwsettings{'key'}){
1963 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1964 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1965 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1966 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1967 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1968 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1969 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1970 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1971 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1972 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1973 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1974 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1975 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1976 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1977 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1978 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1979 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1980 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1981 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1982 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1983 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1984 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1985 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1986 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1987 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1988 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1989 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1990 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
1991 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
1992 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
1993 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
1994 $$hash{$key}[31] = $fwdfwsettings{'nat'};
1999 &General
::writehasharray
("$config", $hash);
2000 if($fwdfwsettings{'oldrulenumber'} > $fwdfwsettings{'rulepos'}){
2002 my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'};
2003 for (my $z=0;$z<$val;$z++){
2004 foreach my $key (sort {$a <=> $b} keys %$hash){
2005 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2007 if (exists $$hash{$last}){
2009 foreach my $y (0 .. $#{$$hash{$last}}) {
2010 $tmp{0}[$y] = $$hash{$last}[$y];
2012 #copy active rule to last
2013 foreach my $i (0 .. $#{$$hash{$last}}) {
2014 $$hash{$last}[$i] = $$hash{$key}[$i];
2016 #copy saved rule to actual position
2017 foreach my $x (0 .. $#{$tmp{0}}) {
2018 $$hash{$key}[$x] = $tmp{0}[$x];
2023 $fwdfwsettings{'oldrulenumber'}--;
2025 &General
::writehasharray
("$config", $hash);
2027 }elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
2029 my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
2030 for (my $z=0;$z<$val;$z++){
2031 foreach my $key (sort {$a <=> $b} keys %$hash){
2032 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2033 my $next = $key + 1;
2034 if (exists $$hash{$next}){
2036 foreach my $y (0 .. $#{$$hash{$next}}) {
2037 $tmp{0}[$y] = $$hash{$next}[$y];
2039 #copy active rule to next
2040 foreach my $i (0 .. $#{$$hash{$next}}) {
2041 $$hash{$next}[$i] = $$hash{$key}[$i];
2043 #copy saved rule to actual position
2044 foreach my $x (0 .. $#{$tmp{0}}) {
2045 $$hash{$key}[$x] = $tmp{0}[$x];
2050 $fwdfwsettings{'oldrulenumber'}++;
2052 &General
::writehasharray
("$config", $hash);
2059 # Checks a hostname against RFC1035
2062 # Each part should be at least two characters in length
2063 # but no more than 63 characters
2064 if (length ($remark) < 1 || length ($remark) > 255) {
2066 # Only valid characters are a-z, A-Z, 0-9 and -
2067 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s
]*$/) {
2069 # First character can only be a letter or a digit
2070 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
2072 # Last character can only be a letter or a digit
2073 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
2079 &General
::readhash
("/var/ipfire/ethernet/settings", \
%netsettings);
2080 &viewtablenew
(\
%configfwdfw,$configfwdfw,"","Forward" );
2081 &viewtablenew
(\
%configinputfw,$configinput,"",$Lang::tr
{'fwdfw xt access'} );
2082 &viewtablenew
(\
%configoutgoingfw,$configoutgoing,"","Outgoing" );
2091 &General
::get_aliases
(\
%aliases);
2092 &General
::readhasharray
("$confighost", \
%customhost);
2093 &General
::readhasharray
("$config", $hash);
2094 &General
::readhasharray
("$configccdnet", \
%ccdnet);
2095 &General
::readhasharray
("$configccdhost", \
%ccdhost);
2097 &Header
::openbox
('100%', 'left',$title);
2105 print"<b>$title1</b><br>";
2106 print"<table width='100%' cellspacing='0' cellpadding='0' border='0'>";
2107 print"<tr><td align='center'><b>#</td><td></td><td align='center' width='25'></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' colspan='6' width='1%'><b>$Lang::tr{'fwdfw action'}</td></tr>";
2108 foreach my $key (sort {$a <=> $b} keys %$hash){
2111 #check if vpn hosts/nets have been deleted
2112 if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){
2113 push (@tmpsrc,$$hash{$key}[4]);
2115 if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){
2116 push (@tmpsrc,$$hash{$key}[6]);
2118 foreach my $host (@tmpsrc){
2119 if($$hash{$key}[3] eq 'ipsec_net_src' || $$hash{$key}[5] eq 'ipsec_net_tgt'){
2120 if(&fwlib
::get_ipsec_net_ip
($host,11) eq ''){
2122 &disable_rule
($key);
2125 }elsif($$hash{$key}[3] eq 'ovpn_net_src' || $$hash{$key}[5] eq 'ovpn_net_tgt'){
2126 if(&fwlib
::get_ovpn_net_ip
($host,1) eq ''){
2128 &disable_rule
($key);
2131 }elsif($$hash{$key}[3] eq 'ovpn_n2n_src' || $$hash{$key}[5] eq 'ovpn_n2n_tgt'){
2132 if(&fwlib
::get_ovpn_n2n_ip
($host,27) eq ''){
2134 &disable_rule
($key);
2137 }elsif($$hash{$key}[3] eq 'ovpn_host_src' || $$hash{$key}[5] eq 'ovpn_host_tgt'){
2138 if(&fwlib
::get_ovpn_host_ip
($host,33) eq ''){
2140 &disable_rule
($key);
2145 $$hash{'ACTIVE'}=$$hash{$key}[2];
2147 if($coloryellow eq 'on'){
2148 print"<tr bgcolor='$color{'color14'}' >";
2150 }elsif($coloryellow eq ''){
2152 $color="$color{'color22'}";
2155 $color="$color{'color20'}";
2158 print"<tr bgcolor='$color' >";
2161 <td align='right' width='18'><b>$key  </b></td>
2164 if ($$hash{$key}[0] eq 'ACCEPT'){
2167 $rulecolor=$color{'color17'};
2168 }elsif($$hash{$key}[0] eq 'DROP'){
2171 $rulecolor=$color{'color25'};
2172 }elsif($$hash{$key}[0] eq 'REJECT'){
2175 $rulecolor=$color{'color16'};
2177 print"<td bgcolor='$rulecolor' align='center' width='10'><span title='$tooltip'><b>$ruletype</b></span></td>";
2180 if ($$hash{$key}[8] && $$hash{$key}[7] eq 'ON'){#source prot if manual
2181 push (@protocols,$$hash{$key}[8]);
2182 }elsif ($$hash{$key}[12]){ #target prot if manual
2183 push (@protocols,$$hash{$key}[12]);
2184 }elsif($$hash{$key}[14] eq 'cust_srv'){
2185 &get_serviceports
("service",$$hash{$key}[15]);
2186 }elsif($$hash{$key}[14] eq 'cust_srvgrp'){
2187 &get_serviceports
("group",$$hash{$key}[15]);
2189 push (@protocols,$Lang::tr
{'all'});
2191 my $protz=join(",",@protocols);
2192 print"<td align='center'>$protz</td>";
2196 &getcolor
($$hash{$key}[3],$$hash{$key}[4],\
%customhost);
2197 print"<td align='center' width='160' $tdcolor>";
2198 if ($$hash{$key}[3] eq 'ipfire_src'){
2199 $ipfireiface='Interface ';
2201 if ($$hash{$key}[3] eq 'std_net_src'){
2202 print &get_name
($$hash{$key}[4]);
2203 }elsif ($$hash{$key}[3] eq 'src_addr'){
2204 my ($split1,$split2) = split("/",$$hash{$key}[4]);
2205 if ($split2 eq '32'){
2208 print $$hash{$key}[4];
2210 }elsif ($$hash{$key}[4] eq 'RED1'){
2211 print "$ipfireiface $Lang::tr{'fwdfw red'}";
2213 print "$$hash{$key}[4]";
2217 &getsrcport
(\
%$hash,$key);
2218 #Is this a SNAT rule?
2219 if ($$hash{$key}[31] eq 'snat' && $$hash{$key}[28] eq 'ON'){
2220 my $net=&get_name
($$hash{$key}[29]);
2221 if ( ! $net){ $net=$$hash{$key}[29];}
2223 if ($$hash{$key}[30] ne ''){
2224 print": $$hash{$key}[30]";
2227 if ($$hash{$key}[17] eq 'ON'){
2228 $log="/images/on.gif";
2230 $log="/images/off.gif";
2235 <form method='post'>
2236 <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 ;'/>
2237 <input type='hidden' name='key' value='$key' />
2238 <input type='hidden' name='config' value='$config' />
2239 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw togglelog'}' />
2243 &getcolor
($$hash{$key}[5],$$hash{$key}[6],\
%customhost);
2245 <td align='center' width='160' $tdcolor>
2247 #Is this a DNAT rule?
2248 if ($$hash{$key}[31] eq 'dnat' && $$hash{$key}[28] eq 'ON'){
2249 print "Firewall ($$hash{$key}[29])";
2250 if($$hash{$key}[30] ne ''){
2251 $$hash{$key}[30]=~ tr/|/,/;
2252 print": $$hash{$key}[30]";
2256 if ($$hash{$key}[5] eq 'ipfire'){
2257 $ipfireiface='Interface';
2259 if ($$hash{$key}[5] eq 'std_net_tgt' || $$hash{$key}[5] eq 'ipfire' || $$hash{$key}[6] eq 'RED1' || $$hash{$key}[6] eq 'GREEN' || $$hash{$key}[6] eq 'ORANGE' || $$hash{$key}[6] eq 'BLUE' ){
2260 if ($$hash{$key}[6] eq 'RED1'){
2261 print "$ipfireiface $Lang::tr{'red1'}";
2262 }elsif ($$hash{$key}[6] eq 'GREEN' || $$hash{$key}[6] eq 'ORANGE' || $$hash{$key}[6] eq 'BLUE'|| $$hash{$key}[6] eq 'ALL')
2264 print "$ipfireiface ".&get_name
($$hash{$key}[6]);
2266 print $$hash{$key}[6];
2268 }elsif ($$hash{$key}[5] eq 'tgt_addr'){
2269 my ($split1,$split2) = split("/",$$hash{$key}[6]);
2270 if ($split2 eq '32'){
2273 print $$hash{$key}[6];
2276 print "$$hash{$key}[6]";
2280 &gettgtport
(\
%$hash,$key);
2283 if($$hash{$key}[2] eq 'ON'){
2284 $gif="/images/on.gif"
2287 $gif="/images/off.gif"
2290 <form method='post'>
2291 <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;' />
2292 <input type='hidden' name='key' value='$key' />
2293 <input type='hidden' name='config' value='$config' />
2294 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw toggle'}' />
2296 <form method='post'>
2297 <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;' />
2298 <input type='hidden' name='key' value='$key' />
2299 <input type='hidden' name='config' value='$config' />
2300 <input type='hidden' name='ACTION' value='editrule' />
2302 <form method='post'>
2303 <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;' />
2304 <input type='hidden' name='key' value='$key' />
2305 <input type='hidden' name='config' value='$config' />
2306 <input type='hidden' name='ACTION' value='copyrule' />
2308 <form method='post'>
2309 <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;' />
2310 <input type='hidden' name='key' value='$key' />
2311 <input type='hidden' name='config' value='$config' />
2312 <input type='hidden' name='ACTION' value='deleterule' />
2315 if (exists $$hash{$key-1}){
2317 <form method='post'>
2318 <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;' />
2319 <input type='hidden' name='key' value='$key' />
2320 <input type='hidden' name='config' value='$config' />
2321 <input type='hidden' name='ACTION' value='moveup' />
2325 print"<td width='25'><input type='image' img src='/images/up.gif' style='visibility:hidden;'></td>";
2327 if (exists $$hash{$key+1}){
2329 <form method='post'>
2330 <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;' />
2331 <input type='hidden' name='key' value='$key' />
2332 <input type='hidden' name='config' value='$config' />
2333 <input type='hidden' name='ACTION' value='movedown' />
2334 </td></form></td></tr>
2337 print"<td width='25'><input type='image' img src='/images/down.gif' style='visibility:hidden;'></td></tr>";
2340 if ($optionsfw{'SHOWREMARK'} eq 'on' && $$hash{$key}[16] ne ''){
2341 print"<tr bgcolor='$color'>";
2342 print"<td> </td><td bgcolor='$rulecolor'></td><td colspan='10'>  $$hash{$key}[16]</td></tr>";
2344 if ($$hash{$key}[18] eq 'ON'){
2346 if ($$hash{$key}[18] eq 'ON'){
2348 if($$hash{$key}[19] ne ''){push (@days,$Lang::tr
{'fwdfw wd_mon'});}
2349 if($$hash{$key}[20] ne ''){push (@days,$Lang::tr
{'fwdfw wd_tue'});}
2350 if($$hash{$key}[21] ne ''){push (@days,$Lang::tr
{'fwdfw wd_wed'});}
2351 if($$hash{$key}[22] ne ''){push (@days,$Lang::tr
{'fwdfw wd_thu'});}
2352 if($$hash{$key}[23] ne ''){push (@days,$Lang::tr
{'fwdfw wd_fri'});}
2353 if($$hash{$key}[24] ne ''){push (@days,$Lang::tr
{'fwdfw wd_sat'});}
2354 if($$hash{$key}[25] ne ''){push (@days,$Lang::tr
{'fwdfw wd_sun'});}
2355 my $weekdays=join(",",@days);
2357 print"<tr bgcolor='$color'>";
2358 print"<td> </td><td bgcolor='$rulecolor'></td><td align='left' colspan='10'>  $weekdays   $$hash{$key}[26] - $$hash{$key}[27] </td></tr>";
2362 print"<tr bgcolor='FFFFFF'><td colspan='13' height='1'></td></tr>";
2365 print "<table width='100%'rules='cols' border='1'>";
2367 if ($config eq '/var/ipfire/forward/config'){
2368 my $pol='fwdfw '.$fwdfwsettings{'POLICY'};
2369 if ($fwdfwsettings{'POLICY'} eq 'MODE1'){
2370 $col="bgcolor='darkred'";
2372 $col="bgcolor='green'";
2374 &show_defaultrules
($col,$pol);
2375 }elsif ($config eq '/var/ipfire/forward/outgoing'){
2376 my $pol='fwdfw '.$fwdfwsettings{'POLICY1'};
2377 if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){
2378 $col="bgcolor='darkred'";
2380 $col="bgcolor='green'";
2382 print"<tr><td $col width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col><font color='#FFFFFF' align='center'>$Lang::tr{$pol}</font></td></tr>";
2384 print"<tr><td bgcolor='darkred' width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td bgcolor='darkred' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw MODE1'}</font></td></tr>";
2389 &Header
::closebox
();
2391 if ($optionsfw{'SHOWTABLES'} eq 'on'){
2392 print "<b>$title1</b><br>";
2393 print"<table width='100%' border='0' rules='none'><tr><td height='30' bgcolor=$color{'color22'} align='center'>$Lang::tr{'fwhost empty'}</td></tr></table>";
2395 if ($config eq '/var/ipfire/forward/config'){
2396 my $pol='fwdfw '.$fwdfwsettings{'POLICY'};
2397 if ($fwdfwsettings{'POLICY'} eq 'MODE1'){
2398 $col="bgcolor='darkred'";
2400 $col="bgcolor='green'";
2402 &show_defaultrules
($col,$pol);
2403 }elsif ($config eq '/var/ipfire/forward/outgoing'){
2404 print "<table width='100%' rules='cols' border='1'>";
2405 my $pol='fwdfw '.$fwdfwsettings{'POLICY1'};
2406 if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){
2407 $col="bgcolor='darkred'";
2409 $col="bgcolor='green'";
2411 print"<tr><td $col align='center' width='20%'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF'>$Lang::tr{$pol}</font></td></tr>";
2413 print"<tr><td bgcolor='darkred' align='center' width='20%'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td align='center'>$Lang::tr{'fwdfw MODE1'}</font></td></tr>";
2415 print"</table><br><br>";
2419 &Header
::closebigbox
();
2420 &Header
::closepage
();
2422 sub show_defaultrules
2426 #STANDARD RULES (From WIKI)
2427 print"</table><br>";
2428 print "<table width='100%' rules='cols' border='1' >";
2429 if ($col eq "bgcolor='green'"){
2430 my $blue = "<font color=$Header::colourblue> $Lang::tr{'blue'}</font> ($Lang::tr{'fwdfw pol block'})" if $ifaces{'BLUE_DEV'};
2431 my $orange = "<font color=$Header::colourorange> $Lang::tr{'orange'}</font> ($Lang::tr{'fwdfw pol block'})" if $ifaces{'ORANGE_DEV'};
2432 my $blue1 = "<font color=$Header::colourblue> $Lang::tr{'blue'}</font> ($Lang::tr{'fwdfw pol allow'})" if $ifaces{'BLUE_DEV'};
2433 my $orange1 = "<font color=$Header::colourorange> $Lang::tr{'orange'}</font> ($Lang::tr{'fwdfw pol allow'})" if $ifaces{'ORANGE_DEV'};
2434 print"<tr><td align='center'><font color='#000000'>$Lang::tr{'green'}</td><td align='center'> <font color=$Header::colourred> $Lang::tr{'red'}</font> ($Lang::tr{'fwdfw pol allow'})</td><td align='center'>$orange1</td><td align='center'>$blue1</td></tr>";
2435 print"<tr><td align='center' width='20%'><font color='#000000'>$Lang::tr{'orange'}</td><td align='center'> <font color=$Header::colourred> $Lang::tr{'red'}</font> ($Lang::tr{'fwdfw pol allow'})</td><td align='center'><font color=$Header::colourgreen> $Lang::tr{'green'}</font> ($Lang::tr{'fwdfw pol block'})</td><td align='center'>$blue</td></tr>";
2436 print"<tr><td align='center'><font color='#000000'>$Lang::tr{'blue'}</td><td align='center'> <font color=$Header::colourred> $Lang::tr{'red'}</font> ($Lang::tr{'fwdfw pol allow'})</td><td align='center'>$orange</td><td align='center'><font color=$Header::colourgreen> $Lang::tr{'green'}</font> ($Lang::tr{'fwdfw pol block'})</td></tr>" if $ifaces{'BLUE_DEV'};
2437 print"<tr><td $col align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'} </font></td><td $col colspan='3' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol allow'}</font></td></tr>";
2438 }elsif($col eq "bgcolor='darkred'"){
2439 print"<tr><td $col width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF'>$Lang::tr{$pol}</font></td></tr>";