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