KumbiaPHP  beta2
Framework PHP
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Páginas
radius_auth.php
Ir a la documentación de este archivo.
1 <?php
31 class RadiusAuth implements AuthInterface
32 {
33 
39  private $filename;
45  private $server;
51  private $username;
57  private $password;
61  private $resource;
65  private $port = 1812;
71  private $secret;
77  private $timeout = 3;
83  private $max_retries = 3;
84 
91  public function __construct($auth, $extra_args)
92  {
93 
94  if (!extension_loaded("radius")) {
95  throw new KumbiaException("Debe cargar la extensi�n de php llamada radius");
96  }
97 
98  foreach (array('server', 'secret') as $param) {
99  if (isset($extra_args[$param])) {
100  $this->$param = $extra_args[$param];
101  } else {
102  throw new KumbiaException("Debe especificar el par�metro '$param' en los par�metros");
103  }
104  }
105 
106  foreach (array('username', 'password') as $param) {
107  if (isset($extra_args[$param])) {
108  $this->$param = $extra_args[$param];
109  }
110  }
111  }
112 
117  public function get_identity()
118  {
119  if (!$this->resource) {
120  new KumbiaException("La conexi�n al servidor Radius es inv�lida");
121  }
122  $identity = array("username" => $this->username, "realm" => $this->username);
123  return $identity;
124  }
125 
131  public function authenticate()
132  {
133 
134  $radius = radius_auth_open();
135  if (!$radius) {
136  throw new KumbiaException("No se pudo crear el autenticador de Radius");
137  }
138 
139  if (!radius_add_server($radius, $this->server, $this->port, $this->secret,
140  $this->timeout, $this->max_retries)) {
141  throw new KumbiaException(radius_strerror(0));
142  }
143 
144  if (!radius_create_request($radius, RADIUS_ACCESS_REQUEST)) {
145  throw new KumbiaException(radius_strerror(0));
146  }
147 
148  if (!radius_put_string($radius, RADIUS_USER_NAME, $this->username)) {
149  throw new KumbiaException(radius_strerror(0));
150  }
151 
152  if (!radius_put_string($radius, RADIUS_USER_PASSWORD, $this->password)) {
153  throw new KumbiaException(radius_strerror(0));
154  }
155 
156  if (!radius_put_int($radius, RADIUS_AUTHENTICATE_ONLY, 1)) {
157  throw new KumbiaException(radius_strerror(0));
158  }
159 
160  $this->resource = $radius;
161 
162  if (radius_send_request($radius) == RADIUS_ACCESS_ACCEPT) {
163  return true;
164  } else {
165  return false;
166  }
167  }
168 
173  public function __destruct()
174  {
175  if ($this->resource) {
176  radius_close($this->resource);
177  }
178  }
179 
185  public function set_params($extra_args)
186  {
187  foreach (array('server', 'secret', 'username', 'principal',
188  'password', 'port', 'max_retries') as $param) {
189  if (isset($extra_args[$param])) {
190  $this->$param = $extra_args[$param];
191  }
192  }
193  }
194 
195 }