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

Source for file BaseAuth.php

Documentation is available at BaseAuth.php

  1. <?php
  2. /**
  3.  * $Header$
  4.  *
  5.  * @package users
  6.  */
  7.  
  8. /**
  9.  * required setup
  10.  */
  11. require_once(UTIL_PKG_PATH "PHP_Compat/Compat/Function/scandir.php");
  12.  
  13. /**
  14.  * Class that manages the base autentication method
  15.  *
  16.  * @package users
  17.  * @subpackage auth
  18.  */
  19. class BaseAuth {
  20.     var $mLogin;
  21.     var $mConfig;
  22.     var $mInfo;
  23.     var $mCfg;
  24.     var $mErrors =array();
  25.  
  26.     function __construct($pAuthId{
  27.         global $gBitSystem;
  28.         $this->mCfg = BaseAuth::getAuthMethod($pAuthId);
  29.         $this->mCfg['auth_id'$pAuthId;
  30.         foreach ($this->getSettings(as $op_id => $op{
  31.             $var_id substr($op_id,strrpos($op_id,"_")+1);
  32.             $var $gBitSystem->getConfig($op_id$op['default']);
  33.             if ($op['type']=="checkbox"{
  34.                 $var ($var== "y");
  35.             }
  36.             $this->mConfig[$var_id]=$var;
  37.         }
  38.     }
  39.  
  40.     public static function &getAuthMethods({
  41.         static $authMethod array();
  42.         static $scaned false;
  43.         if (!$scaned{
  44.             $scaned true;
  45.             BaseAuth::scanAuthPlugins();
  46.         }
  47.         return $authMethod;
  48.     }
  49.  
  50.     public static function getAuthMethod$pAuthId {
  51.         $authMethod =BaseAuth::getAuthMethods();
  52.         if (empty($authMethod[$pAuthId])) return null;
  53.         return $authMethod[$pAuthId];
  54.     }
  55.  
  56.     public static function setAuthMethod($pAuthId,&$method{
  57.         $authMethod =BaseAuth::getAuthMethods();
  58.         $authMethod[$pAuthId]=$method;
  59.     }
  60.  
  61.     public static function scanAuthPlugins({
  62.         global $gBitSystem;
  63.  
  64.         $authDir $gBitSystem->getConfig'users_auth_plugins_dir'USERS_PKG_PATH.'auth/' );
  65.         ifis_dir$authDir && $authScan scandir$authDir ) ) {
  66.             foreach$authScan as $plugDir {
  67.                 if$plugDir != 'CVS' && substr($plugDir,0,1)!='.' && is_dir$authDir.$plugDir ) ) {
  68.                     BaseAuth::register$plugDir,array(
  69.                         'name' => strtoupper$plugDir ).' Auth',
  70.                         'file' => $authDir.$plugDir.'/auth.php',
  71.                         'class' => ucfirst$plugDir ).'Auth',
  72.                     ) );
  73.                 }
  74.             }
  75.         }
  76.     }
  77.  
  78.     public static function register($id,$hash{
  79.         global $gBitSystem;
  80.         $err false;
  81.         $method BaseAuth::getAuthMethod($id);
  82.         if (empty($method)) {
  83.             BaseAuth::authError("Auth Registration Failed: $id already registered");
  84.             $err true;
  85.         }
  86.         if (empty($hash['name'])) {
  87.             BaseAuth::authError("Auth Registration Failed: $id: No Name given");
  88.             $err true;
  89.         }
  90.         if (empty($hash['file'])) {
  91.             BaseAuth::authError("Auth Registration Failed: $id: No file given");
  92.             $err true;
  93.         elseif(!file_exists($hash['file'])) {
  94.             BaseAuth::authError("Auth Registration Failed: $id: File (".basename($hash['file']).") doesn't exist");
  95.             $err true;
  96.         }
  97.         if (empty($hash['class'])) {
  98.             BaseAuth::authError("Auth Registration Failed: $id: No class given");
  99.             $err true;
  100.         }
  101.  
  102.         if (!$err{
  103.             BaseAuth::setAuthMethod($id,$hash);
  104.         }
  105.     }
  106.  
  107.     public static function authError($str{
  108.         $warning '<div class="error">'.$str.'</div>';
  109.         print$warning );
  110.     }
  111.  
  112.     public static function getAuthMethodCount({
  113.         $methods BaseAuth::getAuthMethods();
  114.         if (empty($methods)) return 0;
  115.         return count($methods);
  116.     }
  117.  
  118.     function validate($user,$pass,$challenge,$response{
  119.         if (!$this->isSupported()) return false;
  120.         $this->mLogin $user;
  121.         $this->mInfo['login']=$user;
  122.         $this->mInfo['password']=$pass;
  123.     }
  124.  
  125.     function getUserData({
  126.         return $this->mInfo;
  127.     }
  128.  
  129.     function isSupported({
  130.         $this->mErrors["BaseAuth is not an authentcation method";
  131.         return false;
  132.     }
  133.  
  134.     function createUser(&$userattr{
  135.         $this->mErrors["BaseAuth is not an authentcation method";
  136.         return false;
  137.     }
  138.  
  139.     function getSettings({
  140.         return array();
  141.     }
  142.  
  143.     function canManageAuth({
  144.         $this->mErrors["BaseAuth is not an authentcation method";
  145.         return false;
  146.     }
  147.  
  148.     function getRegistrationFields({
  149.         return array();
  150.     }
  151.  
  152.     public static function isActive($package{
  153.         global $gBitSystem;
  154.         if (empty($package) ) {
  155.             return false;
  156.         }
  157.         for ($i=0;$i<BaseAuth::getAuthMethodCount();$i++{
  158.             $default="";
  159.             if $i=={
  160.                 $default="bit";
  161.             }
  162.             if ($gBitSystem->getConfig("users_auth_method_$i",$default)== $package{
  163.                 return true;
  164.             }
  165.         }
  166.         return false;
  167.     }
  168.  
  169.     public static function init$pAuthMixed {
  170.         global $gBitSystem;
  171.         ifis_numeric$pAuthMixed ) ) {
  172.             $default="";
  173.             if ($pAuthMixed==0{
  174.                 $default="bit";
  175.             }
  176.             $authPlugin $gBitSystem->getConfig("users_auth_method_$pAuthMixed",$default);
  177.             if (!empty$authPlugin ) ) {
  178.                 return BaseAuth::init$authPlugin );
  179.             }
  180.         elseif (!empty($pAuthMixed)) {
  181.             $authPlugin=BaseAuth::getAuthMethod$pAuthMixed );
  182.             if (file_exists$authPlugin['file')) {
  183.                 require_once$authPlugin['file');
  184.                 $cl $authPlugin['class'];
  185.                 $instance new $cl();
  186.                 if$instance->isSupported() ) {
  187.                     return $instance;
  188.                 }
  189.             }
  190.         }
  191.         return false;
  192.     }
  193.  
  194.     public static function getConfig({
  195.         global $gBitSystem;
  196.         $authSettings array();
  197.         foreachBaseAuth::getAuthMethods(as $meth_name => $method {
  198.             $instance BaseAuth::init($meth_name;
  199.             if ($instance{
  200.                 foreach ($instance->getSettings(as $op_id => $op{
  201.                     if (!empty($_REQUEST[$op_id])) {
  202.                         if$op['type'== 'checkbox' {
  203.                             simple_set_toggle$op_idUSERS_PKG_NAME );
  204.                         else {
  205.                             simple_set_value$op_idUSERS_PKG_NAME );
  206.                         }
  207.                     }
  208.                     $value $gBitSystem->getConfig($op_id$op['default']);
  209.                     $op['value']=$value;
  210.                     $method['options'][$op_id$op;
  211.                 }
  212.                 $method['canManageAuth'$instance->canManageAuth();
  213.                 $authSettings['avail'][$meth_name]=$method;
  214.             elseifis_object$instance ) ) {
  215.                 $authSettings['err'][$meth_name]=implode("<br />",$instance->mErrors);
  216.             }
  217.         }
  218.         if (!empty($_REQUEST["loginprefs"])) {
  219.             $used =array();
  220.             for ($i=0,$j=0;$i<count($authSettings['avail']);$i++,$j++{
  221.                 $gBitSystem->storeConfig"users_auth_method_$i",nullUSERS_PKG_NAME );
  222.                 if (empty($_REQUEST["users_auth_method_$i"])) {
  223.                     $j--;
  224.                 elseif(!empty($used[$_REQUEST["users_auth_method_$i"]])) {
  225.                     $j--;
  226.                 else {
  227.                     $used[$_REQUEST["users_auth_method_$i"]]="stored_$j";
  228.                     $gBitSystem->storeConfig"users_auth_method_$j"$_REQUEST["users_auth_method_$i"]USERS_PKG_NAME );
  229.                 }
  230.             }
  231.         }
  232.         $canManageAuth false;
  233.         for ($i=0;$i<count($authSettings['avail']);$i++{
  234.             $default="";
  235.             if ($i==0{
  236.                 $default="bit";
  237.             }
  238.             $authSettings['avail_method'][$i]['value']=$gBitSystem->getConfig("users_auth_method_$i",$default);
  239.             if (!$canManageAuth&&!empty($authSettings['avail_method'][$i]['value'])) {
  240.                 $canManageAuth $authSettings['avail'][$authSettings['avail_method'][$i]['value']]['canManageAuth'];
  241.             }
  242.         }
  243.         if (($gBitSystem->getConfig('users_allow_register','y')=='y')&&!$canManageAuth{
  244.             $authSettings['err']['bit_reg']="Registration is enabled but there are no Auth Methods that support this, Registration won't work!";
  245.         }
  246.         $method['active']=BaseAuth::isActive($meth_name);
  247.         return $authSettings;
  248.     }
  249. }
  250. ?>

Documentation generated on Wed, 29 Jul 2015 13:55:37 +0000 by phpDocumentor 1.5.0-lsces