AuthAction.class.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. //后台验证的基础类
  10. class AuthAction extends BaseAction{
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. $this->check_auth();
  15. }
  16. /**
  17. * 验证检限
  18. * 已登录时验证用户权限, Index模块下的所有函数无需权限验证
  19. * 未登录时跳转登录
  20. */
  21. private function check_auth()
  22. {
  23. $ajax = intval($_REQUEST['ajax']);
  24. //管理员的SESSION
  25. $adm_session = es_session::get(md5(conf("AUTH_KEY")));
  26. $adm_name = $adm_session['adm_name'];
  27. $adm_id = intval($adm_session['adm_id']);
  28. if($adm_id==0){
  29. if($ajax == 0)
  30. $this->redirect("Public/login");
  31. else
  32. $this->error(L("NO_LOGIN"),$ajax);
  33. }
  34. if(intval(app_conf('EXPIRED_TIME'))>0&&$adm_id!=0){
  35. $admin_logined_time = intval($adm_session['admin_logined_time']);
  36. $max_time = intval(app_conf('EXPIRED_TIME'))*60;
  37. if(NOW_TIME-$admin_logined_time>=$max_time)
  38. {
  39. es_session::delete((md5(conf("AUTH_KEY"))));
  40. $this->display();
  41. }
  42. }
  43. //$biz_account = es_session::get("account_info");
  44. $user_info = es_session::get("user_info");
  45. $is_auth = 0;
  46. if(intval($user_info['id'])>0) //会员允许使用后台上传功能
  47. {
  48. if((MODULE_NAME=='File'&&ACTION_NAME=='do_upload')||(MODULE_NAME=='File'&&ACTION_NAME=='do_upload_img'))
  49. {
  50. $is_auth = 1;
  51. }
  52. }
  53. $has_node_id =intval($GLOBALS['db']->getOne("select count(*) from ".conf("DB_PREFIX")."role_node as role_node " .
  54. "left join ".conf("DB_PREFIX")."role_module as role_module on role_module.id = role_node.module_id where role_node.action ='".ACTION_NAME."' and role_module.module = '".MODULE_NAME."' and role_node.is_effect = 1 and role_node.is_delete = 0 " .
  55. "and role_module.is_effect = 1 and role_module.is_delete = 0 "));
  56. if(!$has_node_id){
  57. $is_auth = 1;
  58. }
  59. if($adm_id == 0&&$is_auth==0)
  60. {
  61. if($ajax == 0)
  62. $this->redirect("Public/login");
  63. else
  64. $this->error(L("NO_LOGIN"),$ajax);
  65. }
  66. //var_dump($action_id);exit;
  67. if($adm_name == app_conf("DEFAULT_ADMIN")||MODULE_NAME =='File'||MODULE_NAME =='Index'||MODULE_NAME=='Lang'||ACTION_NAME=='insert'||ACTION_NAME=='update'||MODULE_NAME=='Cache'||MODULE_NAME=='load_module'){
  68. $is_auth = 1;
  69. }
  70. //开始验证权限,当管理员名称不为默认管理员时
  71. //开始验证模块是否需要授权
  72. $sql = "select count(*) as c from ".conf("DB_PREFIX")."role_node as role_node left join ".
  73. conf("DB_PREFIX")."role_module as role_module on role_module.id = role_node.module_id ".
  74. " where role_node.action ='".ACTION_NAME."' and role_module.module = '".MODULE_NAME."'".
  75. " and role_node.is_effect = 1 and role_node.is_delete = 0 and role_module.is_effect = 1 and role_module.is_delete = 0 ";
  76. $count = M()->query($sql);
  77. $count = $count[0]['c'];
  78. if($count==0&&$is_auth==0){
  79. $this->error(L("NO_AUTH"),$ajax);
  80. }
  81. if($is_auth==0)
  82. {
  83. //除IndexAction外需验证的权限列表
  84. $sql = "select count(*) as c from ".conf("DB_PREFIX")."role_node as role_node left join ".
  85. conf("DB_PREFIX")."role_access as role_access on role_node.id=role_access.node_id left join ".
  86. conf("DB_PREFIX")."role as role on role_access.role_id = role.id left join ".
  87. conf("DB_PREFIX")."role_module as role_module on role_module.id = role_node.module_id left join ".
  88. conf("DB_PREFIX")."admin as admin on admin.role_id = role.id ".
  89. " where admin.id = ".$adm_id." and role_node.action ='".ACTION_NAME."' and role_module.module = '".MODULE_NAME."'".
  90. " and role_node.is_effect = 1 and role_node.is_delete = 0 and role_module.is_effect = 1 and role_module.is_delete = 0 and role.is_effect = 1 and role.is_delete = 0";
  91. $count = M()->query($sql);
  92. $count = $count[0]['c'];
  93. if($count == 0)
  94. {
  95. //节点授权不足,开始判断是否有模块授权
  96. $module_sql = "select count(*) as c from ".conf("DB_PREFIX")."role_access as role_access left join ".
  97. conf("DB_PREFIX")."role as role on role_access.role_id = role.id left join ".
  98. conf("DB_PREFIX")."role_module as role_module on role_module.id = role_access.module_id left join ".
  99. conf("DB_PREFIX")."admin as admin on admin.role_id = role.id ".
  100. " where admin.id = ".$adm_id." and role_module.module = '".MODULE_NAME."'".
  101. " and role_access.node_id = 0".
  102. " and role_module.is_effect = 1 and role_module.is_delete = 0 and role.is_effect = 1 and role.is_delete = 0";
  103. $module_count = M()->query($module_sql);
  104. $module_count = $module_count[0]['c'];
  105. if($module_count == 0)
  106. {
  107. if((MODULE_NAME=='File'&&ACTION_NAME=='do_upload')||(MODULE_NAME=='File'&&ACTION_NAME=='do_upload_img'))
  108. {
  109. echo "<script>alert('".L("NO_AUTH")."');</script>";
  110. exit;
  111. }
  112. else
  113. $this->error(L("NO_AUTH"),$ajax);
  114. }
  115. }
  116. }
  117. }
  118. //index列表的前置通知,输出页面标题
  119. public function _before_index()
  120. {
  121. $this->assign("main_title",L(MODULE_NAME."_INDEX"));
  122. }
  123. public function _before_trash()
  124. {
  125. $this->assign("main_title",L(MODULE_NAME."_INDEX"));
  126. }
  127. }
  128. ?>