Config.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  13. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  14. // +----------------------------------------------------------------------
  15. namespace app\admin\controller;
  16. use think\admin\Controller;
  17. use think\admin\service\AdminService;
  18. use think\admin\service\ModuleService;
  19. use think\admin\service\SystemService;
  20. use think\admin\storage\AliossStorage;
  21. use think\admin\storage\QiniuStorage;
  22. use think\admin\storage\TxcosStorage;
  23. /**
  24. * 系统参数配置
  25. * Class Config
  26. * @package app\admin\controller
  27. */
  28. class Config extends Controller
  29. {
  30. const themes = [
  31. 'default' => '默认色0',
  32. 'white' => '简约白0',
  33. 'red-1' => '玫瑰红1',
  34. 'blue-1' => '深空蓝1',
  35. 'green-1' => '小草绿1',
  36. 'black-1' => '经典黑1',
  37. 'red-2' => '玫瑰红2',
  38. 'blue-2' => '深空蓝2',
  39. 'green-2' => '小草绿2',
  40. 'black-2' => '经典黑2',
  41. ];
  42. /**
  43. * 系统参数配置
  44. * @auth true
  45. * @menu true
  46. */
  47. public function index()
  48. {
  49. $this->title = '系统参数配置';
  50. $this->super = AdminService::isSuper();
  51. $this->version = ModuleService::getVersion();
  52. $this->fetch();
  53. }
  54. /**
  55. * 修改系统参数
  56. * @auth true
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. */
  61. public function system()
  62. {
  63. $this->_applyFormToken();
  64. if ($this->request->isGet()) {
  65. $this->title = '修改系统参数';
  66. $this->themes = static::themes;
  67. $this->fetch();
  68. } else {
  69. $post = $this->request->post();
  70. // 修改网站后台入口路径
  71. if (!empty($post['xpath'])) {
  72. if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $post['xpath'])) {
  73. $this->error('后台入口名称需要是由英文字母开头!');
  74. }
  75. if ($post['xpath'] !== 'admin' && file_exists($this->app->getBasePath() . $post['xpath'])) {
  76. $this->error("后台入口名称{$post['xpath']}已经存在应用!");
  77. }
  78. SystemService::setRuntime(null, [$post['xpath'] => 'admin']);
  79. }
  80. // 修改网站 ICON 图标,替换 public/favicon.ico
  81. if (preg_match('#^https?://#', $icon = $post['site_icon'] ?? '')) try {
  82. SystemService::setFavicon($icon);
  83. } catch (\Exception $exception) {
  84. trace_file($exception);
  85. }
  86. // 数据数据到系统配置表
  87. foreach ($post as $k => $v) sysconf($k, $v);
  88. sysoplog('系统配置管理', "修改系统参数成功");
  89. $this->success('修改系统参数成功!', admuri('admin/config/index'));
  90. }
  91. }
  92. /**
  93. * 修改文件存储
  94. * @auth true
  95. * @throws \think\db\exception\DataNotFoundException
  96. * @throws \think\db\exception\DbException
  97. * @throws \think\db\exception\ModelNotFoundException
  98. */
  99. public function storage()
  100. {
  101. $this->_applyFormToken();
  102. if ($this->request->isGet()) {
  103. $this->type = input('type', 'local');
  104. if ($this->type === 'alioss') {
  105. $this->points = AliossStorage::region();
  106. } elseif ($this->type === 'qiniu') {
  107. $this->points = QiniuStorage::region();
  108. } elseif ($this->type === 'txcos') {
  109. $this->points = TxcosStorage::region();
  110. }
  111. $this->fetch("storage-{$this->type}");
  112. } else {
  113. $post = $this->request->post();
  114. if (!empty($post['storage']['allow_exts'])) {
  115. $deny = ['sh', 'asp', 'bat', 'cmd', 'exe', 'php'];
  116. $exts = array_unique(str2arr(strtolower($post['storage']['allow_exts'])));
  117. if (count(array_intersect($deny, $exts)) > 0) $this->error('禁止上传可执行的文件!');
  118. $post['storage']['allow_exts'] = join(',', $exts);
  119. }
  120. foreach ($post as $name => $value) sysconf($name, $value);
  121. sysoplog('系统配置管理', "修改系统存储参数");
  122. $this->success('修改文件存储成功!');
  123. }
  124. }
  125. /**
  126. * 聚合数据设置
  127. * @auth true
  128. * @menu true
  129. */
  130. public function juhe(){
  131. if($this->request->isGet()){
  132. $this->assign('row',sysconf('app_juhe_config'));
  133. $this->fetch();
  134. }else{
  135. sysconf('app_juhe_config',$this->request->post('row'));
  136. $this->success('成功');
  137. }
  138. }
  139. }