]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/forwardfw.cgi
Forward Firewall: Bugfix: Error appending or writing comments in rule
[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 $color;
78 my $confignet = "${General::swroot}/fwhosts/customnetworks";
79 my $confighost = "${General::swroot}/fwhosts/customhosts";
80 my $configgrp = "${General::swroot}/fwhosts/customgroups";
81 my $configsrv = "${General::swroot}/fwhosts/customservices";
82 my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
83 my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
84 my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
85 my $configipsec = "${General::swroot}/vpn/config";
86 my $configipsecrw = "${General::swroot}/vpn/settings";
87 my $configfwdfw = "${General::swroot}/forward/config";
88 my $configinput = "${General::swroot}/forward/input";
89 my $configoutgoing = "${General::swroot}/forward/outgoing";
90 my $configdmz = "${General::swroot}/forward/dmz";
91 my $configovpn = "${General::swroot}/ovpn/settings";
92 my $fwoptions = "${General::swroot}/optionsfw/settings";
93 my $errormessage='';
94 my $hint='';
95 my $ipgrp="${General::swroot}/outgoing/groups";
96 my $tdcolor='';
97 my $checkorange='';
98
99 &General::readhash("${General::swroot}/forward/settings", \%fwdfwsettings);
100 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
101 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
102 &General::readhash($fwoptions, \%optionsfw);
103
104 &Header::showhttpheaders();
105 &Header::getcgihash(\%fwdfwsettings);
106 &Header::openpage($Lang::tr{'fwdfw menu'}, 1, '');
107 &Header::openbigbox('100%', 'center',$errormessage);
108 #### ACTION #####
109
110 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'save'})
111 {
112 my $MODE = $fwdfwsettings{'POLICY'};
113 my $MODE1 = $fwdfwsettings{'POLICY1'};
114 %fwdfwsettings = ();
115 $fwdfwsettings{'POLICY'} = "$MODE";
116 $fwdfwsettings{'POLICY1'} = "$MODE1";
117 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
118 &reread_rules;
119 }
120 if ($fwdfwsettings{'ACTION'} eq 'saverule')
121 {
122 &General::readhasharray("$configfwdfw", \%configfwdfw);
123 &General::readhasharray("$configinput", \%configinputfw);
124 &General::readhasharray("$configoutgoing", \%configoutgoingfw);
125
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 changerule
524 {
525 my $oldchain=shift;
526 $fwdfwsettings{'updatefwrule'}='';
527 $fwdfwsettings{'config'}=$oldchain;
528 $fwdfwsettings{'nobase'}='on';
529 &deleterule;
530 &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
531 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
532 }
533 sub pos_up
534 {
535 my %uphash=();
536 my %tmp=();
537 &General::readhasharray($fwdfwsettings{'config'}, \%uphash);
538 foreach my $key (sort keys %uphash){
539 if ($key eq $fwdfwsettings{'key'}) {
540 my $last = $key -1;
541 if (exists $uphash{$last}){
542 #save rule last
543 foreach my $y (0 .. $#{$uphash{$last}}) {
544 $tmp{0}[$y] = $uphash{$last}[$y];
545 }
546 #copy active rule to last
547 foreach my $i (0 .. $#{$uphash{$last}}) {
548 $uphash{$last}[$i] = $uphash{$key}[$i];
549 }
550 #copy saved rule to actual position
551 foreach my $x (0 .. $#{$tmp{0}}) {
552 $uphash{$key}[$x] = $tmp{0}[$x];
553 }
554 }
555 }
556 }
557 &General::writehasharray($fwdfwsettings{'config'}, \%uphash);
558 &rules;
559 }
560 sub pos_down
561 {
562 my %downhash=();
563 my %tmp=();
564 &General::readhasharray($fwdfwsettings{'config'}, \%downhash);
565 foreach my $key (sort keys %downhash){
566 if ($key eq $fwdfwsettings{'key'}) {
567 my $next = $key + 1;
568 if (exists $downhash{$next}){
569 #save rule next
570 foreach my $y (0 .. $#{$downhash{$next}}) {
571 $tmp{0}[$y] = $downhash{$next}[$y];
572 }
573 #copy active rule to next
574 foreach my $i (0 .. $#{$downhash{$next}}) {
575 $downhash{$next}[$i] = $downhash{$key}[$i];
576 }
577 #copy saved rule to actual position
578 foreach my $x (0 .. $#{$tmp{0}}) {
579 $downhash{$key}[$x] = $tmp{0}[$x];
580 }
581 }
582 }
583 }
584 &General::writehasharray($fwdfwsettings{'config'}, \%downhash);
585 &rules;
586 }
587 sub checkcounter
588 {
589 my ($base1,$val1,$base2,$val2) = @_;
590
591 if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){
592 &dec_counter($confignet,\%customnetwork,$val1);
593 }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){
594 &dec_counter($confighost,\%customhost,$val1);
595 }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){
596 &dec_counter($configgrp,\%customgrp,$val1);
597 }elsif($base1 eq 'cust_srv'){
598 &dec_counter($configsrv,\%customservice,$val1);
599 }elsif($base1 eq 'cust_srvgrp'){
600 &dec_counter($configsrvgrp,\%customservicegrp,$val1);
601 }
602
603 if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){
604 &inc_counter($confignet,\%customnetwork,$val2);
605 }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){
606 &inc_counter($confighost,\%customhost,$val2);
607 }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){
608 &inc_counter($configgrp,\%customgrp,$val2);
609 }elsif($base2 eq 'cust_srv'){
610 &inc_counter($configsrv,\%customservice,$val2);
611 }elsif($base2 eq 'cust_srvgrp'){
612 &inc_counter($configsrvgrp,\%customservicegrp,$val2);
613 }
614 }
615 sub inc_counter
616 {
617 my $config=shift;
618 my %hash=%{(shift)};
619 my $val=shift;
620 my $pos;
621
622 &General::readhasharray($config, \%hash);
623 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
624 if($hash{$key}[0] eq $val){
625 $pos=$#{$hash{$key}};
626 $hash{$key}[$pos] = $hash{$key}[$pos]+1;
627 }
628 }
629 &General::writehasharray($config, \%hash);
630 }
631 sub dec_counter
632 {
633 my $config=shift;
634 my %hash=%{(shift)};
635 my $val=shift;
636 my $pos;
637 #$errormessage.="ALT:config: $config , verringert wird $val <br>";
638 &General::readhasharray($config, \%hash);
639 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
640 if($hash{$key}[0] eq $val){
641 $pos=$#{$hash{$key}};
642 $hash{$key}[$pos] = $hash{$key}[$pos]-1;
643 }
644 }
645 &General::writehasharray($config, \%hash);
646 }
647 sub base
648 {
649 if ($fwdfwsettings{'POLICY'} eq 'MODE1'){ $selected{'POLICY'}{'MODE1'} = 'selected'; } else { $selected{'POLICY'}{'MODE1'} = ''; }
650 if ($fwdfwsettings{'POLICY'} eq 'MODE2'){ $selected{'POLICY'}{'MODE2'} = 'selected'; } else { $selected{'POLICY'}{'MODE2'} = ''; }
651 if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){ $selected{'POLICY1'}{'MODE1'} = 'selected'; } else { $selected{'POLICY1'}{'MODE1'} = ''; }
652 if ($fwdfwsettings{'POLICY1'} eq 'MODE2'){ $selected{'POLICY1'}{'MODE2'} = 'selected'; } else { $selected{'POLICY1'}{'MODE2'} = ''; }
653 &hint;
654 &addrule;
655 print "<br><br>";
656 &Header::openbox('100%', 'center', $Lang::tr{'fwdfw pol title'});
657 print <<END;
658 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
659 <table width='100%' border='0'>
660 <tr><td colspan='3' style='font-weight:bold;color:red;' align='left'>FORWARD </td></tr>
661 <tr><td colspan='3' align='left'>$Lang::tr{'fwdfw pol text'}</td></tr>
662 <tr><td colspan='3'><hr /></td></tr>
663 <tr><td width='15%' align='left'> <select name='POLICY' style="width: 100px">
664 <option value='MODE1' $selected{'POLICY'}{'MODE1'}>$Lang::tr{'fwdfw pol block'}</option>
665 <option value='MODE2' $selected{'POLICY'}{'MODE2'}>$Lang::tr{'fwdfw pol allow'}</option></select>
666 <input type='submit' name='ACTION' value=$Lang::tr{'save'} /></td><td width='45%' align='right'>
667
668 END
669 print "$Lang::tr{'outgoing firewall reset'}: <input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /><input type='hidden' name='poltype' value='forward' /></td></tr>";
670 print "</table></form>";
671 print"<br><br>";
672 print <<END;
673 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
674 <table width='100%' border='0'>
675 <tr><td colspan='3' style='font-weight:bold;color:red;' align='left'>OUTGOING </td></tr>
676 <tr><td colspan='3' align='left'>$Lang::tr{'fwdfw pol text1'}</td></tr>
677 <tr><td colspan='3'><hr /></td></tr>
678 <tr><td width='15%' align='left'> <select name='POLICY1' style="width: 100px">
679 <option value='MODE1' $selected{'POLICY1'}{'MODE1'}>$Lang::tr{'fwdfw pol block'}</option>
680 <option value='MODE2' $selected{'POLICY1'}{'MODE2'}>$Lang::tr{'fwdfw pol allow'}</option></select>
681 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td><td width='45%' align='right'>
682
683 END
684 print "$Lang::tr{'outgoing firewall reset'}: <input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /><input type='hidden' name='poltype' value='outgoing' /></tr>";
685 print "</table></form>";
686 &Header::closebox();
687 }
688 sub addrule
689 {
690 &error;
691 if (-f "${General::swroot}/forward/reread"){
692 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>";
693 }
694 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
695 print "<form method='post'>";
696 print "<table border='0'>";
697 print "<tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'></td>";
698 print"</tr></table></form><hr>";
699 &Header::closebox();
700 &viewtablerule;
701 }
702 sub deleterule
703 {
704 my %delhash=();
705 &General::readhasharray($fwdfwsettings{'config'}, \%delhash);
706 foreach my $key (sort {$a <=> $b} keys %delhash){
707 if ($key == $fwdfwsettings{'key'}){
708 #check hosts/net and groups
709 &checkcounter($delhash{$key}[3],$delhash{$key}[4],,);
710 &checkcounter($delhash{$key}[5],$delhash{$key}[6],,);
711 #check services and groups
712 if ($delhash{$key}[11] eq 'ON'){
713 &checkcounter($delhash{$key}[14],$delhash{$key}[15],,);
714 }
715 }
716 if ($key >= $fwdfwsettings{'key'}) {
717 my $next = $key + 1;
718 if (exists $delhash{$next}) {
719 foreach my $i (0 .. $#{$delhash{$next}}) {
720 $delhash{$key}[$i] = $delhash{$next}[$i];
721 }
722 }
723 }
724 }
725 # Remove the very last entry.
726 my $last_key = (sort {$a <=> $b} keys %delhash)[-1];
727 delete $delhash{$last_key};
728
729 &General::writehasharray($fwdfwsettings{'config'}, \%delhash);
730 &rules;
731
732 if($fwdfwsettings{'nobase'} ne 'on'){
733 &base;
734 }
735 }
736 sub disable_rule
737 {
738 my $key1=shift;
739 &General::readhasharray("$configfwdfw", \%configfwdfw);
740 foreach my $key (sort keys %configfwdfw){
741 if ($key eq $key1 ){
742 if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';}
743 }
744 }
745 &General::writehasharray("$configfwdfw", \%configfwdfw);
746 &rules;
747 }
748 sub checksource
749 {
750 my ($ip,$subnet);
751
752 #check ip-address if manual
753 if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){
754 #check if ip with subnet
755 if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?)$/) {
756 ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'});
757 $subnet = &General::iporsubtocidr($subnet);
758 $fwdfwsettings{'isip'}='on';
759 }
760 #check if only ip
761 if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
762 $ip=$fwdfwsettings{'src_addr'};
763 $subnet = '32';
764 $fwdfwsettings{'isip'}='on';
765 }
766
767 if ($fwdfwsettings{'isip'} ne 'on'){
768 if (&General::validmac($fwdfwsettings{'src_addr'})){$fwdfwsettings{'ismac'}='on';}
769 }
770 if ($fwdfwsettings{'isip'} eq 'on'){
771 #check and form valid IP
772 $ip=&General::ip2dec($ip);
773 $ip=&General::dec2ip($ip);
774 #check if net or broadcast
775 my @tmp= split (/\./,$ip);
776 if (($tmp[3] eq "0") || ($tmp[3] eq "255"))
777 {
778 $errormessage=$Lang::tr{'fwhost err hostip'}."<br>";
779 }
780 $fwdfwsettings{'src_addr'}="$ip/$subnet";
781
782 if(!&General::validipandmask($fwdfwsettings{'src_addr'})){
783 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
784 }
785 }
786 if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){
787 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
788 }
789 }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
790 $errormessage.=$Lang::tr{'fwdfw err nosrcip'};
791 return $errormessage;
792 }
793
794 #check empty fields
795 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err nosrc'}."<br>";}
796 #check icmp source
797 if ($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ICMP'){
798 $fwdfwsettings{'SRC_PORT'}='';
799 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
800 foreach my $key (keys %icmptypes){
801 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){
802 $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]";
803 }
804 }
805 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'GRE'){
806 $fwdfwsettings{'SRC_PORT'}='';
807 $fwdfwsettings{'ICMP_TYPES'}='';
808 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ESP'){
809 $fwdfwsettings{'SRC_PORT'}='';
810 $fwdfwsettings{'ICMP_TYPES'}='';
811 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'AH'){
812 $fwdfwsettings{'SRC_PORT'}='';
813 $fwdfwsettings{'ICMP_TYPES'}='';
814 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} ne 'ICMP'){
815 $fwdfwsettings{'ICMP_TYPES'}='';
816 }else{
817 $fwdfwsettings{'ICMP_TYPES'}='';
818 $fwdfwsettings{'SRC_PORT'}='';
819 $fwdfwsettings{'PROT'}='';
820 }
821
822 if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){
823 my @parts=split(",",$fwdfwsettings{'SRC_PORT'});
824 my @values=();
825 foreach (@parts){
826 chomp($_);
827 if ($_ =~ /^(\d+)\:(\d+)$/) {
828 my $check;
829 #change dashes with :
830 $_=~ tr/-/:/;
831 if ($_ eq "*") {
832 push(@values,"1:65535");
833 $check='on';
834 }
835 if ($_ =~ /^(\D)\:(\d+)$/) {
836 push(@values,"1:$2");
837 $check='on';
838 }
839 if ($_ =~ /^(\d+)\:(\D)$/) {
840 push(@values,"$1:65535");
841 $check='on'
842 }
843 $errormessage .= &General::validportrange($_, 'destination');
844 if(!$check){
845 push (@values,$_);
846 }
847 }else{
848 if (&General::validport($_)){
849 push (@values,$_);
850 }else{
851
852 }
853 }
854 }
855 $fwdfwsettings{'SRC_PORT'}=join("|",@values);
856 return $errormessage;
857 }
858 }
859 sub checktarget
860 {
861 my ($ip,$subnet);
862
863 if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
864 #check if ip with subnet
865 if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?)$/) {
866 ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
867 $subnet = &General::iporsubtocidr($subnet);
868 }
869 #check if only ip
870 if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
871 $ip=$fwdfwsettings{'tgt_addr'};
872 $subnet='32';
873 }
874 #check and form valid IP
875 $ip=&General::ip2dec($ip);
876 $ip=&General::dec2ip($ip);
877
878 ##check if net or broadcast
879 #my @tmp= split (/\./,$ip);
880 #if ($tmp[3] eq "0" || ($tmp[3] eq "255"))
881 #{
882 #$errormessage=$Lang::tr{'fwhost err hostip'}."<br>";
883 #}
884 $fwdfwsettings{'tgt_addr'}="$ip/$subnet";
885
886 if(!&General::validipandmask($fwdfwsettings{'tgt_addr'})){
887 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
888 }
889
890 }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
891 $errormessage.=$Lang::tr{'fwdfw err notgtip'};
892 return $errormessage;
893 }
894
895 #check empty fields
896 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err notgt'}."<br>";}
897
898 #check tgt services
899 if ($fwdfwsettings{'USESRV'} eq 'ON'){
900 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
901 $fwdfwsettings{'TGT_PROT'}='';
902 $fwdfwsettings{'ICMP_TGT'}='';
903 }
904 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
905 $fwdfwsettings{'TGT_PROT'}='';
906 $fwdfwsettings{'ICMP_TGT'}='';
907 #check target service
908 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){
909 $errormessage.=$Lang::tr{'fwdfw err tgt_grp'};
910 }
911 }
912 if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
913 if ($fwdfwsettings{'TGT_PROT'} eq 'TCP' || $fwdfwsettings{'TGT_PROT'} eq 'UDP'){
914 if ($fwdfwsettings{'TGT_PORT'} ne ''){
915 my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
916 my @values=();
917 foreach (@parts){
918 chomp($_);
919 if ($_ =~ /^(\d+)\:(\d+)$/) {
920 my $check;
921 #change dashes with :
922 $_=~ tr/-/:/;
923 if ($_ eq "*") {
924 push(@values,"1:65535");
925 $check='on';
926 }
927 if ($_ =~ /^(\D)\:(\d+)$/) {
928 push(@values,"1:$2");
929 $check='on';
930 }
931 if ($_ =~ /^(\d+)\:(\D)$/) {
932 push(@values,"$1:65535");
933 $check='on'
934 }
935 $errormessage .= &General::validportrange($_, 'destination');
936 if(!$check){
937 push (@values,$_);
938 }
939 }else{
940 if (&General::validport($_)){
941 push (@values,$_);
942 }else{
943
944 }
945 }
946 }
947 $fwdfwsettings{'TGT_PORT'}=join("|",@values);
948 }
949 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'GRE'){
950 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
951 $fwdfwsettings{'TGT_PORT'} = '';
952 $fwdfwsettings{'ICMP_TGT'} = '';
953 }elsif($fwdfwsettings{'TGT_PROT'} eq 'ESP'){
954 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
955 $fwdfwsettings{'TGT_PORT'} = '';
956 $fwdfwsettings{'ICMP_TGT'}='';
957 }elsif($fwdfwsettings{'TGT_PROT'} eq 'AH'){
958 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
959 $fwdfwsettings{'TGT_PORT'} = '';
960 $fwdfwsettings{'ICMP_TGT'}='';
961 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'ICMP'){
962 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
963 $fwdfwsettings{'TGT_PORT'} = '';
964 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
965 foreach my $key (keys %icmptypes){
966
967 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwdfwsettings{'ICMP_TGT'}){
968 $fwdfwsettings{'ICMP_TGT'}=$icmptypes{$key}[0];
969 }
970 }
971 }
972 }
973 }
974
975 #check targetport
976 if ($fwdfwsettings{'USESRV'} ne 'ON'){
977 $fwdfwsettings{'grp3'}='';
978 $fwdfwsettings{$fwdfwsettings{'grp3'}}='';
979 $fwdfwsettings{'TGT_PROT'}='';
980 $fwdfwsettings{'ICMP_TGT'}='';
981 }
982 #check timeframe
983 if($fwdfwsettings{'TIME'} eq 'ON'){
984 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 ''){
985 $errormessage=$Lang::tr{'fwdfw err time'};
986 }
987 }
988 return $errormessage;
989 }
990 sub checkrule
991 {
992 #check valid remark
993 if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
994 $errormessage.=$Lang::tr{'fwdfw err remark'}."<br>";
995 }
996 #check if source and target identical
997 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL'){
998 $errormessage.=$Lang::tr{'fwdfw err same'};
999 return $errormessage;
1000 }
1001
1002 #get source and targetip address if possible
1003 my ($sip,$scidr,$tip,$tcidr);
1004 ($sip,$scidr)=&get_ip("src","grp1");
1005 ($tip,$tcidr)=&get_ip("tgt","grp2");
1006
1007 #check same iprange in source and target
1008 if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){
1009 my $networkip1=&General::getnetworkip($sip,$scidr);
1010 my $networkip2=&General::getnetworkip($tip,$tcidr);
1011 if ($scidr gt $tcidr){
1012 if ( &General::IpInSubnet($networkip1,$tip,&General::iporsubtodec($tcidr))){
1013 $errormessage.=$Lang::tr{'fwdfw err samesub'};
1014 }
1015 }elsif($scidr eq $tcidr && $scidr eq '32'){
1016 my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1);
1017 my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2);
1018 if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){
1019 $hint=$Lang::tr{'fwdfw hint ip1'}."<br>";
1020 $hint.=$Lang::tr{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>";
1021 }
1022 }else{
1023 if ( &General::IpInSubnet($networkip2,$sip,&General::iporsubtodec($scidr)) ){
1024 $errormessage.=$Lang::tr{'fwdfw err samesub'};
1025 }
1026 }
1027 }
1028
1029 #check source and destination protocol if manual
1030 if( $fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'USESRV'} eq 'ON'){
1031 if($fwdfwsettings{'PROT'} ne $fwdfwsettings{'TGT_PROT'} && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
1032 $errormessage.=$Lang::tr{'fwdfw err prot'};
1033 }
1034 #check source and destination protocol if source manual and dest servicegrp
1035 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
1036 &General::readhasharray("$configsrv", \%customservice);
1037 foreach my $key (sort keys %customservice){
1038 if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){
1039 if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){
1040 $errormessage.=$Lang::tr{'fwdfw err prot'};
1041 last;
1042 }
1043 }
1044 }
1045 }
1046 }
1047 }
1048 sub get_ip
1049 {
1050 my $val=shift;
1051 my $grp =shift;
1052 my $a;
1053 my $b;
1054 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1055 if ($fwdfwsettings{$grp} ne $Lang::tr{'fwhost any'}){
1056 if ($fwdfwsettings{$grp} eq $val.'_addr'){
1057 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
1058 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
1059 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
1060 $a=$netsettings{'GREEN_NETADDRESS'};
1061 $b=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'});
1062 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
1063 $a=$netsettings{'ORANGE_NETADDRESS'};
1064 $b=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'});
1065 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
1066 $a=$netsettings{'BLUE_NETADDRESS'};
1067 $b=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'});
1068 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
1069 &General::readhash("$configovpn",\%ovpnsettings);
1070 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
1071 $b=&General::iporsubtocidr($b);
1072 }
1073 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
1074 &General::readhasharray("$confignet", \%customnetwork);
1075 foreach my $key (keys %customnetwork){
1076 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1077 $a=$customnetwork{$key}[1];
1078 $b=&General::iporsubtocidr($customnetwork{$key}[2]);
1079 }
1080 }
1081 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
1082 &General::readhasharray("$confighost", \%customhost);
1083 foreach my $key (keys %customhost){
1084 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
1085 if ($customhost{$key}[1] eq 'ip'){
1086 ($a,$b)=split (/\//,$customhost{$key}[2]);
1087 $b=&General::iporsubtocidr($b);
1088 }else{
1089 if ($grp eq 'grp2'){
1090 $errormessage=$Lang::tr{'fwdfw err tgt_mac'};
1091 }
1092 }
1093 }
1094 }
1095 }
1096 }
1097 return $a,$b;
1098 }
1099 sub newrule
1100 {
1101 &error;
1102 &General::setup_default_networks(\%defaultNetworks);
1103 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1104 #read all configfiles
1105 &General::readhasharray("$configccdnet", \%ccdnet);
1106 &General::readhasharray("$confignet", \%customnetwork);
1107 &General::readhasharray("$configccdhost", \%ccdhost);
1108 &General::readhasharray("$confighost", \%customhost);
1109 &General::readhasharray("$configccdhost", \%ccdhost);
1110 &General::readhasharray("$configgrp", \%customgrp);
1111 &General::readhasharray("$configipsec", \%ipsecconf);
1112 &General::get_aliases(\%aliases);
1113 my %checked=();
1114 my $helper;
1115 my $sum=0;
1116 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
1117 my $config=$fwdfwsettings{'config'};
1118 my %hash=();
1119 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1120 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1121 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1122 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1123 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1124 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1125 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1126 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1127 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1128 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1129 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1130 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1131 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1132 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1133 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1134 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1135 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1136 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1137 #check if update and get values
1138 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
1139 &General::readhasharray("$config", \%hash);
1140 foreach my $key (sort keys %hash){
1141 $sum++;
1142 if ($key eq $fwdfwsettings{'key'}){
1143 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
1144 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
1145 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1146 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1147 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1148 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1149 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1150 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1151 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1152 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1153 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1154 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1155 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1156 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1157 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1158 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1159 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1160 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1161 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1162 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1163 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1164 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1165 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1166 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1167 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1168 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1169 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1170 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
1171 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1172 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1173 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1174 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1175 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1176 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1177 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1178 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1179 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1180 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1181 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1182 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1183 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1184 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1185 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1186 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1187 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1188 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1189 }
1190 }
1191 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1192 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1193 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1194 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1195 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1196 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1197 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1198 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1199 #check if manual ip (source) is orange network
1200 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1201 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1202 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1203 $fwdfwsettings{'oldorange'} ='on';
1204 }
1205 }
1206 }else{
1207 $fwdfwsettings{'ACTIVE'}='ON';
1208 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1209 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1210 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1211 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1212 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1213 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1214 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1215 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1216 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1217 #check if manual ip (source) is orange network
1218 if ($fwdfwsettings{'grp1'} eq 'src_addr'){
1219 my ($sip,$scidr) = split("/",$fwdfwsettings{$fwdfwsettings{'grp1'}});
1220 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1221 $fwdfwsettings{'oldorange'} ='on';
1222 }
1223 }
1224 }
1225 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
1226
1227 print <<END;
1228 <form method="post">
1229 <table border='0'>
1230 <tr><td nowrap>$Lang::tr{'fwdfw rule action'}</td><td><select name='RULE_ACTION'>
1231 END
1232 foreach ("ACCEPT","DROP","REJECT")
1233 {
1234 if($fwdfwsettings{'updatefwrule'} eq 'on'){
1235 print"<option ";
1236 print "selected='selected'" if ($fwdfwsettings{'RULE_ACTION'} eq $_);
1237 print">$_</option>";
1238 }else{
1239 if($fwdfwsettings{'POLICY'} eq 'MODE2'){
1240 $fwdfwsettings{'RULE_ACTION'} = 'DROP';
1241 }
1242
1243 if ($_ eq $fwdfwsettings{'RULE_ACTION'})
1244 {
1245 print"<option selected>$_</option>";
1246 }else{
1247 print"<option>$_</option>";
1248 }
1249 }
1250 }
1251 print"</select></td></tr></table><hr>";
1252
1253 &Header::closebox();
1254 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'});
1255 #------SOURCE-------------------------------------------------------
1256 print<<END;
1257 <table width='100%' border='0'>
1258 <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'}' ></td></tr>
1259 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr>
1260 <tr><td width='1%'><input type='radio' name='grp1' value='std_net_src' $checked{'grp1'}{'std_net_src'}></td><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost stdnet'}</td><td width='13%'><select name='std_net_src' style='min-width:185px;'>
1261 END
1262 foreach my $network (sort keys %defaultNetworks)
1263 {
1264 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
1265 next if($defaultNetworks{$network}{'NAME'} eq "RED");
1266 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1267 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $defaultNetworks{$network}{'NAME'});
1268 print ">$network</option>";
1269 }
1270 print<<END;
1271 </select></td><td width='1%'><input type='radio' name='grp1' value='ovpn_net_src' $checked{'grp1'}{'ovpn_net_src'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_net_src' style='min-width:185px;'>
1272 END
1273 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{'grp1'}});
1274 print<<END;
1275 </select></td></tr>
1276 <tr><td><input type='radio' name='grp1' value='cust_net_src' $checked{'grp1'}{'cust_net_src'}></td><td>$Lang::tr{'fwhost cust net'}</td><td><select name='cust_net_src' style='min-width:185px;'>
1277 END
1278 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{'grp1'}});
1279 print<<END;
1280 </select></td><td width='1%'><input type='radio' name='grp1' value='ovpn_host_src' $checked{'grp1'}{'ovpn_host_src'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_host_src' style='min-width:185px;'>
1281 END
1282 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost)
1283 {
1284 if ($ccdhost{$key}[33] ne ''){
1285
1286 print "<option value='$ccdhost{$key}[1]'";
1287 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ccdhost{$key}[1]);
1288 print ">$ccdhost{$key}[1]</option>";
1289 }
1290 }
1291 print<<END;
1292 </select></td></tr>
1293 <tr><td valign='top'><input type='radio' name='grp1' value='cust_host_src' $checked{'grp1'}{'cust_host_src'}></td><td>$Lang::tr{'fwhost cust addr'}</td><td><select name='cust_host_src' style='min-width:185px;'>
1294 END
1295 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{'grp1'}});
1296 print<<END;
1297 </select></td><td width='1%'><input type='radio' name='grp1' value='ovpn_n2n_src' $checked{'grp1'}{'ovpn_n2n_src'}></td><td >$Lang::tr{'fwhost ovpn_n2n'}</td><td colspan='3'><select name='ovpn_n2n_src' style='min-width:185px;'>
1298 END
1299 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) {
1300 if($ccdhost{$key}[3] eq 'net'){
1301 print"<option ";
1302 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ccdhost{$key}[1]);
1303 print ">$ccdhost{$key}[1]</option>";
1304 }
1305 }
1306 print<<END;
1307 </select></td></tr>
1308
1309 <tr><td valign='top'><input type='radio' name='grp1' value='cust_grp_src' $checked{'grp1'}{'cust_grp_src'}></td><td >$Lang::tr{'fwhost cust grp'}</td><td><select name='cust_grp_src' style='min-width:185px;'>
1310 END
1311 foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } keys %customgrp) {
1312 if($helper ne $customgrp{$key}[0]){
1313 print"<option ";
1314 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $customgrp{$key}[0]);
1315 print ">$customgrp{$key}[0]</option>";
1316 }
1317 $helper=$customgrp{$key}[0];
1318 }
1319 print<<END;
1320 </select></td>
1321 <td valign='top'><input type='radio' name='grp1' value='ipsec_net_src' $checked{'grp1'}{'ipsec_net_src'}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td><select name='ipsec_net_src' style='min-width:185px;'>
1322 END
1323 foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1324 if ($ipsecconf{$key}[3] eq 'net'){
1325 print "<option ";
1326 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ipsecconf{$key}[1]);
1327 print ">$ipsecconf{$key}[1]</option>";
1328 }
1329 }
1330 #sourceport
1331 print<<END;
1332 </select></td></tr>
1333 END
1334
1335 # <td valign='top'><input type='radio' name='grp1' value='ipsec_host_src' $checked{'grp1'}{'ipsec_host_src'}></td><td >$Lang::tr{'fwhost ipsec host'}</td><td><select name='ipsec_host_src' style='min-width:185px;'>
1336 #END
1337 # foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1338 # if ($ipsecconf{$key}[3] eq 'host'){
1339 # print "<option ";
1340 # print "selected='selected'" if($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ipsecconf{$key}[1]);
1341 # print ">$ipsecconf{$key}[1]</option>";
1342 # }
1343 # }
1344 print<<END;
1345 <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
1346 <table width='100%' border='0'>
1347 <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>
1348 <td width='15%' nowrap='nowrap'>$Lang::tr{'fwdfw man port'}</td><td><select name='PROT'>
1349 END
1350 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
1351 {
1352 if ($_ eq $fwdfwsettings{'PROT'})
1353 {
1354 print"<option selected>$_</option>";
1355 }else{
1356 print"<option>$_</option>";
1357 }
1358 }
1359 $fwdfwsettings{'SRC_PORT'}=~ s/\|/,/g;
1360 print<<END;
1361 </select></td><td align='right'><input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18' ></td></tr>
1362 <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;'>
1363 END
1364 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1365 print"<option>All ICMP-Types</option>";
1366 foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) } keys %icmptypes){
1367 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1368 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1369 }else{
1370 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1371 }
1372 }
1373 print<<END;
1374 </select></td></tr></table><br><hr>
1375 END
1376 &Header::closebox();
1377
1378 #---TARGET------------------------------------------------------
1379 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw target'});
1380 print<<END;
1381 <table width='100%' border='0'>
1382 <tr><td width='1%'><input type='radio' name='grp2' value='tgt_addr' checked></td><td colspan='2'>$Lang::tr{'fwdfw targetip'}<input type='TEXT' name='tgt_addr' value='$fwdfwsettings{'tgt_addr'}' size='16'><td><input type='radio' name='grp2' value='ipfire' $checked{'grp2'}{'ipfire'}></td><td><b>IPFire ($Lang::tr{'external access'})</b></td><td><select name='ipfire' style='min-width:185px;'>
1383 END
1384 print "<option value='Default IP' $selected{'ipfire'}{'Default IP'}>Default IP</option>";
1385
1386 foreach my $alias (sort keys %aliases)
1387 {
1388 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1389 }
1390
1391 print<<END;
1392 </td></tr>
1393 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr>
1394 <tr><td width='1%'><input type='radio' name='grp2' value='std_net_tgt' $checked{'grp2'}{'std_net_tgt'}></td><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost stdnet'}</td><td width='13%'><select name='std_net_tgt' style='min-width:185px;'>
1395 END
1396 foreach my $network (sort keys %defaultNetworks)
1397 {
1398 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1399 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1400 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $defaultNetworks{$network}{'NAME'});
1401 print ">$network</option>";
1402 }
1403 print<<END;
1404 </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_net_tgt' $checked{'grp2'}{'ovpn_net_tgt'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_net_tgt' style='min-width:185px;'>
1405 END
1406 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{'grp2'}});
1407 print<<END;
1408 </select></td></tr>
1409 <tr><td><input type='radio' name='grp2' value='cust_net_tgt' $checked{'grp2'}{'cust_net_tgt'}></td><td>$Lang::tr{'fwhost cust net'}</td><td><select name='cust_net_tgt' style='min-width:185px;'>
1410 END
1411 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{'grp2'}});
1412 print<<END;
1413 </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_host_tgt' $checked{'grp2'}{'ovpn_host_tgt'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_host_tgt' style='min-width:185px;'>
1414 END
1415 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost)
1416 {
1417 if ($ccdhost{$key}[33] ne ''){
1418 print "<option value='$ccdhost{$key}[1]' ";
1419 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ccdhost{$key}[33]);
1420 print ">$ccdhost{$key}[1]</option>";
1421 }
1422 }
1423 print<<END;
1424 </select></td></tr>
1425 <tr><td valign='top'><input type='radio' name='grp2' value='cust_host_tgt' $checked{'grp2'}{'cust_host_tgt'}></td><td>$Lang::tr{'fwhost cust addr'}</td><td><select name='cust_host_tgt' style='min-width:185px;'>
1426 END
1427 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{'grp2'}});
1428 print<<END;
1429 </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_n2n_tgt' $checked{'grp2'}{'ovpn_n2n_tgt'}></td><td >$Lang::tr{'fwhost ovpn_n2n'}</td><td colspan='3'><select name='ovpn_n2n_tgt' style='min-width:185px;'>
1430 END
1431 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) {
1432 if($ccdhost{$key}[3] eq 'net'){
1433 print "<option ";
1434 print "selected='selected'" if($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ccdhost{$key}[1]);
1435 print ">$ccdhost{$key}[1]</option>";
1436 }
1437 }
1438 print<<END;
1439 </select></td></tr>
1440 <tr><td valign='top'><input type='radio' name='grp2' value='cust_grp_tgt' $checked{'grp2'}{'cust_grp_tgt'}></td><td >$Lang::tr{'fwhost cust grp'}</td><td><select name='cust_grp_tgt' style='min-width:185px;'>
1441 END
1442 $helper='';
1443 foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } keys %customgrp) {
1444 if($helper ne $customgrp{$key}[0]){
1445 print"<option ";
1446 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $customgrp{$key}[0]);
1447 print">$customgrp{$key}[0]</option>";
1448 }
1449 $helper=$customgrp{$key}[0];
1450 }
1451 print<<END;
1452 </select></td>
1453 <td valign='top'><input type='radio' name='grp2' value='ipsec_net_tgt' $checked{'grp2'}{'ipsec_net_tgt'}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td><select name='ipsec_net_tgt' style='min-width:185px;'>
1454 END
1455 foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1456 if ($ipsecconf{$key}[3] eq 'net'){
1457 print"<option ";
1458 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ipsecconf{$key}[1]);
1459 print">$ipsecconf{$key}[1]</option>";
1460 }
1461 }
1462 print<<END;
1463 </select></td></tr>
1464 END
1465 # <td valign='top'><input type='radio' name='grp2' value='ipsec_host_tgt' $checked{'grp2'}{'ipsec_host_tgt'}></td><td >$Lang::tr{'fwhost ipsec host'}</td><td><select name='ipsec_host_tgt' style='min-width:185px;'>
1466 #END
1467 # foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1468 # if ($ipsecconf{$key}[3] eq 'host'){
1469 # print"<option ";
1470 # print"selected='Selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ipsecconf{$key}[1]);
1471 # print">$ipsecconf{$key}[1]</option>";
1472 # }
1473 # }
1474 print<<END;
1475 </table>
1476 <b>$Lang::tr{'fwhost attention'}:</b><br>
1477 $Lang::tr{'fwhost macwarn'}<br><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; '></hr><br>
1478
1479 <table width='100%' border='0'>
1480 <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;' >
1481 END
1482 &General::readhasharray("$configsrv", \%customservice);
1483 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
1484 print"<option ";
1485 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1486 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1487 }
1488 print<<END;
1489 </select></td></tr>
1490 <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;' >
1491 END
1492 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1493 my $helper;
1494 foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){
1495 if ($helper ne $customservicegrp{$key}[0]){
1496 print"<option ";
1497 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1498 print">$customservicegrp{$key}[0]</option>";
1499 }
1500 $helper=$customservicegrp{$key}[0];
1501 }
1502 print<<END;
1503 </select></td></tr>
1504 <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'>
1505 END
1506 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
1507 {
1508 if ($_ eq $fwdfwsettings{'TGT_PROT'})
1509 {
1510 print"<option selected>$_</option>";
1511 }else{
1512 print"<option>$_</option>";
1513 }
1514 }
1515 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
1516 print<<END;
1517 </select></td><td align='right'><input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18' ></td></tr>
1518 <tr><td colspan='2'></td><td></td><td>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TGT' style='min-width:230px;'>
1519 END
1520 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1521 print"<option>All ICMP-Types</option>";
1522 foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) }keys %icmptypes){
1523 if($fwdfwsettings{'ICMP_TGT'} eq "$icmptypes{$key}[0]"){
1524 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1525 }else{
1526 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1527 }
1528 }
1529 print<<END;
1530 </select></td></tr>
1531 </table><br><hr>
1532
1533 END
1534 &Header::closebox;
1535 #---Activate/logging/remark-------------------------------------
1536 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw additional'});
1537 print<<END;
1538 <table width='100%' border='0'>
1539 <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>
1540 END
1541 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
1542 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
1543 for (my $count =1; $count <= $sum; $count++){
1544 print"<option value='$count' ";
1545 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
1546 print">$count</option>";
1547 }
1548 print"</select></td></tr>";
1549 }else{
1550 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
1551 }
1552
1553 print<<END;
1554 </table><table width='100%'>
1555 <tr><td width='1%'><input type='checkbox' name='ACTIVE' value='ON' $checked{'ACTIVE'}{'ON'}></td><td>$Lang::tr{'fwdfw rule activate'}</td></tr>
1556 <tr><td width='1%'><input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'} ></td><td>$Lang::tr{'fwdfw log rule'}</td></tr>
1557 </table><br><hr>
1558 END
1559 &Header::closebox();
1560 #---ADD TIMEFRAME-----------------------------------------------
1561 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw timeframe'});
1562 print<<END;
1563 <table width='70%' border='0'>
1564 <tr><td width='1%'><input type='checkbox' name='TIME' value='ON' $checked{'TIME'}{'ON'}></td><td colspan='4'>$Lang::tr{'fwdfw timeframe'}</td></tr>
1565 <tr><td colspan='7'>&nbsp</td></tr>
1566 <tr>
1567 <td align='left'>$Lang::tr{'time'}:</td>
1568 <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>
1569 <td width='15%' align='left'>$Lang::tr{'advproxy from'}</td>
1570 <td width='15%' align='left'>$Lang::tr{'advproxy to'}</td>
1571 </tr>
1572 <tr>
1573 <td align='right'></td>
1574 <td width='30%' align='left'>
1575 <input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} />
1576 <input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} />
1577 <input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} />
1578 <input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} />
1579 <input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} />
1580 <input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} />
1581 <input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} />
1582 </td>
1583 <td><select name='TIME_FROM'>
1584 END
1585 for (my $i=0;$i<=23;$i++) {
1586 $i = sprintf("%02s",$i);
1587 for (my $j=0;$j<=45;$j+=15) {
1588 $j = sprintf("%02s",$j);
1589 my $time = $i.":".$j;
1590 print "\t\t\t\t\t<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
1591 }
1592 }
1593 print<<END;
1594 </select></td>
1595 <td><select name='TIME_TO'>
1596 END
1597 for (my $i=0;$i<=23;$i++) {
1598 $i = sprintf("%02s",$i);
1599 for (my $j=0;$j<=45;$j+=15) {
1600 $j = sprintf("%02s",$j);
1601 my $time = $i.":".$j;
1602 print "\t\t\t\t\t<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
1603 }
1604 }
1605 print<<END;
1606 </select></td></tr>
1607 </table><br><hr>
1608 END
1609
1610 #---ACTION------------------------------------------------------
1611 if($fwdfwsettings{'updatefwrule'} ne 'on'){
1612 print<<END;
1613 <table border='0' width='100%'>
1614 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
1615 <input type='hidden' name='config' value='$config' >
1616 <input type='hidden' name='ACTION' value='saverule' >
1617 </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>
1618 </table></form>
1619 END
1620 }else{
1621 print<<END;
1622 <table border='0' width='100%'>
1623 <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'}'>
1624 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
1625 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
1626 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
1627 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
1628 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
1629 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
1630 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
1631 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
1632 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
1633 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
1634 <input type='hidden' name='oldorange' value='$fwdfwsettings{'oldorange'}' />
1635 <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>
1636 </table></form>
1637 END
1638 }
1639 &Header::closebox();
1640 }
1641 sub saverule
1642 {
1643 my $hash=shift;
1644 my $config=shift;
1645 &General::readhasharray("$config", $hash);
1646 if (!$errormessage){
1647 #check if we change a DMZ to an outgoing
1648 if( ($fwdfwsettings{'oldgrp1b'} eq 'ORANGE' || $fwdfwsettings{'oldorange'} eq 'on') && $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1649 &changerule($configdmz);
1650 #print"1";
1651 }
1652 #check if we change a DMZ to an external access
1653 elsif( $fwdfwsettings{'oldgrp1b'} eq 'ORANGE' && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ORANGE' && $fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1654 &changerule($configdmz);
1655 #print"2";
1656 }
1657 #check if we change an external access rule to a outgoing
1658 elsif( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'oldgrp1b'} ne 'IPFire' && $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'oldgrp2a'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1659 &changerule($configinput);
1660 #print"3";
1661 }
1662 #check if we change an external access rule to a DMZ
1663 elsif( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' && $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'oldgrp2a'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1664 &changerule($configinput);
1665 #print"4";
1666 }
1667 #check if we change an outgoing rule to a external access
1668 if( $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'IPFire' && $fwdfwsettings{'oldgrp1b'} eq 'IPFire' && $fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{'oldgrp2a'} ne 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1669 &changerule($configoutgoing);
1670 #print"5";
1671 }
1672 #check if we change an outgoing rule to a DMZ
1673 if( ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' || $checkorange eq 'on') && $fwdfwsettings{'oldgrp1b'} eq 'IPFire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1674 &changerule($configoutgoing);
1675 #print"6";
1676 }
1677 #check if we change an forward rule to an external access
1678 elsif( $fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{'oldgrp2a'} ne 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1679 &changerule($configfwdfw);
1680 #print"7";
1681 }
1682 #check if we change an forward rule to an DMZ
1683 if( ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'ORANGE' || $checkorange eq 'on') && ($fwdfwsettings{'oldgrp1b'} ne 'ORANGE' && $fwdfwsettings{'oldorange'} ne 'on') && $fwdfwsettings{'updatefwrule'} eq 'on'){
1684 &changerule($configfwdfw);
1685 #print"8";
1686 }
1687 #check if we change an forward rule to an outgoing
1688 elsif( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'oldgrp1b'} ne 'IPFire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1689 &changerule($configfwdfw);
1690 #print"9";
1691 }
1692 #check if we change a DMZ to a forward
1693 elsif( ($fwdfwsettings{'oldgrp1b'} eq 'ORANGE' || $fwdfwsettings{'oldorange'} eq 'on') && ($fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ORANGE' && $checkorange ne 'on') && $fwdfwsettings{'updatefwrule'} eq 'on'){
1694 &changerule($configdmz);
1695 #print"10";
1696 }
1697 #check if we change an external access rule to a forward
1698 elsif( $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'oldgrp2a'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1699 &changerule($configinput);
1700 #print"11";
1701 }
1702 #check if we change an outgoing rule to a forward
1703 elsif( $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'IPFire' && $fwdfwsettings{'oldgrp1b'} eq 'IPFire' && $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
1704 &changerule($configoutgoing);
1705 #print"12";
1706 }
1707 if ($fwdfwsettings{'updatefwrule'} ne 'on'){
1708 my $key = &General::findhasharraykey ($hash);
1709 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1710 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1711 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1712 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1713 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1714 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1715 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1716 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1717 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1718 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1719 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1720 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1721 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1722 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1723 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1724 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1725 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1726 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1727 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1728 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1729 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1730 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1731 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1732 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1733 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1734 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1735 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1736 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
1737 &General::writehasharray("$config", $hash);
1738 }else{
1739 foreach my $key (sort {$a <=> $b} keys %$hash){
1740 if($key eq $fwdfwsettings{'key'}){
1741 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1742 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1743 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1744 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1745 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1746 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1747 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1748 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1749 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1750 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1751 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1752 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1753 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1754 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1755 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1756 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1757 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1758 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1759 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1760 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1761 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1762 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1763 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1764 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1765 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1766 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1767 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1768 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
1769 last;
1770 }
1771 }
1772 }
1773 &General::writehasharray("$config", $hash);
1774 if($fwdfwsettings{'oldrulenumber'} > $fwdfwsettings{'rulepos'}){
1775 my %tmp=();
1776 my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'};
1777 for (my $z=0;$z<$val;$z++){
1778 foreach my $key (sort {$a <=> $b} keys %$hash){
1779 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
1780 my $last = $key -1;
1781 if (exists $$hash{$last}){
1782 #save rule last
1783 foreach my $y (0 .. $#{$$hash{$last}}) {
1784 $tmp{0}[$y] = $$hash{$last}[$y];
1785 }
1786 #copy active rule to last
1787 foreach my $i (0 .. $#{$$hash{$last}}) {
1788 $$hash{$last}[$i] = $$hash{$key}[$i];
1789 }
1790 #copy saved rule to actual position
1791 foreach my $x (0 .. $#{$tmp{0}}) {
1792 $$hash{$key}[$x] = $tmp{0}[$x];
1793 }
1794 }
1795 }
1796 }
1797 $fwdfwsettings{'oldrulenumber'}--;
1798 }
1799 &General::writehasharray("$config", $hash);
1800 &rules;
1801 }elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
1802 my %tmp=();
1803 my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
1804 for (my $z=0;$z<$val;$z++){
1805 foreach my $key (sort {$a <=> $b} keys %$hash){
1806 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
1807 my $next = $key + 1;
1808 if (exists $$hash{$next}){
1809 #save rule next
1810 foreach my $y (0 .. $#{$$hash{$next}}) {
1811 $tmp{0}[$y] = $$hash{$next}[$y];
1812 }
1813 #copy active rule to next
1814 foreach my $i (0 .. $#{$$hash{$next}}) {
1815 $$hash{$next}[$i] = $$hash{$key}[$i];
1816 }
1817 #copy saved rule to actual position
1818 foreach my $x (0 .. $#{$tmp{0}}) {
1819 $$hash{$key}[$x] = $tmp{0}[$x];
1820 }
1821 }
1822 }
1823 }
1824 $fwdfwsettings{'oldrulenumber'}++;
1825 }
1826 &General::writehasharray("$config", $hash);
1827 &rules;
1828 }
1829 }
1830 }
1831 sub error
1832 {
1833 if ($errormessage) {
1834 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1835 print "<class name='base'>$errormessage\n";
1836 print "&nbsp;</class>\n";
1837 &Header::closebox();
1838 print"<hr>";
1839 }
1840 }
1841 sub hint
1842 {
1843 if ($hint) {
1844 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1845 print "<class name='base'>$hint\n";
1846 print "&nbsp;</class>\n";
1847 &Header::closebox();
1848 print"<hr>";
1849 }
1850 }
1851 sub get_name
1852 {
1853 my $val=shift;
1854 &General::setup_default_networks(\%defaultNetworks);
1855 foreach my $network (sort keys %defaultNetworks)
1856 {
1857 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1858 }
1859 }
1860 sub validremark
1861 {
1862 # Checks a hostname against RFC1035
1863 my $remark = $_[0];
1864
1865 # Each part should be at least two characters in length
1866 # but no more than 63 characters
1867 if (length ($remark) < 1 || length ($remark) > 255) {
1868 return 0;}
1869 # Only valid characters are a-z, A-Z, 0-9 and -
1870 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
1871 return 0;}
1872 # First character can only be a letter or a digit
1873 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
1874 return 0;}
1875 # Last character can only be a letter or a digit
1876 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
1877 return 0;}
1878 return 1;
1879 }
1880 sub getsrcport
1881 {
1882 my %hash=%{(shift)};
1883 my $key=shift;
1884 if($hash{$key}[7] eq 'ON' && $hash{$key}[8] ne '' && $hash{$key}[10]){
1885 $hash{$key}[10]=~ s/\|/,/g;
1886 print": $hash{$key}[10]";
1887 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
1888 print": <br>$hash{$key}[9] ";
1889 }
1890 }
1891 sub gettgtport
1892 {
1893 my %hash=%{(shift)};
1894 my $key=shift;
1895 my $service;
1896 my $prot;
1897 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1898 if($hash{$key}[14] eq 'cust_srv'){
1899 &General::readhasharray("$configsrv", \%customservice);
1900 foreach my $i (sort keys %customservice){
1901 if($customservice{$i}[0] eq $hash{$key}[15]){
1902 $service = $customservice{$i}[0];
1903 }
1904 }
1905 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
1906 $service=$hash{$key}[15];
1907 }elsif($hash{$key}[14] eq 'TGT_PORT'){
1908 $hash{$key}[15]=~ s/\|/,/g;
1909 $service=$hash{$key}[15];
1910 }
1911 if($service){
1912 print": $service";
1913 }
1914 }elsif($hash{$key}[11] eq 'ON' && $hash{$key}[12] eq 'ICMP'){
1915 print":<br>$hash{$key}[13]";
1916 }
1917 }
1918 sub get_serviceports
1919 {
1920 my $type=shift;
1921 my $name=shift;
1922 &General::readhasharray("$configsrv", \%customservice);
1923 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1924 my $protocols;
1925 my $tcp;
1926 my $udp;
1927 if($type eq 'service'){
1928 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
1929 if ($customservice{$key}[0] eq $name){
1930 $protocols=$customservice{$key}[2];
1931 }
1932 }
1933 }elsif($type eq 'group'){
1934 foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){
1935 if ($customservicegrp{$key}[0] eq $name){
1936 foreach my $key1 (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
1937 if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
1938 if($customservice{$key1}[2] eq 'TCP'){$tcp='TCP';}else{$udp='UDP';}
1939 }
1940 }
1941 }
1942 }
1943 }
1944 if($tcp && $udp){$protocols="TCP,UDP";
1945 }elsif($tcp){$protocols.="TCP";
1946 }elsif($udp){$protocols.="UDP";}
1947 return $protocols;
1948 }
1949 sub viewtablerule
1950 {
1951 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
1952 &viewtablenew(\%configdmzfw,$configdmz,$Lang::tr{'fwdfw rules'},"DMZ" );
1953 &viewtablenew(\%configfwdfw,$configfwdfw,"","Forward" );
1954 &viewtablenew(\%configinputfw,$configinput,"",$Lang::tr{'external access'} );
1955 &viewtablenew(\%configoutgoingfw,$configoutgoing,"","Outgoing" );
1956 }
1957 sub viewtablenew
1958 {
1959 my $hash=shift;
1960 my $config=shift;
1961 my $title=shift;
1962 my $title1=shift;
1963 my $go='';
1964 &General::get_aliases(\%aliases);
1965 &General::readhasharray("$confighost", \%customhost);
1966 &General::readhasharray("$config", $hash);
1967 if( ! -z $config){
1968 &Header::openbox('100%', 'left',$title);
1969 my $count=0;
1970 my ($gif,$log);
1971 my $ruletype;
1972 my $rulecolor;
1973 my $tooltip;
1974 my @tmpsrc=();
1975 my $coloryellow='';
1976 print"<b>$title1</b><br>";
1977 print"<table width='100%' cellspacing='0' style=' padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;'>";
1978 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>";
1979 foreach my $key (sort {$a <=> $b} keys %$hash){
1980 $tdcolor='';
1981 @tmpsrc=();
1982 #check if vpn hosts/nets have been deleted
1983 if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){
1984 push (@tmpsrc,$$hash{$key}[4]);
1985 }
1986 if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){
1987 push (@tmpsrc,$$hash{$key}[6]);
1988 }
1989 foreach my $host (@tmpsrc){
1990 if($$hash{$key}[3] eq 'ipsec_net_src' || $$hash{$key}[5] eq 'ipsec_net_tgt'){
1991 if(&fwlib::get_ipsec_net_ip($host,11) eq ''){
1992 $coloryellow='on';
1993 &disable_rule($key);
1994 $$hash{$key}[2]='';
1995 }
1996 }elsif($$hash{$key}[3] eq 'ovpn_net_src' || $$hash{$key}[5] eq 'ovpn_net_tgt'){
1997 if(&fwlib::get_ovpn_net_ip($host,1) eq ''){
1998 $coloryellow='on';
1999 &disable_rule($key);
2000 $$hash{$key}[2]='';
2001 }
2002 }elsif($$hash{$key}[3] eq 'ovpn_n2n_src' || $$hash{$key}[5] eq 'ovpn_n2n_tgt'){
2003 if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){
2004 $coloryellow='on';
2005 &disable_rule($key);
2006 $$hash{$key}[2]='';
2007 }
2008 }elsif($$hash{$key}[3] eq 'ovpn_host_src' || $$hash{$key}[5] eq 'ovpn_host_tgt'){
2009 if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
2010 $coloryellow='on';
2011 &disable_rule($key);
2012 $$hash{$key}[2]='';
2013 }
2014 }
2015 #$$hash{$key}[3]='';
2016 #$$hash{$key}[5]='';
2017 }
2018 $$hash{'ACTIVE'}=$$hash{$key}[2];
2019 $count++;
2020 if($coloryellow eq 'on'){
2021 print"<tr bgcolor='$color{'color14'}' >";
2022 $coloryellow='';
2023 }elsif($coloryellow eq ''){
2024 if ($count % 2){
2025 $color="$color{'color22'}";
2026 }
2027 else{
2028 $color="$color{'color20'}";
2029 }
2030 }
2031 print"<tr bgcolor='$color' >";
2032 print<<END;
2033 <td align='right' width='15'><b>$key</b></td>
2034 END
2035 if ($$hash{$key}[0] eq 'ACCEPT'){
2036 $ruletype='A';
2037 $tooltip='ACCEPT';
2038 $rulecolor=$color{'color17'};
2039 }elsif($$hash{$key}[0] eq 'DROP'){
2040 $ruletype='D';
2041 $tooltip='DROP';
2042 $rulecolor=$color{'color25'};
2043 }elsif($$hash{$key}[0] eq 'REJECT'){
2044 $ruletype='R';
2045 $tooltip='REJECT';
2046 $rulecolor=$color{'color16'};
2047 }
2048 print"<td bgcolor='$rulecolor' align='center' width='20'><span title='$tooltip'><b>$ruletype</b></span></td>";
2049 &getcolor($$hash{$key}[3],$$hash{$key}[4],\%customhost);
2050 print"<td align='center' width='160' $tdcolor>";
2051 if ($$hash{$key}[3] eq 'std_net_src'){
2052 print &get_name($$hash{$key}[4]);
2053 }else{
2054 print $$hash{$key}[4];
2055 }
2056 $tdcolor='';
2057 &getsrcport(\%$hash,$key);
2058 if ($$hash{$key}[17] eq 'ON'){
2059 $log="/images/on.gif";
2060 }else{
2061 $log="/images/off.gif";
2062 }
2063 print<<END;
2064 </td>
2065 <form method='post'>
2066 <td align='left' width='25'><input type='image' img src='$log' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw togglelog'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;'/>
2067 <input type='hidden' name='key' value='$key' />
2068 <input type='hidden' name='config' value='$config' />
2069 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw togglelog'}' />
2070 </td></form>
2071 END
2072 &getcolor($$hash{$key}[5],$$hash{$key}[6],\%customhost);
2073 print<<END;
2074 <td align='center' width='160' $tdcolor>
2075 END
2076 if ($$hash{$key}[5] eq 'std_net_tgt'){
2077 print &get_name($$hash{$key}[6]);
2078 }else{
2079 print $$hash{$key}[6];
2080 }
2081 $tdcolor='';
2082 &gettgtport(\%$hash,$key);
2083 print"</td>";
2084 #Get Protocol
2085 my $prot;
2086 if ($$hash{$key}[12]){ #target prot if manual
2087 $prot=$$hash{$key}[12];
2088 }elsif($$hash{$key}[8]){ #source prot if manual
2089 $prot=$$hash{$key}[8];
2090 }elsif($$hash{$key}[14] eq 'cust_srv'){
2091 $prot=&get_serviceports("service",$$hash{$key}[15]);
2092 }elsif($$hash{$key}[14] eq 'cust_srvgrp'){
2093 $prot=&get_serviceports("group",$$hash{$key}[15]);
2094 }else{
2095 $prot=$Lang::tr{'all'};
2096 }
2097 print"<td align='center'>$prot</td>";
2098 if ($$hash{$key}[18] eq 'ON'){
2099 my @days=();
2100 if($$hash{$key}[19] ne ''){push (@days,$Lang::tr{'fwdfw wd_mon'});}
2101 if($$hash{$key}[20] ne ''){push (@days,$Lang::tr{'fwdfw wd_tue'});}
2102 if($$hash{$key}[21] ne ''){push (@days,$Lang::tr{'fwdfw wd_wed'});}
2103 if($$hash{$key}[22] ne ''){push (@days,$Lang::tr{'fwdfw wd_thu'});}
2104 if($$hash{$key}[23] ne ''){push (@days,$Lang::tr{'fwdfw wd_fri'});}
2105 if($$hash{$key}[24] ne ''){push (@days,$Lang::tr{'fwdfw wd_sat'});}
2106 if($$hash{$key}[25] ne ''){push (@days,$Lang::tr{'fwdfw wd_sun'});}
2107 my $weekdays=join(",",@days);
2108 if (@days){
2109 print"<td align='center' width='100'>$weekdays &nbsp $$hash{$key}[26] - $$hash{$key}[27]</td>";
2110 }
2111 }else{
2112 print"<td align='center'>24/7</td>";
2113 }
2114 if($$hash{$key}[2] eq 'ON'){
2115 $gif="/images/on.gif"
2116
2117 }else{
2118 $gif="/images/off.gif"
2119 }
2120 print<<END;
2121 <form method='post'>
2122 <td width='25'><input type='image' img src='$gif' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw toggle'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2123 <input type='hidden' name='key' value='$key' />
2124 <input type='hidden' name='config' value='$config' />
2125 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw toggle'}' />
2126 </td></form>
2127 <form method='post'>
2128 <td width='25' ><input type='image' img src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'fwdfw edit'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2129 <input type='hidden' name='key' value='$key' />
2130 <input type='hidden' name='config' value='$config' />
2131 <input type='hidden' name='ACTION' value='editrule' />
2132 </td></form></td>
2133 <form method='post'>
2134 <td width='25'><input type='image' img src='/images/addblue.gif' alt='$Lang::tr{'fwdfw copy'}' title='$Lang::tr{'fwdfw copy'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2135 <input type='hidden' name='key' value='$key' />
2136 <input type='hidden' name='config' value='$config' />
2137 <input type='hidden' name='ACTION' value='copyrule' />
2138 </td></form></td>
2139 <form method='post'>
2140 <td width='25' ><input type='image' img src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'fwdfw delete'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2141 <input type='hidden' name='key' value='$key' />
2142 <input type='hidden' name='config' value='$config' />
2143 <input type='hidden' name='ACTION' value='deleterule' />
2144 </td></form></td>
2145 END
2146 if (exists $$hash{$key-1}){
2147 print<<END;
2148 <form method='post'>
2149 <td width='25'><input type='image' img src='/images/up.gif' alt='$Lang::tr{'fwdfw moveup'}' title='$Lang::tr{'fwdfw moveup'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2150 <input type='hidden' name='key' value='$key' />
2151 <input type='hidden' name='config' value='$config' />
2152 <input type='hidden' name='ACTION' value='moveup' />
2153 </td></form></td>
2154 END
2155 }else{
2156 print"<td width='25'><input type='image' img src='/images/up.gif' style='visibility:hidden;'></td>";
2157 }
2158 if (exists $$hash{$key+1}){
2159 print<<END;
2160 <form method='post'>
2161 <td width='25' ><input type='image' img src='/images/down.gif' alt='$Lang::tr{'fwdfw movedown'}' title='$Lang::tr{'fwdfw movedown'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
2162 <input type='hidden' name='key' value='$key' />
2163 <input type='hidden' name='config' value='$config' />
2164 <input type='hidden' name='ACTION' value='movedown' />
2165 </td></form></td></tr>
2166 END
2167 }else{
2168 print"<td width='25'><input type='image' img src='/images/down.gif' style='visibility:hidden;'></td></tr>";
2169 }
2170 #REMARK
2171 if ($optionsfw{'SHOWREMARK'} eq 'on'){
2172 print"<tr bgcolor='$color'>";
2173 print"<td>&nbsp</td><td bgcolor='$rulecolor'></td><td colspan='11'>&nbsp $$hash{$key}[16]</td></tr>";
2174 }
2175 }
2176 print"</table>";
2177 &Header::closebox();
2178 print "<hr>";
2179 print "<br><br>";
2180 }else{
2181 if ($optionsfw{'SHOWTABLES'} eq 'on'){
2182 print "<b>$title1</b><br>";
2183 print"<table width='100%' border='0' rules='none'><tr><td height='30' bgcolor=$color{'color22'} align='center'>$Lang::tr{'fwhost empty'}</td></tr></table><br><br>";
2184 }
2185 }
2186 }
2187 sub getcolor
2188 {
2189 my $nettype=shift;
2190 my $val=shift;
2191 my $hash=shift;
2192 if($optionsfw{'SHOWCOLORS'} eq 'on'){
2193 #VPN networks
2194 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'){
2195 $tdcolor="style='border: 1px solid $Header::colourovpn;'";
2196 return;
2197 }
2198 if ($nettype eq 'ipsec_net_src' || $nettype eq 'ipsec_net_tgt'){
2199 $tdcolor="style='border: 1px solid $Header::colourvpn;'";
2200 return;
2201 }
2202 #custom Hosts
2203 if ($nettype eq 'cust_host_src' || $nettype eq 'cust_host_tgt'){
2204 foreach my $key (sort keys %$hash){
2205 if ($$hash{$key}[0] eq $val){
2206 $val=$$hash{$key}[2];
2207 }
2208 }
2209 }
2210 #ALIASE
2211 foreach my $alias (sort keys %aliases)
2212 {
2213 if ($val eq $alias){
2214 $tdcolor="style='border: 2px solid red;'";
2215 return;
2216 }
2217 }
2218 #standard networks
2219 if ($val eq 'GREEN'){
2220 $tdcolor="style='border: 1px solid $Header::colourgreen;'";
2221 }elsif ($val eq 'ORANGE'){
2222 $tdcolor="style='border: 1px solid $Header::colourorange;'";
2223 }elsif ($val eq 'BLUE'){
2224 $tdcolor="style='border: 1px solid $Header::colourblue;'";
2225 }elsif ($val eq 'RED'){
2226 $tdcolor="style='border: 1px solid $Header::colourred;'";
2227 }elsif ($val eq 'IPFire' ){
2228 $tdcolor="style='border: 1px solid $Header::colourred;'";
2229 }elsif($val =~ /^(.*?)\/(.*?)$/){
2230 my ($sip,$scidr) = split ("/",$val);
2231 if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
2232 $tdcolor="style='border: 1px solid $Header::colourorange;'";
2233 }
2234 if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
2235 $tdcolor="style='border: 1px solid $Header::colourgreen;'";
2236 }
2237 if ( &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
2238 $tdcolor="style='border: 1px solid $Header::colourblue;'";
2239 }
2240 }elsif ($val eq 'Default IP'){
2241 $tdcolor="style='border: 1px solid red;'";
2242 }else{
2243 $tdcolor='';
2244 }
2245 }
2246 }
2247 sub fillselect
2248 {
2249 my %hash=%{(shift)};
2250 my $val=shift;
2251 my $key;
2252 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
2253 if($hash{$key}[0] eq $val){
2254 print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>";
2255 }else{
2256 print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>";
2257 }
2258 }
2259 }
2260 sub rules
2261 {
2262 if (!-f "${General::swroot}/forward/reread"){
2263 system("touch ${General::swroot}/forward/reread");
2264 system("touch ${General::swroot}/fwhosts/reread");
2265 }
2266 }
2267 sub reread_rules
2268 {
2269 system("/usr/local/bin/forwardfwctrl");
2270 if ( -f "${General::swroot}/forward/reread"){
2271 system("rm ${General::swroot}/forward/reread");
2272 system("rm ${General::swroot}/fwhosts/reread");
2273 }
2274 }
2275 &Header::closebigbox();
2276 &Header::closepage();