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