2008/07/25

The Labs.Com Admin Lab Perl Lab Inline Perl Pages
Last update 2002/02/12
The Labs - Design & Functionality For The Net

Inline Perl in HTML-Pages using mod_perl

  1. Introduction
  2. Download
  3. Installation
  4. Syntax
  5. Security
  6. Other Perl Packages
Inline Perl Pages
1. Introduction
InlinePerlPages is a very experimental script with use of mod_perl perl-modules for Apache HTTPD. It provides following features:
  1. Inline perl statements: stdout goes to output of resulting page.
  2. Include files: include html/perl from a page (recursivly).
  3. No seen CGIs (search-engines parse all your dynamic pages)

Inline Perl Pages
2. Download

$MyVersion: 0.010 - Fri May 10 14:08:44 CEST 2002 - kiwi$

IPP.tar.gz

Inline Perl Pages
3. Installation

You require to run Apache Web-Server then install mod_perl, follow the instructions given at http://perl.apache.org.

Unpack and install IPP.pm:

 tar zxf IPP.tar.gz 
 cd IPP 
 perl Makefile.PL 
 make 
 make install  

then edit your http.conf:

 <VirtualHost 192.168.0.28> 
    ServerAdmin webmaster@host.some_domain.com 
    DocumentRoot /mypath/whatever/ 
    <Location /> 
       SetHandler perl-script 
       # PerlSetVar IPPStrict off 
       PerlHandler Apache::IPP 
       PerlSendHeader On 
    </Location> 
 </VirtualHost> 

Run as root

 /usr/local/apache/sbin/apachectl restart 

By default 'use strict' is enabled within all perl-code, if you want to write unsafe perl-code then remove comment at 'PerlSetVar IPPStrict off'.

Inline Perl Pages
4. Syntax

Following inline commands are available:

#perl ... #/perlsource-code in perl
#include <filename>include a file
#include <filename:arg1,arg2,...>include a file with arguments (they become available as @ARGV)
<perl> ... </perl>source code in perl
<include "file">include a file
<include "file:arg1,arg2,...">include a file with arguments

All above tags must start at the beginning of a line and alone on a line.

Sample Code
 Sample test.html, two version which are identical using two different styles:

 <title>Sample</title> 
 #perl 
 open(F,"sample"); 
 while(<F>) { 
    print $_; 
 } 
 close(F); 
 #/perl 
  
 Another part 
 #include <stuff> 

 <title>Sample</title> 
 <perl> 
 open(F,"sample"); 
 while(<F>) { 
    print $_; 
 } 
 close(F); 
 </perl> 
  
 Another part 
 <include "stuff"> 

Available variables

  • %in has all (possible) CGI variables (GET/POST)
  • %ENV contains all CGI related variables like in normal CGIs
Be careful when changing global variables with in-line perl since it's not sure a script is excecuted in its entirety, httpd may terminate the perl-code at any point.

IPP Cookbook
More examples ...

Inline Perl Pages
5. Security

Security is always a problem on the net, especially on web-servers. InlinePerlPages is powerful, and therefore following recommendations should be considered:
  • Don't allow any web-user to write HTML pages at all.
  • Don't use guestbooks, or threaded discussions which create HTML pages direct, web-user could enter malicious #perl code by themselves.
  • Use guestbooks or discussion-forums which store their submission as text or HTML in separate file(s) (but not .html pages); those files you include from an InlinePerlPages page. This way the data doesn't get interpreted by InlinePerlPages and #perl and #include don't take any effect.
  • In general, anything which is requested direct via http:// is wrapped via InlinePerlPages; anything you include (read from a file or db) within an InlinePerlPages is not interpreted.

Inline Perl Pages
6. Other Perl Packages

PowerPerl
Inline perl using <script language="PerlScript"> tags
Embperl: Embed Perl in HTML
Embedded perl within HTML using [- and -] as tags
ePerl
Alike package, uses <? and !> as tags
ProgrammerHTML Handler()
The more sophisticated handler()

                                                                                                                                   

Mason Perl Lab

Last update 2002/02/12

All Rights Reserved - (C) 1997 - 2008 by The Labs.Com

Top of Page

The Labs.Com