<?

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

  // config
  $ping_cmd = "/bin/ping";

  // functions for the ping option

function ping_options () {

  global $host;
  global $selected_option;
  global $count;
  global $resolve;
  global $packetSize;
  global $quiet;
  global $interval;
  global $runTime;

  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>\n");
  print ("Hostname:</td>\n");
  print ("<td>\n");
  print ("<input type=text name=host size=15 maxlength=128 value=\"" . $host . "\"></td>\n");
  print ("<td>\n");
  print ("<td><img height=1 src=images/cl_pixel.gif width=100></td></td>\n");
  print ("<td align=middle colspan=2>\n");
  print ("<font size=-1><b>Additional Options</font></b></td>\n");
  print ("</tr>\n");
  print ("<tr>\n");

  print ("<td>\n");
  print ("Count (Max 100):</td>\n");
  print ("<td>\n");
  print ("<input type=text name=count value=5 size=5 maxlength=3></td>\n");
  print ("<td>\n");
  print ("<td><img height=1 src=images/cl_pixel.gif width=100></td></td>\n");
  print ("<td>\n");
  print ("DNS Lookup</td>\n");
  print ("<td>\n");
  print ("<input type=checkbox name=resolve checked value=1></td>\n");
  print ("</tr>\n");
  print ("<tr>\n");
  print ("<td>\n");
  print ("Packet Size:</td>\n");

  print ("<td>\n");
  print ("<input type=text name=packetSize size=5 maxlength=5></td>\n");
  print ("<td>\n");
  print ("<td><img height=1 src=images/cl_pixel.gif width=100></td></td>\n");
  print ("<td>\n");
  print ("Summary Only</td>\n");
  print ("<td>\n");
  print ("<input type=checkbox name=quiet value=1></td>\n");
  print ("</tr>\n");
  print ("<tr>\n");
  print ("<td>\n");
  print ("Wait Interval:</td>\n");
  print ("<td>\n");
  print ("<input type=text name=interval value=1 size=5 maxlength=5></td>\n");
  print ("<td>\n");

  print ("<td><img height=1 src=images/cl_pixel.gif width=100></td></td>\n");
  print ("<td colspan=2>\n");
  print ("</td>\n");
  print ("</tr>\n");
  print ("<tr>\n");
  print ("<td>\n");
  print ("Max time to run:</td>\n");
  print ("<td>\n");
  print ("<input type=text name=runTime size=5 maxlength=3></td>\n");
  print ("<td>\n");
  print ("<td><img height=1 src=images/cl_pixel.gif width=100></td></td>\n");
  print ("<td align=left colspan=2>\n");
  print ("<input type=submit name=submit value=\"Send Ping\"></td>\n");
  print ("</tr>\n");
  print ("</table>\n");
  print ("</form>\n");

}

function ping_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 $count;
  global $resolve;
  global $packetSize;
  global $quiet;
  global $interval;
  global $runTime;
  global $ping_cmd;

  // Output data goes here
  if($host) {
    // Set some sanity
    if ((!$count) or ($count > 100)) {
      $count = 100;
    }
    if ($packetSize > 1000) {
      $packetSize = 1000;
    }
    $cmd  = $ping_cmd;
    $cmd .= " -c " . $count . " ";
    $cmd .= " -i " . $interval . " ";
    if (!$resolve) {
      $cmd .= " -n ";
    }
    if ($packetSize) {
      $cmd .= " -s " . $packetSize . " ";
    }
    if ($quiet) {
      $cmd .= " -q ";
    }
    if ($runTime) {
      $cmd .= " -w " . $runTime . " ";
    }
    $cmd .= $host;

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


}
