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