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