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