WebDAV Share

WebDAV is an HTTP based file transfer protocol. It's integrated into Windows, GNOME, KDE and many programs for backups, file sharing and media players.

It's installed as a plugin for a web server. Unfortunately OpenWrt's uhttpd doesn't support it. If you have enough space you can install Lighttpd webserver and configure WebDAV share.

Assuming that USB drive is mounted to /srv/disk/ folder.

mkdir -p /srv/disk/dav/
chown http:www-data /srv/disk/dav/
mkdir -p /etc/lighttpd/conf.d/
mkdir -p /var/lib/lighttpd/
chown http:www-data /var/lib/lighttpd/
echo "var.home_dir = \"/var/lib/lighttpd\"" > /etc/lighttpd/conf.d/1-vars.conf
cat << EOF > /etc/lighttpd/conf.d/99-disk.conf
$HTTP["url"] =~ "^/dav($|/)" {
  server.document-root := "/srv/disk/"
  auth.backend = "plain"
  auth.backend.plain.userfile = "/etc/lighttpd/webdav.shadow"
  auth.require = ("" => ("method" => "basic", "realm" => "webdav", "require" => "valid-user"))
}
EOF
opkg update
opkg install lighttpd-mod-auth lighttpd-mod-authn_file lighttpd-mod-webdav

Now set a password:

echo "youruser:somesecret" > /etc/lighttpd/webdav.shadow

Note: your secret is not encoded and saved on router in clear text for a better performance. If a hacker get access to the file it can see your password. So don't put here a password that you are using anywhere else. Just generate a new one for example with the command:

< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;

And finally restart Lighttpd:

/etc/init.d/lighttpd restart

Open in a browser http://192.168.1.1/dav/ and you'll be prompted for credentials. After login you'll see a directory listing but this not yet a WebDAV, just an additional feature.

To connect to WebDAV see Accessing WebDAV Server.

To test WebDAV from command line use cadaver:

    cadaver http://192.168.1.1/dav/
    Authentication required for webdav on server `192.168.1.1':
    Username: youruser
    Password: 
    dav:/dav/> ls
    Listing collection `/dav/': succeeded.
            README.txt
    dav:/dav/> cat README.txt 
    Displaying `/dav/README.txt':
    It works!
    dav:/dav/> exit
    Connection to `192.168.1.1' closed.

If you don't want to install the cadaver you can test with a curl (replace the youruser):

curl -u youruser -X PROPFIND -H "Depth: 1" 'http://192.168.1.1/dav/'

To watch the share from a browser you can install the small and nice UI https://github.com/dom111/webdav-js

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2022/05/12 21:20
  • by stokito