CGI Scripting
CGI Scripting
We currently run Perl 5.004 and 5.6.1 for CGI scripting. We update it frequently, but anything that works under Perl 5.004 or 5.6.1 should work under any other version of Perl 5.
Wrapper CGI scripts let us give you the ability to run your own CGI scripts without compromising our security. There are few, if any limitations imposed by such wrappers (i.e. most of your scripts will work). For working examples look at http://www.he.net/faq/tutorials
CGI scripts are a way of using programs to both generate web pages dynamically and process user input. You will need to learn a little about how to program in a Unix environment either in C or a script language like Perl.
You can call a program written in C from a CGI script. To compile the code on our servers, you will need to log onto the server using ssh and use the compiler GCC (GNU project C and C++ Compiler v2.4).
A minor note, just so that you understand the conditions under which we support development: We provide the environment so that you can develop script and programs, however you are completely responsible for your development efforts.
In general, when you are working on modifying an example program, which is now failing but worked when you started, go back to the example exactly, copy it, and then modify it slowly until it stops working, then you will know what you did that caused the bug.
Here are a few things to check:
- Be sure to upload your scripts with your FTP client in text mode. Unix uses LF (linefeeds) to separate lines. If you are using DOS it is important the the CR LF to LF translation be done. If you are using the Mac it is important the the CR to LF translation be done. If you use a Unix-style FTP client, type "ASCII" before you send it. If you are using WS_FTP, be sure to click the ASCII radio button (and don't forget to switch back to binary before you download any executables...).
- Be sure to set your script to executable. If it is a CGI script use "chmod 700". If it is a script run as a server side include use "chmod 755".
- If your script is not a binary executable, check the first line. If your script is a Perl script the first line must be "#!/usr/bin/perl" or "#!/usr/local/bin/perl". If your script is a Bourne shell script you first line must be "#!/bin/sh". If your script is using another shell language check to make sure that the path name specified is valid. Also, make sure an extra blank line didn't get added to the top...
- Try to run your script from the command line. This will completely test your function if it does not rely on parameters or environment variables set by the HTTPD. However, many scripts will produce runtime errors when invoked in this manner. If possible modify your script to fail politely when run at the command line so that you can use this technique to check it. Or if your are a more sophisticated programmer write a test script which sets the necessary environment variables and invokes your main script. Even if your script fails when run at the command line if it is a Perl script running it will check it for syntax errors. If it works from the command line, but fails with an error 500 when you call it, it probably is failing to open a file. Are you trying to reference your home directory with a tilde (~) in Perl? That doesn't work...
- Check the URL or path name you are using. CGI scripts invoked as HREFs should use URLs. If your account was on thor.he.net, System CGI scripts have URLs like:
http://thor.he.net/cgi-bin/systemscript.cgi
User CGI scripts are invoked using slightly different URLs. For example, if your account was rflyer on the server thor.he.net, the URL to invoke your script would be:
http://thor.he.net/cgi-bin/suid/~rflyer/userscript.cgi
If suEXEC is enabled in your account and you have a domain name, you can invoke your script directly. If the domain name for your account was squishypenguin.com, you would invoke your script with the URL:
http://www.squishypenguin.com/cgi-bin/userscript.cgi
You can see if suEXEC is enabled for your account by logging into the billing database at https://admin.he.net New accounts come with this feature already enabled. Select Edit Virtual Host Options and see if the suEXEC box is checked. Should you find that it is not, you can now check the box and click the "Change" button to activate the setting.
If you have an IP Address Only account, you can substitute your IP address for the domain name. Please note that suEXEC will only work with a domain name or IP address. Make sure to substitute the correct script name, server and account name or domain name in the URL and to be sure to put your script in the directory at:
/home/username/cgi-bin
Server side include scripts (the "exec cmd" variety) need to use a full path name to be able to correctly locate your file. For convenience server side includes are usually put in your personal cgi-bin directory. The path name will be something like "/home/username/cgi-bin/userscript".
- When in doubt simplify. Reduce the number of subroutines and the amount of code involved to verify that you can invoke your script at all. Then as you can prove that you are getting to a certain point start adding code back in.
If you get the the error message "suid attempt aborted! Reason: execve failed - Permission denied", even when using our Demo CGI, you need to make your script executable. SSH to your account, cd to the cgi-bin directory, and type:
chmod 700 yourscriptname
This will correctly set the permissions for your script.
You need not ask us to enable CGI scripting for your account as we provide you with your own personal cgi-bin into which you can install and modify scripts at your leisure. You do, however, need to have a Starter Virtual Host or higher account. All we ask is that you follow the guidelines on the user scripting page that can be reached from http://www.he.net/faq/tutorials The key one being respect for server resources.
We do not offer any search scripts. You are welcome to install a CGI script to do this. There are several general database packages for Unix which could be invoked via a CGI script. You can also install your own development tools. You will need to install them into your user directory.
We support user CGI scripting and you can install your own form processing CGI script. NMS FormMail is one of many such scripts we know works with our service.
If you are trying to set up an imagemap and noticed we have no imagemap.conf in /httpd/conf/, be advised that we use a version of imagemap that eliminates the need for users to change a central configuration file. Every user can add their own imagemaps at their discretion without intervention from us. You are not required to email us your imagemap co-ords. You have complete and total control over your imagemap files. For more information on how to do imagemaps on our server see http://www.he.net/faq/tutorials
You can run a WAIS gateway script on your server, provided you obtained the script and installed it yourself.
We have mySQL, an SQL type database, installed. There are many different publicly available CGI front-ends available for it. A mySQL database is included with all accounts. Your database name is the same as your account name. Your mySQL database should be initialized when your account is created, so that you may immediately begin using it.
See our mySQL FAQ or [1]mySQL Mirror Site for more information on using mySQL.
Due to economic and performance considerations, we do not offer support for ASP or JSP.
You are welcome to install your own set of additional modules. When you build modules, use the PREFIX option when generating Makefiles:
perl Makefile.PL PREFIX=/home/mydir/perl
then either set the PERL5LIB environment variable before you run scripts that use the modules/libraries (see the perlrun manpage) or say:
use lib '/home/mydir/perl';