#!/usr/local/bin/perl
# Zlocate Gateway
# $Id: zlocate.pl,v 1.5 94/03/19 12:49:28 root Exp $
# Matthew Gray (mkgray@mit.edu) June '93
# Matthew Gray (mkgray@mit.edu) June '94 Converted to CGI

$query=$ENV{'QUERY_STRING'};

print("Content-Type: text/html\n\n");
$query =join(' ', @ARGV) if $ARGV[0];
print("\n");
&do_zlocate($query);

sub do_zlocate {
    local($name, $zl, *ZL) = @_;

    if($name){
	open(ZL, "-|") || (open(STDERR, ">&STDOUT"),
		 exec '/usr/athena/bin/zlocate', '-d', split(/[\+\s]+/,$name));
	while($_ = <ZL>) {$zl .= $_;}

    ($host, @rest) =split(' ', $zl);
	$zl =~ s/^([^ \tH]+)/<a href="\/finger\?$name\@$host">\1<\/a>/;
    	$zl =~ s/>deathtongue/>deatht&ouml;ngue/i;

	print "<ISINDEX><TITLE>Zlocate $name</TITLE>\n";
	print "<h1>Zlocate $name</h1>\n";
	print "<pre>$zl</pre>";
    }
    else{
        print "<ISINDEX><TITLE>Zlocate (information)</TITLE>\n";
	print "<h1>Zlocate Gateway</h1>\n";
	print("<h1>Enter the username of the person you wish to locate</h1>\n");
	print <<"end_msg";
Zlocate is a program used by MIT's Zephyr message system.
You can use it to find out where someone is logged in.
However, if they wish to be hidden, it is not possible to locate them.<p>
Click <a href="zlocate?mkgray+sorokin+nocturne+rei+mjbauer+harrisj">here</a> to
see if any of the Webmasters are on line.<p>
end_msg
    }
}

1;
