]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/outgoingfw.cgi
Hinzugefuegt:
[ipfire-2.x.git] / html / cgi-bin / outgoingfw.cgi
CommitLineData
d9b7aa33
MT
1#!/usr/bin/perl
2#
3# IPFire CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The IPFire Team
8#
9
10use strict;
11# enable only the following on debugging purpose
12use warnings;
13use CGI::Carp 'fatalsToBrowser';
14
15require '/var/ipfire/general-functions.pl';
16require "${General::swroot}/lang.pl";
17require "${General::swroot}/header.pl";
18
19my %outfwsettings = ();
20my %checked = ();
21my %selected= () ;
22my %netsettings = ();
23my $errormessage = "";
24my $configentry = "";
25my @configs = ();
26my @configline = ();
27my $p2pentry = "";
28my @p2ps = ();
29my @p2pline = ();
30
31my $configfile = "/var/ipfire/outgoing/rules";
32my $p2pfile = "/var/ipfire/outgoing/p2protocols";
33
34&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
35
36&Header::showhttpheaders();
37
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'} = '';
1fde937c 55$outfwsettings{'POLICY'} = 'MODE0';
d9b7aa33
MT
56
57&General::readhash("${General::swroot}/outgoing/settings", \%outfwsettings);
58&Header::getcgihash(\%outfwsettings);
59
60if ($outfwsettings{'POLICY'} eq 'MODE0'){ $selected{'POLICY'}{'MODE0'} = 'selected'; } else { $selected{'POLICY'}{'MODE0'} = ''; }
61if ($outfwsettings{'POLICY'} eq 'MODE1'){ $selected{'POLICY'}{'MODE1'} = 'selected'; } else { $selected{'POLICY'}{'MODE1'} = ''; }
62if ($outfwsettings{'POLICY'} eq 'MODE2'){ $selected{'POLICY'}{'MODE2'} = 'selected'; } else { $selected{'POLICY'}{'MODE2'} = ''; }
63
64&Header::openpage('Ausgehende Firewall', 1, '');
65
66print <<END
67<script type="text/javascript">
68<!--
69function BorderOn (id) { id.className='btnOn' }
70function BorderOff(id) { id.className='btnOff' }
71//-->
72</script>
73<style type=text/css>
74.btnOn {
75 border-right: #D5F0FF 2px Inset;
76 border-top: #D5F0FF 2px Inset;
77 border-left: #D5F0FF 2px Inset;
78 border-bottom: #D5F0FF 2px Inset;
79 text-align: Center;
80 text-decoration: None;
81 background-color: #FFFFFF;
82}
83.btnOff {
84 border-right: #D5F0FF 2px Outset;
85 border-top: #D5F0FF 2px Outset;
86 border-left: #D5F0FF 2px Outset;
87 border-bottom: #D5F0FF 2px Outset;
88 text-align: Center;
89 text-decoration: None;
90 background-color: #FFFFFF;
91}
92</style>
93END
94;
95
96&Header::openbigbox('100%', 'left', '', $errormessage);
97
98############################################################################################################################
99############################################################################################################################
100
101if ($outfwsettings{'ACTION'} eq $Lang::tr{'reset'})
102{
103 $outfwsettings{'POLICY'}='MODE0';
104 unlink $configfile;
105 system("/bin/touch $configfile");
106 &General::writehash("${General::swroot}/outgoing/settings", \%outfwsettings);
107}
108if ($outfwsettings{'ACTION'} eq $Lang::tr{'save'})
109{
110 &General::writehash("${General::swroot}/outgoing/settings", \%outfwsettings);
111}
112if ($outfwsettings{'ACTION'} eq 'enable')
113{
114 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
115 @p2ps = <FILE>;
116 close FILE;
117 open( FILE, "> $p2pfile" ) or die "Unable to write $p2pfile";
118 foreach $p2pentry (sort @p2ps)
119 {
120 @p2pline = split( /\;/, $p2pentry );
121 if ($p2pline[1] eq $outfwsettings{'P2PROT'}) {
122 print FILE "$p2pline[0];$p2pline[1];on;\n";
123 } else {
124 print FILE "$p2pline[0];$p2pline[1];$p2pline[2];\n";
125 }
126 }
127 close FILE;
128}
129if ($outfwsettings{'ACTION'} eq 'disable')
130{
131 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
132 @p2ps = <FILE>;
133 close FILE;
134 open( FILE, "> $p2pfile" ) or die "Unable to write $p2pfile";
135 foreach $p2pentry (sort @p2ps)
136 {
137 @p2pline = split( /\;/, $p2pentry );
138 if ($p2pline[1] eq $outfwsettings{'P2PROT'}) {
139 print FILE "$p2pline[0];$p2pline[1];off;\n";
140 } else {
141 print FILE "$p2pline[0];$p2pline[1];$p2pline[2];\n";
142 }
143 }
144 close FILE;
145}
146if ($outfwsettings{'ACTION'} eq $Lang::tr{'edit'})
147{
148 open( FILE, "< $configfile" ) or die "Unable to read $configfile";
149 @configs = <FILE>;
150 close FILE;
151 open( FILE, "> $configfile" ) or die "Unable to write $configfile";
152 foreach $configentry (sort @configs)
153 {
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'}))
164 {
165 print FILE $configentry;
166 }
167 }
168 close FILE;
169 &addrule();
170 &Header::closebigbox();
171 &Header::closepage();
172 exit
173}
174if ($outfwsettings{'ACTION'} eq $Lang::tr{'delete'})
175{
176 open( FILE, "< $configfile" ) or die "Unable to read $configfile";
177 @configs = <FILE>;
178 close FILE;
179 open( FILE, "> $configfile" ) or die "Unable to write $configfile";
180 foreach $configentry (sort @configs)
181 {
182 @configline = split( /\;/, $configentry );
183 unless (($configline[0] eq $outfwsettings{'STATE'}) &&
184 ($configline[1] eq $outfwsettings{'ENABLED'}) &&
185 ($configline[2] eq $outfwsettings{'SNET'}) &&
186 ($configline[3] eq $outfwsettings{'PROT'}) &&
187 ($configline[4] eq $outfwsettings{'NAME'}) &&
188 ($configline[5] eq $outfwsettings{'SIP'}) &&
189 ($configline[6] eq $outfwsettings{'SMAC'}) &&
190 ($configline[7] eq $outfwsettings{'DIP'}) &&
191 ($configline[8] eq $outfwsettings{'DPORT'}))
192 {
193 print FILE $configentry;
194 }
195 }
196 close FILE;
197}
198if ($outfwsettings{'ACTION'} eq $Lang::tr{'add'})
199{
200 if ( $outfwsettings{'VALID'} eq 'yes' ) {
201 open( FILE, ">> $configfile" ) or die "Unable to write $configfile";
202 print FILE <<END
203$outfwsettings{'STATE'};$outfwsettings{'ENABLED'};$outfwsettings{'SNET'};$outfwsettings{'PROT'};$outfwsettings{'NAME'};$outfwsettings{'SIP'};$outfwsettings{'SMAC'};$outfwsettings{'DIP'};$outfwsettings{'DPORT'};
204END
205;
206 close FILE;
207 } else {
208 $outfwsettings{'ACTION'} = 'Regel hinzufuegen';
209 }
210}
211if ($outfwsettings{'ACTION'} eq 'Regel hinzufuegen')
212{
213 &addrule();
214 exit
215}
216
217&General::readhash("${General::swroot}/outgoing/settings", \%outfwsettings);
218
219if ($errormessage) {
220 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
221 print "<class name='base'>$errormessage\n";
222 print "&nbsp;</class>\n";
223 &Header::closebox();
224}
225
226############################################################################################################################
227############################################################################################################################
228
229if ($outfwsettings{'POLICY'} ne 'MODE0'){
230 &Header::openbox('100%', 'center', 'Rules');
231 print <<END
232 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
233 <input type='submit' name='ACTION' class='btnOff' onmouseover='BorderOn(this)' onmouseout='BorderOff(this)' value='Regel hinzufuegen'>
234END
235;
236 open( FILE, "< $configfile" ) or die "Unable to read $configfile";
237 @configs = <FILE>;
238 close FILE;
239 if (@configs) {
240 print <<END
241 <hr>
242 <table border='0' width='100%' cellspacing='0'>
243 <tr><td bgcolor='lightgrey' width='14%'>Protokoll
244 <td bgcolor='lightgrey' width='14%'>Netzwerk
245 <td bgcolor='lightgrey' width='14%'>Ziel
246 <td bgcolor='lightgrey' width='14%'>Anmerkung
247 <td bgcolor='lightgrey' width='14%'>Politik
248 <td bgcolor='lightgrey' width='30%'>Aktionen
249END
250;
251 foreach $configentry (sort @configs)
252 {
253 @configline = split( /\;/, $configentry );
254 $outfwsettings{'STATE'} = $configline[0];
255 $outfwsettings{'ENABLED'} = $configline[1];
256 $outfwsettings{'SNET'} = $configline[2];
257 $outfwsettings{'PROT'} = $configline[3];
258 $outfwsettings{'NAME'} = $configline[4];
259 $outfwsettings{'SIP'} = $configline[5];
260 $outfwsettings{'SMAC'} = $configline[6];
261 $outfwsettings{'DIP'} = $configline[7];
262 $outfwsettings{'DPORT'} = $configline[8];
263 if ($outfwsettings{'DIP'} eq ''){ $outfwsettings{'DISPLAY_DIP'} = 'ALL'; } else { $outfwsettings{'DISPLAY_DIP'} = $outfwsettings{'DIP'}; }
264 if ($outfwsettings{'DPORT'} eq ''){ $outfwsettings{'DISPLAY_DPORT'} = 'ALL'; } else { $outfwsettings{'DISPLAY_DPORT'} = $outfwsettings{'DPORT'}; }
265 if ($outfwsettings{'STATE'} eq 'DENY'){ $outfwsettings{'DISPLAY_STATE'} = "<img src='/images/stock_stop.png' alt='DENY'>"; }
266 if ($outfwsettings{'STATE'} eq 'ALLOW'){ $outfwsettings{'DISPLAY_STATE'} = "<img src='/images/stock_ok.png' alt='ALLOW'>"; }
267 if ((($outfwsettings{'POLICY'} eq 'MODE1') && ($outfwsettings{'STATE'} eq 'ALLOW')) || (($outfwsettings{'POLICY'} eq 'MODE2') && ($outfwsettings{'STATE'} eq 'DENY'))){
268 print <<END
269 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
270 <input type='hidden' name='PROT' value=$outfwsettings{'PROT'}>
271 <input type='hidden' name='STATE' value=$outfwsettings{'STATE'}>
272 <input type='hidden' name='SNET' value=$outfwsettings{'SNET'}>
273 <input type='hidden' name='DPORT' value=$outfwsettings{'DPORT'}>
274 <input type='hidden' name='DIP' value=$outfwsettings{'DIP'}>
275 <input type='hidden' name='SIP' value=$outfwsettings{'SIP'}>
276 <input type='hidden' name='NAME' value=$outfwsettings{'NAME'}>
277 <input type='hidden' name='SMAC' value=$outfwsettings{'SMAC'}>
278 <input type='hidden' name='ENABLED' value=$outfwsettings{'ENABLED'}>
279 <tr><td align='center' bgcolor='#EAEAEA'>$outfwsettings{'PROT'}
280 <td align='center' bgcolor='#EAEAEA'>$outfwsettings{'SNET'}
281 <td align='center' bgcolor='#EAEAEA'>$outfwsettings{'DISPLAY_DIP'}:$outfwsettings{'DISPLAY_DPORT'}
282 <td align='center' bgcolor='#EAEAEA'>$outfwsettings{'NAME'}
283 <td align='center' bgcolor='#EAEAEA'>$outfwsettings{'DISPLAY_STATE'}
284 <td align='right' bgcolor='#EAEAEA'>
285 <button type='submit' name='ACTION' value=$Lang::tr{'edit'} class='btnOff' onmouseover='BorderOn(this)' onmouseout='BorderOff(this)'><img src='/images/edit.gif' width="20" height="20" alt=$Lang::tr{'edit'}></button>&nbsp;
286 <button type='submit' name='ACTION' value=$Lang::tr{'delete'} class='btnOff' onmouseover='BorderOn(this)' onmouseout='BorderOff(this)'><img src='/images/delete.gif' width="20" height="20" alt=$Lang::tr{'delete'}></button>
287END
288;
289 if (($outfwsettings{'SIP'}) || ($outfwsettings{'SMAC'})) {
290 unless ($outfwsettings{'SIP'}) { $outfwsettings{'DISPLAY_SIP'} = '---'; } else { $outfwsettings{'DISPLAY_SIP'} = $outfwsettings{'SIP'}; }
291 unless ($outfwsettings{'SMAC'}) { $outfwsettings{'DISPLAY_SMAC'} = '---'; } else { $outfwsettings{'DISPLAY_SMAC'} = $outfwsettings{'SMAC'}; }
292 print <<END
293 <tr><td width='14%' align='right' bgcolor='#FAFAFA'>Quell-IP-Adresse:
294 <td width='14%' align='left' bgcolor='#FAFAFA'>$outfwsettings{'DISPLAY_SIP'}
295 <td width='14%' align='right' bgcolor='#FAFAFA'>Quell-MAC-Adresse:
296 <td width='14%' align='left' bgcolor='#FAFAFA'>$outfwsettings{'DISPLAY_SMAC'}
297 <td width='44%' colspan='2' align='center' bgcolor='#FAFAFA'>
298END
299;
300 }
301 print <<END
302 </form>
303END
304;
305 }
306 }
307 print <<END
308 </table>
309END
310;
311
312 }
313 print <<END
314 </form>
315END
316;
317 &Header::closebox();
318}
319
320if ($outfwsettings{'POLICY'} eq 'MODE2'){
321 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
322 @p2ps = <FILE>;
323 close FILE;
324 &Header::openbox('100%', 'center', 'P2P-Block');
325 print <<END
326 <table width='40%'>
327 <tr><td bgcolor='lightgrey' width='66%'>Protokoll
328 <td bgcolor='lightgrey' width='33%'>Status
329END
330;
331 foreach $p2pentry (sort @p2ps)
332 {
333 @p2pline = split( /\;/, $p2pentry );
334 print <<END
335 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
336 <tr><td width='66%' align='center'>$p2pline[0]:
337 <td width='33%' align='center'><input type='hidden' name='P2PROT' value=$p2pline[1]>
338END
339;
340 if ($p2pline[2] eq 'on') {
341 print <<END
342 <input type='hidden' name='ACTION' value='disable'>
343 <input type='image' name='submit' src='/images/stock_ok.png' alt=''>
344END
345;
346 } else {
347 print <<END
348 <input type='hidden' name='ACTION' value='enable'>
349 <input type='image' name='submit' src='/images/stock_stop.png' alt=''>
350END
351;
352 }
353 print <<END
354 </form>
355END
356;
357 }
358 print <<END
359 <tr><td colspan='2' align='center'>Klicken Sie auf die Symbole um das entsprechende P2P-Netz zu (de-)aktivieren.
360 </table>
361END
362;
363 &Header::closebox();
364}
365
366&Header::openbox('100%', 'center', 'Policy');
367print <<END
368 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
369 <table width='100%'>
370 <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.
371 <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.
372 <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.
373 <tr><td colspan='3'><hr>
374 <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>
375 <td width='45%' align='left'><input type='submit' name='ACTION' value=$Lang::tr{'save'}>
376 <td width='45%' align='right'>
377END
378;
379 if ($outfwsettings{'POLICY'} ne 'MODE0') {
380 print <<END
381 Alle Regeln loeschen: <input type='submit' name='ACTION' value=$Lang::tr{'reset'}>
382END
383;
384 }
385print <<END
386 </table>
387 </form>
388END
389;
390&Header::closebox();
391
392&Header::closebigbox();
393&Header::closepage();
394
395############################################################################################################################
396############################################################################################################################
397
398sub addrule
399{
400 &Header::openbox('100%', 'center', 'Rules hinzufuegen');
401 if ($outfwsettings{'EDIT'} eq 'no') { $selected{'ENABLED'} = 'checked'; }
402 print <<END
403 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
404 <table width='80%'>
405 <tr><td width='20%' align='right'>Anmerkung: <img src='/blob.gif'>
406 <td width='30%' align='left'><input type='text' name='NAME' maxlength='30' value='$outfwsettings{'NAME'}'>
407 <td width='20%' align='right'>Aktiviert:
408 <td width='30%' align='left'><input type='checkbox' name='ENABLED' $selected{'ENABLED'}>
409 <tr><td width='20%' align='right'>Protokoll:
410 <td width='30%' align='left'><select name='PROT'><option value='tcp' $selected{'PROT'}{'TCP'}>TCP</option><option value='udp' $selected{'PROT'}{'UDP'}>UDP</option></select>
411 <td width='20%' align='right'>Sicherheitspolitik:
412 <td width='30%' align='left'>
413END
414;
415 if ($outfwsettings{'POLICY'} eq 'MODE1'){
416 print "\t\t\tALLOW<input type='hidden' name='STATE' value='ALLOW'>\n";
417 } elsif ($outfwsettings{'POLICY'} eq 'MODE2'){
418 print "\t\t\tDENY<input type='hidden' name='STATE' value='DENY'>\n";
419 }
420 print <<END
421 <tr><td width='20%' align='right'>Quellnetz:
422 <td width='30%' align='left'><select name='SNET'>
423 <option value='all' $selected{'SNET'}{'ALL'}>alle</option>
424 <option value='green' $selected{'SNET'}{'GREEN'}>Gruen</option>
425END
426;
427 if (&Header::blue_used()){
428 print "\t\t\t<option value='blue' $selected{'SNET'}{'BLUE'}>Blau</option>\n";
429 }
430 if (&Header::orange_used()){
431 print "\t\t\t<option value='orange' $selected{'SNET'}{'ORANGE'}>Orange</option>\n";
432 }
433 print <<END
434 </select>
435 <td width='20%' align='right'>Quell-IP-Adresse: <img src='/blob.gif'>
436 <td width='30%' align='left'><input type='text' name='SIP' maxlength='15' value='$outfwsettings{'SIP'}'>
437 <tr><td width='50%' colspan='2'>&nbsp;
438 <td width='20%' align='right'>Quell-MAC-Adresse: <img src='/blob.gif'>
439 <td width='30%' align='left'><input type='text' name='SMAC' maxlength='23' value='$outfwsettings{'SMAC'}'>
440 <tr><td width='20%' align='right'>Ziel-IP-Adresse: <img src='/blob.gif'>
441 <td width='30%' align='left'><input type='text' name='DIP' maxlength='15' value='$outfwsettings{'DIP'}'>
442 <td width='20%' align='right'>Ziel-Port: <img src='/blob.gif'>
443 <td width='30%' align='left'><input type='text' name='DPORT' maxlength='5' value='$outfwsettings{'DPORT'}'>
444 <tr><td colspan='4'>
445 <tr><td width='40%' align='right' colspan='2'><img src='/blob.gif'> $Lang::tr{'this field may be blank'}
446 <td width='60%' align='left' colspan='2'><input type='submit' name='ACTION' value=$Lang::tr{'add'}>
447 </table></form>
448END
449;
450 &Header::closebox();
451}
452