<?php

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

function show_result(){
  $lookupname = $_REQUEST['lookupname'];
  $ipport = split('[:]',$_REQUEST['ip']);
  $ip = $ipport[0];
  $port = $ipport[1]; //"7080"; //$_REQUEST['port'];
  $objlookup=$_REQUEST['object'];
  $objname=$_REQUEST['objname'];
  $key = $_REQUEST['key'];
  $value = $_REQUEST['value'];
  $insert=$_REQUEST['insert'];
  $getrt=$_REQUEST['getrt'];
  $getro=$_REQUEST['getro'];

  if(empty($ip)){
    $_SESSION["user_err"]= "Error: host not selected.\n";
      header("Location: checker.php");
      return;
  }
  chdir("/home/gg2265/p2p/scripts/");
  if($objlookup=='on') {
    exec("/home/gg2265/p2p/scripts/checker -o $objname -a $ip -p $port", $_SESSION["my_result"]);
  }else if($insert=='Publish') {
    if($key==''||$value==''){
      $_SESSION["user_err"]= "Error: Key and/or Value not entered.\n";
      header("Location: checker.php");
      return;
    }
    exec("/home/gg2265/p2p/scripts/checker -i $key -v $value -a $ip -p $port",$_SESSION["my_result"]);
  }else if($getrt=='Get routing table') {
    exec("/home/gg2265/p2p/scripts/checker  -t -R -a $ip -p $port",$_SESSION["my_result"]);
  }else if($getro=='Get resource table') {
    exec("/home/gg2265/p2p/scripts/checker  -t -O -a $ip -p $port",$_SESSION["my_result"]);
  }else {
    if($lookupname==''){
      $_SESSION["user_err"]= "Error:  username not selected.\n";
      header("Location: checker.php");
      return;
    }
    exec("/home/gg2265/p2p/scripts/checker -u $lookupname -a $ip -p $port",$_SESSION["my_result"]);
  }
}  
show_result();
//echo $_SESSION["my_result"];
//foreach ($_SESSION["my_result"] as $str) {
//  echo $str."<br>";
//}
header("Location: checker.php");
?>