Simple LAN filesharing with WebDAV

From Run Your Own
Jump to navigation Jump to search

WebDAV is both an overlooked and quite popular way to access and edit files remotely across a wide range of operating systems. Yes it's web stuff, again, but surprisingly fast, lightweight, and that can recover quite well on unstable networks or when the server has to be restarted, or has gone for lunch. A reason why it may be overlooked is possibly because it's often associated with sausage factories like own/nextcloud, or standalone implementations that are not particularly exciting. What is less known is that many web servers come with their own WebDAV implementation out of the box. Out of the usual suspects, nginx, Apache, and lighttpd, the latter has both the most lightweight and most complete implementation. No need for anything else!

In these notes we only cover a simple LAN setup, you can build upon it for more complex use case of course.

Server side

Installation

  • This is for Debian, but you're smart
sudo apt install lighttpd lighttpd-mod-webdav

Example Configuration

Basically the configuration are in /etc/lighttpd/conf-available and with symlinks in /etc/lighttpd/conf-enabled. In our simple example we have two shared folder, one that can be mounted read-only by anyone, and one that is read-write but requires a username and password.

  • By default a temp config file called 99-unconfigured.conf provides a generic landing page. We don't need it and we just have to enable the authentication config.
sudo lighttpd-disable-mod unconfigured
sudo lighttpd-enable-mod auth
  • Create a user and password for the read-write share
sudo apt install apache2-utils
sudo htpasswd -c /etc/lighttpd/user.htpasswd turtleprincess
  • create a new configuration file /etc/lighttpd/conf-available/66-webdav.conf with the following:
server.modules += ( "mod_webdav" )
dir-listing.encoding = "utf-8"
  
# This is needed for keepings tracks of locks and props which
# are needed for shares that can be edited
webdav.sqlite-db-name = "/var/cache/lighttpd/lighttpd.webdav.db"
  
# auth
server.modules += ("mod_authn_file")
auth.backend = "htpasswd" 
auth.backend.htpasswd.userfile = "/etc/lighttpd/user.htpasswd"
auth.require = ( "/readwrite1"     => ( "method" => "basic", 
                                 "realm" => "YOU WOT MATE", 
                                 "require" => "valid-user" ),
                 "/readwrite2" => ( "method" => "basic",
                                 "realm" => "YOU WOT MATE",
                                 "require" => "valid-user" ))
  
# read-only stuff
$HTTP["url"] =~ "^/readonly(?:/|$)" {
    alias.url = ( "/readonly" => "/local/path/to/readonly" )
    dir-listing.activate = "enable" 
    webdav.activate = "enable" 
    webdav.is-readonly = "enable" 
}
 
# shared pit of madness  
$HTTP["url"] =~ "^/readwrite1(?:/|$)" {
    alias.url = ( "/readwrite1" => "/local/path/to/readwarite1" )
    dir-listing.activate = "enable" 
    webdav.activate = "enable"
    webdav.is-readonly = "disable" 
}
$HTTP["url"] =~ "^/readwrite2(?:/|$)" {
    alias.url = ( "/readwrite2" => "/local/path/to/readwarite2" )
    dir-listing.activate = "enable" 
    webdav.activate = "enable"
    webdav.is-readonly = "disable" 
}

Client side