PublicController.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller;
  12. use app\Request;
  13. use app\services\system\attachment\SystemAttachmentServices;
  14. use app\services\system\SystemRouteServices;
  15. use crmeb\services\CacheService;
  16. use think\facade\Env;
  17. use think\Response;
  18. use think\facade\Db;
  19. class PublicController
  20. {
  21. /**
  22. * 下载文件
  23. * @param string $key
  24. * @return Response|\think\response\File
  25. */
  26. public function download(Request $request, string $key = '')
  27. {
  28. if ($key == '') {
  29. $key = $request->getMore([
  30. ['key', ''],
  31. ], true);
  32. }
  33. if (!$key) {
  34. return Response::create()->code(500);
  35. }
  36. $fileName = CacheService::get($key);
  37. if (is_array($fileName) && isset($fileName['path']) && isset($fileName['fileName']) && $fileName['path'] && $fileName['fileName'] && file_exists($fileName['path'])) {
  38. CacheService::delete($key);
  39. return download($fileName['path'], $fileName['fileName']);
  40. }
  41. return Response::create()->code(500);
  42. }
  43. /**
  44. * 获取workerman请求域名
  45. * @return mixed
  46. */
  47. public function getWorkerManUrl()
  48. {
  49. return app('json')->success(getWorkerManUrl());
  50. }
  51. /**
  52. * 扫码上传
  53. * @param Request $request
  54. * @param int $upload_type
  55. * @param int $type
  56. * @return Response
  57. * @author 吴汐
  58. * @email 442384644@qq.com
  59. * @date 2023/06/13
  60. */
  61. public function scanUpload(Request $request, $upload_type = 0, $type = 0)
  62. {
  63. [$file, $uploadToken, $pid] = $request->postMore([
  64. ['file', 'file'],
  65. ['uploadToken', ''],
  66. ['pid', 0]
  67. ], true);
  68. $service = app()->make(SystemAttachmentServices::class);
  69. if (CacheService::get('scan_upload') != $uploadToken) {
  70. return app('json')->fail(410086);
  71. }
  72. $service->upload((int)$pid, $file, $upload_type, $type, '', $uploadToken);
  73. return app('json')->success(100032);
  74. }
  75. public function import(Request $request)
  76. {
  77. $filePath = $request->param('file_path', '');
  78. if (empty($filePath)) {
  79. return app('json')->fail(12894);
  80. }
  81. app()->make(SystemRouteServices::class)->import($filePath);
  82. return app('json')->success(100010);
  83. }
  84. /**
  85. * 服务器信息
  86. * @return \think\Response
  87. * @author wuhaotian
  88. * @email 442384644@qq.com
  89. * @date 2024/9/24
  90. */
  91. public function getSystemInfo()
  92. {
  93. $info['server'] = [
  94. ['name' => '服务器系统', 'require' => '类UNIX', 'value' => PHP_OS],
  95. ['name' => 'WEB环境', 'require' => 'Apache/Nginx/IIS', 'value' => $_SERVER['SERVER_SOFTWARE']],
  96. ];
  97. $gd_info = function_exists('gd_info') ? gd_info() : array();
  98. $info['environment'] = [
  99. ['name' => 'PHP版本', 'require' => '7.1-7.4', 'value' => phpversion()],
  100. ['name' => 'MySql版本', 'require' => '5.6-8.0', 'value' => Db::query("SELECT VERSION()")[0]['VERSION()']],
  101. ['name' => 'MySqli', 'require' => '开启', 'value' => function_exists('mysqli_connect')],
  102. ['name' => 'Openssl', 'require' => '开启', 'value' => function_exists('openssl_encrypt')],
  103. ['name' => 'Session', 'require' => '开启', 'value' => function_exists('session_start')],
  104. ['name' => 'Safe_Mode', 'require' => '开启', 'value' => !ini_get('safe_mode')],
  105. ['name' => 'GD', 'require' => '开启', 'value' => !empty($gd_info['GD Version'])],
  106. ['name' => 'Curl', 'require' => '开启', 'value' => function_exists('curl_init')],
  107. ['name' => 'Bcmath', 'require' => '开启', 'value' => function_exists('bcadd')],
  108. ['name' => 'Upload', 'require' => '开启', 'value' => (bool)ini_get('file_uploads')],
  109. ];
  110. $info['permissions'] = [
  111. ['name' => 'backup', 'require' => '读写', 'value' => is_readable(root_path('backup')) && is_writable(root_path('backup'))],
  112. ['name' => 'public', 'require' => '读写', 'value' => is_readable(root_path('public')) && is_writable(root_path('public'))],
  113. ['name' => 'runtime', 'require' => '读写', 'value' => is_readable(root_path('runtime')) && is_writable(root_path('runtime'))],
  114. ['name' => '.env', 'require' => '读写', 'value' => is_readable(root_path() . '.env') && is_writable(root_path() . '.env')],
  115. ['name' => '.version', 'require' => '读写', 'value' => is_readable(root_path() . '.version') && is_writable(root_path() . '.version')],
  116. ['name' => '.constant', 'require' => '读写', 'value' => is_readable(root_path() . '.constant') && is_writable(root_path() . '.constant')],
  117. ];
  118. if (function_exists('exec')) {
  119. $workermanOutput = $timerOutput = $queueOutput = [];
  120. exec("ps aux | grep 'php think workerman' | grep -v grep", $workermanOutput);
  121. exec("ps aux | grep 'php think timer' | grep -v grep", $timerOutput);
  122. exec("ps aux | grep 'php think queue' | grep -v grep", $queueOutput);
  123. $info['process'] = [
  124. ['name' => '长链接', 'require' => '开启', 'value' => count($workermanOutput) > 0],
  125. ['name' => '定时任务', 'require' => '开启', 'value' => count($timerOutput) > 0],
  126. ['name' => '消息队列', 'require' => '开启', 'value' => count($queueOutput) > 0],
  127. ];
  128. } else {
  129. $info['process'] = [
  130. ['name' => '长链接', 'require' => '开启', 'value' => file_exists(root_path('runtime') . 'workerman.pid')],
  131. ['name' => '定时任务', 'require' => '开启', 'value' => file_exists(root_path('runtime') . '.timer')],
  132. ['name' => '消息队列', 'require' => '开启', 'value' => file_exists(root_path('runtime') . '.queue')],
  133. ];
  134. }
  135. return app('json')->success($info);
  136. }
  137. public function customAdminJs()
  138. {
  139. return sys_config('custom_admin_js', '');
  140. }
  141. }