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