Index.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\sys\controller;
  4. use think\facade\App;
  5. use think\facade\Db;
  6. use think\facade\Config;
  7. use think\facade\View;
  8. class Index extends Base
  9. {
  10. public function index()
  11. {
  12. // 系统信息
  13. $mysqlVersion = Db::query('SELECT VERSION() AS ver');
  14. $config = [
  15. 'url' => $_SERVER['HTTP_HOST'],
  16. 'document_root' => $_SERVER['DOCUMENT_ROOT'],
  17. 'server_os' => PHP_OS,
  18. 'server_port' => $_SERVER['SERVER_PORT'],
  19. 'server_ip' => isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '',
  20. 'server_soft' => $_SERVER['SERVER_SOFTWARE'],
  21. 'php_version' => PHP_VERSION,
  22. 'mysql_version' => $mysqlVersion[0]['ver'],
  23. 'max_upload_size' => ini_get('upload_max_filesize'),
  24. 'tp_version' => App::version(),
  25. ];
  26. View::assign([
  27. 'config' => $config,
  28. // 'user' => $user,
  29. // 'message' => $message ?? 0,
  30. // 'messageCatUrl' => $messageCatUrl,
  31. 'indexTips' => $this->getIndexTips(),
  32. ]);
  33. return View::fetch('index');
  34. }
  35. // 检查提示信息
  36. private function getIndexTips()
  37. {
  38. $user = $this->getSysUser();
  39. $defaultPassword = Config::get('app.default_password') ?: 'admin';
  40. if ($user->password == md5($defaultPassword.$user->salt)) {
  41. return '<h6 class="mb-0"><i class="icon fas fa-fw fa-exclamation-triangle"></i> 请尽快修改后台初始密码!</h6>';
  42. }
  43. return '';
  44. }
  45. public function usedspace()
  46. {
  47. if ($this->request->isAjax()) {
  48. $dirname = $this->app->getRootPath();
  49. $dirsize = get_dir_size($dirname);
  50. return ['code'=>0, 'size'=>format_bytes($dirsize)];
  51. }
  52. }
  53. public function clearcache()
  54. {
  55. if ($this->request->isAjax()) {
  56. $runtime_path = $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR;
  57. try {
  58. $cache_dir = $runtime_path . 'cache' . DIRECTORY_SEPARATOR;
  59. $admin_dir = $runtime_path . 'admin' . DIRECTORY_SEPARATOR;
  60. $index_dir = $runtime_path . 'index' . DIRECTORY_SEPARATOR;
  61. $api_dir = $runtime_path . 'api' . DIRECTORY_SEPARATOR;
  62. deldir($cache_dir);
  63. deldir($admin_dir);
  64. deldir($index_dir);
  65. deldir($api_dir);
  66. } catch (\Exception $e) {
  67. return ['code'=>0, 'msg'=>$e->getMessage()];
  68. }
  69. return ['code'=>1, 'msg'=>'清除成功'];
  70. }
  71. }
  72. }