Config.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\admin\controller;
  3. use think\admin\Controller;
  4. use think\admin\service\AdminService;
  5. use think\admin\service\ModuleService;
  6. use think\admin\service\SystemService;
  7. use think\admin\storage\AliossStorage;
  8. use think\admin\storage\QiniuStorage;
  9. use think\admin\storage\TxcosStorage;
  10. /**
  11. * 系统参数配置
  12. * Class Config
  13. * @package app\admin\controller
  14. */
  15. class Config extends Controller
  16. {
  17. /**
  18. * 系统参数配置
  19. * @auth true
  20. * @menu true
  21. */
  22. public function index()
  23. {
  24. $this->title = '系统参数配置';
  25. $this->isSuper = AdminService::instance()->isSuper();
  26. $this->version = ModuleService::instance()->getVersion();
  27. $this->fetch();
  28. }
  29. /**
  30. * 修改系统参数
  31. * @auth true
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public function system()
  37. {
  38. $this->_applyFormToken();
  39. if ($this->request->isGet()) {
  40. $this->title = '修改系统参数';
  41. $this->fetch();
  42. } else {
  43. if ($xpath = $this->request->post('xpath')) {
  44. if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $xpath)) {
  45. $this->error('后台入口名称需要是由英文字母开头!');
  46. }
  47. if ($xpath !== 'admin' && file_exists($this->app->getBasePath() . $xpath)) {
  48. $this->error("后台入口名称{$xpath}已经存在应用!");
  49. }
  50. SystemService::instance()->setRuntime(null, [$xpath => 'admin']);
  51. }
  52. foreach ($this->request->post() as $name => $value) {
  53. sysconf($name, $value);
  54. }
  55. sysoplog('系统配置管理', "修改系统参数成功");
  56. $this->success('修改系统参数成功!', sysuri("{$xpath}/index/index") . '#' . url("{$xpath}/config/index"));
  57. }
  58. }
  59. /**
  60. * 修改文件存储
  61. * @auth true
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\DbException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. */
  66. public function storage()
  67. {
  68. $this->_applyFormToken();
  69. if ($this->request->isGet()) {
  70. $this->type = input('type', 'local');
  71. if ($this->type === 'alioss') {
  72. $this->points = AliossStorage::region();
  73. } elseif ($this->type === 'qiniu') {
  74. $this->points = QiniuStorage::region();
  75. } elseif ($this->type === 'txcos') {
  76. $this->points = TxcosStorage::region();
  77. }
  78. $this->fetch("storage-{$this->type}");
  79. } else {
  80. $post = $this->request->post();
  81. if (!empty($post['storage']['allow_exts'])) {
  82. $deny = ['sh', 'asp', 'bat', 'cmd', 'exe', 'php'];
  83. $exts = array_unique(str2arr(strtolower($post['storage']['allow_exts'])));
  84. if (count(array_intersect($deny, $exts)) > 0) {
  85. $this->error('禁止上传可执行的文件!');
  86. }
  87. $post['storage']['allow_exts'] = join(',', $exts);
  88. }
  89. foreach ($post as $name => $value) {
  90. sysconf($name, $value);
  91. }
  92. sysoplog('系统配置管理', "修改系统存储参数");
  93. $this->success('修改文件存储成功!');
  94. }
  95. }
  96. }