[继续摘抄]PHPBB3 权限系统分析

来源:互联网 发布:淘宝卖衣服怎么推广 编辑:程序博客网 时间:2024/06/05 22:34

PhpBB3 Permissions System Overview zh

From PHPBB用户手册

Jump to: navigation, search
[编辑]

PHPBB3 权限系统分析

这篇文章作为一个总览用于描述PHPBB3的权限系统和如何/从何处得到存储的权限相关数据, 以及如何进行使用. 当然本文并不是权限设置的用户指南, 虽然某些方面会有所提及. 我会尽最大的努力去了解代码以确保这些信息尽可能的正确... 但是这并不是一个官方的文档所以总会存在错误. 如果您发现了其中的错误请向我反映. (如果您使用英语的话, 请直接联系英文作者, 否则请在本文的讨论页指出, 或发表于phpbbchina论坛, 如果您对错误之处确信无误, 也可以直接修改, 但需要在讨论页声明修改的原因和时间).

什么是权限系统?
权限系统, 用于论坛管理员控制在论坛中用户能做什么, 不能做什么.

它如何工作?
拥有权限的管理员(当然... 管理员必须要有设置权限的权限) 可以访问管理员控制面板(ACP)并从管理员角度访问权限控制系统. 随後管理员可以为用户设置相应的权限或增添某项功能. 权限称为"权限选项", 用户通过直接, 或从用户组, 角色等途径间接获得这些权限选项所拥有的权利.

这些权限选项是?
这些选项允许或禁止用户行使某项功能. 例如 'f_post', 'm_delete', 'a_ban' 和 'u_sendpm'.

选项中的这些 f_, m_, a_ & u_ 是什么?
这些用于说明权限类型.

什么是权限类型?
权限类型分组一类权限. f_是版面权限类型. m_是版主权限类型. a_是管理员权限类型. u_是用户权限类型.

用户的权限数据保存在哪里?
存储在 phpbb_users 表单

在 phpbb_users 表单里面的哪些字段?
user_permissions - 保存用户权限. 我们在下文中将讨论如何更新这个字段.
user_perm_from - 如果您有 a_switchperm 权限, 您可以暂时使用另一个用户的权限. 如果您这样做这个字段将包含您暂时使用的用户的ID. 正常情况下这个字段为0

权限选项存储在哪里?
存储在表单 phpbb_acl_options.

权限选项 这个表单有哪些字段, 它们的含义是?

  • auth_option_id - 选项的唯一 ID
  • auth_option - 选项的名称
  • is_global - 如果是全站选项则设为1, 否则设为0
  • is_local - 如果是一个局部选项则设为1, 否则设为0
  • founder_only - 如果是一个创始人专用选项则设为1, 否则设为0

什么是局部权限选项?
局部权限选项用于授予用户基于版面的权限. 这允许管理员授予用户在单个版面中行使某个功能的权利. 局部权限.

什么是全站权限选项?
全站权限的有效范围是整个论坛.

一个权限选项可以既是全站的又是局部的吗?
可以. 一个选项可以既是全站的又是局部的. 例如 'm_edit' 这个选项, 它是版主是否能编辑话题的权限. 您可以在某个版面授予某用户这个权限, 然後在全站授予另一个用户这个权限. 要这么做的话, 这个选项的全站和局部属性都必须为1.

创始人专用选项是什么?
某些只能赋予创始人的选项.

默认的phpBB设置中有创始人专用选项吗?
没有.

创始人是什么?
创始人是特殊的用户. 最可靠最可信任的管理员才能被授予创始人的权力. 即使其他管理员删除了某个创始人的权限, 他也可以通过权限系统重新添加自己的权限. 只有创始人可以剥夺其他用户的创始人身份.

角色是什么?
角色是预先设置好的权限组合, 可以方便的应用到用户或用户组上. 如果您修改了某个角色的权限, 相应地使用此角色的用户和用户组也会自动更新他们的权限.

角色信息存储在哪里
它们存储在表单 phpbb_acl_roles.

这个表单中有哪些字段, 每个字段的含义?

  • role_id - 选项的唯一ID
  • role_name - 角色名称, 一般作为一个语言键字
  • role_description - 角色描述, 一般作为一个语言条目
  • role_type - a_, u_, m_ 或 f_, 由角色面向的对象决定
  • role_order - 数字, 决定这些角色在管理员控制面板中显示的次序

用于角色的权限选项存储在哪里?
存储在表单 phpbb_acl_roles_data.

这个表单有哪些字段, 每个字段的含义?

  • role_id - 表单phpbb_acl_roles的role id
  • auth_option_id - 表单phpbb_acl_options的option id
  • auth_setting - 值为 ACL_YES (1), ACL_NO (-1) 或 ACL_NEVER (0)

什么是 ACL_YES(是), ACL_NO(否) & ACL_NEVER(从不)?
用户的最终权限是由他所处的所有用户组和用户权限的集合合并得到的. 这种情况下, 不同的用户组可能会有互不相同的权限项设定. 三值(是, 否, 从不)模型可以方便易懂地合并各种选项. (从不)优先级高于其他两值, 任何一个权限项只要存在一个(从不), 那这个权限的最终值就是(从不). (是)高于(否), 如果一个权限项中存在(是)和(否), 只要有一个(是), 这个权限的最终值就是(是), 只有当一个权限项的所有值都是(否)时, 这个权限才是(否).

如果我给用户指定了角色, 这个信息存储在哪里?
存储在表单 phpbb_acl_users.

这个表单有哪些字段, 每个字段的含义是什么?

  • user_id - 表单phpbb_users中的用户ID
  • forum_id - 如果是局部权限, 则使用phpbb_forums中的版面ID, 否则为0
  • auth_option_id - phpbb_acl_options中的选项ID
  • auth_role_id - 如果是从角色中获取的权限, 则使用表单phpbb_acl_roles中的角色ID, 否则为0
  • auth_setting - 存储ACL_YES (1), ACL_NO (-1) 或 ACL_NEVER (0)

如果我给一个用户组指定了角色, 这个信息存储在哪里?
存储在表单 phpbb_acl_groups.

这个表单有哪些字段, 每个字段的含义是什么?

  • group_id - 表单phpbb_groups中的用户组ID
  • forum_id - 如果是局部权限, 则使用表单phpbb_forums中的版面ID, 否则为0
  • auth_option_id - 表单phpbb_acl_options中的权限ID
  • auth_role_id - 如果是从角色中获取的权限, 则使用表单phpbb_acl_roles中的角色ID, 否则为0
  • auth_setting - 存储ACL_YES (1), ACL_NO (-1) 或 ACL_NEVER (0)

现在我明白权限的各个组成部分的含义了, 我如何设定权限呢?
首先您需要考虑清楚您的目标是什么. 如果您需要设置某个用户增加某种额外权限, 那就按用户权限去设置. 否则最好是去设置用户组的权限, 然後将用户放到那个用户组中去. 如果您有好多权限选项需要设置, 那最好您还是用一个角色来完成这项工作. 另外, 您还需要弄明白这些选项是全局的还是局部的.

设定局部(版面)权限
从"权限" 页选择 "版面权限", "版面管理员(版主)", "用户的版面权限" 或 "用户组的版面权限". 如果您选择的是後两个, 您还需要选择您想要设定的目标版面.

设定高级权限选项和定义角色的页面在哪里?
Each of the tabs represents a permission category. Categories are used to further group permission options together.

So where in the ACP can permissions be setup?
The ACP can be configured to place this modules in multiple places.

OK. So I have setup the permissions I think. How can I view what permissions a user/group will get?
You view what permissions a user/group has by viewing its permission mask.

What are permission masks?
Masks are the effective permissions your user has for the different type of permission as we described already. You have user permissions, moderator permissions both local & global, forum permissions & administrator permissions. So for each of these you have a permission mask which can be viewed in the ACP. For forum permissions & moderator local permissions you need to select the forum you want to check first.

How do I workout permission masks?
From the "PERMISSIONS" tab select from "View administrative permissions", "View user-based permissions", "View global moderation permissions", "View forum moderation permissions" & "View forum-based permissions". If you select either of the last two you will first need to select the forum for which you are trying to view for.

When viewing masks you can view for mutiple/single user(s) or group(s). Permission for a group are set. However since permissions for a user can come from mutliple groups you can trace the permission.

What is tracing a permission?
When viewing the mask of permissions for a user a icon beside each option will show how the option got its value. It will start with the default value and then work through each group the user is a member of and then also the user direct permission at the end. For each group or finally the user permission it looks at the setting and updates the total. Remember a NEVER will wipe out any YES and a YES can not overwrite a NEVER. This is a very handy tool to determine why a user is getting or not getting a permission. The final total is the effective permission for any option.

当用户浏览网站时如何初始化其权限?
当用户(机器人和游客也是用户喔)浏览页面时, 对$user->session_begin()的调用会开始一个session; 然後对$auth->acl($user->data)的调用将初始化用户的权限.

函数$auth->acl 将检查用户的user_permission字段是否需要更新. 通过管理员控制面板更新权限时, 这个字段会被清空. 如果您设置的是单个用户权限, 则只有这个用户的记录下字段被清空, 否则所有用户的这个字段都会被清空. 当用户下一次登录时, acl函数会生成新的用户权限数据填入这个字段.

程序首先检查 _acl_options 的缓存并更新(如果需要重建用户权限). 如果缓存存在但是用户权限数据为空, 程序也会重建用户权限. 如果缓存和用户权限数据都存在则不做任何动作. 这个字段随後从bit流转换为数组, 程序使用这个数组检查用户的权限.

acl_options缓存包含哪些内容?
This cache contains an array which has two elements - local & global. Each of these is an array that contains each of the acl options of that type. As with all cache it checks if the cache is within a valid timeframe, if the timeframe is OK it will setup the array else just return.

So now the page has my users permissions setup how do I check if a user has a single permission option?
You call the $auth->acl_get('u_garage_browse'); and the argument is the option you want to check forIf it was specific to a forum (i.e local) then you do it as $auth->acl_get('u_garage_browse', 3); where 3 is the forum id

取自"http://www.phpbbchina.com/wiki/index.php/PhpBB3_Permissions_System_Overview_zh"

 

原创粉丝点击