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