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