I think that this site (
WSMCafe) is a lively example of what
SamQi is trying to do. It's all CGI, no mod_perl that I can see.
perrin, I'm not sure if I agree with you. Could you please elaborate as to why PerlTransHandler isn't good for something like this. Here's a small example of what I'm working on and I'll soon have a working example to show for it. It seems to do its job pretty well, although I'm pretty sure there are some things that need to be improved. I do agree with you on how it really doesn't need mod_perl to be. But I figure if I have it, I use it. It goes on the theory, why keep on querying the database to make the pages when they can be generated as static pages.
package util::TransHandler;
use strict;
use Apache::Constants qw(:common);
sub handler {
my $r = shift;
my $uri = $r->uri;
my ($host,$port) = split(/:/, $r->headers_in->{'Host'});
lc($host);
print STDERR $host,"\n";
# if the hostname has more than one subdomain from the one specifi
+ed below, reject it.
# bar.slinger.foo.com = OK
# bar.baz.slinger.foo.com = NOT OK
if ($host =~ m/^([a-z0-9]+\.){2,}\.?slinger\.foo\.com$/) {
$r->pnotes('BadHost' => ['1']);
return DECLINED;
# if its not from the base domain. Process it. Find the files and
+return the correct path.
} elsif ($host !~ m/^(slinger)?\.?foo.com$/) {
$host =~ m/^([a-z0-9]+)\.slinger\.foo.com$/;
my $members = MEMBERS->select( { SUBDOMAIN => $1 } );
my $session = SESSIONS->select( { SUBDOMAIN => $1 } );
# if the subdomain exists in the database, process it.
# Otherwise let the user know its available to use.
if ($members != 0 || $session != 0) {
my $thedir = $r->server_root_relative($r->dir_config('User
+Dir'));
my $result;
if (ref($members) eq 'ARRAY') { $result = $members->[0]{DI
+RECTORY}; }
if (ref($session) eq 'ARRAY') { $result = $session->[0]{DI
+RECTORY}; }
return DECLINED unless $uri =~ s!^/(.*)$!$thedir/$result/$
+1!;
$r->pnotes('DontDo' => ['1']);
$r->filename($uri);
return OK;
} else {
# Switch that says the subdomain is available.
$r->pnotes('SubDomain' => [$1]);
return OK;
}
} else {
return DECLINED;
}
}
Any improvements to it would be gladly accepted. This probably looks sloppy to most.
BMaximus
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.