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