diff --git a/doc/webfuse.md b/doc/webfuse.md index adc749c..34cca0f 100644 --- a/doc/webfuse.md +++ b/doc/webfuse.md @@ -15,11 +15,14 @@ filesystem via fuse and exposes it's API via websockets. | --wf-vhost | vhost | localhost | Specify the name of the websocket server's virtual host | | --wf-cert | path | - | Optional. Specify the file path of the server's public certificate | | --wf-key | path | - | Optional. Specify the file path of the server's private key | -| --wf- authenticator | path | - | Optional. Specify the file path of the authenticator executable | +| --wf-authenticator | path | - | Optional. Specify the file path of the authenticator executable | | --wf-auth-header | name | - | Optional. Specify the name of the HTTP header used for authentication | +| --wf-docroot | path | - | Optional. Enabled HTTP server with given document root. | | --wf-timeout | timeout | 10 | Optional. Specify the communication timeout. | | --wf-version | - | - | Print version and exit. | +**Note:** All paths must be absolute _(this might be relaxed if future versions)_. + ## Fuse options | Option | Descripion | diff --git a/src/webfuse/webfuse.cpp b/src/webfuse/webfuse.cpp index 2a9df2a..58c1799 100644 --- a/src/webfuse/webfuse.cpp +++ b/src/webfuse/webfuse.cpp @@ -40,6 +40,7 @@ WEBFUSE options: --wf-key PATH path of the server's private key (optional) --wf-authenticator PATH path of authenticatior app (optional) --wf-auth-header NAME name of the authentication header (optional) + --wf-docroot PATH enables HTTP server with given document root (optional) --wf-timeout TIMEOUT communication timeout in seconds (default: 10) --wf-version print version and exit )"; diff --git a/src/webfuse/ws/config.cpp b/src/webfuse/ws/config.cpp index f280ed8..2a35f4d 100644 --- a/src/webfuse/ws/config.cpp +++ b/src/webfuse/ws/config.cpp @@ -112,6 +112,10 @@ ws_config::ws_config(int argc, char * argv[]) timeout_secs = static_cast(std::stoi(timeout_str)); } } + else if (arg == "--wf-docroot") + { + get_arg(*this, reader, docroot, "missing DOCROOT"); + } else if (arg == "--wf-version") { cmd = command::print_version; diff --git a/src/webfuse/ws/config.hpp b/src/webfuse/ws/config.hpp index a1183bb..068fb4a 100644 --- a/src/webfuse/ws/config.hpp +++ b/src/webfuse/ws/config.hpp @@ -27,6 +27,7 @@ public: uint16_t port; std::string vhost_name; + std::string docroot; bool use_tls; std::string cert_path; diff --git a/src/webfuse/ws/server.cpp b/src/webfuse/ws/server.cpp index 731ae77..e41eba8 100644 --- a/src/webfuse/ws/server.cpp +++ b/src/webfuse/ws/server.cpp @@ -71,20 +71,33 @@ class ws_server::detail public: detail(ws_config const & config) : shutdown_requested(false) + , docroot(config.docroot) , data(config.authenticator, config.auth_header) , timeout_secs(config.timeout_secs) { lws_set_log_level(0, nullptr); + memset(reinterpret_cast(&http_mount), 0, sizeof(http_mount)); + http_mount.mount_next = nullptr; + http_mount.mountpoint = "/"; + http_mount.origin = docroot.c_str(); + http_mount.def = "index.html"; + http_mount.origin_protocol = LWSMPRO_FILE; + http_mount.mountpoint_len = 1; + memset(reinterpret_cast(protocols), 0, sizeof(protocols)); - protocols[0].name = "webfuse2"; - protocols[0].callback = &ws_server_callback; - protocols[0].per_session_data_size = 0; - protocols[0].user = reinterpret_cast(&data); + protocols[0].name = "http"; + protocols[0].callback = lws_callback_http_dummy; + + protocols[1].name = "webfuse2"; + protocols[1].callback = &ws_server_callback; + protocols[1].per_session_data_size = 0; + protocols[1].user = reinterpret_cast(&data); memset(reinterpret_cast(&info), 0, sizeof(info)); info.port = config.port; - info.protocols = protocols; + info.mounts = &http_mount; + info.protocols = (docroot.empty()) ? &protocols[1] : protocols; info.vhost_name = config.vhost_name.c_str(); info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE | LWS_SERVER_OPTION_EXPLICIT_VHOSTS; @@ -121,9 +134,11 @@ public: std::thread thread; std::atomic shutdown_requested; - lws_protocols protocols[2]; + lws_protocols protocols[3]; + lws_http_mount http_mount; lws_context_creation_info info; lws_context * context; + std::string docroot; server_handler data; uint64_t timeout_secs; };