[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/includes/ -> gacl.class.php (source)

   1  <?php
   2  /**
   3  * @version $Id: gacl.class.php 87 2005-09-15 23:12:03Z eddieajau $
   4  * @package Joomla
   5  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
   6  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  */
  13  
  14  /*
  15   * phpGACL - Generic Access Control List
  16   * Copyright (C) 2002,2003 Mike Benoit
  17   *
  18   * This library is free software; you can redistribute it and/or
  19   * modify it under the terms of the GNU Lesser General Public
  20   * License as published by the Free Software Foundation; either
  21   * version 2.1 of the License, or (at your option) any later version.
  22   *
  23   * This library is distributed in the hope that it will be useful,
  24   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  26   * Lesser General Public License for more details.
  27   *
  28   * You should have received a copy of the GNU Lesser General Public
  29   * License along with this library; if not, write to the Free Software
  30   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  31   *
  32   * For questions, help, comments, discussion, etc., please join the
  33   * phpGACL mailing list. http://sourceforge.net/mail/?group_id=57103
  34   *
  35   * You may contact the author of phpGACL by e-mail at:
  36   * ipso@snappymail.ca
  37   *
  38   * The latest version of phpGACL can be obtained from:
  39   * http://phpgacl.sourceforge.net/
  40   *
  41   */
  42  
  43  // no direct access
  44  defined( '_VALID_MOS' ) or die( 'Restricted access' );
  45  
  46  // NOTE, this is a temporary solution until phpGACL libraries are fully implemented
  47  
  48  /* -- Code to manually add a group to the ARO Groups
  49  SET @parent_name = 'Registered';
  50  SET @new_name = 'Support';
  51  
  52  -- Select the parent node to insert after
  53  SELECT @ins_id := group_id, @ins_lft := lft, @ins_rgt := rgt
  54  FROM jos_core_acl_aro_groups
  55  WHERE name = @parent_name;
  56  
  57  SELECT @new_id := MAX(group_id) + 1 FROM jos_core_acl_aro_groups;
  58  
  59  -- Make room for the new node
  60  UPDATE jos_core_acl_aro_groups SET rgt=rgt+2 WHERE rgt>=@ins_rgt;
  61  UPDATE jos_core_acl_aro_groups SET lft=lft+2 WHERE lft>@ins_rgt;
  62  
  63  -- Insert the new node
  64  INSERT INTO jos_core_acl_aro_groups (group_id,parent_id,name,lft,rgt)
  65  VALUES (@new_id,@ins_id,@new_name,@ins_rgt,@ins_rgt+1);
  66  */
  67  
  68  class gacl {
  69  
  70      // --- Private properties ---
  71  
  72      /*
  73       * Enable Debug output.
  74       */
  75      var $_debug = FALSE;
  76  
  77      /*
  78       * Database configuration.
  79       */
  80      var $db=null;
  81      var $_db_table_prefix = '#__core_acl_';
  82  
  83      /*
  84       * NOTE:     This cache must be manually cleaned each time ACL's are modified.
  85       *         Alternatively you could wait for the cache to expire.
  86       */
  87      var $_caching = FALSE;
  88      var $_force_cache_expire = TRUE;
  89  
  90      // --- Fudge properties
  91      var $acl=null;
  92      var $acl_count=0;
  93  
  94      /*
  95       * Constructor
  96       */
  97  	function gacl( $db=null ) {
  98          global $database;
  99  
 100          $this->db = $db ? $db : $database;
 101  
 102          // ARO value is currently the user type,
 103          // this changes to user id in proper implementation
 104          // No hierarchial inheritance so have to do that the long way
 105          $this->acl = array();
 106  
 107          // backend login
 108          $this->_mos_add_acl( 'administration', 'login', 'users', 'administrator', null, null );
 109          $this->_mos_add_acl( 'administration', 'login', 'users', 'super administrator', null, null );
 110          $this->_mos_add_acl( 'administration', 'login', 'users', 'manager', null, null );
 111          // backend menus
 112          //$this->_mos_add_acl( 'administration', 'config', 'users', 'administrator', null, null );
 113          $this->_mos_add_acl( 'administration', 'config', 'users', 'super administrator', null, null );
 114  
 115          // access to db admin
 116          //$this->_mos_add_acl( 'administration', 'manage', 'users', 'super administrator', 'components', 'com_dbadmin' );
 117  
 118          // access to templates
 119          //$this->_mos_add_acl( 'administration', 'manage', 'user', 'administrator', 'components', 'com_templates' )
 120          $this->_mos_add_acl( 'administration', 'manage', 'users', 'super administrator', 'components', 'com_templates' );
 121          $this->_mos_add_acl( 'administration', 'install', 'users', 'super administrator', 'templates', 'all' );
 122  
 123          // access to trash
 124          $this->_mos_add_acl( 'administration', 'manage', 'users', 'administrator', 'components', 'com_trash' );
 125          $this->_mos_add_acl( 'administration', 'manage', 'users', 'super administrator', 'components', 'com_trash' );
 126  
 127          // access to menu manager
 128          $this->_mos_add_acl( 'administration', 'manage', 'users', 'administrator', 'components', 'com_menumanager' );
 129          $this->_mos_add_acl( 'administration', 'manage', 'users', 'super administrator', 'components', 'com_menumanager' );
 130  
 131          // access to language
 132          //$this->_mos_add_acl( 'administration', 'manage', 'users', 'administrator', 'components', 'com_languages' );
 133          $this->_mos_add_acl( 'administration', 'manage', 'users', 'super administrator', 'components', 'com_languages' );
 134          $this->_mos_add_acl( 'administration', 'install', 'users', 'super administrator', 'languages', 'all' );
 135  
 136          // access to modules
 137          $this->_mos_add_acl( 'administration', 'install', 'users', 'administrator', 'modules', 'all' );
 138          $this->_mos_add_acl( 'administration', 'install', 'users', 'super administrator', 'modules', 'all' );
 139  
 140          $this->_mos_add_acl( 'administration', 'edit', 'users', 'super administrator', 'modules', 'all' );
 141          $this->_mos_add_acl( 'administration', 'edit', 'users', 'administrator', 'modules', 'all' );
 142  
 143          // access to modules
 144          $this->_mos_add_acl( 'administration', 'install', 'users', 'administrator', 'mambots', 'all' );
 145          $this->_mos_add_acl( 'administration', 'install', 'users', 'super administrator', 'mambots', 'all' );
 146  
 147          $this->_mos_add_acl( 'administration', 'edit', 'users', 'super administrator', 'mambots', 'all' );
 148          $this->_mos_add_acl( 'administration', 'edit', 'users', 'administrator', 'mambots', 'all' );
 149          // uncomment following to allow managers to edit modules
 150          //array( 'administration', 'edit', 'users', 'manager', 'modules', 'all' );
 151  
 152          // access to components
 153          $this->_mos_add_acl( 'administration', 'install', 'users', 'administrator', 'components', 'all' );
 154          $this->_mos_add_acl( 'administration', 'install', 'users', 'super administrator', 'components', 'all' );
 155  
 156          $this->_mos_add_acl( 'administration', 'edit', 'users', 'super administrator', 'components', 'all' );
 157          $this->_mos_add_acl( 'administration', 'edit', 'users', 'administrator', 'components', 'all' );
 158  
 159          $this->_mos_add_acl( 'administration', 'edit', 'users', 'manager', 'components', 'com_newsflash' );
 160          $this->_mos_add_acl( 'administration', 'edit', 'users', 'manager', 'components', 'com_frontpage' );
 161          $this->_mos_add_acl( 'administration', 'edit', 'users', 'manager', 'components', 'com_media' );
 162              // ** add additional components for a manager as desired, or give access to all
 163  
 164          // massmail
 165          $this->_mos_add_acl( 'administration', 'manage', 'users', 'super administrator', 'components', 'com_massmail' );
 166  
 167          // manage users
 168          $this->_mos_add_acl( 'administration', 'manage', 'users', 'administrator', 'components', 'com_users' );
 169          $this->_mos_add_acl( 'administration', 'manage', 'users', 'super administrator', 'components', 'com_users' );
 170  
 171          // email block users property
 172          $this->_mos_add_acl( 'administration', 'edit', 'users', 'administrator', 'user properties', 'block_user' );
 173          $this->_mos_add_acl( 'administration', 'edit', 'users', 'super administrator', 'user properties', 'block_user' );
 174  
 175          // email system events
 176          $this->_mos_add_acl( 'workflow', 'email_events', 'users', 'administrator', null, null );
 177          $this->_mos_add_acl( 'workflow', 'email_events', 'users', 'super administrator', null, null );
 178  
 179          // actions
 180          $this->_mos_add_acl( 'action', 'add', 'users', 'author', 'content', 'all' );
 181          $this->_mos_add_acl( 'action', 'add', 'users', 'editor', 'content', 'all' );
 182          $this->_mos_add_acl( 'action', 'add', 'users', 'publisher', 'content', 'all' );
 183          $this->_mos_add_acl( 'action', 'edit', 'users', 'author', 'content', 'own' );
 184          $this->_mos_add_acl( 'action', 'edit', 'users', 'editor', 'content', 'all' );
 185          $this->_mos_add_acl( 'action', 'edit', 'users', 'publisher', 'content', 'all' );
 186          $this->_mos_add_acl( 'action', 'publish', 'users', 'publisher', 'content', 'all' );
 187  
 188          $this->_mos_add_acl( 'action', 'add', 'users', 'manager', 'content', 'all' );
 189          $this->_mos_add_acl( 'action', 'edit', 'users', 'manager', 'content', 'all' );
 190          $this->_mos_add_acl( 'action', 'publish', 'users', 'manager', 'content', 'all' );
 191  
 192          $this->_mos_add_acl( 'action', 'add', 'users', 'administrator', 'content', 'all' );
 193          $this->_mos_add_acl( 'action', 'edit', 'users', 'administrator', 'content', 'all' );
 194          $this->_mos_add_acl( 'action', 'publish', 'users', 'administrator', 'content', 'all' );
 195  
 196          $this->_mos_add_acl( 'action', 'add', 'users', 'super administrator', 'content', 'all' );
 197          $this->_mos_add_acl( 'action', 'edit', 'users', 'super administrator', 'content', 'all' );
 198  
 199          $this->_mos_add_acl( 'action', 'publish', 'users', 'super administrator', 'content', 'all' );
 200  
 201          $this->acl_count = count( $this->acl );
 202      }
 203  
 204      /*
 205          This is a temporary function to allow 3PD's to add basic ACL checks for their
 206          modules and components.  NOTE: this information will be compiled in the db
 207          in future versions
 208      */
 209  	function _mos_add_acl( $aco_section_value, $aco_value,
 210          $aro_section_value, $aro_value, $axo_section_value=NULL, $axo_value=NULL ) {
 211  
 212          $this->acl[] = array( $aco_section_value, $aco_value, $aro_section_value, $aro_value, $axo_section_value, $axo_value );
 213          $this->acl_count = count( $this->acl );
 214      }
 215  
 216      /*======================================================================*\
 217          Function:   $gacl_api->debug_text()
 218          Purpose:    Prints debug text if debug is enabled.
 219      \*======================================================================*/
 220  	function debug_text($text) {
 221  
 222          if ($this->_debug) {
 223              echo "$text<br>\n";
 224          }
 225  
 226          return true;
 227      }
 228  
 229      /*======================================================================*\
 230          Function:   $gacl_api->debug_db()
 231          Purpose:    Prints database debug text if debug is enabled.
 232      \*======================================================================*/
 233  	function debug_db($function_name = '') {
 234          if ($function_name != '') {
 235              $function_name .= ' (): ';
 236          }
 237  
 238          return $this->debug_text ($function_name .'database error: '. $this->db->getErrorMsg() .' ('. $this->db->getErrorNum() .')');
 239      }
 240  
 241      /*======================================================================*\
 242          Function:   acl_check()
 243          Purpose:    Function that wraps the actual acl_query() function.
 244                          It is simply here to return TRUE/FALSE accordingly.
 245      \*======================================================================*/
 246  	function acl_check( $aco_section_value, $aco_value,
 247          $aro_section_value, $aro_value, $axo_section_value=NULL, $axo_value=NULL ) {
 248  
 249          $acl_result = 0;
 250          for ($i=0; $i < $this->acl_count; $i++) {
 251              if (strcasecmp( $aco_section_value, $this->acl[$i][0] ) == 0) {
 252                  if (strcasecmp( $aco_value, $this->acl[$i][1] ) == 0) {
 253                      if (strcasecmp( $aro_section_value, $this->acl[$i][2] ) == 0) {
 254                          if (strcasecmp( $aro_value, $this->acl[$i][3] ) == 0) {
 255                              if (strcasecmp( $axo_section_value, $this->acl[$i][4] ) == 0) {
 256                                  if (strcasecmp( $axo_value, $this->acl[$i][5] ) == 0) {
 257                                      $acl_result = 1;
 258                                      break;
 259                                  }
 260                              }
 261                          }
 262                      }
 263                  }
 264              }
 265          }
 266          return $acl_result;
 267      }
 268  
 269  }
 270  
 271  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics