Main.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 中闽 < 1464674022@qq.com >
  5. * Date: 2019/12/5
  6. * Time: 17:44
  7. */
  8. namespace app\admin\controller;
  9. use app\admin\controller\base\Permissions;
  10. use app\admin\model\AdminLog;
  11. use app\admin\model\Urlconfig;
  12. use think\Cache;
  13. use think\Db;
  14. class Main extends Permissions
  15. {
  16. public function index()
  17. {
  18. //tp版本号
  19. $info['tp'] = THINK_VERSION;
  20. //php版本
  21. $info['php'] = PHP_VERSION;
  22. //操作系统
  23. $info['win'] = PHP_OS;
  24. //最大上传限制
  25. $info['upload_max_filesize'] = ini_get('upload_max_filesize');//不能使用ini_set修改
  26. $info['post_max_size'] = ini_get('post_max_size');//不能使用ini_set修改
  27. $info['memory_limit'] = ini_get('memory_limit');
  28. $info['tplay_filesize'] = \app\common\model\Webconfig::getValue('file_size') * 1024;
  29. //脚本执行时间限制
  30. $info['max_execution_time'] = ini_get('max_execution_time') . 'S';
  31. //运行环境
  32. // $sapi = php_sapi_name();
  33. // if ($sapi == 'apache2handler') {
  34. // $info['environment'] = 'apache';
  35. // } elseif ($sapi == 'cgi-fcgi') {
  36. // $info['environment'] = 'cgi';
  37. // } elseif ($sapi == 'cli') {
  38. // $info['environment'] = 'cli';
  39. // } else {
  40. // $info['environment'] = $sapi;
  41. // }
  42. $info['environment'] = $_SERVER['SERVER_SOFTWARE'];
  43. try {
  44. //剩余空间大小,服务器没有权限会报错
  45. $info['disk'] = format_bytes(disk_free_space("/"));
  46. } catch (\Exception $e) {
  47. }
  48. $this->assign('info', $info);
  49. //==============网站数据=============================
  50. //会员
  51. $web['user_num'] = Db::name('user')->where('status', \app\common\model\User::STATUS_PASS)->count();
  52. $web['user_num_wait'] = Db::name('user')->where('status', \app\common\model\User::STATUS_WAIT)->count();
  53. //文章
  54. $web['article_num'] = Db::name('article')->count();
  55. $web['status_article'] = Db::name('article')->where('status', 0)->count();
  56. //附件
  57. $web['file_num'] = Db::name('attachment')->count();
  58. $web['status_file'] = Db::name('attachment')->where('status', 0)->count();
  59. //消息
  60. $web['message_num'] = Db::name('messages')->count();
  61. $web['look_message'] = Db::name('messages')->where('is_look', 0)->count();
  62. //==============管理员操作记录===========================
  63. $today = date('Y-m-d');
  64. //取当前时间的前十天
  65. $date = [];
  66. $date_string = '';
  67. for ($i = 9; $i > 0; $i--) {
  68. $date[] = date("Y-m-d", strtotime("-{$i} day"));
  69. $date_string .= date("Y-m-d", strtotime("-{$i} day")) . ',';
  70. }
  71. $date[] = $today;
  72. $date_string .= $today;
  73. $web['date_string'] = $date_string;
  74. $login_sum = '';
  75. foreach ($date as $k => $val) {
  76. $min_time = strtotime($val);
  77. $max_time = $min_time + 60 * 60 * 24;
  78. $where['create_time'] = [['>=', $min_time], ['<=', $max_time]];
  79. $login_sum .= Db::name('admin_log')->where('params', '<>', '')->where($where)->count() . ',';
  80. }
  81. $web['login_sum'] = $login_sum;
  82. $this->assign('web', $web);
  83. //==============风险提示=============================
  84. $safe = true;
  85. if (file_exists(APP_PATH . 'install')) {
  86. $safe = false;
  87. //提示删除install目录
  88. $this->assign('delete_install', true);
  89. }
  90. //提示改密码
  91. $weekpass = Db::name('admin')->where('id', session(self::ADMIN_ID))->where('password', password('123456'))->count();
  92. if ($weekpass > 0) {
  93. $safe = false;
  94. $this->assign('weekpass', true);
  95. if (!in_array($this->request->ip(), ['0.0.0.0', '127.0.0.1'])) {
  96. $this->assign('waring', ['msg' => "当前密码过于简单,是否立即修改?", "url" => url('admin/admin/editpassword')]);
  97. }
  98. }
  99. //提示设置安全入口
  100. if ((new Urlconfig())->isWeekBackend()) {
  101. $safe = false;
  102. $this->assign('week_backend', true);
  103. }
  104. if (session(self::ADMIN_CATE_ID) == \app\admin\model\Admin::SUPER_ADMIN_ID) {
  105. //登录请求过多,防止被爆破,提示管理员修改后台地址
  106. if ((new AdminLog())->where(['admin_menu_id' => '50', 'params' => ['<>', '']])->whereTime('create_time', 'today')->count() > 100) {
  107. $this->assign('waring', ['msg' => "今日发现多次登录请求,是否立即修改后台地址?", "url" => url('admin/urlsconfig/index')]);
  108. }
  109. }
  110. $this->assign('safe', $safe);
  111. return $this->fetch();
  112. }
  113. /**
  114. * 清除全部缓存
  115. */
  116. public function clear()
  117. {
  118. if (false == Cache::clear()) {
  119. $this->error('清除缓存失败');
  120. } else {
  121. $this->success('清除缓存成功');
  122. }
  123. }
  124. }