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