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