1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00
libwebsockets/plugins/deaddrop
Andy Green d98101d1e3 plugins: generalize and provide public api
Move the common plugin scanning dir stuff to be based on lws_dir, which
already builds for windows.  Previously this was done via dirent for unix
and libuv for windows.

Reduce the dl plat stuff to just wrap instantiation and destruction of
dynlibs, establish common code in lib/misc/dir.c for plugin scanning
itself.

Migrate the libuv windows dl stuff to windows-plugins.c, so that he's
available even if later libuv loop support becomes and event lib plugin.

Remove the existing api exports scheme for plugins, just export a const struct
now which has a fixed header type but then whatever you want afterwards depending
on the class / purpose of the plugin.  Place a "class" string in the header so
there can be different kinds of plugins implying different types exported.

Make the plugin apis public and add support for filter by class string, and
per instantation / destruction callbacks so the subclassed header type can
do its thing for the plugin class.  The user provides a linked-list base
for his class of plugins, so he can manage them completely separately and
in user code / user export types.

Rip out some last hangers-on from generic sessions / tables.

This is all aimed at making the plugins support general enough so it can
provide event lib plugins later.
2020-08-31 16:51:37 +01:00
..
assets clean: codacy 2020-01-14 10:06:26 +00:00
protocol_lws_deaddrop.c plugins: generalize and provide public api 2020-08-31 16:51:37 +01:00
README.md plugin: lws deaddrop 2018-11-28 15:06:10 +08:00

Deaddrop: File upload and sharing plugin

Building the plugin

Just configure lws with cmake .. -DLWS_WITH_PLUGINS=1 and build lws as normal.

Configurable settings

pvo name value meaning
upload-dir A writeable directory where uploaded files will go
max-size Maximum individual file size in bytes
basic-auth Path to basic auth credential file so wss can also be protected

Required mounts

To use deaddrop meaningfully, all the mounts and the ws protocol must be protected by basic auth. And to use basic auth securely, the connection must be protected from snooping by tls.

  1. Set the basic-auth pvo to require valid credentials as described above

  2. Protect your basic fileserving mount by the same basic auth file... this is used to serve index.html, the css etc.

  3. Add a callback mount into "lws-deaddrop" protocol at "upload"... so if your URL for deaddrop is "/tools/share", this would be at "/tools/share/upload". It must also be protected by the basic auth file.

  4. Add a fileserving mount at the url "get" (continuing the example above, it would be "/tools/share/get" whose origin matches the "upload-dir" pvo value you selected. This mount needs any additional mimtype mappings since it's where the uploaded files are shared from.

Using with C

See ./minimal-examples/http-server/minimal-example-http-server-deaddrop for how to use the plugin directly with C.

Using with lwsws / lejp-conf

As a plugin, you can configure the mounts and pvos per-vhost easily in JSON.

All the snippets here

The mountpoints would look something like this (added to vhost/mounts)

	{
         "mountpoint": "/tools/share",
         "origin": "file:///var/www/deaddrop",
         "default": "index.html",
         "basic-auth": "/var/www/ba"
        }, {
         "mountpoint": "/tools/share/upload",
         "origin": "callback://lws-deaddrop",
         "basic-auth": "/var/www/ba"
        }, {
         "mountpoint": "/tools/share/get",
         "origin": "file:///var/cache/deaddrop-uploads",
         "basic-auth": "/var/www/ba",

	 "extra-mimetypes": {
		".bin": "application/octet-stream",
		".ttf": "application/x-font-truetype",
		".otf": "application/font-sfnt",
		".zip": "application/zip",
		".webm": "video/webm",
		".romfs": "application/octet-stream",
		".pdf": "application/pdf",
		".odt": "application/vnd.oasis.opendocument.text",
		".tgz": "application/x-gzip",
		".tar.gz": "application/x-gzip"
	  }
	}

This enables the plugin on the vhost, configures the pvos, and makes the wss serving also depend on having a valid basic auth credential.

         "ws-protocols": [{
                  "lws-deaddrop": {
                  "status": "ok",
                  "upload-dir": "/var/cache/deaddrop-uploads",
                  "max-size": "52428800",
                  "basic-auth": "/var/www/ba"
                }
          }],