Assignment - CGI and Perl

In this assignment you will create 2 matched pairs of files. In each pair, one is an html file and the other is a perl script called by the html file.

You will incorporate your last name into filenames and screen prompts in this assignment. I write the assignment below as if your last name were Smith. Your name is not Smith. You must replace all occurrences of Smith that you see here with your own, actual last name.

The 2 matched pairs of files are:

A. hellosmith.htm which calls hellosmith.cgi, and
B. CS80smith.htm which calls CS80smith.cgi

 

A. hellosmith.htm and hellosmith.cgi

These are adapted versions of two files we examined in class. Namely, printtaghtmlaction.htm and its companion printtaghtml.pl2. In this exercise, you are essentially repeating on your own what we did in class already. Same html and cgi files, adapted to make you unmistakably see your hand and influence in the process.

1) Obtain files

On your local, Windows computer acquire copies of 

printtaghtmlaction.htm
printtaghtml.pl

They can be extracted from cgisamples.zip. Download cgisamles.zip, then extract the 2 files from it.

2) Rename files

printtaghtml.pl is renamed to hellosmith.cgi
printtaghtmlaction.htm is renamed to hellosmith.htm

3) Edit hellosmith.htm

Use Notepad (and no other editor). Replace the <FORM...> line, which reads as follows:

<FORM ACTION="http://sputnik.smc.edu/cgi-bin/printtaghtml.pl">

with the following line instead:

<FORM ACTION="hellosmith.cgi">

And replace the <h2> line, which reads as follows:

<h2>Press to invoke http://sputnik.smc.edu/cgi-bin/printtaghtml.pl</h2>

with the following line instead:

<h2>Press to invoke hellosmith.cgi</h2>

4) Edit hellosmith.cgi

Replace this line:

<H2 align=\"center\">Hello world</H2>

with this one instead:

<H2 align=\"center\">Hello smith</H2>


5) Transfer files

Using ws_ftp log into sputnik. It will deposit you into your home directory. Your home directory has a subdirectory named public_html, displayed as a yellow folder icon. Change directories on sputnik to public_html (by double clicking its icon). Now transfer hellosmith.cgi and hellosmith.htm from your machine over into your public_html directory on sputnik (Use ftp's ascii tranfer mode, not binary.)

6) Change "permissions" to enable execution

hellosmith.cgi is now in place to be executed but sputnik won't let it execute. For that, you have to take care of a unix detail called "changing file permissions." In ws_ftp you see hellosmith.cgi in the right-hand panel (on the remote machine). Click it once to select it (it turns blue). Then click on it with the right mouse button. A menu appears. Find "chmod (UNIX)" on the menu and click on it to bring up a "Remote file permissions" dialog box. In that box, ensure that for owner, "read" "write" and "execute" are all checked. For both group and other, ensure that "read" and "execute" are both checked. Then click the OK button.

A page that illustrates how this is done is at http://adman2000.virtualave.net/ftp.html.

7) Browse the htm and run the cgi to see the results.

In your browser go to http://sputnik.smc.edu/~Smith/hellosmith.htm. The web server software is configured (as is common) such that references to ~Smith will translate to file searches in the particular directory /home/Smith/public_html. So you may view your fellow students' homework by browsing, for example, http://sputnik.smc.edu/~Jones/hellojones.htm. (This would do you less good than you think. You could View/Source to see the html behind their page, but the more interesting perl code that generated it would be nowhere to be viewed.)

When your hellosmith.htm page appears press the submit button it contains, and view the resulting page dynamically generated by your hellosmith.cgi perl script. You should see "Hello Smith" with a horizontal rule beneath it.


B. CS80smith.htm and CS80smith.cgi

This assignment combines an earlier html assignment you did with cgi. Namely, the CS80outcomes.html assignment, which outputs a table. You will write a cgi script in Perl that regurgitates the same html code, word for word and tag for tag, that you previously wrote. When you originally wrote it, you placed it into an html file. Now you will place it instead into a perl script that generates output. The old html text will become the new script's output. The user who activates this script via his browser will see exactly the same page, differently delivered, as if he had opened your CS80outcomes assignment.

Make a copy of hellosmith.cgi and rename it CS80smith.cgi.

Open CS80smith.cgi in Notepad. Select and delete all the stuff between the tags (i.e., the <<"PrintTag" and the subsequent PrintTag). Leave Notepad open.

Open your earlier assignment, CS80outcomes.html, in another copy of Notepad. Select it all. Copy it to the clipboard.

Go back to the copy of Notepad containing CS80smith.cgi. There, paste in (between the tags, where you left the cursor) your CS80outcomes page lock, stock, and barrel from the clipboard where it sits. Instead of a perl script that outputs "Hello Smith," you now have one that outputs the CS80outcomes page from the old assignment. Save the CS80smith.cgi file.

Use ftp to transfer CS80smith.cgi to the public_html subdirectory within your home directory on sputnik. (Use ftp's ascii tranfer mode, not binary.)

CS80smith.cgi is now in place to be executed but sputnik won't let it execute. For that, you have to take care of a unix detail called "changing file permissions." In ws_ftp you see CS80smith.cgi in the right-hand panel (on the remote machine). Click it once to select it (it turns blue). Then click on it with the right mouse button. A menu appears. Find "chmod (UNIX)" on the menu and click on it to bring up a "Remote file permissions" dialog box. In that box, ensure that for owner, "read" "write" and "execute" are all checked. For both group and other, ensure that "read" and "execute" are both checked. Then click the OK button.

Make a copy hellosmith.htm and rename it CS80smith.htm. Edit CS80smith.htm so that the line:

<FORM ACTION="hellosmith.cgi">

becomes instead:

<FORM ACTION="CS80smith.cgi">

Edit CS80smith.htm so that the line:

<h2>Press to invoke hellosmith.cgi</h2>

becomes instead

<h2>Press to invoke CS80smith.cgi</h2>

Use ftp to transfer CS80smith.htm to the public_html subdirectory.


In your browser go to http://sputnik.smc.edu/~Smith/CS80smith.htm.

When your CS80smith.htm page appears press the submit button it contains, and view the resulting page dynamically generated by your CS80smith.cgi perl script. You should recognize it. It is the same as the output of your earlier CS80outcomes.html assignment. You prepared and delivered this to the browser in your previous assignment by putting it in an html file. Now you have prepared it again, but delivered it differently, by putting it as data into a program that will emit it when run. The web server in one case reads the file, in the other runs the program, obtaining exactly the same thing either way so that you see exactly the same screen either way.

"... the whole business of a web server is to translate a URL either into a filename, and then send that file back over the Internet, or into a program name, and then run that program and send its output back. That is the meat of what it does: all the rest is trimming." Apache, The Definitive Guide, page 1.

Now you've done both.


I will grade these by browsing http://sputnik.smc.edu/~Smith/hellosmith.htm and http://sputnik.smc.edu/~Smith/CS80smith.htm. In the first case I want to see "Hello Smith" and the horizontal rule on my screen, in the second I want to see your CS80outcomes html table revealing your relationships and self-esteem factors. Remember, your future happiness is riding on this assignment.