diff --git a/Module.php b/Module.php index ec526e9..4e56e5d 100644 --- a/Module.php +++ b/Module.php @@ -45,6 +45,15 @@ class Module extends \yii\base\Module */ public $yiiScript = '@app/yii'; + /** @var bool Enable composer support */ + public $composerEnabled = false; + + /** @var string composer-command: composer or php composer.phar */ + public $composerCommand = 'composer'; + + /** @var string path to main folder */ + public $composerWorkingDirectory = '@app'; + /** * @var array the list of IPs that are allowed to access this module. * Each array element represents a single IP filter which can be either an IP address diff --git a/controllers/DefaultController.php b/controllers/DefaultController.php index 204e512..cba196c 100644 --- a/controllers/DefaultController.php +++ b/controllers/DefaultController.php @@ -34,7 +34,8 @@ public function actionIndex() $this->layout = 'shell'; return $this->render('index', [ 'quitUrl' => $this->module->quitUrl ? Url::toRoute($this->module->quitUrl) : null, - 'greetings' => $this->module->greetings + 'greetings' => $this->module->greetings, + 'module' => $this->module, ]); } @@ -50,8 +51,22 @@ public function actionRpc() switch ($options['method']) { case 'yii': - list ($status, $output) = $this->runConsole(implode(' ', $options['params'])); + $cmd = Yii::getAlias($this->module->yiiScript) . ' ' + . implode(' ', $options['params']) + . ' 2>&1'; + list ($status, $output) = $this->runConsole($cmd); return ['result' => $output]; + case 'composer': + if (!$this->module->composerEnabled) { + return ['result' => 'no composer support']; + } + + $cmd = $this->module->composerCommand . ' ' + . implode(' ', $options['params']) + . ' -d='.Yii::getAlias($this->module->composerWorkingDirectory) + . ' 2>&1'; + list ($status, $output) = $this->runConsole($cmd); + return ['result' => $output]; } } @@ -64,9 +79,7 @@ public function actionRpc() */ private function runConsole($command) { - $cmd = Yii::getAlias($this->module->yiiScript) . ' ' . $command . ' 2>&1'; - - $handler = popen($cmd, 'r'); + $handler = popen($command, 'r'); $output = ''; while (!feof($handler)) { $output .= fgets($handler); @@ -77,4 +90,4 @@ private function runConsole($command) return [$status, $output]; } -} \ No newline at end of file +} diff --git a/views/default/index.php b/views/default/index.php index 7a76de6..f1846fb 100644 --- a/views/default/index.php +++ b/views/default/index.php @@ -2,6 +2,7 @@ /** @var $this yii\web\View */ /** @var $quitUrl string */ /** @var $greetings string */ +/** @var $module \samdark\webshell\Module*/ use yii\helpers\Url; \samdark\webshell\WebshellAsset::register($this); @@ -10,6 +11,25 @@ $this->title = $greetings; +$jsComposerHelp = ''; +$jsComposerExecution = ''; + +if($module->composerEnabled){ + $jsComposerHelp = <<registerJs( <<