################################################################################
# Sample WsgiDAV configuration file
#
# 1. Rename this file to `wsgidav.conf`
# 2. Adjust settings as appropriate
# 3. Run `wsgidav` from the same directory or pass file name with `--config` option.
#
# NOTE: the recommended configuration file format is now YAML.
#
# See http://wsgidav.readthedocs.io/en/latest/user_guide_configure.html
#

# HELPERS - Do not modify this section

provider_mapping = {}
user_mapping = {}


def addShare(shareName, davProvider):
    provider_mapping[shareName] = davProvider


def addUser(realmName, user, password, description, roles=[]):
    realmName = "/" + realmName.strip(r"\/")
    userDict = user_mapping.setdefault(realmName, {}).setdefault(user, {})
    userDict["password"] = password
    userDict["description"] = description
    userDict["roles"] = roles


################################################################################
# SERVER OPTIONS
#===============================================================================
# Run WsgiDAV inside this  WSGI server.
# Supported servers: "cheroot", "cherrypy-wsgiserver", "ext_wsgiutils",
#     "flup-fcgi", "flup-fcgi-fork", "paste", "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'.)
# Default: "cheroot", use the --server option on command line to change this.

#server = "cheroot"

# Additional arguments passed to the server on initialization (depends on `server`)
# For example for cheroot:

#server_args = {
#    "numthreads": 10,
#    "max": -1,
#    "request_queue_size": 5,
#    "timeout": 10,
#    "shutdown_timeout": 5,
#    "verbose": 0,
#}

# Server port (default: 8080, use --port on command line)
port = 8080

# Server hostname (default: localhost, use --host on command line)
host = "localhost"

#===============================================================================
# Enable SSL support
# Note:
# A valid certificate must match the servers hostname, so the bogus certs will
# not work in all scenarios.
# Create your own certificates instead!

# ssl_certificate = "wsgidav/server/sample_bogo_server.crt"
# ssl_private_key = "wsgidav/server/sample_bogo_server.key"
# ssl_certificate_chain = None

# Cheroot server supports 'builtin' and 'pyopenssl' (default: 'builtin')
# ssl_adapter = "pyopenssl"


#================================================================================
# Misc. setings
#

# Add the MS-Author-Via Response Header to OPTIONS command to allow editing
# with Microsoft Office (default: False)

add_header_MS_Author_Via = True


# Block size in bytes

# block_size = 8192


# Set this to True, to force unquoting of PATH_INFO. This should already be done by the WSGI
# Framework, so this setting should only be used to fix unexpected problems there (see issue #8).

# unquote_path_info = False


# Re-encode PATH_INFO using UTF-8 (falling back to ISO-8859-1).
# This seems to be wrong, since per PEP 3333 PATH_INFO is always ISO-8859-1 encoded
# (see https://www.python.org/dev/peps/pep-3333/#unicode-issues).
# However it seems to resolve errors when accessing resources with Chinese characters, for
# example (see issue #73).
# Set to `None` (the default) to enable this for Python 3 only.

# re_encode_path_info = None


#===============================================================================
# Middlewares
#
# Use this section to override the default middleware stack

#from wsgidav.dir_browser import WsgiDavDirBrowser
#from debug_filter import WsgiDavDebugFilter
#from http_authenticator import HTTPAuthenticator
#from error_printer import ErrorPrinter
#middleware_stack = [ WsgiDavDirBrowser, HTTPAuthenticator, ErrorPrinter, WsgiDavDebugFilter ]

#===============================================================================
# Debugging

verbose = 3          # 0 - quiet
                     # 1 - no output (excepting application exceptions)
                     # 2 - warnings and errors only
                     # 3 - show single line request summaries (HTTP logging)
                     # 4 - show additional events
                     # 5 - show full request/response header info (HTTP Logging)
                     #     request body and GET response bodies not shown


# Enable specific module loggers
# E.g. ["lock_manager", "property_manager", "http_authenticator", ...]
enable_loggers = []

# Enable max. logging for certain http methods
# E.g. ["COPY", "DELETE", "GET", "HEAD", "LOCK", "MOVE", "OPTIONS", "PROPFIND", "PROPPATCH", "PUT", "UNLOCK"]
debug_methods = []

# Enable max. logging during  litmus suite tests that contain certain strings
# E.g. ["lock_excl", "notowner_modify", "fail_cond_put_unlocked", ...]
debug_litmus = []


################################################################################
# WsgiDavDirBrowser
# to enable dir browsing put WsgiDavDirBrowser into middleware_stack config option (see above)

dir_browser = {
    "enable": True,               # Render HTML listing for GET requests on collections
    "ignore": [],
    "response_trailer": "",       # Raw HTML code, appended as footer
    "davmount": False,            # Send <dm:mount> response if request URL contains '?davmount'
    "ms_mount": False,            # Add an 'open as webfolder' link (requires Windows)
    "ms_sharepoint_support": True,  # Invoke MS Offce documents for editing using WebDAV
#    "app_class": MyBrowser,      # (DEPRECATED with 2.4.0) Used instead of WsgiDavDirBrowser
}


################################################################################
# DAV Provider

#===============================================================================
# Property Manager
#
# Uncomment this lines to specify your own property manager.
# Default:        no support for dead properties
# Also available: wsgidav.prop_man.property_manager.PropertyManager
#                 wsgidav.prop_man.property_manager.ShelvePropertyManager
#
# Check the documentation on how to develop custom property managers.
# Note that the default PropertyManager works in-memory, and thus is NOT
# persistent.

### Use in-memory property manager (NOT persistent)
# (this is the same as passing 'property_manager = True')
#from wsgidav.prop_man.property_manager import PropertyManager
#property_manager = PropertyManager()

### Use persistent shelve based property manager
#from wsgidav.prop_man.property_manager import ShelvePropertyManager
#property_manager = ShelvePropertyManager("wsgidav-props.shelve")

### Use persistent MongoDB based property manager
#from wsgidav.prop_man.mongo_property_manager import MongoPropertyManager
#prop_man_opts = {}
#property_manager = MongoPropertyManager(prop_man_opts)

### Use persistent CouchDB based property manager
#from wsgidav.prop_man.couch_property_manager import CouchPropertyManager
#prop_man_opts = {}
#property_manager = CouchPropertyManager(prop_man_opts)

### Use in-memory property manager (NOT persistent)
property_manager = True


### Optional additional live property modification
# Note: by default live properties like file size and last-modified time are
# read-only, but that can be overriden here if the underlying DAV provider
# supports it. For now only the FileSystemProvider supports it and only namely
# changes to the last-modified timestamp. Enable it with the mutable_live_props
# list as below to allow clients to use the utime system call or e.g. the
# touch or cp / rsync commands with the preserve-timestamp flags on a mounted
# DAV share.
# Please note that the timestamp is set on the actual file or directory, so it
# is persistent even for in-memory property managers. It should also be noted
# that mutable last-modified may not be compliant with the RFC 4918.

# mutable_live_props = ["{DAV:}getlastmodified"]


# Handle Microsoft's Win32LastModifiedTime property.
# This is useful only in the case when you copy files from a Windows
# client into a WebDAV share. Windows sends the "last modified" time of
# the file in a Microsoft extended property called "Win32LastModifiedTime"
# instead of the standard WebDAV property "getlastmodified". So without
# this config option set to "True", the "last modified" time of the copied
# file will be "now" instead of its original value.
# The proper solution for dealing with the Windows WebDAV client is to use
# a persistent property manager. This setting is merely a work-around.
# NOTE: Works with Win10, can't work with Win7. Other versions untested.

# emulate_win32_lastmod: True


#===============================================================================
# Lock Manager
#
# Uncomment this lines to specify your own locks manager.
# Default:        wsgidav.lock_storage.LockStorageDict
# Also available: wsgidav.lock_storage.LockStorageShelve
#
# Check the documentation on how to develop custom lock managers.
# Note that the default LockStorageDict works in-memory, and thus is NOT
# persistent.

# Example: Use in-memory lock storage
#          (this is the same as passing 'lock_manager = True', which is default)
#from wsgidav.lock_storage import LockStorageDict
#lock_manager = LockStorageDict()


# Example: Use PERSISTENT shelve based lock manager
#from wsgidav.lock_storage import LockStorageShelve
#lock_manager = LockStorageShelve("wsgidav-locks.shelve")


################################################################################
# SHARES
#
# If you would like to publish files in the location '/v_root' through a
# WsgiDAV share 'files', so that it can be accessed by this URL:
#     http://server:port/files
# insert the following line:
#     addShare("files", "/v_root")
# or on a Windows box:
#     addShare("files", "c:\\v_root")
#
# To access the same directory using a root level share
#     http://server:port/
# insert this line:
#     addShare("", "/v_root")
#
# The above examples use wsgidav.fs_dav_provider.FilesystemProvider, which is
# the default provider implementation.
#
# If you wish to use a custom provider, an object must be passed as second
# parameter. See the examples below.


### Add a read-write file share:
addShare("dav", r"C:\temp")

### Add a read-only file share:
#from wsgidav.fs_dav_provider import FilesystemProvider
#addShare("tmp", FilesystemProvider("/tmp", readonly=True))


### Publish an MySQL 'world' database as share '/world-db'
#from wsgidav.samples.mysql_dav_provider import MySQLBrowserProvider
#addShare("world-db", MySQLBrowserProvider("localhost", "root", "test", "world"))


### Publish a virtual structure
#from wsgidav.samples.virtual_dav_provider import VirtualResourceProvider
#addShare("virtres", VirtualResourceProvider())


### Publish a Mercurial repository
#from wsgidav.samples.hg_dav_provider import HgResourceProvider
#addShare("hg", HgResourceProvider("PATH_OR_URL"))


### Publish a MongoDB
#from wsgidav.samples.mongo_dav_provider import MongoResourceProvider
#mongo_dav_opts = {}
#addShare("mongo", MongoResourceProvider(mongo_dav_opts))


################################################################################
# AUTHENTICATION
#===============================================================================
# HTTP Authentication Options

http_authenticator = {
    "domain_controller": None,  # Use SimpleDomainController
    "accept_basic": True,  # Allow basic authentication, True or False
    "accept_digest": True,  # Allow digest authentication, True or False
    "default_to_digest": True,  # True (default digest) or False (default basic)
    # Enter the name of a header field that will be accepted as authorized user.
    # Including quotes, for example: trusted_auth_header = "REMOTE_USER"
    "trusted_auth_header": None,
    }


simple_dc = {
    "user_mapping": user_mapping,
    }

#===============================================================================
# USERS
#
# This section is ONLY used by the DEFAULT Domain Controller.
#
# Users are defined per realm:
#     addUser(<realm>, <user>, <password>, <description>)
#
# Note that the default Domain Controller uses the share name as realm name.
#
# If no users are specified for a realm, no authentication is required.
# Thus granting read-write access to anonymous!
#
# Note: If you wish to use Windows WebDAV support (such as Windows XP's My
# Network Places), you need to include the domain of the user as part of the
# username (note the DOUBLE slash), such as:
# addUser("v_root", "domain\\user", "password", "description")

addUser("", "tester", "secret", "")
addUser("", "tester2", "secret2", "")

#addUser("dav", "tester", "secret", "")
#addUser("dav", "tester2", "secret2", "")

#addUser("virtres", "tester", "secret", "")
