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