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