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