Printed from TeacherJohn.com • http://teacherjohn.com/cabrillo/dm160c/exercises/ex08.php

Exercise 8: Automated Site Map CGI Script


Resources for this exercise:


In this exercise you will download, configure, install, and use an site map generator Perl CGI script. This script will automatically create a site map for your Web site. This package that you will download also provides you with a template page for the site map, but instead you will use a PHP include to include the site map into your own page.

1) Go to the "tree.pl sitemap script" page to download a free site map generator. This site is at:
http://www.danielnaber.de/tree

2) On this page you will see two links that can be used to download the script:

You can use either one, but given the choice I usually use the tar file. If you try that link and your computer won't decompress the tar archive into a folder called "tree", then use the other link.

3) If all goes correctly, the compressed file will automatically expand into a folder called "tree" after the file downloads. If it doesn't, you may need to manually open the compressed file with your decompression software.

4) You will now have a folder called "tree" containing four text files. Yes, you should read the "README" file, but if you don't want to read it all now you can follow these exercise instructions to get the script to work.

5) With a text editor, open the CGI script called "tree.pl". You need to make several changes to this file.

6) Although commented lines in a Perl file begin with a # symbol, the first line of any Perl script is the "path to Perl" and is not a comment. You will not need to change this, as it is already correct for webhawks.org.

Except for the very first line (the path to Perl), any other lines that begin with a # symbol are comments and are ignored by the script. If the # symbol appears in a line, anything following in that line is a comment.

7) First you need to set the script to run as a CGI script.

Find the line that reads:
$conf::cgi = 0;
and change it to:
$conf::cgi = 1;

8) Now you need to tell the script which directory is the one from which to make a site map. To map your entire site, you would use the absolute path to your "public_html" directory.

Find the line that reads:
$conf::basedir_cgi = "/home/www";
and change it to:
$conf::basedir_cgi = "/home/s87182/dm62student/public_html";

Of course you will need to use your own webhawks user name in the above line. Note that this path does not end in a slash, and that there is no tilde in front of your webhawks user name.

9) Now you need to tell the script that you will not be using the template page that came with the script (instead you will use a PHP include to include the site map into your own page).

Find the line that reads:
$conf::templatefile = "tree-template.html";
and change it to:
$conf::templatefile = "";

10) Now you need to tell the script the first part of the URLs of the pages of your site:

Find the line that reads:
$conf::baseurl = "";
and change it to:
$conf::baseurl = "/~dm62student/";

Of course you will need to use your own webhawks user name in the above line. Note that this path ends in a slash, and that there is a tilde in front of your webhawks user name.

11) Although it is not necessary to make any other changes for the script to work, there are a few more changes that you should make to this file.

Now you need to tell the script what kind of files should show up in the site map. The default is all files, but you should limit it to display only typical Web pages and PDFs.

Find the line that reads:
@conf::file_suffixes = ();
and comment it out by adding a # symbol so that it reads:
#@conf::file_suffixes = ();

Now find the line that reads:
#@conf::file_suffixes = ('shtml', 'html', 'htm', 'pdf');
and uncomment it by deleting the # symbol — and add .php files — so that it reads:
@conf::file_suffixes = ('shtml', 'html', 'htm', 'php', 'pdf');

12) Now you need to tell the script what of files and directories should be excluded from the site map. The default is to include all directories, but there are some directories that you do not want to show up in the site map, such as images, css, includes, js, cgi-bin, etc.

Find the line that reads:
@conf::excludefiles = ();
and comment it out by adding a # symbol so that it reads:
#@conf::excludefiles = ();

Now find the line that reads:
#@conf::excludefiles = ('/secret/*', '/anothersecret/*');
and uncomment it by deleting the # symbol so that it reads:
@conf::excludefiles = ('/secret/*', '/anothersecret/*');
and now indicate the directories to exclude, by doing something like the following:
@conf::excludefiles = ('/images/*', '/css/*', '/cgi-bin/*', '/js/*', '/includes/*', '/ran_con/*', '/rancon/*');

13) The script is written to ouput the site map as an entire Web page. Because you will want to include the output into your own page, you need to edit a section of the script.

Now find the section that reads:

$conf::template =<<__EOF;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Sitemap</title>
<style type="text/css">
<!--
.info { color: #888888; }
-->
</style>
</head><body>

<h1>Sitemap</h1>

##sitemap##

</body>
</html>
__EOF

and change it to:

$conf::template =<<__EOF;
##sitemap##
__EOF

14) Save these changes to "tree.pl" — save this file as a text file, of course.

15) Now create a Web page for exercise 8.

16) This page's <title> must indicate that this is your exercise 8 page, so it should say something like "John Sky's DM62 Exercise 8 ".

17) This page must display your name and say "Exercise 8".

18) This page must contain a relative link to your home page.

19) This page must contain the HTML 5 DocType that will enable you to use an HTML validator (as explained in How to Use the W3C HTML and CSS Validators).

20) This page must contain links (either buttons or text links) to the HTML and CSS validators. See How to Put HTML and CSS Validate Buttons on Your Page for information on how I want you to to do this. (Use the block of code on this page to make the button links or text links, so that clicking on the links automatically lets you know if the page validates or not.)

21) Now place a PHP include on this page that will display the output of the site map script:

<?php
virtual("cgi-bin/tree/tree.pl");
?>

22) Save this page as "exercise8.php".

23) Upload your exercise 8 page into your public_html folder.

24) Create a folder called "tree" in your cgi-bin" folder that is at the root of your public_html folder.

25) Now upload the CGI script, "tree.pl", into the "tree" folder.

Important note: CGI scripts must always be uploaded in "ASCII," or " text," mode. This means that when you upload the script, your FTP software to be in ASCII, or text, mode. Most FTP programs, such as Fetch and Fugu for Macintosh, and CoreFTP for Windows, should automatically do this for you, as they will see the ".pl" extension on the file name and do the right thing.

26) Now you need to make the CGI script (the file "tree.pl") executable. This means you need to change its file permissions to what Unix calls a permissions set of "755" (some FTP programs may show this as "0755"). Using the following instructions, change the permissions of the script, "tree.pl". (Do not change the permissions of your exercise 8 Web page — in fact, do not change the permissions of any file other than "tree.pl".)

How to change file permissions using Fetch (Macintosh):

  1. While viewing the list of remote files in Fetch, control-click (or, if you have a 2-button mouse, right-click) on the file whose permissions you wish to change.
  2. From the pop-up menu that appears, choose "Get Info".
  3. You will now see an "Info" window, with nine checkboxes. (If you do not see the nine checkboxes, click on the tiny triangle to the left of "Ownership and Permissions".) Check the appropriate boxes. (To set the permissions for an executable CGI script, check the following 7 boxes: Read, Write, and Execute of Owner, Read and Execute of Group, and Read and Execute of Others. This is known as chmod 755.)
  4. Click "Apply".
  5. Close the Info window by clicking on the small red button in the upper-left corner of the window.

How to change file permissions using CoreFTP (Windows):

  1. While viewing the list of remote files in CoreFTP, right-click on the file whose permissions you wish to change.
  2. From the pop-up menu that appears, choose "Properties".
  3. You will now see a File Properties window, with nine checkboxes. Check the appropriate boxes. (To set the permissions for an executable CGI script, check the following 7 boxes: Read, Write, and Execute of Owner, Read and Execute of Group, and Read and Execute of Other. This is known as chmod 755.)
  4. Click "OK".

How to change file permissions using Cyberduck (Macintosh):

  1. While viewing the list of remote files in Cyberduck, control-click on the file whose permissions you wish to change.
  2. From the pop-up menu that appears, choose "Get Info".
  3. You will now see an "Info" window, with nine checkboxes. Check the appropriate boxes. (To set the permissions for an executable CGI script, check the following 7 boxes: Read, Write, and Execute of Owner, Read and Execute of Group, and Read and Execute of Everyone. This is known as chmod 755.)
  4. Close the Info window by clicking on the small red button in the upper-left corner of the window.

How to change file permissions using Fugu (Macintosh):

  1. While viewing the list of remote files in Fugu, control-click on the file whose permissions you wish to change.
  2. From the pop-up menu that appears, choose "Get Info".
  3. You will now see an "Info" window, with nine checkboxes. Check the appropriate boxes. (To set the permissions for an executable CGI script, check the following 7 boxes: Read, Write, and Execute of Owner, Read and Execute of Group, and Read and Execute of Everyone. This is known as chmod 755.)
  4. Click "Apply".
  5. Close the Info window by clicking on the small red button in the upper-left corner of the window.

27) View your page (the page on the server, not the page on your disk) in a Web browser.

If it is not working, take a deep breath, and start troubleshooting. Try reuploading the script. Try changing the script's permissions to 755 again. (Important: every time you reupload a CGI script, you may need to change its permissions again.) Check your paths.

28) Make sure the HTML on this page validates (using the HTML 5 DocType) with no errors, according to the W3C's online HTML Validator at http://validator.w3.org/. You can easily do this by clicking on your HTML validator button. For more information, see How to Use the W3C HTML and CSS Validators for step-by-step directions.

29) If you have used any CSS, make sure the CSS on this page validates, with no errors, according to the W3C's online CSS Validator at: http://jigsaw.w3.org/css-validator/validator-uri.html. You can easily do this by clicking on your CSS validator button. See the CSS section of How to Use the W3C HTML and CSS Validators for step-by-step directions.

30) If there are any errors, fix them, re-upload the page, and validate it again.

31) You may wish to customize the exercise 8 page after you get everything working.

32) Make sure your home page has a working link to all your completed exercises, including this exercise, and that the HTML and CSS on your home page validates.

33) Submit the feedback form. To receive full credit for this exercise you must submit this feedback form before it expires. This exercise is due on 3/23/15. Allowing for a one-day grace period, the form will expire at the end of the day following the due date, which means the form for this exercise will expire at 12:00 AM on 03/25/15.