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