#!/usr/athena/bin/perl
# Zlocate Gateway
# $Id: z,v 1.3 1999/12/24 22:41:38 mhpower Exp $
# Matthew Gray (mkgray@mit.edu) June '93
# Matthew Gray (mkgray@mit.edu) June '94 Converted to CGI
# Rex Min (rmin@mit.edu)        December '99   Added HDML support

$query=$ENV{'QUERY_STRING'};

### Send HDML code to wireless phones with UP.Browser
$hdml= ($ENV{'HTTP_USER_AGENT'} =~ /UP\.Link/);

if ($hdml) {
  print("Content-Type: text/x-hdml\n\n");
} else {
  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 =~ /[A-Za-z0-9_+\s]{2,}/){
	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;

      if ($hdml) {   ############ HDML CODE ############
	print <<"end_msg";
<HDML VERSION=3.0 PUBLIC=TRUE MARKABLE=TRUE TTL=0>
  <DISPLAY>
  Zlocate $name <BR>
  $zl
  </DISPLAY>
</HDML>
end_msg
      } else {     ########### HTML CODE ##########
	print <<"end_msg";
<html><head><title>Zlocate $name</title><body>
<h1>Zlocate $name</h1>
<isindex prompt="Enter the username of the person you wish to locate: ">
<pre>$zl</pre>
</body>
end_msg
      }
    }
    else{
      if ($hdml) {
	print <<"end_msg";    ########## HDML CODE ##############
<HDML VERSION=3.0 PUBLIC=TRUE MARKABLE=TRUE>
  <ENTRY KEY=zu>
     <ACTION TYPE=ACCEPT LABEL=OK TASK=GO DEST="zl?\$(zu:e)">
     User to locate:
  </ENTRY>
</HDML>
end_msg
      } else {     ########## HTML CODE #########
	print <<"end_msg";
<html><head><title>Zlocate (information)</title></head><body>
<h1>Zlocate Gateway</h1>
<isindex prompt="Enter the username of the person you wish to locate: ">

<p>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>

<p>Click <a href="zlocate?mkgray+nocturne+yonah+fubob+leira+annmarie+tlai">here</a>
to see if any of the Webmasters are on line.</p>

<p>In order to be locateable by the web zlocate gateway, you must set your
zephyr exposure to be net-announced using the command</p>

<p><code>zctl set exposure net-visible</code></p>

<p><em>Note</em>: This will make you realm-announced as well, so you
will appear in the znols of people who have you in their .anyone
file. For more information on
<a href="/afs/sipb/project/doc/izephyr/html/section3.html">exposure</a>
and other aspects of zephyr, check
<a href="/afs/sipb/project/doc/izephyr/html/izephyr.html">Inessential
Zephyr</a>.</p>

</body></html>
end_msg
       }
    }
}

1;
