2008-12-23

Simple Remote Control with Dropbox

Dropbox

Dropbox is a fantastic application for unobstructive synchronization of files between multiple computers running different operating systems. Everything happens seamlessly behind the scene. The more I use it the more I feel thankful to the creators and devs. Today I found out a new use of Dropbox — a simple remote control tool. All you need is Dropbox and some shell scripts.

The Scenario

Why I would have come up with such an idea? The story is: I have a PC at home which I would like to access from the lab in the institute. It is reachable only if it’s connected to the VPN network in the campus. However, the VPN connection is sometimes not very stable and could die with no reason, not to say the server will automatically terminate a connection from outside of the university every 4 hours.

Therefore I really want to find a way to remotely issue commands on my home PC (which is unreachable), let it connect to the VPN network and report the IP address to me. With Dropbox, its very easy to do.

The Solution

I create a cron job on the home PC, which checks a text file (command.txt) inside my Dropbox folder every minute, when its not empty, execute the content of the file (and clear the file). On the lab PC, I can simply put the command I want to execute into the same file — since its synchronized seconds after I made the modification, it will soon be executed at home. And for reporting IP address, I wrote a wrapper script which runs on home PC to check the VPN status after connecting and redirect the IP address information into another text file (ip.txt) inside Dropbox folder. So when I am in the lab, I put the VPN wrapper script’s name inside the command.txt, maximum a minute later, I check the ip.txt. Now I can ssh to my home PC and do what ever I want.

The Script

I put up together a script which does both the adding command and the checking-then-running command job. I call it “dbrun” which is short for “Dropbox Run”. It can be download here (right-click and save).

Installation & Usage:

  1. Make sure Dropbox daemon is up and running in both systems.

  2. Put dbrun in both the controlling and controlled systems. I prefer the directory ~/.local/bin.

  3. Make it executable if it’s not. chmod +x dbrun

  4. Create a cron job to run dbrun in a short interval (e.g. 1 min) in the controlled system. I do this by creating a file crontab inside ~/.local/etc and then run crontab ~/.local/etc/crontab. The content of the file is:

    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/pdeng/.local/bin
    */1 *   *   *   *   dbrun
    

    You may have noticed since I put dbrun in ~/.local/bin, I include this directory in the $PATH environment variable. (Actually other scripts like my VPN wrapper is also there, so I have to do this).

  5. Now to issue a command, run dbrun 'new command' in the controlling system, you will notice the Dropbox systray icon start animating to indicate the synchronization of the modified command.txt file. The “new command” will be executed soon in the controlled system.

The default location I use to store the command.txt file in the script is ~/Dropbox/command.txt. You can change it to whatever you like by opening the script and changing the value of cmdfile(around line 11).

Security Concern

It is possible to modify the script to let it only run filtered safe commands you selected yourself. But as long as you are not stupid enough to mark the command.txt as “shared” in your Dropbox and you don’t run the script as root, I don’t see (for now) too much danger. Maybe I am too naïve so please let me know in the comment if there is any potential security issue that I overlooked. After all, I only let it help getting my home PC reachable and SSH will be used to finish all other things afterward.

Update: I just did a quick check on Dropbox's wiki (didn't know about this wiki before) and there is already a similar solution for remote control. The advantages of that one is a) it has smaller granularity as it runs in a big loop and check the file every 10 seconds. b) it redirect the output into another file which can be very useful sometimes. Maybe next I should do some search in Google before writing on my own, hehe ...

2008-12-13

Integrate Remember The Milk's Tasks into Evolution

Clock applet with Remember the Milk task list

Today’s Lifehacker has an article about how to integrate Google’s Apps into Evolution, which reminds me I always want to integrate Remember The Milk’s task list into evolution and eventually let it show in the nice looking drop down window of the clock applet on GNOME’s panel.

It should be easy because with the latest (at least, don’t know about previous version) Evolution you can create new task list of the type “On The Web”, for which you will need a webcal URL which you can find at Remember The Milk’s Info page (Using the Settings link in the upper right corner of your RTM webpage, and you will see the Info tab).

Well if you just fill in the URL and your username, you probably will get an error about some sort of authorization problem. Here is the workaround: simply add username & password combination into the address string as seen in the picture below.

New Task List Settings

After the task list is created, you will be asked for the password again (you may want to choose remember it as well), and then you should see all the tasks in you RTM account, incomplete or completed, be retrieved from the server. And meanwhile in the drop down window of the clock applet, all incomplete task should appear.

Quite like how Evolution handled Google Calendar before, the RTM task list is, for the time being, read-only, i.e. you can only see them but not add/remove/mark as complete etc. However, for me, this is exactly where RTM plugin of GNOME Do should play its role, the integration just gives me a better way to keep an eye on the tasks.