<? if ($server) { $pgpserver=$server; }
   else { 
$pgpserver="pgp.dmzs.com"; }
   
$port="11371";
   
$pgplookup="/pks/lookup";
   
$pgpadd="/pks/add";
   
$webserver="http://www.dmzs.com/";
   
$url="~dmz/projects/pks-commands.php";
?>
<?php 
if (!$docmd):?>
<title>Public Key Server Commands</title>
<body  BACKGROUND="../backgrounds/bg1.gif">
<h1>Public Key Server Commands</h1>
<b>HTML Forms support required!</b><p>
<h2><a href="#extract">Extract a key from the server</a></h2>
<h2><a href="#submit">Submit a key to the server</a></h2>
<hr>

<h2><a name="extract">Extracting a key</a></h2>

Here's how to extract a key:

<ol>
 <li> Select either the ``Index'' or ``Verbose Index'' check box.  The
``Verbose'' option also displays all signatures on displayed keys.
 <li> Type ID you want to search for in the ``Search String'' box.
 <li> Press the ``Do the search!'' key.
 <li> The server will return a (verbose) list of keys on the server
matching the given ID.  (The ID can be any valid argument to a pgp
-kv(v) command. If you want to look up a key by its hexadecimal KeyID,
remember to prefix the ID with <tt>0x</tt>.)
 <li> The returned index will have hypertext links for every KeyID,
and every bracket-delimited identifier (i.e. &lt;<a
href="<?echo $webserver $url ?>?docmd=lookup&op=get&exact=on&search=dmz@dmzs.com">
<i>dmz@dmzs.com</i></a>&gt;).  Clicking on the hypertext link will
display an ASCII-armored version of the listed public key.
 </ol>

<hr>
<form action="<?echo $webserver $url ?>" method="GET">
<input type="hidden" name="docmd" value="lookup">
Server: <select name="server">
        <option value="dmzs.com" selected;>DMZ Services</option>
        <option value="keys.pgp.com">NAI</option>
        <option value="pgp5.ai.mit.edu">BAL MIT</option>
        <option value="pgp.cc.gatech.edu">GA Tech</option>
        <option value="pgp.es.net">ESnet</option>
        </select>
Index: <input type="radio" name="op" value="index" checked>
Verbose Index: <input type="radio" name="op" value="vindex">
<p>
Search String: <input name="search" size=40><p>
<input type="checkbox" name="fingerprint"> Show PGP "fingerprints"
for keys <p>
<input type="checkbox" name="exact"> Only return exact matches <p>
<input type="reset" value="Reset">
<input type="submit" value="Do the search!">
</form>
<hr>

<b>Extract caveats:</b>

<ul>
 <li>Currently, hypertext links are only generated for the KeyID and
for text found between matching brackets.  (It's a common convention
to put your e-mail address inside brackets somewhere in the key ID
string.)
 <li>The search engine is not the same as that used by the pgp
program.  It will return information for all keys which contain all
the words in the search string.  A ``word'' in this context is a
string of consecutive alphabetic characters.  For example, in the
string <tt>marc@mit.edu</tt>, the words are <tt>marc</tt>,
<tt>mit</tt>, and <tt>edu</tt>. <p>
 This means that some keys you might not expect will be returned.  If
there was a key in the database for <tt>Marc Edu
&lt;mit.foo.com&gt;</tt>, this would be returned for by the above
query.  If you don't want to see all these extra matches, you can
select ``Only return exact matches'', and only keys containing the
specified search string will be returned.<p>
 This algorithm does <i>not</i> match partial words in any case.  So,
if you are used to specifying only part of a long name, this will no
longer work. <p>

 </ul>

<hr>

<h2><a name="submit">Submitting a new key to the server</a></h2>

Here's how to add a key to the server's keyring:

<ol>
<li> Cut-and-paste an ASCII-armored version of your public key into
the text box.
<li> Press "Submit".
</ol>

That's it!  The keyserver will process your request immediately.  If
you like, you can check that your key exists using the <a
href="#extract">extract</a> procedure above.

<hr>

<form action="<?echo $webserver $url ?>" method="POST">
<input type="hidden" name="docmd" value="add">
Server: <select name="server">
        <option value="dmzs.com" selected;>DMZ Services</option>
        <option value="keys.pgp.com">NAI</option>
        <option value="pgp5.ai.mit.edu">BAL MIT</option>
        <option value="pgp.cc.gatech.edu">GA Tech</option>
        <option value="pgp.es.net">ESnet</option>
        </select><br>
Enter ASCII-armored PGP key here: <p>
<textarea name="keytext" rows=20 cols=66></textarea><p>

<input type="reset" value="Reset">
<input type="submit" value="Submit this key to the keyserver!"><p>
</form>

<hr>

<address>
(Thanks to <a href="http://www-swiss.ai.mit.edu/~bal">Brian LaMacchia</a>,
from whom much of this page is cribbed)<p>
Marc Horowitz <a href="mailto:marc@mit.edu">&lt;marc@mit.edu&gt;</a> <br>
<a href="http://www.mit.edu:8001/sipb/sipb.html">
Student Information Processing Board</a>
</address>
<? endif;?>
<?php 
if ($docmd):?>
<title>Public Key Server <? if ($docmd=="lookup") {echo "Lookup";} else {echo "Add";}?></title>
<h1>Public Key Server <? if ($docmd=="lookup") {echo "Lookup";} else {echo "Add";}?></h1>
<? 
  
if (!$fingerprint) { $fingerprint "off";}
  if (!
$exact) { $exact "off";}
  if (
$docmd == "lookup") { 
    
$servercommand "GET $pgplookup?op=$op&exact=$exact&fingerprint=$fingerprint&search=$search HTTP/1.0\n\n";
    
$regexstr "/pks\/lookup\?/";
    
$replacestr $url "?docmd=lookup&";
    if (
$server) { $replacestr .= "server=" $server "&"; }
  } else if (
$docmd == "add") {
    
$newkey="keytext=".rawurlencode($keytext);
    
$keylen=strlen($newkey);
    
$servercommand "";
    
$servercommand .= "POST $pgpadd HTTP/1.0 \r\n";
    
$servercommand .= "Referer: \r\n";
    
$servercommand .= "User-Agent: php-pkscommands/0.1 \r\n";
    
$servercommand .= "Host: " $webserver "\r\n";
    
$servercommand .= "Content-type: application/x-www-form-urlencoded\r\n";
    
$servercommand .= "Content-length: " $keylen "\r\n\r\n";
    
$servercommand .= $newkey;
    
$regexstr "/pks\/add\?/";
    
$replacestr $url "?docmd=add&";
  }
  
$fp fsockopen($pgpserver$port, &$errno, &$errstr30);
  if (!
$fp) {
    echo 
"Error with PGP Server. " $errstr "(" $errno ")<br>\n";
  } else {
    
fputs($fp$servercommand);
    while (!
feof($fp)) {
      
$line fgets($fp80);
      if (!
strstr($line"HTTP") && !strstr($line"Server: pks_www") && !strstr($line"Content-type: text/html")) {
        echo 
preg_replace($regexstr,$replacestr,$line);
      }
    }
  }
  
fclose($fp);
  echo 
"<hr><a href=\"" $webserver $url "\">Back</a>";
?>
<? 
endif;?>
</body>