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