KumbiaPHP beta2-dev
Framework PHP en español
radius_auth.php
Ir a la documentación de este archivo.
00001 <?php
00032 class RadiusAuth implements AuthInterface {
00033 
00039         private $filename;
00040 
00046         private $server;
00047 
00053         private $username;
00054 
00060         private $password;
00061 
00065         private $resource;
00066 
00070         private $port = 1812;
00071 
00077         private $secret;
00078 
00084         private $timeout = 3;
00085 
00091         private $max_retries = 3;
00092 
00099         public function __construct($auth, $extra_args){
00100 
00101                 if(!extension_loaded("radius")){
00102                         throw new KumbiaException("Debe cargar la extensión de php llamada radius");
00103                 }
00104 
00105                 foreach(array('server', 'secret') as $param){
00106                         if(isset($extra_args[$param])){
00107                                 $this->$param = $extra_args[$param];
00108                         } else {
00109                                 throw new KumbiaException("Debe especificar el parámetro '$param' en los parámetros");
00110                         }
00111                 }
00112 
00113                 foreach(array('username', 'password') as $param){
00114                         if(isset($extra_args[$param])){
00115                                 $this->$param = $extra_args[$param];
00116                         }
00117                 }
00118         }
00119 
00124         public function get_identity(){
00125                 if(!$this->resource){
00126                         new KumbiaException("La conexión al servidor Radius es inválida");
00127                 }
00128                 $identity = array("username" => $this->username, "realm" => $this->username);
00129                 return $identity;
00130         }
00131 
00137         public function authenticate(){
00138 
00139                 $radius = radius_auth_open();
00140         if(!$open_radiuse){
00141                 throw new KumbiaException("No se pudo crear el autenticador de Radius");
00142         }
00143 
00144         if(!radius_add_server($radius, $this->server, $this->port, $this->secret,
00145                         $this->timeout, $this->max_retries)) {
00146                 throw new KumbiaException(radius_strerror(0));
00147         }
00148 
00149         if(!radius_create_request($radius, RADIUS_ACCESS_REQUEST)){
00150                 throw new KumbiaException(radius_strerror(0));
00151         }
00152 
00153         if(!radius_put_string($radius, RADIUS_USER_NAME, $this->username)) {
00154                 throw new KumbiaException(radius_strerror(0));
00155         }
00156 
00157         if(!radius_put_string($radius, RADIUS_USER_PASSWORD, $this->password)) {
00158                 throw new KumbiaException(radius_strerror(0));
00159         }
00160 
00161         if(!radius_put_int($radius, RADIUS_AUTHENTICATE_ONLY, 1)) {
00162                 throw new KumbiaException(radius_strerror(0));
00163         }
00164 
00165         $this->resource = $radius;
00166 
00167         if(radius_send_request()==RADIUS_ACCESS_ACCEPT){
00168                 return true;
00169         } else {
00170                 return false;
00171         }
00172 
00173         }
00174 
00179         public function __destruct(){
00180                 if($this->resource){
00181                         radius_close($this->resource);
00182                 }
00183         }
00184 
00190         public function set_params($extra_args){
00191                 foreach(array('server', 'secret', 'username', 'principal',
00192                         'password', 'port', 'max_retries') as $param){
00193                         if(isset($extra_args[$param])){
00194                                 $this->$param = $extra_args[$param];
00195                         }
00196                 }
00197         }
00198 
00199 }
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Enumeraciones