#!/usr/local/bin/perl
#Calls the system 'finger' function.
#file: finger.pl

$FINGER="/usr/ucb/finger";

print "Content-type: text/html\n\n";

print <<END;
<HTML>
<HEAD>
<TITLE>Finger Gateway</TITLE>
</HEAD>
<BODY bgcolor=#fefece>
END
    ;
if (-e $FINGER)
{
    exec_finger();
}
else 
{
    print "<h1>Cannot find finger on this system.</h1>\n";
}

print <<EOM;
</BODY></HTML>
EOM
    ;

sub exec_finger
{
    $msg = "This is a gateway to \"finger\". Type a user\@host combination in your browser's";
    print <<END;
<H1>Finger Gateway</H1>
<ISINDEX>
$msg
search dialog.<P>
END
    ;

    if (scalar @ARGV) 
    {
        print "<hr size=10 color=#000000><h2 align=center>Requested names</h2>\n";
        print "<table align=center border=1>\n";
        foreach (@ARGV)
	{
	    print "<tr><th valign=top>$_</th><td><PRE>\n";
            if (/^[-.\w\d@]+$/) {
	        $result=`$FINGER $_ 2>&1`;
	        chomp($result);
	        print "$result\n";
            } else {
                print "Illegal characters in name\n";
            }
	    print "</PRE></td></tr>\n";
	}
	print "</table>\n";
    }

}
