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