About Sovernet

Introduction

“CGI” stands for “Common Gateway Interface.” CGI is the method by which a web server can obtain data from (or send data to) databases, documents, and other programs, and present that data to viewers via the web. More simply, CGI is programming for the web. A CGI can be written in any programming language. Perl has become a popular choice for CGI programming because it is available for all platforms, and it has many useful tools that are ideal for the web. CGI programs can be used to enhance your web page by counting hits and storing and retrieving guestbook information among other things.

This page assumes a certain level of knowledge and may seem cryptic to the layman. Please note that Sovernet cannot provide support in the writing, maintenance or running of your CGI scripts. We have provided you the space to implement these scripts on your web pages but can not instruct you in the writing of your scripts nor troubleshoot such scripts if they do not work.

Excellent CGI tutorials, geared to beginners can be found at: http://www.cgi101.com/class and The Mining Company HTML & CGI tutorials

Basically what a CGI script written in Perl does is:

  • Read the information filled in the form by the user from the STDIN standard input
  • Decode this information
  • Do what it is suppose to do with this information
  • Return the result back to the user by sending HTML page through the STDOUT standard output

Before doing anything else there are 2 prerequisites:

  • You must know how to code forms in an HTML webpage
  • You must know the basis of Perl programming

Some good references include:

How do I make my CGIs work on Sovernet?

Sovernet’s webhosting service runs Apache on BDSI which is a flavor of UNIX. Read carefully the following, it should solve 95% of your problems:

  • Be careful! UNIX is case sensitive and mypage.html is certainly NOT equivalent to Mypage.html !
  • IMPORTANT! Your scripts MUST use the LF = (0x0A) symbol as end of line unlike DOS/WIN which uses the CR,LF = (0x0D,0x0A) couple. Here is a Windows utility, FixCRLF, that can do the conversion for you.
  • The first line of your script is the location of the Perl Interpreter on the server: #!/usr/bin/perl5
  • The Perl script must have at least EXECUTABLE rights on the server. If you make the script world or group writable it WILL NOT WORK! You should know how to set these rights or permissions using your FTP software.
  • On Sovernet, our customer directories are located at /home/(first letter of the username)/(2nd letter of the username)/(username) You may find you need this info for certain scripts. An example of your home directory if your username is foo: /home/f/o/foo
  • Check the syntax of your script on your local machine before uploading it onto the server: Perl -cw myscript.pl
  • You must put your scripts into the directory named cgi or into one under the directory named cgi. Do not change directory permissions.
    i.e.--->customer home directory on webhost server
    --> /www.example.com
    --> /cgi

If you are asked for the location of your sendmail program or mailprogram, it is: /usr/sbin/sendmail Finally, you need an FTP (file transfer protocol) client to transfer your HTML pages and Perl scripts to the server.

Password Protected Directories

NOTE—If you are using FrontPage Extensions, you should NOT use this utility or use this methodology to set up Password Protected Directories. There are methods within FrontPage for accomplishing this.

  • First create an authorization file called whatever you like and put it in your home directory. Put into it a username followed by a colon then an encrypted password. IE: user foo password bar would look something like foo:xcGfeXysaje We suggest that you put it directly in your home directory and NOT under your web directory.
    I.E. user foo would put the authorization file named userauth into their base directory /home/f/o/foo In this example "f" is the first letter of your username and “o” is the second letter of your username. So if your username were “xmas” the directory you would specify would be: home/x/m/xmas.
    We understand that this is complicated and have a utility that you can place into your CGI directory to help you with the maintenance of authorized users to a restricted directory. See the section below on configuring the access.cgi script
  • Create a file: .htaccess and put it in the directory you want to protect (we'll use foo as an example: /home/f/o/foo/www/foo would have a file in it called .htaccess).
  • In the .htaccess file, type:
    AuthType Basic
    AuthName "Access into the directory foo"
    AuthUserFile /home/f/o/foo/userauth require valid-user
  • What does all this mean?
    • AuthType - This directive selects the type of user authentication for a directory
    • AuthName - This directive sets the name of the authorization realm for a directory. You MUST use quotation marks.
    • AuthUserFile - The AuthUserFile directive sets the name of a text file containing the list of users and passwords for user authentication.
    • Require - This directive selects which authenticated users can access a directory. You can use valid-user which will allow any user found in the AuthUserFile to gain access or you can use use user followed by a list of usernames that are found in the AuthUserFile.

Configuring the access.cgi script

  • First download the access.cgi script. You may either download it as a .zip file or view it as a text file, then save to your hard drive as: access.cgi. Once on your drive, proceed as follows...
  • The only line in the script you will have to worry about editing is the following: $protect{'foo'} = "/home/f/o/foo/userauth";
  • Edit the 'foo' to display whatever the name of the directory is and edit the path and file name to where your user authorization file will reside. We would not recommend that you name it userauth but a name of your own choosing. This will be the name of the file that you put in the .htaccess file.
  • Upload the script to your /cgi/ directory (See above for things to know about while using these scripts).
  • Run the script. The first time you run the script you will need to put in an administrator password. Don’t lose this as you will need it to add and remove users.

Our custom-built solutions, dedicated team, and state-of-the-art network set us apart.

Learn more about: