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