| 1 | package PLP::Backend::CGI; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 2 | our $VERSION = '1.03'; | |||||||||||||
| 7 | |||||||||||||||
| 8 | 2 | ▶ | use PLP; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | # CGI initializer: opens SCRIPT_FILENAME | ||||||||||||||
| 11 | 25 | ▶ | sub init { | ||||||||||||
|
Subroutine
init: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||
| 12 | 25 | $PLP::print = 'print'; | |||||||||||||
| 13 | 25 | $PLP::read = \&read; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 25 | ▶ | if (defined $ENV{PATH_TRANSLATED}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 16 | # SCRIPT_* points to handler script (Apache CGI) | ||||||||||||||
| 17 | # Run backwards through PATH_TRANSLATED to find target filename, | ||||||||||||||
| 18 | # then get file (relative) by stripping PATH_INFO. | ||||||||||||||
| 19 | 24 | my ($path, $rel) = (delete $ENV{PATH_TRANSLATED}, delete $ENV{PATH_INFO}); | |||||||||||||
| 20 | 24 | my $path_info = ''; | |||||||||||||
| 21 | 24 | ▶ | while (not -f $path) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | 50 | ▶ | if (not $path =~ s/(\/+[^\/]*)$//) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 23 | 1 | warn "PLP: Not found: $path$path_info ($ENV{REQUEST_URI})\n"; | |||||||||||||
| 24 | 1 | PLP::error(undef, 404); | |||||||||||||
| 25 | 1 | return; | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | # move last path element onto PATH_INFO | ||||||||||||||
| 28 | 49 | $path_info = $1 . $path_info; | |||||||||||||
| 29 | } | ||||||||||||||
| 30 | 23 | ▶ | if ($path_info ne '') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | 23 | $rel =~ s/\Q$path_info\E$//; | |||||||||||||
| 32 | 23 | $ENV{PATH_INFO} = $path_info; | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | 23 | $ENV{SCRIPT_FILENAME} = $path; | |||||||||||||
| 35 | 23 | $ENV{SCRIPT_NAME} = $rel; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | elsif (not -f $ENV{SCRIPT_FILENAME}) { | ||||||||||||||
| 38 | 0 | warn "PLP: Not found: $ENV{SCRIPT_FILENAME} ($ENV{REQUEST_URI})\n"; | |||||||||||||
| 39 | 0 | PLP::error(undef, 404); | |||||||||||||
| 40 | 0 | return; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 24 | $ENV{"PLP_$_"} = $ENV{"SCRIPT_$_"} for qw/NAME FILENAME/; | |||||||||||||
| 44 | |||||||||||||||
| 45 | 24 | ▶ | if (not -r $ENV{PLP_FILENAME}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | 1 | warn "PLP: Can't read: $ENV{PLP_FILENAME} ($ENV{REQUEST_URI})\n"; | |||||||||||||
| 47 | 1 | PLP::error(undef, 403); | |||||||||||||
| 48 | 1 | return; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | delete @ENV{ | ||||||||||||||
| 52 | 23 | grep /^REDIRECT_/, keys %ENV | |||||||||||||
| 53 | }; | ||||||||||||||
| 54 | |||||||||||||||
| 55 | 23 | my ($file, $dir) = File::Basename::fileparse($ENV{PLP_FILENAME}); | |||||||||||||
| 56 | 23 | chdir $dir; | |||||||||||||
| 57 | |||||||||||||||
| 58 | 23 | $PLP::code = PLP::source($file, 0, undef, $ENV{PLP_FILENAME}); | |||||||||||||
| 59 | 23 | return 1; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 1 | ▶ | sub read ($) { | ||||||||||||
|
Subroutine
read: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 63 | 1 | my ($bytes) = @_; | |||||||||||||
| 64 | 1 | read *STDIN, my ($data), $bytes; | |||||||||||||
| 65 | 1 | return $data; | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | 25 | ▶ | sub everything { | ||||||||||||
|
Subroutine
everything: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 69 | 25 | PLP::clean(); | |||||||||||||
| 70 | 25 | ▶ | $_[0]->init() and PLP::start(); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | # This is run by the CGI script. (#!perl \n use PLP::Backend::CGI;) | ||||||||||||||
| 74 | 0 | ▶ | sub import { | ||||||||||||
|
Subroutine
import: not called CC=1 SCAR=6.9
| |||||||||||||||
| 75 | 0 | $PLP::interface = $_[0]; | |||||||||||||
| 76 | 0 | $_[0]->everything(); | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 2 | 1; | |||||||||||||
| 80 | |||||||||||||||
| 81 | =head1 NAME | ||||||||||||||
| 82 | |||||||||||||||
| 83 | PLP::Backend::CGI - CGI interface for PLP | ||||||||||||||
| 84 | |||||||||||||||
| 85 | =head1 SYNOPSIS | ||||||||||||||
| 86 | |||||||||||||||
| 87 | For most servers you'll need a script executable. | ||||||||||||||
| 88 | Example F</foo/bar/plp.cgi>: | ||||||||||||||
| 89 | |||||||||||||||
| 90 | #!/usr/bin/perl | ||||||||||||||
| 91 | use PLP::Backend::CGI; | ||||||||||||||
| 92 | |||||||||||||||
| 93 | Or install the C<plp.cgi> included with PLP. | ||||||||||||||
| 94 | |||||||||||||||
| 95 | =head2 Lighttpd | ||||||||||||||
| 96 | |||||||||||||||
| 97 | Add this to your configuration file (usually F</etc/lighttpd/lighttpd.conf>): | ||||||||||||||
| 98 | |||||||||||||||
| 99 | server.modules += ("mod_cgi") | ||||||||||||||
| 100 | cgi.assign += (".plp" => "/foo/bar/plp.cgi") | ||||||||||||||
| 101 | server.indexfiles += ("index.plp") | ||||||||||||||
| 102 | static-file.exclude-extensions += (".plp") | ||||||||||||||
| 103 | |||||||||||||||
| 104 | =head2 Apache | ||||||||||||||
| 105 | |||||||||||||||
| 106 | Enable I<mod_actions> and | ||||||||||||||
| 107 | setup F<httpd.conf> (in new installs just create F</etc/apache/conf.d/plp>) with: | ||||||||||||||
| 108 | |||||||||||||||
| 109 | <IfModule mod_actions.c> | ||||||||||||||
| 110 | ScriptAlias /PLP_COMMON/ /foo/bar/ | ||||||||||||||
| 111 | <Directory /foo/bar/> | ||||||||||||||
| 112 | Options +ExecCGI | ||||||||||||||
| 113 | Order allow,deny | ||||||||||||||
| 114 | Allow from all | ||||||||||||||
| 115 | </Directory> | ||||||||||||||
| 116 | AddHandler plp-document plp | ||||||||||||||
| 117 | Action plp-document /PLP_COMMON/plp.cgi | ||||||||||||||
| 118 | </IfModule> | ||||||||||||||
| 119 | |||||||||||||||
| 120 | =head1 AUTHOR | ||||||||||||||
| 121 | |||||||||||||||
| 122 | Mischa POSLAWSKY <perl@shiar.org> | ||||||||||||||
| 123 | |||||||||||||||
| 124 | =head1 SEE ALSO | ||||||||||||||
| 125 | |||||||||||||||
| 126 | L<PLP>, L<PLP::Backend::FastCGI> | ||||||||||||||
| 127 | |||||||||||||||