Browse Source

Reverse previous commit, which confused how tilde handling in Gegobi works with the way it works in Molly Brown. Actually fix the problem with accessing tilde paths, and a little bit of path handling tidy up.

master
Solderpunk 2 years ago
parent
commit
11aeee9248
1 changed files with 7 additions and 18 deletions
  1. 7
    18
      gegobi.py

+ 7
- 18
gegobi.py View File

@@ -52,10 +52,7 @@ class GegobiHandler(socketserver.BaseRequestHandler):
52 52
         while self.request_path.startswith(os.sep):
53 53
             self.request_path = self.request_path[1:]
54 54
         ## Handle tilde paths
55
-        if (self.request_path.startswith("~") or self.request_path.startswith("/~")) and self.server.args.tilde:
56
-            # Lop off leading slash
57
-            if self.request_path.startswith("/"):
58
-                self.request_path = self.request_path[1:]
55
+        if self.server.args.tilde and self.request_path.startswith("~"):
59 56
             bits = self.request_path.split(os.sep)
60 57
             # Remove ~ to get username
61 58
             bits[0] = bits[0][1:]
@@ -64,12 +61,11 @@ class GegobiHandler(socketserver.BaseRequestHandler):
64 61
             local_path = os.path.join(*bits)
65 62
         ## Standard path
66 63
         else:
67
-            local_path = os.path.join(self.server.args.base, urllib.parse.unquote(self.request_path))
68
-        ## Make absolutely sure we're not anywhere we shouldn't be
69
-        if not (local_path.startswith(self.server.args.base) or
70
-                local_path.startsiwth(self.server.args.tilde)):
71
-            self.send_gemini_header(51, "Not found.")
72
-            return
64
+            local_path = os.path.join(self.server.args.base, self.request_path)
65
+            ## Make absolutely sure we're not anywhere we shouldn't be
66
+            if not local_path.startswith(self.server.args.base):
67
+                self.send_gemini_header(51, "Not found.")
68
+                return
73 69
         # Handle not founds
74 70
         if not os.path.exists(local_path):
75 71
             self.send_gemini_header(51, "Not found.")
@@ -144,6 +140,7 @@ class GegobiHandler(socketserver.BaseRequestHandler):
144 140
         self.request_host = parsed.hostname
145 141
         self.request_port = parsed.port or 1965
146 142
         self.request_path = parsed.path[1:] if parsed.path.startswith("/") else parsed.path
143
+        self.request_path = urllib.parse.unquote(self.request_path)
147 144
         self.request_query = parsed.query
148 145
 
149 146
     def handle_geminimap(self, filename):
@@ -290,14 +287,6 @@ Gemini protocol as well, resulting in "Gemini-Gopher bi-hosting"
290 287
             args.base))
291 288
         sys.exit(1)
292 289
 
293
-    # Absolutise tilde directory and make sure it exists
294
-    if args.tilde:
295
-        args.tilde = os.path.abspath(os.path.join(args.base, args.tilde))
296
-        if not os.path.exists(args.base):
297
-            print("Could not find tilde directory {}.".format(
298
-                args.base))
299
-            sys.exit(1)
300
-
301 290
     if not (os.path.exists(args.cert) and os.path.exists(args.key)):
302 291
         print("Could not find certificate file {} and/or key file {}.".format(
303 292
             args.cert, args.key))

Loading…
Cancel
Save