]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - html/cgi-bin/p2p-block.cgi
Firewall: Renamed directory /var/ipfire/forward to /var/ipfire/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 #
4f585d55 5# Copyright (C) 2013 #
7bf83f9d
AM
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###############################################################################
4f585d55
AM
21# Author: Alexander Marx (Amarx@ipfire.org) #
22###############################################################################
7bf83f9d
AM
23
24use strict;
25no warnings 'uninitialized';
26# enable only the following on debugging purpose
27#use warnings;
28#use CGI::Carp 'fatalsToBrowser';
29
30require '/var/ipfire/general-functions.pl';
31require "${General::swroot}/lang.pl";
32require "${General::swroot}/header.pl";
33
4a75efa5 34my $errormessage = '';
6d8eb5de 35my $p2pfile = "${General::swroot}/firewall/p2protocols";
7bf83f9d
AM
36
37my @p2ps = ();
4a75efa5
MT
38my %fwdfwsettings = ();
39my %color = ();
40my %mainsettings = ();
7bf83f9d 41
7bf83f9d
AM
42&General::readhash("${General::swroot}/main/settings", \%mainsettings);
43&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
44
7bf83f9d
AM
45&Header::showhttpheaders();
46&Header::getcgihash(\%fwdfwsettings);
4a75efa5 47&Header::openpage($Lang::tr{'p2p block'}, 1, '');
0e430797 48&Header::openbigbox('100%', 'center', $errormessage);
7bf83f9d 49
0e430797 50if ($fwdfwsettings{'ACTION'} eq 'togglep2p') {
4a75efa5 51 open( FILE, "<$p2pfile") or die "Unable to read $p2pfile";
7bf83f9d
AM
52 @p2ps = <FILE>;
53 close FILE;
4a75efa5
MT
54 open( FILE, ">$p2pfile") or die "Unable to write $p2pfile";
55 foreach my $p2pentry (sort @p2ps) {
56 my @p2pline = split( /\;/, $p2pentry);
7bf83f9d 57 if ($p2pline[1] eq $fwdfwsettings{'P2PROT'}) {
4a75efa5
MT
58 if ($p2pline[2] eq 'on') {
59 $p2pline[2] = 'off';
60 } else {
61 $p2pline[2] = 'on';
7bf83f9d
AM
62 }
63 }
64 print FILE "$p2pline[0];$p2pline[1];$p2pline[2];\n";
65 }
66 close FILE;
7bf83f9d 67
0e430797
MT
68 &General::firewall_config_changed();
69 &p2pblock();
70} else {
71 &p2pblock();
72}
7bf83f9d 73
4a75efa5 74sub p2pblock {
7bf83f9d 75 my $gif;
4a75efa5
MT
76
77 open(FILE, "<$p2pfile") or die "Unable to read $p2pfile";
7bf83f9d
AM
78 @p2ps = <FILE>;
79 close FILE;
4a75efa5
MT
80
81 &Header::openbox('100%', 'center', $Lang::tr{'p2p block'});
7bf83f9d 82 print <<END;
4a75efa5
MT
83 <table width='35%' border='0'>
84 <tr bgcolor='$color{'color22'}'>
85 <td align=center colspan='2' >
86 <b>$Lang::tr{'protocol'}</b>
87 </td>
88 <td align='center'>
89 <b>$Lang::tr{'status'}</b>
90 </td>
91 </tr>
7bf83f9d 92END
4a75efa5
MT
93
94 foreach my $p2pentry (sort @p2ps) {
95 my @p2pline = split( /\;/, $p2pentry);
96 if ($p2pline[2] eq 'on') {
97 $gif = "/images/on.gif"
98 } else {
99 $gif = "/images/off.gif"
7bf83f9d 100 }
4a75efa5 101
7bf83f9d 102 print <<END;
4a75efa5
MT
103 <tr bgcolor='$color{'color20'}'>
104 <td align='center' colspan='2'>
105 $p2pline[0]:
106 </td>
107 <td align='center'>
108 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
109 <input type='hidden' name='P2PROT' value='$p2pline[1]'>
110 <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;'>
111 <input type='hidden' name='ACTION' value='togglep2p'>
112 </form>
113 </td>
114 </tr>
7bf83f9d
AM
115END
116 }
4a75efa5
MT
117
118 print <<END;
119 <tr>
120 <td>
121 <img src='/images/on.gif'>
122 </td>
123 <td>
124 $Lang::tr{'outgoing firewall p2p allow'}
125 </td>
126 </tr>
127 <tr>
128 <td>
129 <img src='/images/off.gif'>
130 </td>
131 <td>
132 $Lang::tr{'outgoing firewall p2p deny'}
133 </td>
134 </tr>
135 </table>
136END
137
7bf83f9d
AM
138 &Header::closebox();
139}
0e430797 140
7bf83f9d
AM
141&Header::closebigbox();
142&Header::closepage();