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