Apache2-SSI

 view release on metacpan or  search on metacpan

SIGNATURE  view on Meta::CPAN

SHA256 528803b0b83fd9788eef94f411b82d1c3907e1a9a45ed7246c8d339906ad801b META.json
SHA256 2cf5d30d8cade6f2d867c7808e3f7f0e71d0a8c60a61aa4f227c2f0b5c515b0d META.yml
SHA256 8ae9ff751561ca955a9d9e0e711e45a23f112d84956db6067083bfd83f1b2a4b Makefile.PL
SHA256 5709c3fec2f6f36b57d304022ef9be8d6d569f9488169b993dcbde0a4ac863cf README
SHA256 8e4e325b6e7f709937948850fbe2615423022333c7f4da9a744d2c499b0346e2 README.md
SHA256 8d8198ea0421b59e4fe9e82d5607f2c6bf0e1135375b578b15b3c813e9c44ae6 lib/Apache2/Expression.pm
SHA256 9c6bdbfd307f6ccb347066e5efd457b858825535f726554b3cc008bca2525be6 lib/Apache2/SSI.pm
SHA256 511c4b5ea78431dd65e6560517be3d9ec2a0f3e6ef8ee5bafa667f3c8cee47c3 lib/Apache2/SSI/Common.pm
SHA256 bc8be34caa7f51047142ede4d20d4ea7d7b017ceee388e7576c126a3a6c1d305 lib/Apache2/SSI/Datetime.pod
SHA256 11f24f9d391c71354e1e927a05edca8adc09c683792e6f082e6a6bedbfca1ac9 lib/Apache2/SSI/File.pm
SHA256 77a100890939ecec17f7633d0348c932056243bb1369090404c5fffdd5513579 lib/Apache2/SSI/File/Type.json
SHA256 f1b2003d3db47854b27d91efacc7d6be799313271ffafec1a62b112ad726bc29 lib/Apache2/SSI/File/Type.pm
SHA256 6421853430db67805444fc9422ba7aedbbb92e0d23c16b1c7d5c346eae402bfc lib/Apache2/SSI/Finfo.pm
SHA256 6395d058a1d67395d3b829485437db21f8a9416daf0258ea235aecb80bfd5484 lib/Apache2/SSI/Notes.pm
SHA256 c40032d706f1921898090fe8181f7113ca663f7c027d2ec9706dfc5fc31eb142 lib/Apache2/SSI/SemStat.pod
SHA256 67126009dd2bc32619964ef982d49a693d2c670e9e329e3851675f1b1ca78f89 lib/Apache2/SSI/SharedMem.pm
SHA256 1ea41e34072a87d504e189ac7042359e7f9baa0da34371a23615cf259cdb3718 lib/Apache2/SSI/SharedMem.pod
SHA256 e1f0970af0e4787a2e009c9d7a55d48ff9fb69c1dada4a25eb3ba41045fd62c3 lib/Apache2/SSI/URI.pm
SHA256 841ea2c6c09226881822d1d0e99764181983fe073f8e15f6c9d3b40a259d503e scripts/startup.pl
SHA256 c25e83d5bc3da4b519e35ddd25212e2f1c852f18d666e9819cce04906bebeeb7 t/00.load.t
SHA256 6f1861e831ddadad06bd2051dbc6fca476e0c0697b46dabe57f247df4629f98d t/02.pod.t

lib/Apache2/SSI.pm  view on Meta::CPAN

{
    my $self = shift( @_ );
    my $file = shift( @_ ) || return( $self->error( "No file provided to look up." ) );
    my $r = $self->apache_request;
    my $f = Apache2::SSI::File->new(
        $file,
        ( $r ? ( apache_request => $r ) : () ),
        base_file => $self->uri->filename,
        debug => $self->debug
    ) || return( $self->error( "Unable to instantiate an Apache2::SSI::File object: ", Apache2::SSI::File->error ) );
    if( $f->code == 404 )
    {
        # Mimic the Apache error when the file does not exist
        $self->error( "unable to lookup information about \"$file\" in parsed file \"", $self->uri, "\"." );
    }
    return( $f );
}

sub lookup_uri
{
    my $self = shift( @_ );
    my $uri  = shift( @_ );
    my $r = $self->apache_request;
    my $u = Apache2::SSI::URI->new(
        ( $r ? ( apache_request => $r ) : () ),
        base_uri => $self->uri,
        document_uri => $uri,
        document_root => ( $r ? $r->document_root : $self->document_root ),
        debug => $self->debug
    ) || return( $self->error( "Unable to instantiate an Apache2::SSI::URI object: ", Apache2::SSI::URI->error ) );
    if( $u->code == 404 )
    {
        # Mimic the Apache error when the file does not exist
        $self->error( "unable to get information about uri \"$uri\" in parsed file ", $self->uri );
    }
    return( $u );
}

sub mod_perl { return( shift->_set_get_boolean( 'mod_perl', @_ ) ); }

sub new_uri

lib/Apache2/SSI.pm  view on Meta::CPAN

    
    if( $cgi->code != 200 )
    {
        $self->error( "Error including cgi: subrequest returned status '" . $cgi->code . "', not 200" );
        return( $self->errmsg );
    }
    
    my $finfo = $cgi->finfo;
    if( !$finfo->exists )
    {
        $cgi->code( 404 );
        $self->error( "Error including cgi \"$args->{cgi}\". File not found. CGI resolved to \"", $cgi->filename, "\"" );
        return( $self->errmsg );
    }
    elsif( !$finfo->can_exec )
    {
        unless( $^O =~ /^(dos|mswin32|NetWare|symbian|win32)$/i && -T( "$finfo" ) )
        {
            # return( $self->error( "Error including cgi \"$args->{cgi}\". File is not executable by Apache user." ) );
            $self->error( "Error including cgi \"$args->{cgi}\". File is not executable by Apache user." );
            $cgi->code( 401 );

lib/Apache2/SSI/File.pm  view on Meta::CPAN

            {
                $self->apache_request( $rr );
                $newfile = $rr->filename;
                my $finfo = $rr->finfo;
                if( $finfo )
                {
                }
            }
            else
            {
                $self->code( 404 );
                $newfile = $self->collapse_dots( $newfile, { separator => $DIR_SEP });
                # We don't pass it the Apache2::RequestRec object, because it would trigger a fatal error since the file does not exist. Instead, we use the api without Apache2::RequestRec which is more tolerant
                # We do this so the user can call our object $file->finfo->filetype == Apache2::SSI::Finfo::FILETYPE_NOFILE
                $self->{finfo} = Apache2::SSI::Finfo->new( $newfile );
            }
            $self->{filename} = $newfile;
        }
        elsif( !length( $self->{filename} ) )
        {
            $self->{filename} = $r->filename;

lib/Apache2/SSI/File.pm  view on Meta::CPAN

            my $base_dir = $self->base_dir;
            $base_dir .= $DIR_SEP unless( substr( $base_dir, -length( $DIR_SEP ), length( $DIR_SEP ) ) eq $DIR_SEP );
            # If we provide a string for the abs() method it works on Unix, but not on Windows
            # By providing an object, we make it work
            $newfile = URI::file->new( $newfile )->abs( URI::file->new( $base_dir ) )->file( $^O );
            $self->{filename} = $self->collapse_dots( $newfile, { separator => $DIR_SEP })->file( $^O );
            $self->finfo( $newfile );
            my $finfo = $self->finfo;
            if( !$finfo->exists )
            {
                $self->code( 404 );
            }
            # Force to create new Apache2::SSI::URI object
        }
    }
    return( $self->{filename} );
}

# Alias
sub filepath { return( shift->filename( @_ ) ); }

lib/Apache2/SSI/File.pm  view on Meta::CPAN

Returns the base file for this file object.

=head2 clone

Create a clone of the object and return it.

=head2 code

Sets or gets the http code for this file.

    $f->code( 404 );

=head2 collapse_dots

Provided with an uri or a file path, and this will resolve the path and removing the dots, such as C<.> and C<..> and return an L<URI> object.

This is done as per the L<RFC 3986 section 5.2.4 algorithm|https://tools.ietf.org/html/rfc3986#page-33>

    my $file = $f->collapse_dots( '/../a/b/../c/./d.html' );
    # would become /a/c/d.html

lib/Apache2/SSI/File/Type.json  view on Meta::CPAN

      "application/pgp",
      []
   ],
   [
      0,
      0,
      2,
      "beshort",
      null,
      "=",
      34049,
      "n",
      "application/pgp-encrypted",
      []
   ],
   [
      0,
      0,
      3,
      "string",
      null,

lib/Apache2/SSI/URI.pm  view on Meta::CPAN

            code => 200,
        });
    }
    elsif( $uri_path eq '/' )
    {
        return({
            filepath => $doc_root,
            path => $uri_path,
            path_info => undef(),
            query_string => $qs,
            code => ( -e( $doc_root ) ? 200 : 404 ),
        });
    }
    my @parts = split( '/', substr( $uri_path, 1 ) );
    my $trypath = '';
    my $trypath_uri = '';
    my $pathinfo = '';
    foreach my $p ( @parts )
    {
        # The last path was a directory, and we cannot find the element within. So, the rest of the path is not path info, but rather a 404 missing document hierarchy
        # We test the $pathinfo string, so we do not bother checking further if it is already set.
        if( !$pathinfo && -d( "${doc_root}${trypath}" ) && !-e( "${doc_root}${trypath}/${p}" ) )
        {
            # We return the original path provided (minus any query string)
            return({
                filepath => $doc_root . ( length( $trypath ) ? $trypath :  $path ),
                path => $uri_path,
                code => 404,
                query_string => $qs,
            });
        }
        elsif( !$pathinfo && -e( "${doc_root}${trypath}/${p}" ) )
        {
            $trypath_uri .= "/${p}";
            $trypath  .= "${sep}${p}";
        }
        else
        {

lib/Apache2/SSI/URI.pm  view on Meta::CPAN

L<Apache2::SSI::URI> is used to manipulate and query http uri. It is used by L<Apache2::SSI> both for the main query, and also for sub queries like when there is an C<include> directive.

In this case, there would be the main document uri such as C</some/path/file.html> and containing a directive such as:

    <!--#include virtual="../other.html" -->

An L<Apache2::SSI::URI> object would be instantiated to process the uri C<../other.html>, flatten the dots and get its underlying filename.

Even if the uri provided does not exist, am L<Apache2::SSI::URI> object would still be returned, so you need to check if the file exists by doing:

    if( $uri->code == 404 )
    {
        die( "Not there\n" );
    }

Or, this would work too:

    if( $uri->finfo->filetype == Apache2::SSI::Finfo::FILETYPE_NOFILE )
    {
        die( "No such file !\n" );
    }

lib/Apache2/SSI/URI.pm  view on Meta::CPAN

Sets or gets the base reference uri. This is used to render the L</document_uri> provided an absolute uri.

=head2 clone

Create a clone of the object and return it.

=head2 code

Sets or gets the http code for this uri.

    $uri->code( 404 );

=head2 collapse_dots

Provided with an uri, and this will resolve the path and removing the dots, such as C<.> and C<..> and return an L<URI> object.

This is done as per the L<RFC 3986 section 5.2.4 algorithm|https://tools.ietf.org/html/rfc3986#page-33>

    my $uri = $ssi->collapse_dots( '/../a/b/../c/./d.html' );
    # would become /a/c/d.html
    my $uri = $ssi->collapse_dots( '/../a/b/../c/./d.html?foo=../bar' );

t/70.file.t  view on Meta::CPAN


isa_ok( $f, 'Apache2::SSI::File' );

my $failed;
{
    no warnings 'Apache2::SSI::Finfo';
    $failed = Apache2::SSI::File->new( './not-existing.txt', debug => $DEBUG );
}

ok( defined( $failed ), 'Non-existing file object' );
ok( $failed->code == 404, 'Non-existing file code' );
ok( $failed->finfo->filetype == Apache2::SSI::Finfo::FILETYPE_NOFILE, 'Non-existing file type' );

isa_ok( $failed, 'Apache2::SSI::File' );

diag( "Expecting ", File::Spec->catdir( $dir, URI::file->new( '/ssi/include.cgi' )->file( $^O ) ) ) if( $DEBUG );
ok( $f->filename eq File::Spec->catdir( $dir, URI::file->new( '/ssi/include.cgi' )->file( $^O ) ), 'filename' );

ok( $f->code == 200, 'code' );

my $f2 = $f->clone;

{
    no warnings 'Apache2::SSI::File';
    $f2->filename( "${dir}/ssi/../ssi/plop.pl" );
}

diag( "Filename is: ", $f2->filename, " and I am expecting ", File::Spec->catdir( $dir, URI::file->new( '/ssi/plop.pl' )->file( $^O ) ) ) if( $DEBUG );
ok( $f2->filename eq File::Spec->catdir( $dir, URI::file->new( '/ssi/plop.pl' )->file( $^O ) ), 'filename' );

ok( $f2->code == 404, 'code failed' );

# Access to finfo
my $finfo = $f->finfo;
diag( "File ", File::Spec->catdir( $dir, URI::file->new( "/${file}" )->file( $^O ) ), " mode is: '", ( (CORE::stat( File::Spec->catpath( $dir, URI::file->new( "/${file}" )->file( $^O ) ) ))[2] & 07777 ), "' vs finfo one: '", $f->finfo->mode, "'" ) if...
ok( ( (CORE::stat( File::Spec->catdir( $dir, URI::file->new( "/${file}" )->file( $^O ) ) ))[2] & 07777 ) eq $f->finfo->mode, 'finfo' );

ok( $f->finfo->is_file, 'finfo is_file' );

ok( $f->parent->filename eq File::Spec->catdir( $dir, URI::file->new( '/ssi' )->file( $^O ) ), 'parent' );

t/SSITest.pm  view on Meta::CPAN

    my $self = shift( @_ );
    my $failed = $self->_get_test_file_2;
    return( $self->ok( defined( $failed ) && $failed->isa( 'Apache2::SSI::File' ) ) );
}

## Non-existing file code
sub test22
{
    my $self = shift( @_ );
    my $failed = $self->_get_test_file_2;
    return( $self->ok( defined( $failed ) && $failed->code == 404 ) );
}

## Non-existing file code
sub test23
{
    my $self = shift( @_ );
    my $failed = $self->_get_test_file_2;
    return( $self->ok( defined( $failed ) && $failed->finfo->filetype == Apache2::SSI::Finfo::FILETYPE_NOFILE ) );
}

t/SSITest.pm  view on Meta::CPAN

}

## Resulting code from filename updated with non-existing file
sub test26
{
    my $self = shift( @_ );
    my $f = $self->_get_test_file_1;
    my $base = $f->base_dir;
    my $f2 = $f->clone;
    $f2->filename( $self->apache_request->document_root . BASE_URI . "/../ssi/plop.pl" );
    return( $self->ok( $f2->code == 404 ) );
}

## Resulting file type from filename updated with non-existing file
sub test27
{
    my $self = shift( @_ );
    my $f = $self->_get_test_file_1;
    my $base = $f->base_dir;
    my $f2 = $f->clone;
    $f2->filename( $self->apache_request->document_root . BASE_URI . "/../ssi/plop.pl" );



( run in 1.705 second using v1.01-cache-2.11-cpan-39bf76dae61 )