[prev in list] [next in list] [prev in thread] [next in thread]
List: mason
Subject: [Mason] a handler to mason-enable public_html
From: John BEPPU <beppu () lineo ! com>
Date: 2000-11-19 23:36:43
[Download RAW message or body]
package LBox::UserDirectories;
use strict;
use Apache;
use HTML::Mason;
# preloaded modules
{
package HTML::Mason::Commands;
}
# shared parser
my $parser = HTML::Mason::Parser->new();
# HTML::Mason::ApacheHandler instances for each user
my %ah;
# lazy instantiation of
# HTML::Mason::Interp and HTML::Mason::ApacheHandler objects
sub ah_for_user {
my $r = shift;
my $user = shift;
if (not defined $ah{$user}) {
# directories
my $mason_data_prefix = $r->dir_config('mason_data_prefix');
my $home_prefix = $r->dir_config('home_prefix');
my $comp_root = "$home_prefix/$user";
my $data_dir = "$mason_data_prefix/$user";
# mkdir if needed
mkdir($data_dir, 0775) unless (-d $data_dir);
# instantiate
my $interp = HTML::Mason::Interp->new (
parser => $parser,
data_dir => $data_dir,
comp_root => [
[main => $comp_root],
],
);
$ah{$user} = HTML::Mason::ApacheHandler->new(interp => $interp);
chown (scalar(getpwnam "nobody"), scalar(getgrnam "nobody"),
$interp->files_written);
}
return $ah{$user}
}
# delegate request to the appropriate HTML::Mason::ApacheHandler
sub handler {
my $r = shift;
# delegate non-text to default handler
return -1 if $r->content_type && $r->content_type !~ m|^text/|io;
# get user
my $home_prefix = $r->dir_config('home_prefix');
my $user = $r->filename();
$user =~ s:^$home_prefix/::;
$user =~ s:/.*$::;
# get handler and serve request
my $ah = ah_for_user($r, $user);
return $ah->handle_request($r);
}
1;
__END__
=head1 NAME
public_html_handler.pl - make your public_html dirs mason-enabled
=head1 SYNOPSIS
a hypothetical Apache configuration:
PerlRequire /www/mason/bin/public_html_handler.pl
<Directory /home/*/public_html>
SetHandler perl-script
PerlSetVar home_prefix /home
PerlSetVar mason_data_prefix /www/mason/data
PerlHandler LBox::UserDirectories
</Directory>
=head1 DESCRIPTION
This apache content handler allows your users' public_html directories
to be HTML::Mason-enabled. The idea was inspired by the MyUniversity
configuration that I heard some $AustralianUniversity set up for their
students. I have no idea how they implemented it, but I imagine the
core of it must have looked vaguely like this.
I wrote this so that lbox.org could allow its users to have more
dynamic websites if they felt so inclined. Maybe they could even
put down HTML::Mason on their resumés once they got the hang of it.
:-)
=head2 Configuration
This handler was designed to be configured via C<PerlSetVar> directives
to make it easy to move from server to server. The variables that must
be configured are as follows:
=over 4
=item home_prefix
This is the directory where all your home directories are under.
DO NOT include a trailing slash.
=item mason_data_prefix
This is the directory where HTML::Mason will write its internal
data to. DO NOT include a trailing slash. Also, be sure that
the user that C<httpd> is running as is able to write to this
directory.
=back
=head1 AUTHOR
John Beppu <beppu@lbox.org>
=head1 COPYRIGHT
Copyright (c) 2000, John Beppu. All Rights Reserved. This module
is free software. It may be used, redistributed, and/or modified
under the same terms as Perl.
=cut
# $Id: public_html_handler.pl,v 1.1 2000/11/19 23:03:36 beppu Exp $
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/mason-users
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic