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