Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:services:nas:webdav [2022/06/30 18:28] stokitodocs:guide-user:services:nas:webdav [2023/03/18 20:24] – [Test it] removed cadaver stokito
Line 1: Line 1:
 ====== WebDAV Share ====== ====== WebDAV Share ======
-[[wp>WebDAV|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+[[wp>WebDAV|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 [[docs:guide-user:services:webserver:lighttpd|Lighttpd webserver]] and configure WebDAV share.+
  
 +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 [[docs:guide-user:services:webserver:lighttpd|Lighttpd webserver]] and configure WebDAV share.
  
 ==== WebDAV with Lighttpd ==== ==== WebDAV with Lighttpd ====
-Assuming that USB drive is mounted to ''/srv/disk/'' folder.+First of all if you already have the Lighttpd then update it and it's modules to avoid conflicts: 
 +<code bash> 
 +opkg update 
 +opkg list-upgradable | cut -f 1 -d ' ' | grep lighttpd | xargs opkg upgrade 
 +</code> 
 + 
 +Assuming that USB drive is mounted to ''/mnt/disk/'' folder. 
 <code bash> <code bash>
-mkdir -p /srv/disk/dav/ +mkdir -p /etc/lighttpd/conf.d /mnt/disk/dav /var/lib/lighttpd 
-chown http:www-data /srv/disk/dav/ +chown http:www-data /mnt/disk/dav /var/lib/lighttpd 
-mkdir -p /etc/lighttpd/conf.d/ +cat << "EOF> /etc/lighttpd/conf.d/99-disk.conf
-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($|/)" { $HTTP["url"] =~ "^/dav($|/)" {
-  server.document-root := "/srv/disk/"+  server.document-root := "/mnt/disk/"
   auth.backend = "plain"   auth.backend = "plain"
   auth.backend.plain.userfile = "/etc/lighttpd/webdav.shadow"   auth.backend.plain.userfile = "/etc/lighttpd/webdav.shadow"
-  auth.require = ("" => ("method" => "basic", "realm" => "webdav", "require" => "valid-user"))+  auth.require = ( 
 +    "/dav/" => ("method" => "basic", "realm" => "disk", "require" => "valid-user") 
 +  ) 
 +  auth.cache = ("max-age" => "3600")
 } }
 EOF EOF
Line 25: Line 33:
 opkg install lighttpd-mod-auth lighttpd-mod-authn_file lighttpd-mod-webdav opkg install lighttpd-mod-auth lighttpd-mod-authn_file lighttpd-mod-webdav
 </code> </code>
- 
  
 Now set a password: Now set a password:
Line 32: Line 39:
 echo "youruser:somesecret" > /etc/lighttpd/webdav.shadow echo "youruser:somesecret" > /etc/lighttpd/webdav.shadow
 </code> </code>
-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:+ 
 +**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:
  
 <code bash> <code bash>
-< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;+< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32}; echo
 </code> </code>
  
 And finally restart Lighttpd: And finally restart Lighttpd:
-<code>+ 
 +<code bash>
 /etc/init.d/lighttpd restart /etc/init.d/lighttpd restart
 </code> </code>
Line 49: Line 61:
 To connect to WebDAV see [[https://www.webdavsystem.com/server/access/|Accessing WebDAV Server]]. To connect to WebDAV see [[https://www.webdavsystem.com/server/access/|Accessing WebDAV Server]].
  
-To test WebDAV from command line use ''cadaver'': +A quick test can be done with a ''curl'' (replace the ''youruser''):
- +
-<code> +
-    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. +
-</code> +
- +
- +
-If you don't want to install the cadaver you can test with a ''curl'' (replace the ''youruser''):+
  
 <code bash> <code bash>
-curl -u youruser -X PROPFIND -H "Depth: 1'http://192.168.1.1/dav/'+curl -u youruser:pass -X PROPFIND -H 'Depth: 1' http://192.168.1.1/dav/
 </code> </code>
 +You must see a 207 status code and XML response with directory listing.
 +
 +See more details and examples [[https://gist.github.com/stokito/cf82ce965718ce87f36b78f7501d7940|WebDAV with curl]]
  
 ==== Don't forget about encryption! ==== ==== Don't forget about encryption! ====
- 
 Please note that you must configure HTTPS if you are going to access your files from internet. Please note that you must configure HTTPS if you are going to access your files from internet.
-See [[https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_SSL|lighttpd docs: Secure HTTP]]+You'll need to [[docs:guide-user:services:tls:certs|get a TLS certificate]] and  [[https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_SSL|configure lighttpd for HTTPS]]
  
 ==== Browser UI for the WebDAV share ==== ==== Browser UI for the WebDAV share ====
- +To watch the share from a browser you can install the small and nice UI [[https://github.com/dom111/webdav-js|webdav-js]]:
-To watch the share from a browser you can install the small and nice UI  +
-https://github.com/dom111/webdav-js +
- +
-Create a file in /srv/disk/dav/index.html with the content:+
  
 <code html> <code html>
 +cat << EOF > /mnt/disk/dav/index.html
 <!DOCTYPE html> <!DOCTYPE html>
 <html lang="en"> <html lang="en">
 <head> <head>
-    <meta charset="UTF-8"> +<meta charset="UTF-8"> 
-    <title>WebDAV</title> +<title>WebDAV</title> 
-    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/dom111/webdav-js/assets/css/style-min.css"/>+<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/dom111/webdav-js/assets/css/style-min.css"/>
 </head> </head>
 <body> <body>
Line 97: Line 90:
 </body> </body>
 </html> </html>
 +EOF
 </code> </code>
  
-Then open http://192.168.1.1/dav/ and you'll see a simple file manager.+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.+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. 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 to backup data. Some notable apps:
 +  * [[https://diffuse.sh/|Diffuse]] a music player [[https://github.com/icidasset/diffuse|Source code]]
 +  * [[https://app.super-productivity.com/|Supper Productivity]] a powerful TODO App. [[https://github.com/johannesjo/super-productivity|Source code]]
 +  * [[https://buttercup.pw/|Buttercup]] a password manager as a browser extension.
 +  * [[https://app.keeweb.info/|KeeWeb]] a password manager as PWA
 +
 +To allow online apps to connect with your WebDAV it need a CORS enabled.
 +Here is an example [[https://gist.github.com/stokito/0a6274106d407ba6d9fb776e7773445d]]
 +
 +== Useful Apps ==
 +Useful mobile apps that supports WebDAV sync:
 +  * [[https://www.orgzly.com/|Orgzly]] Outliner for notes and to-do lists. [[https://github.com/orgzly|Source code]]
 +  * [[https://www.cloudbeatsapp.com/|CloudBeats]] a music player. Not FOSS!
 +
  
 ==== Links and docs ==== ==== Links and docs ====
-  * https://redmine.lighttpd.net/projects/1/wiki/docs_modauth +  * [[https://redmine.lighttpd.net/projects/1/wiki/docs_modauth|Module mod_auth - Using authentication]] 
-  * https://redmine.lighttpd.net/projects/1/wiki/Docs_ModWebDAV +  * [[https://redmine.lighttpd.net/projects/1/wiki/Docs_ModWebDAV|Module mod_webdav - WebDAV]] 
-  * https://redmine.lighttpd.net/projects/1/wiki/Docs_ModSecDownload +  * [[https://redmine.lighttpd.net/projects/1/wiki/Docs_ModSecDownload|Module mod_secdownload - Secure and fast downloading]] 
-  * https://github.com/fstanis/awesome-webdav+  * [[https://github.com/fstanis/awesome-webdav|Awesome WebDAV]] a list of software that works with WebDAV.
   * [[https://gist.github.com/stokito/77c42f8aff2dade91621c1051f73e58c|WebDAV with Lighttpd on Turris Omnia (TurrisOS)]]   * [[https://gist.github.com/stokito/77c42f8aff2dade91621c1051f73e58c|WebDAV with Lighttpd on Turris Omnia (TurrisOS)]]
  
 +==== ZeroConf autodiscovery ====
 +You can advertise a WebDAV share with [[docs:guide-developer:mdns|umdns]].
 +Then it will be seen in Network folder of a file manager in GNOME and KDE and can be [[https://kodi.wiki/view/Avahi_Zeroconf|discovered from a Kodi media player]].
 +
 +Install the umdns package with ''opkg install umdns'' and create a service description file:
 +
 +<code - /etc/umdns/lighttpd_webdav.json>
 +{
 +  "lighttpd_webdav": {
 +    "service": "_webdav._tcp.local",
 +    "port": 80,
 +    "txt": [
 +      "path=/dav/",
 +      "u=media"
 +    ]
 +  }
 +}
 +</code>
 +
 +The reload the umdns service with: ''ubus call umdns reload'' or ''service umdns reload''.
  • Last modified: 2024/12/19 14:35
  • by stokito