5 # This code is distributed under the terms of the GPL
11 # enable only the following on debugging purpose
13 use CGI
::Carp
'fatalsToBrowser';
15 require '/var/ipfire/general-functions.pl';
16 require "${General::swroot}/lang.pl";
17 require "${General::swroot}/header.pl";
19 my %outfwsettings = ();
23 my $errormessage = "";
31 my $configfile = "/var/ipfire/outgoing/rules";
32 my $p2pfile = "/var/ipfire/outgoing/p2protocols";
33 my $servicefile = "/var/ipfire/outgoing/defaultservices"
35 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
37 &Header
::showhttpheaders
();
39 ### Values that have to be initialized
40 $outfwsettings{'ACTION'} = '';
41 $outfwsettings{'VALID'} = 'yes';
42 $outfwsettings{'EDIT'} = 'no';
43 $outfwsettings{'NAME'} = '';
44 $outfwsettings{'SNET'} = '';
45 $outfwsettings{'SIP'} = '';
46 $outfwsettings{'SPORT'} = '';
47 $outfwsettings{'SMAC'} = '';
48 $outfwsettings{'DIP'} = '';
49 $outfwsettings{'DPORT'} = '';
50 $outfwsettings{'PROT'} = '';
51 $outfwsettings{'STATE'} = '';
52 $outfwsettings{'DISPLAY_DIP'} = '';
53 $outfwsettings{'DISPLAY_DPORT'} = '';
54 $outfwsettings{'DISPLAY_SMAC'} = '';
55 $outfwsettings{'DISPLAY_SIP'} = '';
56 $outfwsettings{'POLICY'} = 'MODE0';
58 &General
::readhash
("${General::swroot}/outgoing/settings", \
%outfwsettings);
59 &Header
::getcgihash
(\
%outfwsettings);
61 if ($outfwsettings{'POLICY'} eq 'MODE0'){ $selected{'POLICY'}{'MODE0'} = 'selected'; } else { $selected{'POLICY'}{'MODE0'} = ''; }
62 if ($outfwsettings{'POLICY'} eq 'MODE1'){ $selected{'POLICY'}{'MODE1'} = 'selected'; } else { $selected{'POLICY'}{'MODE1'} = ''; }
63 if ($outfwsettings{'POLICY'} eq 'MODE2'){ $selected{'POLICY'}{'MODE2'} = 'selected'; } else { $selected{'POLICY'}{'MODE2'} = ''; }
65 &Header
::openpage
('Ausgehende Firewall', 1, '');
66 &Header
::openbigbox
('100%', 'left', '', $errormessage);
68 ############################################################################################################################
69 ############################################################################################################################
71 if ($outfwsettings{'ACTION'} eq $Lang::tr
{'reset'})
73 $outfwsettings{'POLICY'}='MODE0';
75 system("/usr/bin/touch $configfile");
76 &General
::writehash
("${General::swroot}/outgoing/settings", \
%outfwsettings);
78 if ($outfwsettings{'ACTION'} eq $Lang::tr
{'save'})
80 &General
::writehash
("${General::swroot}/outgoing/settings", \
%outfwsettings);
82 if ($outfwsettings{'ACTION'} eq 'enable')
84 open( FILE
, "< $p2pfile" ) or die "Unable to read $p2pfile";
87 open( FILE
, "> $p2pfile" ) or die "Unable to write $p2pfile";
88 foreach $p2pentry (sort @p2ps)
90 @p2pline = split( /\;/, $p2pentry );
91 if ($p2pline[1] eq $outfwsettings{'P2PROT'}) {
92 print FILE
"$p2pline[0];$p2pline[1];on;\n";
94 print FILE
"$p2pline[0];$p2pline[1];$p2pline[2];\n";
99 if ($outfwsettings{'ACTION'} eq 'disable')
101 open( FILE
, "< $p2pfile" ) or die "Unable to read $p2pfile";
104 open( FILE
, "> $p2pfile" ) or die "Unable to write $p2pfile";
105 foreach $p2pentry (sort @p2ps)
107 @p2pline = split( /\;/, $p2pentry );
108 if ($p2pline[1] eq $outfwsettings{'P2PROT'}) {
109 print FILE
"$p2pline[0];$p2pline[1];off;\n";
111 print FILE
"$p2pline[0];$p2pline[1];$p2pline[2];\n";
116 if ($outfwsettings{'ACTION'} eq $Lang::tr
{'edit'})
118 open( FILE
, "< $configfile" ) or die "Unable to read $configfile";
121 open( FILE
, "> $configfile" ) or die "Unable to write $configfile";
122 foreach $configentry (sort @configs)
124 @configline = split( /\;/, $configentry );
125 unless (($configline[0] eq $outfwsettings{'STATE'}) &&
126 ($configline[1] eq $outfwsettings{'ENABLED'}) &&
127 ($configline[2] eq $outfwsettings{'SNET'}) &&
128 ($configline[3] eq $outfwsettings{'PROT'}) &&
129 ($configline[4] eq $outfwsettings{'NAME'}) &&
130 ($configline[5] eq $outfwsettings{'SIP'}) &&
131 ($configline[6] eq $outfwsettings{'SMAC'}) &&
132 ($configline[7] eq $outfwsettings{'DIP'}) &&
133 ($configline[8] eq $outfwsettings{'DPORT'}))
135 print FILE
$configentry;
139 $selected{'SNET'}{"$outfwsettings{'SNET'}"} = 'selected';
140 $selected{'PROT'}{"$outfwsettings{'PROT'}"} = 'selected';
142 &Header
::closebigbox
();
143 &Header
::closepage
();
146 if ($outfwsettings{'ACTION'} eq $Lang::tr
{'delete'})
148 open( FILE
, "< $configfile" ) or die "Unable to read $configfile";
151 open( FILE
, "> $configfile" ) or die "Unable to write $configfile";
152 foreach $configentry (sort @configs)
154 @configline = split( /\;/, $configentry );
155 unless (($configline[0] eq $outfwsettings{'STATE'}) &&
156 ($configline[1] eq $outfwsettings{'ENABLED'}) &&
157 ($configline[2] eq $outfwsettings{'SNET'}) &&
158 ($configline[3] eq $outfwsettings{'PROT'}) &&
159 ($configline[4] eq $outfwsettings{'NAME'}) &&
160 ($configline[5] eq $outfwsettings{'SIP'}) &&
161 ($configline[6] eq $outfwsettings{'SMAC'}) &&
162 ($configline[7] eq $outfwsettings{'DIP'}) &&
163 ($configline[8] eq $outfwsettings{'DPORT'}))
165 print FILE
$configentry;
170 if ($outfwsettings{'ACTION'} eq $Lang::tr
{'add'})
172 if ( $outfwsettings{'VALID'} eq 'yes' ) {
173 open( FILE
, ">> $configfile" ) or die "Unable to write $configfile";
175 $outfwsettings{'STATE'};$outfwsettings{'ENABLED'};$outfwsettings{'SNET'};$outfwsettings{'PROT'};$outfwsettings{'NAME'};$outfwsettings{'SIP'};$outfwsettings{'SMAC'};$outfwsettings{'DIP'};$outfwsettings{'DPORT'};
180 $outfwsettings{'ACTION'} = 'Add rule';
183 if ($outfwsettings{'ACTION'} eq 'Add rule')
189 &General
::readhash
("${General::swroot}/outgoing/settings", \
%outfwsettings);
192 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
193 print "<class name='base'>$errormessage\n";
194 print " </class>\n";
198 ############################################################################################################################
199 ############################################################################################################################
201 if ($outfwsettings{'POLICY'} ne 'MODE0'){
202 &Header
::openbox
('100%', 'center', 'Rules');
204 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
205 <input type='submit' name='ACTION' value='Add rule' />
209 open( FILE
, "< $configfile" ) or die "Unable to read $configfile";
215 <table border='0' width='100%' cellspacing='0'>
217 <td width='14%'><b>Protokoll</b>
218 <td width='14%'><b>Netzwerk</b>
219 <td width='14%'><b>Ziel</b>
220 <td width='14%'><b>Anmerkung</b>
221 <td width='14%'><b>Politik</b>
222 <td width='30%'><b>Aktionen</b>
225 foreach $configentry (sort @configs)
227 @configline = split( /\;/, $configentry );
228 $outfwsettings{'STATE'} = $configline[0];
229 $outfwsettings{'ENABLED'} = $configline[1];
230 $outfwsettings{'SNET'} = $configline[2];
231 $outfwsettings{'PROT'} = $configline[3];
232 $outfwsettings{'NAME'} = $configline[4];
233 $outfwsettings{'SIP'} = $configline[5];
234 $outfwsettings{'SMAC'} = $configline[6];
235 $outfwsettings{'DIP'} = $configline[7];
236 $outfwsettings{'DPORT'} = $configline[8];
237 if ($outfwsettings{'DIP'} eq ''){ $outfwsettings{'DISPLAY_DIP'} = 'ALL'; } else { $outfwsettings{'DISPLAY_DIP'} = $outfwsettings{'DIP'}; }
238 if ($outfwsettings{'DPORT'} eq ''){ $outfwsettings{'DISPLAY_DPORT'} = 'ALL'; } else { $outfwsettings{'DISPLAY_DPORT'} = $outfwsettings{'DPORT'}; }
239 if ($outfwsettings{'STATE'} eq 'DENY'){ $outfwsettings{'DISPLAY_STATE'} = "<img src='/images/stock_stop.png' alt='DENY'>"; }
240 if ($outfwsettings{'STATE'} eq 'ALLOW'){ $outfwsettings{'DISPLAY_STATE'} = "<img src='/images/stock_ok.png' alt='ALLOW'>"; }
241 if ((($outfwsettings{'POLICY'} eq 'MODE1') && ($outfwsettings{'STATE'} eq 'ALLOW')) || (($outfwsettings{'POLICY'} eq 'MODE2') && ($outfwsettings{'STATE'} eq 'DENY'))){
243 <tr bgcolor='#F0F0F0'>
244 <td align='center'>$outfwsettings{'PROT'}
245 <td align='center'>$outfwsettings{'SNET'}
246 <td align='center'>$outfwsettings{'DISPLAY_DIP'}:$outfwsettings{'DISPLAY_DPORT'}
247 <td align='center'>$outfwsettings{'NAME'}
248 <td align='center'>$outfwsettings{'DISPLAY_STATE'}
250 <table border='0' cellpadding='0' cellspacing='0'><tr>
251 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
252 <input type='hidden' name='PROT' value=$outfwsettings{'PROT'}>
253 <input type='hidden' name='STATE' value=$outfwsettings{'STATE'}>
254 <input type='hidden' name='SNET' value=$outfwsettings{'SNET'}>
255 <input type='hidden' name='DPORT' value=$outfwsettings{'DPORT'}>
256 <input type='hidden' name='DIP' value=$outfwsettings{'DIP'}>
257 <input type='hidden' name='SIP' value=$outfwsettings{'SIP'}>
258 <input type='hidden' name='NAME' value=$outfwsettings{'NAME'}>
259 <input type='hidden' name='SMAC' value=$outfwsettings{'SMAC'}>
260 <input type='hidden' name='ENABLED' value=$outfwsettings{'ENABLED'}>
261 <input type='hidden' name='ACTION' value=$Lang::tr{'edit'}>
262 <input type='image' src='/images/edit.gif' width="20" height="20" alt=$Lang::tr{'edit'}>
264 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
265 <input type='hidden' name='PROT' value=$outfwsettings{'PROT'}>
266 <input type='hidden' name='STATE' value=$outfwsettings{'STATE'}>
267 <input type='hidden' name='SNET' value=$outfwsettings{'SNET'}>
268 <input type='hidden' name='DPORT' value=$outfwsettings{'DPORT'}>
269 <input type='hidden' name='DIP' value=$outfwsettings{'DIP'}>
270 <input type='hidden' name='SIP' value=$outfwsettings{'SIP'}>
271 <input type='hidden' name='NAME' value=$outfwsettings{'NAME'}>
272 <input type='hidden' name='SMAC' value=$outfwsettings{'SMAC'}>
273 <input type='hidden' name='ENABLED' value=$outfwsettings{'ENABLED'}>
274 <input type='hidden' name='ACTION' value=$Lang::tr{'delete'}>
275 <input type='image' src='/images/delete.gif' width="20" height="20" alt=$Lang::tr{'delete'}>
279 if (($outfwsettings{'SIP'}) || ($outfwsettings{'SMAC'})) {
280 unless ($outfwsettings{'SIP'}) { $outfwsettings{'DISPLAY_SIP'} = 'ALL'; } else { $outfwsettings{'DISPLAY_SIP'} = $outfwsettings{'SIP'}; }
281 unless ($outfwsettings{'SMAC'}) { $outfwsettings{'DISPLAY_SMAC'} = 'ALL'; } else { $outfwsettings{'DISPLAY_SMAC'} = $outfwsettings{'SMAC'}; }
283 <tr><td width='14%' align='right'>Quell-IP-Adresse:
284 <td width='14%' align='left'>$outfwsettings{'DISPLAY_SIP'}
285 <td width='14%' align='right'>Quell-MAC-Adresse:
286 <td width='14%' align='left'>$outfwsettings{'DISPLAY_SMAC'}
287 <td width='44%' colspan='2' align='center'>
306 if ($outfwsettings{'POLICY'} eq 'MODE2'){
307 open( FILE
, "< $p2pfile" ) or die "Unable to read $p2pfile";
310 &Header
::openbox
('100%', 'center', 'P2P-Block');
313 <tr bgcolor='#FFFFFF'><td width='66%'><b>Protokoll</b>
314 <td width='33%'><b>Status</b>
318 foreach $p2pentry (sort @p2ps)
320 @p2pline = split( /\;/, $p2pentry );
322 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
326 print "\t\t\t<tr bgcolor='#F0F0F0'>\n";
329 print "\t\t\t<tr bgcolor='#FAFAFA'>\n";
333 <td width='66%' align='center'>$p2pline[0]:
334 <td width='33%' align='center'><input type='hidden' name='P2PROT' value=$p2pline[1]>
337 if ($p2pline[2] eq 'on') {
339 <input type='hidden' name='ACTION' value='disable'>
340 <input type='image' name='submit' src='/images/stock_ok.png' alt=''>
345 <input type='hidden' name='ACTION' value='enable'>
346 <input type='image' name='submit' src='/images/stock_stop.png' alt=''>
356 <tr><td colspan='2' align='center'>Klicken Sie auf die Symbole um das entsprechende P2P-Netz zu (de-)aktivieren.
363 &Header
::openbox
('100%', 'center', 'Policy');
365 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
367 <tr><td width='10%' align='right'><b>Modus 0:</b><td width='90%' align='left' colspan='2'>In diesem Modus ist es allen Rechnern im Netzwerk uneingeschraenkt moeglich Verbindungen ins Internet aufzubauen.
368 <tr><td width='10%' align='right'><b>Modus 1:</b><td width='90%' align='left' colspan='2'>In diesem Modus werden nur Verbindungen nach den oben definierten Regeln zugelassen.
369 <tr><td width='10%' align='right'><b>Modus 2:</b><td width='90%' align='left' colspan='2'>In diesem Modus werden saemtliche Verbindungen erlaubt, bis auf die oben definierten Block-Regeln.<br />Hier ist eine Besonderheit der P2P-Filter.
370 <tr><td colspan='3'><hr />
371 <tr><td width='10%' align='right'> <select name='POLICY'><option value='MODE0' $selected{'POLICY'}{'MODE0'}>Modus 0</option><option value='MODE1' $selected{'POLICY'}{'MODE1'}>Modus 1</option><option value='MODE2' $selected{'POLICY'}{'MODE2'}>Modus 2</option></select>
372 <td width='45%' align='left'><input type='submit' name='ACTION' value=$Lang::tr{'save'} />
373 <td width='45%' align='right'>
376 if ($outfwsettings{'POLICY'} ne 'MODE0') {
378 Alle Regeln loeschen: <input type='submit' name='ACTION' value=$Lang::tr{'reset'} />
389 &Header
::closebigbox
();
390 &Header
::closepage
();
392 ############################################################################################################################
393 ############################################################################################################################
397 &Header
::openbox
('100%', 'center', 'Rules hinzufuegen');
398 if ($outfwsettings{'EDIT'} eq 'no') { $selected{'ENABLED'} = 'checked'; }
400 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
402 <tr><td width='20%' align='right'>Anmerkung: <img src='/blob.gif'>
403 <td width='30%' align='left'><input type='text' name='NAME' maxlength='30' value='$outfwsettings{'NAME'}'>
404 <td width='20%' align='right'>Aktiviert:
405 <td width='30%' align='left'><input type='checkbox' name='ENABLED' $selected{'ENABLED'}>
406 <tr><td width='20%' align='right'>Protokoll:
407 <td width='30%' align='left'><select name='PROT'><option value='tcp' $selected{'PROT'}{'tcp'}>TCP</option><option value='tcp&udp' $selected{'PROT'}{'tcp&udp'}>TCP & UDP</option><option value='udp' $selected{'PROT'}{'udp'}>UDP</option></select>
408 <td width='20%' align='right'>Sicherheitspolitik:
409 <td width='30%' align='left'>
412 if ($outfwsettings{'POLICY'} eq 'MODE1'){
413 print "\t\t\tALLOW<input type='hidden' name='STATE' value='ALLOW'>\n";
414 } elsif ($outfwsettings{'POLICY'} eq 'MODE2'){
415 print "\t\t\tDENY<input type='hidden' name='STATE' value='DENY'>\n";
418 <tr><td width='20%' align='right'>Quellnetz:
419 <td width='30%' align='left'><select name='SNET'>
420 <option value='all' $selected{'SNET'}{'ALL'}>alle</option>
421 <option value='ip' $selected{'SNET'}{'ip'}>Quell-IP/MAC benutzen</option>
422 <option value='green' $selected{'SNET'}{'green'}>$Lang::tr{'green'}</option>
425 if (&Header
::blue_used
()){
426 print "\t\t\t<option value='blue' $selected{'SNET'}{'blue'}>$Lang::tr{'wireless'}</option>\n";
428 if (&Header
::orange_used
()){
429 print "\t\t\t<option value='orange' $selected{'SNET'}{'orange'}>$Lang::tr{'dmz'}</option>\n";
433 <td width='20%' align='right'>Quell-IP-Adresse: <img src='/blob.gif'>
434 <td width='30%' align='left'><input type='text' name='SIP' maxlength='15' value='$outfwsettings{'SIP'}'>
435 <tr><td width='50%' colspan='2'>
436 <td width='20%' align='right'>Quell-MAC-Adresse: <img src='/blob.gif'>
437 <td width='30%' align='left'><input type='text' name='SMAC' maxlength='23' value='$outfwsettings{'SMAC'}'>
438 <tr><td width='20%' align='right'>Ziel-IP-Adresse: <img src='/blob.gif'>
439 <td width='30%' align='left'><input type='text' name='DIP' maxlength='15' value='$outfwsettings{'DIP'}'>
440 <td width='20%' align='right'>Ziel-Port: <img src='/blob.gif'>
441 <td width='30%' align='left'><input type='text' name='DPORT' maxlength='11' value='$outfwsettings{'DPORT'}'>
443 <tr><td width='40%' align='right' colspan='2'><img src='/blob.gif'> $Lang::tr{'this field may be blank'}
444 <td width='60%' align='left' colspan='2'><input type='submit' name='ACTION' value=$Lang::tr{'add'}>
450 if ($outfwsettings{'POLICY'} eq 'MODE1')
452 &Header
::openbox
('100%', 'center', 'Quick Add');
454 open( FILE
, "< /var/ipfire/outgoing/defaultservices" ) or die "Unable to read default services";
455 my @defservices = <FILE
>;
458 print "<table width='100%'><tr bgcolor='#F0F0F0'><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></td></tr>";
459 foreach my $serviceline(@defservices)
461 my @service = split(/,/,$serviceline);
463 <tr><form method='post' action='$ENV{'SCRIPT_NAME'}'>
464 <td>$service[0]<input type='hidden' name='NAME' value='@service[0]' /></td>
466 <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>
467 <td>$service[2]<input type='hidden' name='PROT' value='@service[2]' /></td>
468 <td><select name='SNET'><option value='all' $selected{'SNET'}{'ALL'}>$Lang::tr{'all'}</option><option value='green' $selected{'SNET'}{'green'}>$Lang::tr{'green'}</option>
471 if (&Header
::blue_used
()){
472 print "<option value='blue' $selected{'SNET'}{'blue'}>$Lang::tr{'wireless'}</option>";
474 if (&Header
::orange_used
()){
475 print "<option value='orange' $selected{'SNET'}{'orange'}>$Lang::tr{'dmz'}</option>";
479 <input type='hidden' name='ACTION' value=$Lang::tr{'add'} />
480 <input type='image' alt='$Lang::tr{'add'}' src='/images/add.gif' />
481 <input type='hidden' name='ENABLED' value='on' />
482 <input type='hidden' name='STATE' value='ALLOW' />