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