Cover V10, I02

feb2001.tar


Listing 1 Example CGI Script that runs a whois query

#!/usr/bin/perl

# Get the value of the QUERY_STRING environment variable, which is 
# set by the web server to the value of the query string portion of 
# the URI.
$querystring = $ENV{'QUERY_STRING'};

# Separate the key=val pairs into tokens.  They are delimited by &.
@qs = split (/&/, $querystring);

# Split each of the key=val pairs and save in a hash, keyed by key.
foreach $i (0 .. $#qs)
  {
    # Convert plus to space, and convert %hh to the real value.
    $qs[$i] =~ s/\+/ /g;
    $qs[$i] =~ s/%(..)/pack("c",hex($1))/ge;

    # Now, split along the =.
    ($key, $val) = split (/=/, $qs[$i], 2);

    # Save in hash.
    $param{$key} = $val;
  }

# Get the value of the 'parm' key.
$parm = $param{'parm'};

# Since this CGI script is outputting plain text tell the browser
# to expect plain text.
print "Content-type: text/plain\n\n";

# Run a whois query.
print `/bin/whois $parm`;

# Done!
exit;