ACCC Home Page ACADEMIC COMPUTING and COMMUNICATIONS CENTER
Accounts / Passwords Email Labs / Classrooms Telecom Network Security Software Computing and Network Services Education / Teaching Getting Help
 
CGI Programming at UIC
0 Contents 1 Introduction 2 Background 3 Codewrap 4 Perlwrap
5 Perl 6 PHP Examples 7 Perl Examples A1 Related Links  

4. Perlwrap
How to run (perl) scripts

 

In this section, I concentrate just on how to run a perl script in the ACCC environment. Reasons why you want to do things a certain way, or how they work under the covers, is in another section.

 
   
 
     
Basics
 

OK, so you want to go for it. It's as simple as:

  • Make a perl script
  • Put the perl script in the right directory
  • Set the file permissions
  • Figure out the URL and point your browser
You can, of course, just use perl to exec some other executable. Your choice. You can definitely shoot yourself in the foot if you want to; we're just trying to make sure you can't do it easily by accident.
 
     
Directories and URLs
 

The mechanics are fairly simple. You'll need to create a directory, and set file permissions thusly:

    cd
    mkdir cgi-bin
    chmod u+rx cgi-bin
Also, be sure your home directory is publically executable:
   chmod a+x ~
You only need do all that once. Now you need to create a CGI script. Here's a simple example:
#!/usr/local/bin/perl

print <<EOF;
Content-type: text/plain

   Hi!  This is my first CGI!
EOF
Just put this into a file called hi.pl in your cgi-bin directory. (I've not explained perl here. If this script does not make sense to you, you will have to learn some perl.) Either copy this by cut-and-paste, or just use these commands:
    cd ~/cgi-bin
    cp /usr/local/lib/www/hi.pl  .
    chmod u+rx hi.pl
That's it. Note that however you make your CGI scripts, you need to give execute permission to the usr. Unlike normal html files, the CGI scripts do not have to have public read permissions. (In fact, I recommend against public read permission. You want the web server to execute your script, but you generally don't want the public crawling through your code, looking for vulnerabilities.)

Once your script is set up, all you have to do is run it. In the above case, if your netid happened to be adabyron, you would use the following url:

    http://www2.uic.edu/htbin/perlwrap/~adabyron/hi.pl
Obviously, if you were on tigger, you'd use www.uic.edu instead of www2.uic.edu. Everybody uses htbin/perlwrap/, and you don't include the cgi-bin directory, in the same sense that public_html is not included for regular html files.
 
     
Authenticated Scripts with Bluestem
 

Anyone at UIC could connect to the above example anonymously. Suppose you wanted to force the user to authenticate, to give you his/her netid, which your script could then process or record. Of course, this is done safely, so that the user's password is never compromised.

You can have perlwrap invoke the Bluestem system quite easily. In fact, all you need do is change the url. And, you probably want to modify your script to deal with the authenticated netid. Here's an example script:

#!/usr/local/bin/perl

print <<EOF;
Content-type: text/plain

   Hi, $ENV{REMOTE_USER}!  This is my second CGI!
EOF
This script is located in /usr/local/lib/www/backatcha.pl. Copy it to your own cgi-bin directory, set the file permissions, and try out this url:
https://www2.uic.edu/htbin/perlwrap-auth/~adabyron/backatcha.pl
Note:
  1. You must use https, rather than http.
  2. You must use perlwrap-auth, not perlwrap.
  3. The authenticated netid is placed in the REMOTE_USER environment variable.
  4. Use your netid instead of adabyron.
 
     
Debugging
 

Debugging a CGI script is normally painful. Much worse than debugging a normal program, because it is hard to make the error messages come out in a place you can read them. In this regard, using perlwrap has a big advantage -- a debug mode.

Do everything normally, but instead of using perlwrap in your URL, use perlwrap-d. Try it, you'll get all sorts of information, including spooling of STDOUT. You can also use perlwrap-auth-d instead of perlwrap-auth.

 
 

CGI Previous: 3 Codewrap Next: 5 Perl


2006-9-29  wwwtech@uic.edu
UIC Home Page Search UIC Pages Contact UIC