Config.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2021 广州楚才信息科技有限公司 [ 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. /**
  31. * 系统参数配置
  32. * @auth true
  33. * @menu true
  34. */
  35. public function index()
  36. {
  37. $this->title = '系统参数配置';
  38. $this->isSuper = AdminService::instance()->isSuper();
  39. $this->version = ModuleService::instance()->getVersion();
  40. $this->fetch();
  41. }
  42. /**
  43. * 修改系统参数
  44. * @auth true
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. */
  49. public function system()
  50. {
  51. $this->_applyFormToken();
  52. if ($this->request->isGet()) {
  53. $this->title = '修改系统参数';
  54. $this->fetch();
  55. } else {
  56. if ($xpath = $this->request->post('xpath')) {
  57. if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $xpath)) {
  58. $this->error('后台入口名称需要是由英文字母开头!');
  59. }
  60. if ($xpath !== 'admin' && file_exists($this->app->getBasePath() . $xpath)) {
  61. $this->error("后台入口名称{$xpath}已经存在应用!");
  62. }
  63. SystemService::instance()->setRuntime(null, [$xpath => 'admin']);
  64. }
  65. foreach ($this->request->post() as $name => $value) sysconf($name, $value);
  66. sysoplog('系统配置管理', "修改系统参数成功");
  67. $this->success('修改系统参数成功!', sysuri("{$xpath}/index/index") . '#' . url("{$xpath}/config/index"));
  68. }
  69. }
  70. /**
  71. * 修改文件存储
  72. * @auth true
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\DbException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. */
  77. public function storage()
  78. {
  79. $this->_applyFormToken();
  80. if ($this->request->isGet()) {
  81. $this->type = input('type', 'local');
  82. if ($this->type === 'alioss') $this->points = AliossStorage::region();
  83. elseif ($this->type === 'qiniu') $this->points = QiniuStorage::region();
  84. elseif ($this->type === 'txcos') $this->points = TxcosStorage::region();
  85. $this->fetch("storage-{$this->type}");
  86. } else {
  87. $post = $this->request->post();
  88. if (!empty($post['storage']['allow_exts'])) {
  89. $deny = ['sh', 'asp', 'bat', 'cmd', 'exe', 'php'];
  90. $exts = array_unique(str2arr(strtolower($post['storage']['allow_exts'])));
  91. if (count(array_intersect($deny, $exts)) > 0) $this->error('禁止上传可执行的文件!');
  92. $post['storage']['allow_exts'] = join(',', $exts);
  93. }
  94. foreach ($post as $name => $value) sysconf($name, $value);
  95. sysoplog('系统配置管理', "修改系统存储参数");
  96. $this->success('修改文件存储成功!');
  97. }
  98. }
  99. }