]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/firewall.cgi
BUG10615 part2: Add ratelimit to firewallgui
[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'} && $fwdfwsettings{'oldconcon'} eq $fwdfwsettings{'LIMIT_CON_CON'} && $fwdfwsettings{'olduseratelimit'} eq $fwdfwsettings{'RATE_LIMIT'} && $fwdfwsettings{'oldratelimitamount'} eq $fwdfwsettings{'ratecon'} && $fwdfwsettings{'oldratelimittime'} eq $fwdfwsettings{'RATETIME'}) {
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],$configinputfw{$key}[32],$configinputfw{$key}[33],$configinputfw{$key}[34],$configinputfw{$key}[35],$configinputfw{$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],$configinputfw{$key}[32],$configinputfw{$key}[33],$configinputfw{$key}[34],$configinputfw{$key}[35],$configinputfw{$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'} && $fwdfwsettings{'oldconcon'} eq $fwdfwsettings{'LIMIT_CON_CON'} && $fwdfwsettings{'olduseratelimit'} eq $fwdfwsettings{'RATE_LIMIT'} && $fwdfwsettings{'oldratelimitamount'} eq $fwdfwsettings{'ratecon'} && $fwdfwsettings{'oldratelimittime'} eq $fwdfwsettings{'RATETIME'}) {
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],$configinputfw{$key}[32],$configinputfw{$key}[33],$configinputfw{$key}[34],$configinputfw{$key}[35],$configinputfw{$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],$configinputfw{$key}[32],$configinputfw{$key}[33],$configinputfw{$key}[34],$configinputfw{$key}[35],$configinputfw{$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'} && $fwdfwsettings{'oldconcon'} eq $fwdfwsettings{'LIMIT_CON_CON'} && $fwdfwsettings{'olduseratelimit'} eq $fwdfwsettings{'RATE_LIMIT'} && $fwdfwsettings{'oldratelimitamount'} eq $fwdfwsettings{'ratecon'} && $fwdfwsettings{'oldratelimittime'} eq $fwdfwsettings{'RATETIME'}) {
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'){
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 "RED" && $srctgt eq 'src');
1100 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1101 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1102 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $defaultNetworks{$network}{'NAME'});
1103 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
1104 my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK";
1105 my $defsub1=&General::subtocidr($ifaces{$defsub});
1106 $ifaces{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED');
1107 if ($ifaces{$defnet}){
1108 print ">$network ($ifaces{$defnet}/$defsub1)</option>";
1109 }else{
1110 print ">$network</option>";
1111 }
1112 }
1113 print"</select></td></tr>";
1114 #custom networks
1115 if (! -z $confignet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1116 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;'>";
1117 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{$grp}});
1118 print"</select></td>";
1119 }
1120 #custom hosts
1121 if (! -z $confighost || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1122 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;'>";
1123 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{$grp}});
1124 print"</select></td>";
1125 }
1126 #custom groups
1127 if (! -z $configgrp || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1128 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;'>";
1129 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } keys %customgrp) {
1130 if($helper ne $customgrp{$key}[0] && $customgrp{$key}[2] ne 'none'){
1131 print"<option ";
1132 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $customgrp{$key}[0]);
1133 print ">$customgrp{$key}[0]</option>";
1134 }
1135 $helper=$customgrp{$key}[0];
1136 }
1137 print"</select></td>";
1138 }
1139 #End left table. start right table (vpn)
1140 print"</tr></table></td><td valign='top'><table width='95%' border='0' align='right'><tr>";
1141 # CCD networks
1142 if( ! -z $configccdnet || $optionsfw{'SHOWDROPDOWN'} eq 'on'){
1143 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;'>";
1144 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{$grp}});
1145 print"</select></td></tr>";
1146 }
1147 #OVPN CCD Hosts
1148 foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost){
1149 if ($ccdhost{$key}[33] ne '' ){
1150 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 '');
1151 $show='1';
1152 print "<option value='$ccdhost{$key}[1]'";
1153 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1154 print ">$ccdhost{$key}[1]</option>";
1155 }
1156 }
1157 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1158 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>" ;
1159 }
1160 if ($show eq '1'){$show='';print"</select></td></tr>";}
1161 #OVPN N2N
1162 foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost){
1163 if ($ccdhost{$key}[3] eq 'net'){
1164 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 '');
1165 $show='1';
1166 print "<option value='$ccdhost{$key}[1]'";
1167 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ccdhost{$key}[1]);
1168 print ">$ccdhost{$key}[1]</option>";
1169 }
1170 }
1171 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1172 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>" ;
1173 }
1174 if ($show eq '1'){$show='';print"</select></td></tr>";}
1175 #IPsec netze
1176 foreach my $key (sort { ncmp($ipsecconf{$a}[1],$ipsecconf{$b}[1]) } keys %ipsecconf) {
1177 if ($ipsecconf{$key}[3] eq 'net' || ($optionsfw{'SHOWDROPDOWN'} eq 'on' && $ipsecconf{$key}[3] ne 'host')){
1178 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 '');
1179 $show='1';
1180 print "<option ";
1181 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $ipsecconf{$key}[1]);
1182 print ">$ipsecconf{$key}[1]</option>";
1183 }
1184 }
1185 if($optionsfw{'SHOWDROPDOWN'} eq 'on' && $show eq ''){
1186 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>";
1187 }
1188 if ($show eq '1'){$show='';print"</select></td></tr>";}
1189
1190 print"</table>";
1191 print"</td></tr></table><br>";
1192 }
1193 sub get_ip
1194 {
1195 my $val=shift;
1196 my $grp =shift;
1197 my $a;
1198 my $b;
1199 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1200 if ($fwdfwsettings{$grp} ne $Lang::tr{'fwhost any'}){
1201 if ($fwdfwsettings{$grp} eq $val.'_addr'){
1202 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
1203 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
1204 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
1205 $a=$netsettings{'GREEN_NETADDRESS'};
1206 $b=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'});
1207 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
1208 $a=$netsettings{'ORANGE_NETADDRESS'};
1209 $b=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'});
1210 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
1211 $a=$netsettings{'BLUE_NETADDRESS'};
1212 $b=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'});
1213 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
1214 &General::readhash("$configovpn",\%ovpnsettings);
1215 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
1216 $b=&General::iporsubtocidr($b);
1217 }
1218 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
1219 &General::readhasharray("$confignet", \%customnetwork);
1220 foreach my $key (keys %customnetwork){
1221 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1222 $a=$customnetwork{$key}[1];
1223 $b=&General::iporsubtocidr($customnetwork{$key}[2]);
1224 }
1225 }
1226 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
1227 &General::readhasharray("$confighost", \%customhost);
1228 foreach my $key (keys %customhost){
1229 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1230 if ($customhost{$key}[1] eq 'ip'){
1231 ($a,$b)=split (/\//,$customhost{$key}[2]);
1232 $b=&General::iporsubtocidr($b);
1233 }else{
1234 if ($grp eq 'grp2'){
1235 $errormessage=$Lang::tr{'fwdfw err tgt_mac'};
1236 }
1237 }
1238 }
1239 }
1240 }
1241 }
1242 return $a,$b;
1243 }
1244 sub get_name
1245 {
1246 my $val=shift;
1247 &General::setup_default_networks(\%defaultNetworks);
1248 foreach my $network (sort keys %defaultNetworks)
1249 {
1250 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1251 }
1252 }
1253 sub getsrcport
1254 {
1255 my %hash=%{(shift)};
1256 my $key=shift;
1257 if($hash{$key}[7] eq 'ON' && $hash{$key}[10]){
1258 $hash{$key}[10]=~ s/\|/,/g;
1259 print": $hash{$key}[10]";
1260 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
1261 print": <br>$hash{$key}[9] ";
1262 }
1263 }
1264 sub gettgtport
1265 {
1266 my %hash=%{(shift)};
1267 my $key=shift;
1268 my $service;
1269 my $prot;
1270 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1271 if($hash{$key}[14] eq 'cust_srv'){
1272 &General::readhasharray("$configsrv", \%customservice);
1273 foreach my $i (sort keys %customservice){
1274 if($customservice{$i}[0] eq $hash{$key}[15]){
1275 $service = $customservice{$i}[0];
1276 }
1277 }
1278 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
1279 $service=$hash{$key}[15];
1280 }elsif($hash{$key}[14] eq 'TGT_PORT'){
1281 $hash{$key}[15]=~ s/\|/,/g;
1282 $service=$hash{$key}[15];
1283 }
1284 if($service){
1285 print": $service";
1286 }
1287 }
1288 }
1289 sub get_serviceports
1290 {
1291 my $type=shift;
1292 my $name=shift;
1293 &General::readhasharray("$configsrv", \%customservice);
1294 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1295 @protocols=();
1296 my @specprot=("IPIP","IPV6","IGMP","GRE","AH","ESP");
1297 if($type eq 'service'){
1298 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1299 if ($customservice{$key}[0] eq $name){
1300 push (@protocols,$customservice{$key}[2]);
1301 }
1302 }
1303 }elsif($type eq 'group'){
1304 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1305 if ($customservicegrp{$key}[0] eq $name){
1306 if ($customservicegrp{$key}[2] ~~ @specprot){
1307 push (@protocols," ".$customservicegrp{$key}[2]);
1308 }else{
1309 foreach my $key1 (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1310 if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
1311 if (!grep(/$customservice{$key1}[2]/, @protocols)){
1312 push (@protocols,$customservice{$key1}[2]);}
1313 }
1314 }
1315 }
1316 }
1317 }
1318 }
1319
1320 # Sort protocols alphabetically.
1321 @protocols = sort(@protocols);
1322
1323 return @protocols;
1324 }
1325 sub getcolor
1326 {
1327 my $nettype=shift;
1328 my $val=shift;
1329 my $hash=shift;
1330 if($optionsfw{'SHOWCOLORS'} eq 'on'){
1331 # Don't colourise MAC addresses
1332 if (&General::validmac($val)) {
1333 $tdcolor = "";
1334 return;
1335 }
1336
1337 #custom Hosts
1338 if ($nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1339 foreach my $key (sort keys %$hash){
1340 if ($$hash{$key}[0] eq $val){
1341 $val=$$hash{$key}[2];
1342 }
1343 }
1344 }
1345 #standard networks
1346 if ($val eq 'GREEN'){
1347 $tdcolor="style='background-color: $Header::colourgreen;color:white;'";
1348 return;
1349 }elsif ($val eq 'ORANGE'){
1350 $tdcolor="style='background-color: $Header::colourorange;color:white;'";
1351 return;
1352 }elsif ($val eq 'BLUE'){
1353 $tdcolor="style='background-color: $Header::colourblue;color:white;'";
1354 return;
1355 }elsif ($val eq 'RED' ||$val eq 'RED1' ){
1356 $tdcolor="style='background-color: $Header::colourred;color:white;'";
1357 return;
1358 }elsif ($val eq 'IPFire' ){
1359 $tdcolor="style='background-color: $Header::colourred;color:white;'";
1360 return;
1361 }elsif ($val eq 'OpenVPN-Dyn' ){
1362 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1363 return;
1364 }elsif ($val eq 'IPsec RW' ){
1365 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1366 return;
1367 }elsif($val =~ /^(.*?)\/(.*?)$/){
1368 my ($sip,$scidr) = split ("/",$val);
1369 if ( &Header::orange_used() && &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1370 $tdcolor="style='background-color: $Header::colourorange;color:white;'";
1371 return;
1372 }
1373 if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1374 $tdcolor="style='background-color: $Header::colourgreen;color:white;'";
1375 return;
1376 }
1377 if ( &Header::blue_used() && &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
1378 $tdcolor="style='background-color: $Header::colourblue;color:white;'";
1379 return;
1380 }
1381 }elsif ($val eq 'Default IP'){
1382 $tdcolor="style='background-color: $Header::colourred;color:white;'";
1383 return;
1384 }
1385 #Check if a manual IP or custom host is part of a VPN
1386 if ($nettype eq 'src_addr' || $nettype eq 'tgt_addr' || $nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
1387 #Check if IP is part of OpenVPN dynamic subnet
1388 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
1389 my ($c,$d) = split("/",$val);
1390 if (&General::IpInSubnet($c,$a,$b)){
1391 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1392 return;
1393 }
1394 #Check if IP is part of OpenVPN static subnet
1395 foreach my $key (sort keys %ccdnet){
1396 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1397 $b =&General::iporsubtodec($b);
1398 if (&General::IpInSubnet($c,$a,$b)){
1399 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1400 return;
1401 }
1402 }
1403 #Check if IP is part of OpenVPN N2N subnet
1404 foreach my $key (sort keys %ccdhost){
1405 if ($ccdhost{$key}[3] eq 'net'){
1406 my ($a,$b) = split("/",$ccdhost{$key}[11]);
1407 if (&General::IpInSubnet($c,$a,$b)){
1408 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1409 return;
1410 }
1411 }
1412 }
1413 #Check if IP is part of IPsec RW network
1414 if ($ipsecsettings{'RW_NET'} ne ''){
1415 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1416 $b=&General::iporsubtodec($b);
1417 if (&General::IpInSubnet($c,$a,$b)){
1418 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1419 return;
1420 }
1421 }
1422 #Check if IP is part of a IPsec N2N network
1423 foreach my $key (sort keys %ipsecconf){
1424 if ($ipsecconf{$key}[11]){
1425 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1426 $b=&General::iporsubtodec($b);
1427 if (&General::IpInSubnet($c,$a,$b)){
1428 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1429 return;
1430 }
1431 }
1432 }
1433 }
1434 #VPN networks
1435 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'){
1436 $tdcolor="style='background-color: $Header::colourovpn;color:white;'";
1437 return;
1438 }
1439 if ($nettype eq 'ipsec_net_src' || $nettype eq 'ipsec_net_tgt'){
1440 $tdcolor="style='background-color: $Header::colourvpn;color:white;'";
1441 return;
1442 }
1443 #ALIASE
1444 foreach my $alias (sort keys %aliases)
1445 {
1446 if ($val eq $alias){
1447 $tdcolor="style='background-color:$Header::colourred;color:white;'";
1448 return;
1449 }
1450 }
1451 }
1452 $tdcolor='';
1453 return;
1454 }
1455 sub hint
1456 {
1457 if ($hint) {
1458 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1459 print "<class name='base'>$hint\n";
1460 print "&nbsp;</class>\n";
1461 &Header::closebox();
1462 }
1463 }
1464 sub newrule
1465 {
1466 &error;
1467 &General::setup_default_networks(\%defaultNetworks);
1468 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1469 #read all configfiles
1470 &General::readhasharray("$configccdnet", \%ccdnet);
1471 &General::readhasharray("$confignet", \%customnetwork);
1472 &General::readhasharray("$configccdhost", \%ccdhost);
1473 &General::readhasharray("$confighost", \%customhost);
1474 &General::readhasharray("$configccdhost", \%ccdhost);
1475 &General::readhasharray("$configgrp", \%customgrp);
1476 &General::readhasharray("$configipsec", \%ipsecconf);
1477 &General::get_aliases(\%aliases);
1478 my %checked=();
1479 my $helper;
1480 my $sum=0;
1481 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
1482 my $config=$fwdfwsettings{'config'};
1483 my %hash=();
1484 #Get Red IP-ADDRESS
1485 open (CONN1,"/var/ipfire/red/local-ipaddress");
1486 my $redip = <CONN1>;
1487 close(CONN1);
1488 if (! $fwdfwsettings{'RULE_ACTION'} && $fwdfwsettings{'POLICY'} eq 'MODE2'){
1489 $fwdfwsettings{'RULE_ACTION'}='DROP';
1490 }elsif(! $fwdfwsettings{'RULE_ACTION'} && $fwdfwsettings{'POLICY'} eq 'MODE1'){
1491 $fwdfwsettings{'RULE_ACTION'}='ACCEPT';
1492 }
1493 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1494 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1495 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1496 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1497 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1498 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1499 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1500 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1501 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1502 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1503 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1504 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1505 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1506 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1507 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1508 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1509 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1510 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1511 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1512 $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
1513 #check if update and get values
1514 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
1515 &General::readhasharray("$config", \%hash);
1516 foreach my $key (sort keys %hash){
1517 $sum++;
1518 if ($key eq $fwdfwsettings{'key'}){
1519 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
1520 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
1521 $fwdfwsettings{'chain'} = $hash{$key}[1];
1522 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1523 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1524 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1525 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1526 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1527 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1528 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1529 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1530 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1531 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1532 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1533 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1534 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1535 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1536 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1537 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1538 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1539 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1540 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1541 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1542 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1543 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1544 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1545 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1546 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1547 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
1548 $fwdfwsettings{'USE_NAT'} = $hash{$key}[28];
1549 $fwdfwsettings{'nat'} = $hash{$key}[31]; #changed order
1550 $fwdfwsettings{$fwdfwsettings{'nat'}} = $hash{$key}[29];
1551 $fwdfwsettings{'dnatport'} = $hash{$key}[30];
1552 $fwdfwsettings{'LIMIT_CON_CON'} = $hash{$key}[32];
1553 $fwdfwsettings{'concon'} = $hash{$key}[33];
1554 $fwdfwsettings{'RATE_LIMIT'} = $hash{$key}[34];
1555 $fwdfwsettings{'ratecon'} = $hash{$key}[35];
1556 $fwdfwsettings{'RATETIME'} = $hash{$key}[36];
1557 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1558 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1559 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1560 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1561 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1562 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1563 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1564 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1565 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1566 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1567 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1568 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1569 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1570 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1571 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1572 $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} = 'CHECKED';
1573 $checked{'nat'}{$fwdfwsettings{'nat'}} = 'CHECKED';
1574 $checked{'LIMIT_CON_CON'}{$fwdfwsettings{'LIMIT_CON_CON'}} = 'CHECKED';
1575 $checked{'RATE_LIMIT'}{$fwdfwsettings{'RATE_LIMIT'}} = 'CHECKED';
1576 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1577 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1578 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1579 $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} ='selected';
1580 $selected{'dnat'}{$fwdfwsettings{'dnat'}} ='selected';
1581 $selected{'snat'}{$fwdfwsettings{'snat'}} ='selected';
1582 $selected{'RATETIME'}{$fwdfwsettings{'RATETIME'}} ='selected';
1583 }
1584 }
1585 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1586 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1587 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1588 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1589 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1590 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1591 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1592 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1593 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1594 $fwdfwsettings{'oldruletype'}=$fwdfwsettings{'chain'};
1595 $fwdfwsettings{'oldconcon'}=$fwdfwsettings{'LIMIT_CON_CON'};
1596 $fwdfwsettings{'olduseratelimit'}=$fwdfwsettings{'RATE_LIMIT'};
1597 $fwdfwsettings{'olduserateamount'}=$fwdfwsettings{'ratecon'};
1598 $fwdfwsettings{'oldratelimittime'}=$fwdfwsettings{'RATETIME'};
1599
1600 #check if manual ip (source) is orange network
1601 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1602 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1603 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1604 $fwdfwsettings{'oldorange'} ='on';
1605 }
1606 }
1607 }else{
1608 $fwdfwsettings{'ACTIVE'}='ON';
1609 $fwdfwsettings{'nat'} = 'dnat';
1610 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1611 $checked{'nat'}{$fwdfwsettings{'nat'}} = 'CHECKED';
1612 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1613 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1614 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1615 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1616 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1617 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1618 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1619 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1620 $fwdfwsettings{'oldnat'}=$fwdfwsettings{'USE_NAT'};
1621 $fwdfwsettings{'oldconcon'}=$fwdfwsettings{'LIMIT_CON_CON'};
1622 #check if manual ip (source) is orange network
1623 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1624 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1625 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1626 $fwdfwsettings{'oldorange'} ='on';
1627 }
1628 }
1629 }
1630 # Split manual source and target address and delete the subnet
1631 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1632 if ($scidr eq '32'){$fwdfwsettings{$fwdfwsettings{'grp1'}}=$sip;}
1633 my ($dip,$dcidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp2'}});
1634 if ($dcidr eq '32'){$fwdfwsettings{$fwdfwsettings{'grp2'}}=$dip;}
1635 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'});
1636 #------SOURCE-------------------------------------------------------
1637 print "<form method='post'>";
1638 print<<END;
1639 <table width='100%' border='0'>
1640 <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>
1641 END
1642 print"<td align='right'><select name='ipfire_src' style='width:200px;'>";
1643 print "<option value='ALL' $selected{'ipfire_src'}{'ALL'}>$Lang::tr{'all'}</option>";
1644 print "<option value='GREEN' $selected{'ipfire_src'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
1645 print "<option value='ORANGE' $selected{'ipfire_src'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if (&Header::orange_used());
1646 print "<option value='BLUE' $selected{'ipfire_src'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>" if (&Header::blue_used());
1647 print "<option value='RED1' $selected{'ipfire_src'}{'RED1'}>$Lang::tr{'red1'} ($redip)" if ($redip);
1648 if (! -z "${General::swroot}/ethernet/aliases"){
1649 foreach my $alias (sort keys %aliases)
1650 {
1651 print "<option value='$alias' $selected{'ipfire_src'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
1652 }
1653 }
1654 print<<END;
1655 </select></td></tr>
1656 <tr><td><br></td></tr>
1657 </table>
1658 END
1659 &gen_dd_block('src','grp1');
1660 &Header::closebox();
1661
1662 #---SNAT / DNAT ------------------------------------------------
1663 &Header::openbox('100%', 'left', 'NAT');
1664 print<<END;
1665 <label>
1666 <input type='checkbox' name='USE_NAT' id='USE_NAT' value="ON" $checked{'USE_NAT'}{'ON'}>
1667 $Lang::tr{'fwdfw use nat'}
1668 </label>
1669 <div class="NAT">
1670 <table width='100%' border='0'>
1671 <tr>
1672 <td width='5%'></td>
1673 <td width='40%'>
1674 <label>
1675 <input type='radio' name='nat' value='dnat' $checked{'nat'}{'dnat'}>
1676 $Lang::tr{'fwdfw dnat'}
1677 </label>
1678 </td>
1679 END
1680
1681 print <<END;
1682 <td width='25%' align='right'>$Lang::tr{'dnat address'}:</td>
1683 <td width='30%'>
1684 <select name='dnat' style='width: 100%;'>
1685 <option value='AUTO' $selected{'dnat'}{'AUTO'}>- $Lang::tr{'automatic'} -</option>
1686 <option value='Default IP' $selected{'dnat'}{'Default IP'}>$Lang::tr{'red1'} ($redip)</option>
1687 END
1688 if (%aliases) {
1689 foreach my $alias (sort keys %aliases) {
1690 print "<option value='$alias' $selected{'dnat'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
1691 }
1692 }
1693 #DNAT Dropdown
1694 foreach my $network (sort keys %defaultNetworks)
1695 {
1696 if ($defaultNetworks{$network}{'NAME'} eq 'BLUE'||$defaultNetworks{$network}{'NAME'} eq 'GREEN' ||$defaultNetworks{$network}{'NAME'} eq 'ORANGE'){
1697 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1698 print " selected='selected'" if ($fwdfwsettings{'dnat'} eq $defaultNetworks{$network}{'NAME'});
1699 print ">$network ($defaultNetworks{$network}{'NET'})</option>";
1700 }
1701 }
1702 print "</select>";
1703 print "</tr>";
1704
1705 #SNAT
1706 print <<END;
1707 <tr>
1708 <td width='5%'></td>
1709 <td width='40%'>
1710 <label>
1711 <input type='radio' name='nat' value='snat' $checked{'nat'}{'snat'}>
1712 $Lang::tr{'fwdfw snat'}
1713 </label>
1714 </td>
1715 <td width='25%' align='right'>$Lang::tr{'snat new source ip address'}:</td>
1716 <td width='30%'>
1717 <select name='snat' style='width: 100%;'>
1718 END
1719
1720 foreach my $alias (sort keys %aliases) {
1721 print "<option value='$alias' $selected{'snat'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
1722 }
1723 # SNAT Dropdown
1724 foreach my $network (sort keys %defaultNetworks) {
1725 if ($defaultNetworks{$network}{'NAME'} eq 'BLUE'||$defaultNetworks{$network}{'NAME'} eq 'GREEN' ||$defaultNetworks{$network}{'NAME'} eq 'ORANGE'){
1726 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1727 print " selected='selected'" if ($fwdfwsettings{'snat'} eq $defaultNetworks{$network}{'NAME'});
1728 print ">$network ($defaultNetworks{$network}{'NET'})</option>";
1729 }
1730 }
1731 print <<END;
1732 </select>
1733 </td>
1734 </tr>
1735 </table>
1736 </div>
1737 END
1738 &Header::closebox();
1739
1740 #---TARGET------------------------------------------------------
1741 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw target'});
1742 print<<END;
1743 <table width='100%' border='0'>
1744 <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>
1745 END
1746 print"<td align='right'><select name='ipfire' style='width:200px;'>";
1747 print "<option value='ALL' $selected{'ipfire'}{'ALL'}>$Lang::tr{'all'}</option>";
1748 print "<option value='GREEN' $selected{'ipfire'}{'GREEN'}>$Lang::tr{'green'} ($ifaces{'GREEN_ADDRESS'})</option>" if $ifaces{'GREEN_ADDRESS'};
1749 print "<option value='ORANGE' $selected{'ipfire'}{'ORANGE'}>$Lang::tr{'orange'} ($ifaces{'ORANGE_ADDRESS'})</option>" if (&Header::orange_used());
1750 print "<option value='BLUE' $selected{'ipfire'}{'BLUE'}>$Lang::tr{'blue'} ($ifaces{'BLUE_ADDRESS'})</option>"if (&Header::blue_used());
1751 print "<option value='RED1' $selected{'ipfire'}{'RED1'}>$Lang::tr{'red1'} ($redip)" if ($redip);
1752 if (! -z "${General::swroot}/ethernet/aliases"){
1753 foreach my $alias (sort keys %aliases)
1754 {
1755 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias ($aliases{$alias}{'IPT'})</option>";
1756 }
1757 }
1758 print<<END;
1759 </select></td></tr>
1760 <tr><td><br></td></tr></table>
1761 END
1762 &gen_dd_block('tgt','grp2');
1763 &Header::closebox;
1764 #---PROTOCOL------------------------------------------------------
1765 $fwdfwsettings{'SRC_PORT'} =~ s/\|/,/g;
1766 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
1767 $fwdfwsettings{'dnatport'} =~ tr/|/,/;
1768
1769 # The dnatport may be empty, if it matches TGT_PORT
1770 if ($fwdfwsettings{'dnatport'} eq $fwdfwsettings{'TGT_PORT'}) {
1771 $fwdfwsettings{'dnatport'} = "";
1772 }
1773
1774 &Header::openbox('100%', 'left', $Lang::tr{'fwhost prot'});
1775 #Fix Protocol for JQuery
1776 if ($fwdfwsettings{'grp3'} eq 'cust_srv' || $fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
1777 $fwdfwsettings{'PROT'} = 'template';
1778 }
1779 print<<END;
1780 <table width='100%' border='0'>
1781 <tr>
1782 <td width="25%">
1783 <select name='PROT' id='protocol' style="width: 95px;">
1784 END
1785 print "<option value=\"\"";
1786 if ($fwdfwsettings{'PROT'} eq '') {
1787 print " selected=\"selected\"";
1788 }
1789 print ">$Lang::tr{'all'}</option>";
1790
1791 print "<option value=\"template\"";
1792 print " selected=\"selected\"" if ($fwdfwsettings{'grp3'} eq 'cust_srv' || $fwdfwsettings{'grp3'} eq 'cust_srvgrp');
1793 print ">- $Lang::tr{'template'} -</option>";
1794
1795 foreach (@PROTOCOLS) {
1796 print"<option value=\"$_\"";
1797 if ($_ eq $fwdfwsettings{'PROT'}) {
1798 print " selected=\"selected\"";
1799 }
1800 if($_ eq "IPv6"){
1801 print ">$Lang::tr{'fwdfw prot41'}</option>";
1802 }else{
1803 print ">$_</option>";
1804 }
1805 }
1806
1807 print<<END;
1808 </select>
1809 </td>
1810 <td width="75%">
1811 <table width='100%' border='0' id="PROTOCOL_ICMP_TYPES">
1812 <tr>
1813 <td width='20%'>$Lang::tr{'fwhost icmptype'}</td>
1814 <td colspan='2'>
1815 <select name='ICMP_TYPES' style='min-width:230px;'>
1816 END
1817 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1818 print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>";
1819 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
1820 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1821 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1822 }else{
1823 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1824 }
1825 }
1826
1827 print <<END;
1828 </select>
1829 </td>
1830 </tr>
1831 </table>
1832
1833 <table width="100%" border="0" id="PROTOCOL_PORTS">
1834 <tr>
1835 <!-- #SOURCEPORT -->
1836 <td>
1837 $Lang::tr{'fwdfw use srcport'}
1838 </td>
1839 <td>
1840 <input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18'>
1841 </td>
1842 <td width='10%'>
1843 </td>
1844
1845 <!-- #TARGETPORT -->
1846 <td>
1847 $Lang::tr{'fwdfw use srv'}
1848 </td>
1849
1850 <td>
1851 <input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18'>
1852 </td>
1853 </tr>
1854 <tr class="NAT">
1855 <td colspan='3'></td>
1856 <td>$Lang::tr{'fwdfw external port nat'}:</td>
1857 <td>
1858 <input type='text' name='dnatport' value=\"$fwdfwsettings{'dnatport'}\" maxlength='20' size='18'>
1859 </td>
1860 </tr>
1861 </table>
1862
1863 <table width="100%" border="0" id="PROTOCOL_TEMPLATE">
1864 <tr>
1865 <td>
1866 <input type='radio' name='grp3' id='cust_srv' value='cust_srv' checked>
1867 $Lang::tr{'fwhost cust service'}
1868 </td>
1869 <td>
1870 <select name='cust_srv' style='min-width: 230px;'>
1871 END
1872
1873 &General::readhasharray("$configsrv", \%customservice);
1874 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice){
1875 print"<option ";
1876 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1877 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1878 }
1879
1880 print <<END;
1881 </select>
1882 </td>
1883 </tr>
1884 <tr>
1885 <td>
1886 <input type='radio' name='grp3' id='cust_srvgrp' value='cust_srvgrp' $checked{'grp3'}{'cust_srvgrp'}>
1887 $Lang::tr{'fwhost cust srvgrp'}
1888 </td>
1889 <td>
1890 <select name='cust_srvgrp' style='min-width:230px;'>
1891 END
1892
1893 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1894 my $helper;
1895 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1896 if ($helper ne $customservicegrp{$key}[0] && $customservicegrp{$key}[2] ne 'none'){
1897 print"<option ";
1898 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1899 print">$customservicegrp{$key}[0]</option>";
1900 }
1901 $helper=$customservicegrp{$key}[0];
1902 }
1903
1904 print<<END;
1905 </select>
1906 </td>
1907 </tr>
1908 </table>
1909 </td>
1910 </tr>
1911 </table>
1912 END
1913
1914 &Header::closebox;
1915 $checked{"RULE_ACTION"}{$fwdfwsettings{'RULE_ACTION'}} = 'CHECKED';
1916 print <<END;
1917 <center>
1918 <table width="80%" class='tbl' id='actions'>
1919 <tr>
1920 <td width="33%" align="center" bgcolor="$color{'color17'}">
1921 &nbsp;<br>&nbsp;
1922 </td>
1923 <td width="33%" align="center" bgcolor="$color{'color25'}">
1924 &nbsp;<br>&nbsp;
1925 </td>
1926 <td width="33%" align="center" bgcolor="$color{'color16'}">
1927 &nbsp;<br>&nbsp;
1928 </td>
1929 </tr>
1930 <tr>
1931 <td width="33%" align="center">
1932 <label>
1933 <input type="radio" name="RULE_ACTION" value="ACCEPT" $checked{"RULE_ACTION"}{"ACCEPT"}>
1934 <strong>$Lang::tr{'fwdfw ACCEPT'}</strong>
1935 </label>
1936 </td>
1937 <td width="33%" align="center">
1938 <label>
1939 <input type="radio" name="RULE_ACTION" value="DROP" $checked{"RULE_ACTION"}{"DROP"}>
1940 <strong>$Lang::tr{'fwdfw DROP'}</strong>
1941 </label>
1942 </td>
1943 <td width="33%" align="center">
1944 <label>
1945 <input type="radio" name="RULE_ACTION" value="REJECT" $checked{"RULE_ACTION"}{"REJECT"}>
1946 <strong>$Lang::tr{'fwdfw REJECT'}</strong>
1947 </label>
1948 </td>
1949 </tr>
1950 </table>
1951 </center>
1952
1953 <br>
1954 END
1955 #---Activate/logging/remark-------------------------------------
1956 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw additional'});
1957 print<<END;
1958 <table width='100%' border='0'>
1959 END
1960 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>";
1961 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
1962 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
1963 for (my $count =1; $count <= $sum; $count++){
1964 print"<option value='$count' ";
1965 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
1966 print">$count</option>";
1967 }
1968 print"</select></td></tr>";
1969 }else{
1970 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
1971 }
1972
1973 print<<END;
1974 </table>
1975 <table width='100%'>
1976 <tr>
1977 END
1978
1979 if ($fwdfwsettings{'updatefwrule'} eq 'on') {
1980 print <<END;
1981 <td>
1982 <input type='checkbox' name='ACTIVE' value="ON" $checked{'ACTIVE'}{'ON'}>
1983 </td>
1984 <td>$Lang::tr{'fwdfw rule activate'}</td>
1985 END
1986 } else {
1987 print <<END;
1988 <td colspan="2">
1989 <input type="hidden" name="ACTIVE" value="ON">
1990 </td>
1991 END
1992 }
1993
1994 print <<END;
1995 </tr>
1996 <tr>
1997 <td>
1998 <input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'}>
1999 </td>
2000 <td>$Lang::tr{'fwdfw log rule'}</td>
2001 </tr>
2002 <tr>
2003 <td width='1%'>
2004 <input type='checkbox' name='TIME' id="USE_TIME_CONSTRAINTS" value='ON' $checked{'TIME'}{'ON'}>
2005 </td>
2006 <td>$Lang::tr{'fwdfw timeframe'}</td>
2007 </tr>
2008 <tr id="TIME_CONSTRAINTS">
2009 <td colspan="2">
2010 <table width="66%" border="0">
2011 <tr>
2012 <td width="8em">&nbsp;</td>
2013 <td align="center">$Lang::tr{'advproxy monday'}</td>
2014 <td align="center">$Lang::tr{'advproxy tuesday'}</td>
2015 <td align="center">$Lang::tr{'advproxy wednesday'}</td>
2016 <td align="center">$Lang::tr{'advproxy thursday'}</td>
2017 <td align="center">$Lang::tr{'advproxy friday'}</td>
2018 <td align="center">$Lang::tr{'advproxy saturday'}</td>
2019 <td align="center">$Lang::tr{'advproxy sunday'}</td>
2020 <td>&nbsp;</td>
2021 </tr>
2022 <tr>
2023 <td width="8em">&nbsp;</td>
2024 <td align="center"><input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} ></td>
2025 <td align="center"><input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} ></td>
2026 <td align="center"><input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} ></td>
2027 <td align="center"><input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} ></td>
2028 <td align="center"><input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} ></td>
2029 <td align="center"><input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} ></td>
2030 <td align="center"><input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} ></td>
2031 <td>
2032 <select name='TIME_FROM'>
2033 END
2034 for (my $i=0;$i<=23;$i++) {
2035 $i = sprintf("%02s",$i);
2036 for (my $j=0;$j<=45;$j+=15) {
2037 $j = sprintf("%02s",$j);
2038 my $time = $i.":".$j;
2039 print "<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
2040 }
2041 }
2042 print<<END;
2043 </select> &dash;
2044 <select name='TIME_TO'>
2045 END
2046 for (my $i=0;$i<=23;$i++) {
2047 $i = sprintf("%02s",$i);
2048 for (my $j=0;$j<=45;$j+=15) {
2049 $j = sprintf("%02s",$j);
2050 my $time = $i.":".$j;
2051 print "<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
2052 }
2053 }
2054 print<<END;
2055 </select>
2056 </td>
2057 </tr>
2058 </table>
2059 </td>
2060 </tr>
2061 <tr>
2062 <td width='1%'>
2063 <input type='checkbox' name='LIMIT_CON_CON' id="USE_LIMIT_CONCURRENT_CONNECTIONS_PER_IP" value='ON' $checked{'LIMIT_CON_CON'}{'ON'}>
2064 </td>
2065 <td>$Lang::tr{'fwdfw limitconcon'}</td>
2066 </tr>
2067 <tr id="LIMIT_CON">
2068 <td colspan='2'>
2069 <table width='66%' border='0'>
2070 <tr>
2071 <td width="20em">&nbsp;</td>
2072 <td>$Lang::tr{'fwdfw maxconcon'}: <input type='text' name='concon' size='2' value="$fwdfwsettings{'concon'}"></td>
2073 </tr>
2074 </table>
2075 </td>
2076 </tr>
2077 <tr>
2078 <td width='1%'>
2079 <input type='checkbox' name='RATE_LIMIT' id="USE_RATELIMIT" value='ON' $checked{'RATE_LIMIT'}{'ON'}>
2080 </td>
2081 <td>$Lang::tr{'fwdfw ratelimit'}</td>
2082 </tr>
2083 <tr id="RATELIMIT">
2084 <td colspan='2'>
2085 <table width='66%' border='0'>
2086 <tr>
2087 <td width="20em">&nbsp;</td>
2088 <td>$Lang::tr{'fwdfw numcon'}: <input type='text' name='ratecon' size='2' value="$fwdfwsettings{'ratecon'}"> /
2089 <select name='RATETIME' style='width:100px;'>
2090 <option value='second' $selected{'RATETIME'}{'second'}>$Lang::tr{'age second'}</option>
2091 <option value='minute' $selected{'RATETIME'}{'minute'}>$Lang::tr{'minute'}</option>
2092 <option value='hour' $selected{'RATETIME'}{'hour'}>$Lang::tr{'hour'}</option>
2093 </select>
2094 </td>
2095 </tr>
2096 </table>
2097 </td>
2098 </tr>
2099 </table>
2100 <br>
2101 END
2102
2103 #---ACTION------------------------------------------------------
2104 if($fwdfwsettings{'updatefwrule'} ne 'on'){
2105 print<<END;
2106 <table border='0' width='100%'>
2107 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
2108 <input type='hidden' name='config' value='$config' >
2109 <input type='hidden' name='ACTION' value='saverule' ></form>
2110 <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>
2111 </table>
2112 <br>
2113 END
2114 }else{
2115 print<<END;
2116 <table border='0' width='100%'>
2117 <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'}'>
2118 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
2119 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
2120 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
2121 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
2122 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
2123 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
2124 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
2125 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
2126 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
2127 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
2128 <input type='hidden' name='oldorange' value='$fwdfwsettings{'oldorange'}' />
2129 <input type='hidden' name='oldnat' value='$fwdfwsettings{'oldnat'}' />
2130 <input type='hidden' name='oldruletype' value='$fwdfwsettings{'oldruletype'}' />
2131 <input type='hidden' name='oldconcon' value='$fwdfwsettings{'oldconcon'}' />
2132 <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>
2133 </table></form>
2134 END
2135 }
2136 &Header::closebox();
2137 }
2138 sub pos_up
2139 {
2140 my %uphash=();
2141 my %tmp=();
2142 &General::readhasharray($fwdfwsettings{'config'}, \%uphash);
2143 foreach my $key (sort keys %uphash){
2144 if ($key eq $fwdfwsettings{'key'}) {
2145 my $last = $key -1;
2146 if (exists $uphash{$last}){
2147 #save rule last
2148 foreach my $y (0 .. $#{$uphash{$last}}) {
2149 $tmp{0}[$y] = $uphash{$last}[$y];
2150 }
2151 #copy active rule to last
2152 foreach my $i (0 .. $#{$uphash{$last}}) {
2153 $uphash{$last}[$i] = $uphash{$key}[$i];
2154 }
2155 #copy saved rule to actual position
2156 foreach my $x (0 .. $#{$tmp{0}}) {
2157 $uphash{$key}[$x] = $tmp{0}[$x];
2158 }
2159 }
2160 }
2161 }
2162 &General::writehasharray($fwdfwsettings{'config'}, \%uphash);
2163 &General::firewall_config_changed();
2164 }
2165 sub pos_down
2166 {
2167 my %downhash=();
2168 my %tmp=();
2169 &General::readhasharray($fwdfwsettings{'config'}, \%downhash);
2170 foreach my $key (sort keys %downhash){
2171 if ($key eq $fwdfwsettings{'key'}) {
2172 my $next = $key + 1;
2173 if (exists $downhash{$next}){
2174 #save rule next
2175 foreach my $y (0 .. $#{$downhash{$next}}) {
2176 $tmp{0}[$y] = $downhash{$next}[$y];
2177 }
2178 #copy active rule to next
2179 foreach my $i (0 .. $#{$downhash{$next}}) {
2180 $downhash{$next}[$i] = $downhash{$key}[$i];
2181 }
2182 #copy saved rule to actual position
2183 foreach my $x (0 .. $#{$tmp{0}}) {
2184 $downhash{$key}[$x] = $tmp{0}[$x];
2185 }
2186 }
2187 }
2188 }
2189 &General::writehasharray($fwdfwsettings{'config'}, \%downhash);
2190 &General::firewall_config_changed();
2191 }
2192 sub saverule
2193 {
2194 my $hash=shift;
2195 my $config=shift;
2196 &General::readhasharray("$config", $hash);
2197 if (!$errormessage){
2198 ################################################################
2199 #check if we change an INPUT rule to a OUTGOING
2200 if($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW' ){
2201 &changerule($configinput);
2202 #print"1";
2203 }
2204 #check if we change an INPUT rule to a FORWARD
2205 elsif($fwdfwsettings{'oldruletype'} eq 'INPUTFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
2206 &changerule($configinput);
2207 #print"2";
2208 }
2209 ################################################################
2210 #check if we change an OUTGOING rule to an INPUT
2211 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'INPUTFW' ){
2212 &changerule($configoutgoing);
2213 #print"3";
2214 }
2215 #check if we change an OUTGOING rule to a FORWARD
2216 elsif($fwdfwsettings{'oldruletype'} eq 'OUTGOINGFW' && $fwdfwsettings{'chain'} eq 'FORWARDFW' ){
2217 &changerule($configoutgoing);
2218 #print"4";
2219 }
2220 ################################################################
2221 #check if we change a FORWARD rule to an INPUT
2222 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'INPUTFW'){
2223 &changerule($configfwdfw);
2224 #print"5";
2225 }
2226 #check if we change a FORWARD rule to an OUTGOING
2227 elsif($fwdfwsettings{'oldruletype'} eq 'FORWARDFW' && $fwdfwsettings{'chain'} eq 'OUTGOINGFW'){
2228 &changerule($configfwdfw);
2229 #print"6";
2230 }
2231 $fwdfwsettings{'ruleremark'}=~ s/,/;/g;
2232 utf8::decode($fwdfwsettings{'ruleremark'});
2233 $fwdfwsettings{'ruleremark'}=&Header::escape($fwdfwsettings{'ruleremark'});
2234 if ($fwdfwsettings{'updatefwrule'} ne 'on'){
2235 my $key = &General::findhasharraykey ($hash);
2236 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
2237 $$hash{$key}[1] = $fwdfwsettings{'chain'};
2238 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
2239 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
2240 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
2241 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
2242 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
2243 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
2244 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
2245 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
2246 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
2247 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
2248 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
2249 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
2250 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
2251 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
2252 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
2253 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
2254 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
2255 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
2256 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
2257 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
2258 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
2259 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
2260 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
2261 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
2262 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
2263 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
2264 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
2265 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
2266 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
2267 $$hash{$key}[31] = $fwdfwsettings{'nat'};
2268 $$hash{$key}[32] = $fwdfwsettings{'LIMIT_CON_CON'};
2269 $$hash{$key}[33] = $fwdfwsettings{'concon'};
2270 $$hash{$key}[34] = $fwdfwsettings{'RATE_LIMIT'};
2271 $$hash{$key}[35] = $fwdfwsettings{'ratecon'};
2272 $$hash{$key}[36] = $fwdfwsettings{'RATETIME'};
2273 &General::writehasharray("$config", $hash);
2274 }else{
2275 foreach my $key (sort {$a <=> $b} keys %$hash){
2276 if($key eq $fwdfwsettings{'key'}){
2277 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
2278 $$hash{$key}[1] = $fwdfwsettings{'chain'};
2279 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
2280 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
2281 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
2282 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
2283 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
2284 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
2285 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
2286 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
2287 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
2288 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
2289 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
2290 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
2291 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
2292 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
2293 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
2294 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
2295 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
2296 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
2297 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
2298 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
2299 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
2300 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
2301 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
2302 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
2303 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
2304 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
2305 $$hash{$key}[28] = $fwdfwsettings{'USE_NAT'};
2306 $$hash{$key}[29] = $fwdfwsettings{$fwdfwsettings{'nat'}};
2307 $$hash{$key}[30] = $fwdfwsettings{'dnatport'};
2308 $$hash{$key}[31] = $fwdfwsettings{'nat'};
2309 $$hash{$key}[32] = $fwdfwsettings{'LIMIT_CON_CON'};
2310 $$hash{$key}[33] = $fwdfwsettings{'concon'};
2311 $$hash{$key}[34] = $fwdfwsettings{'RATE_LIMIT'};
2312 $$hash{$key}[35] = $fwdfwsettings{'ratecon'};
2313 $$hash{$key}[36] = $fwdfwsettings{'RATETIME'};
2314 last;
2315 }
2316 }
2317 }
2318 &General::writehasharray("$config", $hash);
2319 if($fwdfwsettings{'oldrulenumber'} > $fwdfwsettings{'rulepos'}){
2320 my %tmp=();
2321 my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'};
2322 for (my $z=0;$z<$val;$z++){
2323 foreach my $key (sort {$a <=> $b} keys %$hash){
2324 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2325 my $last = $key -1;
2326 if (exists $$hash{$last}){
2327 #save rule last
2328 foreach my $y (0 .. $#{$$hash{$last}}) {
2329 $tmp{0}[$y] = $$hash{$last}[$y];
2330 }
2331 #copy active rule to last
2332 foreach my $i (0 .. $#{$$hash{$last}}) {
2333 $$hash{$last}[$i] = $$hash{$key}[$i];
2334 }
2335 #copy saved rule to actual position
2336 foreach my $x (0 .. $#{$tmp{0}}) {
2337 $$hash{$key}[$x] = $tmp{0}[$x];
2338 }
2339 }
2340 }
2341 }
2342 $fwdfwsettings{'oldrulenumber'}--;
2343 }
2344 &General::writehasharray("$config", $hash);
2345 &General::firewall_config_changed();
2346 }elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
2347 my %tmp=();
2348 my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
2349 for (my $z=0;$z<$val;$z++){
2350 foreach my $key (sort {$a <=> $b} keys %$hash){
2351 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
2352 my $next = $key + 1;
2353 if (exists $$hash{$next}){
2354 #save rule next
2355 foreach my $y (0 .. $#{$$hash{$next}}) {
2356 $tmp{0}[$y] = $$hash{$next}[$y];
2357 }
2358 #copy active rule to next
2359 foreach my $i (0 .. $#{$$hash{$next}}) {
2360 $$hash{$next}[$i] = $$hash{$key}[$i];
2361 }
2362 #copy saved rule to actual position
2363 foreach my $x (0 .. $#{$tmp{0}}) {
2364 $$hash{$key}[$x] = $tmp{0}[$x];
2365 }
2366 }
2367 }
2368 }
2369 $fwdfwsettings{'oldrulenumber'}++;
2370 }
2371 &General::writehasharray("$config", $hash);
2372 &General::firewall_config_changed();
2373 }
2374 }
2375 }
2376 sub validremark
2377 {
2378 # Checks a hostname against RFC1035
2379 my $remark = $_[0];
2380
2381 # Try to decode $remark into UTF-8. If this doesn't work,
2382 # we assume that the string it not sane.
2383 if (!utf8::decode($remark)) {
2384 return 0;
2385 }
2386
2387 # Check if the string only contains of printable characters.
2388 if ($remark =~ /^[[:print:]]*$/) {
2389 return 1;
2390 }
2391 return 0;
2392 }
2393 sub viewtablerule
2394 {
2395 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
2396
2397 &viewtablenew(\%configfwdfw, $configfwdfw, $Lang::tr{'firewall rules'});
2398 &viewtablenew(\%configinputfw, $configinput, $Lang::tr{'incoming firewall access'});
2399 &viewtablenew(\%configoutgoingfw, $configoutgoing, $Lang::tr{'outgoing firewall access'});
2400 }
2401 sub viewtablenew
2402 {
2403 my $hash=shift;
2404 my $config=shift;
2405 my $title=shift;
2406 my $go='';
2407
2408 my $show_box = (! -z $config) || ($optionsfw{'SHOWTABLES'} eq 'on');
2409 return if (!$show_box);
2410
2411 &General::get_aliases(\%aliases);
2412 &General::readhasharray("$confighost", \%customhost);
2413 &General::readhasharray("$config", $hash);
2414 &General::readhasharray("$configccdnet", \%ccdnet);
2415 &General::readhasharray("$configccdhost", \%ccdhost);
2416 &General::readhasharray("$configgrp", \%customgrp);
2417 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2418
2419 &Header::openbox('100%', 'left', $title);
2420 print "<table width='100%' cellspacing='0' class='tbl'>";
2421
2422 if (! -z $config) {
2423 my $count=0;
2424 my ($gif,$log);
2425 my $ruletype;
2426 my $rulecolor;
2427 my $tooltip;
2428 my @tmpsrc=();
2429 my @tmptgt=();
2430 my $coloryellow='';
2431
2432 print <<END;
2433 <tr>
2434 <th align='right' width='3%'>
2435 #
2436 </th>
2437 <th width='2%'></th>
2438 <th align='center'>
2439 <b>$Lang::tr{'protocol'}</b>
2440 </th>
2441 <th align='center' width='30%'>
2442 <b>$Lang::tr{'fwdfw source'}</b>
2443 </th>
2444 <th align='center'>
2445 <b>$Lang::tr{'fwdfw log'}</b>
2446 </th>
2447 <th align='center' width='30%'>
2448 <b>$Lang::tr{'fwdfw target'}</b>
2449 </th>
2450 <th align='center' colspan='6' width='18%'>
2451 <b>$Lang::tr{'fwdfw action'}</b>
2452 </th>
2453 </tr>
2454 END
2455
2456 foreach my $key (sort {$a <=> $b} keys %$hash){
2457 $tdcolor='';
2458 @tmpsrc=();
2459 @tmptgt=();
2460 #check if vpn hosts/nets have been deleted
2461 if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){
2462 push (@tmpsrc,$$hash{$key}[4]);
2463 }
2464 if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){
2465 push (@tmptgt,$$hash{$key}[6]);
2466 }
2467 foreach my $host (@tmpsrc){
2468 if($$hash{$key}[3] eq 'ipsec_net_src'){
2469 if(&fwlib::get_ipsec_net_ip($host,11) eq ''){
2470 $coloryellow='on';
2471 }
2472 }elsif($$hash{$key}[3] eq 'ovpn_net_src'){
2473 if(&fwlib::get_ovpn_net_ip($host,1) eq ''){
2474 $coloryellow='on';
2475 }
2476 }elsif($$hash{$key}[3] eq 'ovpn_n2n_src'){
2477 if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){
2478 $coloryellow='on';
2479 }
2480 }elsif($$hash{$key}[3] eq 'ovpn_host_src'){
2481 if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
2482 $coloryellow='on';
2483 }
2484 }
2485 }
2486 foreach my $host (@tmptgt){
2487 if($$hash{$key}[5] eq 'ipsec_net_tgt'){
2488 if(&fwlib::get_ipsec_net_ip($host,11) eq ''){
2489 $coloryellow='on';
2490 }
2491 }elsif($$hash{$key}[5] eq 'ovpn_net_tgt'){
2492 if(&fwlib::get_ovpn_net_ip($host,1) eq ''){
2493 $coloryellow='on';
2494 }
2495 }elsif($$hash{$key}[5] eq 'ovpn_n2n_tgt'){
2496 if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){
2497 $coloryellow='on';
2498 }
2499 }elsif($$hash{$key}[5] eq 'ovpn_host_tgt'){
2500 if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
2501 $coloryellow='on';
2502 }
2503 }
2504 }
2505 #check if networkgroups or servicegroups are empty
2506 foreach my $netgroup (sort keys %customgrp){
2507 if(($$hash{$key}[4] eq $customgrp{$netgroup}[0] || $$hash{$key}[6] eq $customgrp{$netgroup}[0]) && $customgrp{$netgroup}[2] eq 'none'){
2508 $coloryellow='on';
2509 }
2510 }
2511 foreach my $srvgroup (sort keys %customservicegrp){
2512 if($$hash{$key}[15] eq $customservicegrp{$srvgroup}[0] && $customservicegrp{$srvgroup}[2] eq 'none'){
2513 $coloryellow='on';
2514 }
2515 }
2516 $$hash{'ACTIVE'}=$$hash{$key}[2];
2517 $count++;
2518 if($coloryellow eq 'on'){
2519 $color="$color{'color14'}";
2520 $coloryellow='';
2521 }elsif($coloryellow eq ''){
2522 if ($count % 2){
2523 $color="$color{'color22'}";
2524 }
2525 else{
2526 $color="$color{'color20'}";
2527 }
2528 }
2529 print<<END;
2530 <tr bgcolor='$color'>
2531 <td align='right' width='3%'>
2532 <b>$key&nbsp;</b>
2533 </td>
2534 END
2535
2536 #RULETYPE (A,R,D)
2537 if ($$hash{$key}[0] eq 'ACCEPT'){
2538 $ruletype='A';
2539 $tooltip='ACCEPT';
2540 $rulecolor=$color{'color17'};
2541 }elsif($$hash{$key}[0] eq 'DROP'){
2542 $ruletype='D';
2543 $tooltip='DROP';
2544 $rulecolor=$color{'color25'};
2545 }elsif($$hash{$key}[0] eq 'REJECT'){
2546 $ruletype='R';
2547 $tooltip='REJECT';
2548 $rulecolor=$color{'color16'};
2549 }
2550
2551 print <<END;
2552 <td bgcolor='$rulecolor' align='center' width='2%'>
2553 <span title='$tooltip'>&nbsp;&nbsp;</span>
2554 </td>
2555 END
2556
2557 #Get Protocol
2558 my $prot;
2559 if ($$hash{$key}[8]){
2560 if ($$hash{$key}[8] eq "IPv6"){
2561 push (@protocols,$Lang::tr{'fwdfw prot41 short'})
2562 }else{
2563 push (@protocols,$$hash{$key}[8]);
2564 }
2565 }elsif($$hash{$key}[14] eq 'cust_srv'){
2566 &get_serviceports("service",$$hash{$key}[15]);
2567 }elsif($$hash{$key}[14] eq 'cust_srvgrp'){
2568 &get_serviceports("group",$$hash{$key}[15]);
2569 }else{
2570 push (@protocols,$Lang::tr{'all'});
2571 }
2572
2573 my $protz=join(", ",@protocols);
2574 if($protz eq 'ICMP' && $$hash{$key}[9] ne 'All ICMP-Types' && $$hash{$key}[14] ne 'cust_srvgrp'){
2575 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
2576 foreach my $keyicmp (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
2577 if($$hash{$key}[9] eq "$icmptypes{$keyicmp}[0]"){
2578 print "<td align='center'><span title='$icmptypes{$keyicmp}[0]'><b>$protz ($icmptypes{$keyicmp}[1])</b></span></td>";
2579 last;
2580 }
2581 }
2582 }elsif($#protocols gt '3'){
2583 print"<td align='center'><span title='$protz'>$Lang::tr{'fwdfw many'}</span></td>";
2584 }else{
2585 print"<td align='center'>$protz</td>";
2586 }
2587 @protocols=();
2588 #SOURCE
2589 my $ipfireiface;
2590 &getcolor($$hash{$key}[3],$$hash{$key}[4],\%customhost);
2591 print"<td align='center' width='30%' $tdcolor>";
2592 if ($$hash{$key}[3] eq 'ipfire_src'){
2593 $ipfireiface=$Lang::tr{'fwdfw iface'};
2594 }
2595 if ($$hash{$key}[3] eq 'std_net_src'){
2596 print &get_name($$hash{$key}[4]);
2597 }elsif ($$hash{$key}[3] eq 'src_addr'){
2598 my ($split1,$split2) = split("/",$$hash{$key}[4]);
2599 if ($split2 eq '32'){
2600 print $split1;
2601 }else{
2602 print $$hash{$key}[4];
2603 }
2604 }elsif ($$hash{$key}[4] eq 'RED1'){
2605 print "$ipfireiface $Lang::tr{'fwdfw red'}";
2606 }elsif ($$hash{$key}[4] eq 'ALL'){
2607 print "$ipfireiface $Lang::tr{'all'}";
2608 }else{
2609 if ($$hash{$key}[4] eq 'GREEN' || $$hash{$key}[4] eq 'ORANGE' || $$hash{$key}[4] eq 'BLUE' || $$hash{$key}[4] eq 'RED'){
2610 print "$ipfireiface $Lang::tr{lc($$hash{$key}[4])}";
2611 }else{
2612 print "$ipfireiface $$hash{$key}[4]";
2613 }
2614 }
2615 $tdcolor='';
2616 #SOURCEPORT
2617 &getsrcport(\%$hash,$key);
2618 #Is this a SNAT rule?
2619 if ($$hash{$key}[31] eq 'snat' && $$hash{$key}[28] eq 'ON'){
2620 my $net=&get_name($$hash{$key}[29]);
2621 if ( ! $net){ $net=$$hash{$key}[29];}
2622 print"<br>->$net";
2623 if ($$hash{$key}[30] ne ''){
2624 print": $$hash{$key}[30]";
2625 }
2626 }
2627 if ($$hash{$key}[17] eq 'ON'){
2628 $log="/images/on.gif";
2629 }else{
2630 $log="/images/off.gif";
2631 }
2632 #LOGGING
2633 print<<END;
2634 </td>
2635 <td align='center'>
2636 <form method='POST' action=''>
2637 <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 ;'/>
2638 <input type='hidden' name='key' value='$key' />
2639 <input type='hidden' name='config' value='$config' />
2640 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw togglelog'}' />
2641 </form>
2642 </td>
2643 END
2644 #TARGET
2645 &getcolor($$hash{$key}[5],$$hash{$key}[6],\%customhost);
2646 print<<END;
2647 <td align='center' $tdcolor>
2648 END
2649 #Is this a DNAT rule?
2650 my $natstring;
2651 if ($$hash{$key}[31] eq 'dnat' && $$hash{$key}[28] eq 'ON'){
2652 if ($$hash{$key}[29] eq 'Default IP'){$$hash{$key}[29]=$Lang::tr{'red1'};}
2653 if ($$hash{$key}[29] eq 'AUTO'){
2654 my @src_addresses=&fwlib::get_addresses(\%$hash,$key,'src');
2655 my @nat_ifaces;
2656 foreach my $val (@src_addresses){
2657 push (@nat_ifaces,&fwlib::get_nat_address($$hash{$key}[29],$val));
2658 }
2659 @nat_ifaces=&del_double(@nat_ifaces);
2660 $natstring = "";
2661 }else{
2662 $natstring = "($$hash{$key}[29])";
2663 }
2664 print "$Lang::tr{'firewall'} $natstring";
2665 if($$hash{$key}[30] ne ''){
2666 $$hash{$key}[30]=~ tr/|/,/;
2667 print": $$hash{$key}[30]";
2668 }
2669 print"<br>-&gt;";
2670 }
2671 if ($$hash{$key}[5] eq 'std_net_tgt' || $$hash{$key}[5] eq 'ipfire'){
2672 if ($$hash{$key}[6] eq 'RED1'){
2673 print "$Lang::tr{'red1'}";
2674 }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')
2675 {
2676 print &get_name($$hash{$key}[6]);
2677 }else{
2678 print $$hash{$key}[6];
2679 }
2680 }elsif ($$hash{$key}[5] eq 'tgt_addr'){
2681 my ($split1,$split2) = split("/",$$hash{$key}[6]);
2682 if ($split2 eq '32'){
2683 print $split1;
2684 }else{
2685 print $$hash{$key}[6];
2686 }
2687 }else{
2688 print "$$hash{$key}[6]";
2689 }
2690 $tdcolor='';
2691 #TARGETPORT
2692 &gettgtport(\%$hash,$key);
2693 print"</td>";
2694 #RULE ACTIVE
2695 if($$hash{$key}[2] eq 'ON'){
2696 $gif="/images/on.gif"
2697
2698 }else{
2699 $gif="/images/off.gif"
2700 }
2701 print<<END;
2702 <td width='3%' align='center'>
2703 <form method='POST' action=''>
2704 <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;' />
2705 <input type='hidden' name='key' value='$key' />
2706 <input type='hidden' name='config' value='$config' />
2707 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw toggle'}' />
2708 </form>
2709 </td>
2710 <td width='3%' align='center'>
2711 <form method='POST' action=''>
2712 <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;' />
2713 <input type='hidden' name='key' value='$key' />
2714 <input type='hidden' name='config' value='$config' />
2715 <input type='hidden' name='ACTION' value='editrule' />
2716 </form>
2717 </td>
2718 <td width='3%' align='center'>
2719 <form method='POST' action=''>
2720 <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;' />
2721 <input type='hidden' name='key' value='$key' />
2722 <input type='hidden' name='config' value='$config' />
2723 <input type='hidden' name='ACTION' value='copyrule' />
2724 </form>
2725 </td>
2726 <td width='3%' align='center'>
2727 <form method='POST' action=''>
2728 <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;' />
2729 <input type='hidden' name='key' value='$key' />
2730 <input type='hidden' name='config' value='$config' />
2731 <input type='hidden' name='ACTION' value='deleterule' />
2732 </form>
2733 </td>
2734 END
2735 if (exists $$hash{$key-1}){
2736 print<<END;
2737 <td width='3%' align='center'>
2738 <form method='POST' action=''>
2739 <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;' />
2740 <input type='hidden' name='key' value='$key' />
2741 <input type='hidden' name='config' value='$config' />
2742 <input type='hidden' name='ACTION' value='moveup' />
2743 </form>
2744 </td>
2745 END
2746 }else{
2747 print"<td width='3%'></td>";
2748 }
2749
2750 if (exists $$hash{$key+1}){
2751 print<<END;
2752 <td width='3%' align='center'>
2753 <form method='POST' action=''>
2754 <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;' />
2755 <input type='hidden' name='key' value='$key' />
2756 <input type='hidden' name='config' value='$config' />
2757 <input type='hidden' name='ACTION' value='movedown' />
2758 </form>
2759 </td>
2760 </tr>
2761 END
2762 }else{
2763 print"<td width='3%'></td></tr>";
2764 }
2765 #REMARK
2766 if ($optionsfw{'SHOWREMARK'} eq 'on' && $$hash{$key}[16] ne ''){
2767 print <<END;
2768 <tr bgcolor='$color'>
2769 <td>&nbsp;</td>
2770 <td bgcolor='$rulecolor'></td>
2771 <td colspan='10'>
2772 &nbsp; <em>$$hash{$key}[16]</em>
2773 </td>
2774 </tr>
2775 END
2776 }
2777
2778 if ($$hash{$key}[18] eq 'ON'){
2779 #TIMEFRAME
2780 if ($$hash{$key}[18] eq 'ON'){
2781 my @days=();
2782 if($$hash{$key}[19] ne ''){push (@days,$Lang::tr{'fwdfw wd_mon'});}
2783 if($$hash{$key}[20] ne ''){push (@days,$Lang::tr{'fwdfw wd_tue'});}
2784 if($$hash{$key}[21] ne ''){push (@days,$Lang::tr{'fwdfw wd_wed'});}
2785 if($$hash{$key}[22] ne ''){push (@days,$Lang::tr{'fwdfw wd_thu'});}
2786 if($$hash{$key}[23] ne ''){push (@days,$Lang::tr{'fwdfw wd_fri'});}
2787 if($$hash{$key}[24] ne ''){push (@days,$Lang::tr{'fwdfw wd_sat'});}
2788 if($$hash{$key}[25] ne ''){push (@days,$Lang::tr{'fwdfw wd_sun'});}
2789 my $weekdays=join(",",@days);
2790 if (@days){
2791 print"<tr bgcolor='$color'>";
2792 print"<td>&nbsp;</td><td bgcolor='$rulecolor'></td><td align='left' colspan='10'>&nbsp; $weekdays &nbsp; $$hash{$key}[26] - $$hash{$key}[27]</td></tr>";
2793 }
2794 }
2795 }
2796 print"<tr bgcolor='FFFFFF'><td colspan='13' height='1'></td></tr>";
2797 }
2798 } elsif ($optionsfw{'SHOWTABLES'} eq 'on') {
2799 print <<END;
2800 <tr>
2801 <td colspan='7' height='30' bgcolor=$color{'color22'} align='center'>$Lang::tr{'fwhost empty'}</td>
2802 </tr>
2803 END
2804 }
2805
2806 #SHOW FINAL RULE
2807 my $policy = 'fwdfw ' . $fwdfwsettings{'POLICY'};
2808 my $colour = "bgcolor='green'";
2809 if ($fwdfwsettings{'POLICY'} eq 'MODE1') {
2810 $colour = "bgcolor='darkred'";
2811 }
2812
2813 my $message;
2814 if (($config eq '/var/ipfire/firewall/config') && ($fwdfwsettings{'POLICY'} ne 'MODE1')) {
2815 print <<END;
2816 <tr>
2817 <td colspan='13'>&nbsp;</td>
2818 </tr>
2819 <tr>
2820 <td colspan='13' style="padding-left:0px;padding-right:0px">
2821 <table width="100%" border='1' rules="cols" cellspacing='0'>
2822 END
2823
2824 # GREEN
2825 print <<END;
2826 <tr>
2827 <td align='center'>
2828 <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
2829 </td>
2830 <td align='center'>
2831 <font color="$Header::colourred">$Lang::tr{'red'}</font>
2832 ($Lang::tr{'fwdfw pol allow'})
2833 </td>
2834 END
2835
2836 if (&Header::orange_used()) {
2837 print <<END;
2838 <td align='center'>
2839 <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
2840 ($Lang::tr{'fwdfw pol allow'})
2841 </td>
2842 END
2843 }
2844
2845 if (&Header::blue_used()) {
2846 print <<END;
2847 <td align='center'>
2848 <font color="$Header::colourblue">$Lang::tr{'blue'}</font>
2849 ($Lang::tr{'fwdfw pol allow'})
2850 </td>
2851 END
2852 }
2853
2854 print"</tr>";
2855
2856 # ORANGE
2857 if (&Header::orange_used()) {
2858 print <<END;
2859 <tr>
2860 <td align='center' width='20%'>
2861 <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
2862 </td>
2863 <td align='center'>
2864 <font color="$Header::colourred">$Lang::tr{'red'}</font>
2865 ($Lang::tr{'fwdfw pol allow'})
2866 </td>
2867 <td align='center'>
2868 <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
2869 ($Lang::tr{'fwdfw pol block'})
2870 </td>
2871 END
2872
2873 if (&Header::blue_used()) {
2874 print <<END;
2875 <td align='center'>
2876 <font color="$Header::colourblue">$Lang::tr{'blue'}</font>
2877 ($Lang::tr{'fwdfw pol block'})
2878 </td>
2879 END
2880 }
2881
2882 print"</tr>";
2883 }
2884
2885 if (&Header::blue_used()) {
2886 print <<END;
2887 <tr>
2888 <td align='center'>
2889 <font color="$Header::colourblue">$Lang::tr{'blue'}</font>
2890 </td>
2891 <td align='center'>
2892 <font color="$Header::colourred">$Lang::tr{'red'}</font>
2893 ($Lang::tr{'fwdfw pol allow'})
2894 </td>
2895 END
2896
2897 if (&Header::orange_used()) {
2898 print <<END;
2899 <td align='center'>
2900 <font color="$Header::colourorange">$Lang::tr{'orange'}</font>
2901 ($Lang::tr{'fwdfw pol block'})
2902 </td>
2903 END
2904 }
2905
2906 print <<END;
2907 <td align='center'>
2908 <font color="$Header::colourgreen">$Lang::tr{'green'}</font>
2909 ($Lang::tr{'fwdfw pol block'})
2910 </td>
2911 </tr>
2912 END
2913 }
2914
2915 print <<END;
2916 </table>
2917 </td>
2918 </tr>
2919 END
2920
2921 $message = $Lang::tr{'fwdfw pol allow'};
2922
2923 } elsif ($config eq '/var/ipfire/firewall/outgoing' && ($fwdfwsettings{'POLICY1'} ne 'MODE1')) {
2924 $message = $Lang::tr{'fwdfw pol allow'};
2925 $colour = "bgcolor='green'";
2926 } else {
2927 $message = $Lang::tr{'fwdfw pol block'};
2928 $colour = "bgcolor='darkred'";
2929 }
2930
2931 if ($message) {
2932 print <<END;
2933 <tr>
2934 <td $colour align='center' colspan='13'>
2935 <font color='#FFFFFF'>$Lang::tr{'policy'}: $message</font>
2936 </td>
2937 </tr>
2938 END
2939 }
2940
2941 print "</table>";
2942 print "<br>";
2943
2944 &Header::closebox();
2945 }
2946
2947 &Header::closebigbox();
2948 &Header::closepage();