X-Git-Url: http://git.shiar.net/perl/plp/.git/blobdiff_plain/65a8aed85aa78407018da99ab616f632f40a8eb9..a4dab1e4ec41edfa4ba07128f9ee5ff97a53c3ee:/PLP/CGI.pm diff --git a/PLP/CGI.pm b/PLP/CGI.pm index 2056af9..698c34b 100644 --- a/PLP/CGI.pm +++ b/PLP/CGI.pm @@ -2,45 +2,49 @@ package PLP::CGI; use strict; -our $VERSION = '1.01'; +our $VERSION = '1.02'; use PLP; # CGI initializer: opens SCRIPT_FILENAME sub init { $PLP::print = 'print'; + $PLP::read = \&read; if (defined $ENV{PATH_TRANSLATED}) { - # Physical mapping provided; SCRIPT_* points to handler script - # (Apache action) - my $path = delete $ENV{PATH_TRANSLATED}; + # SCRIPT_* points to handler script (Apache CGI) + # Run backwards through PATH_TRANSLATED to find target filename, + # then get file (relative) by stripping PATH_INFO. + my ($path, $rel) = (delete $ENV{PATH_TRANSLATED}, delete $ENV{PATH_INFO}); my $path_info; while (not -f $path) { if (not $path =~ s/(\/+[^\/]*)$//) { printf STDERR "PLP: Not found: $path$path_info ($ENV{REQUEST_URI})\n"; PLP::error(undef, 404); - exit; + return; } - # move last path element from PLP_*NAME to PATH_INFO + # move last path element onto PATH_INFO $path_info = $1 . $path_info; } - $ENV{PLP_FILENAME} = $path; - $ENV{PLP_NAME} = delete $ENV{PATH_INFO}; if (defined $path_info) { - $ENV{PLP_NAME} =~ s/\Q$path_info\E$//; + $rel =~ s/\Q$path_info\E$//; $ENV{PATH_INFO} = $path_info; } - } else { - # SCRIPT_*/PATH_INFO already modified to target script - # (Lighttpd cgi.assign) - $ENV{PLP_FILENAME} = $ENV{SCRIPT_FILENAME}; - $ENV{PLP_NAME} = $ENV{SCRIPT_NAME}; + $ENV{SCRIPT_FILENAME} = $path; + $ENV{SCRIPT_NAME} = $rel; } + elsif (not -f $ENV{SCRIPT_FILENAME}) { + print STDERR "PLP: Not found: $ENV{SCRIPT_FILENAME} ($ENV{REQUEST_URI})\n"; + PLP::error(undef, 404); + return; + } + + $ENV{"PLP_$_"} = $ENV{"SCRIPT_$_"} for qw/NAME FILENAME/; if (not -r $ENV{PLP_FILENAME}) { print STDERR "PLP: Can't read: $ENV{PLP_FILENAME} ($ENV{REQUEST_URI})\n"; PLP::error(undef, 403); - exit; + return; } delete @ENV{ @@ -52,14 +56,71 @@ sub init { chdir $dir; $PLP::code = PLP::source($file, 0, undef, $ENV{PLP_FILENAME}); + return 1; +} + +sub read ($) { + my ($bytes) = @_; + read *STDIN, my $data, $bytes; + return $data; } -# This is run by the CGI script. (#!perl \n use PLP::CGI; PLP::CGI::everything;) sub everything { PLP::clean(); - init(); - PLP::start(); + $_[0]->init() and PLP::start(); +} + +# This is run by the CGI script. (#!perl \n use PLP::CGI;) +sub import { + $_[0]->everything(); } 1; +=head1 NAME + +PLP::CGI - CGI interface for PLP + +=head1 SYNOPSIS + +For most servers you'll need a script executable. +Example F: + + #!/usr/bin/perl + use PLP::CGI; + +Or install the C included with PLP. + +=head2 Lighttpd + +Usually in F: +enable I (add/outcomment in server.modules), and add: + + cgi.assign = ( + ".plp" => "/foo/bar/plp.cgi", + ) + +=head2 Apache + +Enable I and setup F +(often just create a F) with: + + + ScriptAlias /PLP_COMMON/ /foo/bar/ + + Options +ExecCGI + Order allow,deny + Allow from all + + AddHandler plp-document plp + Action plp-document /PLP_COMMON/plp.cgi + + +=head1 AUTHOR + +Mischa POSLAWSKY + +=head1 SEE ALSO + +L, L +