7c6f7b3a469cb754c684c4f864dd6c07672eccce
[people/teissler/ipfire-2.x.git] / html / cgi-bin / p2p-block.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 Alexander Marx <amarx@ipfire.org> #
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 no warnings 'uninitialized';
24 # enable only the following on debugging purpose
25 #use warnings;
26 #use CGI::Carp 'fatalsToBrowser';
27
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31
32 my $errormessage='';
33 my $p2pfile = "${General::swroot}/forward/p2protocols";
34
35 my @p2ps = ();
36 my %fwdfwsettings=();
37 my %color=();
38 my %mainsettings=();
39
40 &General::readhash("${General::swroot}/forward/settings", \%fwdfwsettings);
41 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
42 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
43
44
45
46 &Header::showhttpheaders();
47 &Header::getcgihash(\%fwdfwsettings);
48 &Header::openpage($Lang::tr{'fwdfw menu'}, 1, '');
49 &Header::openbigbox('100%', 'center',$errormessage);
50
51 if ($fwdfwsettings{'ACTION'} eq ''){
52 &p2pblock;
53 }
54 if ($fwdfwsettings{'ACTION'} eq 'togglep2p')
55 {
56 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
57 @p2ps = <FILE>;
58 close FILE;
59 open( FILE, "> $p2pfile" ) or die "Unable to write $p2pfile";
60 foreach my $p2pentry (sort @p2ps)
61 {
62 my @p2pline = split( /\;/, $p2pentry );
63 if ($p2pline[1] eq $fwdfwsettings{'P2PROT'}) {
64 if($p2pline[2] eq 'on'){
65 $p2pline[2]='off';
66 }else{
67 $p2pline[2]='on';
68 }
69 }
70 print FILE "$p2pline[0];$p2pline[1];$p2pline[2];\n";
71 }
72 close FILE;
73 &rules;
74 &p2pblock;
75 }
76 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
77 {
78 &reread_rules;
79 &p2pblock;
80 }
81
82
83 sub p2pblock
84 {
85 if (-f "${General::swroot}/forward/reread"){
86 print "<table border='0'><form method='post'><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-face: Comic Sans MS; color: red; font-weight: bold;'>$Lang::tr{'fwhost reread'}</td></tr></table></form><hr><br>";
87 }
88 my $gif;
89 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
90 @p2ps = <FILE>;
91 close FILE;
92 &Header::openbox('100%', 'center', 'P2P-Block');
93 print <<END;
94 <table width='35%' border='0'>
95 <tr bgcolor='$color{'color22'}'><td align=center colspan='2' ><b>$Lang::tr{'protocol'}</b></td><td align='center'><b>$Lang::tr{'status'}</b></td></tr>
96 END
97 foreach my $p2pentry (sort @p2ps)
98 {
99 my @p2pline = split( /\;/, $p2pentry );
100 if($p2pline[2] eq 'on'){
101 $gif="/images/on.gif"
102 }else{
103 $gif="/images/off.gif"
104 }
105 print <<END;
106 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
107 <tr bgcolor='$color{'color20'}'>
108 <td align='center' colspan='2' >$p2pline[0]:</td><td align='center'><input type='hidden' name='P2PROT' value='$p2pline[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;' ><input type='hidden' name='ACTION' value='togglep2p'></td></tr></form>
109 END
110 }
111 print"<tr><td><img src='/images/on.gif'></td><td align='left'>$Lang::tr{'outgoing firewall p2p allow'}</td></tr>";
112 print"<tr><td><img src='/images/off.gif'></td><td align='left'>$Lang::tr{'outgoing firewall p2p deny'}</td></tr></table>";
113 print"<br><br><br><table width='100%'><tr><td align='left'>$Lang::tr{'fwdfw p2p txt'}</td></tr></table>";
114 &Header::closebox();
115 }
116 sub rules
117 {
118 if (!-f "${General::swroot}/forward/reread"){
119 system("touch ${General::swroot}/forward/reread");
120 system("touch ${General::swroot}/fwhosts/reread");
121 }
122 }
123 sub reread_rules
124 {
125 system("/usr/local/bin/forwardfwctrl");
126 if ( -f "${General::swroot}/forward/reread"){
127 system("rm ${General::swroot}/forward/reread");
128 system("rm ${General::swroot}/fwhosts/reread");
129 }
130 }
131 &Header::closebigbox();
132 &Header::closepage();