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