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