<?

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

  // config
  $trace_cmd = "/usr/sbin/tracepath";
  $trace6_cmd = "/usr/sbin/tracepath6";

  // functions for the traceroute option

function tracepath_options () {

  global $host;
  global $selected_option;
  global $ipv6;
  global $resolve;
  global $port;

  if (!$ipv6) { $ipv6 = 0; }

  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=host size=15 maxlength=128 value=\"" . $host . "\"></td>\n");
  print (" <td><img height=1 src=images/cl_pixel.gif width=100></td>\n");
  print (" <td>Port</td>\n");
  print (" <td align=left><input type=text name=port size=5 maxlength=5 value=\"" . $port . "\"></td>\n");
  print ("</tr>\n");
  print ("<tr>\n");
  print (" <td>Resolve DNS:</td>\n");
  if ($resolve) {
    print (" <td align=left><input type=checkbox checked name=resolve value=1></td>\n");
  } else {
    print (" <td align=left><input type=checkbox name=resolve value=1></td>\n");
  }
  print (" <td><img height=1 src=images/cl_pixel.gif width=100></td>\n");
  print (" <td>IPv6</td>\n");
  if ($ipv6) {
    print (" <td align=left><input type=checkbox checked name=ipv6 value=1></td>\n");
  } else {
    print (" <td align=left><input type=checkbox name=ipv6 value=1></td>\n");
  }
  print ("</tr>\n");
  print ("<tr>\n");
  print (" <td colspan=2></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=\"Trace Now\"></td>\n");
  print ("</tr>\n");
  print ("</table>\n");
  print ("</form>\n");

}

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

  global $host;
  global $selected_option;
  global $ipv6;
  global $port;
  global $resolve;
  global $trace_cmd;
  global $trace6_cmd;

  // Output data goes here
  if($host) {

    if ($ipv6) {
      $cmd = $trace6_cmd;
    } else {
      $cmd = $trace_cmd;
    }

    if (!$resolve) { $cmd .= " -n"; }

    $cmd .= " " . $host;

    if ($port) {
      $cmd .= "/" . $port;
    }

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


}
