ADMCITY MANUAL

CHAPTER FOUR - Cgi-bin scripts

Cgi-bin scripts: How do I use them?

4.1) OVERVIEW

4.2) FEEDBACK FORMS, GUESTBOOK & SEARCH

4.3) READY TO RUN SCRIPTS & ALL SITE COUNTERS

4.1) OVERVIEW

4.1.1) Where should I put cgi-bin scripts?

Put your cgi-bin scripts in the WWW subdirectory named cgi-bin.

If your domain is named toyota.com, you would then access your scripts as /cgi-toyota/

4.1.2) 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.

Common paths

4.1.3) Charges

If you prefer, we will install most ready-made scripts that you obtain for a £50.00 charge. More complicated scripts will be installed based on £75.00/hour.

4.2) FEEDBACK FORMS AND SIMILAR FORMS

Cgiemail 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.

4.2.1) add.html

If 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 successfully 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 ...

4.2.2) Mail.txt

Make 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.

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.

4.2.3) How to use Formmail.cgi

Note: formmail.cgi is already in your cgi directory, it just needs to be called correctly from your html page.

In its simplest use, formmail.cgi is used to process and deliver forms from your site to your e-mail address.

Call it as such:

<FORM METHOD="POST" ACTION="/cgi-domain/formmail.cgi">

NOTE: substitute domain with your domain name, but do not use extension..

example using www.toyota.com=

<FORM METHOD="POST" ACTION="/cgi-toyota/formmail.cgi">

You can also call it:

<FORM METHOD="POST" ACTION="http://www.domain.com/cgi-domain/formmail.cgi">

Don't forget to include your e-mail address:

Here's one way:

<INPUT type="hidden" NAME="recipient" VALUE="e-mail@address.com">

4.2.4) How to use Guestbook

Your account includes a preconfigured guestbook, You simply need to use the following URL to access it. **PLEASE make backup copies prior to making any alterations to the script or .html page**

http://yourdomain.com/Guestbook/guestbook.html

4.2.5) 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 completely configured and ready to run, just access it with the following URL:

http://yourdomain.com/cgi-yourdomain/search.cgi

4.2.6) How to use your free-for-all links page
Your site has a "free-for-all links" page ready-to-go.
**PLEASE make backup copies prior to making any alterations to the script or .html page**
It can be called or browsed at:

http://www.yourdomain.com/links/links.htm


4.3) COMPLETE WEB SITE COUNTERS

4.3.1)Text 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 .. Put the following on the page where you want the count file to appear.
<!--#exec cgi="/cgi-yourdomain/counters/counter.cgi"-->

For Example if your domain is fred.com the call would be
<!--#exec cgi="/cgi-fred/counters/counter.cgi"-->

That 's all there is to it. This will create a count file for each page the call is placed on, it will just show up as a number when looking at it from a web page.

Graphical Counter Option (does not need to be on a .shtml or .sht page)

If you prefer a graphical counter, here's one that you can use by placing the following line in your page:

<IMG SRC="/cgi-bin/nph-count?width=5&link=http://yourdomain/yourpage">

This is what the counter looks like :

<IMG SRC="/cgi-bin/nph-count?width=5&amp;link=http://www.admcity.com/man4.shtml">

4.3.2) WWWBoard (Message Board)

The World Wide Web Board is already to run, you can call it from a page with the following URL: http://yourdomain.com/bbs/

**PLEASE make backup copies prior to making any alterations to the script or .html page**

4.3.3) Accessing the Secure Server

Assume your domain is example.com. (Replace machine with the name of the system we have you on this can be found on the FAQ page in your domain http://yourdomain.com/faq.html)

Use the following url to access your pages via the secure server.

https://machine.safe-order.net/example/anypage.html 


The above page would be accessed from the normal web server as:

http://example.com/anypage.html 


Your cgi-bin dir is:

https://machine.safe-order.net/example/cgi-bin/ 


*SPECIAL NOTE FOR FORMMAIL.CGI*

If you are using formmail.cgi thru the secure server, you MUST use the following url:

https://machine.safe-order.net/cgi-bin/formmail.cgi



Here's an example:

<FORM METHOD=POST ACTION="https://machine.safe-order.net/cgi-bin/formmail.cgi">

<input type=hidden name="recipient" value="sales@yourdomain.com">

<input type=hidden name="subject" value="Order">

<input type=hidden name="return_link_url" value="http://yourdomain.com/>

<input type=hidden name="return_link_title" value="Back to Main Page">



The last two lines allow a link back to your main page - thus they get a report

of what they ordered and a link. Replace yourdomain with your userid



4.3.4) 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.
You will need a brief knowledge of Telnet in order to build the login file for this directory, the steps are below.

  1. Login to your domain via telnet.
  2. At prompt type pass, this is a script we created to make adding to the file easy
  3. Follow the prompts. enter login and then passwd desired twice.
  4. You may enter as many logins as you like, you may also go back and add when ever you wish.
  5. Just hit enter, when prompted for login to escape program.

4.3.5) Database and search engine

The database program is located in your www/database directory and is
composed of 5 essential files: database.cfg, database, post.htm,
search.htm and output.html database.cfg - this is the configuration file for your database.

Example.(just a simple list)
Name
Address
City
State
You may have as many as you like listed for these fields
These become your input fields and they must be associated with the input statements on your posting page for each of the above, you should have a matching input statement that looks like the following on your post page: <input = text name = "name" size = "25" > <input = text name = name = "address" size = "25"> Database - This is nothing more than the actual data being stored after it is posted from your posting page. Post.htm - This page is used to write to the database from a webpage. You should have an input statement for each field used in the database .cfg file. You may also use Query boxes, + Radio buttons. The formation for this page should be as follows: <form method post action = "http://your domain.com/cgi-bin/database.cgi"> For better understanding look at the sample files in the database directory on you domain. Email - You may activate this feature by adding the following.
<input type="hidden" name="email" value="youremailaddress"> When active each time someone posts to the database you will receive a email of the content
Search.htm - this is the page that reads the actual database file based on the criteria you would like to search.
The form action for this page should be as follows: <form method = post action = "http://your domain.com/cgi-bin/dsearch.cgi"> use the preconfigured example as a template that is in the database directory of your domain. There are several ways to setup searches for your database. 1. Click on names. This will allow a nice interface for your customer or client, that eliminates the need for a submit button The items before the ? mark call the script, this should always be the same. The first item after the ? mark is the word you are using for the search, then you will notice a & sign the listing after the & sign is the location of the database file (it's directory), i.e, domainname/database/ 2. The other way to do a search page is through checkboxes, radio button, query lists, and straight type in text. You may search by as many different mediums as you like. Look at http://winedine.com/nycsrch.htm For an example of different criteria being used, there are only two variable names you will use in your search page. Keywords and Keywords-predefined. a. Keywords would be used for a single text entry search.
b. Keywords-predefined is used for multiple inputs where you are searching several words as our example with winedine.
Output.html

Return To Menu