chiark / gitweb /
run-mason.cgi: seems to work
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 25 Jan 2013 23:27:03 +0000 (23:27 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 25 Jan 2013 23:27:03 +0000 (23:27 +0000)
run-mason.cgi [new file with mode: 0755]

diff --git a/run-mason.cgi b/run-mason.cgi
new file mode 100755 (executable)
index 0000000..3f42cc5
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/perl -w
+
+use HTML::Mason::CGIHandler;
+use strict;
+use POSIX;
+
+my $script_filename = $ENV{'SCRIPT_FILENAME'};
+my $basis = shift @ARGV;
+sub absify ($) { $_[0] =~ m#^/# ? $_[0] : "$basis/$_[0]"; }
+my $perllib = absify shift @ARGV;
+my $comp_root = absify shift @ARGV;
+
+unshift @INC, $perllib;
+
+my $pathsofar = $comp_root;
+die "$pathsofar $!" unless stat $pathsofar;
+
+system 'printenv |sort >&2';
+
+my $path_info = $ENV{'PATH_INFO'};
+$path_info='' if !defined $path_info;
+
+foreach my $pathcomp (split m#/#, $path_info) {
+    next if $pathcomp eq '';
+    $pathcomp =~ m/^[,_0-9A-Za-z]/ or path_fail('bad initial character');
+    $pathcomp =~ m/[-+:.,_0-9A-Za-z]$/ or path_fail('bad final character');
+    $pathcomp ne 'autohandler' or path_fail('refers to autohandler');
+    $pathcomp ne 'dhandler' or path_fail('refers to dhandler');
+    $pathsofar .= "/$pathcomp";
+    next if access($pathsofar, X_OK);
+    die "$pathsofar $!" unless $!==&ENOENT or $!==&ENOTDIR;
+    last;
+}
+
+our $h;
+$h or $h = HTML::Mason::CGIHandler->new(comp_root => $comp_root);
+$h->handle_request();