X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FController%2FCGIBin.pm;h=e332ef47f818f436b8e5dc9032ac6949665c50aa;hb=e889d52612ce3eaa1fb64150f76543aa03cc6253;hp=8cf9820eb7f89196580df5303758e571a602561e;hpb=c0c72ec290bad02174311dc28f010da1abfaa652;p=catagits%2FCatalyst-Controller-WrapCGI.git diff --git a/lib/Catalyst/Controller/CGIBin.pm b/lib/Catalyst/Controller/CGIBin.pm index 8cf9820..e332ef4 100644 --- a/lib/Catalyst/Controller/CGIBin.pm +++ b/lib/Catalyst/Controller/CGIBin.pm @@ -14,6 +14,7 @@ use Symbol 'gensym'; use List::MoreUtils 'any'; use IO::File (); use Carp; +use File::Temp 'tempfile'; use namespace::clean -except => 'meta'; @@ -23,11 +24,11 @@ Catalyst::Controller::CGIBin - Serve CGIs from root/cgi-bin =head1 VERSION -Version 0.017 +Version 0.021 =cut -our $VERSION = '0.017'; +our $VERSION = '0.021'; =head1 SYNOPSIS @@ -37,12 +38,6 @@ In your controller: use parent qw/Catalyst::Controller::CGIBin/; - # example of a forward to /cgi-bin/hlagh/mtfnpy.cgi - sub serve_cgi : Local Args(0) { - my ($self, $c) = @_; - $c->forward($self->cgi_action('hlagh/mtfnpy.cgi')); - } - In your .conf: @@ -214,18 +209,28 @@ L. sub is_perl_cgi { my ($self, $cgi) = @_; - my $shebang = IO::File->new($cgi)->getline; + my (undef, $tempfile) = tempfile; - return 0 if $shebang !~ /perl/ && $cgi !~ /\.pl\z/; + my $pid = fork; + die "Cannot fork: $!" unless defined $pid; - my $taint_check = $shebang =~ /-T/ ? '-T' : ''; + if ($pid) { + waitpid $pid, 0; + my $errors = IO::File->new($tempfile)->getline; + unlink $tempfile; + return $errors ? 0 : 1; + } + # child + local *NULL; open NULL, '>', File::Spec->devnull; - my $pid = open3(gensym, '&>NULL', '&>NULL', "$^X $taint_check -c $cgi"); - close NULL; - waitpid $pid, 0; + open STDOUT, '>&', \*NULL; + open STDERR, '>&', \*NULL; + close STDIN; - $? >> 8 == 0 + do $cgi; + IO::File->new(">$tempfile")->print($@); + exit; } =head2 wrap_perl_cgi @@ -319,10 +324,12 @@ __PACKAGE__->meta->make_immutable; L, L, L, L, L -=head1 AUTHORS +=head1 AUTHOR Rafael Kitover, C<< >> +=head1 CONTRIBUTORS + Hans Dieter Pearcey, C<< >> =head1 BUGS