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

Source for file RADIUS.php

Documentation is available at RADIUS.php

  1. <?php
  2. //
  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.7 2003/05/13 19:27:35 mbretter 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.  * @access  public
  30.  * @version $Revision: 1.7 $
  31.  */
  32. {
  33.  
  34.     /**
  35.      * Contains a RADIUS object
  36.      * @var object 
  37.      */
  38.     var $radius;
  39.     
  40.     /**
  41.      * Contains the authentication type
  42.      * @var string 
  43.      */
  44.     var $authtype;    
  45.  
  46.     /**
  47.      * Constructor of the container class.
  48.      *
  49.      * $options can have these keys:
  50.      * 'servers'    an array containing an array: servername, port,
  51.      *              sharedsecret, timeout, maxtries
  52.      * 'configfile' The filename of the configuration file
  53.      * 'authtype'   The type of authentication, one of: PAP, CHAP_MD5,
  54.      *              MSCHAPv1, MSCHAPv2, default is PAP
  55.      *
  56.      * @param  $options associative array
  57.      * @return object Returns an error object if something went wrong
  58.      */
  59.     function Auth_Container_RADIUS($options)
  60.     {
  61.         $this->authtype = 'PAP';
  62.         if (isset($options['authtype'])) {
  63.             $this->authtype = $options['authtype'];
  64.         }
  65.         $classname 'Auth_RADIUS_' $this->authtype;
  66.         if (!class_exists($classname)) {
  67.             PEAR::raiseError("Unknown Authtype, please use on of: PAP, CHAP_MD5, MSCHAPv1, MSCHAPv2!",
  68.                                     41PEAR_ERROR_DIE);
  69.         }
  70.         
  71.         $this->radius = new $classname;
  72.  
  73.         if (isset($options['configfile'])) {
  74.             $this->radius->setConfigfile($options['configfile']);
  75.         }
  76.  
  77.         $servers $options['servers'];
  78.         if (is_array($servers)) {
  79.             foreach ($servers as $server{
  80.                 $servername     $server[0];
  81.                 $port           = isset($server[1]$server[1: 0;
  82.                 $sharedsecret   = isset($server[2]$server[2'testing123';
  83.                 $timeout        = isset($server[3]$server[3: 3;
  84.                 $maxtries       = isset($server[4]$server[4: 3;
  85.                 $this->radius->addServer($servername$port$sharedsecret$timeout$maxtries);
  86.             }
  87.         }
  88.         
  89.         if (!$this->radius->start()) {
  90.             PEAR::raiseError($this->radius->getError()41PEAR_ERROR_DIE);
  91.         }
  92.     }
  93.  
  94.     /**
  95.      * Authenticate
  96.      *
  97.      * @param  string Username
  98.      * @param  string Password
  99.      * @return bool   true on success, false on reject
  100.      */
  101.     function fetchData($username$password$challenge = null)
  102.     {
  103.         switch($this->authtype{
  104.         case 'CHAP_MD5':
  105.         case 'MSCHAPv1':
  106.             if (isset($challenge)) {
  107.                 echo $password;
  108.                 $this->radius->challenge = $challenge;
  109.                 $this->radius->chapid    = 1;
  110.                 $this->radius->response  = pack('H*'$password);
  111.             else {
  112.                 require_once 'Crypt_CHAP/CHAP.php';
  113.                 $classname 'Crypt_' $this->authtype;
  114.                 $crpt = new $classname;
  115.                 $crpt->password = $password;
  116.                 $this->radius->challenge = $crpt->challenge;
  117.                 $this->radius->chapid    = $crpt->chapid;
  118.                 $this->radius->response  = $crpt->challengeResponse();
  119.                 break;
  120.             }
  121.  
  122.         case 'MSCHAPv2':
  123.             require_once 'Crypt_CHAP/CHAP.php';
  124.             $crpt = new Crypt_MSCHAPv2;
  125.             $crpt->username = $username;
  126.             $crpt->password = $password;
  127.             $this->radius->challenge     = $crpt->authChallenge;
  128.             $this->radius->peerChallenge = $crpt->peerChallenge;
  129.             $this->radius->chapid        = $crpt->chapid;
  130.             $this->radius->response      = $crpt->challengeResponse();
  131.             break;
  132.  
  133.         default:
  134.             $this->radius->password = $password;
  135.             break;
  136.         }
  137.  
  138.         $this->radius->username = $username;
  139.  
  140.         $this->radius->putAuthAttributes();
  141.         $result $this->radius->send();
  142.         if (PEAR::isError($result)) {
  143.             return false;
  144.         }
  145.  
  146.         $this->radius->getAttributes();
  147. //      just for debugging
  148. //      $this->radius->dumpAttributes();
  149.  
  150.         return $result;
  151.     }
  152. }
  153. ?>

Documentation generated on Mon, 11 Mar 2019 13:52:33 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.