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