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