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