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