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