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