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