diff --git a/app/installapi/controller/CommandExec.php b/app/installapi/controller/CommandExec.php index e54d1bb4..322c09f4 100644 --- a/app/installapi/controller/CommandExec.php +++ b/app/installapi/controller/CommandExec.php @@ -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'); + } /** * 初始化 diff --git a/config/buildadmin.php b/config/buildadmin.php index 9fb7db7f..6beafed9 100644 --- a/config/buildadmin.php +++ b/config/buildadmin.php @@ -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', + ], ]; \ No newline at end of file