<?

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

  // This module is only useful if you have a radius
  // server you want to authenticate against
  // to use this module you must have radtest installed
  // from the freeradius distribution.
  // you can get this from http://www.freeradius.org

  // config
  $radius_cmd        = "/usr/bin/radtest";
  $default_server    = "localhost";

  // functions for the traceroute option

function radius_options () {

  global $selected_option;
  global $radius_server;
  global $radius_secret;
  global $radius_username;
  global $radius_password;
  global $radius_port;
  global $radius_nasport;

  // setup some defaults
  if (!$radius_port) { $radius_port = 1645; }
  if (!$radius_server) { $radius_server = "localhost"; }
  if (!$radius_secret) { $radius_secret = "mysecret"; }
  if (!$radius_nasport) { $radius_nasport = 20; }
  
  
  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>Username:</td>\n");
  print (" <td><input type=text name=radius_username size=15 maxlength=128 value=\"" . $radius_username . "\"></td>\n");
  print (" <td><img height=1 src=images/cl_pixel.gif width=100></td>\n");
  print (" <td>Radius Server:</td>\n");
  print (" <td><input type=text name=radius_server size=15 maxlength=128 value=\"" . $radius_server . "\"></
td>\n");
  print ("</tr>\n");
  print ("<tr>\n");
  print (" <td>Password:</td>\n");
  print (" <td align=left><input type=password name=radius_password size=15 maxlength=128></td>\n");
  print (" <td><img height=1 src=images/cl_pixel.gif width=100></td>\n");
  print (" <td>Server Secret:</td>\n");
  print (" <td><input type=text name=radius_secret size=15 maxlength=128 value=\"" . $radius_secret . "\"></td>\n");
  print ("</tr>\n");
  print ("<tr>\n");
  print (" <td>NAS Port:</td>\n");
  print (" <td><input type=text name=radius_nasport size=5 maxlength=5 value=\"" . $radius_nasport . "\"></td>\n");
  print (" <td><img height=1 src=images/cl_pixel.gif width=100></td>\n");
  print (" <td>RADIUS Port:</td>\n");
  print (" <td><input type=text name=radius_port size=5 maxlength=5 value=\"" . $radius_port . "\"></td>\n");
  print ("</tr>\n");
  print ("<tr>\n");
  print (" <td colspan=3><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 RADIUS Lookup\"></td>\n");
  print ("</tr>\n");
  print ("</table>\n");
  print ("</form>\n");

}

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

  global $selected_option;
  global $radius_server;
  global $radius_secret;
  global $radius_username;
  global $radius_password;
  global $radius_port;
  global $radius_nasport;
  global $radius_cmd;

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

    $cmd  = $radius_cmd . " ";
    $cmd .= $radius_username . " ";
    $cmd .= $radius_password . " ";
    $cmd .= $radius_server . ":" . $radius_port . " ";
    $cmd .= $radius_nasport . " ";
    $cmd .= $radius_secret;

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


}
