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