Wednesday, April 21, 2010

PHP script for SSH access

Today when I was struggling of slowly FTPing a PHP web application (Magento), which the FTP client estimates will take up to 4 hours for that 50+M of files, I start wondering if there is other way to FTP the package to server then unpack it there, not only for dev team, but also for customers. But we have only FTP access to the server, no SSH available, not if I login directly with root certification. After some discuss with colleagues, we can up of an idea of writing PHP code using the exec command to execute the unpack command. This sounds too simple and dangers, and what's worse, it works in our servers. Then I took a little additional effort to wrap up a relatively nicer PHP page to pretend SSH access from browser.

The code is here.

It is easy to see how dangers this could be in shared web hosting. It is even worse when the php is executed as the same user, like 'apache', because that means a client could get full access to others files, and can screw big things up.