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.

Friday, April 2, 2010

Wasted an hour to fix "$(".datepicker").datepicker is not a function"

I have been using datepicker in the jQuery UI package for quite a while and it was always nice and easy, until this morning when I was trying to add it to a page, it keep giving me the error "$(".datepicker").datepicker is not a function". I check from firbugs that, the jquery-ui-1.7.2.min.js is included, so as the jquery-1.3.2.min.js. I was copying the code from another page I wrote, where the datepicker works just well. I was haunting around that several lines of code, trying to use other version of jQuery and jQuery UI, but found nothing, until I roll down to the page and saw that there is another script reference of jquery-1.3.2.min.js, which I added 2 days ago for other purpose. As soon as I remove that second include, the datapicker come back to life.

The lesson is clear, yet is not frequently mentioned and would be a headless blocker for javascript newbies like me. Include the jQuery core library again will overwrite the functions added by the jQuery UI, thus the functions are missed in the final js object.

It is not a good practice to include these kind of library in the middle of a page. But it may still happen some where by some reasons. If you get weird javascript function not found error, try to look for these duplicated library include.