]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/forwardfw.cgi
ef94db1453f0b20da59063018a934439e7fc40dc
[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").hide();
142 }
143
144 // Show NAT area when "use nat" checkbox is clicked
145 \$("#nat").change(function() {
146 \$("#natpart").toggle();
147 });
148
149 // Time constraints
150 if(!\$("#USE_TIME_CONSTRAINTS").attr("checked")) {
151 \$("#TIME_CONSTRAINTS").hide();
152 }
153 \$("#USE_TIME_CONSTRAINTS").change(function() {
154 \$("#TIME_CONSTRAINTS").toggle();
155 });
156
157 // Automatically select radio buttons when corresponding
158 // dropdown menu changes.
159 \$("select").change(function() {
160 var id = \$(this).attr("name");
161
162 // When using SNAT or DNAT, check "USE NAT" Checkbox
163 if (id === 'snat' || id === 'dnat') {
164 \$('#USE_NAT').prop('checked', true);
165 }
166 \$('#' + id).prop("checked", true);
167 });
168 });
169 </script>
170 END
171
172 #### ACTION #####
173
174 if ($fwdfwsettings{'ACTION'} eq 'saverule')
175 {
176 &General::readhasharray("$configfwdfw", \%configfwdfw);
177 &General::readhasharray("$configinput", \%configinputfw);
178 &General::readhasharray("$configoutgoing", \%configoutgoingfw);
179 #Set Variables according to the JQuery code in protocol section
180 if ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP')
181 {
182 if ($fwdfwsettings{'SRC_PORT'} ne '')
183 {
184 $fwdfwsettings{'USE_SRC_PORT'} = 'ON';
185 }
186 if ($fwdfwsettings{'TGT_PORT'} ne '')
187 {
188 $fwdfwsettings{'USESRV'} = 'ON';
189 $fwdfwsettings{'grp3'} = 'TGT_PORT';
190 }
191 }
192 if ($fwdfwsettings{'PROT'} eq 'template')
193 {
194 $fwdfwsettings{'USESRV'} = 'ON';
195 }
196 $errormessage=&checksource;
197 if(!$errormessage){&checktarget;}
198 if(!$errormessage){&checkrule;}
199 #check if manual ip (source) is orange network
200 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
201 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
202 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
203 $checkorange='on';
204 }
205 }
206 #check useless rules
207 if( ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' || $checkorange eq 'on') && $fwdfwsettings{'grp2'} eq 'ipfire'){
208 $errormessage.=$Lang::tr{'fwdfw useless rule'}."<br>";
209 }
210 #check if we try to break rules
211 if( $fwdfwsettings{'grp1'} eq 'ipfire_src' && $fwdfwsettings{'grp2'} eq 'ipfire'){
212 $errormessage=$Lang::tr{'fwdfw err same'};
213 }
214 #INPUT part
215 if($fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ORANGE'){
216 $fwdfwsettings{'config'}=$configinput;
217 $fwdfwsettings{'chain'} = 'INPUTFW';
218 my $maxkey=&General::findhasharraykey(\%configinputfw);
219 #check if we have an identical rule already
220 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
221 foreach my $key (sort keys %configinputfw){
222 if ( "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
223 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]"){
224 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
225 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on'){
226 $errormessage='';
227 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
228 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
229 }
230 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
231 $fwdfwsettings{'nosave'} = 'on';
232 }
233 }
234 }
235 }
236 #check Rulepos on new Rule
237 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
238 $fwdfwsettings{'oldrulenumber'}=$maxkey;
239 foreach my $key (sort keys %configinputfw){
240 if ( "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
241 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]"){
242 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
243 }
244 }
245 }
246 #check if we just close a rule
247 if( $fwdfwsettings{'oldgrp1a'} eq $fwdfwsettings{'grp1'} && $fwdfwsettings{'oldgrp1b'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'oldgrp2a'} eq $fwdfwsettings{'grp2'} && $fwdfwsettings{'oldgrp2b'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'oldgrp3a'} eq $fwdfwsettings{'grp3'} && $fwdfwsettings{'oldgrp3b'} eq $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'oldruletype'} eq $fwdfwsettings{'chain'}) {
248 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
249 $errormessage='';
250 $fwdfwsettings{'nosave2'} = 'on';
251 }
252 }
253 if (!$errormessage){
254 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
255 if ($fwdfwsettings{'nobase'} ne 'on'){
256 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
257 }
258 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
259 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
260 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
261 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
262 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
263 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
264 }
265 if($fwdfwsettings{'nosave2'} ne 'on'){
266 &saverule(\%configinputfw,$configinput);
267 }
268 }
269 }elsif($fwdfwsettings{'grp1'} eq 'ipfire_src' ){
270 # OUTGOING PART
271 $fwdfwsettings{'config'}=$configoutgoing;
272 $fwdfwsettings{'chain'} = 'OUTGOINGFW';
273 my $maxkey=&General::findhasharraykey(\%configoutgoingfw);
274 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
275 foreach my $key (sort keys %configoutgoingfw){
276 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'}"
277 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]"){
278 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
279 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on'){
280 $errormessage='';
281 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
282 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
283 }
284 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
285 $fwdfwsettings{'nosave'} = 'on';
286 }
287 }
288 }
289 }
290 #check Rulepos on new Rule
291 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
292 print"CHECK OUTGOING DOPPELTE REGEL<br>";
293 $fwdfwsettings{'oldrulenumber'}=$maxkey;
294 foreach my $key (sort keys %configoutgoingfw){
295 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'}"
296 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]"){
297 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
298 }
299 }
300 }
301 #check if we just close a rule
302 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'}) {
303 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
304 $fwdfwsettings{'nosave2'} = 'on';
305 $errormessage='';
306 }
307 }
308 #increase counters
309 if (!$errormessage){
310 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
311 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
312 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
313 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
314 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
315 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
316 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
317 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
318 }
319 if ($fwdfwsettings{'nobase'} eq 'on'){
320 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
321 }
322 if ($fwdfwsettings{'nosave2'} ne 'on'){
323 &saverule(\%configoutgoingfw,$configoutgoing);
324 }
325 }
326 }else{
327 #FORWARD PART
328 $fwdfwsettings{'config'}=$configfwdfw;
329 $fwdfwsettings{'chain'} = 'FORWARDFW';
330 my $maxkey=&General::findhasharraykey(\%configfwdfw);
331 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
332 #check if we have an identical rule already
333 foreach my $key (sort keys %configfwdfw){
334 if ( "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'}"
335 eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[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]"){
336 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
337 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' ){
338 $errormessage='';
339 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
340 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
341 }
342 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
343 $fwdfwsettings{'nosave'} = 'on';
344 }
345 }
346 }
347 }
348 #check Rulepos on new Rule
349 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
350 $fwdfwsettings{'oldrulenumber'}=$maxkey;
351 foreach my $key (sort keys %configfwdfw){
352 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'}"
353 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]"){
354 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
355 }
356 }
357 }
358 #check if we just close a rule
359 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'}) {
360 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
361 $fwdfwsettings{'nosave2'} = 'on';
362 $errormessage='';
363 }
364 }
365 #increase counters
366 if (!$errormessage){
367 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
368 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
369 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
370 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
371 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
372 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
373 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
374 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
375 }
376 if ($fwdfwsettings{'nobase'} eq 'on'){
377 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
378 }
379 if ($fwdfwsettings{'nosave2'} ne 'on'){
380 &saverule(\%configfwdfw,$configfwdfw);
381 }
382 }
383 }
384 if ($errormessage){
385 &newrule;
386 }else{
387 if($fwdfwsettings{'nosave2'} ne 'on'){
388 &rules;
389 }
390 &base;
391 }
392 }
393 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw newrule'})
394 {
395 &newrule;
396 }
397 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw toggle'})
398 {
399 my %togglehash=();
400 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
401 foreach my $key (sort keys %togglehash){
402 if ($key eq $fwdfwsettings{'key'}){
403 if ($togglehash{$key}[2] eq 'ON'){$togglehash{$key}[2]='';}else{$togglehash{$key}[2]='ON';}
404 }
405 }
406 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
407 &rules;
408 &base;
409 }
410 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw togglelog'})
411 {
412 my %togglehash=();
413 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
414 foreach my $key (sort keys %togglehash){
415 if ($key eq $fwdfwsettings{'key'}){
416 if ($togglehash{$key}[17] eq 'ON'){$togglehash{$key}[17]='';}else{$togglehash{$key}[17]='ON';}
417 }
418 }
419 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
420 &rules;
421 &base;
422 }
423 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
424 {
425 &reread_rules;
426 &base;
427 }
428 if ($fwdfwsettings{'ACTION'} eq 'editrule')
429 {
430 $fwdfwsettings{'updatefwrule'}='on';
431 &newrule;
432 }
433 if ($fwdfwsettings{'ACTION'} eq 'deleterule')
434 {
435 &deleterule;
436 }
437 if ($fwdfwsettings{'ACTION'} eq 'moveup')
438 {
439 &pos_up;
440 &base;
441 }
442 if ($fwdfwsettings{'ACTION'} eq 'movedown')
443 {
444 &pos_down;
445 &base;
446 }
447 if ($fwdfwsettings{'ACTION'} eq 'copyrule')
448 {
449 $fwdfwsettings{'copyfwrule'}='on';
450 &newrule;
451 }
452 if ($fwdfwsettings{'ACTION'} eq '' or $fwdfwsettings{'ACTION'} eq 'reset')
453 {
454 &base;
455 }
456 ### Functions ####
457 sub addrule
458 {
459 &error;
460 if (-f "${General::swroot}/forward/reread"){
461 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>";
462 }
463 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw menu'});
464 print "<form method='post'>";
465 print "<table border='0'>";
466 print "<tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'></td>";
467 print"</tr></table></form><hr>";
468 &Header::closebox();
469 &viewtablerule;
470 }
471 sub base
472 {
473 &hint;
474 &addrule;
475 }
476 sub changerule
477 {
478 my $oldchain=shift;
479 $fwdfwsettings{'updatefwrule'}='';
480 $fwdfwsettings{'config'}=$oldchain;
481 $fwdfwsettings{'nobase'}='on';
482 &deleterule;
483 &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
484 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
485 }
486 sub checksource
487 {
488 my ($ip,$subnet);
489 #check ip-address if manual
490 if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){
491 #check if ip with subnet
492 if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?)$/) {
493 ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'});
494 $subnet = &General::iporsubtocidr($subnet);
495 $fwdfwsettings{'isip'}='on';
496 }
497 #check if only ip
498 if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
499 $ip=$fwdfwsettings{'src_addr'};
500 $subnet = '32';
501 $fwdfwsettings{'isip'}='on';
502 }
503
504 if ($fwdfwsettings{'isip'} ne 'on'){
505 if (&General::validmac($fwdfwsettings{'src_addr'})){
506 $fwdfwsettings{'ismac'}='on';
507 }
508 }
509 if ($fwdfwsettings{'isip'} eq 'on'){
510 ##check if ip is valid
511 if (! &General::validip($ip)){
512 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
513 return $errormessage;
514 }
515 #check and form valid IP
516 $ip=&General::ip2dec($ip);
517 $ip=&General::dec2ip($ip);
518 #check if net or broadcast
519 $fwdfwsettings{'src_addr'}="$ip/$subnet";
520 if(!&General::validipandmask($fwdfwsettings{'src_addr'})){
521 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
522 return $errormessage;
523 }
524 }
525 if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){
526 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
527 return $errormessage;
528 }
529 }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
530 $errormessage.=$Lang::tr{'fwdfw err nosrcip'};
531 return $errormessage;
532 }
533
534 #check empty fields
535 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err nosrc'}."<br>";}
536 if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){
537 my @parts=split(",",$fwdfwsettings{'SRC_PORT'});
538 my @values=();
539 foreach (@parts){
540 chomp($_);
541 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
542 my $check;
543 #change dashes with :
544 $_=~ tr/-/:/;
545 if ($_ eq "*") {
546 push(@values,"1:65535");
547 $check='on';
548 }
549 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
550 push(@values,"1:$2");
551 $check='on';
552 }
553 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/ ) {
554 push(@values,"$1:65535");
555 $check='on'
556 }
557 $errormessage .= &General::validportrange($_, 'destination');
558 if(!$check){
559 push (@values,$_);
560 }
561 }else{
562 if (&General::validport($_)){
563 push (@values,$_);
564 }else{
565
566 }
567 }
568 }
569 $fwdfwsettings{'SRC_PORT'}=join("|",@values);
570 }
571 return $errormessage;
572 }
573 sub checktarget
574 {
575 my ($ip,$subnet);
576 &General::readhasharray("$configsrv", \%customservice);
577 #check DNAT settings (has to be single Host and single Port or portrange)
578 if ($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat'){
579 if($fwdfwsettings{'grp2'} eq 'tgt_addr' || $fwdfwsettings{'grp2'} eq 'cust_host_tgt' || $fwdfwsettings{'grp2'} eq 'ovpn_host_tgt'){
580 if ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'dnatport'} eq ''){
581 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
582 return $errormessage;
583 }
584 #check if manual ip is a single Host (if set)
585 if ($fwdfwsettings{'grp2'} eq 'tgt_addr'){
586 my @tmp= split (/\./,$fwdfwsettings{$fwdfwsettings{'grp2'}});
587 my @tmp1= split ("/",$tmp[3]);
588 if (($tmp1[0] eq "0") || ($tmp1[0] eq "255"))
589 {
590 $errormessage=$Lang::tr{'fwdfw dnat error'}."<br>";
591 return $errormessage;
592 }
593 }
594 #check if Port is a single Port or portrange
595 if ($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
596 if(($fwdfwsettings{'PROT'} ne 'TCP'|| $fwdfwsettings{'PROT'} ne 'UDP') && $fwdfwsettings{'TGT_PORT'} eq ''){
597 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
598 return $errormessage;
599 }
600 if (($fwdfwsettings{'PROT'} eq 'TCP'|| $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport($fwdfwsettings{'TGT_PORT'})){
601 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
602 return $errormessage;
603 }
604 }
605 }else{
606 $errormessage=$Lang::tr{'fwdfw dnat error'}."<br>";
607 return $errormessage;
608 }
609 }
610 if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
611 #check if ip with subnet
612 if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?)$/) {
613 ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
614 $subnet = &General::iporsubtocidr($subnet);
615 }
616 #check if only ip
617 if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
618 $ip=$fwdfwsettings{'tgt_addr'};
619 $subnet='32';
620 }
621 #check if ip is valid
622 if (! &General::validip($ip)){
623 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
624 return $errormessage;
625 }
626 #check and form valid IP
627 $ip=&General::ip2dec($ip);
628 $ip=&General::dec2ip($ip);
629 $fwdfwsettings{'tgt_addr'}="$ip/$subnet";
630 if(!&General::validipandmask($fwdfwsettings{'tgt_addr'})){
631 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
632 return $errormessage;
633 }
634 }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
635 $errormessage.=$Lang::tr{'fwdfw err notgtip'};
636 return $errormessage;
637 }
638 #check empty fields
639 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err notgt'}."<br>";}
640 #check tgt services
641 if ($fwdfwsettings{'USESRV'} eq 'ON'){
642 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
643 $fwdfwsettings{'TGT_PROT'}='';
644 $fwdfwsettings{'ICMP_TGT'}='';
645 $fwdfwsettings{'TGT_PORT'}='';
646 }
647 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
648 $fwdfwsettings{'TGT_PROT'}='';
649 $fwdfwsettings{'ICMP_TGT'}='';
650 $fwdfwsettings{'TGT_PORT'}='';
651 #check target service
652 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){
653 $errormessage.=$Lang::tr{'fwdfw err tgt_grp'};
654 }
655 }
656 if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
657 if ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP'){
658 if ($fwdfwsettings{'TGT_PORT'} ne ''){
659 if ($fwdfwsettings{'TGT_PORT'} =~ "," && $fwdfwsettings{'USE_NAT'} && $fwdfwsettings{'nat'} eq 'dnat') {
660 $errormessage=$Lang::tr{'fwdfw dnat porterr'}."<br>";
661 return $errormessage;
662 }
663 my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
664 my @values=();
665 foreach (@parts){
666 chomp($_);
667 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
668 my $check;
669 #change dashes with :
670 $_=~ tr/-/:/;
671 if ($_ eq "*") {
672 push(@values,"1:65535");
673 $check='on';
674 }
675 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
676 push(@values,"1:$2");
677 $check='on';
678 }
679 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
680 push(@values,"$1:65535");
681 $check='on'
682 }
683 $errormessage .= &General::validportrange($_, 'destination');
684 if(!$check){
685 push (@values,$_);
686 }
687 }else{
688 if (&General::validport($_)){
689 push (@values,$_);
690 }else{
691 }
692 }
693 }
694 $fwdfwsettings{'TGT_PORT'}=join("|",@values);
695 }
696 }elsif ($fwdfwsettings{'PROT'} eq 'GRE'){
697 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
698 $fwdfwsettings{'TGT_PORT'} = '';
699 $fwdfwsettings{'ICMP_TGT'} = '';
700 }elsif ($fwdfwsettings{'PROT'} eq 'ESP'){
701 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
702 $fwdfwsettings{'TGT_PORT'} = '';
703 $fwdfwsettings{'ICMP_TGT'}='';
704 }elsif ($fwdfwsettings{'PROT'} eq 'AH'){
705 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
706 $fwdfwsettings{'TGT_PORT'} = '';
707 $fwdfwsettings{'ICMP_TGT'}='';
708 }elsif ($fwdfwsettings{'PROT'} eq 'ICMP'){
709 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
710 $fwdfwsettings{'TGT_PORT'} = '';
711 }
712 }
713 }
714 #check targetport
715 if ($fwdfwsettings{'USESRV'} ne 'ON'){
716 $fwdfwsettings{'grp3'}='';
717 $fwdfwsettings{$fwdfwsettings{'grp3'}}='';
718 $fwdfwsettings{'ICMP_TGT'}='';
719 }
720 #check timeframe
721 if($fwdfwsettings{'TIME'} eq 'ON'){
722 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 ''){
723 $errormessage=$Lang::tr{'fwdfw err time'};
724 return $errormessage;
725 }
726 }
727 return $errormessage;
728 }
729 sub check_natport
730 {
731 my $val=shift;
732 if($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
733 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\-(\d+)$/) {
734 $fwdfwsettings{'dnatport'} =~ tr/-/:/;
735 if ($fwdfwsettings{'dnatport'} eq "*") {
736 $fwdfwsettings{'dnatport'}="1:65535";
737 }
738 if ($fwdfwsettings{'dnatport'} =~ /^(\D)\:(\d+)$/) {
739 $fwdfwsettings{'dnatport'} = "1:$2";
740 }
741 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\:(\D)$/) {
742 $fwdfwsettings{'dnatport'} ="$1:65535";
743 }
744 }
745 return 1;
746 }
747 if ($val =~ "," || $val>65536 || $val<0){
748 return 0;
749 }
750 return 1;
751 }
752 sub checkrule
753 {
754 #check valid port for NAT
755 if($fwdfwsettings{'USE_NAT'} eq 'ON'){
756 #if no port is given in nat area, take target host port
757 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$fwdfwsettings{'TGT_PORT'};}
758 #check if port given in nat area is a single valid port or portrange
759 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport($fwdfwsettings{'dnatport'})){
760 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
761 }elsif($fwdfwsettings{'USESRV'} eq 'ON' && $fwdfwsettings{'grp3'} eq 'cust_srv'){
762 my $custsrvport;
763 #get servcie Protocol and Port
764 foreach my $key (sort keys %customservice){
765 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]){
766 if ($customservice{$key}[2] ne 'TCP' && $customservice{$key}[2] ne 'UDP'){
767 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
768 }
769 $custsrvport= $customservice{$key}[1];
770 }
771 }
772 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$custsrvport;}
773 }
774 #check if DNAT port is multiple
775 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
776 my @parts=split(",",$fwdfwsettings{'dnatport'});
777 my @values=();
778 foreach (@parts){
779 chomp($_);
780 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
781 my $check;
782 #change dashes with :
783 $_=~ tr/-/:/;
784 if ($_ eq "*") {
785 push(@values,"1:65535");
786 $check='on';
787 }
788 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
789 push(@values,"1:$2");
790 $check='on';
791 }
792 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
793 push(@values,"$1:65535");
794 $check='on'
795 }
796 $errormessage .= &General::validportrange($_, 'destination');
797 if(!$check){
798 push (@values,$_);
799 }
800 }else{
801 if (&General::validport($_)){
802 push (@values,$_);
803 }else{
804
805 }
806 }
807 }
808 $fwdfwsettings{'dnatport'}=join("|",@values);
809 }
810 }
811 #check valid remark
812 if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
813 $errormessage.=$Lang::tr{'fwdfw err remark'}."<br>";
814 }
815 #check if source and target identical
816 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL'){
817 $errormessage=$Lang::tr{'fwdfw err same'};
818 return $errormessage;
819 }
820 #get source and targetip address if possible
821 my ($sip,$scidr,$tip,$tcidr);
822 ($sip,$scidr)=&get_ip("src","grp1");
823 ($tip,$tcidr)=&get_ip("tgt","grp2");
824 #check same iprange in source and target
825 if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){
826 my $networkip1=&General::getnetworkip($sip,$scidr);
827 my $networkip2=&General::getnetworkip($tip,$tcidr);
828 if ($scidr gt $tcidr){
829 if ( &General::IpInSubnet($networkip1,$tip,&General::iporsubtodec($tcidr))){
830 $errormessage.=$Lang::tr{'fwdfw err samesub'};
831 }
832 }elsif($scidr eq $tcidr && $scidr eq '32'){
833 my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1);
834 my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2);
835 if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){
836 $hint=$Lang::tr{'fwdfw hint ip1'}."<br>";
837 $hint.=$Lang::tr{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>";
838 }
839 }else{
840 if ( &General::IpInSubnet($networkip2,$sip,&General::iporsubtodec($scidr)) ){
841 $errormessage.=$Lang::tr{'fwdfw err samesub'};
842 }
843 }
844 }
845 #When using source- or targetport, the protocol has to be TCP or UDP
846 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')){
847 $errormessage.=$Lang::tr{'fwdfw err prot_port1'};
848 return;
849 }
850 #when icmp selected, no targetport allowed
851 if (($fwdfwsettings{'PROT'} ne '' && $fwdfwsettings{'PROT'} ne 'TCP' && $fwdfwsettings{'PROT'} ne 'UDP' && $fwdfwsettings{'PROT'} ne 'template') && ($fwdfwsettings{'USESRV'} eq 'ON' || $fwdfwsettings{'USE_SRC_PORT'} eq 'ON')){
852 $errormessage.=$Lang::tr{'fwdfw err prot_port'};
853 return;
854 }
855 #change protocol if prot not equal dest single service
856 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
857 foreach my $key (sort keys %customservice){
858 if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){
859 if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){
860 $fwdfwsettings{'PROT'} = $customservice{$key}[2];
861 last;
862 }
863 }
864 }
865 }
866 #check source and destination protocol if source manual and dest servicegroup
867 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
868 $fwdfwsettings{'PROT'} = '';
869 }
870 #ATTENTION: $fwdfwsetting{'TGT_PROT'} deprecated since 30.09.2013
871 $fwdfwsettings{'TGT_PROT'}=''; #Set field empty (deprecated)
872 #Check ICMP Types
873 if ($fwdfwsettings{'PROT'} eq 'ICMP'){
874 $fwdfwsettings{'USE_SRC_PORT'}='';
875 $fwdfwsettings{'SRC_PORT'}='';
876 #$fwdfwsettings{'USESRV'}='';
877 $fwdfwsettings{'TGT_PORT'}='';
878 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
879 foreach my $key (keys %icmptypes){
880 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){
881 $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]";
882 }
883 }
884 }elsif($fwdfwsettings{'PROT'} eq 'GRE'){
885 $fwdfwsettings{'USE_SRC_PORT'}='';
886 $fwdfwsettings{'SRC_PORT'}='';
887 $fwdfwsettings{'ICMP_TYPES'}='';
888 $fwdfwsettings{'USESRV'}='';
889 $fwdfwsettings{'TGT_PORT'}='';
890 }elsif($fwdfwsettings{'PROT'} eq 'ESP'){
891 $fwdfwsettings{'USE_SRC_PORT'}='';
892 $fwdfwsettings{'SRC_PORT'}='';
893 $fwdfwsettings{'ICMP_TYPES'}='';
894 $fwdfwsettings{'USESRV'}='';
895 $fwdfwsettings{'TGT_PORT'}='';
896 }elsif($fwdfwsettings{'PROT'} eq 'AH'){
897 $fwdfwsettings{'USE_SRC_PORT'}='';
898 $fwdfwsettings{'SRC_PORT'}='';
899 $fwdfwsettings{'ICMP_TYPES'}='';
900 $fwdfwsettings{'USESRV'}='';
901 $fwdfwsettings{'TGT_PORT'}='';
902 }elsif($fwdfwsettings{'PROT'} eq 'IGMP'){
903 $fwdfwsettings{'USE_SRC_PORT'}='';
904 $fwdfwsettings{'SRC_PORT'}='';
905 $fwdfwsettings{'ICMP_TYPES'}='';
906 $fwdfwsettings{'USESRV'}='';
907 $fwdfwsettings{'TGT_PORT'}='';
908 }elsif($fwdfwsettings{'PROT'} ne 'TCP' && $fwdfwsettings{'PROT'} ne 'UDP' && $fwdfwsettings{'PROT'} ne 'ICMP'){
909 $fwdfwsettings{'ICMP_TYPES'}='';
910 $fwdfwsettings{'PROT'} = '';
911 }elsif($fwdfwsettings{'PROT'} ne 'ICMP'){
912 $fwdfwsettings{'ICMP_TYPES'}='';
913 }
914 }
915 sub checkcounter
916 {
917 my ($base1,$val1,$base2,$val2) = @_;
918
919 if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){
920 &dec_counter($confignet,\%customnetwork,$val1);
921 }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){
922 &dec_counter($confighost,\%customhost,$val1);
923 }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){
924 &dec_counter($configgrp,\%customgrp,$val1);
925 }elsif($base1 eq 'cust_srv'){
926 &dec_counter($configsrv,\%customservice,$val1);
927 }elsif($base1 eq 'cust_srvgrp'){
928 &dec_counter($configsrvgrp,\%customservicegrp,$val1);
929 }
930
931 if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){
932 &inc_counter($confignet,\%customnetwork,$val2);
933 }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){
934 &inc_counter($confighost,\%customhost,$val2);
935 }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){
936 &inc_counter($configgrp,\%customgrp,$val2);
937 }elsif($base2 eq 'cust_srv'){
938 &inc_counter($configsrv,\%customservice,$val2);
939 }elsif($base2 eq 'cust_srvgrp'){
940 &inc_counter($configsrvgrp,\%customservicegrp,$val2);
941 }
942 }
943 sub checkvpn
944 {
945 my $ip=shift;
946 #Test if manual IP is part of static OpenVPN networks
947 &General::readhasharray("$configccdnet", \%ccdnet);
948 foreach my $key (sort keys %ccdnet){
949 my ($vpnip,$vpnsubnet) = split ("/",$ccdnet{$key}[1]);
950 my $sub=&General::iporsubtodec($vpnsubnet);
951 if (&General::IpInSubnet($ip,$vpnip,$sub)){
952 return 0;
953 }
954 }
955 # A Test if manual ip is part of dynamic openvpn subnet is made in getcolor
956 # because if one creates a custom host with the ip, we need to check the color there!
957 # It does not make sense to check this here
958
959 # Test if manual IP is part of an OpenVPN N2N subnet does also not make sense here
960 # Is also checked in getcolor
961
962 # Test if manual ip is part of an IPsec Network is also checked in getcolor
963 return 1;
964 }
965 sub checkvpncolor
966 {
967
968 }
969 sub deleterule
970 {
971 my %delhash=();
972 &General::readhasharray($fwdfwsettings{'config'}, \%delhash);
973 foreach my $key (sort {$a <=> $b} keys %delhash){
974 if ($key == $fwdfwsettings{'key'}){
975 #check hosts/net and groups
976 &checkcounter($delhash{$key}[3],$delhash{$key}[4],,);
977 &checkcounter($delhash{$key}[5],$delhash{$key}[6],,);
978 #check services and groups
979 if ($delhash{$key}[11] eq 'ON'){
980 &checkcounter($delhash{$key}[14],$delhash{$key}[15],,);
981 }
982 }
983 if ($key >= $fwdfwsettings{'key'}) {
984 my $next = $key + 1;
985 if (exists $delhash{$next}) {
986 foreach my $i (0 .. $#{$delhash{$next}}) {
987 $delhash{$key}[$i] = $delhash{$next}[$i];
988 }
989 }
990 }
991 }
992 # Remove the very last entry.
993 my $last_key = (sort {$a <=> $b} keys %delhash)[-1];
994 delete $delhash{$last_key};
995
996 &General::writehasharray($fwdfwsettings{'config'}, \%delhash);
997 &rules;
998
999 if($fwdfwsettings{'nobase'} ne 'on'){
1000 &base;
1001 }
1002 }
1003 sub disable_rule
1004 {
1005 my $key1=shift;
1006 &General::readhasharray("$configfwdfw", \%configfwdfw);
1007 foreach my $key (sort keys %configfwdfw){
1008 if ($key eq $key1 ){
1009 if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';}
1010 }
1011 }
1012 &General::writehasharray("$configfwdfw", \%configfwdfw);
1013 &rules;
1014 }
1015 sub dec_counter
1016 {
1017 my $config=shift;
1018 my %hash=%{(shift)};
1019 my $val=shift;
1020 my $pos;
1021 &General::readhasharray($config, \%hash);
1022 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
1023 if($hash{$key}[0] eq $val){
1024 $pos=$#{$hash{$key}};
1025 $hash{$key}[$pos] = $hash{$key}[$pos]-1;
1026 }
1027 }
1028 &General::writehasharray($config, \%hash);
1029 }
1030 sub error
1031 {
1032 if ($errormessage) {
1033 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1034 print "<class name='base'>$errormessage\n";
1035 print "&nbsp;</class>\n";
1036 &Header::closebox();
1037 print"<hr>";
1038 }
1039 }
1040 sub fillselect
1041 {
1042 my %hash=%{(shift)};
1043 my $val=shift;
1044 my $key;
1045 foreach my $key (sort { ncmp($hash{$a}[0],$hash{$b}[0]) } keys %hash){
1046 if($hash{$key}[0] eq $val){
1047 print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>";
1048 }else{
1049 print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>";
1050 }
1051 }
1052 }
1053 sub gen_dd_block
1054 {
1055 my $srctgt = shift;
1056 my $grp=shift;
1057 my $helper='';
1058 my $show='';
1059 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1060 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1061 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1062 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1063 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1064 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1065 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1066 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1067 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1068 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1069 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1070 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1071 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1072 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1073 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1074 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1075 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1076 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
1077 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1078 print<<END;
1079 <table width='100%' border='0'>
1080 <tr><td width='50%' valign='top'>
1081 <table width='100%' border='0'>
1082 <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;'>
1083 END
1084 foreach my $network (sort keys %defaultNetworks)
1085 {
1086 next if($defaultNetworks{$network}{'NAME'} eq "RED" && $srctgt eq 'src');
1087 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1088 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1089 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $defaultNetworks{$network}{'NAME'});
1090 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
1091 my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK";
1092 my $defsub1=&General::subtocidr($ifaces{$defsub});
1093 $ifaces{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED');
1094 if ($ifaces{$defnet}){
1095 print ">$network ($ifaces{$defnet}/$defsub1)</option>";
1096 }else{
1097 print ">$network</option>";
1098 }
1099 }
1100 print"</select></td></tr>";
1101 #custom networks
1102 if (! -z $confignet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1103 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;'>";
1104 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{$grp}});
1105 print"</select></td>";
1106 }
1107 #custom hosts
1108 if (! -z $confighost || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1109 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;'>";
1110 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{$grp}});
1111 print"</select></td>";
1112 }
1113 #custom groups
1114 if (! -z $configgrp || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1115 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;'>";
1116 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } keys %customgrp) {
1117 if($helper ne $customgrp{$key}[0]){
1118 print"<option ";
1119 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $customgrp{$key}[0]);
1120 print ">$customgrp{$key}[0]</option>";
1121 }
1122 $helper=$customgrp{$key}[0];
1123 }
1124 print"</select></td>";
1125 }
1126 #End left table. start right table (vpn)
1127 print"</tr></table></td><td valign='top'><table width='100%' border='0'><tr>";
1128 # CCD networks
1129 if( ! -z $configccdnet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1130 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;'>";
1131 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{$grp}});
1132 print"</select></td></tr>";
1133 }
1134 #OVPN CCD Hosts
1135 foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost){
1136 if ($ccdhost{$key}[33] ne '' ){
1137 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 '');
1138 $show='1';
1139 print "<option value='$ccdhost{$key}[1]'";
1140 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1141 print ">$ccdhost{$key}[1]</option>";
1142 }
1143 }
1144 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1145 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>" ;
1146 }
1147 if ($show eq '1'){$show='';print"</select></td></tr>";}
1148 #OVPN N2N
1149 foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost){
1150 if ($ccdhost{$key}[3] eq 'net'){
1151 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 '');
1152 $show='1';
1153 print "<option value='$ccdhost{$key}[1]'";
1154 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1155 print ">$ccdhost{$key}[1]</option>";
1156 }
1157 }
1158 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1159 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>" ;
1160 }
1161 if ($show eq '1'){$show='';print"</select></td></tr>";}
1162 #IPsec netze
1163 foreach my $key (sort { ncmp($ipsecconf{$a}[1],$ipsecconf{$b}[1]) } keys %ipsecconf) {
1164 if ($ipsecconf{$key}[3] eq 'net' || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1165 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 '');
1166 $show='1';
1167 print "<option ";
1168 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ipsecconf{$key}[1]);
1169 print ">$ipsecconf{$key}[1]</option>";
1170 }
1171 }
1172 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1173 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>";
1174 }
1175 if ($show eq '1'){$show='';print"</select></td></tr>";}
1176
1177 print"</table>";
1178 print"</td></tr></table><br>";
1179 }
1180 sub get_ip
1181 {
1182 my $val=shift;
1183 my $grp =shift;
1184 my $a;
1185 my $b;
1186 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1187 if ($fwdfwsettings{$grp} ne $Lang::tr{'fwhost any'}){
1188 if ($fwdfwsettings{$grp} eq $val.'_addr'){
1189 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
1190 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
1191 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
1192 $a=$netsettings{'GREEN_NETADDRESS'};
1193 $b=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'});
1194 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
1195 $a=$netsettings{'ORANGE_NETADDRESS'};
1196 $b=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'});
1197 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
1198 $a=$netsettings{'BLUE_NETADDRESS'};
1199 $b=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'});
1200 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
1201 &General::readhash("$configovpn",\%ovpnsettings);
1202 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
1203 $b=&General::iporsubtocidr($b);
1204 }
1205 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
1206 &General::readhasharray("$confignet", \%customnetwork);
1207 foreach my $key (keys %customnetwork){
1208 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1209 $a=$customnetwork{$key}[1];
1210 $b=&General::iporsubtocidr($customnetwork{$key}[2]);
1211 }
1212 }
1213 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
1214 &General::readhasharray("$confighost", \%customhost);
1215 foreach my $key (keys %customhost){
1216 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1217 if ($customhost{$key}[1] eq 'ip'){
1218 ($a,$b)=split (/\//,$customhost{$key}[2]);
1219 $b=&General::iporsubtocidr($b);
1220 }else{
1221 if ($grp eq 'grp2'){
1222 $errormessage=$Lang::tr{'fwdfw err tgt_mac'};
1223 }
1224 }
1225 }
1226 }
1227 }
1228 }
1229 return $a,$b;
1230 }
1231 sub get_name
1232 {
1233 my $val=shift;
1234 &General::setup_default_networks(\%defaultNetworks);
1235 foreach my $network (sort keys %defaultNetworks)
1236 {
1237 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1238 }
1239 }
1240 sub getsrcport
1241 {
1242 my %hash=%{(shift)};
1243 my $key=shift;
1244 if($hash{$key}[7] eq 'ON' && $hash{$key}[10]){
1245 $hash{$key}[10]=~ s/\|/,/g;
1246 print": $hash{$key}[10]";
1247 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
1248 print": <br>$hash{$key}[9] ";
1249 }
1250 }
1251 sub gettgtport
1252 {
1253 my %hash=%{(shift)};
1254 my $key=shift;
1255 my $service;
1256 my $prot;
1257 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1258 if($hash{$key}[14] eq 'cust_srv'){
1259 &General::readhasharray("$configsrv", \%customservice);
1260 foreach my $i (sort keys %customservice){
1261 if($customservice{$i}[0] eq $hash{$key}[15]){
1262 $service = $customservice{$i}[0];
1263 }
1264 }
1265 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
1266 $service=$hash{$key}[15];
1267 }elsif($hash{$key}[14] eq 'TGT_PORT'){
1268 $hash{$key}[15]=~ s/\|/,/g;
1269 $service=$hash{$key}[15];
1270 }
1271 if($service){
1272 print": $service";
1273 }
1274 }
1275 }
1276 sub get_serviceports
1277 {
1278 my $type=shift;
1279 my $name=shift;
1280 &General::readhasharray("$configsrv", \%customservice);
1281 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1282 my $tcp;
1283 my $udp;
1284 my $icmp;
1285 @protocols=();
1286 if($type eq 'service'){
1287 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1288 if ($customservice{$key}[0] eq $name){
1289 push (@protocols,$customservice{$key}[2]);
1290 }
1291 }
1292 }elsif($type eq 'group'){
1293 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1294 if ($customservicegrp{$key}[0] eq $name){
1295 foreach my $key1 (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1296 if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
1297 if($customservice{$key1}[2] eq 'TCP'){
1298 $tcp='TCP';
1299 }elsif($customservice{$key1}[2] eq 'ICMP'){
1300 $icmp='ICMP';
1301 }elsif($customservice{$key1}[2] eq 'UDP'){
1302 $udp='UDP';
1303 }
1304 }
1305 }
1306 }
1307 }
1308 }
1309 if($tcp && $udp && $icmp){
1310 push (@protocols,"TCP,UDP, <br>ICMP");
1311 return @protocols;
1312 }
1313 if($tcp){
1314 push (@protocols,"TCP");
1315 }
1316 if($udp){
1317 push (@protocols,"UDP");
1318 }
1319 if($icmp){
1320 push (@protocols,"ICMP");
1321 }
1322 return @protocols;
1323 }
1324 sub getcolor
1325 {
1326 my $nettype=shift;
1327 my $val=shift;
1328 my $hash=shift;
1329 if($optionsfw{'SHOWCOLORS'} eq 'on'){
1330 #custom Hosts
1331 if ($nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1332 foreach my $key (sort keys %$hash){
1333 if ($$hash{$key}[0] eq $val){
1334 $val=$$hash{$key}[2];
1335 }
1336 }
1337 }
1338 #standard networks
1339 if ($val eq 'GREEN'){
1340 $tdcolor="style='background-color: $Header::colourgreen;color:white;'";
1341 return;
1342 }elsif ($val eq 'ORANGE'){
1343 $tdcolor="style='background-color: $Header::colourorange;color:white;'";
1344 return;
1345 }elsif ($val eq 'BLUE'){
1346 $tdcolor="style='background-color: $Header::colourblue;color:white;'";
1347 return;
1348 }elsif ($val eq 'RED' ||$val eq 'RED1' ){
1349 $tdcolor="style='background-color: $Header::colourred;color:white;'";
1350 return;
1351 }elsif ($val eq 'IPFire' ){
1352 $tdcolor="style='background-color: $Header::colourred;color:white;'";
1353 return;
1354 }elsif($val =~ /^(.*?)\/(.*?)$/){
1355 my ($sip,$scidr) = split ("/",$val);
1356 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1357 $tdcolor="style='background-color: $Header::colourorange;color:white;'";
1358 return;
1359 }
1360 if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1361 $tdcolor="style='background-color: $Header::colourgreen;color:white;'";
1362 return;
1363 }
1364 if ( &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
1365 $tdcolor="style='background-color: $Header::colourblue;color:white;'";
1366 return;
1367 }
1368 }elsif ($val eq 'Default IP'){
1369 $tdcolor="style='background-color: $Header::colourred;color:white;'";
1370 return;
1371 }
1372 #Check if a manual IP or custom host is part of a VPN
1373 if ($nettype eq 'src_addr' || $nettype eq 'tgt_addr' || $nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1374 #Check if IP is part of OpenVPN dynamic subnet
1375 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
1376 my ($c,$d) = split("/",$val);
1377 if (&General::IpInSubnet($c,$a,$b)){
1378 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1379 return;
1380 }
1381 #Check if IP is part of OpenVPN static subnet
1382 foreach my $key (sort keys %ccdnet){
1383 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1384 $b =&General::iporsubtodec($b);
1385 if (&General::IpInSubnet($c,$a,$b)){
1386 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1387 return;
1388 }
1389 }
1390 #Check if IP is part of OpenVPN N2N subnet
1391 foreach my $key (sort keys %ccdhost){
1392 if ($ccdhost{$key}[3] eq 'net'){
1393 my ($a,$b) = split("/",$ccdhost{$key}[11]);
1394 if (&General::IpInSubnet($c,$a,$b)){
1395 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1396 return;
1397 }
1398 }
1399 }
1400 #Check if IP is part of IPsec RW network
1401 if ($ipsecsettings{'RW_NET'} ne ''){
1402 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1403 $b=&General::iporsubtodec($b);
1404 if (&General::IpInSubnet($c,$a,$b)){
1405 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1406 return;
1407 }
1408 }
1409 #Check if IP is part of a IPsec N2N network
1410 foreach my $key (sort keys %ipsecconf){
1411 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1412 if (&General::IpInSubnet($c,$a,$b)){
1413 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1414 return;
1415 }
1416 }
1417 }
1418 #VPN networks
1419 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'){
1420 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1421 return;
1422 }
1423 if ($nettype eq 'ipsec_net_src' || $nettype eq 'ipsec_net_tgt'){
1424 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1425 return;
1426 }
1427 #ALIASE
1428 foreach my $alias (sort keys %aliases)
1429 {
1430 if ($val eq $alias){
1431 $tdcolor="style='background-color:$Header::colourred;color:white;'";
1432 return;
1433 }
1434 }
1435 }
1436 $tdcolor='';
1437 return;
1438 }
1439 sub hint
1440 {
1441 if ($hint) {
1442 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1443 print "<class name='base'>$hint\n";
1444 print "&nbsp;</class>\n";
1445 &Header::closebox();
1446 print"<hr>";
1447 }
1448 }
1449 sub inc_counter
1450 {
1451 my $config=shift;
1452 my %hash=%{(shift)};
1453 my $val=shift;
1454 my $pos;
1455
1456 &General::readhasharray($config, \%hash);
1457 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
1458 if($hash{$key}[0] eq $val){
1459 $pos=$#{$hash{$key}};
1460 $hash{$key}[$pos] = $hash{$key}[$pos]+1;
1461 }
1462 }
1463 &General::writehasharray($config, \%hash);
1464 }
1465 sub newrule
1466 {
1467 &error;
1468 &General::setup_default_networks(\%defaultNetworks);
1469 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1470 #read all configfiles
1471 &General::readhasharray("$configccdnet", \%ccdnet);
1472 &General::readhasharray("$confignet", \%customnetwork);
1473 &General::readhasharray("$configccdhost", \%ccdhost);
1474 &General::readhasharray("$confighost", \%customhost);
1475 &General::readhasharray("$configccdhost", \%ccdhost);
1476 &General::readhasharray("$configgrp", \%customgrp);
1477 &General::readhasharray("$configipsec", \%ipsecconf);
1478 &General::get_aliases(\%aliases);
1479 my %checked=();
1480 my $helper;
1481 my $sum=0;
1482 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
1483 my $config=$fwdfwsettings{'config'};
1484 my %hash=();
1485 #Get Red IP-ADDRESS
1486 open (CONN1,"/var/ipfire/red/local-ipaddress");
1487 my $redip = <CONN1>;
1488 close(CONN1);
1489 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1490 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1491 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1492 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1493 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1494 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1495 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1496 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1497 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1498 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1499 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1500 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1501 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1502 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1503 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1504 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1505 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1506 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1507 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1508 $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
1509 #check if update and get values
1510 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
1511 &General::readhasharray("$config", \%hash);
1512 foreach my $key (sort keys %hash){
1513 $sum++;
1514 if ($key eq $fwdfwsettings{'key'}){
1515 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
1516 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
1517 $fwdfwsettings{'chain'} = $hash{$key}[1];
1518 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1519 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1520 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1521 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1522 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1523 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1524 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1525 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1526 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1527 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1528 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1529 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1530 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1531 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1532 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1533 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1534 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1535 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1536 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1537 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1538 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1539 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1540 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1541 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1542 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1543 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
1544 $fwdfwsettings{'USE_NAT'} = $hash{$key}[28];
1545 $fwdfwsettings{'nat'} = $hash{$key}[31]; #changed order
1546 $fwdfwsettings{$fwdfwsettings{'nat'}} = $hash{$key}[29];
1547 $fwdfwsettings{'dnatport'} = $hash{$key}[30];
1548 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1549 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1550 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1551 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1552 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1553 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1554 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1555 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1556 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1557 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1558 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1559 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1560 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1561 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1562 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1563 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1564 $checked{'nat'}{$fwdfwsettings{'nat'}} = 'CHECKED';
1565 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1566 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1567 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1568 $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
1569 $selected{'dnat'}{$fwdfwsettings{$fwdfwsettings{'nat'}}} ='selected';
1570 $selected{'snat'}{$fwdfwsettings{$fwdfwsettings{'nat'}}} ='selected';
1571 }
1572 }
1573 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1574 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1575 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1576 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1577 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1578 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1579 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1580 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1581 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1582 $fwdfwsettings{'oldruletype'}=$fwdfwsettings{'chain'};
1583 #check if manual ip (source) is orange network
1584 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1585 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1586 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1587 $fwdfwsettings{'oldorange'} ='on';
1588 }
1589 }
1590 }else{
1591 $fwdfwsettings{'ACTIVE'}='ON';
1592 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1593 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1594 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1595 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1596 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1597 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1598 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1599 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1600 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1601 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1602 #check if manual ip (source) is orange network
1603 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1604 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1605 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1606 $fwdfwsettings{'oldorange'} ='on';
1607 }
1608 }
1609 }
1610 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
1611 &Header::closebox();
1612 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'});
1613 #------SOURCE-------------------------------------------------------
1614 print "<form method='post'>";
1615 print<<END;
1616 <table width='100%' border='0'>
1617 <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>
1618 END
1619 print"<td align='right'><select name='ipfire_src' style='width:200px;'>";
1620 print "<option value='ALL' $selected{'ipfire_src'}{'ALL'}>$Lang::tr{'all'}</option>";
1621 print "<option value='GREEN' $selected{'ipfire_src'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
1622 print "<option value='ORANGE' $selected{'ipfire_src'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if (&Header::orange_used());
1623 print "<option value='BLUE' $selected{'ipfire_src'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>" if (&Header::blue_used());
1624 print "<option value='RED1' $selected{'ipfire_src'}{'RED1'}>$Lang::tr{'red1'} ($redip)" if ($redip);
1625 if (! -z "${General::swroot}/ethernet/aliases"){
1626 foreach my $alias (sort keys %aliases)
1627 {
1628 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1629 }
1630 }
1631 print<<END;
1632 </select></td></tr>
1633 <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
1634 END
1635 &gen_dd_block('src','grp1');
1636 print"<hr>";
1637 &Header::closebox();
1638 #---SNAT / DNAT ------------------------------------------------
1639 &Header::openbox('100%', 'left', 'NAT');
1640 print<<END;
1641 <div id="nat"><table width='100%' border='0'>
1642 <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>
1643 <div id="natpart" class="noscript">
1644 <table width='100%' border='0'><tr>
1645 <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>
1646 END
1647 print"<td width='8%'>Firewall: </td><td width='20%' align='right'><select name='dnat' style='width:140px;'>";
1648 print "<option value='ALL' $selected{'dnat'}{$Lang::tr{'all'}}>$Lang::tr{'all'}</option>";
1649 print "<option value='Default IP' $selected{'dnat'}{'Default IP'}>Default IP</option>";
1650 foreach my $alias (sort keys %aliases)
1651 {
1652 print "<option value='$alias' $selected{'dnat'}{$alias}>$alias</option>";
1653 }
1654 print"</select></td></tr>";
1655 $fwdfwsettings{'dnatport'}=~ tr/|/,/;
1656 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>";
1657 print"<tr><td colspan='8'><br></td></tr>";
1658 #SNAT
1659 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>";
1660 print"<td width='8%'>Firewall: </td><td width='20%' align='right'><select name='snat' style='width:140px;'>";
1661 foreach my $alias (sort keys %aliases)
1662 {
1663 print "<option value='$alias' $selected{'snat'}{$alias}>$alias</option>";
1664 }
1665 foreach my $network (sort keys %defaultNetworks)
1666 {
1667 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1668 next if($defaultNetworks{$network}{'NAME'} eq "ALL");
1669 next if($defaultNetworks{$network}{'NAME'} =~ /OpenVPN/i);
1670 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1671 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'nat'}} eq $defaultNetworks{$network}{'NAME'});
1672 print ">$network</option>";
1673 }
1674 print"</select></td></tr></table>";
1675 print"</div><br><hr>";
1676 &Header::closebox();
1677 #---TARGET------------------------------------------------------
1678 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw target'});
1679 print<<END;
1680 <table width='100%' border='0'>
1681 <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>
1682 END
1683 print"<td align='right'><select name='ipfire' style='width:200px;'>";
1684 print "<option value='ALL' $selected{'ipfire'}{'ALL'}>$Lang::tr{'all'}</option>";
1685 print "<option value='GREEN' $selected{'ipfire'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
1686 print "<option value='ORANGE' $selected{'ipfire'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if (&Header::orange_used());
1687 print "<option value='BLUE' $selected{'ipfire'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>"if (&Header::blue_used());
1688 print "<option value='RED1' $selected{'ipfire'}{'RED1'}>$Lang::tr{'red1'} ($redip)" if ($redip);
1689 if (! -z "${General::swroot}/ethernet/aliases"){
1690 foreach my $alias (sort keys %aliases)
1691 {
1692 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1693 }
1694 }
1695 print<<END;
1696 </select></td></tr>
1697 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
1698 END
1699 &gen_dd_block('tgt','grp2');
1700 print"<hr>";
1701 &Header::closebox;
1702 #---PROTOCOL------------------------------------------------------
1703 &Header::openbox('100%', 'left', $Lang::tr{'fwhost prot'});
1704 #Fix Protocol for JQuery
1705 if ($fwdfwsettings{'grp3'} eq 'cust_srv' || $fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
1706 $fwdfwsettings{'PROT'} = 'template';
1707 }
1708 print<<END;
1709 <div id="prt">
1710 <table width='15%' border='0' style="float:left;">
1711 <tr>
1712 <td>
1713 <select name='PROT' id='protocol'>
1714 END
1715 print "<option value=\"\"";
1716 if ($fwdfwsettings{'PROT'} eq '') {
1717 print " selected=\"selected\"";
1718 }
1719 print ">$Lang::tr{'all'}</option>";
1720
1721 print "<option value=\"template\"";
1722 print " selected=\"selected\"" if ($fwdfwsettings{'grp3'} eq 'cust_srv' || $fwdfwsettings{'grp3'} eq 'cust_srvgrp');
1723 print ">- $Lang::tr{'template'} -</option>";
1724
1725 foreach (@PROTOCOLS) {
1726 print"<option value=\"$_\"";
1727 if ($_ eq $fwdfwsettings{'PROT'}) {
1728 print " selected=\"selected\"";
1729 }
1730 print ">$_</option>";
1731 }
1732 print<<END;
1733 </select>
1734 </td>
1735 </tr>
1736 </table>
1737 </div>
1738
1739 <div id="PROTOCOL_ICMP_TYPES">
1740 <table width='50%' border='0' style="float:left;">
1741 <tr>
1742 <td width='20%'>$Lang::tr{'fwhost icmptype'}</td>
1743 <td colspan='2'>
1744 <select name='ICMP_TYPES' style='min-width:230px;'>
1745 END
1746 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1747 print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>";
1748 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
1749 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1750 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1751 }else{
1752 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1753 }
1754 }
1755
1756 print <<END;
1757 </select>
1758 </td>
1759 </tr>
1760 </table>
1761 </div>
1762 END
1763
1764 $fwdfwsettings{'SRC_PORT'} =~ s/\|/,/g;
1765 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
1766
1767 print <<END;
1768
1769 <div id="PROTOCOL_PORTS">
1770 <table border="0">
1771 <tr>
1772 <!-- #SOURCEPORT -->
1773 <td>
1774 $Lang::tr{'fwdfw use srcport'}
1775 </td>
1776 <td>
1777 <input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18'>
1778 </td>
1779 <td width='10%'>
1780 </td>
1781
1782 <!-- #TARGETPORT -->
1783 <td>
1784 $Lang::tr{'fwdfw use srv'}
1785 </td>
1786
1787 <td>
1788 <input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18'>
1789 </td>
1790 </tr>
1791 </table>
1792 </div>
1793
1794 <div id="PROTOCOL_TEMPLATE">
1795 <table border="0">
1796 <tr>
1797 <td>
1798 <input type='radio' name='grp3' id='cust_srv' value='cust_srv' checked>
1799 $Lang::tr{'fwhost cust service'}
1800 </td>
1801 <td>
1802 <select name='cust_srv' style='min-width: 230px;'>
1803 END
1804 &General::readhasharray("$configsrv", \%customservice);
1805 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1806 print"<option ";
1807 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1808 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1809 }
1810
1811 print<<END;
1812 </select>
1813 </td>
1814 </tr>
1815 <tr>
1816 <td>
1817 <input type='radio' name='grp3' id='cust_srvgrp' value='cust_srvgrp' $checked{'grp3'}{'cust_srvgrp'}>
1818 $Lang::tr{'fwhost cust srvgrp'}
1819 </td>
1820 <td>
1821 <select name='cust_srvgrp' style='min-width:230px;'>
1822 END
1823
1824 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1825 my $helper;
1826 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1827 if ($helper ne $customservicegrp{$key}[0]){
1828 print"<option ";
1829 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1830 print">$customservicegrp{$key}[0]</option>";
1831 }
1832 $helper=$customservicegrp{$key}[0];
1833 }
1834 print<<END;
1835 </select>
1836 </td>
1837 </tr>
1838 </table>
1839 </div>
1840
1841 <br><br><br>
1842 END
1843
1844 &Header::closebox;
1845
1846 $checked{"RULE_ACTION"} = ();
1847 foreach ("ACCEPT", "DROP", "REJECT") {
1848 $checked{"RULE_ACTION"}{$_} = "";
1849 }
1850
1851 if($fwdfwsettings{'updatefwrule'} eq 'on') {
1852 $checked{"RULE_ACTION"}{$fwdfwsettings{'RULE_ACTION'}} = "checked";
1853 } elsif ($fwdfwsettings{'POLICY'} eq 'MODE1') {
1854 $checked{"RULE_ACTION"}{"ACCEPT"} = "checked";
1855 } elsif ($fwdfwsettings{'POLICY'} eq 'MODE2') {
1856 $checked{"RULE_ACTION"}{"DROP"} = "checked";
1857 }
1858
1859 print <<END;
1860 <hr><br>
1861
1862 <center>
1863 <table width="80%" border="0">
1864 <tr>
1865 <td width="33%" align="center" bgcolor="$color{'color17'}">
1866 &nbsp;<br>&nbsp;
1867 </td>
1868 <td width="33%" align="center" bgcolor="$color{'color25'}">
1869 &nbsp;<br>&nbsp;
1870 </td>
1871 <td width="33%" align="center" bgcolor="$color{'color16'}">
1872 &nbsp;<br>&nbsp;
1873 </td>
1874 </tr>
1875 <tr>
1876 <td width="33%" align="center">
1877 <label>
1878 <input type="radio" name="RULE_ACTION" value="ACCEPT" $checked{"RULE_ACTION"}{"ACCEPT"}>
1879 <strong>$Lang::tr{'fwdfw ACCEPT'}</strong>
1880 </label>
1881 </td>
1882 <td width="33%" align="center">
1883 <label>
1884 <input type="radio" name="RULE_ACTION" value="DROP" $checked{"RULE_ACTION"}{"DROP"}>
1885 <strong>$Lang::tr{'fwdfw DROP'}</strong>
1886 </label>
1887 </td>
1888 <td width="33%" align="center">
1889 <label>
1890 <input type="radio" name="RULE_ACTION" value="REJECT" $checked{"RULE_ACTION"}{"REJECT"}>
1891 <strong>$Lang::tr{'fwdfw REJECT'}</strong>
1892 </label>
1893 </td>
1894 </tr>
1895 </table>
1896 </center>
1897
1898 <br>
1899 END
1900
1901 #---Activate/logging/remark-------------------------------------
1902 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw additional'});
1903 print<<END;
1904 <table width='100%' border='0'>
1905 END
1906 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>";
1907 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
1908 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
1909 for (my $count =1; $count <= $sum; $count++){
1910 print"<option value='$count' ";
1911 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
1912 print">$count</option>";
1913 }
1914 print"</select></td></tr>";
1915 }else{
1916 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
1917 }
1918
1919 print<<END;
1920 </table>
1921 <table width='100%'>
1922 <tr>
1923 END
1924
1925 if ($fwdfwsettings{'updatefwrule'} eq 'on') {
1926 print <<END;
1927 <td>
1928 <input type='checkbox' name='ACTIVE' $checked{'ACTIVE'}{'ON'}>
1929 </td>
1930 <td>$Lang::tr{'fwdfw rule activate'}</td>
1931 END
1932 } else {
1933 print <<END;
1934 <td colspan="2">
1935 <input type="hidden" name="ACTIVE" value="ON">
1936 </td>
1937 END
1938 }
1939
1940 print <<END;
1941 </tr>
1942 <tr>
1943 <td>
1944 <input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'}>
1945 </td>
1946 <td>$Lang::tr{'fwdfw log rule'}</td>
1947 </tr>
1948 <tr>
1949 <td width='1%'>
1950 <input type='checkbox' name='TIME' id="USE_TIME_CONSTRAINTS" value='ON' $checked{'TIME'}{'ON'}>
1951 </td>
1952 <td>$Lang::tr{'fwdfw timeframe'}</td>
1953 </tr>
1954 <tr id="TIME_CONSTRAINTS">
1955 <td colspan="2">
1956 <table width="66%" border="0">
1957 <tr>
1958 <td width="8em">&nbsp;</td>
1959 <td align="center">$Lang::tr{'advproxy monday'}</td>
1960 <td align="center">$Lang::tr{'advproxy tuesday'}</td>
1961 <td align="center">$Lang::tr{'advproxy wednesday'}</td>
1962 <td align="center">$Lang::tr{'advproxy thursday'}</td>
1963 <td align="center">$Lang::tr{'advproxy friday'}</td>
1964 <td align="center">$Lang::tr{'advproxy saturday'}</td>
1965 <td align="center">$Lang::tr{'advproxy sunday'}</td>
1966 <td>&nbsp;</td>
1967 </tr>
1968 <tr>
1969 <td width="8em">&nbsp;</td>
1970 <td align="center"><input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} ></td>
1971 <td align="center"><input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} ></td>
1972 <td align="center"><input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} ></td>
1973 <td align="center"><input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} ></td>
1974 <td align="center"><input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} ></td>
1975 <td align="center"><input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} ></td>
1976 <td align="center"><input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} ></td>
1977 <td>
1978 <select name='TIME_FROM'>
1979 END
1980 for (my $i=0;$i<=23;$i++) {
1981 $i = sprintf("%02s",$i);
1982 for (my $j=0;$j<=45;$j+=15) {
1983 $j = sprintf("%02s",$j);
1984 my $time = $i.":".$j;
1985 print "<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
1986 }
1987 }
1988 print<<END;
1989 </select> &dash;
1990 <select name='TIME_TO'>
1991 END
1992 for (my $i=0;$i<=23;$i++) {
1993 $i = sprintf("%02s",$i);
1994 for (my $j=0;$j<=45;$j+=15) {
1995 $j = sprintf("%02s",$j);
1996 my $time = $i.":".$j;
1997 print "<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
1998 }
1999 }
2000 print<<END;
2001 </select>
2002 </td>
2003 </tr>
2004 </table>
2005 </td>
2006 </tr>
2007 </table>
2008 <br><hr>
2009 END
2010
2011 #---ACTION------------------------------------------------------
2012 if($fwdfwsettings{'updatefwrule'} ne 'on'){
2013 print<<END;
2014 <table border='0' width='100%'>
2015 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
2016 <input type='hidden' name='config' value='$config' >
2017 <input type='hidden' name='ACTION' value='saverule' ></form>
2018 <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>
2019 </table>
2020 <br>
2021 END
2022 }else{
2023 print<<END;
2024 <table border='0' width='100%'>
2025 <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'}'>
2026 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
2027 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
2028 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
2029 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
2030 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
2031 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
2032 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
2033 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
2034 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
2035 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
2036 <input type='hidden' name='oldorange' value='$fwdfwsettings{'oldorange'}' />
2037 <input type='hidden' name='oldnat' value='$fwdfwsettings{'oldnat'}' />
2038 <input type='hidden' name='oldruletype' value='$fwdfwsettings{'oldruletype'}' />
2039 <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>
2040 </table></form>
2041 END
2042 }
2043 &Header::closebox();
2044 }
2045 sub pos_up
2046 {
2047 my %uphash=();
2048 my %tmp=();
2049 &General::readhasharray($fwdfwsettings{'config'}, \%uphash);
2050 foreach my $key (sort keys %uphash){
2051 if ($key eq $fwdfwsettings{'key'}) {
2052 my $last = $key -1;
2053 if (exists $uphash{$last}){
2054 #save rule last
2055 foreach my $y (0 .. $#{$uphash{$last}}) {
2056 $tmp{0}[$y] = $uphash{$last}[$y];
2057 }
2058 #copy active rule to last
2059 foreach my $i (0 .. $#{$uphash{$last}}) {
2060 $uphash{$last}[$i] = $uphash{$key}[$i];
2061 }
2062 #copy saved rule to actual position
2063 foreach my $x (0 .. $#{$tmp{0}}) {
2064 $uphash{$key}[$x] = $tmp{0}[$x];
2065 }
2066 }
2067 }
2068 }
2069 &General::writehasharray($fwdfwsettings{'config'}, \%uphash);
2070 &rules;
2071 }
2072 sub pos_down
2073 {
2074 my %downhash=();
2075 my %tmp=();
2076 &General::readhasharray($fwdfwsettings{'config'}, \%downhash);
2077 foreach my $key (sort keys %downhash){
2078 if ($key eq $fwdfwsettings{'key'}) {
2079 my $next = $key + 1;
2080 if (exists $downhash{$next}){
2081 #save rule next
2082 foreach my $y (0 .. $#{$downhash{$next}}) {
2083 $tmp{0}[$y] = $downhash{$next}[$y];
2084 }
2085 #copy active rule to next
2086 foreach my $i (0 .. $#{$downhash{$next}}) {
2087 $downhash{$next}[$i] = $downhash{$key}[$i];
2088 }
2089 #copy saved rule to actual position
2090 foreach my $x (0 .. $#{$tmp{0}}) {
2091 $downhash{$key}[$x] = $tmp{0}[$x];
2092 }
2093 }
2094 }
2095 }
2096 &General::writehasharray($fwdfwsettings{'config'}, \%downhash);
2097 &rules;
2098 }
2099 sub rules
2100 {
2101 if (!-f "${General::swroot}/forward/reread"){
2102 system("touch ${General::swroot}/forward/reread");
2103 system("touch ${General::swroot}/fwhosts/reread");
2104 }
2105 }
2106 sub reread_rules
2107 {
2108 system("/usr/local/bin/forwardfwctrl");
2109 if ( -f "${General::swroot}/forward/reread"){
2110 system("rm ${General::swroot}/forward/reread");
2111 system("rm ${General::swroot}/fwhosts/reread");
2112 }
2113 }
2114 sub saverule
2115 {
2116 my $hash=shift;
2117 my $config=shift;
2118 &General::readhasharray("$config", $hash);
2119 if (!$errormessage){
2120 ################################################################
2121 #check if we change an INPUT rule to a OUTGOING
2122 if($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW' ){
2123 &changerule($configinput);
2124 #print"1";
2125 }
2126 #check if we change an INPUT rule to a FORWARD
2127 elsif($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
2128 &changerule($configinput);
2129 #print"2";
2130 }
2131 ################################################################
2132 #check if we change an OUTGOING rule to an INPUT
2133 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'INPUTFW' ){
2134 &changerule($configoutgoing);
2135 #print"3";
2136 }
2137 #check if we change an OUTGOING rule to a FORWARD
2138 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
2139 &changerule($configoutgoing);
2140 #print"4";
2141 }
2142 ################################################################
2143 #check if we change a FORWARD rule to an INPUT
2144 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'INPUTFW'){
2145 &changerule($configfwdfw);
2146 #print"5";
2147 }
2148 #check if we change a FORWARD rule to an OUTGOING
2149 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW'){
2150 &changerule($configfwdfw);
2151 #print"6";
2152 }
2153 if ($fwdfwsettings{'updatefwrule'} ne 'on'){
2154 my $key = &General::findhasharraykey ($hash);
2155 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
2156 $$hash{$key}[1] = $fwdfwsettings{'chain'};
2157 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
2158 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
2159 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
2160 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
2161 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
2162 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
2163 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
2164 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
2165 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
2166 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
2167 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
2168 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
2169 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
2170 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
2171 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
2172 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
2173 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
2174 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
2175 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
2176 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
2177 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
2178 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
2179 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
2180 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
2181 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
2182 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
2183 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
2184 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
2185 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
2186 $$hash{$key}[31] = $fwdfwsettings{'nat'};
2187 &General::writehasharray("$config", $hash);
2188 }else{
2189 foreach my $key (sort {$a <=> $b} keys %$hash){
2190 if($key eq $fwdfwsettings{'key'}){
2191 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
2192 $$hash{$key}[1] = $fwdfwsettings{'chain'};
2193 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
2194 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
2195 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
2196 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
2197 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
2198 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
2199 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
2200 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
2201 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
2202 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
2203 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
2204 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
2205 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
2206 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
2207 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
2208 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
2209 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
2210 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
2211 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
2212 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
2213 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
2214 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
2215 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
2216 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
2217 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
2218 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
2219 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
2220 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
2221 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
2222 $$hash{$key}[31] = $fwdfwsettings{'nat'};
2223 last;
2224 }
2225 }
2226 }
2227 &General::writehasharray("$config", $hash);
2228 if($fwdfwsettings{'oldrulenumber'} > $fwdfwsettings{'rulepos'}){
2229 my %tmp=();
2230 my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'};
2231 for (my $z=0;$z<$val;$z++){
2232 foreach my $key (sort {$a <=> $b} keys %$hash){
2233 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2234 my $last = $key -1;
2235 if (exists $$hash{$last}){
2236 #save rule last
2237 foreach my $y (0 .. $#{$$hash{$last}}) {
2238 $tmp{0}[$y] = $$hash{$last}[$y];
2239 }
2240 #copy active rule to last
2241 foreach my $i (0 .. $#{$$hash{$last}}) {
2242 $$hash{$last}[$i] = $$hash{$key}[$i];
2243 }
2244 #copy saved rule to actual position
2245 foreach my $x (0 .. $#{$tmp{0}}) {
2246 $$hash{$key}[$x] = $tmp{0}[$x];
2247 }
2248 }
2249 }
2250 }
2251 $fwdfwsettings{'oldrulenumber'}--;
2252 }
2253 &General::writehasharray("$config", $hash);
2254 &rules;
2255 }elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
2256 my %tmp=();
2257 my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
2258 for (my $z=0;$z<$val;$z++){
2259 foreach my $key (sort {$a <=> $b} keys %$hash){
2260 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2261 my $next = $key + 1;
2262 if (exists $$hash{$next}){
2263 #save rule next
2264 foreach my $y (0 .. $#{$$hash{$next}}) {
2265 $tmp{0}[$y] = $$hash{$next}[$y];
2266 }
2267 #copy active rule to next
2268 foreach my $i (0 .. $#{$$hash{$next}}) {
2269 $$hash{$next}[$i] = $$hash{$key}[$i];
2270 }
2271 #copy saved rule to actual position
2272 foreach my $x (0 .. $#{$tmp{0}}) {
2273 $$hash{$key}[$x] = $tmp{0}[$x];
2274 }
2275 }
2276 }
2277 }
2278 $fwdfwsettings{'oldrulenumber'}++;
2279 }
2280 &General::writehasharray("$config", $hash);
2281 &rules;
2282 }
2283 }
2284 }
2285 sub validremark
2286 {
2287 # Checks a hostname against RFC1035
2288 my $remark = $_[0];
2289
2290 # Each part should be at least two characters in length
2291 # but no more than 63 characters
2292 if (length ($remark) < 1 || length ($remark) > 255) {
2293 return 0;}
2294 # Only valid characters are a-z, A-Z, 0-9 and -
2295 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
2296 return 0;}
2297 # First character can only be a letter or a digit
2298 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
2299 return 0;}
2300 # Last character can only be a letter or a digit
2301 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
2302 return 0;}
2303 return 1;
2304 }
2305 sub viewtablerule
2306 {
2307 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
2308 &viewtablenew(\%configfwdfw,$configfwdfw,"","Forward" );
2309 &viewtablenew(\%configinputfw,$configinput,"",$Lang::tr{'fwdfw xt access'} );
2310 &viewtablenew(\%configoutgoingfw,$configoutgoing,"","Outgoing" );
2311 }
2312 sub viewtablenew
2313 {
2314 my $hash=shift;
2315 my $config=shift;
2316 my $title=shift;
2317 my $title1=shift;
2318 my $go='';
2319 &General::get_aliases(\%aliases);
2320 &General::readhasharray("$confighost", \%customhost);
2321 &General::readhasharray("$config", $hash);
2322 &General::readhasharray("$configccdnet", \%ccdnet);
2323 &General::readhasharray("$configccdhost", \%ccdhost);
2324 if( ! -z $config){
2325 &Header::openbox('100%', 'left',$title);
2326 my $count=0;
2327 my ($gif,$log);
2328 my $ruletype;
2329 my $rulecolor;
2330 my $tooltip;
2331 my @tmpsrc=();
2332 my $coloryellow='';
2333 print"<b>$title1</b><br>";
2334 print"<table width='100%' cellspacing='0' cellpadding='0' border='0'>";
2335 print"<tr><td align='center'><b>#</b></td><td></td><td align='center' width='25'></td><td align='center'><b>$Lang::tr{'fwdfw source'}</b></td><td width='1%'><b>Log</b></td><td align='center'><b>$Lang::tr{'fwdfw target'}</b></td><td align='center' colspan='6' width='1%'><b>$Lang::tr{'fwdfw action'}</b></td></tr>";
2336 foreach my $key (sort {$a <=> $b} keys %$hash){
2337 $tdcolor='';
2338 @tmpsrc=();
2339 #check if vpn hosts/nets have been deleted
2340 if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){
2341 push (@tmpsrc,$$hash{$key}[4]);
2342 }
2343 if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){
2344 push (@tmpsrc,$$hash{$key}[6]);
2345 }
2346 foreach my $host (@tmpsrc){
2347 if($$hash{$key}[3] eq 'ipsec_net_src' || $$hash{$key}[5] eq 'ipsec_net_tgt'){
2348 if(&fwlib::get_ipsec_net_ip($host,11) eq ''){
2349 $coloryellow='on';
2350 &disable_rule($key);
2351 $$hash{$key}[2]='';
2352 }
2353 }elsif($$hash{$key}[3] eq 'ovpn_net_src' || $$hash{$key}[5] eq 'ovpn_net_tgt'){
2354 if(&fwlib::get_ovpn_net_ip($host,1) eq ''){
2355 $coloryellow='on';
2356 &disable_rule($key);
2357 $$hash{$key}[2]='';
2358 }
2359 }elsif($$hash{$key}[3] eq 'ovpn_n2n_src' || $$hash{$key}[5] eq 'ovpn_n2n_tgt'){
2360 if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){
2361 $coloryellow='on';
2362 &disable_rule($key);
2363 $$hash{$key}[2]='';
2364 }
2365 }elsif($$hash{$key}[3] eq 'ovpn_host_src' || $$hash{$key}[5] eq 'ovpn_host_tgt'){
2366 if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
2367 $coloryellow='on';
2368 &disable_rule($key);
2369 $$hash{$key}[2]='';
2370 }
2371 }
2372 }
2373 $$hash{'ACTIVE'}=$$hash{$key}[2];
2374 $count++;
2375 if($coloryellow eq 'on'){
2376 print"<tr bgcolor='$color{'color14'}' >";
2377 $coloryellow='';
2378 }elsif($coloryellow eq ''){
2379 if ($count % 2){
2380 $color="$color{'color22'}";
2381 }
2382 else{
2383 $color="$color{'color20'}";
2384 }
2385 }
2386 print"<tr bgcolor='$color' >";
2387 #KEY
2388 print<<END;
2389 <td align='right' width='18'><b>$key &nbsp;</b></td>
2390 END
2391 #RULETYPE (A,R,D)
2392 if ($$hash{$key}[0] eq 'ACCEPT'){
2393 $ruletype='A';
2394 $tooltip='ACCEPT';
2395 $rulecolor=$color{'color17'};
2396 }elsif($$hash{$key}[0] eq 'DROP'){
2397 $ruletype='D';
2398 $tooltip='DROP';
2399 $rulecolor=$color{'color25'};
2400 }elsif($$hash{$key}[0] eq 'REJECT'){
2401 $ruletype='R';
2402 $tooltip='REJECT';
2403 $rulecolor=$color{'color16'};
2404 }
2405 print"<td bgcolor='$rulecolor' align='center' width='10'><span title='$tooltip'><b>$ruletype</b></span></td>";
2406 #Get Protocol
2407 my $prot;
2408 if ($$hash{$key}[8]){
2409 push (@protocols,$$hash{$key}[8]);
2410 }elsif($$hash{$key}[14] eq 'cust_srv'){
2411 &get_serviceports("service",$$hash{$key}[15]);
2412 }elsif($$hash{$key}[14] eq 'cust_srvgrp'){
2413 &get_serviceports("group",$$hash{$key}[15]);
2414 }else{
2415 push (@protocols,$Lang::tr{'all'});
2416 }
2417 my $protz=join(",",@protocols);
2418 if($protz eq 'ICMP' && $$hash{$key}[9] ne 'All ICMP-Types' && $$hash{$key}[14] ne 'cust_srvgrp'){
2419 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
2420 foreach my $keyicmp (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
2421 if($$hash{$key}[9] eq "$icmptypes{$keyicmp}[0]"){
2422 print "<td align='center'><span title='$icmptypes{$keyicmp}[0]'><b>$protz ($icmptypes{$keyicmp}[1])</b></span></td>";
2423 last;
2424 }
2425 }
2426 }else{
2427 print"<td align='center'>$protz</td>";
2428 }
2429 @protocols=();
2430 #SOURCE
2431 my $ipfireiface;
2432 &getcolor($$hash{$key}[3],$$hash{$key}[4],\%customhost);
2433 print"<td align='center' width='160' $tdcolor>";
2434 if ($$hash{$key}[3] eq 'ipfire_src'){
2435 $ipfireiface='Interface ';
2436 }
2437 if ($$hash{$key}[3] eq 'std_net_src'){
2438 print &get_name($$hash{$key}[4]);
2439 }elsif ($$hash{$key}[3] eq 'src_addr'){
2440 my ($split1,$split2) = split("/",$$hash{$key}[4]);
2441 if ($split2 eq '32'){
2442 print $split1;
2443 }else{
2444 print $$hash{$key}[4];
2445 }
2446 }elsif ($$hash{$key}[4] eq 'RED1'){
2447 print "$ipfireiface $Lang::tr{'fwdfw red'}";
2448 }else{
2449 print "$$hash{$key}[4]";
2450 }
2451 $tdcolor='';
2452 #SOURCEPORT
2453 &getsrcport(\%$hash,$key);
2454 #Is this a SNAT rule?
2455 if ($$hash{$key}[31] eq 'snat' && $$hash{$key}[28] eq 'ON'){
2456 my $net=&get_name($$hash{$key}[29]);
2457 if ( ! $net){ $net=$$hash{$key}[29];}
2458 print"<br>->$net";
2459 if ($$hash{$key}[30] ne ''){
2460 print": $$hash{$key}[30]";
2461 }
2462 }
2463 if ($$hash{$key}[17] eq 'ON'){
2464 $log="/images/on.gif";
2465 }else{
2466 $log="/images/off.gif";
2467 }
2468 #LOGGING
2469 print<<END;
2470 </td>
2471 <td align='left' width='25'><form method='post'><input type='image' img src='$log' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw togglelog'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;'/>
2472 <input type='hidden' name='key' value='$key' />
2473 <input type='hidden' name='config' value='$config' />
2474 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw togglelog'}' />
2475 </form></td>
2476 END
2477 #TARGET
2478 &getcolor($$hash{$key}[5],$$hash{$key}[6],\%customhost);
2479 print<<END;
2480 <td align='center' width='160' $tdcolor>
2481 END
2482 #Is this a DNAT rule?
2483 if ($$hash{$key}[31] eq 'dnat' && $$hash{$key}[28] eq 'ON'){
2484 print "Firewall ($$hash{$key}[29])";
2485 if($$hash{$key}[30] ne ''){
2486 $$hash{$key}[30]=~ tr/|/,/;
2487 print": $$hash{$key}[30]";
2488 }
2489 print"<br>->";
2490 }
2491 if ($$hash{$key}[5] eq 'ipfire'){
2492 $ipfireiface='Interface';
2493 }
2494 if ($$hash{$key}[5] eq 'std_net_tgt' || $$hash{$key}[5] eq 'ipfire' || $$hash{$key}[6] eq 'RED1' || $$hash{$key}[6] eq 'GREEN' || $$hash{$key}[6] eq 'ORANGE' || $$hash{$key}[6] eq 'BLUE' ){
2495 if ($$hash{$key}[6] eq 'RED1'){
2496 print "$ipfireiface $Lang::tr{'red1'}";
2497 }elsif ($$hash{$key}[6] eq 'GREEN' || $$hash{$key}[6] eq 'ORANGE' || $$hash{$key}[6] eq 'BLUE'|| $$hash{$key}[6] eq 'ALL')
2498 {
2499 print "$ipfireiface ".&get_name($$hash{$key}[6]);
2500 }else{
2501 print $$hash{$key}[6];
2502 }
2503 }elsif ($$hash{$key}[5] eq 'tgt_addr'){
2504 my ($split1,$split2) = split("/",$$hash{$key}[6]);
2505 if ($split2 eq '32'){
2506 print $split1;
2507 }else{
2508 print $$hash{$key}[6];
2509 }
2510 }else{
2511 print "$$hash{$key}[6]";
2512 }
2513 $tdcolor='';
2514 #TARGETPORT
2515 &gettgtport(\%$hash,$key);
2516 print"</td>";
2517 #RULE ACTIVE
2518 if($$hash{$key}[2] eq 'ON'){
2519 $gif="/images/on.gif"
2520
2521 }else{
2522 $gif="/images/off.gif"
2523 }
2524 print<<END;
2525 <td width='25'><form method='post'><input type='image' img src='$gif' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw toggle'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2526 <input type='hidden' name='key' value='$key' />
2527 <input type='hidden' name='config' value='$config' />
2528 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw toggle'}' />
2529 </form></td>
2530 <td width='25' ><form method='post'><input type='image' img src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'fwdfw edit'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2531 <input type='hidden' name='key' value='$key' />
2532 <input type='hidden' name='config' value='$config' />
2533 <input type='hidden' name='ACTION' value='editrule' />
2534 </form></td>
2535 <td width='25'><form method='post'><input type='image' img src='/images/addblue.gif' alt='$Lang::tr{'fwdfw copy'}' title='$Lang::tr{'fwdfw copy'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2536 <input type='hidden' name='key' value='$key' />
2537 <input type='hidden' name='config' value='$config' />
2538 <input type='hidden' name='ACTION' value='copyrule' />
2539 </form></td>
2540 <td width='25' ><form method='post'><input type='image' img src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'fwdfw delete'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2541 <input type='hidden' name='key' value='$key' />
2542 <input type='hidden' name='config' value='$config' />
2543 <input type='hidden' name='ACTION' value='deleterule' />
2544 </form></td>
2545 END
2546 if (exists $$hash{$key-1}){
2547 print<<END;
2548 <td width='25'><form method='post'><input type='image' img src='/images/up.gif' alt='$Lang::tr{'fwdfw moveup'}' title='$Lang::tr{'fwdfw moveup'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2549 <input type='hidden' name='key' value='$key' />
2550 <input type='hidden' name='config' value='$config' />
2551 <input type='hidden' name='ACTION' value='moveup' />
2552 </form></td>
2553 END
2554 }else{
2555 print"<td width='25'><input type='image' img src='/images/up.gif' style='visibility:hidden;'></td>";
2556 }
2557 if (exists $$hash{$key+1}){
2558 print<<END;
2559 <td width='25' ><form method='post'><input type='image' img src='/images/down.gif' alt='$Lang::tr{'fwdfw movedown'}' title='$Lang::tr{'fwdfw movedown'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2560 <input type='hidden' name='key' value='$key' />
2561 <input type='hidden' name='config' value='$config' />
2562 <input type='hidden' name='ACTION' value='movedown' />
2563 </form></td></tr>
2564 END
2565 }else{
2566 print"<td width='25'><input type='image' img src='/images/down.gif' style='visibility:hidden;'></td></tr>";
2567 }
2568 #REMARK
2569 if ($optionsfw{'SHOWREMARK'} eq 'on' && $$hash{$key}[16] ne ''){
2570 print"<tr bgcolor='$color'>";
2571 print"<td>&nbsp;</td><td bgcolor='$rulecolor'></td><td colspan='10'>&nbsp; $$hash{$key}[16]</td></tr>";
2572 }
2573 if ($$hash{$key}[18] eq 'ON'){
2574 #TIMEFRAME
2575 if ($$hash{$key}[18] eq 'ON'){
2576 my @days=();
2577 if($$hash{$key}[19] ne ''){push (@days,$Lang::tr{'fwdfw wd_mon'});}
2578 if($$hash{$key}[20] ne ''){push (@days,$Lang::tr{'fwdfw wd_tue'});}
2579 if($$hash{$key}[21] ne ''){push (@days,$Lang::tr{'fwdfw wd_wed'});}
2580 if($$hash{$key}[22] ne ''){push (@days,$Lang::tr{'fwdfw wd_thu'});}
2581 if($$hash{$key}[23] ne ''){push (@days,$Lang::tr{'fwdfw wd_fri'});}
2582 if($$hash{$key}[24] ne ''){push (@days,$Lang::tr{'fwdfw wd_sat'});}
2583 if($$hash{$key}[25] ne ''){push (@days,$Lang::tr{'fwdfw wd_sun'});}
2584 my $weekdays=join(",",@days);
2585 if (@days){
2586 print"<tr bgcolor='$color'>";
2587 print"<td>&nbsp;</td><td bgcolor='$rulecolor'></td><td align='left' colspan='10'>&nbsp; $weekdays &nbsp; $$hash{$key}[26] - $$hash{$key}[27] </td></tr>";
2588 }
2589 }
2590 }
2591 print"<tr bgcolor='FFFFFF'><td colspan='13' height='1'></td></tr>";
2592 }
2593 print"</table>";
2594 #SHOW FINAL RULE
2595 print "<table width='100%'rules='cols' border='1'>";
2596 my $col;
2597 if ($config eq '/var/ipfire/forward/config'){
2598 my $pol='fwdfw '.$fwdfwsettings{'POLICY'};
2599 if ($fwdfwsettings{'POLICY'} eq 'MODE1'){
2600 $col="bgcolor='darkred'";
2601 }else{
2602 $col="bgcolor='green'";
2603 }
2604 &show_defaultrules($col,$pol);
2605 }elsif ($config eq '/var/ipfire/forward/outgoing'){
2606 if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){
2607 $col="bgcolor='darkred'";
2608 print"<tr><td $col width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF' >$Lang::tr{'fwdfw pol block'}</font></td></tr>";
2609 }else{
2610 $col="bgcolor='green'";
2611 print"<tr><td $col width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF' >$Lang::tr{'fwdfw pol allow'}</font></td></tr>";
2612 }
2613 }else{
2614 print"<tr><td bgcolor='darkred' width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td bgcolor='darkred' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol block'}</font></td></tr>";
2615 }
2616 print"</table>";
2617 print "<hr>";
2618 print "<br><br>";
2619 &Header::closebox();
2620 }else{
2621 if ($optionsfw{'SHOWTABLES'} eq 'on'){
2622 print "<b>$title1</b><br>";
2623 print"<table width='100%' border='0' rules='none'><tr><td height='30' bgcolor=$color{'color22'} align='center'>$Lang::tr{'fwhost empty'}</td></tr></table>";
2624 my $col;
2625 if ($config eq '/var/ipfire/forward/config'){
2626 my $pol='fwdfw '.$fwdfwsettings{'POLICY'};
2627 if ($fwdfwsettings{'POLICY'} eq 'MODE1'){
2628 $col="bgcolor='darkred'";
2629 }else{
2630 $col="bgcolor='green'";
2631 }
2632 &show_defaultrules($col,$pol);
2633 }elsif ($config eq '/var/ipfire/forward/outgoing'){
2634 print "<table width='100%' rules='cols' border='1'>";
2635 my $pol='fwdfw '.$fwdfwsettings{'POLICY1'};
2636 if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){
2637 $col="bgcolor='darkred'";
2638 print"<tr><td $col align='center' width='20%'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol block'}</font></td></tr>";
2639 }else{
2640 $col="bgcolor='green'";
2641 print"<tr><td $col align='center' width='20%'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol allow'}</font></td></tr>";
2642 }
2643 }else{
2644 print "<table width='100%' rules='cols' border='1'>";
2645 print"<tr><td bgcolor='darkred' align='center' width='20%'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td align='center' bgcolor='darkred'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol block'}</font></td></tr>";
2646 }
2647 print"</table><br><br>";
2648 }
2649 }
2650 }
2651 &Header::closebigbox();
2652 &Header::closepage();
2653
2654 sub show_defaultrules
2655 {
2656 my $col=shift;
2657 my $pol=shift;
2658 #STANDARD RULES (From WIKI)
2659 print"</table>";
2660 if ($col eq "bgcolor='green'"){
2661 print "<br><table width='100%' rules='cols' border='1' >";
2662 my $blue = "<font color=$Header::colourblue> $Lang::tr{'blue'}</font> ($Lang::tr{'fwdfw pol block'})" if (&Header::blue_used());
2663 my $orange = "<font color=$Header::colourorange> $Lang::tr{'orange'}</font> ($Lang::tr{'fwdfw pol block'})" if (&Header::orange_used());
2664 my $blue1 = "<font color=$Header::colourblue> $Lang::tr{'blue'}</font> ($Lang::tr{'fwdfw pol allow'})" if (&Header::blue_used());
2665 my $orange1 = "<font color=$Header::colourorange> $Lang::tr{'orange'}</font> ($Lang::tr{'fwdfw pol allow'})" if (&Header::orange_used());
2666 print"<tr><td align='center'><font color='#000000'>$Lang::tr{'green'}</td><td align='center'> <font color=$Header::colourred> $Lang::tr{'red'}</font> ($Lang::tr{'fwdfw pol allow'})</td>";
2667 print"<td align='center'>$orange1</td>" if (&Header::orange_used());
2668 print"<td align='center'>$blue1</td>" if (&Header::blue_used());
2669 print"</tr>";
2670 if (&Header::orange_used()){
2671 print"<tr><td align='center' width='20%'><font color='#000000'>$Lang::tr{'orange'}</td><td align='center'> <font color=$Header::colourred> $Lang::tr{'red'}</font> ($Lang::tr{'fwdfw pol allow'})</td><td align='center'><font color=$Header::colourgreen> $Lang::tr{'green'}</font> ($Lang::tr{'fwdfw pol block'})</td>";
2672 print"<td align='center'>$blue</td>" if (&Header::blue_used());
2673 print"</tr>";
2674 }
2675 if (&Header::blue_used()){
2676 print"<tr><td align='center'><font color='#000000'>$Lang::tr{'blue'}</td><td align='center'> <font color=$Header::colourred> $Lang::tr{'red'}</font> ($Lang::tr{'fwdfw pol allow'})</td>";
2677 print"<td align='center'>$orange</td>" if (&Header::orange_used());
2678 print"<td align='center'><font color=$Header::colourgreen> $Lang::tr{'green'}</font> ($Lang::tr{'fwdfw pol block'})</td>";
2679 print"</tr>";
2680 }
2681 print"<tr><td $col align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'} </font></td><td $col colspan='3' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol allow'}</font></td></tr>";
2682 }elsif($col eq "bgcolor='darkred'"){
2683 print "<table width='100%' rules='cols' border='1' >";
2684 print"<tr><td $col width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol block'}</font></td></tr>";
2685 }
2686 }