<?

  $option[$number_options] = "Whois";
  $number_options = $number_options + 1;

  // config
  $whois_cmd        = "/usr/bin/whois";
  $whois_file       = "/var/www/html/toolkit-1.1/includes/whois.list";

  // functions for the traceroute option

function whois_options () {

  global $whois_query;
  global $selected_option;
  
  print ("<table cellspacing=0 cellpadding=0 border=0>\n");
  print ("<form ACTION=\"" . $_SERVER[PHP_SELF] . "\" METHOD=\"post\">\n");
  print ("<input type=hidden name=selected_option value=" . $selected_option . ">\n");
  // we need to following to let the main script know we are sending it data for the 
  // second half of this module to process.
  print ("<input type=hidden name=submited value=\"1\"\n");
  // now display our form
  print ("<tr>\n");
  print (" <td>Domain Name:</td>\n");
  print (" <td><input type=text name=whois_query size=15 maxlength=128 value=\"" . $whois_query . "\"></td>\n");
  print (" <td><img height=1 src=images/cl_pixel.gif width=100></td>\n");
  print (" <td></td>\n");
  print (" <td align=left colspan=2><input type=submit name=submit value=\"Lookup Domain\"></td>\n");
  print ("</tr>\n");
  print ("</table>\n");
  print ("</form>\n");

}

function whois_output () {
  // this is called after the submit button is pressed and all the 
  // previous variables should be passed to this function.

  global $whois_cmd;
  global $whois_query;
  global $selected_option;
  global $whois_file;

  // Need to lookup whihc server to query and produce output based on that
  // for this we use the geektools query list
  // read the file into an array and then parse the whois_query variable
  // to find out which host to query.

  $whois_f = fopen ($whois_file, "r");

  while ($whois_info = fscanf ($whois_f, "%s\n")) {
    list ($country, $whois_server, $whois_url) = explode ("|", $whois_info[0]);
    if ($whois_url) {
      $whois_list[$country] = $whois_server . "|" . $whois_url;
    } else {
      $whois_list[$country] = $whois_server;
    }
    $whois_url = "";
    $whois_server = "";
    $whois_country = "";
  }

  // for some reason .com is not listed in geektools
  $whois_list["com"] = "whois.networksolutions.com";
  
  // Get the last field in the name..
  $whois_cc = strtolower(substr(strrchr($whois_query, "."), 1));

  if ($whois_list[$whois_cc] == "NONE") {
    print ("There is no whois server for this Top Level Domain.<br>\n");
    $whois_flag = 1;
  } else {
    list ($whois_type, $whois_url) = explode ("|", $whois_list[$whois_cc]);
    if ($whois_type == "WEB") {
      print ("There is no whoiis server for this Top Level Domain, please ");
      print ("goto <a href=\"" . $whois_url . "\">" . $whois_url . "</a> ");
      print ("for further information.<br>\n");
      $whois_flag = 1;
    }
  }

  // Output data goes here
  if (!$whois_flag) {
    $cmd = $whois_cmd . " " . $whois_query . "@" . $whois_list[$whois_cc];

    $safe_cmd = escapeshellcmd($cmd);
    print("<pre>\n");
    system($safe_cmd);
    print("</pre>\n");

  }


}
