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