Forward Firewall: Some minor changes in Language file timeframe:->timeframe
[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{
345 &General::readhasharray("$configfwdfw", \%configfwdfw);
346 foreach my $key (sort keys %configfwdfw){
347 &checkcounter($configfwdfw{$key}[3],$configfwdfw{$key}[4],,);
348 &checkcounter($configfwdfw{$key}[5],$configfwdfw{$key}[6],,);
349 &checkcounter($configfwdfw{$key}[14],$configfwdfw{$key}[15],,);
350 }
351 &General::readhasharray("$configinput", \%configinputfw);
352 foreach my $key (sort keys %configinputfw){
353 &checkcounter($configinputfw{$key}[3],$configinputfw{$key}[4],,);
354 &checkcounter($configinputfw{$key}[5],$configinputfw{$key}[6],,);
355 &checkcounter($configinputfw{$key}[14],$configinputfw{$key}[15],,);
356 }
7bd9d462 357
2a81ab0d
AM
358 system("rm ${General::swroot}/forward/config");
359 system("rm ${General::swroot}/forward/input");
2a81ab0d
AM
360 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
361 unless (-e "${General::swroot}/forward/config") { system("touch ${General::swroot}/forward/config"); }
362 unless (-e "${General::swroot}/forward/input") { system("touch ${General::swroot}/forward/input"); }
5d7faa45 363 my $MODE1=$fwdfwsettings{'POLICY1'};
62fc8511 364 %fwdfwsettings = ();
7bd9d462 365 $fwdfwsettings{'POLICY'}='MODE2';
5d7faa45
AM
366 $fwdfwsettings{'POLICY1'}=$MODE1;
367 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
368 &reread_rules;
369
370}
371if ($fwdfwsettings{'ACTION'} eq 'resetoutgoing')
372{
373 &General::readhasharray("$configoutgoing", \%configoutgoingfw);
374 foreach my $key (sort keys %configoutgoingfw){
375 &checkcounter($configoutgoingfw{$key}[3],$configoutgoingfw{$key}[4],,);
376 &checkcounter($configoutgoingfw{$key}[5],$configoutgoingfw{$key}[6],,);
377 &checkcounter($configoutgoingfw{$key}[14],$configoutgoingfw{$key}[15],,);
378 }
379 system("rm ${General::swroot}/forward/outgoing");
380 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
381 unless (-e "${General::swroot}/forward/outgoing") { system("touch ${General::swroot}/forward/outgoing"); }
382 my $MODE=$fwdfwsettings{'POLICY'};
383 %fwdfwsettings = ();
384 $fwdfwsettings{'POLICY'}=$MODE;
385 $fwdfwsettings{'POLICY1'}='MODE2';
7bd9d462 386 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
2a81ab0d
AM
387 &reread_rules;
388
389}
390if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw newrule'})
391{
392 &newrule;
393}
394if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw toggle'})
395{
396 my %togglehash=();
397 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
398 foreach my $key (sort keys %togglehash){
399 if ($key eq $fwdfwsettings{'key'}){
400 if ($togglehash{$key}[2] eq 'ON'){$togglehash{$key}[2]='';}else{$togglehash{$key}[2]='ON';}
401 }
402 }
403 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
404 &rules;
405 &base;
406}
407if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw togglelog'})
408{
409 my %togglehash=();
410 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
411 foreach my $key (sort keys %togglehash){
412 if ($key eq $fwdfwsettings{'key'}){
413 if ($togglehash{$key}[17] eq 'ON'){$togglehash{$key}[17]='';}else{$togglehash{$key}[17]='ON';}
414 }
415 }
416 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
417 &rules;
418 &base;
419}
420if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
421{
422 &reread_rules;
423 &base;
424}
425if ($fwdfwsettings{'ACTION'} eq 'editrule')
426{
427 $fwdfwsettings{'updatefwrule'}='on';
428 &newrule;
429}
430if ($fwdfwsettings{'ACTION'} eq 'deleterule')
431{
432 &deleterule;
433}
434if ($fwdfwsettings{'ACTION'} eq 'moveup')
435{
436 &pos_up;
437 &base;
438}
439if ($fwdfwsettings{'ACTION'} eq 'movedown')
440{
441 &pos_down;
442 &base;
443}
444if ($fwdfwsettings{'ACTION'} eq 'copyrule')
445{
446 $fwdfwsettings{'copyfwrule'}='on';
447 #$fwdfwsettings{'updatefwrule'}='on';
448 &newrule;
449}
450if ($fwdfwsettings{'ACTION'} eq '')
451{
452 &base;
453}
454### Functions ####
c7043621
AM
455sub changerule
456{
457 my $oldchain=shift;
458 $fwdfwsettings{'updatefwrule'}='';
459 $fwdfwsettings{'config'}=$oldchain;
460 $fwdfwsettings{'nobase'}='on';
461 &deleterule;
462 &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
463 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
464}
2a81ab0d
AM
465sub pos_up
466{
467 my %uphash=();
468 my %tmp=();
469 &General::readhasharray($fwdfwsettings{'config'}, \%uphash);
470 foreach my $key (sort keys %uphash){
471 if ($key eq $fwdfwsettings{'key'}) {
472 my $last = $key -1;
473 if (exists $uphash{$last}){
474 #save rule last
475 foreach my $y (0 .. $#{$uphash{$last}}) {
476 $tmp{0}[$y] = $uphash{$last}[$y];
477 }
478 #copy active rule to last
479 foreach my $i (0 .. $#{$uphash{$last}}) {
480 $uphash{$last}[$i] = $uphash{$key}[$i];
481 }
482 #copy saved rule to actual position
483 foreach my $x (0 .. $#{$tmp{0}}) {
484 $uphash{$key}[$x] = $tmp{0}[$x];
485 }
486 }
487 }
488 }
489 &General::writehasharray($fwdfwsettings{'config'}, \%uphash);
490 &rules;
491}
492sub pos_down
493{
494 my %downhash=();
495 my %tmp=();
496 &General::readhasharray($fwdfwsettings{'config'}, \%downhash);
497 foreach my $key (sort keys %downhash){
498 if ($key eq $fwdfwsettings{'key'}) {
499 my $next = $key + 1;
500 if (exists $downhash{$next}){
501 #save rule next
502 foreach my $y (0 .. $#{$downhash{$next}}) {
503 $tmp{0}[$y] = $downhash{$next}[$y];
504 }
505 #copy active rule to next
506 foreach my $i (0 .. $#{$downhash{$next}}) {
507 $downhash{$next}[$i] = $downhash{$key}[$i];
508 }
509 #copy saved rule to actual position
510 foreach my $x (0 .. $#{$tmp{0}}) {
511 $downhash{$key}[$x] = $tmp{0}[$x];
512 }
513 }
514 }
515 }
516 &General::writehasharray($fwdfwsettings{'config'}, \%downhash);
517 &rules;
518}
519sub checkcounter
520{
521 my ($base1,$val1,$base2,$val2) = @_;
522
523 if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){
524 &dec_counter($confignet,\%customnetwork,$val1);
525 }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){
526 &dec_counter($confighost,\%customhost,$val1);
527 }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){
528 &dec_counter($configgrp,\%customgrp,$val1);
529 }elsif($base1 eq 'cust_srv'){
530 &dec_counter($configsrv,\%customservice,$val1);
531 }elsif($base1 eq 'cust_srvgrp'){
532 &dec_counter($configsrvgrp,\%customservicegrp,$val1);
533 }
62fc8511 534
2a81ab0d
AM
535 if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){
536 &inc_counter($confignet,\%customnetwork,$val2);
537 }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){
538 &inc_counter($confighost,\%customhost,$val2);
539 }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){
540 &inc_counter($configgrp,\%customgrp,$val2);
541 }elsif($base2 eq 'cust_srv'){
542 &inc_counter($configsrv,\%customservice,$val2);
543 }elsif($base2 eq 'cust_srvgrp'){
544 &inc_counter($configsrvgrp,\%customservicegrp,$val2);
545 }
546}
547sub inc_counter
548{
549 my $config=shift;
550 my %hash=%{(shift)};
551 my $val=shift;
552 my $pos;
62fc8511 553
2a81ab0d
AM
554 &General::readhasharray($config, \%hash);
555 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
556 if($hash{$key}[0] eq $val){
557 $pos=$#{$hash{$key}};
558 $hash{$key}[$pos] = $hash{$key}[$pos]+1;
2a81ab0d
AM
559 }
560 }
561 &General::writehasharray($config, \%hash);
562}
563sub dec_counter
564{
565 my $config=shift;
566 my %hash=%{(shift)};
567 my $val=shift;
568 my $pos;
569 #$errormessage.="ALT:config: $config , verringert wird $val <br>";
570 &General::readhasharray($config, \%hash);
571 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
572 if($hash{$key}[0] eq $val){
573 $pos=$#{$hash{$key}};
574 $hash{$key}[$pos] = $hash{$key}[$pos]-1;
2a81ab0d
AM
575 }
576 }
577 &General::writehasharray($config, \%hash);
578}
579sub base
580{
2a81ab0d
AM
581 if ($fwdfwsettings{'POLICY'} eq 'MODE1'){ $selected{'POLICY'}{'MODE1'} = 'selected'; } else { $selected{'POLICY'}{'MODE1'} = ''; }
582 if ($fwdfwsettings{'POLICY'} eq 'MODE2'){ $selected{'POLICY'}{'MODE2'} = 'selected'; } else { $selected{'POLICY'}{'MODE2'} = ''; }
5d7faa45
AM
583 if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){ $selected{'POLICY1'}{'MODE1'} = 'selected'; } else { $selected{'POLICY1'}{'MODE1'} = ''; }
584 if ($fwdfwsettings{'POLICY1'} eq 'MODE2'){ $selected{'POLICY1'}{'MODE2'} = 'selected'; } else { $selected{'POLICY1'}{'MODE2'} = ''; }
2a81ab0d 585 &hint;
7bd9d462 586 &addrule;
12a43202 587 print "<br><br>";
2b9460ab 588 &Header::openbox('100%', 'center', $Lang::tr{'fwdfw pol title'});
2a81ab0d
AM
589print <<END;
590 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2b9460ab 591 <table width='100%' border='0'>
5d7faa45 592 <tr><td colspan='3' style='font-weight:bold;color:red;'>FORWARD </td></tr>
2b9460ab 593 <tr><td colspan='3'>$Lang::tr{'fwdfw pol text'}</td></tr>
2a81ab0d 594 <tr><td colspan='3'><hr /></td></tr>
8f1634ff 595 <tr><td width='15%' align='left'> <select name='POLICY' style="width: 100px">
2b9460ab
AM
596 <option value='MODE1' $selected{'POLICY'}{'MODE1'}>$Lang::tr{'fwdfw pol block'}</option>
597 <option value='MODE2' $selected{'POLICY'}{'MODE2'}>$Lang::tr{'fwdfw pol allow'}</option></select>
b324de14
AM
598 <input type='submit' name='ACTION' value=$Lang::tr{'save'} /></td><td width='45%' align='right'>
599
2a81ab0d 600END
b324de14 601 print "$Lang::tr{'outgoing firewall reset'}: <input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /></td></tr>";
36196d0d 602 print "</table></form>";
5d7faa45
AM
603 print"<br><br>";
604 print <<END;
605 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
606 <table width='100%' border='0'>
607 <tr><td colspan='3' style='font-weight:bold;color:red;'>OUTGOING </td></tr>
608 <tr><td colspan='3'>$Lang::tr{'fwdfw pol text1'}</td></tr>
609 <tr><td colspan='3'><hr /></td></tr>
610 <tr><td width='15%' align='left'> <select name='POLICY1' style="width: 100px">
611 <option value='MODE1' $selected{'POLICY1'}{'MODE1'}>$Lang::tr{'fwdfw pol block'}</option>
612 <option value='MODE2' $selected{'POLICY1'}{'MODE2'}>$Lang::tr{'fwdfw pol allow'}</option></select>
12a43202 613 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td><td width='45%' align='right'></form><form method='post' >
b324de14 614
5d7faa45 615END
12a43202 616 print "$Lang::tr{'outgoing firewall reset'}: <input type='submit' value='$Lang::tr{'reset'}' /><input type='hidden' name='ACTION' value='resetoutgoing' /></tr>";
5d7faa45 617 print "</table></form>";
2a81ab0d
AM
618 &Header::closebox();
619}
620sub addrule
621{
622 &error;
7bf83f9d
AM
623 if (-f "${General::swroot}/forward/reread"){
624 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>";
625 }
2a81ab0d 626 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
2a81ab0d
AM
627 print "<form method='post'>";
628 print "<table border='0'>";
629 print "<tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'></td>";
7bf83f9d 630 print"</tr></table></form><hr>";
2a81ab0d
AM
631 &Header::closebox();
632 &viewtablerule;
2a81ab0d
AM
633}
634sub deleterule
635{
636 my %delhash=();
637 &General::readhasharray($fwdfwsettings{'config'}, \%delhash);
2da264ec 638 foreach my $key (sort {$a <=> $b} keys %delhash){
992394d5 639 if ($key == $fwdfwsettings{'key'}){
2a81ab0d
AM
640 #check hosts/net and groups
641 &checkcounter($delhash{$key}[3],$delhash{$key}[4],,);
642 &checkcounter($delhash{$key}[5],$delhash{$key}[6],,);
643 #check services and groups
644 if ($delhash{$key}[11] eq 'ON'){
645 &checkcounter($delhash{$key}[14],$delhash{$key}[15],,);
646 }
647 }
992394d5 648 if ($key >= $fwdfwsettings{'key'}) {
2a81ab0d
AM
649 my $next = $key + 1;
650 if (exists $delhash{$next}) {
e5345541 651 foreach my $i (0 .. $#{$delhash{$next}}) {
2a81ab0d
AM
652 $delhash{$key}[$i] = $delhash{$next}[$i];
653 }
654 }
655 }
656 }
657 # Remove the very last entry.
275a92e8 658 my $last_key = (sort {$a <=> $b} keys %delhash)[-1];
2a81ab0d
AM
659 delete $delhash{$last_key};
660
661 &General::writehasharray($fwdfwsettings{'config'}, \%delhash);
662 &rules;
62fc8511 663
2a81ab0d
AM
664 if($fwdfwsettings{'nobase'} ne 'on'){
665 &base;
666 }
667}
668sub disable_rule
669{
670 my $key1=shift;
671 &General::readhasharray("$configfwdfw", \%configfwdfw);
672 foreach my $key (sort keys %configfwdfw){
673 if ($key eq $key1 ){
674 if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';}
675 }
676 }
677 &General::writehasharray("$configfwdfw", \%configfwdfw);
678 &rules;
2a81ab0d
AM
679}
680sub checksource
681{
682 my ($ip,$subnet);
36196d0d 683
2a81ab0d
AM
684 #check ip-address if manual
685 if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){
686 #check if ip with subnet
687 if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?)$/) {
688 ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'});
689 $subnet = &General::iporsubtocidr($subnet);
b5269091 690 $fwdfwsettings{'isip'}='on';
2a81ab0d
AM
691 }
692 #check if only ip
693 if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
694 $ip=$fwdfwsettings{'src_addr'};
695 $subnet = '32';
b5269091 696 $fwdfwsettings{'isip'}='on';
2a81ab0d 697 }
36196d0d 698
b5269091
AM
699 if ($fwdfwsettings{'isip'} ne 'on'){
700 if (&General::validmac($fwdfwsettings{'src_addr'})){$fwdfwsettings{'ismac'}='on';}
701 }
702 if ($fwdfwsettings{'isip'} eq 'on'){
703 #check and form valid IP
704 $ip=&General::ip2dec($ip);
705 $ip=&General::dec2ip($ip);
706 #check if net or broadcast
707 my @tmp= split (/\./,$ip);
708 if (($tmp[3] eq "0") || ($tmp[3] eq "255"))
709 {
710 $errormessage=$Lang::tr{'fwhost err hostip'}."<br>";
711 }
712 $fwdfwsettings{'src_addr'}="$ip/$subnet";
36196d0d 713
b5269091
AM
714 if(!&General::validipandmask($fwdfwsettings{'src_addr'})){
715 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
716 }
717 }
718 if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){
2a81ab0d
AM
719 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
720 }
721 }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
722 $errormessage.=$Lang::tr{'fwdfw err nosrcip'};
723 return $errormessage;
724 }
62fc8511 725
2a81ab0d
AM
726 #check empty fields
727 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err nosrc'}."<br>";}
728 #check icmp source
729 if ($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ICMP'){
730 $fwdfwsettings{'SRC_PORT'}='';
731 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
732 foreach my $key (keys %icmptypes){
733 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){
734 $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]";
735 }
736 }
62fc8511
AM
737 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'GRE'){
738 $fwdfwsettings{'SRC_PORT'}='';
739 $fwdfwsettings{'ICMP_TYPES'}='';
740 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ESP'){
741 $fwdfwsettings{'SRC_PORT'}='';
742 $fwdfwsettings{'ICMP_TYPES'}='';
d1f01304
AM
743 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'AH'){
744 $fwdfwsettings{'SRC_PORT'}='';
745 $fwdfwsettings{'ICMP_TYPES'}='';
2a81ab0d
AM
746 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} ne 'ICMP'){
747 $fwdfwsettings{'ICMP_TYPES'}='';
748 }else{
749 $fwdfwsettings{'ICMP_TYPES'}='';
750 $fwdfwsettings{'SRC_PORT'}='';
751 $fwdfwsettings{'PROT'}='';
752 }
62fc8511 753
8f0b047b
AM
754 if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){
755 my @parts=split(",",$fwdfwsettings{'SRC_PORT'});
756 my @values=();
757 foreach (@parts){
758 chomp($_);
759 if ($_ =~ /^(\d+)\:(\d+)$/) {
760 my $check;
761 #change dashes with :
762 $_=~ tr/-/:/;
763 if ($_ eq "*") {
764 push(@values,"1:65535");
765 $check='on';
766 }
767 if ($_ =~ /^(\D)\:(\d+)$/) {
768 push(@values,"1:$2");
769 $check='on';
770 }
771 if ($_ =~ /^(\d+)\:(\D)$/) {
772 push(@values,"$1:65535");
773 $check='on'
774 }
775 $errormessage .= &General::validportrange($_, 'destination');
776 if(!$check){
777 push (@values,$_);
778 }
779 }else{
780 if (&General::validport($_)){
781 push (@values,$_);
782 }else{
783
784 }
785 }
2a81ab0d 786 }
8f0b047b
AM
787 $fwdfwsettings{'SRC_PORT'}=join("|",@values);
788 return $errormessage;
2a81ab0d 789 }
2a81ab0d
AM
790}
791sub checktarget
792{
793 my ($ip,$subnet);
62fc8511 794
2a81ab0d
AM
795 if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
796 #check if ip with subnet
797 if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?)$/) {
798 ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
799 $subnet = &General::iporsubtocidr($subnet);
800 }
801 #check if only ip
802 if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
803 $ip=$fwdfwsettings{'tgt_addr'};
804 $subnet='32';
805 }
806 #check and form valid IP
807 $ip=&General::ip2dec($ip);
808 $ip=&General::dec2ip($ip);
36196d0d 809
0918e516
AM
810 ##check if net or broadcast
811 #my @tmp= split (/\./,$ip);
812 #if ($tmp[3] eq "0" || ($tmp[3] eq "255"))
813 #{
814 #$errormessage=$Lang::tr{'fwhost err hostip'}."<br>";
815 #}
55674e0d 816 $fwdfwsettings{'tgt_addr'}="$ip/$subnet";
2a81ab0d
AM
817
818 if(!&General::validipandmask($fwdfwsettings{'tgt_addr'})){
819 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
820 }
62fc8511 821
2a81ab0d
AM
822 }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
823 $errormessage.=$Lang::tr{'fwdfw err notgtip'};
824 return $errormessage;
825 }
62fc8511 826
2a81ab0d
AM
827 #check empty fields
828 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err notgt'}."<br>";}
62fc8511 829
2a81ab0d
AM
830 #check tgt services
831 if ($fwdfwsettings{'USESRV'} eq 'ON'){
832 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
833 $fwdfwsettings{'TGT_PROT'}='';
834 $fwdfwsettings{'ICMP_TGT'}='';
835 }
836 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
837 $fwdfwsettings{'TGT_PROT'}='';
838 $fwdfwsettings{'ICMP_TGT'}='';
839 #check target service
840 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){
841 $errormessage.=$Lang::tr{'fwdfw err tgt_grp'};
842 }
843 }
844 if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
bcbf1b8e 845 if ($fwdfwsettings{'TGT_PROT'} eq 'TCP' || $fwdfwsettings{'TGT_PROT'} eq 'UDP'){
2a81ab0d 846 if ($fwdfwsettings{'TGT_PORT'} ne ''){
8f0b047b
AM
847 my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
848 my @values=();
849 foreach (@parts){
850 chomp($_);
851 if ($_ =~ /^(\d+)\:(\d+)$/) {
852 my $check;
853 #change dashes with :
854 $_=~ tr/-/:/;
855 if ($_ eq "*") {
856 push(@values,"1:65535");
857 $check='on';
858 }
859 if ($_ =~ /^(\D)\:(\d+)$/) {
860 push(@values,"1:$2");
861 $check='on';
862 }
863 if ($_ =~ /^(\d+)\:(\D)$/) {
864 push(@values,"$1:65535");
865 $check='on'
866 }
867 $errormessage .= &General::validportrange($_, 'destination');
868 if(!$check){
869 push (@values,$_);
870 }
871 }else{
872 if (&General::validport($_)){
873 push (@values,$_);
874 }else{
875
876 }
877 }
2a81ab0d 878 }
8f0b047b 879 $fwdfwsettings{'TGT_PORT'}=join("|",@values);
2a81ab0d 880 }
62fc8511 881 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'GRE'){
d1f01304 882 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
bcbf1b8e 883 $fwdfwsettings{'TGT_PORT'} = '';
62fc8511 884 $fwdfwsettings{'ICMP_TGT'} = '';
bcbf1b8e 885 }elsif($fwdfwsettings{'TGT_PROT'} eq 'ESP'){
d1f01304 886 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
bcbf1b8e 887 $fwdfwsettings{'TGT_PORT'} = '';
d1f01304 888 $fwdfwsettings{'ICMP_TGT'}='';
bcbf1b8e 889 }elsif($fwdfwsettings{'TGT_PROT'} eq 'AH'){
d1f01304 890 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
bcbf1b8e 891 $fwdfwsettings{'TGT_PORT'} = '';
62fc8511 892 $fwdfwsettings{'ICMP_TGT'}='';
2a81ab0d 893 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'ICMP'){
d1f01304 894 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
bcbf1b8e 895 $fwdfwsettings{'TGT_PORT'} = '';
2a81ab0d
AM
896 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
897 foreach my $key (keys %icmptypes){
898
899 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwdfwsettings{'ICMP_TGT'}){
2a81ab0d
AM
900 $fwdfwsettings{'ICMP_TGT'}=$icmptypes{$key}[0];
901 }
902 }
903 }
904 }
905 }
62fc8511 906
2a81ab0d
AM
907 #check targetport
908 if ($fwdfwsettings{'USESRV'} ne 'ON'){
909 $fwdfwsettings{'grp3'}='';
910 $fwdfwsettings{$fwdfwsettings{'grp3'}}='';
911 $fwdfwsettings{'TGT_PROT'}='';
912 $fwdfwsettings{'ICMP_TGT'}='';
913 }
2a81ab0d
AM
914 #check timeframe
915 if($fwdfwsettings{'TIME'} eq 'ON'){
916 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 ''){
917 $errormessage=$Lang::tr{'fwdfw err time'};
918 }
919 }
2a81ab0d
AM
920 return $errormessage;
921}
922sub checkrule
923{
924 #check valid remark
925 if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
926 $errormessage.=$Lang::tr{'fwdfw err remark'}."<br>";
927 }
928 #check if source and target identical
27f4a6b1 929 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL'){
2a81ab0d
AM
930 $errormessage.=$Lang::tr{'fwdfw err same'};
931 return $errormessage;
932 }
62fc8511 933
2a81ab0d
AM
934 #get source and targetip address if possible
935 my ($sip,$scidr,$tip,$tcidr);
936 ($sip,$scidr)=&get_ip("src","grp1");
937 ($tip,$tcidr)=&get_ip("tgt","grp2");
62fc8511 938
2a81ab0d
AM
939 #check same iprange in source and target
940 if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){
2a81ab0d
AM
941 my $networkip1=&General::getnetworkip($sip,$scidr);
942 my $networkip2=&General::getnetworkip($tip,$tcidr);
943 if ($scidr gt $tcidr){
210ee67b 944 if ( &General::IpInSubnet($networkip1,$tip,&General::iporsubtodec($tcidr))){
2a81ab0d
AM
945 $errormessage.=$Lang::tr{'fwdfw err samesub'};
946 }
947 }elsif($scidr eq $tcidr && $scidr eq '32'){
62fc8511
AM
948 my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1);
949 my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2);
2a81ab0d
AM
950 if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){
951 $hint=$Lang::tr{'fwdfw hint ip1'}."<br>";
55674e0d 952 $hint.=$Lang::tr{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>";
2a81ab0d 953 }
2a81ab0d 954 }else{
6adcf156 955 if ( &General::IpInSubnet($networkip2,$sip,&General::iporsubtodec($scidr)) ){
2a81ab0d
AM
956 $errormessage.=$Lang::tr{'fwdfw err samesub'};
957 }
958 }
959 }
62fc8511 960
2a81ab0d
AM
961 #check source and destination protocol if manual
962 if( $fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'USESRV'} eq 'ON'){
210ee67b 963 if($fwdfwsettings{'PROT'} ne $fwdfwsettings{'TGT_PROT'} && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
2a81ab0d
AM
964 $errormessage.=$Lang::tr{'fwdfw err prot'};
965 }
966 #check source and destination protocol if source manual and dest servicegrp
967 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
968 &General::readhasharray("$configsrv", \%customservice);
969 foreach my $key (sort keys %customservice){
970 if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){
971 if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){
972 $errormessage.=$Lang::tr{'fwdfw err prot'};
973 last;
974 }
975 }
976 }
977 }
978 }
2a81ab0d
AM
979}
980sub get_ip
981{
982 my $val=shift;
983 my $grp =shift;
984 my $a;
985 my $b;
986 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
987 if ($fwdfwsettings{$grp} ne $Lang::tr{'fwhost any'}){
988 if ($fwdfwsettings{$grp} eq $val.'_addr'){
989 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
990 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
991 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
992 $a=$netsettings{'GREEN_NETADDRESS'};
993 $b=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'});
994 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
995 $a=$netsettings{'ORANGE_NETADDRESS'};
996 $b=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'});
997 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
998 $a=$netsettings{'BLUE_NETADDRESS'};
999 $b=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'});
1000 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
1001 &General::readhash("$configovpn",\%ovpnsettings);
1002 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
1003 $b=&General::iporsubtocidr($b);
1004 }
1005 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
1006 &General::readhasharray("$confignet", \%customnetwork);
1007 foreach my $key (keys %customnetwork){
1008 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1009 $a=$customnetwork{$key}[1];
1010 $b=&General::iporsubtocidr($customnetwork{$key}[2]);
1011 }
1012 }
1013 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
1014 &General::readhasharray("$confighost", \%customhost);
1015 foreach my $key (keys %customhost){
1016 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1017 if ($customhost{$key}[1] eq 'ip'){
1018 ($a,$b)=split (/\//,$customhost{$key}[2]);
1019 $b=&General::iporsubtocidr($b);
1020 }else{
1021 if ($grp eq 'grp2'){
1022 $errormessage=$Lang::tr{'fwdfw err tgt_mac'};
1023 }
1024 }
1025 }
1026 }
1027 }
1028 }
2a81ab0d
AM
1029 return $a,$b;
1030}
1031sub newrule
1032{
1033 &error;
1034 &General::setup_default_networks(\%defaultNetworks);
1035 #read all configfiles
1036 &General::readhasharray("$configccdnet", \%ccdnet);
1037 &General::readhasharray("$confignet", \%customnetwork);
1038 &General::readhasharray("$configccdhost", \%ccdhost);
1039 &General::readhasharray("$confighost", \%customhost);
1040 &General::readhasharray("$configccdhost", \%ccdhost);
1041 &General::readhasharray("$configgrp", \%customgrp);
1042 &General::readhasharray("$configipsec", \%ipsecconf);
1043 &General::get_aliases(\%aliases);
2a81ab0d
AM
1044 my %checked=();
1045 my $helper;
2da264ec 1046 my $sum=0;
2a81ab0d
AM
1047 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
1048 my $config=$fwdfwsettings{'config'};
1049 my %hash=();
2a81ab0d
AM
1050 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1051 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1052 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1053 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1054 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1055 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1056 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1057 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1058 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1059 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1060 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1061 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1062 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1063 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1064 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1065 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1066 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1067 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
2a81ab0d
AM
1068 #check if update and get values
1069 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
1070 &General::readhasharray("$config", \%hash);
1071 foreach my $key (sort keys %hash){
2da264ec 1072 $sum++;
2a81ab0d 1073 if ($key eq $fwdfwsettings{'key'}){
70d38e50 1074 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
2a81ab0d
AM
1075 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
1076 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1077 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1078 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1079 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1080 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1081 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1082 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1083 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1084 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1085 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1086 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1087 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1088 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1089 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1090 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1091 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1092 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1093 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1094 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1095 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1096 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1097 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1098 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1099 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1100 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1101 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
2a81ab0d
AM
1102 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1103 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1104 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1105 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1106 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1107 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1108 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1109 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1110 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1111 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1112 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1113 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1114 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1115 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1116 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1117 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1118 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1119 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1120 }
1121 }
1122 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1123 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1124 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1125 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1126 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1127 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1128 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
02da9f7b 1129 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
2a81ab0d
AM
1130 }else{
1131 $fwdfwsettings{'ACTIVE'}='ON';
1132 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1133 }
62fc8511 1134
2a81ab0d 1135 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
62fc8511 1136
2a81ab0d
AM
1137print <<END;
1138 <form method="post">
1139 <table border='0'>
1140 <tr><td nowrap>$Lang::tr{'fwdfw rule action'}</td><td><select name='RULE_ACTION'>
1141END
1142 foreach ("ACCEPT","DROP","REJECT")
1143 {
cf576a12
AM
1144 if($fwdfwsettings{'updatefwrule'} eq 'on'){
1145 print"<option ";
1146 print "selected='selected'" if ($fwdfwsettings{'RULE_ACTION'} eq $_);
1147 print">$_</option>";
2a81ab0d 1148 }else{
cf576a12
AM
1149 if($fwdfwsettings{'POLICY'} eq 'MODE2'){
1150 $fwdfwsettings{'RULE_ACTION'} = 'DROP';
1151 }
1152
1153 if ($_ eq $fwdfwsettings{'RULE_ACTION'})
1154 {
1155 print"<option selected>$_</option>";
1156 }else{
1157 print"<option>$_</option>";
1158 }
2a81ab0d
AM
1159 }
1160 }
1161 print"</select></td></tr></table><hr>";
1162
2a81ab0d
AM
1163 &Header::closebox();
1164 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'});
2a81ab0d
AM
1165 #------SOURCE-------------------------------------------------------
1166 print<<END;
1167 <table width='100%' border='0'>
1168 <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>
1169 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr>
1170 <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
1171END
1172 foreach my $network (sort keys %defaultNetworks)
1173 {
1174 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
62fc8511 1175 next if($defaultNetworks{$network}{'NAME'} eq "RED");
2a81ab0d
AM
1176 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1177 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $defaultNetworks{$network}{'NAME'});
1178 print ">$network</option>";
1179 }
1180 print<<END;
1181 </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;'>
1182END
1183 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{'grp1'}});
1184 print<<END;
1185 </select></td></tr>
1186 <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;'>
1187END
1188 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{'grp1'}});
1189 print<<END;
1190 </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;'>
1191END
1192 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost)
1193 {
1194 if ($ccdhost{$key}[33] ne ''){
1195
1196 print "<option value='$ccdhost{$key}[1]'";
1197 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ccdhost{$key}[1]);
1198 print ">$ccdhost{$key}[1]</option>";
1199 }
1200 }
1201 print<<END;
1202 </select></td></tr>
1203 <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;'>
1204END
1205 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{'grp1'}});
1206 print<<END;
1207 </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;'>
1208END
1209 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) {
1210 if($ccdhost{$key}[3] eq 'net'){
1211 print"<option ";
1212 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ccdhost{$key}[1]);
1213 print ">$ccdhost{$key}[1]</option>";
1214 }
1215 }
1216 print<<END;
1217 </select></td></tr>
62fc8511 1218
2a81ab0d
AM
1219 <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;'>
1220END
1221 foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } keys %customgrp) {
1222 if($helper ne $customgrp{$key}[0]){
1223 print"<option ";
1224 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $customgrp{$key}[0]);
1225 print ">$customgrp{$key}[0]</option>";
2a81ab0d
AM
1226 }
1227 $helper=$customgrp{$key}[0];
1228 }
1229 print<<END;
1230 </select></td>
1231 <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;'>
1232END
1233 foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1234 if ($ipsecconf{$key}[3] eq 'net'){
1235 print "<option ";
1236 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ipsecconf{$key}[1]);
1237 print ">$ipsecconf{$key}[1]</option>";
1238 }
1239 }
1240 #sourceport
1241 print<<END;
1242 </select></td></tr>
1243END
62fc8511 1244
2a81ab0d
AM
1245# <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;'>
1246#END
1247# foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1248# if ($ipsecconf{$key}[3] eq 'host'){
1249# print "<option ";
1250# print "selected='selected'" if($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ipsecconf{$key}[1]);
1251# print ">$ipsecconf{$key}[1]</option>";
1252# }
1253# }
1254 print<<END;
2a81ab0d 1255 <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
2a81ab0d
AM
1256 <table width='100%' border='0'>
1257 <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>
1258 <td width='15%' nowrap='nowrap'>$Lang::tr{'fwdfw man port'}</td><td><select name='PROT'>
1259END
d1f01304 1260 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
2a81ab0d
AM
1261 {
1262 if ($_ eq $fwdfwsettings{'PROT'})
1263 {
1264 print"<option selected>$_</option>";
1265 }else{
1266 print"<option>$_</option>";
1267 }
1268 }
8f0b047b 1269 $fwdfwsettings{'SRC_PORT'}=~ s/\|/,/g;
2a81ab0d 1270 print<<END;
8f0b047b 1271 </select></td><td align='right'><input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18' ></td></tr>
12a43202 1272 <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
1273END
1274 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1275 print"<option>All ICMP-Types</option>";
1276 foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) } keys %icmptypes){
1277 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1278 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1279 }else{
1280 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1281 }
1282 }
1283 print<<END;
5dd84c25 1284 </select></td></tr></table><br><hr>
2a81ab0d
AM
1285END
1286 &Header::closebox();
1287
1288 #---TARGET------------------------------------------------------
1289 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw target'});
1290 print<<END;
1291 <table width='100%' border='0'>
1292 <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;'>
1293END
1294 print "<option value='Default IP' $selected{'ipfire'}{'Default IP'}>Default IP</option>";
62fc8511 1295
2a81ab0d
AM
1296 foreach my $alias (sort keys %aliases)
1297 {
1298 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1299 }
62fc8511 1300
2a81ab0d
AM
1301 print<<END;
1302 </td></tr>
1303 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr>
1304 <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 1305END
2a81ab0d
AM
1306 foreach my $network (sort keys %defaultNetworks)
1307 {
c7043621 1308 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
2a81ab0d
AM
1309 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1310 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $defaultNetworks{$network}{'NAME'});
1311 print ">$network</option>";
1312 }
1313 print<<END;
1314 </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;'>
1315END
1316 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{'grp2'}});
2a81ab0d
AM
1317 print<<END;
1318 </select></td></tr>
1319 <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;'>
1320END
1321 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{'grp2'}});
1322 print<<END;
1323 </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;'>
1324END
1325 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost)
1326 {
1327 if ($ccdhost{$key}[33] ne ''){
1328 print "<option value='$ccdhost{$key}[1]' ";
1329 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ccdhost{$key}[33]);
1330 print ">$ccdhost{$key}[1]</option>";
1331 }
1332 }
1333 print<<END;
1334 </select></td></tr>
1335 <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;'>
1336END
1337 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{'grp2'}});
1338 print<<END;
1339 </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;'>
1340END
1341 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) {
1342 if($ccdhost{$key}[3] eq 'net'){
1343 print "<option ";
1344 print "selected='selected'" if($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ccdhost{$key}[1]);
1345 print ">$ccdhost{$key}[1]</option>";
1346 }
1347 }
1348 print<<END;
1349 </select></td></tr>
2a81ab0d
AM
1350 <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;'>
1351END
1352 $helper='';
1353 foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } keys %customgrp) {
1354 if($helper ne $customgrp{$key}[0]){
1355 print"<option ";
1356 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $customgrp{$key}[0]);
1357 print">$customgrp{$key}[0]</option>";
1358 }
1359 $helper=$customgrp{$key}[0];
1360 }
1361 print<<END;
1362 </select></td>
1363 <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;'>
1364END
1365 foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1366 if ($ipsecconf{$key}[3] eq 'net'){
1367 print"<option ";
1368 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ipsecconf{$key}[1]);
1369 print">$ipsecconf{$key}[1]</option>";
1370 }
1371 }
1372 print<<END;
1373 </select></td></tr>
1374END
2a81ab0d
AM
1375# <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;'>
1376#END
1377# foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1378# if ($ipsecconf{$key}[3] eq 'host'){
1379# print"<option ";
1380# print"selected='Selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ipsecconf{$key}[1]);
1381# print">$ipsecconf{$key}[1]</option>";
1382# }
1383# }
1384 print<<END;
1385 </table>
1386 <b>$Lang::tr{'fwhost attention'}:</b><br>
1387 $Lang::tr{'fwhost macwarn'}<br><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; '></hr><br>
62fc8511 1388
2a81ab0d
AM
1389 <table width='100%' border='0'>
1390 <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;' >
1391END
1392 &General::readhasharray("$configsrv", \%customservice);
62fc8511 1393 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
2a81ab0d
AM
1394 print"<option ";
1395 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1396 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1397 }
1398 print<<END;
1399 </select></td></tr>
12a43202 1400 <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
1401END
1402 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1403 my $helper;
62fc8511 1404 foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){
2a81ab0d
AM
1405 if ($helper ne $customservicegrp{$key}[0]){
1406 print"<option ";
1407 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1408 print">$customservicegrp{$key}[0]</option>";
1409 }
1410 $helper=$customservicegrp{$key}[0];
1411 }
1412 print<<END;
1413 </select></td></tr>
1414 <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'>
1415END
d1f01304 1416 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
2a81ab0d
AM
1417 {
1418 if ($_ eq $fwdfwsettings{'TGT_PROT'})
1419 {
1420 print"<option selected>$_</option>";
1421 }else{
1422 print"<option>$_</option>";
1423 }
1424 }
8f0b047b 1425 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
2a81ab0d 1426 print<<END;
8f0b047b 1427 </select></td><td align='right'><input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18' ></td></tr>
12a43202 1428 <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
1429END
1430 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1431 print"<option>All ICMP-Types</option>";
1432 foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) }keys %icmptypes){
1433 if($fwdfwsettings{'ICMP_TGT'} eq "$icmptypes{$key}[0]"){
1434 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1435 }else{
1436 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1437 }
1438 }
1439 print<<END;
1440 </select></td></tr>
5dd84c25 1441 </table><br><hr>
62fc8511 1442
2a81ab0d 1443END
5dd84c25 1444 &Header::closebox;
2a81ab0d
AM
1445 #---Activate/logging/remark-------------------------------------
1446 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw additional'});
1447 print<<END;
1448 <table width='100%' border='0'>
2da264ec
AM
1449 <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>
1450END
1451 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
1452 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
1453 for (my $count =1; $count <= $sum; $count++){
1454 print"<option value='$count' ";
1455 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
1456 print">$count</option>";
1457 }
1458 print"</select></td></tr>";
70d38e50
AM
1459 }else{
1460 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
2da264ec
AM
1461 }
1462
1463 print<<END;
1464 </table><table width='100%'>
2a81ab0d
AM
1465 <tr><td width='1%'><input type='checkbox' name='ACTIVE' value='ON' $checked{'ACTIVE'}{'ON'}></td><td>$Lang::tr{'fwdfw rule activate'}</td></tr>
1466 <tr><td width='1%'><input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'} ></td><td>$Lang::tr{'fwdfw log rule'}</td></tr>
5dd84c25 1467 </table><br><hr>
2a81ab0d
AM
1468END
1469 &Header::closebox();
1470 #---ADD TIMEFRAME-----------------------------------------------
1471 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw timeframe'});
1472 print<<END;
1473 <table width='70%' border='0'>
1474 <tr><td width='1%'><input type='checkbox' name='TIME' value='ON' $checked{'TIME'}{'ON'}></td><td colspan='4'>$Lang::tr{'fwdfw timeframe'}</td></tr>
1475 <tr><td colspan='7'>&nbsp</td></tr>
1476 <tr>
1477 <td align='left'>$Lang::tr{'time'}:</td>
1478 <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
1479 <td width='15%' align='left'>$Lang::tr{'advproxy from'}</td>
1480 <td width='15%' align='left'>$Lang::tr{'advproxy to'}</td>
1481 </tr>
1482 <tr>
1483 <td align='right'></td>
1484 <td width='30%' align='left'>
1485 <input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} />
1486 <input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} />
1487 <input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} />
1488 <input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} />
1489 <input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} />
1490 <input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} />
27f4a6b1 1491 <input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} />
2a81ab0d 1492 </td>
2a81ab0d
AM
1493 <td><select name='TIME_FROM'>
1494END
1495 for (my $i=0;$i<=23;$i++) {
1496 $i = sprintf("%02s",$i);
1497 for (my $j=0;$j<=45;$j+=15) {
1498 $j = sprintf("%02s",$j);
1499 my $time = $i.":".$j;
1500 print "\t\t\t\t\t<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
1501 }
1502 }
1503 print<<END;
1504 </select></td>
1505 <td><select name='TIME_TO'>
1506END
1507 for (my $i=0;$i<=23;$i++) {
1508 $i = sprintf("%02s",$i);
1509 for (my $j=0;$j<=45;$j+=15) {
1510 $j = sprintf("%02s",$j);
1511 my $time = $i.":".$j;
1512 print "\t\t\t\t\t<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
1513 }
1514 }
62fc8511 1515 print<<END;
2a81ab0d 1516 </select></td></tr>
5dd84c25 1517 </table><br><hr>
2a81ab0d 1518END
5dd84c25 1519
2a81ab0d
AM
1520 #---ACTION------------------------------------------------------
1521 if($fwdfwsettings{'updatefwrule'} ne 'on'){
1522 print<<END;
1523 <table border='0' width='100%'>
1524 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
1525 <input type='hidden' name='config' value='$config' >
70d38e50
AM
1526 <input type='hidden' name='ACTION' value='saverule' >
1527 </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
1528 </table></form>
1529END
1530 }else{
1531 print<<END;
1532 <table border='0' width='100%'>
1533 <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'}'>
1534 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
1535 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
1536 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
1537 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
1538 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
1539 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
1540 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
2da264ec
AM
1541 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
1542 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
8f0b047b 1543 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
2a81ab0d 1544 <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
1545 </table></form>
1546END
1547 }
1548 &Header::closebox();
1549}
1550sub saverule
1551{
2a81ab0d
AM
1552 my $hash=shift;
1553 my $config=shift;
1554 &General::readhasharray("$config", $hash);
1555 if (!$errormessage){
d7127db8
AM
1556 #check if we change an forward rule to an external access
1557 if( $fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{'oldgrp2a'} ne 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1558 &changerule($configfwdfw);
1559 }
1560 #check if we change an forward rule to an outgoing
1561 if( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'oldgrp1b'} ne 'IPFire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1562 &changerule($configfwdfw);
1563 }
1564 #check if we change an external access rule to a forward
1565 if( $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'oldgrp2a'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1566 &changerule($configinput);
1567 }
1568 #check if we change an external access rule to a outgoing
1569 if( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'oldgrp2a'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1570 &changerule($configinput);
1571 }
1572 #check if we change an outgoing rule to a forward
1573 if( $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'IPFire' && $fwdfwsettings{'oldgrp1b'} eq 'IPFire' && $fwdfwsettings{'grp2'} ne 'ipfire' &&$fwdfwsettings{'updatefwrule'} eq 'on'){
1574 &changerule($configoutgoing);
1575 }
1576 #check if we change an outgoing rule to a external access
1577 if( $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'IPFire' && $fwdfwsettings{'oldgrp1b'} eq 'IPFire' && $fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1578 &changerule($configoutgoing);
1579 }
2da264ec 1580 if ($fwdfwsettings{'updatefwrule'} ne 'on'){
2a81ab0d
AM
1581 my $key = &General::findhasharraykey ($hash);
1582 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1583 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1584 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1585 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1586 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1587 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1588 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1589 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1590 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1591 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1592 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1593 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1594 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1595 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1596 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1597 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1598 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1599 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1600 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1601 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1602 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1603 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1604 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1605 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1606 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1607 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1608 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1609 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
1610 &General::writehasharray("$config", $hash);
1611 }else{
e44fa079
AM
1612 foreach my $key (sort {$a <=> $b} keys %$hash){
1613 if($key eq $fwdfwsettings{'key'}){
1614 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1615 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1616 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1617 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1618 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1619 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1620 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1621 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1622 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1623 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1624 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1625 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1626 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1627 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1628 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1629 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1630 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1631 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1632 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1633 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1634 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1635 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1636 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1637 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1638 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1639 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1640 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1641 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
1642 last;
1643 }
1644 }
1645 }
1646 &General::writehasharray("$config", $hash);
0918e516 1647 if($fwdfwsettings{'oldrulenumber'} > $fwdfwsettings{'rulepos'}){
e44fa079
AM
1648 my %tmp=();
1649 my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'};
1650 for (my $z=0;$z<$val;$z++){
1651 foreach my $key (sort {$a <=> $b} keys %$hash){
1652 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
1653 my $last = $key -1;
1654 if (exists $$hash{$last}){
1655 #save rule last
1656 foreach my $y (0 .. $#{$$hash{$last}}) {
1657 $tmp{0}[$y] = $$hash{$last}[$y];
1658 }
1659 #copy active rule to last
1660 foreach my $i (0 .. $#{$$hash{$last}}) {
1661 $$hash{$last}[$i] = $$hash{$key}[$i];
1662 }
1663 #copy saved rule to actual position
1664 foreach my $x (0 .. $#{$tmp{0}}) {
1665 $$hash{$key}[$x] = $tmp{0}[$x];
2da264ec
AM
1666 }
1667 }
1668 }
1669 }
e44fa079
AM
1670 $fwdfwsettings{'oldrulenumber'}--;
1671 }
1672 &General::writehasharray("$config", $hash);
1673 &rules;
0918e516 1674 }elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
e44fa079
AM
1675 my %tmp=();
1676 my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
1677 for (my $z=0;$z<$val;$z++){
1678 foreach my $key (sort {$a <=> $b} keys %$hash){
1679 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
1680 my $next = $key + 1;
1681 if (exists $$hash{$next}){
1682 #save rule next
1683 foreach my $y (0 .. $#{$$hash{$next}}) {
1684 $tmp{0}[$y] = $$hash{$next}[$y];
1685 }
1686 #copy active rule to next
1687 foreach my $i (0 .. $#{$$hash{$next}}) {
1688 $$hash{$next}[$i] = $$hash{$key}[$i];
1689 }
1690 #copy saved rule to actual position
1691 foreach my $x (0 .. $#{$tmp{0}}) {
1692 $$hash{$key}[$x] = $tmp{0}[$x];
2da264ec
AM
1693 }
1694 }
1695 }
2a81ab0d 1696 }
e44fa079 1697 $fwdfwsettings{'oldrulenumber'}++;
2a81ab0d
AM
1698 }
1699 &General::writehasharray("$config", $hash);
e44fa079 1700 &rules;
2a81ab0d
AM
1701 }
1702 }
1703}
1704sub error
1705{
1706 if ($errormessage) {
1707 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1708 print "<class name='base'>$errormessage\n";
1709 print "&nbsp;</class>\n";
1710 &Header::closebox();
1711 print"<hr>";
1712 }
1713}
1714sub hint
1715{
1716 if ($hint) {
1717 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1718 print "<class name='base'>$hint\n";
1719 print "&nbsp;</class>\n";
1720 &Header::closebox();
1721 print"<hr>";
1722 }
1723}
1724sub get_name
1725{
1726 my $val=shift;
1727 &General::setup_default_networks(\%defaultNetworks);
1728 foreach my $network (sort keys %defaultNetworks)
1729 {
1730 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
62fc8511 1731 }
2a81ab0d
AM
1732}
1733sub validremark
1734{
1735 # Checks a hostname against RFC1035
1736 my $remark = $_[0];
1737
1738 # Each part should be at least two characters in length
1739 # but no more than 63 characters
d24a34cb 1740 if (length ($remark) < 1 || length ($remark) > 255) {
2a81ab0d
AM
1741 return 0;}
1742 # Only valid characters are a-z, A-Z, 0-9 and -
e3580608 1743 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
2a81ab0d
AM
1744 return 0;}
1745 # First character can only be a letter or a digit
1746 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
1747 return 0;}
1748 # Last character can only be a letter or a digit
e3580608 1749 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
2a81ab0d
AM
1750 return 0;}
1751 return 1;
1752}
1753sub getsrcport
1754{
1755 my %hash=%{(shift)};
1756 my $key=shift;
93a5f4a5 1757 if($hash{$key}[7] eq 'ON' && $hash{$key}[8] ne '' && $hash{$key}[10]){
8f0b047b 1758 $hash{$key}[10]=~ s/\|/,/g;
93a5f4a5 1759 print": $hash{$key}[10]";
2a81ab0d 1760 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
93a5f4a5 1761 print": <br>$hash{$key}[9] ";
2a81ab0d
AM
1762 }
1763}
1764sub gettgtport
1765{
1766 my %hash=%{(shift)};
1767 my $key=shift;
1768 my $service;
1769 my $prot;
2a81ab0d
AM
1770 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1771 if($hash{$key}[14] eq 'cust_srv'){
1772 &General::readhasharray("$configsrv", \%customservice);
1773 foreach my $i (sort keys %customservice){
2a81ab0d 1774 if($customservice{$i}[0] eq $hash{$key}[15]){
2a81ab0d
AM
1775 $service = $customservice{$i}[0];
1776 }
1777 }
1778 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
2a81ab0d
AM
1779 $service=$hash{$key}[15];
1780 }elsif($hash{$key}[14] eq 'TGT_PORT'){
8f0b047b 1781 $hash{$key}[15]=~ s/\|/,/g;
2a81ab0d 1782 $service=$hash{$key}[15];
2a81ab0d 1783 }
99e698d0
AM
1784 if($service){
1785 print": $service";
1786 }
2a81ab0d 1787 }elsif($hash{$key}[11] eq 'ON' && $hash{$key}[12] eq 'ICMP'){
93a5f4a5 1788 print":<br>$hash{$key}[13]";
2a81ab0d 1789 }
93a5f4a5
AM
1790}
1791sub get_serviceports
1792{
1793 my $type=shift;
1794 my $name=shift;
1795 &General::readhasharray("$configsrv", \%customservice);
1796 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1797 my $protocols;
1798 my $tcp;
1799 my $udp;
1800 if($type eq 'service'){
1801 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
1802 if ($customservice{$key}[0] eq $name){
1803 $protocols=$customservice{$key}[2];
1804 }
1805 }
93a5f4a5
AM
1806 }elsif($type eq 'group'){
1807 foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){
1808 if ($customservicegrp{$key}[0] eq $name){
5edf47ff
AM
1809 foreach my $key1 (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
1810 if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
1811 if($customservice{$key1}[2] eq 'TCP'){$tcp='TCP';}else{$udp='UDP';}
1812 }
1813 }
93a5f4a5 1814 }
2a81ab0d 1815 }
2a81ab0d 1816 }
5edf47ff
AM
1817 if($tcp && $udp){$protocols="TCP,UDP";
1818 }elsif($tcp){$protocols.="TCP";
1819 }elsif($udp){$protocols.="UDP";}
93a5f4a5 1820 return $protocols;
2a81ab0d
AM
1821}
1822sub viewtablerule
1823{
15add1c8 1824 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
2a81ab0d
AM
1825 &viewtablenew(\%configfwdfw,$configfwdfw,$Lang::tr{'fwdfw rules'},"Forward" );
1826 &viewtablenew(\%configinputfw,$configinput,"",$Lang::tr{'external access'} );
c7043621 1827 &viewtablenew(\%configoutgoingfw,$configoutgoing,"","Outgoing" );
2a81ab0d
AM
1828}
1829sub viewtablenew
1830{
1831 my $hash=shift;
1832 my $config=shift;
1833 my $title=shift;
1834 my $title1=shift;
7bd9d462 1835 my $go='';
15add1c8 1836 &General::get_aliases(\%aliases);
7bd9d462 1837 &General::readhasharray("$config", $hash);
5d7faa45 1838 if( ! -z $config){
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>";
15add1c8 1848 print"<table width='100%' cellspacing='1' rules='none'; 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;
15add1c8 1904 <td align='right' width='15'>$key</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>";
12a43202 1920 &getcolor($$hash{$key}[3],$$hash{$key}[4]);
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
12a43202 1943 &getcolor($$hash{$key}[5],$$hash{$key}[6]);
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
AM
2041 #REMARK
2042 print"<tr bgcolor='$color'><td colspan='13' style='border-bottom: 1px solid black'>";
2043 print"<b>$Lang::tr{'remark'}:</b>&nbsp$$hash{$key}[16]</td></tr>";
2a81ab0d
AM
2044 }
2045 print"</table>";
2046 &Header::closebox();
12a43202 2047 print "<hr>";
2a81ab0d 2048 }
2a81ab0d 2049}
15add1c8
AM
2050sub getcolor
2051{
12a43202 2052 my $nettype=shift;
15add1c8
AM
2053 my $val=shift;
2054 if($optionsfw{'SHOWCOLORS'} eq 'on'){
12a43202
AM
2055 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'){
2056 $tdcolor="style='border: 2px solid $Header::colourovpn;'";
2057 return;
2058 }
2059 if ($nettype eq 'ipsec_net_src' || $nettype eq 'ipsec_net_tgt'){
2060 $tdcolor="style='border: 2px solid $Header::colourvpn;'";
2061 return;
2062 }
15add1c8
AM
2063 foreach my $alias (sort keys %aliases)
2064 {
2065 if ($val eq $alias){
2066 $tdcolor="style='border: 2px solid red;'";
2067 return;
2068 }
2069 }
2070 if ($val eq 'GREEN'){
12a43202 2071 $tdcolor="style='border: 2px solid $Header::colourgreen;'";
15add1c8 2072 }elsif ($val eq 'ORANGE'){
12a43202 2073 $tdcolor="style='border: 2px solid $Header::colourorange;'";
15add1c8 2074 }elsif ($val eq 'BLUE'){
12a43202 2075 $tdcolor="style='border: 2px solid $Header::colourblue;'";
15add1c8 2076 }elsif ($val eq 'IPFire' ){
12a43202 2077 $tdcolor="style='border: 2px solid $Header::colourred;'";
15add1c8
AM
2078 }elsif($val =~ /^(.*?)\/(.*?)$/){
2079 my ($sip,$scidr) = split ("/",$val);
2080 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
12a43202 2081 $tdcolor="style='border: 2px solid $Header::colourorange;'";
15add1c8
AM
2082 }
2083 if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
12a43202 2084 $tdcolor="style='border: 2px solid $Header::colourgreen;'";
15add1c8
AM
2085 }
2086 if ( &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
12a43202 2087 $tdcolor="style='border: 2px solid $Header::colourblue;'";
15add1c8
AM
2088 }
2089 }elsif ($val eq 'Default IP'){
2090 $tdcolor="style='border: 2px solid red;'";
2091 }else{
2092 $tdcolor='';
2093 }
2094 }
2095}
2a81ab0d
AM
2096sub fillselect
2097{
2098 my %hash=%{(shift)};
2099 my $val=shift;
2100 my $key;
62fc8511
AM
2101 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
2102 if($hash{$key}[0] eq $val){
2103 print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>";
2104 }else{
2105 print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>";
2a81ab0d 2106 }
62fc8511 2107 }
2a81ab0d
AM
2108}
2109sub rules
2110{
2111 if (!-f "${General::swroot}/forward/reread"){
2112 system("touch ${General::swroot}/forward/reread");
d0815ce4 2113 system("touch ${General::swroot}/fwhosts/reread");
2a81ab0d
AM
2114 }
2115}
2116sub reread_rules
2117{
2118 system("/usr/local/bin/forwardfwctrl");
e974ced8
AM
2119 if ( -f "${General::swroot}/forward/reread"){
2120 system("rm ${General::swroot}/forward/reread");
d0815ce4 2121 system("rm ${General::swroot}/fwhosts/reread");
e974ced8 2122 }
2a81ab0d
AM
2123}
2124&Header::closebigbox();
2125&Header::closepage();