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

Source for file pnSecurity.php

Documentation is available at pnSecurity.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright (c) 2001, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: pnSecurity.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_Core
  10.  * @subpackage pnAPI
  11.  */
  12.  
  13. /**
  14.  * Notes on security system
  15.  *
  16.  * Special UID and GIDS:
  17.  *  UID -1 corresponds to 'all users', includes unregistered users
  18.  *  GID -1 corresponds to 'all groups', includes unregistered users
  19.  *  UID 0 corresponds to unregistered users
  20.  *  GID 0 corresponds to unregistered users
  21.  */
  22.  
  23. /**
  24.  * Defines for access levels
  25.  */
  26. define('ACCESS_INVALID'-1);
  27. define('ACCESS_NONE'0);
  28. define('ACCESS_OVERVIEW'100);
  29. define('ACCESS_READ'200);
  30. define('ACCESS_COMMENT'300);
  31. define('ACCESS_MODERATE'400);
  32. define('ACCESS_EDIT'500);
  33. define('ACCESS_ADD'600);
  34. define('ACCESS_DELETE'700);
  35. define('ACCESS_ADMIN'800);
  36.  
  37. /**
  38.  * Translation functions - avoids globals in external code
  39.  */
  40. // Translate level -> name
  41. function accesslevelname($level)
  42. {
  43.     $accessnames accesslevelnames();
  44.     return $accessnames[$level];
  45. }
  46.  
  47. /**
  48.  * get access level names
  49.  *
  50.  * @return array of access names
  51.  */
  52. function accesslevelnames()
  53. {
  54.     static $accessnames array(  => _ACCESS_NONE,
  55.                                 100 => _ACCESS_OVERVIEW,
  56.                                 200 => _ACCESS_READ,
  57.                                 300 => _ACCESS_COMMENT,
  58.                                 400 => _ACCESS_MODERATE,
  59.                                 500 => _ACCESS_EDIT,
  60.                                 600 => _ACCESS_ADD,
  61.                                 700 => _ACCESS_DELETE,
  62.                                 800 => _ACCESS_ADMIN);
  63.  
  64.     return $accessnames;
  65. }
  66.  
  67. /**
  68.  * addinstanceschemainfo - register an instance schema with the security
  69.  * Will fail if an attempt is made to overwrite an existing schema
  70.  *
  71.  * @param unknown_type $component 
  72.  * @param unknown_type $schema 
  73.  */
  74. function addinstanceschemainfo($component$schema)
  75. {
  76.     pnSecAddSchema($component$schema);
  77. }
  78.  
  79. /**
  80.  * add security schema
  81.  *
  82.  * @param unknown_type $component 
  83.  * @param unknown_type $schema 
  84.  * @return bool 
  85.  */
  86. function pnSecAddSchema($component$schema)
  87. {
  88.     if (!empty($GLOBALS['schemas'][$component])) {
  89.         return false;
  90.     }
  91.  
  92.     $GLOBALS['schemas'][$component$schema;
  93.     return true;
  94. }
  95.  
  96. /**
  97.  * Enter description here...
  98.  *
  99.  * @deprecated
  100.  * @see SecurityUtil::checkPermission()
  101.  * @param unknown_type $testrealm 
  102.  * @param unknown_type $testcomponent 
  103.  * @param unknown_type $testinstance 
  104.  * @param unknown_type $testlevel 
  105.  * @return bool 
  106.  */
  107. function authorised($testrealm$testcomponent$testinstance$testlevel)
  108. {
  109.     // Wrapper for new pnSecAuthAction() function
  110.     return pnSecAuthAction($testrealm$testcomponent$testinstance$testlevel);
  111. }
  112.  
  113. /**
  114.  * see if a user is authorised to carry out a particular task
  115.  *
  116.  * @deprecated
  117.  * @see SecurityUtil::checkPermission()
  118.  * @param realm the realm under test
  119.  * @param component the component under test
  120.  * @param instance the instance under test
  121.  * @param level the level of access required
  122.  * @return bool true if authorised, false if not
  123.  */
  124. function pnSecAuthAction($testrealm$testcomponent$testinstance$testlevel$testuser=null)
  125. {
  126.     LogUtil::log('Function pnSecAuthAction() is deprecated. Please use SecurityUtil::checkPermission() instead.''STRICT');
  127.  
  128.     return SecurityUtil::checkPermission($testcomponent$testinstance$testlevel$testuser);
  129. }
  130.  
  131.  
  132. /**
  133.  * get authorisation information for this user
  134.  *
  135.  * @deprecated
  136.  * @see SecurityUtil::getAuthInfo()
  137.  * @return array two element array of user and group permissions
  138.  */
  139. function pnSecGetAuthInfo($testuser=null)
  140. {
  141.     LogUtil::log('Function pnSecGetAuthInfo() is deprecated. Please use SecurityUtil::getAuthInfo() instead.''STRICT');
  142.  
  143.     return SecurityUtil::getAuthInfo($testuser);
  144. }
  145.  
  146. /**
  147.  * calculate security level for a test item
  148.  *
  149.  * @deprecated
  150.  * @see SecurityUtil::getSecurityLevel
  151.  * @param perms array of permissions to test against
  152.  * @param testrealm realm of item under test
  153.  * @param testcomponent component of item under test
  154.  * @param testinstance instance of item under test
  155.  * @return int matching security level
  156.  */
  157. function pnSecGetLevel($perms$testrealm$testcomponent$testinstance)
  158. {
  159.     LogUtil::log('Function pnSecGetLevel() is deprecated. Please use SecurityUtil::getSecurityLevel() instead.''STRICT');
  160.  
  161.     return SecurityUtil::getSecurityLevel($perms$testcomponent$testinstance);
  162. }
  163.  
  164.  
  165. /**
  166.  * generate an authorisation key
  167.  *
  168.  * The authorisation key is used to confirm that actions requested by a
  169.  * particular user have followed the correct path.  Any stage that an
  170.  * action could be made (e.g. a form or a 'delete' button) this function
  171.  * must be called and the resultant string passed to the client as either
  172.  * a GET or POST variable.  When the action then takes place it first calls
  173.  * <code>pnSecConfirmAuthKey()</code> to ensure that the operation has
  174.  * indeed been manually requested by the user and that the key is valid
  175.  *
  176.  * @see SecurityUtil::generateAuthKey
  177.  * @param modname the module this authorisation key is for (optional)
  178.  * @return string an encrypted key for use in authorisation of operations
  179.  */
  180. function pnSecGenAuthKey($modname '')
  181. {
  182.     LogUtil::log('Function pnSecGenAuthKey() is deprecated. Please use SecurityUtil::generateAuthKey() instead.''STRICT');
  183.  
  184.     return SecurityUtil::generateAuthKey($modname);
  185. }
  186.  
  187.  
  188. /**
  189.  * confirm an authorisation key is valid
  190.  *
  191.  * See description of <code>pnSecGenAuthKey</code> for information on
  192.  * this function
  193.  *
  194.  * @see SecurityUtil::confirmAuthKey()
  195.  * @return bool true if the key is valid, false if it is not
  196.  */
  197. {
  198.     LogUtil::log('Function pnSecConfirmAuthKey() is deprecated. Please use SecurityUtil::confirmAuthKey() instead.''STRICT');
  199.  
  200.     return SecurityUtil::confirmAuthKey();
  201. }

Documentation generated on Fri, 18 Jul 2008 21:54:19 +0200 by phpDocumentor 1.4.1