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