PHP Virtual Shell
May 26th, 2008
Well its been a while since I’ve posted something with a technical nature. So, I decided to write about this small php script I’ve been using to get around hosting limitation regarding ssh access. As I’ve encountered some popular shared hosting providers (such as godaddy) do not provide ssh access. I am not sure why this practice is so common. I am assuming it is more of a support issue than security, as it is possible to execute system commands via php.
This leads me to introduce my php virtual shell. It is basically a simple php script which receives input from the user and executes the command and displays the result. The added bonus is that this script also keeps a history of the commands and supports automatic history completion. I love the history and simple command search of modern shells, so I decided to add this to my virtual shell.
I used a javascript auto complete control which I found here . The script basically stores a history of the commands in a file: .vshellhist, and every time the script is executed this file is used to build a javascript array containing all previous commands. From there on, the auto complete control goes into affect. For more details simply look at the code. It is pretty straight forward.
The php code and relevant javascript files can be dowloaded here: php-vshell.zip. To use this script first change the password in the script file. I put the password just for general protection against misuse. I recommend to also change the script file name. Note that the password is kept on file in the clear. For better protection, I would use a form of password authentication which at least keeps the password encrypted on disk. Probably easiest is to use Apache’s authentication mechanism through the use of a .htaccess file. Once the password is set simply upload the php and javascript files (all to the same directory) and start testing out your new shell.