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