Apache2-SSI
view release on metacpan or search on metacpan
lib/Apache2/SSI.pm view on Meta::CPAN
=item C<apache_filter>
This is the L<Apache2::Filter> object object that is provided if running under mod_perl.
=item C<apache_request>
This is the L<Apache2::RequestRec> object that is provided if running under mod_perl.
it can be retrieved from L<Apache2::RequestUtil/request> or via L<Apache2::Filter/r>
You can get this L<Apache2::RequestRec> object by requiring L<Apache2::RequestUtil> and calling its class method L<Apache2::RequestUtil/request> such as Apache2::RequestUtil->request and assuming you have set C<PerlOptions +GlobalRequest> in your Apa...
Note that there is a main request object and subprocess request object, so to find out which one you are dealing with, use L<Apache2::RequestUtil/is_initial_req>, such as:
use Apache2::RequestUtil (); # extends Apache2::RequestRec objects
my $r = $r->is_initial_req ? $r : $r->main;
=item C<debug>
Sets the debug level. Starting from 3, this will output on the STDERR or in Apache error log a lot of debugging output.
=item C<document_root>
This is only necessary to be provided if this is not running under Apache mod_perl. Without this value, L<Apache2::SSI> has no way to guess the document root and will not be able to function properly and will return an L</error>.
=item C<document_uri>
This is only necessary to be provided if this is not running under Apache mod_perl. This must be the uri of the document being served, such as C</my/path/index.html>. So, if you are using this outside of the rim of Apache mod_perl and your file resid...
=item C<errmsg>
The error message to be returned when a ssi directive fails. By default, it is C<[an error occurred while processing this directive]>
=item C<html>
The html data to be parsed. You do not have to provide that value now. You can provide it to L</parse> as its first argument when you call it.
=item C<legacy>
Takes a boolean value such as C<1> or C<0> to indicate whether the Apache2 expression supported accepts legacy style.
Legacy Apache expression typically allows for perl style variable C<${REQUEST_URI}> versus the modern style of C<%{REQUEST_URI}> and just an equal sign to imply a regular expression such as:
$HTTP_COOKIES = /lang\%22\%3A\%22([a-zA-Z]+\-[a-zA-Z]+)\%22\%7D;?/
Modern expression equivalent would be:
%{HTTP_COOKIES} =~ /lang\%22\%3A\%22([a-zA-Z]+\-[a-zA-Z]+)\%22\%7D;?/
See L<Regexp::Common::Apache2> for more information.
See also the property C<trunk> to enable experimental expressions.
=item C<remote_ip>
This is used when you want to artificially set the remote ip address, i.e. the address of the visitor accessing the page. This is used essentially by the SSI directive:
my $ssi = Apache2::SSI->new( remote_ip => '192.168.2.10' ) ||
die( Apache2::SSI->error );
<!--#if expr="-R '192.168.2.0/24' || -R '127.0.0.1/24'" -->
Remote ip is part of my private network
<!--#else -->
Go away!
<!--#endif -->
=item C<sizefmt>
The default way to format a file size. By default, this is C<abbrev>, which means a human readable format such as C<2.5M> for 2.5 megabytes. Other possible value is C<bytes> which would have the C<fsize> ssi directive return the size in bytes.
See L<Apache2 documentation|https://httpd.apache.org/docs/current/en/howto/ssi.html> for more information on this.
=item C<timefmt>
The default way to format a date time. By default, this uses the display according to your locale, such as C<ja_JP> (for Japan) or C<en_GB> for the United Kingdom. The time zone can be specified in the format, or it will be set to the local time zone...
See L<Apache2 documentation|https://httpd.apache.org/docs/current/en/howto/ssi.html> for more information on this.
=item C<trunk>
This takes a boolean value such as C<0> or C<1> and when enabled this allows the support for Apache2 experimental expressions.
See L<Regexp::Common::Apache2> for more information.
Also, see the property C<legacy> to enable legacy Apache2 expressions.
=back
=head2 handler
This is a key method expected by mod_perl. Depending on how this module is used, it will redirect either to L</apache_filter_handler> or to L</apache_response_handler>
=head2 ap2perl_expr
This method is used to convert Apache2 expressions into perl equivalents to be then eval'ed.
It takes an hash reference provided by L<Apache2::Expression/parse>, an array reference to store the output recursively and an optional hash reference of parameters.
It parse recursively the structure provided in the hash reference to provide the perl equivalent for each Apache2 expression component.
It returns the array reference provided as the content buffer. This array is used by L</parse_expr> and then joined using a single space to form a string of perl expression to be eval'ed.
=head2 apache_filter
Set or get the L<Apache2::Filter> object.
When running under Apache mod_perl this is set automatically from the special L</handler> method.
=head2 apache_filter_handler
This method is called from L</handler> to handle the Apache response when this module L<Apache2::SSI> is used as a filter handler.
See also L</apache_response_handler>
=head2 apache_request
Sets or gets the L<Apache2::RequestRec> object. As explained in the L</new> method, you can get this Apache object by requiring the package L<Apache2::RequestUtil> and calling L<Apache2::RequestUtil/request> such as C<Apache2::RequestUtil->request> a...
When running under Apache mod_perl this is set automatically from the special L</handler> method, such as:
my $r = $f->r; # $f is the Apache2::Filter object provided by Apache
lib/Apache2/SSI.pm view on Meta::CPAN
<!--#set var="debug" value="2" -->
<!--#set decoding="entity" var="HUMAN_RIGHT" value="Tous les êtres humains naissent libres et égaux en dignité et en droits." encoding="urlencoded" -->
See the L<Apache SSI documentation|https://httpd.apache.org/docs/current/en/mod/mod_include.html> for more information.
=head2 parse_ssi
Provided with the html data as a string and this will parse its embedded ssi directives and return its output as a string.
If it fails, it sets an L</error> and returns an empty string.
=head2 path_info
Sets or gets the path info for the current uri.
Example:
my $string = $ssi->path_info;
$ssi->path_info( '/my/path/info' );
The path info value is also set automatically when L</document_uri> is called, such as:
$ssi->document_uri( '/some/path/to/file.html/my/path/info?q=something&l=ja_JP' );
This will also set automatically the C<PATH_INFO> environment variable.
=head2 query_string
Set or gets the query string for the current uri.
Example:
my $string = $ssi->query_string;
$ssi->query_string( 'q=something&l=ja_JP' );
or, using the L<URI> module:
$ssi->query_string( $uri->query );
The query string value is set automatically when you provide an L<document_uri> upon instantiation or after:
$ssi->document_uri( '/some/path/to/file.html?q=something&l=ja_JP' );
This will also set automatically the C<QUERY_STRING> environment variable.
=head2 remote_ip
Sets or gets the remote ip address of the visitor.
Under Apache mod_perl, this will call L<Apache2::Connection/remote_ip> for version 2.2 or lower and will call L<Apache2::Connection/useragent_ip> for version above 2.2, and otherwise this will get the value from the environment variable C<REMOTE_ADDR...
This value can also be overriden by being provided during object instantiation.
# Pretend the ssi directives are accessed from this ip
$ssi->remote_ip( '192.168.2.20' );
This is useful when one wants to check how the rendering will be when accessed from certain ip addresses.
This is used primarily when there is an expression such as
<!--#if expr="-R '192.168.1.0/24' -->
Visitor is part of my private network
<!--#endif -->
or
<!--#if expr="v('REMOTE_ADDR') -R '192.168.1.0/24' -->
<!--#include file="/home/john/special_hidden_login_feature.html" -->
<!--#endif -->
L<Apache2::Connection> also has a L<Apache2::Connection/remote_addr> method, but this returns a L<APR::SockAddr> object that is used to get the binary version of the ip. However you can also get the string version like this:
use APR::SockAddr ();
my $ip = $r->connection->remote_addr->ip_get();
Versions above 2.2 make a distinction between ip from direct connection, or the real ip behind a proxy, i.e. L<Apache2::Connection/useragent_ip>
=head2 request_uri
This is an alias for L</document_uri>
=head2 server_version
Returns the server version as a L<version> object can caches that value.
Under mod_perl2, it uses L<Apache2::ServerUtil/get_server_description> and outside of mod_perl, it tries to find C<apxs> using L<File::Which> and in last resort, tries to find the C<apache2> or C<httpd> binary to get its version information.
=head2 sizefmt
Sets or gets the formatting for file sizes. Value can be either C<bytes> or C<abbrev>
=head2 timefmt
Sets or gets the formatting for date and time values. The format takes the same values as L<POSIX/strftime>
=head1 Encoding
At present time, the html data are treated as utf8 data and decoded and encoded back as such.
If there is a need to broaden support for other charsets, let me know.
=head1 SSI Directives
This is taken from Apache documentation and summarised here for convenience and clarity to the perl community.
=head2 config
<!--#config errmsg="Error occurred" sizefmt="abbrev" timefmt="%B %Y" -->
<!--#config errmsg="Oopsie" -->
<!--#config sizefmt="bytes" -->
# Thursday 24 December 2020
<!--#config timefmt="%A $d %B %Y" -->
=head2 echo
<!--#set var="HTMl_TITLE" value="Un sujet intéressant" -->
<!--#echo var="HTMl_TITLE" encoding="entity" -->
Encoding can be either C<entity>, C<url> or C<none>
=head2 exec
# pwd is "print working directory" in shell
<!--#exec cmd="pwd" -->
<!--#exec cgi="/uri/path/to/prog.cgi" -->
=head2 include
lib/Apache2/SSI.pm view on Meta::CPAN
=item C<tolower>
=item C<toupper>
=item C<unbase64>
=item C<unescape>
=back
=head2 variables
On top of all environment variables available, Apache makes the following ones also accessible:
=over 4
=item DATE_GMT
=item DATE_LOCAL
=item DOCUMENT_ARGS
=item DOCUMENT_NAME
=item DOCUMENT_PATH_INFO
=item DOCUMENT_URI
=item LAST_MODIFIED
=item QUERY_STRING_UNESCAPED
=item USER_NAME
=back
See L<Apache documentation|https://httpd.apache.org/docs/current/en/mod/mod_include.html#page-header> and L<this page too|https://httpd.apache.org/docs/current/en/expr.html#page-header> for more information.
=head2 expressions
There is reasonable, but limited support for Apache expressions. For example, the followings are supported
In the examples below, we use the variable C<QUERY_STRING>, but you can use any other variable of course.
The regular expression are the ones L<PCRE|http://www.pcre.org/> compliant, so your perl regular expressions should work.
<!--#if expr="$QUERY_STRING = 'something'" -->
<!--#if expr="v('QUERY_STRING') = 'something'" -->
<!--#if expr="%{QUERY_STRING} = 'something'" -->
<!--#if expr="$QUERY_STRING = /^something/" -->
<!--#if expr="$QUERY_STRING == /^something/" -->
# works also with eq, ne, lt, le, gt and ge
<!--#if expr="9 gt 3" -->
<!--#if expr="9 -gt 3" -->
# Other operators work too, namely == != < <= > >= =~ !~
<!--#if expr="9 > 3" -->
<!--#if expr="9 !> 3" -->
<!--#if expr="9 !gt 3" -->
# Checks the remote ip is part of this subnet
<!--#if expr="-R 192.168.2.0/24" -->
<!--#if expr="192.168.2.10 -R 192.168.2.0/24" -->
<!--#if expr="192.168.2.10 -ipmatch 192.168.2.0/24" -->
# Checks if variable is non-empty
<!--#if expr="-n $some_variable" -->
# Checks if variable is empty
<!--#if expr="-z $some_variable" -->
# Checks if the visitor can access the uri /restricted/uri
<!--#if expr="-A /restricted/uri" -->
For subnet checks, this uses L<Net::Subnet>
Expressions that would not work outside of Apache, i.e. it will return an empty string:
<!--#expr="%{HTTP:X-example-header} in { 'foo', 'bar', 'baz' }" -->
See L<Apache documentation|http://httpd.apache.org/docs/2.4/en/expr.html> for more information.
=head1 CREDITS
Credits to Ken Williams for his implementation of L<Apache::SSI> from which I borrowed some code.
=head1 AUTHOR
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
CPAN ID: jdeguest
L<https://gitlab.com/jackdeguest/Apache2-SSI>
=head1 SEE ALSO
L<Apache2::SSI::File>, L<Apache2::SSI::Finfo>, L<Apache2::SSI::Notes>, L<Apache2::SSI::URI>, L<Apache2::SSI::SharedMem> and L<Apache2::SSI::SemStat>
mod_include, mod_perl(3), L<Apache::SSI>,
L<https://httpd.apache.org/docs/current/en/mod/mod_include.html>,
L<https://httpd.apache.org/docs/current/en/howto/ssi.html>,
L<https://httpd.apache.org/docs/current/en/expr.html>
L<https://perl.apache.org/docs/2.0/user/handlers/filters.html#C_PerlOutputFilterHandler_>
=head1 COPYRIGHT & LICENSE
Copyright (c) 2020-2021 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated
files under the same terms as Perl itself.
=cut
( run in 0.889 second using v1.01-cache-2.11-cpan-39bf76dae61 )