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