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