• Aucun résultat trouvé

Lab Session

N/A
N/A
Protected

Academic year: 2022

Partager "Lab Session"

Copied!
2
0
0

Texte intégral

(1)

Web Master 1 IFI

Lab Session #3: The Common Gateway Interface

Andrea G. B. Tettamanzi Université côte d'Azur

andrea.tettamanzi@univ-cotedazur.fr Academic Year 2018/2019

Abstract

We will write a simple CGI program to generate a dynamic HTML page.

1 Introduction

The Common Gateway Interface (CGI) is a simple interface for running external programs, software or gateways under an HTTP server in a platform-independent manner.

The CGI has been in use by the World-Wide Web since 1993. The full specication of the

`CGI/1.1' can be found here:

https://tools.ietf.org/html/draft-robinson-www-interface-00.

In order to implement the following requirements, you will need to have an HTTP server (e.g., Apache 2) installed and properly congured on your machine. For Linux machines, it is recommended to install the LAMP stack; for Windows machines, the equivalent stack is called WAMP and for MacOS machines MAMP.

Please refer to the documentation of your HTTP server for how to congure it to set up a directory to serve GCI executables. For instance, with Apache 2 running under Linux, the /cgi-bin path is an alias for the /usr/lib/cgi-bin directory, which is enabled to serve CGI executables (i.e., binaries). One only needs to enable the CGI module by issuing the command

sudo a2enmod cgid

By the way, to allow .py les to be executed as scripts, one has to add the AddHandler cgi-script .py directive to the cgi-bin directory in the serve-cgi-bin.conf le. Notice that the Python script must have the correct path to the Python interpreter on its rst line, for instance

#!/usr/bin/python3

for the HTTP server to know which interpreter it is supposed to launch to execute it.

2 Requirements

We are going to develop a CGI program that takes a natural number as input and produces an HTML page providing its prime factor decomposition.

1. You can write your CGI program in C or Python.

1

(2)

2. The CGI program will be invoked by a HTTP request with method GET. Assuming the script is called td3 in the /cgi-bin directory of the HTTP server, it should be invoked with a URI like

http://localhost/cgi-bin/td3?n=1234567890,

where 1234567890 is the natural number for which a prime factor decomposition is sought for.

3. The CGI program will generate a (valid) HTML page showing the answer in a human- readable format like

1234567890 = 2×32×5×3607×3803.

Use HTML tags like <sup> to obtain superscipts and entities like &times; to obtain the

×symbol.

4. Check the validity of the query string and generate an HTML page showing an error message in case the query string does not comply with the syntax:

n=hunsigned_decimal_integeri.

5. Write a static HTML page containing a form to allow a user to enter a natural number and compute its decomposition by invoking your CGI program.

6. Modify your CGI program to generate the above static HTML page when it is invoked without the query string, i.e., with a URI like

http://localhost/cgi-bin/td3

and to generate the prime factor decomposition below the form when invoked with a valid query string. The user should be able to use the generated page to submit a new request for another natural number.

2

Références

Documents relatifs

Despite the number of learners in each school and the strict timing, we aimed at gathering high quality data from learners: we needed genuine and dependable infor- mation from

Using the block decomposition approach, we show that a minimum geodetic set can be computed in (a proper superclass of) block-cacti and in monopolar chordal graphs (which

We conclude about the existence of imaginary quadratic fields, p-rational for all p ≥ 2 (Angelakis–Stevenhagen on the concept of “minimal absolute abelian Galois group”) which

Please at- tach a cover sheet with a declaration http://tcd-ie.libguides.com/plagiarism/declaration confirming that you know and understand College rules on plagiarism1. On the

Many researchers have focused on the combination of (probabilistic) logic pro- gramming with other formalisms, using it as a component to build more powerful approaches, which pave

In push and push-pull, infor- mation is communicated between adjacent vertices, whereas in visit-exchange and meet-exchange information is passed be- tween an agent and a vertex

Like for- ward conditioning (used in conditioned slicing), backward conditioning consists of specialising a program with respect to a condition inserted into the

to advanced quantum chemistry methods such as Natural Resonance Theory (NRT) based on the Natural Bond Orbitals approach.[8, 9, 10, 11] However, it lacks of physics and does not