ab7c2fa08d484f80bc8b44547b8cae695fa83aab
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";
34 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
36 &Header
::showhttpheaders
();
38 ### Values that have to be initialized
39 $outfwsettings{'ACTION'} = '';
40 $outfwsettings{'VALID'} = 'yes';
41 $outfwsettings{'EDIT'} = 'no';
42 $outfwsettings{'NAME'} = '';
43 $outfwsettings{'SNET'} = '';
44 $outfwsettings{'SIP'} = '';
45 $outfwsettings{'SPORT'} = '';
46 $outfwsettings{'SMAC'} = '';
47 $outfwsettings{'DIP'} = '';
48 $outfwsettings{'DPORT'} = '';
49 $outfwsettings{'PROT'} = '';
50 $outfwsettings{'STATE'} = '';
51 $outfwsettings{'DISPLAY_DIP'} = '';
52 $outfwsettings{'DISPLAY_DPORT'} = '';
53 $outfwsettings{'DISPLAY_SMAC'} = '';
54 $outfwsettings{'DISPLAY_SIP'} = '';
55 $outfwsettings{'POLICY'} = 'MODE0';
57 &General
::readhash
("${General::swroot}/outgoing/settings", \
%outfwsettings);
58 &Header
::getcgihash
(\
%outfwsettings);
60 if ($outfwsettings{'POLICY'} eq 'MODE0'){ $selected{'POLICY'}{'MODE0'} = 'selected'; } else { $selected{'POLICY'}{'MODE0'} = ''; }
61 if ($outfwsettings{'POLICY'} eq 'MODE1'){ $selected{'POLICY'}{'MODE1'} = 'selected'; } else { $selected{'POLICY'}{'MODE1'} = ''; }
62 if ($outfwsettings{'POLICY'} eq 'MODE2'){ $selected{'POLICY'}{'MODE2'} = 'selected'; } else { $selected{'POLICY'}{'MODE2'} = ''; }
64 &Header
::openpage
('Ausgehende Firewall', 1, '');
65 &Header
::openbigbox
('100%', 'left', '', $errormessage);
67 ############################################################################################################################
68 ############################################################################################################################
70 if ($outfwsettings{'ACTION'} eq $Lang::tr
{'reset'})
72 $outfwsettings{'POLICY'}='MODE0';
74 system("/usr/bin/touch $configfile");
75 &General
::writehash
("${General::swroot}/outgoing/settings", \
%outfwsettings);
77 if ($outfwsettings{'ACTION'} eq $Lang::tr
{'save'})
79 &General
::writehash
("${General::swroot}/outgoing/settings", \
%outfwsettings);
81 if ($outfwsettings{'ACTION'} eq 'enable')
83 open( FILE
, "< $p2pfile" ) or die "Unable to read $p2pfile";
86 open( FILE
, "> $p2pfile" ) or die "Unable to write $p2pfile";
87 foreach $p2pentry (sort @p2ps)
89 @p2pline = split( /\;/, $p2pentry );
90 if ($p2pline[1] eq $outfwsettings{'P2PROT'}) {
91 print FILE
"$p2pline[0];$p2pline[1];on;\n";
93 print FILE
"$p2pline[0];$p2pline[1];$p2pline[2];\n";
98 if ($outfwsettings{'ACTION'} eq 'disable')
100 open( FILE
, "< $p2pfile" ) or die "Unable to read $p2pfile";
103 open( FILE
, "> $p2pfile" ) or die "Unable to write $p2pfile";
104 foreach $p2pentry (sort @p2ps)
106 @p2pline = split( /\;/, $p2pentry );
107 if ($p2pline[1] eq $outfwsettings{'P2PROT'}) {
108 print FILE
"$p2pline[0];$p2pline[1];off;\n";
110 print FILE
"$p2pline[0];$p2pline[1];$p2pline[2];\n";
115 if ($outfwsettings{'ACTION'} eq $Lang::tr
{'edit'})
117 open( FILE
, "< $configfile" ) or die "Unable to read $configfile";
120 open( FILE
, "> $configfile" ) or die "Unable to write $configfile";
121 foreach $configentry (sort @configs)
123 @configline = split( /\;/, $configentry );
124 unless (($configline[0] eq $outfwsettings{'STATE'}) &&
125 ($configline[1] eq $outfwsettings{'ENABLED'}) &&
126 ($configline[2] eq $outfwsettings{'SNET'}) &&
127 ($configline[3] eq $outfwsettings{'PROT'}) &&
128 ($configline[4] eq $outfwsettings{'NAME'}) &&
129 ($configline[5] eq $outfwsettings{'SIP'}) &&
130 ($configline[6] eq $outfwsettings{'SMAC'}) &&
131 ($configline[7] eq $outfwsettings{'DIP'}) &&
132 ($configline[8] eq $outfwsettings{'DPORT'}))
134 print FILE
$configentry;
138 $selected{'SNET'}{"$outfwsettings{'SNET'}"} = 'selected';
139 $selected{'PROT'}{"$outfwsettings{'PROT'}"} = 'selected';
141 &Header
::closebigbox
();
142 &Header
::closepage
();
145 if ($outfwsettings{'ACTION'} eq $Lang::tr
{'delete'})
147 open( FILE
, "< $configfile" ) or die "Unable to read $configfile";
150 open( FILE
, "> $configfile" ) or die "Unable to write $configfile";
151 foreach $configentry (sort @configs)
153 @configline = split( /\;/, $configentry );
154 unless (($configline[0] eq $outfwsettings{'STATE'}) &&
155 ($configline[1] eq $outfwsettings{'ENABLED'}) &&
156 ($configline[2] eq $outfwsettings{'SNET'}) &&
157 ($configline[3] eq $outfwsettings{'PROT'}) &&
158 ($configline[4] eq $outfwsettings{'NAME'}) &&
159 ($configline[5] eq $outfwsettings{'SIP'}) &&
160 ($configline[6] eq $outfwsettings{'SMAC'}) &&
161 ($configline[7] eq $outfwsettings{'DIP'}) &&
162 ($configline[8] eq $outfwsettings{'DPORT'}))
164 print FILE
$configentry;
169 if ($outfwsettings{'ACTION'} eq $Lang::tr
{'add'})
171 if ( $outfwsettings{'VALID'} eq 'yes' ) {
172 open( FILE
, ">> $configfile" ) or die "Unable to write $configfile";
174 $outfwsettings{'STATE'};$outfwsettings{'ENABLED'};$outfwsettings{'SNET'};$outfwsettings{'PROT'};$outfwsettings{'NAME'};$outfwsettings{'SIP'};$outfwsettings{'SMAC'};$outfwsettings{'DIP'};$outfwsettings{'DPORT'};
179 $outfwsettings{'ACTION'} = 'Add rule';
182 if ($outfwsettings{'ACTION'} eq 'Add rule')
188 &General
::readhash
("${General::swroot}/outgoing/settings", \
%outfwsettings);
191 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
192 print "<class name='base'>$errormessage\n";
193 print " </class>\n";
197 ############################################################################################################################
198 ############################################################################################################################
200 if ($outfwsettings{'POLICY'} ne 'MODE0'){
201 &Header
::openbox
('100%', 'center', 'Rules');
203 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
204 <input type='submit' name='ACTION' value='Add rule'>
208 open( FILE
, "< $configfile" ) or die "Unable to read $configfile";
214 <table border='0' width='100%' cellspacing='0'>
216 <td width='14%'><b>Protokoll</b>
217 <td width='14%'><b>Netzwerk</b>
218 <td width='14%'><b>Ziel</b>
219 <td width='14%'><b>Anmerkung</b>
220 <td width='14%'><b>Politik</b>
221 <td width='30%'><b>Aktionen</b>
224 foreach $configentry (sort @configs)
226 @configline = split( /\;/, $configentry );
227 $outfwsettings{'STATE'} = $configline[0];
228 $outfwsettings{'ENABLED'} = $configline[1];
229 $outfwsettings{'SNET'} = $configline[2];
230 $outfwsettings{'PROT'} = $configline[3];
231 $outfwsettings{'NAME'} = $configline[4];
232 $outfwsettings{'SIP'} = $configline[5];
233 $outfwsettings{'SMAC'} = $configline[6];
234 $outfwsettings{'DIP'} = $configline[7];
235 $outfwsettings{'DPORT'} = $configline[8];
236 if ($outfwsettings{'DIP'} eq ''){ $outfwsettings{'DISPLAY_DIP'} = 'ALL'; } else { $outfwsettings{'DISPLAY_DIP'} = $outfwsettings{'DIP'}; }
237 if ($outfwsettings{'DPORT'} eq ''){ $outfwsettings{'DISPLAY_DPORT'} = 'ALL'; } else { $outfwsettings{'DISPLAY_DPORT'} = $outfwsettings{'DPORT'}; }
238 if ($outfwsettings{'STATE'} eq 'DENY'){ $outfwsettings{'DISPLAY_STATE'} = "<img src='/images/stock_stop.png' alt='DENY'>"; }
239 if ($outfwsettings{'STATE'} eq 'ALLOW'){ $outfwsettings{'DISPLAY_STATE'} = "<img src='/images/stock_ok.png' alt='ALLOW'>"; }
240 if ((($outfwsettings{'POLICY'} eq 'MODE1') && ($outfwsettings{'STATE'} eq 'ALLOW')) || (($outfwsettings{'POLICY'} eq 'MODE2') && ($outfwsettings{'STATE'} eq 'DENY'))){
242 <tr bgcolor='#F0F0F0'>
243 <td align='center'>$outfwsettings{'PROT'}
244 <td align='center'>$outfwsettings{'SNET'}
245 <td align='center'>$outfwsettings{'DISPLAY_DIP'}:$outfwsettings{'DISPLAY_DPORT'}
246 <td align='center'>$outfwsettings{'NAME'}
247 <td align='center'>$outfwsettings{'DISPLAY_STATE'}
249 <table border='0' cellpadding='0' cellspacing='0'><tr>
250 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
251 <input type='hidden' name='PROT' value=$outfwsettings{'PROT'}>
252 <input type='hidden' name='STATE' value=$outfwsettings{'STATE'}>
253 <input type='hidden' name='SNET' value=$outfwsettings{'SNET'}>
254 <input type='hidden' name='DPORT' value=$outfwsettings{'DPORT'}>
255 <input type='hidden' name='DIP' value=$outfwsettings{'DIP'}>
256 <input type='hidden' name='SIP' value=$outfwsettings{'SIP'}>
257 <input type='hidden' name='NAME' value=$outfwsettings{'NAME'}>
258 <input type='hidden' name='SMAC' value=$outfwsettings{'SMAC'}>
259 <input type='hidden' name='ENABLED' value=$outfwsettings{'ENABLED'}>
260 <input type='hidden' name='ACTION' value=$Lang::tr{'edit'}>
261 <input type='image' src='/images/edit.gif' width="20" height="20" alt=$Lang::tr{'edit'}>
263 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
264 <input type='hidden' name='PROT' value=$outfwsettings{'PROT'}>
265 <input type='hidden' name='STATE' value=$outfwsettings{'STATE'}>
266 <input type='hidden' name='SNET' value=$outfwsettings{'SNET'}>
267 <input type='hidden' name='DPORT' value=$outfwsettings{'DPORT'}>
268 <input type='hidden' name='DIP' value=$outfwsettings{'DIP'}>
269 <input type='hidden' name='SIP' value=$outfwsettings{'SIP'}>
270 <input type='hidden' name='NAME' value=$outfwsettings{'NAME'}>
271 <input type='hidden' name='SMAC' value=$outfwsettings{'SMAC'}>
272 <input type='hidden' name='ENABLED' value=$outfwsettings{'ENABLED'}>
273 <input type='hidden' name='ACTION' value=$Lang::tr{'delete'}>
274 <input type='image' src='/images/delete.gif' width="20" height="20" alt=$Lang::tr{'delete'}>
278 if (($outfwsettings{'SIP'}) || ($outfwsettings{'SMAC'})) {
279 unless ($outfwsettings{'SIP'}) { $outfwsettings{'DISPLAY_SIP'} = 'ALL'; } else { $outfwsettings{'DISPLAY_SIP'} = $outfwsettings{'SIP'}; }
280 unless ($outfwsettings{'SMAC'}) { $outfwsettings{'DISPLAY_SMAC'} = 'ALL'; } else { $outfwsettings{'DISPLAY_SMAC'} = $outfwsettings{'SMAC'}; }
282 <tr><td width='14%' align='right'>Quell-IP-Adresse:
283 <td width='14%' align='left'>$outfwsettings{'DISPLAY_SIP'}
284 <td width='14%' align='right'>Quell-MAC-Adresse:
285 <td width='14%' align='left'>$outfwsettings{'DISPLAY_SMAC'}
286 <td width='44%' colspan='2' align='center'>
305 if ($outfwsettings{'POLICY'} eq 'MODE2'){
306 open( FILE
, "< $p2pfile" ) or die "Unable to read $p2pfile";
309 &Header
::openbox
('100%', 'center', 'P2P-Block');
312 <tr bgcolor='#FFFFFF'><td width='66%'><b>Protokoll</b>
313 <td width='33%'><b>Status</b>
317 foreach $p2pentry (sort @p2ps)
319 @p2pline = split( /\;/, $p2pentry );
321 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
325 print "\t\t\t<tr bgcolor='#F0F0F0'>\n";
328 print "\t\t\t<tr bgcolor='#FAFAFA'>\n";
332 <td width='66%' align='center'>$p2pline[0]:
333 <td width='33%' align='center'><input type='hidden' name='P2PROT' value=$p2pline[1]>
336 if ($p2pline[2] eq 'on') {
338 <input type='hidden' name='ACTION' value='disable'>
339 <input type='image' name='submit' src='/images/stock_ok.png' alt=''>
344 <input type='hidden' name='ACTION' value='enable'>
345 <input type='image' name='submit' src='/images/stock_stop.png' alt=''>
355 <tr><td colspan='2' align='center'>Klicken Sie auf die Symbole um das entsprechende P2P-Netz zu (de-)aktivieren.
362 &Header
::openbox
('100%', 'center', 'Policy');
364 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
366 <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.
367 <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.
368 <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.
369 <tr><td colspan='3'><hr>
370 <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>
371 <td width='45%' align='left'><input type='submit' name='ACTION' value=$Lang::tr{'save'}>
372 <td width='45%' align='right'>
375 if ($outfwsettings{'POLICY'} ne 'MODE0') {
377 Alle Regeln loeschen: <input type='submit' name='ACTION' value=$Lang::tr{'reset'}>
388 &Header
::closebigbox
();
389 &Header
::closepage
();
391 ############################################################################################################################
392 ############################################################################################################################
396 &Header
::openbox
('100%', 'center', 'Rules hinzufuegen');
397 if ($outfwsettings{'EDIT'} eq 'no') { $selected{'ENABLED'} = 'checked'; }
399 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
401 <tr><td width='20%' align='right'>Anmerkung: <img src='/blob.gif'>
402 <td width='30%' align='left'><input type='text' name='NAME' maxlength='30' value='$outfwsettings{'NAME'}'>
403 <td width='20%' align='right'>Aktiviert:
404 <td width='30%' align='left'><input type='checkbox' name='ENABLED' $selected{'ENABLED'}>
405 <tr><td width='20%' align='right'>Protokoll:
406 <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>
407 <td width='20%' align='right'>Sicherheitspolitik:
408 <td width='30%' align='left'>
411 if ($outfwsettings{'POLICY'} eq 'MODE1'){
412 print "\t\t\tALLOW<input type='hidden' name='STATE' value='ALLOW'>\n";
413 } elsif ($outfwsettings{'POLICY'} eq 'MODE2'){
414 print "\t\t\tDENY<input type='hidden' name='STATE' value='DENY'>\n";
417 <tr><td width='20%' align='right'>Quellnetz:
418 <td width='30%' align='left'><select name='SNET'>
419 <option value='all' $selected{'SNET'}{'ALL'}>alle</option>
420 <option value='ip' $selected{'SNET'}{'ip'}>Quell-IP/MAC benutzen</option>
421 <option value='green' $selected{'SNET'}{'green'}>Gruen</option>
424 if (&Header
::blue_used
()){
425 print "\t\t\t<option value='blue' $selected{'SNET'}{'blue'}>Blau</option>\n";
427 if (&Header
::orange_used
()){
428 print "\t\t\t<option value='orange' $selected{'SNET'}{'orange'}>Orange</option>\n";
432 <td width='20%' align='right'>Quell-IP-Adresse: <img src='/blob.gif'>
433 <td width='30%' align='left'><input type='text' name='SIP' maxlength='15' value='$outfwsettings{'SIP'}'>
434 <tr><td width='50%' colspan='2'>
435 <td width='20%' align='right'>Quell-MAC-Adresse: <img src='/blob.gif'>
436 <td width='30%' align='left'><input type='text' name='SMAC' maxlength='23' value='$outfwsettings{'SMAC'}'>
437 <tr><td width='20%' align='right'>Ziel-IP-Adresse: <img src='/blob.gif'>
438 <td width='30%' align='left'><input type='text' name='DIP' maxlength='15' value='$outfwsettings{'DIP'}'>
439 <td width='20%' align='right'>Ziel-Port: <img src='/blob.gif'>
440 <td width='30%' align='left'><input type='text' name='DPORT' maxlength='11' value='$outfwsettings{'DPORT'}'>
442 <tr><td width='40%' align='right' colspan='2'><img src='/blob.gif'> $Lang::tr{'this field may be blank'}
443 <td width='60%' align='left' colspan='2'><input type='submit' name='ACTION' value=$Lang::tr{'add'}>