[Module] Yii web shell

Web shell for Yii allows you to run console commands from your browser. Can be useful for both no-ssh webservers and

console-style administration modules.

Yii web shell uses the same config as your web application so if your application works it will work too.

hi,

this is awesome.

thanks, SamDark!

–iM

This is a great !! … good idea samdark !

I’ve tried it but after install, I only get a black blank page and that’s it:




<html> 

<head> 

    <meta charset="utf-8"> 

    <link rel="stylesheet" type="text/css" href="/project/yii-1.1.4/assets/6cca1998/wterm.css" /> 

<script type="text/javascript" src="/project/yii-1.1.4/assets/75770a22/jquery.js"></script> 

<script type="text/javascript"> 

/*<![CDATA[*/

var webshell = {'wtermOptions':{'WIDTH':'100%','HEIGHT':'100%','WELCOME_MESSAGE':'Welcome to Yii web shell. Type <strong>help<\/strong> for the list of available commands.','PS1':'%','TERMINAL_CLASS':'terminal','PROMPT_CLASS':'prompt','CONTENT_CLASS':'content','THEME_CLASS_PREFIX':'theme_','DEFAULT_THEME':'webshell','HIGHLIGHT_CLASS':'highlighted','KEYWORD_CLASS':'keyword'},'commands':{'test':function(){return "Hello, world!";},'yiic':'http://localhost/project/yii-1.1.4/index.php?r=webshell/default/yiic'},'helpText':'test\tJust a test.\nyiic\tAllows to run <strong>yiic<\/strong> commands.\nclear\tClear screen.\nexit\tExit console.','exitUrl':'http://localhost/project/yii-1.1.4/index.php'};

/*]]>*/

</script> 

<title><?=$this->pageTitle?></title> 

</head> 

<body> 

<script type="text/javascript" src="/project/yii-1.1.4/assets/6cca1998/wterm.jquery.js"></script> 

<script type="text/javascript" src="/project/yii-1.1.4/assets/6cca1998/webshell.js"></script> 

</body> 

</html>



Here is the module configuration :





	'modules'=>array(

        'webshell'=>array(

            'class'=>'application.modules.webshell.WebShellModule',

            // when typing 'exit', user will be redirected to this URL

            'exitUrl' => '/',

            // custom wterm options

            'wtermOptions' => array(

                // linux-like command prompt

                'PS1' => '%',

            ),

            // additional commands (see below)

            'commands' => array(

                'test' => array('js:function(){return "Hello, world!";}', 'Just a test.'),

            ),

            // uncomment to disable yiic

            // 'useYiic' => false,

 

            // adding custom yiic commands not from protected/commands dir

            'yiicCommandMap' => array(

                'email'=>array(

                    'class'=>'ext.mailer.MailerCommand',

                    'from'=>'sam@rmcreative.ru',

                ),

            ),

        ),

	),



What am i doing wrong ?

Thanks

Try using




    'modules'=>array(

        'webshell'=>array(

            'class'=>'application.modules.webshell.WebShellModule',

            // when typing 'exit', user will be redirected to this URL

            'exitUrl' => '/',

         ),

    ),



same result : blank black page

What is your browser? I’ve tested it with FF and Opera only.

FF 3.6.9 and also tried with Chrome 6.7.472.

… I found what the problem is : you are using the shortag (<?=) to render the layout, and my environment does not use it. I’ve modified views/layouts/webShell.php and now it works fine.

Thanks for your help … and again this is a great extension !!

8)

Thanks. Fixed.

Updated links in the first post.

Cool stuff!

One note that came to my mind when looking a the sources: You define a global js var named “commands” in the global namespace here. Nothing wrong with that except that it’s a very common name and a potential source for clashes with other js libs.

Since this module is still young, maybe it’s still time to change that to something more unique like “yiiwebshellcommands”?

Thanks, fixed: http://code.google.com/p/yiiext/source/browse/trunk/app/extensions/yiiext/modules/webshell/assets/webshell.js

Really awesome module! :D

I have one question though:

How do I add the ‘migrate’ command?

I tried to add it by using this:




 'yiicCommandMap' => array(

     'migrate'=>array(

         'class'=>'cli.MigrateCommand',                 

	),

 ), 

That really doesn’t work.

I get ‘migrate’ among the available yiic commands but it does nothing. :)

I hacked around by simply adding all commands from yii.cli.commands so that action Yiic in the default controller becomes:


	function actionYiic() {

    	$tokens = explode(" ", $_GET['tokens']);

    	$commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';

    	$runner = new CConsoleCommandRunner();

    	$runner->commands = $this->getModule()->yiicCommandMap;

    	$runner->addCommands($commandPath);

    	$commandPath = Yii::getFrameworkPath() . DIRECTORY_SEPARATOR . 'cli' . DIRECTORY_SEPARATOR . 'commands';

    	$runner->addCommands($commandPath);


    	ob_start();

    	$runner->run($tokens);


    	echo htmlentities(ob_get_clean(), null, Yii::app()->charset);

	}



That adds other not wanted commands, but it works.

I can now use yiic migrate on hosts without shell access.

I’d still like to know how you do it properly. ;)