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