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