<?php

  session_register("my_result");
  session_register("user_err");

function show_result(){
  $cmd=$_GET['cmd'];
  $lookupname = $_GET['usr'];
  $objname=$_GET['obj'];
  $key=$_GET['key'];
  $value=$_GET['value'];
  $ipport = split('[:]',$_GET['ip']);
  $ip = $ipport[0];
  $port = $ipport[1]; 
  if($_GET['rec']==1){
    $rec="-rec";
  }else {
    $rec="";
  }

  $_SESSION["my_result"]="";

  //chdir("/home/gg2265/p2p/scripts/");
  $USER="salman";
  $PATH="/home/$USER/html/peer/exec/0_2/";
  $CPATH="/home/$USER/html/peer/exec/0_2/checker";
  chdir($PATH);

  if($cmd=='lookupusr'){
    exec("$CPATH $rec $rec -u $lookupname -a $ip -p $port",$_SESSION["my_result"]);
  } else if($cmd=='lookupobj'){
    exec("$CPATH $rec -o $objname -a $ip -p $port",$_SESSION["my_result"]);
  } else if($cmd=='publish') {
    exec("$CPATH $rec -i $key -v $value -a $ip -p $port",$_SESSION["my_result"]);
  } else if($cmd=='getrt') {
    exec("$CPATH $rec -t -R -a $ip -p $port",$_SESSION["my_result"]);
  } else if($cmd=='getro') {
    exec("$CPATH $rec -t -O -a $ip -p $port",$_SESSION["my_result"]);
  } else if($cmd=='getturnalloc') {
    exec("$CPATH $rec -N -a $ip -p $port",$_SESSION["my_result"]);
  }

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

}  
show_result();
//echo $_SESSION["my_result"];

?>