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