]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - html/cgi-bin/forwardfw.cgi
Forward Firewall: reordered Firewall Menu and changed header.pl to reflect the new...
[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 ####
8013bd0a 523sub addrule
2a81ab0d 524{
8013bd0a
AM
525 &error;
526 if (-f "${General::swroot}/forward/reread"){
527 print "<table border='0'><form method='post'><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-face: Comic Sans MS; color: red; font-weight: bold;'>$Lang::tr{'fwhost reread'}</td></tr></table></form><hr><br>";
2a81ab0d 528 }
8013bd0a
AM
529 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
530 print "<form method='post'>";
531 print "<table border='0'>";
532 print "<tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'></td>";
533 print"</tr></table></form><hr>";
534 &Header::closebox();
535 &viewtablerule;
2a81ab0d
AM
536}
537sub base
538{
2a81ab0d
AM
539 if ($fwdfwsettings{'POLICY'} eq 'MODE1'){ $selected{'POLICY'}{'MODE1'} = 'selected'; } else { $selected{'POLICY'}{'MODE1'} = ''; }
540 if ($fwdfwsettings{'POLICY'} eq 'MODE2'){ $selected{'POLICY'}{'MODE2'} = 'selected'; } else { $selected{'POLICY'}{'MODE2'} = ''; }
5d7faa45
AM
541 if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){ $selected{'POLICY1'}{'MODE1'} = 'selected'; } else { $selected{'POLICY1'}{'MODE1'} = ''; }
542 if ($fwdfwsettings{'POLICY1'} eq 'MODE2'){ $selected{'POLICY1'}{'MODE2'} = 'selected'; } else { $selected{'POLICY1'}{'MODE2'} = ''; }
2a81ab0d 543 &hint;
7bd9d462 544 &addrule;
12a43202 545 print "<br><br>";
2b9460ab 546 &Header::openbox('100%', 'center', $Lang::tr{'fwdfw pol title'});
2a81ab0d
AM
547print <<END;
548 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2b9460ab 549 <table width='100%' border='0'>
d9a4000b
AM
550 <tr><td colspan='3' style='font-weight:bold;color:red;' align='left'>FORWARD </td></tr>
551 <tr><td colspan='3' align='left'>$Lang::tr{'fwdfw pol text'}</td></tr>
2a81ab0d 552 <tr><td colspan='3'><hr /></td></tr>
8f1634ff 553 <tr><td width='15%' align='left'> <select name='POLICY' style="width: 100px">
2b9460ab
AM
554 <option value='MODE1' $selected{'POLICY'}{'MODE1'}>$Lang::tr{'fwdfw pol block'}</option>
555 <option value='MODE2' $selected{'POLICY'}{'MODE2'}>$Lang::tr{'fwdfw pol allow'}</option></select>
b324de14
AM
556 <input type='submit' name='ACTION' value=$Lang::tr{'save'} /></td><td width='45%' align='right'>
557
2a81ab0d 558END
e28356b9 559 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 560 print "</table></form>";
5d7faa45
AM
561 print"<br><br>";
562 print <<END;
563 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
564 <table width='100%' border='0'>
d9a4000b
AM
565 <tr><td colspan='3' style='font-weight:bold;color:red;' align='left'>OUTGOING </td></tr>
566 <tr><td colspan='3' align='left'>$Lang::tr{'fwdfw pol text1'}</td></tr>
5d7faa45
AM
567 <tr><td colspan='3'><hr /></td></tr>
568 <tr><td width='15%' align='left'> <select name='POLICY1' style="width: 100px">
569 <option value='MODE1' $selected{'POLICY1'}{'MODE1'}>$Lang::tr{'fwdfw pol block'}</option>
570 <option value='MODE2' $selected{'POLICY1'}{'MODE2'}>$Lang::tr{'fwdfw pol allow'}</option></select>
e28356b9 571 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td><td width='45%' align='right'>
b324de14 572
5d7faa45 573END
e28356b9 574 print "$Lang::tr{'outgoing firewall reset'}: <input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /><input type='hidden' name='poltype' value='outgoing' /></tr>";
5d7faa45 575 print "</table></form>";
2a81ab0d
AM
576 &Header::closebox();
577}
8013bd0a 578sub changerule
2a81ab0d 579{
8013bd0a
AM
580 my $oldchain=shift;
581 $fwdfwsettings{'updatefwrule'}='';
582 $fwdfwsettings{'config'}=$oldchain;
583 $fwdfwsettings{'nobase'}='on';
584 &deleterule;
585 &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
586 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
2a81ab0d
AM
587}
588sub checksource
589{
590 my ($ip,$subnet);
36196d0d 591
2a81ab0d
AM
592 #check ip-address if manual
593 if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){
594 #check if ip with subnet
595 if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?)$/) {
596 ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'});
597 $subnet = &General::iporsubtocidr($subnet);
b5269091 598 $fwdfwsettings{'isip'}='on';
2a81ab0d
AM
599 }
600 #check if only ip
601 if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
602 $ip=$fwdfwsettings{'src_addr'};
603 $subnet = '32';
b5269091 604 $fwdfwsettings{'isip'}='on';
2a81ab0d 605 }
36196d0d 606
b5269091
AM
607 if ($fwdfwsettings{'isip'} ne 'on'){
608 if (&General::validmac($fwdfwsettings{'src_addr'})){$fwdfwsettings{'ismac'}='on';}
609 }
610 if ($fwdfwsettings{'isip'} eq 'on'){
611 #check and form valid IP
612 $ip=&General::ip2dec($ip);
613 $ip=&General::dec2ip($ip);
614 #check if net or broadcast
615 my @tmp= split (/\./,$ip);
616 if (($tmp[3] eq "0") || ($tmp[3] eq "255"))
617 {
618 $errormessage=$Lang::tr{'fwhost err hostip'}."<br>";
619 }
620 $fwdfwsettings{'src_addr'}="$ip/$subnet";
36196d0d 621
b5269091
AM
622 if(!&General::validipandmask($fwdfwsettings{'src_addr'})){
623 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
624 }
625 }
626 if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){
2a81ab0d
AM
627 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
628 }
629 }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
630 $errormessage.=$Lang::tr{'fwdfw err nosrcip'};
631 return $errormessage;
632 }
62fc8511 633
2a81ab0d
AM
634 #check empty fields
635 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err nosrc'}."<br>";}
636 #check icmp source
637 if ($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ICMP'){
638 $fwdfwsettings{'SRC_PORT'}='';
639 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
640 foreach my $key (keys %icmptypes){
641 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){
642 $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]";
643 }
644 }
62fc8511
AM
645 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'GRE'){
646 $fwdfwsettings{'SRC_PORT'}='';
647 $fwdfwsettings{'ICMP_TYPES'}='';
648 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ESP'){
649 $fwdfwsettings{'SRC_PORT'}='';
650 $fwdfwsettings{'ICMP_TYPES'}='';
d1f01304
AM
651 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'AH'){
652 $fwdfwsettings{'SRC_PORT'}='';
653 $fwdfwsettings{'ICMP_TYPES'}='';
2a81ab0d
AM
654 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} ne 'ICMP'){
655 $fwdfwsettings{'ICMP_TYPES'}='';
656 }else{
657 $fwdfwsettings{'ICMP_TYPES'}='';
658 $fwdfwsettings{'SRC_PORT'}='';
659 $fwdfwsettings{'PROT'}='';
660 }
62fc8511 661
8f0b047b
AM
662 if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){
663 my @parts=split(",",$fwdfwsettings{'SRC_PORT'});
664 my @values=();
665 foreach (@parts){
666 chomp($_);
667 if ($_ =~ /^(\d+)\:(\d+)$/) {
668 my $check;
669 #change dashes with :
670 $_=~ tr/-/:/;
671 if ($_ eq "*") {
672 push(@values,"1:65535");
673 $check='on';
674 }
675 if ($_ =~ /^(\D)\:(\d+)$/) {
676 push(@values,"1:$2");
677 $check='on';
678 }
679 if ($_ =~ /^(\d+)\:(\D)$/) {
680 push(@values,"$1:65535");
681 $check='on'
682 }
683 $errormessage .= &General::validportrange($_, 'destination');
684 if(!$check){
685 push (@values,$_);
686 }
687 }else{
688 if (&General::validport($_)){
689 push (@values,$_);
690 }else{
691
692 }
693 }
2a81ab0d 694 }
8f0b047b
AM
695 $fwdfwsettings{'SRC_PORT'}=join("|",@values);
696 return $errormessage;
2a81ab0d 697 }
2a81ab0d
AM
698}
699sub checktarget
700{
701 my ($ip,$subnet);
62fc8511 702
2a81ab0d
AM
703 if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
704 #check if ip with subnet
705 if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?)$/) {
706 ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
707 $subnet = &General::iporsubtocidr($subnet);
708 }
709 #check if only ip
710 if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
711 $ip=$fwdfwsettings{'tgt_addr'};
712 $subnet='32';
713 }
714 #check and form valid IP
715 $ip=&General::ip2dec($ip);
716 $ip=&General::dec2ip($ip);
36196d0d 717
0918e516
AM
718 ##check if net or broadcast
719 #my @tmp= split (/\./,$ip);
720 #if ($tmp[3] eq "0" || ($tmp[3] eq "255"))
721 #{
722 #$errormessage=$Lang::tr{'fwhost err hostip'}."<br>";
723 #}
55674e0d 724 $fwdfwsettings{'tgt_addr'}="$ip/$subnet";
2a81ab0d
AM
725
726 if(!&General::validipandmask($fwdfwsettings{'tgt_addr'})){
727 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
728 }
62fc8511 729
2a81ab0d
AM
730 }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
731 $errormessage.=$Lang::tr{'fwdfw err notgtip'};
732 return $errormessage;
733 }
62fc8511 734
2a81ab0d
AM
735 #check empty fields
736 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err notgt'}."<br>";}
62fc8511 737
2a81ab0d
AM
738 #check tgt services
739 if ($fwdfwsettings{'USESRV'} eq 'ON'){
740 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
741 $fwdfwsettings{'TGT_PROT'}='';
742 $fwdfwsettings{'ICMP_TGT'}='';
743 }
744 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
745 $fwdfwsettings{'TGT_PROT'}='';
746 $fwdfwsettings{'ICMP_TGT'}='';
747 #check target service
748 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){
749 $errormessage.=$Lang::tr{'fwdfw err tgt_grp'};
750 }
751 }
752 if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
bcbf1b8e 753 if ($fwdfwsettings{'TGT_PROT'} eq 'TCP' || $fwdfwsettings{'TGT_PROT'} eq 'UDP'){
2a81ab0d 754 if ($fwdfwsettings{'TGT_PORT'} ne ''){
8f0b047b
AM
755 my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
756 my @values=();
757 foreach (@parts){
758 chomp($_);
759 if ($_ =~ /^(\d+)\:(\d+)$/) {
760 my $check;
761 #change dashes with :
762 $_=~ tr/-/:/;
763 if ($_ eq "*") {
764 push(@values,"1:65535");
765 $check='on';
766 }
767 if ($_ =~ /^(\D)\:(\d+)$/) {
768 push(@values,"1:$2");
769 $check='on';
770 }
771 if ($_ =~ /^(\d+)\:(\D)$/) {
772 push(@values,"$1:65535");
773 $check='on'
774 }
775 $errormessage .= &General::validportrange($_, 'destination');
776 if(!$check){
777 push (@values,$_);
778 }
779 }else{
780 if (&General::validport($_)){
781 push (@values,$_);
782 }else{
783
784 }
785 }
2a81ab0d 786 }
8f0b047b 787 $fwdfwsettings{'TGT_PORT'}=join("|",@values);
2a81ab0d 788 }
62fc8511 789 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'GRE'){
d1f01304 790 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
bcbf1b8e 791 $fwdfwsettings{'TGT_PORT'} = '';
62fc8511 792 $fwdfwsettings{'ICMP_TGT'} = '';
bcbf1b8e 793 }elsif($fwdfwsettings{'TGT_PROT'} eq 'ESP'){
d1f01304 794 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
bcbf1b8e 795 $fwdfwsettings{'TGT_PORT'} = '';
d1f01304 796 $fwdfwsettings{'ICMP_TGT'}='';
bcbf1b8e 797 }elsif($fwdfwsettings{'TGT_PROT'} eq 'AH'){
d1f01304 798 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
bcbf1b8e 799 $fwdfwsettings{'TGT_PORT'} = '';
62fc8511 800 $fwdfwsettings{'ICMP_TGT'}='';
2a81ab0d 801 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'ICMP'){
d1f01304 802 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
bcbf1b8e 803 $fwdfwsettings{'TGT_PORT'} = '';
2a81ab0d
AM
804 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
805 foreach my $key (keys %icmptypes){
806
807 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwdfwsettings{'ICMP_TGT'}){
2a81ab0d
AM
808 $fwdfwsettings{'ICMP_TGT'}=$icmptypes{$key}[0];
809 }
810 }
811 }
812 }
813 }
62fc8511 814
2a81ab0d
AM
815 #check targetport
816 if ($fwdfwsettings{'USESRV'} ne 'ON'){
817 $fwdfwsettings{'grp3'}='';
818 $fwdfwsettings{$fwdfwsettings{'grp3'}}='';
819 $fwdfwsettings{'TGT_PROT'}='';
820 $fwdfwsettings{'ICMP_TGT'}='';
821 }
2a81ab0d
AM
822 #check timeframe
823 if($fwdfwsettings{'TIME'} eq 'ON'){
824 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 ''){
825 $errormessage=$Lang::tr{'fwdfw err time'};
826 }
827 }
2a81ab0d
AM
828 return $errormessage;
829}
830sub checkrule
831{
832 #check valid remark
833 if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
834 $errormessage.=$Lang::tr{'fwdfw err remark'}."<br>";
835 }
836 #check if source and target identical
27f4a6b1 837 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL'){
2a81ab0d
AM
838 $errormessage.=$Lang::tr{'fwdfw err same'};
839 return $errormessage;
840 }
62fc8511 841
2a81ab0d
AM
842 #get source and targetip address if possible
843 my ($sip,$scidr,$tip,$tcidr);
844 ($sip,$scidr)=&get_ip("src","grp1");
845 ($tip,$tcidr)=&get_ip("tgt","grp2");
62fc8511 846
2a81ab0d
AM
847 #check same iprange in source and target
848 if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){
2a81ab0d
AM
849 my $networkip1=&General::getnetworkip($sip,$scidr);
850 my $networkip2=&General::getnetworkip($tip,$tcidr);
851 if ($scidr gt $tcidr){
210ee67b 852 if ( &General::IpInSubnet($networkip1,$tip,&General::iporsubtodec($tcidr))){
2a81ab0d
AM
853 $errormessage.=$Lang::tr{'fwdfw err samesub'};
854 }
8013bd0a
AM
855 }elsif($scidr eq $tcidr && $scidr eq '32'){
856 my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1);
857 my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2);
858 if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){
859 $hint=$Lang::tr{'fwdfw hint ip1'}."<br>";
860 $hint.=$Lang::tr{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>";
861 }
862 }else{
863 if ( &General::IpInSubnet($networkip2,$sip,&General::iporsubtodec($scidr)) ){
864 $errormessage.=$Lang::tr{'fwdfw err samesub'};
865 }
866 }
867 }
868
869 #check source and destination protocol if manual
870 if( $fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'USESRV'} eq 'ON'){
871 if($fwdfwsettings{'PROT'} ne $fwdfwsettings{'TGT_PROT'} && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
872 $errormessage.=$Lang::tr{'fwdfw err prot'};
873 }
874 #check source and destination protocol if source manual and dest servicegrp
875 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
876 &General::readhasharray("$configsrv", \%customservice);
877 foreach my $key (sort keys %customservice){
878 if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){
879 if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){
880 $errormessage.=$Lang::tr{'fwdfw err prot'};
881 last;
882 }
883 }
884 }
885 }
886 }
887}
888sub checkcounter
889{
890 my ($base1,$val1,$base2,$val2) = @_;
891
892 if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){
893 &dec_counter($confignet,\%customnetwork,$val1);
894 }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){
895 &dec_counter($confighost,\%customhost,$val1);
896 }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){
897 &dec_counter($configgrp,\%customgrp,$val1);
898 }elsif($base1 eq 'cust_srv'){
899 &dec_counter($configsrv,\%customservice,$val1);
900 }elsif($base1 eq 'cust_srvgrp'){
901 &dec_counter($configsrvgrp,\%customservicegrp,$val1);
902 }
903
904 if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){
905 &inc_counter($confignet,\%customnetwork,$val2);
906 }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){
907 &inc_counter($confighost,\%customhost,$val2);
908 }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){
909 &inc_counter($configgrp,\%customgrp,$val2);
910 }elsif($base2 eq 'cust_srv'){
911 &inc_counter($configsrv,\%customservice,$val2);
912 }elsif($base2 eq 'cust_srvgrp'){
913 &inc_counter($configsrvgrp,\%customservicegrp,$val2);
914 }
915}
916sub deleterule
917{
918 my %delhash=();
919 &General::readhasharray($fwdfwsettings{'config'}, \%delhash);
920 foreach my $key (sort {$a <=> $b} keys %delhash){
921 if ($key == $fwdfwsettings{'key'}){
922 #check hosts/net and groups
923 &checkcounter($delhash{$key}[3],$delhash{$key}[4],,);
924 &checkcounter($delhash{$key}[5],$delhash{$key}[6],,);
925 #check services and groups
926 if ($delhash{$key}[11] eq 'ON'){
927 &checkcounter($delhash{$key}[14],$delhash{$key}[15],,);
928 }
929 }
930 if ($key >= $fwdfwsettings{'key'}) {
931 my $next = $key + 1;
932 if (exists $delhash{$next}) {
933 foreach my $i (0 .. $#{$delhash{$next}}) {
934 $delhash{$key}[$i] = $delhash{$next}[$i];
935 }
936 }
937 }
938 }
939 # Remove the very last entry.
940 my $last_key = (sort {$a <=> $b} keys %delhash)[-1];
941 delete $delhash{$last_key};
942
943 &General::writehasharray($fwdfwsettings{'config'}, \%delhash);
944 &rules;
945
946 if($fwdfwsettings{'nobase'} ne 'on'){
947 &base;
948 }
949}
950sub disable_rule
951{
952 my $key1=shift;
953 &General::readhasharray("$configfwdfw", \%configfwdfw);
954 foreach my $key (sort keys %configfwdfw){
955 if ($key eq $key1 ){
956 if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';}
957 }
958 }
959 &General::writehasharray("$configfwdfw", \%configfwdfw);
960 &rules;
961}
962sub dec_counter
963{
964 my $config=shift;
965 my %hash=%{(shift)};
966 my $val=shift;
967 my $pos;
968 #$errormessage.="ALT:config: $config , verringert wird $val <br>";
969 &General::readhasharray($config, \%hash);
970 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
971 if($hash{$key}[0] eq $val){
972 $pos=$#{$hash{$key}};
973 $hash{$key}[$pos] = $hash{$key}[$pos]-1;
974 }
975 }
976 &General::writehasharray($config, \%hash);
977}
978sub error
979{
980 if ($errormessage) {
981 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
982 print "<class name='base'>$errormessage\n";
983 print "&nbsp;</class>\n";
984 &Header::closebox();
985 print"<hr>";
986 }
987}
988sub fillselect
989{
990 my %hash=%{(shift)};
991 my $val=shift;
992 my $key;
993 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
994 if($hash{$key}[0] eq $val){
995 print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>";
996 }else{
997 print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>";
998 }
999 }
1000}
1001sub gen_dd_block
1002{
1003 my $srctgt = shift;
1004 my $grp=shift;
1005 my $helper='';
1006 my $show='';
1007 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1008 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1009 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1010 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1011 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1012 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1013 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1014 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1015 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1016 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1017 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1018 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1019 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1020 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1021 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1022 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1023 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1024 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1025print<<END;
1026 <table width='100%' border='0'>
1027 <tr><td width='50%' valign='top'>
1028 <table width='100%' border='0'>
d9987841 1029 <tr><td width='1%'><input type='radio' name='$grp' value='std_net_$srctgt' $checked{$grp}{'std_net_'.$srctgt}></td><td>$Lang::tr{'fwhost stdnet'}</td><td align='right'><select name='std_net_$srctgt' style='min-width:185px;'>
8013bd0a
AM
1030END
1031 foreach my $network (sort keys %defaultNetworks)
1032 {
1033 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
1034 next if($defaultNetworks{$network}{'NAME'} eq "RED");
1035 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1036 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $defaultNetworks{$network}{'NAME'});
1037 print ">$network</option>";
1038 }
1039 print"</select></td></tr>";
1040 #custom networks
d9987841
AM
1041 if (! -z $confignet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1042 print"<tr><td><input type='radio' name='$grp' value='cust_net_$srctgt' $checked{$grp}{'cust_net_'.$srctgt}></td><td>$Lang::tr{'fwhost cust net'}</td><td align='right'><select name='cust_net_$srctgt' style='min-width:185px;'>";
8013bd0a
AM
1043 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{$grp}});
1044 print"</select></td>";
1045 }
1046 #custom hosts
d9987841
AM
1047 if (! -z $confighost || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1048 print"<tr><td><input type='radio' name='$grp' value='cust_host_$srctgt' $checked{$grp}{'cust_host_'.$srctgt}></td><td>$Lang::tr{'fwhost cust addr'}</td><td align='right'><select name='cust_host_$srctgt' style='min-width:185px;'>";
8013bd0a
AM
1049 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{$grp}});
1050 print"</select></td>";
1051 }
1052 #custom groups
d9987841
AM
1053 if (! -z $configgrp || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1054 print"<tr><td valign='top'><input type='radio' name='$grp' value='cust_grp_$srctgt' $checked{$grp}{'cust_grp_'.$srctgt}></td><td >$Lang::tr{'fwhost cust grp'}</td><td align='right'><select name='cust_grp_$srctgt' style='min-width:185px;'>";
8013bd0a
AM
1055 foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } keys %customgrp) {
1056 if($helper ne $customgrp{$key}[0]){
1057 print"<option ";
1058 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $customgrp{$key}[0]);
1059 print ">$customgrp{$key}[0]</option>";
1060 }
1061 $helper=$customgrp{$key}[0];
1062 }
1063 print"</select></td>";
1064 }
1065 #End left table. start right table (vpn)
1066 print"</tr></table></td><td valign='top'><table width='100%' border='0'><tr>";
1067 # CCD networks
d9987841
AM
1068 if( ! -z $configccdnet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1069 print"<td width='1%'><input type='radio' name='$grp' value='ovpn_net_$srctgt' $checked{$grp}{'ovpn_net_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_net_$srctgt' style='min-width:185px;'>";
8013bd0a
AM
1070 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{$grp}});
1071 print"</select></td></tr>";
1072 }
1073 #OVPN CCD Hosts
1074 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost){
d9987841
AM
1075 if ($ccdhost{$key}[33] ne '' ){
1076 print"<tr><td width='1%'><input type='radio' name='$grp' value='ovpn_host_$srctgt' $checked{$grp}{'ovpn_host_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_host_$srctgt' style='min-width:185px;'>" if ($show eq '');
8013bd0a
AM
1077 $show='1';
1078 print "<option value='$ccdhost{$key}[1]'";
1079 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1080 print ">$ccdhost{$key}[1]</option>";
1081 }
1082 }
d9987841
AM
1083 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1084 print"<tr><td width='1%'><input type='radio' name='$grp' value='ovpn_host_$srctgt' $checked{$grp}{'ovpn_host_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_host_$srctgt' style='min-width:185px;'></select></td></tr>" ;
1085 }
8013bd0a
AM
1086 if ($show eq '1'){$show='';print"</select></td></tr>";}
1087 #OVPN N2N
1088 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost){
1089 if ($ccdhost{$key}[3] eq 'net'){
d9987841
AM
1090 print"<tr><td width='1%'><input type='radio' name='$grp' value='ovpn_n2n_$srctgt' $checked{$grp}{'ovpn_n2n_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ovpn_n2n'}:</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_n2n_$srctgt' style='min-width:185px;'>" if ($show eq '');
1091 $show='1';
8013bd0a
AM
1092 print "<option value='$ccdhost{$key}[1]'";
1093 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1094 print ">$ccdhost{$key}[1]</option>";
1095 }
1096 }
d9987841
AM
1097 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1098 print"<tr><td width='1%'><input type='radio' name='$grp' value='ovpn_n2n_$srctgt' $checked{$grp}{'ovpn_n2n_'.$srctgt}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ovpn_n2n'}</td><td nowrap='nowrap' width='1%' align='right'><select name='ovpn_n2n_$srctgt' style='min-width:185px;'></select></td></tr>" ;
1099 }
8013bd0a
AM
1100 if ($show eq '1'){$show='';print"</select></td></tr>";}
1101 #IPsec netze
1102 foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
d9987841
AM
1103 if ($ipsecconf{$key}[3] eq 'net' || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1104 print"<tr><td valign='top'><input type='radio' name='$grp' value='ipsec_net_$srctgt' $checked{$grp}{'ipsec_net_'.$srctgt}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td align='right'><select name='ipsec_net_$srctgt' style='min-width:185px;'>" if ($show eq '');
8013bd0a
AM
1105 $show='1';
1106 print "<option ";
1107 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ipsecconf{$key}[1]);
1108 print ">$ipsecconf{$key}[1]</option>";
1109 }
1110 }
d9987841
AM
1111 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1112 print"<tr><td valign='top'><input type='radio' name='$grp' value='ipsec_net_$srctgt' $checked{$grp}{'ipsec_net_'.$srctgt}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td align='right'><select name='ipsec_net_$srctgt' style='min-width:185px;'><select></td></tr>";
1113 }
8013bd0a
AM
1114 if ($show eq '1'){$show='';print"</select></td></tr>";}
1115
1116 print"</tr></table>";
1117 print"</td></tr></table><br>";
1118}
1119sub get_ip
1120{
1121 my $val=shift;
1122 my $grp =shift;
1123 my $a;
1124 my $b;
1125 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1126 if ($fwdfwsettings{$grp} ne $Lang::tr{'fwhost any'}){
1127 if ($fwdfwsettings{$grp} eq $val.'_addr'){
1128 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
1129 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
1130 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
1131 $a=$netsettings{'GREEN_NETADDRESS'};
1132 $b=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'});
1133 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
1134 $a=$netsettings{'ORANGE_NETADDRESS'};
1135 $b=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'});
1136 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
1137 $a=$netsettings{'BLUE_NETADDRESS'};
1138 $b=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'});
1139 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
1140 &General::readhash("$configovpn",\%ovpnsettings);
1141 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
1142 $b=&General::iporsubtocidr($b);
1143 }
1144 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
1145 &General::readhasharray("$confignet", \%customnetwork);
1146 foreach my $key (keys %customnetwork){
1147 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1148 $a=$customnetwork{$key}[1];
1149 $b=&General::iporsubtocidr($customnetwork{$key}[2]);
1150 }
1151 }
1152 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
1153 &General::readhasharray("$confighost", \%customhost);
1154 foreach my $key (keys %customhost){
1155 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1156 if ($customhost{$key}[1] eq 'ip'){
1157 ($a,$b)=split (/\//,$customhost{$key}[2]);
1158 $b=&General::iporsubtocidr($b);
1159 }else{
1160 if ($grp eq 'grp2'){
1161 $errormessage=$Lang::tr{'fwdfw err tgt_mac'};
1162 }
1163 }
1164 }
1165 }
1166 }
1167 }
1168 return $a,$b;
1169}
1170sub get_name
1171{
1172 my $val=shift;
1173 &General::setup_default_networks(\%defaultNetworks);
1174 foreach my $network (sort keys %defaultNetworks)
1175 {
1176 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1177 }
1178}
1179sub getsrcport
1180{
1181 my %hash=%{(shift)};
1182 my $key=shift;
1183 if($hash{$key}[7] eq 'ON' && $hash{$key}[8] ne '' && $hash{$key}[10]){
1184 $hash{$key}[10]=~ s/\|/,/g;
1185 print": $hash{$key}[10]";
1186 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
1187 print": <br>$hash{$key}[9] ";
1188 }
1189}
1190sub gettgtport
1191{
1192 my %hash=%{(shift)};
1193 my $key=shift;
1194 my $service;
1195 my $prot;
1196 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1197 if($hash{$key}[14] eq 'cust_srv'){
1198 &General::readhasharray("$configsrv", \%customservice);
1199 foreach my $i (sort keys %customservice){
1200 if($customservice{$i}[0] eq $hash{$key}[15]){
1201 $service = $customservice{$i}[0];
1202 }
1203 }
1204 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
1205 $service=$hash{$key}[15];
1206 }elsif($hash{$key}[14] eq 'TGT_PORT'){
1207 $hash{$key}[15]=~ s/\|/,/g;
1208 $service=$hash{$key}[15];
1209 }
1210 if($service){
1211 print": $service";
1212 }
1213 }elsif($hash{$key}[11] eq 'ON' && $hash{$key}[12] eq 'ICMP'){
1214 print":<br>$hash{$key}[13]";
1215 }
1216}
1217sub get_serviceports
1218{
1219 my $type=shift;
1220 my $name=shift;
1221 &General::readhasharray("$configsrv", \%customservice);
1222 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1223 my $protocols;
1224 my $tcp;
1225 my $udp;
1226 if($type eq 'service'){
1227 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
1228 if ($customservice{$key}[0] eq $name){
1229 $protocols=$customservice{$key}[2];
1230 }
1231 }
1232 }elsif($type eq 'group'){
1233 foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){
1234 if ($customservicegrp{$key}[0] eq $name){
1235 foreach my $key1 (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
1236 if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
1237 if($customservice{$key1}[2] eq 'TCP'){$tcp='TCP';}else{$udp='UDP';}
1238 }
1239 }
1240 }
1241 }
1242 }
1243 if($tcp && $udp){$protocols="TCP,UDP";
1244 }elsif($tcp){$protocols.="TCP";
1245 }elsif($udp){$protocols.="UDP";}
1246 return $protocols;
1247}
1248sub getcolor
1249{
1250 my $nettype=shift;
1251 my $val=shift;
1252 my $hash=shift;
1253 if($optionsfw{'SHOWCOLORS'} eq 'on'){
1254 #VPN networks
1255 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'){
1256 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
1257 return;
1258 }
1259 if ($nettype eq 'ipsec_net_src' || $nettype eq 'ipsec_net_tgt'){
1260 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
1261 return;
1262 }
1263 #custom Hosts
1264 if ($nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1265 foreach my $key (sort keys %$hash){
1266 if ($$hash{$key}[0] eq $val){
1267 $val=$$hash{$key}[2];
1268 }
1269 }
1270 }
1271 #ALIASE
1272 foreach my $alias (sort keys %aliases)
1273 {
1274 if ($val eq $alias){
1275 $tdcolor="style='border: 2px solid red;'";
1276 return;
1277 }
1278 }
1279 #standard networks
1280 if ($val eq 'GREEN'){
1281 $tdcolor="style='border: 1px solid $Header::colourgreen;'";
1282 }elsif ($val eq 'ORANGE'){
1283 $tdcolor="style='border: 1px solid $Header::colourorange;'";
1284 }elsif ($val eq 'BLUE'){
1285 $tdcolor="style='border: 1px solid $Header::colourblue;'";
1286 }elsif ($val eq 'RED'){
1287 $tdcolor="style='border: 1px solid $Header::colourred;'";
1288 }elsif ($val eq 'IPFire' ){
1289 $tdcolor="style='border: 1px solid $Header::colourred;'";
1290 }elsif($val =~ /^(.*?)\/(.*?)$/){
1291 my ($sip,$scidr) = split ("/",$val);
1292 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1293 $tdcolor="style='border: 1px solid $Header::colourorange;'";
1294 }
1295 if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1296 $tdcolor="style='border: 1px solid $Header::colourgreen;'";
1297 }
1298 if ( &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
1299 $tdcolor="style='border: 1px solid $Header::colourblue;'";
2a81ab0d 1300 }
8013bd0a
AM
1301 }elsif ($val eq 'Default IP'){
1302 $tdcolor="style='border: 1px solid red;'";
1303 }else{
1304 $tdcolor='';
2a81ab0d
AM
1305 }
1306 }
8013bd0a
AM
1307}
1308sub hint
1309{
1310 if ($hint) {
1311 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1312 print "<class name='base'>$hint\n";
1313 print "&nbsp;</class>\n";
1314 &Header::closebox();
1315 print"<hr>";
2a81ab0d 1316 }
2a81ab0d 1317}
8013bd0a 1318sub inc_counter
2a81ab0d 1319{
8013bd0a
AM
1320 my $config=shift;
1321 my %hash=%{(shift)};
2a81ab0d 1322 my $val=shift;
8013bd0a
AM
1323 my $pos;
1324
1325 &General::readhasharray($config, \%hash);
1326 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
1327 if($hash{$key}[0] eq $val){
1328 $pos=$#{$hash{$key}};
1329 $hash{$key}[$pos] = $hash{$key}[$pos]+1;
2a81ab0d
AM
1330 }
1331 }
8013bd0a 1332 &General::writehasharray($config, \%hash);
2a81ab0d
AM
1333}
1334sub newrule
1335{
1336 &error;
1337 &General::setup_default_networks(\%defaultNetworks);
515863e2 1338 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
2a81ab0d
AM
1339 #read all configfiles
1340 &General::readhasharray("$configccdnet", \%ccdnet);
1341 &General::readhasharray("$confignet", \%customnetwork);
1342 &General::readhasharray("$configccdhost", \%ccdhost);
1343 &General::readhasharray("$confighost", \%customhost);
1344 &General::readhasharray("$configccdhost", \%ccdhost);
1345 &General::readhasharray("$configgrp", \%customgrp);
1346 &General::readhasharray("$configipsec", \%ipsecconf);
1347 &General::get_aliases(\%aliases);
2a81ab0d
AM
1348 my %checked=();
1349 my $helper;
2da264ec 1350 my $sum=0;
2a81ab0d
AM
1351 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
1352 my $config=$fwdfwsettings{'config'};
1353 my %hash=();
2a81ab0d
AM
1354 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1355 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1356 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1357 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1358 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1359 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1360 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1361 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1362 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1363 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1364 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1365 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1366 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1367 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1368 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1369 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1370 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1371 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
2a81ab0d
AM
1372 #check if update and get values
1373 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
1374 &General::readhasharray("$config", \%hash);
1375 foreach my $key (sort keys %hash){
2da264ec 1376 $sum++;
2a81ab0d 1377 if ($key eq $fwdfwsettings{'key'}){
70d38e50 1378 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
2a81ab0d
AM
1379 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
1380 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1381 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1382 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1383 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1384 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1385 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1386 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1387 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1388 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1389 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1390 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1391 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1392 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1393 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1394 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1395 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1396 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1397 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1398 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1399 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1400 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1401 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1402 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1403 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1404 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1405 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
2a81ab0d
AM
1406 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1407 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1408 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1409 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1410 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1411 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1412 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1413 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1414 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1415 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1416 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1417 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1418 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1419 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1420 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1421 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1422 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1423 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1424 }
1425 }
1426 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1427 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1428 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1429 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1430 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1431 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1432 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
02da9f7b 1433 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
515863e2
AM
1434 #check if manual ip (source) is orange network
1435 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1436 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1437 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1438 $fwdfwsettings{'oldorange'} ='on';
1439 }
1440 }
2a81ab0d
AM
1441 }else{
1442 $fwdfwsettings{'ACTIVE'}='ON';
1443 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
515863e2
AM
1444 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1445 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1446 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1447 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1448 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1449 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1450 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1451 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1452 #check if manual ip (source) is orange network
1453 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1454 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1455 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1456 $fwdfwsettings{'oldorange'} ='on';
1457 }
1458 }
2a81ab0d 1459 }
2a81ab0d 1460 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
62fc8511 1461
2a81ab0d
AM
1462print <<END;
1463 <form method="post">
1464 <table border='0'>
1465 <tr><td nowrap>$Lang::tr{'fwdfw rule action'}</td><td><select name='RULE_ACTION'>
1466END
1467 foreach ("ACCEPT","DROP","REJECT")
1468 {
cf576a12
AM
1469 if($fwdfwsettings{'updatefwrule'} eq 'on'){
1470 print"<option ";
1471 print "selected='selected'" if ($fwdfwsettings{'RULE_ACTION'} eq $_);
1472 print">$_</option>";
2a81ab0d 1473 }else{
cf576a12
AM
1474 if($fwdfwsettings{'POLICY'} eq 'MODE2'){
1475 $fwdfwsettings{'RULE_ACTION'} = 'DROP';
1476 }
1477
1478 if ($_ eq $fwdfwsettings{'RULE_ACTION'})
1479 {
1480 print"<option selected>$_</option>";
1481 }else{
1482 print"<option>$_</option>";
1483 }
2a81ab0d
AM
1484 }
1485 }
1486 print"</select></td></tr></table><hr>";
1487
2a81ab0d
AM
1488 &Header::closebox();
1489 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'});
2a81ab0d
AM
1490 #------SOURCE-------------------------------------------------------
1491 print<<END;
1492 <table width='100%' border='0'>
1493 <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>
1494 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr>
8013bd0a 1495 </table>
2a81ab0d 1496END
8013bd0a 1497 &gen_dd_block('src','grp1');
62fc8511 1498
2a81ab0d 1499 print<<END;
2a81ab0d 1500 <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
2a81ab0d
AM
1501 <table width='100%' border='0'>
1502 <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>
1503 <td width='15%' nowrap='nowrap'>$Lang::tr{'fwdfw man port'}</td><td><select name='PROT'>
1504END
d1f01304 1505 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
2a81ab0d
AM
1506 {
1507 if ($_ eq $fwdfwsettings{'PROT'})
1508 {
1509 print"<option selected>$_</option>";
1510 }else{
1511 print"<option>$_</option>";
1512 }
1513 }
8f0b047b 1514 $fwdfwsettings{'SRC_PORT'}=~ s/\|/,/g;
2a81ab0d 1515 print<<END;
8f0b047b 1516 </select></td><td align='right'><input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18' ></td></tr>
12a43202 1517 <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
1518END
1519 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1520 print"<option>All ICMP-Types</option>";
1521 foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) } keys %icmptypes){
1522 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1523 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1524 }else{
1525 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1526 }
1527 }
1528 print<<END;
5dd84c25 1529 </select></td></tr></table><br><hr>
2a81ab0d
AM
1530END
1531 &Header::closebox();
1532
1533 #---TARGET------------------------------------------------------
1534 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw target'});
1535 print<<END;
1536 <table width='100%' border='0'>
8013bd0a 1537 <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 align='right'><select name='ipfire' style='min-width:185px;'>
2a81ab0d
AM
1538END
1539 print "<option value='Default IP' $selected{'ipfire'}{'Default IP'}>Default IP</option>";
62fc8511 1540
2a81ab0d
AM
1541 foreach my $alias (sort keys %aliases)
1542 {
1543 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1544 }
2a81ab0d
AM
1545 print<<END;
1546 </td></tr>
8013bd0a 1547 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
2a81ab0d 1548END
8013bd0a 1549 &gen_dd_block('tgt','grp2');
2a81ab0d 1550 print<<END;
2a81ab0d
AM
1551 <b>$Lang::tr{'fwhost attention'}:</b><br>
1552 $Lang::tr{'fwhost macwarn'}<br><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; '></hr><br>
2a81ab0d
AM
1553 <table width='100%' border='0'>
1554 <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;' >
1555END
1556 &General::readhasharray("$configsrv", \%customservice);
62fc8511 1557 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
2a81ab0d
AM
1558 print"<option ";
1559 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1560 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1561 }
1562 print<<END;
1563 </select></td></tr>
12a43202 1564 <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
1565END
1566 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1567 my $helper;
62fc8511 1568 foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){
2a81ab0d
AM
1569 if ($helper ne $customservicegrp{$key}[0]){
1570 print"<option ";
1571 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1572 print">$customservicegrp{$key}[0]</option>";
1573 }
1574 $helper=$customservicegrp{$key}[0];
1575 }
1576 print<<END;
1577 </select></td></tr>
1578 <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'>
1579END
d1f01304 1580 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
2a81ab0d
AM
1581 {
1582 if ($_ eq $fwdfwsettings{'TGT_PROT'})
1583 {
1584 print"<option selected>$_</option>";
1585 }else{
1586 print"<option>$_</option>";
1587 }
1588 }
8f0b047b 1589 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
2a81ab0d 1590 print<<END;
8f0b047b 1591 </select></td><td align='right'><input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18' ></td></tr>
12a43202 1592 <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
1593END
1594 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1595 print"<option>All ICMP-Types</option>";
1596 foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) }keys %icmptypes){
1597 if($fwdfwsettings{'ICMP_TGT'} eq "$icmptypes{$key}[0]"){
1598 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1599 }else{
1600 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1601 }
1602 }
1603 print<<END;
1604 </select></td></tr>
5dd84c25 1605 </table><br><hr>
62fc8511 1606
2a81ab0d 1607END
5dd84c25 1608 &Header::closebox;
2a81ab0d
AM
1609 #---Activate/logging/remark-------------------------------------
1610 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw additional'});
1611 print<<END;
1612 <table width='100%' border='0'>
2da264ec
AM
1613 <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>
1614END
1615 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
1616 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
1617 for (my $count =1; $count <= $sum; $count++){
1618 print"<option value='$count' ";
1619 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
1620 print">$count</option>";
1621 }
1622 print"</select></td></tr>";
70d38e50
AM
1623 }else{
1624 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
2da264ec
AM
1625 }
1626
1627 print<<END;
1628 </table><table width='100%'>
2a81ab0d
AM
1629 <tr><td width='1%'><input type='checkbox' name='ACTIVE' value='ON' $checked{'ACTIVE'}{'ON'}></td><td>$Lang::tr{'fwdfw rule activate'}</td></tr>
1630 <tr><td width='1%'><input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'} ></td><td>$Lang::tr{'fwdfw log rule'}</td></tr>
5dd84c25 1631 </table><br><hr>
2a81ab0d
AM
1632END
1633 &Header::closebox();
1634 #---ADD TIMEFRAME-----------------------------------------------
1635 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw timeframe'});
1636 print<<END;
1637 <table width='70%' border='0'>
1638 <tr><td width='1%'><input type='checkbox' name='TIME' value='ON' $checked{'TIME'}{'ON'}></td><td colspan='4'>$Lang::tr{'fwdfw timeframe'}</td></tr>
1639 <tr><td colspan='7'>&nbsp</td></tr>
1640 <tr>
1641 <td align='left'>$Lang::tr{'time'}:</td>
1642 <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
1643 <td width='15%' align='left'>$Lang::tr{'advproxy from'}</td>
1644 <td width='15%' align='left'>$Lang::tr{'advproxy to'}</td>
1645 </tr>
1646 <tr>
1647 <td align='right'></td>
1648 <td width='30%' align='left'>
1649 <input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} />
1650 <input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} />
1651 <input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} />
1652 <input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} />
1653 <input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} />
1654 <input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} />
27f4a6b1 1655 <input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} />
2a81ab0d 1656 </td>
2a81ab0d
AM
1657 <td><select name='TIME_FROM'>
1658END
1659 for (my $i=0;$i<=23;$i++) {
1660 $i = sprintf("%02s",$i);
1661 for (my $j=0;$j<=45;$j+=15) {
1662 $j = sprintf("%02s",$j);
1663 my $time = $i.":".$j;
1664 print "\t\t\t\t\t<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
1665 }
1666 }
1667 print<<END;
1668 </select></td>
1669 <td><select name='TIME_TO'>
1670END
1671 for (my $i=0;$i<=23;$i++) {
1672 $i = sprintf("%02s",$i);
1673 for (my $j=0;$j<=45;$j+=15) {
1674 $j = sprintf("%02s",$j);
1675 my $time = $i.":".$j;
1676 print "\t\t\t\t\t<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
1677 }
1678 }
8013bd0a
AM
1679 print<<END;
1680 </select></td></tr>
1681 </table><br><hr>
1682END
1683 #---ACTION------------------------------------------------------
1684 if($fwdfwsettings{'updatefwrule'} ne 'on'){
1685 print<<END;
1686 <table border='0' width='100%'>
1687 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
1688 <input type='hidden' name='config' value='$config' >
1689 <input type='hidden' name='ACTION' value='saverule' >
1690 </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>
1691 </table></form>
1692END
1693 }else{
1694 print<<END;
1695 <table border='0' width='100%'>
1696 <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'}'>
1697 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
1698 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
1699 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
1700 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
1701 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
1702 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
1703 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
1704 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
1705 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
1706 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
1707 <input type='hidden' name='oldorange' value='$fwdfwsettings{'oldorange'}' />
1708 <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>
1709 </table></form>
1710END
1711 }
1712 &Header::closebox();
1713}
1714sub pos_up
1715{
1716 my %uphash=();
1717 my %tmp=();
1718 &General::readhasharray($fwdfwsettings{'config'}, \%uphash);
1719 foreach my $key (sort keys %uphash){
1720 if ($key eq $fwdfwsettings{'key'}) {
1721 my $last = $key -1;
1722 if (exists $uphash{$last}){
1723 #save rule last
1724 foreach my $y (0 .. $#{$uphash{$last}}) {
1725 $tmp{0}[$y] = $uphash{$last}[$y];
1726 }
1727 #copy active rule to last
1728 foreach my $i (0 .. $#{$uphash{$last}}) {
1729 $uphash{$last}[$i] = $uphash{$key}[$i];
1730 }
1731 #copy saved rule to actual position
1732 foreach my $x (0 .. $#{$tmp{0}}) {
1733 $uphash{$key}[$x] = $tmp{0}[$x];
1734 }
1735 }
1736 }
1737 }
1738 &General::writehasharray($fwdfwsettings{'config'}, \%uphash);
1739 &rules;
1740}
1741sub pos_down
1742{
1743 my %downhash=();
1744 my %tmp=();
1745 &General::readhasharray($fwdfwsettings{'config'}, \%downhash);
1746 foreach my $key (sort keys %downhash){
1747 if ($key eq $fwdfwsettings{'key'}) {
1748 my $next = $key + 1;
1749 if (exists $downhash{$next}){
1750 #save rule next
1751 foreach my $y (0 .. $#{$downhash{$next}}) {
1752 $tmp{0}[$y] = $downhash{$next}[$y];
1753 }
1754 #copy active rule to next
1755 foreach my $i (0 .. $#{$downhash{$next}}) {
1756 $downhash{$next}[$i] = $downhash{$key}[$i];
1757 }
1758 #copy saved rule to actual position
1759 foreach my $x (0 .. $#{$tmp{0}}) {
1760 $downhash{$key}[$x] = $tmp{0}[$x];
1761 }
1762 }
1763 }
1764 }
1765 &General::writehasharray($fwdfwsettings{'config'}, \%downhash);
1766 &rules;
1767}
1768sub rules
1769{
1770 if (!-f "${General::swroot}/forward/reread"){
1771 system("touch ${General::swroot}/forward/reread");
1772 system("touch ${General::swroot}/fwhosts/reread");
1773 }
1774}
1775sub reread_rules
1776{
1777 system("/usr/local/bin/forwardfwctrl");
1778 if ( -f "${General::swroot}/forward/reread"){
1779 system("rm ${General::swroot}/forward/reread");
1780 system("rm ${General::swroot}/fwhosts/reread");
1781 }
2a81ab0d
AM
1782}
1783sub saverule
1784{
2a81ab0d
AM
1785 my $hash=shift;
1786 my $config=shift;
1787 &General::readhasharray("$config", $hash);
1788 if (!$errormessage){
515863e2
AM
1789 #check if we change a DMZ to an outgoing
1790 if( ($fwdfwsettings{'oldgrp1b'} eq 'ORANGE' || $fwdfwsettings{'oldorange'} eq 'on') && $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1791 &changerule($configdmz);
d603d1de 1792 #print"1";
515863e2
AM
1793 }
1794 #check if we change a DMZ to an external access
1795 elsif( $fwdfwsettings{'oldgrp1b'} eq 'ORANGE' && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ORANGE' && $fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1796 &changerule($configdmz);
d603d1de 1797 #print"2";
515863e2
AM
1798 }
1799 #check if we change an external access rule to a outgoing
1800 elsif( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'oldgrp1b'} ne 'IPFire' && $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'oldgrp2a'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1801 &changerule($configinput);
d603d1de 1802 #print"3";
515863e2
AM
1803 }
1804 #check if we change an external access rule to a DMZ
1805 elsif( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' && $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'oldgrp2a'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1806 &changerule($configinput);
d603d1de 1807 #print"4";
515863e2
AM
1808 }
1809 #check if we change an outgoing rule to a external access
1810 if( $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'IPFire' && $fwdfwsettings{'oldgrp1b'} eq 'IPFire' && $fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{'oldgrp2a'} ne 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1811 &changerule($configoutgoing);
d603d1de 1812 #print"5";
515863e2
AM
1813 }
1814 #check if we change an outgoing rule to a DMZ
1815 if( ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' || $checkorange eq 'on') && $fwdfwsettings{'oldgrp1b'} eq 'IPFire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1816 &changerule($configoutgoing);
d603d1de 1817 #print"6";
515863e2 1818 }
d7127db8 1819 #check if we change an forward rule to an external access
515863e2 1820 elsif( $fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{'oldgrp2a'} ne 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
d7127db8 1821 &changerule($configfwdfw);
d603d1de 1822 #print"7";
515863e2
AM
1823 }
1824 #check if we change an forward rule to an DMZ
1825 if( ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' || $checkorange eq 'on') && ($fwdfwsettings{'oldgrp1b'} ne 'ORANGE' && $fwdfwsettings{'oldorange'} ne 'on') && $fwdfwsettings{'updatefwrule'} eq 'on'){
1826 &changerule($configfwdfw);
d603d1de 1827 #print"8";
d7127db8
AM
1828 }
1829 #check if we change an forward rule to an outgoing
515863e2 1830 elsif( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'oldgrp1b'} ne 'IPFire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
d7127db8 1831 &changerule($configfwdfw);
d603d1de 1832 #print"9";
d7127db8 1833 }
515863e2
AM
1834 #check if we change a DMZ to a forward
1835 elsif( ($fwdfwsettings{'oldgrp1b'} eq 'ORANGE' || $fwdfwsettings{'oldorange'} eq 'on') && ($fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ORANGE' && $checkorange ne 'on') && $fwdfwsettings{'updatefwrule'} eq 'on'){
1836 &changerule($configdmz);
d603d1de 1837 #print"10";
d7127db8 1838 }
515863e2
AM
1839 #check if we change an external access rule to a forward
1840 elsif( $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'oldgrp2a'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
d7127db8 1841 &changerule($configinput);
d603d1de 1842 #print"11";
d7127db8
AM
1843 }
1844 #check if we change an outgoing rule to a forward
515863e2 1845 elsif( $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'IPFire' && $fwdfwsettings{'oldgrp1b'} eq 'IPFire' && $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
d7127db8 1846 &changerule($configoutgoing);
d603d1de 1847 #print"12";
d7127db8 1848 }
2da264ec 1849 if ($fwdfwsettings{'updatefwrule'} ne 'on'){
2a81ab0d
AM
1850 my $key = &General::findhasharraykey ($hash);
1851 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1852 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1853 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1854 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1855 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1856 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1857 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1858 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1859 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1860 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1861 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1862 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1863 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1864 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1865 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1866 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1867 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1868 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1869 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1870 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1871 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1872 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1873 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1874 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1875 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1876 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1877 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1878 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
1879 &General::writehasharray("$config", $hash);
1880 }else{
e44fa079
AM
1881 foreach my $key (sort {$a <=> $b} keys %$hash){
1882 if($key eq $fwdfwsettings{'key'}){
1883 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1884 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1885 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1886 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1887 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1888 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1889 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1890 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1891 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1892 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1893 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1894 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1895 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1896 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1897 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1898 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1899 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1900 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1901 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1902 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1903 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1904 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1905 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1906 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1907 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1908 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1909 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1910 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
1911 last;
1912 }
1913 }
1914 }
1915 &General::writehasharray("$config", $hash);
0918e516 1916 if($fwdfwsettings{'oldrulenumber'} > $fwdfwsettings{'rulepos'}){
e44fa079
AM
1917 my %tmp=();
1918 my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'};
1919 for (my $z=0;$z<$val;$z++){
1920 foreach my $key (sort {$a <=> $b} keys %$hash){
1921 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
1922 my $last = $key -1;
1923 if (exists $$hash{$last}){
1924 #save rule last
1925 foreach my $y (0 .. $#{$$hash{$last}}) {
1926 $tmp{0}[$y] = $$hash{$last}[$y];
1927 }
1928 #copy active rule to last
1929 foreach my $i (0 .. $#{$$hash{$last}}) {
1930 $$hash{$last}[$i] = $$hash{$key}[$i];
1931 }
1932 #copy saved rule to actual position
1933 foreach my $x (0 .. $#{$tmp{0}}) {
1934 $$hash{$key}[$x] = $tmp{0}[$x];
2da264ec
AM
1935 }
1936 }
1937 }
1938 }
e44fa079
AM
1939 $fwdfwsettings{'oldrulenumber'}--;
1940 }
1941 &General::writehasharray("$config", $hash);
1942 &rules;
0918e516 1943 }elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
e44fa079
AM
1944 my %tmp=();
1945 my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
1946 for (my $z=0;$z<$val;$z++){
1947 foreach my $key (sort {$a <=> $b} keys %$hash){
1948 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
1949 my $next = $key + 1;
1950 if (exists $$hash{$next}){
1951 #save rule next
1952 foreach my $y (0 .. $#{$$hash{$next}}) {
1953 $tmp{0}[$y] = $$hash{$next}[$y];
1954 }
1955 #copy active rule to next
1956 foreach my $i (0 .. $#{$$hash{$next}}) {
1957 $$hash{$next}[$i] = $$hash{$key}[$i];
1958 }
1959 #copy saved rule to actual position
1960 foreach my $x (0 .. $#{$tmp{0}}) {
1961 $$hash{$key}[$x] = $tmp{0}[$x];
2da264ec
AM
1962 }
1963 }
1964 }
2a81ab0d 1965 }
e44fa079 1966 $fwdfwsettings{'oldrulenumber'}++;
2a81ab0d
AM
1967 }
1968 &General::writehasharray("$config", $hash);
e44fa079 1969 &rules;
2a81ab0d
AM
1970 }
1971 }
1972}
2a81ab0d
AM
1973sub validremark
1974{
1975 # Checks a hostname against RFC1035
1976 my $remark = $_[0];
1977
1978 # Each part should be at least two characters in length
1979 # but no more than 63 characters
d24a34cb 1980 if (length ($remark) < 1 || length ($remark) > 255) {
2a81ab0d
AM
1981 return 0;}
1982 # Only valid characters are a-z, A-Z, 0-9 and -
e3580608 1983 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
2a81ab0d
AM
1984 return 0;}
1985 # First character can only be a letter or a digit
1986 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
1987 return 0;}
1988 # Last character can only be a letter or a digit
e3580608 1989 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
2a81ab0d
AM
1990 return 0;}
1991 return 1;
1992}
2a81ab0d
AM
1993sub viewtablerule
1994{
15add1c8 1995 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
515863e2
AM
1996 &viewtablenew(\%configdmzfw,$configdmz,$Lang::tr{'fwdfw rules'},"DMZ" );
1997 &viewtablenew(\%configfwdfw,$configfwdfw,"","Forward" );
2a81ab0d 1998 &viewtablenew(\%configinputfw,$configinput,"",$Lang::tr{'external access'} );
c7043621 1999 &viewtablenew(\%configoutgoingfw,$configoutgoing,"","Outgoing" );
2a81ab0d
AM
2000}
2001sub viewtablenew
2002{
2003 my $hash=shift;
2004 my $config=shift;
2005 my $title=shift;
2006 my $title1=shift;
7bd9d462 2007 my $go='';
15add1c8 2008 &General::get_aliases(\%aliases);
af768a7e 2009 &General::readhasharray("$confighost", \%customhost);
7bd9d462 2010 &General::readhasharray("$config", $hash);
5d7faa45 2011 if( ! -z $config){
2a81ab0d
AM
2012 &Header::openbox('100%', 'left',$title);
2013 my $count=0;
2014 my ($gif,$log);
2015 my $ruletype;
2016 my $rulecolor;
2017 my $tooltip;
2018 my @tmpsrc=();
2019 my $coloryellow='';
2a81ab0d 2020 print"<b>$title1</b><br>";
5b375ca7 2021 print"<table width='100%' cellspacing='0' cellpadding='0'>";
562d24b8 2022 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 2023 foreach my $key (sort {$a <=> $b} keys %$hash){
12a43202 2024 $tdcolor='';
2a81ab0d
AM
2025 @tmpsrc=();
2026 #check if vpn hosts/nets have been deleted
2027 if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){
2028 push (@tmpsrc,$$hash{$key}[4]);
2029 }
2030 if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){
2031 push (@tmpsrc,$$hash{$key}[6]);
2032 }
2a81ab0d
AM
2033 foreach my $host (@tmpsrc){
2034 if($$hash{$key}[3] eq 'ipsec_net_src' || $$hash{$key}[5] eq 'ipsec_net_tgt'){
62fc8511 2035 if(&fwlib::get_ipsec_net_ip($host,11) eq ''){
2a81ab0d
AM
2036 $coloryellow='on';
2037 &disable_rule($key);
2038 $$hash{$key}[2]='';
2a81ab0d
AM
2039 }
2040 }elsif($$hash{$key}[3] eq 'ovpn_net_src' || $$hash{$key}[5] eq 'ovpn_net_tgt'){
2041 if(&fwlib::get_ovpn_net_ip($host,1) eq ''){
2042 $coloryellow='on';
2043 &disable_rule($key);
2044 $$hash{$key}[2]='';
2045 }
2046 }elsif($$hash{$key}[3] eq 'ovpn_n2n_src' || $$hash{$key}[5] eq 'ovpn_n2n_tgt'){
2047 if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){
2048 $coloryellow='on';
2049 &disable_rule($key);
2050 $$hash{$key}[2]='';
2051 }
2052 }elsif($$hash{$key}[3] eq 'ovpn_host_src' || $$hash{$key}[5] eq 'ovpn_host_tgt'){
2053 if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
2054 $coloryellow='on';
2055 &disable_rule($key);
2056 $$hash{$key}[2]='';
2057 }
2058 }
12a43202
AM
2059 #$$hash{$key}[3]='';
2060 #$$hash{$key}[5]='';
2a81ab0d 2061 }
2a81ab0d
AM
2062 $$hash{'ACTIVE'}=$$hash{$key}[2];
2063 $count++;
2a81ab0d
AM
2064 if($coloryellow eq 'on'){
2065 print"<tr bgcolor='$color{'color14'}' >";
2066 $coloryellow='';
2067 }elsif($coloryellow eq ''){
2068 if ($count % 2){
15add1c8 2069 $color="$color{'color22'}";
2a81ab0d
AM
2070 }
2071 else{
15add1c8 2072 $color="$color{'color20'}";
2a81ab0d
AM
2073 }
2074 }
15add1c8 2075 print"<tr bgcolor='$color' >";
2a81ab0d 2076 print<<END;
96502a5a 2077 <td align='right' width='15'><b>$key</b></td>
2a81ab0d
AM
2078END
2079 if ($$hash{$key}[0] eq 'ACCEPT'){
2080 $ruletype='A';
2081 $tooltip='ACCEPT';
2082 $rulecolor=$color{'color17'};
2083 }elsif($$hash{$key}[0] eq 'DROP'){
2084 $ruletype='D';
2085 $tooltip='DROP';
2086 $rulecolor=$color{'color25'};
2087 }elsif($$hash{$key}[0] eq 'REJECT'){
2088 $ruletype='R';
2089 $tooltip='REJECT';
2090 $rulecolor=$color{'color16'};
2091 }
15add1c8 2092 print"<td bgcolor='$rulecolor' align='center' width='20'><span title='$tooltip'><b>$ruletype</b></span></td>";
af768a7e 2093 &getcolor($$hash{$key}[3],$$hash{$key}[4],\%customhost);
15add1c8 2094 print"<td align='center' width='160' $tdcolor>";
2a81ab0d
AM
2095 if ($$hash{$key}[3] eq 'std_net_src'){
2096 print &get_name($$hash{$key}[4]);
2097 }else{
2098 print $$hash{$key}[4];
2099 }
15add1c8 2100 $tdcolor='';
2a81ab0d
AM
2101 &getsrcport(\%$hash,$key);
2102 if ($$hash{$key}[17] eq 'ON'){
2103 $log="/images/on.gif";
2104 }else{
2105 $log="/images/off.gif";
2106 }
2107 print<<END;
2108 </td>
2a81ab0d 2109 <form method='post'>
15add1c8 2110 <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
2111 <input type='hidden' name='key' value='$key' />
2112 <input type='hidden' name='config' value='$config' />
2113 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw togglelog'}' />
2114 </td></form>
2115END
af768a7e 2116 &getcolor($$hash{$key}[5],$$hash{$key}[6],\%customhost);
2a81ab0d 2117 print<<END;
15add1c8 2118 <td align='center' width='160' $tdcolor>
2a81ab0d
AM
2119END
2120 if ($$hash{$key}[5] eq 'std_net_tgt'){
2121 print &get_name($$hash{$key}[6]);
2122 }else{
2123 print $$hash{$key}[6];
2124 }
12a43202 2125 $tdcolor='';
2a81ab0d 2126 &gettgtport(\%$hash,$key);
93a5f4a5
AM
2127 print"</td>";
2128 #Get Protocol
2129 my $prot;
2130 if ($$hash{$key}[12]){ #target prot if manual
2131 $prot=$$hash{$key}[12];
2132 }elsif($$hash{$key}[8]){ #source prot if manual
2133 $prot=$$hash{$key}[8];
2134 }elsif($$hash{$key}[14] eq 'cust_srv'){
2135 $prot=&get_serviceports("service",$$hash{$key}[15]);
2136 }elsif($$hash{$key}[14] eq 'cust_srvgrp'){
2137 $prot=&get_serviceports("group",$$hash{$key}[15]);
2138 }else{
2139 $prot=$Lang::tr{'all'};
2140 }
2141 print"<td align='center'>$prot</td>";
15add1c8
AM
2142 if ($$hash{$key}[18] eq 'ON'){
2143 my @days=();
2144 if($$hash{$key}[19] ne ''){push (@days,$Lang::tr{'fwdfw wd_mon'});}
2145 if($$hash{$key}[20] ne ''){push (@days,$Lang::tr{'fwdfw wd_tue'});}
2146 if($$hash{$key}[21] ne ''){push (@days,$Lang::tr{'fwdfw wd_wed'});}
2147 if($$hash{$key}[22] ne ''){push (@days,$Lang::tr{'fwdfw wd_thu'});}
2148 if($$hash{$key}[23] ne ''){push (@days,$Lang::tr{'fwdfw wd_fri'});}
2149 if($$hash{$key}[24] ne ''){push (@days,$Lang::tr{'fwdfw wd_sat'});}
2150 if($$hash{$key}[25] ne ''){push (@days,$Lang::tr{'fwdfw wd_sun'});}
2151 my $weekdays=join(",",@days);
2152 if (@days){
2153 print"<td align='center' width='100'>$weekdays &nbsp $$hash{$key}[26] - $$hash{$key}[27]</td>";
2154 }
2155 }else{
562d24b8 2156 print"<td align='center'>24/7</td>";
15add1c8 2157 }
2a81ab0d
AM
2158 if($$hash{$key}[2] eq 'ON'){
2159 $gif="/images/on.gif"
2160
2161 }else{
2162 $gif="/images/off.gif"
2a81ab0d
AM
2163 }
2164 print<<END;
2165 <form method='post'>
15add1c8 2166 <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
2167 <input type='hidden' name='key' value='$key' />
2168 <input type='hidden' name='config' value='$config' />
2169 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw toggle'}' />
2170 </td></form>
2a81ab0d 2171 <form method='post'>
15add1c8 2172 <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
2173 <input type='hidden' name='key' value='$key' />
2174 <input type='hidden' name='config' value='$config' />
2175 <input type='hidden' name='ACTION' value='editrule' />
2176 </td></form></td>
2a81ab0d 2177 <form method='post'>
15add1c8 2178 <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
2179 <input type='hidden' name='key' value='$key' />
2180 <input type='hidden' name='config' value='$config' />
2181 <input type='hidden' name='ACTION' value='copyrule' />
2182 </td></form></td>
2a81ab0d 2183 <form method='post'>
15add1c8 2184 <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
2185 <input type='hidden' name='key' value='$key' />
2186 <input type='hidden' name='config' value='$config' />
2187 <input type='hidden' name='ACTION' value='deleterule' />
2188 </td></form></td>
2189END
2190 if (exists $$hash{$key-1}){
2191 print<<END;
2192 <form method='post'>
15add1c8 2193 <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
2194 <input type='hidden' name='key' value='$key' />
2195 <input type='hidden' name='config' value='$config' />
2196 <input type='hidden' name='ACTION' value='moveup' />
2197 </td></form></td>
2198END
2199 }else{
15add1c8 2200 print"<td width='25'><input type='image' img src='/images/up.gif' style='visibility:hidden;'></td>";
2a81ab0d 2201 }
2a81ab0d
AM
2202 if (exists $$hash{$key+1}){
2203 print<<END;
2204 <form method='post'>
15add1c8 2205 <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
2206 <input type='hidden' name='key' value='$key' />
2207 <input type='hidden' name='config' value='$config' />
2208 <input type='hidden' name='ACTION' value='movedown' />
2209 </td></form></td></tr>
2210END
2211 }else{
15add1c8 2212 print"<td width='25'><input type='image' img src='/images/down.gif' style='visibility:hidden;'></td></tr>";
2a81ab0d 2213 }
15add1c8 2214 #REMARK
96502a5a 2215 if ($optionsfw{'SHOWREMARK'} eq 'on'){
6ca0b0f5 2216 print"<tr bgcolor='$color'>";
25dd450c 2217 print"<td>&nbsp</td><td bgcolor='$rulecolor'></td><td colspan='11'>&nbsp $$hash{$key}[16]</td></tr>";
96502a5a 2218 }
5b375ca7 2219 print"<tr bgcolor='$color'><td height='1'></td><td bgcolor='$rulecolor'></td><td colspan='11'></td></tr>";
2a81ab0d
AM
2220 }
2221 print"</table>";
2222 &Header::closebox();
12a43202 2223 print "<hr>";
515863e2
AM
2224 print "<br><br>";
2225 }else{
2226 if ($optionsfw{'SHOWTABLES'} eq 'on'){
2227 print "<b>$title1</b><br>";
2228 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>";
2229 }
2a81ab0d 2230 }
2a81ab0d 2231}
8013bd0a
AM
2232
2233
2a81ab0d
AM
2234&Header::closebigbox();
2235&Header::closepage();