refactor:增加allowed_commands配置项

This commit is contained in:
妙码生花 2022-02-23 21:32:52 +08:00
parent 9e5da13cee
commit 57a3a4182b
2 changed files with 21 additions and 12 deletions

View File

@ -2,6 +2,8 @@
namespace app\installapi\controller;
use think\facade\Config;
/**
* 命令执行类
*/
@ -34,17 +36,12 @@ class CommandExec
* 对可以执行的命令进行限制
* @var string[]
*/
protected $command = [
'ping-baidu' => 'ping baidu.com',
'cnpm-install' => 'cnpm install',
'npm-v' => 'npm -v',
'cnpm-v' => 'cnpm -v',
'node-v' => 'node -v',
'install-cnpm' => 'npm install -g cnpm --registry=https://registry.npmmirror.com',
'test-install' => 'cd npm-install-test && cnpm install',
'web-install' => 'cd ../web && cnpm install',
'web-build' => 'cd ../web && cnpm run build:online',
];
protected $command = [];
public function __construct()
{
$this->command = Config::get('buildadmin.allowed_commands');
}
/**
* 初始化

View File

@ -5,5 +5,17 @@
return [
// 允许跨域访问的域名
'cors_request_domain' => 'localhost,127.0.0.1'
'cors_request_domain' => 'localhost,127.0.0.1',
// 允许执行的命令
'allowed_commands' => [
'ping-baidu' => 'ping baidu.com',
'cnpm-install' => 'cnpm install',
'npm-v' => 'npm -v',
'cnpm-v' => 'cnpm -v',
'node-v' => 'node -v',
'install-cnpm' => 'npm install -g cnpm --registry=https://registry.npmmirror.com',
'test-install' => 'cd npm-install-test && cnpm install',
'web-install' => 'cd ../web && cnpm install',
'web-build' => 'cd ../web && cnpm run build:online',
],
];