#!/usr/local/bin/perl
# PERL based finger gateway, by Josiah Hamilton
# I know nobody uses finger anymore, with the lookup services and all.
# And I also know that the standard installations of most web servers
# come with a finger gateway script.  And I also know that the people
# who know what finger is will probably just execute it from the shell
# in front of them.  All that in mind, here's a script that calls finger
# and passes it the user's input, then grabs the output and formats it.
# Feel free to use/copy this script.

# set this to your pretty background file

  $background = "/images/backgrnd.jpg";

# set this to your finger command
  $fingercommand = '/usr/bin/finger';

# get the input from the form

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# parse it out into name/value pares (I stole this from Matt Wright)

# split the content length web-environment var on the ampersands
@pairs = split(/&/, $buffer);

   foreach $pair (@pairs) {

# split ampersand delimited pairs on the equals sign

      ($name, $value) = split(/=/, $pair);
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

# strip out spooky shell command type characters
# note: this will chop up an otherwise valid address if it contains these
# characters, but email addresses generally don't have them.

      $value !~ tr/&;|>//;

# build name-value pair hash

      $FORM{$name} = $value;
   }

# start printing the page

    print "Content-type: text/html\n\n";
    print "<HTML><HEAD><TITLE>Finger Results</TITLE></HEAD>";
    print "<BODY background=$background>";

# check to see if the user put something in the blank
# if not, tell the user to go back and do it

     if ($FORM{'address'} eq "") {
       print "<p><p><p><center><h3>You need to put an address in the
blank.";
       print "<p><a href=\"$ENV{'HTTP_REFERER'}\">Go back</a>";
       print " and try again.</h3></center>";

     } else {

# get ready to print the results

       print "<p><center><h3>Results for: $FORM{'address'}</h3></center><p>";

# run finger.  Note: you must verify the path here!!

       $finger = `$fingercommand $FORM{'address'}`;

# turn the end of line characters into html breaks

       read(STDIN, $buffer, $finger);
       $finger =~ s/\n/<BR>/g;

# check to see if finger returned anything, if so, print it

        if ($finger ne "") {
         print "<center><font face = \"arial\" size = 3>$finger</font></center>";
         } else {

# if not, apologize profusely

           print "<center><font face = \"arial\" size = 3>";
           print "Nothing available, sorry.</font></center>";
         }
       }

# finish out the page

     print "<p>";
     print "<CENTER><a href=\"$ENV{'HTTP_REFERER'}\">Return.</a>";
     print "</CENTER></BODY></HTML>" 

