chiark / gitweb /
run-mason.cgi: seems to work
[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 system 'printenv |sort >&2';
19
20 my $path_info = $ENV{'PATH_INFO'};
21 $path_info='' if !defined $path_info;
22
23 foreach my $pathcomp (split m#/#, $path_info) {
24     next if $pathcomp eq '';
25     $pathcomp =~ m/^[,_0-9A-Za-z]/ or path_fail('bad initial character');
26     $pathcomp =~ m/[-+:.,_0-9A-Za-z]$/ or path_fail('bad final character');
27     $pathcomp ne 'autohandler' or path_fail('refers to autohandler');
28     $pathcomp ne 'dhandler' or path_fail('refers to dhandler');
29     $pathsofar .= "/$pathcomp";
30     next if access($pathsofar, X_OK);
31     die "$pathsofar $!" unless $!==&ENOENT or $!==&ENOTDIR;
32     last;
33 }
34
35 our $h;
36 $h or $h = HTML::Mason::CGIHandler->new(comp_root => $comp_root);
37 $h->handle_request();