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