OVERVIEWFEEDBACK FORMS, GUESTBOOK & SEARCHIMAGEMAPSREADY TO RUN SCRIPTS & ALL SITE COUNTERS
TROUBLESHOOTING
OVERVIEW
What are CGI scripts?"CGI" stands for "Common Gateway Interface", a fancy name meaning computer programs running on the web server that can be invoked from a www page at the browser. The "bin" part alludes to the binary executables that result from compiled or assembled programs. It is a bit misleading because cgi's can also be Unix shell scripts or interpreted languages like Perl. A typical use for cgi is the processing of online forms. When the user fills in the boxes on the form and hits the SUBMIT button, the cgi program specified in the html will be run at the server, and the information in the boxes become available to the program as parameters. The program, being a program, can then do anything the programmer wanted it to do. "cgiemail", for example, is a canned program written in C that gathers up the contents of the boxes on the form and emails them to a specified destination, then sends a WWW page confirming the action.
Where should I put my CGI scripts?Put your cgi-bin scripts in the WWW subdirectory named cgi-bin. If your domain is named company.com, you would then access your scripts as /cgi-company/
What is the path of date, mail, perl ...?To find the path of the program date, type which date. Do this for any program that you need your cgi-bin script to access. I see lots of perls, which one should I use? They should all be the same. /usr/local/bin/perl should work nicely.
FEEDBACK FORMS AND SIMILAR FORMSCgiemail is a program written in the C language that takes the contents of fill-in boxes on a form and emails them to a specified destination. In addition to the form specification in the .html file, a mail specification in a .txt file is required to format the resulting email message. We provide cgiemail in the cgi-bin directory of each machine. Thus, it would be called with a URI such as /cgi-bin/cgiemail/mail.txt. Details are provided below. While there are a number of subsections below this one, they all work together and are meant to be read from start to finish.
add.htmlIf you've never dealt with HTML forms before, don't worry. They're easy to create and understand. (And if you briefly tried that link and thought, noooooo!!! I don't want to read this!, scroll down a bit. The easy examples are at the bottom. You should not need to follow it at all to understand what will be explained presently.) The form prompts the user for data which is sent to the server as simple key-value pairs. Each <input> tag specifies a record. The key is given by the name attribute, and the value is given by the value attribute. The type attribute tells the browser what kind of data to expect. Now, try looking at the example. Please note that the hidden items are used to transmit critical info to cgiemail. They provide the location of the success file, the name of the person the results should be sent to, and the subject of the form. When making your own forms, you would definitely (please!) change the e-mail address in the "required-to" field, and likely the subject in the "subject" field. The first item tells cgiemail what to show the user after succesfully completing the form. You can, but don't need to, customize this. After that come the items that are actually presented to the user. You'll want to use type=text input items with cgiemail; it's a simple tool. The size=60 tells the browser how big to make the box. The name=something is required in each input tag, otherwise the browser wouldn't know how to send the data to the server. The value="" attribute is correct in most cases, unless you want a default value in the form. Note that if a field begins with required-, cgiemail will require that the user enter a value for this field. This is particularly useful if you want to require a user to submit their e-mail address. When the user presses the Submit button, the data goes to our machine where cgiemail starts doing something with it. What it does is controlled by ...
Mail.txtMake sure that you upload mail.txt in ASCII mode. Failure to upload mail.txt in ASCII mode will generate the message:
Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Now that we have all this data, what do we do with it? Mail it, of course! But for flexibility, cgiemail requires that you create a mail.txt file to show it what to send. (If you didn't want flexibility you'd use a mailto link.) The program will read in this file, perform substitutions, and pass it to the mail system. First, how does cgiemail know where to find this file? Look at the first line in the example form used in the previous section. The bit after the word cgiemail in the action attribute tells cgiemail where to look. When called from zoneit.com, cgiemail does not know what your domain is because it is installed for everyone. So, the first component of this path must be your domain. After that, it goes to your www directory and looks from there. If you have a domain name, we suggest that you explicitly put it in the action attribute, because the behavior is different: cgiemail does know what your domain is if called for your domain. Fred.com might want to put the mail.txt file in his www directory. His form would then start off with <form method=post action="http://www.fred.com/cgi-bin/cgiemail/mail.txt"> BTW, there's nothing magical about the name mail.txt. Feel free to call it mail1.txt, or form1.mail, or what suits you, as long as the form has the correct name for what you uploaded. Here's the mail.txt we used with the form presented earlier. It's pretty simple. Note that the first several lines are mail headers. You probably shouldn't change that part, or the corresponding parts in your form. In particular, there must be a To: header or the mail won't go anywhere! What cgiemail does is simply replace every string that looks like [key] with the value the user typed in to the field with name=key. That's all. You can lay out your form as is best for your users, but lay out your mail.txt as is best for you to read. You can even insert gobs of text to help format the output. Only the [key] parts will be replaced by cgiemail.
How to use cgiemailActually, if you've read the previous two sections you should know enough to use it. We'll summarize here.
Cgiemail was developed at MIT and is copyright 1994, 1995. Formmail.cgi
Formmail is a program written in the Perl language that takes the contents
of
Setting Up the FormMail Script:
The FormMail.pl script does not have to be extensively configured to get
Necessary Form Fields:
There is only one form field that you must have in your form, for
Field: recipient
Description: This form field allows you to specify to whom you wish for your
Syntax: <input type=hidden name="recipient" value="email@your.host.xxx"> -----------------------------------------------------------------------------
Optional Form Fields: Field: subject Description: The subject field will allow you to specify the subject that you wish to appear in the e-mail that is sent to you after this form has been filled out. If you do not have this option turned on, then the script will default to a message subject: WWW Form Submission Syntax:
If you wish to choose what the subject is: To allow the user to choose a subject: <input type=text name="subject"> ----------------------------------------------------------------------------- Field: email Description: This form field will allow the user to specify their return e-mail address. If you want to be able to return e-mail to your user, I strongly suggest that you include this form field and allow them to fill it in. This will be put into the From: field of the message you receive. Syntax: <input type=text name="email"> ----------------------------------------------------------------------------- Field: realname Description: The realname form field will allow the user to input their real name. This field is useful for identification purposes and will also be put into the From: line of your message header. Syntax: <input type=text name="realname"> ----------------------------------------------------------------------------- Field: redirect Description: If you wish to redirect the user to a different URL, rather than having them see the default response to the fill-out form, you can use this hidden variable to send them to a pre-made HTML page. Syntax: To choose the URL they will end up at: <input type=hidden name="redirect" value="http://your.address/to/file.html"> To allow them to specify a URL they wish to travel to once the form is filled out: <input type=text name="redirect"> ----------------------------------------------------------------------------- Field: required Version Added: 1.3 Description: You can now require for certain fields in your form to be filled in before the user can successfully submit the form. Simply place all field names that you want to be mandatory into this field. If the required fields are not filled in, the user will be notified of what they need to fill in, and a link back to the form they just submitted will be provided. Syntax: If you want to require that they fill in the email and phone fields in your form, so that you can reach them once you have received the mail, use a syntax like:
<input type=hidden name="required" value="email,phone"> Field: env_report Version Added: 1.3 Description: Allows you to have Environment variables included in the e-mail message you receive after a user has filled out your form. Useful if you wish to know what browser they were using, what domain they were coming from or any other attributes associated with environment variables. The following is a short list of valid environment variables that might be useful:
There are others, but these are a few of the most useful. Syntax: If you wanted to find the remote host and browser sending the request, you would put the following into your form: <input type=hidden name="env_report" value="REMOTE_HOST,HTTP_USER_AGENT"> ----------------------------------------------------------------------------- Field: sort Version Added: 1.4 Description: This field allows you to choose the order in which you wish for your variables to appear in the e-mail that FormMail generates. You can choose to have the field sorted alphabetically or specify a set order in which you want the fields to appear in your mail message. By leaving this field out, the order will simply default to the order in which the browsers sends the information to the script (which isn't always the exact same order they appeared in the form.) When sorting by a set order of fields, you should include the phrase "order:" as the first part of your value for the sort field, and then follow that with the field names you want to be listed in the e-mail message, separated by commas. Syntax: To sort alphabetically: <input type=hidden name="sort" value="alphabetic"> To sort by a set field order: <input type=hidden name="sort" value="order:name1,name2,etc..."> ----------------------------------------------------------------------------- Field: print_config Version Added: 1.5 Description: print_config allows you to specify which of the config variables you would like to have printed in your e-mail message. By deafult, no config fields are printed to your e-mail. This is because the important form fields, like email, subject, etc... are included in the header of the message. However some users have asked for this option so they can have these fields printed in the body of the message. The config fields that you wish to have printed should be in the value attribute of your input tag separated by commas. Syntax: If you want to print the email and subject fields in the body of your message, you would place the following form tag: <input type=hidden name="print_config" value="email,subject"> ---------------------------------------------------------------------------- Field: title Version Added: 1.3 Description: This form field allows you to specify the title and header that will appear on the resulting page if you do not specify a redirect URL. Syntax: If you wanted a title of 'Feedback Form Results': <input type=hidden name="title" value="Feedback Form Results"> ----------------------------------------------------------------------------- Field: return_link_url Version Added: 1.3 Description: This field allows you to specify a URL that will appear, as return_link_title, on the following report page. This field will not be used if you have the redirect field set, but it is useful if you allow the user to receive the report on the following page, but want to offer them a way to get back to your main page. Syntax: <input type=hidden name="return_link_url" value="http://your.host.xxx/main.html"> ----------------------------------------------------------------------------- Field: return_link_title Version Added: 1.3 Description: This is the title that will be used to link the user back to the page you specify with return_link_url. The two fields will be shown on the resulting form page as: <a href="return_link_url">return_link_title Syntax: <input type=hidden name="return_link_title" value="Back to Main Page"> ----------------------------------------------------------------------------- Field: background Version Added: 1.3 Description: This form field allow you to specify a background image that will appear if you do not have the redirect field set. This image will appear as the background to the form results page. Syntax: <input type=hidden name="background" value="http://your.host.xxx/image.gif"> ----------------------------------------------------------------------------- Field: bgcolor Version Added: 1.3 Description: This form field allow you to specify a bgcolor for the form results page in much the way you specify a background image. This field should not be set if the redirect field is. Syntax: For a background color of White: <input type=hidden name="bgcolor" value="#FFFFFF"> ----------------------------------------------------------------------------- Field: text_color Version Added: 1.3 Description: This field works in the same way as bgcolor, except that it will change the color of your text. Syntax: For a text color of Black: <input type=hidden name="text_color" value="#000000"> ----------------------------------------------------------------------------- Field: link_color Version Added: 1.3 Description: Changes the color of links on the resulting page. Works in the same way as text_color. Should not be defined if redirect is. Syntax: For a link color of Red: <input type=hidden name="link_color" value="#FF0000"> ----------------------------------------------------------------------------- Field: vlink_color Version Added: 1.3 Description: Changes the color of visited links on the resulting page. Works exactly the same as link_color. Should not be set if redirect is. Syntax: For a visited link color of Blue: <input type=hidden name="vlink_color" value="#0000FF"> ----------------------------------------------------------------------------- Field: alink_color Version Added: 1.4 Description: Changes the color of active links on the resulting page. Works exactly the same as link_color. Should not be set if redirect is. Syntax: For a visited link color of Blue: <input type=hidden name="alink_color" value="#0000FF"> -----------------------------------------------------------------------------
How to use Guestbook
If you have an account that includes a preconfigured guestbook, You simply
need to use the following URL to access it.
http://yourdomain.com/Guestbook/guestbook.html
How to use Search.cgi
Search will look at all your html pages for words you enter, and return all
pages on a list with links. This program is completly configured and ready
to run, just access it with the following URL
http://yourdomain.com/cgi-yourdomain/search.cgi
IMAGEMAPS'Imagemap' refers to an interaction between a user's browser and the WWW server which allows clicking on an image to select hyperlinks. (Other implementations have a seperate /cgi-bin/imagemap program. Our server handles them internally. Use the reference style shown below, not one like /cgi-bin/imagemap/mymap.map.) Each designated portion of the image may select different links. Images that are to be used as imagemaps must be designated as "ISMAP". A companion .map file specifies the coordinates of the portions of the image that are hyperlinks, and the URL or local reference of the link. The following HTML:
<A HREF="name-of-map-spec-file.map"> tell the browser that "name-of-image.gif" is to be displayed and used as an imagemap. The "name-of-map-spec-file.map" file contains the coordinates of the clickable areas in the image and specify the hyperlinks associated with each clickable area. The map specification file MUST have extension ".map". While this example assumes the file is located in your www directory, it may be located anywhere under the www directory. In such a case, the path from the www directory must be specified. If you put it in /home/your-id/www/map-directory, then use <A HREF="../map-directory/name-of-map-spec-file.map"> Please use the NCSA format for your .map file. A file named imagemap.conf does NOT have to edited when using our imagemap program. That complication has been removed from our version of imagemap. Here is a sample file named fo-abc.map:
default http://oceania.org/weblinks.html poly http://oceania.org/weblinks.html#A 23,14 44,2 66,14 66,39 45,51 23,39 poly http://oceania.org/weblinks.html#A 67,14 88,2 110,14 110,39 89,51 67,39 poly http://oceania.org/weblinks.html#C 111,14 132,2 154,14 154,39 133,51 111,39 Note that the URL's are full URLs. You can't use relative URLs. The number pairs specify the X-Y coordinates in pixels of the points of the three hexagons that are the clickable areas in fo-abc.map. Clicks outside of the areas specified get the default link.
COMPLETE WEB SITE COUNTERS
Site Counter using SSI
Very simple to use, first the page which you would like to count must have
the extension .shtml or .sht rather than .htm or .html
WWWBoardThe World Wide web Board is already to run, you can call it from a page with the following URL: http://yourdomain.com/bbs/
Secure and Unsecure Orderform calls
A secured server (SSL) dir must be requested - it is not yet setup.
When we setup your secured dir we provide a sample secure and unsecure order
form. These can be easily modified or changed to suite your individual or
business needs. When calling a non secure order form there is nothing different,
you would use your standard URL:
http://yourdomain.com/order.html assuming the order form
is in your main directory. To call a form or a document as secure you will
be using Zone Internet registration key. What this means is the page must
be called thru our secure server, so the URL that points to this must be
as follows: https://safe-order.com/domainname/filenamehere.
You will have to keep both secure and non-secure order forms on your domain,
you will find that the calls for each are different because the directory
hierchy changes for the secure form, graphics and cgi scripts will have to
be called in two different fashions for each form. If you follow the samples
supplied for formaction and redirection, you should have no problems using
this successfully.
Password Protected Web directory
Placed in your WWW directory, you will find a sub directory called secure.
This has been setup with the password file in place, and it cannot be entered
from the web without first being prompted for a login and password.
Database and search engineCreates pages on the fly by category from a simple texted based data file. Features include variable number of input fields, configurable printouts and completely writable from a web page. A matching search engine, allows the database to be searched from a web page.
TROUBLESHOOTING(This section will grow as we remember to add what we keep doing every day anyway.) "When I activate my CGI program, I get back a page that says 'Server Misconfigured'". Log on and go to your www/cgi-bin directory. Try running the program manually to see what errors you get. Remember that when a CGI program produces error output, that output is discarded and you get the non-specific page you saw. To check on it, you'll have to run it yourself. If you get something like
bash: ./search.pl: No such file or directory and you know you typed the name correctly, it's almost certain you uploaded the script from your PC or Macintosh in binary mode. Perl scripts are ASCII text and must be transferred in ASCII mode. (So are shell scripts and any other kind of script that starts with '#!' on the first line.) You know it's this if ./search.pl doesn't work and perl search.pl does. Assuming you don't have any legitimate carriage returns in the program (doubtful), this will fix it:
Then there's this response:
Literal @zoneit now requires backslash at ./bigones line 16, within string Many scripts that you'll find widely distributed are still written for Perl, version 4. Our /usr/bin/perl is version 5, which is 99.9% compatible with version 4, along with many improvements. You've found the other 0.1%. In Perl 4, you could get away with a statement like
$mailaddress = "joe@schmoe.com"; because Perl didn't think the '@' sign was special in a string. Perl 5 does, so you need to escape it, like so:
$mailaddres = "joe\@schmoe.com"; You can't just change all the '@' signs to '\@', only the ones in strings. To speed your search, however, Perl gives you the line number of the problem line(s) in its error message. (To check for them without accidentally running the program, if that would be a problem, use perl -c script.) Fix them, and see if it works. Tom Christianson (well-known in the Perl world) has written The Idiot's Guide to Solving Perl CGI problems (http://www.perl.com/perl/faq/idiots-guide.html) for the comp.lang.perl.misc newsgroup. Not everything in there is correct for the graycat setup, but it's useful. This page is maintained by Zone Internet |