<?php
session_register("my_result");
session_register("user_err");
$key = $_GET['key'];
$value = $_GET['value'];
$usr = $_GET['usr'];
$obj = $_GET['obj'];
$ip = $_GET['ip'];
?>
<html>
<body>
<h2>Welcome to P2PP monitor.</h2>
<a href="index.html">Home</a> <br>

Welcome to the web interface of our 500+ node Kademlia overlay
network built using <a href="http://tools.ietf.org/html/draft-baset-p2psip-p2pp-01">P2PP-01 protocol</a>. 
We are running three instances of the P2PP executable on ~180 planet lab machines distributed around
  the world. Each peer has been assigned a randomly generated user-name.

<p>
In this page, you can search for a user-name from any peer <b>(LookupUser)</b>,
publish a key/value pair <b>(Publish)</b>, and look it up <b>(LookupObject)</b>. You 
can also check the routing table of a peer <b>(Get routing table)</b>
and the resource objects it stores <b>(Get resource table)</b>. </p>

<p>Our system also lets you perform <b>LookupUser</b>, <b>LookupObject</b>, and <b>PublishObject</b> 
queries from any peer in a recursive or iterative fashion. For each
operation, we also show the time taken to complete the operation and
exponential weighted moving average of bytes sent and received.</p>

<p>
If you will like to use our command line tool <a href="consistency.html">checker</a> 
to check the publish/lookup consistency of our system in a batch mode, please 
use the following file <a href="user_name">user_name_list</a>.<br>

<script language="Javascript">
function userselected(list){
  document.forms[0]["usrname"].value=list[list.selectedIndex].value;
}
</script>

  <form method="post" action="lookup.php">
  <table> <tr> <td valign="top">
  <table border="0" widtd="50%" cellpadding="2" cellspacing="30">
   
<?php
  include 'create_select_list.php';
  create_select_list($ip);
?>
  </table>
  </td>

    <td valign="top">
 <table >
      <tr> <br> </tr>
      <tr> <br> </tr>
      <tr> <br> </tr>
      <tr> <br> </tr>
   <tr >
      <td valign="top"> <b>Recursive routing </b></td>
      <td> <input type="checkbox" name="recursive"  </td>
    </tr>
    <tr> <td> <br> </td> </tr>
   <tr >
      <td valign="top"> <b> LookupUser </b></td>
      <td> <input type="text" name="usrname" value="<?echo $usr?>"/> </td>
    </tr>
    <tr>
       <td> <font size=2> (enter/select username, <br>select host and press lookup) </font> </td> 
    </tr>
    <tr>
      <td> <input type="submit"  name="lookup"  value="Lookup User"/> </td>
    </tr>

    <tr> <td> <br> </td> </tr>

    <tr>
      <td> <b>LookupObject </b></td>
      <td> <input type="text" name="objname" value="<?echo $obj?>"/> </td>
    </tr>
    <tr>
       <td> <font size=2> (enter objectname, <br>select host and press lookup) </font> </td> 
    </tr>
    <tr>
      <td> <input type="submit"  name="lookup" value="Lookup Object"/> </td>
    </tr>

    <tr> <td> <br> </td> </tr>


    <tr>
      <td> <b>Publish </b> </td>
    </tr>
    <tr>
      <td> Object (string)  </td>
      <td> <input type="text" name="key" value="<?echo $key?>"/> </td>
    </tr>
    <tr>
      <td> Value </td>
      <td> <input type="text" name="value" value="<?echo $value?>"/> </td>
    </tr>
    <tr>
       <td> <font size=2> (enter object, value, <br>select host and press publish) </font> </td> 
    </tr>
    <tr>
      <td> <input type="submit"  name="insert"  value="Publish"/> </td>
    </tr>

    <tr> <td> <br> </td> </tr>

    <tr>
      <td> <b>Get routing table </b></td>
    </tr>
    <tr>
       <td> <font size=2> (select host and <br> press get routing table) </font> </td> 
    </tr>
    <tr>
      <td> <input type="submit" name="getrt" value="Get routing table"> </td>
    </tr>

    <tr> <td> <br> </td> </tr>

    <tr>
      <td> <b>Get resource table</b> </td>
    </tr>
    <tr>
       <td> <font size=2> (select host and <br> press get resource table) </font> </td> 
    </tr>
    <tr>
      <td> <input type="submit" name="getro" value="Get resource table"> </td>
    </tr>

  </table>
  </td>
  <td> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp </td>
  <td valign="top" align="right">
    <table>
      <tr> <br> </tr>
      <tr> <br> </tr>
      <tr> <br> </tr>
      <tr> <br> </tr>
      <b>

	<?php
        $errstr=$_SESSION["user_err"];
        if($errstr){
	 echo("<tr> <td> <b> Error: </b></td> </tr>");
	 echo("<tr> <td>");
	 echo("<font color=\"red\"> $errstr </font> <br>");
	 echo("</tr> </td>");
        }
        $result=$_SESSION["my_result"];
	if($result){
	 echo("<tr> <td> <b> Result: </b></td> </tr>");
	 echo("<tr> <td>");
	   echo("<b>");
	   foreach ($result as $str) {
	   if(strstr($str,"200 Ok")!=FALSE){
	    $outstr= "<font color=\"green\"> $str </font> <br>";
	   }else if(strstr($str,"404 Not")!=FALSE) {
	    $outstr= "<font color=\"red\"> $str </font> <br>";
	   }else if(strstr($str,"413 Timeout")!=FALSE) {
	    $outstr= "<font color=\"orange\"> $str </font> <br>";
	   }else if(strstr($str,"302 response")!=FALSE) {
	    $outstr= "<font color=\"blue\"> $str </font> <br>";
	   }else {
	    $outstr = $str."<br>";
	   }
	   echo $outstr;
	   }
	   echo("</b>");
	   //echo ($result);
	   echo("</tr> </td>");
	}
	$_SESSION["my_result"]="";
	   $_SESSION["user_err"]="";    
	?>
    </table>
  </td>
  </tr>
  </table>
  </form>
</body>
</html>