<?php

$success = 0;
$rad = radius_auth_open();
foreach ($config['auth_radius_server'] as $server) {
  if(radius_add_server($rad, $server, $config['auth_radius_port'], $config['auth_radius_secret'], $config['auth_radius_timeout'], $config['auth_radius_retries'])) {
    $success = 1;
  }
}
if (!$success) {
  // FIXME handle error?
  die;
}

function authenticate($username,$password)
{
  global $config, $rad;

  if ($username && $rad)
  {
    radius_create_request($rad, RADIUS_ACCESS_REQUEST);
    radius_put_string($rad, 1, $username);
    radius_put_string($rad, 2, $password);
    radius_put_string($rad, 4, $_SERVER['SERVER_ADDR']);
    
    $response = radius_send_request($rad);
    if ($response == RADIUS_ACCESS_ACCEPT) {
      return 1;
    }
  }

  return 0;
}

function passwordscanchange($username = "")
{
  return 0;
}

function changepassword($username,$newpassword)
{
  # Not supported
}

function auth_usermanagement()
{
  return 0;
}

function adduser($username, $password, $level, $email = "", $realname = "", $can_modify_passwd = '1')
{
  # Not supported
  return 0;
}

function user_exists($username)
{
  return 0;
}

function get_userlevel($username)
{
  return 10;
}

function get_userid($username)
{
  return -1;
}

function deluser($username)
{
  # Not supported
  return 0;
}

function get_userlist()
{
  $userlist = array();
  return $userlist;
}

?>
