sigyllly commited on
Commit
b4dd6fc
·
verified ·
1 Parent(s): aaa7691

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -44
app.py CHANGED
@@ -1,45 +1,49 @@
1
- from wsgidav.wsgidav_app import WsgiDAVApp
2
- from wsgidav.fs_dav_provider import FilesystemProvider
3
- from cheroot.wsgi import Server as WSGIServer
4
  import os
5
-
6
- # Configuration
7
- HOST = "0.0.0.0" # Listen on all interfaces
8
- PORT = 7860 # Port to run the server on
9
- PATH = "./webauth" # Directory to share via WebDAV
10
-
11
- # Create the webauth directory if it doesn't exist
12
- if not os.path.exists(PATH):
13
- os.makedirs(PATH)
14
- print(f"Created directory: {PATH}")
15
-
16
- # Create a sample test.txt file inside the webauth directory
17
- sample_file_path = os.path.join(PATH, "test.txt")
18
- with open(sample_file_path, "w") as f:
19
- f.write("This is a sample file for testing the WebDAV server.\n")
20
- print(f"Created sample file: {sample_file_path}")
21
-
22
- # Create a FilesystemProvider to serve files from the webauth directory
23
- provider = FilesystemProvider(PATH)
24
-
25
- # Configure the WebDAV app
26
- config = {
27
- "provider_mapping": {
28
- "/": provider, # Map the root URL to the provider
29
- },
30
- "http_authenticator": {
31
- "domain_controller": None, # Disable authentication
32
- },
33
- "simple_dc": None, # Disable simple domain controller
34
- "verbose": 1, # Enable verbose logging
35
- }
36
-
37
- # Create the WebDAV app
38
- app = WsgiDAVApp(config)
39
-
40
- # Create the WSGI server
41
- server = WSGIServer((HOST, PORT), app)
42
-
43
- # Start the server
44
- print(f"WebDAV server running on http://{HOST}:{PORT}")
45
- server.start()
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
+ from wsgidav.server.server_thread import WsgiDAVApp
3
+ from wsgidav.dav_provider import DAVProvider
4
+ from wsgidav.request import Request
5
+ from wsgidav.response import Response
6
+
7
+ # Create a folder named 'files' and add a 'sample.txt' file if not already present
8
+ directory = 'files'
9
+ file_name = os.path.join(directory, 'sample.txt')
10
+
11
+ # Create the directory and file if they do not exist
12
+ if not os.path.exists(directory):
13
+ os.makedirs(directory)
14
+
15
+ if not os.path.exists(file_name):
16
+ with open(file_name, 'w') as f:
17
+ f.write("This is a sample text file.")
18
+
19
+ # WebDAV Provider Class
20
+ class MyDAVProvider(DAVProvider):
21
+ def __init__(self, base_path):
22
+ super().__init__(base_path)
23
+
24
+ # WebDAV App Configuration
25
+ def start_webdav_server():
26
+ # The base folder that the WebDAV server will expose
27
+ base_path = os.path.abspath(directory)
28
+
29
+ # Set up the WebDAV provider (which provides file management)
30
+ provider = MyDAVProvider(base_path)
31
+
32
+ # Server settings (no authentication required)
33
+ config = {
34
+ "host": "0.0.0.0", # Listen on all interfaces
35
+ "port": 7860, # Port number
36
+ "provider": provider, # File system provider
37
+ "authenticator": None, # Disable authentication
38
+ }
39
+
40
+ # Create the WSGI WebDAV app
41
+ app = WsgiDAVApp(config)
42
+
43
+ print(f"Starting WebDAV server on http://0.0.0.0:7860/")
44
+
45
+ # Start the WebDAV server
46
+ app.run()
47
+
48
+ if __name__ == "__main__":
49
+ start_webdav_server()