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