loveorigami/yii2-webshell

Yii2-Webshell allows you to execute any shell command from a web-interface.

Installs: 233

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 1

Type:yii2-extension

dev-master 2019-06-07 06:45 UTC

This package is auto-updated.

Last update: 2024-11-07 19:44:11 UTC


README

It is a [fork from] (https://github.com/asinfotrack/yii2-webshell)

Yii2-Webshell allows you to execute any shell command from a web-interface. This is especially useful to call console-commands from the frontend. The execution is done via AJAX and a special action-class (ShellAction).

The output of the shell action is displayed live (line by line).

Installation

The preferred way to install this extension is through composer.

"loveorigami/yii2-webshell": "*"
ShellAction

This is the action you can attach to any controller via its actions()-method. Here you define who and who the action can be accessed. All the regular RBAC-controls are of course available.

The following is an example for a configuration calling a yii-console-command under windows:

class MyController extends \yii\web\Controller
{

	//...
	
	public function actions()
	{
		return [
			'my-shell-action'=>[
				'class'=>'lo\wshell\actions\ShellAction',
				'command'=>'my-console-command/index',
				'yiiScript'=>'@app/yii',
			],
		];
	}
	
	//...

}

Widgets

ShellWidget

The widget allows you to create a console like container in your views, which communicates with a ShellAction as documented above. The following represents a full configuration:

echo Button::widget([
	'label'=>'Run', 
	'options'=>[
		'data-shell-widget-run'=>'my-shell-widget',
	],
]) 

echo ShellWidget::widget([
	'id'=>'my-shell-widget',
	'route'=>['my-controller/my-shell-action'],
	'autorun'=>false,
	'initialContent'=>Yii::t('app', 'Ready and waiting...'),
	'clientOptions'=>[
        //custom client options here
	],
]) 

As you can see, the console can either be ran automatically or not. In any case you can create buttons which will then trigger the action. To do so simply use the attribute data-shell-widget-run and fill it with the id of the ShellWidget. You can customize all the js-options (including the attribute name) with the clientOptions property of the widget.

For a full documentation of the widgets possibilities check out the doc within its code.