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