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