[ Index ]
 

Code source de CakePHP 1.1.13.4450

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/cake/libs/controller/components/iniacl/ -> ini_acl.php (source)

   1  <?php
   2  /* SVN FILE: $Id: ini_acl.php 4409 2007-02-02 13:20:59Z phpnut $ */
   3  /**
   4   * This is core configuration file.
   5   *
   6   * Use it to configure core behaviour ofCake.
   7   *
   8   * PHP versions 4 and 5
   9   *
  10   * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
  11   * Copyright 2005-2007, Cake Software Foundation, Inc.
  12   *                                1785 E. Sahara Avenue, Suite 490-204
  13   *                                Las Vegas, Nevada 89104
  14   *
  15   * Licensed under The MIT License
  16   * Redistributions of files must retain the above copyright notice.
  17   *
  18   * @filesource
  19   * @copyright        Copyright 2005-2007, Cake Software Foundation, Inc.
  20   * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
  21   * @package            cake
  22   * @subpackage        cake.cake.libs.controller.componenets.iniacl
  23   * @since            CakePHP(tm) v 0.2.9
  24   * @version            $Revision: 4409 $
  25   * @modifiedby        $LastChangedBy: phpnut $
  26   * @lastmodified    $Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $
  27   * @license            http://www.opensource.org/licenses/mit-license.php The MIT License
  28   */
  29  /**
  30   * load AclBase
  31   */
  32  uses('controller/components/acl_base');
  33  /**
  34   * In this file you can extend the AclBase.
  35   *
  36   * @package        cake
  37   * @subpackage    cake.cake.libs.controller.componenets.iniacl
  38   */
  39  class INI_ACL extends AclBase {
  40  /**
  41   * Array with configuration, parsed from ini file
  42   *
  43   * @var array
  44   */
  45      var $config = null;
  46  /**
  47   * Constructor
  48   *
  49   */
  50  	function __construct() {
  51      }
  52  
  53  /**
  54   * Main ACL check function. Checks to see if the ARO (access request object) has access to the ACO (access control object).
  55   * Looks at the acl.ini.php file for permissions (see instructions in/config/acl.ini.php).
  56   *
  57   * @param string $aro
  58   * @param string $aco
  59   * @return boolean
  60   * @access public
  61   */
  62  	function check($aro, $aco, $acoAction = null) {
  63          if ($this->config == null) {
  64              $this->config = $this->readConfigFile(CONFIGS . 'acl.ini.php');
  65          }
  66          $aclConfig = $this->config;
  67  
  68          //First, if the user is specifically denied, then DENY
  69          if (isset($aclConfig[$aro]['deny'])) {
  70              $userDenies = $this->arrayTrim(explode(",", $aclConfig[$aro]['deny']));
  71  
  72              if (array_search($aco, $userDenies)) {
  73                  //echo "User Denied!";
  74                  return false;
  75              }
  76          }
  77  
  78          //Second, if the user is specifically allowed, then ALLOW
  79          if (isset($aclConfig[$aro]['allow'])) {
  80              $userAllows = $this->arrayTrim(explode(",", $aclConfig[$aro]['allow']));
  81  
  82              if (array_search($aco, $userAllows)) {
  83                  //echo "User Allowed!";
  84                  return true;
  85              }
  86          }
  87  
  88          //Check group permissions
  89          if (isset($aclConfig[$aro]['groups'])) {
  90              $userGroups = $this->arrayTrim(explode(",", $aclConfig[$aro]['groups']));
  91  
  92              foreach($userGroups as $group) {
  93                  //If such a group exists,
  94                  if (array_key_exists($group, $aclConfig)) {
  95                      //If the group is specifically denied, then DENY
  96                      if (isset($aclConfig[$group]['deny'])) {
  97                          $groupDenies=$this->arrayTrim(explode(",", $aclConfig[$group]['deny']));
  98  
  99                          if (array_search($aco, $groupDenies)) {
 100                              //echo("Group Denied!");
 101                              return false;
 102                          }
 103                      }
 104  
 105                      //If the group is specifically allowed, then ALLOW
 106                      if (isset($aclConfig[$group]['allow'])) {
 107                          $groupAllows = $this->arrayTrim(explode(",", $aclConfig[$group]['allow']));
 108  
 109                          if (array_search($aco, $groupAllows)) {
 110                              //echo("Group Allowed!");
 111                              return true;
 112                          }
 113                      }
 114                  }
 115              }
 116          }
 117  
 118          //Default, DENY
 119          //echo("DEFAULT: DENY.");
 120          return false;
 121      }
 122  
 123  /**
 124   * Parses an INI file and returns an array that reflects the INI file's section structure. Double-quote friendly.
 125   *
 126   * @param string $fileName
 127   * @return array
 128   */
 129  	function readConfigFile($fileName) {
 130          $fileLineArray = file($fileName);
 131  
 132          foreach($fileLineArray as $fileLine) {
 133                  $dataLine = trim($fileLine);
 134                  $firstChar = substr($dataLine, 0, 1);
 135  
 136                  if ($firstChar != ';' && $dataLine != '') {
 137                      if ($firstChar == '[' && substr($dataLine, -1, 1) == ']') {
 138                          $sectionName = preg_replace('/[\[\]]/', '', $dataLine);
 139                      } else {
 140                          $delimiter = strpos($dataLine, '=');
 141  
 142                          if ($delimiter > 0) {
 143                              $key = strtolower(trim(substr($dataLine, 0, $delimiter)));
 144                              $value = trim(substr($dataLine, $delimiter + 1));
 145  
 146                              if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
 147                                  $value = substr($value, 1, -1);
 148                              }
 149  
 150                              $iniSetting[$sectionName][$key]=stripcslashes($value);
 151                          } else {
 152                              if (!isset($sectionName)) {
 153                                  $sectionName = '';
 154                              }
 155  
 156                              $iniSetting[$sectionName][strtolower(trim($dataLine))]='';
 157                          }
 158                      }
 159                  } else {
 160                  }
 161          }
 162  
 163          return $iniSetting;
 164      }
 165  
 166  /**
 167   * Removes trailing spaces on all array elements (to prepare for searching)
 168   *
 169   * @param array $array
 170   * @return array
 171   */
 172  	function arrayTrim($array) {
 173          foreach($array as $element) {
 174              $element = trim($element);
 175          }
 176  
 177          //Adding this element keeps array_search from returning 0:
 178          //0 is the first key, which may be correct, but 0 is interpreted as false.
 179          //Adding this element makes all the keys be positive integers.
 180          array_unshift($array, "");
 181          return $array;
 182      }
 183  }
 184  ?>


Généré le : Sun Feb 25 19:27:47 2007 par Balluche grâce à PHPXref 0.7