|
|
PART 5 - CGI SCRIPTS
What's CGI stand for? What's CGI stand for? We don't provide free support for CGI scripts that we did not install. So, if you are not already familiar with CGI scripting, you may want to read a book on the subject or refer to our Tips and Tutorials section. Where to Put CGI-Bin Scripts Paths to Perl and Other Programs Perl5.003: /usr/bin/perl --OR-- /usr/local/bin/perl Perl5.004: /usr/bin/perl5.004 (Full 5.004 lib support not currently available) Date: /bin/date Java:/usr/bin/java Python:/usr/bin/python Domain path: /www/yourdomain (puts you in your Web directory) CGI-bin path: /www/yourdomain/cgi-bin (puts you in your cgi-bin) Setting Permissions NOTE: Every time you re-upload and overwrite the existing file, its file permissions stay the same. Permissions Defined Read permission allows you to view the contents of a file. For a directory, having read permission allows you to list the directory's contents. Write permission allows you to modify the contents of the file. For a directory, write permission allows you to alter the contents of the directory (i.e., to add or delete files). Execute permission allows you to run the file if it is an executable program or script. Execute permission is irrelevant for nonexecutable files. To List or Change File/Directory Permissions You can also use Telnet or FTP.
Cgiwrap - Secure Server CGI Wrapper
You can call cgiwrap explicitly with the following call, which does the same thing as the above call:
This assumes script.cgi is in your cgi-bin. You can also use cgiwrapd in place of cgiwrap to get extra debugging information if there is a problem. For nph-style scripts, use nph-cgiwrap or nph-cgiwrapd instead. Preconfigured, Preinstalled Scripts Bulletin Boards (Forums) Once you have created your forum, access it by going to http://www.yourdomain.com/forums/name_of_your_forum These forums are completely configurable. If you need to re-install this script, login to your Web Control Panel, select Free Scripts, then select Multi User Forums. Cgiemail FormCgiemail is a form processing script, totally different from Formmail. It is a program written in the C language that takes the contents of fill-in boxes on a form and e-mails them to a specified location. In addition to the form specification in the .html file, a mail specification in a .txt file is required to format the resulting e-mail message. We provide the cgiemail in the cgi-bin directory of your server. You need to have an action in your order.htm file to call it. It should look like this:
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. order.htm 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 may want to 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. This form is customizable. Next are the items that are actually presented to the user. You'll want to use type=text input items with cgiemail; it's a simple method. 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 server where cgiemail starts processing it. What it does is controlled by the order.txt file discussed below. order.txt Make sure that you upload order.txt in ASCII mode. Failure to upload order.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." There is already an example order.txt document in the forms directory in your www directory. By the way, there's nothing magical about the name "order.txt." Feel free to call it "mail1.txt" or "form1.mail," or whatever suits you, as long as the form has the correct name for what you uploaded. 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 into the field as name=key. That's all. You can lay out your form as is best for your users, but lay out your order.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. Cgiemail does not report environmental variables like Formmail does, but other than that, it is an excellent program, allowing you more flexibility in the way your data can be returned by the form. Click and Go RedirectionThe clickgo.cgi script is preinstalled in your cgi-bin directory. To utilize this script, you will need to add syntax like the following to your HTML page: <FORM METHOD=POST ACTION="http://www.yourdomain.com/cgi-bin/clickgo.cgi"> Replace "yourdomain.com" with your domain address. The only other things you will modify are the option values. The values in " " are the hyperlink addresses of where that option will take your visitor. You can add as many options as you like. Below is what the script looks like after it is set up: This script is one from Matt's Script Archive which we have installed and preconfigured for your domain. Formmail is a generic WWW form to e-mail gateway, which will parse the results of any form and send them to the specified user. This script has many formatting and operational options, most of which can be specified through the form, meaning you don't need any programming knowledge or multiple scripts for multiple forms. This also makes Formmail the perfect system-wide solution for allowing users form-based user feedback capabilities without the risks inherent in granting full CGI access. There is only one form field that you must have in your form for Formmail to work correctly. This is the recipient field. Other hidden configuration fields can also be used to enhance the operation of Formmail on your site. The action of your form needs to refer to the location of the script, and the method used must be "POST", expressed in capital letters. Here's an example of the form fields to put in your form: <FORM METHOD=POST ACTION="http://yourdomain.com/cgi-bin/formmail.cgi"> The following are descriptions and proper syntax for fields you can use with Formmail. Recipient Field Syntax: <input type=hidden name="recipient" value="email@yourdomain.com"> Subject Field Syntax: If you wish to choose what the subject is: <input type=hidden name="subject" value="Your Subject"> To allow the user to choose a subject: <input type=text name="subject"> E-mail Field Syntax: <input type=text name="email"> Realname Field Syntax: <input type=text name="realname"> Redirect Field Syntax: To choose the URL they will end up at: <input type=hidden name="redirect" value="http://yourdomain.com/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"> Required Field Syntax: To require that they fill in the e-mail and phone fields in your form: <input type=hidden name="required" value="email,phone"> Env_report Field
REMOTE_ADDRSends the IP address of the remote host HTTP_USER_AGENTIdentifies the browser the client is using NOTE: In our case, REMOTE_HOST and REMOTE_ADDR are the same, since our servers do not perform the reverse DNS lookup needed to generate the true REMOTE_HOST string. Syntax: To determine all the above variables: <input type=hidden name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT"> Sort Field Syntax: To sort alphabetically: <input type=hidden name="sort" value="alphabetic"> To sort into a specific order: <input type=hidden name="sort" value="order:name1,name2,etc..."> Print_config Field Print_blank_fields Field Syntax: <input type=hidden name="print_blank_fields" value="1"> Title Field Syntax: To specify a title of "Feedback Form Results", you would include the following form tag: <input type=hidden name="title" value="Feedback Form Results"> Return_link_url Field Syntax: <input type=hidden name="return_link_url" value="http://yourdomain.com/index.htm"> Return_link_title Back to Main Page Syntax: <input type=hidden name="return_link_title" value="Back to Main Page"> Free-For-All Links Page If you need to re-install this script, login to your Web Control Panel, select Free Scripts, then select Pro Links page. Graphical Page CountersThere are three different types of page counters you can place on your pages. The first is a no-frills graphical counter which looks like this: To use this one, put the following tag somewhere on your page, but change the yourpage.htm to the address of the actual page you are putting this counter on. The width=5 part refers to the number of digits in your counter. This counter is not as reliable as the others mentioned. <img src="/cgi-bin/nph-count?width=5&link=http://yourdomain/yourpage.htm">The second is the Virtual Publisher Counter (Not available on accounts established after June 1999). It is another graphical counter, but it will give you all kinds of stats such as time and date of visits, and domains that your visitors came from, etc. It looks like this: To put this counter on your page, insert the following tag somewhere. In your code, the tag should occupy one line, with no spaces in between any of the characters. <img src="http://yourdomain.com/cgi-bin/counter/counter.cgi?fnam= Where you see fnam=testcount, replace "testcount" with the name of the page you want to put the counter on. The viz=yes part tells the counter script whether your counter should be invisible or not. If you want the counter to be visible, leave it as "yes." If you want it to be invisible, change it to "no." The "isinv=yes" lets you choose whether you want the counter to be inverted (white against black background) or not. If you want the number to be black against a white background, change it to isinv=no. Another great thing about this one is that you can access the log files for each page you have the counter on, and also reset the count to any number you wish. To see the instruction page, go to:
Please be aware that a count file will not be created until a page is accessed for the first time. Text-Based Page Counter (uses SSI)Finally, the third and simplest kind of page counter is a text-based counter. It uses SSI, so the page you are putting it on must have the .sht, .shtm, or .shtml extension. You may assign the counter's text and size attributes. The tag looks like this:
Replace "/your_cgi-bin" with the relative path to your cgi-bin from the page where you place the counter. After you've placed the counter on your page, look at it with your browser. If you don't see the counter the first time, hit reload or refresh. Then you should see the number 1. If you want to change the page count, FTP to your site, and look in the counters directory in your cgi-bin. There will be a file there with the name of the page you placed this counter on. Edit this file - change the starting number and re-upload the file (in ASCII format). Once the file is re-uploaded, hit reload or refresh to reset the number. PostcardsTo install this script, go to your Web Control Panel (http://www.yourdomain.com/cgi-bin/plusmail), select Free Scripts, then select Postcards. Once the script is installed (wait 15 minutes before trying to access the script), you can access it by going to http://www.yourdomain.com/cards. Quiz Master To install this script, go to your Web Control Panel (http://www.yourdomain.com/cgi-bin/plusmail), select Free Scripts, then select Quiz Master. Once the script is installed (wait 15 minutes before trying to access the script), you can access it by going to http://www.yourdomain.com/quiz. Random Text Generator This script is preconfigured for your server. There is a directory in your www directory called "random." Inside that directory is a file called "random.txt." Just download this file to your hard drive, and edit it with any random text you would like placed in an HTML document. Remember to keep the %% separator between quotes. You can use any HTML formatting tags you want, including The script uses Server-Side Includes (SSI), so the page you want to use random text on must have the .sht, .shtm, or .shtml extension. On your page, just put this tag wherever you want the random text to appear:
That's all there is to it! Secure Server Order FormsNormally, any text (such as your credit card number) sent from your browser to the web server is sent as plain text. This means that a hacker could potentially intercept (however unlikely) the information sent from your browser and read it. By using the secure server, the information is encrypted before it is sent from your browser. It would be practically impossible for anyone to decrypt it without knowing the key. Please use the secure server only when necessary, as when requesting sensitive information from your visitors. The domains hosted by us are housed on any number of computers, and each of them has a different machine name. The machine name you are to use for your secure order access calls was included in your Welcome e-mail from us. Your Web Control Panel also lists your machine name. Each server has its own safe-order site, and although you will be putting your form on your own domain, it must be called through the safe-order server in order for the form to be secure. To do this, create your form as usual and put it somewhere in your www directory. You can put your form anywhere you want, but for this example, let's assume the normal URL for your form can be accessed from a browser with this URL:
To call the form through the secure-order server, you need to use the following URL (even though your form resides on your own domain space):
This is the URL you would use as the <a href> link to your form. Don't forget the "s" in "https." Your CGI-bin directory is:
Special Instructions for Using formmail.cgi with the Secure Server
Here's an example of how the first parts of your form might look (replace "machinename" with your machine's name): <FORM METHOD=POST ACTION="https://machinename.safe-order.net/cgi-bin/formmail.cgi"> It is still important that you call your order page through a secure URL in order for it to work properly. For example: https://machinename.safe-order.net/yourdomain/order.htm. PageSearch (On older accounts) Perlfect Search (Our former Power Search) On older accounts, you may already have this installed. Follow the instructions at http://www.yourdomain.com/search_instructions.htm for configuration options. SFE PageSearch Simple Site Search (On older accounts)
Now you can access search.cgi with the following URL: http://yourdomain.com/cgi-bin/search.cgi. To add the Simple Site Search to an existing page, add the following source code:
<b>Search:</b> <INPUT TYPE="text" size="25" NAME="keywords" MAXLENGTH="80"> <INPUT TYPE="SUBMIT" VALUE="Search"> </FORM> There is a configuration file called search_define.pl which accompanies search.cgi and sets up the variables for it. You can customize which files you wish to exclude from searches and also the cosmetics of the search and results pages. That's An Order Shopping Cart
VisitorBook Pro Guestbooks Vote/Survey Whois Script To add the whois script to an existing page, add the following source code:
Search for domain name; NIC handle; host IP; or lastname, firstname: <input type="text" name="query"> <input type="submit" value="Whois"></form> Permissions on Preinstalled Scripts
How to Test Your CGI Scripts Using Telnet At the shell prompt, change to the directory where your script resides. At the prompt, type "perl script_name" (Perl being the language interpreter in this case) or "script_name". For example, if the script name is links.pl, you would type "perl links.pl" or "links.pl". After you have located the problem, you can edit the script from the shell prompt by using PICO. Troubleshooting CGI-Bin Problems Also, check out our Online FAQ on CGI-Scripts and Programming Langauges. When I activate my CGI program, I get back a page that says, "Internal Server Error. The server encountered an internal error or misconfiguration and was unable to complete your request." I am being told, "File Not Found," or "No Such File or Directory." When I test my Perl script in local mode (by Telnet), I receive the following error: "Literal @domain now requires backslash at myscript.pl line 3, within string. Execution of myscript.pl aborted due to compilation errors." I am getting the message, "POST not implemented." It's saying I don't have permission to access / Notice Consider visiting our Technical Reference section for books on cgi, and other languages. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Copyright © 1998-2004 Tuffy Enterprizes. All Rights Reserved. Copyright Notice | Policies & Guidelines | Privacy Statement | Contact |