This quick guide will get you set up with a secured simple WebDAV server using Ruby and Rack. The idea is to make your Dropbox accessible through WebDAV. This enables secure saving of documents from the iPad iWork apps back into your Dropbox account.
The script was inspired by Billy He’s RackDAV Thin script and improved to add self-signed certificates for an encrypted connection.
Prerequisites
This guide was written with Mac OS X in mind, but with a few changes should work on any *nix-like system. Ruby and RubyGems are assumed to be already installed.
sudo gem install rack rack_dav
Create self-signed certificates
cd ~/Dropbox mkdir .certs cd .certs/
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Remove the unnecessary PEM password unless you’re really paranoid:
cp server.key server.key.org openssl rsa -in server.key.org -out server.key
Verbose Info: http://efreedom.com/Question/3-73979/Easily-Create-SSL-Certificate-Configure-Apache2-Mac-OS
The RackDAV script
Here’s the RackDAV script which you could save as rackdav.rb in your Dropbox folder. Replace all instances of USERNAME and PASSWORD as needed.
#!/usr/bin/env ruby require 'rubygems' require 'rack' require 'rack_dav' require 'webrick' require 'webrick/https' require 'openssl' pkey = OpenSSL::PKey::RSA.new(File.open("/Users/USERNAME/Dropbox/.certs/server.key").read) cert = OpenSSL::X509::Certificate.new(File.open("/Users/USERNAME/Dropbox/.certs/server.crt").read) app = Rack::Builder.new do use Rack::ShowExceptions use Rack::CommonLogger use Rack::Reloader use Rack::Lint use Rack::Auth::Basic do |username, password| [username, password] === ['USERNAME', 'PASSWORD'] end run RackDAV::Handler.new(:root => '/Users/USERNAME/Dropbox') end.to_app Rack::Handler::WEBrick.run(app, :Port => 1024, :SSLEnable => true, :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE, :SSLCertificate => cert, :SSLPrivateKey => pkey, :SSLCertName => [["CN",WEBrick::Utils::getservername]])
Source: This script was inspired by the one found at http://surrealtime.tumblr.com/dropbox_webdav.
Make sure it works and runs:
chmod +x rackdav.rb
sudo ./rackdav.rb
Tip: To terminate the webrick server, try ctrl+alt+c.
Starting on system boot using launchd
Edit and save this plist file in /Library/LaunchDaemons/org.YOURNAME.RackDAV.plist and don’t foreget to change ALL CAP items like USERNAME.
< ?xml version="1.0" encoding="UTF-8"?> < !DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>ExitTimeOut</key> <integer>150</integer> <key>HopefullyExitsFirst</key> <true /> <key>Label</key> <string>com.YOURNAME.RackDAV</string> <key>UserName</key> <string>USERNAME</string> <key>ProgramArguments</key> <array> <string>/usr/bin/ruby</string> <string>/Users/USERNAME/Dropbox/rackdav.rb</string> </array> <key>RunAtLoad</key> <true /> </dict> </plist>
You can load and unload this daemon without restarting using the following commands:
sudo launchctl load -w /Library/LaunchDaemons/org.YOURNAME.RackDAV.plist
sudo launchctl unload -w /Library/LaunchDaemons/org.YOURNAME.RackDAV.plist
Hi, is there a way to do it on windows?
thanks!!
Hello John,
I am very interested by your script due to Dropdav change as Ray said.
But, I have a basic question : how do I connect from iPad?
Thanks
// Rick
Well, DropDAV is no longer free. They start charging $5 a month. That sucks given the 2GB Dropbox account is FREE! I am not going to pay just to sync.
Well my DropDAV has stopped working. Can login to Dropbox ok and can log into DropDAV manage account page but dropdav from Pages in the iPad does not work.
DropDAV actually is free. They just explained the pricing a bit confusingly on their website. If your Dropbox is a 2GB free account, then you can use DropDAV for free, but if you pay for your Dropbox, you pay for DropDAV (or get a free 14-day trial). It works painlessly, efficiently and beautifully.
I have just made the following change to this guide: run server as non-privileged user. The script now starts the server on port 1024 rather than 80 so that it doesn’t need to be run as root. The launchd plist file now specifies the user that the server should be started as. Files created should then have the ownership of the user rather than root.
Some have asked privately why WEBrick was used rather than mongel. The answer is Mongrel does not have the capability of secured connections without the use of a proxy as far as I can tell.
Unfortunately it does not appear that DropDAV is free after 14 days.
Now there’s a service that enables WebDAV support for Dropbox. It’s called DropDAV and it works really, really well. Check it out at https://dropdav.com