| Server IP : 156.238.232.47 / Your IP : 216.73.216.150 Web Server : nginx/1.25.3 System : Linux C202504152095410 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : www ( 1000) PHP Version : 8.3.25 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /www/data/wwwroot/2025_04_20_01-副本/application/admin/behavior/ |
Upload File : |
<?php
namespace app\admin\behavior;
use think\Db;
/**
* ���ԱȨ����
*/
load_trait('controller/Jump');
class AuthRoleBehavior
{
use \traits\controller\Jump;
protected static $actionName;
protected static $controllerName;
protected static $moduleName;
protected static $method;
protected static $admin_info;
/**
* ���췽��
* @param Request $request Request����
* @access public
*/
public function __construct()
{
!isset(self::$moduleName) && self::$moduleName = request()->module();
!isset(self::$controllerName) && self::$controllerName = request()->controller();
!isset(self::$actionName) && self::$actionName = request()->action();
!isset(self::$method) && self::$method = request()->method();
!isset(self::$admin_info) && self::$admin_info = session('admin_info');
/*$result = Db::name('admin')
->field("b.*, b.name AS role_name")
->alias('a')
->join('__AUTH_ROLE__ b', 'a.role_id = b.id', 'LEFT')
->where('a.admin_id','eq', self::$admin_info['admin_id'])
->find();
if (!empty($result['id'])) {
$result['language'] = safe_unserialize($result['language']);
$result['cud'] = safe_unserialize($result['cud']);
$result['permission'] = safe_unserialize($result['permission']);
self::$admin_info['auth_role_info'] = $result;
}*/
}
/**
* ģ��ʼ��
* @param array $params ������
* @access public
*/
public function moduleInit(&$params)
{
}
/**
* �����ʼִ��
* @param array $params ������
* @access public
*/
public function actionBegin(&$params)
{
if (0 < intval(self::$admin_info['role_id'])) {
// ���ȫ�ֵ�����ġ�ɾ��Ȩ�ޡ������ȼ����
$this->cud_access();
// ���ÿ��С����Ȩ��
$this->weapp_access();
// ���Ŀ����ÿ����ĿȨ��
$this->arctype_access();
// ������ݹ��ÿ����Ŀ��Ӧ�������б��Ȩ��
$this->archives_access();
}
}
/**
* ��ͼ���ݹ���
* @param array $params ������
* @access public
*/
public function viewFilter(&$params)
{
}
/**
* Ӧ�ý��
* @param array $params ������
* @access public
*/
public function appEnd(&$params)
{
}
/**
* ���ȫ�ֵ�����ġ�ɾ��Ȩ��
* @access private
*/
private function cud_access()
{
/*ֻ����Ӧ�Ŀ�����Ͳ�����ִ�У��Ա��������*/
$ctl = strtolower(self::$controllerName);
$act = strtolower(self::$actionName);
if ('archives' == $ctl && in_array($act, ['check','uncheck'])) { // �����Ϣ\ȡ������Ϣ
$act = 'changetableval';
}
$actArr = ['add','edit','del','rebackdraft'];
if ('weapp' == $ctl && 'execute' == $act) {
$sa = input('param.sa/s');
foreach ($actArr as $key => $cud) {
$sa = preg_replace('/^(.*)_('.$cud.')$/i', '$2', $sa); // ͬ�add ������_add���ƽ�β������
if ($sa == $cud) {
$admin_info = self::$admin_info;
$auth_role_info = !empty($admin_info['auth_role_info']) ? $admin_info['auth_role_info'] : [];
$cudArr = !empty($auth_role_info['cud']) ? $auth_role_info['cud'] : [];
if (!in_array($sa, $cudArr)) {
$this->error('�û�в��Ȩ�ޣ���ϵ�������Ա����Ȩ��');
}
break;
}
}
} else {
$post = input('post.');
array_push($actArr, 'changetableval'); // �����Ϣ
foreach ($actArr as $key => $cud) {
$act = preg_replace('/^(.*)_('.$cud.')$/i', '$2', $act); // ͬ�add ������_add���ƽ�β������
if ($act == $cud) {
$admin_info = self::$admin_info;
$auth_role_info = !empty($admin_info['auth_role_info']) ? $admin_info['auth_role_info'] : [];
$cudArr = !empty($auth_role_info['cud']) ? $auth_role_info['cud'] : [];
if (!in_array($act, $cudArr)) {
if ('changetableval' == $act && 'index' == $ctl) {
// �����Ϣ
if ('archives' == $post['table'] && 'arcrank' == $post['field']) {
$this->error('�û�в��Ȩ�ޣ���ϵ�������Ա����Ȩ��', null, '', 2);
}
} else {
$this->error('�û�в��Ȩ�ޣ���ϵ�������Ա����Ȩ��');
}
} else {
if (!in_array('changetableval', $cudArr)) {
// �����Ϣ
if (IS_POST && 'edit' == $act) {
$archivesInfo = M('archives')->field('arcrank,admin_id')->find($post['aid']);
if (-1 == $archivesInfo['arcrank'] && isset($post['arcrank']) && $archivesInfo['arcrank'] != $post['arcrank']) {
$this->error('�û�в��Ȩ�ޣ���ϵ�������Ա����Ȩ��', url('Archives/edit', ['id'=>$post['aid']]), '', 3);
}
}
}
}
break;
}
}
}
/*--end*/
}
/**
* ���ÿ��С����Ȩ��
* @access private
*/
private function weapp_access()
{
/*ֻ����Ӧ�Ŀ�����Ͳ�����ִ�У��Ա��������*/
$ctl = strtolower(self::$controllerName);
$act = strtolower(self::$actionName);
if ('weapp' == $ctl) {
if ('execute' == $act) {
$sc = input('param.sc/s');
$sm = input('param.sm/s');
$sa = input('param.sa/s');
$admin_info = self::$admin_info;
$auth_role_info = !empty($admin_info['auth_role_info']) ? $admin_info['auth_role_info'] : [];
$plugins = !empty($auth_role_info['permission']['plugins']) ? $auth_role_info['permission']['plugins'] : [];
// ���������õ�Ȩ��б�
$config = include WEAPP_PATH.$sm.DS.'config.php';
$plugins_permission = !empty($config['permission']) ? array_keys($config['permission']) : [];
// ���Աӵ�еIJ�����Ȩ��
$admin_permission = !empty($plugins[$sm]['child']) ? $plugins[$sm]['child'] : [];
// û�и������Ա�IJ�����Ȩ��
$diff_plugins_perm = array_diff($plugins_permission, $admin_permission);
// ����Ȩ��
$bool = true;
if (empty($plugins_permission) && !isset($plugins[$sm])) {
$bool = false;
} else if (!empty($plugins_permission)) {
foreach ($diff_plugins_perm as $key => $val) {
if (strtolower($sm.'@'.$sa) == strtolower($val)) {
$bool = false;
break;
}
}
}
if (!$bool) {
$this->error('�û�в��Ȩ�ޣ���ϵ�������Ա����Ȩ��');
}
} else if (in_array($act, ['plugin','mybuy'])) {
if (0 < intval(session('admin_info.role_id'))) {
$this->error('�û�в��Ȩ�ޣ�ֻ����ʼ�˺ͳ������Ա���');
}
}
}
/*--end*/
}
/**
* ���Ŀ����ÿ����ĿȨ��
* @access private
*/
private function arctype_access()
{
/*ֻ����Ӧ�Ŀ�����Ͳ�����ִ�У��Ա��������*/
$ctl_all = strtolower(self::$controllerName.'@*');
$ctlArr = ['arctype@*'];
if (in_array($ctl_all, $ctlArr)) {
$typeids = [];
if (in_array(strtolower(self::$actionName), ['edit','del'])) {
$typeids[] = input('id/d', 0);
} else if (in_array(strtolower(self::$actionName), ['add'])) {
$typeids[] = input('parent_id/d', 0);
}
if (!$this->is_check_arctype($typeids)) {
$this->error('�û�в��Ȩ�ޣ���ϵ�������Ա����Ȩ��');
}
}
/*--end*/
}
/**
* ������ݹ��ÿ����Ŀ��Ӧ�������б��Ȩ��
* @access private
*/
private function archives_access()
{
/*ֻ����Ӧ�Ŀ�����Ͳ�����ִ�У��Ա��������*/
$ctl = strtolower(self::$controllerName);
$act = strtolower(self::$actionName);
$ctl_act = $ctl.'@'.$act;
$ctl_all = $ctl.'@*';
$ctlArr= ['arctype@single','archives@*'];
$row = \think\Db::name('channeltype')
->where('nid','NOTIN', ['single'])
->column('ctl_name');
foreach ($row as $key => $val) {
array_push($ctlArr, strtolower($val).'@*');
}
if (in_array($ctl_act, $ctlArr) || in_array($ctl_all, $ctlArr)) {
$typeids = [];
if (in_array($act, ['add','edit','del'])) {
$aids = [];
switch ($act) {
case 'edit':
$aids = input('id/a', []);
break;
case 'del':
$aids = input('del_id/a', []);
break;
default:
# code...
break;
}
if (!empty($aids)) {
$typeids = M('archives')->where('aid','IN',$aids)->column('typeid');
}
} else {
$typeids[] = input('typeid/d', 0);
}
if (!$this->is_check_arctype($typeids)) {
$this->error('�û�в��Ȩ�ޣ���ϵ�������Ա����Ȩ��');
}
}
/*--end*/
}
/**
* ���Ŀ�Ƿ���Ȩ��
*/
private function is_check_arctype($typeids = []) {
$bool_flag = true;
$admin_info = self::$admin_info;
if (0 < intval($admin_info['role_id'])) {
$auth_role_info = $admin_info['auth_role_info'];
$permission = $auth_role_info['permission'];
foreach ($typeids as $key => $tid) {
if (0 < intval($tid) && !in_array($tid, $permission['arctype'])) {
$bool_flag = false;
break;
}
}
}
return $bool_flag;
}
}