2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 Alexander Marx <amarx@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
25 use feature
'unicode_strings';
26 use experimental
'smartmatch';
28 no warnings
'uninitialized';
30 # enable only the following on debugging purpose
32 #use CGI::Carp 'fatalsToBrowser';
34 require '/var/ipfire/general-functions.pl';
35 require '/var/ipfire/network-functions.pl';
36 require "${General::swroot}/lang.pl";
37 require "${General::swroot}/header.pl";
38 require "${General::swroot}/location-functions.pl";
39 require "/usr/lib/firewall/firewall-lib.pl";
41 unless (-d
"${General::swroot}/firewall") { &General
::system("mkdir", "${General::swroot}/firewall"); }
42 unless (-e
"${General::swroot}/firewall/settings") { &General
::system("touch", "${General::swroot}/firewall/settings"); }
43 unless (-e
"${General::swroot}/firewall/config") { &General
::system("touch", "${General::swroot}/firewall/config"); }
44 unless (-e
"${General::swroot}/firewall/input") { &General
::system("touch", "${General::swroot}/firewall/input"); }
45 unless (-e
"${General::swroot}/firewall/outgoing") { &General
::system("touch", "${General::swroot}/firewall/outgoing"); }
49 my %defaultNetworks=();
53 my %customlocationgrp=();
54 my %customnetworks=();
56 my %customservicegrp=();
62 my %configoutgoingfw=();
75 my @PROTOCOLS = ("TCP", "UDP", "ICMP", "IGMP", "AH", "ESP", "GRE","IPv6","IPIP");
78 my $confignet = "${General::swroot}/fwhosts/customnetworks";
79 my $confighost = "${General::swroot}/fwhosts/customhosts";
80 my $configgrp = "${General::swroot}/fwhosts/customgroups";
81 my $configlocationgrp = "${General::swroot}/fwhosts/customlocationgrp";
82 my $configsrv = "${General::swroot}/fwhosts/customservices";
83 my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
84 my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
85 my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
86 my $configipsec = "${General::swroot}/vpn/config";
87 my $configipsecrw = "${General::swroot}/vpn/settings";
88 my $configfwdfw = "${General::swroot}/firewall/config";
89 my $configinput = "${General::swroot}/firewall/input";
90 my $configoutgoing = "${General::swroot}/firewall/outgoing";
91 my $configovpn = "${General::swroot}/ovpn/settings";
92 my $fwoptions = "${General::swroot}/optionsfw/settings";
93 my $ifacesettings = "${General::swroot}/ethernet/settings";
96 my $ipgrp="${General::swroot}/outgoing/groups";
100 &General
::readhash
("${General::swroot}/firewall/settings", \
%fwdfwsettings);
101 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
102 &General
::readhash
("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \
%color);
103 &General
::readhash
($fwoptions, \
%optionsfw);
104 &General
::readhash
($ifacesettings, \
%ifaces);
105 &General
::readhash
("$configovpn", \
%ovpnsettings);
106 &General
::readhash
("$configipsecrw", \
%ipsecsettings);
107 &General
::readhasharray
("$configipsec", \
%ipsecconf);
108 &Header
::showhttpheaders
();
109 &Header
::getcgihash
(\
%fwdfwsettings);
110 &Header
::openpage
($Lang::tr
{'firewall rules'}, 1, '');
111 &Header
::openbigbox
('100%', 'center',$errormessage);
112 #### JAVA SCRIPT ####
115 var PROTOCOLS_WITH_PORTS = ["TCP", "UDP"];
117 var update_protocol = function() {
118 var protocol = \$("#protocol").val();
120 if (protocol === undefined)
123 // Check if a template is/should be used.
124 if (protocol === "template") {
125 \$("#PROTOCOL_TEMPLATE").show();
127 \$("#PROTOCOL_TEMPLATE").hide();
130 // Check if we are dealing with a protocol, that knows ports.
131 if (\$.inArray(protocol, PROTOCOLS_WITH_PORTS) >= 0) {
132 \$("#PROTOCOL_PORTS").show();
134 \$("#PROTOCOL_PORTS").hide();
138 if (protocol === "ICMP") {
139 \$("#PROTOCOL_ICMP_TYPES").show();
141 \$("#PROTOCOL_ICMP_TYPES").hide();
145 \$(document).ready(function() {
146 \$("#protocol").change(update_protocol);
149 // Show/Hide elements when NAT checkbox is checked.
150 if (\$("#USE_NAT").attr("checked")) {
151 \$("#actions").hide();
156 // Show NAT area when "use nat" checkbox is clicked
157 \$("#USE_NAT").change(function() {
159 \$("#actions").toggle();
162 // Hide SNAT items when DNAT is selected and vice versa.
163 if (\$('input[name=nat]:checked').val() == 'dnat') {
169 // Show/Hide elements when SNAT/DNAT get changed.
170 \$('input[name=nat]').change(function() {
171 \$('.snat').toggle();
172 \$('.dnat').toggle();
176 if(!\$("#USE_TIME_CONSTRAINTS").attr("checked")) {
177 \$("#TIME_CONSTRAINTS").hide();
179 \$("#USE_TIME_CONSTRAINTS").change(function() {
180 \$("#TIME_CONSTRAINTS").toggle();
183 // Limit concurrent connections per ip
184 if(!\$("#USE_LIMIT_CONCURRENT_CONNECTIONS_PER_IP").attr("checked")) {
185 \$("#LIMIT_CON").hide();
187 \$("#USE_LIMIT_CONCURRENT_CONNECTIONS_PER_IP").change(function() {
188 \$("#LIMIT_CON").toggle();
191 // Rate-limit new connections
192 if(!\$("#USE_RATELIMIT").attr("checked")) {
193 \$("#RATELIMIT").hide();
195 \$("#USE_RATELIMIT").change(function() {
196 \$("#RATELIMIT").toggle();
199 // Automatically select radio buttons when corresponding
200 // dropdown menu changes.
201 \$("select").change(function() {
202 var id = \$(this).attr("name");
203 \$('#' + id).prop("checked", true);
211 if ($fwdfwsettings{'ACTION'} eq 'saverule')
213 &General
::readhasharray
("$configfwdfw", \
%configfwdfw);
214 &General
::readhasharray
("$configinput", \
%configinputfw);
215 &General
::readhasharray
("$configoutgoing", \
%configoutgoingfw);
216 &General
::readhash
("/var/ipfire/ethernet/settings", \
%netsettings);
218 #Set Variables according to the JQuery code in protocol section
219 if ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP')
221 if ($fwdfwsettings{'SRC_PORT'} ne '')
223 $fwdfwsettings{'USE_SRC_PORT'} = 'ON';
225 if ($fwdfwsettings{'TGT_PORT'} ne '')
227 $fwdfwsettings{'USESRV'} = 'ON';
228 $fwdfwsettings{'grp3'} = 'TGT_PORT';
231 if ($fwdfwsettings{'PROT'} eq 'template')
233 $fwdfwsettings{'USESRV'} = 'ON';
236 # Check if a manual target IP is one of the IPFire's addresses.
237 if ($fwdfwsettings{'grp2'} eq 'tgt_addr') {
238 # Grab all available network zones.
239 my @network_zones = &Network
::get_available_network_zones
();
241 # Loop through the array of network zones.
242 foreach my $zone (@network_zones) {
243 # Skip red network zone.
244 next if $zone eq "red";
246 # Convert current zone name into upper case.
249 # Generate key to access the required data from the netsettings hash.
250 my $key = $zone . "_ADDRESS";
252 # Obtain the configured address for the current zone from the netsettings hash.
253 my $zone_address = $netsettings{$key};
255 # Check if the given address and the current processed zone address are the same.
256 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $zone_address) {
257 # Map the type and target.
258 $fwdfwsettings{'grp2'} = 'ipfire';
259 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $zone;
267 $errormessage=&checksource
;
268 if(!$errormessage){&checktarget
;}
269 if(!$errormessage){&checkrule
;}
271 #check if manual ip (source) is orange network
272 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
273 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
274 if ( &General
::IpInSubnet
($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
278 #check if we try to break rules
279 if( $fwdfwsettings{'grp1'} eq 'ipfire_src' && $fwdfwsettings{'grp2'} eq 'ipfire'){
280 $errormessage=$Lang::tr
{'fwdfw err same'};
283 if ($fwdfwsettings{'grp2'} eq 'ipfire') {
284 $fwdfwsettings{'config'}=$configinput;
285 $fwdfwsettings{'chain'} = 'INPUTFW';
286 $maxkey=&General
::findhasharraykey
(\
%configinputfw);
287 %rulehash=%configinputfw;
288 }elsif ($fwdfwsettings{'grp1'} eq 'ipfire_src' ){
290 $fwdfwsettings{'config'}=$configoutgoing;
291 $fwdfwsettings{'chain'} = 'OUTGOINGFW';
292 $maxkey=&General
::findhasharraykey
(\
%configoutgoingfw);
293 %rulehash=%configoutgoingfw;
296 $fwdfwsettings{'config'}=$configfwdfw;
297 $fwdfwsettings{'chain'} = 'FORWARDFW';
298 $maxkey=&General
::findhasharraykey
(\
%configfwdfw);
299 %rulehash=%configfwdfw;
301 #check if we have an identical rule already
302 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
303 foreach my $key (sort keys %rulehash){
304 if ( "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'ruleremark'},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'},$fwdfwsettings{'LIMIT_CON_CON'},$fwdfwsettings{'concon'},$fwdfwsettings{'RATE_LIMIT'},$fwdfwsettings{'ratecon'},$fwdfwsettings{'RATETIME'}"
305 eq "$rulehash{$key}[0],$rulehash{$key}[2],$rulehash{$key}[3],$rulehash{$key}[4],$rulehash{$key}[5],$rulehash{$key}[6],$rulehash{$key}[7],$rulehash{$key}[8],$rulehash{$key}[9],$rulehash{$key}[10],$rulehash{$key}[11],$rulehash{$key}[12],$rulehash{$key}[13],$rulehash{$key}[14],$rulehash{$key}[15],$rulehash{$key}[16],$rulehash{$key}[17],$rulehash{$key}[18],$rulehash{$key}[19],$rulehash{$key}[20],$rulehash{$key}[21],$rulehash{$key}[22],$rulehash{$key}[23],$rulehash{$key}[24],$rulehash{$key}[25],$rulehash{$key}[26],$rulehash{$key}[27],$rulehash{$key}[28],$rulehash{$key}[29],$rulehash{$key}[30],$rulehash{$key}[31],$rulehash{$key}[32],$rulehash{$key}[33],$rulehash{$key}[34],$rulehash{$key}[35],$rulehash{$key}[36]"){
306 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
307 if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark
($fwdfwsettings{'ruleremark'})){
308 $errormessage=$Lang::tr
{'fwdfw err remark'}."<br>";
310 if($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && &validremark
($fwdfwsettings{'ruleremark'})){
313 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
314 $fwdfwsettings{'nosave'} = 'on';
319 #check Rulepos on new Rule
320 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
321 $fwdfwsettings{'oldrulenumber'}=$maxkey;
322 foreach my $key (sort keys %rulehash){
323 if ( "$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'},$fwdfwsettings{'USE_NAT'},$fwdfwsettings{$fwdfwsettings{'nat'}},$fwdfwsettings{'dnatport'},$fwdfwsettings{'nat'},$fwdfwsettings{'LIMIT_CON_CON'},$fwdfwsettings{'concon'},$fwdfwsettings{'RATE_LIMIT'},$fwdfwsettings{'ratecon'},$fwdfwsettings{'RATETIME'}"
324 eq "$rulehash{$key}[0],$rulehash{$key}[2],$rulehash{$key}[3],$rulehash{$key}[4],$rulehash{$key}[5],$rulehash{$key}[6],$rulehash{$key}[7],$rulehash{$key}[8],$rulehash{$key}[9],$rulehash{$key}[10],$rulehash{$key}[11],$rulehash{$key}[12],$rulehash{$key}[13],$rulehash{$key}[14],$rulehash{$key}[15],$rulehash{$key}[18],$rulehash{$key}[19],$rulehash{$key}[20],$rulehash{$key}[21],$rulehash{$key}[22],$rulehash{$key}[23],$rulehash{$key}[24],$rulehash{$key}[25],$rulehash{$key}[26],$rulehash{$key}[27],$rulehash{$key}[28],$rulehash{$key}[29],$rulehash{$key}[30],$rulehash{$key}[31],$rulehash{$key}[32],$rulehash{$key}[33],$rulehash{$key}[34],$rulehash{$key}[35],$rulehash{$key}[36]"){
325 $errormessage.=$Lang::tr
{'fwdfw err ruleexists'};
329 #check if we just close a rule
330 if( $fwdfwsettings{'oldgrp1a'} eq $fwdfwsettings{'grp1'} && $fwdfwsettings{'oldgrp1b'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'oldgrp2a'} eq $fwdfwsettings{'grp2'} && $fwdfwsettings{'oldgrp2b'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'oldgrp3a'} eq $fwdfwsettings{'grp3'} && $fwdfwsettings{'oldgrp3b'} eq $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'oldruletype'} eq $fwdfwsettings{'chain'}){
331 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
332 $fwdfwsettings{'nosave2'} = 'on';
336 #check max concurrent connections per ip address
337 if ($fwdfwsettings{'LIMIT_CON_CON'} eq 'ON'){
338 if (!($fwdfwsettings{'concon'} =~ /^(\d+)$/)) {
339 $errormessage.=$Lang::tr
{'fwdfw err concon'};
342 $fwdfwsettings{'concon'}='';
344 #check ratelimit value
345 if ($fwdfwsettings{'RATE_LIMIT'} eq 'ON'){
346 if (!($fwdfwsettings{'ratecon'} =~ /^(\d+)$/)) {
347 $errormessage.=$Lang::tr
{'fwdfw err ratecon'};
350 $fwdfwsettings{'ratecon'}='';
354 if ($fwdfwsettings{'nosave2'} ne 'on'){
355 &saverule
(\
%rulehash,$fwdfwsettings{'config'});
361 if($fwdfwsettings{'nosave2'} ne 'on'){
362 &General
::firewall_config_changed
();
367 if ($fwdfwsettings{'ACTION'} eq $Lang::tr
{'fwdfw newrule'})
371 if ($fwdfwsettings{'ACTION'} eq $Lang::tr
{'fwdfw toggle'})
374 &General
::readhasharray
($fwdfwsettings{'config'}, \
%togglehash);
375 foreach my $key (sort keys %togglehash){
376 if ($key eq $fwdfwsettings{'key'}){
377 if ($togglehash{$key}[2] eq 'ON'){$togglehash{$key}[2]='';}else{$togglehash{$key}[2]='ON';}
380 &General
::writehasharray
($fwdfwsettings{'config'}, \
%togglehash);
381 &General
::firewall_config_changed
();
384 if ($fwdfwsettings{'ACTION'} eq $Lang::tr
{'fwdfw togglelog'})
387 &General
::readhasharray
($fwdfwsettings{'config'}, \
%togglehash);
388 foreach my $key (sort keys %togglehash){
389 if ($key eq $fwdfwsettings{'key'}){
390 if ($togglehash{$key}[17] eq 'ON'){$togglehash{$key}[17]='';}else{$togglehash{$key}[17]='ON';}
393 &General
::writehasharray
($fwdfwsettings{'config'}, \
%togglehash);
394 &General
::firewall_config_changed
();
397 if ($fwdfwsettings{'ACTION'} eq $Lang::tr
{'fwdfw reread'})
399 &General
::firewall_reload
();
402 if ($fwdfwsettings{'ACTION'} eq 'editrule')
404 $fwdfwsettings{'updatefwrule'}='on';
407 if ($fwdfwsettings{'ACTION'} eq 'deleterule')
411 if ($fwdfwsettings{'ACTION'} eq 'moveup')
416 if ($fwdfwsettings{'ACTION'} eq 'movedown')
421 if ($fwdfwsettings{'ACTION'} eq 'copyrule')
423 $fwdfwsettings{'copyfwrule'}='on';
426 if ($fwdfwsettings{'ACTION'} eq '' or $fwdfwsettings{'ACTION'} eq 'reset')
435 &Header
::openbox
('100%', 'left', "");
437 <form method="POST" action="">
438 <table border='0' width="100%">
441 <input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'>
444 if (&General
::firewall_needs_reload
()) {
446 <input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-weight: bold; color: green;'>
470 $fwdfwsettings{'updatefwrule'}='';
471 $fwdfwsettings{'config'}=$oldchain;
472 $fwdfwsettings{'nobase'}='on';
478 #check ip-address if manual
479 if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){
480 #check if ip with subnet
481 if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?
)$/) {
482 ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'});
483 $subnet = &General
::iporsubtocidr
($subnet);
484 $fwdfwsettings{'isip'}='on';
487 if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
488 $ip=$fwdfwsettings{'src_addr'};
490 $fwdfwsettings{'isip'}='on';
493 if ($fwdfwsettings{'isip'} ne 'on'){
494 if (&General
::validmac
($fwdfwsettings{'src_addr'})){
495 $fwdfwsettings{'ismac'}='on';
498 if ($fwdfwsettings{'isip'} eq 'on'){
500 $ip = &Network
::ip_remove_zero
($ip);
502 ##check if ip is valid
503 if (! &General
::validip
($ip)){
504 $errormessage.=$Lang::tr
{'fwdfw err src_addr'}."<br>";
505 return $errormessage;
507 #check and form valid IP
508 $ip=&General
::ip2dec
($ip);
509 $ip=&General
::dec2ip
($ip);
510 #check if net or broadcast
511 $fwdfwsettings{'src_addr'}="$ip/$subnet";
512 if(!&General
::validipandmask
($fwdfwsettings{'src_addr'})){
513 $errormessage.=$Lang::tr
{'fwdfw err src_addr'}."<br>";
514 return $errormessage;
517 if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){
518 $errormessage.=$Lang::tr
{'fwdfw err src_addr'}."<br>";
519 return $errormessage;
521 }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
522 $fwdfwsettings{'grp1'}='std_net_src';
523 $fwdfwsettings{$fwdfwsettings{'grp1'}} = 'ALL';
527 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr
{'fwdfw err nosrc'}."<br>";}
528 if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){
529 my @parts=split(",",$fwdfwsettings{'SRC_PORT'});
533 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
535 #change dashes with :
538 push(@values,"1:65535");
541 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
542 push(@values,"1:$2");
545 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/ ) {
546 push(@values,"$1:65535");
549 $errormessage .= &General
::validportrange
($_, 'destination');
554 if (&General
::validport
($_)){
561 $fwdfwsettings{'SRC_PORT'}=join("|",@values);
563 return $errormessage;
568 &General
::readhasharray
("$configsrv", \
%customservice);
569 #check DNAT settings (has to be single Host and single Port or portrange)
570 if ($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat'){
571 if($fwdfwsettings{'grp2'} eq 'tgt_addr' || $fwdfwsettings{'grp2'} eq 'cust_host_tgt' || $fwdfwsettings{'grp2'} eq 'ovpn_host_tgt'){
572 # Check if a manual entered IP is a single Host (if set)
573 if ($fwdfwsettings{'grp2'} eq 'tgt_addr') {
574 # Split input into address and prefix (if provided).
575 my ($address, $subnet) = split ('/', $fwdfwsettings{$fwdfwsettings{'grp2'}});
577 # Check if a subnet is given.
579 # Check if the prefix or subnetmask is for a single host.
580 unless ($subnet eq "32" || $subnet eq "255.255.255.255") {
582 $errormessage=$Lang::tr
{'fwdfw dnat error'}."<br>";
585 return $errormessage;
590 #check if Port is a single Port or portrange
591 if ($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
592 if(($fwdfwsettings{'PROT'} ne 'TCP'|| $fwdfwsettings{'PROT'} ne 'UDP') && $fwdfwsettings{'TGT_PORT'} eq ''){
593 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
594 return $errormessage;
596 if (($fwdfwsettings{'PROT'} eq 'TCP'|| $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport
($fwdfwsettings{'TGT_PORT'})){
597 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
598 return $errormessage;
602 if ($fwdfwsettings{'grp2'} ne 'ipfire'){
603 $errormessage=$Lang::tr
{'fwdfw dnat error'}."<br>";
604 return $errormessage;
608 if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
609 #check if ip with subnet
610 if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?
)$/) {
611 ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
612 $subnet = &General
::iporsubtocidr
($subnet);
616 if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
617 $ip=$fwdfwsettings{'tgt_addr'};
621 $ip = &Network
::ip_remove_zero
($ip);
623 #check if ip is valid
624 if (! &General
::validip
($ip)){
625 $errormessage.=$Lang::tr
{'fwdfw err tgt_addr'}."<br>";
626 return $errormessage;
628 #check and form valid IP
629 $ip=&General
::ip2dec
($ip);
630 $ip=&General
::dec2ip
($ip);
631 $fwdfwsettings{'tgt_addr'}="$ip/$subnet";
632 if(!&General
::validipandmask
($fwdfwsettings{'tgt_addr'})){
633 $errormessage.=$Lang::tr
{'fwdfw err tgt_addr'}."<br>";
634 return $errormessage;
636 }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
637 $fwdfwsettings{'grp2'}='std_net_tgt';
638 $fwdfwsettings{$fwdfwsettings{'grp2'}} = 'ALL';
640 #check for mac in targetgroup
641 if ($fwdfwsettings{'grp2'} eq 'cust_grp_tgt'){
642 &General
::readhasharray
("$configgrp", \
%customgrp);
643 &General
::readhasharray
("$confighost", \
%customhost);
644 foreach my $grpkey (sort keys %customgrp){
645 foreach my $hostkey (sort keys %customhost){
646 if ($customgrp{$grpkey}[2] eq $customhost{$hostkey}[0] && $customgrp{$grpkey}[2] eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $customhost{$hostkey}[1] eq 'mac'){
647 $hint=$Lang::tr
{'fwdfw hint mac'};
654 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr
{'fwdfw err notgt'}."<br>";}
656 if ($fwdfwsettings{'USESRV'} eq 'ON'){
657 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
658 $fwdfwsettings{'TGT_PROT'}='';
659 $fwdfwsettings{'ICMP_TGT'}='';
660 $fwdfwsettings{'TGT_PORT'}='';
662 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
663 $fwdfwsettings{'TGT_PROT'}='';
664 $fwdfwsettings{'ICMP_TGT'}='';
665 $fwdfwsettings{'TGT_PORT'}='';
666 #check target service
667 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){
668 $errormessage.=$Lang::tr
{'fwdfw err tgt_grp'};
671 if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
672 if ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP'){
673 if ($fwdfwsettings{'TGT_PORT'} ne ''){
674 if ($fwdfwsettings{'TGT_PORT'} =~ "," && $fwdfwsettings{'USE_NAT'} && $fwdfwsettings{'nat'} eq 'dnat') {
675 $errormessage=$Lang::tr
{'fwdfw dnat porterr'}."<br>";
676 return $errormessage;
678 my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
682 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
684 #change dashes with :
687 push(@values,"1:65535");
690 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
691 push(@values,"1:$2");
694 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
695 push(@values,"$1:65535");
698 $errormessage .= &General
::validportrange
($_, 'destination');
703 if (&General
::validport
($_)){
706 $errormessage=$Lang::tr
{'fwdfw err tgt_port'};
707 return $errormessage;
711 $fwdfwsettings{'TGT_PORT'}=join("|",@values);
713 }elsif ($fwdfwsettings{'PROT'} eq 'GRE'){
714 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
715 $fwdfwsettings{'TGT_PORT'} = '';
716 $fwdfwsettings{'ICMP_TGT'} = '';
717 }elsif ($fwdfwsettings{'PROT'} eq 'ESP'){
718 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
719 $fwdfwsettings{'TGT_PORT'} = '';
720 $fwdfwsettings{'ICMP_TGT'}='';
721 }elsif ($fwdfwsettings{'PROT'} eq 'AH'){
722 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
723 $fwdfwsettings{'TGT_PORT'} = '';
724 $fwdfwsettings{'ICMP_TGT'}='';
725 }elsif ($fwdfwsettings{'PROT'} eq 'ICMP'){
726 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
727 $fwdfwsettings{'TGT_PORT'} = '';
732 if ($fwdfwsettings{'USESRV'} ne 'ON'){
733 $fwdfwsettings{'grp3'}='';
734 $fwdfwsettings{$fwdfwsettings{'grp3'}}='';
735 $fwdfwsettings{'ICMP_TGT'}='';
738 if($fwdfwsettings{'TIME'} eq 'ON'){
739 if($fwdfwsettings{'TIME_MON'} eq '' && $fwdfwsettings{'TIME_TUE'} eq '' && $fwdfwsettings{'TIME_WED'} eq '' && $fwdfwsettings{'TIME_THU'} eq '' && $fwdfwsettings{'TIME_FRI'} eq '' && $fwdfwsettings{'TIME_SAT'} eq '' && $fwdfwsettings{'TIME_SUN'} eq ''){
740 $errormessage=$Lang::tr
{'fwdfw err time'};
741 return $errormessage;
744 return $errormessage;
749 if($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
750 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\-(\d+)$/) {
751 $fwdfwsettings{'dnatport'} =~ tr/-/:/;
752 if ($fwdfwsettings{'dnatport'} eq "*") {
753 $fwdfwsettings{'dnatport'}="1:65535";
755 if ($fwdfwsettings{'dnatport'} =~ /^(\D)\:(\d+)$/) {
756 $fwdfwsettings{'dnatport'} = "1:$2";
758 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\:(\D)$/) {
759 $fwdfwsettings{'dnatport'} ="$1:65535";
764 if ($val =~ "," || $val>65536 || $val<0){
771 #check valid port for NAT
772 if($fwdfwsettings{'USE_NAT'} eq 'ON'){
773 #RULE_ACTION must be ACCEPT if we use NAT
774 $fwdfwsettings{'RULE_ACTION'} = 'ACCEPT';
776 #if no dnat or snat selected errormessage
777 if ($fwdfwsettings{'nat'} eq ''){
778 $errormessage=$Lang::tr
{'fwdfw dnat nochoice'};
782 #if using snat, the external port has to be empty
783 if ($fwdfwsettings{'nat'} eq 'snat' && $fwdfwsettings{'dnatport'} ne ''){
784 $errormessage=$Lang::tr
{'fwdfw dnat extport'};
787 #if no dest port is given in nat area, take target host port
788 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$fwdfwsettings{'TGT_PORT'};}
789 if($fwdfwsettings{'TGT_PORT'} eq '' && $fwdfwsettings{'dnatport'} ne '' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP')){
790 $errormessage=$Lang::tr
{'fwdfw dnat porterr2'};
793 #check if port given in nat area is a single valid port or portrange
794 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport
($fwdfwsettings{'dnatport'})){
795 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
796 }elsif($fwdfwsettings{'USESRV'} eq 'ON' && $fwdfwsettings{'grp3'} eq 'cust_srv'){
798 #get service Protocol and Port
799 foreach my $key (sort keys %customservice){
800 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]){
801 if ($customservice{$key}[2] ne 'TCP' && $customservice{$key}[2] ne 'UDP'){
802 $errormessage=$Lang::tr
{'fwdfw target'}.": ".$Lang::tr
{'fwdfw dnat porterr'}."<br>";
804 $custsrvport= $customservice{$key}[1];
807 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$custsrvport;}
809 #check if DNAT port is multiple
810 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
811 my @parts=split(",",$fwdfwsettings{'dnatport'});
815 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
817 #change dashes with :
820 push(@values,"1:65535");
823 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
824 push(@values,"1:$2");
827 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
828 push(@values,"$1:65535");
831 $errormessage .= &General
::validportrange
($_, 'destination');
836 if (&General
::validport
($_)){
843 $fwdfwsettings{'dnatport'}=join("|",@values);
845 #check if a rule with prot tcp or udp and ports is edited and now prot is "all", then delete all ports
846 if($fwdfwsettings{'PROT'} eq ''){
847 $fwdfwsettings{'dnatport'}='';
851 if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark
($fwdfwsettings{'ruleremark'})){
852 $errormessage.=$Lang::tr
{'fwdfw err remark'}."<br>";
854 #check if source and target identical
855 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL' && $fwdfwsettings{'grp2'} ne 'ipfire'){
856 $errormessage=$Lang::tr
{'fwdfw err same'};
857 return $errormessage;
859 #get source and targetip address if possible
860 my ($sip,$scidr,$tip,$tcidr);
861 ($sip,$scidr)=&get_ip
("src","grp1");
862 ($tip,$tcidr)=&get_ip
("tgt","grp2");
863 #check same iprange in source and target
864 if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){
865 my $networkip1=&General
::getnetworkip
($sip,$scidr);
866 my $networkip2=&General
::getnetworkip
($tip,$tcidr);
867 if ($scidr gt $tcidr){
868 if ( &General
::IpInSubnet
($networkip1,$tip,&General
::iporsubtodec
($tcidr))){
869 $errormessage.=$Lang::tr
{'fwdfw err samesub'};
871 }elsif($scidr eq $tcidr && $scidr eq '32'){
872 my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1);
873 my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2);
874 if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){
875 $hint=$Lang::tr
{'fwdfw hint ip1'}."<br>";
876 $hint.=$Lang::tr
{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>";
879 if ( &General
::IpInSubnet
($networkip2,$sip,&General
::iporsubtodec
($scidr)) ){
880 $errormessage.=$Lang::tr
{'fwdfw err samesub'};
884 #when icmp selected, no source and targetport allowed
885 if (($fwdfwsettings{'PROT'} ne '' && $fwdfwsettings{'PROT'} ne 'TCP' && $fwdfwsettings{'PROT'} ne 'UDP' && $fwdfwsettings{'PROT'} ne 'template') && ($fwdfwsettings{'USESRV'} eq 'ON' || $fwdfwsettings{'USE_SRC_PORT'} eq 'ON')){
886 $errormessage.=$Lang::tr
{'fwdfw err prot_port'};
889 #change protocol if prot not equal dest single service
890 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
891 foreach my $key (sort keys %customservice){
892 if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){
893 if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){
894 $fwdfwsettings{'PROT'} = $customservice{$key}[2];
900 #check source and destination protocol if source manual and dest servicegroup
901 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
902 $fwdfwsettings{'PROT'} = '';
904 #ATTENTION: $fwdfwsetting{'TGT_PROT'} deprecated since 30.09.2013
905 $fwdfwsettings{'TGT_PROT'}=''; #Set field empty (deprecated)
907 if ($fwdfwsettings{'PROT'} eq 'ICMP'){
908 $fwdfwsettings{'USE_SRC_PORT'}='';
909 $fwdfwsettings{'SRC_PORT'}='';
910 #$fwdfwsettings{'USESRV'}='';
911 $fwdfwsettings{'TGT_PORT'}='';
912 &General
::readhasharray
("${General::swroot}/fwhosts/icmp-types", \
%icmptypes);
913 foreach my $key (keys %icmptypes){
914 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){
915 $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]";
918 }elsif($fwdfwsettings{'PROT'} eq 'GRE'){
919 $fwdfwsettings{'USE_SRC_PORT'}='';
920 $fwdfwsettings{'SRC_PORT'}='';
921 $fwdfwsettings{'ICMP_TYPES'}='';
922 $fwdfwsettings{'USESRV'}='';
923 $fwdfwsettings{'TGT_PORT'}='';
924 }elsif($fwdfwsettings{'PROT'} eq 'ESP'){
925 $fwdfwsettings{'USE_SRC_PORT'}='';
926 $fwdfwsettings{'SRC_PORT'}='';
927 $fwdfwsettings{'ICMP_TYPES'}='';
928 $fwdfwsettings{'USESRV'}='';
929 $fwdfwsettings{'TGT_PORT'}='';
930 }elsif($fwdfwsettings{'PROT'} eq 'AH'){
931 $fwdfwsettings{'USE_SRC_PORT'}='';
932 $fwdfwsettings{'SRC_PORT'}='';
933 $fwdfwsettings{'ICMP_TYPES'}='';
934 $fwdfwsettings{'USESRV'}='';
935 $fwdfwsettings{'TGT_PORT'}='';
936 }elsif($fwdfwsettings{'PROT'} eq 'IGMP'){
937 $fwdfwsettings{'USE_SRC_PORT'}='';
938 $fwdfwsettings{'SRC_PORT'}='';
939 $fwdfwsettings{'ICMP_TYPES'}='';
940 $fwdfwsettings{'USESRV'}='';
941 $fwdfwsettings{'TGT_PORT'}='';
942 }elsif($fwdfwsettings{'PROT'} eq 'IPv6'){
943 $fwdfwsettings{'USE_SRC_PORT'}='';
944 $fwdfwsettings{'SRC_PORT'}='';
945 $fwdfwsettings{'ICMP_TYPES'}='';
946 $fwdfwsettings{'USESRV'}='';
947 $fwdfwsettings{'TGT_PORT'}='';
948 }elsif($fwdfwsettings{'PROT'} eq 'IPIP'){
949 $fwdfwsettings{'USE_SRC_PORT'}='';
950 $fwdfwsettings{'SRC_PORT'}='';
951 $fwdfwsettings{'ICMP_TYPES'}='';
952 $fwdfwsettings{'USESRV'}='';
953 $fwdfwsettings{'TGT_PORT'}='';
954 }elsif($fwdfwsettings{'PROT'} ne 'TCP' && $fwdfwsettings{'PROT'} ne 'UDP'){
955 $fwdfwsettings{'ICMP_TYPES'}='';
956 $fwdfwsettings{'SRC_PORT'}='';
957 $fwdfwsettings{'TGT_PORT'}='';
958 }elsif($fwdfwsettings{'PROT'} ne 'ICMP'){
959 $fwdfwsettings{'ICMP_TYPES'}='';
965 #Test if manual IP is part of static OpenVPN networks
966 &General
::readhasharray
("$configccdnet", \
%ccdnet);
967 foreach my $key (sort keys %ccdnet){
968 my ($vpnip,$vpnsubnet) = split ("/",$ccdnet{$key}[1]);
969 my $sub=&General
::iporsubtodec
($vpnsubnet);
970 if (&General
::IpInSubnet
($ip,$vpnip,$sub)){
974 # A Test if manual ip is part of dynamic openvpn subnet is made in getcolor
975 # because if one creates a custom host with the ip, we need to check the color there!
976 # It does not make sense to check this here
978 # Test if manual IP is part of an OpenVPN N2N subnet does also not make sense here
979 # Is also checked in getcolor
981 # Test if manual ip is part of an IPsec Network is also checked in getcolor
991 &General
::readhasharray
($fwdfwsettings{'config'}, \
%delhash);
992 foreach my $key (sort {$a <=> $b} keys %delhash){
993 if ($key >= $fwdfwsettings{'key'}) {
995 if (exists $delhash{$next}) {
996 foreach my $i (0 .. $#{$delhash{$next}}) {
997 $delhash{$key}[$i] = $delhash{$next}[$i];
1002 # Remove the very last entry.
1003 my $last_key = (sort {$a <=> $b} keys %delhash)[-1];
1004 delete $delhash{$last_key};
1006 &General
::writehasharray
($fwdfwsettings{'config'}, \
%delhash);
1007 &General
::firewall_config_changed
();
1009 if($fwdfwsettings{'nobase'} ne 'on'){
1022 &General
::readhasharray
("$configfwdfw", \
%configfwdfw);
1023 foreach my $key (sort keys %configfwdfw){
1024 if ($key eq $key1 ){
1025 if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';}
1028 &General
::writehasharray
("$configfwdfw", \
%configfwdfw);
1029 &General
::firewall_config_changed
();
1033 if ($errormessage) {
1034 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
1035 print "<class name='base'>$errormessage\n";
1036 print " </class>\n";
1037 &Header
::closebox
();
1042 my %hash=%{(shift)};
1045 foreach my $key (sort { ncmp
($hash{$a}[0],$hash{$b}[0]) } keys %hash){
1046 if($hash{$key}[0] eq $val){
1047 print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>";
1049 print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>";
1063 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1064 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1065 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1066 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1067 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1068 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1069 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1070 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1071 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1072 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1073 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1074 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1075 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1076 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1077 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1078 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1079 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1081 <table width='100%' border='0'>
1082 <tr><td width='50%' valign='top'>
1083 <table width='95%' border='0'>
1084 <tr><td width='1%'><input type='radio' name='$grp' id='std_net_$srctgt' value='std_net_$srctgt' $checked{$grp}{'std_net_'.$srctgt}></td><td>$Lang::tr{'fwhost stdnet'}</td><td align='right'><select name='std_net_$srctgt' style='width:200px;'>
1086 foreach my $network (sort keys %defaultNetworks)
1088 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1089 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1091 # Check if the the key handles a standard network.
1092 if ( grep(/std_net_/, $fwdfwsettings{$grp}) ) {
1093 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $defaultNetworks{$network}{'NAME'});
1096 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
1097 my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK";
1098 my $defsub1=&General
::subtocidr
($ifaces{$defsub});
1099 $ifaces{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED');
1100 if ($ifaces{$defnet}){
1101 print ">$network ($ifaces{$defnet}/$defsub1)</option>";
1103 print ">$network</option>";
1106 print"</select></td></tr>";
1108 if (! -z
$confignet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1109 print"<tr><td><input type='radio' name='$grp' id='cust_net_$srctgt' value='cust_net_$srctgt' $checked{$grp}{'cust_net_'.$srctgt}></td><td>$Lang::tr{'fwhost cust net'}</td><td align='right'><select name='cust_net_$srctgt' style='width:200px;'>";
1110 &fillselect
(\
%customnetwork,$fwdfwsettings{$fwdfwsettings{$grp}});
1111 print"</select></td>";
1114 if (! -z
$confighost || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1115 print"<tr><td><input type='radio' name='$grp' id='cust_host_$srctgt' value='cust_host_$srctgt' $checked{$grp}{'cust_host_'.$srctgt}></td><td>$Lang::tr{'fwhost cust addr'}</td><td align='right'><select name='cust_host_$srctgt' style='width:200px;'>";
1116 &fillselect
(\
%customhost,$fwdfwsettings{$fwdfwsettings{$grp}});
1117 print"</select></td>";
1120 if (! -z
$configgrp || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1121 print"<tr><td valign='top'><input type='radio' name='$grp' id='cust_grp_$srctgt' value='cust_grp_$srctgt' $checked{$grp}{'cust_grp_'.$srctgt}></td><td >$Lang::tr{'fwhost cust grp'}</td><td align='right'><select name='cust_grp_$srctgt' style='width:200px;'>";
1122 foreach my $key (sort { ncmp
($customgrp{$a}[0],$customgrp{$b}[0]) } keys %customgrp) {
1123 if($helper ne $customgrp{$key}[0] && $customgrp{$key}[2] ne 'none'){
1125 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $customgrp{$key}[0]);
1126 print ">$customgrp{$key}[0]</option>";
1128 $helper=$customgrp{$key}[0];
1130 print"</select></td>";
1132 # Locations / groups.
1133 my @locations = &fwlib
::get_locations
();
1136 print "<td valign='top'><input type='radio' name='$grp' id='cust_location_$srctgt' value='cust_location_$srctgt' $checked{$grp}{'cust_location_'.$srctgt}></td>\n";
1137 print "<td>$Lang::tr{'location'}</td>\n";
1138 print "<td align='right'><select name='cust_location_$srctgt' style='width:200px;'>\n";
1140 # Add Location groups to dropdown.
1141 if (!-z
$configlocationgrp) {
1142 print "<optgroup label='$Lang::tr{'fwhost cust locationgroup'}'>\n";
1143 foreach my $key (sort { ncmp
($customlocationgrp{$a}[0],$customlocationgrp{$b}[0]) } keys %customlocationgrp) {
1146 # Generate stored value for select detection.
1147 my $stored = join(':', "group",$customlocationgrp{$key}[0]);
1149 # Only show a group once and group with elements.
1150 if($helper ne $customlocationgrp{$key}[0] && $customlocationgrp{$key}[2] ne 'none') {
1151 # Mark current entry as selected.
1152 if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $stored) {
1153 $selected = "selected='selected'";
1155 print"<option $selected value='group:$customlocationgrp{$key}[0]'>$customlocationgrp{$key}[0]</option>\n";
1157 $helper=$customlocationgrp{$key}[0];
1159 print "</optgroup>\n";
1163 print "<optgroup label='$Lang::tr{'fwhost cust location'}'>\n";
1164 foreach my $location (@locations) {
1166 my $country_name = &Location
::Functions
::get_full_country_name
($location);
1168 # Mark current entry as selected.
1170 if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $location) {
1171 $selected = "selected='selected'";
1173 print "<option $selected value='$location'>$location - $country_name</option>\n";
1175 print "</optgroup>\n";
1177 # Close Locations dropdown.
1178 print "</select></td>\n";
1180 #End left table. start right table (vpn)
1181 print"</tr></table></td><td valign='top'><table width='95%' border='0' align='right'><tr>";
1183 if( ! -z
$configccdnet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1184 print"<td width='1%'><input type='radio' name='$grp' id='ovpn_net_$srctgt' value='ovpn_net_$srctgt' $checked{$grp}{'ovpn_net_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_net_$srctgt' style='width:200px;'>";
1185 &fillselect
(\
%ccdnet,$fwdfwsettings{$fwdfwsettings{$grp}});
1186 print"</select></td></tr>";
1189 foreach my $key (sort { ncmp
($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost){
1190 if ($ccdhost{$key}[33] ne '' ){
1191 print"<tr><td width='1%'><input type='radio' name='$grp' id='ovpn_host_$srctgt' value='ovpn_host_$srctgt' $checked{$grp}{'ovpn_host_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_host_$srctgt' style='width:200px;'>" if ($show eq '');
1193 print "<option value='$ccdhost{$key}[1]'";
1194 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1195 print ">$ccdhost{$key}[1]</option>";
1198 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1199 print"<tr><td width='1%'><input type='radio' name='$grp' id='ovpn_host_$srctgt' value='ovpn_host_$srctgt' $checked{$grp}{'ovpn_host_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_host_$srctgt' style='width:200px;'></select></td></tr>" ;
1201 if ($show eq '1'){$show='';print"</select></td></tr>";}
1203 foreach my $key (sort { ncmp
($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost){
1204 if ($ccdhost{$key}[3] eq 'net'){
1205 print"<tr><td width='1%'><input type='radio' name='$grp' id='ovpn_n2n_$srctgt' value='ovpn_n2n_$srctgt' $checked{$grp}{'ovpn_n2n_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ovpn_n2n'}:</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_n2n_$srctgt' style='width:200px;'>" if ($show eq '');
1207 print "<option value='$ccdhost{$key}[1]'";
1208 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1209 print ">$ccdhost{$key}[1]</option>";
1212 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1213 print"<tr><td width='1%'><input type='radio' name='$grp' id='ovpn_n2n_$srctgt' value='ovpn_n2n_$srctgt' $checked{$grp}{'ovpn_n2n_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ovpn_n2n'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_n2n_$srctgt' style='width:200px;'></select></td></tr>" ;
1215 if ($show eq '1'){$show='';print"</select></td></tr>";}
1217 foreach my $key (sort { ncmp
($ipsecconf{$a}[1],$ipsecconf{$b}[1]) } keys %ipsecconf) {
1218 if ($ipsecconf{$key}[3] eq 'net' || ($optionsfw{'SHOWDROPDOWN'} eq 'on' && $ipsecconf{$key}[3] ne 'host')){
1219 print"<tr><td valign='top'><input type='radio' name='$grp' id='ipsec_net_$srctgt' value='ipsec_net_$srctgt' $checked{$grp}{'ipsec_net_'.$srctgt}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td align='right'><select name='ipsec_net_$srctgt' style='width:200px;'>" if ($show eq '');
1222 #Check if we have more than one REMOTE subnet in config
1223 my @arr1 = split /\|/, $ipsecconf{$key}[11];
1227 print "value=$ipsecconf{$key}[1]";
1228 print " selected " if ($fwdfwsettings{$fwdfwsettings{$grp}} eq "$ipsecconf{$key}[1]");
1229 print ">$ipsecconf{$key}[1] ";
1230 print "($Lang::tr{'fwdfw all subnets'})" if $cnt1 > 1; #If this Conenction has more than one subnet, print one option for all subnets
1234 foreach my $val (@arr1){
1235 #normalize subnet to cidr notation
1236 my ($val1,$val2) = split /\//, $val;
1237 my $val3 = &General
::iporsubtocidr
($val2);
1239 print "value='$ipsecconf{$key}[1]|$val1/$val3'";
1240 print "selected " if ($fwdfwsettings{$fwdfwsettings{$grp}} eq "$ipsecconf{$key}[1]|$val1/$val3");
1241 print ">$ipsecconf{$key}[1] ($val1/$val3)</option>";
1246 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1247 print"<tr><td valign='top'><input type='radio' name='$grp' id='ipsec_net_$srctgt' value='ipsec_net_$srctgt' $checked{$grp}{'ipsec_net_'.$srctgt}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td align='right'><select name='ipsec_net_$srctgt' style='width:200px;'><select></td></tr>";
1249 if ($show eq '1'){$show='';print"</select></td></tr>";}
1252 print"</td></tr></table><br>";
1260 &General
::readhash
("/var/ipfire/ethernet/settings", \
%netsettings);
1261 if ($fwdfwsettings{$grp} ne $Lang::tr
{'fwhost any'}){
1262 if ($fwdfwsettings{$grp} eq $val.'_addr'){
1263 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
1264 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
1265 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
1266 $a=$netsettings{'GREEN_NETADDRESS'};
1267 $b=&General
::iporsubtocidr
($netsettings{'GREEN_NETMASK'});
1268 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
1269 $a=$netsettings{'ORANGE_NETADDRESS'};
1270 $b=&General
::iporsubtocidr
($netsettings{'ORANGE_NETMASK'});
1271 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
1272 $a=$netsettings{'BLUE_NETADDRESS'};
1273 $b=&General
::iporsubtocidr
($netsettings{'BLUE_NETMASK'});
1274 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
1275 &General
::readhash
("$configovpn",\
%ovpnsettings);
1276 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
1277 $b=&General
::iporsubtocidr
($b);
1279 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
1280 &General
::readhasharray
("$confignet", \
%customnetwork);
1281 foreach my $key (keys %customnetwork){
1282 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1283 $a=$customnetwork{$key}[1];
1284 $b=&General
::iporsubtocidr
($customnetwork{$key}[2]);
1287 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
1288 &General
::readhasharray
("$confighost", \
%customhost);
1289 foreach my $key (keys %customhost){
1290 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1291 if ($customhost{$key}[1] eq 'ip'){
1292 ($a,$b)=split (/\//,$customhost{$key}[2]);
1293 $b=&General
::iporsubtocidr
($b);
1295 if ($grp eq 'grp2'){
1296 $errormessage=$Lang::tr
{'fwdfw err tgt_mac'};
1308 &General
::setup_default_networks
(\
%defaultNetworks);
1309 foreach my $network (sort keys %defaultNetworks)
1311 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1316 my %hash=%{(shift)};
1318 if($hash{$key}[7] eq 'ON' && $hash{$key}[10]){
1319 $hash{$key}[10]=~ s/\|/,/g;
1320 print": $hash{$key}[10]";
1321 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
1322 print": <br>$hash{$key}[9] ";
1327 my %hash=%{(shift)};
1331 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1332 if($hash{$key}[14] eq 'cust_srv'){
1333 &General
::readhasharray
("$configsrv", \
%customservice);
1334 foreach my $i (sort keys %customservice){
1335 if($customservice{$i}[0] eq $hash{$key}[15]){
1336 $service = $customservice{$i}[0];
1339 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
1340 $service=$hash{$key}[15];
1341 }elsif($hash{$key}[14] eq 'TGT_PORT'){
1342 $hash{$key}[15]=~ s/\|/,/g;
1343 $service=$hash{$key}[15];
1350 sub get_serviceports
1354 &General
::readhasharray
("$configsrv", \
%customservice);
1355 &General
::readhasharray
("$configsrvgrp", \
%customservicegrp);
1357 my @specprot=("IPIP","IPV6","IGMP","GRE","AH","ESP");
1358 if($type eq 'service'){
1359 foreach my $key (sort { ncmp
($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1360 if ($customservice{$key}[0] eq $name){
1361 push (@protocols,$customservice{$key}[2]);
1364 }elsif($type eq 'group'){
1365 foreach my $key (sort { ncmp
($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1366 if ($customservicegrp{$key}[0] eq $name){
1367 if ($customservicegrp{$key}[2] ~~ @specprot){
1368 push (@protocols," ".$customservicegrp{$key}[2]);
1370 foreach my $key1 (sort { ncmp
($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1371 if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
1372 if (!grep(/$customservice{$key1}[2]/, @protocols)){
1373 push (@protocols,$customservice{$key1}[2]);}
1381 # Sort protocols alphabetically.
1382 @protocols = sort(@protocols);
1391 if($optionsfw{'SHOWCOLORS'} eq 'on'){
1392 # Don't colourise MAC addresses
1393 if (&General
::validmac
($val)) {
1399 if ($nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1400 foreach my $key (sort keys %$hash){
1401 if ($$hash{$key}[0] eq $val){
1402 $val=$$hash{$key}[2];
1407 if ($val eq 'GREEN'){
1408 $tdcolor="style='background-color: $Header::colourgreen;color:white;'";
1410 }elsif ($val eq 'ORANGE'){
1411 $tdcolor="style='background-color: $Header::colourorange;color:white;'";
1413 }elsif ($val eq 'BLUE'){
1414 $tdcolor="style='background-color: $Header::colourblue;color:white;'";
1416 }elsif ($val eq 'RED' ||$val eq 'RED1' ){
1417 $tdcolor="style='background-color: $Header::colourred;color:white;'";
1419 }elsif ($val eq 'IPFire' ){
1420 $tdcolor="style='background-color: $Header::colourred;color:white;'";
1422 }elsif ($val eq 'OpenVPN-Dyn' ){
1423 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1425 }elsif ($val eq 'IPsec RW' ){
1426 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1428 }elsif($val =~ /^(.*?)\/(.*?
)$/){
1429 my ($sip,$scidr) = split ("/",$val);
1430 if ( &Header
::orange_used
() && &General
::IpInSubnet
($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1431 $tdcolor="style='background-color: $Header::colourorange;color:white;'";
1434 if ( &General
::IpInSubnet
($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1435 $tdcolor="style='background-color: $Header::colourgreen;color:white;'";
1438 if ( &Header
::blue_used
() && &General
::IpInSubnet
($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
1439 $tdcolor="style='background-color: $Header::colourblue;color:white;'";
1442 }elsif ($val eq 'Default IP'){
1443 $tdcolor="style='background-color: $Header::colourred;color:white;'";
1446 #Check if a manual IP or custom host is part of a VPN
1447 if ($nettype eq 'src_addr' || $nettype eq 'tgt_addr' || $nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1448 #Check if IP is part of OpenVPN dynamic subnet
1449 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
1450 my ($c,$d) = split("/",$val);
1451 if (&General
::IpInSubnet
($c,$a,$b)){
1452 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1455 #Check if IP is part of OpenVPN static subnet
1456 foreach my $key (sort keys %ccdnet){
1457 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1458 $b =&General
::iporsubtodec
($b);
1459 if (&General
::IpInSubnet
($c,$a,$b)){
1460 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1464 #Check if IP is part of OpenVPN N2N subnet
1465 foreach my $key (sort keys %ccdhost){
1466 if ($ccdhost{$key}[3] eq 'net'){
1467 my ($a,$b) = split("/",$ccdhost{$key}[11]);
1468 if (&General
::IpInSubnet
($c,$a,$b)){
1469 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1474 #Check if IP is part of IPsec RW network
1475 if ($ipsecsettings{'RW_NET'} ne ''){
1476 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1477 $b=&General
::iporsubtodec
($b);
1478 if (&General
::IpInSubnet
($c,$a,$b)){
1479 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1483 #Check if IP is part of a IPsec N2N network
1484 foreach my $key (sort keys %ipsecconf){
1485 if ($ipsecconf{$key}[11]){
1486 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1487 $b=&General
::iporsubtodec
($b);
1488 if (&General
::IpInSubnet
($c,$a,$b)){
1489 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1496 if ($nettype eq 'ovpn_n2n_src' || $nettype eq 'ovpn_n2n_tgt' || $nettype eq 'ovpn_net_src' || $nettype eq 'ovpn_net_tgt'|| $nettype eq 'ovpn_host_src' || $nettype eq 'ovpn_host_tgt'){
1497 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1500 if ($nettype eq 'ipsec_net_src' || $nettype eq 'ipsec_net_tgt'){
1501 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1505 foreach my $alias (sort keys %aliases)
1507 if ($val eq $alias){
1508 $tdcolor="style='background-color:$Header::colourred;color:white;'";
1519 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwhost hint'});
1520 print "<class name='base'>$hint\n";
1521 print " </class>\n";
1522 &Header
::closebox
();
1528 &General
::setup_default_networks
(\
%defaultNetworks);
1529 &General
::readhash
("/var/ipfire/ethernet/settings", \
%netsettings);
1530 #read all configfiles
1531 &General
::readhasharray
("$configccdnet", \
%ccdnet);
1532 &General
::readhasharray
("$confignet", \
%customnetwork);
1533 &General
::readhasharray
("$configccdhost", \
%ccdhost);
1534 &General
::readhasharray
("$confighost", \
%customhost);
1535 &General
::readhasharray
("$configccdhost", \
%ccdhost);
1536 &General
::readhasharray
("$configgrp", \
%customgrp);
1537 &General
::readhasharray
("$configlocationgrp", \
%customlocationgrp);
1538 &General
::readhasharray
("$configipsec", \
%ipsecconf);
1539 &General
::get_aliases
(\
%aliases);
1546 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
1547 my $config=$fwdfwsettings{'config'};
1550 open (CONN1
,"/var/ipfire/red/local-ipaddress");
1551 my $redip = <CONN1
>;
1553 if (! $fwdfwsettings{'RULE_ACTION'} && $fwdfwsettings{'POLICY'} eq 'MODE2'){
1554 $fwdfwsettings{'RULE_ACTION'}='DROP';
1555 }elsif(! $fwdfwsettings{'RULE_ACTION'} && $fwdfwsettings{'POLICY'} eq 'MODE1'){
1556 $fwdfwsettings{'RULE_ACTION'}='ACCEPT';
1558 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1559 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1560 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1561 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1562 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1563 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1564 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1565 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1566 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1567 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1568 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1569 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1570 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1571 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1572 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1573 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1574 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1575 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1576 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} = 'selected' if ($fwdfwsettings{'grp2'} eq "ipfire");
1577 $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} = 'selected' if ($fwdfwsettings{'grp1'} eq "ipfire_src");
1578 #check if update and get values
1579 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
1580 &General
::readhasharray
("$config", \
%hash);
1581 foreach my $key (sort keys %hash){
1583 if ($key eq $fwdfwsettings{'key'}){
1584 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
1585 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
1586 $fwdfwsettings{'chain'} = $hash{$key}[1];
1587 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1588 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1589 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1590 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1591 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1592 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1593 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1594 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1595 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1596 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1597 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1598 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1599 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1600 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1601 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1602 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1603 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1604 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1605 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1606 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1607 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1608 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1609 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1610 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1611 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1612 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
1613 $fwdfwsettings{'USE_NAT'} = $hash{$key}[28];
1614 $fwdfwsettings{'nat'} = $hash{$key}[31]; #changed order
1615 $fwdfwsettings{$fwdfwsettings{'nat'}} = $hash{$key}[29];
1617 #When copying a DNAT Rule, the sourceport has to be empty at this point.
1618 if($hash{$key}[14] eq 'cust_srv' and $hash{$key}[31] eq 'dnat'){
1619 $hash{$key}[30] = '';
1621 $fwdfwsettings{'dnatport'} = $hash{$key}[30];
1622 $fwdfwsettings{'LIMIT_CON_CON'} = $hash{$key}[32];
1623 $fwdfwsettings{'concon'} = $hash{$key}[33];
1624 $fwdfwsettings{'RATE_LIMIT'} = $hash{$key}[34];
1625 $fwdfwsettings{'ratecon'} = $hash{$key}[35];
1626 $fwdfwsettings{'RATETIME'} = $hash{$key}[36];
1627 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1628 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1629 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1630 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1631 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1632 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1633 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1634 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1635 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1636 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1637 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1638 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1639 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1640 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1641 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1642 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1643 $checked{'nat'}{$fwdfwsettings{'nat'}} = 'CHECKED';
1644 $checked{'LIMIT_CON_CON'}{$fwdfwsettings{'LIMIT_CON_CON'}} = 'CHECKED';
1645 $checked{'RATE_LIMIT'}{$fwdfwsettings{'RATE_LIMIT'}} = 'CHECKED';
1646 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1647 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1648 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} = 'selected' if ($fwdfwsettings{'grp2'} eq "ipfire");
1649 $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} = 'selected' if ($fwdfwsettings{'grp1'} eq "ipfire_src");
1650 $selected{'dnat'}{$fwdfwsettings{'dnat'}} ='selected';
1651 $selected{'snat'}{$fwdfwsettings{'snat'}} ='selected';
1652 $selected{'RATETIME'}{$fwdfwsettings{'RATETIME'}} ='selected';
1655 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1656 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1657 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1658 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1659 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1660 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1661 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1662 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1663 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1664 $fwdfwsettings{'oldruletype'}=$fwdfwsettings{'chain'};
1665 $fwdfwsettings{'oldconcon'}=$fwdfwsettings{'LIMIT_CON_CON'};
1666 $fwdfwsettings{'olduseratelimit'}=$fwdfwsettings{'RATE_LIMIT'};
1667 $fwdfwsettings{'olduseratelimitamount'}=$fwdfwsettings{'ratecon'};
1668 $fwdfwsettings{'oldratelimittime'}=$fwdfwsettings{'RATETIME'};
1670 #check if manual ip (source) is orange network
1671 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1672 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1673 if ( &General
::IpInSubnet
($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1674 $fwdfwsettings{'oldorange'} ='on';
1678 $fwdfwsettings{'ACTIVE'}='ON';
1679 $fwdfwsettings{'nat'} = 'dnat';
1680 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1681 $checked{'nat'}{$fwdfwsettings{'nat'}} = 'CHECKED';
1682 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1683 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1684 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1685 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1686 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1687 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1688 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1689 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1690 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1691 $fwdfwsettings{'oldconcon'}=$fwdfwsettings{'LIMIT_CON_CON'};
1692 #check if manual ip (source) is orange network
1693 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1694 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1695 if ( &General
::IpInSubnet
($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1696 $fwdfwsettings{'oldorange'} ='on';
1700 # Split manual source and target address and delete the subnet
1701 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1702 if ($scidr eq '32'){$fwdfwsettings{$fwdfwsettings{'grp1'}}=$sip;}
1703 my ($dip,$dcidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp2'}});
1704 if ($dcidr eq '32'){$fwdfwsettings{$fwdfwsettings{'grp2'}}=$dip;}
1705 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw source'});
1706 #------SOURCE-------------------------------------------------------
1707 print "<form method='post'>";
1709 <table width='100%' border='0'>
1710 <tr><td width='1%'><input type='radio' name='grp1' value='src_addr' checked></td><td width='60%'>$Lang::tr{'fwdfw sourceip'}<input type='TEXT' name='src_addr' value='$fwdfwsettings{'src_addr'}' size='16' maxlength='18' ></td><td width='1%'><input type='radio' name='grp1' id='ipfire_src' value='ipfire_src' $checked{'grp1'}{'ipfire_src'}></td><td><b>Firewall</b></td>
1712 print"<td align='right'><select name='ipfire_src' style='width:200px;'>";
1713 print "<option value='ALL' $selected{'ipfire_src'}{'ALL'}>$Lang::tr{'all'}</option>";
1714 print "<option value='GREEN' $selected{'ipfire_src'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
1715 print "<option value='ORANGE' $selected{'ipfire_src'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if (&Header
::orange_used
());
1716 print "<option value='BLUE' $selected{'ipfire_src'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>" if (&Header
::blue_used
());
1717 print "<option value='RED1' $selected{'ipfire_src'}{'RED1'}>$Lang::tr{'red1'} ($redip)" if ($redip);
1718 if (! -z
"${General::swroot}/ethernet/aliases"){
1719 foreach my $alias (sort keys %aliases)
1721 print "<option value='$alias' $selected{'ipfire_src'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
1726 <tr><td><br></td></tr>
1729 &gen_dd_block
('src','grp1');
1730 &Header
::closebox
();
1732 #---SNAT / DNAT ------------------------------------------------
1733 &Header
::openbox
('100%', 'left', 'NAT');
1736 <input type='checkbox' name='USE_NAT' id='USE_NAT' value="ON" $checked{'USE_NAT'}{'ON'}>
1737 $Lang::tr{'fwdfw use nat'}
1740 <table class='fw-nat' width='100%' border='0'>
1742 <td width='5%'></td>
1745 <input type='radio' name='nat' value='dnat' $checked{'nat'}{'dnat'}>
1746 $Lang::tr{'fwdfw dnat'}
1752 <td width='25%' align='right'><span class='dnat'>$Lang::tr{'dnat address'}:</span></td>
1754 <select name='dnat' class='dnat' style='width: 100%;'>
1755 <option value='AUTO' $selected{'dnat'}{'AUTO'}>- $Lang::tr{'automatic'} -</option>
1756 <option value='Default IP' $selected{'dnat'}{'Default IP'}>$Lang::tr{'red1'} ($redip)</option>
1759 foreach my $alias (sort keys %aliases) {
1760 print "<option value='$alias' $selected{'dnat'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
1764 foreach my $network (sort keys %defaultNetworks)
1766 if ($defaultNetworks{$network}{'NAME'} eq 'BLUE'||$defaultNetworks{$network}{'NAME'} eq 'GREEN' ||$defaultNetworks{$network}{'NAME'} eq 'ORANGE'){
1767 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1768 print " selected='selected'" if ($fwdfwsettings{'dnat'} eq $defaultNetworks{$network}{'NAME'});
1769 print ">$network ($defaultNetworks{$network}{'NET'})</option>";
1778 <td width='5%'></td>
1781 <input type='radio' name='nat' value='snat' $checked{'nat'}{'snat'}>
1782 $Lang::tr{'fwdfw snat'}
1785 <td width='25%' align='right'><span class='snat'>$Lang::tr{'snat new source ip address'}:</span></td>
1787 <select name='snat' class='snat' style='width: 100%;'>
1788 <option value='RED' $selected{'snat'}{'RED'}>$Lang::tr{'red1'} ($redip)</option>
1791 foreach my $alias (sort keys %aliases) {
1792 print "<option value='$alias' $selected{'snat'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
1795 foreach my $network (sort keys %defaultNetworks) {
1796 if ($defaultNetworks{$network}{'NAME'} eq 'BLUE'||$defaultNetworks{$network}{'NAME'} eq 'GREEN' ||$defaultNetworks{$network}{'NAME'} eq 'ORANGE'){
1797 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1798 print " selected='selected'" if ($fwdfwsettings{'snat'} eq $defaultNetworks{$network}{'NAME'});
1799 print ">$network ($defaultNetworks{$network}{'NET'})</option>";
1809 &Header
::closebox
();
1811 #---TARGET------------------------------------------------------
1812 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw target'});
1814 <table width='100%' border='0'>
1815 <tr><td width='1%'><input type='radio' name='grp2' value='tgt_addr' checked></td><td width='60%' nowrap='nowrap'>$Lang::tr{'fwdfw targetip'}<input type='TEXT' name='tgt_addr' value='$fwdfwsettings{'tgt_addr'}' size='16' maxlength='18'><td width='1%'><input type='radio' name='grp2' id='ipfire' value='ipfire' $checked{'grp2'}{'ipfire'}></td><td><b>Firewall</b></td>
1817 print"<td align='right'><select name='ipfire' style='width:200px;'>";
1818 print "<option value='ALL' $selected{'ipfire'}{'ALL'}>$Lang::tr{'all'}</option>";
1819 print "<option value='GREEN' $selected{'ipfire'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
1820 print "<option value='ORANGE' $selected{'ipfire'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if (&Header
::orange_used
());
1821 print "<option value='BLUE' $selected{'ipfire'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>"if (&Header
::blue_used
());
1822 print "<option value='RED1' $selected{'ipfire'}{'RED1'}>$Lang::tr{'red1'} ($redip)" if ($redip);
1823 if (! -z
"${General::swroot}/ethernet/aliases"){
1824 foreach my $alias (sort keys %aliases)
1826 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
1831 <tr><td><br></td></tr></table>
1833 &gen_dd_block
('tgt','grp2');
1835 #---PROTOCOL------------------------------------------------------
1836 $fwdfwsettings{'SRC_PORT'} =~ s/\|/,/g;
1837 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
1838 $fwdfwsettings{'dnatport'} =~ tr/|/,/;
1840 # The dnatport may be empty, if it matches TGT_PORT
1841 if ($fwdfwsettings{'dnatport'} eq $fwdfwsettings{'TGT_PORT'}) {
1842 $fwdfwsettings{'dnatport'} = "";
1845 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwhost prot'});
1846 #Fix Protocol for JQuery
1847 if ($fwdfwsettings{'grp3'} eq 'cust_srv' || $fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
1848 $fwdfwsettings{'PROT'} = 'template';
1851 <table width='100%' border='0'>
1854 <select name='PROT' id='protocol' style="width: 95px;">
1856 print "<option value=\"\"";
1857 if ($fwdfwsettings{'PROT'} eq '') {
1858 print " selected=\"selected\"";
1860 print ">$Lang::tr{'all'}</option>";
1862 print "<option value=\"template\"";
1863 print " selected=\"selected\"" if ($fwdfwsettings{'grp3'} eq 'cust_srv' || $fwdfwsettings{'grp3'} eq 'cust_srvgrp');
1864 print ">- $Lang::tr{'template'} -</option>";
1866 foreach (@PROTOCOLS) {
1867 print"<option value=\"$_\"";
1868 if ($_ eq $fwdfwsettings{'PROT'}) {
1869 print " selected=\"selected\"";
1872 print ">$Lang::tr{'fwdfw prot41'}</option>";
1874 print ">$_</option>";
1882 <table width='100%' border='0' id="PROTOCOL_ICMP_TYPES">
1884 <td width='20%'>$Lang::tr{'fwhost icmptype'}</td>
1886 <select name='ICMP_TYPES' style='min-width:230px;'>
1888 &General
::readhasharray
("${General::swroot}/fwhosts/icmp-types", \
%icmptypes);
1889 print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>";
1890 foreach my $key (sort { ncmp
($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
1891 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1892 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1894 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1904 <table width="100%" border="0" id="PROTOCOL_PORTS">
1906 <!-- #SOURCEPORT -->
1908 $Lang::tr{'fwdfw use srcport'}
1911 <input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18'>
1916 <!-- #TARGETPORT -->
1918 $Lang::tr{'fwdfw use srv'}
1922 <input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18'>
1926 <td colspan='3'></td>
1927 <td>$Lang::tr{'fwdfw external port nat'}:</td>
1929 <input type='text' name='dnatport' value=\"$fwdfwsettings{'dnatport'}\" maxlength='20' size='18'>
1934 <table width="100%" border="0" id="PROTOCOL_TEMPLATE">
1937 <input type='radio' name='grp3' id='cust_srv' value='cust_srv' checked>
1938 $Lang::tr{'fwhost cust service'}
1941 <select name='cust_srv' style='min-width: 230px;'>
1944 &General
::readhasharray
("$configsrv", \
%customservice);
1945 foreach my $key (sort { ncmp
($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1947 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1948 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1957 <input type='radio' name='grp3' id='cust_srvgrp' value='cust_srvgrp' $checked{'grp3'}{'cust_srvgrp'}>
1958 $Lang::tr{'fwhost cust srvgrp'}
1961 <select name='cust_srvgrp' style='min-width:230px;'>
1964 &General
::readhasharray
("$configsrvgrp", \
%customservicegrp);
1966 foreach my $key (sort { ncmp
($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1967 if ($helper ne $customservicegrp{$key}[0] && $customservicegrp{$key}[2] ne 'none'){
1969 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1970 print">$customservicegrp{$key}[0]</option>";
1972 $helper=$customservicegrp{$key}[0];
1986 $checked{"RULE_ACTION"}{$fwdfwsettings{'RULE_ACTION'}} = 'CHECKED';
1989 <table width="80%" class='tbl' id='actions'>
1991 <td width="33%" align="center" bgcolor="$color{'color17'}">
1994 <td width="33%" align="center" bgcolor="$color{'color25'}">
1997 <td width="33%" align="center" bgcolor="$color{'color16'}">
2002 <td width="33%" align="center">
2004 <input type="radio" name="RULE_ACTION" value="ACCEPT" $checked{"RULE_ACTION"}{"ACCEPT"}>
2005 <strong>$Lang::tr{'fwdfw ACCEPT'}</strong>
2008 <td width="33%" align="center">
2010 <input type="radio" name="RULE_ACTION" value="DROP" $checked{"RULE_ACTION"}{"DROP"}>
2011 <strong>$Lang::tr{'fwdfw DROP'}</strong>
2014 <td width="33%" align="center">
2016 <input type="radio" name="RULE_ACTION" value="REJECT" $checked{"RULE_ACTION"}{"REJECT"}>
2017 <strong>$Lang::tr{'fwdfw REJECT'}</strong>
2026 #---Activate/logging/remark-------------------------------------
2027 &Header
::openbox
('100%', 'left', $Lang::tr
{'fwdfw additional'});
2029 <table width='100%' border='0'>
2031 print"<tr><td width='12%'>$Lang::tr{'remark'}:</td><td width='88%' align='left'><input type='text' name='ruleremark' maxlength='255' value='$fwdfwsettings{'ruleremark'}' style='width:99%;'></td></tr>";
2032 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
2033 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
2034 for (my $count =1; $count <= $sum; $count++){
2035 print"<option value='$count' ";
2036 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
2037 print">$count</option>";
2039 print"</select></td></tr>";
2041 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
2046 <table width='100%'>
2050 if ($fwdfwsettings{'updatefwrule'} eq 'on') {
2053 <input type='checkbox' name='ACTIVE' value="ON" $checked{'ACTIVE'}{'ON'}>
2055 <td>$Lang::tr{'fwdfw rule activate'}</td>
2060 <input type="hidden" name="ACTIVE" value="ON">
2069 <input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'}>
2071 <td>$Lang::tr{'fwdfw log rule'}</td>
2075 <input type='checkbox' name='TIME' id="USE_TIME_CONSTRAINTS" value='ON' $checked{'TIME'}{'ON'}>
2077 <td>$Lang::tr{'fwdfw timeframe'}</td>
2079 <tr id="TIME_CONSTRAINTS">
2081 <table width="66%" border="0">
2083 <td width="8em"> </td>
2084 <td align="center">$Lang::tr{'advproxy monday'}</td>
2085 <td align="center">$Lang::tr{'advproxy tuesday'}</td>
2086 <td align="center">$Lang::tr{'advproxy wednesday'}</td>
2087 <td align="center">$Lang::tr{'advproxy thursday'}</td>
2088 <td align="center">$Lang::tr{'advproxy friday'}</td>
2089 <td align="center">$Lang::tr{'advproxy saturday'}</td>
2090 <td align="center">$Lang::tr{'advproxy sunday'}</td>
2094 <td width="8em"> </td>
2095 <td align="center"><input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} ></td>
2096 <td align="center"><input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} ></td>
2097 <td align="center"><input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} ></td>
2098 <td align="center"><input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} ></td>
2099 <td align="center"><input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} ></td>
2100 <td align="center"><input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} ></td>
2101 <td align="center"><input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} ></td>
2103 <select name='TIME_FROM'>
2105 for (my $i=0;$i<=23;$i++) {
2106 $i = sprintf("%02s",$i);
2107 for (my $j=0;$j<=45;$j+=15) {
2108 $j = sprintf("%02s",$j);
2109 my $time = $i.":".$j;
2110 print "<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
2115 <select name='TIME_TO'>
2117 for (my $i=0;$i<=23;$i++) {
2118 $i = sprintf("%02s",$i);
2119 for (my $j=0;$j<=45;$j+=15) {
2120 $j = sprintf("%02s",$j);
2121 my $time = $i.":".$j;
2122 print "<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
2134 <input type='checkbox' name='LIMIT_CON_CON' id="USE_LIMIT_CONCURRENT_CONNECTIONS_PER_IP" value='ON' $checked{'LIMIT_CON_CON'}{'ON'}>
2136 <td>$Lang::tr{'fwdfw limitconcon'}</td>
2140 <table width='66%' border='0'>
2142 <td width="20em"> </td>
2143 <td>$Lang::tr{'fwdfw maxconcon'}: <input type='text' name='concon' size='2' value="$fwdfwsettings{'concon'}"></td>
2150 <input type='checkbox' name='RATE_LIMIT' id="USE_RATELIMIT" value='ON' $checked{'RATE_LIMIT'}{'ON'}>
2152 <td>$Lang::tr{'fwdfw ratelimit'}</td>
2156 <table width='66%' border='0'>
2158 <td width="20em"> </td>
2159 <td>$Lang::tr{'fwdfw numcon'}: <input type='text' name='ratecon' size='2' value="$fwdfwsettings{'ratecon'}"> /
2160 <select name='RATETIME' style='width:100px;'>
2161 <option value='second' $selected{'RATETIME'}{'second'}>$Lang::tr{'age second'}</option>
2162 <option value='minute' $selected{'RATETIME'}{'minute'}>$Lang::tr{'minute'}</option>
2163 <option value='hour' $selected{'RATETIME'}{'hour'}>$Lang::tr{'hour'}</option>
2174 #---ACTION------------------------------------------------------
2175 if($fwdfwsettings{'updatefwrule'} ne 'on'){
2177 <table border='0' width='100%'>
2178 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
2179 <input type='hidden' name='config' value='$config' >
2180 <input type='hidden' name='ACTION' value='saverule' ></form>
2181 <form method='post' style='display:inline;'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='reset'></form></td></tr>
2187 <table border='0' width='100%'>
2188 <tr><td align='right'><input type='submit' value='$Lang::tr{'fwdfw change'}' style='min-width:100px;' /><input type='hidden' name='updatefwrule' value='$fwdfwsettings{'updatefwrule'}'><input type='hidden' name='key' value='$fwdfwsettings{'key'}'>
2189 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
2190 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
2191 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
2192 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
2193 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
2194 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
2195 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
2196 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
2197 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
2198 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
2199 <input type='hidden' name='oldorange' value='$fwdfwsettings{'oldorange'}' />
2200 <input type='hidden' name='oldnat' value='$fwdfwsettings{'oldnat'}' />
2201 <input type='hidden' name='oldruletype' value='$fwdfwsettings{'oldruletype'}' />
2202 <input type='hidden' name='oldconcon' value='$fwdfwsettings{'oldconcon'}' />
2203 <input type='hidden' name='ACTION' value='saverule' ></form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'><input type='hidden' name='ACTION' value'reset'></td></td>
2207 &Header
::closebox
();
2213 &General
::readhasharray
($fwdfwsettings{'config'}, \
%uphash);
2214 foreach my $key (sort keys %uphash){
2215 if ($key eq $fwdfwsettings{'key'}) {
2217 if (exists $uphash{$last}){
2219 foreach my $y (0 .. $#{$uphash{$last}}) {
2220 $tmp{0}[$y] = $uphash{$last}[$y];
2222 #copy active rule to last
2223 foreach my $i (0 .. $#{$uphash{$last}}) {
2224 $uphash{$last}[$i] = $uphash{$key}[$i];
2226 #copy saved rule to actual position
2227 foreach my $x (0 .. $#{$tmp{0}}) {
2228 $uphash{$key}[$x] = $tmp{0}[$x];
2233 &General
::writehasharray
($fwdfwsettings{'config'}, \
%uphash);
2234 &General
::firewall_config_changed
();
2240 &General
::readhasharray
($fwdfwsettings{'config'}, \
%downhash);
2241 foreach my $key (sort keys %downhash){
2242 if ($key eq $fwdfwsettings{'key'}) {
2243 my $next = $key + 1;
2244 if (exists $downhash{$next}){
2246 foreach my $y (0 .. $#{$downhash{$next}}) {
2247 $tmp{0}[$y] = $downhash{$next}[$y];
2249 #copy active rule to next
2250 foreach my $i (0 .. $#{$downhash{$next}}) {
2251 $downhash{$next}[$i] = $downhash{$key}[$i];
2253 #copy saved rule to actual position
2254 foreach my $x (0 .. $#{$tmp{0}}) {
2255 $downhash{$key}[$x] = $tmp{0}[$x];
2260 &General
::writehasharray
($fwdfwsettings{'config'}, \
%downhash);
2261 &General
::firewall_config_changed
();
2267 &General
::readhasharray
("$config", $hash);
2268 if (!$errormessage){
2269 ################################################################
2270 #check if we change an INPUT rule to a OUTGOING
2271 if($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW' ){
2272 &changerule
($configinput);
2275 #check if we change an INPUT rule to a FORWARD
2276 elsif($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
2277 &changerule
($configinput);
2280 ################################################################
2281 #check if we change an OUTGOING rule to an INPUT
2282 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'INPUTFW' ){
2283 &changerule
($configoutgoing);
2286 #check if we change an OUTGOING rule to a FORWARD
2287 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
2288 &changerule
($configoutgoing);
2291 ################################################################
2292 #check if we change a FORWARD rule to an INPUT
2293 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'INPUTFW'){
2294 &changerule
($configfwdfw);
2297 #check if we change a FORWARD rule to an OUTGOING
2298 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW'){
2299 &changerule
($configfwdfw);
2302 $fwdfwsettings{'ruleremark'}=~ s/,/;/g;
2303 utf8
::decode
($fwdfwsettings{'ruleremark'});
2304 $fwdfwsettings{'ruleremark'}=&Header
::escape
($fwdfwsettings{'ruleremark'});
2305 if ($fwdfwsettings{'updatefwrule'} ne 'on'){
2306 my $key = &General
::findhasharraykey
($hash);
2307 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
2308 $$hash{$key}[1] = $fwdfwsettings{'chain'};
2309 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
2310 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
2311 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
2312 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
2313 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
2314 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
2315 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
2316 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
2317 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
2318 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
2319 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
2320 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
2321 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
2322 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
2323 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
2324 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
2325 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
2326 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
2327 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
2328 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
2329 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
2330 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
2331 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
2332 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
2333 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
2334 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
2335 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
2336 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
2337 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
2338 $$hash{$key}[31] = $fwdfwsettings{'nat'};
2339 $$hash{$key}[32] = $fwdfwsettings{'LIMIT_CON_CON'};
2340 $$hash{$key}[33] = $fwdfwsettings{'concon'};
2341 $$hash{$key}[34] = $fwdfwsettings{'RATE_LIMIT'};
2342 $$hash{$key}[35] = $fwdfwsettings{'ratecon'};
2343 $$hash{$key}[36] = $fwdfwsettings{'RATETIME'};
2344 &General
::writehasharray
("$config", $hash);
2346 foreach my $key (sort {$a <=> $b} keys %$hash){
2347 if($key eq $fwdfwsettings{'key'}){
2348 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
2349 $$hash{$key}[1] = $fwdfwsettings{'chain'};
2350 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
2351 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
2352 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
2353 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
2354 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
2355 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
2356 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
2357 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
2358 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
2359 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
2360 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
2361 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
2362 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
2363 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
2364 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
2365 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
2366 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
2367 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
2368 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
2369 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
2370 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
2371 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
2372 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
2373 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
2374 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
2375 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
2376 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
2377 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
2378 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
2379 $$hash{$key}[31] = $fwdfwsettings{'nat'};
2380 $$hash{$key}[32] = $fwdfwsettings{'LIMIT_CON_CON'};
2381 $$hash{$key}[33] = $fwdfwsettings{'concon'};
2382 $$hash{$key}[34] = $fwdfwsettings{'RATE_LIMIT'};
2383 $$hash{$key}[35] = $fwdfwsettings{'ratecon'};
2384 $$hash{$key}[36] = $fwdfwsettings{'RATETIME'};
2389 &General
::writehasharray
("$config", $hash);
2390 if($fwdfwsettings{'oldrulenumber'} > $fwdfwsettings{'rulepos'}){
2392 my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'};
2393 for (my $z=0;$z<$val;$z++){
2394 foreach my $key (sort {$a <=> $b} keys %$hash){
2395 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2397 if (exists $$hash{$last}){
2399 foreach my $y (0 .. $#{$$hash{$last}}) {
2400 $tmp{0}[$y] = $$hash{$last}[$y];
2402 #copy active rule to last
2403 foreach my $i (0 .. $#{$$hash{$last}}) {
2404 $$hash{$last}[$i] = $$hash{$key}[$i];
2406 #copy saved rule to actual position
2407 foreach my $x (0 .. $#{$tmp{0}}) {
2408 $$hash{$key}[$x] = $tmp{0}[$x];
2413 $fwdfwsettings{'oldrulenumber'}--;
2415 &General
::writehasharray
("$config", $hash);
2416 &General
::firewall_config_changed
();
2417 }elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
2419 my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
2420 for (my $z=0;$z<$val;$z++){
2421 foreach my $key (sort {$a <=> $b} keys %$hash){
2422 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2423 my $next = $key + 1;
2424 if (exists $$hash{$next}){
2426 foreach my $y (0 .. $#{$$hash{$next}}) {
2427 $tmp{0}[$y] = $$hash{$next}[$y];
2429 #copy active rule to next
2430 foreach my $i (0 .. $#{$$hash{$next}}) {
2431 $$hash{$next}[$i] = $$hash{$key}[$i];
2433 #copy saved rule to actual position
2434 foreach my $x (0 .. $#{$tmp{0}}) {
2435 $$hash{$key}[$x] = $tmp{0}[$x];
2440 $fwdfwsettings{'oldrulenumber'}++;
2442 &General
::writehasharray
("$config", $hash);
2443 &General
::firewall_config_changed
();
2449 # Checks a hostname against RFC1035
2452 # Try to decode $remark into UTF-8. If this doesn't work,
2453 # we assume that the string it not sane.
2454 if (!utf8
::decode
($remark)) {
2458 # Check if the string only contains of printable characters.
2459 if ($remark =~ /^[[:print:]]*$/) {
2466 &General
::readhash
("/var/ipfire/ethernet/settings", \
%netsettings);
2468 &viewtablenew
(\
%configfwdfw, $configfwdfw, $Lang::tr
{'firewall rules'});
2469 &viewtablenew
(\
%configinputfw, $configinput, $Lang::tr
{'incoming firewall access'});
2470 &viewtablenew
(\
%configoutgoingfw, $configoutgoing, $Lang::tr
{'outgoing firewall access'});
2479 my $show_box = (! -z
$config) || ($optionsfw{'SHOWTABLES'} eq 'on');
2480 return if (!$show_box);
2482 &General
::get_aliases
(\
%aliases);
2483 &General
::readhasharray
("$confighost", \
%customhost);
2484 &General
::readhasharray
("$config", $hash);
2485 &General
::readhasharray
("$configccdnet", \
%ccdnet);
2486 &General
::readhasharray
("$configccdhost", \
%ccdhost);
2487 &General
::readhasharray
("$configgrp", \
%customgrp);
2488 &General
::readhasharray
("$configsrvgrp", \
%customservicegrp);
2490 &Header
::openbox
('100%', 'left', $title);
2491 print "<table width='100%' cellspacing='0' class='tbl'>";
2505 <th align='right' width='3%'>
2508 <th width='2%'></th>
2510 <b>$Lang::tr{'protocol'}</b>
2512 <th align='center' width='30%'>
2513 <b>$Lang::tr{'fwdfw source'}</b>
2516 <b>$Lang::tr{'fwdfw log'}</b>
2518 <th align='center' width='30%'>
2519 <b>$Lang::tr{'fwdfw target'}</b>
2521 <th align='center' colspan='6' width='18%'>
2522 <b>$Lang::tr{'fwdfw action'}</b>
2527 foreach my $key (sort {$a <=> $b} keys %$hash){
2531 #check if vpn hosts/nets have been deleted
2532 if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){
2533 push (@tmpsrc,$$hash{$key}[4]);
2535 if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){
2536 push (@tmptgt,$$hash{$key}[6]);
2538 foreach my $host (@tmpsrc){
2539 if($$hash{$key}[3] eq 'ipsec_net_src'){
2540 if(&fwlib
::get_ipsec_net_ip
($host,11) eq ''){
2543 }elsif($$hash{$key}[3] eq 'ovpn_net_src'){
2544 if(&fwlib
::get_ovpn_net_ip
($host,1) eq ''){
2547 }elsif($$hash{$key}[3] eq 'ovpn_n2n_src'){
2548 if(&fwlib
::get_ovpn_n2n_ip
($host,27) eq ''){
2551 }elsif($$hash{$key}[3] eq 'ovpn_host_src'){
2552 if(&fwlib
::get_ovpn_host_ip
($host,33) eq ''){
2557 foreach my $host (@tmptgt){
2558 if($$hash{$key}[5] eq 'ipsec_net_tgt'){
2559 if(&fwlib
::get_ipsec_net_ip
($host,11) eq ''){
2562 }elsif($$hash{$key}[5] eq 'ovpn_net_tgt'){
2563 if(&fwlib
::get_ovpn_net_ip
($host,1) eq ''){
2566 }elsif($$hash{$key}[5] eq 'ovpn_n2n_tgt'){
2567 if(&fwlib
::get_ovpn_n2n_ip
($host,27) eq ''){
2570 }elsif($$hash{$key}[5] eq 'ovpn_host_tgt'){
2571 if(&fwlib
::get_ovpn_host_ip
($host,33) eq ''){
2576 #check if networkgroups or servicegroups are empty
2577 foreach my $netgroup (sort keys %customgrp){
2578 if(($$hash{$key}[4] eq $customgrp{$netgroup}[0] || $$hash{$key}[6] eq $customgrp{$netgroup}[0]) && $customgrp{$netgroup}[2] eq 'none'){
2582 foreach my $srvgroup (sort keys %customservicegrp){
2583 if($$hash{$key}[15] eq $customservicegrp{$srvgroup}[0] && $customservicegrp{$srvgroup}[2] eq 'none'){
2587 $$hash{'ACTIVE'}=$$hash{$key}[2];
2589 if($coloryellow eq 'on'){
2590 $color="$color{'color14'}";
2592 }elsif($coloryellow eq ''){
2594 $color="$color{'color22'}";
2597 $color="$color{'color20'}";
2601 <tr bgcolor='$color'>
2602 <td align='right' width='3%'>
2608 if ($$hash{$key}[0] eq 'ACCEPT'){
2611 $rulecolor=$color{'color17'};
2612 }elsif($$hash{$key}[0] eq 'DROP'){
2615 $rulecolor=$color{'color25'};
2616 }elsif($$hash{$key}[0] eq 'REJECT'){
2619 $rulecolor=$color{'color16'};
2623 <td bgcolor='$rulecolor' align='center' width='2%'>
2624 <span title='$tooltip'> </span>
2630 if ($$hash{$key}[8]){
2631 if ($$hash{$key}[8] eq "IPv6"){
2632 push (@protocols,$Lang::tr
{'fwdfw prot41 short'})
2634 push (@protocols,$$hash{$key}[8]);
2636 }elsif($$hash{$key}[14] eq 'cust_srv'){
2637 &get_serviceports
("service",$$hash{$key}[15]);
2638 }elsif($$hash{$key}[14] eq 'cust_srvgrp'){
2639 &get_serviceports
("group",$$hash{$key}[15]);
2641 push (@protocols,$Lang::tr
{'all'});
2644 my $protz=join(", ",@protocols);
2645 if($protz eq 'ICMP' && $$hash{$key}[9] ne 'All ICMP-Types' && $$hash{$key}[14] ne 'cust_srvgrp'){
2646 &General
::readhasharray
("${General::swroot}/fwhosts/icmp-types", \
%icmptypes);
2647 foreach my $keyicmp (sort { ncmp
($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
2648 if($$hash{$key}[9] eq "$icmptypes{$keyicmp}[0]"){
2649 print "<td align='center'><span title='$icmptypes{$keyicmp}[0]'><b>$protz ($icmptypes{$keyicmp}[1])</b></span></td>";
2653 }elsif($#protocols gt '3'){
2654 print"<td align='center'><span title='$protz'>$Lang::tr{'fwdfw many'}</span></td>";
2656 print"<td align='center'>$protz</td>";
2661 &getcolor
($$hash{$key}[3],$$hash{$key}[4],\
%customhost);
2662 # Check SRC Host and replace "|" with space
2663 if ($$hash{$key}[4] =~ /\|/){
2664 $$hash{$key}[4] =~ s/\|/ (/g;
2665 $$hash{$key}[4] = $$hash{$key}[4].")";
2667 print"<td align='center' width='30%' $tdcolor>";
2668 if ($$hash{$key}[3] eq 'ipfire_src'){
2669 $ipfireiface=$Lang::tr
{'fwdfw iface'};
2671 if ($$hash{$key}[3] eq 'std_net_src'){
2672 print &get_name
($$hash{$key}[4]);
2673 }elsif ($$hash{$key}[3] eq 'src_addr'){
2674 my ($split1,$split2) = split("/",$$hash{$key}[4]);
2675 if ($split2 eq '32'){
2678 print $$hash{$key}[4];
2680 }elsif ($$hash{$key}[3] eq 'cust_location_src') {
2681 my ($split1,$split2) = split(":", $$hash{$key}[4]);
2685 print "$Lang::tr{'location'}: $$hash{$key}[4]\n";
2687 }elsif ($$hash{$key}[4] eq 'RED1'){
2688 print "$ipfireiface $Lang::tr{'fwdfw red'}";
2689 }elsif ($$hash{$key}[4] eq 'ALL'){
2690 print "$ipfireiface $Lang::tr{'all'}";
2692 if ($$hash{$key}[4] eq 'GREEN' || $$hash{$key}[4] eq 'ORANGE' || $$hash{$key}[4] eq 'BLUE' || $$hash{$key}[4] eq 'RED'){
2693 print "$ipfireiface $Lang::tr{lc($$hash{$key}[4])}";
2695 print "$ipfireiface $$hash{$key}[4]";
2700 &getsrcport
(\
%$hash,$key);
2701 #Is this a SNAT rule?
2702 if ($$hash{$key}[31] eq 'snat' && $$hash{$key}[28] eq 'ON'){
2703 my $net=&get_name
($$hash{$key}[29]);
2704 if ( ! $net){ $net=$$hash{$key}[29];}
2706 if ($$hash{$key}[30] ne ''){
2707 print": $$hash{$key}[30]";
2710 if ($$hash{$key}[17] eq 'ON'){
2711 $log="/images/on.gif";
2713 $log="/images/off.gif";
2719 <form method='POST' action=''>
2720 <input type='image' img src='$log' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw togglelog'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;'/>
2721 <input type='hidden' name='key' value='$key' />
2722 <input type='hidden' name='config' value='$config' />
2723 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw togglelog'}' />
2728 &getcolor
($$hash{$key}[5],$$hash{$key}[6],\
%customhost);
2730 <td align='center' $tdcolor>
2732 # Check TGT Host and replace "|" with space
2733 if ($$hash{$key}[6] =~ /\|/){
2734 $$hash{$key}[6] =~ s/\|/ (/g;
2735 $$hash{$key}[6] = $$hash{$key}[6].")";
2737 #Is this a DNAT rule?
2739 if ($$hash{$key}[31] eq 'dnat' && $$hash{$key}[28] eq 'ON'){
2740 if ($$hash{$key}[29] eq 'Default IP'){$$hash{$key}[29]=$Lang::tr
{'red1'};}
2741 if ($$hash{$key}[29] eq 'AUTO'){
2742 my @src_addresses=&fwlib
::get_addresses
(\
%$hash,$key,'src');
2744 foreach my $val (@src_addresses){
2745 push (@nat_ifaces,&fwlib
::get_nat_address
($$hash{$key}[29],$val));
2747 @nat_ifaces=&del_double
(@nat_ifaces);
2750 $natstring = "($$hash{$key}[29])";
2752 print "$Lang::tr{'firewall'} $natstring";
2753 if($$hash{$key}[30] ne ''){
2754 $$hash{$key}[30]=~ tr/|/,/;
2755 print": $$hash{$key}[30]";
2759 if ($$hash{$key}[5] eq 'std_net_tgt' || $$hash{$key}[5] eq 'ipfire'){
2760 if ($$hash{$key}[6] eq 'RED1'){
2761 print "$Lang::tr{'red1'}";
2762 }elsif ($$hash{$key}[6] eq 'GREEN' || $$hash{$key}[6] eq 'ORANGE' || $$hash{$key}[6] eq 'BLUE'|| $$hash{$key}[6] eq 'ALL' || $$hash{$key}[6] eq 'RED')
2764 print &get_name
($$hash{$key}[6]);
2766 print $$hash{$key}[6];
2768 }elsif ($$hash{$key}[5] eq 'cust_location_tgt') {
2769 my ($split1,$split2) = split(":", $$hash{$key}[6]);
2773 print "$Lang::tr{'location'}: $$hash{$key}[6]\n";
2775 }elsif ($$hash{$key}[5] eq 'tgt_addr'){
2776 my ($split1,$split2) = split("/",$$hash{$key}[6]);
2777 if ($split2 eq '32'){
2780 print $$hash{$key}[6];
2783 print "$$hash{$key}[6]";
2787 &gettgtport
(\
%$hash,$key);
2790 if($$hash{$key}[2] eq 'ON'){
2791 $gif="/images/on.gif"
2793 $gif="/images/off.gif"
2796 <td width='3%' align='center'>
2797 <form method='POST' action=''>
2798 <input type='image' img src='$gif' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw toggle'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2799 <input type='hidden' name='key' value='$key' />
2800 <input type='hidden' name='config' value='$config' />
2801 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw toggle'}' />
2804 <td width='3%' align='center'>
2805 <form method='POST' action=''>
2806 <input type='image' img src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'fwdfw edit'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2807 <input type='hidden' name='key' value='$key' />
2808 <input type='hidden' name='config' value='$config' />
2809 <input type='hidden' name='ACTION' value='editrule' />
2812 <td width='3%' align='center'>
2813 <form method='POST' action=''>
2814 <input type='image' img src='/images/addblue.gif' alt='$Lang::tr{'fwdfw copy'}' title='$Lang::tr{'fwdfw copy'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2815 <input type='hidden' name='key' value='$key' />
2816 <input type='hidden' name='config' value='$config' />
2817 <input type='hidden' name='ACTION' value='copyrule' />
2820 <td width='3%' align='center'>
2821 <form method='POST' action=''>
2822 <input type='image' img src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'fwdfw delete'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2823 <input type='hidden' name='key' value='$key' />
2824 <input type='hidden' name='config' value='$config' />
2825 <input type='hidden' name='ACTION' value='deleterule' />
2829 if (exists $$hash{$key-1}){
2831 <td width='3%' align='center'>
2832 <form method='POST' action=''>
2833 <input type='image' img src='/images/up.gif' alt='$Lang::tr{'fwdfw moveup'}' title='$Lang::tr{'fwdfw moveup'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2834 <input type='hidden' name='key' value='$key' />
2835 <input type='hidden' name='config' value='$config' />
2836 <input type='hidden' name='ACTION' value='moveup' />
2841 print"<td width='3%'></td>";
2844 if (exists $$hash{$key+1}){
2846 <td width='3%' align='center'>
2847 <form method='POST' action=''>
2848 <input type='image' img src='/images/down.gif' alt='$Lang::tr{'fwdfw movedown'}' title='$Lang::tr{'fwdfw movedown'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2849 <input type='hidden' name='key' value='$key' />
2850 <input type='hidden' name='config' value='$config' />
2851 <input type='hidden' name='ACTION' value='movedown' />
2857 print"<td width='3%'></td></tr>";
2860 if ($optionsfw{'SHOWREMARK'} eq 'on' && $$hash{$key}[16] ne ''){
2862 <tr bgcolor='$color'>
2864 <td bgcolor='$rulecolor'></td>
2866 <em>$$hash{$key}[16]</em>
2872 if ($$hash{$key}[18] eq 'ON'){
2874 if ($$hash{$key}[18] eq 'ON'){
2876 if($$hash{$key}[19] ne ''){push (@days,$Lang::tr
{'fwdfw wd_mon'});}
2877 if($$hash{$key}[20] ne ''){push (@days,$Lang::tr
{'fwdfw wd_tue'});}
2878 if($$hash{$key}[21] ne ''){push (@days,$Lang::tr
{'fwdfw wd_wed'});}
2879 if($$hash{$key}[22] ne ''){push (@days,$Lang::tr
{'fwdfw wd_thu'});}
2880 if($$hash{$key}[23] ne ''){push (@days,$Lang::tr
{'fwdfw wd_fri'});}
2881 if($$hash{$key}[24] ne ''){push (@days,$Lang::tr
{'fwdfw wd_sat'});}
2882 if($$hash{$key}[25] ne ''){push (@days,$Lang::tr
{'fwdfw wd_sun'});}
2883 my $weekdays=join(",",@days);
2885 print"<tr bgcolor='$color'>";
2886 print"<td> </td><td bgcolor='$rulecolor'></td><td align='left' colspan='10'> $weekdays $$hash{$key}[26] - $$hash{$key}[27]</td></tr>";
2890 print"<tr bgcolor='FFFFFF'><td colspan='13' height='1'></td></tr>";
2892 } elsif ($optionsfw{'SHOWTABLES'} eq 'on') {
2895 <td colspan='7' height='30' bgcolor=$color{'color22'} align='center'>$Lang::tr{'fwhost empty'}</td>
2901 my $policy = 'fwdfw ' . $fwdfwsettings{'POLICY'};
2902 my $colour = "bgcolor='green'";
2903 if ($fwdfwsettings{'POLICY'} eq 'MODE1') {
2904 $colour = "bgcolor='darkred'";
2908 if (($config eq '/var/ipfire/firewall/config') && ($fwdfwsettings{'POLICY'} ne 'MODE1')) {
2911 <td colspan='13'> </td>
2914 <td colspan='13' style="padding-left:0px;padding-right:0px">
2915 <table width="100%" border='1' rules="cols" cellspacing='0'>
2922 <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
2925 <font color="$Header::colourred">$Lang::tr{'red'}</font>
2926 ($Lang::tr{'fwdfw pol allow'})
2930 if (&Header
::orange_used
()) {
2933 <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
2934 ($Lang::tr{'fwdfw pol allow'})
2939 if (&Header
::blue_used
()) {
2942 <font color="$Header::colourblue">$Lang::tr{'blue'}</font>
2943 ($Lang::tr{'fwdfw pol allow'})
2951 if (&Header
::orange_used
()) {
2954 <td align='center' width='20%'>
2955 <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
2958 <font color="$Header::colourred">$Lang::tr{'red'}</font>
2959 ($Lang::tr{'fwdfw pol allow'})
2962 <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
2963 ($Lang::tr{'fwdfw pol block'})
2967 if (&Header
::blue_used
()) {
2970 <font color="$Header::colourblue">$Lang::tr{'blue'}</font>
2971 ($Lang::tr{'fwdfw pol block'})
2979 if (&Header
::blue_used
()) {
2983 <font color="$Header::colourblue">$Lang::tr{'blue'}</font>
2986 <font color="$Header::colourred">$Lang::tr{'red'}</font>
2987 ($Lang::tr{'fwdfw pol allow'})
2991 if (&Header
::orange_used
()) {
2994 <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
2995 ($Lang::tr{'fwdfw pol block'})
3002 <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
3003 ($Lang::tr{'fwdfw pol block'})
3015 $message = $Lang::tr
{'fwdfw pol allow'};
3017 } elsif ($config eq '/var/ipfire/firewall/outgoing' && ($fwdfwsettings{'POLICY1'} ne 'MODE1')) {
3018 $message = $Lang::tr
{'fwdfw pol allow'};
3019 $colour = "bgcolor='green'";
3021 $message = $Lang::tr
{'fwdfw pol block'};
3022 $colour = "bgcolor='darkred'";
3028 <td $colour align='center' colspan='13'>
3029 <font color='#FFFFFF'>$Lang::tr{'policy'}: $message</font>
3038 &Header
::closebox
();
3041 &Header
::closebigbox
();
3042 &Header
::closepage
();