<?

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

  // config
  $dns_cmd        = "/usr/bin/host";
  $default_server = "localhost";

  // functions for the traceroute option

function dns_options () {

  global $dns_host;
  global $selected_option;
  global $dns_queryType;
  global $dns_verbose;
  global $dns_server;
  global $dns_soa;

  
  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>Hostname:</td>\n");
  print (" <td><input type=text name=dns_host size=15 maxlength=128 value=\"" . $dns_host . "\"></td>\n");
  print (" <td><img height=1 src=images/cl_pixel.gif width=100></td>\n");
  print (" <td>Class</td>\n");
  print (" <td align=left>\n");
  print ("  <select name=dns_queryType>\n");
  print ("   <option value=\"\">Default</option>\n");
  print ("   <option value=\"MX\">MX</option>\n");
  print ("   <option value=\"NS\">NS</option>\n");
  print ("   <option value=\"TXT\">TXT</option>\n");
  print ("   <option value=\"SOA\">SOA</option>\n");
  print ("  </select>\n");
  print ("  </td>\n");
  print ("</tr>\n");
  print ("<tr>\n");
  print (" <td>Name Server:</td>\n");
  print (" <td align=left><input type=text name=host size=15 maxlength=128 value=\"" . $dns_server . "\"></td>\n");
  print (" <td><img height=1 src=images/cl_pixel.gif width=100></td>\n");
  print (" <td>Extended Output:</td>\n");
  if ($dns_verbose) {
    print (" <td align=left><input type=checkbox checked name=dns_verbose value=1></td>\n");
  } else {
    print (" <td align=left><input type=checkbox name=dns_verbose value=1></td>\n");
  }
  print ("</tr>\n");
  print ("<tr>\n");
  print (" <td>List SOA:</td>\n");
  if ($dns_soa) {
    print (" <td align=left><input type=checkbox checked name=dns_soa value=1></td>\n");
  } else {
    print (" <td align=left><input type=checkbox name=dns_soa value=1></td>\n");
  }
  print (" <td><img height=1 src=images/cl_pixel.gif width=100></td>\n");
  print (" <td align=left colspan=2><input type=submit name=submit value=\"Do DNS Lookup\"></td>\n");
  print ("</tr>\n");
  print ("</table>\n");
  print ("</form>\n");

}

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

  global $dns_cmd;
  global $dns_host;
  global $selected_option;
  global $dns_queryType;
  global $dns_verbose;
  global $dns_server;
  global $dns_soa;

  // Output data goes here
  print ("Host: " . $dns_host . "\n" );
  if($dns_host) {

    $cmd = $dns_cmd;

    if ($dns_queryType) {
      $cmd .= " -t " . $dns_queryType;
    }

    if ($dns_soa) {
      $cmd .= " -C";
    }

    if ($dns_verbose) {
      $cmd .= " -v";
    }

    $cmd .= " " . $dns_host;

    if ($dns_server) {
      $cmd .= " " . $dns_server;
    }

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


}
