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