]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/outgoingfw.cgi
Removed mldonkey and ocaml.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / outgoingfw.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2005-2010 IPFire Team #
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 use strict;
23 # enable only the following on debugging purpose
24 #use warnings;
25 #use CGI::Carp 'fatalsToBrowser';
26
27 require '/var/ipfire/general-functions.pl';
28 require "${General::swroot}/lang.pl";
29 require "${General::swroot}/header.pl";
30
31 my %outfwsettings = ();
32 my %checked = ();
33 my %selected= () ;
34 my %netsettings = ();
35 my $errormessage = "";
36 my $configentry = "";
37 my @configs = ();
38 my @configline = ();
39 my $p2pentry = "";
40 my @p2ps = ();
41 my @p2pline = ();
42
43 my $configfile = "/var/ipfire/outgoing/rules";
44 my $configpath = "/var/ipfire/outgoing/groups/";
45 my $p2pfile = "/var/ipfire/outgoing/p2protocols";
46 my $servicefile = "/var/ipfire/outgoing/defaultservices";
47
48 my %color = ();
49 my %mainsettings = ();
50 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
51 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
52
53 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
54
55 &Header::showhttpheaders();
56
57 ### Values that have to be initialized
58 $outfwsettings{'ACTION'} = '';
59 $outfwsettings{'VALID'} = 'yes';
60 $outfwsettings{'EDIT'} = 'no';
61 $outfwsettings{'NAME'} = '';
62 $outfwsettings{'SNET'} = '';
63 $outfwsettings{'SIP'} = '';
64 $outfwsettings{'SPORT'} = '';
65 $outfwsettings{'SMAC'} = '';
66 $outfwsettings{'DIP'} = '';
67 $outfwsettings{'DPORT'} = '';
68 $outfwsettings{'PROT'} = '';
69 $outfwsettings{'STATE'} = '';
70 $outfwsettings{'DISPLAY_DIP'} = '';
71 $outfwsettings{'DISPLAY_DPORT'} = '';
72 $outfwsettings{'DISPLAY_SMAC'} = '';
73 $outfwsettings{'DISPLAY_SIP'} = '';
74 $outfwsettings{'POLICY'} = 'MODE0';
75 $outfwsettings{'MODE1LOG'} = 'off';
76
77 $outfwsettings{'TIME_FROM'} = '00:00';
78 $outfwsettings{'TIME_TO'} = '00:00';
79
80 &General::readhash("${General::swroot}/outgoing/settings", \%outfwsettings);
81 &Header::getcgihash(\%outfwsettings);
82
83 ###############
84 # DEBUG DEBUG
85 #&Header::openbox('100%', 'left', 'DEBUG');
86 #my $debugCount = 0;
87 #foreach my $line (sort keys %outfwsettings) {
88 #print "$line = $outfwsettings{$line}<br />\n";
89 # $debugCount++;
90 #}
91 #print "&nbsp;Count: $debugCount\n";
92 #&Header::closebox();
93 # DEBUG DEBUG
94 ###############
95
96 $selected{'TIME_FROM'}{$outfwsettings{'TIME_FROM'}} = "selected='selected'";
97 $selected{'TIME_TO'}{$outfwsettings{'TIME_TO'}} = "selected='selected'";
98
99 $checked{'MODE1LOG'}{'off'} = '';
100 $checked{'MODE1LOG'}{'on'} = '';
101 $checked{'MODE1LOG'}{$outfwsettings{'MODE1LOG'}} = "checked='checked'";
102 $checked{'TIME_MON'}{'off'} = '';
103 $checked{'TIME_MON'}{'on'} = '';
104 $checked{'TIME_MON'}{$outfwsettings{'TIME_MON'}} = "checked='checked'";
105 $checked{'TIME_TUE'}{'off'} = '';
106 $checked{'TIME_TUE'}{'on'} = '';
107 $checked{'TIME_TUE'}{$outfwsettings{'TIME_TUE'}} = "checked='checked'";
108 $checked{'TIME_WED'}{'off'} = '';
109 $checked{'TIME_WED'}{'on'} = '';
110 $checked{'TIME_WED'}{$outfwsettings{'TIME_WED'}} = "checked='checked'";
111 $checked{'TIME_THU'}{'off'} = '';
112 $checked{'TIME_THU'}{'on'} = '';
113 $checked{'TIME_THU'}{$outfwsettings{'TIME_THU'}} = "checked='checked'";
114 $checked{'TIME_FRI'}{'off'} = '';
115 $checked{'TIME_FRI'}{'on'} = '';
116 $checked{'TIME_FRI'}{$outfwsettings{'TIME_FRI'}} = "checked='checked'";
117 $checked{'TIME_SAT'}{'off'} = '';
118 $checked{'TIME_SAT'}{'on'} = '';
119 $checked{'TIME_SAT'}{$outfwsettings{'TIME_SAT'}} = "checked='checked'";
120 $checked{'TIME_SUN'}{'off'} = '';
121 $checked{'TIME_SUN'}{'on'} = '';
122 $checked{'TIME_SUN'}{$outfwsettings{'TIME_SUN'}} = "checked='checked'";
123
124 if ($outfwsettings{'POLICY'} eq 'MODE0'){ $selected{'POLICY'}{'MODE0'} = 'selected'; } else { $selected{'POLICY'}{'MODE0'} = ''; }
125 if ($outfwsettings{'POLICY'} eq 'MODE1'){ $selected{'POLICY'}{'MODE1'} = 'selected'; } else { $selected{'POLICY'}{'MODE1'} = ''; }
126 if ($outfwsettings{'POLICY'} eq 'MODE2'){ $selected{'POLICY'}{'MODE2'} = 'selected'; } else { $selected{'POLICY'}{'MODE2'} = ''; }
127
128 # This is a little hack if poeple donĀ“t mark any date then all will be selected, because they might have forgotten to select
129 # a valid day. A Rule without any matching day will never work, because the timeranges are new feature people might not notice
130 # that they have to select a day for the rule.
131
132 if ( $outfwsettings{'TIME_MON'} eq "" &&
133 $outfwsettings{'TIME_TUE'} eq "" &&
134 $outfwsettings{'TIME_WED'} eq "" &&
135 $outfwsettings{'TIME_THU'} eq "" &&
136 $outfwsettings{'TIME_FRI'} eq "" &&
137 $outfwsettings{'TIME_SAT'} eq "" &&
138 $outfwsettings{'TIME_SUN'} eq "" )
139 {
140 $outfwsettings{'TIME_MON'} = "on";
141 $outfwsettings{'TIME_TUE'} = "on";
142 $outfwsettings{'TIME_WED'} = "on";
143 $outfwsettings{'TIME_THU'} = "on";
144 $outfwsettings{'TIME_FRI'} = "on";
145 $outfwsettings{'TIME_SAT'} = "on";
146 $outfwsettings{'TIME_SUN'} = "on";
147 }
148
149 &Header::openpage($Lang::tr{'outgoing firewall'}, 1, '');
150 &Header::openbigbox('100%', 'left', '', $errormessage);
151
152 ############################################################################################################################
153 ############################################################################################################################
154
155 if ($outfwsettings{'ACTION'} eq $Lang::tr{'reset'})
156 {
157 $outfwsettings{'POLICY'}='MODE0';
158 unlink $configfile;
159 system("/usr/bin/touch $configfile");
160 my $MODE = $outfwsettings{'POLICY'};
161 %outfwsettings = ();
162 $outfwsettings{'POLICY'} = "$MODE";
163 &General::writehash("${General::swroot}/outgoing/settings", \%outfwsettings);
164 }
165 if ($outfwsettings{'ACTION'} eq $Lang::tr{'save'})
166 {
167 my $MODE = $outfwsettings{'POLICY'};
168 my $MODE1LOG = $outfwsettings{'MODE1LOG'};
169 %outfwsettings = ();
170 $outfwsettings{'POLICY'} = "$MODE";
171 $outfwsettings{'MODE1LOG'} = "$MODE1LOG";
172 &General::writehash("${General::swroot}/outgoing/settings", \%outfwsettings);
173 system("/usr/local/bin/outgoingfwctrl");
174 }
175 if ($outfwsettings{'ACTION'} eq 'enable')
176 {
177 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
178 @p2ps = <FILE>;
179 close FILE;
180 open( FILE, "> $p2pfile" ) or die "Unable to write $p2pfile";
181 foreach $p2pentry (sort @p2ps)
182 {
183 @p2pline = split( /\;/, $p2pentry );
184 if ($p2pline[1] eq $outfwsettings{'P2PROT'}) {
185 print FILE "$p2pline[0];$p2pline[1];on;\n";
186 } else {
187 print FILE "$p2pline[0];$p2pline[1];$p2pline[2];\n";
188 }
189 }
190 close FILE;
191 system("/usr/local/bin/outgoingfwctrl");
192 }
193 if ($outfwsettings{'ACTION'} eq 'disable')
194 {
195 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
196 @p2ps = <FILE>;
197 close FILE;
198 open( FILE, "> $p2pfile" ) or die "Unable to write $p2pfile";
199 foreach $p2pentry (sort @p2ps)
200 {
201 @p2pline = split( /\;/, $p2pentry );
202 if ($p2pline[1] eq $outfwsettings{'P2PROT'}) {
203 print FILE "$p2pline[0];$p2pline[1];off;\n";
204 } else {
205 print FILE "$p2pline[0];$p2pline[1];$p2pline[2];\n";
206 }
207 }
208 close FILE;
209 system("/usr/local/bin/outgoingfwctrl");
210 }
211 if ($outfwsettings{'ACTION'} eq $Lang::tr{'edit'})
212 {
213 open( FILE, "< $configfile" ) or die "Unable to read $configfile";
214 @configs = <FILE>;
215 close FILE;
216 open( FILE, "> $configfile" ) or die "Unable to write $configfile";
217 foreach $configentry (sort @configs)
218 {
219 @configline = split( /\;/, $configentry );
220
221 $configline[10] = "on" if not exists $configline[11];
222 $configline[11] = "on" if not exists $configline[11];
223 $configline[12] = "on" if not exists $configline[12];
224 $configline[13] = "on" if not exists $configline[13];
225 $configline[14] = "on" if not exists $configline[14];
226 $configline[15] = "on" if not exists $configline[15];
227 $configline[16] = "on" if not exists $configline[16];
228 $configline[17] = "00:00" if not exists $configline[17];
229 $configline[18] = "00:00" if not exists $configline[18];
230
231 unless (($configline[0] eq $outfwsettings{'STATE'}) &&
232 ($configline[1] eq $outfwsettings{'ENABLED'}) &&
233 ($configline[2] eq $outfwsettings{'SNET'}) &&
234 ($configline[3] eq $outfwsettings{'PROT'}) &&
235 ($configline[4] eq $outfwsettings{'NAME'}) &&
236 ($configline[5] eq $outfwsettings{'SIP'}) &&
237 ($configline[6] eq $outfwsettings{'SMAC'}) &&
238 ($configline[7] eq $outfwsettings{'DIP'}) &&
239 ($configline[9] eq $outfwsettings{'LOG'}) &&
240 ($configline[8] eq $outfwsettings{'DPORT'}) &&
241 ($configline[10] eq $outfwsettings{'TIME_MON'}) &&
242 ($configline[11] eq $outfwsettings{'TIME_TUE'}) &&
243 ($configline[12] eq $outfwsettings{'TIME_WED'}) &&
244 ($configline[13] eq $outfwsettings{'TIME_THU'}) &&
245 ($configline[14] eq $outfwsettings{'TIME_FRI'}) &&
246 ($configline[15] eq $outfwsettings{'TIME_SAT'}) &&
247 ($configline[16] eq $outfwsettings{'TIME_SUN'}) &&
248 ($configline[17] eq $outfwsettings{'TIME_FROM'}) &&
249 ($configline[18] eq $outfwsettings{'TIME_TO'}))
250 {
251 print FILE $configentry;
252 }
253 }
254 close FILE;
255 $selected{'SNET'}{"$outfwsettings{'SNET'}"} = 'selected';
256 $selected{'PROT'}{"$outfwsettings{'PROT'}"} = 'selected';
257 $selected{'LOG'}{"$outfwsettings{'LOG'}"} = 'selected';
258 &addrule();
259 &Header::closebigbox();
260 &Header::closepage();
261 exit
262 system("/usr/local/bin/outgoingfwctrl");
263 }
264 if ($outfwsettings{'ACTION'} eq $Lang::tr{'delete'})
265 {
266 open( FILE, "< $configfile" ) or die "Unable to read $configfile";
267 @configs = <FILE>;
268 close FILE;
269 open( FILE, "> $configfile" ) or die "Unable to write $configfile";
270 foreach $configentry (sort @configs)
271 {
272 @configline = split( /\;/, $configentry );
273
274 $configline[10] = "on" if not exists $configline[11];
275 $configline[11] = "on" if not exists $configline[11];
276 $configline[12] = "on" if not exists $configline[12];
277 $configline[13] = "on" if not exists $configline[13];
278 $configline[14] = "on" if not exists $configline[14];
279 $configline[15] = "on" if not exists $configline[15];
280 $configline[16] = "on" if not exists $configline[16];
281 $configline[17] = "00:00" if not exists $configline[17];
282 $configline[18] = "00:00" if not exists $configline[18];
283
284 unless (($configline[0] eq $outfwsettings{'STATE'}) &&
285 ($configline[1] eq $outfwsettings{'ENABLED'}) &&
286 ($configline[2] eq $outfwsettings{'SNET'}) &&
287 ($configline[3] eq $outfwsettings{'PROT'}) &&
288 ($configline[4] eq $outfwsettings{'NAME'}) &&
289 ($configline[5] eq $outfwsettings{'SIP'}) &&
290 ($configline[6] eq $outfwsettings{'SMAC'}) &&
291 ($configline[7] eq $outfwsettings{'DIP'}) &&
292 ($configline[9] eq $outfwsettings{'LOG'}) &&
293 ($configline[8] eq $outfwsettings{'DPORT'}) &&
294 ($configline[10] eq $outfwsettings{'TIME_MON'}) &&
295 ($configline[11] eq $outfwsettings{'TIME_TUE'}) &&
296 ($configline[12] eq $outfwsettings{'TIME_WED'}) &&
297 ($configline[13] eq $outfwsettings{'TIME_THU'}) &&
298 ($configline[14] eq $outfwsettings{'TIME_FRI'}) &&
299 ($configline[15] eq $outfwsettings{'TIME_SAT'}) &&
300 ($configline[16] eq $outfwsettings{'TIME_SUN'}) &&
301 ($configline[17] eq $outfwsettings{'TIME_FROM'}) &&
302 ($configline[18] eq $outfwsettings{'TIME_TO'}))
303 {
304 print FILE $configentry;
305 }
306 }
307 close FILE;
308 system("/usr/local/bin/outgoingfwctrl");
309 }
310 if ($outfwsettings{'ACTION'} eq $Lang::tr{'add'})
311 {
312 if ( $outfwsettings{'VALID'} eq 'yes' ) {
313
314 if ( $outfwsettings{'SNET'} eq "all" ) {
315 $outfwsettings{'SIP'} ="";
316 $outfwsettings{'SMAC'}="";
317 }
318 open( FILE, ">> $configfile" ) or die "Unable to write $configfile";
319 print FILE <<END
320 $outfwsettings{'STATE'};$outfwsettings{'ENABLED'};$outfwsettings{'SNET'};$outfwsettings{'PROT'};$outfwsettings{'NAME'};$outfwsettings{'SIP'};$outfwsettings{'SMAC'};$outfwsettings{'DIP'};$outfwsettings{'DPORT'};$outfwsettings{'LOG'};$outfwsettings{'TIME_MON'};$outfwsettings{'TIME_TUE'};$outfwsettings{'TIME_WED'};$outfwsettings{'TIME_THU'};$outfwsettings{'TIME_FRI'};$outfwsettings{'TIME_SAT'};$outfwsettings{'TIME_SUN'};$outfwsettings{'TIME_FROM'};$outfwsettings{'TIME_TO'};
321 END
322 ;
323 close FILE;
324 system("/usr/local/bin/outgoingfwctrl");
325 } else {
326 $outfwsettings{'ACTION'} = 'Add rule';
327 }
328 }
329 if ($outfwsettings{'ACTION'} eq $Lang::tr{'Add Rule'})
330 {
331 &addrule();
332 exit
333 }
334
335 &General::readhash("${General::swroot}/outgoing/settings", \%outfwsettings);
336
337 if ($errormessage) {
338 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
339 print "<class name='base'>$errormessage\n";
340 print "&nbsp;</class>\n";
341 &Header::closebox();
342 }
343
344 ############################################################################################################################
345 ############################################################################################################################
346
347 if ($outfwsettings{'POLICY'} ne 'MODE0'){
348 &Header::openbox('100%', 'center', 'Rules');
349 print <<END
350 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
351 <input type='submit' name='ACTION' value='$Lang::tr{'Add Rule'}' />
352 </form>
353 END
354 ;
355 open( FILE, "< $configfile" ) or die "Unable to read $configfile";
356 @configs = <FILE>;
357 close FILE;
358 if (@configs) {
359 print <<END
360 <hr />
361 <table border='0' width='100%' cellspacing='0'>
362 <tr bgcolor='$color{'color22'}'>
363 <td width='14%' align='center'><b>$Lang::tr{'protocol'}</b></td>
364 <td width='14%' align='center'><b>$Lang::tr{'network'}</b></td>
365 <td width='14%' align='center'><b>$Lang::tr{'destination'}</b></td>
366 <td width='14%' align='center'><b>$Lang::tr{'description'}</b></td>
367 <td width='14%' align='center'><b>$Lang::tr{'policy'}</b></td>
368 <td width='16%' align='center'><b>$Lang::tr{'logging'}</b></td>
369 <td width='14%' align='center'><b>$Lang::tr{'action'}</b></td>
370 END
371 ;
372 foreach $configentry (sort @configs)
373 {
374 @configline = split( /\;/, $configentry );
375 $outfwsettings{'STATE'} = $configline[0];
376 $outfwsettings{'ENABLED'} = $configline[1];
377 $outfwsettings{'SNET'} = $configline[2];
378 $outfwsettings{'PROT'} = $configline[3];
379 $outfwsettings{'NAME'} = $configline[4];
380 $outfwsettings{'SIP'} = $configline[5];
381 $outfwsettings{'SMAC'} = $configline[6];
382 $outfwsettings{'DIP'} = $configline[7];
383 $outfwsettings{'DPORT'} = $configline[8];
384 $outfwsettings{'LOG'} = $configline[9];
385
386 $configline[10] = "on" if not exists $configline[11];
387 $configline[11] = "on" if not exists $configline[11];
388 $configline[12] = "on" if not exists $configline[12];
389 $configline[13] = "on" if not exists $configline[13];
390 $configline[14] = "on" if not exists $configline[14];
391 $configline[15] = "on" if not exists $configline[15];
392 $configline[16] = "on" if not exists $configline[16];
393 $configline[17] = "00:00" if not exists $configline[17];
394 $configline[18] = "00:00" if not exists $configline[18];
395
396 $outfwsettings{'TIME_MON'} = $configline[10];
397 $outfwsettings{'TIME_TUE'} = $configline[11];
398 $outfwsettings{'TIME_WED'} = $configline[12];
399 $outfwsettings{'TIME_THU'} = $configline[13];
400 $outfwsettings{'TIME_FRI'} = $configline[14];
401 $outfwsettings{'TIME_SAT'} = $configline[15];
402 $outfwsettings{'TIME_SUN'} = $configline[16];
403 $outfwsettings{'TIME_FROM'} = $configline[17];
404 $outfwsettings{'TIME_TO'} = $configline[18];
405
406 if ($outfwsettings{'DIP'} eq ''){ $outfwsettings{'DISPLAY_DIP'} = 'ALL'; } else { $outfwsettings{'DISPLAY_DIP'} = $outfwsettings{'DIP'}; }
407 if ($outfwsettings{'DPORT'} eq ''){ $outfwsettings{'DISPLAY_DPORT'} = 'ALL'; } else { $outfwsettings{'DISPLAY_DPORT'} = $outfwsettings{'DPORT'}; }
408 if ($outfwsettings{'STATE'} eq 'DENY'){ $outfwsettings{'DISPLAY_STATE'} = "<img src='/images/stock_stop.png' alt='DENY' />"; }
409 if ($outfwsettings{'STATE'} eq 'ALLOW'){ $outfwsettings{'DISPLAY_STATE'} = "<img src='/images/stock_ok.png' alt='ALLOW' />"; }
410 if ((($outfwsettings{'POLICY'} eq 'MODE1') && ($outfwsettings{'STATE'} eq 'ALLOW')) || (($outfwsettings{'POLICY'} eq 'MODE2') && ($outfwsettings{'STATE'} eq 'DENY'))){
411 if ( $outfwsettings{'ENABLED'} eq "on" ){
412 print "<tr bgcolor='$color{'color20'}'>";
413 } else {
414 print "<tr bgcolor='$color{'color18'}'>";
415 }
416 print <<END
417 <td align='center'>$outfwsettings{'PROT'}
418 <td align='center'>$outfwsettings{'SNET'}
419 <td align='center'>$outfwsettings{'DISPLAY_DIP'}:$outfwsettings{'DISPLAY_DPORT'}
420 <td align='center'>$outfwsettings{'NAME'}
421 <td align='center'>$outfwsettings{'DISPLAY_STATE'}
422 <td align='center'>$outfwsettings{'LOG'}
423 <td align='center'>
424 <table border='0' cellpadding='0' cellspacing='0'><tr>
425 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
426 <input type='hidden' name='PROT' value='$outfwsettings{'PROT'}' />
427 <input type='hidden' name='STATE' value='$outfwsettings{'STATE'}' />
428 <input type='hidden' name='SNET' value='$outfwsettings{'SNET'}' />
429 <input type='hidden' name='DPORT' value='$outfwsettings{'DPORT'}' />
430 <input type='hidden' name='DIP' value='$outfwsettings{'DIP'}' />
431 <input type='hidden' name='SIP' value='$outfwsettings{'SIP'}' />
432 <input type='hidden' name='NAME' value='$outfwsettings{'NAME'}' />
433 <input type='hidden' name='SMAC' value='$outfwsettings{'SMAC'}' />
434 <input type='hidden' name='ENABLED' value='$outfwsettings{'ENABLED'}' />
435 <input type='hidden' name='LOG' value='$outfwsettings{'LOG'}' />
436 <input type='hidden' name='TIME_MON' value='$outfwsettings{'TIME_MON'}' />
437 <input type='hidden' name='TIME_TUE' value='$outfwsettings{'TIME_TUE'}' />
438 <input type='hidden' name='TIME_WED' value='$outfwsettings{'TIME_WED'}' />
439 <input type='hidden' name='TIME_THU' value='$outfwsettings{'TIME_THU'}' />
440 <input type='hidden' name='TIME_FRI' value='$outfwsettings{'TIME_FRI'}' />
441 <input type='hidden' name='TIME_SAT' value='$outfwsettings{'TIME_SAT'}' />
442 <input type='hidden' name='TIME_SUN' value='$outfwsettings{'TIME_SUN'}' />
443 <input type='hidden' name='TIME_FROM' value='$outfwsettings{'TIME_FROM'}' />
444 <input type='hidden' name='TIME_TO' value='$outfwsettings{'TIME_TO'}' />
445 <input type='hidden' name='ACTION' value=$Lang::tr{'edit'} />
446 <input type='image' src='/images/edit.gif' width="20" height="20" alt=$Lang::tr{'edit'} />
447 </form>
448 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
449 <input type='hidden' name='PROT' value='$outfwsettings{'PROT'}' />
450 <input type='hidden' name='STATE' value='$outfwsettings{'STATE'}' />
451 <input type='hidden' name='SNET' value='$outfwsettings{'SNET'}' />
452 <input type='hidden' name='DPORT' value='$outfwsettings{'DPORT'}' />
453 <input type='hidden' name='DIP' value='$outfwsettings{'DIP'}' />
454 <input type='hidden' name='SIP' value='$outfwsettings{'SIP'}' />
455 <input type='hidden' name='NAME' value='$outfwsettings{'NAME'}' />
456 <input type='hidden' name='SMAC' value='$outfwsettings{'SMAC'}' />
457 <input type='hidden' name='ENABLED' value='$outfwsettings{'ENABLED'}' />
458 <input type='hidden' name='LOG' value='$outfwsettings{'LOG'}' />
459 <input type='hidden' name='TIME_MON' value='$outfwsettings{'TIME_MON'}' />
460 <input type='hidden' name='TIME_TUE' value='$outfwsettings{'TIME_TUE'}' />
461 <input type='hidden' name='TIME_WED' value='$outfwsettings{'TIME_WED'}' />
462 <input type='hidden' name='TIME_THU' value='$outfwsettings{'TIME_THU'}' />
463 <input type='hidden' name='TIME_FRI' value='$outfwsettings{'TIME_FRI'}' />
464 <input type='hidden' name='TIME_SAT' value='$outfwsettings{'TIME_SAT'}' />
465 <input type='hidden' name='TIME_SUN' value='$outfwsettings{'TIME_SUN'}' />
466 <input type='hidden' name='TIME_FROM' value='$outfwsettings{'TIME_FROM'}' />
467 <input type='hidden' name='TIME_TO' value='$outfwsettings{'TIME_TO'}' />
468 <input type='hidden' name='ACTION' value=$Lang::tr{'delete'} />
469 <input type='image' src='/images/delete.gif' width="20" height="20" alt=$Lang::tr{'delete'} />
470 </form></table>
471 END
472 ;
473 if (($outfwsettings{'SIP'}) || ($outfwsettings{'SMAC'})) {
474
475 unless ($outfwsettings{'SIP'}) {
476 $outfwsettings{'DISPLAY_SIP'} = 'ALL';
477 } else {
478 $outfwsettings{'DISPLAY_SIP'} = $outfwsettings{'SIP'};
479 }
480
481 unless ($outfwsettings{'SMAC'}) {
482 $outfwsettings{'DISPLAY_SMAC'} = 'ALL';
483 print "<tr><td /><td align='left'>$Lang::tr{'source ip or net'}: </td>";
484 print "<td align='left' colspan='2'>$outfwsettings{'DISPLAY_SIP'}</td>";
485 } else {
486 $outfwsettings{'DISPLAY_SMAC'} = $outfwsettings{'SMAC'};
487 print "<tr><td /><td align='left'>$Lang::tr{'source'} $Lang::tr{'mac address'}: </td>";
488 print "<td align='left' colspan='2'>$outfwsettings{'DISPLAY_SMAC'}</td>";
489 }
490 }
491 print <<END
492 <tr><td width='14%' align='right'>$Lang::tr{'time'} - </td>
493 <td width='14%' align='left'>
494 END
495 ;
496 if ($outfwsettings{'TIME_MON'} eq 'on') { print "<font color='$Header::colourgreen'>";}
497 else { print "<font color='$Header::colourred'>";}
498 print "$Lang::tr{'advproxy monday'}</font>,";
499 if ($outfwsettings{'TIME_TUE'} eq 'on') { print "<font color='$Header::colourgreen'>";}
500 else { print "<font color='$Header::colourred'>";}
501 print "$Lang::tr{'advproxy tuesday'}</font>,";
502 if ($outfwsettings{'TIME_WED'} eq 'on') { print "<font color='$Header::colourgreen'>";}
503 else { print "<font color='$Header::colourred'>";}
504 print "$Lang::tr{'advproxy wednesday'}</font>,";
505 if ($outfwsettings{'TIME_THU'} eq 'on') { print "<font color='$Header::colourgreen'>";}
506 else { print "<font color='$Header::colourred'>";}
507 print "$Lang::tr{'advproxy thursday'}</font>,";
508 if ($outfwsettings{'TIME_FRI'} eq 'on') { print "<font color='$Header::colourgreen'>";}
509 else { print "<font color='$Header::colourred'>";}
510 print "$Lang::tr{'advproxy friday'}</font>,";
511 if ($outfwsettings{'TIME_SAT'} eq 'on') { print "<font color='$Header::colourgreen'>";}
512 else { print "<font color='$Header::colourred'>";}
513 print "$Lang::tr{'advproxy saturday'}</font>,";
514 if ($outfwsettings{'TIME_SUN'} eq 'on') { print "<font color='$Header::colourgreen'>";}
515 else { print "<font color='$Header::colourred'>";}
516 print "$Lang::tr{'advproxy sunday'}</font>";
517 print <<END
518 </td>
519 <td width='22%' align='center'>$Lang::tr{'advproxy from'} $outfwsettings{'TIME_FROM'}</td>
520 <td width='22%' align='center'>$Lang::tr{'advproxy to'} $outfwsettings{'TIME_TO'}</td>
521 </form>
522 END
523 ;
524 }
525 }
526 if ($outfwsettings{'POLICY'} eq 'MODE1'){
527 print <<END
528 <tr bgcolor='$color{'color20'}'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
529 <td align='center'>all
530 <td align='center'>all
531 <td align='center'>ALL
532 <td align='center'>drop
533 <td align='center'><img src='/images/stock_stop.png' alt='DENY' />
534 <td align='center'>on <input type='radio' name='MODE1LOG' value='on' $checked{'MODE1LOG'}{'on'} /><input type='radio' name='MODE1LOG' value='off' $checked{'MODE1LOG'}{'off'} /> off
535 <td align='center'><input type='hidden' name='ACTION' value=$Lang::tr{'save'} /><input type='image' src='/images/media-floppy.png' width="18" height="18" alt=$Lang::tr{'save'} /></form></tr>
536 <table border='0' cellpadding='0' cellspacing='0'><tr>
537 <td>
538 <td></table>
539 END
540 ;
541 }
542 print <<END
543 </table>
544 END
545 ;
546
547 }
548 &Header::closebox();
549 }
550
551 if ($outfwsettings{'POLICY'} ne 'MODE0'){
552 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
553 @p2ps = <FILE>;
554 close FILE;
555 &Header::openbox('100%', 'center', 'P2P-Block');
556 print <<END
557 <table width='40%'>
558 <tr bgcolor='$color{'color22'}'><td width='66%' align=center><b>$Lang::tr{'protocol'}</b>
559 <td width='33%' align=center><b>$Lang::tr{'status'}</b>
560 END
561 ;
562 my $id = 1;
563 foreach $p2pentry (sort @p2ps)
564 {
565 @p2pline = split( /\;/, $p2pentry );
566 print <<END
567 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
568 END
569 ;
570 print "\t\t\t<tr bgcolor='$color{'color20'}'>\n";
571 print <<END
572 <td width='66%' align='center'>$p2pline[0]:
573 <td width='33%' align='center'><input type='hidden' name='P2PROT' value='$p2pline[1]' />
574 END
575 ;
576 if ($p2pline[2] eq 'on') {
577 print <<END
578 <input type='hidden' name='ACTION' value='disable' />
579 <input type='image' name='submit' src='/images/stock_ok.png' alt='$Lang::tr{'outgoing firewall p2p allow'}' title='$Lang::tr{'outgoing firewall p2p allow'}'/>
580 END
581 ;
582 } else {
583 print <<END
584 <input type='hidden' name='ACTION' value='enable' />
585 <input type='image' name='submit' src='/images/stock_stop.png' alt='$Lang::tr{'outgoing firewall p2p deny'}' title='$Lang::tr{'outgoing firewall p2p deny'}' />
586 END
587 ;
588 }
589 print <<END
590 </form>
591 END
592 ;
593 }
594 print <<END
595 </table>
596 <br />$Lang::tr{'outgoing firewall p2p description 1'} <img src='/images/stock_ok.png' align='absmiddle' alt='$Lang::tr{'outgoing firewall p2p deny'}'> $Lang::tr{'outgoing firewall p2p description 2'} <img src='/images/stock_stop.png' align='absmiddle' alt='$Lang::tr{'outgoing firewall p2p deny'}'> $Lang::tr{'outgoing firewall p2p description 3'}
597 END
598 ;
599 &Header::closebox();
600 }
601
602 &Header::openbox('100%', 'center', 'Policy');
603 print <<END
604 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
605 <table width='100%'>
606 <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>
607 <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>
608 <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>
609 <tr><td colspan='3'><hr /></td></tr>
610 <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>
611 <td width='45%' align='left'><input type='submit' name='ACTION' value=$Lang::tr{'save'} />
612 <td width='45%' align='left'>
613 END
614 ;
615 if ($outfwsettings{'POLICY'} ne 'MODE0') {
616 print <<END
617 $Lang::tr{'outgoing firewall reset'}: <input type='submit' name='ACTION' value=$Lang::tr{'reset'} />
618 END
619 ;
620 }
621 print <<END
622 </table>
623 </form>
624 END
625 ;
626 &Header::closebox();
627
628 ############################################################################################################################
629 ############################################################################################################################
630
631 sub addrule
632 {
633 &Header::openbox('100%', 'center', $Lang::tr{'Add Rule'});
634 if ($outfwsettings{'EDIT'} eq 'no') { $selected{'ENABLED'} = 'checked'; }
635 $selected{'TIME_FROM'}{$outfwsettings{'TIME_FROM'}} = "selected='selected'";
636 $selected{'TIME_TO'}{$outfwsettings{'TIME_TO'}} = "selected='selected'";
637 print <<END
638 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
639 <table width='80%'>
640 <tr>
641 <td width='20%' align='right'>$Lang::tr{'description'}: <img src='/blob.gif' /></td>
642 <td width='30%' align='left'><input type='text' name='NAME' maxlength='30' value='$outfwsettings{'NAME'}' /></td>
643 <td width='20%' align='right' colspan='2'>$Lang::tr{'active'}:</td>
644 <td width='30%' align='left' colspan='2'><input type='checkbox' name='ENABLED' $selected{'ENABLED'} /></td>
645 </tr>
646 <tr>
647 <td width='20%' align='right'>$Lang::tr{'protocol'}</td>
648 <td width='30%' align='left'>
649 <select name='PROT'>
650 <option value='all' $selected{'PROT'}{'all'}>All</option>
651 <option value='tcp' $selected{'PROT'}{'tcp'}>TCP</option>
652 <option value='udp' $selected{'PROT'}{'udp'}>UDP</option>
653 <option value='gre' $selected{'PROT'}{'gre'}>GRE</option>
654 <option value='esp' $selected{'PROT'}{'esp'}>ESP</option>
655 </select>
656 </td>
657 <td width='20%' align='right' colspan='2'>$Lang::tr{'policy'}:</td>
658 <td width='30%' align='left' colspan='2'>
659 END
660 ;
661 if ($outfwsettings{'POLICY'} eq 'MODE1'){
662 print "\t\t\t\tALLOW<input type='hidden' name='STATE' value='ALLOW' />\n";
663 } elsif ($outfwsettings{'POLICY'} eq 'MODE2'){
664 print "\t\t\t\tDENY<input type='hidden' name='STATE' value='DENY' />\n";
665 }
666 print <<END
667 </td>
668 </tr>
669 <tr>
670 <td width='20%' align='right'>$Lang::tr{'source'}:</td>
671 <td width='30%' align='left'>
672 <select name='SNET'>
673 <optgroup label='---'>
674 <option value='all' $selected{'SNET'}{'ALL'}>$Lang::tr{'all'}</option>
675 <optgroup label='$Lang::tr{'mac address'}'>
676 <option value='mac' $selected{'SNET'}{'mac'}>$Lang::tr{'source'} $Lang::tr{'mac address'}</option>
677 </optgroup>
678 <optgroup label='$Lang::tr{'ip address'}'>
679 <option value='ip' $selected{'SNET'}{'ip'}>$Lang::tr{'source ip or net'}</option>
680 <option value='red' $selected{'SNET'}{'red'}>$Lang::tr{'red'} IP</option>
681 </optgroup>
682 <optgroup label='$Lang::tr{'alt vpn'}'>
683 <option value='ovpn' $selected{'SNET'}{'ovpn'}>OpenVPN $Lang::tr{'interface'}</option>
684 </optgroup>
685 <optgroup label='$Lang::tr{'network'}'>
686 <option value='green' $selected{'SNET'}{'green'}>$Lang::tr{'green'}</option>
687 END
688 ;
689 if (&Header::blue_used()){
690 print "\t\t\t\t\t<option value='blue' $selected{'SNET'}{'blue'}>$Lang::tr{'wireless'}</option>\n";
691 }
692 if (&Header::orange_used()){
693 print "\t\t\t\t\t<option value='orange' $selected{'SNET'}{'orange'}>$Lang::tr{'dmz'}</option>\n";
694 }
695 print <<END
696 </optgroup>
697 <optgroup label='IP $Lang::tr{'advproxy NCSA group'}'>
698 END
699 ;
700 my @ipgroups = qx(ls $configpath/ipgroups/);
701 foreach (sort @ipgroups){
702 print "\t\t\t\t\t<option value='$_' $selected{'SNET'}{'$_'}>$_</option>\n";
703 }
704 print <<END
705 </optgroup>
706 <optgroup label='MAC $Lang::tr{'advproxy NCSA group'}'>
707 END
708 ;
709 my @macgroups = qx(ls $configpath/macgroups/);
710 foreach (sort @macgroups){
711 print "\t\t\t\t\t<option value='$_' $selected{'SNET'}{'$_'}>$_</option>\n";
712 }
713 print <<END
714 </optgroup>
715 </select>
716 </td>
717 <td align='right' colspan='4'><font color='red'>$Lang::tr{'outgoing firewall warning'}</font></td>
718 </tr>
719 <tr>
720 <td align='right' colspan='4' >$Lang::tr{'source ip or net'}<img src='/blob.gif' /></td>
721 <td align='left' colspan='4' ><input type='text' name='SIP' value='$outfwsettings{'SIP'}' /></td>
722 </tr>
723 <tr>
724 <td align='right' colspan='4' >$Lang::tr{'source'} $Lang::tr{'mac address'}: <img src='/blob.gif' />
725 <td align='left' colspan='4' ><input type='text' name='SMAC' maxlength='23' value='$outfwsettings{'SMAC'}' />
726 </tr>
727 <tr>
728 <td width='20%' align='right'>$Lang::tr{'logging'}:</td>
729 <td width='30%' align='left'>
730 <select name='LOG'>
731 <option value='$Lang::tr{'active'}' $selected{'LOG'}{$Lang::tr{'active'}}>$Lang::tr{'active'}</option>
732 <option value='$Lang::tr{'inactive'}' $selected{'LOG'}{$Lang::tr{'inactive'}}>$Lang::tr{'inactive'}</option>
733 </select>
734 </td>
735 <td width='20%' align='right' colspan='2' />
736 <td width='30%' align='left' colspan='2' />
737 <tr>
738 <td width='20%' align='right'>$Lang::tr{'destination ip or net'}: <img src='/blob.gif' /></td>
739 <td width='30%' align='left'><input type='text' name='DIP' value='$outfwsettings{'DIP'}' /></td>
740 <td width='20%' align='right' colspan='2'>$Lang::tr{'destination port'}(s) <img src='/blob.gif' /></td>
741 <td width='30%' align='left' colspan='2'><input type='text' name='DPORT' value='$outfwsettings{'DPORT'}' /></td>
742 </tr>
743 <tr>
744 <td width='20%' align='right'>$Lang::tr{'time'}:</td>
745 <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>
746 <td width='20%' align='right' colspan='2' />
747 <td width='15%' align='left'>$Lang::tr{'advproxy from'}</td>
748 <td width='15%' align='left'>$Lang::tr{'advproxy to'}</td>
749 </tr>
750 <tr>
751 <td width='20%' align='right'></td>
752 <td width='30%' align='left'>
753 <input type='checkbox' name='TIME_MON' $checked{'TIME_MON'}{'on'} />
754 <input type='checkbox' name='TIME_TUE' $checked{'TIME_TUE'}{'on'} />
755 <input type='checkbox' name='TIME_WED' $checked{'TIME_WED'}{'on'} />
756 <input type='checkbox' name='TIME_THU' $checked{'TIME_THU'}{'on'} />
757 <input type='checkbox' name='TIME_FRI' $checked{'TIME_FRI'}{'on'} />
758 <input type='checkbox' name='TIME_SAT' $checked{'TIME_SAT'}{'on'} />
759 <input type='checkbox' name='TIME_SUN' $checked{'TIME_SUN'}{'on'} />
760 </td>
761 <td width='20%' align='right' colspan='2' />
762 <td width='15%' align='left'>
763 <select name='TIME_FROM'>
764 END
765 ;
766 for (my $i=0;$i<=23;$i++) {
767 $i = sprintf("%02s",$i);
768 for (my $j=0;$j<=45;$j+=15) {
769 $j = sprintf("%02s",$j);
770 my $time = $i.":".$j;
771 print "\t\t\t\t\t<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
772 }
773 }
774 print <<END
775 </select>
776 </td>
777 <td width='15%' align='left'><select name='TIME_TO'>
778 END
779 ;
780 for (my $i=0;$i<=23;$i++) {
781 $i = sprintf("%02s",$i);
782 for (my $j=0;$j<=45;$j+=15) {
783 $j = sprintf("%02s",$j);
784 my $time = $i.":".$j;
785 print "\t\t\t\t\t<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
786 }
787 }
788 print <<END
789 </select>
790 </td>
791 </tr>
792 <tr>
793 <td colspan='6' />
794 <tr>
795 <tr>
796 <td width='40%' align='right' colspan='2'><img src='/blob.gif' />$Lang::tr{'this field may be blank'}</td>
797 <td width='60%' align='left' colspan='4'><input type='submit' name='ACTION' value=$Lang::tr{'add'} /></td>
798 </table></form>
799 END
800 ;
801 &Header::closebox();
802
803 if ($outfwsettings{'POLICY'} eq 'MODE1' || $outfwsettings{'POLICY'} eq 'MODE2')
804 {
805 &Header::openbox('100%', 'center', 'Quick Add');
806
807 open( FILE, "< /var/ipfire/outgoing/defaultservices" ) or die "Unable to read default services";
808 my @defservices = <FILE>;
809 close FILE;
810
811 print "<table width='100%'><tr bgcolor='$color{'color20'}'><td><b>$Lang::tr{'service'}</b></td><td><b>$Lang::tr{'description'}</b></td><td><b>$Lang::tr{'port'}</b></td><td><b>$Lang::tr{'protocol'}</b></td><td><b>$Lang::tr{'source net'}</b></td><td><b>$Lang::tr{'logging'}</b></td><td><b>$Lang::tr{'action'}</b></td></tr>";
812 foreach my $serviceline(@defservices)
813 {
814 my @service = split(/,/,$serviceline);
815 print <<END
816 <tr><form method='post' action='$ENV{'SCRIPT_NAME'}'>
817 <td>$service[0]<input type='hidden' name='NAME' value='@service[0]' /></td>
818 <td>$service[3]</td>
819 <td><a href='http://isc.sans.org/port_details.php?port=$service[1]' target='top'>$service[1]</a><input type='hidden' name='DPORT' value='@service[1]' /></td>
820 <td>$service[2]<input type='hidden' name='PROT' value='@service[2]' /></td>
821 <td><select name='SNET'><option value='all' $selected{'SNET'}{'ALL'}>$Lang::tr{'all'}</option><option value='green' $selected{'SNET'}{'green'}>$Lang::tr{'green'}</option>
822 END
823 ;
824 if (&Header::blue_used()){
825 print "<option value='blue' $selected{'SNET'}{'blue'}>$Lang::tr{'wireless'}</option>";
826 }
827 if (&Header::orange_used()){
828 print "<option value='orange' $selected{'SNET'}{'orange'}>$Lang::tr{'dmz'}</option>";
829 }
830 print <<END
831 </select></td>
832 <td><select name='LOG'><option value='$Lang::tr{'active'}'>$Lang::tr{'active'}</option><option value='$Lang::tr{'inactive'}' 'selected'>$Lang::tr{'inactive'}</option></select></td><td>
833 <input type='hidden' name='ACTION' value=$Lang::tr{'add'} />
834 <input type='image' alt='$Lang::tr{'add'}' src='/images/add.gif' />
835 <input type='hidden' name='ENABLED' value='on' />
836 END
837 ;
838 if ($outfwsettings{'POLICY'} eq 'MODE1'){ print "<input type='hidden' name='STATE' value='ALLOW' /></form></td></tr>";}
839 elsif ($outfwsettings{'POLICY'} eq 'MODE2'){print "<input type='hidden' name='STATE' value='DENY' /></form></td></tr>";}
840 }
841 print "</table>";
842 &Header::closebox();
843 }
844 }
845
846 &Header::closebigbox();
847 &Header::closepage();