Auth
[ class tree: Auth ] [ index: Auth ] [ all elements ]

Source for file RADIUS.php

Documentation is available at RADIUS.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Michael Bretterklieber <michael@bretterklieber.com>         |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: RADIUS.php,v 1.9 2006/02/28 02:19:22 aashley Exp $
  20. //
  21.  
  22. require_once "Auth/Container.php";
  23. require_once "Auth/RADIUS.php";
  24.  
  25. /**
  26.  * Storage driver for authenticating users against RADIUS servers.
  27.  *
  28.  * @author  Michael Bretterklieber <michael@bretterklieber.com>
  29.  * @author  Adam Ashley <aashley@php.net>
  30.  * @access  public
  31.  * @version $Revision: 1.9 $
  32.  */
  33. {
  34.  
  35.     // {{{ properties
  36.  
  37.     /**
  38.      * Contains a RADIUS object
  39.      * @var object 
  40.      */
  41.     var $radius;
  42.     
  43.     /**
  44.      * Contains the authentication type
  45.      * @var string 
  46.      */
  47.     var $authtype;    
  48.  
  49.     // }}}
  50.  
  51.     // {{{ Auth_Container_RADIUS() [constructor]
  52.  
  53.     /**
  54.      * Constructor of the container class.
  55.      *
  56.      * $options can have these keys:
  57.      * 'servers'    an array containing an array: servername, port,
  58.      *              sharedsecret, timeout, maxtries
  59.      * 'configfile' The filename of the configuration file
  60.      * 'authtype'   The type of authentication, one of: PAP, CHAP_MD5,
  61.      *              MSCHAPv1, MSCHAPv2, default is PAP
  62.      *
  63.      * @param  $options associative array
  64.      * @return object Returns an error object if something went wrong
  65.      */
  66.     function Auth_Container_RADIUS($options)
  67.     {
  68.         $this->authtype = 'PAP';
  69.         if (isset($options['authtype'])) {
  70.             $this->authtype = $options['authtype'];
  71.         }
  72.         $classname 'Auth_RADIUS_' $this->authtype;
  73.         if (!class_exists($classname)) {
  74.             PEAR::raiseError("Unknown Authtype, please use on of: "
  75.                     ."PAP, CHAP_MD5, MSCHAPv1, MSCHAPv2!"41PEAR_ERROR_DIE);
  76.         }
  77.         
  78.         $this->radius = new $classname;
  79.  
  80.         if (isset($options['configfile'])) {
  81.             $this->radius->setConfigfile($options['configfile']);
  82.         }
  83.  
  84.         $servers $options['servers'];
  85.         if (is_array($servers)) {
  86.             foreach ($servers as $server{
  87.                 $servername     $server[0];
  88.                 $port           = isset($server[1]$server[1: 0;
  89.                 $sharedsecret   = isset($server[2]$server[2'testing123';
  90.                 $timeout        = isset($server[3]$server[3: 3;
  91.                 $maxtries       = isset($server[4]$server[4: 3;
  92.                 $this->radius->addServer($servername$port$sharedsecret$timeout$maxtries);
  93.             }
  94.         }
  95.         
  96.         if (!$this->radius->start()) {
  97.             PEAR::raiseError($this->radius->getError()41PEAR_ERROR_DIE);
  98.         }
  99.     }
  100.  
  101.     // }}}
  102.     // {{{ fetchData()
  103.  
  104.     /**
  105.      * Authenticate
  106.      *
  107.      * @param  string Username
  108.      * @param  string Password
  109.      * @return bool   true on success, false on reject
  110.      */
  111.     function fetchData($username$password$challenge = null)
  112.     {
  113.         switch($this->authtype{
  114.         case 'CHAP_MD5':
  115.         case 'MSCHAPv1':
  116.             if (isset($challenge)) {
  117.                 echo $password;
  118.                 $this->radius->challenge = $challenge;
  119.                 $this->radius->chapid    = 1;
  120.                 $this->radius->response  = pack('H*'$password);
  121.             else {
  122.                 require_once 'Crypt/CHAP.php';
  123.                 $classname 'Crypt_' $this->authtype;
  124.                 $crpt = new $classname;
  125.                 $crpt->password = $password;
  126.                 $this->radius->challenge = $crpt->challenge;
  127.                 $this->radius->chapid    = $crpt->chapid;
  128.                 $this->radius->response  = $crpt->challengeResponse();
  129.                 break;
  130.             }
  131.  
  132.         case 'MSCHAPv2':
  133.             require_once 'Crypt/CHAP.php';
  134.             $crpt = new Crypt_MSCHAPv2;
  135.             $crpt->username = $username;
  136.             $crpt->password = $password;
  137.             $this->radius->challenge     = $crpt->authChallenge;
  138.             $this->radius->peerChallenge = $crpt->peerChallenge;
  139.             $this->radius->chapid        = $crpt->chapid;
  140.             $this->radius->response      = $crpt->challengeResponse();
  141.             break;
  142.  
  143.         default:
  144.             $this->radius->password = $password;
  145.             break;
  146.         }
  147.  
  148.         $this->radius->username = $username;
  149.  
  150.         $this->radius->putAuthAttributes();
  151.         $result $this->radius->send();
  152.         if (PEAR::isError($result)) {
  153.             return false;
  154.         }
  155.  
  156.         $this->radius->getAttributes();
  157. //      just for debugging
  158. //      $this->radius->dumpAttributes();
  159.  
  160.         return $result;
  161.     }
  162.  
  163.     // }}}
  164.  
  165. }
  166. ?>

Documentation generated on Mon, 11 Mar 2019 14:37:17 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.