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