Core Update 168: Ship liburcu
[people/pmueller/ipfire-2.x.git] / html / html / redirect.cgi
CommitLineData
10e4f239 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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###############################################################################
10e4f239 21
e157791f
MT
22use CGI;
23use HTML::Entities;
24use HTML::Template;
10e4f239 25
e157791f
MT
26my $swroot="/var/ipfire";
27my $templateroot = "/srv/web/ipfire/html/redirect-templates";
10e4f239
MT
28
29my %netsettings;
30my %filtersettings;
31
32&readhash("$swroot/ethernet/settings", \%netsettings);
33&readhash("$swroot/urlfilter/settings", \%filtersettings);
34
e157791f 35# Read the template file.
87e33a42 36my $template = $filtersettings{'REDIRECT_TEMPLATE'};
e157791f
MT
37if (($template eq '') || (! -e "$templateroot/$template")) {
38 $template = "legacy";
39}
40my $tmpl = HTML::Template->new(
41 filename => "$templateroot/$template/template.html",
42 die_on_bad_params => 0
43);
44
45# Address where to load more resources from.
46$tmpl->param(ADDRESS => "http://$netsettings{'GREEN_ADDRESS'}:81");
10e4f239 47
e157791f
MT
48# Message text 1
49my $msgtext1 = $filtersettings{'MSG_TEXT_1'};
50if ($msgtext1 eq '') {
10e4f239 51 $msgtext1 = "A C C E S S &nbsp;&nbsp; D E N I E D";
e157791f
MT
52}
53$tmpl->param(MSG_TEXT_1 => $msgtext1);
54
55# Message text 2
56my $msgtext2 = $filtersettings{'MSG_TEXT_2'};
57if ($msgtext2 eq '') {
10e4f239 58 $msgtext2 = "Access to the requested page has been denied";
e157791f
MT
59}
60$tmpl->param(MSG_TEXT_2 => $msgtext2);
61
62# Message text 3
63my $msgtext3 = $filtersettings{'MSG_TEXT_3'};
64if ($msgtext3 eq '') {
10e4f239 65 $msgtext3 = "Please contact the Network Administrator if you think there has been an error";
e157791f
MT
66}
67$tmpl->param(MSG_TEXT_3 => $msgtext3);
68
69# Category
70my $category = CGI::param("category");
71$tmpl->param(CATEGORY => &escape($category));
72
73# URL
74my $url = CGI::param("url");
75$tmpl->param(URL => &escape($url));
10e4f239 76
e157791f
MT
77# IP address
78my $ip_address = CGI::param("ip");
79$tmpl->param(IP_ADDRESS => &escape($ip_address));
10e4f239 80
e157791f 81# Print header
10e4f239
MT
82print "Pragma: no-cache\n";
83print "Cache-control: no-cache\n";
84print "Connection: close\n";
85print "Content-type: text/html\n\n";
e157791f 86print $tmpl->output;
10e4f239 87
e157791f
MT
88sub escape($) {
89 my $s = shift;
90 return HTML::Entities::encode_entities($s);
10e4f239 91}
10e4f239 92
e157791f 93sub readhash {
10e4f239
MT
94 my $filename = $_[0];
95 my $hash = $_[1];
96 my ($var, $val);
97
e157791f 98 if (-e $filename) {
10e4f239 99 open(FILE, $filename) or die "Unable to read file $filename";
e157791f 100 while (<FILE>) {
10e4f239
MT
101 chop;
102 ($var, $val) = split /=/, $_, 2;
e157791f 103 if ($var) {
10e4f239
MT
104 $val =~ s/^\'//g;
105 $val =~ s/\'$//g;
66c36198 106
10e4f239
MT
107 # Untaint variables read from hash
108 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
109 $val =~ /([\w\W]*)/; $val = $1;
110 $hash->{$var} = $val;
111 }
112 }
e157791f 113
10e4f239
MT
114 close FILE;
115 }
116}