Sunday, April 11, 2010

How to share files on your WebOS smart-phone over the Internet



One of the best “hacker friendly” smart phones is the Palm Pre and more specifically phones running on the WebOS platform. WebOS is a Linux based distribution with proprietary components from Palm allowing the platform to support its touch screen interface and phone features. Palm has to-date been very supporting of the homebrew community and their passion for digging into the guts of the phone and unlocking all of its secrets. Two groups in particular lead the charge WebOS Internals and Palm Pre Hacks. These dedicated individuals spend their free-time looking into ways to better the user experience of the Palm Pre. A lot of the background research that went into this post has come from these groups and I would like to thank them for their hard work.

If you are looking at this post then we must assume you are not content on using the out-of-the-box features of your phone and would like to extend its capabilities. Maybe it is the challenge, maybe it is the wow-factor you get from your friends and coworkers. In any event, this post will guarantee to give you both. Recently I came across a few postings from Palm Pre Hacks describing how to run WordPress on a Palm Pre. This excellent post got me thinking about some of the other things you could do with a web server running on your smart-phone. My first idea was for a simple way to share the pictures on your phone with your friends and family. So without further ado here are the steps you need to do to start sharing your pictures (or anything else on your phone)

Prerequisites

To implement the steps of this post you must first “root” your phone. This simply means you need to be able to access the Linux shell of your phone. There are several accepted techniques but if this is the first time you are rooting your phone you will need to use the Novaterm technique. Once you have gained access to the Linux shell you can continue. I prefer to SSH into my Palm Pre since it is the standard approach to connecting to remote Linux shells.

Before we can get to the heart of this post we must first tackle a big issue. If you are going to let others view the files off your phone using the Internet then you are going to have to give those people and easy way to access your phone. Dynamic DNS is the answer we are looking for. Dynamic DNS allows your friends and family to enter a user friendly name like http://johnsmithpalmpre.selfip.com:8081/ to gain access to your phone. Setting up the Dynamic DNS is easy to do. The best post I have found for doing this comes from Palm Pre Hacks and their posting on setting up SSH on the Palm Pre. Once on the post scroll down to the section titled Step by Steps to Setup Dynamic DNS for your Palm Pre.

One more thing to consider. The majority of the steps in this post requires the modification of configuration files. The accepted Linux tool for doing this is the vi text editor. If however you are a novice at Linux the vi text editor can be VERY daunting. I have found the Linux nano text editor to be much easier for beginner Linux users to grasp. To install nano on your palm pre type the following command inside your linux shell




sudo ipkg-opt install nano



Setting up LighttpddirectoryBrowsing

The secret to this post is setting up a web server that supports directory browsing. What is directory browsing? Well a web server can be configured to display the contents of the server just like you see when you use Windows Explorer. This means you can give your friends and family a URL to a virtual directory on your web server (phone) and allow them to view the contents of that folder, including sub folders and of course files.

For this posting we will be using Lighttpd. Lighttpd is an open-source lightweight web server for the Linux OS and is ideal for websites with light traffic or for Palm Pre smart-phones :=) Again WebOS Internals steps to the plate with a simple to follow post on how to install Lighttpd. Please note that if you follow the posting from WebOS Internals your default server port will be 8081 and your default folder for your web server will be /opt/share/www. Once you have the web server installed we need to make a few tweaks to the configuration file. The Lighttpd configuration file is located at /opt/etc/lighttpd/lighttpd.conf. Using your favorite Linux text editor you need to modify/add the following settings (I will be using nano)









cd /opt/etc/lighttpd


sudo cp lighttpd.conf lighttpd.conf.bak


sudo nano lighttpd.conf


The first command cd /opt/etc/lighttpd will navigate you to the folder location of the configuration file.

sudo cp lighttpd.conf lighttpd.conf.bak will make a backup copy of the configuration file. I never make a change to a configuration fie without fist backing it up. You never know when you may need to revert your changes!

The last command sudo nano lighttpd.conf launches the nano text editor. Once inside your text editor you need to find the following line of text:

dir-listing.activate

In nano you can do this by pressing CTRL+W and typing dir-listing.activate

ssh1

If the line of text starts with # remove it. Also make sure the value of the setting is set to enabled. The line of text should look like






## virtual directory listings

dir-listing.activate = "enable"


Now scroll to the bottom of the file and add the following text:






server.follow-symlink = "enable"



The setting: server.follow-symlink tells Lighttpd to support using sym links which are like Windows shortcuts. After you have added this command save your changes and exit the text editor. In nano, all you need to do is press CTRL+X and then Y. For the changes we just did to take affect we need to restart the web server. To do this type the following command:






sudo /opt/etc/init.d/S80lighttpd restart


Setting up virtual directories

Now that the hard stuff has been done all we need to do is tell the web server which directories we wish to support. The simplest approach is to setup a symlink underneath the root web folder. Pictures taken on your phone are stored in the /media/internal/DCIM folder.

ssh2

To allow your web-server to list the contents of this folder type the following commands:







cd /opt/share/www



sudo ln –s /media/internal/DCIM pictures


The cd /opt/share/www command navigates you to the root web folder of Lighttpd. sudo ln –s /media/internal/DCIM pictures creates a symlink to the /media/internal/DCIM folder and gives it the name pictures.

Testing your setup

Now that you have configured your web server to support directory listing, enabled supporting symbolic links, and setup a symlink under the root web folder it is time to test your hard work out. All you need to do is go to your favorite web browser and type the address of your Dynamic DNS entry you setup previously adding :8081/pictures to the end of the URL. For example:

http://yourdynamicdnsentry:8081/pictures

If everything worked you should see a directory listing of all the pictures in your DCIM folder on your phone. If you click on one of the links you will be able to see the picture!

proof1

Conclusion

Setting up a web server to run on your Palm Pre is very simple to do. Once you have this web server up and running the number of things you can do with it are limitless. Keep in mind that your phone won’t be the speediest web server on the block, but it will do for simple file viewing and impressing your co-workers and friends. Using the power of symlinks you can open up any folder on your phone you wish. Of course with great power comes great responsibility. Make sure you follow all copyright laws when opening up your phone for browsing. I would also advice not giving out the Dynamic DNS address of your phone to the public as you don’t want to spend your precious CPU cycles severing up pictures to the general populace. Enjoy!