]>
Commit | Line | Data |
---|---|---|
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 |
22 | use CGI; |
23 | use HTML::Entities; | |
24 | use HTML::Template; | |
10e4f239 | 25 | |
e157791f MT |
26 | my $swroot="/var/ipfire"; |
27 | my $templateroot = "/srv/web/ipfire/html/redirect-templates"; | |
10e4f239 MT |
28 | |
29 | my %netsettings; | |
30 | my %filtersettings; | |
31 | ||
32 | &readhash("$swroot/ethernet/settings", \%netsettings); | |
33 | &readhash("$swroot/urlfilter/settings", \%filtersettings); | |
34 | ||
e157791f | 35 | # Read the template file. |
87e33a42 | 36 | my $template = $filtersettings{'REDIRECT_TEMPLATE'}; |
e157791f MT |
37 | if (($template eq '') || (! -e "$templateroot/$template")) { |
38 | $template = "legacy"; | |
39 | } | |
40 | my $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 |
49 | my $msgtext1 = $filtersettings{'MSG_TEXT_1'}; | |
50 | if ($msgtext1 eq '') { | |
10e4f239 | 51 | $msgtext1 = "A C C E S S D E N I E D"; |
e157791f MT |
52 | } |
53 | $tmpl->param(MSG_TEXT_1 => $msgtext1); | |
54 | ||
55 | # Message text 2 | |
56 | my $msgtext2 = $filtersettings{'MSG_TEXT_2'}; | |
57 | if ($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 | |
63 | my $msgtext3 = $filtersettings{'MSG_TEXT_3'}; | |
64 | if ($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 | |
70 | my $category = CGI::param("category"); | |
71 | $tmpl->param(CATEGORY => &escape($category)); | |
72 | ||
73 | # URL | |
74 | my $url = CGI::param("url"); | |
75 | $tmpl->param(URL => &escape($url)); | |
10e4f239 | 76 | |
e157791f MT |
77 | # IP address |
78 | my $ip_address = CGI::param("ip"); | |
79 | $tmpl->param(IP_ADDRESS => &escape($ip_address)); | |
10e4f239 | 80 | |
e157791f | 81 | # Print header |
10e4f239 MT |
82 | print "Pragma: no-cache\n"; |
83 | print "Cache-control: no-cache\n"; | |
84 | print "Connection: close\n"; | |
85 | print "Content-type: text/html\n\n"; | |
e157791f | 86 | print $tmpl->output; |
10e4f239 | 87 | |
e157791f MT |
88 | sub escape($) { |
89 | my $s = shift; | |
90 | return HTML::Entities::encode_entities($s); | |
10e4f239 | 91 | } |
10e4f239 | 92 | |
e157791f | 93 | sub 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 | } |