Execution of Perl scripts in internet pages (Apache web server, Windows XP)

Similar documents
PHP Debugging. Draft: March 19, Christopher Vickery

Apache 2.2 on Windows: A Primer

Redatam+SP REtrieval of DATa for Small Areas by Microcomputer

Greenstone Documentation

Adding web interfaces to complex scientific computer models brings the following benefits:

Getting the software The Apache webserver can be downloaded free from the Apache website :

7 Why Use Perl for CGI?

PHP and XML. Brian J. Stafford, Mark McIntyre and Fraser Gallop

UNIX Web Hosting Support Documentation

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

SIMIAN systems. Setting up a Sitellite development environment on Windows. Sitellite Content Management System

10.1 The Common Gateway Interface

C:\www\apache2214\conf\httpd.conf Freitag, 16. Dezember :50

Contents: 1. Preparation/download files 2. Apache HTTPD Web Server MySQL PHP PHPMyAdmin Ruby On Rails 1.8.

PassMark Software BurnInTest Management Console. Quick start guide

Chapter 1 Introduction to web development and PHP

Created by : Ashish Shah, J.M. PATEL COLLEGE UNIT-5 CHAP-1 CONFIGURING WEB SERVER

Install Apache on windows 8 Create your own server

How to install IntronBase on your computer. Alexander Leow

Installing SQL-Ledger on Windows

APACHE WEB SERVER. Andri Mirzal, PhD N

How To Install Amyshelf On Windows 2000 Or Later

Itelpop Simple Screenpop Web Application Installation & Configuration Guide Version 1.0

Designing and Implementing Forms 34

High Availability Configuration of ActiveVOS Central with Apache Load Balancer


Matlab Web Server Installation and Configuration Guide

PHP+MYSQL, EASYPHP INSTALLATION GUIDE

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

Comparison table for an idea on features and differences between most famous statistics tools (AWStats, Analog, Webalizer,...).

Setting up an Apache Web Server for Greenstone 2 Walkthrough

The Web, SAS, and Security Daryl B. Baird, Trilogy Consulting, Denver, CO

Why File Upload Forms are a Major Security Threat

Installation Guide. Understanding Faith 2014 Intranet. Understanding Faith

Web Page Redirect. Application Note

Tutorial for Avaya 4600 and 9600 Series IP Telephones Push and Browser Applications Setup

WEB2CS INSTALLATION GUIDE

MAMP 3 User Guide! March 2014 (c) appsolute GmbH!

CTIS 256 Web Technologies II. Week # 1 Serkan GENÇ

Perl/CGI. CS 299 Web Programming and Design

OECGI3.EXE Installation and Configuration Quick Start Guide

Lab 3.4.2: Managing a Web Server

Outline Definition of Webserver HTTP Static is no fun Software SSL. Webserver. in a nutshell. Sebastian Hollizeck. June, the 4 th 2013

Systems Integration On Free Software

HOW TO SETUP AN APACHE WEB SERVER AND INTEGRATE COLDFUSION

Document History Revision Date: October 30, 2006

Plugin for Cisco NAC (Network Admission Control) Installation Guide

MySQL Quick Start Guide

CGI An Example. CGI Model (Pieces)

MOODLE Installation on Windows Platform

Witango Application Server 6. Installation Guide for Windows

CONFIGURING A WEB SERVER AND TESTING WEBSPEED

1. When will an IP process drop a datagram? 2. When will an IP process fragment a datagram? 3. When will a TCP process drop a segment?

Apache Usage. Apache is used to serve static and dynamic content

PHP ON A FAST TRACK INTRODUCTION: ROADMAP BY JAROSLAW FRANCIK. Companion web site: php.francik.name

Application Note - JDSU PathTrak Video Monitoring System Data Backup and Restore Process

Users Guide and Reference

Introduction Connecting Via FTP Where do I upload my website? What to call your home page? Troubleshooting FTP...

ADT: Mailing List Manager. Version 1.0

ADT: Inventory Manager. Version 1.0

Federated Access to an HTTP Web Service Using Apache (WSTIERIA Project Technical Note 1)

Chapter 24: Creating Reports and Extracting Data

Backup and Restore MySQL Databases

MAMP PRO 3 - User Guide! March 2014 (c) appsolute GmbH!

Install & Configure Apache with PHP, JSP and MySQL on Windows XP Pro

Graphviz Website Installation, Administration and Maintenance

Pulse Secure Client. Customization Developer Guide. Product Release 5.1. Document Revision 1.0. Published:

Contents. Downloading the Data Files Centering Page Elements... 6

INSTALLING, CONFIGURING, AND DEVELOPING WITH XAMPP

cpanel 11 User Manual

Cybozu Garoon 3 Server Distributed System Installation Guide Edition 3.1 Cybozu, Inc.

Talk Internet User Guides Controlgate Administrative User Guide

LAMP Quickstart for Red Hat Enterprise Linux 4

PDG Software. Site Design Guide

Practice Fusion API Client Installation Guide for Windows

Web Development Guide. Information Systems

Installation and Deployment

HTML Tables. IT 3203 Introduction to Web Development

Customer Control Panel Manual

Witango Application Server 6. Installation Guide for OS X

MailEnable Web Mail End User Manual V 2.x

ISI ACADEMY Web applications Programming Diploma using PHP& MySQL

The only skill required really is to locate and edit text-files with a text-editor like Notepad.

HOW TO CREATE AN HTML5 JEOPARDY- STYLE GAME IN CAPTIVATE

CGI Programming. What is CGI?

Introduction to Web Development

CREATING WEB FORMS WEB and FORMS FRAMES AND

DiskPulse DISK CHANGE MONITOR

Securepoint Security Systems

Installing and Configuring Apache

Short notes on webpage programming languages

Automatic updates for Websense data endpoints

ShoreTel Enterprise Contact Center 8 Installing and Implementing Chat

C HAPTER E IGHTEEN T HE PGP, MAIL, AND CGI LIBRARIES. PGP Interface Library

Fax via HTTP (POST) Traitel Telecommunications Pty Ltd 2012 Telephone: (61) (2) Page 1

IBM Tivoli Access Manager for e-business 6.1: Writing External Authentication Interface Servers

Context-sensitive Help Guide

MySQL Quick Start Guide

Cache Configuration Reference

How To Write A Program In Php (Php)

Transcription:

Execution of Perl scripts in internet pages (Apache web server, Windows XP) The power of Perl scripts can also be used by embedding them into web pages, presented by a web server like Apache. The Perl code can be executed using the CGI (Common Gateway Interface) module of the web server to generate dynamically new web pages. To execute CGI scripts from inside web pages for e.g. calculations, the inclusion of scripts (Include module) must be enabled to allow use of "server-sided includes" (SSI). Security: The possibility to use server sided-includes and the execution of CGI scripts provides additional targets for hacker attacks. They are normally disabled. Compare the Apache security tips: http://httpd.apache.org/docs/2.2/misc/security_tips.html 1. Configuration of web server Apache We chose the last stable Apache-Version Apache 2.2.9, and AciveState Perl 5.10.0.1003. Apache can best be installed as part of a WAMPP system (Windows, Apache, MySQL, PHP, phpmyadmin) as described in WAMPP_install.pdf, chapter 2. The Perl distribution is installed as described in perl_install_xp.pdf. The configuration file is httpd.conf in "C:\Program Files\Apache Software Foundation\Apache2.2\conf" The web pages presented by the Apache server are located in the \htdocs directory: "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs" The Perl scripts executed by the Apache web server are located in: "C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin" For enabling CGI-scripts the configuration file httpd.conf in the folder "C:\Program Files\Apache Software Foundation\Apache2.2\conf" has to be edited: 1a. To load the respective Apache modules at start-up the comment sign "#" has to be removed from the LoadModule section for the cgi_module and include_module, if not already done:. LoadModule cgi_module modules/mod_cgi.so.. LoadModule include_module modules/mod_include.so. C1

1b. The usage settings of the web pages root directory /htdocs and the CGI script directory /cgi-bin directory should both be enabled for execution of includes and the /cgi-bin directory for execution of CGI scripts. The "Options" parameter has to be modified by adding the "+Includes" and "+ExecCGI" options as described in: http://httpd.apache.org/docs/2.2/en/mod/core.html#options <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">. Options Indexes FollowSymLinks +IncludesNOEXEC. </Directory>. <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgibin"> Options +Includes +ExecCGI </Directory> Security: This configuration allows CGI scripts only to be executed, when located inside the "\cgibin" directory. The option "IncludesNOEXEC" will not allow only include calling routines not starting an executable script directly by using "exec cgi" or "exec cmd". Scripts can only be called using "include virtual" from a dedicated script directory "\cgi-bin", remapped by the "ScriptAlias" directive of the httpd.conf file. The script directory is not a subdirectory of the web pages root directory "/htdocs" and is therefore only available by the remapping and by "include virtual" calls. 1c. Check the correct setting of the directory for the CGI scripts (ScriptAlias). The indicated alias "/cgi-bin/" directory gets pointed to a specific script directory: <IfModule alias_module> ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/" </IfModule> 1d. The extension of Perl scripts ".pl" should be added to the cgi-script MIME handler for "cgi-script" and the comment sign "#" should be removed. Further down a MIME handler "text/html" is added for the extension ".shtml" and an output filter to enable scanning for includes for this file type is switched on. The comment signs "#" should be removed: C2

<IfModule mime_module> AddHandler cgi-script.cgi.pl AddType text/html.shtml AddOutputFilter INCLUDES.shtml </IfModule> 1e. The modified httpd.conf file is saved and the Apache web server has to be stopped and restarted to read the new configuration settings. By double clicking on the Apache Monitor Tool you can open the Monitor window. Here you can "stop" and "start" the httpd server. Security and performance: Includes are only executed from special.shtml files and not searched for in normal.html or other files. This also frees the web server from scanning every file for includes. 2. Modification of Perl scripts Any Perl script should contain an absolute first "she-bang" line, not indented, starting with the she-bang symbol "#!" and followed by the directory of the Perl executable program. The flag "-w" can be used to allow extended error reporting. #!C:/Program Files/Perl/bin/perl.exe -w Using the Perl module CGI::Carp allows sending error messages produced during execution of the Perl script to the Browser Window: use CGI::CARP qw(fatalstobrowser); 3. Calling the Perl script from a HTML web site From an HTML file the Perl CGI script is called 1) either directly as a <a href> web link, which deletes the old page and opens a new one interpreting the output of the Perl scripts "print" commands as HTML text and commands: <a href="/cgi-bin/printenv2.pl">environment variables</a> 2) as an included part of a web page using the call "#exec cgi" for a script not receiving additional parameter values from the calling web site or using "#include virtual" for scripts which may use parameters delivered by the calling web site. C3

The calls are surrounded by HTML comment tags: ("<!-- -->"). If the directory option "IncludeNOEXEC" was used in httpd.conf, only "include virtual" is possible for scripts in a directory defined by the httpd.conf option "ScriptAlias": <!--#exec cgi="/cgi-bin/printenv2.pl" --> <!--#include virtual="/cgi-bin/printenv2.pl" --> 4. Test-HTML for executing the Perl script Following HTML-code can be copied as a file "showenv.shtml" into the web server root directory "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs". It will call the Perl script "printenv2.pl" shown below, which should be saved in the web server cgi-bin folder: "C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin". The web site can be called by targeting http://localhost/showenv.shtml with your browser. The Perl script "printenv2.pl" will list the environment variables. For demonstration it is called directly from the page as an include using "include virtual" or it is executed by clicking on the link "Environment" producing a new page. HTML code showenv.shtml: <html> <head> <title>environment</title> <style type="text/css"> body { font-family:helvetica, ARIAL, sans-serif; font-size:9pt; line-height:12pt; } </style> </head> <body> <a href="/cgi-bin/printenv2.pl">environment variables</a><br><br> <!--#echo var="server_name" --><br><br> <!--#config timefmt="%d.%m.%y, %H.%M" --> C4

<!--#echo var="date_local" --><br><br> <!--#include virtual="/cgi-bin/printenv2.pl" --> </body> </html> Perl script printenv2.pl: #!C:/Program Files/Perl/bin/perl.exe -w # printenv2 -- CGI program printing its environment use strict; # send error messages to the browser use CGI::CARP qw(fatalstobrowser); # set MIME type text/html and character set print "Content-type: text/html; charset=iso-8859-1\n\n"; # Printing the environment variables to the calling HTML page # Printing is done one for one in a foreach loop # the hash %ENV contains the environment settings # sort(keys %ENV) sorts the keys (parameter names) of the environment hash # $_ is the actual environment parameter name loaded # $ENV{$_} is the value of the actual environment parameter foreach (sort(keys %ENV)) { print $_. " = ". "\"$ENV{$_}\"". "<br>\n"; } exit; C5

5. Example: Perl generating web pages with Apache - DNA analysis The following HTML page dnamw.html will collect DNA data from the user and call the Perl script dna1.pl inside the /cgi-bin folder to analyse the DNA and calculate the molecular weight. Web service to show base composition, CG-content and molecular weight dnamw.html /cgi-bin/dna1.pl Copy the file dnamw.html to the Apache \htdocs directory and dna1.pl to the \cgi-bin directory. Call the web page by using Firefox with following link dependent on your web server port (80 or 8080): http://localhost/dnamw.html or http://localhost:8080/dnamw.html Fill the entry fields with data and press "Analyze". The data are given to the Perl script by the HTML POST method, which codes them inside the calling string. Special characters inside the data are formatted as "%hexcode". dna1.pl has to retranslate the hex-coded data to the original characters before analysing them. The HTML has a <form></form> section which is bound to the Perl script by POST method by its action and method modifiers. It is activated by pressing the submit button "Analyze" and will send the data copied into the textfiled "Name:" and the text-area " DNA Sequence (plain or FASTA):" <form action="/cgi-bin/dna1.pl" method="post" name="input"> <p>name:<br><input type="text" name="name" size="40" maxlength="40"></p> <p>dna Sequence (plain or FASTA):<br><textarea rows="5" cols="50" name="sequence"></textarea></p> <p><input type="submit" value="analyze"></p> </form> The POST string received by the Perl program from STDIN uses "&" as field separators, the above in the HTML code underlined filed names and the field content associated by an equal sign "=" to the tags: &name=testdna&sequence=acgttat. A common strategy used also in this script is to collect the data from STDIN (which is here not the keyboard but the web server Apache), split the field-value pairs into an array using the "&" as split-indicator, and splitting the array contents step for step into an hash with field names as keys and the field content as hash values. The hex-coded special characters are recoded to normal characters. Special characters which should be shown on the web site have to be encoded by HTML ampersands, e.g. the FASTA sequence start symbol "<" as ">" most important as an HTML tag open marker. C6

Compare at SELFHTML: http://de.selfhtml.org/html/referenz/zeichen.htm#benannte_html Apache sends FASTA ">" as hex code: %62 Perl decodes hex code to normal characters: > Apache gets the ">" coded as ampersand: > The hex-decoding and ampersand-coding is done by following constructs: $value =~ s/%([a-fa-f0-9][a-fa-f0-9])/pack("c", hex($1))/eg; $value =~ s/>/>/g; The yellow labelled pattern in parentheses is caught as $1 (hex number without prefixed %) in the search pattern and is recalculated in the substitution pattern (e modifier allows functions!) - the function hex recodes hex to ASCII numbers - the recoded hex number is "packed" by pack as one character of class "C" (normal characters). Next, if there is a FASTA header line inside the sequence present in the hash %fileds_values key entry "sequence", it is separated from the sequence: if ($fields_values{sequence} =~ /(^\&gt\;[^\n]*)\n([a-za-z]*)/){ $fasta_header = $1; $dna_sequence = $2; } The first parentheses set searches our already ampersand-recoded "<" FASTA start symbol at the beginning (^). The & and semicolon are meta characters in regular expressions and have to be masked by a backslash, followed by zero to many (quantifier *) non-line-breaks [^\n]. Attention: The caret ^ in cornered brackets says: "not" the following alternatives. The output HTML page is just printed using print into STDOUT, which is still Apache and not the screen: print "Content-type: text/html\n\n"; print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">', "\n"; print "<html>\n"; print "<head>\n";... C7