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