From dc804b9d5f3a2a9f1fffa1b97d82e0e04c44508b Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Mon, 19 Sep 2022 15:00:15 +0000 Subject: [PATCH 1/3] remove unused code --- src/Site/Site.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Site/Site.py b/src/Site/Site.py index ea19c4a25..7deab5cc5 100644 --- a/src/Site/Site.py +++ b/src/Site/Site.py @@ -35,7 +35,6 @@ class Site(object): def __init__(self, address, allow_create=True, settings=None): self.address = str(re.sub("[^A-Za-z0-9]", "", address)) # Make sure its correct address self.address_hash = hashlib.sha256(self.address.encode("ascii")).digest() - self.address_sha1 = hashlib.sha1(self.address.encode("ascii")).digest() self.address_short = "%s..%s" % (self.address[:6], self.address[-4:]) # Short address for logging self.log = logging.getLogger("Site:%s" % self.address_short) self.addEventListeners() From 128ff2dc3984072bd379e697f9d13637b38ddd3d Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Mon, 19 Sep 2022 15:27:45 +0000 Subject: [PATCH 2/3] comment in Db --- src/Db/Db.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Db/Db.py b/src/Db/Db.py index d1d9ce159..3d4b6d7da 100644 --- a/src/Db/Db.py +++ b/src/Db/Db.py @@ -1,3 +1,5 @@ +## please note that this file uses custom db cursor and thus may surprise you with how sql queries are performed + import sqlite3 import json import time From 53d51e8bc88ae408709f48ffcedc63251da1a8e8 Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Mon, 19 Sep 2022 16:05:25 +0000 Subject: [PATCH 3/3] redirect .bit domains to hash actual addresses refs #23 --- src/Ui/UiRequest.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Ui/UiRequest.py b/src/Ui/UiRequest.py index e34d22cb6..1b2d5cf31 100644 --- a/src/Ui/UiRequest.py +++ b/src/Ui/UiRequest.py @@ -372,7 +372,7 @@ def formatRedirect(self, url): # Redirect to an url def actionRedirect(self, url): self.start_response('301 Redirect', [('Location', str(url))]) - yield self.formatRedirect(url) + return self.formatRedirect(url) def actionIndex(self): return self.actionRedirect("/" + config.homepage + "/") @@ -634,7 +634,9 @@ def parsePath(self, path): match = re.match(r"/(media/)?(?P
[A-Za-z0-9]+[A-Za-z0-9\._-]+)(?P/.*|$)", path) if match: path_parts = match.groupdict() - if self.isDomain(path_parts["address"]): + addr = path_parts["address"] + if self.isDomain(addr): + path_parts["domain"] = addr path_parts["address"] = self.resolveDomain(path_parts["address"]) path_parts["request_address"] = path_parts["address"] # Original request address (for Merger sites) path_parts["inner_path"] = path_parts["inner_path"].lstrip("/") @@ -651,6 +653,12 @@ def actionSiteMedia(self, path, header_length=True, header_noscript=False): except SecurityError as err: return self.error403(err) + if "domain" in path_parts: + addr = path_parts['address'] + path = path_parts['inner_path'] + query = self.env['QUERY_STRING'] + return self.actionRedirect(f"/{addr}/{path}?{query}") + if not path_parts: return self.error404(path)