2
2
Fork 0

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.

This commit is contained in:
Solderpunk 2020-02-01 20:44:29 +01:00
parent 2970846430
commit 11aeee9248
1 changed files with 7 additions and 18 deletions

View File

@ -52,10 +52,7 @@ class GegobiHandler(socketserver.BaseRequestHandler):
while self.request_path.startswith(os.sep):
self.request_path = self.request_path[1:]
## Handle tilde paths
if (self.request_path.startswith("~") or self.request_path.startswith("/~")) and self.server.args.tilde:
# Lop off leading slash
if self.request_path.startswith("/"):
self.request_path = self.request_path[1:]
if self.server.args.tilde and self.request_path.startswith("~"):
bits = self.request_path.split(os.sep)
# Remove ~ to get username
bits[0] = bits[0][1:]
@ -64,12 +61,11 @@ class GegobiHandler(socketserver.BaseRequestHandler):
local_path = os.path.join(*bits)
## Standard path
else:
local_path = os.path.join(self.server.args.base, urllib.parse.unquote(self.request_path))
## Make absolutely sure we're not anywhere we shouldn't be
if not (local_path.startswith(self.server.args.base) or
local_path.startsiwth(self.server.args.tilde)):
self.send_gemini_header(51, "Not found.")
return
local_path = os.path.join(self.server.args.base, self.request_path)
## Make absolutely sure we're not anywhere we shouldn't be
if not local_path.startswith(self.server.args.base):
self.send_gemini_header(51, "Not found.")
return
# Handle not founds
if not os.path.exists(local_path):
self.send_gemini_header(51, "Not found.")
@ -144,6 +140,7 @@ class GegobiHandler(socketserver.BaseRequestHandler):
self.request_host = parsed.hostname
self.request_port = parsed.port or 1965
self.request_path = parsed.path[1:] if parsed.path.startswith("/") else parsed.path
self.request_path = urllib.parse.unquote(self.request_path)
self.request_query = parsed.query
def handle_geminimap(self, filename):
@ -290,14 +287,6 @@ Gemini protocol as well, resulting in "Gemini-Gopher bi-hosting"
args.base))
sys.exit(1)
# Absolutise tilde directory and make sure it exists
if args.tilde:
args.tilde = os.path.abspath(os.path.join(args.base, args.tilde))
if not os.path.exists(args.base):
print("Could not find tilde directory {}.".format(
args.base))
sys.exit(1)
if not (os.path.exists(args.cert) and os.path.exists(args.key)):
print("Could not find certificate file {} and/or key file {}.".format(
args.cert, args.key))