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