mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2026-11-17 17:13:34 +08:00
背景与目的:方法覆盖可使非 POST 请求进入原有写入分支,需要与已升级组件的表单令牌防护共同约束后台写操作。 主要改动:两个接口按 ThinkPHP 解析后的方法仅允许 GET 和 POST,其余方法返回 HTTP 405 与 Allow 响应头,覆盖表单及请求头方法覆盖。 影响范围与兼容性:保留 GET 表单、合法 POST、令牌字段及请求头兼容;存储配置继续优先执行演示环境拦截,不调整权限和成功响应。 验证入口及实际结果:在临时应用中复用 check-form-token.php,加载本项目控制器与已安装依赖,以内存会话和 SQLite 验证,178/178 通过;PHP 语法与差异检查通过。未进行浏览器或真实服务验收。
170 lines
6.3 KiB
PHP
170 lines
6.3 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
/**
|
||
* +----------------------------------------------------------------------
|
||
* | ThinkAdmin Plugin for ThinkAdmin
|
||
* +----------------------------------------------------------------------
|
||
* | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ]
|
||
* +----------------------------------------------------------------------
|
||
* | 官方网站: https://thinkadmin.top
|
||
* +----------------------------------------------------------------------
|
||
* | 开源协议 ( https://mit-license.org )
|
||
* | 免责声明 ( https://thinkadmin.top/disclaimer )
|
||
* | 会员特权 ( https://thinkadmin.top/vip-introduce )
|
||
* +----------------------------------------------------------------------
|
||
* | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
|
||
* | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
|
||
* +----------------------------------------------------------------------
|
||
*/
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use app\admin\service\UploadSecurity;
|
||
use think\admin\Controller;
|
||
use think\admin\Plugin;
|
||
use think\admin\service\AdminService;
|
||
use think\admin\service\ModuleService;
|
||
use think\admin\service\RuntimeService;
|
||
use think\admin\service\SystemService;
|
||
use think\admin\Storage;
|
||
use think\admin\storage\AliossStorage;
|
||
use think\admin\storage\QiniuStorage;
|
||
use think\admin\storage\TxcosStorage;
|
||
use think\exception\HttpException;
|
||
|
||
/**
|
||
* 系统参数配置.
|
||
* @class Config
|
||
*/
|
||
class Config extends Controller
|
||
{
|
||
public const themes = [
|
||
'default' => '默认色0',
|
||
'white' => '简约白0',
|
||
'red-1' => '玫瑰红1',
|
||
'blue-1' => '深空蓝1',
|
||
'green-1' => '小草绿1',
|
||
'black-1' => '经典黑1',
|
||
'red-2' => '玫瑰红2',
|
||
'blue-2' => '深空蓝2',
|
||
'green-2' => '小草绿2',
|
||
'black-2' => '经典黑2',
|
||
];
|
||
|
||
/**
|
||
* 系统参数配置.
|
||
* @auth true
|
||
* @menu true
|
||
*/
|
||
public function index()
|
||
{
|
||
$this->title = '系统参数配置';
|
||
$this->files = Storage::types();
|
||
$this->plugins = Plugin::get(null, true);
|
||
$this->issuper = AdminService::isSuper();
|
||
$this->systemid = ModuleService::getRunVar('uni');
|
||
$this->framework = ModuleService::getLibrarys('topthink/framework');
|
||
$this->thinkadmin = ModuleService::getLibrarys('zoujingli/think-library');
|
||
if (AdminService::isSuper() && $this->app->session->get('user.password') === md5('admin')) {
|
||
$url = url('admin/index/pass', ['id' => AdminService::getUserId()]);
|
||
$this->showErrorMessage = lang("超级管理员账号的密码未修改,建议立即<a data-modal='%s'>修改密码</a>!", [$url]);
|
||
}
|
||
uasort($this->plugins, static function ($a, $b) {
|
||
if ($a['space'] === $b['space']) {
|
||
return 0;
|
||
}
|
||
return $a['space'] > $b['space'] ? 1 : -1;
|
||
});
|
||
$this->fetch();
|
||
}
|
||
|
||
/**
|
||
* 修改系统参数.
|
||
* @auth true
|
||
* @throws \think\admin\Exception
|
||
*/
|
||
public function system()
|
||
{
|
||
if ($this->request->isGet()) {
|
||
$this->title = '修改系统参数';
|
||
$this->themes = static::themes;
|
||
$this->fetch();
|
||
} else {
|
||
if (RuntimeService::check('demo')) {
|
||
$this->error('演示环境禁止修改系统配置!');
|
||
}
|
||
$post = $this->request->post();
|
||
// 修改网站后台入口路径
|
||
if (!empty($post['xpath'])) {
|
||
if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $post['xpath'])) {
|
||
$this->error('后台入口格式错误!');
|
||
}
|
||
if ($post['xpath'] !== 'admin') {
|
||
if (is_dir(syspath("app/{$post['xpath']}")) || !empty(Plugin::get($post['xpath']))) {
|
||
$this->error(lang('已存在 %s 应用!', [$post['xpath']]));
|
||
}
|
||
}
|
||
RuntimeService::set(null, [$post['xpath'] => 'admin']);
|
||
}
|
||
// 修改网站 ICON 图标,替换 public/favicon.ico
|
||
if (preg_match('#^https?://#', $post['site_icon'] ?? '')) {
|
||
try {
|
||
SystemService::setFavicon($post['site_icon'] ?? '');
|
||
} catch (\Exception $exception) {
|
||
trace_file($exception);
|
||
}
|
||
}
|
||
// 数据数据到系统配置表
|
||
foreach ($post as $k => $v) {
|
||
sysconf($k, $v);
|
||
}
|
||
sysoplog('系统配置管理', '修改系统参数成功');
|
||
$this->success('数据保存成功!', admuri('admin/config/index'));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 修改文件存储.
|
||
* @auth true
|
||
* @throws \think\admin\Exception
|
||
*/
|
||
public function storage()
|
||
{
|
||
if (!$this->request->isGet() && RuntimeService::check('demo')) {
|
||
$this->error('演示环境禁止修改系统配置!');
|
||
}
|
||
if (!in_array($this->request->method(), ['GET', 'POST'], true)) {
|
||
throw new HttpException(405, 'Method Not Allowed', null, ['Allow' => 'GET, POST']);
|
||
}
|
||
$this->_applyFormToken();
|
||
if ($this->request->isGet()) {
|
||
$this->type = input('type', 'local');
|
||
if ($this->type === 'alioss') {
|
||
$this->points = AliossStorage::region();
|
||
} elseif ($this->type === 'qiniu') {
|
||
$this->points = QiniuStorage::region();
|
||
} elseif ($this->type === 'txcos') {
|
||
$this->points = TxcosStorage::region();
|
||
}
|
||
$this->fetch("storage-{$this->type}");
|
||
} else {
|
||
$post = $this->request->post();
|
||
if (!empty($post['storage']['allow_exts'])) {
|
||
$exts = array_unique(str2arr(strtolower($post['storage']['allow_exts'])));
|
||
foreach ($exts as $extension) {
|
||
if (!UploadSecurity::isExtensionSafe($extension)) {
|
||
$this->error('禁止上传可执行的文件!');
|
||
}
|
||
}
|
||
$post['storage']['allow_exts'] = join(',', $exts);
|
||
}
|
||
foreach ($post as $name => $value) {
|
||
sysconf($name, $value);
|
||
}
|
||
sysoplog('系统配置管理', '修改系统存储参数');
|
||
$this->success('修改文件存储成功!');
|
||
}
|
||
}
|
||
}
|