Forward Firewall: set default options for optionsfw and minor change on optionsfw.cgi
[people/teissler/ipfire-2.x.git] / html / cgi-bin / forwardfw.cgi
CommitLineData
2a81ab0d
AM
1#!/usr/bin/perl
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2012 #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
f8bf364f 21
2a81ab0d
AM
22
23use strict;
eff2dbf8 24use Sort::Naturally;
2a81ab0d
AM
25no warnings 'uninitialized';
26# enable only the following on debugging purpose
27#use warnings;
28#use CGI::Carp 'fatalsToBrowser';
29
30require '/var/ipfire/general-functions.pl';
31require "${General::swroot}/lang.pl";
32require "${General::swroot}/header.pl";
33require "${General::swroot}/forward/bin/firewall-lib.pl";
34
35unless (-d "${General::swroot}/forward") { system("mkdir ${General::swroot}/forward"); }
36unless (-e "${General::swroot}/forward/settings") { system("touch ${General::swroot}/forward/settings"); }
37unless (-e "${General::swroot}/forward/config") { system("touch ${General::swroot}/forward/config"); }
38unless (-e "${General::swroot}/forward/input") { system("touch ${General::swroot}/forward/input"); }
c7043621 39unless (-e "${General::swroot}/forward/outgoing") { system("touch ${General::swroot}/forward/outgoing"); }
2a81ab0d
AM
40
41my %fwdfwsettings=();
42my %selected=() ;
43my %defaultNetworks=();
44my %netsettings=();
45my %customhost=();
46my %customgrp=();
47my %customnetworks=();
48my %customservice=();
49my %customservicegrp=();
50my %ccdnet=();
51my %customnetwork=();
52my %ccdhost=();
53my %configfwdfw=();
54my %configinputfw=();
c7043621 55my %configoutgoingfw=();
2a81ab0d
AM
56my %ipsecconf=();
57my %color=();
58my %mainsettings=();
59my %checked=();
60my %icmptypes=();
61my %ovpnsettings=();
62my %ipsecsettings=();
63my %aliases=();
15add1c8 64my %optionsfw=();
2669161d 65my %ifaces=();
c7043621 66
6584a984 67my $VERSION='0.9.9.11';
2a81ab0d
AM
68my $color;
69my $confignet = "${General::swroot}/fwhosts/customnetworks";
70my $confighost = "${General::swroot}/fwhosts/customhosts";
71my $configgrp = "${General::swroot}/fwhosts/customgroups";
72my $configsrv = "${General::swroot}/fwhosts/customservices";
73my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
74my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
75my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
76my $configipsec = "${General::swroot}/vpn/config";
77my $configipsecrw = "${General::swroot}/vpn/settings";
78my $configfwdfw = "${General::swroot}/forward/config";
79my $configinput = "${General::swroot}/forward/input";
c7043621 80my $configoutgoing = "${General::swroot}/forward/outgoing";
2a81ab0d 81my $configovpn = "${General::swroot}/ovpn/settings";
15add1c8 82my $fwoptions = "${General::swroot}/optionsfw/settings";
2669161d 83my $ifacesettings = "${General::swroot}/ethernet/settings";
2a81ab0d
AM
84my $errormessage='';
85my $hint='';
86my $ipgrp="${General::swroot}/outgoing/groups";
15add1c8 87my $tdcolor='';
515863e2 88my $checkorange='';
b3f4a4ef 89my @protocols;
2a81ab0d
AM
90&General::readhash("${General::swroot}/forward/settings", \%fwdfwsettings);
91&General::readhash("${General::swroot}/main/settings", \%mainsettings);
92&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
15add1c8 93&General::readhash($fwoptions, \%optionsfw);
2669161d 94&General::readhash($ifacesettings, \%ifaces);
931e1fed
AM
95&General::readhash("$configovpn", \%ovpnsettings);
96&General::readhash("$configipsecrw", \%ipsecsettings);
97&General::readhasharray("$configipsec", \%ipsecconf);
2a81ab0d
AM
98&Header::showhttpheaders();
99&Header::getcgihash(\%fwdfwsettings);
100&Header::openpage($Lang::tr{'fwdfw menu'}, 1, '');
101&Header::openbigbox('100%', 'center',$errormessage);
b88c8829
AM
102#### JAVA SCRIPT ####
103print<<END;
104<script>
105 \$(document).ready(function() {
106 // Automatically select radio buttons when corresponding
107 // dropdown menu changes.
108 \$("select").change(function() {
109 var id = \$(this).attr("name");
110 //When using SNAT or DNAT, check "USE NAT" Checkbox
111 if ( id === 'snat' || id === 'dnat') {
112 \$('#USE_NAT').prop('checked', true);
113 }
114 \$('#' + id).prop("checked", true);
115 });
116 });
117function checkradio(a){
118 \$(a).attr('checked', true);
119}
120</script>
121END
122
2a81ab0d
AM
123#### ACTION #####
124
2a81ab0d
AM
125if ($fwdfwsettings{'ACTION'} eq 'saverule')
126{
127 &General::readhasharray("$configfwdfw", \%configfwdfw);
128 &General::readhasharray("$configinput", \%configinputfw);
5d7faa45 129 &General::readhasharray("$configoutgoing", \%configoutgoingfw);
2a81ab0d
AM
130 $errormessage=&checksource;
131 if(!$errormessage){&checktarget;}
132 if(!$errormessage){&checkrule;}
a60dbb4b 133
515863e2
AM
134 #check if manual ip (source) is orange network
135 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
136 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
137 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
138 $checkorange='on';
139 }
140 }
141 #check useless rules
142 if( ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' || $checkorange eq 'on') && $fwdfwsettings{'grp2'} eq 'ipfire'){
143 $errormessage.=$Lang::tr{'fwdfw useless rule'}."<br>";
144 }
c7043621 145 #check if we try to break rules
d4cb89d2 146 if( $fwdfwsettings{'grp1'} eq 'ipfire_src' && $fwdfwsettings{'grp2'} eq 'ipfire'){
cb4439f3 147 $errormessage=$Lang::tr{'fwdfw err same'};
c7043621 148 }
2a81ab0d 149 #INPUT part
c12392c0 150 if($fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ORANGE'){
5de39dea 151 $fwdfwsettings{'config'}=$configinput;
2a81ab0d 152 $fwdfwsettings{'chain'} = 'INPUTFW';
70d38e50 153 my $maxkey=&General::findhasharraykey(\%configinputfw);
2a81ab0d 154 #check if we have an identical rule already
70d38e50 155 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
2da264ec 156 foreach my $key (sort keys %configinputfw){
f8bf364f
AM
157 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{'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'}"
158 eq "$configinputfw{$key}[0],$configinputfw{$key}[2],$configinputfw{$key}[3],$configinputfw{$key}[4],$configinputfw{$key}[5],$configinputfw{$key}[6],$configinputfw{$key}[7],$configinputfw{$key}[8],$configinputfw{$key}[9],$configinputfw{$key}[10],$configinputfw{$key}[11],$configinputfw{$key}[12],$configinputfw{$key}[13],$configinputfw{$key}[14],$configinputfw{$key}[15],$configinputfw{$key}[17],$configinputfw{$key}[18],$configinputfw{$key}[19],$configinputfw{$key}[20],$configinputfw{$key}[21],$configinputfw{$key}[22],$configinputfw{$key}[23],$configinputfw{$key}[24],$configinputfw{$key}[25],$configinputfw{$key}[26],$configinputfw{$key}[27],$configinputfw{$key}[28],$configinputfw{$key}[29],$configinputfw{$key}[30],$configinputfw{$key}[31]"){
2da264ec 159 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
25dd450c 160 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on'){
02da9f7b 161 $errormessage='';
15add1c8 162 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
61068ee1 163 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
02da9f7b
AM
164 }
165 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
166 $fwdfwsettings{'nosave'} = 'on';
167 }
2da264ec 168 }
62fc8511 169 }
2da264ec 170 }
70d38e50
AM
171 #check Rulepos on new Rule
172 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
173 $fwdfwsettings{'oldrulenumber'}=$maxkey;
174 foreach my $key (sort keys %configinputfw){
f8bf364f
AM
175 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{'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'}"
176 eq "$configinputfw{$key}[0],$configinputfw{$key}[2],$configinputfw{$key}[3],$configinputfw{$key}[4],$configinputfw{$key}[5],$configinputfw{$key}[6],$configinputfw{$key}[7],$configinputfw{$key}[8],$configinputfw{$key}[9],$configinputfw{$key}[10],$configinputfw{$key}[11],$configinputfw{$key}[12],$configinputfw{$key}[13],$configinputfw{$key}[14],$configinputfw{$key}[15],$configinputfw{$key}[17],$configinputfw{$key}[18],$configinputfw{$key}[19],$configinputfw{$key}[20],$configinputfw{$key}[21],$configinputfw{$key}[22],$configinputfw{$key}[23],$configinputfw{$key}[24],$configinputfw{$key}[25],$configinputfw{$key}[26],$configinputfw{$key}[27],$configinputfw{$key}[28],$configinputfw{$key}[29],$configinputfw{$key}[30],$configinputfw{$key}[31]"){
70d38e50
AM
177 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
178 }
179 }
180 }
992394d5 181 #check if we just close a rule
2669161d 182 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'}) {
992394d5
AM
183 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
184 $errormessage='';
185 $fwdfwsettings{'nosave2'} = 'on';
186 }
187 }
62fc8511
AM
188 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
189 if ($fwdfwsettings{'nobase'} ne 'on'){
190 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
191 }
192 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
193 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
194 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
195 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
196 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
197 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
198 }
992394d5
AM
199 if($fwdfwsettings{'nosave2'} ne 'on'){
200 &saverule(\%configinputfw,$configinput);
201 }
a0fb1099
AM
202 }elsif($fwdfwsettings{'grp1'} eq 'ipfire_src' ){
203 # OUTGOING PART
c7043621
AM
204 $fwdfwsettings{'config'}=$configoutgoing;
205 $fwdfwsettings{'chain'} = 'OUTGOINGFW';
206 my $maxkey=&General::findhasharraykey(\%configoutgoingfw);
207 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
208 foreach my $key (sort keys %configoutgoingfw){
f8bf364f
AM
209 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{'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'}"
210 eq "$configoutgoingfw{$key}[0],$configoutgoingfw{$key}[2],$configoutgoingfw{$key}[3],$configoutgoingfw{$key}[4],$configoutgoingfw{$key}[5],$configoutgoingfw{$key}[6],$configoutgoingfw{$key}[7],$configoutgoingfw{$key}[8],$configoutgoingfw{$key}[9],$configoutgoingfw{$key}[10],$configoutgoingfw{$key}[11],$configoutgoingfw{$key}[12],$configoutgoingfw{$key}[13],$configoutgoingfw{$key}[14],$configoutgoingfw{$key}[15],$configoutgoingfw{$key}[17],$configoutgoingfw{$key}[18],$configoutgoingfw{$key}[19],$configoutgoingfw{$key}[20],$configoutgoingfw{$key}[21],$configoutgoingfw{$key}[22],$configoutgoingfw{$key}[23],$configoutgoingfw{$key}[24],$configoutgoingfw{$key}[25],$configoutgoingfw{$key}[26],$configoutgoingfw{$key}[27],$configoutgoingfw{$key}[28],$configoutgoingfw{$key}[29],$configoutgoingfw{$key}[30],$configoutgoingfw{$key}[31]"){
c7043621 211 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
25dd450c 212 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on'){
c7043621 213 $errormessage='';
15add1c8 214 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
c7043621
AM
215 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
216 }
217 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
218 $fwdfwsettings{'nosave'} = 'on';
219 }
220 }
221 }
222 }
223 #check Rulepos on new Rule
224 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
5d7faa45 225 print"CHECK OUTGOING DOPPELTE REGEL<br>";
c7043621
AM
226 $fwdfwsettings{'oldrulenumber'}=$maxkey;
227 foreach my $key (sort keys %configoutgoingfw){
f8bf364f
AM
228 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{'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'}"
229 eq "$configoutgoingfw{$key}[0],$configoutgoingfw{$key}[2],$configoutgoingfw{$key}[3],$configoutgoingfw{$key}[4],$configoutgoingfw{$key}[5],$configoutgoingfw{$key}[6],$configoutgoingfw{$key}[7],$configoutgoingfw{$key}[8],$configoutgoingfw{$key}[9],$configoutgoingfw{$key}[10],$configoutgoingfw{$key}[11],$configoutgoingfw{$key}[12],$configoutgoingfw{$key}[13],$configoutgoingfw{$key}[14],$configoutgoingfw{$key}[15],$configoutgoingfw{$key}[17],$configoutgoingfw{$key}[18],$configoutgoingfw{$key}[19],$configoutgoingfw{$key}[20],$configoutgoingfw{$key}[21],$configoutgoingfw{$key}[22],$configoutgoingfw{$key}[23],$configoutgoingfw{$key}[24],$configoutgoingfw{$key}[25],$configoutgoingfw{$key}[26],$configoutgoingfw{$key}[27],$configoutgoingfw{$key}[28],$configoutgoingfw{$key}[29],$configoutgoingfw{$key}[30],$configoutgoingfw{$key}[31]"){
c7043621
AM
230 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
231 }
232 }
233 }
234 #check if we just close a rule
2669161d 235 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'}) {
c7043621
AM
236 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
237 $fwdfwsettings{'nosave2'} = 'on';
238 $errormessage='';
239 }
240 }
241 #increase counters
242 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
243 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
244 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
245 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
246 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
247 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
248 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
249 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
250 }
251 if ($fwdfwsettings{'nobase'} eq 'on'){
252 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
253 }
254 if ($fwdfwsettings{'nosave2'} ne 'on'){
255 &saverule(\%configoutgoingfw,$configoutgoing);
256 }
2a81ab0d 257 }else{
27f4a6b1 258 #FORWARD PART
5de39dea 259 $fwdfwsettings{'config'}=$configfwdfw;
2a81ab0d 260 $fwdfwsettings{'chain'} = 'FORWARDFW';
70d38e50 261 my $maxkey=&General::findhasharraykey(\%configfwdfw);
2da264ec
AM
262 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
263 #check if we have an identical rule already
264 foreach my $key (sort keys %configfwdfw){
ac9e77e3 265 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'}"
f8bf364f 266 eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[18],$configfwdfw{$key}[19],$configfwdfw{$key}[20],$configfwdfw{$key}[21],$configfwdfw{$key}[22],$configfwdfw{$key}[23],$configfwdfw{$key}[24],$configfwdfw{$key}[25],$configfwdfw{$key}[26],$configfwdfw{$key}[27],$configfwdfw{$key}[28],$configfwdfw{$key}[29],$configfwdfw{$key}[30],$configfwdfw{$key}[31]"){
2da264ec 267 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
25dd450c 268 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' ){
02da9f7b 269 $errormessage='';
15add1c8 270 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
61068ee1 271 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
02da9f7b
AM
272 }
273 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
274 $fwdfwsettings{'nosave'} = 'on';
275 }
2da264ec
AM
276 }
277 }
2a81ab0d 278 }
70d38e50
AM
279 #check Rulepos on new Rule
280 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
281 $fwdfwsettings{'oldrulenumber'}=$maxkey;
282 foreach my $key (sort keys %configfwdfw){
ac9e77e3 283 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'}"
f8bf364f 284 eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[18],$configfwdfw{$key}[19],$configfwdfw{$key}[20],$configfwdfw{$key}[21],$configfwdfw{$key}[22],$configfwdfw{$key}[23],$configfwdfw{$key}[24],$configfwdfw{$key}[25],$configfwdfw{$key}[26],$configfwdfw{$key}[27],$configfwdfw{$key}[28],$configfwdfw{$key}[29],$configfwdfw{$key}[30],$configfwdfw{$key}[31]"){
70d38e50
AM
285 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
286 }
287 }
288 }
992394d5 289 #check if we just close a rule
533a2da3 290 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'}) {
992394d5
AM
291 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
292 $fwdfwsettings{'nosave2'} = 'on';
293 $errormessage='';
294 }
295 }
2a81ab0d
AM
296 #increase counters
297 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
2a81ab0d 298 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
2a81ab0d
AM
299 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
300 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
301 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
302 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
303 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
304 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
305 }
2a81ab0d
AM
306 if ($fwdfwsettings{'nobase'} eq 'on'){
307 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
308 }
992394d5
AM
309 if ($fwdfwsettings{'nosave2'} ne 'on'){
310 &saverule(\%configfwdfw,$configfwdfw);
311 }
2a81ab0d
AM
312 }
313 if ($errormessage){
314 &newrule;
315 }else{
992394d5
AM
316 if($fwdfwsettings{'nosave2'} ne 'on'){
317 &rules;
318 }
2a81ab0d
AM
319 &base;
320 }
2a81ab0d 321}
2a81ab0d
AM
322if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw newrule'})
323{
324 &newrule;
325}
326if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw toggle'})
327{
328 my %togglehash=();
329 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
330 foreach my $key (sort keys %togglehash){
331 if ($key eq $fwdfwsettings{'key'}){
332 if ($togglehash{$key}[2] eq 'ON'){$togglehash{$key}[2]='';}else{$togglehash{$key}[2]='ON';}
333 }
334 }
335 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
336 &rules;
337 &base;
338}
339if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw togglelog'})
340{
341 my %togglehash=();
342 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
343 foreach my $key (sort keys %togglehash){
344 if ($key eq $fwdfwsettings{'key'}){
345 if ($togglehash{$key}[17] eq 'ON'){$togglehash{$key}[17]='';}else{$togglehash{$key}[17]='ON';}
346 }
347 }
348 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
349 &rules;
350 &base;
351}
352if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
353{
354 &reread_rules;
355 &base;
356}
357if ($fwdfwsettings{'ACTION'} eq 'editrule')
358{
359 $fwdfwsettings{'updatefwrule'}='on';
360 &newrule;
361}
362if ($fwdfwsettings{'ACTION'} eq 'deleterule')
363{
364 &deleterule;
365}
366if ($fwdfwsettings{'ACTION'} eq 'moveup')
367{
368 &pos_up;
369 &base;
370}
371if ($fwdfwsettings{'ACTION'} eq 'movedown')
372{
373 &pos_down;
374 &base;
375}
376if ($fwdfwsettings{'ACTION'} eq 'copyrule')
377{
378 $fwdfwsettings{'copyfwrule'}='on';
2a81ab0d
AM
379 &newrule;
380}
381if ($fwdfwsettings{'ACTION'} eq '')
382{
383 &base;
384}
385### Functions ####
8013bd0a 386sub addrule
2a81ab0d 387{
8013bd0a
AM
388 &error;
389 if (-f "${General::swroot}/forward/reread"){
b88c8829 390 print "<table border='1' rules='groups' bgcolor='lightgreen' width='100%'><form method='post'><td><div style='font-size:11pt; font-weight: bold;vertical-align: middle; '><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-face: Comic Sans MS; color: green; font-weight: bold; font-size: 14pt;'>&nbsp &nbsp $Lang::tr{'fwhost reread'}</div></td></tr></table></form><br>";
2a81ab0d 391 }
e1eef9d5 392 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw menu'});
8013bd0a
AM
393 print "<form method='post'>";
394 print "<table border='0'>";
395 print "<tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'></td>";
396 print"</tr></table></form><hr>";
397 &Header::closebox();
398 &viewtablerule;
2a81ab0d
AM
399}
400sub base
401{
2a81ab0d 402 &hint;
7bd9d462 403 &addrule;
12a43202 404 print "<br><br>";
7874d820 405 print "<br><br><div align='right'><font size='1' color='grey'>Version: $VERSION</font></div>";
2a81ab0d 406}
8013bd0a 407sub changerule
2a81ab0d 408{
8013bd0a
AM
409 my $oldchain=shift;
410 $fwdfwsettings{'updatefwrule'}='';
411 $fwdfwsettings{'config'}=$oldchain;
412 $fwdfwsettings{'nobase'}='on';
413 &deleterule;
414 &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
415 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
2a81ab0d
AM
416}
417sub checksource
418{
419 my ($ip,$subnet);
2a81ab0d
AM
420 #check ip-address if manual
421 if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){
422 #check if ip with subnet
423 if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?)$/) {
424 ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'});
425 $subnet = &General::iporsubtocidr($subnet);
b5269091 426 $fwdfwsettings{'isip'}='on';
2a81ab0d
AM
427 }
428 #check if only ip
429 if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
430 $ip=$fwdfwsettings{'src_addr'};
431 $subnet = '32';
b5269091 432 $fwdfwsettings{'isip'}='on';
2a81ab0d 433 }
36196d0d 434
b5269091
AM
435 if ($fwdfwsettings{'isip'} ne 'on'){
436 if (&General::validmac($fwdfwsettings{'src_addr'})){$fwdfwsettings{'ismac'}='on';}
437 }
438 if ($fwdfwsettings{'isip'} eq 'on'){
931e1fed
AM
439 ##check if ip is valid
440 if (! &General::validip($ip)){
441 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
442 return $errormessage;
443 }
b5269091
AM
444 #check and form valid IP
445 $ip=&General::ip2dec($ip);
446 $ip=&General::dec2ip($ip);
447 #check if net or broadcast
448 my @tmp= split (/\./,$ip);
449 if (($tmp[3] eq "0") || ($tmp[3] eq "255"))
450 {
451 $errormessage=$Lang::tr{'fwhost err hostip'}."<br>";
931e1fed
AM
452 return $errormessage;
453 }
d9b691e1 454 $fwdfwsettings{'src_addr'}="$ip/$subnet";
b5269091
AM
455 if(!&General::validipandmask($fwdfwsettings{'src_addr'})){
456 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
931e1fed 457 return $errormessage;
b5269091
AM
458 }
459 }
460 if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){
2a81ab0d 461 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
931e1fed 462 return $errormessage;
2a81ab0d
AM
463 }
464 }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
465 $errormessage.=$Lang::tr{'fwdfw err nosrcip'};
466 return $errormessage;
467 }
62fc8511 468
2a81ab0d
AM
469 #check empty fields
470 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err nosrc'}."<br>";}
471 #check icmp source
472 if ($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ICMP'){
473 $fwdfwsettings{'SRC_PORT'}='';
474 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
475 foreach my $key (keys %icmptypes){
476 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){
477 $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]";
478 }
479 }
62fc8511
AM
480 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'GRE'){
481 $fwdfwsettings{'SRC_PORT'}='';
482 $fwdfwsettings{'ICMP_TYPES'}='';
483 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ESP'){
484 $fwdfwsettings{'SRC_PORT'}='';
485 $fwdfwsettings{'ICMP_TYPES'}='';
d1f01304
AM
486 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'AH'){
487 $fwdfwsettings{'SRC_PORT'}='';
488 $fwdfwsettings{'ICMP_TYPES'}='';
2a81ab0d
AM
489 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} ne 'ICMP'){
490 $fwdfwsettings{'ICMP_TYPES'}='';
491 }else{
492 $fwdfwsettings{'ICMP_TYPES'}='';
493 $fwdfwsettings{'SRC_PORT'}='';
494 $fwdfwsettings{'PROT'}='';
495 }
62fc8511 496
8f0b047b
AM
497 if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){
498 my @parts=split(",",$fwdfwsettings{'SRC_PORT'});
499 my @values=();
500 foreach (@parts){
501 chomp($_);
829697d0 502 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
8f0b047b
AM
503 my $check;
504 #change dashes with :
505 $_=~ tr/-/:/;
506 if ($_ eq "*") {
507 push(@values,"1:65535");
508 $check='on';
509 }
829697d0 510 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
8f0b047b
AM
511 push(@values,"1:$2");
512 $check='on';
513 }
829697d0 514 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/ ) {
8f0b047b
AM
515 push(@values,"$1:65535");
516 $check='on'
517 }
518 $errormessage .= &General::validportrange($_, 'destination');
519 if(!$check){
520 push (@values,$_);
521 }
522 }else{
523 if (&General::validport($_)){
524 push (@values,$_);
525 }else{
526
527 }
528 }
2a81ab0d 529 }
8f0b047b 530 $fwdfwsettings{'SRC_PORT'}=join("|",@values);
2a81ab0d 531 }
931e1fed 532 return $errormessage;
2a81ab0d
AM
533}
534sub checktarget
535{
536 my ($ip,$subnet);
a6edca5a 537 &General::readhasharray("$configsrv", \%customservice);
bc912c6e 538 #check DNAT settings (has to be single Host and single Port or portrange)
a6edca5a
AM
539 if ($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat'){
540 if($fwdfwsettings{'grp2'} eq 'tgt_addr' || $fwdfwsettings{'grp2'} eq 'cust_host_tgt' || $fwdfwsettings{'grp2'} eq 'ovpn_host_tgt'){
98cee89f 541 if ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'dnatport'} eq ''){
a6edca5a 542 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
931e1fed 543 return $errormessage;
a6edca5a
AM
544 }
545 #check if manual ip is a single Host (if set)
546 if ($fwdfwsettings{'grp2'} eq 'tgt_addr'){
547 my @tmp= split (/\./,$fwdfwsettings{$fwdfwsettings{'grp2'}});
548 my @tmp1= split ("/",$tmp[3]);
549 if (($tmp1[0] eq "0") || ($tmp1[0] eq "255"))
550 {
551 $errormessage=$Lang::tr{'fwdfw dnat error'}."<br>";
931e1fed 552 return $errormessage;
a6edca5a
AM
553 }
554 }
bc912c6e 555 #check if Port is a single Port or portrange
a6edca5a
AM
556 if ($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
557 if(($fwdfwsettings{'TGT_PROT'} ne 'TCP'|| $fwdfwsettings{'TGT_PROT'} ne 'UDP') && $fwdfwsettings{'TGT_PORT'} eq ''){
558 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
931e1fed 559 return $errormessage;
a6edca5a
AM
560 }
561 if (($fwdfwsettings{'TGT_PROT'} eq 'TCP'|| $fwdfwsettings{'TGT_PROT'} eq 'UDP') && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport($fwdfwsettings{'TGT_PORT'})){
562 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
931e1fed 563 return $errormessage;
a6edca5a
AM
564 }
565 }
566 }else{
567 $errormessage=$Lang::tr{'fwdfw dnat error'}."<br>";
931e1fed 568 return $errormessage;
a6edca5a
AM
569 }
570 }
2a81ab0d
AM
571 if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
572 #check if ip with subnet
573 if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?)$/) {
574 ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
575 $subnet = &General::iporsubtocidr($subnet);
576 }
577 #check if only ip
578 if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
579 $ip=$fwdfwsettings{'tgt_addr'};
580 $subnet='32';
581 }
931e1fed
AM
582 #check if ip is valid
583 if (! &General::validip($ip)){
584 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
585 return $errormessage;
586 }
2a81ab0d
AM
587 #check and form valid IP
588 $ip=&General::ip2dec($ip);
589 $ip=&General::dec2ip($ip);
d9b691e1 590 $fwdfwsettings{'tgt_addr'}="$ip/$subnet";
2a81ab0d
AM
591 if(!&General::validipandmask($fwdfwsettings{'tgt_addr'})){
592 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
931e1fed 593 return $errormessage;
2a81ab0d 594 }
2a81ab0d
AM
595 }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
596 $errormessage.=$Lang::tr{'fwdfw err notgtip'};
597 return $errormessage;
598 }
2a81ab0d
AM
599 #check empty fields
600 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err notgt'}."<br>";}
2a81ab0d
AM
601 #check tgt services
602 if ($fwdfwsettings{'USESRV'} eq 'ON'){
603 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
604 $fwdfwsettings{'TGT_PROT'}='';
605 $fwdfwsettings{'ICMP_TGT'}='';
606 }
607 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
608 $fwdfwsettings{'TGT_PROT'}='';
609 $fwdfwsettings{'ICMP_TGT'}='';
610 #check target service
611 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){
612 $errormessage.=$Lang::tr{'fwdfw err tgt_grp'};
613 }
614 }
615 if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
bcbf1b8e 616 if ($fwdfwsettings{'TGT_PROT'} eq 'TCP' || $fwdfwsettings{'TGT_PROT'} eq 'UDP'){
2a81ab0d 617 if ($fwdfwsettings{'TGT_PORT'} ne ''){
08e1c65d 618 if ($fwdfwsettings{'TGT_PORT'} =~ "," && $fwdfwsettings{'USE_NAT'} && $fwdfwsettings{'nat'} eq 'dnat') {
829697d0 619 $errormessage=$Lang::tr{'fwdfw dnat porterr'}."<br>";
931e1fed 620 return $errormessage;
829697d0 621 }
8f0b047b
AM
622 my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
623 my @values=();
624 foreach (@parts){
625 chomp($_);
829697d0 626 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
8f0b047b
AM
627 my $check;
628 #change dashes with :
629 $_=~ tr/-/:/;
630 if ($_ eq "*") {
631 push(@values,"1:65535");
632 $check='on';
633 }
829697d0 634 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
8f0b047b
AM
635 push(@values,"1:$2");
636 $check='on';
637 }
829697d0 638 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
8f0b047b
AM
639 push(@values,"$1:65535");
640 $check='on'
641 }
642 $errormessage .= &General::validportrange($_, 'destination');
643 if(!$check){
644 push (@values,$_);
645 }
646 }else{
647 if (&General::validport($_)){
648 push (@values,$_);
649 }else{
650
651 }
652 }
2a81ab0d 653 }
8f0b047b 654 $fwdfwsettings{'TGT_PORT'}=join("|",@values);
2a81ab0d 655 }
62fc8511 656 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'GRE'){
d1f01304 657 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
bcbf1b8e 658 $fwdfwsettings{'TGT_PORT'} = '';
62fc8511 659 $fwdfwsettings{'ICMP_TGT'} = '';
bcbf1b8e 660 }elsif($fwdfwsettings{'TGT_PROT'} eq 'ESP'){
d1f01304 661 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
bcbf1b8e 662 $fwdfwsettings{'TGT_PORT'} = '';
d1f01304 663 $fwdfwsettings{'ICMP_TGT'}='';
bcbf1b8e 664 }elsif($fwdfwsettings{'TGT_PROT'} eq 'AH'){
d1f01304 665 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
bcbf1b8e 666 $fwdfwsettings{'TGT_PORT'} = '';
62fc8511 667 $fwdfwsettings{'ICMP_TGT'}='';
2a81ab0d 668 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'ICMP'){
d1f01304 669 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
bcbf1b8e 670 $fwdfwsettings{'TGT_PORT'} = '';
2a81ab0d
AM
671 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
672 foreach my $key (keys %icmptypes){
673
674 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwdfwsettings{'ICMP_TGT'}){
2a81ab0d
AM
675 $fwdfwsettings{'ICMP_TGT'}=$icmptypes{$key}[0];
676 }
677 }
678 }
679 }
680 }
2a81ab0d
AM
681 #check targetport
682 if ($fwdfwsettings{'USESRV'} ne 'ON'){
683 $fwdfwsettings{'grp3'}='';
684 $fwdfwsettings{$fwdfwsettings{'grp3'}}='';
2a81ab0d
AM
685 $fwdfwsettings{'ICMP_TGT'}='';
686 }
2a81ab0d
AM
687 #check timeframe
688 if($fwdfwsettings{'TIME'} eq 'ON'){
689 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 ''){
690 $errormessage=$Lang::tr{'fwdfw err time'};
931e1fed 691 return $errormessage;
2a81ab0d
AM
692 }
693 }
2a81ab0d
AM
694 return $errormessage;
695}
a6edca5a
AM
696sub check_natport
697{
698 my $val=shift;
829697d0
AM
699 if($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
700 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\-(\d+)$/) {
701 $fwdfwsettings{'dnatport'} =~ tr/-/:/;
702 if ($fwdfwsettings{'dnatport'} eq "*") {
703 $fwdfwsettings{'dnatport'}="1:65535";
704 }
705 if ($fwdfwsettings{'dnatport'} =~ /^(\D)\:(\d+)$/) {
706 $fwdfwsettings{'dnatport'} = "1:$2";
707 }
708 if ($fwdfwsettings{'dnatport'} =~ /^(\d+)\:(\D)$/) {
709 $fwdfwsettings{'dnatport'} ="$1:65535";
710 }
711 }
712 return 1;
713 }
714 if ($val =~ "," || $val>65536 || $val<0){
a6edca5a
AM
715 return 0;
716 }
717 return 1;
718}
2a81ab0d
AM
719sub checkrule
720{
a6edca5a
AM
721 #check valid port for NAT
722 if($fwdfwsettings{'USE_NAT'} eq 'ON'){
6b681c40 723 #if no port is given in nat area, take target host port
a6edca5a 724 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'grp3'} eq 'TGT_PORT' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$fwdfwsettings{'TGT_PORT'};}
bc912c6e 725 #check if port given in nat area is a single valid port or portrange
98cee89f 726 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'TGT_PORT'} ne '' && !&check_natport($fwdfwsettings{'dnatport'})){
a6edca5a 727 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
98cee89f 728 }elsif($fwdfwsettings{'USESRV'} eq 'ON' && $fwdfwsettings{'grp3'} eq 'cust_srv'){
a6edca5a
AM
729 my $custsrvport;
730 #get servcie Protocol and Port
731 foreach my $key (sort keys %customservice){
732 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]){
733 if ($customservice{$key}[2] ne 'TCP' && $customservice{$key}[2] ne 'UDP'){
734 $errormessage=$Lang::tr{'fwdfw target'}.": ".$Lang::tr{'fwdfw dnat porterr'}."<br>";
735 }
736 $custsrvport= $customservice{$key}[1];
737 }
738 }
739 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} eq ''){$fwdfwsettings{'dnatport'}=$custsrvport;}
740 }
98cee89f
AM
741 #check if DNAT port is multiple
742 if($fwdfwsettings{'nat'} eq 'dnat' && $fwdfwsettings{'dnatport'} ne ''){
743 my @parts=split(",",$fwdfwsettings{'dnatport'});
744 my @values=();
745 foreach (@parts){
746 chomp($_);
747 if ($_ =~ /^(\d+)\-(\d+)$/ || $_ =~ /^(\d+)\:(\d+)$/) {
748 my $check;
749 #change dashes with :
750 $_=~ tr/-/:/;
751 if ($_ eq "*") {
752 push(@values,"1:65535");
753 $check='on';
754 }
755 if ($_ =~ /^(\D)\:(\d+)$/ || $_ =~ /^(\D)\-(\d+)$/) {
756 push(@values,"1:$2");
757 $check='on';
758 }
759 if ($_ =~ /^(\d+)\:(\D)$/ || $_ =~ /^(\d+)\-(\D)$/) {
760 push(@values,"$1:65535");
761 $check='on'
762 }
763 $errormessage .= &General::validportrange($_, 'destination');
764 if(!$check){
765 push (@values,$_);
766 }
767 }else{
768 if (&General::validport($_)){
769 push (@values,$_);
770 }else{
771
772 }
773 }
774 }
775 $fwdfwsettings{'dnatport'}=join("|",@values);
776 }
a6edca5a 777 }
2a81ab0d
AM
778 #check valid remark
779 if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
780 $errormessage.=$Lang::tr{'fwdfw err remark'}."<br>";
781 }
782 #check if source and target identical
27f4a6b1 783 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL'){
cb4439f3 784 $errormessage=$Lang::tr{'fwdfw err same'};
2a81ab0d
AM
785 return $errormessage;
786 }
2a81ab0d
AM
787 #get source and targetip address if possible
788 my ($sip,$scidr,$tip,$tcidr);
789 ($sip,$scidr)=&get_ip("src","grp1");
790 ($tip,$tcidr)=&get_ip("tgt","grp2");
2a81ab0d
AM
791 #check same iprange in source and target
792 if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){
2a81ab0d
AM
793 my $networkip1=&General::getnetworkip($sip,$scidr);
794 my $networkip2=&General::getnetworkip($tip,$tcidr);
795 if ($scidr gt $tcidr){
210ee67b 796 if ( &General::IpInSubnet($networkip1,$tip,&General::iporsubtodec($tcidr))){
2a81ab0d
AM
797 $errormessage.=$Lang::tr{'fwdfw err samesub'};
798 }
8013bd0a
AM
799 }elsif($scidr eq $tcidr && $scidr eq '32'){
800 my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1);
801 my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2);
802 if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){
803 $hint=$Lang::tr{'fwdfw hint ip1'}."<br>";
804 $hint.=$Lang::tr{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>";
805 }
806 }else{
807 if ( &General::IpInSubnet($networkip2,$sip,&General::iporsubtodec($scidr)) ){
808 $errormessage.=$Lang::tr{'fwdfw err samesub'};
809 }
810 }
811 }
8013bd0a
AM
812 #check source and destination protocol if manual
813 if( $fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'USESRV'} eq 'ON'){
814 if($fwdfwsettings{'PROT'} ne $fwdfwsettings{'TGT_PROT'} && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
815 $errormessage.=$Lang::tr{'fwdfw err prot'};
816 }
817 #check source and destination protocol if source manual and dest servicegrp
818 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
8013bd0a
AM
819 foreach my $key (sort keys %customservice){
820 if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){
821 if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){
822 $errormessage.=$Lang::tr{'fwdfw err prot'};
823 last;
824 }
825 }
826 }
827 }
828 }
72586f0f
AM
829 if( $fwdfwsettings{'USE_SRC_PORT'} ne 'ON' && $fwdfwsettings{'USESRV'} ne 'ON'){
830 $fwdfwsettings{'PROT'}='';
831 $fwdfwsettings{'TGT_PROT'}='';
832 }
8013bd0a
AM
833}
834sub checkcounter
835{
836 my ($base1,$val1,$base2,$val2) = @_;
837
838 if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){
839 &dec_counter($confignet,\%customnetwork,$val1);
840 }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){
841 &dec_counter($confighost,\%customhost,$val1);
842 }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){
843 &dec_counter($configgrp,\%customgrp,$val1);
844 }elsif($base1 eq 'cust_srv'){
845 &dec_counter($configsrv,\%customservice,$val1);
846 }elsif($base1 eq 'cust_srvgrp'){
847 &dec_counter($configsrvgrp,\%customservicegrp,$val1);
848 }
849
850 if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){
851 &inc_counter($confignet,\%customnetwork,$val2);
852 }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){
853 &inc_counter($confighost,\%customhost,$val2);
854 }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){
855 &inc_counter($configgrp,\%customgrp,$val2);
856 }elsif($base2 eq 'cust_srv'){
857 &inc_counter($configsrv,\%customservice,$val2);
858 }elsif($base2 eq 'cust_srvgrp'){
859 &inc_counter($configsrvgrp,\%customservicegrp,$val2);
860 }
931e1fed
AM
861}
862sub checkvpn
863{
864 my $ip=shift;
865 #Test if manual IP is part of static OpenVPN networks
866 &General::readhasharray("$configccdnet", \%ccdnet);
867 foreach my $key (sort keys %ccdnet){
868 my ($vpnip,$vpnsubnet) = split ("/",$ccdnet{$key}[1]);
869 my $sub=&General::iporsubtodec($vpnsubnet);
870 if (&General::IpInSubnet($ip,$vpnip,$sub)){
871 return 0;
872 }
873 }
874 # A Test if manual ip is part of dynamic openvpn subnet is made in getcolor
875 # because if one creates a custom host with the ip, we need to check the color there!
876 # It does not make sense to check this here
877
878 # Test if manual IP is part of an OpenVPN N2N subnet does also not make sense here
879 # Is also checked in getcolor
880
881 # Test if manual ip is part of an IPsec Network is also checked in getcolor
882 return 1;
883}
884sub checkvpncolor
885{
886
8013bd0a
AM
887}
888sub deleterule
889{
890 my %delhash=();
891 &General::readhasharray($fwdfwsettings{'config'}, \%delhash);
892 foreach my $key (sort {$a <=> $b} keys %delhash){
893 if ($key == $fwdfwsettings{'key'}){
894 #check hosts/net and groups
895 &checkcounter($delhash{$key}[3],$delhash{$key}[4],,);
896 &checkcounter($delhash{$key}[5],$delhash{$key}[6],,);
897 #check services and groups
898 if ($delhash{$key}[11] eq 'ON'){
899 &checkcounter($delhash{$key}[14],$delhash{$key}[15],,);
900 }
901 }
902 if ($key >= $fwdfwsettings{'key'}) {
903 my $next = $key + 1;
904 if (exists $delhash{$next}) {
905 foreach my $i (0 .. $#{$delhash{$next}}) {
906 $delhash{$key}[$i] = $delhash{$next}[$i];
907 }
908 }
909 }
910 }
911 # Remove the very last entry.
912 my $last_key = (sort {$a <=> $b} keys %delhash)[-1];
913 delete $delhash{$last_key};
914
915 &General::writehasharray($fwdfwsettings{'config'}, \%delhash);
916 &rules;
917
918 if($fwdfwsettings{'nobase'} ne 'on'){
919 &base;
920 }
921}
922sub disable_rule
923{
924 my $key1=shift;
925 &General::readhasharray("$configfwdfw", \%configfwdfw);
926 foreach my $key (sort keys %configfwdfw){
927 if ($key eq $key1 ){
928 if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';}
929 }
930 }
931 &General::writehasharray("$configfwdfw", \%configfwdfw);
932 &rules;
933}
934sub dec_counter
935{
936 my $config=shift;
937 my %hash=%{(shift)};
938 my $val=shift;
939 my $pos;
8013bd0a
AM
940 &General::readhasharray($config, \%hash);
941 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
942 if($hash{$key}[0] eq $val){
943 $pos=$#{$hash{$key}};
944 $hash{$key}[$pos] = $hash{$key}[$pos]-1;
945 }
946 }
947 &General::writehasharray($config, \%hash);
948}
949sub error
950{
951 if ($errormessage) {
952 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
953 print "<class name='base'>$errormessage\n";
954 print "&nbsp;</class>\n";
955 &Header::closebox();
956 print"<hr>";
957 }
958}
959sub fillselect
960{
961 my %hash=%{(shift)};
962 my $val=shift;
963 my $key;
eff2dbf8 964 foreach my $key (sort { ncmp($hash{$a}[0],$hash{$b}[0]) } keys %hash){
8013bd0a
AM
965 if($hash{$key}[0] eq $val){
966 print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>";
967 }else{
968 print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>";
969 }
970 }
971}
972sub gen_dd_block
973{
974 my $srctgt = shift;
975 my $grp=shift;
976 my $helper='';
977 my $show='';
978 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
979 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
980 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
981 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
982 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
983 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
984 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
985 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
986 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
987 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
988 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
989 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
990 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
991 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
992 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
993 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
994 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
a0fb1099 995 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
8013bd0a
AM
996 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
997print<<END;
998 <table width='100%' border='0'>
999 <tr><td width='50%' valign='top'>
1000 <table width='100%' border='0'>
b88c8829 1001 <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;'>
8013bd0a
AM
1002END
1003 foreach my $network (sort keys %defaultNetworks)
1004 {
223d3b1d 1005 next if($defaultNetworks{$network}{'NAME'} eq "RED" && $srctgt eq 'src');
a0fb1099 1006 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
8013bd0a
AM
1007 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1008 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $defaultNetworks{$network}{'NAME'});
3b2ad4a1 1009 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
1a8fde0e
AM
1010 my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK";
1011 my $defsub1=&General::subtocidr($ifaces{$defsub});
7326051e 1012 $ifaces{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED');
a0fb1099 1013 if ($ifaces{$defnet}){
1a8fde0e 1014 print ">$network ($ifaces{$defnet}/$defsub1)</option>";
a0fb1099
AM
1015 }else{
1016 print ">$network</option>";
1017 }
8013bd0a
AM
1018 }
1019 print"</select></td></tr>";
1020 #custom networks
d9987841 1021 if (! -z $confignet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
b88c8829 1022 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;'>";
8013bd0a
AM
1023 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{$grp}});
1024 print"</select></td>";
1025 }
1026 #custom hosts
d9987841 1027 if (! -z $confighost || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
b88c8829 1028 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;'>";
8013bd0a
AM
1029 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{$grp}});
1030 print"</select></td>";
1031 }
1032 #custom groups
d9987841 1033 if (! -z $configgrp || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
b88c8829 1034 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;'>";
eff2dbf8 1035 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } keys %customgrp) {
8013bd0a
AM
1036 if($helper ne $customgrp{$key}[0]){
1037 print"<option ";
1038 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $customgrp{$key}[0]);
1039 print ">$customgrp{$key}[0]</option>";
1040 }
1041 $helper=$customgrp{$key}[0];
1042 }
1043 print"</select></td>";
1044 }
1045 #End left table. start right table (vpn)
1046 print"</tr></table></td><td valign='top'><table width='100%' border='0'><tr>";
1047 # CCD networks
d9987841 1048 if( ! -z $configccdnet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
b88c8829 1049 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;'>";
8013bd0a
AM
1050 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{$grp}});
1051 print"</select></td></tr>";
1052 }
1053 #OVPN CCD Hosts
eff2dbf8 1054 foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost){
d9987841 1055 if ($ccdhost{$key}[33] ne '' ){
b88c8829 1056 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 '');
8013bd0a
AM
1057 $show='1';
1058 print "<option value='$ccdhost{$key}[1]'";
1059 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1060 print ">$ccdhost{$key}[1]</option>";
1061 }
1062 }
d9987841 1063 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
b88c8829 1064 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>" ;
d9987841 1065 }
8013bd0a
AM
1066 if ($show eq '1'){$show='';print"</select></td></tr>";}
1067 #OVPN N2N
eff2dbf8 1068 foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost){
8013bd0a 1069 if ($ccdhost{$key}[3] eq 'net'){
b88c8829 1070 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 '');
d9987841 1071 $show='1';
8013bd0a
AM
1072 print "<option value='$ccdhost{$key}[1]'";
1073 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1074 print ">$ccdhost{$key}[1]</option>";
1075 }
1076 }
d9987841 1077 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
b88c8829 1078 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>" ;
d9987841 1079 }
8013bd0a
AM
1080 if ($show eq '1'){$show='';print"</select></td></tr>";}
1081 #IPsec netze
eff2dbf8 1082 foreach my $key (sort { ncmp($ipsecconf{$a}[1],$ipsecconf{$b}[1]) } keys %ipsecconf) {
d9987841 1083 if ($ipsecconf{$key}[3] eq 'net' || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
97e2e7b4 1084 print"<tr><td valign='top'><input type='radio' name='$grp' value='ipsec_net_$srctgt' $checked{$grp}{'ipsec_net_'.$srctgt}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td align='right'><select name='ipsec_net_$srctgt' style='width:200px;'>" if ($show eq '');
8013bd0a
AM
1085 $show='1';
1086 print "<option ";
1087 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ipsecconf{$key}[1]);
1088 print ">$ipsecconf{$key}[1]</option>";
1089 }
1090 }
d9987841 1091 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
b88c8829 1092 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>";
d9987841 1093 }
8013bd0a
AM
1094 if ($show eq '1'){$show='';print"</select></td></tr>";}
1095
b88c8829 1096 print"</table>";
8013bd0a
AM
1097 print"</td></tr></table><br>";
1098}
1099sub get_ip
1100{
1101 my $val=shift;
1102 my $grp =shift;
1103 my $a;
1104 my $b;
1105 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1106 if ($fwdfwsettings{$grp} ne $Lang::tr{'fwhost any'}){
1107 if ($fwdfwsettings{$grp} eq $val.'_addr'){
1108 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
1109 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
1110 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
1111 $a=$netsettings{'GREEN_NETADDRESS'};
1112 $b=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'});
1113 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
1114 $a=$netsettings{'ORANGE_NETADDRESS'};
1115 $b=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'});
1116 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
1117 $a=$netsettings{'BLUE_NETADDRESS'};
1118 $b=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'});
1119 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
1120 &General::readhash("$configovpn",\%ovpnsettings);
1121 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
1122 $b=&General::iporsubtocidr($b);
1123 }
1124 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
1125 &General::readhasharray("$confignet", \%customnetwork);
1126 foreach my $key (keys %customnetwork){
1127 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1128 $a=$customnetwork{$key}[1];
1129 $b=&General::iporsubtocidr($customnetwork{$key}[2]);
1130 }
1131 }
1132 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
1133 &General::readhasharray("$confighost", \%customhost);
1134 foreach my $key (keys %customhost){
1135 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1136 if ($customhost{$key}[1] eq 'ip'){
1137 ($a,$b)=split (/\//,$customhost{$key}[2]);
1138 $b=&General::iporsubtocidr($b);
1139 }else{
1140 if ($grp eq 'grp2'){
1141 $errormessage=$Lang::tr{'fwdfw err tgt_mac'};
1142 }
1143 }
1144 }
1145 }
1146 }
1147 }
1148 return $a,$b;
1149}
1150sub get_name
1151{
1152 my $val=shift;
1153 &General::setup_default_networks(\%defaultNetworks);
1154 foreach my $network (sort keys %defaultNetworks)
1155 {
1156 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1157 }
1158}
1159sub getsrcport
1160{
1161 my %hash=%{(shift)};
1162 my $key=shift;
1163 if($hash{$key}[7] eq 'ON' && $hash{$key}[8] ne '' && $hash{$key}[10]){
1164 $hash{$key}[10]=~ s/\|/,/g;
1165 print": $hash{$key}[10]";
1166 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
1167 print": <br>$hash{$key}[9] ";
1168 }
1169}
1170sub gettgtport
1171{
1172 my %hash=%{(shift)};
1173 my $key=shift;
1174 my $service;
1175 my $prot;
1176 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1177 if($hash{$key}[14] eq 'cust_srv'){
1178 &General::readhasharray("$configsrv", \%customservice);
1179 foreach my $i (sort keys %customservice){
1180 if($customservice{$i}[0] eq $hash{$key}[15]){
1181 $service = $customservice{$i}[0];
1182 }
1183 }
1184 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
1185 $service=$hash{$key}[15];
1186 }elsif($hash{$key}[14] eq 'TGT_PORT'){
1187 $hash{$key}[15]=~ s/\|/,/g;
1188 $service=$hash{$key}[15];
1189 }
1190 if($service){
1191 print": $service";
1192 }
1193 }elsif($hash{$key}[11] eq 'ON' && $hash{$key}[12] eq 'ICMP'){
1194 print":<br>$hash{$key}[13]";
1195 }
1196}
1197sub get_serviceports
1198{
1199 my $type=shift;
1200 my $name=shift;
1201 &General::readhasharray("$configsrv", \%customservice);
1202 &General::readhasharray("$configsrvgrp", \%customservicegrp);
8013bd0a
AM
1203 my $tcp;
1204 my $udp;
b3f4a4ef
AM
1205 my $icmp;
1206 @protocols=();
8013bd0a 1207 if($type eq 'service'){
eff2dbf8 1208 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
8013bd0a 1209 if ($customservice{$key}[0] eq $name){
b3f4a4ef 1210 push (@protocols,$customservice{$key}[2]);
8013bd0a
AM
1211 }
1212 }
1213 }elsif($type eq 'group'){
eff2dbf8 1214 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
8013bd0a 1215 if ($customservicegrp{$key}[0] eq $name){
eff2dbf8 1216 foreach my $key1 (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
8013bd0a 1217 if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
b3f4a4ef
AM
1218 if($customservice{$key1}[2] eq 'TCP'){
1219 $tcp='TCP';
1220 }elsif($customservice{$key1}[2] eq 'ICMP'){
1221 $icmp='ICMP';
1222 }elsif($customservice{$key1}[2] eq 'UDP'){
1223 $udp='UDP';
1224 }
8013bd0a
AM
1225 }
1226 }
1227 }
1228 }
1229 }
b3f4a4ef
AM
1230 if($tcp && $udp && $icmp){
1231 push (@protocols,"All");
1232 return @protocols;
1233 }
1234 if($tcp){
1235 push (@protocols,"TCP");
1236 }
1237 if($udp){
1238 push (@protocols,"UDP");
1239 }
1240 if($icmp){
1241 push (@protocols,"ICMP");
1242 }
1243 return @protocols;
8013bd0a
AM
1244}
1245sub getcolor
1246{
1247 my $nettype=shift;
1248 my $val=shift;
1249 my $hash=shift;
1250 if($optionsfw{'SHOWCOLORS'} eq 'on'){
e3c58927
AM
1251 #standard networks
1252 if ($val eq 'GREEN'){
1253 $tdcolor="style='border: 1px solid $Header::colourgreen;'";
1254 return;
1255 }elsif ($val eq 'ORANGE'){
1256 $tdcolor="style='border: 1px solid $Header::colourorange;'";
1257 return;
1258 }elsif ($val eq 'BLUE'){
1259 $tdcolor="style='border: 1px solid $Header::colourblue;'";
1260 return;
05d4f131 1261 }elsif ($val eq 'RED' ||$val eq 'RED1' ){
e3c58927
AM
1262 $tdcolor="style='border: 1px solid $Header::colourred;'";
1263 return;
1264 }elsif ($val eq 'IPFire' ){
1265 $tdcolor="style='border: 1px solid $Header::colourred;'";
1266 return;
1267 }elsif($val =~ /^(.*?)\/(.*?)$/){
1268 my ($sip,$scidr) = split ("/",$val);
1269 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1270 $tdcolor="style='border: 1px solid $Header::colourorange;'";
1271 return;
1272 }
1273 if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1274 $tdcolor="style='border: 1px solid $Header::colourgreen;'";
1275 return;
1276 }
1277 if ( &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
1278 $tdcolor="style='border: 1px solid $Header::colourblue;'";
1279 return;
1280 }
1281 }elsif ($val eq 'Default IP'){
1282 $tdcolor="style='border: 1px solid $Header::colourred;'";
1283 return;
1284 }
931e1fed
AM
1285 #Check if a manual IP is part of a VPN
1286 if ($nettype eq 'src_addr' || $nettype eq 'tgt_addr'){
1287 #Check if IP is part of OpenVPN dynamic subnet
1288 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
1289 my ($c,$d) = split("/",$val);
1290 if (&General::IpInSubnet($c,$a,$b)){
1291 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1292 return;
1293 }
d9b691e1
AM
1294 #Check if IP is part of OpenVPN static subnet
1295 foreach my $key (sort keys %ccdnet){
1296 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1297 $b =&General::iporsubtodec($b);
1298 if (&General::IpInSubnet($c,$a,$b)){
1299 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1300 return;
1301 }
1302 }
1303 #Check if IP is part of OpenVPN N2N subnet
1304 foreach my $key (sort keys %ccdhost){
1305 if ($ccdhost{$key}[3] eq 'net'){
1306 my ($a,$b) = split("/",$ccdhost{$key}[11]);
1307 if (&General::IpInSubnet($c,$a,$b)){
1308 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1309 return;
1310 }
1311 }
1312 }
931e1fed
AM
1313 #Check if IP is part of IPsec RW network
1314 if ($ipsecsettings{'RW_NET'} ne ''){
1315 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1316 $b=&General::iporsubtodec($b);
1317 if (&General::IpInSubnet($c,$a,$b)){
1318 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1319 return;
1320 }
1321 }
1322 #Check if IP is part of a IPsec N2N network
1323 foreach my $key (sort keys %ipsecconf){
1324 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1325 if (&General::IpInSubnet($c,$a,$b)){
1326 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1327 return;
1328 }
1329 }
1330 }
8013bd0a
AM
1331 #VPN networks
1332 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'){
1333 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1334 return;
1335 }
1336 if ($nettype eq 'ipsec_net_src' || $nettype eq 'ipsec_net_tgt'){
1337 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1338 return;
1339 }
1340 #custom Hosts
1341 if ($nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1342 foreach my $key (sort keys %$hash){
1343 if ($$hash{$key}[0] eq $val){
1344 $val=$$hash{$key}[2];
1345 }
1346 }
1347 }
1348 #ALIASE
1349 foreach my $alias (sort keys %aliases)
1350 {
1351 if ($val eq $alias){
f2ab6fba 1352 $tdcolor="style='border: 1px solid $Header::colourred;'";
8013bd0a
AM
1353 return;
1354 }
1355 }
2a81ab0d 1356 }
e3c58927
AM
1357 $tdcolor='';
1358 return;
8013bd0a
AM
1359}
1360sub hint
1361{
1362 if ($hint) {
1363 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1364 print "<class name='base'>$hint\n";
1365 print "&nbsp;</class>\n";
1366 &Header::closebox();
1367 print"<hr>";
2a81ab0d 1368 }
2a81ab0d 1369}
8013bd0a 1370sub inc_counter
2a81ab0d 1371{
8013bd0a
AM
1372 my $config=shift;
1373 my %hash=%{(shift)};
2a81ab0d 1374 my $val=shift;
8013bd0a
AM
1375 my $pos;
1376
1377 &General::readhasharray($config, \%hash);
1378 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
1379 if($hash{$key}[0] eq $val){
1380 $pos=$#{$hash{$key}};
1381 $hash{$key}[$pos] = $hash{$key}[$pos]+1;
2a81ab0d
AM
1382 }
1383 }
8013bd0a 1384 &General::writehasharray($config, \%hash);
2a81ab0d
AM
1385}
1386sub newrule
1387{
1388 &error;
1389 &General::setup_default_networks(\%defaultNetworks);
515863e2 1390 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
2a81ab0d
AM
1391 #read all configfiles
1392 &General::readhasharray("$configccdnet", \%ccdnet);
1393 &General::readhasharray("$confignet", \%customnetwork);
1394 &General::readhasharray("$configccdhost", \%ccdhost);
1395 &General::readhasharray("$confighost", \%customhost);
1396 &General::readhasharray("$configccdhost", \%ccdhost);
1397 &General::readhasharray("$configgrp", \%customgrp);
1398 &General::readhasharray("$configipsec", \%ipsecconf);
1399 &General::get_aliases(\%aliases);
2a81ab0d
AM
1400 my %checked=();
1401 my $helper;
2da264ec 1402 my $sum=0;
2a81ab0d
AM
1403 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
1404 my $config=$fwdfwsettings{'config'};
1405 my %hash=();
43d8be09 1406 #Get Red IP-ADDRESS
1407 open (CONN1,"/var/ipfire/red/local-ipaddress");
1408 my $redip = <CONN1>;
1409 close(CONN1);
2a81ab0d
AM
1410 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1411 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1412 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1413 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1414 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1415 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1416 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1417 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1418 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1419 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1420 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1421 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1422 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1423 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1424 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
a6edca5a 1425 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
2a81ab0d
AM
1426 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1427 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1428 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
43d8be09 1429 $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
2a81ab0d
AM
1430 #check if update and get values
1431 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
1432 &General::readhasharray("$config", \%hash);
1433 foreach my $key (sort keys %hash){
2da264ec 1434 $sum++;
2a81ab0d 1435 if ($key eq $fwdfwsettings{'key'}){
70d38e50 1436 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
2a81ab0d 1437 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
2669161d 1438 $fwdfwsettings{'chain'} = $hash{$key}[1];
2a81ab0d
AM
1439 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1440 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1441 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1442 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1443 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1444 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1445 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1446 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1447 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1448 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1449 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1450 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1451 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1452 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1453 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1454 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1455 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1456 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1457 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1458 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1459 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1460 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1461 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1462 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1463 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1464 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
2669161d 1465 $fwdfwsettings{'USE_NAT'} = $hash{$key}[28];
a6edca5a 1466 $fwdfwsettings{'nat'} = $hash{$key}[31]; #changed order
2669161d 1467 $fwdfwsettings{$fwdfwsettings{'nat'}} = $hash{$key}[29];
a6edca5a 1468 $fwdfwsettings{'dnatport'} = $hash{$key}[30];
2a81ab0d
AM
1469 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1470 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1471 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1472 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1473 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1474 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1475 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1476 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1477 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1478 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1479 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1480 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1481 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1482 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1483 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
2669161d
AM
1484 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1485 $checked{'nat'}{$fwdfwsettings{'nat'}} = 'CHECKED';
2a81ab0d
AM
1486 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1487 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1488 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
b044bb05 1489 $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
2669161d
AM
1490 $selected{'dnat'}{$fwdfwsettings{$fwdfwsettings{'nat'}}} ='selected';
1491 $selected{'snat'}{$fwdfwsettings{$fwdfwsettings{'nat'}}} ='selected';
2a81ab0d
AM
1492 }
1493 }
1494 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1495 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1496 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1497 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1498 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1499 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1500 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
02da9f7b 1501 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
2669161d 1502 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
8442c937 1503 $fwdfwsettings{'oldruletype'}=$fwdfwsettings{'chain'};
515863e2
AM
1504 #check if manual ip (source) is orange network
1505 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1506 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1507 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1508 $fwdfwsettings{'oldorange'} ='on';
1509 }
1510 }
2a81ab0d
AM
1511 }else{
1512 $fwdfwsettings{'ACTIVE'}='ON';
1513 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
515863e2
AM
1514 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1515 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1516 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1517 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1518 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1519 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1520 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1521 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
2669161d 1522 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
515863e2
AM
1523 #check if manual ip (source) is orange network
1524 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1525 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1526 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1527 $fwdfwsettings{'oldorange'} ='on';
1528 }
1529 }
2a81ab0d 1530 }
2a81ab0d 1531 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
ed618226 1532 print "<form method='post'>";
2a81ab0d
AM
1533 &Header::closebox();
1534 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'});
2a81ab0d
AM
1535 #------SOURCE-------------------------------------------------------
1536 print<<END;
1537 <table width='100%' border='0'>
b88c8829 1538 <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='17' ></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>
a0fb1099
AM
1539END
1540 print"<td align='right'><select name='ipfire_src' style='width:200px;'>";
b044bb05
AM
1541 print "<option value='ALL' $selected{'ipfire_src'}{'ALL'}>$Lang::tr{'all'}</option>";
1542 print "<option value='GREEN' $selected{'ipfire_src'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
595a90f0
AM
1543 print "<option value='ORANGE' $selected{'ipfire_src'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if (&Header::orange_used());
1544 print "<option value='BLUE' $selected{'ipfire_src'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>" if (&Header::blue_used());
b044bb05 1545 print "<option value='RED1' $selected{'ipfire_src'}{'RED1'}>$Lang::tr{'red1'} ($redip)" if ($redip);
a0fb1099
AM
1546
1547 if (! -z "${General::swroot}/ethernet/aliases"){
1548 foreach my $alias (sort keys %aliases)
1549 {
1550 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1551 }
1552 }
1553 print<<END;
b88c8829 1554 </select></td></tr>
a0fb1099 1555 <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
2a81ab0d 1556END
8013bd0a 1557 &gen_dd_block('src','grp1');
2a81ab0d 1558 print<<END;
b88c8829 1559 <table><tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
2a81ab0d
AM
1560 <table width='100%' border='0'>
1561 <tr><td width='1%'><input type='checkbox' name='USE_SRC_PORT' value='ON' $checked{'USE_SRC_PORT'}{'ON'}></td><td width='51%' colspan='3'>$Lang::tr{'fwdfw use srcport'}</td>
1562 <td width='15%' nowrap='nowrap'>$Lang::tr{'fwdfw man port'}</td><td><select name='PROT'>
1563END
d1f01304 1564 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
2a81ab0d
AM
1565 {
1566 if ($_ eq $fwdfwsettings{'PROT'})
1567 {
1568 print"<option selected>$_</option>";
1569 }else{
1570 print"<option>$_</option>";
1571 }
1572 }
8f0b047b 1573 $fwdfwsettings{'SRC_PORT'}=~ s/\|/,/g;
2a81ab0d 1574 print<<END;
8f0b047b 1575 </select></td><td align='right'><input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18' ></td></tr>
12a43202 1576 <tr><td></td><td></td><td></td><td></td><td nowrap='nowrap'>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TYPES' style='width:230px;'>
2a81ab0d
AM
1577END
1578 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1579 print"<option>All ICMP-Types</option>";
eff2dbf8 1580 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) } keys %icmptypes){
2a81ab0d
AM
1581 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1582 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1583 }else{
1584 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1585 }
1586 }
1587 print<<END;
5dd84c25 1588 </select></td></tr></table><br><hr>
2a81ab0d
AM
1589END
1590 &Header::closebox();
1591
1592 #---TARGET------------------------------------------------------
1593 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw target'});
1594 print<<END;
1595 <table width='100%' border='0'>
b88c8829 1596 <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='17'><td width='1%'><input type='radio' name='grp2' id='ipfire' value='ipfire' $checked{'grp2'}{'ipfire'}></td><td><b>Firewall</b></td>
2a81ab0d 1597END
05d4f131 1598 print"<td align='right'><select name='ipfire' style='width:200px;'>";
a0fb1099
AM
1599 print "<option value='ALL' $selected{'ipfire'}{'ALL'}>$Lang::tr{'all'}</option>";
1600 print "<option value='GREEN' $selected{'ipfire'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
595a90f0
AM
1601 print "<option value='ORANGE' $selected{'ipfire'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if (&Header::orange_used());
1602 print "<option value='BLUE' $selected{'ipfire'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>"if (&Header::blue_used());
fc83b09d 1603 print "<option value='RED1' $selected{'ipfire'}{'RED1'}>$Lang::tr{'red1'} ($redip)" if ($redip);
05d4f131 1604 if (! -z "${General::swroot}/ethernet/aliases"){
bedb72f3
AM
1605 foreach my $alias (sort keys %aliases)
1606 {
1607 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1608 }
2a81ab0d 1609 }
2a81ab0d 1610 print<<END;
b88c8829 1611 </select></td></tr>
8013bd0a 1612 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
2a81ab0d 1613END
8013bd0a 1614 &gen_dd_block('tgt','grp2');
2a81ab0d 1615 print<<END;
b88c8829 1616 <hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; '><br>
2a81ab0d 1617 <table width='100%' border='0'>
b88c8829 1618 <tr><td width='1%'><input type='checkbox' name='USESRV' value='ON' $checked{'USESRV'}{'ON'} ></td><td width='48%'>$Lang::tr{'fwdfw use srv'}</td><td width='1%'><input type='radio' name='grp3' id='cust_srv' value='cust_srv' checked></td><td nowrap='nowrap'>$Lang::tr{'fwhost cust service'}</td><td width='1%' colspan='2'><select name='cust_srv' style='min-width:230px;' >
2a81ab0d
AM
1619END
1620 &General::readhasharray("$configsrv", \%customservice);
eff2dbf8 1621 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
2a81ab0d
AM
1622 print"<option ";
1623 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1624 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1625 }
1626 print<<END;
1627 </select></td></tr>
b88c8829 1628 <tr><td colspan='2'></td><td><input type='radio' name='grp3' id='cust_srvgrp' value='cust_srvgrp' $checked{'grp3'}{'cust_srvgrp'}></td><td nowrap='nowrap'>$Lang::tr{'fwhost cust srvgrp'}</td><td colspan='2'><select name='cust_srvgrp' style='min-width:230px;' >
2a81ab0d
AM
1629END
1630 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1631 my $helper;
eff2dbf8 1632 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
2a81ab0d
AM
1633 if ($helper ne $customservicegrp{$key}[0]){
1634 print"<option ";
1635 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1636 print">$customservicegrp{$key}[0]</option>";
1637 }
1638 $helper=$customservicegrp{$key}[0];
1639 }
1640 print<<END;
1641 </select></td></tr>
b88c8829 1642 <tr><td colspan='2'></td><td><input type='radio' name='grp3' id='TGT_PORT' value='TGT_PORT' $checked{'grp3'}{'TGT_PORT'}></td><td>$Lang::tr{'fwdfw man port'}</td><td><select name='TGT_PROT' onchange='checkradio(\"#TGT_PORT\")'>
2a81ab0d 1643END
d1f01304 1644 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
2a81ab0d
AM
1645 {
1646 if ($_ eq $fwdfwsettings{'TGT_PROT'})
1647 {
1648 print"<option selected>$_</option>";
1649 }else{
1650 print"<option>$_</option>";
1651 }
1652 }
8f0b047b 1653 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
2a81ab0d 1654 print<<END;
b88c8829 1655 </select></td><td align='right'><input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18' onclick='checkradio(\"#TGT_PORT\")'></td></tr>
12a43202 1656 <tr><td colspan='2'></td><td></td><td>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TGT' style='min-width:230px;'>
2a81ab0d
AM
1657END
1658 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1659 print"<option>All ICMP-Types</option>";
eff2dbf8 1660 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
2a81ab0d
AM
1661 if($fwdfwsettings{'ICMP_TGT'} eq "$icmptypes{$key}[0]"){
1662 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1663 }else{
1664 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1665 }
1666 }
1667 print<<END;
1668 </select></td></tr>
5dd84c25 1669 </table><br><hr>
62fc8511 1670
2a81ab0d 1671END
5dd84c25 1672 &Header::closebox;
2669161d
AM
1673 #---SNAT / DNAT ------------------------------------------------
1674 &Header::openbox('100%', 'left', 'NAT');
1675 print<<END;
1676 <table width='100%' border='0'>
b88c8829
AM
1677 <tr><td width='1%'><input type='checkbox' name='USE_NAT' id='USE_NAT' value='ON' $checked{'USE_NAT'}{'ON'}></td><td width='15%'>$Lang::tr{'fwdfw use nat'}</td><td colspan='5'></td></tr>
1678 <tr><td colspan='2'></td><td width='1%'><input type='radio' name='nat' id='dnat' value='dnat' checked ></td><td width='50%'>$Lang::tr{'fwdfw dnat'}</td>
2669161d 1679END
93b75f31
AM
1680 print"<td width='8%'>IPFire: </td><td width='20%' align='right'><select name='dnat' style='width:140px;'>";
1681 print "<option value='ALL' $selected{'dnat'}{$Lang::tr{'all'}}>$Lang::tr{'all'}</option>";
1682 print "<option value='Default IP' $selected{'dnat'}{'Default IP'}>Default IP</option>";
1683 foreach my $alias (sort keys %aliases)
1684 {
1685 print "<option value='$alias' $selected{'dnat'}{$alias}>$alias</option>";
2669161d 1686 }
b88c8829 1687 print"</select></td></tr>";
98cee89f 1688 $fwdfwsettings{'dnatport'}=~ tr/|/,/;
b88c8829 1689 print"<tr><td colspan='4'></td><td>Port: </td><td align='right'><input type='text' name='dnatport' style='width:130px;' value=\"$fwdfwsettings{'dnatport'}\"> </td></tr>";
2669161d
AM
1690 print"<tr><td colspan='8'><br></td></tr>";
1691 #SNAT
b88c8829 1692 print"<tr><td colspan='2'></td><td width='1%'><input type='radio' name='nat' id='snat' value='snat' $checked{'nat'}{'snat'}></td><td width='20%'>$Lang::tr{'fwdfw snat'}</td>";
a6edca5a 1693 print"<td width='8%'>IPFire: </td><td width='20%' align='right'><select name='snat' style='width:140px;'>";
2669161d
AM
1694 foreach my $alias (sort keys %aliases)
1695 {
1696 print "<option value='$alias' $selected{'snat'}{$alias}>$alias</option>";
1697 }
1698 foreach my $network (sort keys %defaultNetworks)
1699 {
2669161d
AM
1700 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1701 next if($defaultNetworks{$network}{'NAME'} eq "ALL");
a6edca5a 1702 next if($defaultNetworks{$network}{'NAME'} =~ /OpenVPN/i);
2669161d
AM
1703 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1704 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'nat'}} eq $defaultNetworks{$network}{'NAME'});
1705 print ">$network</option>";
1706 }
b88c8829 1707 print"</select></td></tr></table>";
2669161d
AM
1708 print"<hr>";
1709 &Header::closebox();
2a81ab0d
AM
1710 #---Activate/logging/remark-------------------------------------
1711 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw additional'});
1712 print<<END;
43d8be09 1713 <table width='100%' border='0'>
bedb72f3 1714 <tr><td nowrap>$Lang::tr{'fwdfw rule action'}</td><td><select name='RULE_ACTION'>
2da264ec 1715END
bedb72f3
AM
1716 foreach ("ACCEPT","DROP","REJECT")
1717 {
1718 if($fwdfwsettings{'updatefwrule'} eq 'on'){
1719 print"<option value='$_'";
1720 print "selected='selected'" if ($fwdfwsettings{'RULE_ACTION'} eq $_);
1721 print">$Lang::tr{'fwdfw '.$_}</option>";
1722 }else{
1723 if($fwdfwsettings{'POLICY'} eq 'MODE2'){
1724 $fwdfwsettings{'RULE_ACTION'} = 'DROP';
1725 }
1726 if ($_ eq $fwdfwsettings{'RULE_ACTION'})
1727 {
f2ab6fba 1728 print"<option value='$_' selected>$Lang::tr{'fwdfw '.$_}</option>";
bedb72f3 1729 }else{
f2ab6fba 1730 print"<option value='$_'>$Lang::tr{'fwdfw '.$_}</option>";
bedb72f3
AM
1731 }
1732 }
1733 }
1734 print"</select></td></tr>";
b88c8829 1735 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>";
2da264ec
AM
1736 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
1737 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
1738 for (my $count =1; $count <= $sum; $count++){
1739 print"<option value='$count' ";
1740 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
1741 print">$count</option>";
1742 }
1743 print"</select></td></tr>";
70d38e50
AM
1744 }else{
1745 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
2da264ec
AM
1746 }
1747
1748 print<<END;
1749 </table><table width='100%'>
2a81ab0d
AM
1750 <tr><td width='1%'><input type='checkbox' name='ACTIVE' value='ON' $checked{'ACTIVE'}{'ON'}></td><td>$Lang::tr{'fwdfw rule activate'}</td></tr>
1751 <tr><td width='1%'><input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'} ></td><td>$Lang::tr{'fwdfw log rule'}</td></tr>
5dd84c25 1752 </table><br><hr>
2a81ab0d
AM
1753END
1754 &Header::closebox();
1755 #---ADD TIMEFRAME-----------------------------------------------
1756 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw timeframe'});
1757 print<<END;
1758 <table width='70%' border='0'>
b88c8829
AM
1759 <tr><td width='1%'><input type='checkbox' name='TIME' value='ON' $checked{'TIME'}{'ON'}></td><td colspan='9'>$Lang::tr{'fwdfw timeframe'}</td></tr>
1760 <tr><td colspan='10'>&nbsp;</td></tr>
2a81ab0d
AM
1761 <tr>
1762 <td align='left'>$Lang::tr{'time'}:</td>
1763 <td width='30%' align='left'>$Lang::tr{'advproxy monday'} $Lang::tr{'advproxy tuesday'} $Lang::tr{'advproxy wednesday'} $Lang::tr{'advproxy thursday'} $Lang::tr{'advproxy friday'} $Lang::tr{'advproxy saturday'} $Lang::tr{'advproxy sunday'}</td>
2a81ab0d
AM
1764 <td width='15%' align='left'>$Lang::tr{'advproxy from'}</td>
1765 <td width='15%' align='left'>$Lang::tr{'advproxy to'}</td>
1766 </tr>
1767 <tr>
1768 <td align='right'></td>
b88c8829
AM
1769 <td width='1%' align='left'><input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} /></td>
1770 <td width='1%' align='left'><input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} /></td>
1771 <td width='1%' align='left'><input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} /></td>
1772 <td width='1%' align='left'><input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} /></td>
1773 <td width='1%' align='left'><input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} /></td>
1774 <td width='1%' align='left'><input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} /></td>
1775 <td width='15%' align='left'><input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} /></td>
2a81ab0d
AM
1776 <td><select name='TIME_FROM'>
1777END
1778 for (my $i=0;$i<=23;$i++) {
1779 $i = sprintf("%02s",$i);
1780 for (my $j=0;$j<=45;$j+=15) {
1781 $j = sprintf("%02s",$j);
1782 my $time = $i.":".$j;
1783 print "\t\t\t\t\t<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
1784 }
1785 }
1786 print<<END;
1787 </select></td>
1788 <td><select name='TIME_TO'>
1789END
1790 for (my $i=0;$i<=23;$i++) {
1791 $i = sprintf("%02s",$i);
1792 for (my $j=0;$j<=45;$j+=15) {
1793 $j = sprintf("%02s",$j);
1794 my $time = $i.":".$j;
1795 print "\t\t\t\t\t<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
1796 }
1797 }
8013bd0a 1798 print<<END;
b88c8829 1799 </select></td></tr></table><br><hr>
8013bd0a
AM
1800END
1801 #---ACTION------------------------------------------------------
1802 if($fwdfwsettings{'updatefwrule'} ne 'on'){
1803 print<<END;
1804 <table border='0' width='100%'>
1805 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
1806 <input type='hidden' name='config' value='$config' >
b88c8829
AM
1807 <input type='hidden' name='ACTION' value='saverule' ></form>
1808 <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>
1809 </table>
1810 <br>
8013bd0a
AM
1811END
1812 }else{
1813 print<<END;
1814 <table border='0' width='100%'>
1815 <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'}'>
1816 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
1817 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
1818 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
1819 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
1820 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
1821 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
1822 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
1823 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
1824 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
1825 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
1826 <input type='hidden' name='oldorange' value='$fwdfwsettings{'oldorange'}' />
2669161d
AM
1827 <input type='hidden' name='oldnat' value='$fwdfwsettings{'oldnat'}' />
1828 <input type='hidden' name='oldruletype' value='$fwdfwsettings{'oldruletype'}' />
8013bd0a
AM
1829 <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>
1830 </table></form>
1831END
1832 }
1833 &Header::closebox();
1834}
1835sub pos_up
1836{
1837 my %uphash=();
1838 my %tmp=();
1839 &General::readhasharray($fwdfwsettings{'config'}, \%uphash);
1840 foreach my $key (sort keys %uphash){
1841 if ($key eq $fwdfwsettings{'key'}) {
1842 my $last = $key -1;
1843 if (exists $uphash{$last}){
1844 #save rule last
1845 foreach my $y (0 .. $#{$uphash{$last}}) {
1846 $tmp{0}[$y] = $uphash{$last}[$y];
1847 }
1848 #copy active rule to last
1849 foreach my $i (0 .. $#{$uphash{$last}}) {
1850 $uphash{$last}[$i] = $uphash{$key}[$i];
1851 }
1852 #copy saved rule to actual position
1853 foreach my $x (0 .. $#{$tmp{0}}) {
1854 $uphash{$key}[$x] = $tmp{0}[$x];
1855 }
1856 }
1857 }
1858 }
1859 &General::writehasharray($fwdfwsettings{'config'}, \%uphash);
1860 &rules;
1861}
1862sub pos_down
1863{
1864 my %downhash=();
1865 my %tmp=();
1866 &General::readhasharray($fwdfwsettings{'config'}, \%downhash);
1867 foreach my $key (sort keys %downhash){
1868 if ($key eq $fwdfwsettings{'key'}) {
1869 my $next = $key + 1;
1870 if (exists $downhash{$next}){
1871 #save rule next
1872 foreach my $y (0 .. $#{$downhash{$next}}) {
1873 $tmp{0}[$y] = $downhash{$next}[$y];
1874 }
1875 #copy active rule to next
1876 foreach my $i (0 .. $#{$downhash{$next}}) {
1877 $downhash{$next}[$i] = $downhash{$key}[$i];
1878 }
1879 #copy saved rule to actual position
1880 foreach my $x (0 .. $#{$tmp{0}}) {
1881 $downhash{$key}[$x] = $tmp{0}[$x];
1882 }
1883 }
1884 }
1885 }
1886 &General::writehasharray($fwdfwsettings{'config'}, \%downhash);
1887 &rules;
1888}
1889sub rules
1890{
1891 if (!-f "${General::swroot}/forward/reread"){
1892 system("touch ${General::swroot}/forward/reread");
1893 system("touch ${General::swroot}/fwhosts/reread");
1894 }
1895}
1896sub reread_rules
1897{
1898 system("/usr/local/bin/forwardfwctrl");
1899 if ( -f "${General::swroot}/forward/reread"){
1900 system("rm ${General::swroot}/forward/reread");
1901 system("rm ${General::swroot}/fwhosts/reread");
1902 }
2a81ab0d
AM
1903}
1904sub saverule
1905{
2a81ab0d
AM
1906 my $hash=shift;
1907 my $config=shift;
1908 &General::readhasharray("$config", $hash);
1909 if (!$errormessage){
2669161d 1910 ################################################################
2669161d 1911 #check if we change an INPUT rule to a OUTGOING
c12392c0 1912 if($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW' ){
2669161d 1913 &changerule($configinput);
c12392c0 1914 #print"1";
d7127db8 1915 }
8442c937 1916 #check if we change an INPUT rule to a FORWARD
2669161d
AM
1917 elsif($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
1918 &changerule($configinput);
c12392c0 1919 #print"2";
d7127db8 1920 }
2669161d
AM
1921 ################################################################
1922 #check if we change an OUTGOING rule to an INPUT
1923 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'INPUTFW' ){
1924 &changerule($configoutgoing);
c12392c0 1925 #print"3";
d7127db8 1926 }
8442c937 1927 #check if we change an OUTGOING rule to a FORWARD
2669161d 1928 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
d7127db8 1929 &changerule($configoutgoing);
c12392c0 1930 #print"4";
2669161d
AM
1931 }
1932 ################################################################
1933 #check if we change a FORWARD rule to an INPUT
1934 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'INPUTFW'){
1935 &changerule($configfwdfw);
c12392c0 1936 #print"5";
2669161d
AM
1937 }
1938 #check if we change a FORWARD rule to an OUTGOING
1939 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW'){
1940 &changerule($configfwdfw);
c12392c0 1941 #print"6";
2669161d 1942 }
2da264ec 1943 if ($fwdfwsettings{'updatefwrule'} ne 'on'){
2a81ab0d
AM
1944 my $key = &General::findhasharraykey ($hash);
1945 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1946 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1947 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1948 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1949 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1950 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1951 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1952 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1953 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1954 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1955 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1956 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1957 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1958 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1959 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1960 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1961 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1962 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1963 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1964 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1965 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1966 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1967 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1968 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1969 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1970 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1971 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1972 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
c12392c0
AM
1973 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
1974 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
1975 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
1976 $$hash{$key}[31] = $fwdfwsettings{'nat'};
2a81ab0d
AM
1977 &General::writehasharray("$config", $hash);
1978 }else{
e44fa079
AM
1979 foreach my $key (sort {$a <=> $b} keys %$hash){
1980 if($key eq $fwdfwsettings{'key'}){
1981 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1982 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1983 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1984 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1985 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1986 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1987 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1988 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1989 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1990 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1991 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1992 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1993 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1994 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1995 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1996 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1997 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1998 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1999 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
2000 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
2001 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
2002 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
2003 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
2004 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
2005 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
2006 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
2007 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
2008 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
c12392c0
AM
2009 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
2010 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
2011 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
2012 $$hash{$key}[31] = $fwdfwsettings{'nat'};
e44fa079
AM
2013 last;
2014 }
2015 }
2016 }
2017 &General::writehasharray("$config", $hash);
0918e516 2018 if($fwdfwsettings{'oldrulenumber'} > $fwdfwsettings{'rulepos'}){
e44fa079
AM
2019 my %tmp=();
2020 my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'};
2021 for (my $z=0;$z<$val;$z++){
2022 foreach my $key (sort {$a <=> $b} keys %$hash){
2023 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2024 my $last = $key -1;
2025 if (exists $$hash{$last}){
2026 #save rule last
2027 foreach my $y (0 .. $#{$$hash{$last}}) {
2028 $tmp{0}[$y] = $$hash{$last}[$y];
2029 }
2030 #copy active rule to last
2031 foreach my $i (0 .. $#{$$hash{$last}}) {
2032 $$hash{$last}[$i] = $$hash{$key}[$i];
2033 }
2034 #copy saved rule to actual position
2035 foreach my $x (0 .. $#{$tmp{0}}) {
2036 $$hash{$key}[$x] = $tmp{0}[$x];
2da264ec
AM
2037 }
2038 }
2039 }
2040 }
e44fa079
AM
2041 $fwdfwsettings{'oldrulenumber'}--;
2042 }
2043 &General::writehasharray("$config", $hash);
2044 &rules;
0918e516 2045 }elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
e44fa079
AM
2046 my %tmp=();
2047 my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
2048 for (my $z=0;$z<$val;$z++){
2049 foreach my $key (sort {$a <=> $b} keys %$hash){
2050 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2051 my $next = $key + 1;
2052 if (exists $$hash{$next}){
2053 #save rule next
2054 foreach my $y (0 .. $#{$$hash{$next}}) {
2055 $tmp{0}[$y] = $$hash{$next}[$y];
2056 }
2057 #copy active rule to next
2058 foreach my $i (0 .. $#{$$hash{$next}}) {
2059 $$hash{$next}[$i] = $$hash{$key}[$i];
2060 }
2061 #copy saved rule to actual position
2062 foreach my $x (0 .. $#{$tmp{0}}) {
2063 $$hash{$key}[$x] = $tmp{0}[$x];
2da264ec
AM
2064 }
2065 }
2066 }
2a81ab0d 2067 }
e44fa079 2068 $fwdfwsettings{'oldrulenumber'}++;
2a81ab0d
AM
2069 }
2070 &General::writehasharray("$config", $hash);
e44fa079 2071 &rules;
2a81ab0d
AM
2072 }
2073 }
2074}
2a81ab0d
AM
2075sub validremark
2076{
2077 # Checks a hostname against RFC1035
2078 my $remark = $_[0];
2079
2080 # Each part should be at least two characters in length
2081 # but no more than 63 characters
d24a34cb 2082 if (length ($remark) < 1 || length ($remark) > 255) {
2a81ab0d
AM
2083 return 0;}
2084 # Only valid characters are a-z, A-Z, 0-9 and -
e3580608 2085 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
2a81ab0d
AM
2086 return 0;}
2087 # First character can only be a letter or a digit
2088 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
2089 return 0;}
2090 # Last character can only be a letter or a digit
e3580608 2091 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
2a81ab0d
AM
2092 return 0;}
2093 return 1;
2094}
2a81ab0d
AM
2095sub viewtablerule
2096{
15add1c8 2097 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
515863e2 2098 &viewtablenew(\%configfwdfw,$configfwdfw,"","Forward" );
ed618226 2099 &viewtablenew(\%configinputfw,$configinput,"",$Lang::tr{'fwdfw xt access'} );
4f3bd0ca 2100 &viewtablenew(\%configoutgoingfw,$configoutgoing,"","Outgoing" );
2a81ab0d
AM
2101}
2102sub viewtablenew
2103{
2104 my $hash=shift;
2105 my $config=shift;
2106 my $title=shift;
2107 my $title1=shift;
7bd9d462 2108 my $go='';
15add1c8 2109 &General::get_aliases(\%aliases);
af768a7e 2110 &General::readhasharray("$confighost", \%customhost);
7bd9d462 2111 &General::readhasharray("$config", $hash);
d9b691e1
AM
2112 &General::readhasharray("$configccdnet", \%ccdnet);
2113 &General::readhasharray("$configccdhost", \%ccdhost);
5d7faa45 2114 if( ! -z $config){
2a81ab0d
AM
2115 &Header::openbox('100%', 'left',$title);
2116 my $count=0;
2117 my ($gif,$log);
2118 my $ruletype;
2119 my $rulecolor;
2120 my $tooltip;
2121 my @tmpsrc=();
2122 my $coloryellow='';
2a81ab0d 2123 print"<b>$title1</b><br>";
533a2da3 2124 print"<table width='100%' cellspacing='0' cellpadding='0' border='0'>";
b88c8829 2125 print"<tr><td align='center'><b>#</b></td><td></td><td align='center' width='25'></td><td align='center'><b>$Lang::tr{'fwdfw source'}</b></td><td width='1%'><b>Log</b></td><td align='center'><b>$Lang::tr{'fwdfw target'}</b></td><td align='center' colspan='6' width='1%'><b>$Lang::tr{'fwdfw action'}</b></td></tr>";
62fc8511 2126 foreach my $key (sort {$a <=> $b} keys %$hash){
12a43202 2127 $tdcolor='';
2a81ab0d
AM
2128 @tmpsrc=();
2129 #check if vpn hosts/nets have been deleted
2130 if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){
2131 push (@tmpsrc,$$hash{$key}[4]);
2132 }
2133 if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){
2134 push (@tmpsrc,$$hash{$key}[6]);
2135 }
2a81ab0d
AM
2136 foreach my $host (@tmpsrc){
2137 if($$hash{$key}[3] eq 'ipsec_net_src' || $$hash{$key}[5] eq 'ipsec_net_tgt'){
62fc8511 2138 if(&fwlib::get_ipsec_net_ip($host,11) eq ''){
2a81ab0d
AM
2139 $coloryellow='on';
2140 &disable_rule($key);
2141 $$hash{$key}[2]='';
2a81ab0d
AM
2142 }
2143 }elsif($$hash{$key}[3] eq 'ovpn_net_src' || $$hash{$key}[5] eq 'ovpn_net_tgt'){
2144 if(&fwlib::get_ovpn_net_ip($host,1) eq ''){
2145 $coloryellow='on';
2146 &disable_rule($key);
2147 $$hash{$key}[2]='';
2148 }
2149 }elsif($$hash{$key}[3] eq 'ovpn_n2n_src' || $$hash{$key}[5] eq 'ovpn_n2n_tgt'){
2150 if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){
2151 $coloryellow='on';
2152 &disable_rule($key);
2153 $$hash{$key}[2]='';
2154 }
2155 }elsif($$hash{$key}[3] eq 'ovpn_host_src' || $$hash{$key}[5] eq 'ovpn_host_tgt'){
2156 if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
2157 $coloryellow='on';
2158 &disable_rule($key);
2159 $$hash{$key}[2]='';
2160 }
2161 }
2a81ab0d 2162 }
2a81ab0d
AM
2163 $$hash{'ACTIVE'}=$$hash{$key}[2];
2164 $count++;
2a81ab0d
AM
2165 if($coloryellow eq 'on'){
2166 print"<tr bgcolor='$color{'color14'}' >";
2167 $coloryellow='';
2168 }elsif($coloryellow eq ''){
2169 if ($count % 2){
15add1c8 2170 $color="$color{'color22'}";
2a81ab0d
AM
2171 }
2172 else{
15add1c8 2173 $color="$color{'color20'}";
2a81ab0d
AM
2174 }
2175 }
15add1c8 2176 print"<tr bgcolor='$color' >";
a0fb1099 2177 #KEY
2a81ab0d 2178 print<<END;
b88c8829 2179 <td align='right' width='18'><b>$key &nbsp;</b></td>
2a81ab0d 2180END
a0fb1099 2181 #RULETYPE (A,R,D)
2a81ab0d
AM
2182 if ($$hash{$key}[0] eq 'ACCEPT'){
2183 $ruletype='A';
2184 $tooltip='ACCEPT';
2185 $rulecolor=$color{'color17'};
2186 }elsif($$hash{$key}[0] eq 'DROP'){
2187 $ruletype='D';
2188 $tooltip='DROP';
2189 $rulecolor=$color{'color25'};
2190 }elsif($$hash{$key}[0] eq 'REJECT'){
2191 $ruletype='R';
2192 $tooltip='REJECT';
2193 $rulecolor=$color{'color16'};
2194 }
533a2da3 2195 print"<td bgcolor='$rulecolor' align='center' width='10'><span title='$tooltip'><b>$ruletype</b></span></td>";
a0fb1099
AM
2196 #Get Protocol
2197 my $prot;
2198 if ($$hash{$key}[8] && $$hash{$key}[7] eq 'ON'){#source prot if manual
2199 push (@protocols,$$hash{$key}[8]);
2200 }elsif ($$hash{$key}[12]){ #target prot if manual
2201 push (@protocols,$$hash{$key}[12]);
2202 }elsif($$hash{$key}[14] eq 'cust_srv'){
2203 &get_serviceports("service",$$hash{$key}[15]);
2204 }elsif($$hash{$key}[14] eq 'cust_srvgrp'){
2205 &get_serviceports("group",$$hash{$key}[15]);
2206 }else{
2207 push (@protocols,$Lang::tr{'all'});
2208 }
2209 my $protz=join(",",@protocols);
2210 print"<td align='center'>$protz</td>";
2211 @protocols=();
2212 #SOURCE
d4cb89d2 2213 my $ipfireiface;
af768a7e 2214 &getcolor($$hash{$key}[3],$$hash{$key}[4],\%customhost);
15add1c8 2215 print"<td align='center' width='160' $tdcolor>";
d4cb89d2
AM
2216 if ($$hash{$key}[3] eq 'ipfire_src'){
2217 $ipfireiface='Interface ';
2218 }
2a81ab0d
AM
2219 if ($$hash{$key}[3] eq 'std_net_src'){
2220 print &get_name($$hash{$key}[4]);
4f3bd0ca
AM
2221 }elsif ($$hash{$key}[3] eq 'src_addr'){
2222 my ($split1,$split2) = split("/",$$hash{$key}[4]);
2223 if ($split2 eq '32'){
2224 print $split1;
2225 }else{
2226 print $$hash{$key}[4];
2227 }
43d8be09 2228 }elsif ($$hash{$key}[4] eq 'RED1'){
d4cb89d2 2229 print "$ipfireiface $Lang::tr{'fwdfw red'}";
2a81ab0d 2230 }else{
f1934a05 2231 print "$$hash{$key}[4]";
2a81ab0d 2232 }
15add1c8 2233 $tdcolor='';
a0fb1099 2234 #SOURCEPORT
2a81ab0d 2235 &getsrcport(\%$hash,$key);
2669161d 2236 #Is this a SNAT rule?
ac9e77e3 2237 if ($$hash{$key}[31] eq 'snat' && $$hash{$key}[28] eq 'ON'){
f1934a05
AM
2238 my $net=&get_name($$hash{$key}[29]);
2239 if ( ! $net){ $net=$$hash{$key}[29];}
2240 print"<br>->$net";
2669161d
AM
2241 if ($$hash{$key}[30] ne ''){
2242 print": $$hash{$key}[30]";
2243 }
2244 }
2a81ab0d
AM
2245 if ($$hash{$key}[17] eq 'ON'){
2246 $log="/images/on.gif";
2247 }else{
2248 $log="/images/off.gif";
2249 }
a0fb1099 2250 #LOGGING
2a81ab0d
AM
2251 print<<END;
2252 </td>
b88c8829 2253 <td align='left' width='25'><form method='post'><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 ;'/>
2a81ab0d
AM
2254 <input type='hidden' name='key' value='$key' />
2255 <input type='hidden' name='config' value='$config' />
2256 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw togglelog'}' />
b88c8829 2257 </form></td>
2a81ab0d 2258END
a0fb1099 2259 #TARGET
af768a7e 2260 &getcolor($$hash{$key}[5],$$hash{$key}[6],\%customhost);
2a81ab0d 2261 print<<END;
15add1c8 2262 <td align='center' width='160' $tdcolor>
2a81ab0d 2263END
2669161d 2264 #Is this a DNAT rule?
ac9e77e3 2265 if ($$hash{$key}[31] eq 'dnat' && $$hash{$key}[28] eq 'ON'){
a0fb1099 2266 print "Firewall ($$hash{$key}[29])";
a6edca5a 2267 if($$hash{$key}[30] ne ''){
98cee89f 2268 $$hash{$key}[30]=~ tr/|/,/;
a6edca5a 2269 print": $$hash{$key}[30]";
2669161d 2270 }
533a2da3 2271 print"<br>->";
2669161d 2272 }
d4cb89d2
AM
2273 if ($$hash{$key}[5] eq 'ipfire'){
2274 $ipfireiface='Interface';
2275 }
fc83b09d 2276 if ($$hash{$key}[5] eq 'std_net_tgt' || $$hash{$key}[5] eq 'ipfire' || $$hash{$key}[6] eq 'RED1' || $$hash{$key}[6] eq 'GREEN' || $$hash{$key}[6] eq 'ORANGE' || $$hash{$key}[6] eq 'BLUE' ){
cb4439f3 2277 if ($$hash{$key}[6] eq 'RED1'){
d4cb89d2 2278 print "$ipfireiface $Lang::tr{'red1'}";
b044bb05 2279 }elsif ($$hash{$key}[6] eq 'GREEN' || $$hash{$key}[6] eq 'ORANGE' || $$hash{$key}[6] eq 'BLUE'|| $$hash{$key}[6] eq 'ALL')
cb4439f3 2280 {
f1934a05 2281 print "$ipfireiface ".&get_name($$hash{$key}[6]);
05d4f131 2282 }else{
b044bb05 2283 print $$hash{$key}[6];
05d4f131 2284 }
4f3bd0ca
AM
2285 }elsif ($$hash{$key}[5] eq 'tgt_addr'){
2286 my ($split1,$split2) = split("/",$$hash{$key}[6]);
2287 if ($split2 eq '32'){
2288 print $split1;
2289 }else{
2290 print $$hash{$key}[6];
2291 }
2a81ab0d 2292 }else{
cb4439f3 2293 print "$$hash{$key}[6]";
2a81ab0d 2294 }
12a43202 2295 $tdcolor='';
a0fb1099 2296 #TARGETPORT
2a81ab0d 2297 &gettgtport(\%$hash,$key);
93a5f4a5 2298 print"</td>";
a0fb1099 2299 #RULE ACTIVE
2a81ab0d
AM
2300 if($$hash{$key}[2] eq 'ON'){
2301 $gif="/images/on.gif"
2302
2303 }else{
2304 $gif="/images/off.gif"
2a81ab0d
AM
2305 }
2306 print<<END;
b88c8829 2307 <td width='25'><form method='post'><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;' />
2a81ab0d
AM
2308 <input type='hidden' name='key' value='$key' />
2309 <input type='hidden' name='config' value='$config' />
2310 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw toggle'}' />
b88c8829
AM
2311 </form></td>
2312 <td width='25' ><form method='post'><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;' />
2a81ab0d
AM
2313 <input type='hidden' name='key' value='$key' />
2314 <input type='hidden' name='config' value='$config' />
2315 <input type='hidden' name='ACTION' value='editrule' />
b88c8829
AM
2316 </form></td>
2317 <td width='25'><form method='post'><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;' />
2a81ab0d
AM
2318 <input type='hidden' name='key' value='$key' />
2319 <input type='hidden' name='config' value='$config' />
2320 <input type='hidden' name='ACTION' value='copyrule' />
b88c8829
AM
2321 </form></td>
2322 <td width='25' ><form method='post'><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;' />
2a81ab0d
AM
2323 <input type='hidden' name='key' value='$key' />
2324 <input type='hidden' name='config' value='$config' />
2325 <input type='hidden' name='ACTION' value='deleterule' />
b88c8829 2326 </form></td>
2a81ab0d
AM
2327END
2328 if (exists $$hash{$key-1}){
2329 print<<END;
b88c8829 2330 <td width='25'><form method='post'><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;' />
2a81ab0d
AM
2331 <input type='hidden' name='key' value='$key' />
2332 <input type='hidden' name='config' value='$config' />
2333 <input type='hidden' name='ACTION' value='moveup' />
b88c8829 2334 </form></td>
2a81ab0d
AM
2335END
2336 }else{
15add1c8 2337 print"<td width='25'><input type='image' img src='/images/up.gif' style='visibility:hidden;'></td>";
2a81ab0d 2338 }
2a81ab0d
AM
2339 if (exists $$hash{$key+1}){
2340 print<<END;
b88c8829 2341 <td width='25' ><form method='post'><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;' />
2a81ab0d
AM
2342 <input type='hidden' name='key' value='$key' />
2343 <input type='hidden' name='config' value='$config' />
2344 <input type='hidden' name='ACTION' value='movedown' />
b88c8829 2345 </form></td></tr>
2a81ab0d
AM
2346END
2347 }else{
15add1c8 2348 print"<td width='25'><input type='image' img src='/images/down.gif' style='visibility:hidden;'></td></tr>";
2a81ab0d 2349 }
15add1c8 2350 #REMARK
3b2ad4a1 2351 if ($optionsfw{'SHOWREMARK'} eq 'on' && $$hash{$key}[16] ne ''){
6ca0b0f5 2352 print"<tr bgcolor='$color'>";
b88c8829 2353 print"<td>&nbsp;</td><td bgcolor='$rulecolor'></td><td colspan='10'>&nbsp; $$hash{$key}[16]</td></tr>";
3b2ad4a1
AM
2354 }
2355 if ($$hash{$key}[18] eq 'ON'){
533a2da3
AM
2356 #TIMEFRAME
2357 if ($$hash{$key}[18] eq 'ON'){
2358 my @days=();
2359 if($$hash{$key}[19] ne ''){push (@days,$Lang::tr{'fwdfw wd_mon'});}
2360 if($$hash{$key}[20] ne ''){push (@days,$Lang::tr{'fwdfw wd_tue'});}
2361 if($$hash{$key}[21] ne ''){push (@days,$Lang::tr{'fwdfw wd_wed'});}
2362 if($$hash{$key}[22] ne ''){push (@days,$Lang::tr{'fwdfw wd_thu'});}
2363 if($$hash{$key}[23] ne ''){push (@days,$Lang::tr{'fwdfw wd_fri'});}
2364 if($$hash{$key}[24] ne ''){push (@days,$Lang::tr{'fwdfw wd_sat'});}
2365 if($$hash{$key}[25] ne ''){push (@days,$Lang::tr{'fwdfw wd_sun'});}
2366 my $weekdays=join(",",@days);
2367 if (@days){
3b2ad4a1 2368 print"<tr bgcolor='$color'>";
b88c8829 2369 print"<td>&nbsp;</td><td bgcolor='$rulecolor'></td><td align='left' colspan='10'>&nbsp; $weekdays &nbsp; $$hash{$key}[26] - $$hash{$key}[27] </td></tr>";
533a2da3 2370 }
3b2ad4a1 2371 }
96502a5a 2372 }
533a2da3 2373 print"<tr bgcolor='FFFFFF'><td colspan='13' height='1'></td></tr>";
2a81ab0d 2374 }
a6485463
AM
2375 print"</table>";
2376 print "<table width='100%'rules='cols' border='1'>";
2af92cf5
AM
2377 my $col;
2378 if ($config eq '/var/ipfire/forward/config'){
2379 my $pol='fwdfw '.$fwdfwsettings{'POLICY'};
2380 if ($fwdfwsettings{'POLICY'} eq 'MODE1'){
2381 $col="bgcolor='darkred'";
2382 }else{
2383 $col="bgcolor='green'";
2384 }
7326051e 2385 &show_defaultrules($col,$pol);
2af92cf5
AM
2386 }elsif ($config eq '/var/ipfire/forward/outgoing'){
2387 my $pol='fwdfw '.$fwdfwsettings{'POLICY1'};
2388 if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){
2389 $col="bgcolor='darkred'";
2390 }else{
2391 $col="bgcolor='green'";
2392 }
7326051e 2393 print"<tr><td $col width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col><font color='#FFFFFF' align='center'>$Lang::tr{$pol}</font></td></tr>";
2af92cf5 2394 }else{
7326051e 2395 print"<tr><td bgcolor='darkred' width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td bgcolor='darkred' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw MODE1'}</font></td></tr>";
2af92cf5 2396 }
2a81ab0d 2397 print"</table>";
12a43202 2398 print "<hr>";
515863e2 2399 print "<br><br>";
2af92cf5 2400 &Header::closebox();
515863e2
AM
2401 }else{
2402 if ($optionsfw{'SHOWTABLES'} eq 'on'){
2403 print "<b>$title1</b><br>";
4d2e7a35 2404 print"<table width='100%' border='0' rules='none'><tr><td height='30' bgcolor=$color{'color22'} align='center'>$Lang::tr{'fwhost empty'}</td></tr></table>";
2af92cf5
AM
2405 my $col;
2406 if ($config eq '/var/ipfire/forward/config'){
2407 my $pol='fwdfw '.$fwdfwsettings{'POLICY'};
2408 if ($fwdfwsettings{'POLICY'} eq 'MODE1'){
2409 $col="bgcolor='darkred'";
2410 }else{
2411 $col="bgcolor='green'";
2412 }
a6485463 2413 &show_defaultrules($col,$pol);
2af92cf5 2414 }elsif ($config eq '/var/ipfire/forward/outgoing'){
4d2e7a35 2415 print "<table width='100%' rules='cols' border='1'>";
2af92cf5
AM
2416 my $pol='fwdfw '.$fwdfwsettings{'POLICY1'};
2417 if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){
2418 $col="bgcolor='darkred'";
2419 }else{
2420 $col="bgcolor='green'";
2421 }
7326051e 2422 print"<tr><td $col align='center' width='20%'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF'>$Lang::tr{$pol}</font></td></tr>";
2af92cf5 2423 }else{
7326051e 2424 print"<tr><td bgcolor='darkred' align='center' width='20%'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td align='center'>$Lang::tr{'fwdfw MODE1'}</font></td></tr>";
2af92cf5
AM
2425 }
2426 print"</table><br><br>";
515863e2 2427 }
2a81ab0d 2428 }
2a81ab0d 2429}
2a81ab0d
AM
2430&Header::closebigbox();
2431&Header::closepage();
a6485463
AM
2432
2433sub show_defaultrules
2434{
2435 my $col=shift;
2436 my $pol=shift;
2437 #STANDARD RULES (From WIKI)
7326051e
AM
2438 print"</table><br>";
2439 print "<table width='100%' rules='cols' border='1' >";
a6485463 2440 if ($col eq "bgcolor='green'"){
595a90f0
AM
2441 my $blue = "<font color=$Header::colourblue> $Lang::tr{'blue'}</font> ($Lang::tr{'fwdfw pol block'})" if (&Header::blue_used());
2442 my $orange = "<font color=$Header::colourorange> $Lang::tr{'orange'}</font> ($Lang::tr{'fwdfw pol block'})" if (&Header::orange_used());
2443 my $blue1 = "<font color=$Header::colourblue> $Lang::tr{'blue'}</font> ($Lang::tr{'fwdfw pol allow'})" if (&Header::blue_used());
2444 my $orange1 = "<font color=$Header::colourorange> $Lang::tr{'orange'}</font> ($Lang::tr{'fwdfw pol allow'})" if (&Header::orange_used());
2445 print"<tr><td align='center'><font color='#000000'>$Lang::tr{'green'}</td><td align='center'> <font color=$Header::colourred> $Lang::tr{'red'}</font> ($Lang::tr{'fwdfw pol allow'})</td>";
2446 print"<td align='center'>$orange1</td>" if (&Header::orange_used());
2447 print"<td align='center'>$blue1</td>" if (&Header::blue_used());
2448 print"</tr>";
2449 if (&Header::orange_used()){
2450 print"<tr><td align='center' width='20%'><font color='#000000'>$Lang::tr{'orange'}</td><td align='center'> <font color=$Header::colourred> $Lang::tr{'red'}</font> ($Lang::tr{'fwdfw pol allow'})</td><td align='center'><font color=$Header::colourgreen> $Lang::tr{'green'}</font> ($Lang::tr{'fwdfw pol block'})</td>";
2451 print"<td align='center'>$blue</td>" if (&Header::blue_used());
2452 print"</tr>";
2453 }
2454 if (&Header::blue_used()){
2455 print"<tr><td align='center'><font color='#000000'>$Lang::tr{'blue'}</td><td align='center'> <font color=$Header::colourred> $Lang::tr{'red'}</font> ($Lang::tr{'fwdfw pol allow'})</td>";
2456 print"<td align='center'>$orange</td>" if (&Header::orange_used());
2457 print"<td align='center'><font color=$Header::colourgreen> $Lang::tr{'green'}</font> ($Lang::tr{'fwdfw pol block'})</td>";
2458 print"</tr>";
2459 }
7326051e 2460 print"<tr><td $col align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'} </font></td><td $col colspan='3' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw pol allow'}</font></td></tr>";
a6485463 2461 }elsif($col eq "bgcolor='darkred'"){
7326051e 2462 print"<tr><td $col width='20%' align='center'><font color='#FFFFFF'>$Lang::tr{'fwdfw final_rule'}</td><td $col align='center'><font color='#FFFFFF'>$Lang::tr{$pol}</font></td></tr>";
a6485463
AM
2463 }
2464}