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