]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - html/cgi-bin/p2p-block.cgi
Forward Firewall: moved "firewall default behaviour" from firewall page to firewall...
[people/teissler/ipfire-2.x.git] / html / cgi-bin / p2p-block.cgi
CommitLineData
7bf83f9d
AM
1#!/usr/bin/perl
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2012 #
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# Hi folks! I hope this code is useful for all. I needed something to handle #
23# my VPN Connections in a comfortable way. As a prerequisite i needed #
24# something that makes sure the vpn roadwarrior are able to have a fixed #
25# ip-address. So i developed the ccd extension for the vpn server. #
26# #
27# Now that the ccd extension is ready i am able to develop the main request. #
28# Any feedback is appreciated. #
29# #
30#Copymaster #
31###############################################################################
32
33use strict;
34no warnings 'uninitialized';
35# enable only the following on debugging purpose
36#use warnings;
37#use CGI::Carp 'fatalsToBrowser';
38
39require '/var/ipfire/general-functions.pl';
40require "${General::swroot}/lang.pl";
41require "${General::swroot}/header.pl";
42
43my $errormessage='';
44my $p2pfile = "${General::swroot}/forward/p2protocols";
45
46my @p2ps = ();
47my %fwdfwsettings=();
48my %color=();
49my %mainsettings=();
50
51&General::readhash("${General::swroot}/forward/settings", \%fwdfwsettings);
52&General::readhash("${General::swroot}/main/settings", \%mainsettings);
53&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
54
55
56
57&Header::showhttpheaders();
58&Header::getcgihash(\%fwdfwsettings);
59&Header::openpage($Lang::tr{'fwdfw menu'}, 1, '');
60&Header::openbigbox('100%', 'center',$errormessage);
61
62if ($fwdfwsettings{'ACTION'} eq ''){
63&p2pblock;
64}
65if ($fwdfwsettings{'ACTION'} eq 'togglep2p')
66{
67 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
68 @p2ps = <FILE>;
69 close FILE;
70 open( FILE, "> $p2pfile" ) or die "Unable to write $p2pfile";
71 foreach my $p2pentry (sort @p2ps)
72 {
73 my @p2pline = split( /\;/, $p2pentry );
74 if ($p2pline[1] eq $fwdfwsettings{'P2PROT'}) {
75 if($p2pline[2] eq 'on'){
76 $p2pline[2]='off';
77 }else{
78 $p2pline[2]='on';
79 }
80 }
81 print FILE "$p2pline[0];$p2pline[1];$p2pline[2];\n";
82 }
83 close FILE;
84 &rules;
85 &p2pblock;
86}
87if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
88{
89 &reread_rules;
90 &p2pblock;
91}
92
93
94sub p2pblock
95{
96 if (-f "${General::swroot}/forward/reread"){
97 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>";
98 }
99 my $gif;
100 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
101 @p2ps = <FILE>;
102 close FILE;
103 &Header::openbox('100%', 'center', 'P2P-Block');
104 print <<END;
105 <table width='35%' border='0'>
106 <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>
107END
108 foreach my $p2pentry (sort @p2ps)
109 {
110 my @p2pline = split( /\;/, $p2pentry );
111 if($p2pline[2] eq 'on'){
112 $gif="/images/on.gif"
113 }else{
114 $gif="/images/off.gif"
115 }
116 print <<END;
117 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
118 <tr bgcolor='$color{'color20'}'>
119 <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>
120END
121 }
122 print"<tr><td><img src='/images/on.gif'></td><td align='left'>$Lang::tr{'outgoing firewall p2p allow'}</td></tr>";
123 print"<tr><td><img src='/images/off.gif'></td><td align='left'>$Lang::tr{'outgoing firewall p2p deny'}</td></tr></table>";
515863e2 124 print"<br><br><br><table width='100%'><tr><td align='left'>$Lang::tr{'fwdfw p2p txt'}</td></tr></table>";
7bf83f9d
AM
125 &Header::closebox();
126}
127sub rules
128{
129 if (!-f "${General::swroot}/forward/reread"){
130 system("touch ${General::swroot}/forward/reread");
131 system("touch ${General::swroot}/fwhosts/reread");
132 }
133}
134sub reread_rules
135{
136 system("/usr/local/bin/forwardfwctrl");
137 if ( -f "${General::swroot}/forward/reread"){
138 system("rm ${General::swroot}/forward/reread");
139 system("rm ${General::swroot}/fwhosts/reread");
140 }
141}
142&Header::closebigbox();
143&Header::closepage();