For a vanilla OpenWRT see WebDAV with Lighttpd on OpenWRT. Those instructions are slightly different.
What is this for?
You can turn your router into a small NAS and file server. Just connect an SSD into USB and install a WebDAV server which allows to get access to the disk. Then you need to connect to router via SSH which is a remote command line an execute the commands bellow.
Connect with SHH. See SSH access for newcomers.
Install dependencies:
opkg update
opkg install lighttpd-mod-auth lighttpd-mod-authn_file lighttpd-mod-webdav
Create a test folder to share with some file:
mkdir -p /srv/disk/dav/
echo "It works!" > /srv/disk/dav/README.txt
If you are going to share SSD or HDD connected to USB then you have to mount it first. See Using storage devices
In the /etc/lighttpd/modules.d/30-webdav.load
is already configured some WebDAV folder at /dav/
path.
But the config is not complete. Instead of changing the file we'll create a separate config that overrides it for the same /dav/
path.
Thus, you can safely upgrade the Lighttpd package and your config won't be overwritten by a new version from repository.
Create /etc/lighttpd/conf.d/disk.conf
:
# Override the /dav/ folder configured in 30-webdav.conf
$HTTP["url"] =~ "^/dav($|/)" {
# The root / is ovveriden by an alais in turris-root.conf so we must add another override
alias.url = ( "/dav/" => "/srv/disk/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"))
# (Optional) add a directory index to see files from a browser
server.dir-listing := "enable"
dir-listing.encoding := "utf-8"
webdav.sqlite-db-name := "/etc/lighttpd/webdav_lock.db"
}
Explanation
document-root := "/srv/disk/"
is a parent folder where your website is stored but WebDAV will work only fordav/
folder inside. The:=
means overriding the value i.e. content root for your main site. So your files folder can be in another location than main website (if any).auth.backend = "plain"
means that we'll use a clear text passwords instead ofcrypt(3)
encrypted.userfile = "/etc/lighttpd/webdav.shadow"
the place where the passwords will be stored.dir-listing = "enable"
enables a usual directory listing from browser. It's not needed for DAV so you can remove it.webdav.sqlite-db-name := "/etc/lighttpd/webdav_lock.db"
SQLite database for WebDAV properties and WebDAV locks
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
In case of error on start run:
lighttpd -f /etc/lighttpd/lighttpd.conf -tt
This will load all configurations and validate them.
To check logs:
less /var/log/lighttpd/error.log
To see the whole generated config:
lighttpd -f /etc/lighttpd/lighttpd.conf -p
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