chiark / gitweb /
.gitignore: add data dir
[nj-awaymsg.git] / run-mason.cgi
1 #!/usr/bin/perl -w
2
3 use HTML::Mason::CGIHandler;
4 use strict;
5 use POSIX;
6
7 my $script_filename = $ENV{'SCRIPT_FILENAME'};
8 my $basis = shift @ARGV;
9 sub absify ($) { $_[0] =~ m#^/# ? $_[0] : "$basis/$_[0]"; }
10 my $perllib = absify shift @ARGV;
11 my $comp_root = absify shift @ARGV;
12
13 unshift @INC, $perllib;
14
15 my $pathsofar = $comp_root;
16 die "$pathsofar $!" unless stat $pathsofar;
17
18 $ENV{'PATH_INFO'} ||= '/main';
19 my $path_info = $ENV{'PATH_INFO'};
20
21 foreach my $pathcomp (split m#/#, $path_info) {
22     next if $pathcomp eq '';
23     $pathcomp =~ m/^[,_0-9A-Za-z]/ or path_fail('bad initial character');
24     $pathcomp =~ m/[-+:.,_0-9A-Za-z]$/ or path_fail('bad final character');
25     $pathcomp ne 'autohandler' or path_fail('refers to autohandler');
26     $pathcomp ne 'dhandler' or path_fail('refers to dhandler');
27     $pathsofar .= "/$pathcomp";
28     next if access($pathsofar, X_OK);
29     die "$pathsofar $!" unless $!==&ENOENT or $!==&ENOTDIR;
30     last;
31 }
32
33 our $h;
34 $h or $h = HTML::Mason::CGIHandler->new(comp_root => $comp_root);
35 $h->handle_request();