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