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