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