### Install wsgidav from Source Source: https://github.com/mar10/wsgidav/blob/master/docs/source/development.md Install the wsgidav package in editable mode for development. ```bash pip install -e . ``` -------------------------------- ### Install WsgiDAV with Cheroot Source: https://github.com/mar10/wsgidav/blob/master/docs/source/index.md Install WsgiDAV and the Cheroot WSGI server using pip. This is a common setup for running WsgiDAV. ```default $ pip install cheroot wsgidav ``` -------------------------------- ### WsgiDAV YAML Configuration Example Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_configure.md Example of a wsgidav.yaml configuration file. Note the 'mount_path' setting which is exposed differently by the reverse proxy. ```yaml host: 127.0.0.1 port: 8080 mount_path: "/drive" provider_mapping: "/public_drive": # Exposed as http://HOST/drive by nginx reverse proxy root: "fixtures/share" ``` -------------------------------- ### Install and Run WsgiDAV with gevent Server Source: https://github.com/mar10/wsgidav/blob/master/tests/stressor/results.md Installs the gevent library and then runs WsgiDAV with the gevent server. Use this to test WsgiDAV performance with gevent. ```bash $ pip install gevent $ wsgidav --root tests/stressor/htdocs/ --host 127.0.0.1 --port 8082 --auth anonymous --no-config --server gevent -q ``` -------------------------------- ### Install and Run WsgiDAV Command-Line Source: https://github.com/mar10/wsgidav/blob/master/README.md Install WsgiDAV and Cheroot, then run the server with anonymous authentication, exposing a local directory. Use 'wsgidav --help' for more options. ```bash pip install wsgidav cheroot wsgidav --host=0.0.0.0 --port=80 --root=/tmp --auth=anonymous ``` ```log $ pip install wsgidav cheroot $ wsgidav --host=0.0.0.0 --port=80 --root=/tmp --auth=anonymous Running without configuration file. 10:54:16.597 - INFO : WsgiDAV/4.0.0-a1 Python/3.9.1 macOS-12.0.1-x86_64-i386-64bit 10:54:16.598 - INFO : Registered DAV providers by route: 10:54:16.598 - INFO : - '/:dir_browser': FilesystemProvider for path '/Users/martin/prj/git/wsgidav/wsgidav/dir_browser/htdocs' (Read-Only) (anonymous) 10:54:16.599 - INFO : - '/': FilesystemProvider for path '/tmp' (Read-Write) (anonymous) 10:54:16.599 - WARNING : Basic authentication is enabled: It is highly recommended to enable SSL. 10:54:16.599 - WARNING : Share '/' will allow anonymous write access. 10:54:16.813 - INFO : Running WsgiDAV/4.0.0-a1 Cheroot/8.5.2 Python 3.9.1 10:54:16.813 - INFO : Serving on http://0.0.0.0:80 ... ``` -------------------------------- ### Run Uvicorn Server Source: https://github.com/mar10/wsgidav/blob/master/docs/source/source_server_cli.md Starts the WsgiDAV application using the Uvicorn server. Ensure Uvicorn is installed. ```python version = f"uvicorn/{uvicorn.__version__}" version = f"{util.public_wsgidav_info} {version} {util.public_python_info}" _logger.info(f"Running {version} ...") uvicorn.run(app, **server_args) ``` -------------------------------- ### Install WsgiDAV from GitHub Source: https://github.com/mar10/wsgidav/blob/master/docs/source/installation.md Installs the latest development version of WsgiDAV directly from its GitHub repository using pip. ```bash pip install git+https://github.com/mar10/wsgidav.git ``` -------------------------------- ### Install WsgiDAV using Winget on Windows Source: https://github.com/mar10/wsgidav/blob/master/docs/source/index.md Install WsgiDAV using the Windows Package Manager (winget). This is an alternative installation method for Windows users. ```default > winget install wsgidav ``` -------------------------------- ### Install Cheroot WSGI Server Source: https://github.com/mar10/wsgidav/blob/master/docs/source/installation.md Installs the Cheroot WSGI server, which is required to run WsgiDAV from the command line. ```bash pip install cheroot ``` -------------------------------- ### Install Development Requirements Source: https://github.com/mar10/wsgidav/blob/master/docs/source/development.md Install development dependencies from the requirements file. ```bash pip install -r requirements-dev.txt ``` -------------------------------- ### Example Docker Run Command Source: https://github.com/mar10/wsgidav/blob/master/docs/source/installation.md An example of how to run the WsgiDAV Docker container, mapping port 8080 on the host to port 8080 in the container and sharing the 'c:/temp' directory. ```bash docker run --rm -it -p 8080:8080 -v c:/temp:/var/wsgidav-root mar10/wsgidav ``` -------------------------------- ### Install lxml (Optional) Source: https://github.com/mar10/wsgidav/blob/master/docs/source/installation.md Installs the lxml library on Ubuntu using apt-get. This is an optional dependency that can improve the performance of PROPPATCH requests. ```bash sudo apt-get install python-lxml ``` -------------------------------- ### WsgiDAV Server Command Line Examples Source: https://github.com/mar10/wsgidav/blob/master/docs/source/source_server_cli.md Demonstrates how to run the WsgiDAV server using command-line arguments for sharing a filesystem folder or using a specific configuration file. It also mentions the default configuration file search behavior. ```bash wsgidav --port=80 --host=0.0.0.0 --root=/temp --auth=anonymous ``` ```bash wsgidav --port=80 --host=0.0.0.0 --config=~/my_wsgidav.yaml ``` -------------------------------- ### Initialize Configuration and Run Server Source: https://github.com/mar10/wsgidav/blob/master/docs/source/source_server_cli.md Main entry point for the WsgiDAV server CLI. Initializes configuration, sets up logging, and starts the selected server handler. ```python from multiprocessing import freeze_support freeze_support() run() ``` -------------------------------- ### Run WsgiDAV Server Source: https://github.com/mar10/wsgidav/blob/master/tests/stressor/results.md Command to start a WsgiDAV server for stress testing. Ensure you are in the correct project directory. ```bash cd /wsgidav wsgidav --root tests/stressor/htdocs/ --host 127.0.0.1 --port 8082 --auth anonymous --no-config -q ``` -------------------------------- ### Instantiate middleware with arguments Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_configure.md Example of how to instantiate a middleware component with specific arguments when building the middleware stack. ```python from wsgidav.mw.debug_filter import WsgiDavDebugFilter debug_filter = WsgiDavDebugFilter(wsgidav_app, next_app, config) conf = { ... "middleware_stack": [ debug_filter, ... ], ... } ``` -------------------------------- ### Install WsgiDAV with PAM Authentication Source: https://github.com/mar10/wsgidav/blob/master/README.md Install WsgiDAV with the 'pam' extra requirement for PAM login authentication on Linux/OSX. Then, run the server specifying the 'pam-login' authentication method. ```bash pip install wsgidav[pam] wsgidav --host=0.0.0.0 --port=8080 --root=/tmp --auth=pam-login ``` -------------------------------- ### Reference URL Examples Source: https://github.com/mar10/wsgidav/blob/master/docs/source/reference_guide_glossary.md Provides examples of reference URLs, which are unique identifiers for resources used in WsgiDAV, including those derived from virtual locations. ```default /dav/public/my%20folder/file1.txt /dav/by_key/1234 /dav/by_status/approved/file1.txt ``` ```default /dav/by_key/1234 ``` -------------------------------- ### Get WsgiDAV CLI Help Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_cli.md Display the help message for the WsgiDAV command-line interface, showing all available options and their descriptions. ```default $ wsgidav --help usage: wsgidav [-h] [-p PORT] [-H HOST] [-r ROOT_PATH] [--auth {anonymous,nt,pam-login}] [--server {cheroot,ext-wsgiutils,gevent,gunicorn,paste,uvicorn,wsgiref}] [--ssl-adapter {builtin,pyopenssl}] [-v | -q] [-c CONFIG_FILE | --no-config] [--browse] [-V] Run a WEBDAV server to share file system folders. Examples: Share filesystem folder '/temp' for anonymous access (no config file used): wsgidav --port=80 --host=0.0.0.0 --root=/temp --auth=anonymous Run using a specific configuration file: wsgidav --port=80 --host=0.0.0.0 --config=~/my_wsgidav.yaml If no config file is specified, the application will look for a file named 'wsgidav.yaml' in the current directory. See http://wsgidav.readthedocs.io/en/latest/run-configure.html for some explanation of the configuration file format. optional arguments: -h, --help show this help message and exit -p PORT, --port PORT port to serve on (default: 8080) -H HOST, --host HOST host to serve from (default: localhost). 'localhost' is only accessible from the local computer. Use 0.0.0.0 to make your application public -r ROOT_PATH, --root ROOT_PATH path to a file system folder to publish as share '/'. --auth {anonymous,nt,pam-login} quick configuration of a domain controller when no config file is used --server {cheroot,ext-wsgiutils,gevent,gunicorn,paste,uvicorn,wsgiref} type of pre-installed WSGI server to use (default: cheroot). --ssl-adapter {builtin,pyopenssl} used by 'cheroot' server if SSL certificates are configured (default: builtin). -v, --verbose increment verbosity by one (default: 3, range: 0..5) -q, --quiet decrement verbosity by one -c CONFIG_FILE, --config CONFIG_FILE configuration file (default: ('wsgidav.yaml', 'wsgidav.json') in current directory) --no-config do not try to load default ('wsgidav.yaml', 'wsgidav.json') --browse open browser on start -V, --version print version info and exit (may be combined with --verbose) Licensed under the MIT license. See https://github.com/mar10/wsgidav for additional information. ``` -------------------------------- ### Verify WsgiDAV Installation Source: https://github.com/mar10/wsgidav/blob/master/docs/source/installation.md Checks the installed WsgiDAV version and displays verbose information. Also shows the help message for the wsgidav command. ```bash wsgidav --version -v wsgidav --help ``` -------------------------------- ### Install WsgiDAV with pip Source: https://github.com/mar10/wsgidav/blob/master/docs/source/installation.md Installs WsgiDAV, Cheroot, and lxml using pip within a virtual environment. It's recommended to use a virtual environment for managing project dependencies. ```bash $ mkdir wsgidav_test $ cd wsgidav_test $ wsgidav_test % python -m venv .venv $ wsgidav_test % source .venv/bin/activate $ (.venv) wsgidav_test % python -m pip install -U pip $ (.venv) wsgidav_test % python -m pip install wsgidav cheroot lxml $ (.venv) wsgidav_test % wsgidav --root . --auth anonymous --browse ``` -------------------------------- ### Install davfs2 on Ubuntu Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_access.md Install the davfs2 package to enable mounting WebDAV file systems on Ubuntu. This is a prerequisite for using davfs2. ```default $ sudo apt-get install davfs2 ``` -------------------------------- ### Check wsgidav Version Source: https://github.com/mar10/wsgidav/blob/master/docs/source/development.md Verify the installed wsgidav version. ```bash wsgidav --version ``` -------------------------------- ### Run WsgiDAV with Cheroot Server Source: https://github.com/mar10/wsgidav/blob/master/docs/source/source_server_cli.md Use this snippet to run WsgiDAV with the cheroot.server backend. Ensure cheroot is installed (`pip install cheroot`). Supports SSL configuration. ```python def _run_cheroot(app, config, _server): """Run WsgiDAV using cheroot.server (https://cheroot.cherrypy.dev/).""" try: from cheroot import server, wsgi except ImportError: _logger.exception("Could not import Cheroot (https://cheroot.cherrypy.dev/).") _logger.error("Try `pip install cheroot`.") return False version = ( f"{util.public_wsgidav_info} {wsgi.Server.version} {util.public_python_info}" ) # wsgi.Server.version = version info = _get_common_info(config) # Support SSL if info["use_ssl"]: ssl_adapter = info["ssl_adapter"] ssl_adapter = server.get_ssl_adapter_class(ssl_adapter) wsgi.Server.ssl_adapter = ssl_adapter( info["ssl_cert"], info["ssl_pk"], info["ssl_chain"] ) _logger.info(f"SSL / HTTPS enabled. Adapter: {ssl_adapter}") _logger.info(f"Running {version}") _logger.info(f"Serving on {info['url']} ...") server_args = { "bind_addr": (config["host"], config["port"]), "wsgi_app": app, "server_name": version, # File Explorer needs lot of threads (see issue #149): "numthreads": 50, # TODO: still required? } # Override or add custom args custom_args = util.get_dict_value(config, "server_args", as_dict=True) server_args.update(custom_args) class PatchedServer(wsgi.Server): STARTUP_NOTIFICATION_DELAY = 0.5 def serve(self, *args, **kwargs): _logger.error("wsgi.Server.serve") if startup_event and not startup_event.is_set(): Timer(self.STARTUP_NOTIFICATION_DELAY, startup_event.set).start() _logger.error("wsgi.Server is ready") return super().serve(*args, **kwargs) # If the caller passed a startup event, monkey patch the server to set it # when the request handler loop is entered startup_event = config.get("startup_event") if startup_event: server = PatchedServer(**server_args) else: server = wsgi.Server(**server_args) try: server.start() except KeyboardInterrupt: _logger.warning("Caught Ctrl-C, shutting down...") finally: server.stop() return ``` -------------------------------- ### Run WsgiDAV with paste.httpserver Source: https://github.com/mar10/wsgidav/blob/master/docs/source/source_server_cli.md Use this snippet to run WsgiDAV with paste.httpserver. Ensure Paste is installed (`pip install paste`). Supports custom logging for connection handling. ```python from paste import httpserver server = httpserver.serve( app, host=config["host"], port=config["port"], server_version=version, protocol_version="HTTP/1.1", start_loop=False, ) if config["verbose"] >= 5: __handle_one_request = server.RequestHandlerClass.handle_one_request def handle_one_request(self): __handle_one_request(self) if self.close_connection == 1: _logger.debug("HTTP Connection : close") else: _logger.debug("HTTP Connection : continue") server.RequestHandlerClass.handle_one_request = handle_one_request server.serve_forever() ``` -------------------------------- ### Run WsgiRef Server Source: https://github.com/mar10/wsgidav/blob/master/docs/source/source_server_cli.md Starts the WsgiDAV application using Python's built-in wsgiref.simple_server. This server is single-threaded and not recommended for production environments. ```python from wsgiref.simple_server import WSGIRequestHandler, make_server version = WSGIRequestHandler.server_version version = f"{util.public_wsgidav_info} {version}" # {util.public_python_info}" _logger.info(f"Running {version} ...") _logger.warning( "WARNING: This single threaded server (wsgiref) is not meant for production." ) WSGIRequestHandler.server_version = version httpd = make_server(config["host"], config["port"], app) # httpd.RequestHandlerClass.server_version = version try: httpd.serve_forever() except KeyboardInterrupt: _logger.warning("Caught Ctrl-C, shutting down...") return ``` -------------------------------- ### Run WsgiDAV with Anonymous Access Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_cli.md Serve the /tmp folder as a WebDAV / share with anonymous access. This command starts the server and displays its configuration and status. ```default $ wsgidav --host 0.0.0.0 --port 80 --root /tmp --auth anonymous Running without configuration file. 10:54:16.597 - INFO : WsgiDAV/4.0.0-a1 Python/3.9.1 macOS-12.0.1-x86_64-i386-64bit 10:54:16.598 - INFO : Lock manager: LockManager(LockStorageDict) 10:54:16.598 - INFO : Property manager: None 10:54:16.598 - INFO : Domain controller: SimpleDomainController() 10:54:16.598 - INFO : Registered DAV providers by route: 10:54:16.598 - INFO : - '/:dir_browser': FilesystemProvider for path '/Users/martin/prj/git/wsgidav/wsgidav/dir_browser/htdocs' (Read-Only) (anonymous) 10:54:16.599 - INFO : - '/': FilesystemProvider for path '/tmp' (Read-Write) (anonymous) 10:54:16.599 - WARNING : Basic authentication is enabled: It is highly recommended to enable SSL. 10:54:16.599 - WARNING : Share '/' will allow anonymous write access. 10:54:16.599 - WARNING : Share '/:dir_browser' will allow anonymous read access. 10:54:16.599 - WARNING : Could not import lxml: using xml instead (up to 10% slower). Consider `pip install lxml`(see https://pypi.python.org/pypi/lxml). 10:54:16.813 - INFO : Running WsgiDAV/4.0.0-a1 Cheroot/8.5.2 Python 3.9.1 10:54:16.813 - INFO : Serving on http://0.0.0.0:80 ... ``` -------------------------------- ### Run WsgiDAV with gevent Server Source: https://github.com/mar10/wsgidav/blob/master/docs/source/source_server_cli.md Use this snippet to run WsgiDAV with the gevent backend. Ensure gevent is installed (`pip install gevent`). Supports SSL configuration and integrates with gevent's asynchronous capabilities. ```python def _run_gevent(app, config, server): """Run WsgiDAV using gevent if gevent (https://www.gevent.org). See https://github.com/gevent/gevent/blob/master/src/gevent/pywsgi.py#L1356 https://github.com/gevent/gevent/blob/master/src/gevent/server.py#L38 for more options. """ try: import gevent import gevent.monkey from gevent.pywsgi import WSGIServer except ImportError: _logger.exception("Could not import gevent (http://www.gevent.org).") _logger.error("Try `pip install gevent`.") return False gevent.monkey.patch_all() info = _get_common_info(config) version = f"gevent/{gevent.__version__}" version = f"{util.public_wsgidav_info} {version} {util.public_python_info}" # Override or add custom args server_args = { "wsgi_app": app, "bind_addr": (config["host"], config["port"]), } custom_args = util.get_dict_value(config, "server_args", as_dict=True) server_args.update(custom_args) if info["use_ssl"]: dav_server = WSGIServer( server_args["bind_addr"], app, keyfile=info["ssl_pk"], certfile=info["ssl_cert"], ca_certs=info["ssl_chain"], ) else: dav_server = WSGIServer(server_args["bind_addr"], app) # If the caller passed a startup event, monkey patch the server to set it # when the request handler loop is entered startup_event = config.get("startup_event") if startup_event: def _patched_start(): dav_server.start_accepting = org_start # undo the monkey patch org_start() _logger.info("gevent is ready") startup_event.set() org_start = dav_server.start_accepting dav_server.start_accepting = _patched_start _logger.info(f"Running {version}") _logger.info(f"Serving on {info['url']} ...") try: gevent.spawn(dav_server.serve_forever()) except KeyboardInterrupt: _logger.warning("Caught Ctrl-C, shutting down...") return ``` -------------------------------- ### Run wsgidav with Cheroot WSGI Server Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_lib.md Integrate wsgidav with the Cheroot WSGI server. This example publishes the '/Users/joe/pub' directory to 'http://0.0.0.0:8080/'. ```python from cheroot import wsgi from wsgidav.wsgidav_app import WsgiDAVApp config = { "host": "0.0.0.0", "port": 8080, "provider_mapping": { "/": "/Users/joe/pub", }, "verbose": 1, } app = WsgiDAVApp(config) server_args = { "bind_addr": (config["host"], config["port"]), "wsgi_app": app, } server = wsgi.Server(**server_args) try: server.start() except KeyboardInterrupt: print("Received Ctrl-C: stopping...") finally: server.stop() ``` -------------------------------- ### Extend middleware stack with third-party tools Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_configure.md Example demonstrating how to remove a default middleware (directory browser) and add a third-party debugging tool to the middleware stack. ```python import dozer # from wsgidav.dir_browser import WsgiDavDirBrowser from wsgidav.mw.debug_filter import WsgiDavDebugFilter from wsgidav.error_printer import ErrorPrinter from wsgidav.http_authenticator import HTTPAuthenticator from wsgidav.request_resolver import RequestResolver # Enable online profiling and GC inspection. See https://github.com/mgedmin/dozer ``` -------------------------------- ### Start Browser Automatically Source: https://github.com/mar10/wsgidav/blob/master/docs/source/source_server_cli.md Optionally opens a web browser to the server's URL after a short delay. Useful for quick testing and access. ```python from threading import Timer BROWSE_DELAY = 2.0 def _worker(): url = info["url"] url = url.replace("0.0.0.0", "127.0.0.1") _logger.info(f"Starting browser on {url} ...") webbrowser.open(url) Timer(BROWSE_DELAY, _worker).start() ``` -------------------------------- ### Run WsgiDAV with Docker Source: https://github.com/mar10/wsgidav/blob/master/docs/source/index.md Run WsgiDAV using a Docker container, exposing a local directory via WebDAV. This is an experimental setup for containerized deployments. ```default $ docker pull mar10/wsgidav $ docker run --rm -it -p :8080 -v :/var/wsgidav-root mar10/wsgidav ``` ```default $ docker run --rm -it -p 8080:8080 -v c:/temp:/var/wsgidav-root mar10/wsgidav ``` -------------------------------- ### Start WSGIDAv server with gevent backend Source: https://github.com/mar10/wsgidav/blob/master/tests/stressor/results.md Launch WSGIDAv WebDAV server using gevent as the WSGI server implementation with anonymous authentication on localhost port 8082. ```bash $ wsgidav --root tests/stressor/htdocs/ --host 127.0.0.1 --port 8082 --auth anonymous --no-config --server gevent -q ``` -------------------------------- ### Get wsgidav Version Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_lib.md Check the installed version of the wsgidav package. ```python from wsgidav import __version__ __version__ ``` -------------------------------- ### Initialize Server Configuration Source: https://github.com/mar10/wsgidav/blob/master/docs/source/source_server_cli.md Sets up the configuration dictionary by merging defaults, command-line options, and configuration file settings. Command-line arguments override file settings, which in turn override defaults. ```python def _init_config(): """Setup configuration dictionary from default, command line and configuration file.""" cli_opts, parser = _init_command_line_options() cli_verbose = cli_opts["verbose"] # Set config defaults config = copy.deepcopy(DEFAULT_CONFIG) config["_config_file"] = None config["_config_root"] = os.getcwd() # Configuration file overrides defaults config_file = cli_opts.get("config_file") if config_file: file_opts = _read_config_file(config_file, cli_verbose) util.deep_update(config, file_opts) if cli_verbose != DEFAULT_VERBOSE and "verbose" in file_opts: if cli_verbose >= 2: print( "Config file defines 'verbose: {}' but is overridden by command line: {}.".format( file_opts["verbose"], cli_verbose ) ) config["verbose"] = cli_verbose else: if cli_verbose >= 2: print("Running without configuration file.") # Command line overrides file if cli_opts.get("port"): config["port"] = cli_opts.get("port") if cli_opts.get("host"): config["host"] = cli_opts.get("host") if cli_opts.get("profile") is not None: config["profile"] = True if cli_opts.get("server") is not None: config["server"] = cli_opts.get("server") if cli_opts.get("ssl_adapter") is not None: config["ssl_adapter"] = cli_opts.get("ssl_adapter") # Command line overrides file only if -v or -q where passed: if cli_opts.get("verbose") != DEFAULT_VERBOSE: config["verbose"] = cli_opts.get("verbose") if cli_opts.get("root_path"): root_path = os.path.abspath(cli_opts.get("root_path")) config["provider_mapping"]["/"] = FilesystemProvider( root_path, fs_opts=config.get("fs_dav_provider"), ) if config["verbose"] >= 5: # TODO: remove passwords from user_mapping config_cleaned = util.purge_passwords(config) print( "Configuration({}):\n{}".format( cli_opts["config_file"], pformat(config_cleaned), ) ) if not config["provider_mapping"]: parser.error("No DAV provider defined.") # Quick-configuration of DomainController auth = cli_opts.get("auth") auth_conf = util.get_dict_value(config, "http_authenticator", as_dict=True) if auth and auth_conf.get("domain_controller"): parser.error( "--auth option can only be used when no domain_controller is configured" ) if auth == "anonymous": if config["simple_dc"]["user_mapping"]: parser.error( "--auth=anonymous can only be used when no user_mapping is configured" ) auth_conf.update( { "domain_controller": "wsgidav.dc.simple_dc.SimpleDomainController", "accept_basic": True, "accept_digest": True, "default_to_digest": True, } ) config["simple_dc"]["user_mapping"] = {"*": True} elif auth == "nt": if config.get("nt_dc"): parser.error( "--auth=nt can only be used when no nt_dc settings are configured" ) auth_conf.update( { "domain_controller": "wsgidav.dc.nt_dc.NTDomainController", "accept_basic": True, "accept_digest": False, "default_to_digest": False, } ) config["nt_dc"] = {} elif auth == "pam-login": if config.get("pam_dc"): parser.error( "--auth=pam-login can only be used when no pam_dc settings are configured" ) auth_conf.update( { "domain_controller": "wsgidav.dc.pam_dc.PAMDomainController", "accept_basic": True, "accept_digest": False, "default_to_digest": False, } ) config["pam_dc"] = {"service": "login"} # print(config) # if cli_opts.get("reload"): # print("Installing paste.reloader.", file=sys.stderr) # from paste import reloader # @UnresolvedImport # reloader.install() # if config_file: # # Add config file changes # reloader.watch_file(config_file) # # import pydevd # # pydevd.settrace() if config["suppress_version_info"]: util.public_wsgidav_info = "WsgiDAV" util.public_python_info = f"Python/{sys.version_info[0]}" return cli_opts, config ``` -------------------------------- ### Sample WsgiDAV Configuration Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_configure.md A sample wsgidav.yaml file demonstrating basic server configuration, including the WSGI server, host, and port. ```default # WsgiDAV configuration file # # 1. Rename this file to `wsgidav.yaml`. # 2. Adjust settings as appropriate. # 3. Run `wsgidav` from the same directory or pass file path with `--config` option. # # See https://wsgidav.readthedocs.io/en/latest/user_guide_configure.html # # ============================================================================ # SERVER OPTIONS #: Run WsgiDAV inside this WSGI server. #: Supported servers: #: cheroot, ext-wsgiutils, gevent, gunicorn, paste, uvicorn, wsgiref #: 'wsgiref' and 'ext_wsgiutils' are simple builtin servers that should *not* be #: used in production. #: All other servers must have been installed before, e.g. `pip install cheroot`. #: (The binary MSI distribution already includes 'cheroot'.) #: NOTE: Using 'gunicorn' with more than 1 worker can cause problems with the #: in-memory and shelve-based lock storage as both are not safe for concurrent #: access. (see issue #332) Instead, you can use 'gunicorn' with multiple `threads` #: or try the 'redis' based lock storage (#186). #: Default: 'cheroot', use the `--server` command line option to change this. server: cheroot #: Server specific arguments, passed to the server. For example cheroot: #: https://cheroot.cherrypy.dev/en/latest/pkg/cheroot.wsgi.html#cheroot.wsgi.Server # server_args: # max: -1 # numthreads: 10 # request_queue_size: 5 # shutdown_timeout: 5 # timeout: 10 # Server hostname (default: localhost, use --host on command line) host: 0.0.0.0 # Server port (default: 8080, use --port on command line) port: 8080 ``` -------------------------------- ### Run WsgiDAV Test Suite Source: https://github.com/mar10/wsgidav/blob/master/tests/teststatus_py3.md Execute the WsgiDAV test suite using the setup.py script. Ensure you are in the correct virtual environment. ```shell $ workon wsgidav3_py27 (wsgidav3_py27) $ python setup.py test ``` -------------------------------- ### Run WsgiDAV with Gunicorn Source: https://github.com/mar10/wsgidav/blob/master/docs/source/source_server_cli.md Use this snippet to run WsgiDAV with Gunicorn. Ensure Gunicorn is installed (`pip install gunicorn`). Supports SSL configuration. ```python import gunicorn.app.base class GunicornApplication(gunicorn.app.base.BaseApplication): def __init__(self, app, options=None): self.options = options or {} self.application = app super().__init__() def load_config(self): config = { key: value for key, value in self.options.items() if key in self.cfg.settings and value is not None } for key, value in config.items(): self.cfg.set(key.lower(), value) def load(self): return self.application # Example usage within _run_gunicorn function: server_args = { "bind": "{}:{}".format(config["host"], config["port"]), "threads": 50, "timeout": 1200, } if info["use_ssl"]: server_args.update({ "keyfile": info["ssl_pk"], "certfile": info["ssl_cert"], "ca_certs": info["ssl_chain"], }) custom_args = util.get_dict_value(config, "server_args", as_dict=True) server_args.update(custom_args) GunicornApplication(app, server_args).run() ``` -------------------------------- ### Sample WebDAV Provider for Virtual Structures Source: https://github.com/mar10/wsgidav/blob/master/docs/source/changelog04.md Notes the inclusion of a sample WebDAV provider designed for generic virtual structures. ```python Added a sample WebDAV provider for generich virtual structures ``` -------------------------------- ### Run WsgiDAV with Uvicorn Source: https://github.com/mar10/wsgidav/blob/master/docs/source/source_server_cli.md Use this snippet to run WsgiDAV with Uvicorn. Ensure Uvicorn is installed (`pip install uvicorn`). Supports SSL configuration and custom arguments. ```python import uvicorn server_args = { "interface": "wsgi", "host": config["host"], "port": config["port"], } if info["use_ssl"]: server_args.update({ "ssl_keyfile": info["ssl_pk"], "ssl_certfile": info["ssl_cert"], "ssl_ca_certs": info["ssl_chain"], }) custom_args = util.get_dict_value(config, "server_args", as_dict=True) server_args.update(custom_args) # Example usage within _run_uvicorn function: # uvicorn.run(app, **server_args) # This line is implied by the function's purpose but not explicitly in the provided snippet. ``` -------------------------------- ### Specify a configuration file Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_configure.md How to specify a custom configuration file using the --config option. ```bash $ wsgidav --config=my_config.yaml ``` -------------------------------- ### Serve a Directory with PAM Authentication on Linux Source: https://github.com/mar10/wsgidav/blob/master/docs/source/index.md Serve a directory with authentication against known users using PAM on Linux. This is suitable for environments with existing user accounts. ```default $ wsgidav --host=0.0.0.0 --port=80 --root=/tmp --auth=pam-login ``` -------------------------------- ### Build Documentation with Tox Source: https://github.com/mar10/wsgidav/blob/master/docs/source/development.md Generate the project's Sphinx documentation using the tox docs environment. ```bash tox -e docs ``` -------------------------------- ### Constructing a Complete URL Source: https://github.com/mar10/wsgidav/blob/master/docs/source/reference_guide_glossary.md Demonstrates how to construct a full URL using the `makeCompleteURL` utility function, which combines environment variables to form a complete URI. ```python fullUrl = util.makeCompleteURL(environ) ``` -------------------------------- ### Run Selective Tests with Pytest Source: https://github.com/mar10/wsgidav/blob/master/docs/source/development.md Directly call py.test to run selective tests, for example, specific files or modules. ```bash py.test -ra wsgidav tests/test_util.py ``` -------------------------------- ### Run WsgiDAV with CLI arguments Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_configure.md Basic command-line arguments for running WsgiDAV, specifying host, port, root directory, and authentication method. ```bash $ wsgidav --host=0.0.0.0 --port=8080 --root=/tmp --auth=anonymous Serving on http://0.0.0.0:8080 ... ``` -------------------------------- ### Format Code with Tox Source: https://github.com/mar10/wsgidav/blob/master/docs/source/development.md Re-format the code according to the project's style guide using the tox format environment. ```bash tox -e format ``` -------------------------------- ### Configure MongoPropertyManager Source: https://github.com/mar10/wsgidav/blob/master/docs/source/addons-mongo-propman.md Add these lines to your wsgidav.conf to initialize the MongoPropertyManager. Ensure the import statement is present. ```python from wsgidav.prop_man.mongo_property_manager import MongoPropertyManager prop_man_opts = {} property_manager = MongoPropertyManager(prop_man_opts) ``` -------------------------------- ### FilesystemProvider Constructor Source: https://github.com/mar10/wsgidav/blob/master/docs/source/changelog04.md Illustrates the constructor for FilesystemProvider, which now accepts 'rootFolderPath' to map URIs to absolute file paths. This change standardizes URI handling across providers. ```python !FilesystemProvider has a new constructor argument: 'rootFolderPath', so it can perform the mapping from URI to absolute file path. ``` -------------------------------- ### Initialize NTDomainController Source: https://github.com/mar10/wsgidav/blob/master/docs/source/addons-ntdc.md Instantiate the NTDomainController with the wsgidav application and configuration. The preset_domain and preset_server arguments can be used to specify a default domain or domain controller, respectively. ```python from wsgidav.dc.nt_dc import NTDomainController domain_controller = NTDomainController(wsgidav_app, config) ``` -------------------------------- ### Run WsgiDAV with Docker Source: https://github.com/mar10/wsgidav/blob/master/README.md Pull the WsgiDAV Docker image and run it, mapping a local folder to the container's WebDAV root and exposing the desired port. ```bash docker pull mar10/wsgidav docker run --rm -it -p :8080 -v :/var/wsgidav-root mar10/wsgidav ``` ```bash docker run --rm -it -p 8080:8080 -v /tmp:/var/wsgidav-root mar10/wsgidav ``` -------------------------------- ### Initialize CouchDB Property Manager Source: https://github.com/mar10/wsgidav/blob/master/docs/source/addons-couch-propman.md Add these lines to your wsgidav.conf to initialize the CouchDB property manager. Ensure CouchDB is running and accessible. ```python from wsgidav.prop_man.couch_property_manager import CouchPropertyManager prop_man_opts = {} property_manager = CouchPropertyManager(prop_man_opts) ``` -------------------------------- ### Configure Filesystem Provider Options Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_configure.md Set options for the FilesystemProvider, such as mapping specific URLs to file locations or enabling symbolic link following. ```yaml fs_dav_provider: #: Mapping from request URL to physical file location, e.g. #: make sure that a `/favicon.ico` URL is resolved, even if a `*.html` #: or `*.txt` resource file was opened using the DirBrowser # shadow_map: # '/favicon.ico': 'file_path/to/favicon.ico' #: Serve symbolic link files and folders (default: false) follow_symlinks: false ``` -------------------------------- ### Nginx Reverse Proxy Configuration for WsgiDAV Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_configure.md Example nginx.conf snippet for proxying requests to a WsgiDAV instance. It shows how to map external paths to internal WsgiDAV mount points. ```nginx http { ... server { listen 80; server_name example.com; ... location /drive/ { proxy_pass http://127.0.0.1:8080/public_drive/; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $host; } # If dir browser is enabled for WsgiDAV: location /drive/:dir_browser/ { proxy_pass http://127.0.0.1:8080/:dir_browser/; } ``` -------------------------------- ### Override Default Configuration with WsgiDAVApp Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_configure.md When a Python dictionary is passed to the `WsgiDAVApp` constructor, its values will override the defaults. This example shows how to set host, port, provider mapping, and verbosity. ```python root_path = gettempdir() provider = FilesystemProvider(root_path, readonly=False, fs_opts={}) config = { "host": "0.0.0.0", "port": 8080, "provider_mapping": {"/": provider}, "verbose": 1, } app = WsgiDAVApp(config) ``` -------------------------------- ### Run WsgiDAV with ext_wsgiutils Server Source: https://github.com/mar10/wsgidav/blob/master/docs/source/source_server_cli.md Use this snippet to run WsgiDAV with the ext_wsgiutils_server from the wsgidav package. This server is single-threaded and not recommended for production environments. ```python def _run_ext_wsgiutils(app, config, _server): """Run WsgiDAV using ext_wsgiutils_server from the wsgidav package.""" from wsgidav.server import ext_wsgiutils_server _logger.warning( "WARNING: This single threaded server (ext-wsgiutils) is not meant for production." ) try: ext_wsgiutils_server.serve(config, app) except KeyboardInterrupt: _logger.warning("Caught Ctrl-C, shutting down...") return ``` -------------------------------- ### Publish Virtual Resources Source: https://github.com/mar10/wsgidav/blob/master/docs/source/addons-virtual.md Add these lines to your configuration file to publish the sample virtual resources. This sets up a virtual share named 'virtres'. ```python from wsgidav.samples.virtual_dav_provider import VirtualResourceProvider addShare("virtres", VirtualResourceProvider()) ``` -------------------------------- ### Run WsgiDAV Performance Benchmarks Source: https://github.com/mar10/wsgidav/blob/master/tests/teststatus_py3.md Execute the WsgiDAV performance benchmark script. It is recommended to run the benchmarks twice and use the second result for analysis. ```shell $ workon wsgidav3_py27 (wsgidav3_py27) $ python tests/benchmarks.py ``` -------------------------------- ### Configure SSL Support Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_configure.md Specify paths for SSL certificate, private key, and certificate chain. Also, select the SSL adapter to use. ```yaml # ssl_certificate: 'wsgidav/server/sample_bogo_server.crt' # ssl_private_key: 'wsgidav/server/sample_bogo_server.key' # ssl_certificate_chain: null #: Cheroot server supports 'builtin' and 'pyopenssl' (default: 'builtin') # ssl_adapter: 'pyopenssl' ``` -------------------------------- ### Configure SimpleDomainController with User Mapping Source: https://github.com/mar10/wsgidav/blob/master/docs/source/user_guide_configure.md Use SimpleDomainController for basic user authentication against a plain mapping of shares and user names. The pseudo-share '*' maps all URLs not explicitly listed. Anonymous access can be enabled with 'true'. ```yaml http_authenticator: domain_controller: null # Same as wsgidav.dc.simple_dc.SimpleDomainController accept_basic: true # Pass false to prevent sending clear text passwords accept_digest: true default_to_digest: true simple_dc: user_mapping: "*": "user1": password: "abc123" "user2": password: "qwerty" "/pub": true ``` -------------------------------- ### WsgiDAV Version Information Source: https://github.com/mar10/wsgidav/blob/master/tests/stressor/results.md Command to display the version and build information for the WsgiDAV server. ```bash wsgidav -Vv ``` -------------------------------- ### Run Test Suite with Tox Source: https://github.com/mar10/wsgidav/blob/master/docs/source/development.md Execute the full test suite, including style checks and coverage, using tox. ```bash tox ``` -------------------------------- ### List Available Tox Targets Source: https://github.com/mar10/wsgidav/blob/master/docs/source/development.md Display all possible commands and targets available in tox. ```bash tox -av ```