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