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