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