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