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