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