|
|
import os |
|
|
from cheroot import wsgi |
|
|
from wsgidav.wsgidav_app import WsgiDAVApp |
|
|
from wsgidav.fs_dav_provider import FilesystemProvider |
|
|
|
|
|
from wsgidav.dir_browser import WsgiDavDirBrowser |
|
|
from wsgidav.error_printer import ErrorPrinter |
|
|
from wsgidav.http_authenticator import HTTPAuthenticator |
|
|
|
|
|
|
|
|
from wsgidav.mw.cors import Cors |
|
|
from wsgidav.request_resolver import RequestResolver |
|
|
|
|
|
DEFAULT_VERBOSE = 3 |
|
|
DEFAULT_LOGGER_DATE_FORMAT = "%H:%M:%S" |
|
|
DEFAULT_LOGGER_FORMAT = "%(asctime)s.%(msecs)03d - %(levelname)-8s: %(message)s" |
|
|
|
|
|
curr_path = os.path.dirname(os.path.realpath(__file__)) |
|
|
|
|
|
print(f"CP: {curr_path}") |
|
|
print(f"CWD: {os.getcwd()}") |
|
|
|
|
|
files_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "files") |
|
|
if not os.path.exists(files_dir): |
|
|
os.makedirs(files_dir) |
|
|
|
|
|
|
|
|
with open(os.path.join(files_dir, "sample.txt"), "w") as f: |
|
|
f.write("This is a sample file for the WebDAV server.") |
|
|
|
|
|
print(f"Created 'files' directory with sample.txt at {files_dir}") |
|
|
|
|
|
config = { |
|
|
"provider_mapping": { |
|
|
"/": FilesystemProvider(files_dir) |
|
|
}, |
|
|
"middleware_stack": [ |
|
|
|
|
|
Cors, |
|
|
ErrorPrinter, |
|
|
HTTPAuthenticator, |
|
|
|
|
|
WsgiDavDirBrowser, |
|
|
RequestResolver, |
|
|
], |
|
|
"http_authenticator": { |
|
|
"domain_controller": None, |
|
|
"accept_basic": True, |
|
|
"accept_digest": True, |
|
|
"default_to_digest": True, |
|
|
|
|
|
"trusted_auth_header": None, |
|
|
}, |
|
|
"simple_dc": {"user_mapping": { |
|
|
"*": { |
|
|
"user": { |
|
|
"password": "hunter123", |
|
|
"roles": ["editor", "admin"] |
|
|
} |
|
|
} |
|
|
}}, |
|
|
"verbose": DEFAULT_VERBOSE, |
|
|
"logging": { |
|
|
"enable": True, |
|
|
"logger_date_format": DEFAULT_LOGGER_DATE_FORMAT, |
|
|
"logger_format": DEFAULT_LOGGER_FORMAT, |
|
|
"enable_loggers": [], |
|
|
"debug_methods": [], |
|
|
}, |
|
|
"dir_browser": { |
|
|
"enable": True, |
|
|
|
|
|
"directory_slash": True, |
|
|
|
|
|
"ignore": [ |
|
|
".DS_Store", |
|
|
"._*", |
|
|
"Thumbs.db", |
|
|
], |
|
|
"icon": True, |
|
|
"response_trailer": True, |
|
|
"show_user": True, |
|
|
|
|
|
"davmount": True, |
|
|
|
|
|
"davmount_links": False, |
|
|
"ms_sharepoint_support": False, |
|
|
"libre_office_support": False, |
|
|
|
|
|
|
|
|
"htdocs_path": "/home/user/app/dir_browser/htdocs", |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
app = WsgiDAVApp(config) |
|
|
|
|
|
|
|
|
server_addr = "0.0.0.0" |
|
|
server_port = 7860 |
|
|
server = wsgi.Server((server_addr, server_port), app) |
|
|
|
|
|
print(f"Starting WebDAV server at http://{server_addr}:{server_port}") |
|
|
try: |
|
|
server.start() |
|
|
except KeyboardInterrupt: |
|
|
print("Stopping server...") |
|
|
server.stop() |