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