priv

Posted dennylau

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了priv相关的知识,希望对你有一定的参考价值。

<?php

class priv
{
const GOD = 0;
const CMS = 1<<0;
const FLAG = 1<<1;
const HALL = 1<<2;
const APARTMENTS = 1<<3;

const MODULES = [
self::GOD => [‘name‘=>‘上帝‘,‘namespace‘=>[‘namespace‘]],
self::CMS => [‘name‘=>‘上帝‘,‘namespace‘=>[‘namespace‘]],
self::FLAG => [‘name‘=>‘上帝‘,‘namespace‘=>[‘namespace‘]],
self::HALL => [‘name‘=>‘上帝‘,‘namespace‘=>[‘namespace‘]],
self::APARTMENTS => [‘name‘=>‘上帝‘,‘namespace‘=>[‘namespace‘]],
];


const MODULES_METHOD = [
self::CMS => [
‘method‘ => [
‘name‘=>‘name1‘,
‘namespace‘=>‘namespace1‘,
‘priv_code‘=>1<<0,
]
],
self::FLAG => [
‘xxx‘ => [
‘name‘=>‘name1‘,
‘priv_code‘=>1<<0,
]
]
];

/**
* [resetPriv 全部重新授权]
* @param [type] $userPrivs [[array [moduleids,权限json]] moduleIds数据库默认是0
* @param [type] $moduleId [1,2,3,4]
* @param [type] $method [1=>[1,2,3],2=>[1,2,3,4]]
*/
public static function resetPriv($moduleIds,$methods=[])
{
$userPrivs[‘module_ids‘] = 0;
$userPrivs[‘method_ids‘] = []
foreach ($moduleId as $moduleId){
$userPrivs[‘module_ids‘] = $userPrivs[‘module_ids‘] | $moduleId;

if(isset($methods[$moduleId])){
$userPrivs[‘method_ids‘][$moduleId] = 0;
foreach ($methods[$moduleId] as $m){
$userPrivs[‘method_ids‘][$moduleId] = $userPrivs[‘method_ids‘][$moduleId] | $m;
}
}
}

return $userPrivs;
}

 

/**
* [checkPriv 权限判断]
* @param [type] $userPriv [array [模块id集合,权限json]
* @param [type] $systemPirv [‘namespace必填’,‘method选填‘]
* @return [bool] [true通过 false不通过]
*/
public static function checkPriv($userPrivs, $systemPirv){
if($userPrivs[‘module_ids‘] === 0){
return true;
}
$namespace = $systemPirv[‘namespace‘];
//0为不存在
$moduleId = self::moduleIdByNamespace($namespace);
if($moduleId === 0 ){
return false;
}

//模块权限
$modulePrivPass = $userPrivs[‘module_ids‘] & $moduleId;

//方法权限
//-1为命名空间下的都可以用
$methodPrivCode = $systemPirv[‘mothed‘] ?? -1;

if ($methodPrivCode == -1){
return true;
}

$methodPrivPass = $userPrivs[‘method_ids‘][$moduleId] & $methodPrivCode;

if ($modulePrivPass && $methodPrivPass){
return true;
}

return false;
}


/**
* [methodPriv description]
* @param [type] $moduleId [description]
* @param [type] $method [description]
* @return [type] [description]
*/
public static function methodPrivByMethod($moduleId,$method){
if(!isset(self::MODULES_METHOD[$moduleId])){
return 0;
}

return self::MODULES_METHOD[$moduleId][‘method‘][‘priv_code‘] ?? -1;
}
/**
* [moduleIdByNamespace 通过命名空间获取模块id]
* @param [type] $namespace [namespace]
* @return [type] [modules_id]
*/
public static function moduleIdByNamespace($namespace)
{
foreach (self::MODULES as $id => $module){
foreach ($module[‘namespace‘] as $ns){
if($systemPirv[0] == $ns) {
return $id
}
}
}

return 0;
}


public static function menus($userPrivs)
{
$menus = [];
foreach (self::MODULES as $id => $module){
$menus[$id][‘name‘] = $module[‘name‘];
$menus[$id][‘child‘] = [];
foreach (self::MODULES_METHOD[$id] as $m=> $methodDetail){
[$methodDetail[‘namespace‘],$methodDetail[‘me‘]
}

}
}
}

 

以上是关于priv的主要内容,如果未能解决你的问题,请参考以下文章

MySQL : --secure-file-priv

oracle确定被授予的对象权限

system下的app和priv-app有啥区别

C++程序在使用GDAL时为啥必须包含头文件:gdal_priv.h?gdal_priv.h包含的是啥文件?

小米三的system/priv-app在哪里呀?找不到这个文件夹,找到system,却找不到pri

priv