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 /etc/lighttpd/conf.d /srv/disk/dav /var/lib/lighttpd
chown http:www-data /srv/disk/dav /var/lib/lighttpd
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 = (
    "/dav/" => ("method" => "basic", "realm" => "disk", "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/

Please note that you must configure HTTPS if you are going to access your files from internet. See lighttpd docs: Secure HTTP

To watch the share from a browser you can install the small and nice UI webdav-js:

cat << EOF > /srv/disk/dav/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>WebDAV</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/dom111/webdav-js/assets/css/style-min.css"/>
</head>
<body>
<script src="https://cdn.jsdelivr.net/gh/dom111/webdav-js/src/webdav-min.js"/>
</body>
</html>
EOF

Then open http://192.168.1.1/dav/ and you'll see a simple file manager.

The disadvantage of the method is that it's doesn't work for subfolders i.e. when you open http://192.168.1.1/dav/Documents/ then the index.html file wont be show. That's fine for 99% of usages.

Online apps and PWAs

You can also try an online apps that can connect directly to your WebDAV share.

You'll need a CORS enabled. Here is an example https://gist.github.com/stokito/0a6274106d407ba6d9fb776e7773445d

Useful Apps

Useful mobile apps that supports WebDAV sync:

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: 2023/01/20 11:17
  • by stokito