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