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